#ifndef COSMOPOLITAN_H_
#define COSMOPOLITAN_H_


/*!BEGIN libc/integral/normalize.inc */

#ifdef __COSMOPOLITAN__
#undef __COSMOPOLITAN__
#endif

#define __COSMOPOLITAN_MAJOR__ 3
#define __COSMOPOLITAN_MINOR__ 3
#define __COSMOPOLITAN_PATCH__ 9
#define __COSMOPOLITAN__                                                   \
  (100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
   __COSMOPOLITAN_PATCH__)

#ifndef __COUNTER__
#define __COUNTER__ __LINE__
#endif

#if __GNUC__ + 0 < 2
#undef __GNUC__
#elif defined(__GNUC__) && defined(SWIG) /* lool */
#undef __GNUC__
#elif defined(__GNUC__) && defined(__NVCC__) /* lool */
#undef __GNUC__
#elif !defined(__GNUC__) && defined(__APPLE__) /* modesty */
#define __GNUC__            4
#define __GNUC_MINOR__      2
#define __GNUC_PATCHLEVEL__ 1
#elif !defined(__GNUC__) && defined(__TINYC__)
#define __GNUC__            2
#define __GNUC_MINOR__      0
#define __GNUC_PATCHLEVEL__ 0
#endif

#if !defined(__x86_64__) && \
    (defined(__amd64__) || (defined(_M_AMD64) && defined(_M_X64)))
#define __x86_64__ 1
#elif !defined(__i386__) && ((defined(__i486__) || defined(__i586__) ||  \
                              defined(__i686__) || defined(__i786__)) || \
                             _M_IX86 + 0 >= 400)
#define __i386__ 1
#elif !defined(__ia16__) && (defined(__MSDOS__) || defined(__BCC__))
#define __ia16__ 1
#endif
#if __ia16__ + __i386__ + __x86_64__ + 0
#define __x86__ 1
#endif

#ifdef _MSC_VER
#define __STRICT_ANSI__
#ifndef __STDC__
#define __STDC__
#endif
#endif

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif
#ifndef __has_extension
#define __has_extension(x) 0
#endif

#ifdef unix
#undef unix
#endif

#ifdef linux
#undef linux
#endif

#ifdef __linux
#undef __linux
#endif

#ifdef __linux__
#undef __linux__
#endif

#ifndef __BIGGEST_ALIGNMENT__
#define __BIGGEST_ALIGNMENT__ 16
#endif

#ifdef _COSMO_SOURCE
#define FRAMESIZE 65536
#define _PAGESIZE 4096
#endif

#if defined(__LP64__) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/lp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xfffffffffffffffful
#define __SIZE_MAX__    0xfffffffffffffffful
#define __INTPTR_MAX__  0x7fffffffffffffffl
#define __UINTPTR_MAX__ 0xfffffffffffffffful
#define __WINT_MAX__    0xffffffffu
#define __UINTMAX_MAX__ 0xffffffffffffffffUL
#define __INTMAX_MAX__  0x7fffffffffffffffL

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        8
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      8
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __INT16_TYPE__   short int
#define __INT32_TYPE__   int
#define __INT64_TYPE__   long int
#define __INT8_TYPE__    signed char
#define __INTMAX_TYPE__  long int
#define __INTPTR_TYPE__  long int
#define __PTRDIFF_TYPE__ long int
#define __SIZE_TYPE__    long unsigned int
#define __UINT16_TYPE__  short unsigned int
#define __UINT32_TYPE__  unsigned int
#define __UINT64_TYPE__  long unsigned int
#define __UINT8_TYPE__   unsigned char
#define __UINTMAX_TYPE__ long unsigned int
#define __UINTPTR_TYPE__ long unsigned int
#define __WCHAR_TYPE__   int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#elif defined(_MSC_VER) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/llp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xffffffffffffffffull
#define __SIZE_MAX__    0xffffffffffffffffull
#define __INTPTR_MAX__  0x7fffffffffffffffll
#define __UINTPTR_MAX__ 0xffffffffffffffffull
#define __WINT_MAX__    0xffffffffu

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        4
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      4
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#define __INT8_C(c)   c
#define __UINT8_C(c)  c
#define __INT16_C(c)  c
#define __UINT16_C(c) c
#define __INT32_C(c)  c
#define __UINT32_C(c) c##U
#define __INT64_C(c)  c##LL
#define __UINT64_C(c) c##ULL

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __INT8_TYPE__    signed char
#define __UINT8_TYPE__   unsigned char
#define __INT16_TYPE__   short int
#define __UINT16_TYPE__  short unsigned int
#define __INT32_TYPE__   int
#define __UINT32_TYPE__  unsigned int
#define __INT64_TYPE__   long long int
#define __UINT64_TYPE__  long long unsigned int
#define __INTPTR_TYPE__  long long int
#define __UINTPTR_TYPE__ long long unsigned int
#define __PTRDIFF_TYPE__ long long int
#define __SIZE_TYPE__    unsigned int
#define __WCHAR_TYPE__   int
#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef __STDC__


/*!BEGIN libc/integral/c.inc */

#if __GNUC__ + 0 < 2
#define __attribute__(x)
#endif

#ifndef __cplusplus
#define COSMOPOLITAN_C_START_
#define COSMOPOLITAN_C_END_
#define COSMOPOLITAN_CXX_START_
#define COSMOPOLITAN_CXX_END_
#define COSMOPOLITAN_CXX_USING_
#endif

#ifndef __ia16__
#define __far
#endif

#if !defined(__GNUC__) && __cplusplus + 0 >= 201103L
#define typeof(x) decltype(x)
#elif !defined(__GNUC__) && __STDC_VERSION__ + 0 < 201112
#define typeof(x) __typeof(x)
#endif

#ifdef __cplusplus
#if __cplusplus >= 201103L
#define _Alignof(x) alignof(x)
#endif /* C++11 */
#else  /* __cplusplus */
#if __STDC_VERSION__ + 0 < 201112
#if __GNUC__ + _MSC_VER + 0
#define _Alignof(x) __alignof(x)
#else
#define _Alignof(x) /* basically all it ever did lool */ sizeof(x)
#endif /* GNU/MSVC/!ANSI */
#endif /* C11 */
#endif /* __cplusplus */

#if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901
#if defined(__GNUC__) || defined(_MSC_VER)
#define inline __inline
#else
#define inline
#define __inline
#endif
#endif

#ifdef __chibicc__
#define __extension__
#endif

#if __STDC_VERSION__ + 0 < 201112
#ifdef __GNUC__
#define _Alignas(x) __attribute__((__aligned__(x)))
#elif defined(_MSC_VER)
#define _Alignas(x) __declspec(align(x))
#endif
#endif

#ifdef _MSC_VER
#define __builtin_unreachable() __assume(false)
#elif !((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
        defined(__clang__) || defined(__INTEL_COMPILER) ||    \
        __has_builtin(__builtin_unreachable))
#define __builtin_unreachable() \
  for (;;) {                    \
  }
#endif

#if (!defined(__llvm__) && !__has_builtin(__builtin_assume))
#define __builtin_assume(x)    \
  do {                         \
    if (!(x))                  \
      __builtin_unreachable(); \
  } while (0)
#endif

#if __STDC_VERSION__ + 0 < 201112
#define _Atomic(TYPE) TYPE volatile
#endif

#ifdef __llvm__
#define __gnu_printf__ __printf__
#define __gnu_scanf__  __scanf__
#endif

#if __cplusplus + 0 >= 201103L
#define NULL nullptr
#elif !defined(__cplusplus)
#define NULL ((void *)0)
#else
#define NULL 0
#endif

#ifndef __cplusplus
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wc++-compat"
#endif
typedef __WCHAR_TYPE__ wchar_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC pop_options
#endif
#endif /* __cplusplus */

#ifndef __COSMOCC__


/*!BEGIN libc/stdbool.h */

#define COSMOPOLITAN_LIBC_STDBOOL_H_

#ifndef __cplusplus

#define bool _Bool
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
#define true  ((_Bool) + 1u)
#define false ((_Bool) + 0u)
#else
#define true  1
#define false 0
#endif

#else /* __cplusplus */

#define _Bool bool

#endif /* __cplusplus */

#define __bool_true_false_are_defined 1

#endif

#define _LIBCPP_STDINT_H

typedef int errno_t;
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __WINT_TYPE__ wint_t; /* uint32_t on linux but int32_t on xnu */
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ bool32;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;

#define __DEFINED_max_align_t
typedef long double max_align_t;

#ifdef _COSMO_SOURCE
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || defined(__llvm__)
typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t;
#endif
#endif /* _COSMO_SOURCE */

#ifndef __AXDX_T
#define __AXDX_T
typedef struct {
  intptr_t ax, dx;
} axdx_t;
#endif

#ifndef __chibicc__
#define va_list            __builtin_va_list
#define va_arg(ap, type)   __builtin_va_arg(ap, type)
#define va_copy(dest, src) __builtin_va_copy(dest, src)
#define va_end(ap)         __builtin_va_end(ap)
#define va_start(ap, last) __builtin_va_start(ap, last)
#else


/*!BEGIN libc/integral/lp64arg.inc */

/* variadic arguments for chibicc */

/* <sync libc/runtime/valist.c> */
struct __va_list {
  uint32_t gp_offset;
  uint32_t fp_offset;
  void *overflow_arg_area;
  void *reg_save_area;
};
/* </sync libc/runtime/valist.c> */

void *__va_arg(struct __va_list *, size_t, unsigned, unsigned);

#define __GNUC_VA_LIST 1
#define __gnuc_va_list va_list

#define va_end(AP)
#define va_copy(DST, SRC) ((DST)[0] = (SRC)[0])
#define va_start(AP, LAST)                    \
  do {                                        \
    *(AP) = *(struct __va_list *)__va_area__; \
  } while (0)

#define va_arg(AP, TYPE)                               \
  (*(TYPE *)__va_arg(AP, sizeof(TYPE), _Alignof(TYPE), \
                     __builtin_reg_class(TYPE)))

typedef struct __va_list va_list[1];
#endif

#define libcesque   dontthrow dontcallback
#define memcpyesque libcesque
#define strlenesque libcesque nosideeffect paramsnonnull()
#define vallocesque \
  libcesque __wur returnsaligned((65536)) returnspointerwithnoaliases
#define reallocesque libcesque returnsaligned((16))
#define mallocesque  reallocesque returnspointerwithnoaliases
#define interruptfn  nocallersavedregisters forcealignargpointer

#ifndef pureconst
#define pureconst __attribute__((__const__))
#endif

#ifndef forcealign
#define forcealign(bytes) __attribute__((__aligned__(bytes)))
#endif
#define thatispacked __attribute__((__packed__))

#define printfesque(n)   __attribute__((__format__(__gnu_printf__, n, n + 1)))
#define scanfesque(n)    __attribute__((__format__(__gnu_scanf__, n, n + 1)))
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))

#ifndef privileged
#define privileged \
  _Section(".privileged") dontinline dontinstrument dontubsan dontasan
#endif

#ifndef wontreturn
#if (__has_attribute(__noreturn__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208)
#define wontreturn __attribute__((__noreturn__))
#else
#define wontreturn
#endif
#endif

#ifndef nosideeffect
#if (__has_attribute(__pure__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296)
#define nosideeffect __attribute__((__pure__))
#else
#define nosideeffect
#endif
#endif

#ifndef dontinline
#ifdef _MSC_VER
#define dontinline __declspec(noinline)
#elif (__has_attribute(__noinline__) || \
       (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
#define dontinline __attribute__((__noinline__))
#else
#define dontinline
#endif
#endif

#ifndef dontclone
#if (__has_attribute(__noclone__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405)
#define dontclone __attribute__((__noclone__))
#else
#define dontclone
#endif
#endif

#ifndef forceinline
#ifdef __cplusplus
#define forceinline inline
#else
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
    !defined(__cplusplus) ||                              \
    (defined(__clang__) &&                                \
     (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define forceinline                                                 \
  static __inline __attribute__((__always_inline__, __gnu_inline__, \
                                 __no_instrument_function__, __unused__))
#else
#define forceinline                                 \
  static __inline __attribute__((__always_inline__, \
                                 __no_instrument_function__, __unused__))
#endif /* __GNUC_STDC_INLINE__ */
#endif /* GCC >= 4.3 */
#elif defined(_MSC_VER)
#define forceinline __forceinline
#else
#define forceinline static inline
#endif /* !ANSI && GCC >= 3.2 */
#endif /* __cplusplus */
#endif /* forceinline */

#ifndef __wur
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
     __has_attribute(__warn_unused_result__))
#define __wur __attribute__((__warn_unused_result__))
#else
#define __wur
#endif
#endif

#ifndef nullterminated
#if __has_attribute(__sentinel__) || __GNUC__ + 0 >= 4
#define nullterminated(x) __attribute__((__sentinel__ x))
#else
#define nullterminated(x)
#endif
#endif

#ifndef flattenout
#if __has_attribute(__flatten__) || \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401 && !defined(__llvm__))
#define flattenout __attribute__((__flatten__))
#else
#define flattenout
#endif
#endif

#ifndef externinline
#if (!defined(__cplusplus) ||                              \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
     (defined(__clang__) &&                                \
      (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__))))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define externinline extern __inline __attribute__((__gnu_inline__))
#else
#define externinline extern __inline __attribute__((__always_inline__))
#endif
#else
#define externinline inline
#endif
#endif

#ifndef relegated
#if (__has_attribute(__cold__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define relegated __attribute__((__cold__))
#else
#define relegated
#endif
#endif

#if (__has_attribute(__warning__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define warnifused(s) __attribute__((__warning__(s)))
#else
#define warnifused(s)
#endif

#ifndef firstclass
#if (__has_attribute(__hot__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define firstclass __attribute__((__hot__))
#else
#define firstclass
#endif
#endif

#ifndef paramsnonnull
#if (__has_attribute(__nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs))
#else
#define paramsnonnull(opt_1idxs)
#endif
#endif

#if __STDC_VERSION__ + 0 >= 199901L
#define hasatleast static
#else
#define hasatleast
#endif

#if __STDC_VERSION__ + 0 < 199901L && !defined(restrict)
#if !defined(__cplusplus) && \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER))
#define restrict __restrict__
#else
#define restrict
#define __restrict
#endif
#endif

#ifndef dontcallback
#if (__has_attribute(__leaf__) || \
     (!defined(__llvm__) &&       \
      (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406))
#define dontcallback __attribute__((__leaf__))
#else
#define dontcallback
#endif
#endif

#ifndef dontthrow
#if defined(__cplusplus) &&        \
    (__has_attribute(dontthrow) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define dontthrow __attribute__((__nothrow__))
#elif defined(_MSC_VER)
#define dontthrow __declspec(nothrow)
#else
#define dontthrow
#endif
#endif

#ifndef returnstwice
#if (__has_attribute(__returns_twice__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402)
#define returnstwice __attribute__((__returns_twice__))
#else
#define returnstwice
#endif
#endif

#ifndef nodebuginfo
#if __has_attribute(__nodebug__) || defined(__llvm__)
#define nodebuginfo __attribute__((__nodebug__))
#else
#define nodebuginfo
#endif
#endif

#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
    __has_attribute(__force_align_arg_pointer__)
#define forcealignargpointer __attribute__((__force_align_arg_pointer__))
#else
#define forcealignargpointer "need modern compiler"
#endif

#ifndef returnsnonnull
#if (__has_attribute(__returns_nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsnonnull __attribute__((__returns_nonnull__))
#else
#define returnsnonnull
#endif
#endif

#if (__has_attribute(__assume_aligned__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsaligned(x) __attribute__((__assume_aligned__ x))
#else
#define returnsaligned(x)
#endif

#ifndef returnspointerwithnoaliases
#if (__has_attribute(__malloc__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnspointerwithnoaliases __attribute__((__malloc__))
#elif defined(_MSC_VER)
#define returnspointerwithnoaliases __declspec(allocator)
#else
#define returnspointerwithnoaliases
#endif
#endif

#ifndef attributeallocsize
#if (__has_attribute(__alloc_size__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocsize(x) __attribute__((__alloc_size__ x))
#else
#define attributeallocsize(x)
#endif
#endif

#ifndef attributeallocalign
#if (__has_attribute(__alloc_align__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocalign(x) __attribute__((__alloc_align__ x))
#else
#define attributeallocalign(x)
#endif
#endif

#if __cplusplus + 0 >= 201103L
#define autotype(x) auto
#elif ((__has_builtin(__auto_type) || defined(__llvm__) ||     \
        (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) && \
       !defined(__chibicc__))
#define autotype(x) __auto_type
#else
#define autotype(x) typeof(x)
#endif

#define offsetof(type, member) __builtin_offsetof(type, member)

#ifdef _COSMO_SOURCE

#ifndef dontinstrument
#if (__has_attribute(__no_instrument_function__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
#if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \
    __has_attribute(__patchable_function_entry__)
#define dontinstrument                       \
  __attribute__((__no_instrument_function__, \
                 __patchable_function_entry__(0, 0)))
#else
#define dontinstrument __attribute__((__no_instrument_function__))
#endif
#else
#define dontinstrument
#endif
#endif

#ifndef mayalias
#if (__has_attribute(__may_alias__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define mayalias __attribute__((__may_alias__))
#else
#define mayalias
#endif
#endif

#ifndef dontoptimize
#if defined(__llvm__) || __has_attribute(__optnone__)
#define dontoptimize __attribute__((__optnone__))
#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define dontoptimize __attribute__((__optimize__(0)))
#endif
#endif

#ifndef optimizesize
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define optimizesize __attribute__((__optimize__("s")))
#elif defined(__llvm__) || __has_attribute(__optnone__)
#define optimizesize __attribute__((__optnone__))
#endif
#endif

#ifndef optimizespeed
/* warning: corrupts frame pointer; only use on leaf functions */
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define optimizespeed __attribute__((__optimize__(3)))
#else
#define optimizespeed
#endif
#endif

#ifndef unrollloops
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define unrollloops __attribute__((__optimize__("unroll-loops")))
#else
#define unrollloops
#endif
#endif

#ifndef _Microarchitecture
#if (__has_attribute(__target__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
#define _Microarchitecture(march) __attribute__((__target__(march)))
#else
#define _Microarchitecture(march)
#endif
#endif

#ifdef __x86_64__
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
#else
#define nocallersavedregisters "need modern compiler"
#endif
#else
#define nocallersavedregisters
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_address__))
#define dontasan __attribute__((__no_sanitize_address__))
#else
#define dontasan
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_undefined__))
#define dontubsan __attribute__((__no_sanitize_undefined__))
#else
#define dontubsan
#endif

#ifdef __x86_64__
#define notpossible          \
  do {                       \
    __asm__("nop\n\t"        \
            "ud2\n\t"        \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#elif defined(__aarch64__)
#define notpossible          \
  do {                       \
    __asm__("udf\t#0\n\t"    \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#else
#define notpossible __builtin_trap()
#endif

#define donothing \
  do {            \
  } while (0)

#define textstartup _Section(".text.startup")
#define textexit    _Section(".text.exit")
#define textreal    _Section(".text.real")
#define texthead    _Section(".text.head")
#define textwindows _Section(".text.windows")
#define antiquity   _Section(".text.antiquity")

#ifdef __llvm__
#define __builtin_ia32_movntdq(x, y) (*(x) = (y))
#endif

#ifndef _Section
#define _Section(s) __attribute__((__section__(s)))
#endif

#ifndef __llvm__
#pragma GCC diagnostic ignored "-Wformat=0" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
#pragma GCC diagnostic warning "-Wunknown-pragmas"
#else
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wconstant-logical-operand" /* what */
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wstring-plus-int"       /* features 4 losers */
#pragma GCC diagnostic ignored "-Wkeyword-compat"        /* c++ upgrade */
#pragma GCC diagnostic ignored "-Wuser-defined-literals" /* reserved for me */
#endif

#pragma GCC diagnostic ignored "-Wformat-extra-args"     /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wunused-function"       /* contradicts dce */
#pragma GCC diagnostic ignored "-Wunused-const-variable" /* sooo ridiculous */
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */
#endif

#ifdef __x86_64__
#define DebugBreak() __asm__("int3")
#elif defined(__aarch64__)
#define DebugBreak() __asm__("brk\t#0x666")
#else
#define DebugBreak() __builtin_trap()
#endif

#ifdef __aarch64__
/* raise sigill (not sigtrap) like x86 does */
#define __builtin_trap()     \
  do {                       \
    __asm__("udf\t#0x666");  \
    __builtin_unreachable(); \
  } while (0)
#endif

#endif /* _COSMO_SOURCE */

#define __veil(CONSTRAINT, EXPRESSION)                               \
  __extension__({                                                    \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                 \
    __asm__("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                     \
  })

#define __conceal(CONSTRAINT, EXPRESSION)                                     \
  __extension__({                                                             \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                          \
    __asm__ volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                              \
  })

#define __expropriate(EXPRESSION)                      \
  __extension__({                                      \
    __asm__ volatile("" ::"g"(EXPRESSION) : "memory"); \
    0;                                                 \
  })

#if !defined(__APPLE__) && defined(__x86_64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
#elif defined(__aarch64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
#else
#define __yoink(SYMBOL) (void)0
#endif

#if !defined(__APPLE__) && defined(__x86_64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#elif defined(__aarch64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
#else
#define __static_yoink(SYMBOLSTR)
#endif

#if !defined(IM_FEELING_NAUGHTY)
#define __static_yoink_source(PATH) __static_yoink(PATH)
#else
#define __static_yoink_source(PATH)
#endif

#define __weak_reference(sym, alias) __weak_reference_impl(sym, alias)
#define __weak_reference_impl(sym, alias)  \
  __asm__(".weak\t" #alias "\n\t"          \
          ".equ\t" #alias ", " #sym "\n\t" \
          ".type\t" #alias ",@notype")

#ifndef __chibicc__
#define __strong_reference(sym, alias) \
  extern __typeof(sym) alias __attribute__((__alias__(#sym)))
#else
#define __strong_reference(sym, alias) __weak_reference(sym, alias)
#endif

#if defined(__GNUC__) || defined(__llvm__)
#define __funline \
  extern __inline \
      __attribute__((__gnu_inline__, __always_inline__, __artificial__))
#else
#define __funline static inline
#endif

#if defined(__x86_64__) && (defined(__GNUC__) || defined(__llvm__)) && \
    !defined(__chibicc__) && defined(__OPTIMIZE__)
#define __target_clones(x) __attribute__((__target_clones__(x ",default")))
#else
#define __target_clones(x)
#endif

#if !defined(TINY) && !defined(__AVX__)
#define __vex __target_clones("avx")
#else
#define __vex
#endif

#define __notice(sym, str)                                                   \
  __attribute__((__section__(".notice"), __aligned__(1))) const char sym[] = \
      "\n\n" str

#define MACHINE_CODE_ANALYSIS_BEGIN_
#define MACHINE_CODE_ANALYSIS_END_
#else
#define const
#define volatile
#endif
#ifdef __cplusplus


/*!BEGIN libc/integral/cxx.inc */

#define COSMOPOLITAN_CXX_START_ namespace cosmo {
#define COSMOPOLITAN_CXX_END_   }
#define COSMOPOLITAN_CXX_USING_ using namespace cosmo;
#define COSMOPOLITAN_C_START_   extern "C" {
#define COSMOPOLITAN_C_END_     }

#if !defined(__builtin_types_compatible_p) && !__has_builtin(types_compatible_p)
#if 0 /* todo jart whyyyy */


/*!BEGIN libc/integral/cxxtypescompat.inc */

#define NAME __cxx_types_compatible
#define QUALIFIED(Q1, Q2)       \
  template <class _T, class _U> \
  struct NAME<_T Q1, _U Q2> : NAME<_T, _U> {}

template <class, class>
struct NAME {
  enum { _value = 0 };
};

template <class _T>
struct NAME<_T, _T> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[], _T[N]> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[N], _T[]> {
  enum { _value = 1 };
};

QUALIFIED(const volatile, );
QUALIFIED(const volatile, const);
QUALIFIED(const, const volatile);
QUALIFIED(volatile, const volatile);
QUALIFIED(const volatile, volatile);
QUALIFIED(const, volatile);
QUALIFIED(volatile, const);
QUALIFIED(, const);
QUALIFIED(const, );
QUALIFIED(, volatile);
QUALIFIED(volatile, );

#undef QUALIFIED
#undef NAME
#define __builtin_types_compatible_p(A, B) \
  (__cxx_types_compatible<A, B>::_value)
#else
#define __builtin_types_compatible_p(A, B) 0
#endif
#endif

#if !defined(__builtin_choose_expr) && !__has_builtin(choose_expr)
#if 1
template <bool _P, typename _T, typename _U>
struct __cxx_choose_expr {
  __cxx_choose_expr(_T _a, _U _b) : _value(_a) {
  }
  const _T _value;
};
template <typename _T, typename _U>
struct __cxx_choose_expr<false, _T, _U> {
  __cxx_choose_expr(_T _a, _U _b) : _value(_b) {
  }
  const _U _value;
};
#define __builtin_choose_expr(X, A, B) \
  (__cxx_choose_expr<X, typeof(A), typeof(B)>(A, B)._value)
#else
#define __builtin_choose_expr(X, A, B) ((X) ? (A) : (B))
#endif
#endif

#ifdef __aarch64__
/* todo jart whyyyy */
#define _Float16 __fp16
#endif
#endif
#endif


/*!BEGIN ape/ape.h */

#define COSMOPOLITAN_APE_APE_H_

#define APE_VERSION_MAJOR 1
#define APE_VERSION_MINOR 10
#define APE_VERSION_STR   APE_VERSION_STR_(APE_VERSION_MAJOR, APE_VERSION_MINOR)
#define APE_VERSION_NOTE  APE_VERSION_NOTE_(APE_VERSION_MAJOR, APE_VERSION_MINOR)

#define APE_VERSION_STR__(x, y) #x "." #y
#define APE_VERSION_STR_(x, y)  APE_VERSION_STR__(x, y)
#define APE_VERSION_NOTE_(x, y) (100000000 * (x) + 1000000 * (y))



/*!BEGIN ape/relocations.h */

#define COSMOPOLITAN_APE_RELOCATIONS_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ αcτµαlly pδrταblε εxεcµταblε § relocations                                   │
╚──────────────────────────────────────────────────────────────────────────────╝
  One of the things αcτµαlly pδrταblε εxεcµταblε does a good job
  abstracting, is how a program needs to exist at three addresses
  simultaneously during the early stages of the loading process.

  By default, the linker calculates all symbols using virtual addresses.
  In some cases it's necessary to use addend macros that change virtual
  addresses into the other two types: physical and real. */

#define IMAGE_BASE_REAL 0x2000

#ifndef IMAGE_BASE_VIRTUAL
#define IMAGE_BASE_VIRTUAL 0x400000
#endif

#ifndef IMAGE_BASE_PHYSICAL
#define IMAGE_BASE_PHYSICAL 0x100000
#endif

/**
 * Returns Relative Virtual Address.
 */
#define RVA(x) ((x) - (IMAGE_BASE_VIRTUAL))

/**
 * Adjusts virtual address so it's relative to load address.
 */
#define PHYSICAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_PHYSICAL))

/**
 * Makes high-entropy read-only addresses relocatable in real mode.
 */
#define REAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_REAL))

#if IMAGE_BASE_VIRTUAL % 0x1000 != 0
#error "IMAGE_BASE_VIRTUAL must be 4kb aligned"
#endif
#if IMAGE_BASE_PHYSICAL % 0x1000 != 0
#error "IMAGE_BASE_PHYSICAL must be 4kb aligned"
#endif
#if IMAGE_BASE_REAL % 0x1000 != 0
#error "IMAGE_BASE_REAL must be 4kb aligned"
#endif



/*!BEGIN libc/ar.h */

#define COSMOPOLITAN_LIBC_AR_H_
COSMOPOLITAN_C_START_

#define ARMAG  "!<arch>\n"
#define SARMAG 8
#define ARFMAG "`\n"

struct ar_hdr {
  char ar_name[16];
  char ar_date[12];
  char ar_uid[6];
  char ar_gid[6];
  char ar_mode[8];
  char ar_size[10];
  char ar_fmag[2];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/assert.h */

#undef _ASSERT_H
#undef assert
#ifdef _COSMO_SOURCE
#undef unassert
#undef npassert
#ifndef NDEBUG
#undef __assert_macro
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

#define _ASSERT_H
COSMOPOLITAN_C_START_

void __assert_fail(const char *, const char *, int) libcesque;
void unassert(const char *, const char *, int) libcesque;

#ifdef NDEBUG
#define assert(x) ((void)0)
#else
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0)))
#endif

#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
#undef static_assert
#define static_assert _Static_assert
#endif

#ifdef _COSMO_SOURCE
#ifndef NDEBUG
#define unassert(x) __assert_macro(x, #x)
#define npassert(x) __assert_macro(x, #x)
#define __assert_macro(x, s)             \
  ({                                     \
    if (__builtin_expect(!(x), 0)) {     \
      (unassert)(s, __FILE__, __LINE__); \
      __asm__("nop");                    \
      __builtin_unreachable();           \
    }                                    \
    (void)0;                             \
  })
#else
#define npassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_trap();              \
    }                                \
    (void)0;                         \
  })
#define unassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_unreachable();       \
    }                                \
    (void)0;                         \
  })
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/atomic.h */

#define COSMOPOLITAN_LIBC_ATOMIC_H_

#define atomic_bool           _Atomic(_Bool)
#define atomic_bool32         _Atomic(__INT32_TYPE__)
#define atomic_char           _Atomic(char)
#define atomic_schar          _Atomic(signed char)
#define atomic_uchar          _Atomic(unsigned char)
#define atomic_short          _Atomic(short)
#define atomic_ushort         _Atomic(unsigned short)
#define atomic_int            _Atomic(int)
#define atomic_uint           _Atomic(unsigned int)
#define atomic_long           _Atomic(long)
#define atomic_ulong          _Atomic(unsigned long)
#define atomic_llong          _Atomic(long long)
#define atomic_ullong         _Atomic(unsigned long long)
#define atomic_char16_t       _Atomic(__CHAR16_TYPE__)
#define atomic_char32_t       _Atomic(__CHAR32_TYPE__)
#define atomic_wchar_t        _Atomic(__WCHAR_TYPE__)
#define atomic_intptr_t       _Atomic(__INTPTR_TYPE__)
#define atomic_uintptr_t      _Atomic(__UINTPTR_TYPE__)
#define atomic_size_t         _Atomic(__SIZE_TYPE__)
#define atomic_ptrdiff_t      _Atomic(__PTRDIFF_TYPE__)
#define atomic_int_fast8_t    _Atomic(__INT_FAST8_TYPE__)
#define atomic_uint_fast8_t   _Atomic(__UINT_FAST8_TYPE__)
#define atomic_int_fast16_t   _Atomic(__INT_FAST16_TYPE__)
#define atomic_uint_fast16_t  _Atomic(__UINT_FAST16_TYPE__)
#define atomic_int_fast32_t   _Atomic(__INT_FAST32_TYPE__)
#define atomic_uint_fast32_t  _Atomic(__UINT_FAST32_TYPE__)
#define atomic_int_fast64_t   _Atomic(__INT_FAST64_TYPE__)
#define atomic_uint_fast64_t  _Atomic(__UINT_FAST64_TYPE__)
#define atomic_int_least8_t   _Atomic(__INT_LEAST8_TYPE__)
#define atomic_uint_least8_t  _Atomic(__UINT_LEAST8_TYPE__)
#define atomic_int_least16_t  _Atomic(__INT_LEAST16_TYPE__)
#define atomic_uint_least16_t _Atomic(__UINT_LEAST16_TYPE__)
#define atomic_int_least32_t  _Atomic(__INT_LEAST32_TYPE__)
#define atomic_uint_least32_t _Atomic(__UINT_LEAST32_TYPE__)
#define atomic_int_least64_t  _Atomic(__INT_LEAST64_TYPE__)
#define atomic_uint_least64_t _Atomic(__UINT_LEAST64_TYPE__)

#ifdef __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_BOOL_LOCK_FREE     __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __CLANG_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __CLANG_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __CLANG_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __CLANG_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __CLANG_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __CLANG_ATOMIC_POINTER_LOCK_FREE
#else
#define ATOMIC_BOOL_LOCK_FREE     __GCC_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __GCC_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __GCC_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __GCC_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __GCC_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __GCC_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __GCC_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __GCC_ATOMIC_POINTER_LOCK_FREE
#endif



/*!BEGIN libc/complex.h */

#define COSMOPOLITAN_LIBC_COMPLEX_H_
COSMOPOLITAN_C_START_
#if __STDC_VERSION__ + 0 >= 201112 && !defined(__STDC_NO_COMPLEX__)

#define complex   _Complex
#define imaginary _Imaginary

double cabs(complex double) libcesque;
double carg(complex double) libcesque;
double cimag(complex double) libcesque;
double creal(complex double) libcesque;

float cabsf(complex float) libcesque;
float cargf(complex float) libcesque;
float cimagf(complex float) libcesque;
float crealf(complex float) libcesque;

long double cabsl(complex long double) libcesque;
long double cargl(complex long double) libcesque;
long double cimagl(complex long double) libcesque;
long double creall(complex long double) libcesque;

complex double cacos(complex double) libcesque;
complex double cacosh(complex double) libcesque;
complex double casin(complex double) libcesque;
complex double casinh(complex double) libcesque;
complex double catan(complex double) libcesque;
complex double catanh(complex double) libcesque;
complex double ccos(complex double) libcesque;
complex double ccosh(complex double) libcesque;
complex double cexp(complex double) libcesque;
complex double cexp2(complex double) libcesque;
complex double clog(complex double) libcesque;
complex double conj(complex double) libcesque;
complex double cpow(complex double, complex double) libcesque;
complex double cproj(complex double) libcesque;
complex double csin(complex double) libcesque;
complex double csinh(complex double) libcesque;
complex double csqrt(complex double) libcesque;
complex double ctan(complex double) libcesque;
complex double ctanh(complex double) libcesque;

complex float cacosf(complex float) libcesque;
complex float cacoshf(complex float) libcesque;
complex float casinf(complex float) libcesque;
complex float casinhf(complex float) libcesque;
complex float catanf(complex float) libcesque;
complex float catanhf(complex float) libcesque;
complex float ccosf(complex float) libcesque;
complex float ccoshf(complex float) libcesque;
complex float cexpf(complex float) libcesque;
complex float cexp2f(complex float) libcesque;
complex float clogf(complex float) libcesque;
complex float conjf(complex float) libcesque;
complex float cpowf(complex float, complex float) libcesque;
complex float cprojf(complex float) libcesque;
complex float csinf(complex float) libcesque;
complex float csinhf(complex float) libcesque;
complex float csqrtf(complex float) libcesque;
complex float ctanf(complex float) libcesque;
complex float ctanhf(complex float) libcesque;

complex long double cprojl(complex long double) libcesque;
complex long double csinhl(complex long double) libcesque;
complex long double csinl(complex long double) libcesque;
complex long double csqrtl(complex long double) libcesque;
complex long double ctanhl(complex long double) libcesque;
complex long double ctanl(complex long double) libcesque;
complex long double cacoshl(complex long double) libcesque;
complex long double cacosl(complex long double) libcesque;
complex long double casinhl(complex long double) libcesque;
complex long double casinl(complex long double) libcesque;
complex long double catanhl(complex long double) libcesque;
complex long double catanl(complex long double) libcesque;
complex long double ccoshl(complex long double) libcesque;
complex long double ccosl(complex long double) libcesque;
complex long double cexpl(complex long double) libcesque;
complex long double cexp2l(complex long double) libcesque;
complex long double clogl(complex long double) libcesque;
complex long double conjl(complex long double) libcesque;
complex long double cpowl(complex long double, complex long double) libcesque;

#ifndef __cplusplus
#define __CIMAG(x, t)   \
  (+(union {            \
      _Complex t __z;   \
      t __xy[2];        \
    }){(_Complex t)(x)} \
        .__xy[1])
#define creal(x)  ((double)(x))
#define crealf(x) ((float)(x))
#define creall(x) ((long double)(x))
#define cimag(x)  __CIMAG(x, double)
#define cimagf(x) __CIMAG(x, float)
#define cimagl(x) __CIMAG(x, long double)
#endif

#ifdef __GNUC__
#define _Complex_I (__extension__(0.0f + 1.0fi))
#else
#define _Complex_I (0.0f + 1.0fi)
#endif

#ifdef _Imaginary_I
#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I * (t)(y))
#elif defined(__clang__)
#define __CMPLX(x, y, t) (+(_Complex t){(t)(x), (t)(y)})
#else
#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y)))
#endif

#define CMPLX(x, y)  __CMPLX(x, y, double)
#define CMPLXF(x, y) __CMPLX(x, y, float)
#define CMPLXL(x, y) __CMPLX(x, y, long double)

#endif /* C11 */
COSMOPOLITAN_C_END_


/*!BEGIN libc/cosmo.h */

#define COSMOPOLITAN_LIBC_COSMO_H_
COSMOPOLITAN_C_START_

errno_t cosmo_once(_Atomic(uint32_t) *, void (*)(void));
int systemvpe(const char *, char *const[], char *const[]) libcesque;
char *GetProgramExecutableName(void);
void unleaf(void);
int __demangle(char *, const char *, size_t);
int __is_mangled(const char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/cxxabi.h */

#define _CXXABI_H
COSMOPOLITAN_C_START_

#ifdef __cplusplus
namespace __cxxabiv1 {
#endif /* __cplusplus */

char *__cxa_demangle(const char *, char *, size_t *, int *);
int __cxa_atexit(void (*)(void *), void *, void *) paramsnonnull((1)) dontthrow;
int __cxa_thread_atexit(void (*)(void *), void *, void *) dontthrow;
void __cxa_finalize(void *);

#ifdef __cplusplus
} /* namespace __cxxabiv1 */
#endif /* __cplusplus */

COSMOPOLITAN_C_END_


/*!BEGIN libc/dce.h */

#ifndef COSMOPOLITAN_LIBC_DCE_H_
#define COSMOPOLITAN_LIBC_DCE_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § autotune » dead code elimination                              │
╚─────────────────────────────────────────────────────────────────────────────*/

#ifndef SUPPORT_VECTOR
#ifdef __x86_64__
/**
 * Supported Platforms Tuning Knob (Runtime & Compile-Time)
 * Tuning this bitmask will remove platform polyfills at compile-time.
 */
#define SUPPORT_VECTOR 255
#else
#define SUPPORT_VECTOR (_HOSTLINUX | _HOSTXNU | _HOSTFREEBSD)
#endif
#endif

#define _HOSTLINUX   1
#define _HOSTMETAL   2
#define _HOSTWINDOWS 4
#define _HOSTXNU     8
#define _HOSTOPENBSD 16
#define _HOSTFREEBSD 32
#define _HOSTNETBSD  64

#ifdef NDEBUG
#define NoDebug() 1
#else
#define NoDebug() 0
#endif

#ifdef MODE_DBG
#define IsModeDbg() 1
#else
#define IsModeDbg() 0
#endif

#ifdef TRUSTWORTHY
#define IsTrustworthy() 1
#else
#define IsTrustworthy() 0
#endif

#ifdef TINY
#define IsTiny() 1
#else
#define IsTiny() 0
#endif

#ifdef __OPTIMIZE__
#define IsOptimized() 1
#else
#define IsOptimized() 0
#endif

#ifdef __SANITIZE_ADDRESS__
#define IsAsan() 1
#else
#define IsAsan() 0
#endif

#ifdef __aarch64__
#define IsAarch64()    1
#define IsXnuSilicon() IsXnu()
#else
#define IsAarch64()    0
#define IsXnuSilicon() 0
#endif

#if defined(__x86_64__)
#define _ARCH_NAME "amd64"
#elif defined(__aarch64__)
#define _ARCH_NAME "arm64"
#elif defined(__powerpc64__)
#define _ARCH_NAME "ppc64"
#elif defined(__s390x__)
#define _ARCH_NAME "s390x"
#elif defined(__riscv)
#define _ARCH_NAME "riscv"
#endif

#define SupportsLinux()   ((SUPPORT_VECTOR & _HOSTLINUX) == _HOSTLINUX)
#define SupportsMetal()   ((SUPPORT_VECTOR & _HOSTMETAL) == _HOSTMETAL)
#define SupportsWindows() ((SUPPORT_VECTOR & _HOSTWINDOWS) == _HOSTWINDOWS)
#define SupportsXnu()     ((SUPPORT_VECTOR & _HOSTXNU) == _HOSTXNU)
#define SupportsFreebsd() ((SUPPORT_VECTOR & _HOSTFREEBSD) == _HOSTFREEBSD)
#define SupportsOpenbsd() ((SUPPORT_VECTOR & _HOSTOPENBSD) == _HOSTOPENBSD)
#define SupportsNetbsd()  ((SUPPORT_VECTOR & _HOSTNETBSD) == _HOSTNETBSD)
#define SupportsBsd() \
  (!!(SUPPORT_VECTOR & (_HOSTXNU | _HOSTFREEBSD | _HOSTOPENBSD | _HOSTNETBSD)))
#define SupportsSystemv() \
  (!!(SUPPORT_VECTOR &    \
      (_HOSTLINUX | _HOSTXNU | _HOSTOPENBSD | _HOSTFREEBSD | _HOSTNETBSD)))

#ifndef __ASSEMBLER__
#define IsLinux()   (SupportsLinux() && (__hostos & _HOSTLINUX))
#define IsMetal()   (SupportsMetal() && (__hostos & _HOSTMETAL))
#define IsWindows() (SupportsWindows() && (__hostos & _HOSTWINDOWS))
#define IsXnu()     (SupportsXnu() && (__hostos & _HOSTXNU))
#define IsFreebsd() (SupportsFreebsd() && (__hostos & _HOSTFREEBSD))
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & _HOSTOPENBSD))
#define IsNetbsd()  (SupportsNetbsd() && (__hostos & _HOSTNETBSD))
#define IsBsd()     (IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd())
#else
/* clang-format off */
#define IsLinux() $_HOSTLINUX,__hostos(%rip)
#define IsMetal() $_HOSTMETAL,__hostos(%rip)
#define IsWindows() $_HOSTWINDOWS,__hostos(%rip)
#define IsBsd() $_HOSTXNU|_HOSTFREEBSD|_HOSTOPENBSD|_HOSTNETBSD,__hostos(%rip)
#define IsXnu() $_HOSTXNU,__hostos(%rip)
#define IsFreebsd() $_HOSTFREEBSD,__hostos(%rip)
#define IsOpenbsd() $_HOSTOPENBSD,__hostos(%rip)
#define IsNetbsd() $_HOSTNETBSD,__hostos(%rip)
/* clang-format on */
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __hostos;

int IsQemuUser(void);

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_DCE_H_ */


/*!BEGIN libc/errno.h */

#define COSMOPOLITAN_LIBC_ERRNO_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview System Five error codes.
 *
 * This file defines the `errno` global variable. When system calls
 * (e.g. read(), write(), etc.) fail they return -1 to indicate the
 * failure, and that is *the only* error return value. System calls
 * also update `errno` too whenever -1 is returned (otherwise errno
 * isn't changed) to be a non-zero value holding one of the numbers
 * below, in order to indicate why the system call failed.
 *
 * There is only one exception to the above rule; some system calls
 * are documented with the `@returnserrno` tag, which means they'll
 * return the error number rather than stuffing it in a global. You
 * can usually spot these system calls easily since most of them'll
 * have names like `posix_foo()` or `pthread_bar()`.
 *
 * @see libc/sysv/consts.sh for assigned numbers
 * @see libc/sysv/dos2errno.sh for multimapped numbers
 */

#if defined(__GNUC__) && defined(__aarch64__) && !defined(__cplusplus)
/* this header is included by 700+ files; therefore we */
/* hand-roll &__get_tls()->tib_errno to avoid #include */
/* cosmopolitan uses x28 as the tls register b/c apple */
#define errno                                      \
  (*__extension__({                                \
    errno_t *__ep;                                 \
    __asm__("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
    __ep;                                          \
  }))
#else
#define errno (*__errno_location())
#endif

/**
 * System call unavailable.
 * @note kNtErrorInvalidFunction on NT
 */
extern const errno_t ENOSYS;

/**
 * Operation not permitted.
 * @note kNtErrorInvalidAccess on NT
 */
extern const errno_t EPERM;

/**
 * No such file or directory.
 */
extern const errno_t ENOENT;

/**
 * No such process.
 */
extern const errno_t ESRCH;

/**
 * The greatest of all errnos.
 */
extern const errno_t EINTR;

/**
 * Unix consensus.
 */
extern const errno_t EIO;

/**
 * No such device or address.
 */
extern const errno_t ENXIO;

/**
 * Argument list too long.
 */
extern const errno_t E2BIG;

/**
 * Exec format error.
 */
extern const errno_t ENOEXEC;

/**
 * Bad file descriptor.
 */
extern const errno_t EBADF;

/**
 * No child process.
 */
extern const errno_t ECHILD;

/**
 * Resource temporarily unavailable (e.g. SO_RCVTIMEO expired, too many
 * processes, too much memory locked, read or write with O_NONBLOCK needs
 * polling, etc.).
 */
extern const errno_t EAGAIN;

/**
 * We require more vespene gas.
 */
extern const errno_t ENOMEM;

/**
 * Permission denied.
 */
extern const errno_t EACCES;

/**
 * Pointer passed to system call that would otherwise segfault.
 */
extern const errno_t EFAULT;

/**
 * Block device required.
 */
extern const errno_t ENOTBLK;

/**
 * Device or resource busy.
 */
extern const errno_t EBUSY;

/**
 * File exists.
 */
extern const errno_t EEXIST;

/**
 * Improper link.
 */
extern const errno_t EXDEV;

/**
 * No such device.
 */
extern const errno_t ENODEV;

/**
 * Not a directory.
 */
extern const errno_t ENOTDIR;

/**
 * Is a a directory.
 */
extern const errno_t EISDIR;

/**
 * Invalid argument.
 */
extern const errno_t EINVAL;

/**
 * Too many open files in system.
 */
extern const errno_t ENFILE;

/**
 * Too many open files.
 */
extern const errno_t EMFILE;

/**
 * Inappropriate i/o control operation.
 */
extern const errno_t ENOTTY;

/**
 * Won't open executable that's executing in write mode.
 */
extern const errno_t ETXTBSY;

/**
 * File too large.
 */
extern const errno_t EFBIG;

/**
 * No space left on device.
 */
extern const errno_t ENOSPC;

/**
 * Disk quota exceeded.
 */
extern const errno_t EDQUOT;

/**
 * Invalid seek.
 */
extern const errno_t ESPIPE;

/**
 * Read-only filesystem.
 */
extern const errno_t EROFS;

/**
 * Too many links.
 */
extern const errno_t EMLINK;

/**
 * Broken pipe.
 */
extern const errno_t EPIPE;

/**
 * Mathematics argument out of domain of function.
 */
extern const errno_t EDOM;

/**
 * Result too large.
 */
extern const errno_t ERANGE;

/**
 * Resource deadlock avoided.
 */
extern const errno_t EDEADLK;

/**
 * Filename too long.
 */
extern const errno_t ENAMETOOLONG;

/**
 * No locks available.
 */
extern const errno_t ENOLCK;

/**
 * Directory not empty.
 */
extern const errno_t ENOTEMPTY;

/**
 * Too many levels of symbolic links.
 */
extern const errno_t ELOOP;

/**
 * No message error.
 */
extern const errno_t ENOMSG;

/**
 * Identifier removed.
 */
extern const errno_t EIDRM;

/**
 * Timer expired.
 */
extern const errno_t ETIME;

/**
 * Protocol error.
 */
extern const errno_t EPROTO;

/**
 * Overflow error.
 */
extern const errno_t EOVERFLOW;

/**
 * Unicode decoding error.
 */
extern const errno_t EILSEQ;

/**
 * Too many users.
 */
extern const errno_t EUSERS;

/**
 * Not a socket.
 */
extern const errno_t ENOTSOCK;

/**
 * Destination address required.
 */
extern const errno_t EDESTADDRREQ;

/**
 * Message too long.
 */
extern const errno_t EMSGSIZE;

/**
 * Protocol wrong type for socket.
 */
extern const errno_t EPROTOTYPE;

/**
 * Protocol not available.
 */
extern const errno_t ENOPROTOOPT;

/**
 * Protocol not supported.
 */
extern const errno_t EPROTONOSUPPORT;

/**
 * Socket type not supported.
 */
extern const errno_t ESOCKTNOSUPPORT;

/**
 * Operation not supported.
 */
extern const errno_t ENOTSUP;

/**
 * Socket operation not supported.
 */
extern const errno_t EOPNOTSUPP;

/**
 * Protocol family not supported.
 */
extern const errno_t EPFNOSUPPORT;

/**
 * Address family not supported.
 */
extern const errno_t EAFNOSUPPORT;

/**
 * Address already in use.
 */
extern const errno_t EADDRINUSE;

/**
 * Address not available.
 */
extern const errno_t EADDRNOTAVAIL;

/**
 * Network is down.
 */
extern const errno_t ENETDOWN;

/**
 * Host is unreachable.
 */
extern const errno_t ENETUNREACH;

/**
 * Connection reset by network.
 */
extern const errno_t ENETRESET;

/**
 * Connection reset before accept.
 */
extern const errno_t ECONNABORTED;

/**
 * Connection reset by client.
 */
extern const errno_t ECONNRESET;

/**
 * No buffer space available.
 */
extern const errno_t ENOBUFS;

/**
 * Socket is connected.
 */
extern const errno_t EISCONN;

/**
 * Socket is not connected.
 */
extern const errno_t ENOTCONN;

/**
 * Cannot send after transport endpoint shutdown.
 */
extern const errno_t ESHUTDOWN;

/**
 * Too many references: cannot splice.
 */
extern const errno_t ETOOMANYREFS;

/**
 * Connection timed out.
 */
extern const errno_t ETIMEDOUT;

/**
 * Connection refused error.
 */
extern const errno_t ECONNREFUSED;

/**
 * Host down error.
 */
extern const errno_t EHOSTDOWN;

/**
 * Host unreachable error.
 */
extern const errno_t EHOSTUNREACH;

/**
 * Connection already in progress.
 */
extern const errno_t EALREADY;

/**
 * Operation already in progress.
 */
extern const errno_t EINPROGRESS;

/**
 * Stale error.
 */
extern const errno_t ESTALE;

/**
 * Remote error.
 */
extern const errno_t EREMOTE;

/**
 * Bad message.
 */
extern const errno_t EBADMSG;

/**
 * Operation canceled.
 */
extern const errno_t ECANCELED;

/**
 * Owner died.
 */
extern const errno_t EOWNERDEAD;

/**
 * State not recoverable.
 */
extern const errno_t ENOTRECOVERABLE;

/**
 * No network.
 */
extern const errno_t ENONET;

/**
 * Please restart syscall.
 */
extern const errno_t ERESTART;

/**
 * Out of streams resources.
 */
extern const errno_t ENOSR;

/**
 * No string.
 */
extern const errno_t ENOSTR;

/**
 * No data.
 */
extern const errno_t ENODATA;

/**
 * Multihop attempted.
 */
extern const errno_t EMULTIHOP;

/**
 * Link severed.
 */
extern const errno_t ENOLINK;

/**
 * No medium found.
 */
extern const errno_t ENOMEDIUM;

/**
 * Wrong medium type.
 */
extern const errno_t EMEDIUMTYPE;

/**
 * Inappropriate file type or format.
 */
extern const errno_t EFTYPE;

extern const errno_t EAUTH;
extern const errno_t EBADARCH;
extern const errno_t EBADEXEC;
extern const errno_t EBADMACHO;
extern const errno_t EBADRPC;
extern const errno_t EDEVERR;
extern const errno_t ENEEDAUTH;
extern const errno_t ENOATTR;
extern const errno_t ENOPOLICY;
extern const errno_t EPROCLIM;
extern const errno_t EPROCUNAVAIL;
extern const errno_t EPROGMISMATCH;
extern const errno_t EPROGUNAVAIL;
extern const errno_t EPWROFF;
extern const errno_t ERPCMISMATCH;
extern const errno_t ESHLIBVERS;
extern const errno_t EADV;
extern const errno_t EBADE;
extern const errno_t EBADFD;
extern const errno_t EBADR;
extern const errno_t EBADRQC;
extern const errno_t EBADSLT;
extern const errno_t ECHRNG;
extern const errno_t ECOMM;
extern const errno_t EDOTDOT;
extern const errno_t EHWPOISON;
extern const errno_t EISNAM;
extern const errno_t EKEYEXPIRED;
extern const errno_t EKEYREJECTED;
extern const errno_t EKEYREVOKED;
extern const errno_t EL2HLT;
extern const errno_t EL2NSYNC;
extern const errno_t EL3HLT;
extern const errno_t EL3RST;
extern const errno_t ELIBACC;
extern const errno_t ELIBBAD;
extern const errno_t ELIBEXEC;
extern const errno_t ELIBMAX;
extern const errno_t ELIBSCN;
extern const errno_t ELNRNG;
extern const errno_t ENAVAIL;
extern const errno_t ENOANO;
extern const errno_t ENOCSI;
extern const errno_t ENOKEY;
extern const errno_t ENOPKG;
extern const errno_t ENOTNAM;
extern const errno_t ENOTUNIQ;
extern const errno_t EREMCHG;
extern const errno_t EREMOTEIO;
extern const errno_t ERFKILL;
extern const errno_t ESRMNT;
extern const errno_t ESTRPIPE;
extern const errno_t EUCLEAN;
extern const errno_t EUNATCH;
extern const errno_t EXFULL;

#define E2BIG           E2BIG
#define EACCES          EACCES
#define EADDRINUSE      EADDRINUSE
#define EADDRNOTAVAIL   EADDRNOTAVAIL
#define EAFNOSUPPORT    EAFNOSUPPORT
#define EAGAIN          EAGAIN
#define EALREADY        EALREADY
#define EBADF           EBADF
#define EBADMSG         EBADMSG
#define EBUSY           EBUSY
#define ECANCELED       ECANCELED
#define ECHILD          ECHILD
#define ECONNABORTED    ECONNABORTED
#define ECONNREFUSED    ECONNREFUSED
#define ECONNRESET      ECONNRESET
#define EDEADLK         EDEADLK
#define EDESTADDRREQ    EDESTADDRREQ
#define EDOM            EDOM
#define EDQUOT          EDQUOT
#define EEXIST          EEXIST
#define EFAULT          EFAULT
#define EFBIG           EFBIG
#define EFTYPE          EFTYPE
#define EHOSTDOWN       EHOSTDOWN
#define EHOSTUNREACH    EHOSTUNREACH
#define EIDRM           EIDRM
#define EILSEQ          EILSEQ
#define EINPROGRESS     EINPROGRESS
#define EINTR           EINTR
#define EINVAL          EINVAL
#define EIO             EIO
#define EISCONN         EISCONN
#define EISDIR          EISDIR
#define ELOOP           ELOOP
#define EMEDIUMTYPE     EMEDIUMTYPE
#define EMFILE          EMFILE
#define EMLINK          EMLINK
#define EMSGSIZE        EMSGSIZE
#define EMULTIHOP       EMULTIHOP
#define ENAMETOOLONG    ENAMETOOLONG
#define ENETDOWN        ENETDOWN
#define ENETRESET       ENETRESET
#define ENETUNREACH     ENETUNREACH
#define ENFILE          ENFILE
#define ENOBUFS         ENOBUFS
#define ENODATA         ENODATA
#define ENODEV          ENODEV
#define ENOENT          ENOENT
#define ENOEXEC         ENOEXEC
#define ENOLCK          ENOLCK
#define ENOLINK         ENOLINK
#define ENOMEDIUM       ENOMEDIUM
#define ENOMEM          ENOMEM
#define ENOMSG          ENOMSG
#define ENONET          ENONET
#define ENOPROTOOPT     ENOPROTOOPT
#define ENOSPC          ENOSPC
#define ENOSR           ENOSR
#define ENOSTR          ENOSTR
#define ENOSYS          ENOSYS
#define ENOTBLK         ENOTBLK
#define ENOTCONN        ENOTCONN
#define ENOTDIR         ENOTDIR
#define ENOTEMPTY       ENOTEMPTY
#define ENOTRECOVERABLE ENOTRECOVERABLE
#define ENOTSOCK        ENOTSOCK
#define ENOTSUP         ENOTSUP
#define ENOTTY          ENOTTY
#define ENXIO           ENXIO
#define EOPNOTSUPP      EOPNOTSUPP
#define EOVERFLOW       EOVERFLOW
#define EOWNERDEAD      EOWNERDEAD
#define EPERM           EPERM
#define EPFNOSUPPORT    EPFNOSUPPORT
#define EPIPE           EPIPE
#define EPROTO          EPROTO
#define EPROTONOSUPPORT EPROTONOSUPPORT
#define EPROTOTYPE      EPROTOTYPE
#define ERANGE          ERANGE
#define EREMOTE         EREMOTE
#define ERESTART        ERESTART
#define EROFS           EROFS
#define ESHUTDOWN       ESHUTDOWN
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT
#define ESPIPE          ESPIPE
#define ESRCH           ESRCH
#define ESTALE          ESTALE
#define ETIME           ETIME
#define ETIMEDOUT       ETIMEDOUT
#define ETOOMANYREFS    ETOOMANYREFS
#define ETXTBSY         ETXTBSY
#define EUSERS          EUSERS
#define EWOULDBLOCK     EAGAIN
#define EXDEV           EXDEV

extern errno_t __errno;
errno_t *__errno_location(void) dontthrow pureconst;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
extern char *program_invocation_short_name;
extern char *program_invocation_name;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/inttypes.h */

#define COSMOPOLITAN_LIBC_INTTYPES_H_

typedef __INT_LEAST8_TYPE__ int_least8_t;
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
typedef __INT_LEAST16_TYPE__ int_least16_t;
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
typedef __INT_LEAST32_TYPE__ int_least32_t;
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
typedef __INT_LEAST64_TYPE__ int_least64_t;
typedef __UINT_LEAST64_TYPE__ uint_least64_t;

typedef __INT_FAST8_TYPE__ int_fast8_t;
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
typedef __INT_FAST16_TYPE__ int_fast16_t;
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
typedef __INT_FAST32_TYPE__ int_fast32_t;
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
typedef __INT_FAST64_TYPE__ int_fast64_t;
typedef __UINT_FAST64_TYPE__ uint_fast64_t;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define __PRI8 "hh"

#if __SIZEOF_INT__ == 2
#define __PRI16 ""
#elif __SIZEOF_SHORT__ == 2
#define __PRI16 "h"
#elif __SIZEOF_LONG__ == 2
#define __PRI16 "l"
#endif

#if __SIZEOF_INT__ == 4
#define __PRI32 ""
#elif __SIZEOF_LONG__ == 4
#define __PRI32 "l"
#elif __SIZEOF_LONG_LONG__ == 4
#define __PRI32 "ll"
#endif

#if __SIZEOF_INT__ == 8
#define __PRI64 ""
#elif __SIZEOF_LONG__ == 8
#define __PRI64 "l"
#elif __SIZEOF_LONG_LONG__ == 8
#define __PRI64 "ll"
#endif

#if __SIZEOF_INT__ == 16
#define __PRI128 ""
#elif __SIZEOF_LONG__ == 16
#define __PRI128 "l"
#elif __SIZEOF_LONG_LONG__ == 16
#define __PRI128 "ll"
#elif __SIZEOF_INTMAX__ == 16
#define __PRI128 "j"
#else
#define __PRI128 "jj"
#endif

#if __SIZEOF_POINTER__ == __SIZEOF_INT__
#define __PRIPTR ""
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG__
#define __PRIPTR "l"
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__
#define __PRIPTR "ll"
#endif

#if __INT_FAST16_WIDTH__ == 16
#define __PRIFAST16 "h"
#elif __INT_FAST16_WIDTH__ == 32
#define __PRIFAST16 ""
#else
#define __PRIFAST16 "l"
#endif

#if __INT_FAST32_WIDTH__ == 32
#define __PRIFAST32 ""
#else
#define __PRIFAST32 "l"
#endif

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » decimal                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRId8   __PRI8 "d"
#define PRId16  __PRI16 "d"
#define PRId32  __PRI32 "d"
#define PRId64  __PRI64 "d"
#define PRId128 __PRI128 "d"

#define PRIdLEAST8   __PRI8 "d"
#define PRIdLEAST16  __PRI16 "d"
#define PRIdLEAST32  __PRI32 "d"
#define PRIdLEAST64  __PRI64 "d"
#define PRIdLEAST128 __PRI128 "d"

#define PRIdFAST8   __PRI8 "d"
#define PRIdFAST16  __PRIFAST16 "d"
#define PRIdFAST32  __PRIFAST32 "d"
#define PRIdFAST64  __PRI64 "d"
#define PRIdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » unsigned decimal        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIu8   __PRI8 "u"
#define PRIu16  __PRI16 "u"
#define PRIu32  __PRI32 "u"
#define PRIu64  __PRI64 "u"
#define PRIu128 __PRI128 "u"

#define PRIuLEAST8   __PRI8 "u"
#define PRIuLEAST16  __PRI16 "u"
#define PRIuLEAST32  __PRI32 "u"
#define PRIuLEAST64  __PRI64 "u"
#define PRIuLEAST128 __PRI128 "u"

#define PRIuFAST8   __PRI8 "u"
#define PRIuFAST16  __PRIFAST16 "u"
#define PRIuFAST32  __PRIFAST32 "u"
#define PRIuFAST64  __PRI64 "u"
#define PRIuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » wut                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIi8   __PRI8 "i"
#define PRIi16  __PRI16 "i"
#define PRIi32  __PRI32 "i"
#define PRIi64  __PRI64 "i"
#define PRIi128 __PRI128 "i"

#define PRIiLEAST8   __PRI8 "i"
#define PRIiLEAST16  __PRI16 "i"
#define PRIiLEAST32  __PRI32 "i"
#define PRIiLEAST64  __PRI64 "i"
#define PRIiLEAST128 __PRI128 "i"

#define PRIiFAST8   __PRI8 "i"
#define PRIiFAST16  __PRIFAST16 "i"
#define PRIiFAST32  __PRIFAST32 "i"
#define PRIiFAST64  __PRI64 "i"
#define PRIiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » octal                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIo8   __PRI8 "o"
#define PRIo16  __PRI16 "o"
#define PRIo32  __PRI32 "o"
#define PRIo64  __PRI64 "o"
#define PRIo128 __PRI128 "o"

#define PRIoLEAST8   __PRI8 "o"
#define PRIoLEAST16  __PRI16 "o"
#define PRIoLEAST32  __PRI32 "o"
#define PRIoLEAST64  __PRI64 "o"
#define PRIoLEAST128 __PRI128 "o"

#define PRIoFAST8   __PRI8 "o"
#define PRIoFAST16  __PRIFAST16 "o"
#define PRIoFAST32  __PRIFAST32 "o"
#define PRIoFAST64  __PRI64 "o"
#define PRIoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » hexadecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIx8   __PRI8 "x"
#define PRIx16  __PRI16 "x"
#define PRIx32  __PRI32 "x"
#define PRIx64  __PRI64 "x"
#define PRIx128 __PRI128 "x"

#define PRIxLEAST8   __PRI8 "x"
#define PRIxLEAST16  __PRI16 "x"
#define PRIxLEAST32  __PRI32 "x"
#define PRIxLEAST64  __PRI64 "x"
#define PRIxLEAST128 __PRI128 "x"

#define PRIxFAST8   __PRI8 "x"
#define PRIxFAST16  __PRIFAST16 "x"
#define PRIxFAST32  __PRIFAST32 "x"
#define PRIxFAST64  __PRI64 "x"
#define PRIxFAST128 __PRI128 "x"

#define PRIX8   __PRI8 "X"
#define PRIX16  __PRI16 "X"
#define PRIX32  __PRI32 "X"
#define PRIX64  __PRI64 "X"
#define PRIX128 __PRI128 "X"

#define PRIXLEAST8   __PRI8 "X"
#define PRIXLEAST16  __PRI16 "X"
#define PRIXLEAST32  __PRI32 "X"
#define PRIXLEAST64  __PRI64 "X"
#define PRIXLEAST128 __PRI128 "X"

#define PRIXFAST8   __PRI8 "X"
#define PRIXFAST16  __PRIFAST16 "X"
#define PRIXFAST32  __PRIFAST32 "X"
#define PRIXFAST64  __PRI64 "X"
#define PRIXFAST128 __PRI128 "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » binary                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIb8   __PRI8 "b"
#define PRIb16  __PRI16 "b"
#define PRIb32  __PRI32 "b"
#define PRIb64  __PRI64 "b"
#define PRIb128 __PRI128 "b"

#define PRIbLEAST8   __PRI8 "b"
#define PRIbLEAST16  __PRI16 "b"
#define PRIbLEAST32  __PRI32 "b"
#define PRIbLEAST64  __PRI64 "b"
#define PRIbLEAST128 __PRI128 "b"

#define PRIbFAST8   __PRI8 "b"
#define PRIbFAST16  __PRIFAST16 "b"
#define PRIbFAST32  __PRIFAST32 "b"
#define PRIbFAST64  __PRI64 "b"
#define PRIbFAST128 __PRI128 "b"

#define PRIB8   __PRI8 "B"
#define PRIB16  __PRI16 "B"
#define PRIB32  __PRI32 "B"
#define PRIB64  __PRI64 "B"
#define PRIB128 __PRI128 "B"

#define PRIBLEAST8   __PRI8 "B"
#define PRIBLEAST16  __PRI16 "B"
#define PRIBLEAST32  __PRI32 "B"
#define PRIBLEAST64  __PRI64 "B"
#define PRIBLEAST128 __PRI128 "B"

#define PRIBFAST8   __PRI8 "B"
#define PRIBFAST16  __PRIFAST16 "B"
#define PRIBFAST32  __PRIFAST32 "B"
#define PRIBFAST64  __PRI64 "B"
#define PRIBFAST128 __PRI128 "B"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » miscellaneous           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIdMAX "jd"
#define PRIiMAX "ji"
#define PRIoMAX "jo"
#define PRIuMAX "ju"
#define PRIxMAX "jx"
#define PRIXMAX "jX"

#define PRIdPTR __PRIPTR "d"
#define PRIiPTR __PRIPTR "i"
#define PRIoPTR __PRIPTR "o"
#define PRIuPTR __PRIPTR "u"
#define PRIxPTR __PRIPTR "x"
#define PRIXPTR __PRIPTR "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » decimal                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNd8   __PRI8 "d"
#define SCNd16  __PRI16 "d"
#define SCNd32  __PRI32 "d"
#define SCNd64  __PRI64 "d"
#define SCNd128 __PRI128 "d"

#define SCNdLEAST8   __PRI8 "d"
#define SCNdLEAST16  __PRI16 "d"
#define SCNdLEAST32  __PRI32 "d"
#define SCNdLEAST64  __PRI64 "d"
#define SCNdLEAST128 __PRI128 "d"

#define SCNdFAST8   __PRI8 "d"
#define SCNdFAST16  __PRIFAST16 "d"
#define SCNdFAST32  __PRIFAST32 "d"
#define SCNdFAST64  __PRI64 "d"
#define SCNdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » flexidecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNi8   __PRI8 "i"
#define SCNi16  __PRI16 "i"
#define SCNi32  __PRI32 "i"
#define SCNi64  __PRI64 "i"
#define SCNi128 __PRI128 "i"

#define SCNiLEAST8   __PRI8 "i"
#define SCNiLEAST16  __PRI16 "i"
#define SCNiLEAST32  __PRI32 "i"
#define SCNiLEAST64  __PRI64 "i"
#define SCNiLEAST128 __PRI128 "i"

#define SCNiFAST8   __PRI8 "i"
#define SCNiFAST16  __PRIFAST16 "i"
#define SCNiFAST32  __PRIFAST32 "i"
#define SCNiFAST64  __PRI64 "i"
#define SCNiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » unsigned decimal         ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNu8   __PRI8 "u"
#define SCNu16  __PRI16 "u"
#define SCNu32  __PRI32 "u"
#define SCNu64  __PRI64 "u"
#define SCNu128 __PRI128 "u"

#define SCNuLEAST8   __PRI8 "u"
#define SCNuLEAST16  __PRI16 "u"
#define SCNuLEAST32  __PRI32 "u"
#define SCNuLEAST64  __PRI64 "u"
#define SCNuLEAST128 __PRI128 "u"

#define SCNuFAST8   __PRI8 "u"
#define SCNuFAST16  __PRIFAST16 "u"
#define SCNuFAST32  __PRIFAST32 "u"
#define SCNuFAST64  __PRI64 "u"
#define SCNuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » octal                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNo8   __PRI8 "o"
#define SCNo16  __PRI16 "o"
#define SCNo32  __PRI32 "o"
#define SCNo64  __PRI64 "o"
#define SCNo128 __PRI128 "o"

#define SCNoLEAST8   __PRI8 "o"
#define SCNoLEAST16  __PRI16 "o"
#define SCNoLEAST32  __PRI32 "o"
#define SCNoLEAST64  __PRI64 "o"
#define SCNoLEAST128 __PRI128 "o"

#define SCNoFAST8   __PRI8 "o"
#define SCNoFAST16  __PRIFAST16 "o"
#define SCNoFAST32  __PRIFAST32 "o"
#define SCNoFAST64  __PRI64 "o"
#define SCNoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » hexadecimal              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNx8   __PRI8 "x"
#define SCNx16  __PRI16 "x"
#define SCNx32  __PRI32 "x"
#define SCNx64  __PRI64 "x"
#define SCNx128 __PRI128 "x"

#define SCNxLEAST8   __PRI8 "x"
#define SCNxLEAST16  __PRI16 "x"
#define SCNxLEAST32  __PRI32 "x"
#define SCNxLEAST64  __PRI64 "x"
#define SCNxLEAST128 __PRI128 "x"

#define SCNxFAST8   __PRI8 "x"
#define SCNxFAST16  __PRIFAST16 "x"
#define SCNxFAST32  __PRIFAST32 "x"
#define SCNxFAST64  __PRI64 "x"
#define SCNxFAST128 __PRI128 "x"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » binary                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNb8   __PRI8 "b"
#define SCNb16  __PRI16 "b"
#define SCNb32  __PRI32 "b"
#define SCNb64  __PRI64 "b"
#define SCNb128 __PRI128 "b"

#define SCNbLEAST8   __PRI8 "b"
#define SCNbLEAST16  __PRI16 "b"
#define SCNbLEAST32  __PRI32 "b"
#define SCNbLEAST64  __PRI64 "b"
#define SCNbLEAST128 __PRI128 "b"

#define SCNbFAST8   __PRI8 "b"
#define SCNbFAST16  __PRIFAST16 "b"
#define SCNbFAST32  __PRIFAST32 "b"
#define SCNbFAST64  __PRI64 "b"
#define SCNbFAST128 __PRI128 "b"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » miscellaneous            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNdMAX "jd"
#define SCNiMAX "ji"
#define SCNoMAX "jo"
#define SCNuMAX "ju"
#define SCNxMAX "jx"

#define SCNdPTR __PRIPTR "d"
#define SCNiPTR __PRIPTR "i"
#define SCNoPTR __PRIPTR "o"
#define SCNuPTR __PRIPTR "u"
#define SCNxPTR __PRIPTR "x"



/*!BEGIN libc/limits.h */

#define COSMOPOLITAN_LIBC_LIMITS_H_
#define __STDC_LIMIT_MACROS

#define CHAR_BIT 8
#define PATH_MAX 1024
#define NAME_MAX 255
#define ARG_MAX  131074

#define UCHAR_MIN 0
#define UCHAR_MAX 255

#if '\200' < 0
#define CHAR_MIN '\200'
#define CHAR_MAX '\177'
#else
#define CHAR_MIN '\0'
#define CHAR_MAX '\377'
#endif

#define SCHAR_MAX     __SCHAR_MAX__
#define SHRT_MAX      __SHRT_MAX__
#define INT_MAX       __INT_MAX__
#define LONG_MAX      __LONG_MAX__
#define LLONG_MAX     LONG_LONG_MAX
#define LONG_LONG_MAX __LONG_LONG_MAX__
#define SIZE_MAX      __SIZE_MAX__
#define INT8_MAX      __INT8_MAX__
#define INT16_MAX     __INT16_MAX__
#define INT32_MAX     __INT32_MAX__
#define INT64_MAX     __INT64_MAX__
#define WINT_MAX      __WINT_MAX__
#define WCHAR_MAX     __WCHAR_MAX__
#define INTPTR_MAX    __INTPTR_MAX__
#define PTRDIFF_MAX   __PTRDIFF_MAX__
#define UINTPTR_MAX   __UINTPTR_MAX__
#define UINT8_MAX     __UINT8_MAX__
#define UINT16_MAX    __UINT16_MAX__
#define UINT32_MAX    __UINT32_MAX__
#define UINT64_MAX    __UINT64_MAX__
#define INTMAX_MAX    __INTMAX_MAX__
#define UINTMAX_MAX   __UINTMAX_MAX__
#define SSIZE_MAX     __INT64_MAX__

#define SCHAR_MIN     (-SCHAR_MAX - 1)
#define SHRT_MIN      (-SHRT_MAX - 1)
#define INT_MIN       (-INT_MAX - 1)
#define LONG_MIN      (-LONG_MAX - 1)
#define LLONG_MIN     (-LLONG_MAX - 1)
#define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
#define SIZE_MIN      (-SIZE_MAX - 1)
#define INT8_MIN      (-INT8_MAX - 1)
#define INT16_MIN     (-INT16_MAX - 1)
#define INT32_MIN     (-INT32_MAX - 1)
#define INT64_MIN     (-INT64_MAX - 1)
#define INTMAX_MIN    (-INTMAX_MAX - 1)
#define INTPTR_MIN    (-INTPTR_MAX - 1)
#define WINT_MIN      __WINT_MIN__
#define WCHAR_MIN     (-WCHAR_MAX - 1)
#define PTRDIFF_MIN   (-PTRDIFF_MAX - 1)

#define USHRT_MAX 65535
#define UINT_MAX  0xffffffffu
#if __SIZEOF_LONG__ == 8
#define ULONG_MAX 0xfffffffffffffffful
#else
#define ULONG_MAX 0xfffffffful
#endif
#define ULLONG_MAX     0xffffffffffffffffull
#define ULONG_LONG_MAX 0xffffffffffffffffull

#define USHRT_MIN      0
#define UINT_MIN       0u
#define ULONG_MIN      0ul
#define ULLONG_MIN     0ull
#define ULONG_LONG_MIN 0ull
#define UINT8_MIN      0
#define UINT16_MIN     0
#define UINT32_MIN     0u
#define UINT64_MIN     0ull
#define UINTPTR_MIN    0ull
#define UINTMAX_MIN    ((uintmax_t)0)

#define MB_CUR_MAX 4
#define MB_LEN_MAX 4

#ifdef _COSMO_SOURCE
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 406 || defined(__llvm__)
#define INT128_MIN  (-INT128_MAX - 1)
#define UINT128_MIN ((uint128_t)0)
#define INT128_MAX \
  ((int128_t)0x7fffffffffffffff << 64 | (int128_t)0xffffffffffffffff)
#define UINT128_MAX \
  ((uint128_t)0xffffffffffffffff << 64 | (uint128_t)0xffffffffffffffff)
#endif /* GCC 4.6+ */
#endif /* _COSMO_SOURCE */

#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX

#define FILESIZEBITS   64
#define SYMLOOP_MAX    40
#define TTY_NAME_MAX   32
#define HOST_NAME_MAX  255
#define TZNAME_MAX     6
#define WORD_BIT       32
#define SEM_VALUE_MAX  0x7fffffff
#define SEM_NSEMS_MAX  256
#define DELAYTIMER_MAX 0x7fffffff
#define MQ_PRIO_MAX    32768
#define LOGIN_NAME_MAX 256

#define NL_ARGMAX  9
#define NL_MSGMAX  32767
#define NL_SETMAX  255
#define NL_TEXTMAX 2048

#define INT_FAST8_MIN    (-__INT_FAST8_MAX__ - 1)
#define INT_FAST16_MIN   (-__INT_FAST16_MAX__ - 1)
#define INT_FAST32_MIN   (-__INT_FAST32_MAX__ - 1)
#define INT_FAST64_MIN   (-__INT_FAST64_MAX__ - 1)
#define INT_LEAST8_MIN   (-__INT_LEAST8_MAX__ - 1)
#define INT_LEAST16_MIN  (-__INT_LEAST16_MAX__ - 1)
#define INT_LEAST32_MIN  (-__INT_LEAST32_MAX__ - 1)
#define INT_LEAST64_MIN  (-__INT_LEAST64_MAX__ - 1)
#define INT_FAST8_MAX    __INT_FAST8_MAX__
#define INT_FAST16_MAX   __INT_FAST16_MAX__
#define INT_FAST32_MAX   __INT_FAST32_MAX__
#define INT_FAST64_MAX   __INT_FAST64_MAX__
#define INT_LEAST8_MAX   __INT_LEAST8_MAX__
#define INT_LEAST16_MAX  __INT_LEAST16_MAX__
#define INT_LEAST32_MAX  __INT_LEAST32_MAX__
#define INT_LEAST64_MAX  __INT_LEAST64_MAX__
#define UINT_FAST8_MAX   __UINT_FAST8_MAX__
#define UINT_FAST16_MAX  __UINT_FAST16_MAX__
#define UINT_FAST32_MAX  __UINT_FAST32_MAX__
#define UINT_FAST64_MAX  __UINT_FAST64_MAX__
#define UINT_LEAST8_MAX  __UINT_LEAST8_MAX__
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__

#define BC_BASE_MAX        99
#define BC_DIM_MAX         2048
#define BC_SCALE_MAX       99
#define BC_STRING_MAX      1000
#define CHARCLASS_NAME_MAX 14
#define COLL_WEIGHTS_MAX   2
#define EXPR_NEST_MAX      32
#define LINE_MAX           4096
#define RE_DUP_MAX         255
#define LONG_BIT           64
#define NZERO              20
#define NL_LANGMAX         32



/*!BEGIN libc/literal.h */

#define COSMOPOLITAN_LIBC_LITERAL_H_
#define __STDC_CONSTANT_MACROS

#ifdef __INT8_C
#define INT8_C(c)   __INT8_C(c)
#define UINT8_C(c)  __UINT8_C(c)
#define INT16_C(c)  __INT16_C(c)
#define UINT16_C(c) __UINT16_C(c)
#define INT32_C(c)  __INT32_C(c)
#define UINT32_C(c) __UINT32_C(c)
#define INT64_C(c)  __INT64_C(c)
#define UINT64_C(c) __UINT64_C(c)
#else
#define INT8_C(c)   c
#define UINT8_C(c)  c
#define INT16_C(c)  c
#define UINT16_C(c) c
#define INT32_C(c)  c
#define UINT32_C(c) c##U
#define INT64_C(c)  c##L
#define UINT64_C(c) c##UL
#endif

#if UINTPTR_MAX == UINT64_MAX
#define INTMAX_C(c)  c##L
#define UINTMAX_C(c) c##UL
#else
#define INTMAX_C(c)  c##LL
#define UINTMAX_C(c) c##ULL
#endif



/*!BEGIN libc/math.h */

#define COSMOPOLITAN_LIBC_MATH_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § mathematics                                                   │
╚─────────────────────────────────────────────────────────────────────────────*/

#define M_E        2.7182818284590452354  /* 𝑒 */
#define M_LOG2E    1.4426950408889634074  /* log₂𝑒 */
#define M_LOG10E   0.43429448190325182765 /* log₁₀𝑒 */
#define M_LN2      0.69314718055994530942 /* logₑ2 */
#define M_LN10     2.30258509299404568402 /* logₑ10 */
#define M_PI       3.14159265358979323846 /* 𝜋 */
#define M_PI_2     1.57079632679489661923 /* 𝜋/2 */
#define M_PI_4     0.78539816339744830962 /* 𝜋/4 */
#define M_1_PI     0.31830988618379067154 /* 1/𝜋 */
#define M_2_PI     0.63661977236758134308 /* 2/𝜋 */
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(𝜋) */
#define M_SQRT2    1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2  0.70710678118654752440 /* 1/sqrt(2) */

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_Ef        2.7182818284590452354f  /* 𝑒 */
#define M_LOG2Ef    1.4426950408889634074f  /* log₂𝑒 */
#define M_LOG10Ef   0.43429448190325182765f /* log₁₀𝑒 */
#define M_LN2f      0.69314718055994530942f /* logₑ2 */
#define M_LN10f     2.30258509299404568402f /* logₑ10 */
#define M_PIf       3.14159265358979323846f /* 𝜋 */
#define M_PI_2f     1.57079632679489661923f /* 𝜋/2 */
#define M_PI_4f     0.78539816339744830962f /* 𝜋/4 */
#define M_1_PIf     0.31830988618379067154f /* 1/𝜋 */
#define M_2_PIf     0.63661977236758134308f /* 2/𝜋 */
#define M_2_SQRTPIf 1.12837916709551257390f /* 2/sqrt(𝜋) */
#define M_SQRT2f    1.41421356237309504880f /* sqrt(2) */
#define M_SQRT1_2f  0.70710678118654752440f /* 1/sqrt(2) */
#endif

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_El        2.718281828459045235360287471352662498L /* 𝑒 */
#define M_LOG2El    1.442695040888963407359924681001892137L /* log₂𝑒 */
#define M_LOG10El   0.434294481903251827651128918916605082L /* log₁₀𝑒 */
#define M_LN2l      0.693147180559945309417232121458176568L /* logₑ2 */
#define M_LN10l     2.302585092994045684017991454684364208L /* logₑ10 */
#define M_PIl       3.141592653589793238462643383279502884L /* 𝜋 */
#define M_PI_2l     1.570796326794896619231321691639751442L /* 𝜋/2 */
#define M_PI_4l     0.785398163397448309615660845819875721L /* 𝜋/4 */
#define M_1_PIl     0.318309886183790671537767526745028724L /* 1/𝜋 */
#define M_2_PIl     0.636619772367581343075535053490057448L /* 2/𝜋 */
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(𝜋) */
#define M_SQRT2l    1.414213562373095048801688724209698079L /* sqrt(2) */
#define M_SQRT1_2l  0.707106781186547524400844362104849039L /* 1/sqrt(2) */
#endif

#define DBL_DECIMAL_DIG   __DBL_DECIMAL_DIG__
#define DBL_DIG           __DBL_DIG__
#define DBL_EPSILON       __DBL_EPSILON__
#define DBL_HAS_SUBNORM   __DBL_HAS_DENORM__
#define DBL_IS_IEC_60559  __DBL_IS_IEC_60559__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MAX           __DBL_MAX__
#define DBL_MAX_10_EXP    __DBL_MAX_10_EXP__
#define DBL_MAX_EXP       __DBL_MAX_EXP__
#define DBL_MIN           __DBL_MIN__ /* 2.23e–308 ↔ 1.79e308 */
#define DBL_MIN_10_EXP    __DBL_MIN_10_EXP__
#define DBL_MIN_EXP       __DBL_MIN_EXP__
#define DBL_NORM_MAX      __DBL_NORM_MAX__
#define DBL_TRUE_MIN      __DBL_DENORM_MIN__
#define DECIMAL_DIG       __LDBL_DECIMAL_DIG__
#define FLT_DECIMAL_DIG   __FLT_DECIMAL_DIG__
#define FLT_DIG           __FLT_DIG__
#define FLT_EPSILON       __FLT_EPSILON__
#define FLT_HAS_SUBNORM   __FLT_HAS_DENORM__
#define FLT_IS_IEC_60559  __FLT_IS_IEC_60559__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MAX           __FLT_MAX__
#define FLT_MAX_10_EXP    __FLT_MAX_10_EXP__
#define FLT_MAX_EXP       __FLT_MAX_EXP__
#define FLT_MIN           __FLT_MIN__ /* 1.18e–38 ↔ 3.40e38 */
#define FLT_MIN_10_EXP    __FLT_MIN_10_EXP__
#define FLT_MIN_EXP       __FLT_MIN_EXP__
#define FLT_NORM_MAX      __FLT_NORM_MAX__
#define FLT_RADIX         __FLT_RADIX__
#define FLT_TRUE_MIN      __FLT_DENORM_MIN__
#define HLF_MAX           6.50e4f
#define HLF_MIN           3.10e-5f
#define LDBL_DECIMAL_DIG  __LDBL_DECIMAL_DIG__
#define LDBL_DIG          __LDBL_DIG__
#define LDBL_EPSILON      __LDBL_EPSILON__
#define LDBL_HAS_SUBNORM  __LDBL_HAS_DENORM__
#define LDBL_IS_IEC_60559 __LDBL_IS_IEC_60559__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MAX          __LDBL_MAX__
#define LDBL_MAX_10_EXP   __LDBL_MAX_10_EXP__
#define LDBL_MAX_EXP      __LDBL_MAX_EXP__
#define LDBL_MIN          __LDBL_MIN__ /* 3.37e–4932 ↔ 1.18e4932 */
#define LDBL_MIN_10_EXP   __LDBL_MIN_10_EXP__
#define LDBL_MIN_EXP      __LDBL_MIN_EXP__
#define LDBL_NORM_MAX     __LDBL_NORM_MAX__
#define LDBL_TRUE_MIN     __LDBL_DENORM_MIN__

#define FP_NAN       0
#define FP_INFINITE  1
#define FP_ZERO      2
#define FP_SUBNORMAL 3
#define FP_NORMAL    4
#define FP_ILOGB0    (-2147483647 - 1)
#define FP_ILOGBNAN  (-2147483647 - 1)

#define MATH_ERRNO     1
#define MATH_ERREXCEPT 2

#ifdef __FAST_MATH__
#define math_errhandling 0
#elif defined(__NO_MATH_ERRNO__)
#define math_errhandling (MATH_ERREXCEPT)
#else
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
#endif

#ifdef __FP_FAST_FMA
#define FP_FAST_FMA 1
#endif
#ifdef __FP_FAST_FMAF
#define FP_FAST_FMAF 1
#endif
#ifdef __FP_FAST_FMAL
#define FP_FAST_FMAL 1
#endif

COSMOPOLITAN_C_START_

#define NAN       __builtin_nanf("")
#define INFINITY  __builtin_inff()
#define HUGE_VAL  __builtin_inf()
#define HUGE_VALF __builtin_inff()
#define HUGE_VALL __builtin_infl()

#if __FLT_EVAL_METHOD__ + 0 == 2
typedef long double float_t;
typedef long double double_t;
#else
typedef float float_t;
typedef double double_t;
#endif

#define isinf(x)             __builtin_isinf(x)
#define isnan(x)             __builtin_isnan(x)
#define isfinite(x)          __builtin_isfinite(x)
#define isnormal(x)          __builtin_isnormal(x)
#define isgreater(x, y)      __builtin_isgreater(x, y)
#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
#define isless(x, y)         __builtin_isless(x, y)
#define islessequal(x, y)    __builtin_islessequal(x, y)
#define islessgreater(x, y)  __builtin_islessgreater(x, y)
#define isunordered(x, y)    __builtin_isunordered(x, y)

#define fpclassify(x) \
  __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)

#define signbit(x)                                          \
  (sizeof(x) == sizeof(long double) ? __builtin_signbitl(x) \
   : sizeof(x) == sizeof(float)     ? __builtin_signbitf(x) \
                                    : __builtin_signbit(x))

extern int signgam;

double acos(double) libcesque;
double acosh(double) libcesque;
double asin(double) libcesque;
double asinh(double) libcesque;
double atan(double) libcesque;
double atan2(double, double) libcesque;
double atanh(double) libcesque;
double cbrt(double) libcesque;
double ceil(double) libcesque;
double copysign(double, double) libcesque;
double cos(double) libcesque;
double cosh(double) libcesque;
double drem(double, double) libcesque;
double erf(double) libcesque;
double erfc(double) libcesque;
double exp(double) libcesque;
double exp10(double) libcesque;
double exp2(double) libcesque;
double expm1(double) libcesque;
double fabs(double) libcesque;
double fdim(double, double) libcesque;
double floor(double) libcesque;
double fma(double, double, double) libcesque;
double fmax(double, double) libcesque;
double fmin(double, double) libcesque;
double fmod(double, double) libcesque;
double hypot(double, double) libcesque;
double ldexp(double, int) libcesque;
double log(double) libcesque;
double log10(double) libcesque;
double log1p(double) libcesque;
double log2(double) libcesque;
double logb(double) libcesque;
double nearbyint(double) libcesque;
double nextafter(double, double) libcesque;
double nexttoward(double, long double) libcesque;
double pow(double, double) libcesque;
double pow10(double) libcesque;
double powi(double, int) libcesque;
double remainder(double, double) libcesque;
double rint(double) libcesque;
double round(double) libcesque;
double scalb(double, double) libcesque;
double scalbln(double, long int) libcesque;
double scalbn(double, int) libcesque;
double significand(double) libcesque;
double sin(double) libcesque;
double sinh(double) libcesque;
double sqrt(double) libcesque;
double tan(double) libcesque;
double tanh(double) libcesque;
double trunc(double) libcesque;
double tgamma(double) libcesque;
double lgamma(double) libcesque;
double lgamma_r(double, int *) libcesque;
int finite(double) libcesque;

float acosf(float) libcesque;
float acoshf(float) libcesque;
float asinf(float) libcesque;
float asinhf(float) libcesque;
float atan2f(float, float) libcesque;
float atanf(float) libcesque;
float atanhf(float) libcesque;
float cbrtf(float) libcesque;
float ceilf(float) libcesque;
float copysignf(float, float) libcesque;
float cosf(float) libcesque;
float coshf(float) libcesque;
float dremf(float, float) libcesque;
float erfcf(float) libcesque;
float erff(float) libcesque;
float exp10f(float) libcesque;
float exp2f(float) libcesque;
float expf(float) libcesque;
float expm1f(float) libcesque;
float fabsf(float) libcesque;
float fdimf(float, float) libcesque;
float floorf(float) libcesque;
float fmaf(float, float, float) libcesque;
float fmaxf(float, float) libcesque;
float fminf(float, float) libcesque;
float fmodf(float, float) libcesque;
float hypotf(float, float) libcesque;
float ldexpf(float, int) libcesque;
float lgammaf(float) libcesque;
float lgammaf_r(float, int *) libcesque;
float log10f(float) libcesque;
float log1pf(float) libcesque;
float log2f(float) libcesque;
float logbf(float) libcesque;
float logf(float) libcesque;
float nearbyintf(float) libcesque;
float nextafterf(float, float) libcesque;
float nexttowardf(float, long double) libcesque;
float pow10f(float) libcesque;
float powf(float, float) libcesque;
float powif(float, int) libcesque;
float remainderf(float, float) libcesque;
float rintf(float) libcesque;
float roundf(float) libcesque;
float scalbf(float, float) libcesque;
float scalblnf(float, long int) libcesque;
float scalbnf(float, int) libcesque;
float significandf(float) libcesque;
float sinf(float) libcesque;
float sinhf(float) libcesque;
float sqrtf(float) libcesque;
float tanf(float) libcesque;
float tanhf(float) libcesque;
float tgammaf(float) libcesque;
float truncf(float) libcesque;
int finitef(float) libcesque;

int finitel(long double) libcesque;
long double acoshl(long double) libcesque;
long double acosl(long double) libcesque;
long double asinhl(long double) libcesque;
long double asinl(long double) libcesque;
long double atan2l(long double, long double) libcesque;
long double atanhl(long double) libcesque;
long double atanl(long double) libcesque;
long double cbrtl(long double) libcesque;
long double ceill(long double) libcesque;
long double copysignl(long double, long double) libcesque;
long double coshl(long double) libcesque;
long double cosl(long double) libcesque;
long double dreml(long double, long double) libcesque;
long double erfcl(long double) libcesque;
long double erfl(long double) libcesque;
long double exp10l(long double) libcesque;
long double exp2l(long double) libcesque;
long double expl(long double) libcesque;
long double expm1l(long double) libcesque;
long double fabsl(long double) libcesque;
long double fdiml(long double, long double) libcesque;
long double floorl(long double) libcesque;
long double fmal(long double, long double, long double) libcesque;
long double fmaxl(long double, long double) libcesque;
long double fminl(long double, long double) libcesque;
long double fmodl(long double, long double) libcesque;
long double hypotl(long double, long double) libcesque;
long double ldexpl(long double, int) libcesque;
long double lgammal(long double) libcesque;
long double lgammal_r(long double, int *) libcesque;
long double log10l(long double) libcesque;
long double log1pl(long double) libcesque;
long double log2l(long double) libcesque;
long double logbl(long double) libcesque;
long double logl(long double) libcesque;
long double nearbyintl(long double) libcesque;
long double nextafterl(long double, long double) libcesque;
long double nexttowardl(long double, long double) libcesque;
long double pow10l(long double) libcesque;
long double powl(long double, long double) libcesque;
long double remainderl(long double, long double) libcesque;
long double rintl(long double) libcesque;
long double roundl(long double) libcesque;
long double scalbl(long double, long double) libcesque;
long double scalblnl(long double, long int) libcesque;
long double scalbnl(long double, int) libcesque;
long double significandl(long double) libcesque;
long double sinhl(long double) libcesque;
long double sinl(long double) libcesque;
long double sqrtl(long double) libcesque;
long double tanhl(long double) libcesque;
long double tanl(long double) libcesque;
long double tgammal(long double) libcesque;
long double truncl(long double) libcesque;

long lrint(double) libcesque;
long lrintf(float) libcesque;
long lrintl(long double) libcesque;
long lround(double) libcesque;
long lroundf(float) libcesque;
long lroundl(long double) libcesque;

int ilogbf(float) libcesque;
int ilogb(double) libcesque;
int ilogbl(long double) libcesque;

long long llrint(double) libcesque;
long long llrintf(float) libcesque;
long long llrintl(long double) libcesque;
long long llround(double) libcesque;
long long llroundf(float) libcesque;
long long llroundl(long double) libcesque;

double frexp(double, int *) libcesque;
double modf(double, double *) libcesque;
double nan(const char *) libcesque;
double remquo(double, double, int *) libcesque;
float frexpf(float, int *) libcesque;
float modff(float, float *) libcesque;
float nanf(const char *) libcesque;
float remquof(float, float, int *) libcesque;
long double frexpl(long double, int *) libcesque;
long double modfl(long double, long double *) libcesque;
long double nanl(const char *) libcesque;
long double remquol(long double, long double, int *) libcesque;
void sincos(double, double *, double *) libcesque;
void sincosf(float, float *, float *) libcesque;
void sincosl(long double, long double *, long double *) libcesque;

double fsumf(const float *, size_t) libcesque;
double fsum(const double *, size_t) libcesque;

double j0(double) libcesque;
double j1(double) libcesque;
double jn(int, double) libcesque;
float j0f(float) libcesque;
float j1f(float) libcesque;
float jnf(int, float) libcesque;

double y0(double) libcesque;
double y1(double) libcesque;
double yn(int, double) libcesque;
float y0f(float) libcesque;
float y1f(float) libcesque;
float ynf(int, float) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/paths.h */

#define COSMOPOLITAN_LIBC_PATHS_H_

#define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin"
#define _PATH_STDPATH "/bin:/usr/bin:/sbin:/usr/sbin"

#define _PATH_BSHELL   "/bin/sh"
#define _PATH_CONSOLE  "/dev/console"
#define _PATH_DEVNULL  "/dev/null"
#define _PATH_KLOG     "/proc/kmsg"
#define _PATH_LASTLOG  "/var/log/lastlog"
#define _PATH_MAILDIR  "/var/mail"
#define _PATH_MAN      "/usr/share/man"
#define _PATH_MNTTAB   "/etc/fstab"
#define _PATH_MOUNTED  "/etc/mtab"
#define _PATH_NOLOGIN  "/etc/nologin"
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
#define _PATH_SHADOW   "/etc/shadow"
#define _PATH_SHELLS   "/etc/shells"
#define _PATH_TTY      "/dev/tty"
#define _PATH_UTMP     "/dev/null/utmp"
#define _PATH_VI       "/usr/bin/vi"
#define _PATH_WTMP     "/dev/null/wtmp"

#define _PATH_DEV    "/dev/"
#define _PATH_TMP    "/tmp/"
#define _PATH_VARDB  "/var/lib/misc/"
#define _PATH_VARRUN "/var/run/"
#define _PATH_VARTMP "/var/tmp/"



/*!BEGIN libc/serialize.h */

#define COSMOPOLITAN_SERIALIZE_H_
#ifdef _COSMO_SOURCE

#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define __SWAPBE16(x) (x)
#define __SWAPBE32(x) (x)
#define __SWAPBE64(x) (x)
#else
#define __SWAPBE16(x) __builtin_bswap16(x)
#define __SWAPBE32(x) __builtin_bswap32(x)
#define __SWAPBE64(x) __builtin_bswap64(x)
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __SWAPLE16(x) (x)
#define __SWAPLE32(x) (x)
#define __SWAPLE64(x) (x)
#else
#define __SWAPLE16(x) __builtin_bswap16(x)
#define __SWAPLE32(x) __builtin_bswap32(x)
#define __SWAPLE64(x) __builtin_bswap64(x)
#endif

#define READ16LE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPLE16(__x);                   \
  }))

#define READ16BE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPBE16(__x);                   \
  }))

#define READ32LE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ32BE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPBE32(__x);                   \
  }))

#define READ64LE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ64BE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPBE64(__x);                   \
  }))

#define WRITE16LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPLE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE16BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPBE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE32LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPLE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE32BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPBE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE64LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPLE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#define WRITE64BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPBE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/stdckdint.h */

#define COSMOPOLITAN_LIBC_STDCKDINT_H_
/* clang-format off */

/**
 * @fileoverview C23 Checked Arithmetic
 *
 * This header defines three type generic functions:
 *
 *   - `bool ckd_add(res, a, b)`
 *   - `bool ckd_sub(res, a, b)`
 *   - `bool ckd_mul(res, a, b)`
 *
 * Which allow integer arithmetic errors to be detected. There are many
 * kinds of integer errors, e.g. overflow, truncation, etc. These funcs
 * catch them all. Here's an example of how it works:
 *
 *     uint32_t c;
 *     int32_t a = 0x7fffffff;
 *     int32_t b = 2;
 *     assert(!ckd_add(&c, a, b));
 *     assert(c == 0x80000001u);
 *
 * Experienced C / C++ users should find this example counter-intuitive
 * because the expression `0x7fffffff + 2` not only overflows it's also
 * undefined behavior. However here we see it's specified, and does not
 * result in an error. That's because C23 checked arithmetic is not the
 * arithmetic you're used to. The new standard changes the mathematics.
 *
 * C23 checked arithmetic is defined as performing the arithmetic using
 * infinite precision and then checking if the resulting value will fit
 * in the output type. Our example above did not result in an error due
 * to `0x80000001` being a legal value for `uint32_t`.
 *
 * This implementation will use the GNU compiler builtins, when they're
 * available, only if you don't use build flags like `-std=c11` because
 * they define `__STRICT_ANSI__` and GCC extensions aren't really ANSI.
 * Instead, you'll get a pretty good pure C11 and C++11 implementation.
 *
 * @see https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
 * @version 0.1 (2023-07-22)
 */

#define __STDC_VERSION_STDCKDINT_H__ 202311L

#if ((defined(__llvm__) ||                                              \
      (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406)) && \
     !defined(__STRICT_ANSI__))
#define __ckd_have_int128
#define __ckd_intmax __int128
#elif ((defined(__cplusplus) && __cplusplus >= 201103L) ||              \
       (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L))
#define __ckd_intmax long long
#else
#define __ckd_intmax long
#endif

typedef signed __ckd_intmax __ckd_intmax_t;
typedef unsigned __ckd_intmax __ckd_uintmax_t;

#if (!defined(__STRICT_ANSI__) &&                       \
     ((defined(__GNUC__) && __GNUC__ >= 5 &&            \
       !defined(__chibicc__) && !defined(__ICC)) ||     \
      (__has_builtin(__builtin_add_overflow) &&         \
       __has_builtin(__builtin_sub_overflow) &&         \
       __has_builtin(__builtin_mul_overflow))))
#define ckd_add(res, x, y) __builtin_add_overflow((x), (y), (res))
#define ckd_sub(res, x, y) __builtin_sub_overflow((x), (y), (res))
#define ckd_mul(res, x, y) __builtin_mul_overflow((x), (y), (res))

#elif defined(__cplusplus) && __cplusplus >= 201103L

template <typename __T, typename __U, typename __V>
inline bool ckd_add(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x + __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u + u
      return __truncated | (__z < __x);
    case 1:  // u = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 2:  // u = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 3:  // u = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z | __x) &  __y) |
                                       ((__z & __x) & ~__y)) < 0);
    case 4:  // s = u + u
      return __truncated | (__z < __x) | (static_cast<__ckd_intmax_t>(__z) < 0);
    case 5:  // s = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __y);
    case 6:  // s = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __x);
    case 7:  // s = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_sub(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x - __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u - u
      return __truncated | (__x < __y);
    case 1:  // u = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    case 2:  // u = s - u
      return __truncated | (__y > __x) | (static_cast<__ckd_intmax_t>(__x) < 0);
    case 3:  // u = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z & __x) &  __y) |
                                       ((__z | __x) & ~__y)) < 0);
    case 4:  // s = u - u
      return __truncated |
          ((__x < __y) ^ (static_cast<__ckd_intmax_t>(__z) < 0));
    case 5:  // s = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x >= __y);
    case 6:  // s = s - u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x < __y);
    case 7:  // s = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_mul(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  if ((sizeof(__U) * 8 - std::is_signed<__U>::value) +
      (sizeof(__V) * 8 - std::is_signed<__V>::value) <=
      (sizeof(__T) * 8 - std::is_signed<__T>::value)) {
    if (sizeof(__ckd_uintmax_t) > sizeof(__T) || std::is_signed<__T>::value) {
      __ckd_intmax_t __z = __x * __y;
      return __z != (*__res = __z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0: {  // u = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 1: {  // u = u * s
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__y) < 0) & !!__x) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 2: {  // u = s * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__x) < 0) & !!__y) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 3: { // u = s * s
      int __o = false;
      if (static_cast<__ckd_intmax_t>(__x & __y) < 0) {
        __x = -__x;
        __y = -__y;
      } else if (static_cast<__ckd_intmax_t>(__x ^ __y) < 0) {
        __o = __x && __y;
      }
      __ckd_uintmax_t __z = __x * __y;
      __o |= __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 4: {  // s = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | (static_cast<__ckd_intmax_t>(__z) < 0) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 5: {  // s = u * s
      __ckd_uintmax_t __t = -__y;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __y : __t;
      __ckd_uintmax_t __p = __t * __x;
      int __o = __t && __p / __t != __x;
      int __n = static_cast<__ckd_intmax_t>(__y) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 6: {  // s = s * u
      __ckd_uintmax_t __t = -__x;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __x : __t;
      __ckd_uintmax_t __p = __t * __y;
      int __o = __t && __p / __t != __y;
      int __n = static_cast<__ckd_intmax_t>(__x) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 7: {  // s = s * s
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return ((((static_cast<__ckd_intmax_t>(__y) < 0) &&
                (static_cast<__ckd_intmax_t>(__x) ==
                 std::numeric_limits<__ckd_intmax_t>::min())) ||
               (__y && ((static_cast<__ckd_intmax_t>(__z) /
                         static_cast<__ckd_intmax_t>(__y)) !=
                        static_cast<__ckd_intmax_t>(__x)))) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    default:
      for (;;) (void)0;
  }
}

#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L

#define ckd_add(res, a, b) __ckd_expr(add, (res), (a), (b))
#define ckd_sub(res, a, b) __ckd_expr(sub, (res), (a), (b))
#define ckd_mul(res, a, b) __ckd_expr(mul, (res), (a), (b))

#if defined(__GNUC__) || defined(__llvm__)
#define __ckd_inline                                    \
  extern __inline __attribute__((__gnu_inline__,        \
                                 __always_inline__,     \
                                 __artificial__))
#else
#define __ckd_inline static inline
#endif

#ifdef __ckd_have_int128
#define __ckd_generic_int128(x, y) , signed __int128: x, unsigned __int128: y
#else
#define __ckd_generic_int128(x, y)
#endif

#define __ckd_sign(T)                           \
  ((T)1 << (sizeof(T) * 8 - 1))

#define __ckd_is_signed(x)                      \
  _Generic(x,                                   \
           signed char: 1,                      \
           unsigned char: 0,                    \
           signed short: 1,                     \
           unsigned short: 0,                   \
           signed int: 1,                       \
           unsigned int: 0,                     \
           signed long: 1,                      \
           unsigned long: 0,                    \
           signed long long: 1,                 \
           unsigned long long: 0                \
           __ckd_generic_int128(1, 0))

#define __ckd_expr(op, res, a, b)                       \
  (_Generic(*res,                                       \
            signed char: __ckd_##op##_schar,            \
            unsigned char: __ckd_##op##_uchar,          \
            signed short: __ckd_##op##_sshort,          \
            unsigned short: __ckd_##op##_ushort,        \
            signed int: __ckd_##op##_sint,              \
            unsigned int: __ckd_##op##_uint,            \
            signed long: __ckd_##op##_slong,            \
            unsigned long: __ckd_##op##_ulong,          \
            signed long long: __ckd_##op##_slonger,     \
            unsigned long long: __ckd_##op##_ulonger    \
            __ckd_generic_int128(                       \
                __ckd_##op##_sint128,                   \
                __ckd_##op##_uint128))(                 \
                    res, a, b,                          \
                    __ckd_is_signed(a),                 \
                    __ckd_is_signed(b)))

#define __ckd_declare_add(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x + __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u + u */                                          \
        return __truncated | (__z < __x);                               \
      case 1:  /* u = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 2:  /* u = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 3:  /* u = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z | __x) &  __y) |                    \
                              ((__z & __x) & ~__y)) < 0);               \
      case 4:  /* s = u + u */                                          \
        return __truncated | (__z < __x) | ((__ckd_intmax_t)__z < 0);   \
      case 5:  /* s = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __y);                         \
      case 6:  /* s = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __x);                         \
      case 7:  /* s = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_add(__ckd_add_schar, signed char)
__ckd_declare_add(__ckd_add_uchar, unsigned char)
__ckd_declare_add(__ckd_add_sshort, signed short)
__ckd_declare_add(__ckd_add_ushort, unsigned short)
__ckd_declare_add(__ckd_add_sint, signed int)
__ckd_declare_add(__ckd_add_uint, unsigned int)
__ckd_declare_add(__ckd_add_slong, signed long)
__ckd_declare_add(__ckd_add_ulong, unsigned long)
__ckd_declare_add(__ckd_add_slonger, signed long long)
__ckd_declare_add(__ckd_add_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_add(__ckd_add_sint128, signed __int128)
__ckd_declare_add(__ckd_add_uint128, unsigned __int128)
#endif

#define __ckd_declare_sub(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x - __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u - u */                                          \
        return __truncated | (__x < __y);                               \
      case 1:  /* u = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      case 2:  /* u = s - u */                                          \
        return __truncated | (__y > __x) | ((__ckd_intmax_t)__x < 0);   \
      case 3:  /* u = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z & __x) &  __y) |                    \
                              ((__z | __x) & ~__y)) < 0);               \
      case 4:  /* s = u - u */                                          \
        return __truncated | ((__x < __y) ^ ((__ckd_intmax_t)__z < 0)); \
      case 5:  /* s = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x >= __y);                              \
      case 6:  /* s = s - u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x < __y);                               \
      case 7:  /* s = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_sub(__ckd_sub_schar, signed char)
__ckd_declare_sub(__ckd_sub_uchar, unsigned char)
__ckd_declare_sub(__ckd_sub_sshort, signed short)
__ckd_declare_sub(__ckd_sub_ushort, unsigned short)
__ckd_declare_sub(__ckd_sub_sint, signed int)
__ckd_declare_sub(__ckd_sub_uint, unsigned int)
__ckd_declare_sub(__ckd_sub_slong, signed long)
__ckd_declare_sub(__ckd_sub_ulong, unsigned long)
__ckd_declare_sub(__ckd_sub_slonger, signed long long)
__ckd_declare_sub(__ckd_sub_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_sub(__ckd_sub_sint128, signed __int128)
__ckd_declare_sub(__ckd_sub_uint128, unsigned __int128)
#endif

#define __ckd_declare_mul(S, T)                                 \
  __ckd_inline char S(void *__res,                              \
                      __ckd_uintmax_t __x,                      \
                      __ckd_uintmax_t __y,                      \
                      char __a_signed,                          \
                      char __b_signed) {                        \
    switch (__ckd_is_signed((T)0) << 2 |                        \
            __a_signed << 1 | __b_signed) {                     \
      case 0: {  /* u = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 1: {  /* u = u * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__y < 0) & !!__x) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 2: {  /* u = s * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__x < 0) & !!__y) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 3: {  /* u = s * s */                                \
        int __o = 0;                                            \
        if ((__ckd_intmax_t)(__x & __y) < 0) {                  \
          __x = -__x;                                           \
          __y = -__y;                                           \
        } else if ((__ckd_intmax_t)(__x ^ __y) < 0) {           \
          __o = __x && __y;                                     \
        }                                                       \
        __ckd_uintmax_t __z = __x * __y;                        \
        __o |= __x && __z / __x != __y;                         \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 4: {  /* s = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | ((__ckd_intmax_t)(__z) < 0) |             \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 5: {  /* s = u * s */                                \
        __ckd_uintmax_t __t = -__y;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __y : __t;            \
        __ckd_uintmax_t __p = __t * __x;                        \
        int __o = __t && __p / __t != __x;                      \
        int __n = (__ckd_intmax_t)__y < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 6: {  /* s = s * u */                                \
        __ckd_uintmax_t __t = -__x;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __x : __t;            \
        __ckd_uintmax_t __p = __t * __y;                        \
        int __o = __t && __p / __t != __y;                      \
        int __n = (__ckd_intmax_t)__x < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 7: {  /* s = s * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        *(T *)__res = __z;                                      \
        return (((((__ckd_intmax_t)__y < 0) &&                  \
                  (__x == __ckd_sign(__ckd_uintmax_t))) ||      \
                 (__y && (((__ckd_intmax_t)__z /                \
                           (__ckd_intmax_t)__y) !=              \
                          (__ckd_intmax_t)__x))) |              \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      default:                                                  \
        for (;;) (void)0;                                       \
    }                                                           \
  }

__ckd_declare_mul(__ckd_mul_schar, signed char)
__ckd_declare_mul(__ckd_mul_uchar, unsigned char)
__ckd_declare_mul(__ckd_mul_sshort, signed short)
__ckd_declare_mul(__ckd_mul_ushort, unsigned short)
__ckd_declare_mul(__ckd_mul_sint, signed int)
__ckd_declare_mul(__ckd_mul_uint, unsigned int)
__ckd_declare_mul(__ckd_mul_slong, signed long)
__ckd_declare_mul(__ckd_mul_ulong, unsigned long)
__ckd_declare_mul(__ckd_mul_slonger, signed long long)
__ckd_declare_mul(__ckd_mul_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_mul(__ckd_mul_sint128, signed __int128)
__ckd_declare_mul(__ckd_mul_uint128, unsigned __int128)
#endif

#else
#pragma message "checked integer arithmetic unsupported in this environment"

#define ckd_add(res, x, y) (*(res) = (x) + (y), 0)
#define ckd_sub(res, x, y) (*(res) = (x) - (y), 0)
#define ckd_mul(res, x, y) (*(res) = (x) * (y), 0)

#endif /* GNU */
/* clang-format on */


/*!BEGIN libc/stdlib.h */

#define COSMOPOLITAN_LIBC_STDLIB_H_
COSMOPOLITAN_C_START_

char *fcvt(double, int, int *, int *) libcesque;
char *ecvt(double, int, int *, int *) libcesque;
char *gcvt(double, int, char *) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void setkey(const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/temp.h */

#define COSMOPOLITAN_LIBC_TEMP_H_
COSMOPOLITAN_C_START_

char *mktemp(char *) libcesque returnsnonnull paramsnonnull();
char *mkdtemp(char *) libcesque paramsnonnull() __wur;
int mkstemp(char *) libcesque paramsnonnull() __wur;
int mkstemps(char *, int) libcesque paramsnonnull() __wur;

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
int mkostemp(char *, unsigned) libcesque paramsnonnull() __wur;
int mkostemps(char *, int, unsigned) libcesque paramsnonnull() __wur;
#endif

#ifdef _COSMO_SOURCE
int openatemp(int, char *, int, int, int) libcesque paramsnonnull() __wur;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/time.h */

#define COSMOPOLITAN_LIBC_TIME_H_

#define TIME_UTC 1

COSMOPOLITAN_C_START_

struct tm {
  int32_t tm_sec;
  int32_t tm_min;
  int32_t tm_hour;
  int32_t tm_mday; /* 1-indexed */
  int32_t tm_mon;  /* 0-indexed */
  int32_t tm_year; /* minus 1900 */
  int32_t tm_wday;
  int32_t tm_yday;
  int32_t tm_isdst;
  int64_t tm_gmtoff;
  const char *tm_zone;
};

struct timezone {
  int32_t tz_minuteswest;
  int32_t tz_dsttime;
};

extern char *tzname[2];
extern long timezone;
extern int daylight;

void tzset(void) libcesque;
char *asctime(const struct tm *) libcesque;
char *asctime_r(const struct tm *, char *) libcesque;
char *strptime(const char *, const char *, struct tm *) libcesque;
int64_t mktime(struct tm *) libcesque;
int64_t timegm(struct tm *) libcesque;
int64_t timelocal(struct tm *) libcesque;
int64_t timeoff(struct tm *, long) libcesque;
size_t strftime(char *, size_t, const char *, const struct tm *) libcesque
    strftimeesque(3) libcesque;
size_t wcsftime(wchar_t *, size_t, const wchar_t *,
                const struct tm *) libcesque;
struct tm *gmtime(const int64_t *) libcesque;
struct tm *gmtime_r(const int64_t *, struct tm *) libcesque;
struct tm *localtime(const int64_t *) libcesque;
struct tm *localtime_r(const int64_t *, struct tm *) libcesque;

char *ctime(const int64_t *) libcesque;
char *ctime_r(const int64_t *, char *) libcesque;
double difftime(int64_t, int64_t)
pureconst libcesque;
int stime(const int64_t *) libcesque;
void tzset(void) libcesque;

#ifdef _COSMO_SOURCE
extern const char kWeekdayNameShort[7][4];
extern const char kWeekdayName[7][10];
extern const char kMonthNameShort[12][4];
extern const char kMonthName[12][10];
extern const unsigned short kMonthYearDay[2][12];
#define iso8601 __iso8601
char *iso8601(char[hasatleast 20], struct tm *) libcesque;
#define iso8601us __iso8601us
char *iso8601us(char[hasatleast 27], struct tm *, long) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/type2str.h */

#define COSMOPOLITAN_LIBC_TYPE2STR_H_
#if __STDC_VERSION__ + 0 >= 201112
/* clang-format off */

#define _TYPE2STR(X)                          \
  _Generic(X,                                 \
    _Bool:              "_Bool",              \
    signed char:        "signed char",        \
    unsigned char:      "unsigned char",      \
    char:               "char",               \
    short:              "short",              \
    unsigned short:     "unsigned short",     \
    int:                "int",                \
    unsigned:           "unsigned",           \
    long:               "long",               \
    unsigned long:      "unsigned long",      \
    long long:          "long long",          \
    unsigned long long: "unsigned long long", \
    __int128:           "__int128",           \
    unsigned __int128:  "unsigned __int128",  \
    float:              "float",              \
    double:             "double",             \
    long double:        "long double")

#define _PRINTF_GENERIC(X, D, U) \
  _Generic(X,                    \
    _Bool:              "hhh" U, \
    signed char:        "hh" D,  \
    unsigned char:      "hh" U,  \
    char:               "hh" D,  \
    short:              "h" D,   \
    unsigned short:     "h" U,   \
    int:                D,       \
    unsigned:           U,       \
    long:               "l" D,   \
    unsigned long:      "l" U,   \
    long long:          "ll" D,  \
    unsigned long long: "ll" U,  \
    float:              "f",     \
    double:             "f",     \
    long double:        "Lf")

/* clang-format on */
#endif /* C11 */


/*!BEGIN libc/unistd.h */

#define COSMOPOLITAN_LIBC_UNISTD_H_
COSMOPOLITAN_C_START_

#define _CS_PATH 0

size_t confstr(int, char *, size_t) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void encrypt(char *, int) libcesque;
char *crypt(const char *, const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/utime.h */

#define COSMOPOLITAN_LIBC_UTIME_H_
COSMOPOLITAN_C_START_

struct utimbuf {
  int64_t actime;  /* access time */
  int64_t modtime; /* modified time */
};

int utime(const char *, const struct utimbuf *) libcesque;

#ifdef _COSMO_SOURCE
int sys_utime(const char *, const struct utimbuf *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/typedef/u.h */

#define COSMOPOLITAN_LIBC_CALLS_TYPEDEF_U_H_
COSMOPOLITAN_C_START_

typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
typedef unsigned u_int32_t;
typedef char *caddr_t;
typedef unsigned char u_char;
typedef unsigned short u_short, ushort;
typedef unsigned u_int, uint;
typedef unsigned long u_long, ulong;
typedef long long quad_t;
typedef unsigned long long u_quad_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/cpuset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_

#define CPU_SETSIZE 1024

COSMOPOLITAN_C_START_

typedef struct cpu_set_t {
  uint64_t __bits[16];
} cpu_set_t;

int sched_getcpu(void) libcesque;
int sched_getaffinity(int, size_t, cpu_set_t *) libcesque;
int sched_setaffinity(int, size_t, const cpu_set_t *) libcesque;

#define CPU_SET(i, s)   ((s)->__bits[(i) / 64] |= 1ull << ((i) % 64))
#define CPU_CLR(i, s)   ((s)->__bits[(i) / 64] &= ~(1ull << ((i) % 64)))
#define CPU_ISSET(i, s) (!!((s)->__bits[(i) / 64] & (1ull << ((i) % 64))))

void CPU_ZERO(cpu_set_t *) libcesque;
#define CPU_ZERO(x) CPU_ZERO(x)

int CPU_COUNT(cpu_set_t *) libcesque;
#define CPU_COUNT(x) CPU_COUNT(x)

int CPU_EQUAL(cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_EQUAL(x, y) CPU_EQUAL(x, y)

void CPU_AND(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_AND(x, y, z) CPU_AND(x, y, z)

void CPU_OR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_OR(x, y, z) CPU_OR(x, y, z)

void CPU_XOR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_XOR(x, y, z) CPU_XOR(x, y, z)

int CPU_COUNT_S(size_t, const cpu_set_t *) libcesque;
#define CPU_COUNT_S(x, y) CPU_COUNT_S(x, y)

#define CPU_ALLOC_SIZE(n) \
  ((((n) + (8 * sizeof(long) - 1)) & -(8 * sizeof(long))) / sizeof(long))

#define CPU_ALLOC(n)                  ((cpu_set_t *)calloc(1, CPU_ALLOC_SIZE(n)))
#define CPU_FREE(set)                 free(set)
#define CPU_ZERO_S(size, set)         memset(set, 0, size)
#define CPU_EQUAL_S(size, set1, set2) (!memcmp(set1, set2, size))
#define _CPU_S(i, size, set, op)                                              \
  ((i) / 8U >= (size) ? 0                                                     \
                      : (((unsigned long *)(set))[(i) / 8 / sizeof(long)] op( \
                            1UL << ((i) % (8 * sizeof(long))))))
#define CPU_SET_S(i, size, set)   _CPU_S(i, size, set, |=)
#define CPU_CLR_S(i, size, set)   _CPU_S(i, size, set, &= ~)
#define CPU_ISSET_S(i, size, set) _CPU_S(i, size, set, &)

typedef cpu_set_t cpuset_t; /* for freebsd compatibility */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/dirent.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_
COSMOPOLITAN_C_START_

struct dirent {      /* linux getdents64 abi */
  uint64_t d_ino;    /* inode number */
  int64_t d_off;     /* implementation-dependent location number */
  uint16_t d_reclen; /* byte length of this whole struct and string */
  uint8_t d_type;    /* DT_REG, DT_DIR, DT_UNKNOWN, DT_BLK, etc. */
  char d_name[256];  /* NUL-terminated basename */
};

struct dirstream;
typedef struct dirstream DIR;

DIR *fdopendir(int) libcesque __wur;
DIR *opendir(const char *) libcesque __wur;
int closedir(DIR *) libcesque;
int dirfd(DIR *) libcesque;
long telldir(DIR *) libcesque;
struct dirent *readdir(DIR *) libcesque;
int readdir_r(DIR *, struct dirent *, struct dirent **) libcesque;
void rewinddir(DIR *) libcesque;
void seekdir(DIR *, long) libcesque;
int alphasort(const struct dirent **, const struct dirent **) libcesque;
int versionsort(const struct dirent **, const struct dirent **) libcesque;
int scandir(const char *, struct dirent ***, int (*)(const struct dirent *),
            int (*)(const struct dirent **, const struct dirent **)) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/flock.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FLOCK_H_
COSMOPOLITAN_C_START_

struct flock {      /* cosmopolitan abi */
  int16_t l_type;   /* F_RDLCK, F_WRLCK, F_UNLCK */
  int16_t l_whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
  int64_t l_start;  /* starting offset */
  int64_t l_len;    /* no. bytes (0 means to end of file) */
  int32_t l_pid;    /* lock owner */
  int32_t l_sysid;  /* remote system id or zero for local (freebsd) */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/framebuffercolormap.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERCOLORMAP_H_

struct FrameBufferColorMap {
  uint32_t start;
  uint32_t len;
  uint16_t *red;
  uint16_t *green;
  uint16_t *blue;
  uint16_t *transp;
};



/*!BEGIN libc/calls/struct/framebufferfixedscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERFIXEDSCREENINFO_H_

struct FrameBufferFixedScreenInfo {
  char id[16];
  uint64_t smem_start;
  uint32_t smem_len;
  uint32_t type;
  uint32_t type_aux;
  uint32_t visual;
  uint16_t xpanstep;
  uint16_t ypanstep;
  uint16_t ywrapstep;
  uint32_t line_length;
  uint64_t mmio_start;
  uint32_t mmio_len;
  uint32_t accel;
  uint16_t capabilities;
  uint16_t reserved[2];
};



/*!BEGIN libc/calls/struct/framebuffervirtualscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERVIRTUALSCREENINFO_H_

struct FrameBufferBitField {
  uint32_t offset;
  uint32_t length;
  uint32_t msb_right;
};

struct FrameBufferVirtualScreenInfo {
  uint32_t xres;
  uint32_t yres;
  uint32_t xres_virtual;
  uint32_t yres_virtual;
  uint32_t xoffset;
  uint32_t yoffset;
  uint32_t bits_per_pixel;
  uint32_t grayscale;
  struct FrameBufferBitField red;
  struct FrameBufferBitField green;
  struct FrameBufferBitField blue;
  struct FrameBufferBitField transp;
  uint32_t nonstd;
  uint32_t activate;
  uint32_t height;
  uint32_t width;
  uint32_t accel_flags;
  uint32_t pixclock;
  uint32_t left_margin;
  uint32_t right_margin;
  uint32_t upper_margin;
  uint32_t lower_margin;
  uint32_t hsync_len;
  uint32_t vsync_len;
  uint32_t sync;
  uint32_t vmode;
  uint32_t rotate;
  uint32_t colorspace;
  uint32_t reserved[4];
};



/*!BEGIN libc/calls/struct/fsid.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FSID_H_
COSMOPOLITAN_C_START_

typedef struct fsid_t {
  uint32_t __val[2];
} fsid_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/iovec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct iovec {
  void *iov_base;
  size_t iov_len;
};

ssize_t preadv(int, struct iovec *, int, int64_t) libcesque;
ssize_t pwritev(int, const struct iovec *, int, int64_t) libcesque;
ssize_t readv(int, const struct iovec *, int) libcesque;
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t) libcesque;
ssize_t writev(int, const struct iovec *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/itimerval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_H_


/*!BEGIN libc/calls/struct/timeval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_


/*!BEGIN libc/calls/struct/timespec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct timespec {
  int64_t tv_sec;
  int64_t tv_nsec; /* nanoseconds */
};

int clock_getres(int, struct timespec *) libcesque;
int clock_gettime(int, struct timespec *) libcesque;
int clock_settime(int, const struct timespec *) libcesque;
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int futimens(int, const struct timespec[2]) libcesque;
int nanosleep(const struct timespec *, struct timespec *) libcesque;
int utimensat(int, const char *, const struct timespec[2], int) libcesque;
int timespec_getres(struct timespec *, int) libcesque;
int timespec_get(struct timespec *, int) libcesque;

#ifdef _COSMO_SOURCE
int sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int cosmo_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
#define timespec_zero ((struct timespec){0})
#define timespec_max  ((struct timespec){0x7fffffffffffffff, 999999999})
libcesque int timespec_cmp(struct timespec, struct timespec) pureconst;
libcesque int64_t timespec_tomicros(struct timespec) pureconst;
libcesque int64_t timespec_tomillis(struct timespec) pureconst;
libcesque int64_t timespec_tonanos(struct timespec) pureconst;
libcesque struct timespec timespec_add(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_fromnanos(int64_t) pureconst;
libcesque struct timespec timespec_frommicros(int64_t) pureconst;
libcesque struct timespec timespec_frommillis(int64_t) pureconst;
libcesque struct timespec timespec_real(void) libcesque;
libcesque struct timespec timespec_mono(void) libcesque;
libcesque struct timespec timespec_sleep(struct timespec) libcesque;
libcesque int timespec_sleep_until(struct timespec) libcesque;
libcesque struct timespec timespec_sub(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_subz(struct timespec,
                                        struct timespec) pureconst;
int sys_futex(int *, int, int, const struct timespec *, int *);
static inline struct timespec timespec_fromseconds(int64_t __x) {
  return (struct timespec){__x};
}
static inline int timespec_iszero(struct timespec __ts) {
  return !(__ts.tv_sec | __ts.tv_nsec);
}
static inline int timespec_isvalid(struct timespec __ts) {
  return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
}
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

struct timeval {
  int64_t tv_sec;
  int64_t tv_usec; /* microseconds */
};

int futimes(int, const struct timeval[2]);
int futimesat(int, const char *, const struct timeval[2]);
int gettimeofday(struct timeval *, struct timezone *);
int settimeofday(const struct timeval *, const struct timezone *);
int lutimes(const char *, const struct timeval[2]);
int utimes(const char *, const struct timeval[2]);

#ifdef _COSMO_SOURCE
/* cosmopolitan libc's non-posix timevals library
   removed by default due to emacs codebase clash */
#define timeval_zero ((struct timeval){0})
#define timeval_max  ((struct timeval){0x7fffffffffffffff, 999999})
int timeval_cmp(struct timeval, struct timeval) pureconst;
struct timeval timeval_real(void);
struct timeval timeval_frommicros(int64_t) pureconst;
struct timeval timeval_frommillis(int64_t) pureconst;
struct timeval timeval_add(struct timeval, struct timeval) pureconst;
struct timeval timeval_sub(struct timeval, struct timeval) pureconst;
struct timeval timeval_subz(struct timeval, struct timeval) pureconst;
int64_t timeval_toseconds(struct timeval);
int64_t timeval_tomicros(struct timeval);
int64_t timeval_tomillis(struct timeval);
struct timeval timespec_totimeval(struct timespec) pureconst;
static inline struct timeval timeval_fromseconds(int64_t __x) {
  return (struct timeval){__x};
}
static inline struct timespec timeval_totimespec(struct timeval __tv) {
  return (struct timespec){__tv.tv_sec, __tv.tv_usec * 1000};
}
static inline int timeval_iszero(struct timeval __tv) {
  return !(__tv.tv_sec | __tv.tv_usec);
}
static inline int timeval_isvalid(struct timeval __tv) {
  return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull;
}
#endif /* _COSMO_SOURCE */

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
#define timercmp(s, t, op)                                  \
  ((s)->tv_sec == (t)->tv_sec ? (s)->tv_usec op(t)->tv_usec \
                              : (s)->tv_sec op(t)->tv_sec)
#define timeradd(s, t, a)                                           \
  (void)((a)->tv_sec = (s)->tv_sec + (t)->tv_sec,                   \
         ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
             ((a)->tv_usec -= 1000000, (a)->tv_sec++))
#define timersub(s, t, a)                                    \
  (void)((a)->tv_sec = (s)->tv_sec - (t)->tv_sec,            \
         ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
             ((a)->tv_usec += 1000000, (a)->tv_sec--))
#endif

#ifdef _GNU_SOURCE
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
  ((ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0)
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
  ((tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0)
#endif

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct itimerval {
  struct timeval it_interval; /* {0,0} means singleshot */
  struct timeval it_value;    /* {0,0} means disarm */
};

int getitimer(int, struct itimerval *);
int setitimer(int, const struct itimerval *, struct itimerval *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/metasigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METASIGALTSTACK_H_


/*!BEGIN libc/calls/struct/sigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGALTSTACK_H_
COSMOPOLITAN_C_START_

struct sigaltstack {
  void *ss_sp;
  int ss_flags;
  size_t ss_size;
};

typedef struct sigaltstack stack_t;

int sigaltstack(const struct sigaltstack *, struct sigaltstack *) libcesque;

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct sigaltstack_bsd {
  void *ss_sp;
  uint64_t ss_size;
  int32_t ss_flags;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rlimit.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_
COSMOPOLITAN_C_START_

struct rlimit {
  uint64_t rlim_cur; /* current (soft) limit in bytes */
  uint64_t rlim_max; /* maximum limit in bytes */
};

int getrlimit(int, struct rlimit *) libcesque;
int setrlimit(int, const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rusage.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_
COSMOPOLITAN_C_START_

struct rusage {
  struct timeval ru_utime; /* user CPU time used */
  struct timeval ru_stime; /* system CPU time used */
  int64_t ru_maxrss;       /* maximum resident set size in (kb) */
  int64_t ru_ixrss;        /* shared memory size (integral kb CLK_TCK) */
  int64_t ru_idrss;        /* unshared data size (integral kb CLK_TCK) */
  int64_t ru_isrss;        /* unshared stack size (integral kb CLK_TCK) */
  int64_t ru_minflt;       /* page reclaims */
  int64_t ru_majflt;       /* page faults */
  int64_t ru_nswap;        /* swaps */
  int64_t ru_inblock;      /* block input operations */
  int64_t ru_oublock;      /* block output operations */
  int64_t ru_msgsnd;       /* IPC messages sent */
  int64_t ru_msgrcv;       /* IPC messages received */
  int64_t ru_nsignals;     /* signals received */
  int64_t ru_nvcsw;        /* voluntary context switches */
  int64_t ru_nivcsw;       /* involuntary context switches */
};

int getrusage(int, struct rusage *) libcesque;
int wait3(int *, int, struct rusage *) libcesque;
int wait4(int, int *, int, struct rusage *) libcesque;
void rusage_add(struct rusage *, const struct rusage *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sched_param.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SCHED_PARAM_H_
COSMOPOLITAN_C_START_

struct sched_param {
  int32_t sched_priority;
};

int sched_get_priority_max(int) libcesque;
int sched_get_priority_min(int) libcesque;
int sched_getparam(int, struct sched_param *) libcesque;
int sched_getscheduler(int) libcesque;
int sched_rr_get_interval(int, struct timespec *) libcesque;
int sched_setparam(int, const struct sched_param *) libcesque;
int sched_setscheduler(int, int, const struct sched_param *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigaction.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_


/*!BEGIN libc/calls/struct/siginfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_H_


/*!BEGIN libc/calls/struct/sigval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_
COSMOPOLITAN_C_START_

union sigval {
  int32_t sival_int;
  void *sival_ptr;
};

int sigqueue(int, int, const union sigval);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct siginfo {
  int32_t si_signo;
  int32_t si_errno;
  int32_t si_code; /* {SICODE,SEGV,ILL,FPE,POLL}_xxx */
  union {
    struct {
      union {
        struct {
          /* signals sent by kill() and sigqueue() set these */
          int32_t si_pid;
          uint32_t si_uid;
        };
        struct {
          /* SIGALRM sets these */
          int32_t si_timerid;
          int32_t si_overrun;
        };
      };
      union {
        union sigval si_value; /* provided by third arg of sigqueue(2) */
        struct {
          int32_t si_status;
          int64_t si_utime;
          int64_t si_stime;
        };
      };
    };
    struct {
      void *si_addr;
      int16_t si_addr_lsb;
      union {
        struct {
          void *si_lower;
          void *si_upper;
        };
        uint32_t si_pkey;
      };
    };
    struct {
      int64_t si_band; /* SIGPOLL */
      int32_t si_fd;
    };
    struct {
      void *si_call_addr;
      int32_t si_syscall;
      uint32_t si_arch;
    };
    char __ignoreme[128 - 2 * sizeof(int32_t) - sizeof(int64_t)];
  };
};

typedef struct siginfo siginfo_t;

#ifdef _COSMO_SOURCE
void __minicrash(int, siginfo_t *, void *) libcesque;
char __is_stack_overflow(siginfo_t *, void *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_
COSMOPOLITAN_C_START_

typedef uint64_t sigset_t;

int sigaddset(sigset_t *, int) paramsnonnull();
int sigdelset(sigset_t *, int) paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull();
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect;
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect;
int sigprocmask(int, const sigset_t *, sigset_t *);
int sigsuspend(const sigset_t *);
int sigpending(sigset_t *);
int pthread_sigmask(int, const sigset_t *, sigset_t *);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef void (*sighandler_t)(int);
typedef void (*sigaction_f)(int, struct siginfo *, void *);

struct sigaction {
  union {
    sighandler_t sa_handler;
    sigaction_f sa_sigaction;
  };
  uint64_t sa_flags;
  void (*sa_restorer)(void);
  sigset_t sa_mask;
};

sighandler_t signal(int, sighandler_t) libcesque;
int sigaction(int, const struct sigaction *, struct sigaction *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_H_
COSMOPOLITAN_C_START_

struct stat {              /* cosmo abi */
  uint64_t st_dev;         /* 0: id of device with file */
  uint64_t st_ino;         /* 8: inode number in disk b-tree */
  uint64_t st_nlink;       /* 16: hard link count */
  uint32_t st_mode;        /* 24: octal file mask thing */
  uint32_t st_uid;         /* 28: user id of owner */
  uint32_t st_gid;         /* group id of owning group */
  uint32_t st_flags;       /* nt/xnu/bsd-only */
  uint64_t st_rdev;        /* id of device if a special file */
  int64_t st_size;         /* bytes in file */
  int64_t st_blksize;      /* preferred chunking for underlying filesystem */
  int64_t st_blocks;       /* number of 512-byte pages allocated to file */
  struct timespec st_atim; /* access time */
  struct timespec st_mtim; /* modified time */
  struct timespec st_ctim; /* complicated time */
  struct timespec st_birthtim;
  uint64_t st_gen; /* xnu/bsd only */
};

int stat(const char *, struct stat *);
int lstat(const char *, struct stat *);
int fstat(int, struct stat *);
int fstatat(int, const char *, struct stat *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.macros.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_MACROS_H_

#define STAT_HAVE_NSEC 1

#define st_atime st_atim.tv_sec
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec

#define st_atime_nsec st_atim.tv_nsec
#define st_mtime_nsec st_mtim.tv_nsec
#define st_ctime_nsec st_ctim.tv_nsec

#define st_atimensec st_atim.tv_nsec
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
#define st_birthtime st_birthtim.tv_sec

#define st_file_attributes st_flags

#define INIT_STRUCT_STAT_PADDING(st) (void)st



/*!BEGIN libc/calls/struct/statfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
COSMOPOLITAN_C_START_

struct statfs {       /* cosmo abi */
  int64_t f_type;     /* type of filesystem */
  int64_t f_bsize;    /* optimal transfer block size */
  int64_t f_blocks;   /* total data blocks in filesystem */
  int64_t f_bfree;    /* free blocks in filesystem */
  int64_t f_bavail;   /* free blocks available to unprivileged users */
  int64_t f_files;    /* total file nodes in filesystem */
  int64_t f_ffree;    /* free file nodes in filesystem */
  fsid_t f_fsid;      /* filesystem id */
  int64_t f_namelen;  /* maximum length of filenames */
  int64_t f_frsize;   /* fragment size */
  int64_t f_flags;    /* mount flags of filesystem 2.6.36 */
  int64_t f_spare[4]; /* end of linux abi */
  uint32_t f_owner;
  char f_fstypename[16];
};

int statfs(const char *, struct statfs *) libcesque;
int fstatfs(int, struct statfs *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/statvfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
COSMOPOLITAN_C_START_

struct statvfs {
  unsigned long f_bsize;   /* Filesystem block size */
  unsigned long f_frsize;  /* Fragment size */
  uint64_t f_blocks;       /* Size of fs in f_frsize units */
  uint64_t f_bfree;        /* Number of free blocks */
  uint64_t f_bavail;       /* Number of free blocks for unprivileged users */
  uint64_t f_files;        /* Number of inodes */
  uint64_t f_ffree;        /* Number of free inodes */
  uint64_t f_favail;       /* Number of free inodes for unprivileged users */
  unsigned long f_fsid;    /* Filesystem ID */
  unsigned long f_flag;    /* Mount flags */
  unsigned long f_namemax; /* Maximum filename length */
};

int statvfs(const char *, struct statvfs *);
int fstatvfs(int, struct statvfs *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sysinfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_
COSMOPOLITAN_C_START_

struct sysinfo {
  int64_t uptime;     /* seconds since boot */
  uint64_t loads[3];  /* 1-5-15 min active process averages */
  uint64_t totalram;  /* system physical memory */
  uint64_t freeram;   /* amount of ram currently going to waste */
  uint64_t sharedram; /* bytes w/ pages mapped into multiple progs */
  uint64_t bufferram; /* lingering disk pages; see fadvise */
  uint64_t totalswap; /* size of emergency memory */
  uint64_t freeswap;  /* hopefully equal to totalswap */
  uint16_t procs;     /* number of processes */
  int16_t __ignore1;  /* padding */
  int32_t __ignore2;  /* padding */
  uint64_t totalhigh; /* wut */
  uint64_t freehigh;  /* wut */
  uint32_t mem_unit;  /* ram stuff above is multiples of this */
};

int sysinfo(struct sysinfo *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TERMIOS_H_

#define NCCS 20

COSMOPOLITAN_C_START_

struct termios {      /* cosmo abi */
  uint32_t c_iflag;   /* input modes */
  uint32_t c_oflag;   /* output modes */
  uint32_t c_cflag;   /* control modes */
  uint32_t c_lflag;   /* local modes */
  uint8_t c_cc[NCCS]; /* code mappings */
  uint32_t _c_ispeed; /* use cfgetispeed() and cfsetispeed() */
  uint32_t _c_ospeed; /* use cfgetospeed() and cfsetospeed() */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/tms.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_
COSMOPOLITAN_C_START_

struct tms {
  int64_t tms_utime;  /* userspace time */
  int64_t tms_stime;  /* kernelspace time */
  int64_t tms_cutime; /* children userspace time */
  int64_t tms_cstime; /* children kernelspace time */
};

long times(struct tms *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/user_regs_struct.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_USER_REGS_STRUCT_H_
COSMOPOLITAN_C_START_

/**
 * Linux Kernel user registers.
 *
 * @note superset of struct pt_regs
 * @see ptrace() w/ PTRACE_SYSCALL
 */
struct user_regs_struct {
  uint64_t r15;
  uint64_t r14;
  uint64_t r13;
  uint64_t r12;
  uint64_t rbp;
  uint64_t rbx;
  uint64_t r11;
  uint64_t r10;
  uint64_t r9;
  uint64_t r8;
  uint64_t rax;
  uint64_t rcx;
  uint64_t rdx;
  uint64_t rsi;
  uint64_t rdi;
  uint64_t orig_rax;
  uint64_t rip;
  uint64_t cs;
  uint64_t eflags;
  uint64_t rsp;
  uint64_t ss;
  uint64_t fs_base;
  uint64_t gs_base;
  uint64_t ds;
  uint64_t es;
  uint64_t fs;
  uint64_t gs;
};

struct useregs_struct_freebsd {
  int64_t r15;
  int64_t r14;
  int64_t r13;
  int64_t r12;
  int64_t r11;
  int64_t r10;
  int64_t r9;
  int64_t r8;
  int64_t rdi;
  int64_t rsi;
  int64_t rbp;
  int64_t rbx;
  int64_t rdx;
  int64_t rcx;
  int64_t rax;
  uint32_t trapno;
  uint16_t fs;
  uint16_t gs;
  uint32_t err;
  uint16_t es;
  uint16_t ds;
  int64_t rip;
  int64_t cs;
  int64_t rflags;
  int64_t rsp;
  int64_t ss;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/utsname.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UTSNAME_H_

#define SYS_NMLN 150

COSMOPOLITAN_C_START_

struct utsname {             /* cosmo abi */
  char sysname[SYS_NMLN];    /* name of os */
  char nodename[SYS_NMLN];   /* name of network node */
  char release[SYS_NMLN];    /* release level */
  char version[SYS_NMLN];    /* version level */
  char machine[SYS_NMLN];    /* hardware type */
  char domainname[SYS_NMLN]; /* domain name */
};

int uname(struct utsname *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/winsize.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_
COSMOPOLITAN_C_START_

struct winsize {
  uint16_t ws_row;
  uint16_t ws_col;
  uint16_t ws_xpixel;
  uint16_t ws_ypixel;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/cachestat.h */

#define COSMOPOLITAN_LIBC_CALLS_CACHESTAT_H_

COSMOPOLITAN_C_START_

struct cachestat_range {
  uint64_t off;
  uint64_t len;
};

struct cachestat {
  /** Number of cached pages. */
  uint64_t nr_cache;
  /** Number of dirty pages */
  uint64_t nr_dirty;
  /** Number of pages marked for writeback. */
  uint64_t nr_writeback;
  /** Number of pages evicted from the cache. */
  uint64_t nr_evicted;
  /**
   * Number of recently evicted pages.
   * A page is recently evicted if its last eviction was recent enough that its
   * reentry to the cache would indicate that it is actively being used by the
   * system, and that there is memory pressure on the system.
   */
  uint64_t nr_recently_evicted;
};

int cachestat(int, struct cachestat_range *, struct cachestat *, uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/calls.h */

#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_

#define _POSIX_VERSION  200809L
#define _POSIX2_VERSION _POSIX_VERSION
#define _XOPEN_VERSION  700

#define _POSIX_MAPPED_FILES               _POSIX_VERSION
#define _POSIX_FSYNC                      _POSIX_VERSION
#define _POSIX_IPV6                       _POSIX_VERSION
#define _POSIX_THREADS                    _POSIX_VERSION
#define _POSIX_THREAD_PROCESS_SHARED      _POSIX_VERSION
#define _POSIX_THREAD_SAFE_FUNCTIONS      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKADDR      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKSIZE      _POSIX_VERSION
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
#define _POSIX_THREAD_CPUTIME             _POSIX_VERSION
#define _POSIX_TIMEOUTS                   _POSIX_VERSION
#define _POSIX_MONOTONIC_CLOCK            _POSIX_VERSION
#define _POSIX_CPUTIME                    _POSIX_VERSION
#define _POSIX_BARRIERS                   _POSIX_VERSION
#define _POSIX_SPIN_LOCKS                 _POSIX_VERSION
#define _POSIX_READER_WRITER_LOCKS        _POSIX_VERSION
#define _POSIX_SEMAPHORES                 _POSIX_VERSION
#define _POSIX_SHARED_MEMORY_OBJECTS      _POSIX_VERSION
#define _POSIX_MEMLOCK_RANGE              _POSIX_VERSION
#define _POSIX_SPAWN                      _POSIX_VERSION

#define NSIG 64

#define SEEK_SET 0          /* relative to beginning */
#define SEEK_CUR 1          /* relative to current position */
#define SEEK_END 2          /* relative to end */
#define __WALL   0x40000000 /* Wait on all children, regardless of type */
#define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */

#define SIG_ERR ((void (*)(int))(-1))
#define SIG_DFL ((void (*)(int))0)
#define SIG_IGN ((void (*)(int))1)

#define CLOCKS_PER_SEC 1000000L

#define MAP_FAILED ((void *)-1)

#define WTERMSIG(x)     (127 & (x))
#define WCOREDUMP(x)    (128 & (x))
#define WIFEXITED(x)    (!WTERMSIG(x))
#define WEXITSTATUS(x)  ((x) >> 8)
#define WSTOPSIG(x)     ((0xff00 & (x)) >> 8)
#define WIFSTOPPED(x)   __wifstopped(x)
#define WIFSIGNALED(x)  __wifsignaled(x)
#define WIFCONTINUED(x) __wifcontinued(x)
#define W_STOPCODE(x)   ((x) << 8 | 0177)

#ifdef _COSMO_SOURCE
#define clone         __clone
#define commandv      __commandv
#define fileexists    __fileexists
#define ischardev     __ischardev
#define isdirectory   __isdirectory
#define isexecutable  __isexecutable
#define isregularfile __isregularfile
#define issymlink     __issymlink
#define makedirs      __makedirs
#define tmpfd         __tmpfd
#endif

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § system calls                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

typedef int sig_atomic_t;

bool32 isatty(int) libcesque;
char *getcwd(char *, size_t) dontthrow;
char *realpath(const char *, char *) libcesque __wur;
char *ttyname(int) libcesque;
int access(const char *, int) libcesque;
int chdir(const char *) libcesque;
int chmod(const char *, unsigned) libcesque;
int chown(const char *, unsigned, unsigned) libcesque;
int chroot(const char *) libcesque;
int close(int) libcesque;
int close_range(unsigned, unsigned, unsigned) libcesque;
int closefrom(int) libcesque;
int creat(const char *, unsigned) libcesque;
int dup(int) libcesque;
int dup2(int, int) libcesque;
int dup3(int, int, int) libcesque;
int execl(const char *, const char *, ...) nullterminated() libcesque;
int execle(const char *, const char *, ...) nullterminated((1)) libcesque;
int execlp(const char *, const char *, ...) nullterminated() libcesque;
int execv(const char *, char *const[]) libcesque;
int execve(const char *, char *const[], char *const[]) libcesque;
int execvp(const char *, char *const[]) libcesque;
int faccessat(int, const char *, int, int) libcesque;
int fchdir(int) libcesque;
int fchmod(int, unsigned) libcesque;
int fchmodat(int, const char *, unsigned, int) libcesque;
int fchown(int, unsigned, unsigned) libcesque;
int fchownat(int, const char *, unsigned, unsigned, int) libcesque;
int fcntl(int, int, ...) libcesque;
int fdatasync(int) libcesque;
int fexecve(int, char *const[], char *const[]) libcesque;
int flock(int, int) libcesque;
int fork(void) libcesque;
int fsync(int) libcesque;
int ftruncate(int, int64_t) libcesque;
int getdomainname(char *, size_t) libcesque;
int getgroups(int, unsigned[]) libcesque;
int gethostname(char *, size_t) libcesque;
int getloadavg(double *, int) libcesque;
int getpgid(int) libcesque;
int getpgrp(void) libcesque nosideeffect;
int getpid(void) libcesque nosideeffect;
int getppid(void) libcesque;
int getpriority(int, unsigned) libcesque;
int getsid(int) nosideeffect libcesque;
int ioctl(int, unsigned long, ...) libcesque;
int issetugid(void) libcesque;
int kill(int, int) libcesque;
int killpg(int, int) libcesque;
int lchmod(const char *, unsigned) libcesque;
int lchown(const char *, unsigned, unsigned) libcesque;
int link(const char *, const char *) libcesque;
int linkat(int, const char *, int, const char *, int) libcesque;
int mincore(void *, size_t, unsigned char *) libcesque;
int mkdir(const char *, unsigned) libcesque;
int mkdirat(int, const char *, unsigned) libcesque;
int mknod(const char *, unsigned, uint64_t) libcesque;
int nice(int) libcesque;
int open(const char *, int, ...) libcesque;
int openat(int, const char *, int, ...) libcesque;
int pause(void) libcesque;
int pipe(int[hasatleast 2]) libcesque;
int pipe2(int[hasatleast 2], int) libcesque;
int posix_fadvise(int, int64_t, int64_t, int) libcesque;
int posix_madvise(void *, uint64_t, int) libcesque;
int raise(int) libcesque;
int reboot(int) libcesque;
int remove(const char *) libcesque;
int rename(const char *, const char *) libcesque;
int renameat(int, const char *, int, const char *) libcesque;
int rmdir(const char *) libcesque;
int sched_yield(void) libcesque;
int setegid(unsigned) libcesque;
int seteuid(unsigned) libcesque;
int setfsgid(unsigned) libcesque;
int setfsuid(unsigned) libcesque;
int setgid(unsigned) libcesque;
int setgroups(size_t, const unsigned[]) libcesque;
int setpgid(int, int) libcesque;
int setpgrp(void) libcesque;
int setpriority(int, unsigned, int) libcesque;
int setregid(unsigned, unsigned) libcesque;
int setreuid(unsigned, unsigned) libcesque;
int setsid(void) libcesque;
int setuid(unsigned) libcesque;
int shm_open(const char *, int, unsigned) libcesque;
int shm_unlink(const char *) libcesque;
int sigignore(int) libcesque;
int siginterrupt(int, int) libcesque;
int symlink(const char *, const char *) libcesque;
int symlinkat(const char *, int, const char *) libcesque;
int tcgetpgrp(int) libcesque;
int tcsetpgrp(int, int) libcesque;
int truncate(const char *, int64_t) libcesque;
int ttyname_r(int, char *, size_t) libcesque;
int unlink(const char *) libcesque;
int unlinkat(int, const char *, int) libcesque;
int usleep(uint64_t) libcesque;
int vfork(void) libcesque returnstwice;
int wait(int *) libcesque;
int waitpid(int, int *, int) libcesque;
int64_t clock(void) libcesque;
int64_t time(int64_t *) libcesque;
ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned) libcesque;
ssize_t lseek(int, int64_t, int) libcesque;
ssize_t pread(int, void *, size_t, int64_t) libcesque;
ssize_t pwrite(int, const void *, size_t, int64_t) libcesque;
ssize_t read(int, void *, size_t) libcesque;
ssize_t readlink(const char *, char *, size_t) libcesque;
ssize_t readlinkat(int, const char *, char *, size_t) libcesque;
ssize_t write(int, const void *, size_t) libcesque;
unsigned alarm(unsigned) libcesque;
unsigned getegid(void) libcesque nosideeffect;
unsigned geteuid(void) libcesque nosideeffect;
unsigned getgid(void) libcesque nosideeffect;
unsigned getuid(void) libcesque;
unsigned sleep(unsigned) libcesque;
unsigned ualarm(unsigned, unsigned) libcesque;
unsigned umask(unsigned) libcesque;
void sync(void) libcesque;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
int syncfs(int) libcesque;
int prctl(int, ...) libcesque;
int gettid(void) libcesque;
int setresgid(unsigned, unsigned, unsigned) libcesque;
int setresuid(unsigned, unsigned, unsigned) libcesque;
int getresgid(unsigned *, unsigned *, unsigned *) libcesque;
int getresuid(unsigned *, unsigned *, unsigned *) libcesque;
char *get_current_dir_name(void) libcesque __wur;
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned) libcesque;
int memfd_create(const char *, unsigned int) libcesque;
int execvpe(const char *, char *const[], char *const[]) libcesque;
int euidaccess(const char *, int) libcesque;
int eaccess(const char *, int) libcesque;
int madvise(void *, uint64_t, int) libcesque;
int getcpu(unsigned *, unsigned *) libcesque;
#endif

#ifdef _COSMO_SOURCE
bool32 fdexists(int) libcesque;
bool32 fileexists(const char *) libcesque;
bool32 ischardev(int) libcesque;
bool32 isdirectory(const char *) libcesque;
bool32 isexecutable(const char *) libcesque;
bool32 isregularfile(const char *) libcesque;
bool32 issymlink(const char *) libcesque;
char *commandv(const char *, char *, size_t) libcesque;
int __getcwd(char *, size_t) libcesque;
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
int fadvise(int, uint64_t, uint64_t, int) libcesque;
int makedirs(const char *, unsigned) libcesque;
int pivot_root(const char *, const char *) libcesque;
int pledge(const char *, const char *) libcesque;
int seccomp(unsigned, unsigned, void *) libcesque;
int sys_iopl(int) libcesque;
int sys_ioprio_get(int, int) libcesque;
int sys_ioprio_set(int, int, int) libcesque;
int sys_mlock(const void *, size_t) libcesque;
int sys_mlock2(const void *, size_t, int) libcesque;
int sys_mlockall(int) libcesque;
int sys_munlock(const void *, size_t) libcesque;
int sys_munlockall(void) libcesque;
int sys_personality(uint64_t) libcesque;
int sys_ptrace(int, ...) libcesque;
int sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque;
int sysctlbyname(const char *, void *, size_t *, void *, size_t) libcesque;
int sysctlnametomib(const char *, int *, size_t *) libcesque;
int tmpfd(void) libcesque;
int touch(const char *, unsigned) libcesque;
int unveil(const char *, const char *) libcesque;
long ptrace(int, ...) libcesque;
ssize_t copyfd(int, int, size_t) libcesque;
ssize_t readansi(int, char *, size_t) libcesque;
ssize_t tinyprint(int, const char *, ...) libcesque nullterminated();
void shm_path_np(const char *, char[hasatleast 78]) libcesque;
#endif /* _COSMO_SOURCE */

int system(const char *) libcesque;

int __wifstopped(int) libcesque pureconst;
int __wifcontinued(int) libcesque pureconst;
int __wifsignaled(int) libcesque pureconst;

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define lseek64     lseek
#define pread64     pread
#define pwrite64    pwrite
#define truncate64  truncate
#define ftruncate64 ftruncate
#define lockf64     lockf
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ipc.h */

#define COSMOPOLITAN_LIBC_CALLS_IPC_H_

#define IPC_PRIVATE 0
#define IPC_RMID    0
#define IPC_SET     1
#define IPC_STAT    2
#define IPC_INFO    3
#define IPC_CREAT   01000
#define IPC_EXCL    02000
#define IPC_NOWAIT  04000

COSMOPOLITAN_C_START_

int ftok(const char *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/landlock.h */

#define COSMOPOLITAN_LIBC_CALLS_LANDLOCK_H_

#define LANDLOCK_CREATE_RULESET_VERSION 0x0001ul

#define LANDLOCK_ACCESS_FS_EXECUTE     0x0001ul
#define LANDLOCK_ACCESS_FS_WRITE_FILE  0x0002ul
#define LANDLOCK_ACCESS_FS_READ_FILE   0x0004ul
#define LANDLOCK_ACCESS_FS_READ_DIR    0x0008ul
#define LANDLOCK_ACCESS_FS_REMOVE_DIR  0x0010ul
#define LANDLOCK_ACCESS_FS_REMOVE_FILE 0x0020ul
#define LANDLOCK_ACCESS_FS_MAKE_CHAR   0x0040ul
#define LANDLOCK_ACCESS_FS_MAKE_DIR    0x0080ul
#define LANDLOCK_ACCESS_FS_MAKE_REG    0x0100ul
#define LANDLOCK_ACCESS_FS_MAKE_SOCK   0x0200ul
#define LANDLOCK_ACCESS_FS_MAKE_FIFO   0x0400ul
#define LANDLOCK_ACCESS_FS_MAKE_BLOCK  0x0800ul
#define LANDLOCK_ACCESS_FS_MAKE_SYM    0x1000ul

/**
 * Allow renaming or linking file to a different directory.
 *
 * @see https://lore.kernel.org/r/20220329125117.1393824-8-mic@digikod.net
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 2+
 */
#define LANDLOCK_ACCESS_FS_REFER 0x2000ul

/**
 * Control file truncation.
 *
 * @see
 * https://lore.kernel.org/all/20221018182216.301684-1-gnoack3000@gmail.com/
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 3+
 */
#define LANDLOCK_ACCESS_FS_TRUNCATE 0x4000ul

COSMOPOLITAN_C_START_

enum landlock_rule_type {
  LANDLOCK_RULE_PATH_BENEATH = 1,
};

struct landlock_ruleset_attr {
  uint64_t handled_access_fs;
};

struct thatispacked landlock_path_beneath_attr {
  uint64_t allowed_access;
  int32_t parent_fd;
};

int landlock_restrict_self(int, uint32_t);
int landlock_add_rule(int, enum landlock_rule_type, const void *, uint32_t);
int landlock_create_ruleset(const struct landlock_ruleset_attr *, size_t,
                            uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/makedev.h */

#define COSMOPOLITAN_LIBC_CALLS_MAKEDEV_H_

uint64_t makedev(uint32_t, uint32_t) libcesque;
uint32_t major(uint64_t) libcesque;
uint32_t minor(uint64_t) libcesque;

#define major(x)      major(x)
#define minor(x)      minor(x)
#define makedev(x, y) makedev(x, y)



/*!BEGIN libc/calls/mount.h */

#define COSMOPOLITAN_LIBC_CALLS_MOUNT_H_
COSMOPOLITAN_C_START_

int mount(const char *, const char *, const char *, unsigned long,
          const void *);
int unmount(const char *, int);

#ifdef _GNU_SOURCE
int umount(const char *);
int umount2(const char *, int);
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/pledge.h */

#define COSMOPOLITAN_LIBC_CALLS_PLEDGE_H_

#define PLEDGE_PENALTY_KILL_THREAD  0x0000
#define PLEDGE_PENALTY_KILL_PROCESS 0x0001
#define PLEDGE_PENALTY_RETURN_EPERM 0x0002
#define PLEDGE_PENALTY_MASK         0x000f
#define PLEDGE_STDERR_LOGGING       0x0010

COSMOPOLITAN_C_START_

extern int __pledge_mode;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/sigtimedwait.h */

#define COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_H_
COSMOPOLITAN_C_START_

int sigwait(const sigset_t *, int *);
int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *);
int sigwaitinfo(const sigset_t *, siginfo_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_H_
COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § teletypewriter control                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int tcgetattr(int, struct termios *) libcesque;
int tcsetattr(int, int, const struct termios *) libcesque;

int openpty(int *, int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2));
int forkpty(int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2)) __wur;
char *ptsname(int) libcesque;
errno_t ptsname_r(int, char *, size_t) libcesque;

int grantpt(int) libcesque;
int unlockpt(int) libcesque;
int posix_openpt(int) libcesque __wur;

int tcdrain(int) libcesque;
int tcgetsid(int) libcesque;
int tcflow(int, int) libcesque;
int tcflush(int, int) libcesque;
int tcsetsid(int, int) libcesque;
int tcsendbreak(int, int) libcesque;
void cfmakeraw(struct termios *) libcesque;
int cfsetspeed(struct termios *, uint32_t) libcesque;
int cfsetospeed(struct termios *, uint32_t) libcesque;
int cfsetispeed(struct termios *, uint32_t) libcesque;
uint32_t cfgetospeed(const struct termios *) libcesque;
uint32_t cfgetispeed(const struct termios *) libcesque;
int tcsetwinsize(int, const struct winsize *) libcesque;
int tcgetwinsize(int, struct winsize *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ttydefaults.h */

#define COSMOPOLITAN_LIBC_CALLS_TTYDEFAULTS_H_


/*!BEGIN libc/sysv/consts/termios.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TERMIOS_H_
COSMOPOLITAN_C_START_

#define EXTA B19200
#define EXTB B38400

extern const int _POSIX_VDISABLE;
extern const uint32_t BRKINT;
extern const uint32_t BS1;
extern const uint32_t BS2;
extern const uint32_t BSDLY;
extern const uint32_t CLOCAL;
extern const uint32_t CMSPAR;
extern const uint32_t CR1;
extern const uint32_t CR2;
extern const uint32_t CR3;
extern const uint32_t CRDLY;
extern const uint32_t CREAD;
extern const uint32_t CS5;
extern const uint32_t CS6;
extern const uint32_t CS7;
extern const uint32_t CS8;
extern const uint32_t CSIZE;
extern const uint32_t CSTOPB;
extern const uint32_t ECHOCTL;
extern const uint32_t ECHOE;
extern const uint32_t ECHOK;
extern const uint32_t ECHOKE;
extern const uint32_t ECHONL;
extern const uint32_t ECHOPRT;
extern const long EXTPROC;
extern const uint32_t FF1;
extern const uint32_t FF2;
extern const uint32_t FFDLY;
extern const uint32_t FLUSHO;
extern const uint32_t HUPCL;
extern const uint32_t ICANON;
extern const uint32_t ICRNL;
extern const uint32_t IEXTEN;
extern const uint32_t IGNBRK;
extern const uint32_t IGNCR;
extern const uint32_t IGNPAR;
extern const uint32_t IMAXBEL;
extern const uint32_t INLCR;
extern const uint32_t INPCK;
extern const uint32_t ISIG;
extern const uint32_t ISTRIP;
extern const uint32_t IUCLC;
extern const uint32_t IUTF8;
extern const uint32_t IXANY;
extern const uint32_t IXOFF;
extern const uint32_t IXON;
extern const uint32_t NL1;
extern const uint32_t NL2;
extern const uint32_t NL3;
extern const uint32_t NLDLY;
extern const uint32_t NOFLSH;
extern const uint32_t OCRNL;
extern const uint32_t OFDEL;
extern const uint32_t OFILL;
extern const uint32_t OLCUC;
extern const uint32_t ONLCR;
extern const uint32_t ONLRET;
extern const uint32_t ONOCR;
extern const uint32_t OPOST;
extern const uint32_t PARENB;
extern const uint32_t PARMRK;
extern const uint32_t PARODD;
extern const uint32_t PENDIN;
extern const uint32_t TAB1;
extern const uint32_t TAB2;
extern const uint32_t TAB3;
extern const uint32_t TABDLY;
extern const uint64_t TIOCCONS;
extern const uint64_t TIOCGETD;
extern const uint64_t TIOCGWINSZ;
extern const uint64_t TIOCNOTTY;
extern const uint64_t TIOCNXCL;
extern const uint64_t TIOCOUTQ;
extern const uint64_t TIOCSCTTY;
extern const uint64_t TIOCSETD;
extern const uint64_t TIOCSIG;
extern const uint64_t TIOCSPGRP;
extern const uint64_t TIOCSTI;
extern const uint64_t TIOCSWINSZ;
extern const long TOSTOP;
extern const uint8_t VDISCARD;
extern const uint8_t VEOF;
extern const uint8_t VEOL2;
extern const uint8_t VEOL;
extern const uint8_t VERASE;
extern const uint8_t VINTR;
extern const uint8_t VKILL;
extern const uint8_t VLNEXT;
extern const uint8_t VMIN;
extern const uint8_t VQUIT;
extern const uint8_t VREPRINT;
extern const uint8_t VSTART;
extern const uint8_t VSTOP;
extern const uint8_t VSUSP;
extern const uint8_t VSWTC;
extern const uint32_t VT1;
extern const uint32_t VT2;
extern const uint32_t VTDLY;
extern const uint8_t VTIME;
extern const uint8_t VWERASE;
extern const uint32_t XCASE;
extern const uint32_t XTABS;
extern const uint32_t CRTSCTS;

#define BRKINT  0x02
#define ICRNL   0x0100
#define IGNBRK  0x01
#define IGNCR   0x80
#define IGNPAR  0x04
#define IMAXBEL 0x2000
#define INLCR   0x40
#define INPCK   0x10
#define ISTRIP  0x20
#define IXANY   0x0800
#define OPOST   0x01
#define PARMRK  0x08

#define _POSIX_VDISABLE _POSIX_VDISABLE

#define NLDLY   NLDLY
#define NL0     0
#define NL1     NL1
#define NL2     NL2
#define NL3     NL3
#define CRDLY   CRDLY
#define CR0     0
#define CR1     CR1
#define CR2     CR2
#define CR3     CR3
#define TABDLY  TABDLY
#define TAB0    0
#define TAB1    TAB1
#define TAB2    TAB2
#define TAB3    TAB3
#define XTABS   XTABS
#define CRTSCTS CRTSCTS
#define BSDLY   BSDLY
#define BS0     0
#define BS1     BS1
#define BS2     BS2
#define VTDLY   VTDLY
#define VT0     0
#define VT1     VT1
#define VT2     VT2
#define FFDLY   FFDLY
#define FF0     0
#define FF1     FF1
#define FF2     FF2

#define CLOCAL   CLOCAL
#define CREAD    CREAD
#define CS5      CS5
#define CS6      CS6
#define CS7      CS7
#define CS8      CS8
#define CSIZE    CSIZE
#define CSTOPB   CSTOPB
#define ECHO     8
#define ECHOCTL  ECHOCTL
#define ECHOE    ECHOE
#define ECHOK    ECHOK
#define ECHOKE   ECHOKE
#define ECHONL   ECHONL
#define ECHOPRT  ECHOPRT
#define EXTPROC  EXTPROC
#define FLUSHO   FLUSHO
#define HUPCL    HUPCL
#define ICANON   ICANON
#define IEXTEN   IEXTEN
#define ISIG     ISIG
#define IUCLC    IUCLC
#define IUTF8    IUTF8
#define IXOFF    IXOFF
#define IXON     IXON
#define NOFLSH   NOFLSH
#define OCRNL    OCRNL
#define OFDEL    OFDEL
#define OFILL    OFILL
#define OLCUC    OLCUC
#define ONLCR    ONLCR
#define ONLRET   ONLRET
#define ONOCR    ONOCR
#define PARENB   PARENB
#define PARODD   PARODD
#define PENDIN   PENDIN
#define TOSTOP   TOSTOP
#define VDISCARD VDISCARD
#define VEOF     VEOF
#define VEOL     VEOL
#define VEOL2    VEOL2
#define VERASE   VERASE
#define VINTR    VINTR
#define VKILL    VKILL
#define VLNEXT   VLNEXT
#define VMIN     VMIN
#define VQUIT    VQUIT
#define VREPRINT VREPRINT
#define VSTART   VSTART
#define VSTOP    VSTOP
#define VSUSP    VSUSP
#define VSWTC    VSWTC
#define VTIME    VTIME
#define VWERASE  VWERASE
#define XCASE    XCASE

/* terminal ioctls */
#define TIOCGWINSZ TIOCGWINSZ /* get tty dimensions */
#define TIOCSWINSZ TIOCSWINSZ /* set tty dimensions */
#define TIOCCONS   TIOCCONS   /* redirect terminal */
#define TIOCGETD   TIOCGETD   /* get line discipline */
#define TIOCSETD   TIOCSETD   /* set line discipline */
#define TIOCNOTTY  TIOCNOTTY  /* give up terminal */
#define TIOCNXCL   TIOCNXCL   /* disable exclusive mode */
#define TIOCOUTQ   TIOCOUTQ   /* bytes in output buffer */
#define TIOCSCTTY  TIOCSCTTY  /* make controlling terminal */
#define TIOCSIG    TIOCSIG    /* generate pty signal */
#define TIOCSTI    TIOCSTI    /* insert fake tty input */

/* tcsetattr() */
#define TCSANOW   0
#define TCSAFLUSH 2
#define TCSADRAIN 1
extern const unsigned long TCGETS; /* use tcgetattr() */
extern const unsigned long TCSETS; /* use tcsetattr() */

/* tcflush() */
extern const int TCIFLUSH;
extern const int TCOFLUSH;
extern const int TCIOFLUSH;
#define TCIFLUSH  TCIFLUSH
#define TCOFLUSH  TCOFLUSH
#define TCIOFLUSH TCIOFLUSH

/* tcflow() */
#define TCOOFF 0
#define TCOON  1
#define TCIOFF 2
#define TCION  3

COSMOPOLITAN_C_END_

#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS)
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE | ECHOKE | ECHOCTL)
#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
#define TTYDEF_SPEED (B9600)

#define CTRL(x)  ((x) ^ 0100)
#define CEOF     CTRL('D')
#define CERASE   CTRL('?')
#define CINTR    CTRL('C')
#define CKILL    CTRL('U')
#define CQUIT    CTRL('\\')
#define CSUSP    CTRL('Z')
#define CDSUSP   CTRL('Y')
#define CSTART   CTRL('Q')
#define CSTOP    CTRL('S')
#define CLNEXT   CTRL('V')
#define CDISCARD CTRL('O')
#define CWERASE  CTRL('W')
#define CREPRINT CTRL('R')
#define CEOT     CEOF
#define CBRK     CEOL
#define CRPRNT   CREPRINT
#define CFLUSH   CDISCARD
#define CEOL     255
#define CMIN     1
#define CTIME    0



/*!BEGIN libc/calls/ucontext.h */

#define COSMOPOLITAN_LIBC_CALLS_UCONTEXT_H_
COSMOPOLITAN_C_START_

#ifdef __x86_64__

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define REG_R8      0
#define REG_R9      1
#define REG_R10     2
#define REG_R11     3
#define REG_R12     4
#define REG_R13     5
#define REG_R14     6
#define REG_R15     7
#define REG_RDI     8
#define REG_RSI     9
#define REG_RBP     10
#define REG_RBX     11
#define REG_RDX     12
#define REG_RAX     13
#define REG_RCX     14
#define REG_RSP     15
#define REG_RIP     16
#define REG_EFL     17
#define REG_CSGSFS  18
#define REG_ERR     19
#define REG_TRAPNO  20
#define REG_OLDMASK 21
#define REG_CR2     22
#endif

struct XmmRegister {
  uint64_t u64[2];
};

struct FpuStackEntry {
  uint16_t significand[4];
  uint16_t exponent;
  uint16_t padding[3];
};

struct thatispacked FpuState {

  /* 8087 FPU Control Word
      IM: Invalid Operation ───────────────┐
      DM: Denormal Operand ───────────────┐│
      ZM: Zero Divide ───────────────────┐││
      OM: Overflow ─────────────────────┐│││
      UM: Underflow ───────────────────┐││││
      PM: Precision ──────────────────┐│││││
      PC: Precision Control ───────┐  ││││││
       {float,∅,double,long double}│  ││││││
      RC: Rounding Control ──────┐ │  ││││││
       {even, →-∞, →+∞, →0}      │┌┤  ││││││
                                ┌┤││  ││││││
                               d││││rr││││││
                          0b0000001001111111 */
  uint16_t cwd;

  /* 8087 FPU Status Word */
  uint16_t swd;

  uint16_t ftw;
  uint16_t fop;
  uint64_t rip;
  uint64_t rdp;

  /* SSE CONTROL AND STATUS REGISTER
     IE: Invalid Operation Flag ──────────────┐
     DE: Denormal Flag ──────────────────────┐│
     ZE: Divide-by-Zero Flag ───────────────┐││
     OE: Overflow Flag ────────────────────┐│││
     UE: Underflow Flag ──────────────────┐││││
     PE: Precision Flag ─────────────────┐│││││
     DAZ: Denormals Are Zeros ──────────┐││││││
     IM: Invalid Operation Mask ───────┐│││││││
     DM: Denormal Operation Mask ─────┐││││││││
     ZM: Divide-by-Zero Mask ────────┐│││││││││
     OM: Overflow Mask ─────────────┐││││││││││
     UM: Underflow Mask ───────────┐│││││││││││
     PM: Precision Mask ──────────┐││││││││││││
     RC: Rounding Control ───────┐│││││││││││││
       {even, →-∞, →+∞, →0}      ││││││││││││││
     FTZ: Flush To Zero ───────┐ ││││││││││││││
                               │┌┤│││││││││││││
               ┌──────────────┐││││││││││││││││
               │   reserved   │││││││││││││││││
             0b00000000000000000001111110000000 */
  uint32_t mxcsr;
  uint32_t mxcr_mask;

  struct FpuStackEntry st[8];
  struct XmmRegister xmm[16];
  uint32_t __padding[24];
};

typedef long long greg_t;
typedef greg_t gregset_t[23];
typedef struct FpuState *fpregset_t;

#endif /* __x86_64__ */

struct sigcontext {
#ifdef __x86_64__
  union {
    struct {
      uint64_t r8;     /* 40 */
      uint64_t r9;     /* 48 */
      uint64_t r10;    /* 56 */
      uint64_t r11;    /* 64 */
      uint64_t r12;    /* 72 */
      uint64_t r13;    /* 80 */
      uint64_t r14;    /* 88 */
      uint64_t r15;    /* 96 */
      uint64_t rdi;    /* 104 */
      uint64_t rsi;    /* 112 */
      uint64_t rbp;    /* 120 */
      uint64_t rbx;    /* 128 */
      uint64_t rdx;    /* 136 */
      uint64_t rax;    /* 144 */
      uint64_t rcx;    /* 152 */
      uint64_t rsp;    /* 160 */
      uint64_t rip;    /* 168 */
      uint64_t eflags; /* 176 */
      uint16_t cs;
      uint16_t gs;
      uint16_t fs;
      uint16_t __pad0;
      uint64_t err;
      uint64_t trapno;
      uint64_t oldmask;
      uint64_t cr2;
    };
    gregset_t gregs;
  };
  struct FpuState *fpregs; /* zero when no fpu context */
  uint64_t __pad1[8];
#elif defined(__aarch64__)
  uint64_t fault_address;
  uint64_t regs[31];
  uint64_t sp;
  uint64_t pc;
  uint64_t pstate;
  uint8_t __reserved[4096] __attribute__((__aligned__(16)));
#endif /* __x86_64__ */
};

typedef struct sigcontext mcontext_t;

struct ucontext {
  uint64_t uc_flags; /* don't use this */
  struct ucontext *uc_link;
  stack_t uc_stack;
#ifdef __x86_64__
  struct sigcontext uc_mcontext;
  sigset_t uc_sigmask;
  uint64_t __pad[2];
  struct FpuState __fpustate; /* for cosmo on non-linux */
#elif defined(__aarch64__)
  sigset_t uc_sigmask;
  uint8_t __unused[1024 / 8];
  struct sigcontext uc_mcontext;
#endif
} forcealign(16);

typedef struct ucontext ucontext_t;

int getcontext(ucontext_t *) dontthrow;
int setcontext(const ucontext_t *) dontthrow;
int swapcontext(ucontext_t *, const ucontext_t *) dontthrow returnstwice;
void makecontext(ucontext_t *, void *, int, ...) dontthrow dontcallback;
void __sig_restore(const ucontext_t *) wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/weirdtypes.h */

#define COSMOPOLITAN_LIBC_CALLS_WEIRDTYPES_H_

/**
 * @fileoverview Types we'd prefer hadn't been invented.
 */

typedef int64_t blkcnt_t;
typedef uint8_t cc_t;
typedef int64_t clock_t; /* uint64_t on xnu */
typedef uint64_t dev_t;  /* int32_t on xnu */
typedef uint64_t fsblkcnt_t;
typedef int64_t fsfilcnt_t; /* uint32_t on xnu */
typedef uint32_t gid_t;
typedef int32_t id_t; /* int32_t on linux/freebsd/etc. */
typedef uint32_t in_addr_t;
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
typedef uint64_t ino_t;
typedef int32_t key_t;
typedef int64_t loff_t;
typedef uint32_t mode_t; /* uint16_t on xnu */
typedef uint64_t nfds_t;
typedef int64_t off_t;
typedef int32_t pid_t;
typedef int64_t register_t;
typedef uint16_t sa_family_t; /* bsd:uint8_t */
typedef uint32_t socklen_t;
typedef uint32_t speed_t;
typedef uint32_t suseconds_t;
typedef uint64_t useconds_t;   /* uint32_t on xnu */
typedef int64_t syscall_arg_t; /* uint64_t on xnu */
typedef uint32_t tcflag_t;
typedef int64_t time_t;
typedef void *timer_t;
typedef uint32_t uid_t;
typedef uint64_t rlim_t; /* int64_t on bsd */
typedef int32_t clockid_t;

#ifdef __x86_64__
typedef int64_t blksize_t; /* int32_t on xnu */
typedef uint64_t nlink_t;
#elif defined(__aarch64__)
typedef int32_t blksize_t;
typedef uint32_t nlink_t; /* uint16_t on xnu */
#endif

#define TIME_T_MAX __INT64_MAX__
#define TIME_T_MIN (-TIME_T_MAX - 1)

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define F_GETLK64         F_GETLK
#define F_SETLK64         F_SETLK
#define F_SETLKW64        F_SETLKW
#define RLIM64_INFINITY   RLIM_INFINITY
#define RLIM64_SAVED_CUR  RLIM_SAVED_CUR
#define RLIM64_SAVED_MAX  RLIM_SAVED_MAX
#define alphasort64       alphasort
#define blkcnt64_t        blkcnt_t
#define dirent64          dirent
#define flock64           flock
#define fsfilcnt64_t      fsfilcnt_t
#define fstat64           fstat
#define fstatat64         fstatat
#define fstatfs64         fstatfs
#define fstatvfs64        fstatvfs
#define getrlimit64       getrlimit
#define ino64_t           ino_t
#define lockf64           lockf
#define lstat64           lstat
#define mmap64            mmap
#define off64_t           off_t
#define open64            open
#define openat64          openat
#define posix_fadvise64   posix_fadvise
#define posix_fallocate64 posix_fallocate
#define readdir64         readdir
#define readdir64_r       readdir_r
#define rlim64_t          rlim_t
#define rlimit64          rlimit
#define scandir64         scandir
#define sendfile64        sendfile
#define setrlimit64       setrlimit
#define stat64            stat
#define statfs64          statfs
#define statvfs64         statvfs
#define versionsort64     versionsort
#endif



/*!BEGIN libc/elf/def.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DEF_H_

/**
 * @fileoverview Executable and Linkable Format Definitions.
 */

#define EI_NIDENT 16

#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3

#define ELFMAG  "\177ELF"
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define SELFMAG 4

#define EI_CLASS     4
#define ELFCLASSNONE 0
#define ELFCLASS32   1
#define ELFCLASS64   2
#define ELFCLASSNUM  3

#define EI_DATA     5
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define ELFDATANUM  3

#define EI_VERSION 6

#define EI_OSABI            7
#define ELFOSABI_NONE       0
#define ELFOSABI_SYSV       0
#define ELFOSABI_HPUX       1
#define ELFOSABI_NETBSD     2
#define ELFOSABI_LINUX      3
#define ELFOSABI_GNU        3
#define ELFOSABI_SOLARIS    6
#define ELFOSABI_AIX        7
#define ELFOSABI_IRIX       8
#define ELFOSABI_FREEBSD    9
#define ELFOSABI_TRU64      10
#define ELFOSABI_MODESTO    11
#define ELFOSABI_OPENBSD    12
#define ELFOSABI_ARM        97
#define ELFOSABI_STANDALONE 255

#define EI_ABIVERSION 8

#define EI_PAD 9

#define ET_NONE   0
#define ET_REL    1
#define ET_EXEC   2
#define ET_DYN    3
#define ET_CORE   4
#define ET_NUM    5
#define ET_LOOS   0xfe00
#define ET_HIOS   0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff

#define EM_NONE      0
#define EM_M32       1
#define EM_386       3
#define EM_PPC64     21
#define EM_S390      22
#define EM_ARM       40
#define EM_NEXGEN32E 62
#define EM_X86_64    EM_NEXGEN32E
#define EM_IA32E     EM_NEXGEN32E
#define EM_AMD64     EM_NEXGEN32E
#define EM_PDP11     65
#define EM_CRAYNV2   172
#define EM_L10M      180
#define EM_K10M      181
#define EM_AARCH64   183
#define EM_CUDA      190
#define EM_Z80       220
#define EM_RISCV     243
#define EM_BPF       247

/* the ape flag, "lol cat 5" */
#define EF_APE_MODERN      0x101ca75
#define EF_APE_MODERN_MASK 0x1ffffff

#define GRP_COMDAT 1
#define STN_UNDEF  0

#define EV_NONE    0
#define EV_CURRENT 1
#define EV_NUM     2

#define SYMINFO_NONE          0
#define SYMINFO_CURRENT       1
#define SYMINFO_NUM           2
#define SYMINFO_BT_SELF       0xffff
#define SYMINFO_BT_PARENT     0xfffe
#define SYMINFO_BT_LOWRESERVE 0xff00
#define SYMINFO_FLG_DIRECT    0x0001
#define SYMINFO_FLG_PASSTHRU  0x0002
#define SYMINFO_FLG_COPY      0x0004
#define SYMINFO_FLG_LAZYLOAD  0x0008

#define PT_NULL         0
#define PT_LOAD         1
#define PT_DYNAMIC      2
#define PT_INTERP       3
#define PT_NOTE         4
#define PT_SHLIB        5
#define PT_PHDR         6
#define PT_TLS          7
#define PT_NUM          8
#define PT_LOOS         0x60000000
#define PT_GNU_EH_FRAME 0x6474e550
#define PT_GNU_STACK    0x6474e551
#define PT_GNU_RELRO    0x6474e552
#define PT_LOSUNW       0x6ffffffa
#define PT_SUNWBSS      0x6ffffffa
#define PT_SUNWSTACK    0x6ffffffb
#define PT_HISUNW       0x6fffffff
#define PT_HIOS         0x6fffffff
#define PT_LOPROC       0x70000000
#define PT_HIPROC       0x7fffffff

#define PN_XNUM 0xffff

#define PF_X        1
#define PF_W        2
#define PF_R        4
#define PF_MASKOS   0x0ff00000
#define PF_MASKPROC 0xf0000000

#define R_X86_64_NONE            0
#define R_X86_64_64              1
#define R_X86_64_PC32            2
#define R_X86_64_GOT32           3
#define R_X86_64_PLT32           4
#define R_X86_64_COPY            5
#define R_X86_64_GLOB_DAT        6
#define R_X86_64_JUMP_SLOT       7
#define R_X86_64_RELATIVE        8
#define R_X86_64_GOTPCREL        9
#define R_X86_64_32              10
#define R_X86_64_32S             11
#define R_X86_64_16              12
#define R_X86_64_PC16            13
#define R_X86_64_8               14
#define R_X86_64_PC8             15
#define R_X86_64_DTPMOD64        16
#define R_X86_64_DTPOFF64        17
#define R_X86_64_TPOFF64         18
#define R_X86_64_TLSGD           19
#define R_X86_64_TLSLD           20
#define R_X86_64_DTPOFF32        21
#define R_X86_64_GOTTPOFF        22
#define R_X86_64_TPOFF32         23
#define R_X86_64_PC64            24
#define R_X86_64_GOTOFF64        25
#define R_X86_64_GOTPC32         26
#define R_X86_64_GOT64           27
#define R_X86_64_GOTPCREL64      28
#define R_X86_64_GOTPC64         29
#define R_X86_64_GOTPLT64        30
#define R_X86_64_PLTOFF64        31
#define R_X86_64_SIZE32          32
#define R_X86_64_SIZE64          33
#define R_X86_64_GOTPC32_TLSDESC 34
#define R_X86_64_TLSDESC_CALL    35
#define R_X86_64_TLSDESC         36
#define R_X86_64_IRELATIVE       37
#define R_X86_64_RELATIVE64      38
#define R_X86_64_GOTPCRELX       41 /* 6 bytes */
#define R_X86_64_REX_GOTPCRELX   42 /* 7 bytes */
#define R_X86_64_NUM             43

#define R_AARCH64_NONE   0
#define R_AARCH64_ABS64  257
#define R_AARCH64_ABS32  258
#define R_AARCH64_ABS16  259
#define R_AARCH64_PREL64 260
#define R_AARCH64_PREL32 261
#define R_AARCH64_PREL16 262

#define R_PPC_NONE   0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR24 2
#define R_PPC_ADDR16 3
#define R_PPC_REL32  26

#define R_PPC64_NONE   R_PPC_NONE
#define R_PPC64_ADDR32 R_PPC_ADDR32
#define R_PPC64_ADDR24 R_PPC_ADDR24
#define R_PPC64_ADDR16 R_PPC_ADDR16
#define R_PPC64_REL32  R_PPC_REL32

#define R_RISCV_NONE     0
#define R_RISCV_32       1
#define R_RISCV_64       2
#define R_RISCV_RELATIVE 3

#define R_390_NONE 0
#define R_390_8    1
#define R_390_12   2
#define R_390_16   3
#define R_390_32   4
#define R_390_PC32 5

#define STB_LOCAL      0
#define STB_GLOBAL     1
#define STB_WEAK       2
#define STB_NUM        3
#define STB_LOOS       10
#define STB_GNU_UNIQUE 10
#define STB_HIOS       12
#define STB_LOPROC     13
#define STB_HIPROC     15

#define STT_NOTYPE    0
#define STT_OBJECT    1
#define STT_FUNC      2
#define STT_SECTION   3
#define STT_FILE      4
#define STT_COMMON    5
#define STT_TLS       6
#define STT_NUM       7
#define STT_LOOS      10
#define STT_GNU_IFUNC 10
#define STT_HIOS      12
#define STT_LOPROC    13
#define STT_HIPROC    15

#define STV_DEFAULT   0
#define STV_INTERNAL  1
#define STV_HIDDEN    2
#define STV_PROTECTED 3

#define SHN_UNDEF     0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC    0xff00
#define SHN_BEFORE    0xff00
#define SHN_AFTER     0xff01
#define SHN_HIPROC    0xff1f
#define SHN_LOOS      0xff20
#define SHN_HIOS      0xff3f
#define SHN_ABS       0xfff1
#define SHN_COMMON    0xfff2
#define SHN_XINDEX    0xffff
#define SHN_HIRESERVE 0xffff

#define SHF_WRITE            (1 << 0)
#define SHF_ALLOC            (1 << 1)
#define SHF_EXECINSTR        (1 << 2)
#define SHF_MERGE            (1 << 4)
#define SHF_STRINGS          (1 << 5)
#define SHF_INFO_LINK        (1 << 6)
#define SHF_LINK_ORDER       (1 << 7)
#define SHF_OS_NONCONFORMING (1 << 8)
#define SHF_GROUP            (1 << 9)
#define SHF_TLS              (1 << 10)
#define SHF_COMPRESSED       (1 << 11)
#define SHF_MASKOS           0x0ff00000
#define SHF_MASKPROC         0xf0000000
#define SHF_ORDERED          (1 << 30)
#define SHF_EXCLUDE          (1U << 31)

#define ELFCOMPRESS_ZLIB   1
#define ELFCOMPRESS_LOOS   0x60000000
#define ELFCOMPRESS_HIOS   0x6fffffff
#define ELFCOMPRESS_LOPROC 0x70000000
#define ELFCOMPRESS_HIPROC 0x7fffffff

#define SHT_NULL           0
#define SHT_PROGBITS       1
#define SHT_SYMTAB         2
#define SHT_STRTAB         3
#define SHT_RELA           4
#define SHT_HASH           5
#define SHT_DYNAMIC        6
#define SHT_NOTE           7
#define SHT_NOBITS         8
#define SHT_REL            9
#define SHT_SHLIB          10
#define SHT_DYNSYM         11
#define SHT_INIT_ARRAY     14
#define SHT_FINI_ARRAY     15
#define SHT_PREINIT_ARRAY  16
#define SHT_GROUP          17
#define SHT_SYMTAB_SHNDX   18
#define SHT_NUM            19
#define SHT_LOOS           0x60000000
#define SHT_GNU_ATTRIBUTES 0x6ffffff5
#define SHT_GNU_HASH       0x6ffffff6
#define SHT_GNU_LIBLIST    0x6ffffff7
#define SHT_CHECKSUM       0x6ffffff8
#define SHT_LOSUNW         0x6ffffffa
#define SHT_SUNW_move      0x6ffffffa
#define SHT_SUNW_COMDAT    0x6ffffffb
#define SHT_SUNW_syminfo   0x6ffffffc
#define SHT_GNU_verdef     0x6ffffffd
#define SHT_GNU_verneed    0x6ffffffe
#define SHT_GNU_versym     0x6fffffff
#define SHT_HISUNW         0x6fffffff
#define SHT_HIOS           0x6fffffff
#define SHT_LOPROC         0x70000000
#define SHT_HIPROC         0x7fffffff
#define SHT_LOUSER         0x80000000
#define SHT_HIUSER         0x8fffffff

#define DT_NULL               0
#define DT_NEEDED             1
#define DT_PLTRELSZ           2
#define DT_PLTGOT             3
#define DT_HASH               4
#define DT_STRTAB             5
#define DT_SYMTAB             6
#define DT_RELA               7
#define DT_RELASZ             8
#define DT_RELAENT            9
#define DT_STRSZ              10
#define DT_SYMENT             11
#define DT_INIT               12
#define DT_FINI               13
#define DT_SONAME             14
#define DT_RPATH              15
#define DT_SYMBOLIC           16
#define DT_REL                17
#define DT_RELSZ              18
#define DT_RELENT             19
#define DT_PLTREL             20
#define DT_DEBUG              21
#define DT_TEXTREL            22
#define DT_JMPREL             23
#define DT_BIND_NOW           24
#define DT_INIT_ARRAY         25
#define DT_FINI_ARRAY         26
#define DT_INIT_ARRAYSZ       27
#define DT_FINI_ARRAYSZ       28
#define DT_RUNPATH            29
#define DT_FLAGS              30
#define DT_ENCODING           32
#define DT_PREINIT_ARRAY      32
#define DT_PREINIT_ARRAYSZ    33
#define DT_SYMTAB_SHNDX       34
#define DT_NUM                35
#define DT_LOOS               0x6000000d
#define DT_HIOS               0x6ffff000
#define DT_LOPROC             0x70000000
#define DT_HIPROC             0x7fffffff
#define DT_VALRNGLO           0x6ffffd00
#define DT_GNU_PRELINKED      0x6ffffdf5
#define DT_GNU_CONFLICTSZ     0x6ffffdf6
#define DT_GNU_LIBLISTSZ      0x6ffffdf7
#define DT_CHECKSUM           0x6ffffdf8
#define DT_PLTPADSZ           0x6ffffdf9
#define DT_MOVEENT            0x6ffffdfa
#define DT_MOVESZ             0x6ffffdfb
#define DT_FEATURE_1          0x6ffffdfc
#define DT_POSFLAG_1          0x6ffffdfd
#define DT_SYMINSZ            0x6ffffdfe
#define DT_SYMINENT           0x6ffffdff
#define DT_VALRNGHI           0x6ffffdff
#define DT_VALTAGIDX(tag)     (DT_VALRNGHI - (tag))
#define DT_VALNUM             12
#define DT_ADDRRNGLO          0x6ffffe00
#define DT_GNU_HASH           0x6ffffef5
#define DT_TLSDESC_PLT        0x6ffffef6
#define DT_TLSDESC_GOT        0x6ffffef7
#define DT_GNU_CONFLICT       0x6ffffef8
#define DT_GNU_LIBLIST        0x6ffffef9
#define DT_CONFIG             0x6ffffefa
#define DT_DEPAUDIT           0x6ffffefb
#define DT_AUDIT              0x6ffffefc
#define DT_PLTPAD             0x6ffffefd
#define DT_MOVETAB            0x6ffffefe
#define DT_SYMINFO            0x6ffffeff
#define DT_ADDRRNGHI          0x6ffffeff
#define DT_ADDRTAGIDX(tag)    (DT_ADDRRNGHI - (tag))
#define DT_ADDRNUM            11
#define DT_VERSYM             0x6ffffff0
#define DT_RELACOUNT          0x6ffffff9
#define DT_RELCOUNT           0x6ffffffa
#define DT_FLAGS_1            0x6ffffffb
#define DT_VERDEF             0x6ffffffc
#define DT_VERDEFNUM          0x6ffffffd
#define DT_VERNEED            0x6ffffffe
#define DT_VERNEEDNUM         0x6fffffff
#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag))
#define DT_VERSIONTAGNUM      16
#define DT_AUXILIARY          0x7ffffffd
#define DT_FILTER             0x7fffffff
#define DT_EXTRATAGIDX(tag)   ((Elf32_Word) - ((Elf32_Sword)(tag) << 1 >> 1) - 1)
#define DT_EXTRANUM           3

#define VER_NEED_NONE    0
#define VER_NEED_CURRENT 1
#define VER_NEED_NUM     2
#define VER_FLG_WEAK     0x2

#define ELF_NOTE_SOLARIS       "SUNW Solaris"
#define ELF_NOTE_GNU           "GNU"
#define ELF_NOTE_PAGESIZE_HINT 1
#define ELF_NOTE_ABI           NT_GNU_ABI_TAG
#define ELF_NOTE_OS_LINUX      0
#define ELF_NOTE_OS_GNU        1
#define ELF_NOTE_OS_SOLARIS2   2
#define ELF_NOTE_OS_FREEBSD    3

#define NT_GNU_ABI_TAG      1
#define NT_GNU_BUILD_ID     3
#define NT_GNU_GOLD_VERSION 4

#define EF_CPU32 0x00810000

#define DF_ORIGIN       0x00000001
#define DF_SYMBOLIC     0x00000002
#define DF_TEXTREL      0x00000004
#define DF_BIND_NOW     0x00000008
#define DF_STATIC_TLS   0x00000010
#define DF_1_NOW        0x00000001
#define DF_1_GLOBAL     0x00000002
#define DF_1_GROUP      0x00000004
#define DF_1_NODELETE   0x00000008
#define DF_1_LOADFLTR   0x00000010
#define DF_1_INITFIRST  0x00000020
#define DF_1_NOOPEN     0x00000040
#define DF_1_ORIGIN     0x00000080
#define DF_1_DIRECT     0x00000100
#define DF_1_TRANS      0x00000200
#define DF_1_INTERPOSE  0x00000400
#define DF_1_NODEFLIB   0x00000800
#define DF_1_NODUMP     0x00001000
#define DF_1_CONFALT    0x00002000
#define DF_1_ENDFILTEE  0x00004000
#define DF_1_DISPRELDNE 0x00008000
#define DF_1_DISPRELPND 0x00010000
#define DF_1_NODIRECT   0x00020000
#define DF_1_IGNMULDEF  0x00040000
#define DF_1_NOKSYMS    0x00080000
#define DF_1_NOHDR      0x00100000
#define DF_1_EDITED     0x00200000
#define DF_1_NORELOC    0x00400000
#define DF_1_SYMINTPOSE 0x00800000
#define DF_1_GLOBAUDIT  0x01000000
#define DF_1_SINGLETON  0x02000000
#define DF_1_STUB       0x04000000
#define DF_1_PIE        0x08000000
#define DTF_1_PARINIT   0x00000001
#define DTF_1_CONFEXP   0x00000002
#define DF_P1_LAZYLOAD  0x00000001
#define DF_P1_GROUPPERM 0x00000002

#define ELF64_ST_BIND(val)        (((unsigned char)(val)) >> 4)
#define ELF64_ST_TYPE(val)        ((val)&0xf)
#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf))
#define ELF64_ST_VISIBILITY(o)    ((o)&0x03)

#define ELF64_R_SYM(i)          ((i) >> 32)
#define ELF64_R_TYPE(i)         ((i)&0xffffffff)
#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type))

#define ELF64_M_SYM(info)       ((info) >> 8)
#define ELF64_M_SIZE(info)      ((unsigned char)(info))
#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))

#define NT_PRSTATUS         1
#define NT_PRFPREG          2
#define NT_FPREGSET         2
#define NT_PRPSINFO         3
#define NT_PRXREG           4
#define NT_TASKSTRUCT       4
#define NT_PLATFORM         5
#define NT_AUXV             6
#define NT_GWINDOWS         7
#define NT_ASRS             8
#define NT_PSTATUS          10
#define NT_PSINFO           13
#define NT_PRCRED           14
#define NT_UTSNAME          15
#define NT_LWPSTATUS        16
#define NT_LWPSINFO         17
#define NT_PRFPXREG         20
#define NT_SIGINFO          0x53494749
#define NT_FILE             0x46494c45
#define NT_PRXFPREG         0x46e62b7f
#define NT_PPC_VMX          0x100
#define NT_PPC_SPE          0x101
#define NT_PPC_VSX          0x102
#define NT_PPC_TAR          0x103
#define NT_PPC_PPR          0x104
#define NT_PPC_DSCR         0x105
#define NT_PPC_EBB          0x106
#define NT_PPC_PMU          0x107
#define NT_PPC_TM_CGPR      0x108
#define NT_PPC_TM_CFPR      0x109
#define NT_PPC_TM_CVMX      0x10a
#define NT_PPC_TM_CVSX      0x10b
#define NT_PPC_TM_SPR       0x10c
#define NT_PPC_TM_CTAR      0x10d
#define NT_PPC_TM_CPPR      0x10e
#define NT_PPC_TM_CDSCR     0x10f
#define NT_X86_XSTATE       0x202
#define NT_S390_HIGH_GPRS   0x300
#define NT_S390_TIMER       0x301
#define NT_S390_TODCMP      0x302
#define NT_S390_TODPREG     0x303
#define NT_S390_CTRS        0x304
#define NT_S390_PREFIX      0x305
#define NT_S390_LAST_BREAK  0x306
#define NT_S390_SYSTEM_CALL 0x307
#define NT_S390_TDB         0x308
#define NT_S390_VXRS_LOW    0x309
#define NT_S390_VXRS_HIGH   0x30a
#define NT_S390_GS_CB       0x30b
#define NT_S390_GS_BC       0x30c
#define NT_S390_RI_CB       0x30d
#define NT_ARM_VFP          0x400
#define NT_ARM_TLS          0x401
#define NT_ARM_HW_BREAK     0x402
#define NT_ARM_HW_WATCH     0x403
#define NT_ARM_SYSTEM_CALL  0x404
#define NT_ARM_SVE          0x405
#define NT_ARM_PAC_MASK     0x406
#define NT_METAG_CBUF       0x500
#define NT_METAG_RPIPE      0x501
#define NT_METAG_TLS        0x502
#define NT_ARC_V2           0x600
#define NT_VMCOREDD         0x700
#define NT_VERSION          1

#define VER_DEF_NONE      0
#define VER_DEF_CURRENT   1
#define VER_DEF_NUM       2
#define VER_FLG_BASE      0x1
#define VER_FLG_WEAK      0x2
#define VER_NDX_LOCAL     0
#define VER_NDX_GLOBAL    1
#define VER_NDX_LORESERVE 0xff00
#define VER_NDX_ELIMINATE 0xff01

#define LL_NONE           0
#define LL_EXACT_MATCH    (1 << 0)
#define LL_IGNORE_INT_VER (1 << 1)
#define LL_REQUIRE_MINOR  (1 << 2)
#define LL_EXPORTS        (1 << 3)
#define LL_DELAY_LOAD     (1 << 4)
#define LL_DELTA          (1 << 5)

#define R_BPF_NONE   0
#define R_BPF_MAP_FD 1



/*!BEGIN libc/elf/elf.h */

#define COSMOPOLITAN_LIBC_ELF_H_


/*!BEGIN libc/elf/struct/ehdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_EHDR_H_


/*!BEGIN libc/elf/scalar.h */

#define COSMOPOLITAN_LIBC_ELF_SCALAR_H_

#define Elf64_Addr    uint64_t
#define Elf64_Half    uint16_t
#define Elf64_Off     uint64_t
#define Elf64_Section uint16_t
#define Elf64_Sword   int32_t
#define Elf64_Sxword  int64_t
#define Elf64_Versym  Elf64_Half
#define Elf64_Word    uint32_t
#define Elf64_Xword   uint64_t
#define Elf_Symndx    uint32_t


/*
 * ELF header.
 */
typedef struct Elf64_Ehdr {

  /*
   * Leading bytes of ELF header.
   *
   * - `e_ident[0]` is always `127`
   * - `e_ident[1]` is always `'E'`
   * - `e_ident[2]` is always `'L'`
   * - `e_ident[3]` is always `'F'`
   *
   * - `e_ident[EI_CLASS]` is mandatory and should be:
   *
   *   - `ELFCLASSNONE64` if it's an Elf64 image
   *   - `ELFCLASSNONE32` if it's an Elf32 image
   *   - Otherwise we assume it's an Elf64 image
   *
   * - `e_ident[EI_DATA]` is advisory and could be:
   *
   *   - `ELFDATANONE` isn't strictly valid
   *   - `ELFDATA2LSB` for little-endian
   *   - `ELFDATA2MSB` for big-endian
   *
   * - `e_ident[EI_VERSION]` is advisory and should be:
   *
   *   - `EV_NONE` if it's zero or unspecified
   *   - `EV_CURRENT` for current ELF version (which is 1)
   *
   * - `e_ident[EI_OSABI]` is mandatory and could be:
   *
   *   - `ELFOSABI_NONE` is zero
   *   - `ELFOSABI_GNU` is for GNU
   *   - `ELFOSABI_SYSV` used by GNU
   *   - `ELFOSABI_LINUX` doesn't care
   *   - `ELFOSABI_FREEBSD` does care (recommended)
   *   - `ELFOSABI_NETBSD` doesn't care (see `PT_NOTE`)
   *   - `ELFOSABI_OPENBSD` doesn't care (see `PT_NOTE`)
   *
   * - `e_ident[EI_ABIVERSION]` is advisory
   *
   */
  unsigned char e_ident[16];

  /*
   * ELF image type.
   *
   * This field is mandatory and should be one of:
   *
   * - `ET_REL` for `.o` object files
   * - `ET_DYN` for `.so` files and `-pie` executables
   * - `ET_EXEC` for statically-linked executables
   *
   */
  Elf64_Half e_type;

  /*
   * ELF machine type.
   *
   * This field is mandatory and could be one of:
   *
   * - `EM_M32` for Bellmac
   * - `EM_X86_64` for Amd64
   * - `EM_AARCH64` for Arm64
   * - `EM_PPC64` for Raptors
   * - `EM_RISCV` for Berkeley
   * - `EM_S390` for System/360
   *
   */
  Elf64_Half e_machine;

  /*
   * ELF version.
   *
   * This field is advisory and could be:
   *
   * - `EV_NONE` if it's zero or unspecified
   * - `EV_CURRENT` for current ELF version (which is 1)
   *
   * @see `e_ident[EI_VERSION]`
   */
  Elf64_Word e_version;

  /*
   * ELF executable entrypoint.
   *
   * Static executables should use this field to store the virtual
   * address of the _start() function. This field may be zero, for
   * unspecified.
   */
  Elf64_Addr e_entry;

  /*
   * `Elf64_Phdr` file offset.
   *
   * This field is mandatory. Object files should set it to zero.
   */
  Elf64_Off e_phoff;

  /*
   * `Elf64_Shdr` file offset.
   *
   * This field is advisory.
   */
  Elf64_Off e_shoff;

  /*
   * ELF flags.
   *
   * This field is advisory.
   */
  Elf64_Word e_flags;

  /*
   * `Elf64_Ehdr` size.
   *
   * This field is advisory and should be 64.
   */
  Elf64_Half e_ehsize;

  /*
   * `Elf64_Phdr` element size.
   *
   * This field *is* cared about and should be set to 56. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_phentsize;

  /*
   * `Elf64_Phdr` array count.
   */
  Elf64_Half e_phnum;

  /*
   * `Elf64_Shdr` element size.
   *
   * This field is advisory and should be set to 64. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_shentsize;

  /*
   * `Elf64_Shdr` count.
   *
   * This field is advisory.
   */
  Elf64_Half e_shnum;

  /*
   * Section header index of section name string table.
   */
  Elf64_Half e_shstrndx;

} Elf64_Ehdr;



/*!BEGIN libc/elf/struct/phdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_PHDR_H_

typedef struct Elf64_Phdr {
  Elf64_Word p_type;
  Elf64_Word p_flags;
  Elf64_Off p_offset;
  Elf64_Addr p_vaddr;
  Elf64_Addr p_paddr;
  Elf64_Xword p_filesz;
  Elf64_Xword p_memsz;
  Elf64_Xword p_align;
} Elf64_Phdr;



/*!BEGIN libc/elf/struct/shdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SHDR_H_

/**
 * Section header.
 * @see https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html
 */
typedef struct Elf64_Shdr {

  Elf64_Word sh_name;

  Elf64_Word sh_type; /* SHT_{PROGBITS,NOBITS,STRTAB,SYMTAB,RELA,...} */

  Elf64_Xword sh_flags; /* SHF_{WRITE,ALLOC,EXECINSTR,TLS,MERGE,STRINGS,,...} */

  Elf64_Addr sh_addr;

  Elf64_Off sh_offset;

  Elf64_Xword sh_size;

  /*
   * Index of linked section header.
   *
   * If `sh_type` is `SHT_RELA` then `sh_link` holds the section header
   * index of the associated symbol table.
   *
   * If `sh_type` is `SHT_SYMTAB` then `sh_link` holds the section
   * header index of the associated string table.
   */
  Elf64_Word sh_link;

  /*
   * If `sh_type` is `SHT_RELA` then `sh_info` contains the index of the
   * section to which relocations apply.
   *
   * If `sh_type` is `SHT_SYMTAB` or `SHT_DYNSYM` then `sh_info`
   * contains an index that's one greater than symbol table index of
   * last `STB_LOCAL` symbol.
   */
  Elf64_Word sh_info;

  Elf64_Xword sh_addralign;

  Elf64_Xword sh_entsize;

} Elf64_Shdr;



/*!BEGIN libc/elf/struct/sym.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYM_H_

typedef struct Elf64_Sym {

  /*
   * Symbol name.
   *
   * This value is a byte offset into the `.strtab` section. If this
   * value is zero, then the symbol has no name.
   */
  Elf64_Word st_name;

  /*
   * Symbol type and binding.
   *
   * This value may be created using:
   *
   *     sym.st_info = ELF64_ST_INFO(bind, type);
   *
   * This value may be read using:
   *
   *     int bind = ELF64_ST_BIND(sym.st_info);
   *     int type = ELF64_ST_TYPE(sym.st_info);
   *
   * Where `bind` is typically:
   *
   * - `STB_LOCAL`
   * - `STB_GLOBAL`
   * - `STB_WEAK`
   *
   * Where `type` is typically:
   *
   * - `STT_NOTYPE`
   * - `STT_OBJECT`
   * - `STT_FUNC`
   * - `STT_SECTION`
   * - `STT_FILE`
   * - `STT_COMMON`
   * - `STT_TLS`
   */
  uint8_t st_info;

  /*
   * Symbol visibility.
   *
   * This value should be accessed using:
   *
   *     int visibility = ELF64_ST_VISIBILITY(sym.st_other);
   *
   * Where `visibility` is typically:
   *
   * - `STV_DEFAULT`
   * - `STV_INTERNAL`
   * - `STV_HIDDEN`
   * - `STV_PROTECTED`
   */
  uint8_t st_other;

  /*
   * Symbol section.
   *
   * If `st_shndx` is within `(SHN_UNDEF,SHN_LORESERVE)` then it holds
   * an index into the section header table.
   *
   * Otherwise `st_shndx` is usually one of the following magic numbers:
   *
   * - `SHN_UNDEF` means symbol is undefined
   * - `SHN_ABS` means symbol is a linker integer
   * - `SHN_COMMON` means symbol is defined traditionally
   */
  Elf64_Section st_shndx;

  /*
   * Symbol value.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is `SHN_COMMON`, then
   * `st_value` holds the required symbol alignment, or ≤ 1 if no
   * alignment is required.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is a section index, then
   * `st_value` holds a byte offset into the section memory.
   *
   * If `e_type` isn't `ET_REL` then `st_value` holds a virtual address.
   */
  Elf64_Addr st_value;

  /* byte length optionally set by .size directive */
  Elf64_Xword st_size;

} Elf64_Sym;

#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § executable linkable format                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
/* clang-format off */

bool32 IsElfSymbolContent(const Elf64_Sym *);
bool32 IsElf64Binary(const Elf64_Ehdr *, size_t);
char *GetElfStringTable(const Elf64_Ehdr *, size_t, const char *);
Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
/* clang-format on */


/*!BEGIN libc/elf/link.h */

#define COSMOPOLITAN_ELF_LINK_H_


/*!BEGIN libc/elf/struct/dyn.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DYN_H_

typedef struct Elf64_Dyn {
  Elf64_Sxword d_tag;
  union {
    Elf64_Xword d_val;
    Elf64_Addr d_ptr;
  } d_un;
} Elf64_Dyn;

COSMOPOLITAN_C_START_

#define ElfW(type) Elf64_##type

struct dl_phdr_info {
  Elf64_Addr dlpi_addr;
  const char *dlpi_name;
  const Elf64_Phdr *dlpi_phdr;
  Elf64_Half dlpi_phnum;
  unsigned long long int dlpi_adds;
  unsigned long long int dlpi_subs;
  size_t dlpi_tls_modid;
  void *dlpi_tls_data;
};

struct link_map {
  Elf64_Addr l_addr;
  char *l_name;
  Elf64_Dyn *l_ld;
  struct link_map *l_next;
  struct link_map *l_prev;
};

struct r_debug {
  int r_version;
  struct link_map *r_map;
  Elf64_Addr r_brk;
  enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state;
  Elf64_Addr r_ldbase;
};

int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/elf/struct/auxv.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_AUXV_H_

typedef struct Elf64_auxv_t {
  uint64_t a_type;
  union {
    uint64_t a_val;
  } a_un;
} Elf64_auxv_t;



/*!BEGIN libc/elf/struct/chdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_CHDR_H_

typedef struct Elf64_Chdr {
  Elf64_Word ch_type;
  Elf64_Word ch_reserved;
  Elf64_Xword ch_size;
  Elf64_Xword ch_addralign;
} Elf64_Chdr;



/*!BEGIN libc/elf/struct/lib.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_LIB_H_

typedef struct Elf64_Lib {
  Elf64_Word l_name;
  Elf64_Word l_time_stamp;
  Elf64_Word l_checksum;
  Elf64_Word l_version;
  Elf64_Word l_flags;
} Elf64_Lib;



/*!BEGIN libc/elf/struct/move.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_MOVE_H_

typedef struct Elf64_Move {
  Elf64_Xword m_value;
  Elf64_Xword m_info;
  Elf64_Xword m_poffset;
  Elf64_Half m_repeat;
  Elf64_Half m_stride;
} Elf64_Move;



/*!BEGIN libc/elf/struct/nhdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_NHDR_H_

typedef struct Elf64_Nhdr {
  Elf64_Word n_namesz;
  Elf64_Word n_descsz;
  Elf64_Word n_type;
} Elf64_Nhdr;



/*!BEGIN libc/elf/struct/rel.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_REL_H_

/*
 * ELF relocation.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_REL`.
 *
 * @see Elf64_Rela
 */
typedef struct Elf64_Rel {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` might be:
   *
   * - `R_X86_64_64`
   * - `R_X86_64_PC32`
   * - `R_X86_64_GOTPCRELX`
   * - `R_AARCH64_ABS64`
   *
   * Each relocation type specifies a mathematical formula that's used
   * to compute the appropriate value for the fixed-up object code. If
   * it needs an addend, then this struct doesn't have one, but it can
   * still be embedded by the compiler in the location to be modified.
   */
  Elf64_Xword r_info;

} Elf64_Rel;



/*!BEGIN libc/elf/struct/rela.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_RELA_H_

/*
 * ELF relocation w/ explicit addend.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_RELA`
 *
 * @see Elf64_Rel
 */
typedef struct Elf64_Rela {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` will likely be:
   *
   * - `R_X86_64_PC32`
   * - `R_X86_64_PLT32`
   * - `R_X86_64_32`
   * - `R_X86_64_64`
   * - `R_X86_64_32S`
   * - `R_X86_64_8`
   * - `R_X86_64_16`
   * - `R_X86_64_DTPOFF32`
   * - `R_X86_64_GOTPCREL`
   * - `R_X86_64_PC16`
   * - `R_X86_64_REX_GOTPCRELX`
   * - `R_X86_64_TPOFF32`
   *
   */
  Elf64_Xword r_info;

  /*
   * Relocation parameter.
   *
   * Each relocation type has its own mathematical formula, which should
   * incorporate this value in its own unique way.
   */
  Elf64_Sxword r_addend;

} Elf64_Rela;



/*!BEGIN libc/elf/struct/syminfo.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYMINFO_H_

typedef struct Elf64_Syminfo {
  Elf64_Half si_boundto;
  Elf64_Half si_flags;
} Elf64_Syminfo;



/*!BEGIN libc/elf/struct/verdaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDAUX_H_

typedef struct Elf64_Verdaux {
  Elf64_Word vda_name;
  Elf64_Word vda_next;
} Elf64_Verdaux;



/*!BEGIN libc/elf/struct/verdef.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDEF_H_

typedef struct Elf64_Verdef {
  Elf64_Half vd_version;
  Elf64_Half vd_flags;
  Elf64_Half vd_ndx;
  Elf64_Half vd_cnt;
  Elf64_Word vd_hash;
  Elf64_Word vd_aux;
  Elf64_Word vd_next;
} Elf64_Verdef;



/*!BEGIN libc/elf/struct/vernaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNAUX_H_

typedef struct Elf64_Vernaux {
  Elf64_Word vna_hash;
  Elf64_Half vna_flags;
  Elf64_Half vna_other;
  Elf64_Word vna_name;
  Elf64_Word vna_next;
} Elf64_Vernaux;



/*!BEGIN libc/elf/struct/verneed.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNEED_H_

typedef struct Elf64_Verneed {
  Elf64_Half vn_version;
  Elf64_Half vn_cnt;
  Elf64_Word vn_file;
  Elf64_Word vn_aux;
  Elf64_Word vn_next;
} Elf64_Verneed;



/*!BEGIN libc/fmt/conv.h */

#define COSMOPOLITAN_LIBC_FMT_CONV_H_
COSMOPOLITAN_C_START_

int abs(int) libcesque pureconst;
long labs(long) libcesque pureconst;
long long llabs(long long) libcesque pureconst;
libcesque intmax_t imaxabs(intmax_t) pureconst;
int atoi(const char *) paramsnonnull() libcesque;
long atol(const char *) paramsnonnull() libcesque;
long long atoll(const char *) paramsnonnull() libcesque;
unsigned long strtoul(const char *, char **, int) libcesque paramsnonnull((1));
long long strtoll(const char *, char **, int) libcesque paramsnonnull((1));
unsigned long long strtoull(const char *, char **, int) paramsnonnull((1));
intmax_t strtoimax(const char *, char **, int) libcesque paramsnonnull((1));
uintmax_t strtoumax(const char *, char **, int) libcesque paramsnonnull((1));
intmax_t wcstoimax(const wchar_t *, wchar_t **, int) libcesque;
uintmax_t wcstoumax(const wchar_t *, wchar_t **, int) libcesque;
long wcstol(const wchar_t *, wchar_t **, int) libcesque;
unsigned long wcstoul(const wchar_t *, wchar_t **, int) libcesque;
long strtol(const char *, char **, int) paramsnonnull((1)) libcesque;
long sizetol(const char *, long) paramsnonnull() libcesque;
char *sizefmt(char *, uint64_t, uint64_t) libcesque;
long long wcstoll(const wchar_t *, wchar_t **, int) libcesque;
unsigned long long wcstoull(const wchar_t *, wchar_t **, int) libcesque;
int wcscoll(const wchar_t *, const wchar_t *) libcesque;
size_t wcsxfrm(wchar_t *, const wchar_t *, size_t) libcesque;

double atof(const char *) libcesque;
float strtof(const char *, char **) libcesque;
double strtod(const char *, char **) libcesque;
long double strtold(const char *, char **) libcesque;
float wcstof(const wchar_t *, wchar_t **) libcesque;
double wcstod(const wchar_t *, wchar_t **) libcesque;
long double wcstold(const wchar_t *, wchar_t **) libcesque;

#ifdef _COSMO_SOURCE
char *stripext(char *) libcesque;
char *stripexts(char *) libcesque;
#endif /* _COSMO_SOURCE */

typedef struct {
  int quot;
  int rem;
} div_t;

typedef struct {
  long int quot;
  long int rem;
} ldiv_t;

typedef struct {
  long long int quot;
  long long int rem;
} lldiv_t;

typedef struct {
  intmax_t quot;
  intmax_t rem;
} imaxdiv_t;

libcesque div_t div(int, int) pureconst;
libcesque ldiv_t ldiv(long, long) pureconst;
libcesque lldiv_t lldiv(long long, long long) pureconst;
libcesque imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;

#if __STDC_VERSION__ + 0 >= 199901L
#define div(num, den)   ((div_t){(num) / (den), (num) % (den)})
#define ldiv(num, den)  ((ldiv_t){(num) / (den), (num) % (den)})
#define lldiv(num, den) ((lldiv_t){(num) / (den), (num) % (den)})
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/fmt/itoa.h */

#ifndef COSMOPOLITAN_LIBC_FMT_ITOA_H_
#define COSMOPOLITAN_LIBC_FMT_ITOA_H_
COSMOPOLITAN_C_START_

#define LengthInt64           __LengthInt64
#define LengthUint64          __LengthUint64
#define LengthInt64Thousands  __LengthInt64Thousands
#define LengthUint64Thousands __LengthUint64Thousands
#define FormatInt32           __FormatInt32
#define FormatUint32          __FormatUint32
#define FormatInt64           __FormatInt64
#define FormatUint64          __FormatUint64
#define FormatInt64Thousands  __FormatInt64Thousands
#define FormatUint64Thousands __FormatUint64Thousands
#define FormatOctal32         __FormatOctal32
#define FormatOctal64         __FormatOctal64
#define FormatBinary64        __FormatBinary64
#define FormatHex64           __FormatHex64
#define FormatFlex64          __FormatFlex64
#define uint64toarray_radix16 __uint64toarray_radix16
#define uint64toarray_fixed16 __uint64toarray_fixed16
#define uint64toarray_radix8  __uint64toarray_radix8

libcesque unsigned LengthInt64(int64_t) pureconst;
libcesque unsigned LengthUint64(uint64_t) pureconst;
libcesque unsigned LengthInt64Thousands(int64_t) pureconst;
libcesque unsigned LengthUint64Thousands(uint64_t) pureconst;
libcesque char *FormatInt32(char[hasatleast 12], int32_t);
libcesque char *FormatUint32(char[hasatleast 12], uint32_t);
libcesque char *FormatInt64(char[hasatleast 21], int64_t);
libcesque char *FormatUint64(char[hasatleast 21], uint64_t);
libcesque char *FormatInt64Thousands(char[hasatleast 27], int64_t);
libcesque char *FormatUint64Thousands(char[hasatleast 27], uint64_t);
libcesque char *FormatOctal32(char[hasatleast 13], uint32_t, bool32);
libcesque char *FormatOctal64(char[hasatleast 24], uint64_t, bool32);
libcesque char *FormatBinary64(char[hasatleast 67], uint64_t, char);
libcesque char *FormatHex64(char[hasatleast 19], uint64_t, char);
libcesque char *FormatFlex64(char[hasatleast 24], int64_t, char);
libcesque size_t uint64toarray_radix16(uint64_t, char[hasatleast 17]);
libcesque size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
libcesque size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_ITOA_H_ */


/*!BEGIN libc/fmt/leb128.h */

#ifndef COSMOPOLITAN_LIBC_FMT_LEB128_H_
#define COSMOPOLITAN_LIBC_FMT_LEB128_H_
COSMOPOLITAN_C_START_

#define sleb64   __sleb64
#define zleb64   __zleb64
#define uleb64   __uleb64
#define unzleb64 __unzleb64
#define unuleb64 __unuleb64

char *sleb64(char *, int64_t) libcesque;
char *zleb64(char[hasatleast 10], int64_t) libcesque;
char *uleb64(char[hasatleast 10], uint64_t) libcesque;
int unzleb64(const char *, size_t, int64_t *) libcesque;
int unuleb64(const char *, size_t, uint64_t *) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_LEB128_H_ */


/*!BEGIN libc/fmt/libgen.h */

#define COSMOPOLITAN_LIBC_FMT_LIBGEN_H_
COSMOPOLITAN_C_START_

char *dirname(char *) libcesque;
char *basename(char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/dlopen/dlfcn.h */

#define COSMOPOLITAN_LIBC_DLFCN_H_

#define RTLD_LOCAL  0
#define RTLD_LAZY   1
#define RTLD_NOW    2
#define RTLD_GLOBAL 256

COSMOPOLITAN_C_START_

#define RTLD_NEXT    ((void *)-1)
#define RTLD_DEFAULT ((void *)0)

char *dlerror(void) libcesque;
void *dlopen(const char *, int) libcesque;
void *dlsym(void *, const char *) libcesque;
int dlclose(void *) libcesque;

char *cosmo_dlerror(void) libcesque;
void *cosmo_dlopen(const char *, int) libcesque;
void *cosmo_dlsym(void *, const char *) libcesque;
void *cosmo_dltramp(void *) libcesque;
int cosmo_dlclose(void *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/asancodes.h */

#define COSMOPOLITAN_LIBC_INTRIN_ASANCODES_H_

#define kAsanScale           3
#define kAsanMagic           0x7fff8000
#define kAsanNullPage        -1  /* ∅ 0xff */
#define kAsanProtected       -2  /* P 0xfe */
#define kAsanHeapFree        -3  /* F 0xfd */
#define kAsanHeapRelocated   -4  /* R 0xfc */
#define kAsanAllocaOverrun   -5  /* 𝑂 0xfb */
#define kAsanHeapUnderrun    -6  /* U 0xfa */
#define kAsanHeapOverrun     -7  /* O 0xf9 */
#define kAsanStackUnscoped   -8  /* s 0xf8 */
#define kAsanStackOverflow   -9  /* ! 0xf7 */
#define kAsanGlobalOrder     -10 /* I 0xf6 */
#define kAsanStackFree       -11 /* r 0xf5 */
#define kAsanStackPartial    -12 /* p 0xf4 */
#define kAsanStackOverrun    -13 /* o 0xf3 */
#define kAsanStackMiddle     -14 /* m 0xf2 */
#define kAsanStackUnderrun   -15 /* u 0xf1 */
#define kAsanAllocaUnderrun  -16 /* 𝑈 0xf0 */
#define kAsanUnmapped        -17 /* M 0xef */
#define kAsanGlobalRedzone   -18 /* G 0xee */
#define kAsanGlobalGone      -19 /* 𝐺 0xed */
#define kAsanGlobalUnderrun  -20 /* μ 0xec */
#define kAsanGlobalOverrun   -21 /* Ω 0xeb */
#define kAsanMmapSizeOverrun -22 /* Z 0xea */



/*!BEGIN libc/intrin/asmflag.h */

#define COSMOPOLITAN_LIBC_BITS_ASMFLAG_H_

/*
 * Constraints for virtual machine flags.
 * @note we beseech clang devs for flag constraints
 */
#ifdef __GCC_ASM_FLAG_OUTPUTS__ /* GCC6+ CLANG10+ */
#define CFLAG_CONSTRAINT  "=@ccc"
#define CFLAG_ASM(OP)     OP
#define ZFLAG_CONSTRAINT  "=@ccz"
#define ZFLAG_ASM(OP)     OP
#define OFLAG_CONSTRAINT  "=@cco"
#define OFLAG_ASM(OP)     OP
#define SFLAG_CONSTRAINT  "=@ccs"
#define SFLAG_ASM(SP)     SP
#define ABOVE_CONSTRAINT  "=@cca" /* i.e. !ZF && !CF */
#define ABOVEFLAG_ASM(OP) OP
#else
#define CFLAG_CONSTRAINT  "=q"
#define CFLAG_ASM(OP)     OP "\n\tsetc\t%b0"
#define ZFLAG_CONSTRAINT  "=q"
#define ZFLAG_ASM(OP)     OP "\n\tsetz\t%b0"
#define OFLAG_CONSTRAINT  "=q"
#define OFLAG_ASM(OP)     OP "\n\tseto\t%b0"
#define SFLAG_CONSTRAINT  "=q"
#define SFLAG_ASM(SP)     OP "\n\tsets\t%b0"
#define ABOVE_CONSTRAINT  "=@cca"
#define ABOVEFLAG_ASM(OP) OP "\n\tseta\t%b0"
#endif



/*!BEGIN libc/intrin/atomic.h */

#define COSMOPOLITAN_LIBC_BITS_ATOMIC_H_

/**
 * @fileoverview Cosmopolitan C11 Atomics Library
 *
 * - Forty-two different ways to say MOV.
 * - Fourteen different ways to say XCHG.
 * - Twenty different ways to say LOCK CMPXCHG.
 *
 * @see libc/atomic.h
 */

typedef int memory_order;

enum {
  memory_order_relaxed,
  memory_order_consume,
  memory_order_acquire,
  memory_order_release,
  memory_order_acq_rel,
  memory_order_seq_cst,
};

#define ATOMIC_VAR_INIT(...)     __VA_ARGS__
#define atomic_is_lock_free(obj) ((void)(obj), sizeof(obj) <= sizeof(void *))

#define atomic_flag      atomic_bool
#define ATOMIC_FLAG_INIT ATOMIC_VAR_INIT(0)
#define atomic_flag_test_and_set_explicit(x, order) \
  atomic_exchange_explicit(x, 1, order)
#define atomic_flag_clear_explicit(x, order) atomic_store_explicit(x, 0, order)

#define atomic_compare_exchange_strong(pObject, pExpected, desired) \
  atomic_compare_exchange_strong_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_compare_exchange_weak(pObject, pExpected, desired) \
  atomic_compare_exchange_weak_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_exchange(pObject, desired) \
  atomic_exchange_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_fetch_add(pObject, operand) \
  atomic_fetch_add_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_and(pObject, operand) \
  atomic_fetch_and_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_or(pObject, operand) \
  atomic_fetch_or_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_sub(pObject, operand) \
  atomic_fetch_sub_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_xor(pObject, operand) \
  atomic_fetch_xor_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_load(pObject) atomic_load_explicit(pObject, memory_order_seq_cst)
#define atomic_store(pObject, desired) \
  atomic_store_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_flag_test_and_set(x) \
  atomic_flag_test_and_set_explicit(x, memory_order_seq_cst)
#define atomic_flag_clear(x) atomic_flag_clear_explicit(x, memory_order_seq_cst)

#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)

#define atomic_init(obj, value)    __c11_atomic_init(obj, value)
#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
#define atomic_signal_fence(order) __c11_atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(object, expected, desired, \
                                                success, failure)          \
  __c11_atomic_compare_exchange_strong(object, expected, desired, success, \
                                       failure)
#define atomic_compare_exchange_weak_explicit(object, expected, desired, \
                                              success, failure)          \
  __c11_atomic_compare_exchange_weak(object, expected, desired, success, \
                                     failure)
#define atomic_exchange_explicit(object, desired, order) \
  __c11_atomic_exchange(object, desired, order)
#define atomic_fetch_add_explicit(object, operand, order) \
  __c11_atomic_fetch_add(object, operand, order)
#define atomic_fetch_and_explicit(object, operand, order) \
  __c11_atomic_fetch_and(object, operand, order)
#define atomic_fetch_or_explicit(object, operand, order) \
  __c11_atomic_fetch_or(object, operand, order)
#define atomic_fetch_sub_explicit(object, operand, order) \
  __c11_atomic_fetch_sub(object, operand, order)
#define atomic_fetch_xor_explicit(object, operand, order) \
  __c11_atomic_fetch_xor(object, operand, order)
#define atomic_load_explicit(object, order) __c11_atomic_load(object, order)
#define atomic_store_explicit(object, desired, order) \
  __c11_atomic_store(object, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __atomic_thread_fence(order)
#define atomic_signal_fence(order) __atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(pObject, pExpected, desired, \
                                                success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 0, success, failure)
#define atomic_compare_exchange_weak_explicit(pObject, pExpected, desired, \
                                              success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 1, success, failure)
#define atomic_exchange_explicit(pObject, desired, order) \
  __atomic_exchange_n(pObject, desired, order)
#define atomic_fetch_add_explicit(pObject, operand, order) \
  __atomic_fetch_add(pObject, operand, order)
#define atomic_fetch_and_explicit(pObject, operand, order) \
  __atomic_fetch_and(pObject, operand, order)
#define atomic_fetch_or_explicit(pObject, operand, order) \
  __atomic_fetch_or(pObject, operand, order)
#define atomic_fetch_sub_explicit(pObject, operand, order) \
  __atomic_fetch_sub(pObject, operand, order)
#define atomic_fetch_xor_explicit(pObject, operand, order) \
  __atomic_fetch_xor(pObject, operand, order)
#define atomic_load_explicit(pObject, order) __atomic_load_n(pObject, order)
#define atomic_store_explicit(pObject, desired, order) \
  __atomic_store_n(pObject, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __sync_synchronize()
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define __atomic_apply_stride(object, operand) \
  (((__typeof__(*(object)))0) + (operand))
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    __typeof__(expected) __ep = (expected);                                   \
    __typeof__(*__ep) __e = *__ep;                                            \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    (*__ep = __sync_val_compare_and_swap(object, __e, desired)) == __e;       \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#if __has_builtin(__sync_swap)
#define atomic_exchange_explicit(object, desired, order) \
  ((void)(order), __sync_swap(object, desired))
#else
#define atomic_exchange_explicit(object, desired, order) \
  __extension__({                                        \
    __typeof__(object) __o = (object);                   \
    __typeof__(desired) __d = (desired);                 \
    (void)(order);                                       \
    __sync_synchronize();                                \
    __sync_lock_test_and_set(__o, __d);                  \
  })
#endif
#define atomic_fetch_add_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_add(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_and_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_and(object, operand))
#define atomic_fetch_or_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_or(object, operand))
#define atomic_fetch_sub_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_sub(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_xor_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_xor(object, operand))
#define atomic_load_explicit(object, order) \
  ((void)(order), __sync_fetch_and_add(object, 0))
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#elif defined(__GNUC__) && defined(__x86__) /* x86 with gcc 4.0 and earlier */

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __asm__ volatile("mfence" ::: "memory")
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    char DidIt;                                                               \
    __typeof__(object) IfThing = (object);                                    \
    __typeof__(IfThing) IsEqualToMe = (expected);                             \
    __typeof__(*IfThing) ReplaceItWithMe = (desired), ax;                     \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    __asm__ volatile("lock cmpxchg\t%3,(%1)\n\t"                              \
                     "setz\t%b0"                                              \
                     : "=q"(DidIt), "=r"(IfThing), "+a"(ax)                   \
                     : "r"(ReplaceItWithMe), "2"(*IsEqualToMe)                \
                     : "memory", "cc");                                       \
    *IsEqualToMe = ax;                                                        \
    DidIt;                                                                    \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#define atomic_exchange_explicit(object, desired, order)                \
  __extension__({                                                       \
    __typeof__(object) __o = (object);                                  \
    __typeof__(*__o) __d = (desired);                                   \
    (void)(order);                                                      \
    __asm__ volatile("xchg\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                \
  })
#define atomic_fetch_add_explicit(object, operand, order)                    \
  __extension__({                                                            \
    __typeof__(object) __o = (object);                                       \
    __typeof__(*__o) __d = (desired);                                        \
    (void)(order);                                                           \
    __asm__ volatile("lock xadd\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                     \
  })
#define atomic_fetch_sub_explicit(object, operand, order) \
  atomic_fetch_add_explicit(object, -(operand), order)
#define atomic_load_explicit(object, order) \
  atomic_fetch_add_explicit(object, 0, order)
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#else /* non-gcc or old gcc w/o x86 */
#error "atomic operations not supported with this compiler and/or architecture"
#endif



/*!BEGIN libc/intrin/bsf.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
COSMOPOLITAN_C_START_

libcesque int bsf(int) pureconst;
libcesque int bsfl(long) pureconst;
libcesque int bsfll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsf(x)   __builtin_ctz(x)
#define bsfl(x)  __builtin_ctzl(x)
#define bsfll(x) __builtin_ctzll(x)
#endif

/* deprecated */
#define _bsf(x)   bsf(x)
#define _bsfl(x)  bsfl(x)
#define _bsfll(x) bsfll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */


/*!BEGIN libc/intrin/bsr.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
COSMOPOLITAN_C_START_

libcesque int bsr(int) pureconst;
libcesque int bsrl(long) pureconst;
libcesque int bsrll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsr(x)   (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
#define bsrl(x)  (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
#define bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
#endif

/* deprecated */
#define _bsr(x)   bsr(x)
#define _bsrl(x)  bsrl(x)
#define _bsrll(x) bsrll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */


/*!BEGIN libc/intrin/bswap.h */

#define COSMOPOLITAN_LIBC_BITS_BSWAP_H_
COSMOPOLITAN_C_START_

libcesque uint16_t bswap_16(uint16_t) pureconst;
libcesque uint32_t bswap_32(uint32_t) pureconst;
libcesque uint64_t bswap_64(uint64_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bswap_16(x) __builtin_bswap16(x)
#define bswap_32(x) __builtin_bswap32(x)
#define bswap_64(x) __builtin_bswap64(x)
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/cmpxchg.h */

#define COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
COSMOPOLITAN_C_START_

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME)                       \
  ({                                                                          \
    bool32 DidIt;                                                             \
    autotype(IFTHING) IfThing = (IFTHING);                                    \
    typeof(*IfThing) IsEqualToMe = (ISEQUALTOME);                             \
    typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME);                     \
    asm volatile(ZFLAG_ASM("cmpxchg\t%3,%1")                                  \
                 : ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
                 : "r"(ReplaceItWithMe)                                       \
                 : "cc");                                                     \
    DidIt;                                                                    \
  })
#else
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
  (*(IFTHING) == (ISEQUALTOME) ? (*(IFTHING) = (REPLACEITWITHME), 1) : 0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/dll.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define dll_make_first   __dll_make_first
#define dll_make_last    __dll_make_last
#define dll_remove       __dll_remove
#define dll_splice_after __dll_splice_after
COSMOPOLITAN_C_START_

#define DLL_CONTAINER(t, f, p) ((t *)(((char *)(p)) - offsetof(t, f)))

struct Dll {
  struct Dll *next;
  struct Dll *prev;
};

static inline void dll_init(struct Dll *e) {
  e->next = e;
  e->prev = e;
}

static inline int dll_is_alone(struct Dll *e) {
  return e->next == e && e->prev == e;
}

static inline int dll_is_empty(struct Dll *list) {
  return !list;
}

static inline struct Dll *dll_last(struct Dll *list) {
  return list;
}

static inline struct Dll *dll_first(struct Dll *list) {
  struct Dll *first = 0;
  if (list) first = list->next;
  return first;
}

static inline struct Dll *dll_next(struct Dll *list, struct Dll *e) {
  struct Dll *next = 0;
  if (e != list) next = e->next;
  return next;
}

static inline struct Dll *dll_prev(struct Dll *list, struct Dll *e) {
  struct Dll *prev = 0;
  if (e != list->next) prev = e->prev;
  return prev;
}

void dll_remove(struct Dll **, struct Dll *) paramsnonnull() libcesque;
void dll_make_last(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_make_first(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */


/*!BEGIN libc/intrin/hilbert.h */

#define COSMOPOLITAN_LIBC_BITS_HILBERT_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#define hilbert   __hilbert
#define unhilbert __unhilbert

libcesque long hilbert(long, long, long) pureconst;
libcesque axdx_t unhilbert(long, long) pureconst;

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/kprintf.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
#define COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_

#define klog         __klog
#define kprintf      __kprintf
#define ksnprintf    __ksnprintf
#define kvprintf     __kvprintf
#define kvsnprintf   __kvsnprintf
#define kloghandle   __kloghandle
#define kisdangerous __kisdangerous
#define uprintf      __uprintf
#define uvprintf     __uvprintf

#if !(__ASSEMBLER__ + __LINKER__ + 0)

COSMOPOLITAN_C_START_

void kprintf(const char *, ...) libcesque;
size_t ksnprintf(char *, size_t, const char *, ...) libcesque;
void kvprintf(const char *, va_list) libcesque;
size_t kvsnprintf(char *, size_t, const char *, va_list) libcesque;

bool32 kisdangerous(const void *) libcesque;

void klog(const char *, size_t) libcesque;
void _klog_serial(const char *, size_t) libcesque;
long kloghandle(void) libcesque;

void uprintf(const char *, ...) libcesque;
void uvprintf(const char *, va_list) libcesque;

#ifndef TINY
#define KINFOF(FMT, ...)                                         \
  do {                                                           \
    uprintf("\r\e[35m%s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                      \
  } while (0)
#define KWARNF(FMT, ...)                                                  \
  do {                                                                    \
    uprintf("\r\e[94;49mwarn: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                               \
  } while (0)
#else
#define KINFOF(FMT, ...) ((void)0)
#define KWARNF(FMT, ...) ((void)0)
#endif
#define KDIEF(FMT, ...)                                                     \
  do {                                                                      \
    kprintf("\r\e[30;101mfatal: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                                 \
    for (;;) asm volatile("cli\n\thlt");                                    \
  } while (0)

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_ */


/*!BEGIN libc/intrin/likely.h */

#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
#ifdef _COSMO_SOURCE

#define LIKELY(x)   __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_LIKELY(x) __builtin_expect_with_probability(!!(x), 1, 0.999)
#else
#define VERY_LIKELY(x) LIKELY(x)
#endif

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_UNLIKELY(x) __builtin_expect_with_probability(!!(x), 0, 0.999)
#else
#define VERY_UNLIKELY(x) UNLIKELY(x)
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/macros.h */

#define COSMOPOLITAN_LIBC_INTRIN_MACROS_H_


/*!BEGIN libc/nexgen32e/x86feature.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86FEATURE_H_
#ifdef __x86_64__


/*!BEGIN libc/nexgen32e/kcpuids.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_KCPUIDS_H_

#define KCPUIDS_0H        0
#define KCPUIDS_1H        1
#define KCPUIDS_2H        2
#define KCPUIDS_7H        3
#define KCPUIDS_80000001H 4
#define KCPUIDS_80000007H 5
#define KCPUIDS_16H       6
#define KCPUIDS_7H_1H     7
#define KCPUIDS_LEN       8
#define KCPUIDS_6H        -1 /* TBD: Thermal and Power Management */
#define KCPUIDS_DH        -1 /* TBD: Extended state features */
#define KCPUIDS_80000008H -1 /* TBD: AMD Miscellaneous */
#define KCPUIDS_8000000AH -1 /* TBD: AMD SVM */

#define KCPUIDS_EAX 0
#define KCPUIDS_EBX 1
#define KCPUIDS_ECX 2
#define KCPUIDS_EDX 3

#define KCPUIDS(LEAF, REG) _KCPUIDS(LEAF, REG)
#ifdef __ASSEMBLER__
#define _KCPUIDS(LEAF, REG) KCPUIDS_##LEAF * 16 + KCPUIDS_##REG * 4
#else
#define _KCPUIDS(LEAF, REG) kCpuids[KCPUIDS_##LEAF][KCPUIDS_##REG]
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const unsigned kCpuids[KCPUIDS_LEN][4];

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nexgen32e/x86compiler.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86COMPILER_H_
#ifdef __x86_64__

/**
 * @fileoverview x86 cpu feature compile-time requirement detection.
 * @see -march=native, -mavx2, etc.
 */

#ifdef __AES__
#define _X86_CC_AES 1
#else
#define _X86_CC_AES 0
#endif

#ifdef __AVX__
#define _X86_CC_AVX 1
#else
#define _X86_CC_AVX 0
#endif

#ifdef __AVX2__
#define _X86_CC_AVX2 1
#else
#define _X86_CC_AVX2 0
#endif

#ifdef __F16C__
#define _X86_CC_F16C 1
#else
#define _X86_CC_F16C 0
#endif

#ifdef __AVXVNNI__
#define _X86_CC_AVXVNNI 1
#else
#define _X86_CC_AVXVNNI 0
#endif

#ifdef __AVXVNNIINT8__
#define _X86_CC_AVXVNNIINT8 1
#else
#define _X86_CC_AVXVNNIINT8 0
#endif

#ifdef __AVXVNNIINT16__
#define _X86_CC_AVXVNNIINT16 1
#else
#define _X86_CC_AVXVNNIINT16 0
#endif

#ifdef __AVX512F__
#define _X86_CC_AVX512F 1
#else
#define _X86_CC_AVX512F 0
#endif

#ifdef __AVX512BF16__
#define _X86_CC_AVX512BF16 1
#else
#define _X86_CC_AVX512BF16 0
#endif

#ifdef __AVX512FP16__
#define _X86_CC_AVX512FP16 1
#else
#define _X86_CC_AVX512FP16 0
#endif

#ifdef __AVX512VBMI__
#define _X86_CC_AVX512VBMI 1
#else
#define _X86_CC_AVX512VBMI 0
#endif

#ifdef __AVX512VNNI__
#define _X86_CC_AVX512VNNI 1
#else
#define _X86_CC_AVX512VNNI 0
#endif

#ifdef __AVX5124VNNIW__
#define _X86_CC_AVX5124VNNIW 1
#else
#define _X86_CC_AVX5124VNNIW 0
#endif

#ifdef __ABM__
#define _X86_CC_ABM 1
#else
#define _X86_CC_ABM 0
#endif

#ifdef __BMI__
#define _X86_CC_BMI 1
#else
#define _X86_CC_BMI 0
#endif

#ifdef __BMI2__
#define _X86_CC_BMI2 1
#else
#define _X86_CC_BMI2 0
#endif

#ifdef __FMA__
#define _X86_CC_FMA 1
#else
#define _X86_CC_FMA 0
#endif

#ifdef __ADX__
#define _X86_CC_ADX 1
#else
#define _X86_CC_ADX 0
#endif

#ifdef __PCLMUL__
#define _X86_CC_PCLMUL 1
#else
#define _X86_CC_PCLMUL 0
#endif

#ifdef __POPCNT__
#define _X86_CC_POPCNT 1
#else
#define _X86_CC_POPCNT 0
#endif

#ifdef __RDRND__
#define _X86_CC_RDRND 1
#else
#define _X86_CC_RDRND 0
#endif

#ifdef __RDSEED__
#define _X86_CC_RDSEED 1
#else
#define _X86_CC_RDSEED 0
#endif

#ifdef __SHA__
#define _X86_CC_SHA 1
#else
#define _X86_CC_SHA 0
#endif

#ifdef __SSSE3__
#define _X86_CC_SSSE3 1
#else
#define _X86_CC_SSSE3 0
#endif

#ifdef __SSE__
#define _X86_CC_SSE 1
#else
#define _X86_CC_SSE 0
#endif

#ifdef __SSE2__
#define _X86_CC_SSE2 1
#else
#define _X86_CC_SSE2 0
#endif

#ifdef __SSE3__
#define _X86_CC_SSE3 1
#else
#define _X86_CC_SSE3 0
#endif

#ifdef __SSE4_1__
#define _X86_CC_SSE4_1 1
#else
#define _X86_CC_SSE4_1 0
#endif

#ifdef __SSE4_2__
#define _X86_CC_SSE4_2 1
#else
#define _X86_CC_SSE4_2 0
#endif

#ifdef __XSAVE__
#define _X86_CC_XSAVE 1
#else
#define _X86_CC_XSAVE 0
#endif

#ifdef __CLFLUSHOPT__
#define _X86_CC_CLFLUSHOPT 1
#else
#define _X86_CC_CLFLUSHOPT 0
#endif

#ifdef __RDPID__
#define _X86_CC_RDPID 1
#else
#define _X86_CC_RDPID 0
#endif

#endif /* __x86_64__ */

/* Returns true if x86 FEATURE is present.
   This performs a runtime check in normal portable builds.
   It's usually dead code eliminated for -march=native builds. */
#define X86_HAVE(FEATURE) _X86_HAVE(X86_##FEATURE)

/* Returns true if x86 FEATURE is present.
   This will *always* perform a runtime check.
   It's useful for checking compile-time cpu features are present. */
#define X86_CHECK(FEATURE) _X86_CHECK(X86_##FEATURE)

/* Returns true if x86 FEATURE is mandatory at build time.
   This will never perform runtime checks; it's always constant. */
#define X86_NEED(FEATURE) _X86_NEED(X86_##FEATURE)

/* clang-format off */
/*      --- FEATURE              LEAF       REG BIT  COMPILE-TIME-DEFINE */
#define X86_ACC                  1H,        EDX, 29, 0
#define X86_ACPI                 1H,        EDX, 22, 0
#define X86_ADX                  7H,        EBX, 19, _X86_CC_ADX              /* broadwell c. 2014 */
#define X86_AES                  1H,        ECX, 25, _X86_CC_AES              /* westmere c. 2010 */
#define X86_APIC                 1H,        EDX,  9, 0
#define X86_ARCH_CAPABILITIES    7H,        EDX, 29, 0
#define X86_AVX                  1H,        ECX, 28, _X86_CC_AVX              /* sandybridge c. 2012 */
#define X86_AVX2                 7H,        EBX,  5, _X86_CC_AVX2             /* haswell c. 2013 */
#define X86_AVXVNNI              7H_1H,     EAX,  4, _X86_CC_AVXVNNI
#define X86_AVXVNNIINT8          7H_1H,     EDX,  4, _X86_CC_AVXVNNIINT8
#define X86_AVXVNNIINT16         7H_1H,     EDX, 10, _X86_CC_AVXVNNIINT16
#define X86_AVX512BW             7H,        EBX, 30, 0
#define X86_AVX512CD             7H,        EBX, 28, 0
#define X86_AVX512DQ             7H,        EBX, 17, 0
#define X86_AVX512ER             7H,        EBX, 27, 0
#define X86_AVX512F              7H,        EBX, 16, _X86_CC_AVX512F
#define X86_AVX512IFMA           7H,        EBX, 21, 0
#define X86_AVX512PF             7H,        EBX, 26, 0
#define X86_AVX512VBMI           7H,        ECX,  1, _X86_CC_AVX512VBMI
#define X86_AVX512VL             7H,        EBX, 31, 0
#define X86_AVX512_4FMAPS        7H,        EDX,  3, 0
#define X86_AVX512_4VNNIW        7H,        EDX,  2, _X86_CC_AVX5124VNNIW
#define X86_AVX512_FP16          7H,        EDX, 23, _X86_CC_AVX512FP16
#define X86_AVX512_BF16          7H_1H,     EAX,  5, _X86_CC_AVX512BF16
#define X86_AVX512_BITALG        7H,        ECX, 12, 0
#define X86_AVX512_VBMI2         7H,        ECX,  6, 0
#define X86_AVX512_VNNI          7H,        ECX, 11, _X86_CC_AVX512VNNI
#define X86_AVX512_VP2INTERSECT  7H,        EDX,  8, 0
#define X86_AVX512_VPOPCNTDQ     7H,        ECX, 14, 0
#define X86_BMI                  7H,        EBX,  3, _X86_CC_BMI              /* haswell c. 2013 */
#define X86_BMI2                 7H,        EBX,  8, _X86_CC_BMI2             /* haswell c. 2013 */
#define X86_CID                  1H,        ECX, 10, 0
#define X86_CLDEMOTE             7H,        ECX, 25, 0
#define X86_CLFLUSH              1H,        EDX, 19, _X86_CC_SSE2
#define X86_CLFLUSHOPT           7H,        EBX, 23, _X86_CC_CLFLUSHOPT       /* skylake/zen  */
#define X86_CLWB                 7H,        EBX, 24, 0                        /* skylake/zen2 */
#define X86_CMOV                 1H,        EDX, 15, 0
#define X86_CQM                  7H,        EBX, 12, 0
#define X86_CX16                 1H,        ECX, 13, 0
#define X86_CX8                  1H,        EDX,  8, 0
#define X86_DCA                  1H,        ECX, 18, 0
#define X86_DE                   1H,        EDX,  2, 0
#define X86_DS                   1H,        EDX, 21, 0
#define X86_DSCPL                1H,        ECX,  4, 0
#define X86_DTES64               1H,        ECX,  2, 0
#define X86_ERMS                 7H,        EBX,  9, 0                        /* broaadwell c. 2014 */
#define X86_EST                  1H,        ECX,  7, 0
#define X86_F16C                 1H,        ECX, 29, _X86_CC_F16C
#define X86_FDP_EXCPTN_ONLY      7H,        EBX,  6, 0
#define X86_FLUSH_L1D            7H,        EDX, 28, 0
#define X86_FMA                  1H,        ECX, 12, _X86_CC_FMA              /* haswell c. 2013 */
#define X86_FPU                  1H,        EDX,  0, 0
#define X86_FSGSBASE             7H,        EBX,  0, 0
#define X86_FXSR                 1H,        EDX, 24, 0
#define X86_GBPAGES              80000001H, EDX, 26, 0
#define X86_GFNI                 7H,        ECX,  8, 0
#define X86_HLE                  7H,        EBX,  4, 0
#define X86_HT                   1H,        EDX, 28, 0
#define X86_HYPERVISOR           1H,        ECX, 31, 0
#define X86_IA64                 1H,        EDX, 30, 0
#define X86_INTEL_PT             7H,        EBX, 25, 0
#define X86_INTEL_STIBP          7H,        EDX, 27, 0
#define X86_INVPCID              1H,        EBX, 10, 0
#define X86_INVTSC               80000007H, EDX,  8, _X86_CC_POPCNT           /* i.e. not a K8 */
#define X86_LA57                 7H,        ECX, 16, 0
#define X86_LAHF_LM              80000001H, ECX,  0, 0
#define X86_LM                   80000001H, EDX, 29, 0
#define X86_MCA                  1H,        EDX, 14, 0
#define X86_MCE                  1H,        EDX,  7, 0
#define X86_MD_CLEAR             7H,        EDX, 10, 0
#define X86_MMX                  1H,        EDX, 23, 0
#define X86_MOVBE                1H,        ECX, 22, 0
#define X86_MOVDIR64B            7H,        ECX, 28, 0
#define X86_MOVDIRI              7H,        ECX, 27, 0
#define X86_MP                   80000001H, EDX, 19, 0
#define X86_MPX                  7H,        EBX, 14, 0
#define X86_MSR                  1H,        EDX,  5, 0
#define X86_MTRR                 1H,        EDX, 12, 0
#define X86_MWAIT                1H,        ECX,  3, 0
#define X86_NX                   80000001H, EDX, 20, 0
#define X86_OSPKE                7H,        ECX,  4, 0
#define X86_OSXSAVE              1H,        ECX, 27, 0
#define X86_PAE                  1H,        EDX,  6, 0
#define X86_PAT                  1H,        EDX, 16, 0
#define X86_PBE                  1H,        EDX, 31, 0
#define X86_PCID                 1H,        ECX, 17, 0
#define X86_PCLMUL               1H,        ECX,  1, _X86_CC_PCLMUL           /* westmere c. 2010 */
#define X86_PCONFIG              7H,        EDX, 18, 0
#define X86_PDCM                 1H,        ECX, 15, 0
#define X86_PGE                  1H,        EDX, 13, 0
#define X86_PKU                  7H,        ECX,  3, 0
#define X86_PN                   1H,        EDX, 18, 0
#define X86_POPCNT               1H,        ECX, 23, _X86_CC_POPCNT           /* nehalem c. 2008 */
#define X86_PSE                  1H,        EDX,  3, 0
#define X86_PSE36                1H,        EDX, 17, 0
#define X86_RDPID                7H,        ECX, 22, _X86_CC_RDPID            /* cannonlake c. 2018 */
#define X86_RDRND                1H,        ECX, 30, _X86_CC_RDRND            /* ivybridge c. 2012 */
#define X86_RDSEED               7H,        EBX, 18, _X86_CC_RDSEED           /* broadwell c. 2014 */
#define X86_RDTSCP               80000001H, EDX, 27, 0
#define X86_RDT_A                7H,        EBX, 15, 0
#define X86_RTM                  7H,        EBX, 11, 0
#define X86_SDBG                 1H,        ECX, 11, 0
#define X86_SELFSNOOP            1H,        EDX, 27, 0
#define X86_SEP                  1H,        EDX, 11, 0
#define X86_SHA                  7H,        EBX, 29, _X86_CC_SHA              /* goldmont (2016) */
#define X86_SMAP                 7H,        EBX, 20, 0
#define X86_SMEP                 7H,        EBX,  7, 0
#define X86_SMX                  1H,        ECX,  6, 0
#define X86_SPEC_CTRL            7H,        EDX, 26, 0
#define X86_SPEC_CTRL_SSBD       7H,        EDX, 31, 0
#define X86_SSE                  1H,        EDX, 25, _X86_CC_SSE              /* pentium c. 1999 */
#define X86_SSE2                 1H,        EDX, 26, _X86_CC_SSE2             /* pentium c. 2001 */
#define X86_SSE3                 1H,        ECX,  0, _X86_CC_SSE3             /* k8 c. 2005 */
#define X86_SSE4_1               1H,        ECX, 19, _X86_CC_SSE4_1           /* core c. 2006 */
#define X86_SSE4_2               1H,        ECX, 20, _X86_CC_SSE4_2           /* nehalem c. 2008 */
#define X86_SSSE3                1H,        ECX,  9, _X86_CC_SSSE3            /* westmere c. 2010 */
#define X86_SYSCALL              80000001H, EDX, 11, 0
#define X86_TM2                  1H,        ECX,  8, 0
#define X86_TME                  7H,        ECX, 13, 0
#define X86_TSC                  1H,        EDX,  4, 0
#define X86_TSC_ADJUST           7H,        EBX,  1, 0
#define X86_TSC_DEADLINE_TIMER   1H,        ECX, 24, 0
#define X86_TSX_FORCE_ABORT      7H,        EDX, 13, 0
#define X86_UMIP                 7H,        ECX,  2, 0
#define X86_VAES                 7H,        ECX,  9, 0
#define X86_VME                  1H,        EDX,  1, 0
#define X86_VMX                  1H,        ECX,  5, 0
#define X86_VPCLMULQDQ           7H,        ECX, 10, 0
#define X86_WAITPKG              7H,        ECX,  5, 0
#define X86_X2APIC               1H,        ECX, 21, 0
#define X86_XSAVE                1H,        ECX, 26, _X86_CC_XSAVE            /* sandybridge c. 2012 */
#define X86_XTPR                 1H,        ECX, 14, 0
#define X86_ZERO_FCS_FDS         7H,        EBX, 13, 0
#define X86_JIT                  80000001H, ECX, 31, 0                        /* IsGenuineBlink() */
#define X86_HYBRID_CPU           7H,        EDX, 15, 0                        /* Has performance and efficiency cores */
/* clang-format on */

/* AMD specific features */
#define X86_ABM            80000001H, ECX, 5, _X86_CC_ABM
#define X86_3DNOW          80000001H, EDX, 31, 0
#define X86_3DNOWEXT       80000001H, EDX, 30, 0
#define X86_3DNOWPREFETCH  80000001H, ECX, 8, 0
#define X86_BPEXT          80000001H, ECX, 26, 0
#define X86_CMP_LEGACY     80000001H, ECX, 1, 0
#define X86_CR8_LEGACY     80000001H, ECX, 4, 0
#define X86_EXTAPIC        80000001H, ECX, 3, 0
#define X86_FMA4           80000001H, ECX, 16, 0
#define X86_FXSR_OPT       80000001H, EDX, 25, 0
#define X86_IBS            80000001H, ECX, 10, 0
#define X86_LWP            80000001H, ECX, 15, 0
#define X86_MISALIGNSSE    80000001H, ECX, 7, 0
#define X86_MMXEXT         80000001H, EDX, 22, 0
#define X86_MWAITX         80000001H, ECX, 29, 0
#define X86_NODEID_MSR     80000001H, ECX, 19, 0
#define X86_OSVW           80000001H, ECX, 9, 0
#define X86_OVERFLOW_RECOV 80000007H, EBX, 0, 0
#define X86_PERFCTR_CORE   80000001H, ECX, 23, 0
#define X86_PERFCTR_LLC    80000001H, ECX, 28, 0
#define X86_PERFCTR_NB     80000001H, ECX, 24, 0
#define X86_PTSC           80000001H, ECX, 27, 0
#define X86_SKINIT         80000001H, ECX, 12, 0
#define X86_SMCA           80000007H, EBX, 3, 0
#define X86_SSE4A          80000001H, ECX, 6, 0
#define X86_SUCCOR         80000007H, EBX, 1, 0
#define X86_SVM            80000001H, ECX, 2, 0
#define X86_TBM            80000001H, ECX, 21, 0
#define X86_TCE            80000001H, ECX, 17, 0
#define X86_TOPOEXT        80000001H, ECX, 22, 0
#define X86_WDT            80000001H, ECX, 13, 0
#define X86_XOP            80000001H, ECX, 11, 0

/* Defined but not loaded by kCpuids.S */
#define X86_ARAT            6H, EAX, 2, 0
#define X86_AVIC            8000000AH, EDX, 13, 0
#define X86_CLZERO          80000008H, EBX, 0, 0
#define X86_DECODEASSISTS   8000000AH, EDX, 7, 0
#define X86_DTHERM          6H, EAX, 0, 0
#define X86_FLUSHBYASID     8000000AH, EDX, 6, 0
#define X86_HWP             6H, EAX, 7, 0
#define X86_HWP_ACT_WINDOW  6H, EAX, 9, 0
#define X86_HWP_EPP         6H, EAX, 10, 0
#define X86_HWP_NOTIFY      6H, EAX, 8, 0
#define X86_HWP_PKG_REQ     6H, EAX, 11, 0
#define X86_IBPB            80000008H, EBX, 12, 0
#define X86_IBRS            80000008H, EBX, 14, 0
#define X86_IDA             6H, EAX, 1, 0
#define X86_IRPERF          80000008H, EBX, 1, 0
#define X86_LBRV            8000000AH, EDX, 1, 0
#define X86_NPT             8000000AH, EDX, 0, 0
#define X86_NRIPS           8000000AH, EDX, 3, 0
#define X86_PAUSEFILTER     8000000AH, EDX, 10, 0
#define X86_PFTHRESHOLD     8000000AH, EDX, 12, 0
#define X86_PLN             6H, EAX, 4, 0
#define X86_PTS             6H, EAX, 6, 0
#define X86_SSBD            80000008H, EBX, 24, 0
#define X86_SSB_NO          80000008H, EBX, 26, 0
#define X86_STIBP           80000008H, EBX, 15, 0
#define X86_STIBP_ALWAYS_ON 80000008H, EBX, 17, 0
#define X86_SVML            8000000AH, EDX, 2, 0
#define X86_TSCRATEMSR      8000000AH, EDX, 4, 0
#define X86_VGIF            8000000AH, EDX, 16, 0
#define X86_VIRT_SSBD       80000008H, EBX, 25, 0
#define X86_VMCBCLEAN       8000000AH, EDX, 5, 0
#define X86_V_VMSAVE_VMLOAD 8000000AH, EDX, 15, 0
#define X86_WBNOINVD        80000008H, EBX, 9, 0
#define X86_XGETBV1         DH, EAX, 2, 0
#define X86_XSAVEC          DH, EAX, 1, 0
#define X86_XSAVEERPTR      80000008H, EBX, 2, 0
#define X86_XSAVEOPT        DH, EAX, 0, 0
#define X86_XSAVES          DH, EAX, 3, 0

#define X86_WORD(FEATURE) _X86_WORD(X86_##FEATURE)
#define X86_LEAF(FEATURE) _X86_LEAF(X86_##FEATURE)
#define X86_REG(FEATURE)  _X86_REG(X86_##FEATURE)
#define X86_BIT(FEATURE)  _X86_BIT(X86_##FEATURE)

#define _X86_CHECK(FEATURE) __X86_CHECK(FEATURE)
#define _X86_HAVE(FEATURE)  __X86_HAVE(FEATURE)
#define _X86_NEED(FEATURE)  __X86_NEED(FEATURE)
#define _X86_WORD(FEATURE)  __X86_WORD(FEATURE)
#define _X86_LEAF(FEATURE)  __X86_LEAF(FEATURE)
#define _X86_REG(FEATURE)   __X86_REG(FEATURE)
#define _X86_BIT(FEATURE)   __X86_BIT(FEATURE)

#define __X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  ___X86_CHECK(LEAF, REG, BIT, MANDATORY)
#define __X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  ___X86_HAVE(LEAF, REG, BIT, MANDATORY)
#define __X86_NEED(LEAF, REG, BIT, MANDATORY) MANDATORY
#define __X86_WORD(LEAF, REG, BIT, MANDATORY) KCPUIDS(LEAF, REG)
#define __X86_LEAF(LEAF, REG, BIT, MANDATORY) LEAF
#define __X86_REG(LEAF, REG, BIT, MANDATORY)  REG
#define __X86_BIT(LEAF, REG, BIT, MANDATORY)  BIT

#define ___X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  !!(KCPUIDS(LEAF, REG) & (1u << BIT))

#ifndef __ASSEMBLER__
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  !!(MANDATORY || KCPUIDS(LEAF, REG) & (1u << BIT))
#else
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  $1 << (BIT % 8), BIT / 8 + KCPUIDS(LEAF, REG)
#endif

#else
#define X86_HAVE(FEATURE)  0
#define X86_NEED(FEATURE)  0
#define X86_CHECK(FEATURE) 0
#endif /* __x86_64__ */

#define INTRIN_COMMUTATIVE "%"
#define INTRIN_NONCOMMUTATIVE

#if defined(__x86_64__) && !defined(__STRICT_ANSI__)

typedef char __intrin_xmm_t
    __attribute__((__vector_size__(16), __aligned__(16), __may_alias__));

#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C)                    \
  do {                                                                         \
    if (X86_HAVE(ISA)) {                                                       \
      __intrin_xmm_t *Xmm0 = (void *)(A);                                      \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);                \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(C);                \
      if (!X86_NEED(AVX)) {                                                    \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm2), "0"(*Xmm1));        \
      } else {                                                                 \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm1), "x"(*Xmm2)); \
      }                                                                        \
    } else {                                                                   \
      PURE(A, B, C);                                                           \
    }                                                                          \
  } while (0)

#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)                 \
  do {                                                               \
    if (X86_HAVE(ISA)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I));     \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)                 \
  do {                                                          \
    if (X86_HAVE(ISA)) {                                        \
      __intrin_xmm_t *Xmm0 = (void *)(A);                       \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B); \
      if (!X86_NEED(AVX)) {                                     \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "0"(*Xmm1));           \
      } else {                                                  \
        asm("v" OP "\t%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1));       \
      }                                                         \
    } else {                                                    \
      PURE(A, B);                                               \
    }                                                           \
  } while (0)

#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)                   \
  do {                                                               \
    if (!IsModeDbg() && X86_HAVE(ISA)) {                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "i"(I), "0"(*Xmm1));        \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#else
#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C) PURE(A, B, C)
#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)        PURE(A, B, I)
#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)          PURE(A, B, I)
#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)             PURE(A, B)
#endif /* X86 && !ANSI */



/*!BEGIN libc/intrin/newbie.h */

#define COSMOPOLITAN_LIBC_BITS_NEWBIE_H_

#define BYTE_ORDER    __BYTE_ORDER__
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define PDP_ENDIAN    __ORDER_PDP_ENDIAN__

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define htobe16(x) bswap_16(x)
#define be16toh(x) bswap_16(x)
#define betoh16(x) bswap_16(x)
#define htobe32(x) bswap_32(x)
#define be32toh(x) bswap_32(x)
#define betoh32(x) bswap_32(x)
#define htobe64(x) bswap_64(x)
#define be64toh(x) bswap_64(x)
#define betoh64(x) bswap_64(x)
#define htole16(x) (uint16_t)(x)
#define le16toh(x) (uint16_t)(x)
#define letoh16(x) (uint16_t)(x)
#define htole32(x) (uint32_t)(x)
#define le32toh(x) (uint32_t)(x)
#define letoh32(x) (uint32_t)(x)
#define htole64(x) (uint64_t)(x)
#define le64toh(x) (uint64_t)(x)
#define letoh64(x) (uint64_t)(x)
#else
#define htobe16(x) (uint16_t)(x)
#define be16toh(x) (uint16_t)(x)
#define betoh16(x) (uint16_t)(x)
#define htobe32(x) (uint32_t)(x)
#define be32toh(x) (uint32_t)(x)
#define betoh32(x) (uint32_t)(x)
#define htobe64(x) (uint64_t)(x)
#define be64toh(x) (uint64_t)(x)
#define betoh64(x) (uint64_t)(x)
#define htole16(x) bswap_16(x)
#define le16toh(x) bswap_16(x)
#define letoh16(x) bswap_16(x)
#define htole32(x) bswap_32(x)
#define le32toh(x) bswap_32(x)
#define letoh32(x) bswap_32(x)
#define htole64(x) bswap_64(x)
#define le64toh(x) bswap_64(x)
#define letoh64(x) bswap_64(x)
#endif



/*!BEGIN libc/intrin/packsswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKSSWB_H_
COSMOPOLITAN_C_START_

void packsswb(int8_t[16], const int16_t[8], const int16_t[8]);

#define packsswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packsswb, SSE2, "packsswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/packuswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKUSWB_H_
COSMOPOLITAN_C_START_

void packuswb(uint8_t[16], const int16_t[8], const int16_t[8]);

#define packuswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packuswb, SSE2, "packuswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/paddw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PADDW_H_
COSMOPOLITAN_C_START_

void paddw(int16_t[8], const int16_t[8], const int16_t[8]);

#define paddw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(paddw, SSE2, "paddw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/palignr.h */

#define COSMOPOLITAN_LIBC_INTRIN_PALIGNR_H_


/*!BEGIN libc/str/str.h */

#define COSMOPOLITAN_LIBC_STR_STR_H_

#define INVALID_CODEPOINT 0xfffd

#define _tolower(u) (0040 | (u))
#define _toupper(u) (0137 & (u))

#ifdef _COSMO_SOURCE
#define chomp         _chomp
#define chomp16       _chomp16
#define wchomp        _wchomp
#define tpenc         _tpenc
#define isutf8        _isutf8
#define istext        _istext
#define startswith    _startswith
#define startswithi   _startswithi
#define endswith      _endswith
#define wcsendswith   _wcsendswith
#define wcsstartswith _wcsstartswith
#endif /* _COSMO_SOURCE */

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

int isascii(int) libcesque;
int isspace(int) libcesque;
int isalpha(int) libcesque;
int isdigit(int) libcesque;
int isalnum(int) libcesque;
int isxdigit(int) libcesque;
int isprint(int) libcesque;
int islower(int) libcesque;
int isupper(int) libcesque;
int isblank(int) libcesque;
int iscntrl(int) libcesque;
int isgraph(int) libcesque;
int tolower(int) libcesque;
int ispunct(int) libcesque;
int toupper(int) libcesque;
int toascii(int) libcesque;

int iswalnum(wint_t) libcesque;
int iswalpha(wint_t) libcesque;
int iswblank(wint_t) libcesque;
int iswcntrl(wint_t) libcesque;
int iswdigit(wint_t) libcesque;
int iswgraph(wint_t) libcesque;
int iswlower(wint_t) libcesque;
int iswspace(wint_t) libcesque;
int iswupper(wint_t) libcesque;
int iswxdigit(wint_t) libcesque;
int iswpunct(wint_t) libcesque;
int iswprint(wint_t) libcesque;
int iswseparator(wint_t) libcesque;
wint_t towlower(wint_t) libcesque;
wint_t towupper(wint_t) libcesque;

void *memset(void *, int, size_t) memcpyesque;
void *memmove(void *, const void *, size_t) memcpyesque;
void *memcpy(void *restrict, const void *restrict, size_t) memcpyesque;
void *mempcpy(void *restrict, const void *restrict, size_t) memcpyesque;
char *hexpcpy(char *restrict, const void *restrict, size_t) memcpyesque;
void *memccpy(void *restrict, const void *restrict, int, size_t) memcpyesque;
void explicit_bzero(void *, size_t);

int memcmp(const void *, const void *, size_t) strlenesque;
int timingsafe_bcmp(const void *, const void *, size_t) libcesque;
int timingsafe_memcmp(const void *, const void *, size_t) libcesque;

size_t strlen(const char *) strlenesque;
size_t strnlen(const char *, size_t) strlenesque;
size_t strnlen_s(const char *, size_t) libcesque;
char *strchr(const char *, int) strlenesque;
void *memchr(const void *, int, size_t) strlenesque;
char *strchrnul(const char *, int) strlenesque returnsnonnull;
void *rawmemchr(const void *, int) strlenesque returnsnonnull;
size_t wcslen(const wchar_t *) strlenesque;
size_t wcsnlen(const wchar_t *, size_t) strlenesque;
size_t wcsnlen_s(const wchar_t *, size_t) libcesque;
wchar_t *wcschr(const wchar_t *, wchar_t) strlenesque;
wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) strlenesque;
wchar_t *wcschrnul(const wchar_t *, wchar_t)
strlenesque returnsnonnull;
char *strstr(const char *, const char *) strlenesque;
char *strcasestr(const char *, const char *) strlenesque;
wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque;
int strcmp(const char *, const char *) strlenesque;
int strncmp(const char *, const char *, size_t) strlenesque;
int wcscmp(const wchar_t *, const wchar_t *) strlenesque;
int wcsncmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int wmemcmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int strcasecmp(const char *, const char *) strlenesque;
int memcasecmp(const void *, const void *, size_t) strlenesque;
int wcscasecmp(const wchar_t *, const wchar_t *) strlenesque;
int strncasecmp(const char *, const char *, size_t) strlenesque;
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
char *strrchr(const char *, int) strlenesque;
void *memrchr(const void *, int, size_t) strlenesque;
wchar_t *wcsrchr(const wchar_t *, wchar_t) strlenesque;
void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque;
char *strpbrk(const char *, const char *) strlenesque;
wchar_t *wcspbrk(const wchar_t *, const wchar_t *) strlenesque;
size_t strspn(const char *, const char *) strlenesque;
size_t wcsspn(const wchar_t *, const wchar_t *) strlenesque;
size_t strcspn(const char *, const char *) strlenesque;
size_t wcscspn(const wchar_t *, const wchar_t *) strlenesque;
void *memfrob(void *, size_t) memcpyesque;
int strcoll(const char *, const char *) strlenesque;
char *strsep(char **, const char *) libcesque paramsnonnull();
char *stpcpy(char *, const char *) memcpyesque;
char *stpncpy(char *, const char *, size_t) memcpyesque;
char *strcat(char *, const char *) memcpyesque;
wchar_t *wcscat(wchar_t *, const wchar_t *) memcpyesque;
size_t strlcpy(char *, const char *, size_t) libcesque;
size_t strlcat(char *, const char *, size_t) libcesque;
size_t strxfrm(char *, const char *, size_t) libcesque;
char *strcpy(char *, const char *) memcpyesque;
wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque;
char *strncat(char *, const char *, size_t) memcpyesque;
wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t) memcpyesque;
char *strncpy(char *, const char *, size_t) memcpyesque;
char *strtok(char *, const char *) paramsnonnull((2)) libcesque;
char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
int strverscmp(const char *, const char *) libcesque;
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
void *memmem(const void *, size_t, const void *, size_t)
libcesque nosideeffect;
ssize_t strfmon(char *, size_t, const char *, ...) libcesque;
long a64l(const char *) libcesque;
char *l64a(long) libcesque;

typedef unsigned mbstate_t;

wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t) libcesque;
int mbtowc(wchar_t *, const char *, size_t) libcesque;
size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *) libcesque;
size_t mbstowcs(wchar_t *, const char *, size_t) libcesque;
size_t wcrtomb(char *, wchar_t, mbstate_t *) libcesque;
size_t c32rtomb(char *, char32_t, mbstate_t *) libcesque;
size_t mbrtoc32(char32_t *, const char *, size_t, mbstate_t *) libcesque;
size_t c16rtomb(char *, char16_t, mbstate_t *) libcesque;
size_t mbrtoc16(char16_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbrlen(const char *, size_t, mbstate_t *) libcesque;
size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *);
size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *);
size_t wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *) libcesque;
size_t wcstombs(char *, const wchar_t *, size_t) libcesque;
int mbsinit(const mbstate_t *) libcesque;
int mblen(const char *, size_t) libcesque;
int wctomb(char *, wchar_t) libcesque;
int wctob(wint_t) libcesque;
wint_t btowc(int) libcesque;

typedef unsigned wctype_t;
wctype_t wctype(const char *) strlenesque;
pureconst int iswctype(wint_t, wctype_t) libcesque;

typedef const int *wctrans_t;
wctrans_t wctrans(const char *) libcesque;
wint_t towctrans(wint_t, wctrans_t) libcesque;

int getsubopt(char **, char *const *, char **) libcesque paramsnonnull();
char *strsignal(int) returnsnonnull libcesque;
char *strerror(int) returnsnonnull dontthrow dontcallback;
errno_t strerror_r(int, char *, size_t) libcesque;
char *__xpg_strerror_r(int, char *, size_t) libcesque;

#ifdef _COSMO_SOURCE
pureconst uint64_t tpenc(uint32_t) libcesque;
char *chomp(char *) libcesque;
wchar_t *wchomp(wchar_t *) libcesque;
uint64_t __fnv(const void *, size_t) strlenesque;
bool32 startswith(const char *, const char *) strlenesque;
bool32 startswithi(const char *, const char *) strlenesque;
bool32 endswith(const char *, const char *) strlenesque;
bool32 istext(const void *, size_t) libcesque;
bool32 isutf8(const void *, size_t) libcesque;
const char *strsignal_r(int, char[21]) returnsnonnull libcesque __wur;
char16_t *chomp16(char16_t *) libcesque;
size_t strlen16(const char16_t *) strlenesque;
size_t strnlen16(const char16_t *, size_t) strlenesque;
char16_t *strchr16(const char16_t *, int) strlenesque;
void *memchr16(const void *, int, size_t) strlenesque;
char16_t *strchrnul16(const char16_t *, int) strlenesque returnsnonnull;
void *rawmemchr16(const void *, int) strlenesque returnsnonnull;
char16_t *strstr16(const char16_t *, const char16_t *) strlenesque;
int strcmp16(const char16_t *, const char16_t *) strlenesque;
int strncmp16(const char16_t *, const char16_t *, size_t) strlenesque;
int strcasecmp16(const char16_t *, const char16_t *) strlenesque;
int strncasecmp16(const char16_t *, const char16_t *, size_t) strlenesque;
char16_t *strrchr16(const char16_t *, int) strlenesque;
void *memrchr16(const void *, int, size_t) strlenesque;
char16_t *strpbrk16(const char16_t *, const char16_t *) strlenesque;
size_t strspn16(const char16_t *, const char16_t *) strlenesque;
size_t strcspn16(const char16_t *, const char16_t *) strlenesque;
char16_t *strcat16(char16_t *, const char16_t *) memcpyesque;
char16_t *strcpy16(char16_t *, const char16_t *) memcpyesque;
char16_t *strncat16(char16_t *, const char16_t *, size_t) memcpyesque;
char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque;
bool32 startswith16(const char16_t *, const char16_t *) strlenesque;
bool32 endswith16(const char16_t *, const char16_t *) strlenesque;
axdx_t tprecode8to16(char16_t *, size_t, const char *) libcesque;
axdx_t tprecode16to8(char *, size_t, const char16_t *) libcesque;
bool32 wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
bool32 wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
char *__join_paths(char *, size_t, const char *, const char *) libcesque __wur;
int __mkntpathat(int, const char *, int, char16_t[hasatleast 1024]);
#endif /* _COSMO_SOURCE */

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_POSIX_SOURCE) ||                                                 \
    (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE + 0 < 200809L) ||            \
    (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE + 0 < 700)
int bcmp(const void *, const void *, size_t) strlenesque;
void bcopy(const void *, void *, size_t) memcpyesque;
void bzero(void *, size_t) memcpyesque;
char *index(const char *, int) strlenesque;
char *rindex(const char *, int) strlenesque;
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

void palignr(void *, const void *, const void *, unsigned long);

#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__)
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
#define palignr(C, B, A, I)                                                \
  do {                                                                     \
    if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSSE3), \
                         1)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(C);                                  \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);            \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(A);            \
      if (__builtin_constant_p(I)) {                                       \
        if (!X86_NEED(AVX)) {                                              \
          asm("palignr\t%2,%1,%0"                                          \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm2), "i"(I), "0"(*Xmm1));                           \
        } else {                                                           \
          asm("vpalignr\t%3,%2,%1,%0"                                      \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm1), "x"(*Xmm2), "i"(I));                           \
        }                                                                  \
      } else {                                                             \
        unsigned long Vimm = (I);                                          \
        typeof(__palignrs) *Fn;                                            \
        if (__builtin_expect(Vimm < 32, 1)) {                              \
          Fn = (typeof(__palignrs) *)((uintptr_t)&__palignrs + Vimm * 8);  \
          *Xmm0 = Fn(*Xmm1, *Xmm2);                                        \
        } else {                                                           \
          memset(Xmm0, 0, 16);                                             \
        }                                                                  \
      }                                                                    \
    } else {                                                               \
      palignr(C, B, A, I);                                                 \
    }                                                                      \
  } while (0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pandn.h */

#define COSMOPOLITAN_LIBC_INTRIN_PANDN_H_
COSMOPOLITAN_C_START_

void pandn(uint64_t[2], const uint64_t[2], const uint64_t[2]);

#define pandn(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pandn, SSE2, "pandn", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTB_H_
COSMOPOLITAN_C_START_

void pcmpgtb(int8_t[16], const int8_t[16], const int8_t[16]);

#define pcmpgtb(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtb, SSE2, "pcmpgtb", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTW_H_
COSMOPOLITAN_C_START_

void pcmpgtw(int16_t[8], const int16_t[8], const int16_t[8]);

#define pcmpgtw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtw, SSE2, "pcmpgtw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmaddubsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMADDUBSW_H_
COSMOPOLITAN_C_START_

void pmaddubsw(int16_t[8], const uint8_t[16], const int8_t[16]);

#define pmaddubsw(W, B, C)                                                   \
  INTRIN_SSEVEX_X_X_X_(pmaddubsw, SSSE3, "pmaddubsw", INTRIN_NONCOMMUTATIVE, \
                       W, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmovmskb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMOVMSKB_H_
COSMOPOLITAN_C_START_

uint32_t pmovmskb(const uint8_t[16]);

#if defined(__x86_64__) && defined(__GNUC__)
#define pmovmskb(A)                                            \
  ({                                                           \
    uint32_t Mask;                                             \
    if (!IsModeDbg() && X86_HAVE(SSE2)) {                      \
      const __intrin_xmm_t *Xmm = (const __intrin_xmm_t *)(A); \
      if (!X86_NEED(AVX)) {                                    \
        asm("pmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));       \
      } else {                                                 \
        asm("vpmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));      \
      }                                                        \
    } else {                                                   \
      Mask = pmovmskb(A);                                      \
    }                                                          \
    Mask;                                                      \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmulhrsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMULHRSW_H_
COSMOPOLITAN_C_START_

void pmulhrsw(int16_t a[8], const int16_t b[8], const int16_t c[8]);

#define pmulhrsw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pmulhrsw, SSSE3, "pmulhrsw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/popcnt.h */

#define COSMOPOLITAN_LIBC_BITS_POPCNT_H_
COSMOPOLITAN_C_START_

libcesque size_t _countbits(const void *, size_t);
libcesque unsigned long popcnt(unsigned long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define popcnt(X)                                                \
  (__builtin_constant_p(X) ? __builtin_popcountll(X) : ({        \
    unsigned long PoP = (X);                                     \
    if (X86_HAVE(POPCNT)) {                                      \
      asm("popcnt\t%0,%0" : "+r"(PoP) : /* no inputs */ : "cc"); \
    } else {                                                     \
      PoP = (popcnt)(PoP);                                       \
    }                                                            \
    PoP;                                                         \
  }))
#else
#define popcnt(x) __builtin_popcountll(x)
#endif /* GNUC && !ANSI */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/psraw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PSRAW_H_
COSMOPOLITAN_C_START_

void psraw(int16_t[8], const int16_t[8], unsigned char) libcesque;
void psrawv(int16_t[8], const int16_t[8], const uint64_t[2]) libcesque;

#define psraw(A, B, I) INTRIN_SSEVEX_X_I_(psraw, SSE2, "psraw", A, B, I)
#define psrawv(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(psrawv, SSE2, "psraw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHBW_H_
COSMOPOLITAN_C_START_

void punpckhbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpckhbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhbw, SSE2, "punpckhbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHWD_H_
COSMOPOLITAN_C_START_

void punpckhwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpckhwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhwd, SSE2, "punpckhwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLBW_H_
COSMOPOLITAN_C_START_

void punpcklbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpcklbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklbw, SSE2, "punpcklbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLWD_H_
COSMOPOLITAN_C_START_

void punpcklwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpcklwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklwd, SSE2, "punpcklwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/repmovsb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
#ifdef _COSMO_SOURCE

forceinline void repmovsb(void **dest, const void **src, size_t cx) {
  char *di = (char *)*dest;
  const char *si = (const char *)*src;
  while (cx) *di++ = *si++, cx--;
  *dest = di, *src = si;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repmovsb(DI, SI, CX)                                       \
  ({                                                               \
    void *Di = *(DI);                                              \
    const void *Si = *(SI);                                        \
    size_t Cx = (CX);                                              \
    asm("rep movsb"                                                \
        : "=D"(Di), "=S"(Si), "=c"(Cx), "=m"(*(char(*)[Cx])Di)     \
        : "0"(Di), "1"(Si), "2"(Cx), "m"(*(const char(*)[Cx])Si)); \
    *(DI) = Di, *(SI) = Si;                                        \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/repstosb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
#ifdef _COSMO_SOURCE

forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
  unsigned char *di = (unsigned char *)dest;
  while (cx) *di++ = al, cx--;
  return di;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repstosb(DI, AL, CX)                         \
  ({                                                 \
    void *Di = (DI);                                 \
    size_t Cx = (CX);                                \
    unsigned char Al = (AL);                         \
    asm("rep stosb %b5,(%0)"                         \
        : "=D"(Di), "=c"(Cx), "=m"(*(char(*)[Cx])Di) \
        : "0"(Di), "1"(Cx), "a"(Al));                \
    Di;                                              \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/ubsan.h */

#define COSMOPOLITAN_LIBC_INTRIN_UBSAN_H_
COSMOPOLITAN_C_START_

extern bool32 __ubsan_strict;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/ulock.h */

#define COSMOPOLITAN_ULOCK_H_
COSMOPOLITAN_C_START_

/* both wake and wait take one of these */
#define UL_COMPARE_AND_WAIT          1 /* multi-thread */
#define UL_UNFAIR_LOCK               2
#define UL_COMPARE_AND_WAIT_SHARED   3 /* multi-thread/process */
#define UL_UNFAIR_LOCK64_SHARED      4
#define UL_COMPARE_AND_WAIT64        5
#define UL_COMPARE_AND_WAIT64_SHARED 6

#define ULF_WAKE_ALL             0x00000100
#define ULF_WAKE_THREAD          0x00000200 /* takes wake_value */
#define ULF_WAKE_ALLOW_NON_OWNER 0x00000400

#define ULF_WAIT_WORKQ_DATA_CONTENTION 0x00010000
#define ULF_WAIT_CANCEL_POINT          0x00020000 /* raises eintr */
#define ULF_WAIT_ADAPTIVE_SPIN         0x00040000

int ulock_wake(uint32_t, void *, uint64_t) libcesque;
int ulock_wait(uint32_t, void *, uint64_t, uint32_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/weaken.h */

#define COSMOPOLITAN_LIBC_BITS_WEAKEN_H_

#ifndef __chibicc__
#define _weaken(symbol)                                         \
  __extension__({                                               \
    extern __typeof__(symbol) symbol __attribute__((__weak__)); \
    &symbol;                                                    \
  })
#else
#define _weaken(symbol) (&(symbol))
#endif



/*!BEGIN libc/intrin/x86.h */

#define COSMOPOLITAN_LIBC_INTRIN_X86_H_
COSMOPOLITAN_C_START_

enum VendorSignatures {
  SIG_INTEL = 0x756e6547, /* Genu */
  SIG_AMD = 0x68747541,   /* Auth */
};

enum ProcessorVendors {
  VENDOR_INTEL = 1,
  VENDOR_AMD,
  VENDOR_OTHER,
  VENDOR_MAX
};

enum ProcessorTypes {
  INTEL_BONNELL = 1,
  INTEL_CORE2,
  INTEL_COREI7,
  AMDFAM10H,
  AMDFAM15H,
  INTEL_SILVERMONT,
  INTEL_KNL,
  AMD_BTVER1,
  AMD_BTVER2,
  AMDFAM17H,
  INTEL_KNM,
  INTEL_GOLDMONT,
  INTEL_GOLDMONT_PLUS,
  INTEL_TREMONT,
  AMDFAM19H,
  ZHAOXIN_FAM7H,
  INTEL_SIERRAFOREST,
  INTEL_GRANDRIDGE,
  INTEL_CLEARWATERFOREST,
  CPU_TYPE_MAX
};

enum ProcessorSubtypes {
  INTEL_COREI7_NEHALEM = 1,
  INTEL_COREI7_WESTMERE,
  INTEL_COREI7_SANDYBRIDGE,
  AMDFAM10H_BARCELONA,
  AMDFAM10H_SHANGHAI,
  AMDFAM10H_ISTANBUL,
  AMDFAM15H_BDVER1,
  AMDFAM15H_BDVER2,
  AMDFAM15H_BDVER3,
  AMDFAM15H_BDVER4,
  AMDFAM17H_ZNVER1,
  INTEL_COREI7_IVYBRIDGE,
  INTEL_COREI7_HASWELL,
  INTEL_COREI7_BROADWELL,
  INTEL_COREI7_SKYLAKE,
  INTEL_COREI7_SKYLAKE_AVX512,
  INTEL_COREI7_CANNONLAKE,
  INTEL_COREI7_ICELAKE_CLIENT,
  INTEL_COREI7_ICELAKE_SERVER,
  AMDFAM17H_ZNVER2,
  INTEL_COREI7_CASCADELAKE,
  INTEL_COREI7_TIGERLAKE,
  INTEL_COREI7_COOPERLAKE,
  INTEL_COREI7_SAPPHIRERAPIDS,
  INTEL_COREI7_ALDERLAKE,
  AMDFAM19H_ZNVER3,
  INTEL_COREI7_ROCKETLAKE,
  ZHAOXIN_FAM7H_LUJIAZUI,
  AMDFAM19H_ZNVER4,
  INTEL_COREI7_GRANITERAPIDS,
  INTEL_COREI7_GRANITERAPIDS_D,
  INTEL_COREI7_ARROWLAKE,
  INTEL_COREI7_ARROWLAKE_S,
  INTEL_COREI7_PANTHERLAKE,
  CPU_SUBTYPE_MAX
};

enum ProcessorFeatures {
  FEATURE_CMOV = 0,
  FEATURE_MMX,
  FEATURE_POPCNT,
  FEATURE_SSE,
  FEATURE_SSE2,
  FEATURE_SSE3,
  FEATURE_SSSE3,
  FEATURE_SSE4_1,
  FEATURE_SSE4_2,
  FEATURE_AVX,
  FEATURE_AVX2,
  FEATURE_SSE4_A,
  FEATURE_FMA4,
  FEATURE_XOP,
  FEATURE_FMA,
  FEATURE_AVX512F,
  FEATURE_BMI,
  FEATURE_BMI2,
  FEATURE_AES,
  FEATURE_PCLMUL,
  FEATURE_AVX512VL,
  FEATURE_AVX512BW,
  FEATURE_AVX512DQ,
  FEATURE_AVX512CD,
  FEATURE_AVX512ER,
  FEATURE_AVX512PF,
  FEATURE_AVX512VBMI,
  FEATURE_AVX512IFMA,
  FEATURE_AVX5124VNNIW,
  FEATURE_AVX5124FMAPS,
  FEATURE_AVX512VPOPCNTDQ,
  FEATURE_AVX512VBMI2,
  FEATURE_GFNI,
  FEATURE_VPCLMULQDQ,
  FEATURE_AVX512VNNI,
  FEATURE_AVX512BITALG,
  FEATURE_AVX512BF16,
  FEATURE_AVX512VP2INTERSECT,

  FEATURE_CMPXCHG16B = 46,
  FEATURE_F16C = 49,
  FEATURE_LAHF_LM = 54,
  FEATURE_LM,
  FEATURE_WP,
  FEATURE_LZCNT,
  FEATURE_MOVBE,

  FEATURE_AVX512FP16 = 94,
  FEATURE_X86_64_BASELINE,
  FEATURE_X86_64_V2,
  FEATURE_X86_64_V3,
  FEATURE_X86_64_V4,
  CPU_FEATURE_MAX
};

struct __processor_model {
  unsigned __cpu_vendor;
  unsigned __cpu_type;
  unsigned __cpu_subtype;
  unsigned __cpu_features[1];
  const char *__cpu_march;
};

extern struct __processor_model __cpu_model;

const char *__cpu_march(unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/bsd.h */

#define COSMOPOLITAN_LIBC_LOG_BSD_H_
COSMOPOLITAN_C_START_

void err(int, const char *, ...) wontreturn;
void verr(int, const char *, va_list) wontreturn;
void errc(int, int, const char *, ...) wontreturn;
void verrc(int, int, const char *, va_list) wontreturn;
void errx(int, const char *, ...) wontreturn;
void verrx(int, const char *, va_list) wontreturn;
void warn(const char *, ...);
void vwarn(const char *, va_list);
void warnc(int, const char *, ...);
void vwarnc(int, const char *, va_list);
void warnx(const char *, ...);
void vwarnx(const char *, va_list);
void err_set_exit(void (*)(int));

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/check.h */

#define COSMOPOLITAN_LIBC_LOG_CHECK_H_
COSMOPOLITAN_C_START_

#define CHECK(X, ...)         __CHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define CHECK_EQ(Y, X, ...)   __CHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NE(Y, X, ...)   __CHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LE(Y, X, ...)   __CHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LT(Y, X, ...)   __CHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GE(Y, X, ...)   __CHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GT(Y, X, ...)   __CHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NOTNULL(X, ...) __CHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define DCHECK(X, ...)       __DCHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define DCHECK_EQ(Y, X, ...) __DCHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NE(Y, X, ...) __DCHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LE(Y, X, ...) __DCHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LT(Y, X, ...) __DCHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GE(Y, X, ...) __DCHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GT(Y, X, ...) __DCHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NOTNULL(X, ...) \
  __DCHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define CHECK_ALIGNED(BYTES, VAR, ...)                                \
  do {                                                                \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                            \
      __check_fail_aligned(BYTES, (uintptr_t)VAR, __FILE__, __LINE__, \
                           "" __VA_ARGS__);                           \
      __builtin_unreachable();                                        \
    }                                                                 \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES);          \
  } while (0)

#define DCHECK_ALIGNED(BYTES, VAR, ...)                      \
  do {                                                       \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                   \
      __DCHK_ALIGNED(BYTES, (uintptr_t)VAR, "" __VA_ARGS__); \
      __builtin_unreachable();                               \
    }                                                        \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES); \
  } while (0)

#define __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...)                   \
  do {                                                                       \
    autotype(GOT) Got = (GOT);                                               \
    autotype(WANT) Want = (WANT);                                            \
    if (!(Want OP Got)) {                                                    \
      if (!NoDebug()) {                                                      \
        __check_fail(#SUFFIX, #OP, (uint64_t)Want, (WANTSTR), (uint64_t)Got, \
                     (GOTSTR), __FILE__, __LINE__, __VA_ARGS__);             \
      } else {                                                               \
        __check_fail_##SUFFIX((uint64_t)Want, (uint64_t)Got, __FILE__,       \
                              __LINE__, 0, __VA_ARGS__);                     \
      }                                                                      \
      __builtin_unreachable();                                               \
    }                                                                        \
  } while (0)

#ifdef NDEBUG
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, ...) \
  do {                                              \
    autotype(GOT) Got = (GOT);                      \
    autotype(WANT) Want = (WANT);                   \
    if (!(Want OP Got)) {                           \
      __builtin_unreachable();                      \
    }                                               \
  } while (0)
#else
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \
  __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, __VA_ARGS__)
#endif /* NDEBUG */

#ifdef NDEBUG
#define __DCHK_ALIGNED(BYTES, VAR, ...)
#else
#define __DCHK_ALIGNED(BYTES, VAR, ...) \
  __check_fail_aligned(BYTES, VAR, __FILE__, __LINE__, __VA_ARGS__)
#endif

void __check_fail(const char *, const char *, uint64_t, const char *, uint64_t,
                  const char *, const char *, int, const char *,
                  ...) relegated wontreturn;

void __check_fail_eq(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ne(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_le(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_lt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ge(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_gt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_aligned(unsigned, uint64_t, const char *, int, const char *,
                          ...) relegated wontreturn;

#ifdef __VSCODE_INTELLISENSE__
#undef __CHK
#define __CHK(...)
#undef __DCHK
#define __DCHK(...)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countbranch.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTBRANCH_H_
COSMOPOLITAN_C_START_

#define COUNTBRANCH(x) COUNTBRANCH_(x, #x, STRINGIFY(__FILE__), __LINE__)
#define COUNTBRANCH_(x, xs, file, line) \
  COUNTBRANCH__(x, STRINGIFY(xs), STRINGIFY(xs), file, line)
#define COUNTBRANCH__(x, xs, xss, file, line)                   \
  ({                                                            \
    bool Cond;                                                  \
    struct countbranch *Info;                                   \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31338:\t"                                              \
        ".asciz\t" xs "\n"                                      \
        "31339:\t"                                              \
        ".asciz\t" xss "\n"                                     \
        "31340:\t"                                              \
        ".asciz\t" file "\n\t"                                  \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountbranch_data(%%rip)\n\t"                     \
        ".previous\n\t"                                         \
        ".section .sort.data.countbranch.2,\"a\",@progbits\n\t" \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t0\n\t"                                          \
        ".quad\t0\n\t"                                          \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31339b\n\t"                                     \
        ".quad\t31340b\n\t"                                     \
        ".quad\t" #line "\n\t"                                  \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(Info));                                          \
    Cond = (x);                                                 \
    ++Info->total;                                              \
    if (Cond) ++Info->taken;                                    \
    Cond;                                                       \
  })

struct countbranch {
  long total;
  long taken;
  const char *code;
  const char *xcode;
  const char *file;
  long line;
};

extern struct countbranch countbranch_data[];

void countbranch_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countexpr.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_


/*!BEGIN libc/nexgen32e/bench.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_BENCH_H_


/*!BEGIN libc/nexgen32e/rdtsc.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSC_H_
COSMOPOLITAN_C_START_

/**
 * Reads CPU timestamp counter.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(INVTSC)
 */
#define rdtsc() __RDTSC("rdtsc")

/**
 * Reads CPU timestamp counter w/ full serialization.
 *
 * This macro inhibits CPU magic.
 * This macro inhibits compiler magic.
 *
 * The clock isn't read until:
 *
 *   1. previous instructions finish executing; and
 *   2. previous loads are globally visible; and
 *   3. previous stores are globally visible.
 *
 * Later instructions won't dispatch until RDTSC completes.
 *
 * @see X86_HAVE(INVTSC)
 */
#define mfence_lfence_rdtsc_lfence() \
  __RDTSC("mfence\n\tlfence\n\trdtsc\n\tlfence")

#ifdef __x86__
#define __RDTSC(ASM)                                                       \
  ({                                                                       \
    uint64_t Rax, Rdx;                                                     \
    asm volatile(ASM : "=a"(Rax), "=d"(Rdx) : /* no inputs */ : "memory"); \
    Rdx << 32 | Rax;                                                       \
  })
#elif defined(__aarch64__)
#define __RDTSC(ASM)                                \
  ({                                                \
    uint64_t _Ts;                                   \
    asm volatile("mrs\t%0,cntvct_el0" : "=r"(_Ts)); \
    _Ts * 48; /* the fudge factor */                \
  })
#elif defined(__powerpc64__)
#define __RDTSC(ASM)                           \
  ({                                           \
    uint64_t _Ts;                              \
    asm volatile("mfspr\t%0,268" : "=r"(_Ts)); \
    _Ts;                                       \
  })
#elif defined(__riscv)
#define __RDTSC(ASM)                         \
  ({                                         \
    uint64_t _Ts;                            \
    asm volatile("rdcycle\t%0" : "=r"(_Ts)); \
    _Ts;                                     \
  })
#endif

COSMOPOLITAN_C_END_

/**
 * @fileoverview NexGen32e Microbenchmarking.
 *
 * @see X86_HAVE(INVTSC)
 * @see libc/testlib/bench.h
 */

#ifdef __x86__
#define __startbench()                            \
  ({                                              \
    uint64_t Ticks;                               \
    asm volatile("lfence\n\t"                     \
                 "push\t%%rbx\n\t"                \
                 "cpuid\n\t"                      \
                 "pop\t%%rbx\n\t"                 \
                 "rdtsc\n\t"                      \
                 "shl\t%2,%%rdx\n\t"              \
                 "or\t%%rdx,%0"                   \
                 : "=a"(Ticks)                    \
                 : "0"(0), "J"(32)                \
                 : "rcx", "rdx", "memory", "cc"); \
    Ticks;                                        \
  })
#define __endbench()                                     \
  ({                                                     \
    uint64_t Ticks;                                      \
    asm volatile("rdtscp\n\t"                            \
                 "shl\t%1,%%rdx\n\t"                     \
                 "or\t%%rdx,%%rax\n\t"                   \
                 "mov\t%%rax,%0\n\t"                     \
                 "xor\t%%eax,%%eax\n\t"                  \
                 "push\t%%rbx\n\t"                       \
                 "cpuid\n\t"                             \
                 "pop\t%%rbx"                            \
                 : "=r"(Ticks)                           \
                 : "J"(32)                               \
                 : "rax", "rcx", "rdx", "memory", "cc"); \
    Ticks;                                               \
  })
#else
#define __startbench()                \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#define __endbench()                  \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#endif

#define __startbench_m() mfence_lfence_rdtsc_lfence()
#define __endbench_m()   __startbench_m()
#define __marker()       asm("nop")
#define __ordered()      asm volatile("" ::: "memory")
#define __fakeread(X)    asm volatile("" : /* no outputs */ : "g"(X))
#define __fakereadwrite(X)                 \
  ({                                       \
    autotype(X) Res = (X);                 \
    asm volatile("" : "=g"(Res) : "0"(X)); \
    Res;                                   \
  })

COSMOPOLITAN_C_START_

/**
 * Shows nanosecond timings histogram for expr at exit().
 */
#define COUNTEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, rdtsc, rdtsc, \
             "COUNTEXPR")

/**
 * Like COUNTEXPR() but can be used on function calls that return void.
 */
#define COUNTSTMT(stmt)                                                    \
  (void)COUNTEXPR_((stmt, 0), #stmt, STRINGIFY(__FILE__), __LINE__, rdtsc, \
                   rdtsc, "COUNTSTMT")

/**
 * Same as COUNTEXPR() but uses Intel's expensive measurement technique.
 */
#define BENCHEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, __startbench, \
             __endbench, "BENCHEXPR")

#define COUNTEXPR_(expr, code, file, line, start, stop, macro) \
  COUNTEXPR__(expr, STRINGIFY(code), file, line, start, stop, STRINGIFY(macro))

#define COUNTEXPR__(expr, code, file, line, start, stop, macro) \
  ({                                                            \
    struct countexpr *InfO;                                     \
    uint64_t t1_, t2_, TiCkS, NaNoS;                            \
    t1_ = start();                                              \
    asm volatile("" ::: "memory");                              \
    autotype(expr) ReS = (expr);                                \
    asm volatile("" ::: "memory");                              \
    t2_ = stop();                                               \
    TiCkS = t2_ >= t1_ ? t2_ - t1_ : ~t1_ + t2_ + 1;            \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31340:\t.asciz\t" file "\n\t"                          \
        "31338:\t.asciz\t" code "\n"                            \
        "31332:\t.asciz\t" macro "\n"                           \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountexpr_data(%%rip)\n\t"                       \
        ".previous\n\t"                                         \
        ".section .sort.data.countexpr.2,\"a\",@progbits\n\t"   \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t" #line "\n\t"                                  \
        ".quad\t31340b\n\t"                                     \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31332b\n\t"                                     \
        ".rept\t65\n\t"                                         \
        ".quad\t0\n\t"                                          \
        ".endr\n\t"                                             \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(InfO));                                          \
    /* approximation of round(x*.323018) which is usually */    \
    /* the ratio, between x86 rdtsc ticks and nanoseconds */    \
    NaNoS = (TiCkS * 338709) >> 20;                             \
    ++InfO->logos[NaNoS ? bsrl(NaNoS) + 1 : 0];                 \
    ReS;                                                        \
  })

struct countexpr {
  long line; /* zero for last entry */
  const char *file;
  const char *code;
  const char *macro;
  long logos[65];
};

extern struct countexpr countexpr_data[];

void countexpr_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/gdb.h */

#define COSMOPOLITAN_LIBC_LOG_GDB_H_


/*!BEGIN libc/sysv/consts/nr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NR_H_
#ifdef _COSMO_SOURCE
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __NR_exit;
extern const int __NR_exit_group;
extern const int __NR_read;
extern const int __NR_write;
extern const int __NR_open;
extern const int __NR_close;
extern const int __NR_stat;
extern const int __NR_fstat;
extern const int __NR_lstat;
extern const int __NR_poll;
extern const int __NR_ppoll;
extern const int __NR_lseek;
extern const int __NR_mmap;
extern const int __NR_msync;
extern const int __NR_mprotect;
extern const int __NR_munmap;
extern const int __NR_sigaction;
extern const int __NR_sigprocmask;
extern const int __NR_ioctl;
extern const int __NR_pread;
extern const int __NR_pwrite;
extern const int __NR_readv;
extern const int __NR_writev;
extern const int __NR_access;
extern const int __NR_pipe;
extern const int __NR_select;
extern const int __NR_pselect;
extern const int __NR_pselect6;
extern const int __NR_sched_yield;
extern const int __NR_mremap;
extern const int __NR_mincore;
extern const int __NR_madvise;
extern const int __NR_shmget;
extern const int __NR_shmat;
extern const int __NR_shmctl;
extern const int __NR_dup;
extern const int __NR_dup2;
extern const int __NR_pause;
extern const int __NR_nanosleep;
extern const int __NR_getitimer;
extern const int __NR_setitimer;
extern const int __NR_alarm;
extern const int __NR_getpid;
extern const int __NR_sendfile;
extern const int __NR_socket;
extern const int __NR_connect;
extern const int __NR_accept;
extern const int __NR_sendto;
extern const int __NR_recvfrom;
extern const int __NR_sendmsg;
extern const int __NR_recvmsg;
extern const int __NR_shutdown;
extern const int __NR_bind;
extern const int __NR_listen;
extern const int __NR_getsockname;
extern const int __NR_getpeername;
extern const int __NR_socketpair;
extern const int __NR_setsockopt;
extern const int __NR_getsockopt;
extern const int __NR_fork;
extern const int __NR_vfork;
extern const int __NR_posix_spawn;
extern const int __NR_execve;
extern const int __NR_wait4;
extern const int __NR_kill;
extern const int __NR_killpg;
extern const int __NR_clone;
extern const int __NR_tkill;
extern const int __NR_futex;
extern const int __NR_set_robust_list;
extern const int __NR_get_robust_list;
extern const int __NR_uname;
extern const int __NR_semget;
extern const int __NR_semop;
extern const int __NR_semctl;
extern const int __NR_shmdt;
extern const int __NR_msgget;
extern const int __NR_msgsnd;
extern const int __NR_msgrcv;
extern const int __NR_msgctl;
extern const int __NR_fcntl;
extern const int __NR_flock;
extern const int __NR_fsync;
extern const int __NR_fdatasync;
extern const int __NR_truncate;
extern const int __NR_ftruncate;
extern const int __NR_getcwd;
extern const int __NR_chdir;
extern const int __NR_fchdir;
extern const int __NR_rename;
extern const int __NR_mkdir;
extern const int __NR_rmdir;
extern const int __NR_creat;
extern const int __NR_link;
extern const int __NR_unlink;
extern const int __NR_symlink;
extern const int __NR_readlink;
extern const int __NR_chmod;
extern const int __NR_fchmod;
extern const int __NR_chown;
extern const int __NR_fchown;
extern const int __NR_lchown;
extern const int __NR_umask;
extern const int __NR_gettimeofday;
extern const int __NR_getrlimit;
extern const int __NR_getrusage;
extern const int __NR_sysinfo;
extern const int __NR_times;
extern const int __NR_ptrace;
extern const int __NR_syslog;
extern const int __NR_getuid;
extern const int __NR_getgid;
extern const int __NR_getppid;
extern const int __NR_getpgrp;
extern const int __NR_setsid;
extern const int __NR_getsid;
extern const int __NR_getpgid;
extern const int __NR_setpgid;
extern const int __NR_geteuid;
extern const int __NR_getegid;
extern const int __NR_getgroups;
extern const int __NR_setgroups;
extern const int __NR_setreuid;
extern const int __NR_setregid;
extern const int __NR_setuid;
extern const int __NR_setgid;
extern const int __NR_setresuid;
extern const int __NR_setresgid;
extern const int __NR_getresuid;
extern const int __NR_getresgid;
extern const int __NR_sigpending;
extern const int __NR_sigsuspend;
extern const int __NR_sigaltstack;
extern const int __NR_mknod;
extern const int __NR_mknodat;
extern const int __NR_mkfifo;
extern const int __NR_mkfifoat;
extern const int __NR_statfs;
extern const int __NR_fstatfs;
extern const int __NR_getpriority;
extern const int __NR_setpriority;
extern const int __NR_mlock;
extern const int __NR_munlock;
extern const int __NR_mlockall;
extern const int __NR_munlockall;
extern const int __NR_setrlimit;
extern const int __NR_chroot;
extern const int __NR_sync;
extern const int __NR_acct;
extern const int __NR_settimeofday;
extern const int __NR_mount;
extern const int __NR_reboot;
extern const int __NR_quotactl;
extern const int __NR_setfsuid;
extern const int __NR_setfsgid;
extern const int __NR_capget;
extern const int __NR_capset;
extern const int __NR_sigtimedwait;
extern const int __NR_sigqueueinfo;
extern const int __NR_personality;
extern const int __NR_ustat;
extern const int __NR_sysfs;
extern const int __NR_sched_setparam;
extern const int __NR_sched_getparam;
extern const int __NR_sched_setscheduler;
extern const int __NR_sched_getscheduler;
extern const int __NR_sched_get_priority_max;
extern const int __NR_sched_get_priority_min;
extern const int __NR_sched_rr_get_interval;
extern const int __NR_vhangup;
extern const int __NR_modify_ldt;
extern const int __NR_pivot_root;
extern const int __NR__sysctl;
extern const int __NR_prctl;
extern const int __NR_arch_prctl;
extern const int __NR_adjtimex;
extern const int __NR_umount2;
extern const int __NR_swapon;
extern const int __NR_swapoff;
extern const int __NR_sethostname;
extern const int __NR_setdomainname;
extern const int __NR_iopl;
extern const int __NR_ioperm;
extern const int __NR_init_module;
extern const int __NR_delete_module;
extern const int __NR_gettid;
extern const int __NR_readahead;
extern const int __NR_setxattr;
extern const int __NR_fsetxattr;
extern const int __NR_getxattr;
extern const int __NR_fgetxattr;
extern const int __NR_listxattr;
extern const int __NR_flistxattr;
extern const int __NR_removexattr;
extern const int __NR_fremovexattr;
extern const int __NR_lsetxattr;
extern const int __NR_lgetxattr;
extern const int __NR_llistxattr;
extern const int __NR_lremovexattr;
extern const int __NR_sched_setaffinity;
extern const int __NR_sched_getaffinity;
extern const int __NR_cpuset_getaffinity;
extern const int __NR_cpuset_setaffinity;
extern const int __NR_io_setup;
extern const int __NR_io_destroy;
extern const int __NR_io_getevents;
extern const int __NR_io_submit;
extern const int __NR_io_cancel;
extern const int __NR_lookup_dcookie;
extern const int __NR_epoll_create;
extern const int __NR_epoll_wait;
extern const int __NR_epoll_ctl;
extern const int __NR_getdents;
extern const int __NR_set_tid_address;
extern const int __NR_restart_syscall;
extern const int __NR_semtimedop;
extern const int __NR_fadvise;
extern const int __NR_timer_create;
extern const int __NR_timer_settime;
extern const int __NR_timer_gettime;
extern const int __NR_timer_getoverrun;
extern const int __NR_timer_delete;
extern const int __NR_clock_settime;
extern const int __NR_clock_gettime;
extern const int __NR_clock_getres;
extern const int __NR_clock_nanosleep;
extern const int __NR_tgkill;
extern const int __NR_mbind;
extern const int __NR_set_mempolicy;
extern const int __NR_get_mempolicy;
extern const int __NR_mq_open;
extern const int __NR_mq_unlink;
extern const int __NR_mq_timedsend;
extern const int __NR_mq_timedreceive;
extern const int __NR_mq_notify;
extern const int __NR_mq_getsetattr;
extern const int __NR_kexec_load;
extern const int __NR_waitid;
extern const int __NR_add_key;
extern const int __NR_request_key;
extern const int __NR_keyctl;
extern const int __NR_ioprio_set;
extern const int __NR_ioprio_get;
extern const int __NR_inotify_init;
extern const int __NR_inotify_add_watch;
extern const int __NR_inotify_rm_watch;
extern const int __NR_openat;
extern const int __NR_mkdirat;
extern const int __NR_fchownat;
extern const int __NR_utime;
extern const int __NR_utimes;
extern const int __NR_futimesat;
extern const int __NR_futimes;
extern const int __NR_futimens;
extern const int __NR_fstatat;
extern const int __NR_unlinkat;
extern const int __NR_renameat;
extern const int __NR_linkat;
extern const int __NR_symlinkat;
extern const int __NR_readlinkat;
extern const int __NR_fchmodat;
extern const int __NR_faccessat;
extern const int __NR_unshare;
extern const int __NR_splice;
extern const int __NR_tee;
extern const int __NR_vmsplice;
extern const int __NR_migrate_pages;
extern const int __NR_move_pages;
extern const int __NR_preadv;
extern const int __NR_pwritev;
extern const int __NR_utimensat;
extern const int __NR_fallocate;
extern const int __NR_posix_fallocate;
extern const int __NR_accept4;
extern const int __NR_dup3;
extern const int __NR_pipe2;
extern const int __NR_epoll_pwait;
extern const int __NR_epoll_create1;
extern const int __NR_perf_event_open;
extern const int __NR_inotify_init1;
extern const int __NR_tgsigqueueinfo;
extern const int __NR_signalfd;
extern const int __NR_signalfd4;
extern const int __NR_eventfd;
extern const int __NR_eventfd2;
extern const int __NR_timerfd_create;
extern const int __NR_timerfd_settime;
extern const int __NR_timerfd_gettime;
extern const int __NR_recvmmsg;
extern const int __NR_fanotify_init;
extern const int __NR_fanotify_mark;
extern const int __NR_prlimit;
extern const int __NR_name_to_handle_at;
extern const int __NR_open_by_handle_at;
extern const int __NR_clock_adjtime;
extern const int __NR_syncfs;
extern const int __NR_sendmmsg;
extern const int __NR_setns;
extern const int __NR_getcpu;
extern const int __NR_process_vm_readv;
extern const int __NR_process_vm_writev;
extern const int __NR_kcmp;
extern const int __NR_finit_module;
extern const int __NR_sched_setattr;
extern const int __NR_sched_getattr;
extern const int __NR_renameat2;
extern const int __NR_seccomp;
extern const int __NR_getrandom;
extern const int __NR_memfd_create;
extern const int __NR_kexec_file_load;
extern const int __NR_bpf;
extern const int __NR_execveat;
extern const int __NR_userfaultfd;
extern const int __NR_membarrier;
extern const int __NR_mlock2;
extern const int __NR_copy_file_range;
extern const int __NR_preadv2;
extern const int __NR_pwritev2;
extern const int __NR_pkey_mprotect;
extern const int __NR_pkey_alloc;
extern const int __NR_pkey_free;
extern const int __NR_statx;
extern const int __NR_io_pgetevents;
extern const int __NR_rseq;
extern const int __NR_pidfd_send_signal;
extern const int __NR_io_uring_setup;
extern const int __NR_io_uring_enter;
extern const int __NR_io_uring_register;
extern const int __NR_pledge;
extern const int __NR_msyscall;
extern const int __NR_ktrace;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/w.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_W_H_
COSMOPOLITAN_C_START_

extern const int WNOHANG;
extern const int WUNTRACED;
extern const int WCONTINUED;

#define WNOHANG    1
#define WUNTRACED  WUNTRACED
#define WCONTINUED WCONTINUED


COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/**
 * @fileoverview GDB Attach Support Code.
 *
 * The goal of these macros is to make the backtrace into the failing
 * code as short as possible. It also helps avoid GDB getting confused
 * about how we don't use its readability destroying unwind directives.
 */

extern volatile int g_gdbsync;

int gdbexec(const char *);
int AttachDebugger(intptr_t);

#define AttachDebugger(CONTINUE_TO_ADDR) /* shorten backtraces */ \
  SYNCHRONIZE_DEBUGGER((AttachDebugger)(CONTINUE_TO_ADDR))

#define SYNCHRONIZE_DEBUGGER(PID)                                    \
  ({                                                                 \
    int Rc, Pid = (PID);                                             \
    if (Pid != -1) {                                                 \
      while ((Rc = __inline_wait4(Pid, NULL, WNOHANG, NULL)) == 0) { \
        if (g_gdbsync) {                                             \
          g_gdbsync = 0;                                             \
          if (Rc > 0) Pid = 0;                                       \
          break;                                                     \
        } else {                                                     \
          sched_yield();                                             \
        }                                                            \
      }                                                              \
    }                                                                \
    Pid;                                                             \
  })

#ifdef __x86_64__
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE)     \
  ({                                                                      \
    int64_t WaAx;                                                         \
    if (!IsWindows()) {                                                   \
      asm volatile("mov\t%5,%%r10\n\t"                                    \
                   "syscall"                                              \
                   : "=a"(WaAx)                                           \
                   : "0"(__NR_wait4), "D"(PID), "S"(OPT_OUT_WSTATUS),     \
                     "d"(OPTIONS), "g"(OPT_OUT_RUSAGE)                    \
                   : "rcx", "r8", "r9", "r10", "r11", "memory", "cc");    \
    } else {                                                              \
      WaAx = sys_wait4_nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \
    }                                                                     \
    WaAx;                                                                 \
  })
#else
#define __inline_wait4 wait4
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/log.h */

#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
#define COSMOPOLITAN_LIBC_LOG_LOG_H_


/*!BEGIN libc/stdio/stdio.h */

#define COSMOPOLITAN_LIBC_STDIO_H_

#define EOF    -1  /* end of file */
#define WEOF   -1u /* end of file (multibyte) */
#define _IOFBF 0   /* fully buffered */
#define _IOLBF 1   /* line buffered */
#define _IONBF 2   /* no buffering */

#define L_tmpnam     20
#define L_ctermid    20
#define P_tmpdir     "/tmp"
#define FILENAME_MAX 1024
#define FOPEN_MAX    1000
#define TMP_MAX      10000
#define BUFSIZ       4096

COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct FILE;
typedef struct FILE FILE;

extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;

errno_t ferror(FILE *) libcesque paramsnonnull();
void clearerr(FILE *) libcesque paramsnonnull();
int feof(FILE *) libcesque paramsnonnull();
int getc(FILE *) libcesque paramsnonnull();
int putc(int, FILE *) libcesque paramsnonnull();
int fflush(FILE *) libcesque;
int fpurge(FILE *) libcesque;
int fgetc(FILE *) libcesque paramsnonnull();
char *fgetln(FILE *, size_t *) libcesque paramsnonnull((1));
int ungetc(int, FILE *) libcesque paramsnonnull();
int fileno(FILE *) libcesque paramsnonnull() nosideeffect;
int fputc(int, FILE *) libcesque paramsnonnull();
int fputs(const char *, FILE *) libcesque paramsnonnull();
int fputws(const wchar_t *, FILE *) libcesque paramsnonnull();
void flockfile(FILE *) libcesque paramsnonnull();
void funlockfile(FILE *) libcesque paramsnonnull();
int ftrylockfile(FILE *) libcesque paramsnonnull();
char *fgets(char *, int, FILE *) libcesque paramsnonnull();
wchar_t *fgetws(wchar_t *, int, FILE *) libcesque paramsnonnull();
wint_t putwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t fputwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t putwchar(wchar_t) libcesque;
wint_t getwchar(void) libcesque;
wint_t getwc(FILE *) libcesque paramsnonnull();
wint_t fgetwc(FILE *) libcesque paramsnonnull();
wint_t ungetwc(wint_t, FILE *) libcesque paramsnonnull();
int getchar(void) libcesque;
int putchar(int) libcesque;
int puts(const char *) libcesque;
ssize_t getline(char **, size_t *, FILE *) libcesque paramsnonnull();
ssize_t getdelim(char **, size_t *, int, FILE *) libcesque paramsnonnull();
FILE *fopen(const char *, const char *) libcesque paramsnonnull((2)) __wur;
FILE *fdopen(int, const char *) libcesque paramsnonnull() __wur;
FILE *fmemopen(void *, size_t, const char *) libcesque paramsnonnull((3)) __wur;
FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3));
size_t fread(void *, size_t, size_t, FILE *) libcesque paramsnonnull((4));
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4));
int fclose(FILE *) libcesque;
int fseek(FILE *, long, int) libcesque paramsnonnull();
long ftell(FILE *) libcesque paramsnonnull();
int fseeko(FILE *, int64_t, int) libcesque paramsnonnull();
int64_t ftello(FILE *) libcesque paramsnonnull();
void rewind(FILE *) libcesque paramsnonnull();
int fopenflags(const char *) libcesque paramsnonnull();
void setlinebuf(FILE *) libcesque;
void setbuf(FILE *, char *) libcesque;
void setbuffer(FILE *, char *, size_t) libcesque;
int setvbuf(FILE *, char *, int, size_t) libcesque;
int pclose(FILE *) libcesque;
char *ctermid(char *) libcesque;
void perror(const char *) libcesque relegated;

typedef uint64_t fpos_t;
char *gets(char *) libcesque paramsnonnull();
int fgetpos(FILE *, fpos_t *) libcesque paramsnonnull();
int fsetpos(FILE *, const fpos_t *) libcesque paramsnonnull();

FILE *tmpfile(void) libcesque __wur;
char *tmpnam(char *) libcesque __wur;
char *tmpnam_r(char *) libcesque __wur;

FILE *popen(const char *, const char *) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » formatting                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int printf(const char *, ...) printfesque(1) paramsnonnull((1)) libcesque;
int vprintf(const char *, va_list) paramsnonnull() libcesque;
int fprintf(FILE *, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vfprintf(FILE *, const char *, va_list) paramsnonnull() libcesque;
int scanf(const char *, ...) libcesque scanfesque(1);
int vscanf(const char *, va_list) libcesque;
int fscanf(FILE *, const char *, ...) libcesque scanfesque(2);
int vfscanf(FILE *, const char *, va_list) libcesque;

int snprintf(char *, size_t, const char *, ...) printfesque(3) libcesque;
int vsnprintf(char *, size_t, const char *, va_list) libcesque;
int sprintf(char *, const char *, ...) libcesque;
int vsprintf(char *, const char *, va_list) libcesque;

int fwprintf(FILE *, const wchar_t *, ...) libcesque;
int fwscanf(FILE *, const wchar_t *, ...) libcesque;
int swprintf(wchar_t *, size_t, const wchar_t *, ...) libcesque;
int swscanf(const wchar_t *, const wchar_t *, ...) libcesque;
int vfwprintf(FILE *, const wchar_t *, va_list) libcesque;
int vfwscanf(FILE *, const wchar_t *, va_list) libcesque;
int vswprintf(wchar_t *, size_t, const wchar_t *, va_list) libcesque;
int vswscanf(const wchar_t *, const wchar_t *, va_list) libcesque;
int vwprintf(const wchar_t *, va_list) libcesque;
int vwscanf(const wchar_t *, va_list) libcesque;
int wprintf(const wchar_t *, ...) libcesque;
int wscanf(const wchar_t *, ...) libcesque;
int fwide(FILE *, int) libcesque;

int sscanf(const char *, const char *, ...) libcesque scanfesque(2);
int vsscanf(const char *, const char *, va_list) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » allocating                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int asprintf(char **, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » without mutexes                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int getc_unlocked(FILE *) libcesque paramsnonnull();
int puts_unlocked(const char *) libcesque;
int getchar_unlocked(void) libcesque;
int putc_unlocked(int, FILE *) libcesque paramsnonnull();
int putchar_unlocked(int) libcesque;
void clearerr_unlocked(FILE *) libcesque;
int feof_unlocked(FILE *) libcesque;
int ferror_unlocked(FILE *) libcesque;
int fileno_unlocked(FILE *) libcesque;
int fflush_unlocked(FILE *) libcesque;
int fgetc_unlocked(FILE *) libcesque;
int fputc_unlocked(int, FILE *) libcesque;
size_t fread_unlocked(void *, size_t, size_t, FILE *) libcesque;
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *) libcesque;
char *fgets_unlocked(char *, int, FILE *) libcesque;
int fputs_unlocked(const char *, FILE *) libcesque;
wint_t getwc_unlocked(FILE *) libcesque;
wint_t getwchar_unlocked(void) libcesque;
wint_t fgetwc_unlocked(FILE *) libcesque;
wint_t fputwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwchar_unlocked(wchar_t) libcesque;
wchar_t *fgetws_unlocked(wchar_t *, int, FILE *) libcesque;
int fputws_unlocked(const wchar_t *, FILE *) libcesque;
wint_t ungetwc_unlocked(wint_t, FILE *) libcesque paramsnonnull();
int ungetc_unlocked(int, FILE *) libcesque paramsnonnull();
int fseek_unlocked(FILE *, int64_t, int) libcesque paramsnonnull();
ssize_t getdelim_unlocked(char **, size_t *, int, FILE *) paramsnonnull();
int fprintf_unlocked(FILE *, const char *, ...) printfesque(2) libcesque;
int vfprintf_unlocked(FILE *, const char *, va_list) paramsnonnull() libcesque;

COSMOPOLITAN_C_END_

#define kLogFatal   0
#define kLogError   1
#define kLogWarn    2
#define kLogInfo    3
#define kLogVerbose 4
#define kLogDebug   5
#define kLogNoise   6

/**
 * Log level for compile-time DCE.
 */
#ifndef LOGGABLELEVEL
#ifndef TINY
#define LOGGABLELEVEL kLogNoise
/* #elif IsTiny() */
/* #define LOGGABLELEVEL kLogInfo */
#else
#define LOGGABLELEVEL kLogVerbose
#endif
#endif

#ifdef TINY
#define _LOG_TINY 1
#else
#define _LOG_TINY 0
#endif

COSMOPOLITAN_C_START_

extern FILE *__log_file;

int __watch(void *, size_t);
void __die(void) relegated wontreturn; /* print backtrace and abort() */
void _meminfo(int);                    /* shows malloc statistics &c. */
void _memsummary(int);                 /* light version of same thing */
const char *commandvenv(const char *, const char *);
const char *GetAddr2linePath(void);
const char *GetGdbPath(void);
bool32 IsDebuggerPresent(bool32);
bool32 IsRunningUnderMake(void);
char *GetSymbolByAddr(int64_t);
void PrintGarbage(void);
void PrintGarbageNumeric(FILE *);
void PrintWindowsMemory(const char *, size_t);

#ifndef __STRICT_ANSI__

#define _LOG_UNLIKELY(x) __builtin_expect(!!(x), 0)

extern unsigned __log_level; /* log level for runtime check */

#define LOGGABLE(LEVEL)                                          \
  ((!__builtin_constant_p(LEVEL) || (LEVEL) <= LOGGABLELEVEL) && \
   (LEVEL) <= __log_level)

// log a message with the specified log level (not checking if LOGGABLE)
#define LOGF(LEVEL, FMT, ...)                                   \
  do {                                                          \
    if (!_LOG_TINY) _log_untrace();                             \
    flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    if (!_LOG_TINY) _log_retrace();                             \
  } while (0)

// report an error without backtrace and debugger invocation
#define FATALF(FMT, ...)                                            \
  do {                                                              \
    if (!_LOG_TINY) _log_untrace();                                 \
    flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                   \
  } while (0)

#define DIEF(FMT, ...)                                                \
  do {                                                                \
    if (!_LOG_TINY) _log_untrace();                                   \
    ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    __builtin_unreachable();                                          \
  } while (0)

#define ERRORF(FMT, ...)                   \
  do {                                     \
    if (LOGGABLE(kLogError)) {             \
      LOGF(kLogError, FMT, ##__VA_ARGS__); \
    }                                      \
  } while (0)

#define WARNF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogWarn)) {             \
      LOGF(kLogWarn, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define INFOF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogInfo)) {             \
      LOGF(kLogInfo, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define VERBOSEF(FMT, ...)                                                  \
  do {                                                                      \
    if (LOGGABLE(kLogVerbose)) {                                            \
      if (!_LOG_TINY) _log_untrace();                                       \
      fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                       \
    }                                                                       \
  } while (0)

#define DEBUGF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define NOISEF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define FLOGF(F, FMT, ...)                                        \
  do {                                                            \
    if (LOGGABLE(kLogInfo)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FWARNF(F, FMT, ...)                                       \
  do {                                                            \
    if (LOGGABLE(kLogWarn)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FFATALF(F, FMT, ...)                                     \
  do {                                                           \
    if (!_LOG_TINY) _log_untrace();                              \
    flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                \
  } while (0)

#define FDEBUGF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define FNOISEF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define LOGIFNEG1(FORM)                                                \
  ({                                                                   \
    int e = _log_get_errno();                                          \
    autotype(FORM) Ax = (FORM);                                        \
    if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
      if (!_LOG_TINY) _log_untrace();                                  \
      _log_errno(__FILE__, __LINE__, #FORM);                           \
      if (!_LOG_TINY) _log_retrace();                                  \
      _log_set_errno(e);                                               \
    }                                                                  \
    Ax;                                                                \
  })

#define LOGIFNULL(FORM)                      \
  ({                                         \
    int e = _log_get_errno();                \
    autotype(FORM) Ax = (FORM);              \
    if (Ax == NULL && LOGGABLE(kLogWarn)) {  \
      if (!_LOG_TINY) _log_untrace();        \
      _log_errno(__FILE__, __LINE__, #FORM); \
      if (!_LOG_TINY) _log_retrace();        \
      _log_set_errno(e);                     \
    }                                        \
    Ax;                                      \
  })

void _log_errno(const char *, int, const char *) relegated;
int _log_get_errno(void);
void _log_set_errno(int);
void _log_untrace(void);
void _log_retrace(void);
void _log_exit(int) wontreturn;

#define ARGS  unsigned, const char *, int, FILE *, const char *
#define ATTR  paramsnonnull((5)) printfesque(5)
#define ATTRV paramsnonnull((5))
void flogf(ARGS, ...) ATTR libcesque;
void vflogf(ARGS, va_list) ATTRV libcesque;
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfverbosef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fdebugf(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfdebugf(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fnoisef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfnoisef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void ffatalf(ARGS, ...) asm("flogf") ATTR relegated wontreturn libcesque;
void vffatalf(ARGS, va_list) asm("vflogf") ATTRV relegated wontreturn libcesque;
#undef ARGS
#undef ATTR
#undef ATTRV

#endif /* __STRICT_ANSI__ */
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_LOG_LOG_H_ */


/*!BEGIN libc/log/traceme.h */

#define COSMOPOLITAN_LIBC_LOG_TRACEME_H_
COSMOPOLITAN_C_START_

extern int traceme;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alg.h */

#define COSMOPOLITAN_LIBC_ALG_ALG_H_
COSMOPOLITAN_C_START_

void *bsearch(const void *, const void *, size_t, size_t,
              int (*)(const void *, const void *)) paramsnonnull() nosideeffect;
void *bsearch_r(const void *, const void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 2, 5)) nosideeffect;
void djbsort(int32_t *, size_t) libcesque;
void qsort3(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort_r(void *, size_t, size_t,
             int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 4));
void smoothsort(void *, size_t, size_t, int (*)(const void *, const void *));
void smoothsort_r(void *, size_t, size_t,
                  int (*)(const void *, const void *, void *), void *);
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
int heapsort_r(void *, size_t, size_t,
               int (*)(const void *, const void *, void *), void *);
int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
int mergesort_r(void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *);

int radix_sort_int32(int32_t *, size_t) libcesque;
int radix_sort_int64(int64_t *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alloca.h */

#define COSMOPOLITAN_LIBC_MEM_ALLOCA_H_

#define alloca(size) __builtin_alloca(size)



/*!BEGIN libc/mem/critbit0.h */

#define COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § data structures » critical bit tree (for c strings)       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct critbit0 {
  void *root;
  size_t count;
};

bool critbit0_contains(struct critbit0 *, const char *) libcesque nosideeffect
    paramsnonnull();
int critbit0_insert(struct critbit0 *, const char *) paramsnonnull();
bool critbit0_delete(struct critbit0 *, const char *) libcesque paramsnonnull();
void critbit0_clear(struct critbit0 *) libcesque paramsnonnull();
char *critbit0_get(struct critbit0 *, const char *);
intptr_t critbit0_allprefixed(struct critbit0 *, const char *,
                              intptr_t (*)(const char *, void *), void *)
    paramsnonnull((1, 2, 3)) libcesque;
int critbit0_emplace(struct critbit0 *, const void *, size_t) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/gc.h */

#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_
#define COSMOPOLITAN_LIBC_MEM_GC_H_
COSMOPOLITAN_C_START_

libcesque void _gc_free(void *);
libcesque void __defer(void *, void *, void *);
libcesque void gclongjmp(void *, int) wontreturn;
#define gc(THING)  defer((void *)_gc_free, (void *)(THING))
#define _gc(THING) defer((void *)_gc_free, (void *)(THING))
#define defer(FN, ARG)                             \
  ({                                               \
    autotype(ARG) Arg = (ARG);                     \
    /* prevent weird opts like tail call */        \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    __defer(__builtin_frame_address(0), FN, Arg);  \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    Arg;                                           \
  })

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */


/*!BEGIN libc/mem/mem.h */

#define COSMOPOLITAN_LIBC_MEM_MEM_H_

#define M_TRIM_THRESHOLD (-1)
#define M_GRANULARITY    (-2)
#define M_MMAP_THRESHOLD (-3)

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dynamic memory                                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

void free(void *) libcesque;
void *malloc(size_t) attributeallocsize((1)) mallocesque;
void *calloc(size_t, size_t) attributeallocsize((1, 2)) mallocesque;
void *memalign(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
void *realloc(void *, size_t) reallocesque;
void *realloc_in_place(void *, size_t) reallocesque;
void *reallocarray(void *, size_t, size_t) __wur;
void *valloc(size_t) attributeallocsize((1)) vallocesque;
void *pvalloc(size_t) vallocesque;
char *strdup(const char *) paramsnonnull() mallocesque;
char *strndup(const char *, size_t) paramsnonnull() mallocesque;
void *aligned_alloc(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
int posix_memalign(void **, size_t, size_t) libcesque;

int mallopt(int, int) libcesque;
int malloc_trim(size_t) libcesque;
size_t bulk_free(void **, size_t) libcesque;
size_t malloc_usable_size(void *) libcesque;
void **independent_calloc(size_t, size_t, void **) libcesque;
void **independent_comalloc(size_t, size_t *, void **) libcesque;

wchar_t *wcsdup(const wchar_t *) strlenesque __wur;

struct mallinfo {
  size_t arena;    /* non-mmapped space allocated from system */
  size_t ordblks;  /* number of free chunks */
  size_t smblks;   /* always 0 */
  size_t hblks;    /* always 0 */
  size_t hblkhd;   /* space in mmapped regions */
  size_t usmblks;  /* maximum total allocated space */
  size_t fsmblks;  /* always 0 */
  size_t uordblks; /* total allocated space */
  size_t fordblks; /* total free space */
  size_t keepcost; /* releasable (via malloc_trim) space */
};

struct mallinfo mallinfo(void) libcesque;

size_t malloc_footprint(void) libcesque;
size_t malloc_max_footprint(void) libcesque;
size_t malloc_footprint_limit(void) libcesque;
size_t malloc_set_footprint_limit(size_t) libcesque;
void malloc_inspect_all(void (*)(void *, void *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/cachesize.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CACHESIZE_H_

#define kCpuCacheTypeData        1
#define kCpuCacheTypeInstruction 2
#define kCpuCacheTypeUnified     3

COSMOPOLITAN_C_START_

unsigned _getcachesize(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/crc32.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CRC32_H_
COSMOPOLITAN_C_START_

extern const uint32_t kCrc32cTab[256];

void crc32init(uint32_t[hasatleast 256], uint32_t);
uint32_t crc32c(uint32_t, const void *, size_t) nosideeffect;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/ffs.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_
COSMOPOLITAN_C_START_

int ffs(int) pureconst;
int ffsl(long) pureconst;
int ffsll(long long) pureconst;

#ifdef __GNUC__
#define ffs(u)   __builtin_ffs(u)
#define ffsl(u)  __builtin_ffsl(u)
#define ffsll(u) __builtin_ffsll(u)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/kompressor.h */

#define COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
#ifdef _COSMO_SOURCE

#define rldecode  __rldecode
#define rldecode2 __rldecode2
#define lz4check  __lz4check
#define lz4cpy    __lz4cpy
#define lz4len    __lz4len
#define lz4decode __lz4decode

COSMOPOLITAN_C_START_

struct RlDecode {
  uint8_t repititions;
  uint8_t byte;
};

void rldecode(void *dest, const struct RlDecode *);
void rldecode2(void *dest, const struct RlDecode *);
const uint8_t *lz4check(const void *data);
void *lz4cpy(void *dest, const void *blockdata, size_t blocksize);
size_t lz4len(const void *blockdata, size_t blocksize);
void *lz4decode(void *dest, const void *src);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/nexgen32e/lz4.h */

#define COSMOPOLITAN_LIBC_LZ4_H_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4                                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  LZ4 is a brilliant framing format for REP MOVSB designed by Yann Collet.

  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md
  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Block_format.md
  @see http://ticki.github.io/blog/how-lz4-works/ */

#define LZ4_EOF                0
#define LZ4_VERSION            1
#define LZ4_MAGICNUMBER        0x184D2204
#define LZ4_SKIPPABLE0         0x184D2A50
#define LZ4_SKIPPABLEMASK      0xFFFFFFF0
#define LZ4_MAXHEADERSIZE      (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1)
#define LZ4_BLOCKMAXSIZE_64KB  4
#define LZ4_BLOCKMAXSIZE_256KB 5
#define LZ4_BLOCKMAXSIZE_1MB   6
#define LZ4_BLOCKMAXSIZE_4MB   7

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » frames                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_MAGIC(FRAME)                      READ32LE(FRAME)
#define LZ4_FRAME_VERSION(FRAME)              ((_LZ4_FRAME_FLG(FRAME) >> 6) & 3)
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
#define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1)
#define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \
  ((_LZ4_FRAME_FLG(FRAME) >> 2) & 1)
#define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1)
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME)     ((_LZ4_FRAME_BD(FRAME) >> 4) & 7)
#define LZ4_FRAME_RESERVED1(FRAME)        ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
#define LZ4_FRAME_RESERVED2(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
#define LZ4_FRAME_RESERVED3(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 0) & 15)
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
  (LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? READ64LE((FRAME) + 4 + 1 + 1) : 0)
#define LZ4_FRAME_DICTIONARYID(FRAME)                          \
  (LZ4_FRAME_DICTIONARYIDFLAG(FRAME)                           \
       ? READ32LE(((FRAME) + 4 + 1 + 1 +                       \
                   8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME))) \
       : 0)
#define LZ4_FRAME_HEADERCHECKSUM(FRAME)                                \
  (*((FRAME) + 4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
     4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME)))
#define LZ4_FRAME_HEADERSIZE(FRAME)                        \
  (4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
   4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME) + 1)
#define _LZ4_FRAME_FLG(FRAME) (*((FRAME) + 4))
#define _LZ4_FRAME_BD(FRAME)  (*((FRAME) + 5))

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » blocks                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_BLOCK_DATA(block)         (block + sizeof(uint32_t))
#define LZ4_BLOCK_DATASIZE(block)     (READ32LE(block) & 0x7fffffff)
#define LZ4_BLOCK_ISEOF(block)        (READ32LE(block) == LZ4_EOF)
#define LZ4_BLOCK_ISCOMPRESSED(block) ((READ32LE(block) & 0x80000000) == 0)
#define LZ4_BLOCK_SIZE(frame, block)              \
  (sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \
   (LZ4_FRAME_BLOCKCHECKSUMFLAG(frame) ? sizeof(uint8_t) : 0))

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nexgen32e.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NEXGEN32E_H_
COSMOPOLITAN_C_START_

extern long kHalfCache3;
extern const uint64_t kTens[20];
extern const uint32_t kSha256[64];
extern const uint64_t kSha512[80];
extern const unsigned char kTensIndex[64];

void CheckStackIsAligned(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nt2sysv.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_


/*!BEGIN libc/nexgen32e/trampoline.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_

#define TRAMPOLINE(FUNCTION, THUNK)   \
  ({                                  \
    typeof(FUNCTION) *Tramp;          \
    asm(".section .text.trampoline\n" \
        "183:\n\t"                    \
        "mov\t%1,%%eax\n\t"           \
        "jmp\t" #THUNK "\n\t"         \
        ".previous\n\t"               \
        "mov\t$183b,%k0"              \
        : "=r"(Tramp)                 \
        : "i"(FUNCTION));             \
    Tramp;                            \
  })


/**
 * Creates function to thunk FUNCTION from MSX64 to System V ABI.
 *
 * This macro should be used when specifying callbacks in the WIN32 API.
 */
#define NT2SYSV(FUNCTION) TRAMPOLINE(FUNCTION, __nt2sysv)



/*!BEGIN libc/nexgen32e/rdtscp.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_
COSMOPOLITAN_C_START_

#define TSC_AUX_CORE(MSR) ((MSR) & 0xfff)
#define TSC_AUX_NODE(MSR) (((MSR) >> 12) & 0xfff)

/**
 * Reads CPU timestamp counter and IA32_TSC_AUX.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(RDTSCP)
 */
#define rdtscp(OPT_OUT_IA32_TSC_AUX)               \
  ({                                               \
    uint64_t Rax, Rdx;                             \
    uint32_t Ecx, *EcxOut;                         \
    asm volatile("rdtscp"                          \
                 : "=a"(Rax), "=c"(Ecx), "=d"(Rdx) \
                 : /* no inputs */                 \
                 : "memory");                      \
    EcxOut = (OPT_OUT_IA32_TSC_AUX);               \
    if (EcxOut) *EcxOut = Ecx;                     \
    Rdx << 32 | Rax;                               \
  })

/**
 * Reads timestamp counter auxiliary model specific register value.
 */
#define rdpid()                                                           \
  ({                                                                      \
    long Msr;                                                             \
    bool32 Ok;                                                            \
    Ok = false;                                                           \
    if (X86_HAVE(RDPID)) {                                                \
      asm volatile("rdpid\t%0" : "=r"(Msr) : /* no inputs */ : "memory"); \
      Ok = true;                                                          \
    } else if (IsLinux()) {                                               \
      char *p = (char *)0x7b;                                             \
      asm volatile(ZFLAG_ASM("lsl\t%2,%1")                                \
                   : ZFLAG_CONSTRAINT(Ok), "=r"(Msr)                      \
                   : "r"(p)                                               \
                   : "memory");                                           \
    }                                                                     \
    if (!Ok && X86_HAVE(RDTSCP)) {                                        \
      asm volatile("rdtscp"                                               \
                   : "=c"(Msr)                                            \
                   : /* no inputs */                                      \
                   : "eax", "edx", "memory");                             \
      Ok = true;                                                          \
    }                                                                     \
    if (!Ok) {                                                            \
      Msr = -1;                                                           \
    }                                                                     \
    Msr;                                                                  \
  })

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/sha.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_SHA_H_
COSMOPOLITAN_C_START_

void sha1_transform_avx2(uint32_t[hasatleast 5], const void *, unsigned);
void sha1_transform_ni(uint32_t[hasatleast 5], const void *, unsigned);
void sha256_transform_rorx(uint32_t[hasatleast 8], const void *, unsigned);
void sha256_transform_ni(uint32_t[hasatleast 8], const void *, unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/stackframe.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
COSMOPOLITAN_C_START_

struct StackFrame {
  struct StackFrame *next;
  intptr_t addr;
};

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_ */


/*!BEGIN libc/nexgen32e/x86info.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86INFO_H_

#define kX86CpuStepping    ((KCPUIDS(1H, EAX) >> 0) & 15)
#define kX86CpuModelid     ((KCPUIDS(1H, EAX) >> 4) & 15)
#define kX86CpuFamilyid    ((KCPUIDS(1H, EAX) >> 8) & 15)
#define kX86CpuType        ((KCPUIDS(1H, EAX) >> 12) & 3)
#define kX86CpuExtmodelid  ((KCPUIDS(1H, EAX) >> 16) & 15)
#define kX86CpuExtfamilyid ((KCPUIDS(1H, EAX) >> 20) & 255)

#define kX86CpuFamily \
  (kX86CpuFamilyid + (kX86CpuFamilyid == 15 ? kX86CpuExtfamilyid : 0))

#define kX86CpuModel                                                       \
  (kX86CpuModelid |                                                        \
   (kX86CpuFamilyid == 6 || kX86CpuFamilyid == 15 ? kX86CpuExtmodelid : 0) \
       << 4)

#define kX86ProcessorModelKey                                                 \
  (kX86CpuExtfamilyid << 12 | kX86CpuFamilyid << 8 | kX86CpuExtmodelid << 4 | \
   kX86CpuModelid)

#define X86_MARCH_UNKNOWN        0
#define X86_MARCH_CORE2          1
#define X86_MARCH_NEHALEM        2
#define X86_MARCH_WESTMERE       3
#define X86_MARCH_SANDYBRIDGE    4
#define X86_MARCH_IVYBRIDGE      5
#define X86_MARCH_HASWELL        6
#define X86_MARCH_BROADWELL      7
#define X86_MARCH_SKYLAKE        8
#define X86_MARCH_KABYLAKE       9
#define X86_MARCH_CANNONLAKE     10
#define X86_MARCH_ICELAKE        11
#define X86_MARCH_TIGERLAKE      12
#define X86_MARCH_BONNELL        13
#define X86_MARCH_SALTWELL       14
#define X86_MARCH_SILVERMONT     15
#define X86_MARCH_AIRMONT        16
#define X86_MARCH_GOLDMONT       17
#define X86_MARCH_GOLDMONTPLUS   18
#define X86_MARCH_TREMONT        19
#define X86_MARCH_KNIGHTSLANDING 20
#define X86_MARCH_KNIGHTSMILL    21
#define X86_MARCH_SAPPHIRERAPIDS 22
#define X86_MARCH_ALDERLAKE      23
#define X86_MARCH_COMETLAKE      24
#define X86_MARCH_RAPTORLAKE     25
#define X86_MARCH_ROCKETLAKE     26

#define X86_GRADE_UNKNOWN   0
#define X86_GRADE_APPLIANCE 1
#define X86_GRADE_MOBILE    2
#define X86_GRADE_TABLET    3
#define X86_GRADE_DESKTOP   4
#define X86_GRADE_CLIENT    5
#define X86_GRADE_DENSITY   6
#define X86_GRADE_SERVER    7
#define X86_GRADE_SCIENCE   8

struct X86ProcessorModel {
  short key;
  unsigned char march;
  unsigned char grade;
};

extern const size_t kX86ProcessorModelCount;
extern const struct X86ProcessorModel kX86ProcessorModels[];

const struct X86ProcessorModel *getx86processormodel(short) nosideeffect;



/*!BEGIN libc/nt/enum/accessmask.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ACCESSMASK_H_

#define kNtGenericRead            0x80000000u
#define kNtGenericWrite           0x40000000u
#define kNtGenericExecute         0x20000000u
#define kNtGenericAll             0x10000000u
#define kNtDelete                 0x00010000u
#define kNtReadControl            0x00020000u
#define kNtWriteDac               0x00040000u
#define kNtWriteOwner             0x00080000u
#define kNtSynchronize            0x00100000u
#define kNtStandardRightsRequired 0x000F0000u
#define kNtStandardRightsRead     kNtReadControl
#define kNtStandardRightsWrite    kNtReadControl
#define kNtStandardRightsExecute  kNtReadControl
#define kNtStandardRightsAll      0x001F0000u
#define kNtSpecificRightsAll      0x0000FFFFu
#define kNtAccessSystemSecurity   0x01000000u
#define kNtMaximumAllowed         0x02000000u
#define kNtFileReadData           0x0001u
#define kNtFileListDirectory      0x0001u
#define kNtFileWriteData          0x0002u
#define kNtFileAddFile            0x0002u
#define kNtFileAppendData         0x0004u
#define kNtFileAddSubdirectory    0x0004u
#define kNtFileCreatePipeInstance 0x0004u
#define kNtFileReadEa             0x0008u
#define kNtFileWriteEa            0x0010u
#define kNtFileExecute            0x0020u
#define kNtFileTraverse           0x0020u
#define kNtFileDeleteChild        0x0040u
#define kNtFileReadAttributes     0x0080u
#define kNtFileWriteAttributes    0x0100u
#define kNtFileAllAccess          (kNtStandardRightsRequired | kNtSynchronize | 0x1FFu)
#define kNtFileGenericRead                                           \
  (kNtStandardRightsRead | kNtFileReadData | kNtFileReadAttributes | \
   kNtFileReadEa | kNtSynchronize)
#define kNtFileGenericWrite                                             \
  (kNtStandardRightsWrite | kNtFileWriteData | kNtFileWriteAttributes | \
   kNtFileWriteEa | kNtFileAppendData | kNtSynchronize)
#define kNtFileGenericExecute                                          \
  (kNtStandardRightsExecute | kNtFileReadAttributes | kNtFileExecute | \
   kNtSynchronize)
#define kNtTokenAssignPrimary    0x0001u
#define kNtTokenDuplicate        0x0002u
#define kNtTokenImpersonate      0x0004u
#define kNtTokenQuery            0x0008u
#define kNtTokenQuerySource      0x0010u
#define kNtTokenAdjustPrivileges 0x0020u
#define kNtTokenAdjustGroups     0x0040u
#define kNtTokenAdjustDefault    0x0080u
#define kNtTokenAdjustSessionid  0x0100u
#define kNtTokenAllAccessP                                                 \
  (kNtStandardRightsRequired | kNtTokenAssignPrimary | kNtTokenDuplicate | \
   kNtTokenImpersonate | kNtTokenQuery | kNtTokenQuerySource |             \
   kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | kNtTokenAdjustDefault)
#define kNtTokenAllAccess kNtTokenAllAccessP | kNtTokenAdjustSessionid
#define kNtTokenRead      kNtStandardRightsRead | kNtTokenQuery
#define kNtTokenWrite                                                         \
  (kNtStandardRightsWrite | kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | \
   kNtTokenAdjustDefault)
#define kNtTokenExecute kNtStandardRightsExecute
#define kNtTokenTrustConstraintMask \
  (kNtStandardRightsRead | kNtTokenQuery | kNtTokenQuerySource)
#define kNtTokenAccessPseudoHandleWin8 kNtTokenQuery | kNtTokenQuerySource
#define kNtTokenAccessPseudoHandle     kNtTokenAccessPseudoHandleWin8



/*!BEGIN libc/nt/enum/afd.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_AFD_H_

#define kNtAfdPollReceive          0x0001
#define kNtAfdPollReceiveExpedited 0x0002
#define kNtAfdPollSend             0x0004
#define kNtAfdPollDisconnect       0x0008
#define kNtAfdPollAbort            0x0010
#define kNtAfdPollLocalClose       0x0020
#define kNtAfdPollAccept           0x0080
#define kNtAfdPollConnectFail      0x0100



/*!BEGIN libc/nt/enum/bitblt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_BITBLT_H_

#define kNtSrccopy     0x00CC0020u /* src */
#define kNtSrcpaint    0x00EE0086u /* src | dst */
#define kNtSrcand      0x008800C6u /* src & dst */
#define kNtSrcinvert   0x00660046u /* src ^ dst */
#define kNtSrcerase    0x00440328u /* src & ~dst */
#define kNtNotsrccopy  0x00330008u /* ~src */
#define kNtNotsrcerase 0x001100A6u /* ~src & ~dst */
#define kNtMergecopy   0x00C000CAu /* (src & pattern) */
#define kNtMergepaint  0x00BB0226u /* ~src | dst */
#define kNtPatcopy     0x00F00021u /* pat */
#define kNtPatpaint    0x00FB0A09u /* wut */
#define kNtPatinvert   0x005A0049u /* pat ^ dst */
#define kNtDstinvert   0x00550009u /* ~dst */
#define kNtBlackness   0x00000042u /* black */
#define kNtWhiteness   0x00FF0062u /* white */



/*!BEGIN libc/nt/enum/callback.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CALLBACK_H_

#define kNtCallbackChunkFinished 0
#define kNtCallbackStreamSwitch  1



/*!BEGIN libc/nt/enum/color.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COLOR_H_

#define kNtColorScrollbar               0
#define kNtColorBackground              1
#define kNtColorActivecaption           2
#define kNtColorInactivecaption         3
#define kNtColorMenu                    4
#define kNtColorWindow                  5
#define kNtColorWindowframe             6
#define kNtColorMenutext                7
#define kNtColorWindowtext              8
#define kNtColorCaptiontext             9
#define kNtColorActiveborder            10
#define kNtColorInactiveborder          11
#define kNtColorAppworkspace            12
#define kNtColorHighlight               13
#define kNtColorHighlighttext           14
#define kNtColorBtnface                 15
#define kNtColorBtnshadow               16
#define kNtColorGraytext                17
#define kNtColorBtntext                 18
#define kNtColorInactivecaptiontext     19
#define kNtColorBtnhighlight            20
#define kNtColor3ddkshadow              21
#define kNtColor3dlight                 22
#define kNtColorInfotext                23
#define kNtColorInfobk                  24
#define kNtColorHotlight                26
#define kNtColorGradientactivecaption   27
#define kNtColorGradientinactivecaption 28
#define kNtColorMenuhilight             29
#define kNtColorMenubar                 30



/*!BEGIN libc/nt/enum/computernameformat.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COMPUTERNAMEFORMAT_H_

#define kNtComputerNameNetBios                   0
#define kNtComputerNameDnsHostname               1
#define kNtComputerNameDnsDomain                 2
#define kNtComputerNameDnsFullyQualified         3
#define kNtComputerNamePhysicalNetBios           4
#define kNtComputerNamePhysicalDnsHostname       5
#define kNtComputerNamePhysicalDnsDomain         6
#define kNtComputerNamePhysicalDnsFullyQualified 7
#define kNtComputerName_MAX                      8



/*!BEGIN libc/nt/enum/consolemodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLEMODEFLAGS_H_

/* input mode */
#define kNtEnableProcessedInput 0x0001u
#define kNtEnableLineInput 0x0002u
#define kNtEnableEchoInput 0x0004u
#define kNtEnableWindowInput 0x0008u
#define kNtEnableMouseInput 0x0010u
#define kNtEnableInsertMode 0x0020u
#define kNtEnableQuickEditMode 0x0040u
#define kNtEnableExtendedFlags 0x0080u
#define kNtEnableAutoPosition 0x0100u
#define kNtEnableVirtualTerminalInput 0x0200u

/* output mode */
#define kNtEnableProcessedOutput 0x0001u
#define kNtEnableWrapAtEolOutput 0x0002u
#define kNtEnableVirtualTerminalProcessing 0x0004u
#define kNtDisableNewlineAutoReturn 0x0008u
#define kNtEnableLvbGridWorldwide 0x0010u



/*!BEGIN libc/nt/enum/consoleselectionflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLESELECTIONFLAGS_H_

#define kNtConsoleNoSelection 0x0000u
#define kNtConsoleSelectionInProgress 0x0001u
#define kNtConsoleSelectionNotEmpty 0x0002u
#define kNtConsoleMouseSelection 0x0004u
#define kNtConsoleMouseDown 0x0008u



/*!BEGIN libc/nt/enum/context.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONTEXT_H_

#define kNtContextAmd64 0x00100000

#define kNtContextControl        (kNtContextAmd64 | 0x00000001)
#define kNtContextInteger        (kNtContextAmd64 | 0x00000002)
#define kNtContextSegments       (kNtContextAmd64 | 0x00000004)
#define kNtContextFloatingPoint  (kNtContextAmd64 | 0x00000008)
#define kNtContextDebugRegisters (kNtContextAmd64 | 0x00000010)

#define kNtContextFull \
  (kNtContextControl | kNtContextInteger | kNtContextFloatingPoint)

#define kNtContextAll                                           \
  (kNtContextControl | kNtContextInteger | kNtContextSegments | \
   kNtContextFloatingPoint | kNtContextDebugRegisters)

#define kNtContextXstate (kNtContextAmd64 | 0x00000040)



/*!BEGIN libc/nt/enum/copyfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COPYFILE_H_

#define kNtCopyFileFailIfExists              0x00000001
#define kNtCopyFileRestartable               0x00000002
#define kNtCopyFileOpenSourceForWrite        0x00000004
#define kNtCopyFileAllowDecryptedDestination 0x00000008
#define kNtCopyFileCopySymlink               0x00000800
#define kNtCopyFileNoBuffering               0x00001000
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileResumeFromPause           0x00004000 /* Win8+ */
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileNoOffload                 0x00040000 /* Win8+ */
#define kNtCopyFileIgnoreEdpBlock            0x00400000 /* Win10+ */
#define kNtCopyFileIgnoreSourceEncryption    0x00800000 /* Win10+ */



/*!BEGIN libc/nt/enum/creationdisposition.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CREATIONDISPOSITION_H_

#define kNtCreateNew 1
#define kNtCreateAlways 2
#define kNtOpenExisting 3
#define kNtOpenAlways 4
#define kNtTruncateExisting 5



/*!BEGIN libc/nt/enum/cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CS_H_

#define kNtCsVredraw         0x00000001
#define kNtCsHredraw         0x00000002
#define kNtCsDblclks         0x00000008
#define kNtCsOwndc           0x00000020
#define kNtCsClassdc         0x00000040
#define kNtCsParentdc        0x00000080
#define kNtCsNoclose         0x00000200
#define kNtCsSavebits        0x00000800
#define kNtCsBytealignclient 0x00001000
#define kNtCsBytealignwindow 0x00002000
#define kNtCsGlobalclass     0x00004000
#define kNtCsIme             0x00010000
#define kNtCsDropshadow      0x00020000



/*!BEGIN libc/nt/enum/ctrlevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CTRLEVENT_H_

#define kNtCtrlCEvent 0      /* SIGINT */
#define kNtCtrlBreakEvent 1  /* SIGQUIT */
#define kNtCtrlCloseEvent 2  /* SIGHUP */
#define kNtCtrlLogoffEvent 5 /* SIGTERM */
#define kNtCtrlShutdownEvent 6



/*!BEGIN libc/nt/enum/cw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CW_H_

#define kNtCwUsedefault ((int)0x80000000)



/*!BEGIN libc/nt/enum/dialogresult.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_DIALOGRESULT_H_

#define kNtIdok       1
#define kNtIdcancel   2
#define kNtIdabort    3
#define kNtIdretry    4
#define kNtIdignore   5
#define kNtIdyes      6
#define kNtIdno       7
#define kNtIdclose    8
#define kNtIdhelp     9
#define kNtIdtryagain 10
#define kNtIdcontinue 11



/*!BEGIN libc/nt/enum/errormodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ERRORMODEFLAGS_H_

#define kNtErrorModeDefault      0x0
#define kNtSemFailcriticalerrors 0x1
#define kNtSemNogpfaulterrorbox  0x2
#define kNtSemNoopenfileerrorbox 0x8000



/*!BEGIN libc/nt/enum/event.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENT_H_

#define kNtEventSystemSound            0x0001
#define kNtEventSystemAlert            0x0002
#define kNtEventSystemForeground       0x0003
#define kNtEventSystemMenustart        0x0004
#define kNtEventSystemMenuend          0x0005
#define kNtEventSystemMenupopupstart   0x0006
#define kNtEventSystemMenupopupend     0x0007
#define kNtEventSystemCapturestart     0x0008
#define kNtEventSystemCaptureend       0x0009
#define kNtEventSystemMovesizestart    0x000A
#define kNtEventSystemMovesizeend      0x000B
#define kNtEventSystemContexthelpstart 0x000C
#define kNtEventSystemContexthelpend   0x000D
#define kNtEventSystemDragdropstart    0x000E
#define kNtEventSystemDragdropend      0x000F
#define kNtEventSystemDialogstart      0x0010
#define kNtEventSystemDialogend        0x0011
#define kNtEventSystemScrollingstart   0x0012
#define kNtEventSystemScrollingend     0x0013
#define kNtEventSystemSwitchstart      0x0014
#define kNtEventSystemSwitchend        0x0015
#define kNtEventSystemMinimizestart    0x0016
#define kNtEventSystemMinimizeend      0x0017

#define kNtEventConsoleCaret            0x4001
#define kNtEventConsoleUpdateRegion     0x4002
#define kNtEventConsoleUpdateSimple     0x4003
#define kNtEventConsoleUpdateScroll     0x4004
#define kNtEventConsoleLayout           0x4005
#define kNtEventConsoleStartApplication 0x4006
#define kNtEventConsoleEndApplication   0x4007

#define kNtEventObjectCreate            0x8000
#define kNtEventObjectDestroy           0x8001
#define kNtEventObjectShow              0x8002
#define kNtEventObjectHide              0x8003
#define kNtEventObjectReorder           0x8004
#define kNtEventObjectFocus             0x8005
#define kNtEventObjectSelection         0x8006
#define kNtEventObjectSelectionadd      0x8007
#define kNtEventObjectSelectionremove   0x8008
#define kNtEventObjectSelectionwithin   0x8009
#define kNtEventObjectStatechange       0x800A
#define kNtEventObjectLocationchange    0x800B
#define kNtEventObjectNamechange        0x800C
#define kNtEventObjectDescriptionchange 0x800D
#define kNtEventObjectValuechange       0x800E
#define kNtEventObjectParentchange      0x800F
#define kNtEventObjectHelpchange        0x8010
#define kNtEventObjectDefactionchange   0x8011
#define kNtEventObjectAcceleratorchange 0x8012



/*!BEGIN libc/nt/enum/eventtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENTTYPE_H_

#define kNtNotificationEvent    0
#define kNtSynchronizationEvent 1



/*!BEGIN libc/nt/enum/exceptionhandleractions.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EXCEPTIONHANDLERACTIONS_H_

#define kNtExceptionExecuteHandler 0x1u
#define kNtExceptionContinueExecution 0xffffffffu
#define kNtExceptionContinueSearch 0x0u



/*!BEGIN libc/nt/enum/fileflagandattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEFLAGANDATTRIBUTES_H_

/**
 * MS-DOS File Attributes.
 *
 * @see GetFileInformationByHandle()
 * @see libc/sysv/consts.sh
 */
#define kNtFileAttributeReadonly    0x00000001u
#define kNtFileAttributeHidden      0x00000002u
#define kNtFileAttributeSystem      0x00000004u
#define kNtFileAttributeVolumelabel 0x00000008u
#define kNtFileAttributeDirectory   0x00000010u
#define kNtFileAttributeArchive     0x00000020u

/**
 * NT File Attributes.
 */
#define kNtFileAttributeDevice            0x00000040u
#define kNtFileAttributeNormal            0x00000080u
#define kNtFileAttributeTemporary         0x00000100u
#define kNtFileAttributeSparseFile        0x00000200u
#define kNtFileAttributeReparsePoint      0x00000400u
#define kNtFileAttributeCompressed        0x00000800u
#define kNtFileAttributeOffline           0x00001000u
#define kNtFileAttributeNotContentIndexed 0x00002000u
#define kNtFileAttributeEncrypted         0x00004000u

/**
 * NT File Flags.
 */
#define kNtFileFlagWriteThrough      0x80000000u
#define kNtFileFlagOverlapped        0x40000000u
#define kNtFileFlagNoBuffering       0x20000000u
#define kNtFileFlagRandomAccess      0x10000000u
#define kNtFileFlagSequentialScan    0x08000000u
#define kNtFileFlagDeleteOnClose     0x04000000u
#define kNtFileFlagBackupSemantics   0x02000000u
#define kNtFileFlagPosixSemantics    0x01000000u
#define kNtFileFlagOpenReparsePoint  0x00200000u
#define kNtFileFlagOpenNoRecall      0x00100000u
#define kNtFileFlagFirstPipeInstance 0x00080000u



/*!BEGIN libc/nt/enum/fileinfobyhandleclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFOBYHANDLECLASS_H_

#define kNtFileBasicInfo                  0 /* struct NtFileBasicInformation */
#define kNtFileStandardInfo               1 /* struct NtFileStandardInformation */
#define kNtFileNameInfo                   2 /* struct NtFileNameInformation */
#define kNtFileStreamInfo                 7 /* struct NtFileStreamInformation */
#define kNtFileCompressionInfo            8 /* struct NtFileCompressionInfo */
#define kNtFileAttributeTagInfo           9 /* struct NtFileAttributeTagInformation */
#define kNtFileIdBothDirectoryInfo        10
#define kNtFileIdBothDirectoryRestartInfo 11
#define kNtFileRemoteProtocolInfo         13
#define kNtFileFullDirectoryInfo          14 /* NtFileFullDirectoryInformation */
#define kNtFileFullDirectoryRestartInfo   15
#define kNtFileStorageInfo                16 /* win8+ */
#define kNtFileAlignmentInfo              17 /* win8+ */
#define kNtFileIdInfo                     18 /* win8+ */
#define kNtFileIdExtdDirectoryInfo        19 /* win8+ */
#define kNtFileIdExtdDirectoryRestartInfo 20 /* win8+ */

#define kNtFileRenameInfo         4
#define kNtFileDispositionInfo    5
#define kNtFileAllocationInfo     6
#define kNtFileEndOfFileInfo      7
#define kNtFileIoPriorityHintInfo 13
#define kNtFileDispositionInfoEx  22 /* win10+ */
#define kNtFileRenameInfoEx       23 /* win10+ */



/*!BEGIN libc/nt/enum/fileinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFORMATIONCLASS_H_

#define kNtFileDirectoryInformation 1 /*→ struct NtFileDirectoryInformation */
#define kNtFileFullDirectoryInformation 2 /*→ etc. */
#define kNtFileBothDirectoryInformation 3
#define kNtFileBasicInformation 4
#define kNtFileStandardInformation 5
#define kNtFileInternalInformation 6
#define kNtFileEaInformation 7
#define kNtFileAccessInformation 8
#define kNtFileNameInformation 9
#define kNtFileRenameInformation 10
#define kNtFileLinkInformation 11
#define kNtFileNamesInformation 12
#define kNtFileDispositionInformation 13
#define kNtFilePositionInformation 14
#define kNtFileFullEaInformation 15
#define kNtFileModeInformation 16
#define kNtFileAlignmentInformation 17
#define kNtFileAllInformation 18
#define kNtFileAllocationInformation 19
#define kNtFileEndOfFileInformation 20
#define kNtFileAlternateNameInformation 21
#define kNtFileStreamInformation 22
#define kNtFilePipeInformation 23
#define kNtFilePipeLocalInformation 24
#define kNtFilePipeRemoteInformation 25
#define kNtFileMailslotQueryInformation 26
#define kNtFileMailslotSetInformation 27
#define kNtFileCompressionInformation 28
#define kNtFileObjectIdInformation 29
#define kNtFileCompletionInformation 30
#define kNtFileMoveClusterInformation 31
#define kNtFileQuotaInformation 32
#define kNtFileReparsePointInformation 33
#define kNtFileNetworkOpenInformation 34
#define kNtFileAttributeTagInformation 35
#define kNtFileTrackingInformation 36
#define kNtFileIdBothDirectoryInformation 37
#define kNtFileIdFullDirectoryInformation 38
#define kNtFileValidDataLengthInformation 39
#define kNtFileShortNameInformation 40
#define kNtFileInformation_MAX 40



/*!BEGIN libc/nt/enum/filelockflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILELOCKFLAGS_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/filemapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMAPFLAGS_H_

#define kNtFileMapCopy           0x00000001u
#define kNtFileMapWrite          0x00000002u
#define kNtFileMapRead           0x00000004u
#define kNtFileMapExecute        0x00000020u
#define kNtFileMapReserve        0x80000000u
#define kNtFileMapTargetsInvalid 0x40000000u
#define kNtFileMapLargePages     0x20000000u



/*!BEGIN libc/nt/enum/filemovemethod.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMOVEMETHOD_H_

#define kNtFileBegin   0
#define kNtFileCurrent 1
#define kNtFileEnd     2



/*!BEGIN libc/nt/enum/filesharemode.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILESHAREFLAGS_H_

#define kNtFileShareExclusive 0x00000000u
#define kNtFileShareRead 0x00000001u
#define kNtFileShareWrite 0x00000002u
#define kNtFileShareDelete 0x00000004u



/*!BEGIN libc/nt/enum/filetype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILETYPE_H_

#define kNtFileTypeUnknown 0x0000
#define kNtFileTypeDisk    0x0001 /* @see S_ISBLK() */
#define kNtFileTypeChar    0x0002 /* @see S_ISCHR() */
#define kNtFileTypePipe    0x0003 /* @see S_ISFIFO() */
#define kNtFileTypeRemote  0x8000 /* unused -MSDN */



/*!BEGIN libc/nt/enum/fillattribute.h */

#define COSMOPOLITAN_LIBC_NT_NTFILLATTRIBUTE_H_

#define kNtForegroundBlue 0x0001
#define kNtForegroundGreen 0x0002
#define kNtForegroundRed 0x0004
#define kNtForegroundIntensity 0x0008
#define kNtBackgroundBlue 0x0010
#define kNtBackgroundGreen 0x0020
#define kNtBackgroundRed 0x0040
#define kNtBackgroundIntensity 0x0080



/*!BEGIN libc/nt/enum/findexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXINFOLEVELS_H_

#define kNtFindExInfoStandard     0
#define kNtFindExInfoBasic        1
#define kNtFindExInfoMaxInfoLevel 2



/*!BEGIN libc/nt/enum/findexsearchops.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXSEARCHOPS_H_

#define kNtFindExSearchNameMatch          0
#define kNtFindExSearchLimitToDirectories 1
#define kNtFindExSearchLimitToDevices     2
#define kNtFindExSearchMaxSearchOp        3



/*!BEGIN libc/nt/enum/formatmessageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FORMATMESSAGEFLAGS_H_

#define kNtFormatMessageAllocateBuffer 0x100
#define kNtFormatMessageIgnoreInserts  0x200
#define kNtFormatMessageFromString     0x400
#define kNtFormatMessageFromHmodule    0x800
#define kNtFormatMessageFromSystem     0x1000
#define kNtFormatMessageArgumentArray  0x2000
#define kNtFormatMessageMaxWidthMask   0xff



/*!BEGIN libc/nt/enum/fsctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSCTL_H_

#define kNtFsctlDisableLocalBuffering   0x000902B8u
#define kNtFsctlFilePrefetch            0x00090120u
#define kNtFsctlFilesystemGetStatistics 0x00090060u
#define kNtFsctlGetCompression          0x0009003Cu
#define kNtFsctlGetNtfsFileRecord       0x00090068u
#define kNtFsctlGetNtfsVolumeData       0x00090064u
#define kNtFsctlQueryAllocatedRanges    0x000940CFu
#define kNtFsctlScrubData               0x000902B0u
#define kNtFsctlSetCompression          0x0009C040u
#define kNtFsctlSetSparse               0x000900C4u
#define kNtFsctlSetZeroData             0x000980C8u
#define kNtFsctlGetReparsePoint         0x000900a8u
#define kNtFsctlSetReparsePoint         0x000900a4u



/*!BEGIN libc/nt/enum/fsinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSINFORMATIONCLASS_H_

#define kNtFileFsVolumeInformation 1
#define kNtFileFsLabelInformation 2
#define kNtFileFsSizeInformation 3
#define kNtFileFsDeviceInformation 4
#define kNtFileFsAttributeInformation 5
#define kNtFileFsControlInformation 6
#define kNtFileFsFullSizeInformation 7
#define kNtFileFsObjectIdInformation 8
#define kNtFileFsDriverPathInformation 9
#define kNtFileFsInformation_MAX 10



/*!BEGIN libc/nt/enum/getfileexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_GETFILEEXINFOLEVELS_H_

#define kNtGetFileExInfoStandard 0



/*!BEGIN libc/nt/enum/heap.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HEAP_H_

#define kNtHeapNoSerialize        1
#define kNtHeapGenerateExceptions 4
#define kNtHeapZeroMemory         8
#define kNtHeapReallocInPlaceOnly 16



/*!BEGIN libc/nt/enum/ht.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HT_H_

#define kNtHterror       -2
#define kNtHttransparent -1
#define kNtHtnowhere     0
#define kNtHtclient      1
#define kNtHtcaption     2
#define kNtHtsysmenu     3
#define kNtHtgrowbox     4
#define kNtHtsize        kNtHtgrowbox
#define kNtHtmenu        5
#define kNtHthscroll     6
#define kNtHtvscroll     7
#define kNtHtminbutton   8
#define kNtHtmaxbutton   9
#define kNtHtleft        10
#define kNtHtright       11
#define kNtHttop         12
#define kNtHttopleft     13
#define kNtHttopright    14
#define kNtHtbottom      15
#define kNtHtbottomleft  16
#define kNtHtbottomright 17
#define kNtHtborder      18
#define kNtHtreduce      kNtHtminbutton
#define kNtHtzoom        kNtHtmaxbutton
#define kNtHtsizefirst   kNtHtleft
#define kNtHtsizelast    kNtHtbottomright
#define kNtHtobject      19
#define kNtHtclose       20
#define kNtHthelp        21



/*!BEGIN libc/nt/enum/idc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IDC_H_
COSMOPOLITAN_C_START_

#define kNtIdcArrow    ((const char16_t *)32512)
#define kNtIdcIbeam    ((const char16_t *)32513)
#define kNtIdcWait     ((const char16_t *)32514)
#define kNtIdcCross    ((const char16_t *)32515)
#define kNtIdcUparrow  ((const char16_t *)32516)
#define kNtIdcSizenwse ((const char16_t *)32642)
#define kNtIdcSizenesw ((const char16_t *)32643)
#define kNtIdcSizewe   ((const char16_t *)32644)
#define kNtIdcSizens   ((const char16_t *)32645)
#define kNtIdcSizeall  ((const char16_t *)32646)
#define kNtIdcNo       ((const char16_t *)32648)
#define kNtIdcHand     ((const char16_t *)32649)
#define kNtIdcHelp     ((const char16_t *)32651)
#define kNtIdcPin      ((const char16_t *)32671)
#define kNtIdcPerson   ((const char16_t *)32672)

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/imageauxsymboltype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMAGEAUXSYMBOLTYPE_H_

#define kNtImageAuxSymbolTypeTokenDef 1



/*!BEGIN libc/nt/enum/importobjectnametype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTNAMETYPE_H_

enum NtImportObjectNameType {
  IMPORT_OBJECT_ORDINAL,
  IMPORT_OBJECT_NAME,
  IMPORT_OBJECT_NAME_NO_PREFIX,
  IMPORT_OBJECT_NAME_UNDECORATE,
  IMPORT_OBJECT_NAME_EXPORTAS
};



/*!BEGIN libc/nt/enum/importobjecttype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTTYPE_H_

enum NtImportObjectType {
  IMPORT_OBJECT_CODE,
  IMPORT_OBJECT_DATA,
  IMPORT_OBJECT_CONST
};



/*!BEGIN libc/nt/enum/io.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IO_H_

#define kNtIoReparseTagSymlink    0xa000000c
#define kNtIoReparseTagMountPoint 0xa0000003



/*!BEGIN libc/nt/enum/ioctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IOCTL_H_

#define kNtIoctlDiskGetDriveGeometry 0x00070000u
#define kNtIoctlAfdPoll              0x00012024u



/*!BEGIN libc/nt/enum/jobobjectinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_JOBOBJECTINFOCLASS_H_

#define kNtJobObjectBasicAccountingInformation         1
#define kNtJobObjectBasicLimitInformation              2
#define kNtJobObjectBasicProcessIdList                 3
#define kNtJobObjectBasicUIRestrictions                4
#define kNtJobObjectSecurityLimitInformation           5
#define kNtJobObjectEndOfJobTimeInformation            6
#define kNtJobObjectAssociateCompletionPortInformation 7
#define kNtJobObjectBasicAndIoAccountingInformation    8
#define kNtJobObjectExtendedLimitInformation           9
#define kNtJobObjectJobSetInformation                  10



/*!BEGIN libc/nt/enum/keyaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_

#define kNtKeyRead      0x00020019
#define kNtKeyWrite     0x00020006
#define kNtKeyExecute   0x00020019
#define kNtKeyAllAccess 0x000f003f



/*!BEGIN libc/nt/enum/keyedevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYEDEVENT_H_

#define kNtKeyedeventWait 0x00000001u
#define kNtKeyedeventWake 0x00000002u
#define kNtKeyedeventAllAccess \
  (kNtStandardRightsRequired | kNtKeyedeventWait | kNtKeyedeventWake)



/*!BEGIN libc/nt/enum/keyinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYINFORMATIONCLASS_H_

#define kNtKeyBasicInformation 0
#define kNtKeyNodeInformation  1
#define kNtKeyFullInformation  2
#define kNtKeyNameInformation  3



/*!BEGIN libc/nt/enum/kwaitreason.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KWAITREASON_H_

#define kNtExecutive 0
#define kNtFreePage 1
#define kNtPageIn 2
#define kNtPoolAllocation 3
#define kNtDelayExecution 4
#define kNtSuspended 5
#define kNtUserRequest 6
#define kNtWrExecutive 7
#define kNtWrFreePage 8
#define kNtWrPageIn 9
#define kNtWrPoolAllocation 10
#define kNtWrDelayExecution 11
#define kNtWrSuspended 12
#define kNtWrUserRequest 13
#define kNtWrEventPair 14
#define kNtWrQueue 15
#define kNtWrLpcReceive 16
#define kNtWrLpcReply 17
#define kNtWrVirtualMemory 18
#define kNtWrPageOut 19
#define kNtWrRendezvous 20
#define kNtSpare2 21
#define kNtSpare3 22
#define kNtSpare4 23
#define kNtSpare5 24
#define kNtSpare6 25
#define kNtWrKernel 26
#define kNtMaximumWaitReason 27



/*!BEGIN libc/nt/enum/lang.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LANG_H_

#define MAKELANGID(p, s) ((((uint16_t)(s)) << 10) | (uint16_t)(p))

#define kNtLangNeutral            0x00
#define kNtLangInvariant          0x7f
#define kNtLangAfrikaans          0x36
#define kNtLangAlbanian           0x1c
#define kNtLangAlsatian           0x84
#define kNtLangAmharic            0x5e
#define kNtLangArabic             0x01
#define kNtLangArmenian           0x2b
#define kNtLangAssamese           0x4d
#define kNtLangAzeri              0x2c
#define kNtLangAzerbaijani        0x2c
#define kNtLangBangla             0x45
#define kNtLangBashkir            0x6d
#define kNtLangBasque             0x2d
#define kNtLangBelarusian         0x23
#define kNtLangBengali            0x45
#define kNtLangBreton             0x7e
#define kNtLangBosnian            0x1a
#define kNtLangBosnianNeutral     0x781a
#define kNtLangBulgarian          0x02
#define kNtLangCatalan            0x03
#define kNtLangCentralKurdish     0x92
#define kNtLangCherokee           0x5c
#define kNtLangChinese            0x04
#define kNtLangChineseSimplified  0x04
#define kNtLangChineseTraditional 0x7c04
#define kNtLangCorsican           0x83
#define kNtLangCroatian           0x1a
#define kNtLangCzech              0x05
#define kNtLangDanish             0x06
#define kNtLangDari               0x8c
#define kNtLangDivehi             0x65
#define kNtLangDutch              0x13
#define kNtLangEnglish            0x09
#define kNtLangEstonian           0x25
#define kNtLangFaeroese           0x38
#define kNtLangFarsi              0x29
#define kNtLangFilipino           0x64
#define kNtLangFinnish            0x0b
#define kNtLangFrench             0x0c
#define kNtLangFrisian            0x62
#define kNtLangFulah              0x67
#define kNtLangGalician           0x56
#define kNtLangGeorgian           0x37
#define kNtLangGerman             0x07
#define kNtLangGreek              0x08
#define kNtLangGreenlandic        0x6f
#define kNtLangGujarati           0x47
#define kNtLangHausa              0x68
#define kNtLangHawaiian           0x75
#define kNtLangHebrew             0x0d
#define kNtLangHindi              0x39
#define kNtLangHungarian          0x0e
#define kNtLangIcelandic          0x0f
#define kNtLangIgbo               0x70
#define kNtLangIndonesian         0x21
#define kNtLangInuktitut          0x5d
#define kNtLangIrish              0x3c
#define kNtLangItalian            0x10
#define kNtLangJapanese           0x11
#define kNtLangKannada            0x4b
#define kNtLangKashmiri           0x60
#define kNtLangKazak              0x3f
#define kNtLangKhmer              0x53
#define kNtLangKiche              0x86
#define kNtLangKinyarwanda        0x87
#define kNtLangKonkani            0x57
#define kNtLangKorean             0x12
#define kNtLangKyrgyz             0x40
#define kNtLangLao                0x54
#define kNtLangLatvian            0x26
#define kNtLangLithuanian         0x27
#define kNtLangLowerSorbian       0x2e
#define kNtLangLuxembourgish      0x6e
#define kNtLangMacedonian         0x2f
#define kNtLangMalay              0x3e
#define kNtLangMalayalam          0x4c
#define kNtLangMaltese            0x3a
#define kNtLangManipuri           0x58
#define kNtLangMaori              0x81
#define kNtLangMapudungun         0x7a
#define kNtLangMarathi            0x4e
#define kNtLangMohawk             0x7c
#define kNtLangMongolian          0x50
#define kNtLangNepali             0x61
#define kNtLangNorwegian          0x14
#define kNtLangOccitan            0x82
#define kNtLangOdia               0x48
#define kNtLangOriya              0x48
#define kNtLangPashto             0x63
#define kNtLangPersian            0x29
#define kNtLangPolish             0x15
#define kNtLangPortuguese         0x16
#define kNtLangPular              0x67
#define kNtLangPunjabi            0x46
#define kNtLangQuechua            0x6b
#define kNtLangRomanian           0x18
#define kNtLangRomansh            0x17
#define kNtLangRussian            0x19
#define kNtLangSakha              0x85
#define kNtLangSami               0x3b
#define kNtLangSanskrit           0x4f
#define kNtLangScottishGaelic     0x91
#define kNtLangSerbian            0x1a
#define kNtLangSerbianNeutral     0x7c1a
#define kNtLangSindhi             0x59
#define kNtLangSinhalese          0x5b
#define kNtLangSlovak             0x1b
#define kNtLangSlovenian          0x24
#define kNtLangSotho              0x6c
#define kNtLangSpanish            0x0a
#define kNtLangSwahili            0x41
#define kNtLangSwedish            0x1d
#define kNtLangSyriac             0x5a
#define kNtLangTajik              0x28
#define kNtLangTamazight          0x5f
#define kNtLangTamil              0x49
#define kNtLangTatar              0x44
#define kNtLangTelugu             0x4a
#define kNtLangThai               0x1e
#define kNtLangTibetan            0x51
#define kNtLangTigrigna           0x73
#define kNtLangTigrinya           0x73
#define kNtLangTswana             0x32
#define kNtLangTurkish            0x1f
#define kNtLangTurkmen            0x42
#define kNtLangUighur             0x80
#define kNtLangUkrainian          0x22
#define kNtLangUpperSorbian       0x2e
#define kNtLangUrdu               0x20
#define kNtLangUzbek              0x43
#define kNtLangValencian          0x03
#define kNtLangVietnamese         0x2a
#define kNtLangWelsh              0x52
#define kNtLangWolof              0x88
#define kNtLangXhosa              0x34
#define kNtLangYakut              0x85
#define kNtLangYi                 0x78
#define kNtLangYoruba             0x6a
#define kNtLangZulu               0x35

#define kNtSublangNeutral                          0x00
#define kNtSublangDefault                          0x01
#define kNtSublangSysDefault                       0x02
#define kNtSublangCustomDefault                    0x03
#define kNtSublangCustomUnspecified                0x04
#define kNtSublangUiCustomDefault                  0x05
#define kNtSublangAfrikaansSouthAfrica             0x01
#define kNtSublangAlbanianAlbania                  0x01
#define kNtSublangAlsatianFrance                   0x01
#define kNtSublangAmharicEthiopia                  0x01
#define kNtSublangArabicSaudiArabia                0x01
#define kNtSublangArabicIraq                       0x02
#define kNtSublangArabicEgypt                      0x03
#define kNtSublangArabicLibya                      0x04
#define kNtSublangArabicAlgeria                    0x05
#define kNtSublangArabicMorocco                    0x06
#define kNtSublangArabicTunisia                    0x07
#define kNtSublangArabicOman                       0x08
#define kNtSublangArabicYemen                      0x09
#define kNtSublangArabicSyria                      0x0a
#define kNtSublangArabicJordan                     0x0b
#define kNtSublangArabicLebanon                    0x0c
#define kNtSublangArabicKuwait                     0x0d
#define kNtSublangArabicUae                        0x0e
#define kNtSublangArabicBahrain                    0x0f
#define kNtSublangArabicQatar                      0x10
#define kNtSublangArmenianArmenia                  0x01
#define kNtSublangAssameseIndia                    0x01
#define kNtSublangAzeriLatin                       0x01
#define kNtSublangAzeriCyrillic                    0x02
#define kNtSublangAzerbaijaniAzerbaijanLatin       0x01
#define kNtSublangAzerbaijaniAzerbaijanCyrillic    0x02
#define kNtSublangBanglaIndia                      0x01
#define kNtSublangBanglaBangladesh                 0x02
#define kNtSublangBashkirRussia                    0x01
#define kNtSublangBasqueBasque                     0x01
#define kNtSublangBelarusianBelarus                0x01
#define kNtSublangBengaliIndia                     0x01
#define kNtSublangBengaliBangladesh                0x02
#define kNtSublangBosnianBosniaHerzegovinaLatin    0x05
#define kNtSublangBosnianBosniaHerzegovinaCyrillic 0x08
#define kNtSublangBretonFrance                     0x01
#define kNtSublangBulgarianBulgaria                0x01
#define kNtSublangCatalanCatalan                   0x01
#define kNtSublangCentralKurdishIraq               0x01
#define kNtSublangCherokeeCherokee                 0x01
#define kNtSublangChineseTraditional               0x01
#define kNtSublangChineseSimplified                0x02
#define kNtSublangChineseHongkong                  0x03
#define kNtSublangChineseSingapore                 0x04
#define kNtSublangChineseMacau                     0x05
#define kNtSublangCorsicanFrance                   0x01
#define kNtSublangCzechCzechRepublic               0x01
#define kNtSublangCroatianCroatia                  0x01
#define kNtSublangCroatianBosniaHerzegovinaLatin   0x04
#define kNtSublangDanishDenmark                    0x01
#define kNtSublangDariAfghanistan                  0x01
#define kNtSublangDivehiMaldives                   0x01
#define kNtSublangDutch                            0x01
#define kNtSublangDutchBelgian                     0x02
#define kNtSublangEnglishUs                        0x01
#define kNtSublangEnglishUk                        0x02
#define kNtSublangEnglishAus                       0x03
#define kNtSublangEnglishCan                       0x04
#define kNtSublangEnglishNz                        0x05
#define kNtSublangEnglishEire                      0x06
#define kNtSublangEnglishSouthAfrica               0x07
#define kNtSublangEnglishJamaica                   0x08
#define kNtSublangEnglishCaribbean                 0x09
#define kNtSublangEnglishBelize                    0x0a
#define kNtSublangEnglishTrinidad                  0x0b
#define kNtSublangEnglishZimbabwe                  0x0c
#define kNtSublangEnglishPhilippines               0x0d
#define kNtSublangEnglishIndia                     0x10
#define kNtSublangEnglishMalaysia                  0x11
#define kNtSublangEnglishSingapore                 0x12
#define kNtSublangEstonianEstonia                  0x01
#define kNtSublangFaeroeseFaroeIslands             0x01
#define kNtSublangFilipinoPhilippines              0x01
#define kNtSublangFinnishFinland                   0x01
#define kNtSublangFrench                           0x01
#define kNtSublangFrenchBelgian                    0x02
#define kNtSublangFrenchCanadian                   0x03
#define kNtSublangFrenchSwiss                      0x04
#define kNtSublangFrenchLuxembourg                 0x05
#define kNtSublangFrenchMonaco                     0x06
#define kNtSublangFrisianNetherlands               0x01
#define kNtSublangFulahSenegal                     0x02
#define kNtSublangGalicianGalician                 0x01
#define kNtSublangGeorgianGeorgia                  0x01
#define kNtSublangGerman                           0x01
#define kNtSublangGermanSwiss                      0x02
#define kNtSublangGermanAustrian                   0x03
#define kNtSublangGermanLuxembourg                 0x04
#define kNtSublangGermanLiechtenstein              0x05
#define kNtSublangGreekGreece                      0x01
#define kNtSublangGreenlandicGreenland             0x01
#define kNtSublangGujaratiIndia                    0x01
#define kNtSublangHausaNigeriaLatin                0x01
#define kNtSublangHawaiianUs                       0x01
#define kNtSublangHebrewIsrael                     0x01
#define kNtSublangHindiIndia                       0x01
#define kNtSublangHungarianHungary                 0x01
#define kNtSublangIcelandicIceland                 0x01
#define kNtSublangIgboNigeria                      0x01
#define kNtSublangIndonesianIndonesia              0x01
#define kNtSublangInuktitutCanada                  0x01
#define kNtSublangInuktitutCanadaLatin             0x02
#define kNtSublangIrishIreland                     0x02
#define kNtSublangItalian                          0x01
#define kNtSublangItalianSwiss                     0x02
#define kNtSublangJapaneseJapan                    0x01
#define kNtSublangKannadaIndia                     0x01
#define kNtSublangKashmiriSasia                    0x02
#define kNtSublangKashmiriIndia                    0x02
#define kNtSublangKazakKazakhstan                  0x01
#define kNtSublangKhmerCambodia                    0x01
#define kNtSublangKicheGuatemala                   0x01
#define kNtSublangKinyarwandaRwanda                0x01
#define kNtSublangKonkaniIndia                     0x01
#define kNtSublangKorean                           0x01
#define kNtSublangKyrgyzKyrgyzstan                 0x01
#define kNtSublangLaoLao                           0x01
#define kNtSublangLatvianLatvia                    0x01
#define kNtSublangLithuanian                       0x01
#define kNtSublangLowerSorbianGermany              0x02
#define kNtSublangLuxembourgishLuxembourg          0x01
#define kNtSublangMacedonianMacedonia              0x01
#define kNtSublangMalayMalaysia                    0x01
#define kNtSublangMalayBruneiDarussalam            0x02
#define kNtSublangMalayalamIndia                   0x01
#define kNtSublangMalteseMalta                     0x01
#define kNtSublangMaoriNewZealand                  0x01
#define kNtSublangMapudungunChile                  0x01
#define kNtSublangMarathiIndia                     0x01
#define kNtSublangMohawkMohawk                     0x01
#define kNtSublangMongolianCyrillicMongolia        0x01
#define kNtSublangMongolianPrc                     0x02
#define kNtSublangNepaliIndia                      0x02
#define kNtSublangNepaliNepal                      0x01
#define kNtSublangNorwegianBokmal                  0x01
#define kNtSublangNorwegianNynorsk                 0x02
#define kNtSublangOccitanFrance                    0x01
#define kNtSublangOdiaIndia                        0x01
#define kNtSublangOriyaIndia                       0x01
#define kNtSublangPashtoAfghanistan                0x01
#define kNtSublangPersianIran                      0x01
#define kNtSublangPolishPoland                     0x01
#define kNtSublangPortuguese                       0x02
#define kNtSublangPortugueseBrazilian              0x01
#define kNtSublangPularSenegal                     0x02
#define kNtSublangPunjabiIndia                     0x01
#define kNtSublangPunjabiPakistan                  0x02
#define kNtSublangQuechuaBolivia                   0x01
#define kNtSublangQuechuaEcuador                   0x02
#define kNtSublangQuechuaPeru                      0x03
#define kNtSublangRomanianRomania                  0x01
#define kNtSublangRomanshSwitzerland               0x01
#define kNtSublangRussianRussia                    0x01
#define kNtSublangSakhaRussia                      0x01
#define kNtSublangSamiNorthernNorway               0x01
#define kNtSublangSamiNorthernSweden               0x02
#define kNtSublangSamiNorthernFinland              0x03
#define kNtSublangSamiLuleNorway                   0x04
#define kNtSublangSamiLuleSweden                   0x05
#define kNtSublangSamiSouthernNorway               0x06
#define kNtSublangSamiSouthernSweden               0x07
#define kNtSublangSamiSkoltFinland                 0x08
#define kNtSublangSamiInariFinland                 0x09
#define kNtSublangSanskritIndia                    0x01
#define kNtSublangScottishGaelic                   0x01
#define kNtSublangSerbianBosniaHerzegovinaLatin    0x06
#define kNtSublangSerbianBosniaHerzegovinaCyrillic 0x07
#define kNtSublangSerbianMontenegroLatin           0x0b
#define kNtSublangSerbianMontenegroCyrillic        0x0c
#define kNtSublangSerbianSerbiaLatin               0x09
#define kNtSublangSerbianSerbiaCyrillic            0x0a
#define kNtSublangSerbianCroatia                   0x01
#define kNtSublangSerbianLatin                     0x02
#define kNtSublangSerbianCyrillic                  0x03
#define kNtSublangSindhiIndia                      0x01
#define kNtSublangSindhiPakistan                   0x02
#define kNtSublangSindhiAfghanistan                0x02
#define kNtSublangSinhaleseSriLanka                0x01
#define kNtSublangSothoNorthernSouthAfrica         0x01
#define kNtSublangSlovakSlovakia                   0x01
#define kNtSublangSlovenianSlovenia                0x01
#define kNtSublangSpanish                          0x01
#define kNtSublangSpanishMexican                   0x02
#define kNtSublangSpanishModern                    0x03
#define kNtSublangSpanishGuatemala                 0x04
#define kNtSublangSpanishCostaRica                 0x05
#define kNtSublangSpanishPanama                    0x06
#define kNtSublangSpanishDominicanRepublic         0x07
#define kNtSublangSpanishVenezuela                 0x08
#define kNtSublangSpanishColombia                  0x09
#define kNtSublangSpanishPeru                      0x0a
#define kNtSublangSpanishArgentina                 0x0b
#define kNtSublangSpanishEcuador                   0x0c
#define kNtSublangSpanishChile                     0x0d
#define kNtSublangSpanishUruguay                   0x0e
#define kNtSublangSpanishParaguay                  0x0f
#define kNtSublangSpanishBolivia                   0x10
#define kNtSublangSpanishElSalvador                0x11
#define kNtSublangSpanishHonduras                  0x12
#define kNtSublangSpanishNicaragua                 0x13
#define kNtSublangSpanishPuertoRico                0x14
#define kNtSublangSpanishUs                        0x15
#define kNtSublangSwahiliKenya                     0x01
#define kNtSublangSwedish                          0x01
#define kNtSublangSwedishFinland                   0x02
#define kNtSublangSyriacSyria                      0x01
#define kNtSublangTajikTajikistan                  0x01
#define kNtSublangTamazightAlgeriaLatin            0x02
#define kNtSublangTamazightMoroccoTifinagh         0x04
#define kNtSublangTamilIndia                       0x01
#define kNtSublangTamilSriLanka                    0x02
#define kNtSublangTatarRussia                      0x01
#define kNtSublangTeluguIndia                      0x01
#define kNtSublangThaiThailand                     0x01
#define kNtSublangTibetanPrc                       0x01
#define kNtSublangTigrignaEritrea                  0x02
#define kNtSublangTigrinyaEritrea                  0x02
#define kNtSublangTigrinyaEthiopia                 0x01
#define kNtSublangTswanaBotswana                   0x02
#define kNtSublangTswanaSouthAfrica                0x01
#define kNtSublangTurkishTurkey                    0x01
#define kNtSublangTurkmenTurkmenistan              0x01
#define kNtSublangUighurPrc                        0x01
#define kNtSublangUkrainianUkraine                 0x01
#define kNtSublangUpperSorbianGermany              0x01
#define kNtSublangUrduPakistan                     0x01
#define kNtSublangUrduIndia                        0x02
#define kNtSublangUzbekLatin                       0x01
#define kNtSublangUzbekCyrillic                    0x02
#define kNtSublangValencianValencia                0x02
#define kNtSublangVietnameseVietnam                0x01
#define kNtSublangWelshUnitedKingdom               0x01
#define kNtSublangWolofSenegal                     0x01
#define kNtSublangXhosaSouthAfrica                 0x01
#define kNtSublangYakutRussia                      0x01
#define kNtSublangYiPrc                            0x01
#define kNtSublangYorubaNigeria                    0x01
#define kNtSublangZuluSouthAfrica                  0x01



/*!BEGIN libc/nt/enum/loadlibrarysearch.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOADLIBRARYSEARCH_H_

#define kNtLoadLibrarySearchApplicationDir 0x00000200u
#define kNtLoadLibrarySearchSearchSystem32 0x00000800u
#define kNtLoadLibrarySearchUserDirs       0x00000400u
#define kNtLoadLibrarySearchDefaultDirs    0x00001000u



/*!BEGIN libc/nt/enum/lockfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOCKFILE_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/mb.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MB_H_

#define kNtMbOk                      0x00000000
#define kNtMbOkcancel                0x00000001
#define kNtMbAbortretryignore        0x00000002
#define kNtMbYesnocancel             0x00000003
#define kNtMbYesno                   0x00000004
#define kNtMbRetrycancel             0x00000005
#define kNtMbCanceltrycontinue       0x00000006
#define kNtMbIconhand                0x00000010
#define kNtMbIconquestion            0x00000020
#define kNtMbIconexclamation         0x00000030
#define kNtMbIconasterisk            0x00000040
#define kNtMbUsericon                0x00000080
#define kNtMbIconwarning             kNtMbIconexclamation
#define kNtMbIconerror               kNtMbIconhand
#define kNtMbIconinformation         kNtMbIconasterisk
#define kNtMbIconstop                kNtMbIconhand
#define kNtMbDefbutton1              0x00000000
#define kNtMbDefbutton2              0x00000100
#define kNtMbDefbutton3              0x00000200
#define kNtMbDefbutton4              0x00000300
#define kNtMbApplmodal               0x00000000
#define kNtMbSystemmodal             0x00001000
#define kNtMbTaskmodal               0x00002000
#define kNtMbHelp                    0x00004000
#define kNtMbNofocus                 0x00008000
#define kNtMbSetforeground           0x00010000
#define kNtMbDefaultDesktopOnly      0x00020000
#define kNtMbTopmost                 0x00040000
#define kNtMbRight                   0x00080000
#define kNtMbRtlreading              0x00100000
#define kNtMbServiceNotification     0x00200000
#define kNtMbServiceNotificationNt3x 0x00040000
#define kNtMbTypemask                0x0000000F
#define kNtMbIconmask                0x000000F0
#define kNtMbDefmask                 0x00000F00
#define kNtMbModemask                0x00003000
#define kNtMbMiscmask                0x0000C000



/*!BEGIN libc/nt/enum/memflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMFLAGS_H_

#define kNtMemCommit     0x1000 /* perform physical memory reservation step */
#define kNtMemReserve    0x2000 /* perform virtual memory reservation step */
#define kNtMemDecommit   0x4000
#define kNtMemRelease    0x8000
#define kNtMemFree       0x10000
#define kNtMemPrivate    0x20000
#define kNtMemMapped     0x40000
#define kNtMemReset      0x80000
#define kNtMemTopDown    0x100000
#define kNtMemWriteWatch 0x200000
#define kNtMemPhysical   0x400000
#define kNtMemImage      0x1000000
#define kNtMemLargePages 0x20000000
#define kNtMem4mbPages   0x80000000

#define kNtMemReplacePlaceholder 0x00004000



/*!BEGIN libc/nt/enum/memoryinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMORYINFORMATIONCLASS_H_

#define kNtMemoryBasicInformation    0
#define kNtMemoryWorkingSetList      1
#define kNtMemorySectionName         2
#define kNtMemoryBasicVlmInformation 3



/*!BEGIN libc/nt/enum/mf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MF_H_

#define kNtMfInsert          0x00000000
#define kNtMfChange          0x00000080
#define kNtMfAppend          0x00000100
#define kNtMfDelete          0x00000200
#define kNtMfRemove          0x00001000
#define kNtMfBycommand       0x00000000
#define kNtMfByposition      0x00000400
#define kNtMfSeparator       0x00000800
#define kNtMfEnabled         0x00000000
#define kNtMfGrayed          0x00000001
#define kNtMfDisabled        0x00000002
#define kNtMfUnchecked       0x00000000
#define kNtMfChecked         0x00000008
#define kNtMfUsecheckbitmaps 0x00000200
#define kNtMfString          0x00000000
#define kNtMfBitmap          0x00000004
#define kNtMfOwnerdraw       0x00000100
#define kNtMfPopup           0x00000010
#define kNtMfMenubarbreak    0x00000020
#define kNtMfMenubreak       0x00000040
#define kNtMfUnhilite        0x00000000
#define kNtMfHilite          0x00000080
#define kNtMfDefault         0x00001000
#define kNtMfSysmenu         0x00002000
#define kNtMfHelp            0x00004000
#define kNtMfRightjustify    0x00004000
#define kNtMfMouseselect     0x00008000



/*!BEGIN libc/nt/enum/mk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MK_H_

#define kNtMkLbutton  0x0001
#define kNtMkRbutton  0x0002
#define kNtMkShift    0x0004
#define kNtMkControl  0x0008
#define kNtMkMbutton  0x0010
#define kNtMkXbutton1 0x0020
#define kNtMkXbutton2 0x0040



/*!BEGIN libc/nt/enum/movefileexflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MOVEFILEEXFLAGS_H_

#define kNtMovefileReplaceExisting    1
#define kNtMovefileCopyAllowed        2
#define kNtMovefileDelayUntilReboot   4
#define kNtMovefileWriteThrough       8
#define kNtMovefileCreateHardlink     16
#define kNtMovefileFailIfNotTrackable 32



/*!BEGIN libc/nt/enum/objectinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OBJECTINFORMATIONCLASS_H_

#define kNtObjectBasicInformation 0 /*→ struct NtObjectBasicInformation */
#define kNtObjectNameInformation  1 /*→ etc. */
#define kNtObjectTypeInformation  2
#define kNtObjectAllInformation   3
#define kNtObjectDataInformation  4



/*!BEGIN libc/nt/enum/offerpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFFERPRIORITY_H_

/* TODO(jart): Are these values correct? */
#define kNtVmOfferPriorityVeryLow     1 /* 0x00001000? */
#define kNtVmOfferPriorityLow         2 /* 0x00002000? */
#define kNtVmOfferPriorityBelowNormal 3 /* 0x00002000? */
#define kNtVmOfferPriorityNormal      4 /* 0x00002000? */



/*!BEGIN libc/nt/enum/ofn.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFN_H_

#define kNtOfnReadonly             0x00000001
#define kNtOfnOverwriteprompt      0x00000002
#define kNtOfnHidereadonly         0x00000004
#define kNtOfnNochangedir          0x00000008
#define kNtOfnShowhelp             0x00000010
#define kNtOfnEnablehook           0x00000020
#define kNtOfnEnabletemplate       0x00000040
#define kNtOfnEnabletemplatehandle 0x00000080
#define kNtOfnNovalidate           0x00000100
#define kNtOfnAllowmultiselect     0x00000200
#define kNtOfnExtensiondifferent   0x00000400
#define kNtOfnPathmustexist        0x00000800
#define kNtOfnFilemustexist        0x00001000
#define kNtOfnCreateprompt         0x00002000
#define kNtOfnShareaware           0x00004000
#define kNtOfnNoreadonlyreturn     0x00008000
#define kNtOfnNotestfilecreate     0x00010000
#define kNtOfnNonetworkbutton      0x00020000
#define kNtOfnNolongnames          0x00040000
#define kNtOfnExplorer             0x00080000
#define kNtOfnNodereferencelinks   0x00100000
#define kNtOfnLongnames            0x00200000
#define kNtOfnEnableincludenotify  0x00400000
#define kNtOfnEnablesizing         0x00800000
#define kNtOfnDontaddtorecent      0x02000000
#define kNtOfnForceshowhidden      0x10000000



/*!BEGIN libc/nt/enum/pageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PAGEFLAGS_H_

/* Pick One */
#define kNtPageNoaccess         0x001
#define kNtPageReadonly         0x002
#define kNtPageReadwrite        0x004
#define kNtPageWritecopy        0x008
#define kNtPageExecute          0x010
#define kNtPageExecuteRead      0x020
#define kNtPageExecuteReadwrite 0x040
#define kNtPageExecuteWritecopy 0x080
#define kNtPageGuard            0x100
#define kNtPageNocache          0x200
#define kNtPageWritecombine     0x400

/* These may be OR'd */
#define kNtSecReserve        0x04000000
#define kNtSecCommit         0x08000000 /* default */
#define kNtSecImageNoExecute 0x11000000
#define kNtSecImage          0x01000000
#define kNtSecNocache        0x10000000
#define kNtSecLargePages     0x80000000
#define kNtSecWritecombine   0x40000000



/*!BEGIN libc/nt/enum/pdh.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PDH_H_

#define kNtPdhFmtRaw          0x00000010u
#define kNtPdhFmtAnsi         0x00000020u
#define kNtPdhFmtUnicode      0x00000040u
#define kNtPdhFmtLong         0x00000100u
#define kNtPdhFmtDouble       0x00000200u
#define kNtPdhFmtLarge        0x00000400u
#define kNtPdhFmtNoscale      0x00001000u
#define kNtPdhFmt1000         0x00002000u
#define kNtPdhFmtNodata       0x00004000u
#define kNtPdhFmtNocap100     0x00008000u
#define kNtPerfDetailCostly   0x00010000u
#define kNtPerfDetailStandard 0x0000FFFFu



/*!BEGIN libc/nt/enum/processaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSACCESS_H_

#define kNtProcessCreateProcess 0x0080u
#define kNtProcessCreateThread 0x0002u
#define kNtProcessDupHandle 0x0040u
#define kNtProcessQueryInformation 0x0400u
#define kNtProcessQueryLimitedInformation 0x1000u
#define kNtProcessSetInformation 0x0200u
#define kNtProcessSetQuota 0x0100u
#define kNtProcessSuspendResume 0x0800u
#define kNtProcessTerminate 0x0001u
#define kNtProcessVmOperation 0x0008u
#define kNtProcessVmRead 0x0010u
#define kNtProcessVmWrite 0x0020u
#define kNtProcessSynchronize kNtSynchronize
#define kNtProcessAllAccess \
  (kNtStandardRightsRequired | kNtSynchronize | 0xffffu)



/*!BEGIN libc/nt/enum/processcreationflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSCREATIONFLAGS_H_

#define kNtIdlePriorityClass        0x00000040u
#define kNtBelowNormalPriorityClass 0x00004000u
#define kNtNormalPriorityClass      0x00000020u
#define kNtAboveNormalPriorityClass 0x00008000u
#define kNtHighPriorityClass        0x00000080u
#define kNtRealtimePriorityClass    0x00000100u

#define kNtDebugProcess                 0x00000001u
#define kNtDebugOnlyThisProcess         0x00000002u
#define kNtCreateSuspended              0x00000004u
#define kNtDetachedProcess              0x00000008u
#define kNtCreateNewConsole             0x00000010u
#define kNtCreateNewProcessGroup        0x00000200u
#define kNtCreateUnicodeEnvironment     0x00000400u
#define kNtCreateSeparateWowVdm         0x00000800u
#define kNtCreateSharedWowVdm           0x00001000u
#define kNtCreateForcedos               0x00002000u
#define kNtInheritParentAffinity        0x00010000u
#define kNtCreateProtectedProcess       0x00040000u
#define kNtExtendedStartupinfoPresent   0x00080000u
#define kNtProcessModeBackgroundBegin   0x00100000u
#define kNtProcessModeBackgroundEnd     0x00200000u
#define kNtCreateSecureProcess          0x00400000u
#define kNtCreateBreakawayFromJob       0x01000000u
#define kNtCreatePreserveCodeAuthzLevel 0x02000000u
#define kNtCreateDefaultErrorMode       0x04000000u
#define kNtCreateNoWindow               0x08000000u
#define kNtProfileUser                  0x10000000u
#define kNtProfileKernel                0x20000000u
#define kNtProfileServer                0x40000000u
#define kNtCreateIgnoreSystemDefault    0x80000000u

#define kNtStackSizeParamIsAReservation 0x00010000



/*!BEGIN libc/nt/enum/processinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSINFOCLASS_H_

#define kNtProcessBasicInformation 0
#define kNtProcessQuotaLimits      1
#define kNtProcessIoCounters       2
#define kNtProcessVmCounters       3
#define kNtProcessTimes            4
#define kNtProcessBasePriority     5
#define kNtProcessRaisePriority    6
#define kNtProcessDebugPort        7
#define kNtProcessExceptionPort    8
#define kNtProcessAccessToken      9
#define kNtProcessWow64Information 26
#define kNtProcessImageFileName    27



/*!BEGIN libc/nt/enum/procthreadattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCTHREADATTRIBUTES_H_

#define kNtProcThreadAttributeReplaceValue 1
#define kNtProcThreadAttributeHandleList 0x00020002



/*!BEGIN libc/nt/enum/progress.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROGRESS_H_

#define kNtProgressContinue 0
#define kNtProgressCancel   1
#define kNtProgressStop     2
#define kNtProgressQuiet    3



/*!BEGIN libc/nt/enum/pseudoconsole.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PSEUDOCONSOLE_H_

#define kNtPseudoconsoleInheritCursor 1



/*!BEGIN libc/nt/enum/pwr.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PWR_H_

#define kNtPwrOk             1
#define kNtPwrFail           (-1)
#define kNtPwrSuspendrequest 1
#define kNtPwrSuspendresume  2
#define kNtPwrCriticalresume 3



/*!BEGIN libc/nt/enum/rdw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_RDW_H_

#define kNtRdwInvalidate      0x0001
#define kNtRdwInternalpaint   0x0002
#define kNtRdwErase           0x0004
#define kNtRdwValidate        0x0008
#define kNtRdwNointernalpaint 0x0010
#define kNtRdwNoerase         0x0020
#define kNtRdwNochildren      0x0040
#define kNtRdwAllchildren     0x0080
#define kNtRdwUpdatenow       0x0100
#define kNtRdwErasenow        0x0200
#define kNtRdwFrame           0x0400
#define kNtRdwNoframe         0x0800



/*!BEGIN libc/nt/enum/reggetvalueflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGGETVALUEFLAGS_H_

#define kNtRrfRtRegNone        0x00000001
#define kNtRrfRtRegSz          0x00000002
#define kNtRrfRtRegExpandSz    0x00000004
#define kNtRrfRtRegBinary      0x00000008
#define kNtRrfRtRegDword       0x00000010
#define kNtRrfRtRegMultiSz     0x00000020
#define kNtRrfRtRegQword       0x00000040
#define kNtRrfRtDword          (kNtRrfRtRegBinary | kNtRrfRtRegDword)
#define kNtRrfRtQword          (kNtRrfRtRegBinary | kNtRrfRtRegQword)
#define kNtRrfRtAny            0x0000ffff
#define kNtRrfSubkeyWow6464key 0x00010000
#define kNtRrfSubkeyWow6432key 0x00020000
#define kNtRrfWow64Mask        0x00030000
#define kNtRrfNoexpand         0x10000000
#define kNtRrfZeroonfailure    0x20000000



/*!BEGIN libc/nt/enum/regtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGTYPE_H_

#define kNtRegNone                     0
#define kNtRegSz                       1 /* UTF-16 string */
#define kNtRegExpandSz                 2 /* UTF-16 string w/ env vars refs */
#define kNtRegBinary                   3
#define kNtRegDword                    4
#define kNtRegDwordBigEndian           5
#define kNtRegLink                     6
#define kNtRegMultiSz                  7 /* UTF-16 double-nul-terminated */
#define kNtRegResourceList             8
#define kNtRegFullResourceDescriptor   9
#define kNtRegResourceRequirementsList 10
#define kNtRegQword                    11



/*!BEGIN libc/nt/enum/replacefile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REPLACEFILE_H_

#define kNtReplacefileWriteThrough      1
#define kNtReplacefileIgnoreMergeErrors 2
#define kNtReplacefileIgnoreAclErrors   4



/*!BEGIN libc/nt/enum/sc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SC_H_

#define kNtScSize         0xF000
#define kNtScMove         0xF010
#define kNtScMinimize     0xF020
#define kNtScMaximize     0xF030
#define kNtScNextwindow   0xF040
#define kNtScPrevwindow   0xF050
#define kNtScClose        0xF060
#define kNtScVscroll      0xF070
#define kNtScHscroll      0xF080
#define kNtScMousemenu    0xF090
#define kNtScKeymenu      0xF100
#define kNtScArrange      0xF110
#define kNtScRestore      0xF120
#define kNtScTasklist     0xF130
#define kNtScScreensave   0xF140
#define kNtScHotkey       0xF150
#define kNtScDefault      0xF160
#define kNtScMonitorpower 0xF170
#define kNtScContexthelp  0xF180
#define kNtScSeparator    0xF00F



/*!BEGIN libc/nt/enum/sectioninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINFORMATIONCLASS_H_

#define kNtSectionBasicInformation 0
#define kNtSectionImageInformation 1



/*!BEGIN libc/nt/enum/sectioninherit.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINHERIT_H_

enum NtSectionInherit { kNtViewShare = 1, kNtViewUnmap = 2 };



/*!BEGIN libc/nt/enum/sectionmapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONMAPFLAGS_H_

#define kNtSectionQuery              0x0001
#define kNtSectionMapWrite           0x0002
#define kNtSectionMapRead            0x0004
#define kNtSectionMapExecute         0x0008
#define kNtSectionExtendSize         0x0010
#define kNtSectionMapExecuteExplicit 0x0020



/*!BEGIN libc/nt/enum/securityimpersonationlevel.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYIMPERSONATIONLEVEL_H_

#define kNtSecurityAnonymous      0
#define kNtSecurityIdentification 1
#define kNtSecurityImpersonation  2
#define kNtSecurityDelegation     3



/*!BEGIN libc/nt/enum/securityinformation.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYINFORMATION_H_

#define kNtOwnerSecurityInformation 0x00000001
#define kNtGroupSecurityInformation 0x00000002
#define kNtDaclSecurityInformation 0x00000004
#define kNtSaclSecurityInformation 0x00000008
#define kNtLabelSecurityInformation 0x00000010
#define kNtAttributeSecurityInformation 0x00000020
#define kNtScopeSecurityInformation 0x00000040
#define kNtProcessTrustLabelSecurityInformation 0x00000080
#define kNtAccessFilterSecurityInformation 0x00000100
#define kNtBackupSecurityInformation 0x00010000
#define kNtProtectedDaclSecurityInformation 0x80000000
#define kNtProtectedSaclSecurityInformation 0x40000000
#define kNtUnprotectedDaclSecurityInformation 0x20000000
#define kNtUnprotectedSaclSecurityInformation 0x10000000



/*!BEGIN libc/nt/enum/signal.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIGNAL_H_

#define kNtSignalBreakpoint          0x80000003u
#define kNtSignalIllegalInstruction  0xC000001Du
#define kNtSignalPrivInstruction     0xC0000096u
#define kNtSignalGuardPage           0x80000001u
#define kNtSignalAccessViolation     0xC0000005u
#define kNtSignalInPageError         0xC0000006u
#define kNtSignalInvalidHandle       0xC0000008u
#define kNtSignalInvalidParameter    0xC000000du
#define kNtSignalFltDenormalOperand  0xC000008Du
#define kNtSignalFltDivideByZero     0xC000008Eu
#define kNtSignalFltInexactResult    0xC000008Fu
#define kNtSignalFltInvalidOperation 0xC0000090u
#define kNtSignalFltOverflow         0xC0000091u
#define kNtSignalFltStackCheck       0xC0000092u
#define kNtSignalFltUnderflow        0xC0000093u
#define kNtSignalIntegerDivideByZero 0xC0000094u
#define kNtSignalDllNotFound         0xC0000135u
#define kNtSignalOrdinalNotFound     0xC0000138u
#define kNtSignalEntrypointNotFound  0xC0000139u
#define kNtSignalControlCExit        0xC000013Au
#define kNtSignalDllInitFailed       0xC0000142u
#define kNtSignalFloatMultipleFaults 0xC00002B4u
#define kNtSignalFloatMultipleTraps  0xC00002B5u
#define kNtSignalAssertionFailure    0xC0000420u



/*!BEGIN libc/nt/enum/sio.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIO_H_

#define kNtSioAbsorbRtralert                      0x98000005u
#define kNtSioAcquirePortReservation              0x98000064u
#define kNtSioAddressListChange                   0x28000017u
#define kNtSioAddressListQuery                    0x48000016u
#define kNtSioAddressListSort                     0xc8000019u
#define kNtSioApplyTransportSetting               0x98000013u
#define kNtSioAssociateHandle                     0x88000001u
#define kNtSioAssociatePortReservation            0x98000066u
#define kNtSioBaseHandle                          0x48000022u
#define kNtSioBspHandlePoll                       0x4800001Du
#define kNtSioDeletePeerTargetName                0x980000cbu
#define kNtSioEnableCircularQueueing              0x28000002u
#define kNtSioFindRoute                           0x48000003u
#define kNtSioFlush                               0x28000004u
#define kNtSioGetBroadcastAddress                 0x48000005u
#define kNtSioGetExtensionFunctionPointer         0xc8000006u
#define kNtSioGetGroupQos                         0xc8000008u
#define kNtSioGetInterfaceList                    0x4008747fu
#define kNtSioGetMultipleExtensionFunctionPointer 0xc8000024u
#define kNtSioGetQos                              0xc8000007u
#define kNtSioIndexAddMcast                       0x9800000au
#define kNtSioIndexBind                           0x98000008u
#define kNtSioIndexDelMcast                       0x9800000bu
#define kNtSioIndexMcastif                        0x98000009u
#define kNtSioKeepaliveVals                       0x98000004u
#define kNtSioLimitBroadcasts                     0x98000007u
#define kNtSioLoopbackFastPath                    0x98000010u
#define kNtSioMulticastScope                      0x8800000au
#define kNtSioMultipointLoopback                  0x88000009u
#define kNtSioQueryRssProcessorInfo               0x48000025u
#define kNtSioQueryRssScalabilityInfo             0x580000d2u
#define kNtSioQuerySecurity                       0xd80000c9u
#define kNtSioQueryTargetPnpHandle                0x48000018u
#define kNtSioQueryTransportSetting               0x98000014u
#define kNtSioQueryWfpAleEndpointHandle           0x580000cdu
#define kNtSioQueryWfpConnectionRedirectContext   0x980000ddu
#define kNtSioQueryWfpConnectionRedirectRecords   0x980000dcu
#define kNtSioRcvall                              0x98000001u
#define kNtSioRcvallIf                            0x9800000eu
#define kNtSioRcvallIgmpmcast                     0x98000003u
#define kNtSioRcvallMcast                         0x98000002u
#define kNtSioRcvallMcastIf                       0x9800000du
#define kNtSioReleasePortReservation              0x98000065u
#define kNtSioReserved1                           0x8800001au
#define kNtSioReserved2                           0x88000021u
#define kNtSioRoutingInterfaceChange              0x88000015u
#define kNtSioRoutingInterfaceQuery               0xc8000014u
#define kNtSioSetGroupQos                         0x8800000cu
#define kNtSioSetPeerTargetName                   0x980000cau
#define kNtSioSetPriorityHint                     0x98000018u
#define kNtSioSetQos                              0x8800000bu
#define kNtSioSetSecurity                         0x980000c8u
#define kNtSioSetWfpConnectionRedirectRecords     0x980000deu
#define kNtSioSocketCloseNotify                   0x9800000du
#define kNtSioSocketUsageNotification             0x980000ccu
#define kNtSioTcpInfo                             0xd8000027u
#define kNtSioTcpInitialRto                       0x98000011u
#define kNtSioTcpSetAckFrequency                  0x98000017u
#define kNtSioTcpSetIcw                           0x98000016u
#define kNtSioTranslateHandle                     0xc800000du
#define kNtSioUcastIf                             0x98000006u
#define kNtSioUdpConnreset                        0x9800000cu
#define kNtSioUdpNetreset                         0x9800000fu



/*!BEGIN libc/nt/enum/size.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIZE_H_

#define kNtSizeRestored  0
#define kNtSizeMinimized 1
#define kNtSizeMaximized 2
#define kNtSizeMaxshow   3
#define kNtSizeMaxhide   4



/*!BEGIN libc/nt/enum/startf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STARTF_H_

#define kNtStartfUseshowwindow 0x00000001 /* otherwise wShowWindow ignored */
#define kNtStartfUsesize 0x00000002       /* otherwise dwX / dwY ignored */
#define kNtStartfUseposition 0x00000004   /* otherwise dwX/YSize ignored */
#define kNtStartfUsecountchars 0x00000008 /* otherwise dwX/YCountChars ign. */
#define kNtStartfUsefillattribute 0x00000010 /* etc. */
#define kNtStartfRunfullscreen 0x00000020
#define kNtStartfForceonfeedback 0x00000040
#define kNtStartfForceofffeedback 0x00000080
#define kNtStartfUsestdhandles 0x00000100 /* otherwise hStd... ignored */
#define kNtStartfUsehotkey 0x00000200
#define kNtStartfTitleislinkname 0x00000800
#define kNtStartfTitleisappid 0x00001000
#define kNtStartfPreventpinning 0x00002000
#define kNtStartfUntrustedsource 0x00008000



/*!BEGIN libc/nt/enum/statfs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STATFS_H_
COSMOPOLITAN_C_START_

#define kNtFileCasePreservedNames         0x00000002
#define kNtFileCaseSensitiveSearch        0x00000001
#define kNtFileFileCompression            0x00000010
#define kNtFileNamedStreams               0x00040000
#define kNtFilePersistentAcls             0x00000008
#define kNtFileReadOnlyVolume             0x00080000 /* ST_RDONLY */
#define kNtFileSequentialWriteOnce        0x00100000
#define kNtFileSupportsEncryption         0x00020000
#define kNtFileSupportsExtendedAttributes 0x00800000
#define kNtFileSupportsHardLinks          0x00400000
#define kNtFileSupportsObjectIds          0x00010000
#define kNtFileSupportsOpenByFileId       0x01000000
#define kNtFileSupportsReparsePoints      0x00000080
#define kNtFileSupportsSparseFiles        0x00000040
#define kNtFileSupportsTransactions       0x00200000
#define kNtFileSupportsUsnJournal         0x02000000
#define kNtFileUnicodeOnDisk              0x00000004
#define kNtFileVolumeIsCompressed         0x00008000
#define kNtFileVolumeQuotas               0x00000020
#define kNtFileSupportsBlockRefcounting   0x08000000

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/status.h */

#define COSMOPOLITAN_LIBC_NT_STATUS_H_

/* high two bits = {success,informational,warning,error} */
#define kNtStatusSuccess                  0x00000000 /* success statuses */
#define kNtStatusWait0                    0x00000000
#define kNtStatusAbandonedWait0           0x00000080
#define kNtStatusUserApc                  0x000000C0
#define kNtStatusTimeout                  0x00000102
#define kNtStatusPending                  0x00000103
#define kNtStatusGuardPageViolation       0x80000001 /* warning statuses */
#define kNtStatusDatatypeMisalignment     0x80000002
#define kNtStatusBreakpoint               0x80000003
#define kNtStatusSingleStep               0x80000004
#define kNtStatusLongjump                 0x80000026
#define kNtStatusUnwindConsolidate        0x80000029
#define kNtStatusAccessViolation          0xC0000005 /* error statuses */
#define kNtStatusInPageError              0xC0000006
#define kNtStatusInvalidHandle            0xC0000008
#define kNtStatusInvalidParameter         0xC000000D
#define kNtStatusNoMemory                 0xC0000017
#define kNtStatusIllegalInstruction       0xC000001D
#define kNtStatusNoncontinuableException  0xC0000025
#define kNtStatusInvalidDisposition       0xC0000026
#define kNtStatusArrayBoundsExceeded      0xC000008C
#define kNtStatusFloatDenormalOperand     0xC000008D
#define kNtStatusFloatDivideByZero        0xC000008E
#define kNtStatusFloatInexactResult       0xC000008F
#define kNtStatusFloatInvalidOperation    0xC0000090
#define kNtStatusFloatOverflow            0xC0000091
#define kNtStatusFloatStackCheck          0xC0000092
#define kNtStatusFloatUnderflow           0xC0000093
#define kNtStatusIntegerDivideBYZero      0xC0000094
#define kNtStatusIntegerOverflow          0xC0000095
#define kNtStatusPrivilegedInstruction    0xC0000096
#define kNtStatusStackOverflow            0xC00000FD
#define kNtStatusDllNotFound              0xC0000135
#define kNtStatusOrdinalNotFound          0xC0000138
#define kNtStatusEntrypointNotFound       0xC0000139
#define kNtStatusControlCExit             0xC000013A
#define kNtStatusDllInitFailed            0xC0000142
#define kNtStatusFloatMultipleFaults      0xC00002B4
#define kNtStatusFloatMultipleTraps       0xC00002B5
#define kNtStatusRegNatConsumption        0xC00002C9
#define kNtStatusHeapCorruption           0xC0000374
#define kNtStatusStackBufferOverrun       0xC0000409
#define kNtStatusInvalidCruntimeParameter 0xC0000417
#define kNtStatusAssertionFailure         0xC0000420
#define kNtStatusEnclaveViolation         0xC00004A2
#define kNtStatusSegmentNotification      0x40000005
#define kNtStatusFatalAppExit             0x40000015
#define kNtStatusNotFound                 0xC0000225
#define kNtStatusCancelled                0xC0000120

#define kNtDbgExceptionHandled    0x00010001
#define kNtDbgContinue            0x00010002
#define kNtDbgReplyLater          0x40010001
#define kNtDbgTerminateThread     0x40010003
#define kNtDbgTerminateProcess    0x40010004
#define kNtDbgControlC            0x40010005
#define kNtDbgPrintexceptionC     0x40010006
#define kNtDbgRipexception        0x40010007
#define kNtDbgControlBreak        0x40010008
#define kNtDbgCommandException    0x40010009
#define kNtDbgPrintexceptionWideC 0x4001000A
#define kNtDbgExceptionNotHandled 0x80010001
#define kNtStillActive            kNtStatusPending

#if !(__ASSEMBLER__ + __LINKER__ + 0)

typedef uint32_t NtStatus;

#define NtSuccess(s)      ((NtStatus)(s) >= 0)
#define NtInformation(s)  (NtSeverity(s) == 1)
#define NtWarning(s)      (NtSeverity(s) == 2)
#define NtError(s)        (NtSeverity(s) == 3)
#define NtCode(s)         ((NtStatus)(s)&0xffff)
#define NtSeverity(s)     ((NtStatus)(s) >> 30)
#define NtFacility(s)     (((NtStatus)(s) >> 16) & 0xfff)
#define NtFacilityCode(s) ((NtStatus)(s)&0x0FFFFFFF)

#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nt/enum/sw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SW_H_

#define kNtSwHide            0
#define kNtSwShownormal      1
#define kNtSwNormal          1
#define kNtSwShowminimized   2
#define kNtSwShowmaximized   3
#define kNtSwMaximize        3
#define kNtSwShownoactivate  4
#define kNtSwShow            5
#define kNtSwMinimize        6
#define kNtSwShowminnoactive 7
#define kNtSwShowna          8
#define kNtSwRestore         9
#define kNtSwShowdefault     10
#define kNtSwForceminimize   11



/*!BEGIN libc/nt/enum/symboliclink.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYMBOLICLINK_H_

#define kNtSymbolicLinkFlagDirectory               1
#define kNtSymbolicLinkFlagAllowUnprivilegedCreate 2



/*!BEGIN libc/nt/enum/systeminformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYSTEMINFORMATIONCLASS_H_

#define kNtSystemBasicInformation 0
#define kNtSystemProcessorInformation 1
#define kNtSystemPerformanceInformation 2
#define kNtSystemTimeOfDayInformation 3
#define kNtSystemProcessInformation 5
#define kNtSystemProcessorTimes 8
#define kNtSystemGlobalFlag 9
#define kNtSystemModuleInformation 11
#define kNtSystemLockInformation 12
#define kNtSystemHandleInformation 16
#define kNtSystemObjectInformation 17
#define kNtSystemInterruptInformation 23
#define kNtSystemExceptionInformation 33
#define kNtSystemRegistryQuotaInformation 37
#define kNtSystemLookasideInformation 45



/*!BEGIN libc/nt/enum/th32cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TH32CS_H_

#define kNtTh32csInherit      0x80000000
#define kNtTh32csSnapheaplist 0x00000001
#define kNtTh32csSnapmodule   0x00000008
#define kNtTh32csSnapmodule32 0x00000010
#define kNtTh32csSnapprocess  0x00000002
#define kNtTh32csSnapthread   0x00000004



/*!BEGIN libc/nt/enum/threadaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADACCESS_H_

#define kNtThreadTerminate 0x0001
#define kNtThreadSuspendResume 0x0002
#define kNtThreadGetContext 0x0008
#define kNtThreadSetContext 0x0010
#define kNtThreadQueryInformation 0x0040
#define kNtThreadSetInformation 0x0020
#define kNtThreadSetThreadToken 0x0080
#define kNtThreadImpersonate 0x0100
#define kNtThreadDirectImpersonation 0x0200
#define kNtThreadSetLimitedInformation 0x0400
#define kNtThreadQueryLimitedInformation 0x0800
#define kNtThreadResume 0x1000
#define kNtThreadAllAccess (kNtStandardRightsRequired | kNtSynchronize | 0xFFFF)



/*!BEGIN libc/nt/enum/threadinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADINFOCLASS_H_

enum NtThreadInfoClass {
  kNtThreadBasicInformation,
  kNtThreadTimes,
  kNtThreadPriority,
  kNtThreadBasePriority,
  kNtThreadAffinityMask,
  kNtThreadImpersonationToken,
  kNtThreadDescriptorTableEntry,
  kNtThreadEnableAlignmentFaultFixup,
  kNtThreadEventPair_Reusable,
  kNtThreadQuerySetWin32StartAddress,
  kNtThreadZeroTlsCell,
  kNtThreadPerformanceCount,
  kNtThreadAmILastThread,
  kNtThreadIdealProcessor,
  kNtThreadPriorityBoost,
  kNtThreadSetTlsArrayAddress,
  kNtThreadIsIoPending,
  kNtThreadHideFromDebugger,
  kNtThreadInfoClass_MAX
};



/*!BEGIN libc/nt/enum/threadpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADPRIORITY_H_

#define kNtThreadBasePriorityIdle  (-15)
#define kNtThreadBasePriorityMin   (-2)
#define kNtThreadBasePriorityMax   2
#define kNtThreadBasePriorityLowrt 15

#define kNtThreadPriorityIdle         kNtThreadBasePriorityIdle
#define kNtThreadPriorityLowest       kNtThreadBasePriorityMin
#define kNtThreadPriorityBelowNormal  (kNtThreadPriorityLowest + 1)
#define kNtThreadPriorityNormal       0
#define kNtThreadPriorityAboveNormal  (kNtThreadPriorityHighest - 1)
#define kNtThreadPriorityHighest      kNtThreadBasePriorityMax
#define kNtThreadPriorityTimeCritical kNtThreadBasePriorityLowrt



/*!BEGIN libc/nt/enum/threadstate.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADSTATE_H_

#define kNtStateInitialized 0
#define kNtStateReady       1
#define kNtStateRunning     2
#define kNtStateStandby     3
#define kNtStateTerminated  4
#define kNtStateWait        5
#define kNtStateTransition  6
#define kNtStateUnknown     7



/*!BEGIN libc/nt/enum/timezoneid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TIMEZONEID_H_

#define kNtTimeZoneIdUnknown  0
#define kNtTimeZoneIdStandard 1
#define kNtTimeZoneIdDaylight 2



/*!BEGIN libc/nt/enum/tokeninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENINFORMATIONCLASS_H_

#define kNtTokenUser 1
#define kNtTokenGroups 2
#define kNtTokenPrivileges 3
#define kNtTokenOwner 4
#define kNtTokenPrimaryGroup 5
#define kNtTokenDefaultDacl 6
#define kNtTokenSource 7
#define kNtTokenType 8
#define kNtTokenImpersonationLevel 9
#define kNtTokenStatistics 10
#define kNtTokenRestrictedSids 11
#define kNtTokenSessionId 12
#define kNtTokenGroupsAndPrivileges 13
#define kNtTokenSessionReference 14
#define kNtTokenSandBoxInert 15
#define kNtTokenAuditPolicy 16
#define kNtTokenOrigin 17
#define kNtTokenInfoClass_MAX 18



/*!BEGIN libc/nt/enum/tokentype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENTYPE_H_

#define kNtTokenPrimary       1
#define kNtTokenImpersonation 2



/*!BEGIN libc/nt/enum/tpm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TPM_H_

#define kNtTpmLeftbutton      0x00000
#define kNtTpmRightbutton     0x00002
#define kNtTpmLeftalign       0x00000
#define kNtTpmCenteralign     0x00004
#define kNtTpmRightalign      0x00008
#define kNtTpmTopalign        0x00000
#define kNtTpmVcenteralign    0x00010
#define kNtTpmBottomalign     0x00020
#define kNtTpmHorizontal      0x00000
#define kNtTpmVertical        0x00040
#define kNtTpmNonotify        0x00080
#define kNtTpmReturncmd       0x00100
#define kNtTpmRecurse         0x00001
#define kNtTpmHorposanimation 0x00400
#define kNtTpmHorneganimation 0x00800
#define kNtTpmVerposanimation 0x01000
#define kNtTpmVerneganimation 0x02000
#define kNtTpmNoanimation     0x04000
#define kNtTpmLayoutrtl       0x08000
#define kNtTpmWorkarea        0x10000



/*!BEGIN libc/nt/enum/valueinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VALUEINFORMATIONCLASS_H_

#define kNtKeyValueBasicInformation          0
#define kNtKeyValueFullInformation           1
#define kNtKeyValuePartialInformation        2
#define kNtKeyValueFullInformationAlign64    3
#define kNtKeyValuePartialInformationAlign64 4



/*!BEGIN libc/nt/enum/version.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VERSION_H_

/**
 * Known versions of the New Technology executive.
 * @see IsAtLeastWindows10()
 * @see NtGetVersion()
 */
#define kNtVersionWindows10    0x0a00
#define kNtVersionWindows81    0x0603
#define kNtVersionWindows8     0x0602
#define kNtVersionWindows7     0x0601
#define kNtVersionWindowsVista 0x0600 /* intended baseline */
#define kNtVersionWindowsXp64  0x0502 /* end of the road */
#define kNtVersionWindowsXp    0x0501 /* snowball's chance */
#define kNtVersionWindows2000  0x0500 /* the golden age */
#define kNtVersionFuture       0x0b00



/*!BEGIN libc/nt/enum/vk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VK_H_

#define kNtVkLbutton                      0x01
#define kNtVkRbutton                      0x02
#define kNtVkCancel                       0x03
#define kNtVkMbutton                      0x04
#define kNtVkXbutton1                     0x05
#define kNtVkXbutton2                     0x06
#define kNtVkBack                         0x08
#define kNtVkTab                          0x09
#define kNtVkClear                        0x0C
#define kNtVkReturn                       0x0D
#define kNtVkShift                        0x10
#define kNtVkControl                      0x11
#define kNtVkMenu                         0x12 /* alt? */
#define kNtVkPause                        0x13
#define kNtVkCapital                      0x14
#define kNtVkKana                         0x15
#define kNtVkHangul                       0x15
#define kNtVkJunja                        0x17
#define kNtVkFinal                        0x18
#define kNtVkHanja                        0x19
#define kNtVkKanji                        0x19
#define kNtVkEscape                       0x1B
#define kNtVkConvert                      0x1C
#define kNtVkNonconvert                   0x1D
#define kNtVkAccept                       0x1E
#define kNtVkModechange                   0x1F
#define kNtVkSpace                        0x20
#define kNtVkPrior                        0x21 /* page up */
#define kNtVkNext                         0x22 /* page down */
#define kNtVkEnd                          0x23
#define kNtVkHome                         0x24
#define kNtVkLeft                         0x25
#define kNtVkUp                           0x26
#define kNtVkRight                        0x27
#define kNtVkDown                         0x28
#define kNtVkSelect                       0x29
#define kNtVkPrint                        0x2A
#define kNtVkExecute                      0x2B
#define kNtVkSnapshot                     0x2C
#define kNtVkInsert                       0x2D
#define kNtVkDelete                       0x2E
#define kNtVkHelp                         0x2F
#define kNtVkLwin                         0x5B
#define kNtVkRwin                         0x5C
#define kNtVkApps                         0x5D
#define kNtVkSleep                        0x5F
#define kNtVkNumpad0                      0x60
#define kNtVkNumpad1                      0x61
#define kNtVkNumpad2                      0x62
#define kNtVkNumpad3                      0x63
#define kNtVkNumpad4                      0x64
#define kNtVkNumpad5                      0x65
#define kNtVkNumpad6                      0x66
#define kNtVkNumpad7                      0x67
#define kNtVkNumpad8                      0x68
#define kNtVkNumpad9                      0x69
#define kNtVkMultiply                     0x6A
#define kNtVkAdd                          0x6B
#define kNtVkSeparator                    0x6C
#define kNtVkSubtract                     0x6D
#define kNtVkDecimal                      0x6E
#define kNtVkDivide                       0x6F
#define kNtVkF1                           0x70
#define kNtVkF2                           0x71
#define kNtVkF3                           0x72
#define kNtVkF4                           0x73
#define kNtVkF5                           0x74
#define kNtVkF6                           0x75
#define kNtVkF7                           0x76
#define kNtVkF8                           0x77
#define kNtVkF9                           0x78
#define kNtVkF10                          0x79
#define kNtVkF11                          0x7A
#define kNtVkF12                          0x7B
#define kNtVkF13                          0x7C
#define kNtVkF14                          0x7D
#define kNtVkF15                          0x7E
#define kNtVkF16                          0x7F
#define kNtVkF17                          0x80
#define kNtVkF18                          0x81
#define kNtVkF19                          0x82
#define kNtVkF20                          0x83
#define kNtVkF21                          0x84
#define kNtVkF22                          0x85
#define kNtVkF23                          0x86
#define kNtVkF24                          0x87
#define kNtVkNumlock                      0x90
#define kNtVkScroll                       0x91
#define kNtVkLshift                       0xA0
#define kNtVkRshift                       0xA1
#define kNtVkLcontrol                     0xA2
#define kNtVkRcontrol                     0xA3
#define kNtVkLmenu                        0xA4
#define kNtVkRmenu                        0xA5
#define kNtVkBrowserBack                  0xA6
#define kNtVkBrowserForward               0xA7
#define kNtVkBrowserRefresh               0xA8
#define kNtVkBrowserStop                  0xA9
#define kNtVkBrowserSearch                0xAA
#define kNtVkBrowserFavorites             0xAB
#define kNtVkBrowserHome                  0xAC
#define kNtVkVolumeMute                   0xAD
#define kNtVkVolumeDown                   0xAE
#define kNtVkVolumeUp                     0xAF
#define kNtVkMediaNextTrack               0xB0
#define kNtVkMediaPrevTrack               0xB1
#define kNtVkMediaStop                    0xB2
#define kNtVkMediaPlayPause               0xB3
#define kNtVkLaunchMail                   0xB4
#define kNtVkLaunchMediaSelect            0xB5
#define kNtVkLaunchApp1                   0xB6
#define kNtVkLaunchApp2                   0xB7
#define kNtVkOem_1                        0xBA
#define kNtVkOemPlus                      0xBB
#define kNtVkOemComma                     0xBC
#define kNtVkOemMinus                     0xBD
#define kNtVkOemPeriod                    0xBE
#define kNtVkOem_2                        0xBF
#define kNtVkOem_3                        0xC0
#define kNtVkGamepadA                     0xC3
#define kNtVkGamepadB                     0xC4
#define kNtVkGamepadX                     0xC5
#define kNtVkGamepadY                     0xC6
#define kNtVkGamepadRightShoulder         0xC7
#define kNtVkGamepadLeftShoulder          0xC8
#define kNtVkGamepadLeftTrigger           0xC9
#define kNtVkGamepadRightTrigger          0xCA
#define kNtVkGamepadDpadUp                0xCB
#define kNtVkGamepadDpadDown              0xCC
#define kNtVkGamepadDpadLeft              0xCD
#define kNtVkGamepadDpadRight             0xCE
#define kNtVkGamepadMenu                  0xCF
#define kNtVkGamepadView                  0xD0
#define kNtVkGamepadLeftThumbstickButton  0xD1
#define kNtVkGamepadRightThumbstickButton 0xD2
#define kNtVkGamepadLeftThumbstickUp      0xD3
#define kNtVkGamepadLeftThumbstickDown    0xD4
#define kNtVkGamepadLeftThumbstickRight   0xD5
#define kNtVkGamepadLeftThumbstickLeft    0xD6
#define kNtVkGamepadRightThumbstickUp     0xD7
#define kNtVkGamepadRightThumbstickDown   0xD8
#define kNtVkGamepadRightThumbstickRight  0xD9
#define kNtVkGamepadRightThumbstickLeft   0xDA
#define kNtVkOem_4                        0xDB
#define kNtVkOem_5                        0xDC
#define kNtVkOem_6                        0xDD
#define kNtVkOem_7                        0xDE
#define kNtVkOem_8                        0xDF
#define kNtVkOemAx                        0xE1
#define kNtVkOem_102                      0xE2
#define kNtVkIcoHelp                      0xE3
#define kNtVkIco_00                       0xE4
#define kNtVkProcesskey                   0xE5
#define kNtVkIcoClear                     0xE6
#define kNtVkPacket                       0xE7
#define kNtVkOemReset                     0xE9
#define kNtVkOemJump                      0xEA
#define kNtVkOemPa1                       0xEB
#define kNtVkOemPa2                       0xEC
#define kNtVkOemPa3                       0xED
#define kNtVkOemWsctrl                    0xEE
#define kNtVkOemCusel                     0xEF
#define kNtVkOemAttn                      0xF0
#define kNtVkOemFinish                    0xF1
#define kNtVkOemCopy                      0xF2
#define kNtVkOemAuto                      0xF3
#define kNtVkOemEnlw                      0xF4
#define kNtVkOemBacktab                   0xF5
#define kNtVkAttn                         0xF6
#define kNtVkCrsel                        0xF7
#define kNtVkExsel                        0xF8
#define kNtVkEreof                        0xF9
#define kNtVkPlay                         0xFA
#define kNtVkZoom                         0xFB
#define kNtVkNoname                       0xFC
#define kNtVkPa1                          0xFD
#define kNtVkOemClear                     0xFE



/*!BEGIN libc/nt/enum/wa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WA_H_

#define kNtWaInactive    0
#define kNtWaActive      1
#define kNtWaClickactive 2



/*!BEGIN libc/nt/enum/wait.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WAIT_H_

#define kNtWaitFailed    0xffffffffu
#define kNtWaitTimeout   0x00000102u
#define kNtWaitAbandoned 0x00000080u



/*!BEGIN libc/nt/enum/wm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WM_H_

#define kNtWmNull                   0x0000
#define kNtWmCreate                 0x0001
#define kNtWmDestroy                0x0002
#define kNtWmMove                   0x0003
#define kNtWmSize                   0x0005
#define kNtWmActivate               0x0006
#define kNtWmSetfocus               0x0007
#define kNtWmKillfocus              0x0008
#define kNtWmEnable                 0x000A
#define kNtWmSetredraw              0x000B
#define kNtWmSettext                0x000C
#define kNtWmGettext                0x000D
#define kNtWmGettextlength          0x000E
#define kNtWmPaint                  0x000F
#define kNtWmClose                  0x0010
#define kNtWmQueryendsession        0x0011
#define kNtWmQueryopen              0x0013
#define kNtWmEndsession             0x0016
#define kNtWmQuit                   0x0012
#define kNtWmErasebkgnd             0x0014
#define kNtWmSyscolorchange         0x0015
#define kNtWmShowwindow             0x0018
#define kNtWmWininichange           0x001A
#define kNtWmSettingchange          kNtWmWininichange
#define kNtWmDevmodechange          0x001B
#define kNtWmActivateapp            0x001C
#define kNtWmFontchange             0x001D
#define kNtWmTimechange             0x001E
#define kNtWmCancelmode             0x001F
#define kNtWmSetcursor              0x0020
#define kNtWmMouseactivate          0x0021
#define kNtWmChildactivate          0x0022
#define kNtWmQueuesync              0x0023
#define kNtWmGetminmaxinfo          0x0024
#define kNtWmPainticon              0x0026
#define kNtWmIconerasebkgnd         0x0027
#define kNtWmNextdlgctl             0x0028
#define kNtWmSpoolerstatus          0x002A
#define kNtWmDrawitem               0x002B
#define kNtWmMeasureitem            0x002C
#define kNtWmDeleteitem             0x002D
#define kNtWmVkeytoitem             0x002E
#define kNtWmChartoitem             0x002F
#define kNtWmSetfont                0x0030
#define kNtWmGetfont                0x0031
#define kNtWmSethotkey              0x0032
#define kNtWmGethotkey              0x0033
#define kNtWmQuerydragicon          0x0037
#define kNtWmCompareitem            0x0039
#define kNtWmGetobject              0x003D
#define kNtWmCompacting             0x0041
#define kNtWmWindowposchanging      0x0046
#define kNtWmWindowposchanged       0x0047
#define kNtWmPower                  0x0048
#define kNtWmCopydata               0x004A
#define kNtWmCanceljournal          0x004B
#define kNtWmNotify                 0x004E
#define kNtWmInputlangchangerequest 0x0050
#define kNtWmInputlangchange        0x0051
#define kNtWmTcard                  0x0052
#define kNtWmHelp                   0x0053
#define kNtWmUserchanged            0x0054
#define kNtWmNotifyformat           0x0055
#define kNtWmContextmenu            0x007B
#define kNtWmStylechanging          0x007C
#define kNtWmStylechanged           0x007D
#define kNtWmDisplaychange          0x007E
#define kNtWmGeticon                0x007F
#define kNtWmSeticon                0x0080
#define kNtWmNccreate               0x0081
#define kNtWmNcdestroy              0x0082
#define kNtWmNccalcsize             0x0083
#define kNtWmNchittest              0x0084
#define kNtWmNcpaint                0x0085
#define kNtWmNcactivate             0x0086
#define kNtWmGetdlgcode             0x0087
#define kNtWmNcmousemove            0x00A0
#define kNtWmNclbuttondown          0x00A1
#define kNtWmNclbuttonup            0x00A2
#define kNtWmNclbuttondblclk        0x00A3
#define kNtWmNcrbuttondown          0x00A4
#define kNtWmNcrbuttonup            0x00A5
#define kNtWmNcrbuttondblclk        0x00A6
#define kNtWmNcmbuttondown          0x00A7
#define kNtWmNcmbuttonup            0x00A8
#define kNtWmNcmbuttondblclk        0x00A9
#define kNtWmNcxbuttondown          0x00AB
#define kNtWmNcxbuttonup            0x00AC
#define kNtWmNcxbuttondblclk        0x00AD
#define kNtWmKeyfirst               0x0100
#define kNtWmKeydown                0x0100
#define kNtWmKeyup                  0x0101
#define kNtWmChar                   0x0102
#define kNtWmDeadchar               0x0103
#define kNtWmSyskeydown             0x0104
#define kNtWmSyskeyup               0x0105
#define kNtWmSyschar                0x0106
#define kNtWmSysdeadchar            0x0107
#define kNtWmUnichar                0x0109
#define kNtWmKeylast                0x0109
#define kNtWmInitdialog             0x0110
#define kNtWmCommand                0x0111
#define kNtWmSyscommand             0x0112
#define kNtWmTimer                  0x0113
#define kNtWmHscroll                0x0114
#define kNtWmVscroll                0x0115
#define kNtWmInitmenu               0x0116
#define kNtWmInitmenupopup          0x0117
#define kNtWmGesture                0x0119
#define kNtWmGesturenotify          0x011A
#define kNtWmMenuselect             0x011F
#define kNtWmMenuchar               0x0120
#define kNtWmEnteridle              0x0121
#define kNtWmMenurbuttonup          0x0122
#define kNtWmMenudrag               0x0123
#define kNtWmMenugetobject          0x0124
#define kNtWmUninitmenupopup        0x0125
#define kNtWmMenucommand            0x0126
#define kNtWmChangeuistate          0x0127
#define kNtWmUpdateuistate          0x0128
#define kNtWmQueryuistate           0x0129
#define kNtWmMousefirst             0x0200
#define kNtWmMousemove              0x0200
#define kNtWmLbuttondown            0x0201
#define kNtWmLbuttonup              0x0202
#define kNtWmLbuttondblclk          0x0203
#define kNtWmRbuttondown            0x0204
#define kNtWmRbuttonup              0x0205
#define kNtWmRbuttondblclk          0x0206
#define kNtWmMbuttondown            0x0207
#define kNtWmMbuttonup              0x0208
#define kNtWmMbuttondblclk          0x0209
#define kNtWmMousewheel             0x020A
#define kNtWmXbuttondown            0x020B
#define kNtWmXbuttonup              0x020C
#define kNtWmXbuttondblclk          0x020D
#define kNtWmMousehwheel            0x020E
#define kNtWmMouselast              0x020E
#define kNtWmParentnotify           0x0210
#define kNtWmEntermenuloop          0x0211
#define kNtWmExitmenuloop           0x0212
#define kNtWmNextmenu               0x0213
#define kNtWmSizing                 0x0214
#define kNtWmCapturechanged         0x0215
#define kNtWmMoving                 0x0216
#define kNtWmPowerbroadcast         0x0218
#define kNtWmMdicreate              0x0220
#define kNtWmMdidestroy             0x0221
#define kNtWmMdiactivate            0x0222
#define kNtWmMdirestore             0x0223
#define kNtWmMdinext                0x0224
#define kNtWmMdimaximize            0x0225
#define kNtWmMditile                0x0226
#define kNtWmMdicascade             0x0227
#define kNtWmMdiiconarrange         0x0228
#define kNtWmMdigetactive           0x0229
#define kNtWmMdisetmenu             0x0230
#define kNtWmEntersizemove          0x0231
#define kNtWmExitsizemove           0x0232
#define kNtWmDropfiles              0x0233
#define kNtWmMdirefreshmenu         0x0234
#define kNtWmCut                    0x0300
#define kNtWmCopy                   0x0301
#define kNtWmPaste                  0x0302
#define kNtWmClear                  0x0303
#define kNtWmUndo                   0x0304
#define kNtWmRenderformat           0x0305
#define kNtWmRenderallformats       0x0306
#define kNtWmDestroyclipboard       0x0307
#define kNtWmDrawclipboard          0x0308
#define kNtWmPaintclipboard         0x0309
#define kNtWmVscrollclipboard       0x030A
#define kNtWmSizeclipboard          0x030B
#define kNtWmAskcbformatname        0x030C
#define kNtWmChangecbchain          0x030D
#define kNtWmHscrollclipboard       0x030E
#define kNtWmQuerynewpalette        0x030F
#define kNtWmPaletteischanging      0x0310
#define kNtWmPalettechanged         0x0311
#define kNtWmHotkey                 0x0312



/*!BEGIN libc/nt/enum/ws.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WS_H_

#define kNtWsOverlapped   0x00000000
#define kNtWsPopup        0x80000000
#define kNtWsChild        0x40000000
#define kNtWsMinimize     0x20000000
#define kNtWsVisible      0x10000000
#define kNtWsDisabled     0x08000000
#define kNtWsClipsiblings 0x04000000
#define kNtWsClipchildren 0x02000000
#define kNtWsMaximize     0x01000000
#define kNtWsCaption      0x00C00000
#define kNtWsBorder       0x00800000
#define kNtWsDlgframe     0x00400000
#define kNtWsVscroll      0x00200000
#define kNtWsHscroll      0x00100000
#define kNtWsSysmenu      0x00080000
#define kNtWsThickframe   0x00040000
#define kNtWsGroup        0x00020000
#define kNtWsTabstop      0x00010000
#define kNtWsMinimizebox  0x00020000
#define kNtWsMaximizebox  0x00010000
#define kNtWsTiled        kNtWsOverlapped
#define kNtWsIconic       kNtWsMinimize
#define kNtWsSizebox      kNtWsThickframe
#define kNtWsTiledwindow  kNtWsOverlappedwindow
#define kNtWsOverlappedwindow                                        \
  (kNtWsOverlapped | kNtWsCaption | kNtWsSysmenu | kNtWsThickframe | \
   kNtWsMinimizebox | kNtWsMaximizebox)
#define kNtWsPopupwindow (kNtWsPopup | kNtWsBorder | kNtWsSysmenu)

#define kNtWsExDlgmodalframe       0x00000001
#define kNtWsExNoparentnotify      0x00000004
#define kNtWsExTopmost             0x00000008
#define kNtWsExAcceptfiles         0x00000010
#define kNtWsExTransparent         0x00000020
#define kNtWsExMdichild            0x00000040
#define kNtWsExToolwindow          0x00000080
#define kNtWsExWindowedge          0x00000100
#define kNtWsExClientedge          0x00000200
#define kNtWsExContexthelp         0x00000400
#define kNtWsExRight               0x00001000
#define kNtWsExLeft                0x00000000
#define kNtWsExRtlreading          0x00002000
#define kNtWsExLtrreading          0x00000000
#define kNtWsExLeftscrollbar       0x00004000
#define kNtWsExRightscrollbar      0x00000000
#define kNtWsExControlparent       0x00010000
#define kNtWsExStaticedge          0x00020000
#define kNtWsExAppwindow           0x00040000
#define kNtWsExNoinheritlayout     0x00100000
#define kNtWsExNoredirectionbitmap 0x00200000
#define kNtWsExLayoutrtl           0x00400000
#define kNtWsExComposited          0x02000000
#define kNtWsExNoactivate          0x08000000

#define kNtWsExOverlappedwindow (kNtWsExWindowedge | kNtWsExClientedge)
#define kNtWsExPalettewindow \
  (kNtWsExWindowedge | kNtWsExToolwindow | kNtWsExTopmost)



/*!BEGIN libc/nt/enum/wsa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSA_H_


/*!BEGIN libc/nt/errors.h */

#define COSMOPOLITAN_NT_ERRORS_H_

#define kNtNoError 0

#define kNtErrorInsufficientBuffer 122

#define kNtErrorSuccess                                             0
#define kNtErrorInvalidFunction                                     1 /* ENOSYS */
#define kNtErrorFileNotFound                                        2 /* ENOENT */
#define kNtErrorPathNotFound                                        3 /* ENOTDIR */
#define kNtErrorTooManyOpenFiles                                    4 /* EMFILE */
#define kNtErrorAccessDenied                                        5 /* EACCES */
#define kNtErrorInvalidHandle                                       6 /* EBADF */
#define kNtErrorArenaTrashed                                        7
#define kNtErrorNotEnoughMemory                                     8
#define kNtErrorInvalidBlock                                        9
#define kNtErrorBadEnvironment                                      10
#define kNtErrorBadFormat                                           11
#define kNtErrorInvalidAccess                                       12 /* EPERM */
#define kNtErrorInvalidData                                         13
#define kNtErrorOutofmemory                                         14 /* ENOMEM */
#define kNtErrorInvalidDrive                                        15
#define kNtErrorCurrentDirectory                                    16
#define kNtErrorNotSameDevice                                       17
#define kNtErrorNoMoreFiles                                         18
#define kNtErrorWriteProtect                                        19
#define kNtErrorBadUnit                                             20
#define kNtErrorNotReady                                            21
#define kNtErrorBadCommand                                          22
#define kNtErrorCrc                                                 23
#define kNtErrorBadLength                                           24
#define kNtErrorSeek                                                25 /* ESPIPE */
#define kNtErrorNotDosDisk                                          26 /* ENOTBLK */
#define kNtErrorSectorNotFound                                      27
#define kNtErrorOutOfPaper                                          28
#define kNtErrorWriteFault                                          29
#define kNtErrorReadFault                                           30
#define kNtErrorGenFailure                                          31
#define kNtErrorSharingViolation                                    32
#define kNtErrorLockViolation                                       33
#define kNtErrorWrongDisk                                           34
#define kNtErrorSharingBufferExceeded                               36
#define kNtErrorHandleEof                                           38 /* w/ GetOverlappedResult() */
#define kNtErrorHandleDiskFull                                      39
#define kNtErrorNotSupported                                        50
#define kNtErrorRemNotList                                          51
#define kNtErrorDupName                                             52
#define kNtErrorBadNetpath                                          53
#define kNtErrorNetworkBusy                                         54
#define kNtErrorDevNotExist                                         55
#define kNtErrorTooManyCmds                                         56
#define kNtErrorAdapHdwErr                                          57
#define kNtErrorBadNetResp                                          58
#define kNtErrorUnexpNetErr                                         59
#define kNtErrorBadRemAdap                                          60
#define kNtErrorPrintqFull                                          61
#define kNtErrorNoSpoolSpace                                        62
#define kNtErrorPrintCancelled                                      63
#define kNtErrorNetnameDeleted                                      64
#define kNtErrorNetworkAccessDenied                                 65
#define kNtErrorBadDevType                                          66
#define kNtErrorBadNetName                                          67
#define kNtErrorTooManyNames                                        68
#define kNtErrorTooManySess                                         69
#define kNtErrorSharingPaused                                       70
#define kNtErrorReqNotAccep                                         71
#define kNtErrorRedirPaused                                         72
#define kNtErrorFileExists                                          80 /* EEXIST */
#define kNtErrorCannotMake                                          82
#define kNtErrorFailI24                                             83
#define kNtErrorOutOfStructures                                     84
#define kNtErrorAlreadyAssigned                                     85
#define kNtErrorInvalidPassword                                     86
#define kNtErrorInvalidParameter                                    87 /* EINVAL */
#define kNtErrorNetWriteFault                                       88
#define kNtErrorNoProcSlots                                         89
#define kNtErrorTooManySemaphores                                   100
#define kNtErrorExclSemAlreadyOwned                                 101
#define kNtErrorSemIsSet                                            102
#define kNtErrorTooManySemRequests                                  103
#define kNtErrorInvalidAtInterruptTime                              104
#define kNtErrorSemOwnerDied                                        105 /* EOWNERDEAD */
#define kNtErrorSemUserLimit                                        106
#define kNtErrorDiskChange                                          107
#define kNtErrorDriveLocked                                         108
#define kNtErrorBrokenPipe                                          109 /* EPIPE; happens on ReadFile() too */
#define kNtErrorOpenFailed                                          110
#define kNtErrorBufferOverflow                                      111
#define kNtErrorDiskFull                                            112 /* ENOSPC */
#define kNtErrorNoMoreSearchHandles                                 113
#define kNtErrorInvalidTargetHandle                                 114 /* EBADF */
#define kNtErrorInvalidCategory                                     117 /* ENOATTR */
#define kNtErrorInvalidVerifySwitch                                 118
#define kNtErrorBadDriverLevel                                      119
#define kNtErrorCallNotImplemented                                  120
#define kNtErrorSemTimeout                                          121
#define kNtErrorInsufficientBuffer                                  122
#define kNtErrorInvalidName                                         123
#define kNtErrorInvalidLevel                                        124
#define kNtErrorNoVolumeLabel                                       125
#define kNtErrorModNotFound                                         126
#define kNtErrorProcNotFound                                        127
#define kNtErrorWaitNoChildren                                      128 /* ECHILD */
#define kNtErrorChildNotComplete                                    129
#define kNtErrorDirectAccessHandle                                  130 /* EBADF */
#define kNtErrorNegativeSeek                                        131
#define kNtErrorSeekOnDevice                                        132
#define kNtErrorIsJoinTarget                                        133
#define kNtErrorIsJoined                                            134
#define kNtErrorIsSubsted                                           135
#define kNtErrorNotJoined                                           136
#define kNtErrorNotSubsted                                          137
#define kNtErrorJoinToJoin                                          138
#define kNtErrorSubstToSubst                                        139
#define kNtErrorJoinToSubst                                         140
#define kNtErrorSubstToJoin                                         141
#define kNtErrorBusyDrive                                           142
#define kNtErrorSameDrive                                           143
#define kNtErrorDirNotRoot                                          144
#define kNtErrorDirNotEmpty                                         145
#define kNtErrorIsSubstPath                                         146
#define kNtErrorIsJoinPath                                          147
#define kNtErrorPathBusy                                            148 /* ETXTBSY */
#define kNtErrorIsSubstTarget                                       149
#define kNtErrorSystemTrace                                         150
#define kNtErrorInvalidEventCount                                   151
#define kNtErrorTooManyMuxwaiters                                   152
#define kNtErrorInvalidListFormat                                   153
#define kNtErrorLabelTooLong                                        154
#define kNtErrorTooManyTcbs                                         155
#define kNtErrorSignalRefused                                       156
#define kNtErrorDiscarded                                           157
#define kNtErrorNotLocked                                           158 /* ENOLCK */
#define kNtErrorBadThreadidAddr                                     159
#define kNtErrorBadArguments                                        160
#define kNtErrorBadPathname                                         161
#define kNtErrorSignalPending                                       162
#define kNtErrorMaxThrdsReached                                     164
#define kNtErrorLockFailed                                          167
#define kNtErrorBusy                                                170 /* EBUSY */
#define kNtErrorDeviceSupportInProgress                             171
#define kNtErrorCancelViolation                                     173
#define kNtErrorAtomicLocksNotSupported                             174
#define kNtErrorInvalidSegmentNumber                                180
#define kNtErrorInvalidOrdinal                                      182
#define kNtErrorAlreadyExists                                       183 /* EEXIST */
#define kNtErrorInvalidFlagNumber                                   186
#define kNtErrorSemNotFound                                         187
#define kNtErrorInvalidStartingCodeseg                              188
#define kNtErrorInvalidStackseg                                     189
#define kNtErrorInvalidModuletype                                   190
#define kNtErrorInvalidExeSignature                                 191
#define kNtErrorExeMarkedInvalid                                    192 /* EBADEXEC */
#define kNtErrorBadExeFormat                                        193 /* ENOEXEC */
#define kNtErrorIteratedDataExceeds_64k                             194
#define kNtErrorInvalidMinallocsize                                 195
#define kNtErrorDynlinkFromInvalidRing                              196
#define kNtErrorIoplNotEnabled                                      197
#define kNtErrorInvalidSegdpl                                       198
#define kNtErrorAutodatasegExceeds_64k                              199
#define kNtErrorRing2segMustBeMovable                               200
#define kNtErrorRelocChainXeedsSeglim                               201
#define kNtErrorInfloopInRelocChain                                 202
#define kNtErrorEnvvarNotFound                                      203
#define kNtErrorNoSignalSent                                        205
#define kNtErrorFilenameExcedRange                                  206 /* ENAMETOOLONG */
#define kNtErrorRing2StackInUse                                     207
#define kNtErrorMetaExpansionTooLong                                208
#define kNtErrorInvalidSignalNumber                                 209
#define kNtErrorThread_1Inactive                                    210
#define kNtErrorLocked                                              212
#define kNtErrorTooManyModules                                      214
#define kNtErrorNestingNotAllowed                                   215
#define kNtErrorExeMachineTypeMismatch                              216 /* EBADARCH */
#define kNtErrorExeCannotModifySignedBinary                         217
#define kNtErrorExeCannotModifyStrongSignedBinary                   218
#define kNtErrorFileCheckedOut                                      220
#define kNtErrorCheckoutRequired                                    221
#define kNtErrorBadFileType                                         222 /* EFTYPE */
#define kNtErrorFileTooLarge                                        223 /* EFBIG */
#define kNtErrorFormsAuthRequired                                   224 /* ENEEDAUTH */
#define kNtErrorVirusInfected                                       225
#define kNtErrorVirusDeleted                                        226
#define kNtErrorPipeLocal                                           229
#define kNtErrorBadPipe                                             230
#define kNtErrorPipeBusy                                            231
#define kNtErrorNoData                                              232
#define kNtErrorPipeNotConnected                                    233
#define kNtErrorMoreData                                            234
#define kNtErrorNoWorkDone                                          235
#define kNtErrorVcDisconnected                                      240
#define kNtErrorInvalidEaName                                       254
#define kNtErrorEaListInconsistent                                  255
#define kNtErrorNoMoreItems                                         259
#define kNtErrorCannotCopy                                          266
#define kNtErrorDirectory                                           267 /* EISDIR */
#define kNtErrorEasDidntFit                                         275
#define kNtErrorEaFileCorrupt                                       276
#define kNtErrorEaTableFull                                         277
#define kNtErrorInvalidEaHandle                                     278
#define kNtErrorEasNotSupported                                     282
#define kNtErrorNotOwner                                            288
#define kNtErrorTooManyPosts                                        298
#define kNtErrorPartialCopy                                         299
#define kNtErrorOplockNotGranted                                    300
#define kNtErrorInvalidOplockProtocol                               301
#define kNtErrorDiskTooFragmented                                   302
#define kNtErrorDeletePending                                       303
#define kNtErrorIncompatibleWithGlobalShortNameRegistrySetting      304
#define kNtErrorShortNamesNotEnabledOnVolume                        305
#define kNtErrorSecurityStreamIsInconsistent                        306
#define kNtErrorInvalidLockRange                                    307
#define kNtErrorImageSubsystemNotPresent                            308
#define kNtErrorNotificationGuidAlreadyDefined                      309
#define kNtErrorInvalidExceptionHandler                             310
#define kNtErrorDuplicatePrivileges                                 311
#define kNtErrorNoRangesProcessed                                   312
#define kNtErrorNotAllowedOnSystemFile                              313
#define kNtErrorDiskResourcesExhausted                              314
#define kNtErrorInvalidToken                                        315
#define kNtErrorDeviceFeatureNotSupported                           316
#define kNtErrorMrMidNotFound                                       317
#define kNtErrorScopeNotFound                                       318
#define kNtErrorUndefinedScope                                      319
#define kNtErrorInvalidCap                                          320
#define kNtErrorDeviceUnreachable                                   321
#define kNtErrorDeviceNoResources                                   322
#define kNtErrorDataChecksumError                                   323
#define kNtErrorIntermixedKernelEaOperation                         324
#define kNtErrorFileLevelTrimNotSupported                           326
#define kNtErrorOffsetAlignmentViolation                            327
#define kNtErrorInvalidFieldInParameterList                         328
#define kNtErrorOperationInProgress                                 329 /* EPROGUNAVAIL */
#define kNtErrorBadDevicePath                                       330
#define kNtErrorTooManyDescriptors                                  331 /* ENFILE */
#define kNtErrorScrubDataDisabled                                   332
#define kNtErrorNotRedundantStorage                                 333
#define kNtErrorResidentFileNotSupported                            334
#define kNtErrorCompressedFileNotSupported                          335
#define kNtErrorDirectoryNotSupported                               336
#define kNtErrorNotReadFromCopy                                     337
#define kNtErrorFtWriteFailure                                      338
#define kNtErrorFtDiScanRequired                                    339
#define kNtErrorInvalidKernelInfoVersion                            340
#define kNtErrorInvalidPepInfoVersion                               341
#define kNtErrorObjectNotExternallyBacked                           342
#define kNtErrorExternalBackingProviderUnknown                      343
#define kNtErrorCompressionNotBeneficial                            344
#define kNtErrorStorageTopologyIdMismatch                           345
#define kNtErrorBlockedByParentalControls                           346
#define kNtErrorBlockTooManyReferences                              347
#define kNtErrorMarkedToDisallowWrites                              348
#define kNtErrorEnclaveFailure                                      349
#define kNtErrorFailNoactionReboot                                  350
#define kNtErrorFailShutdown                                        351
#define kNtErrorFailRestart                                         352
#define kNtErrorMaxSessionsReached                                  353
#define kNtErrorNetworkAccessDeniedEdp                              354
#define kNtErrorDeviceHintNameBufferTooSmall                        355
#define kNtErrorEdpPolicyDeniesOperation                            356
#define kNtErrorEdpDplPolicyCantBeSatisfied                         357
#define kNtErrorCloudFileSyncRootMetadataCorrupt                    358
#define kNtErrorDeviceInMaintenance                                 359
#define kNtErrorNotSupportedOnDax                                   360
#define kNtErrorDaxMappingExists                                    361
#define kNtErrorCloudFileProviderNotRunning                         362
#define kNtErrorCloudFileMetadataCorrupt                            363
#define kNtErrorCloudFileMetadataTooLarge                           364
#define kNtErrorCloudFilePropertyBlobTooLarge                       365
#define kNtErrorCloudFilePropertyBlobChecksumMismatch               366
#define kNtErrorChildProcessBlocked                                 367
#define kNtErrorStorageLostDataPersistence                          368
#define kNtErrorFileSystemVirtualizationUnavailable                 369
#define kNtErrorFileSystemVirtualizationMetadataCorrupt             370
#define kNtErrorFileSystemVirtualizationBusy                        371
#define kNtErrorFileSystemVirtualizationProviderUnknown             372
#define kNtErrorGdiHandleLeak                                       373
#define kNtErrorCloudFileTooManyPropertyBlobs                       374
#define kNtErrorCloudFilePropertyVersionNotSupported                375
#define kNtErrorNotACloudFile                                       376
#define kNtErrorCloudFileNotInSync                                  377
#define kNtErrorCloudFileAlreadyConnected                           378
#define kNtErrorCloudFileNotSupported                               379
#define kNtErrorCloudFileInvalidRequest                             380
#define kNtErrorCloudFileReadOnlyVolume                             381
#define kNtErrorCloudFileConnectedProviderOnly                      382
#define kNtErrorCloudFileValidationFailed                           383
#define kNtErrorSmb1NotAvailable                                    384
#define kNtErrorFileSystemVirtualizationInvalidOperation            385
#define kNtErrorCloudFileAuthenticationFailed                       386
#define kNtErrorCloudFileInsufficientResources                      387
#define kNtErrorCloudFileNetworkUnavailable                         388
#define kNtErrorCloudFileUnsuccessful                               389
#define kNtErrorCloudFileNotUnderSyncRoot                           390
#define kNtErrorCloudFileInUse                                      391
#define kNtErrorCloudFilePinned                                     392
#define kNtErrorCloudFileRequestAborted                             393
#define kNtErrorCloudFilePropertyCorrupt                            394
#define kNtErrorCloudFileAccessDenied                               395
#define kNtErrorCloudFileIncompatibleHardlinks                      396
#define kNtErrorCloudFilePropertyLockConflict                       397
#define kNtErrorCloudFileRequestCanceled                            398
#define kNtErrorExternalSyskeyNotSupported                          399
#define kNtErrorThreadModeAlreadyBackground                         400
#define kNtErrorThreadModeNotBackground                             401
#define kNtErrorProcessModeAlreadyBackground                        402
#define kNtErrorProcessModeNotBackground                            403
#define kNtErrorCloudFileProviderTerminated                         404
#define kNtErrorNotACloudSyncRoot                                   405
#define kNtErrorFileProtectedUnderDpl                               406
#define kNtErrorVolumeNotClusterAligned                             407
#define kNtErrorNoPhysicallyAlignedFreeSpaceFound                   408
#define kNtErrorAppxFileNotEncrypted                                409
#define kNtErrorRwrawEncryptedFileNotEncrypted                      410
#define kNtErrorRwrawEncryptedInvalidEdatainfoFileoffset            411
#define kNtErrorRwrawEncryptedInvalidEdatainfoFilerange             412
#define kNtErrorRwrawEncryptedInvalidEdatainfoParameter             413
#define kNtErrorLinuxSubsystemNotPresent                            414
#define kNtErrorCapauthzNotDevunlocked                              450
#define kNtErrorCapauthzChangeType                                  451
#define kNtErrorCapauthzNotProvisioned                              452
#define kNtErrorCapauthzNotAuthorized                               453
#define kNtErrorCapauthzNoPolicy                                    454
#define kNtErrorCapauthzDbCorrupted                                 455
#define kNtErrorCapauthzSccdInvalidCatalog                          456
#define kNtErrorCapauthzSccdNoAuthEntity                            457
#define kNtErrorCapauthzSccdParseError                              458
#define kNtErrorCapauthzSccdDevModeRequired                         459
#define kNtErrorCapauthzSccdNoCapabilityMatch                       460
#define kNtErrorPnpQueryRemoveDeviceTimeout                         480
#define kNtErrorPnpQueryRemoveRelatedDeviceTimeout                  481
#define kNtErrorPnpQueryRemoveUnrelatedDeviceTimeout                482
#define kNtErrorDeviceHardwareError                                 483 /* EDEVERR */
#define kNtErrorInvalidAddress                                      487 /* EFAULT */
#define kNtErrorVrfCfgEnabled                                       1183
#define kNtErrorPartitionTerminating                                1184
#define kNtErrorUserProfileLoad                                     500
#define kNtErrorArithmeticOverflow                                  534 /* EOVERFLOW */
#define kNtErrorPipeConnected                                       535
#define kNtErrorPipeListening                                       536
#define kNtErrorVerifierStop                                        537
#define kNtErrorAbiosError                                          538
#define kNtErrorWx86Warning                                         539
#define kNtErrorWx86Error                                           540
#define kNtErrorTimerNotCanceled                                    541
#define kNtErrorUnwind                                              542
#define kNtErrorBadStack                                            543
#define kNtErrorInvalidUnwindTarget                                 544
#define kNtErrorInvalidPortAttributes                               545
#define kNtErrorPortMessageTooLong                                  546
#define kNtErrorInvalidQuotaLower                                   547
#define kNtErrorDeviceAlreadyAttached                               548
#define kNtErrorInstructionMisalignment                             549
#define kNtErrorProfilingNotStarted                                 550
#define kNtErrorProfilingNotStopped                                 551
#define kNtErrorCouldNotInterpret                                   552
#define kNtErrorProfilingAtLimit                                    553
#define kNtErrorCantWait                                            554
#define kNtErrorCantTerminateSelf                                   555
#define kNtErrorUnexpectedMmCreateErr                               556
#define kNtErrorUnexpectedMmMapError                                557
#define kNtErrorUnexpectedMmExtendErr                               558
#define kNtErrorBadFunctionTable                                    559
#define kNtErrorNoGuidTranslation                                   560
#define kNtErrorInvalidLdtSize                                      561
#define kNtErrorInvalidLdtOffset                                    563
#define kNtErrorInvalidLdtDescriptor                                564
#define kNtErrorTooManyThreads                                      565
#define kNtErrorThreadNotInProcess                                  566 /* ESRCH */
#define kNtErrorPagefileQuotaExceeded                               567
#define kNtErrorLogonServerConflict                                 568
#define kNtErrorSynchronizationRequired                             569
#define kNtErrorNetOpenFailed                                       570
#define kNtErrorIoPrivilegeFailed                                   571
#define kNtErrorControlCExit                                        572
#define kNtErrorMissingSystemfile                                   573
#define kNtErrorUnhandledException                                  574
#define kNtErrorAppInitFailure                                      575
#define kNtErrorPagefileCreateFailed                                576
#define kNtErrorInvalidImageHash                                    577
#define kNtErrorNoPagefile                                          578
#define kNtErrorIllegalFloatContext                                 579
#define kNtErrorNoEventPair                                         580
#define kNtErrorDomainCtrlrConfigError                              581
#define kNtErrorIllegalCharacter                                    582 /* EILSEQ */
#define kNtErrorUndefinedCharacter                                  583
#define kNtErrorFloppyVolume                                        584
#define kNtErrorBiosFailedToConnectInterrupt                        585
#define kNtErrorBackupController                                    586
#define kNtErrorMutantLimitExceeded                                 587
#define kNtErrorFsDriverRequired                                    588
#define kNtErrorCannotLoadRegistryFile                              589
#define kNtErrorDebugAttachFailed                                   590
#define kNtErrorSystemProcessTerminated                             591
#define kNtErrorDataNotAccepted                                     592
#define kNtErrorVdmHardError                                        593
#define kNtErrorDriverCancelTimeout                                 594
#define kNtErrorReplyMessageMismatch                                595 /* EPROGMISMATCH */
#define kNtErrorLostWritebehindData                                 596
#define kNtErrorClientServerParametersInvalid                       597
#define kNtErrorNotTinyStream                                       598
#define kNtErrorStackOverflowRead                                   599
#define kNtErrorConvertToLarge                                      600
#define kNtErrorFoundOutOfScope                                     601
#define kNtErrorAllocateBucket                                      602
#define kNtErrorMarshallOverflow                                    603
#define kNtErrorInvalidVariant                                      604
#define kNtErrorBadCompressionBuffer                                605
#define kNtErrorAuditFailed                                         606
#define kNtErrorTimerResolutionNotSet                               607
#define kNtErrorInsufficientLogonInfo                               608
#define kNtErrorBadDllEntrypoint                                    609
#define kNtErrorBadServiceEntrypoint                                610
#define kNtErrorIpAddressConflict1                                  611
#define kNtErrorIpAddressConflict2                                  612
#define kNtErrorRegistryQuotaLimit                                  613
#define kNtErrorNoCallbackActive                                    614
#define kNtErrorPwdTooShort                                         615
#define kNtErrorPwdTooRecent                                        616
#define kNtErrorPwdHistoryConflict                                  617
#define kNtErrorUnsupportedCompression                              618
#define kNtErrorInvalidHwProfile                                    619
#define kNtErrorInvalidPlugplayDevicePath                           620
#define kNtErrorQuotaListInconsistent                               621
#define kNtErrorEvaluationExpiration                                622
#define kNtErrorIllegalDllRelocation                                623
#define kNtErrorDllInitFailedLogoff                                 624
#define kNtErrorValidateContinue                                    625
#define kNtErrorNoMoreMatches                                       626
#define kNtErrorRangeListConflict                                   627
#define kNtErrorServerSidMismatch                                   628
#define kNtErrorCantEnableDenyOnly                                  629
#define kNtErrorFloatMultipleFaults                                 630
#define kNtErrorFloatMultipleTraps                                  631
#define kNtErrorNointerface                                         632
#define kNtErrorDriverFailedSleep                                   633
#define kNtErrorCorruptSystemFile                                   634
#define kNtErrorCommitmentMinimum                                   635
#define kNtErrorPnpRestartEnumeration                               636
#define kNtErrorSystemImageBadSignature                             637
#define kNtErrorPnpRebootRequired                                   638
#define kNtErrorInsufficientPower                                   639 /* EPWROFF */
#define kNtErrorMultipleFaultViolation                              640
#define kNtErrorSystemShutdown                                      641
#define kNtErrorPortNotSet                                          642
#define kNtErrorDsVersionCheckFailure                               643
#define kNtErrorRangeNotFound                                       644
#define kNtErrorNotSafeModeDriver                                   646
#define kNtErrorFailedDriverEntry                                   647
#define kNtErrorDeviceEnumerationError                              648
#define kNtErrorMountPointNotResolved                               649
#define kNtErrorInvalidDeviceObjectParameter                        650
#define kNtErrorMcaOccured                                          651
#define kNtErrorDriverDatabaseError                                 652
#define kNtErrorSystemHiveTooLarge                                  653
#define kNtErrorDriverFailedPriorUnload                             654
#define kNtErrorVolsnapPrepareHibernate                             655
#define kNtErrorHibernationFailure                                  656
#define kNtErrorPwdTooLong                                          657
#define kNtErrorFileSystemLimitation                                665
#define kNtErrorAssertionFailure                                    668
#define kNtErrorAcpiError                                           669
#define kNtErrorWowAssertion                                        670
#define kNtErrorPnpBadMpsTable                                      671
#define kNtErrorPnpTranslationFailed                                672
#define kNtErrorPnpIrqTranslationFailed                             673
#define kNtErrorPnpInvalidId                                        674
#define kNtErrorWakeSystemDebugger                                  675
#define kNtErrorHandlesClosed                                       676
#define kNtErrorExtraneousInformation                               677
#define kNtErrorRxactCommitNecessary                                678
#define kNtErrorMediaCheck                                          679
#define kNtErrorGuidSubstitutionMade                                680
#define kNtErrorStoppedOnSymlink                                    681
#define kNtErrorLongjump                                            682
#define kNtErrorPlugplayQueryVetoed                                 683
#define kNtErrorUnwindConsolidate                                   684
#define kNtErrorRegistryHiveRecovered                               685
#define kNtErrorDllMightBeInsecure                                  686
#define kNtErrorDllMightBeIncompatible                              687
#define kNtErrorDbgExceptionNotHandled                              688
#define kNtErrorDbgReplyLater                                       689
#define kNtErrorDbgUnableToProvideHandle                            690
#define kNtErrorDbgTerminateThread                                  691
#define kNtErrorDbgTerminateProcess                                 692
#define kNtErrorDbgControlC                                         693
#define kNtErrorDbgPrintexceptionC                                  694
#define kNtErrorDbgRipexception                                     695
#define kNtErrorDbgControlBreak                                     696
#define kNtErrorDbgCommandException                                 697
#define kNtErrorObjectNameExists                                    698
#define kNtErrorThreadWasSuspended                                  699
#define kNtErrorImageNotAtBase                                      700
#define kNtErrorRxactStateCreated                                   701
#define kNtErrorSegmentNotification                                 702
#define kNtErrorBadCurrentDirectory                                 703
#define kNtErrorFtReadRecoveryFromBackup                            704
#define kNtErrorFtWriteRecovery                                     705
#define kNtErrorImageMachineTypeMismatch                            706
#define kNtErrorReceivePartial                                      707
#define kNtErrorReceiveExpedited                                    708
#define kNtErrorReceivePartialExpedited                             709
#define kNtErrorEventDone                                           710
#define kNtErrorEventPending                                        711
#define kNtErrorCheckingFileSystem                                  712
#define kNtErrorFatalAppExit                                        713
#define kNtErrorPredefinedHandle                                    714
#define kNtErrorWasUnlocked                                         715
#define kNtErrorServiceNotification                                 716
#define kNtErrorWasLocked                                           717
#define kNtErrorLogHardError                                        718
#define kNtErrorAlreadyWin32                                        719
#define kNtErrorImageMachineTypeMismatchExe                         720
#define kNtErrorNoYieldPerformed                                    721
#define kNtErrorTimerResumeIgnored                                  722
#define kNtErrorArbitrationUnhandled                                723
#define kNtErrorCardbusNotSupported                                 724
#define kNtErrorMpProcessorMismatch                                 725
#define kNtErrorHibernated                                          726
#define kNtErrorResumeHibernation                                   727
#define kNtErrorFirmwareUpdated                                     728
#define kNtErrorDriversLeakingLockedPages                           729
#define kNtErrorWakeSystem                                          730
#define kNtErrorWait_1                                              731
#define kNtErrorWait_2                                              732
#define kNtErrorWait_3                                              733
#define kNtErrorWait_63                                             734
#define kNtErrorAbandonedWait_0                                     735
#define kNtErrorAbandonedWait_63                                    736
#define kNtErrorUserApc                                             737
#define kNtErrorKernelApc                                           738
#define kNtErrorAlerted                                             739
#define kNtErrorElevationRequired                                   740
#define kNtErrorReparse                                             741
#define kNtErrorOplockBreakInProgress                               742
#define kNtErrorVolumeMounted                                       743
#define kNtErrorRxactCommitted                                      744
#define kNtErrorNotifyCleanup                                       745
#define kNtErrorPrimaryTransportConnectFailed                       746
#define kNtErrorPageFaultTransition                                 747
#define kNtErrorPageFaultDemandZero                                 748
#define kNtErrorPageFaultCopyOnWrite                                749
#define kNtErrorPageFaultGuardPage                                  750
#define kNtErrorPageFaultPagingFile                                 751
#define kNtErrorCachePageLocked                                     752
#define kNtErrorCrashDump                                           753
#define kNtErrorBufferAllZeros                                      754
#define kNtErrorReparseObject                                       755
#define kNtErrorResourceRequirementsChanged                         756
#define kNtErrorTranslationComplete                                 757
#define kNtErrorNothingToTerminate                                  758
#define kNtErrorProcessNotInJob                                     759
#define kNtErrorProcessInJob                                        760
#define kNtErrorVolsnapHibernateReady                               761
#define kNtErrorFsfilterOpCompletedSuccessfully                     762
#define kNtErrorInterruptVectorAlreadyConnected                     763
#define kNtErrorInterruptStillConnected                             764
#define kNtErrorWaitForOplock                                       765
#define kNtErrorDbgExceptionHandled                                 766
#define kNtErrorDbgContinue                                         767
#define kNtErrorCallbackPopStack                                    768
#define kNtErrorCompressionDisabled                                 769
#define kNtErrorCantfetchbackwards                                  770
#define kNtErrorCantscrollbackwards                                 771
#define kNtErrorRowsnotreleased                                     772
#define kNtErrorBadAccessorFlags                                    773
#define kNtErrorErrorsEncountered                                   774
#define kNtErrorNotCapable                                          775
#define kNtErrorRequestOutOfSequence                                776
#define kNtErrorVersionParseError                                   777
#define kNtErrorBadstartposition                                    778
#define kNtErrorMemoryHardware                                      779
#define kNtErrorDiskRepairDisabled                                  780
#define kNtErrorInsufficientResourceForSpecifiedSharedSectionSize   781
#define kNtErrorSystemPowerstateTransition                          782
#define kNtErrorSystemPowerstateComplexTransition                   783
#define kNtErrorMcaException                                        784
#define kNtErrorAccessAuditByPolicy                                 785
#define kNtErrorAccessDisabledNoSaferUiByPolicy                     786
#define kNtErrorAbandonHiberfile                                    787
#define kNtErrorLostWritebehindDataNetworkDisconnected              788
#define kNtErrorLostWritebehindDataNetworkServerError               789
#define kNtErrorLostWritebehindDataLocalDiskError                   790
#define kNtErrorBadMcfgTable                                        791
#define kNtErrorDiskRepairRedirected                                792
#define kNtErrorDiskRepairUnsuccessful                              793
#define kNtErrorCorruptLogOverfull                                  794
#define kNtErrorCorruptLogCorrupted                                 795
#define kNtErrorCorruptLogUnavailable                               796
#define kNtErrorCorruptLogDeletedFull                               797
#define kNtErrorCorruptLogCleared                                   798
#define kNtErrorOrphanNameExhausted                                 799
#define kNtErrorOplockSwitchedToNewHandle                           800
#define kNtErrorCannotGrantRequestedOplock                          801
#define kNtErrorCannotBreakOplock                                   802
#define kNtErrorOplockHandleClosed                                  803
#define kNtErrorNoAceCondition                                      804
#define kNtErrorInvalidAceCondition                                 805
#define kNtErrorFileHandleRevoked                                   806
#define kNtErrorImageAtDifferentBase                                807
#define kNtErrorEncryptedIoNotPossible                              808
#define kNtErrorFileMetadataOptimizationInProgress                  809
#define kNtErrorQuotaActivity                                       810
#define kNtErrorHandleRevoked                                       811
#define kNtErrorCallbackInvokeInline                                812
#define kNtErrorCpuSetInvalid                                       813
#define kNtErrorEnclaveNotTerminated                                814
#define kNtErrorEnclaveViolation                                    815
#define kNtErrorEaAccessDenied                                      994
#define kNtErrorOperationAborted                                    995
#define kNtErrorIoIncomplete                                        996
#define kNtErrorIoPending                                           997
#define kNtErrorNoaccess                                            998
#define kNtErrorSwaperror                                           999
#define kNtErrorStackOverflow                                       1001
#define kNtErrorInvalidMessage                                      1002
#define kNtErrorCanNotComplete                                      1003
#define kNtErrorInvalidFlags                                        1004
#define kNtErrorUnrecognizedVolume                                  1005
#define kNtErrorFileInvalid                                         1006
#define kNtErrorFullscreenMode                                      1007
#define kNtErrorNoToken                                             1008
#define kNtErrorBaddb                                               1009
#define kNtErrorBadkey                                              1010
#define kNtErrorCantopen                                            1011
#define kNtErrorCantread                                            1012
#define kNtErrorCantwrite                                           1013
#define kNtErrorRegistryRecovered                                   1014
#define kNtErrorRegistryCorrupt                                     1015
#define kNtErrorRegistryIoFailed                                    1016
#define kNtErrorNotRegistryFile                                     1017
#define kNtErrorKeyDeleted                                          1018
#define kNtErrorNoLogSpace                                          1019
#define kNtErrorKeyHasChildren                                      1020
#define kNtErrorChildMustBeVolatile                                 1021
#define kNtErrorNotifyEnumDir                                       1022
#define kNtErrorDependentServicesRunning                            1051
#define kNtErrorInvalidServiceControl                               1052
#define kNtErrorServiceRequestTimeout                               1053
#define kNtErrorServiceNoThread                                     1054
#define kNtErrorServiceDatabaseLocked                               1055
#define kNtErrorServiceAlreadyRunning                               1056
#define kNtErrorInvalidServiceAccount                               1057
#define kNtErrorServiceDisabled                                     1058
#define kNtErrorCircularDependency                                  1059
#define kNtErrorServiceDoesNotExist                                 1060
#define kNtErrorServiceCannotAcceptCtrl                             1061
#define kNtErrorServiceNotActive                                    1062
#define kNtErrorFailedServiceControllerConnect                      1063
#define kNtErrorExceptionInService                                  1064
#define kNtErrorDatabaseDoesNotExist                                1065
#define kNtErrorServiceSpecificError                                1066
#define kNtErrorProcessAborted                                      1067
#define kNtErrorServiceDependencyFail                               1068
#define kNtErrorServiceLogonFailed                                  1069
#define kNtErrorServiceStartHang                                    1070
#define kNtErrorInvalidServiceLock                                  1071
#define kNtErrorServiceMarkedForDelete                              1072
#define kNtErrorServiceExists                                       1073
#define kNtErrorAlreadyRunningLkg                                   1074
#define kNtErrorServiceDependencyDeleted                            1075
#define kNtErrorBootAlreadyAccepted                                 1076
#define kNtErrorServiceNeverStarted                                 1077
#define kNtErrorDuplicateServiceName                                1078
#define kNtErrorDifferentServiceAccount                             1079
#define kNtErrorCannotDetectDriverFailure                           1080
#define kNtErrorCannotDetectProcessAbort                            1081
#define kNtErrorNoRecoveryProgram                                   1082
#define kNtErrorServiceNotInExe                                     1083
#define kNtErrorNotSafebootService                                  1084
#define kNtErrorEndOfMedia                                          1100
#define kNtErrorFilemarkDetected                                    1101
#define kNtErrorBeginningOfMedia                                    1102
#define kNtErrorSetmarkDetected                                     1103
#define kNtErrorNoDataDetected                                      1104
#define kNtErrorPartitionFailure                                    1105
#define kNtErrorInvalidBlockLength                                  1106
#define kNtErrorDeviceNotPartitioned                                1107
#define kNtErrorUnableToLockMedia                                   1108
#define kNtErrorUnableToUnloadMedia                                 1109
#define kNtErrorMediaChanged                                        1110
#define kNtErrorBusReset                                            1111
#define kNtErrorNoMediaInDrive                                      1112 /* ENXIO */
#define kNtErrorNoUnicodeTranslation                                1113
#define kNtErrorDllInitFailed                                       1114
#define kNtErrorShutdownInProgress                                  1115
#define kNtErrorNoShutdownInProgress                                1116
#define kNtErrorIoDevice                                            1117 /* EIO */
#define kNtErrorSerialNoDevice                                      1118 /* ENOTTY */
#define kNtErrorIrqBusy                                             1119
#define kNtErrorMoreWrites                                          1120
#define kNtErrorCounterTimeout                                      1121
#define kNtErrorFloppyIdMarkNotFound                                1122
#define kNtErrorFloppyWrongCylinder                                 1123
#define kNtErrorFloppyUnknownError                                  1124
#define kNtErrorFloppyBadRegisters                                  1125
#define kNtErrorDiskRecalibrateFailed                               1126
#define kNtErrorDiskOperationFailed                                 1127
#define kNtErrorDiskResetFailed                                     1128
#define kNtErrorEomOverflow                                         1129
#define kNtErrorNotEnoughServerMemory                               1130
#define kNtErrorPossibleDeadlock                                    1131 /* EDEADLK */
#define kNtErrorMappedAlignment                                     1132
#define kNtErrorSetPowerStateVetoed                                 1140
#define kNtErrorSetPowerStateFailed                                 1141
#define kNtErrorTooManyLinks                                        1142
#define kNtErrorOldWinVersion                                       1150
#define kNtErrorAppWrongOs                                          1151
#define kNtErrorSingleInstanceApp                                   1152
#define kNtErrorRmodeApp                                            1153
#define kNtErrorInvalidDll                                          1154
#define kNtErrorNoAssociation                                       1155
#define kNtErrorDdeFail                                             1156
#define kNtErrorDllNotFound                                         1157
#define kNtErrorNoMoreUserHandles                                   1158
#define kNtErrorMessageSyncOnly                                     1159
#define kNtErrorSourceElementEmpty                                  1160
#define kNtErrorDestinationElementFull                              1161
#define kNtErrorIllegalElementAddress                               1162
#define kNtErrorMagazineNotPresent                                  1163
#define kNtErrorDeviceReinitializationNeeded                        1164
#define kNtErrorDeviceRequiresCleaning                              1165
#define kNtErrorDeviceDoorOpen                                      1166
#define kNtErrorDeviceNotConnected                                  1167
#define kNtErrorNotFound                                            1168
#define kNtErrorNoMatch                                             1169
#define kNtErrorSetNotFound                                         1170
#define kNtErrorPointNotFound                                       1171
#define kNtErrorNoTrackingService                                   1172
#define kNtErrorNoVolumeId                                          1173
#define kNtErrorUnableToRemoveReplaced                              1175
#define kNtErrorUnableToMoveReplacement                             1176
#define kNtErrorUnableToMoveReplacement_2                           1177
#define kNtErrorJournalDeleteInProgress                             1178
#define kNtErrorJournalNotActive                                    1179
#define kNtErrorPotentialFileFound                                  1180
#define kNtErrorJournalEntryDeleted                                 1181
#define kNtErrorShutdownIsScheduled                                 1190
#define kNtErrorShutdownUsersLoggedOn                               1191
#define kNtErrorBadDevice                                           1200 /* ENODEV */
#define kNtErrorConnectionUnavail                                   1201
#define kNtErrorDeviceAlreadyRemembered                             1202
#define kNtErrorNoNetOrBadPath                                      1203
#define kNtErrorBadProvider                                         1204
#define kNtErrorCannotOpenProfile                                   1205
#define kNtErrorBadProfile                                          1206
#define kNtErrorNotContainer                                        1207
#define kNtErrorExtendedError                                       1208
#define kNtErrorInvalidGroupname                                    1209
#define kNtErrorInvalidComputername                                 1210
#define kNtErrorInvalidEventname                                    1211
#define kNtErrorInvalidDomainname                                   1212
#define kNtErrorInvalidServicename                                  1213
#define kNtErrorInvalidNetname                                      1214
#define kNtErrorInvalidSharename                                    1215
#define kNtErrorInvalidPasswordname                                 1216
#define kNtErrorInvalidMessagename                                  1217
#define kNtErrorInvalidMessagedest                                  1218
#define kNtErrorSessionCredentialConflict                           1219
#define kNtErrorRemoteSessionLimitExceeded                          1220
#define kNtErrorDupDomainname                                       1221
#define kNtErrorNoNetwork                                           1222
#define kNtErrorCancelled                                           1223 /* ECANCELED */
#define kNtErrorUserMappedFile                                      1224
#define kNtErrorConnectionRefused                                   1225
#define kNtErrorGracefulDisconnect                                  1226
#define kNtErrorAddressAlreadyAssociated                            1227
#define kNtErrorAddressNotAssociated                                1228
#define kNtErrorConnectionInvalid                                   1229
#define kNtErrorConnectionActive                                    1230
#define kNtErrorNetworkUnreachable                                  1231
#define kNtErrorHostUnreachable                                     1232
#define kNtErrorProtocolUnreachable                                 1233 /* multimapped to ENETUNREACH */
#define kNtErrorPortUnreachable                                     1234
#define kNtErrorRequestAborted                                      1235
#define kNtErrorConnectionAborted                                   1236
#define kNtErrorRetry                                               1237
#define kNtErrorConnectionCountLimit                                1238
#define kNtErrorLoginTimeRestriction                                1239
#define kNtErrorLoginWkstaRestriction                               1240
#define kNtErrorIncorrectAddress                                    1241
#define kNtErrorAlreadyRegistered                                   1242
#define kNtErrorServiceNotFound                                     1243
#define kNtErrorNotAuthenticated                                    1244 /* EAUTH */
#define kNtErrorNotLoggedOn                                         1245
#define kNtErrorContinue                                            1246
#define kNtErrorAlreadyInitialized                                  1247
#define kNtErrorNoMoreDevices                                       1248
#define kNtErrorNoSuchSite                                          1249
#define kNtErrorDomainControllerExists                              1250
#define kNtErrorOnlyIfConnected                                     1251
#define kNtErrorOverrideNochanges                                   1252
#define kNtErrorBadUserProfile                                      1253
#define kNtErrorNotSupportedOnSbs                                   1254
#define kNtErrorServerShutdownInProgress                            1255
#define kNtErrorHostDown                                            1256
#define kNtErrorNonAccountSid                                       1257
#define kNtErrorNonDomainSid                                        1258
#define kNtErrorApphelpBlock                                        1259
#define kNtErrorAccessDisabledByPolicy                              1260
#define kNtErrorRegNatConsumption                                   1261
#define kNtErrorCscshareOffline                                     1262
#define kNtErrorPkinitFailure                                       1263
#define kNtErrorSmartcardSubsystemFailure                           1264
#define kNtErrorDowngradeDetected                                   1265
#define kNtErrorMachineLocked                                       1271
#define kNtErrorSmbGuestLogonBlocked                                1272
#define kNtErrorCallbackSuppliedInvalidData                         1273
#define kNtErrorSyncForegroundRefreshRequired                       1274
#define kNtErrorDriverBlocked                                       1275
#define kNtErrorInvalidImportOfNonDll                               1276
#define kNtErrorAccessDisabledWebblade                              1277
#define kNtErrorAccessDisabledWebbladeTamper                        1278
#define kNtErrorRecoveryFailure                                     1279
#define kNtErrorAlreadyFiber                                        1280
#define kNtErrorAlreadyThread                                       1281
#define kNtErrorStackBufferOverrun                                  1282
#define kNtErrorParameterQuotaExceeded                              1283
#define kNtErrorDebuggerInactive                                    1284
#define kNtErrorDelayLoadFailed                                     1285
#define kNtErrorVdmDisallowed                                       1286
#define kNtErrorUnidentifiedError                                   1287 /* EIDRM */
#define kNtErrorInvalidCruntimeParameter                            1288
#define kNtErrorBeyondVdl                                           1289
#define kNtErrorIncompatibleServiceSidType                          1290
#define kNtErrorDriverProcessTerminated                             1291
#define kNtErrorImplementationLimit                                 1292
#define kNtErrorProcessIsProtected                                  1293
#define kNtErrorServiceNotifyClientLagging                          1294
#define kNtErrorDiskQuotaExceeded                                   1295
#define kNtErrorContentBlocked                                      1296
#define kNtErrorIncompatibleServicePrivilege                        1297
#define kNtErrorAppHang                                             1298
#define kNtErrorInvalidLabel                                        1299
#define kNtErrorNotAllAssigned                                      1300
#define kNtErrorSomeNotMapped                                       1301
#define kNtErrorNoQuotasForAccount                                  1302
#define kNtErrorLocalUserSessionKey                                 1303
#define kNtErrorNullLmPassword                                      1304
#define kNtErrorUnknownRevision                                     1305
#define kNtErrorRevisionMismatch                                    1306
#define kNtErrorInvalidOwner                                        1307
#define kNtErrorInvalidPrimaryGroup                                 1308
#define kNtErrorNoImpersonationToken                                1309
#define kNtErrorCantDisableMandatory                                1310
#define kNtErrorNoLogonServers                                      1311
#define kNtErrorNoSuchLogonSession                                  1312
#define kNtErrorNoSuchPrivilege                                     1313
#define kNtErrorPrivilegeNotHeld                                    1314
#define kNtErrorInvalidAccountName                                  1315
#define kNtErrorUserExists                                          1316
#define kNtErrorNoSuchUser                                          1317
#define kNtErrorGroupExists                                         1318
#define kNtErrorNoSuchGroup                                         1319
#define kNtErrorMemberInGroup                                       1320
#define kNtErrorMemberNotInGroup                                    1321
#define kNtErrorLastAdmin                                           1322
#define kNtErrorWrongPassword                                       1323
#define kNtErrorIllFormedPassword                                   1324
#define kNtErrorPasswordRestriction                                 1325
#define kNtErrorLogonFailure                                        1326
#define kNtErrorAccountRestriction                                  1327
#define kNtErrorInvalidLogonHours                                   1328
#define kNtErrorInvalidWorkstation                                  1329
#define kNtErrorPasswordExpired                                     1330
#define kNtErrorAccountDisabled                                     1331
#define kNtErrorNoneMapped                                          1332
#define kNtErrorTooManyLuidsRequested                               1333
#define kNtErrorLuidsExhausted                                      1334
#define kNtErrorInvalidSubAuthority                                 1335
#define kNtErrorInvalidAcl                                          1336
#define kNtErrorInvalidSid                                          1337
#define kNtErrorInvalidSecurityDescr                                1338
#define kNtErrorBadInheritanceAcl                                   1340
#define kNtErrorServerDisabled                                      1341
#define kNtErrorServerNotDisabled                                   1342
#define kNtErrorInvalidIdAuthority                                  1343
#define kNtErrorAllottedSpaceExceeded                               1344
#define kNtErrorInvalidGroupAttributes                              1345
#define kNtErrorBadImpersonationLevel                               1346
#define kNtErrorCantOpenAnonymous                                   1347
#define kNtErrorBadValidationClass                                  1348
#define kNtErrorBadTokenType                                        1349
#define kNtErrorNoSecurityOnObject                                  1350
#define kNtErrorCantAccessDomainInfo                                1351
#define kNtErrorInvalidServerState                                  1352
#define kNtErrorInvalidDomainState                                  1353
#define kNtErrorInvalidDomainRole                                   1354
#define kNtErrorNoSuchDomain                                        1355
#define kNtErrorDomainExists                                        1356
#define kNtErrorDomainLimitExceeded                                 1357
#define kNtErrorInternalDbCorruption                                1358
#define kNtErrorInternalError                                       1359
#define kNtErrorGenericNotMapped                                    1360
#define kNtErrorBadDescriptorFormat                                 1361
#define kNtErrorNotLogonProcess                                     1362
#define kNtErrorLogonSessionExists                                  1363
#define kNtErrorNoSuchPackage                                       1364
#define kNtErrorBadLogonSessionState                                1365
#define kNtErrorLogonSessionCollision                               1366
#define kNtErrorInvalidLogonType                                    1367
#define kNtErrorCannotImpersonate                                   1368
#define kNtErrorRxactInvalidState                                   1369
#define kNtErrorRxactCommitFailure                                  1370
#define kNtErrorSpecialAccount                                      1371
#define kNtErrorSpecialGroup                                        1372
#define kNtErrorSpecialUser                                         1373
#define kNtErrorMembersPrimaryGroup                                 1374
#define kNtErrorTokenAlreadyInUse                                   1375
#define kNtErrorNoSuchAlias                                         1376
#define kNtErrorMemberNotInAlias                                    1377
#define kNtErrorMemberInAlias                                       1378
#define kNtErrorAliasExists                                         1379
#define kNtErrorLogonNotGranted                                     1380
#define kNtErrorTooManySecrets                                      1381
#define kNtErrorSecretTooLong                                       1382
#define kNtErrorInternalDbError                                     1383
#define kNtErrorTooManyContextIds                                   1384
#define kNtErrorLogonTypeNotGranted                                 1385
#define kNtErrorNtCrossEncryptionRequired                           1386
#define kNtErrorNoSuchMember                                        1387
#define kNtErrorInvalidMember                                       1388
#define kNtErrorTooManySids                                         1389
#define kNtErrorLmCrossEncryptionRequired                           1390
#define kNtErrorNoInheritance                                       1391
#define kNtErrorFileCorrupt                                         1392
#define kNtErrorDiskCorrupt                                         1393
#define kNtErrorNoUserSessionKey                                    1394
#define kNtErrorLicenseQuotaExceeded                                1395
#define kNtErrorWrongTargetName                                     1396
#define kNtErrorMutualAuthFailed                                    1397
#define kNtErrorTimeSkew                                            1398
#define kNtErrorCurrentDomainNotAllowed                             1399
#define kNtErrorInvalidWindowHandle                                 1400
#define kNtErrorInvalidMenuHandle                                   1401
#define kNtErrorInvalidCursorHandle                                 1402
#define kNtErrorInvalidAccelHandle                                  1403
#define kNtErrorInvalidHookHandle                                   1404
#define kNtErrorInvalidDwpHandle                                    1405
#define kNtErrorTlwWithWschild                                      1406
#define kNtErrorCannotFindWndClass                                  1407
#define kNtErrorWindowOfOtherThread                                 1408
#define kNtErrorHotkeyAlreadyRegistered                             1409
#define kNtErrorClassAlreadyExists                                  1410
#define kNtErrorClassDoesNotExist                                   1411
#define kNtErrorClassHasWindows                                     1412
#define kNtErrorInvalidIndex                                        1413
#define kNtErrorInvalidIconHandle                                   1414
#define kNtErrorPrivateDialogIndex                                  1415
#define kNtErrorListboxIdNotFound                                   1416
#define kNtErrorNoWildcardCharacters                                1417
#define kNtErrorClipboardNotOpen                                    1418
#define kNtErrorHotkeyNotRegistered                                 1419
#define kNtErrorWindowNotDialog                                     1420
#define kNtErrorControlIdNotFound                                   1421
#define kNtErrorInvalidComboboxMessage                              1422
#define kNtErrorWindowNotCombobox                                   1423
#define kNtErrorInvalidEditHeight                                   1424
#define kNtErrorDcNotFound                                          1425
#define kNtErrorInvalidHookFilter                                   1426
#define kNtErrorInvalidFilterProc                                   1427
#define kNtErrorHookNeedsHmod                                       1428
#define kNtErrorGlobalOnlyHook                                      1429
#define kNtErrorJournalHookSet                                      1430
#define kNtErrorHookNotInstalled                                    1431
#define kNtErrorInvalidLbMessage                                    1432
#define kNtErrorSetcountOnBadLb                                     1433
#define kNtErrorLbWithoutTabstops                                   1434
#define kNtErrorDestroyObjectOfOtherThread                          1435
#define kNtErrorChildWindowMenu                                     1436
#define kNtErrorNoSystemMenu                                        1437
#define kNtErrorInvalidMsgboxStyle                                  1438
#define kNtErrorInvalidSpiValue                                     1439
#define kNtErrorScreenAlreadyLocked                                 1440
#define kNtErrorHwndsHaveDiffParent                                 1441
#define kNtErrorNotChildWindow                                      1442
#define kNtErrorInvalidGwCommand                                    1443
#define kNtErrorInvalidThreadId                                     1444
#define kNtErrorNonMdichildWindow                                   1445
#define kNtErrorPopupAlreadyActive                                  1446
#define kNtErrorNoScrollbars                                        1447
#define kNtErrorInvalidScrollbarRange                               1448
#define kNtErrorInvalidShowwinCommand                               1449
#define kNtErrorNoSystemResources                                   1450
#define kNtErrorNonpagedSystemResources                             1451
#define kNtErrorPagedSystemResources                                1452
#define kNtErrorWorkingSetQuota                                     1453
#define kNtErrorPagefileQuota                                       1454
#define kNtErrorCommitmentLimit                                     1455
#define kNtErrorMenuItemNotFound                                    1456
#define kNtErrorInvalidKeyboardHandle                               1457
#define kNtErrorHookTypeNotAllowed                                  1458
#define kNtErrorRequiresInteractiveWindowstation                    1459
#define kNtErrorTimeout                                             1460 /* ETIMEDOUT */
#define kNtErrorInvalidMonitorHandle                                1461
#define kNtErrorIncorrectSize                                       1462
#define kNtErrorSymlinkClassDisabled                                1463
#define kNtErrorSymlinkNotSupported                                 1464
#define kNtErrorXmlParseError                                       1465
#define kNtErrorXmldsigError                                        1466
#define kNtErrorRestartApplication                                  1467
#define kNtErrorWrongCompartment                                    1468
#define kNtErrorAuthipFailure                                       1469
#define kNtErrorNoNvramResources                                    1470
#define kNtErrorNotGuiProcess                                       1471
#define kNtErrorEventlogFileCorrupt                                 1500
#define kNtErrorEventlogCantStart                                   1501
#define kNtErrorLogFileFull                                         1502
#define kNtErrorEventlogFileChanged                                 1503
#define kNtErrorContainerAssigned                                   1504
#define kNtErrorJobNoContainer                                      1505
#define kNtErrorInvalidTaskName                                     1550
#define kNtErrorInvalidTaskIndex                                    1551
#define kNtErrorThreadAlreadyInTask                                 1552
#define kNtErrorInstallServiceFailure                               1601
#define kNtErrorInstallUserexit                                     1602
#define kNtErrorInstallFailure                                      1603
#define kNtErrorInstallSuspend                                      1604
#define kNtErrorUnknownProduct                                      1605
#define kNtErrorUnknownFeature                                      1606
#define kNtErrorUnknownComponent                                    1607
#define kNtErrorUnknownProperty                                     1608
#define kNtErrorInvalidHandleState                                  1609
#define kNtErrorBadConfiguration                                    1610
#define kNtErrorIndexAbsent                                         1611
#define kNtErrorInstallSourceAbsent                                 1612
#define kNtErrorInstallPackageVersion                               1613
#define kNtErrorProductUninstalled                                  1614
#define kNtErrorBadQuerySyntax                                      1615
#define kNtErrorInvalidField                                        1616
#define kNtErrorDeviceRemoved                                       1617
#define kNtErrorInstallAlreadyRunning                               1618
#define kNtErrorInstallPackageOpenFailed                            1619
#define kNtErrorInstallPackageInvalid                               1620
#define kNtErrorInstallUiFailure                                    1621
#define kNtErrorInstallLogFailure                                   1622
#define kNtErrorInstallLanguageUnsupported                          1623
#define kNtErrorInstallTransformFailure                             1624
#define kNtErrorInstallPackageRejected                              1625
#define kNtErrorFunctionNotCalled                                   1626 /* EBADRPC */
#define kNtErrorFunctionFailed                                      1627 /* ERPCMISMATCH */
#define kNtErrorInvalidTable                                        1628
#define kNtErrorDatatypeMismatch                                    1629
#define kNtErrorUnsupportedType                                     1630
#define kNtErrorCreateFailed                                        1631
#define kNtErrorInstallTempUnwritable                               1632
#define kNtErrorInstallPlatformUnsupported                          1633
#define kNtErrorInstallNotused                                      1634
#define kNtErrorPatchPackageOpenFailed                              1635
#define kNtErrorPatchPackageInvalid                                 1636
#define kNtErrorPatchPackageUnsupported                             1637
#define kNtErrorProductVersion                                      1638
#define kNtErrorInvalidCommandLine                                  1639 /* E2BIG */
#define kNtErrorInstallRemoteDisallowed                             1640
#define kNtErrorSuccessRebootInitiated                              1641
#define kNtErrorPatchTargetNotFound                                 1642
#define kNtErrorPatchPackageRejected                                1643
#define kNtErrorInstallTransformRejected                            1644
#define kNtErrorInstallRemoteProhibited                             1645
#define kNtErrorPatchRemovalUnsupported                             1646
#define kNtErrorUnknownPatch                                        1647
#define kNtErrorPatchNoSequence                                     1648
#define kNtErrorPatchRemovalDisallowed                              1649
#define kNtErrorInvalidPatchXml                                     1650
#define kNtErrorPatchManagedAdvertisedProduct                       1651
#define kNtErrorInstallServiceSafeboot                              1652
#define kNtErrorFailFastException                                   1653
#define kNtErrorInstallRejected                                     1654
#define kNtErrorDynamicCodeBlocked                                  1655
#define kNtErrorNotSameObject                                       1656
#define kNtErrorStrictCfgViolation                                  1657
#define kNtErrorSetContextDenied                                    1660
#define kNtErrorCrossPartitionViolation                             1661
#define kNtErrorInvalidUserBuffer                                   1784
#define kNtErrorUnrecognizedMedia                                   1785
#define kNtErrorNoTrustLsaSecret                                    1786
#define kNtErrorNoTrustSamAccount                                   1787
#define kNtErrorTrustedDomainFailure                                1788
#define kNtErrorTrustedRelationshipFailure                          1789
#define kNtErrorTrustFailure                                        1790
#define kNtErrorNetlogonNotStarted                                  1792
#define kNtErrorAccountExpired                                      1793
#define kNtErrorRedirectorHasOpenHandles                            1794
#define kNtErrorPrinterDriverAlreadyInstalled                       1795
#define kNtErrorUnknownPort                                         1796
#define kNtErrorUnknownPrinterDriver                                1797
#define kNtErrorUnknownPrintprocessor                               1798
#define kNtErrorInvalidSeparatorFile                                1799
#define kNtErrorInvalidPriority                                     1800
#define kNtErrorInvalidPrinterName                                  1801
#define kNtErrorPrinterAlreadyExists                                1802
#define kNtErrorInvalidPrinterCommand                               1803
#define kNtErrorInvalidDatatype                                     1804
#define kNtErrorInvalidEnvironment                                  1805
#define kNtErrorNologonInterdomainTrustAccount                      1807
#define kNtErrorNologonWorkstationTrustAccount                      1808
#define kNtErrorNologonServerTrustAccount                           1809
#define kNtErrorDomainTrustInconsistent                             1810
#define kNtErrorServerHasOpenHandles                                1811
#define kNtErrorResourceDataNotFound                                1812
#define kNtErrorResourceTypeNotFound                                1813
#define kNtErrorResourceNameNotFound                                1814
#define kNtErrorResourceLangNotFound                                1815
#define kNtErrorNotEnoughQuota                                      1816 /* EDQUOT */
#define kNtErrorInvalidTime                                         1901
#define kNtErrorInvalidFormName                                     1902
#define kNtErrorInvalidFormSize                                     1903
#define kNtErrorAlreadyWaiting                                      1904
#define kNtErrorPrinterDeleted                                      1905
#define kNtErrorInvalidPrinterState                                 1906
#define kNtErrorPasswordMustChange                                  1907
#define kNtErrorDomainControllerNotFound                            1908
#define kNtErrorAccountLockedOut                                    1909
#define kNtErrorNoSitename                                          1919
#define kNtErrorCantAccessFile                                      1920
#define kNtErrorCantResolveFilename                                 1921
#define kNtErrorKmDriverBlocked                                     1930
#define kNtErrorContextExpired                                      1931
#define kNtErrorPerUserTrustQuotaExceeded                           1932
#define kNtErrorAllUserTrustQuotaExceeded                           1933
#define kNtErrorUserDeleteTrustQuotaExceeded                        1934
#define kNtErrorAuthenticationFirewallFailed                        1935
#define kNtErrorRemotePrintConnectionsBlocked                       1936
#define kNtErrorNtlmBlocked                                         1937
#define kNtErrorPasswordChangeRequired                              1938
#define kNtErrorLostModeLogonRestriction                            1939
#define kNtErrorInvalidPixelFormat                                  2000
#define kNtErrorBadDriver                                           2001
#define kNtErrorInvalidWindowStyle                                  2002
#define kNtErrorMetafileNotSupported                                2003
#define kNtErrorTransformNotSupported                               2004
#define kNtErrorClippingNotSupported                                2005
#define kNtErrorInvalidCmm                                          2010
#define kNtErrorInvalidProfile                                      2011
#define kNtErrorTagNotFound                                         2012
#define kNtErrorTagNotPresent                                       2013
#define kNtErrorDuplicateTag                                        2014
#define kNtErrorProfileNotAssociatedWithDevice                      2015
#define kNtErrorProfileNotFound                                     2016
#define kNtErrorInvalidColorspace                                   2017
#define kNtErrorIcmNotEnabled                                       2018
#define kNtErrorDeletingIcmXform                                    2019
#define kNtErrorInvalidTransform                                    2020
#define kNtErrorColorspaceMismatch                                  2021
#define kNtErrorInvalidColorindex                                   2022
#define kNtErrorProfileDoesNotMatchDevice                           2023
#define kNtErrorConnectedOtherPassword                              2108
#define kNtErrorConnectedOtherPasswordDefault                       2109
#define kNtErrorBadUsername                                         2202
#define kNtErrorNotConnected                                        2250
#define kNtErrorOpenFiles                                           2401
#define kNtErrorActiveConnections                                   2402
#define kNtErrorDeviceInUse                                         2404
#define kNtErrorUnknownPrintMonitor                                 3000
#define kNtErrorPrinterDriverInUse                                  3001
#define kNtErrorSpoolFileNotFound                                   3002
#define kNtErrorSplNoStartdoc                                       3003
#define kNtErrorSplNoAddjob                                         3004
#define kNtErrorPrintProcessorAlreadyInstalled                      3005
#define kNtErrorPrintMonitorAlreadyInstalled                        3006
#define kNtErrorInvalidPrintMonitor                                 3007
#define kNtErrorPrintMonitorInUse                                   3008
#define kNtErrorPrinterHasJobsQueued                                3009
#define kNtErrorSuccessRebootRequired                               3010
#define kNtErrorSuccessRestartRequired                              3011
#define kNtErrorPrinterNotFound                                     3012
#define kNtErrorPrinterDriverWarned                                 3013
#define kNtErrorPrinterDriverBlocked                                3014
#define kNtErrorPrinterDriverPackageInUse                           3015
#define kNtErrorCoreDriverPackageNotFound                           3016
#define kNtErrorFailRebootRequired                                  3017
#define kNtErrorFailRebootInitiated                                 3018
#define kNtErrorPrinterDriverDownloadNeeded                         3019
#define kNtErrorPrintJobRestartRequired                             3020
#define kNtErrorInvalidPrinterDriverManifest                        3021
#define kNtErrorPrinterNotShareable                                 3022
#define kNtErrorRequestPaused                                       3050
#define kNtErrorAppexecConditionNotSatisfied                        3060
#define kNtErrorAppexecHandleInvalidated                            3061
#define kNtErrorAppexecInvalidHostGeneration                        3062
#define kNtErrorAppexecUnexpectedProcessRegistration                3063
#define kNtErrorAppexecInvalidHostState                             3064
#define kNtErrorAppexecNoDonor                                      3065
#define kNtErrorAppexecHostIdMismatch                               3066
#define kNtErrorIoReissueAsCached                                   3950
#define kNtErrorWinsInternal                                        4000
#define kNtErrorCanNotDelLocalWins                                  4001
#define kNtErrorStaticInit                                          4002
#define kNtErrorIncBackup                                           4003
#define kNtErrorFullBackup                                          4004
#define kNtErrorRecNonExistent                                      4005
#define kNtErrorRplNotAllowed                                       4006
#define kNtErrorDhcpAddressConflict                                 4100
#define kNtErrorWmiGuidNotFound                                     4200
#define kNtErrorWmiInstanceNotFound                                 4201
#define kNtErrorWmiItemidNotFound                                   4202
#define kNtErrorWmiTryAgain                                         4203
#define kNtErrorWmiDpNotFound                                       4204
#define kNtErrorWmiUnresolvedInstanceRef                            4205
#define kNtErrorWmiAlreadyEnabled                                   4206
#define kNtErrorWmiGuidDisconnected                                 4207
#define kNtErrorWmiServerUnavailable                                4208
#define kNtErrorWmiDpFailed                                         4209
#define kNtErrorWmiInvalidMof                                       4210
#define kNtErrorWmiInvalidReginfo                                   4211
#define kNtErrorWmiAlreadyDisabled                                  4212
#define kNtErrorWmiReadOnly                                         4213
#define kNtErrorWmiSetFailure                                       4214
#define kNtErrorNotAppcontainer                                     4250
#define kNtErrorAppcontainerRequired                                4251
#define kNtErrorNotSupportedInAppcontainer                          4252
#define kNtErrorInvalidPackageSidLength                             4253
#define kNtErrorInvalidMedia                                        4300
#define kNtErrorInvalidLibrary                                      4301
#define kNtErrorInvalidMediaPool                                    4302
#define kNtErrorDriveMediaMismatch                                  4303
#define kNtErrorMediaOffline                                        4304
#define kNtErrorLibraryOffline                                      4305
#define kNtErrorEmpty                                               4306 /* ENOMSG */
#define kNtErrorNotEmpty                                            4307
#define kNtErrorMediaUnavailable                                    4308
#define kNtErrorResourceDisabled                                    4309
#define kNtErrorInvalidCleaner                                      4310
#define kNtErrorUnableToClean                                       4311
#define kNtErrorObjectNotFound                                      4312
#define kNtErrorDatabaseFailure                                     4313
#define kNtErrorDatabaseFull                                        4314
#define kNtErrorMediaIncompatible                                   4315
#define kNtErrorResourceNotPresent                                  4316
#define kNtErrorInvalidOperation                                    4317
#define kNtErrorMediaNotAvailable                                   4318
#define kNtErrorDeviceNotAvailable                                  4319
#define kNtErrorRequestRefused                                      4320
#define kNtErrorInvalidDriveObject                                  4321
#define kNtErrorLibraryFull                                         4322
#define kNtErrorMediumNotAccessible                                 4323
#define kNtErrorUnableToLoadMedium                                  4324
#define kNtErrorUnableToInventoryDrive                              4325
#define kNtErrorUnableToInventorySlot                               4326
#define kNtErrorUnableToInventoryTransport                          4327
#define kNtErrorTransportFull                                       4328
#define kNtErrorControllingIeport                                   4329
#define kNtErrorUnableToEjectMountedMedia                           4330
#define kNtErrorCleanerSlotSet                                      4331
#define kNtErrorCleanerSlotNotSet                                   4332
#define kNtErrorCleanerCartridgeSpent                               4333
#define kNtErrorUnexpectedOmid                                      4334
#define kNtErrorCantDeleteLastItem                                  4335
#define kNtErrorMessageExceedsMaxSize                               4336
#define kNtErrorVolumeContainsSysFiles                              4337
#define kNtErrorIndigenousType                                      4338
#define kNtErrorNoSupportingDrives                                  4339
#define kNtErrorCleanerCartridgeInstalled                           4340
#define kNtErrorIeportFull                                          4341
#define kNtErrorFileOffline                                         4350
#define kNtErrorRemoteStorageNotActive                              4351
#define kNtErrorRemoteStorageMediaError                             4352
#define kNtErrorNotAReparsePoint                                    4390
#define kNtErrorReparseAttributeConflict                            4391
#define kNtErrorInvalidReparseData                                  4392
#define kNtErrorReparseTagInvalid                                   4393
#define kNtErrorReparseTagMismatch                                  4394
#define kNtErrorReparsePointEncountered                             4395
#define kNtErrorAppDataNotFound                                     4400
#define kNtErrorAppDataExpired                                      4401
#define kNtErrorAppDataCorrupt                                      4402
#define kNtErrorAppDataLimitExceeded                                4403
#define kNtErrorAppDataRebootRequired                               4404
#define kNtErrorSecurebootRollbackDetected                          4420
#define kNtErrorSecurebootPolicyViolation                           4421
#define kNtErrorSecurebootInvalidPolicy                             4422
#define kNtErrorSecurebootPolicyPublisherNotFound                   4423
#define kNtErrorSecurebootPolicyNotSigned                           4424
#define kNtErrorSecurebootNotEnabled                                4425
#define kNtErrorSecurebootFileReplaced                              4426
#define kNtErrorSecurebootPolicyNotAuthorized                       4427
#define kNtErrorSecurebootPolicyUnknown                             4428
#define kNtErrorSecurebootPolicyMissingAntirollbackversion          4429
#define kNtErrorSecurebootPlatformIdMismatch                        4430
#define kNtErrorSecurebootPolicyRollbackDetected                    4431
#define kNtErrorSecurebootPolicyUpgradeMismatch                     4432
#define kNtErrorSecurebootRequiredPolicyFileMissing                 4433
#define kNtErrorSecurebootNotBasePolicy                             4434
#define kNtErrorSecurebootNotSupplementalPolicy                     4435
#define kNtErrorOffloadReadFltNotSupported                          4440
#define kNtErrorOffloadWriteFltNotSupported                         4441
#define kNtErrorOffloadReadFileNotSupported                         4442
#define kNtErrorOffloadWriteFileNotSupported                        4443
#define kNtErrorAlreadyHasStreamId                                  4444
#define kNtErrorSmrGarbageCollectionRequired                        4445
#define kNtErrorWofWimHeaderCorrupt                                 4446
#define kNtErrorWofWimResourceTableCorrupt                          4447
#define kNtErrorWofFileResourceTableCorrupt                         4448
#define kNtErrorVolumeNotSisEnabled                                 4500
#define kNtErrorSystemIntegrityRollbackDetected                     4550
#define kNtErrorSystemIntegrityPolicyViolation                      4551
#define kNtErrorSystemIntegrityInvalidPolicy                        4552
#define kNtErrorSystemIntegrityPolicyNotSigned                      4553
#define kNtErrorVsmNotInitialized                                   4560
#define kNtErrorVsmDmaProtectionNotInUse                            4561
#define kNtErrorPlatformManifestNotAuthorized                       4570
#define kNtErrorPlatformManifestInvalid                             4571
#define kNtErrorPlatformManifestFileNotAuthorized                   4572
#define kNtErrorPlatformManifestCatalogNotAuthorized                4573
#define kNtErrorPlatformManifestBinaryIdNotFound                    4574
#define kNtErrorPlatformManifestNotActive                           4575
#define kNtErrorPlatformManifestNotSigned                           4576
#define kNtErrorDependentResourceExists                             5001
#define kNtErrorDependencyNotFound                                  5002
#define kNtErrorDependencyAlreadyExists                             5003
#define kNtErrorResourceNotOnline                                   5004
#define kNtErrorHostNodeNotAvailable                                5005
#define kNtErrorResourceNotAvailable                                5006
#define kNtErrorResourceNotFound                                    5007
#define kNtErrorShutdownCluster                                     5008
#define kNtErrorCantEvictActiveNode                                 5009
#define kNtErrorObjectAlreadyExists                                 5010
#define kNtErrorObjectInList                                        5011
#define kNtErrorGroupNotAvailable                                   5012
#define kNtErrorGroupNotFound                                       5013
#define kNtErrorGroupNotOnline                                      5014
#define kNtErrorHostNodeNotResourceOwner                            5015
#define kNtErrorHostNodeNotGroupOwner                               5016
#define kNtErrorResmonCreateFailed                                  5017
#define kNtErrorResmonOnlineFailed                                  5018
#define kNtErrorResourceOnline                                      5019
#define kNtErrorQuorumResource                                      5020
#define kNtErrorNotQuorumCapable                                    5021
#define kNtErrorClusterShuttingDown                                 5022
#define kNtErrorInvalidState                                        5023
#define kNtErrorResourcePropertiesStored                            5024
#define kNtErrorNotQuorumClass                                      5025
#define kNtErrorCoreResource                                        5026
#define kNtErrorQuorumResourceOnlineFailed                          5027
#define kNtErrorQuorumlogOpenFailed                                 5028
#define kNtErrorClusterlogCorrupt                                   5029
#define kNtErrorClusterlogRecordExceedsMaxsize                      5030
#define kNtErrorClusterlogExceedsMaxsize                            5031
#define kNtErrorClusterlogChkpointNotFound                          5032
#define kNtErrorClusterlogNotEnoughSpace                            5033
#define kNtErrorQuorumOwnerAlive                                    5034
#define kNtErrorNetworkNotAvailable                                 5035
#define kNtErrorNodeNotAvailable                                    5036
#define kNtErrorAllNodesNotAvailable                                5037
#define kNtErrorResourceFailed                                      5038
#define kNtErrorClusterInvalidNode                                  5039
#define kNtErrorClusterNodeExists                                   5040
#define kNtErrorClusterJoinInProgress                               5041
#define kNtErrorClusterNodeNotFound                                 5042
#define kNtErrorClusterLocalNodeNotFound                            5043
#define kNtErrorClusterNetworkExists                                5044
#define kNtErrorClusterNetworkNotFound                              5045
#define kNtErrorClusterNetinterfaceExists                           5046
#define kNtErrorClusterNetinterfaceNotFound                         5047
#define kNtErrorClusterInvalidRequest                               5048
#define kNtErrorClusterInvalidNetworkProvider                       5049
#define kNtErrorClusterNodeDown                                     5050
#define kNtErrorClusterNodeUnreachable                              5051
#define kNtErrorClusterNodeNotMember                                5052
#define kNtErrorClusterJoinNotInProgress                            5053
#define kNtErrorClusterInvalidNetwork                               5054
#define kNtErrorClusterNodeUp                                       5056
#define kNtErrorClusterIpaddrInUse                                  5057
#define kNtErrorClusterNodeNotPaused                                5058
#define kNtErrorClusterNoSecurityContext                            5059
#define kNtErrorClusterNetworkNotInternal                           5060
#define kNtErrorClusterNodeAlreadyUp                                5061
#define kNtErrorClusterNodeAlreadyDown                              5062
#define kNtErrorClusterNetworkAlreadyOnline                         5063
#define kNtErrorClusterNetworkAlreadyOffline                        5064
#define kNtErrorClusterNodeAlreadyMember                            5065
#define kNtErrorClusterLastInternalNetwork                          5066
#define kNtErrorClusterNetworkHasDependents                         5067
#define kNtErrorInvalidOperationOnQuorum                            5068
#define kNtErrorDependencyNotAllowed                                5069
#define kNtErrorClusterNodePaused                                   5070
#define kNtErrorNodeCantHostResource                                5071
#define kNtErrorClusterNodeNotReady                                 5072
#define kNtErrorClusterNodeShuttingDown                             5073
#define kNtErrorClusterJoinAborted                                  5074
#define kNtErrorClusterIncompatibleVersions                         5075
#define kNtErrorClusterMaxnumOfResourcesExceeded                    5076
#define kNtErrorClusterSystemConfigChanged                          5077
#define kNtErrorClusterResourceTypeNotFound                         5078
#define kNtErrorClusterRestypeNotSupported                          5079
#define kNtErrorClusterResnameNotFound                              5080
#define kNtErrorClusterNoRpcPackagesRegistered                      5081
#define kNtErrorClusterOwnerNotInPreflist                           5082
#define kNtErrorClusterDatabaseSeqmismatch                          5083
#define kNtErrorResmonInvalidState                                  5084
#define kNtErrorClusterGumNotLocker                                 5085
#define kNtErrorQuorumDiskNotFound                                  5086
#define kNtErrorDatabaseBackupCorrupt                               5087
#define kNtErrorClusterNodeAlreadyHasDfsRoot                        5088
#define kNtErrorResourcePropertyUnchangeable                        5089
#define kNtErrorNoAdminAccessPoint                                  5090
#define kNtErrorClusterMembershipInvalidState                       5890
#define kNtErrorClusterQuorumlogNotFound                            5891
#define kNtErrorClusterMembershipHalt                               5892
#define kNtErrorClusterInstanceIdMismatch                           5893
#define kNtErrorClusterNetworkNotFoundForIp                         5894
#define kNtErrorClusterPropertyDataTypeMismatch                     5895
#define kNtErrorClusterEvictWithoutCleanup                          5896
#define kNtErrorClusterParameterMismatch                            5897
#define kNtErrorNodeCannotBeClustered                               5898
#define kNtErrorClusterWrongOsVersion                               5899
#define kNtErrorClusterCantCreateDupClusterName                     5900
#define kNtErrorCluscfgAlreadyCommitted                             5901
#define kNtErrorCluscfgRollbackFailed                               5902
#define kNtErrorCluscfgSystemDiskDriveLetterConflict                5903
#define kNtErrorClusterOldVersion                                   5904
#define kNtErrorClusterMismatchedComputerAcctName                   5905
#define kNtErrorClusterNoNetAdapters                                5906
#define kNtErrorClusterPoisoned                                     5907
#define kNtErrorClusterGroupMoving                                  5908
#define kNtErrorClusterResourceTypeBusy                             5909
#define kNtErrorResourceCallTimedOut                                5910
#define kNtErrorInvalidClusterIpv6Address                           5911
#define kNtErrorClusterInternalInvalidFunction                      5912
#define kNtErrorClusterParameterOutOfBounds                         5913
#define kNtErrorClusterPartialSend                                  5914
#define kNtErrorClusterRegistryInvalidFunction                      5915
#define kNtErrorClusterInvalidStringTermination                     5916
#define kNtErrorClusterInvalidStringFormat                          5917
#define kNtErrorClusterDatabaseTransactionInProgress                5918
#define kNtErrorClusterDatabaseTransactionNotInProgress             5919
#define kNtErrorClusterNullData                                     5920
#define kNtErrorClusterPartialRead                                  5921
#define kNtErrorClusterPartialWrite                                 5922
#define kNtErrorClusterCantDeserializeData                          5923
#define kNtErrorDependentResourcePropertyConflict                   5924
#define kNtErrorClusterNoQuorum                                     5925
#define kNtErrorClusterInvalidIpv6Network                           5926
#define kNtErrorClusterInvalidIpv6TunnelNetwork                     5927
#define kNtErrorQuorumNotAllowedInThisGroup                         5928
#define kNtErrorDependencyTreeTooComplex                            5929
#define kNtErrorExceptionInResourceCall                             5930
#define kNtErrorClusterRhsFailedInitialization                      5931
#define kNtErrorClusterNotInstalled                                 5932
#define kNtErrorClusterResourcesMustBeOnlineOnTheSameNode           5933
#define kNtErrorClusterMaxNodesInCluster                            5934
#define kNtErrorClusterTooManyNodes                                 5935
#define kNtErrorClusterObjectAlreadyUsed                            5936
#define kNtErrorNoncoreGroupsFound                                  5937
#define kNtErrorFileShareResourceConflict                           5938
#define kNtErrorClusterEvictInvalidRequest                          5939
#define kNtErrorClusterSingletonResource                            5940
#define kNtErrorClusterGroupSingletonResource                       5941
#define kNtErrorClusterResourceProviderFailed                       5942
#define kNtErrorClusterResourceConfigurationError                   5943
#define kNtErrorClusterGroupBusy                                    5944
#define kNtErrorClusterNotSharedVolume                              5945
#define kNtErrorClusterInvalidSecurityDescriptor                    5946
#define kNtErrorClusterSharedVolumesInUse                           5947
#define kNtErrorClusterUseSharedVolumesApi                          5948
#define kNtErrorClusterBackupInProgress                             5949
#define kNtErrorNonCsvPath                                          5950
#define kNtErrorCsvVolumeNotLocal                                   5951
#define kNtErrorClusterWatchdogTerminating                          5952
#define kNtErrorClusterResourceVetoedMoveIncompatibleNodes          5953
#define kNtErrorClusterInvalidNodeWeight                            5954
#define kNtErrorClusterResourceVetoedCall                           5955
#define kNtErrorResmonSystemResourcesLacking                        5956
#define kNtErrorClusterResourceVetoedMoveNotEnoughResourcesOnSource 5958
#define kNtErrorClusterGroupQueued                                  5959
#define kNtErrorClusterResourceLockedStatus                         5960
#define kNtErrorClusterSharedVolumeFailoverNotAllowed               5961
#define kNtErrorClusterNodeDrainInProgress                          5962
#define kNtErrorClusterDiskNotConnected                             5963
#define kNtErrorDiskNotCsvCapable                                   5964
#define kNtErrorResourceNotInAvailableStorage                       5965
#define kNtErrorClusterSharedVolumeRedirected                       5966
#define kNtErrorClusterSharedVolumeNotRedirected                    5967
#define kNtErrorClusterCannotReturnProperties                       5968
#define kNtErrorClusterResourceIsInMaintenanceMode                  5970
#define kNtErrorClusterAffinityConflict                             5971
#define kNtErrorClusterResourceIsReplicaVirtualMachine              5972
#define kNtErrorClusterUpgradeIncompatibleVersions                  5973
#define kNtErrorClusterUpgradeFixQuorumNotSupported                 5974
#define kNtErrorClusterUpgradeRestartRequired                       5975
#define kNtErrorClusterUpgradeInProgress                            5976
#define kNtErrorClusterUpgradeIncomplete                            5977
#define kNtErrorClusterNodeInGracePeriod                            5978
#define kNtErrorClusterCsvIoPauseTimeout                            5979
#define kNtErrorNodeNotActiveClusterMember                          5980
#define kNtErrorClusterResourceNotMonitored                         5981
#define kNtErrorClusterResourceDoesNotSupportUnmonitored            5982
#define kNtErrorClusterResourceIsReplicated                         5983
#define kNtErrorClusterNodeIsolated                                 5984
#define kNtErrorClusterNodeQuarantined                              5985
#define kNtErrorClusterDatabaseUpdateConditionFailed                5986
#define kNtErrorClusterSpaceDegraded                                5987
#define kNtErrorClusterTokenDelegationNotSupported                  5988
#define kNtErrorClusterCsvInvalidHandle                             5989
#define kNtErrorClusterCsvSupportedOnlyOnCoordinator                5990
#define kNtErrorGroupsetNotAvailable                                5991
#define kNtErrorGroupsetNotFound                                    5992
#define kNtErrorGroupsetCantProvide                                 5993
#define kNtErrorClusterFaultDomainParentNotFound                    5994
#define kNtErrorClusterFaultDomainInvalidHierarchy                  5995
#define kNtErrorClusterFaultDomainFailedS2dValidation               5996
#define kNtErrorClusterFaultDomainS2dConnectivityLoss               5997
#define kNtErrorClusterInvalidInfrastructureFileserverName          5998
#define kNtErrorClustersetManagementClusterUnreachable              5999
#define kNtErrorEncryptionFailed                                    6000
#define kNtErrorDecryptionFailed                                    6001
#define kNtErrorFileEncrypted                                       6002
#define kNtErrorNoRecoveryPolicy                                    6003
#define kNtErrorNoEfs                                               6004
#define kNtErrorWrongEfs                                            6005
#define kNtErrorNoUserKeys                                          6006
#define kNtErrorFileNotEncrypted                                    6007
#define kNtErrorNotExportFormat                                     6008
#define kNtErrorFileReadOnly                                        6009 /* EROFS */
#define kNtErrorDirEfsDisallowed                                    6010
#define kNtErrorEfsServerNotTrusted                                 6011
#define kNtErrorBadRecoveryPolicy                                   6012
#define kNtErrorEfsAlgBlobTooBig                                    6013
#define kNtErrorVolumeNotSupportEfs                                 6014
#define kNtErrorEfsDisabled                                         6015
#define kNtErrorEfsVersionNotSupport                                6016
#define kNtErrorCsEncryptionInvalidServerResponse                   6017
#define kNtErrorCsEncryptionUnsupportedServer                       6018
#define kNtErrorCsEncryptionExistingEncryptedFile                   6019
#define kNtErrorCsEncryptionNewEncryptedFile                        6020
#define kNtErrorCsEncryptionFileNotCse                              6021
#define kNtErrorEncryptionPolicyDeniesOperation                     6022
#define kNtErrorNoBrowserServersFound                               6118
#define kNtErrorLogSectorInvalid                                    6600
#define kNtErrorLogSectorParityInvalid                              6601
#define kNtErrorLogSectorRemapped                                   6602
#define kNtErrorLogBlockIncomplete                                  6603
#define kNtErrorLogInvalidRange                                     6604 /* ERANGE */
#define kNtErrorLogBlocksExhausted                                  6605
#define kNtErrorLogReadContextInvalid                               6606
#define kNtErrorLogRestartInvalid                                   6607
#define kNtErrorLogBlockVersion                                     6608
#define kNtErrorLogBlockInvalid                                     6609
#define kNtErrorLogReadModeInvalid                                  6610
#define kNtErrorLogNoRestart                                        6611
#define kNtErrorLogMetadataCorrupt                                  6612
#define kNtErrorLogMetadataInvalid                                  6613
#define kNtErrorLogMetadataInconsistent                             6614
#define kNtErrorLogReservationInvalid                               6615
#define kNtErrorLogCantDelete                                       6616
#define kNtErrorLogContainerLimitExceeded                           6617
#define kNtErrorLogStartOfLog                                       6618
#define kNtErrorLogPolicyAlreadyInstalled                           6619
#define kNtErrorLogPolicyNotInstalled                               6620
#define kNtErrorLogPolicyInvalid                                    6621
#define kNtErrorLogPolicyConflict                                   6622
#define kNtErrorLogPinnedArchiveTail                                6623
#define kNtErrorLogRecordNonexistent                                6624
#define kNtErrorLogRecordsReservedInvalid                           6625
#define kNtErrorLogSpaceReservedInvalid                             6626
#define kNtErrorLogTailInvalid                                      6627
#define kNtErrorLogFull                                             6628
#define kNtErrorCouldNotResizeLog                                   6629
#define kNtErrorLogMultiplexed                                      6630
#define kNtErrorLogDedicated                                        6631
#define kNtErrorLogArchiveNotInProgress                             6632
#define kNtErrorLogArchiveInProgress                                6633
#define kNtErrorLogEphemeral                                        6634
#define kNtErrorLogNotEnoughContainers                              6635
#define kNtErrorLogClientAlreadyRegistered                          6636
#define kNtErrorLogClientNotRegistered                              6637
#define kNtErrorLogFullHandlerInProgress                            6638
#define kNtErrorLogContainerReadFailed                              6639
#define kNtErrorLogContainerWriteFailed                             6640
#define kNtErrorLogContainerOpenFailed                              6641
#define kNtErrorLogContainerStateInvalid                            6642
#define kNtErrorLogStateInvalid                                     6643
#define kNtErrorLogPinned                                           6644
#define kNtErrorLogMetadataFlushFailed                              6645
#define kNtErrorLogInconsistentSecurity                             6646
#define kNtErrorLogAppendedFlushFailed                              6647
#define kNtErrorLogPinnedReservation                                6648
#define kNtErrorInvalidTransaction                                  6700
#define kNtErrorTransactionNotActive                                6701
#define kNtErrorTransactionRequestNotValid                          6702
#define kNtErrorTransactionNotRequested                             6703
#define kNtErrorTransactionAlreadyAborted                           6704
#define kNtErrorTransactionAlreadyCommitted                         6705
#define kNtErrorTmInitializationFailed                              6706
#define kNtErrorResourcemanagerReadOnly                             6707
#define kNtErrorTransactionNotJoined                                6708
#define kNtErrorTransactionSuperiorExists                           6709
#define kNtErrorCrmProtocolAlreadyExists                            6710
#define kNtErrorTransactionPropagationFailed                        6711
#define kNtErrorCrmProtocolNotFound                                 6712
#define kNtErrorTransactionInvalidMarshallBuffer                    6713
#define kNtErrorCurrentTransactionNotValid                          6714
#define kNtErrorTransactionNotFound                                 6715
#define kNtErrorResourcemanagerNotFound                             6716
#define kNtErrorEnlistmentNotFound                                  6717
#define kNtErrorTransactionmanagerNotFound                          6718
#define kNtErrorTransactionmanagerNotOnline                         6719
#define kNtErrorTransactionmanagerRecoveryNameCollision             6720
#define kNtErrorTransactionNotRoot                                  6721
#define kNtErrorTransactionObjectExpired                            6722
#define kNtErrorTransactionResponseNotEnlisted                      6723
#define kNtErrorTransactionRecordTooLong                            6724
#define kNtErrorImplicitTransactionNotSupported                     6725
#define kNtErrorTransactionIntegrityViolated                        6726
#define kNtErrorTransactionmanagerIdentityMismatch                  6727
#define kNtErrorRmCannotBeFrozenForSnapshot                         6728
#define kNtErrorTransactionMustWritethrough                         6729
#define kNtErrorTransactionNoSuperior                               6730
#define kNtErrorHeuristicDamagePossible                             6731
#define kNtErrorTransactionalConflict                               6800
#define kNtErrorRmNotActive                                         6801
#define kNtErrorRmMetadataCorrupt                                   6802
#define kNtErrorDirectoryNotRm                                      6803
#define kNtErrorTransactionsUnsupportedRemote                       6805
#define kNtErrorLogResizeInvalidSize                                6806
#define kNtErrorObjectNoLongerExists                                6807
#define kNtErrorStreamMiniversionNotFound                           6808
#define kNtErrorStreamMiniversionNotValid                           6809
#define kNtErrorMiniversionInaccessibleFromSpecifiedTransaction     6810
#define kNtErrorCantOpenMiniversionWithModifyIntent                 6811
#define kNtErrorCantCreateMoreStreamMiniversions                    6812
#define kNtErrorRemoteFileVersionMismatch                           6814
#define kNtErrorHandleNoLongerValid                                 6815
#define kNtErrorNoTxfMetadata                                       6816
#define kNtErrorLogCorruptionDetected                               6817
#define kNtErrorCantRecoverWithHandleOpen                           6818
#define kNtErrorRmDisconnected                                      6819
#define kNtErrorEnlistmentNotSuperior                               6820
#define kNtErrorRecoveryNotNeeded                                   6821
#define kNtErrorRmAlreadyStarted                                    6822
#define kNtErrorFileIdentityNotPersistent                           6823
#define kNtErrorCantBreakTransactionalDependency                    6824
#define kNtErrorCantCrossRmBoundary                                 6825
#define kNtErrorTxfDirNotEmpty                                      6826
#define kNtErrorIndoubtTransactionsExist                            6827
#define kNtErrorTmVolatile                                          6828
#define kNtErrorRollbackTimerExpired                                6829
#define kNtErrorTxfAttributeCorrupt                                 6830
#define kNtErrorEfsNotAllowedInTransaction                          6831
#define kNtErrorTransactionalOpenNotAllowed                         6832
#define kNtErrorLogGrowthFailed                                     6833
#define kNtErrorTransactedMappingUnsupportedRemote                  6834
#define kNtErrorTxfMetadataAlreadyPresent                           6835
#define kNtErrorTransactionScopeCallbacksNotSet                     6836
#define kNtErrorTransactionRequiredPromotion                        6837
#define kNtErrorCannotExecuteFileInTransaction                      6838
#define kNtErrorTransactionsNotFrozen                               6839
#define kNtErrorTransactionFreezeInProgress                         6840
#define kNtErrorNotSnapshotVolume                                   6841
#define kNtErrorNoSavepointWithOpenFiles                            6842
#define kNtErrorDataLostRepair                                      6843
#define kNtErrorSparseNotAllowedInTransaction                       6844
#define kNtErrorTmIdentityMismatch                                  6845
#define kNtErrorFloatedSection                                      6846
#define kNtErrorCannotAcceptTransactedWork                          6847
#define kNtErrorCannotAbortTransactions                             6848
#define kNtErrorBadClusters                                         6849
#define kNtErrorCompressionNotAllowedInTransaction                  6850
#define kNtErrorVolumeDirty                                         6851
#define kNtErrorNoLinkTrackingInTransaction                         6852
#define kNtErrorOperationNotSupportedInTransaction                  6853
#define kNtErrorExpiredHandle                                       6854
#define kNtErrorTransactionNotEnlisted                              6855
#define kNtErrorCtxWinstationNameInvalid                            7001
#define kNtErrorCtxInvalidPd                                        7002
#define kNtErrorCtxPdNotFound                                       7003
#define kNtErrorCtxWdNotFound                                       7004
#define kNtErrorCtxCannotMakeEventlogEntry                          7005
#define kNtErrorCtxServiceNameCollision                             7006
#define kNtErrorCtxClosePending                                     7007
#define kNtErrorCtxNoOutbuf                                         7008
#define kNtErrorCtxModemInfNotFound                                 7009
#define kNtErrorCtxInvalidModemname                                 7010
#define kNtErrorCtxModemResponseError                               7011
#define kNtErrorCtxModemResponseTimeout                             7012
#define kNtErrorCtxModemResponseNoCarrier                           7013
#define kNtErrorCtxModemResponseNoDialtone                          7014
#define kNtErrorCtxModemResponseBusy                                7015
#define kNtErrorCtxModemResponseVoice                               7016
#define kNtErrorCtxTdError                                          7017
#define kNtErrorCtxWinstationNotFound                               7022
#define kNtErrorCtxWinstationAlreadyExists                          7023
#define kNtErrorCtxWinstationBusy                                   7024
#define kNtErrorCtxBadVideoMode                                     7025
#define kNtErrorCtxGraphicsInvalid                                  7035
#define kNtErrorCtxLogonDisabled                                    7037
#define kNtErrorCtxNotConsole                                       7038
#define kNtErrorCtxClientQueryTimeout                               7040
#define kNtErrorCtxConsoleDisconnect                                7041
#define kNtErrorCtxConsoleConnect                                   7042
#define kNtErrorCtxShadowDenied                                     7044
#define kNtErrorCtxWinstationAccessDenied                           7045
#define kNtErrorCtxInvalidWd                                        7049
#define kNtErrorCtxShadowInvalid                                    7050
#define kNtErrorCtxShadowDisabled                                   7051
#define kNtErrorCtxClientLicenseInUse                               7052
#define kNtErrorCtxClientLicenseNotSet                              7053
#define kNtErrorCtxLicenseNotAvailable                              7054
#define kNtErrorCtxLicenseClientInvalid                             7055
#define kNtErrorCtxLicenseExpired                                   7056
#define kNtErrorCtxShadowNotRunning                                 7057
#define kNtErrorCtxShadowEndedByModeChange                          7058
#define kNtErrorActivationCountExceeded                             7059
#define kNtErrorCtxWinstationsDisabled                              7060
#define kNtErrorCtxEncryptionLevelRequired                          7061
#define kNtErrorCtxSessionInUse                                     7062
#define kNtErrorCtxNoForceLogoff                                    7063
#define kNtErrorCtxAccountRestriction                               7064
#define kNtErrorRdpProtocolError                                    7065 /* EPROTO */
#define kNtErrorCtxCdmConnect                                       7066
#define kNtErrorCtxCdmDisconnect                                    7067
#define kNtErrorCtxSecurityLayerError                               7068
#define kNtErrorTsIncompatibleSessions                              7069
#define kNtErrorTsVideoSubsystemError                               7070
#define kNtErrorDsNotInstalled                                      8200
#define kNtErrorDsMembershipEvaluatedLocally                        8201
#define kNtErrorDsNoAttributeOrValue                                8202
#define kNtErrorDsInvalidAttributeSyntax                            8203
#define kNtErrorDsAttributeTypeUndefined                            8204
#define kNtErrorDsAttributeOrValueExists                            8205
#define kNtErrorDsBusy                                              8206
#define kNtErrorDsUnavailable                                       8207
#define kNtErrorDsNoRidsAllocated                                   8208
#define kNtErrorDsNoMoreRids                                        8209
#define kNtErrorDsIncorrectRoleOwner                                8210
#define kNtErrorDsRidmgrInitError                                   8211
#define kNtErrorDsObjClassViolation                                 8212
#define kNtErrorDsCantOnNonLeaf                                     8213
#define kNtErrorDsCantOnRdn                                         8214
#define kNtErrorDsCantModObjClass                                   8215
#define kNtErrorDsCrossDomMoveError                                 8216
#define kNtErrorDsGcNotAvailable                                    8217
#define kNtErrorSharedPolicy                                        8218
#define kNtErrorPolicyObjectNotFound                                8219
#define kNtErrorPolicyOnlyInDs                                      8220
#define kNtErrorPromotionActive                                     8221
#define kNtErrorNoPromotionActive                                   8222
#define kNtErrorDsOperationsError                                   8224
#define kNtErrorDsProtocolError                                     8225
#define kNtErrorDsTimelimitExceeded                                 8226
#define kNtErrorDsSizelimitExceeded                                 8227
#define kNtErrorDsAdminLimitExceeded                                8228
#define kNtErrorDsCompareFalse                                      8229
#define kNtErrorDsCompareTrue                                       8230
#define kNtErrorDsAuthMethodNotSupported                            8231
#define kNtErrorDsStrongAuthRequired                                8232
#define kNtErrorDsInappropriateAuth                                 8233
#define kNtErrorDsAuthUnknown                                       8234
#define kNtErrorDsReferral                                          8235
#define kNtErrorDsUnavailableCritExtension                          8236
#define kNtErrorDsConfidentialityRequired                           8237
#define kNtErrorDsInappropriateMatching                             8238
#define kNtErrorDsConstraintViolation                               8239
#define kNtErrorDsNoSuchObject                                      8240
#define kNtErrorDsAliasProblem                                      8241
#define kNtErrorDsInvalidDnSyntax                                   8242
#define kNtErrorDsIsLeaf                                            8243
#define kNtErrorDsAliasDerefProblem                                 8244
#define kNtErrorDsUnwillingToPerform                                8245
#define kNtErrorDsLoopDetect                                        8246
#define kNtErrorDsNamingViolation                                   8247
#define kNtErrorDsObjectResultsTooLarge                             8248
#define kNtErrorDsAffectsMultipleDsas                               8249
#define kNtErrorDsServerDown                                        8250
#define kNtErrorDsLocalError                                        8251
#define kNtErrorDsEncodingError                                     8252
#define kNtErrorDsDecodingError                                     8253
#define kNtErrorDsFilterUnknown                                     8254
#define kNtErrorDsParamError                                        8255
#define kNtErrorDsNotSupported                                      8256
#define kNtErrorDsNoResultsReturned                                 8257
#define kNtErrorDsControlNotFound                                   8258
#define kNtErrorDsClientLoop                                        8259
#define kNtErrorDsReferralLimitExceeded                             8260
#define kNtErrorDsSortControlMissing                                8261
#define kNtErrorDsOffsetRangeError                                  8262
#define kNtErrorDsRidmgrDisabled                                    8263
#define kNtErrorDsRootMustBeNc                                      8301
#define kNtErrorDsAddReplicaInhibited                               8302
#define kNtErrorDsAttNotDefInSchema                                 8303
#define kNtErrorDsMaxObjSizeExceeded                                8304
#define kNtErrorDsObjStringNameExists                               8305
#define kNtErrorDsNoRdnDefinedInSchema                              8306
#define kNtErrorDsRdnDoesntMatchSchema                              8307
#define kNtErrorDsNoRequestedAttsFound                              8308
#define kNtErrorDsUserBufferToSmall                                 8309
#define kNtErrorDsAttIsNotOnObj                                     8310
#define kNtErrorDsIllegalModOperation                               8311
#define kNtErrorDsObjTooLarge                                       8312
#define kNtErrorDsBadInstanceType                                   8313
#define kNtErrorDsMasterdsaRequired                                 8314
#define kNtErrorDsObjectClassRequired                               8315
#define kNtErrorDsMissingRequiredAtt                                8316
#define kNtErrorDsAttNotDefForClass                                 8317
#define kNtErrorDsAttAlreadyExists                                  8318
#define kNtErrorDsCantAddAttValues                                  8320
#define kNtErrorDsSingleValueConstraint                             8321
#define kNtErrorDsRangeConstraint                                   8322
#define kNtErrorDsAttValAlreadyExists                               8323
#define kNtErrorDsCantRemMissingAtt                                 8324
#define kNtErrorDsCantRemMissingAttVal                              8325
#define kNtErrorDsRootCantBeSubref                                  8326
#define kNtErrorDsNoChaining                                        8327
#define kNtErrorDsNoChainedEval                                     8328
#define kNtErrorDsNoParentObject                                    8329
#define kNtErrorDsParentIsAnAlias                                   8330
#define kNtErrorDsCantMixMasterAndReps                              8331
#define kNtErrorDsChildrenExist                                     8332
#define kNtErrorDsObjNotFound                                       8333
#define kNtErrorDsAliasedObjMissing                                 8334
#define kNtErrorDsBadNameSyntax                                     8335
#define kNtErrorDsAliasPointsToAlias                                8336
#define kNtErrorDsCantDerefAlias                                    8337
#define kNtErrorDsOutOfScope                                        8338
#define kNtErrorDsObjectBeingRemoved                                8339
#define kNtErrorDsCantDeleteDsaObj                                  8340
#define kNtErrorDsGenericError                                      8341
#define kNtErrorDsDsaMustBeIntMaster                                8342
#define kNtErrorDsClassNotDsa                                       8343
#define kNtErrorDsInsuffAccessRights                                8344
#define kNtErrorDsIllegalSuperior                                   8345
#define kNtErrorDsAttributeOwnedBySam                               8346
#define kNtErrorDsNameTooManyParts                                  8347
#define kNtErrorDsNameTooLong                                       8348
#define kNtErrorDsNameValueTooLong                                  8349
#define kNtErrorDsNameUnparseable                                   8350
#define kNtErrorDsNameTypeUnknown                                   8351
#define kNtErrorDsNotAnObject                                       8352
#define kNtErrorDsSecDescTooShort                                   8353
#define kNtErrorDsSecDescInvalid                                    8354
#define kNtErrorDsNoDeletedName                                     8355
#define kNtErrorDsSubrefMustHaveParent                              8356
#define kNtErrorDsNcnameMustBeNc                                    8357
#define kNtErrorDsCantAddSystemOnly                                 8358
#define kNtErrorDsClassMustBeConcrete                               8359
#define kNtErrorDsInvalidDmd                                        8360
#define kNtErrorDsObjGuidExists                                     8361
#define kNtErrorDsNotOnBacklink                                     8362
#define kNtErrorDsNoCrossrefForNc                                   8363
#define kNtErrorDsShuttingDown                                      8364
#define kNtErrorDsUnknownOperation                                  8365
#define kNtErrorDsInvalidRoleOwner                                  8366
#define kNtErrorDsCouldntContactFsmo                                8367
#define kNtErrorDsCrossNcDnRename                                   8368
#define kNtErrorDsCantModSystemOnly                                 8369
#define kNtErrorDsReplicatorOnly                                    8370
#define kNtErrorDsObjClassNotDefined                                8371
#define kNtErrorDsObjClassNotSubclass                               8372
#define kNtErrorDsNameReferenceInvalid                              8373
#define kNtErrorDsCrossRefExists                                    8374
#define kNtErrorDsCantDelMasterCrossref                             8375
#define kNtErrorDsSubtreeNotifyNotNcHead                            8376
#define kNtErrorDsNotifyFilterTooComplex                            8377
#define kNtErrorDsDupRdn                                            8378
#define kNtErrorDsDupOid                                            8379
#define kNtErrorDsDupMapiId                                         8380
#define kNtErrorDsDupSchemaIdGuid                                   8381
#define kNtErrorDsDupLdapDisplayName                                8382
#define kNtErrorDsSemanticAttTest                                   8383
#define kNtErrorDsSyntaxMismatch                                    8384
#define kNtErrorDsExistsInMustHave                                  8385
#define kNtErrorDsExistsInMayHave                                   8386
#define kNtErrorDsNonexistentMayHave                                8387
#define kNtErrorDsNonexistentMustHave                               8388
#define kNtErrorDsAuxClsTestFail                                    8389
#define kNtErrorDsNonexistentPossSup                                8390
#define kNtErrorDsSubClsTestFail                                    8391
#define kNtErrorDsBadRdnAttIdSyntax                                 8392
#define kNtErrorDsExistsInAuxCls                                    8393
#define kNtErrorDsExistsInSubCls                                    8394
#define kNtErrorDsExistsInPossSup                                   8395
#define kNtErrorDsRecalcschemaFailed                                8396
#define kNtErrorDsTreeDeleteNotFinished                             8397
#define kNtErrorDsCantDelete                                        8398
#define kNtErrorDsAttSchemaReqId                                    8399
#define kNtErrorDsBadAttSchemaSyntax                                8400
#define kNtErrorDsCantCacheAtt                                      8401
#define kNtErrorDsCantCacheClass                                    8402
#define kNtErrorDsCantRemoveAttCache                                8403
#define kNtErrorDsCantRemoveClassCache                              8404
#define kNtErrorDsCantRetrieveDn                                    8405
#define kNtErrorDsMissingSupref                                     8406
#define kNtErrorDsCantRetrieveInstance                              8407
#define kNtErrorDsCodeInconsistency                                 8408
#define kNtErrorDsDatabaseError                                     8409
#define kNtErrorDsGovernsidMissing                                  8410
#define kNtErrorDsMissingExpectedAtt                                8411
#define kNtErrorDsNcnameMissingCrRef                                8412
#define kNtErrorDsSecurityCheckingError                             8413
#define kNtErrorDsSchemaNotLoaded                                   8414
#define kNtErrorDsSchemaAllocFailed                                 8415
#define kNtErrorDsAttSchemaReqSyntax                                8416
#define kNtErrorDsGcverifyError                                     8417
#define kNtErrorDsDraSchemaMismatch                                 8418
#define kNtErrorDsCantFindDsaObj                                    8419
#define kNtErrorDsCantFindExpectedNc                                8420
#define kNtErrorDsCantFindNcInCache                                 8421
#define kNtErrorDsCantRetrieveChild                                 8422
#define kNtErrorDsSecurityIllegalModify                             8423
#define kNtErrorDsCantReplaceHiddenRec                              8424
#define kNtErrorDsBadHierarchyFile                                  8425
#define kNtErrorDsBuildHierarchyTableFailed                         8426
#define kNtErrorDsConfigParamMissing                                8427
#define kNtErrorDsCountingAbIndicesFailed                           8428
#define kNtErrorDsHierarchyTableMallocFailed                        8429
#define kNtErrorDsInternalFailure                                   8430
#define kNtErrorDsUnknownError                                      8431
#define kNtErrorDsRootRequiresClassTop                              8432
#define kNtErrorDsRefusingFsmoRoles                                 8433
#define kNtErrorDsMissingFsmoSettings                               8434
#define kNtErrorDsUnableToSurrenderRoles                            8435
#define kNtErrorDsDraGeneric                                        8436
#define kNtErrorDsDraInvalidParameter                               8437
#define kNtErrorDsDraBusy                                           8438
#define kNtErrorDsDraBadDn                                          8439
#define kNtErrorDsDraBadNc                                          8440
#define kNtErrorDsDraDnExists                                       8441
#define kNtErrorDsDraInternalError                                  8442
#define kNtErrorDsDraInconsistentDit                                8443
#define kNtErrorDsDraConnectionFailed                               8444
#define kNtErrorDsDraBadInstanceType                                8445
#define kNtErrorDsDraOutOfMem                                       8446
#define kNtErrorDsDraMailProblem                                    8447
#define kNtErrorDsDraRefAlreadyExists                               8448
#define kNtErrorDsDraRefNotFound                                    8449
#define kNtErrorDsDraObjIsRepSource                                 8450
#define kNtErrorDsDraDbError                                        8451
#define kNtErrorDsDraNoReplica                                      8452
#define kNtErrorDsDraAccessDenied                                   8453
#define kNtErrorDsDraNotSupported                                   8454
#define kNtErrorDsDraRpcCancelled                                   8455
#define kNtErrorDsDraSourceDisabled                                 8456
#define kNtErrorDsDraSinkDisabled                                   8457
#define kNtErrorDsDraNameCollision                                  8458
#define kNtErrorDsDraSourceReinstalled                              8459
#define kNtErrorDsDraMissingParent                                  8460
#define kNtErrorDsDraPreempted                                      8461
#define kNtErrorDsDraAbandonSync                                    8462
#define kNtErrorDsDraShutdown                                       8463
#define kNtErrorDsDraIncompatiblePartialSet                         8464
#define kNtErrorDsDraSourceIsPartialReplica                         8465
#define kNtErrorDsDraExtnConnectionFailed                           8466
#define kNtErrorDsInstallSchemaMismatch                             8467
#define kNtErrorDsDupLinkId                                         8468
#define kNtErrorDsNameErrorResolving                                8469
#define kNtErrorDsNameErrorNotFound                                 8470
#define kNtErrorDsNameErrorNotUnique                                8471
#define kNtErrorDsNameErrorNoMapping                                8472
#define kNtErrorDsNameErrorDomainOnly                               8473
#define kNtErrorDsNameErrorNoSyntacticalMapping                     8474
#define kNtErrorDsConstructedAttMod                                 8475
#define kNtErrorDsWrongOmObjClass                                   8476
#define kNtErrorDsDraReplPending                                    8477
#define kNtErrorDsDsRequired                                        8478
#define kNtErrorDsInvalidLdapDisplayName                            8479
#define kNtErrorDsNonBaseSearch                                     8480
#define kNtErrorDsCantRetrieveAtts                                  8481
#define kNtErrorDsBacklinkWithoutLink                               8482
#define kNtErrorDsEpochMismatch                                     8483
#define kNtErrorDsSrcNameMismatch                                   8484
#define kNtErrorDsSrcAndDstNcIdentical                              8485
#define kNtErrorDsDstNcMismatch                                     8486
#define kNtErrorDsNotAuthoritiveForDstNc                            8487
#define kNtErrorDsSrcGuidMismatch                                   8488
#define kNtErrorDsCantMoveDeletedObject                             8489
#define kNtErrorDsPdcOperationInProgress                            8490
#define kNtErrorDsCrossDomainCleanupReqd                            8491
#define kNtErrorDsIllegalXdomMoveOperation                          8492
#define kNtErrorDsCantWithAcctGroupMembershps                       8493
#define kNtErrorDsNcMustHaveNcParent                                8494
#define kNtErrorDsCrImpossibleToValidate                            8495
#define kNtErrorDsDstDomainNotNative                                8496
#define kNtErrorDsMissingInfrastructureContainer                    8497
#define kNtErrorDsCantMoveAccountGroup                              8498
#define kNtErrorDsCantMoveResourceGroup                             8499
#define kNtErrorDsInvalidSearchFlag                                 8500
#define kNtErrorDsNoTreeDeleteAboveNc                               8501
#define kNtErrorDsCouldntLockTreeForDelete                          8502
#define kNtErrorDsCouldntIdentifyObjectsForTreeDelete               8503
#define kNtErrorDsSamInitFailure                                    8504
#define kNtErrorDsSensitiveGroupViolation                           8505
#define kNtErrorDsCantModPrimarygroupid                             8506
#define kNtErrorDsIllegalBaseSchemaMod                              8507
#define kNtErrorDsNonsafeSchemaChange                               8508
#define kNtErrorDsSchemaUpdateDisallowed                            8509
#define kNtErrorDsCantCreateUnderSchema                             8510
#define kNtErrorDsInstallNoSrcSchVersion                            8511
#define kNtErrorDsInstallNoSchVersionInInifile                      8512
#define kNtErrorDsInvalidGroupType                                  8513
#define kNtErrorDsNoNestGlobalgroupInMixeddomain                    8514
#define kNtErrorDsNoNestLocalgroupInMixeddomain                     8515
#define kNtErrorDsGlobalCantHaveLocalMember                         8516
#define kNtErrorDsGlobalCantHaveUniversalMember                     8517
#define kNtErrorDsUniversalCantHaveLocalMember                      8518
#define kNtErrorDsGlobalCantHaveCrossdomainMember                   8519
#define kNtErrorDsLocalCantHaveCrossdomainLocalMember               8520
#define kNtErrorDsHavePrimaryMembers                                8521
#define kNtErrorDsStringSdConversionFailed                          8522
#define kNtErrorDsNamingMasterGc                                    8523
#define kNtErrorDsDnsLookupFailure                                  8524
#define kNtErrorDsCouldntUpdateSpns                                 8525
#define kNtErrorDsCantRetrieveSd                                    8526
#define kNtErrorDsKeyNotUnique                                      8527
#define kNtErrorDsWrongLinkedAttSyntax                              8528
#define kNtErrorDsSamNeedBootkeyPassword                            8529
#define kNtErrorDsSamNeedBootkeyFloppy                              8530
#define kNtErrorDsCantStart                                         8531
#define kNtErrorDsInitFailure                                       8532
#define kNtErrorDsNoPktPrivacyOnConnection                          8533
#define kNtErrorDsSourceDomainInForest                              8534
#define kNtErrorDsDestinationDomainNotInForest                      8535
#define kNtErrorDsDestinationAuditingNotEnabled                     8536
#define kNtErrorDsCantFindDcForSrcDomain                            8537
#define kNtErrorDsSrcObjNotGroupOrUser                              8538
#define kNtErrorDsSrcSidExistsInForest                              8539
#define kNtErrorDsSrcAndDstObjectClassMismatch                      8540
#define kNtErrorSamInitFailure                                      8541
#define kNtErrorDsDraSchemaInfoShip                                 8542
#define kNtErrorDsDraSchemaConflict                                 8543
#define kNtErrorDsDraEarlierSchemaConflict                          8544
#define kNtErrorDsDraObjNcMismatch                                  8545
#define kNtErrorDsNcStillHasDsas                                    8546
#define kNtErrorDsGcRequired                                        8547
#define kNtErrorDsLocalMemberOfLocalOnly                            8548
#define kNtErrorDsNoFpoInUniversalGroups                            8549
#define kNtErrorDsCantAddToGc                                       8550
#define kNtErrorDsNoCheckpointWithPdc                               8551
#define kNtErrorDsSourceAuditingNotEnabled                          8552
#define kNtErrorDsCantCreateInNondomainNc                           8553
#define kNtErrorDsInvalidNameForSpn                                 8554
#define kNtErrorDsFilterUsesContructedAttrs                         8555
#define kNtErrorDsUnicodepwdNotInQuotes                             8556
#define kNtErrorDsMachineAccountQuotaExceeded                       8557
#define kNtErrorDsMustBeRunOnDstDc                                  8558
#define kNtErrorDsSrcDcMustBeSp4OrGreater                           8559
#define kNtErrorDsCantTreeDeleteCriticalObj                         8560
#define kNtErrorDsInitFailureConsole                                8561
#define kNtErrorDsSamInitFailureConsole                             8562
#define kNtErrorDsForestVersionTooHigh                              8563
#define kNtErrorDsDomainVersionTooHigh                              8564
#define kNtErrorDsForestVersionTooLow                               8565
#define kNtErrorDsDomainVersionTooLow                               8566
#define kNtErrorDsIncompatibleVersion                               8567
#define kNtErrorDsLowDsaVersion                                     8568
#define kNtErrorDsNoBehaviorVersionInMixeddomain                    8569
#define kNtErrorDsNotSupportedSortOrder                             8570
#define kNtErrorDsNameNotUnique                                     8571
#define kNtErrorDsMachineAccountCreatedPrent4                       8572
#define kNtErrorDsOutOfVersionStore                                 8573
#define kNtErrorDsIncompatibleControlsUsed                          8574
#define kNtErrorDsNoRefDomain                                       8575
#define kNtErrorDsReservedLinkId                                    8576
#define kNtErrorDsLinkIdNotAvailable                                8577
#define kNtErrorDsAgCantHaveUniversalMember                         8578
#define kNtErrorDsModifydnDisallowedByInstanceType                  8579
#define kNtErrorDsNoObjectMoveInSchemaNc                            8580
#define kNtErrorDsModifydnDisallowedByFlag                          8581
#define kNtErrorDsModifydnWrongGrandparent                          8582
#define kNtErrorDsNameErrorTrustReferral                            8583
#define kNtErrorNotSupportedOnStandardServer                        8584
#define kNtErrorDsCantAccessRemotePartOfAd                          8585
#define kNtErrorDsCrImpossibleToValidateV2                          8586
#define kNtErrorDsThreadLimitExceeded                               8587
#define kNtErrorDsNotClosest                                        8588
#define kNtErrorDsCantDeriveSpnWithoutServerRef                     8589
#define kNtErrorDsSingleUserModeFailed                              8590
#define kNtErrorDsNtdscriptSyntaxError                              8591
#define kNtErrorDsNtdscriptProcessError                             8592
#define kNtErrorDsDifferentReplEpochs                               8593
#define kNtErrorDsDrsExtensionsChanged                              8594
#define kNtErrorDsReplicaSetChangeNotAllowedOnDisabledCr            8595
#define kNtErrorDsNoMsdsIntid                                       8596
#define kNtErrorDsDupMsdsIntid                                      8597
#define kNtErrorDsExistsInRdnattid                                  8598
#define kNtErrorDsAuthorizationFailed                               8599
#define kNtErrorDsInvalidScript                                     8600
#define kNtErrorDsRemoteCrossrefOpFailed                            8601
#define kNtErrorDsCrossRefBusy                                      8602
#define kNtErrorDsCantDeriveSpnForDeletedDomain                     8603
#define kNtErrorDsCantDemoteWithWriteableNc                         8604
#define kNtErrorDsDuplicateIdFound                                  8605
#define kNtErrorDsInsufficientAttrToCreateObject                    8606
#define kNtErrorDsGroupConversionError                              8607
#define kNtErrorDsCantMoveAppBasicGroup                             8608
#define kNtErrorDsCantMoveAppQueryGroup                             8609
#define kNtErrorDsRoleNotVerified                                   8610
#define kNtErrorDsWkoContainerCannotBeSpecial                       8611
#define kNtErrorDsDomainRenameInProgress                            8612
#define kNtErrorDsExistingAdChildNc                                 8613
#define kNtErrorDsReplLifetimeExceeded                              8614
#define kNtErrorDsDisallowedInSystemContainer                       8615
#define kNtErrorDsLdapSendQueueFull                                 8616
#define kNtErrorDsDraOutScheduleWindow                              8617
#define kNtErrorDsPolicyNotKnown                                    8618
#define kNtErrorNoSiteSettingsObject                                8619
#define kNtErrorNoSecrets                                           8620
#define kNtErrorNoWritableDcFound                                   8621
#define kNtErrorDsNoServerObject                                    8622
#define kNtErrorDsNoNtdsaObject                                     8623
#define kNtErrorDsNonAsqSearch                                      8624
#define kNtErrorDsAuditFailure                                      8625
#define kNtErrorDsInvalidSearchFlagSubtree                          8626
#define kNtErrorDsInvalidSearchFlagTuple                            8627
#define kNtErrorDsHierarchyTableTooDeep                             8628
#define kNtErrorDsDraCorruptUtdVector                               8629
#define kNtErrorDsDraSecretsDenied                                  8630
#define kNtErrorDsReservedMapiId                                    8631
#define kNtErrorDsMapiIdNotAvailable                                8632
#define kNtErrorDsDraMissingKrbtgtSecret                            8633
#define kNtErrorDsDomainNameExistsInForest                          8634
#define kNtErrorDsFlatNameExistsInForest                            8635
#define kNtErrorInvalidUserPrincipalName                            8636
#define kNtErrorDsOidMappedGroupCantHaveMembers                     8637
#define kNtErrorDsOidNotFound                                       8638
#define kNtErrorDsDraRecycledTarget                                 8639
#define kNtErrorDsDisallowedNcRedirect                              8640
#define kNtErrorDsHighAdldsFfl                                      8641
#define kNtErrorDsHighDsaVersion                                    8642
#define kNtErrorDsLowAdldsFfl                                       8643
#define kNtErrorDomainSidSameAsLocalWorkstation                     8644
#define kNtErrorDsUndeleteSamValidationFailed                       8645
#define kNtErrorIncorrectAccountType                                8646
#define kNtErrorDsSpnValueNotUniqueInForest                         8647
#define kNtErrorDsUpnValueNotUniqueInForest                         8648
#define kNtErrorDsMissingForestTrust                                8649
#define kNtErrorDsValueKeyNotUnique                                 8650
#define kNtErrorIpsecQmPolicyExists                                 13000
#define kNtErrorIpsecQmPolicyNotFound                               13001
#define kNtErrorIpsecQmPolicyInUse                                  13002
#define kNtErrorIpsecMmPolicyExists                                 13003
#define kNtErrorIpsecMmPolicyNotFound                               13004
#define kNtErrorIpsecMmPolicyInUse                                  13005
#define kNtErrorIpsecMmFilterExists                                 13006
#define kNtErrorIpsecMmFilterNotFound                               13007
#define kNtErrorIpsecTransportFilterExists                          13008
#define kNtErrorIpsecTransportFilterNotFound                        13009
#define kNtErrorIpsecMmAuthExists                                   13010
#define kNtErrorIpsecMmAuthNotFound                                 13011
#define kNtErrorIpsecMmAuthInUse                                    13012
#define kNtErrorIpsecDefaultMmPolicyNotFound                        13013
#define kNtErrorIpsecDefaultMmAuthNotFound                          13014
#define kNtErrorIpsecDefaultQmPolicyNotFound                        13015
#define kNtErrorIpsecTunnelFilterExists                             13016
#define kNtErrorIpsecTunnelFilterNotFound                           13017
#define kNtErrorIpsecMmFilterPendingDeletion                        13018
#define kNtErrorIpsecTransportFilterPendingDeletion                 13019
#define kNtErrorIpsecTunnelFilterPendingDeletion                    13020
#define kNtErrorIpsecMmPolicyPendingDeletion                        13021
#define kNtErrorIpsecMmAuthPendingDeletion                          13022
#define kNtErrorIpsecQmPolicyPendingDeletion                        13023
#define kNtErrorIpsecIkeNegStatusBegin                              13800
#define kNtErrorIpsecIkeAuthFail                                    13801
#define kNtErrorIpsecIkeAttribFail                                  13802
#define kNtErrorIpsecIkeNegotiationPending                          13803
#define kNtErrorIpsecIkeGeneralProcessingError                      13804
#define kNtErrorIpsecIkeTimedOut                                    13805
#define kNtErrorIpsecIkeNoCert                                      13806
#define kNtErrorIpsecIkeSaDeleted                                   13807
#define kNtErrorIpsecIkeSaReaped                                    13808
#define kNtErrorIpsecIkeMmAcquireDrop                               13809
#define kNtErrorIpsecIkeQmAcquireDrop                               13810
#define kNtErrorIpsecIkeQueueDropMm                                 13811
#define kNtErrorIpsecIkeQueueDropNoMm                               13812
#define kNtErrorIpsecIkeDropNoResponse                              13813
#define kNtErrorIpsecIkeMmDelayDrop                                 13814
#define kNtErrorIpsecIkeQmDelayDrop                                 13815
#define kNtErrorIpsecIkeError                                       13816
#define kNtErrorIpsecIkeCrlFailed                                   13817
#define kNtErrorIpsecIkeInvalidKeyUsage                             13818
#define kNtErrorIpsecIkeInvalidCertType                             13819
#define kNtErrorIpsecIkeNoPrivateKey                                13820
#define kNtErrorIpsecIkeSimultaneousRekey                           13821
#define kNtErrorIpsecIkeDhFail                                      13822
#define kNtErrorIpsecIkeCriticalPayloadNotRecognized                13823
#define kNtErrorIpsecIkeInvalidHeader                               13824
#define kNtErrorIpsecIkeNoPolicy                                    13825
#define kNtErrorIpsecIkeInvalidSignature                            13826
#define kNtErrorIpsecIkeKerberosError                               13827
#define kNtErrorIpsecIkeNoPublicKey                                 13828
#define kNtErrorIpsecIkeProcessErr                                  13829
#define kNtErrorIpsecIkeProcessErrSa                                13830
#define kNtErrorIpsecIkeProcessErrProp                              13831
#define kNtErrorIpsecIkeProcessErrTrans                             13832
#define kNtErrorIpsecIkeProcessErrKe                                13833
#define kNtErrorIpsecIkeProcessErrId                                13834
#define kNtErrorIpsecIkeProcessErrCert                              13835
#define kNtErrorIpsecIkeProcessErrCertReq                           13836
#define kNtErrorIpsecIkeProcessErrHash                              13837
#define kNtErrorIpsecIkeProcessErrSig                               13838
#define kNtErrorIpsecIkeProcessErrNonce                             13839
#define kNtErrorIpsecIkeProcessErrNotify                            13840
#define kNtErrorIpsecIkeProcessErrDelete                            13841
#define kNtErrorIpsecIkeProcessErrVendor                            13842
#define kNtErrorIpsecIkeInvalidPayload                              13843
#define kNtErrorIpsecIkeLoadSoftSa                                  13844
#define kNtErrorIpsecIkeSoftSaTornDown                              13845
#define kNtErrorIpsecIkeInvalidCookie                               13846
#define kNtErrorIpsecIkeNoPeerCert                                  13847
#define kNtErrorIpsecIkePeerCrlFailed                               13848
#define kNtErrorIpsecIkePolicyChange                                13849
#define kNtErrorIpsecIkeNoMmPolicy                                  13850
#define kNtErrorIpsecIkeNotcbpriv                                   13851
#define kNtErrorIpsecIkeSecloadfail                                 13852
#define kNtErrorIpsecIkeFailsspinit                                 13853
#define kNtErrorIpsecIkeFailqueryssp                                13854
#define kNtErrorIpsecIkeSrvacqfail                                  13855
#define kNtErrorIpsecIkeSrvquerycred                                13856
#define kNtErrorIpsecIkeGetspifail                                  13857
#define kNtErrorIpsecIkeInvalidFilter                               13858
#define kNtErrorIpsecIkeOutOfMemory                                 13859
#define kNtErrorIpsecIkeAddUpdateKeyFailed                          13860
#define kNtErrorIpsecIkeInvalidPolicy                               13861
#define kNtErrorIpsecIkeUnknownDoi                                  13862
#define kNtErrorIpsecIkeInvalidSituation                            13863
#define kNtErrorIpsecIkeDhFailure                                   13864
#define kNtErrorIpsecIkeInvalidGroup                                13865
#define kNtErrorIpsecIkeEncrypt                                     13866
#define kNtErrorIpsecIkeDecrypt                                     13867
#define kNtErrorIpsecIkePolicyMatch                                 13868
#define kNtErrorIpsecIkeUnsupportedId                               13869
#define kNtErrorIpsecIkeInvalidHash                                 13870
#define kNtErrorIpsecIkeInvalidHashAlg                              13871
#define kNtErrorIpsecIkeInvalidHashSize                             13872
#define kNtErrorIpsecIkeInvalidEncryptAlg                           13873
#define kNtErrorIpsecIkeInvalidAuthAlg                              13874
#define kNtErrorIpsecIkeInvalidSig                                  13875
#define kNtErrorIpsecIkeLoadFailed                                  13876
#define kNtErrorIpsecIkeRpcDelete                                   13877
#define kNtErrorIpsecIkeBenignReinit                                13878
#define kNtErrorIpsecIkeInvalidResponderLifetimeNotify              13879
#define kNtErrorIpsecIkeInvalidMajorVersion                         13880
#define kNtErrorIpsecIkeInvalidCertKeylen                           13881
#define kNtErrorIpsecIkeMmLimit                                     13882
#define kNtErrorIpsecIkeNegotiationDisabled                         13883
#define kNtErrorIpsecIkeQmLimit                                     13884
#define kNtErrorIpsecIkeMmExpired                                   13885
#define kNtErrorIpsecIkePeerMmAssumedInvalid                        13886
#define kNtErrorIpsecIkeCertChainPolicyMismatch                     13887
#define kNtErrorIpsecIkeUnexpectedMessageId                         13888
#define kNtErrorIpsecIkeInvalidAuthPayload                          13889
#define kNtErrorIpsecIkeDosCookieSent                               13890
#define kNtErrorIpsecIkeShuttingDown                                13891
#define kNtErrorIpsecIkeCgaAuthFailed                               13892
#define kNtErrorIpsecIkeProcessErrNatoa                             13893
#define kNtErrorIpsecIkeInvalidMmForQm                              13894
#define kNtErrorIpsecIkeQmExpired                                   13895
#define kNtErrorIpsecIkeTooManyFilters                              13896
#define kNtErrorIpsecIkeNegStatusEnd                                13897
#define kNtErrorIpsecIkeKillDummyNapTunnel                          13898
#define kNtErrorIpsecIkeInnerIpAssignmentFailure                    13899
#define kNtErrorIpsecIkeRequireCpPayloadMissing                     13900
#define kNtErrorIpsecKeyModuleImpersonationNegotiationPending       13901
#define kNtErrorIpsecIkeCoexistenceSuppress                         13902
#define kNtErrorIpsecIkeRatelimitDrop                               13903
#define kNtErrorIpsecIkePeerDoesntSupportMobike                     13904
#define kNtErrorIpsecIkeAuthorizationFailure                        13905
#define kNtErrorIpsecIkeStrongCredAuthorizationFailure              13906
#define kNtErrorIpsecIkeAuthorizationFailureWithOptionalRetry       13907
#define kNtErrorIpsecIkeStrongCredAuthorizationAndCertmapFailure    13908
#define kNtErrorIpsecIkeNegStatusExtendedEnd                        13909
#define kNtErrorIpsecBadSpi                                         13910
#define kNtErrorIpsecSaLifetimeExpired                              13911
#define kNtErrorIpsecWrongSa                                        13912
#define kNtErrorIpsecReplayCheckFailed                              13913
#define kNtErrorIpsecInvalidPacket                                  13914
#define kNtErrorIpsecIntegrityCheckFailed                           13915
#define kNtErrorIpsecClearTextDrop                                  13916
#define kNtErrorIpsecAuthFirewallDrop                               13917
#define kNtErrorIpsecThrottleDrop                                   13918
#define kNtErrorIpsecDospBlock                                      13925
#define kNtErrorIpsecDospReceivedMulticast                          13926
#define kNtErrorIpsecDospInvalidPacket                              13927
#define kNtErrorIpsecDospStateLookupFailed                          13928
#define kNtErrorIpsecDospMaxEntries                                 13929
#define kNtErrorIpsecDospKeymodNotAllowed                           13930
#define kNtErrorIpsecDospNotInstalled                               13931
#define kNtErrorIpsecDospMaxPerIpRatelimitQueues                    13932
#define kNtErrorSxsSectionNotFound                                  14000
#define kNtErrorSxsCantGenActctx                                    14001
#define kNtErrorSxsInvalidActctxdataFormat                          14002
#define kNtErrorSxsAssemblyNotFound                                 14003
#define kNtErrorSxsManifestFormatError                              14004
#define kNtErrorSxsManifestParseError                               14005
#define kNtErrorSxsActivationContextDisabled                        14006
#define kNtErrorSxsKeyNotFound                                      14007
#define kNtErrorSxsVersionConflict                                  14008
#define kNtErrorSxsWrongSectionType                                 14009
#define kNtErrorSxsThreadQueriesDisabled                            14010
#define kNtErrorSxsProcessDefaultAlreadySet                         14011
#define kNtErrorSxsUnknownEncodingGroup                             14012
#define kNtErrorSxsUnknownEncoding                                  14013
#define kNtErrorSxsInvalidXmlNamespaceUri                           14014
#define kNtErrorSxsRootManifestDependencyNotInstalled               14015
#define kNtErrorSxsLeafManifestDependencyNotInstalled               14016
#define kNtErrorSxsInvalidAssemblyIdentityAttribute                 14017
#define kNtErrorSxsManifestMissingRequiredDefaultNamespace          14018
#define kNtErrorSxsManifestInvalidRequiredDefaultNamespace          14019
#define kNtErrorSxsPrivateManifestCrossPathWithReparsePoint         14020
#define kNtErrorSxsDuplicateDllName                                 14021
#define kNtErrorSxsDuplicateWindowclassName                         14022
#define kNtErrorSxsDuplicateClsid                                   14023
#define kNtErrorSxsDuplicateIid                                     14024
#define kNtErrorSxsDuplicateTlbid                                   14025
#define kNtErrorSxsDuplicateProgid                                  14026
#define kNtErrorSxsDuplicateAssemblyName                            14027
#define kNtErrorSxsFileHashMismatch                                 14028
#define kNtErrorSxsPolicyParseError                                 14029
#define kNtErrorSxsXmlEMissingquote                                 14030
#define kNtErrorSxsXmlECommentsyntax                                14031
#define kNtErrorSxsXmlEBadstartnamechar                             14032
#define kNtErrorSxsXmlEBadnamechar                                  14033
#define kNtErrorSxsXmlEBadcharinstring                              14034
#define kNtErrorSxsXmlEXmldeclsyntax                                14035
#define kNtErrorSxsXmlEBadchardata                                  14036
#define kNtErrorSxsXmlEMissingwhitespace                            14037
#define kNtErrorSxsXmlEExpectingtagend                              14038
#define kNtErrorSxsXmlEMissingsemicolon                             14039
#define kNtErrorSxsXmlEUnbalancedparen                              14040
#define kNtErrorSxsXmlEInternalerror                                14041
#define kNtErrorSxsXmlEUnexpectedWhitespace                         14042
#define kNtErrorSxsXmlEIncompleteEncoding                           14043
#define kNtErrorSxsXmlEMissingParen                                 14044
#define kNtErrorSxsXmlEExpectingclosequote                          14045
#define kNtErrorSxsXmlEMultipleColons                               14046
#define kNtErrorSxsXmlEInvalidDecimal                               14047
#define kNtErrorSxsXmlEInvalidHexidecimal                           14048
#define kNtErrorSxsXmlEInvalidUnicode                               14049
#define kNtErrorSxsXmlEWhitespaceorquestionmark                     14050
#define kNtErrorSxsXmlEUnexpectedendtag                             14051
#define kNtErrorSxsXmlEUnclosedtag                                  14052
#define kNtErrorSxsXmlEDuplicateattribute                           14053
#define kNtErrorSxsXmlEMultipleroots                                14054
#define kNtErrorSxsXmlEInvalidatrootlevel                           14055
#define kNtErrorSxsXmlEBadxmldecl                                   14056
#define kNtErrorSxsXmlEMissingroot                                  14057
#define kNtErrorSxsXmlEUnexpectedeof                                14058
#define kNtErrorSxsXmlEBadperefinsubset                             14059
#define kNtErrorSxsXmlEUnclosedstarttag                             14060
#define kNtErrorSxsXmlEUnclosedendtag                               14061
#define kNtErrorSxsXmlEUnclosedstring                               14062
#define kNtErrorSxsXmlEUnclosedcomment                              14063
#define kNtErrorSxsXmlEUncloseddecl                                 14064
#define kNtErrorSxsXmlEUnclosedcdata                                14065
#define kNtErrorSxsXmlEReservednamespace                            14066
#define kNtErrorSxsXmlEInvalidencoding                              14067
#define kNtErrorSxsXmlEInvalidswitch                                14068
#define kNtErrorSxsXmlEBadxmlcase                                   14069
#define kNtErrorSxsXmlEInvalidStandalone                            14070
#define kNtErrorSxsXmlEUnexpectedStandalone                         14071
#define kNtErrorSxsXmlEInvalidVersion                               14072
#define kNtErrorSxsXmlEMissingequals                                14073
#define kNtErrorSxsProtectionRecoveryFailed                         14074
#define kNtErrorSxsProtectionPublicKeyTooShort                      14075
#define kNtErrorSxsProtectionCatalogNotValid                        14076
#define kNtErrorSxsUntranslatableHresult                            14077
#define kNtErrorSxsProtectionCatalogFileMissing                     14078
#define kNtErrorSxsMissingAssemblyIdentityAttribute                 14079
#define kNtErrorSxsInvalidAssemblyIdentityAttributeName             14080
#define kNtErrorSxsAssemblyMissing                                  14081
#define kNtErrorSxsCorruptActivationStack                           14082
#define kNtErrorSxsCorruption                                       14083
#define kNtErrorSxsEarlyDeactivation                                14084
#define kNtErrorSxsInvalidDeactivation                              14085
#define kNtErrorSxsMultipleDeactivation                             14086
#define kNtErrorSxsProcessTerminationRequested                      14087
#define kNtErrorSxsReleaseActivationContext                         14088
#define kNtErrorSxsSystemDefaultActivationContextEmpty              14089
#define kNtErrorSxsInvalidIdentityAttributeValue                    14090
#define kNtErrorSxsInvalidIdentityAttributeName                     14091
#define kNtErrorSxsIdentityDuplicateAttribute                       14092
#define kNtErrorSxsIdentityParseError                               14093
#define kNtErrorMalformedSubstitutionString                         14094
#define kNtErrorSxsIncorrectPublicKeyToken                          14095
#define kNtErrorUnmappedSubstitutionString                          14096
#define kNtErrorSxsAssemblyNotLocked                                14097
#define kNtErrorSxsComponentStoreCorrupt                            14098
#define kNtErrorAdvancedInstallerFailed                             14099
#define kNtErrorXmlEncodingMismatch                                 14100
#define kNtErrorSxsManifestIdentitySameButContentsDifferent         14101
#define kNtErrorSxsIdentitiesDifferent                              14102
#define kNtErrorSxsAssemblyIsNotADeployment                         14103
#define kNtErrorSxsFileNotPartOfAssembly                            14104
#define kNtErrorSxsManifestTooBig                                   14105
#define kNtErrorSxsSettingNotRegistered                             14106
#define kNtErrorSxsTransactionClosureIncomplete                     14107
#define kNtErrorSmiPrimitiveInstallerFailed                         14108
#define kNtErrorGenericCommandFailed                                14109
#define kNtErrorSxsFileHashMissing                                  14110
#define kNtErrorEvtInvalidChannelPath                               15000
#define kNtErrorEvtInvalidQuery                                     15001
#define kNtErrorEvtPublisherMetadataNotFound                        15002
#define kNtErrorEvtEventTemplateNotFound                            15003
#define kNtErrorEvtInvalidPublisherName                             15004
#define kNtErrorEvtInvalidEventData                                 15005
#define kNtErrorEvtChannelNotFound                                  15007
#define kNtErrorEvtMalformedXmlText                                 15008
#define kNtErrorEvtSubscriptionToDirectChannel                      15009
#define kNtErrorEvtConfigurationError                               15010
#define kNtErrorEvtQueryResultStale                                 15011
#define kNtErrorEvtQueryResultInvalidPosition                       15012
#define kNtErrorEvtNonValidatingMsxml                               15013
#define kNtErrorEvtFilterAlreadyscoped                              15014
#define kNtErrorEvtFilterNoteltset                                  15015
#define kNtErrorEvtFilterInvarg                                     15016
#define kNtErrorEvtFilterInvtest                                    15017
#define kNtErrorEvtFilterInvtype                                    15018
#define kNtErrorEvtFilterParseerr                                   15019
#define kNtErrorEvtFilterUnsupportedop                              15020
#define kNtErrorEvtFilterUnexpectedtoken                            15021
#define kNtErrorEvtInvalidOperationOverEnabledDirectChannel         15022
#define kNtErrorEvtInvalidChannelPropertyValue                      15023
#define kNtErrorEvtInvalidPublisherPropertyValue                    15024
#define kNtErrorEvtChannelCannotActivate                            15025
#define kNtErrorEvtFilterTooComplex                                 15026
#define kNtErrorEvtMessageNotFound                                  15027
#define kNtErrorEvtMessageIdNotFound                                15028
#define kNtErrorEvtUnresolvedValueInsert                            15029
#define kNtErrorEvtUnresolvedParameterInsert                        15030
#define kNtErrorEvtMaxInsertsReached                                15031
#define kNtErrorEvtEventDefinitionNotFound                          15032
#define kNtErrorEvtMessageLocaleNotFound                            15033
#define kNtErrorEvtVersionTooOld                                    15034
#define kNtErrorEvtVersionTooNew                                    15035
#define kNtErrorEvtCannotOpenChannelOfQuery                         15036
#define kNtErrorEvtPublisherDisabled                                15037
#define kNtErrorEvtFilterOutOfRange                                 15038
#define kNtErrorEcSubscriptionCannotActivate                        15080
#define kNtErrorEcLogDisabled                                       15081
#define kNtErrorEcCircularForwarding                                15082
#define kNtErrorEcCredstoreFull                                     15083
#define kNtErrorEcCredNotFound                                      15084
#define kNtErrorEcNoActiveChannel                                   15085
#define kNtErrorMuiFileNotFound                                     15100
#define kNtErrorMuiInvalidFile                                      15101
#define kNtErrorMuiInvalidRcConfig                                  15102
#define kNtErrorMuiInvalidLocaleName                                15103
#define kNtErrorMuiInvalidUltimatefallbackName                      15104
#define kNtErrorMuiFileNotLoaded                                    15105
#define kNtErrorResourceEnumUserStop                                15106
#define kNtErrorMuiIntlsettingsUilangNotInstalled                   15107
#define kNtErrorMuiIntlsettingsInvalidLocaleName                    15108
#define kNtErrorMrmRuntimeNoDefaultOrNeutralResource                15110
#define kNtErrorMrmInvalidPriconfig                                 15111
#define kNtErrorMrmInvalidFileType                                  15112
#define kNtErrorMrmUnknownQualifier                                 15113
#define kNtErrorMrmInvalidQualifierValue                            15114
#define kNtErrorMrmNoCandidate                                      15115
#define kNtErrorMrmNoMatchOrDefaultCandidate                        15116
#define kNtErrorMrmResourceTypeMismatch                             15117
#define kNtErrorMrmDuplicateMapName                                 15118
#define kNtErrorMrmDuplicateEntry                                   15119
#define kNtErrorMrmInvalidResourceIdentifier                        15120
#define kNtErrorMrmFilepathTooLong                                  15121
#define kNtErrorMrmUnsupportedDirectoryType                         15122
#define kNtErrorMrmInvalidPriFile                                   15126
#define kNtErrorMrmNamedResourceNotFound                            15127
#define kNtErrorMrmMapNotFound                                      15135
#define kNtErrorMrmUnsupportedProfileType                           15136
#define kNtErrorMrmInvalidQualifierOperator                         15137
#define kNtErrorMrmIndeterminateQualifierValue                      15138
#define kNtErrorMrmAutomergeEnabled                                 15139
#define kNtErrorMrmTooManyResources                                 15140
#define kNtErrorMrmUnsupportedFileTypeForMerge                      15141
#define kNtErrorMrmUnsupportedFileTypeForLoadUnloadPriFile          15142
#define kNtErrorMrmNoCurrentViewOnThread                            15143
#define kNtErrorDifferentProfileResourceManagerExist                15144
#define kNtErrorOperationNotAllowedFromSystemComponent              15145
#define kNtErrorMrmDirectRefToNonDefaultResource                    15146
#define kNtErrorMrmGenerationCountMismatch                          15147
#define kNtErrorPriMergeVersionMismatch                             15148
#define kNtErrorPriMergeMissingSchema                               15149
#define kNtErrorPriMergeLoadFileFailed                              15150
#define kNtErrorPriMergeAddFileFailed                               15151
#define kNtErrorPriMergeWriteFileFailed                             15152
#define kNtErrorPriMergeMultiplePackageFamiliesNotAllowed           15153
#define kNtErrorPriMergeMultipleMainPackagesNotAllowed              15154
#define kNtErrorPriMergeBundlePackagesNotAllowed                    15155
#define kNtErrorPriMergeMainPackageRequired                         15156
#define kNtErrorPriMergeResourcePackageRequired                     15157
#define kNtErrorPriMergeInvalidFileName                             15158
#define kNtErrorMcaInvalidCapabilitiesString                        15200
#define kNtErrorMcaInvalidVcpVersion                                15201
#define kNtErrorMcaMonitorViolatesMccsSpecification                 15202
#define kNtErrorMcaMccsVersionMismatch                              15203
#define kNtErrorMcaUnsupportedMccsVersion                           15204
#define kNtErrorMcaInternalError                                    15205
#define kNtErrorMcaInvalidTechnologyTypeReturned                    15206
#define kNtErrorMcaUnsupportedColorTemperature                      15207
#define kNtErrorAmbiguousSystemDevice                               15250
#define kNtErrorSystemDeviceNotFound                                15299
#define kNtErrorHashNotSupported                                    15300
#define kNtErrorHashNotPresent                                      15301
#define kNtErrorSecondaryIcProviderNotRegistered                    15321
#define kNtErrorGpioClientInformationInvalid                        15322
#define kNtErrorGpioVersionNotSupported                             15323
#define kNtErrorGpioInvalidRegistrationPacket                       15324
#define kNtErrorGpioOperationDenied                                 15325
#define kNtErrorGpioIncompatibleConnectMode                         15326
#define kNtErrorGpioInterruptAlreadyUnmasked                        15327
#define kNtErrorCannotSwitchRunlevel                                15400
#define kNtErrorInvalidRunlevelSetting                              15401
#define kNtErrorRunlevelSwitchTimeout                               15402
#define kNtErrorRunlevelSwitchAgentTimeout                          15403
#define kNtErrorRunlevelSwitchInProgress                            15404
#define kNtErrorServicesFailedAutostart                             15405
#define kNtErrorComTaskStopPending                                  15501
#define kNtErrorInstallOpenPackageFailed                            15600
#define kNtErrorInstallPackageNotFound                              15601
#define kNtErrorInstallInvalidPackage                               15602
#define kNtErrorInstallResolveDependencyFailed                      15603
#define kNtErrorInstallOutOfDiskSpace                               15604
#define kNtErrorInstallNetworkFailure                               15605
#define kNtErrorInstallRegistrationFailure                          15606
#define kNtErrorInstallDeregistrationFailure                        15607
#define kNtErrorInstallCancel                                       15608
#define kNtErrorInstallFailed                                       15609
#define kNtErrorRemoveFailed                                        15610
#define kNtErrorPackageAlreadyExists                                15611
#define kNtErrorNeedsRemediation                                    15612
#define kNtErrorInstallPrerequisiteFailed                           15613
#define kNtErrorPackageRepositoryCorrupted                          15614
#define kNtErrorInstallPolicyFailure                                15615
#define kNtErrorPackageUpdating                                     15616
#define kNtErrorDeploymentBlockedByPolicy                           15617
#define kNtErrorPackagesInUse                                       15618
#define kNtErrorRecoveryFileCorrupt                                 15619
#define kNtErrorInvalidStagedSignature                              15620
#define kNtErrorDeletingExistingApplicationdataStoreFailed          15621
#define kNtErrorInstallPackageDowngrade                             15622
#define kNtErrorSystemNeedsRemediation                              15623
#define kNtErrorAppxIntegrityFailureClrNgen                         15624
#define kNtErrorResiliencyFileCorrupt                               15625
#define kNtErrorInstallFirewallServiceNotRunning                    15626
#define kNtErrorPackageMoveFailed                                   15627
#define kNtErrorInstallVolumeNotEmpty                               15628
#define kNtErrorInstallVolumeOffline                                15629
#define kNtErrorInstallVolumeCorrupt                                15630
#define kNtErrorNeedsRegistration                                   15631
#define kNtErrorInstallWrongProcessorArchitecture                   15632
#define kNtErrorDevSideloadLimitExceeded                            15633
#define kNtErrorInstallOptionalPackageRequiresMainPackage           15634
#define kNtErrorPackageNotSupportedOnFilesystem                     15635
#define kNtErrorPackageMoveBlockedByStreaming                       15636
#define kNtErrorInstallOptionalPackageApplicationidNotUnique        15637
#define kNtErrorPackageStagingOnhold                                15638
#define kNtErrorInstallInvalidRelatedSetUpdate                      15639
#define kNtErrorPackagesReputationCheckFailed                       15643
#define kNtErrorPackagesReputationCheckTimedout                     15644
#define kNtErrorStateLoadStoreFailed                                15800
#define kNtErrorStateGetVersionFailed                               15801
#define kNtErrorStateSetVersionFailed                               15802
#define kNtErrorStateStructuredResetFailed                          15803
#define kNtErrorStateOpenContainerFailed                            15804
#define kNtErrorStateCreateContainerFailed                          15805
#define kNtErrorStateDeleteContainerFailed                          15806
#define kNtErrorStateReadSettingFailed                              15807
#define kNtErrorStateWriteSettingFailed                             15808
#define kNtErrorStateDeleteSettingFailed                            15809
#define kNtErrorStateQuerySettingFailed                             15810
#define kNtErrorStateReadCompositeSettingFailed                     15811
#define kNtErrorStateWriteCompositeSettingFailed                    15812
#define kNtErrorStateEnumerateContainerFailed                       15813
#define kNtErrorStateEnumerateSettingsFailed                        15814
#define kNtErrorStateCompositeSettingValueSizeLimitExceeded         15815
#define kNtErrorStateSettingValueSizeLimitExceeded                  15816
#define kNtErrorStateSettingNameSizeLimitExceeded                   15817
#define kNtErrorStateContainerNameSizeLimitExceeded                 15818
#define kNtErrorApiUnavailable                                      15841 /* EPROCUNAVAIL */

#define kNtWaitIoCompletion 0xc0

/* WinSock Error Codes: 10000-11999 */
#define WSABASEERR                  10000
#define WSAEINTR                    10004
#define WSAEBADF                    10009
#define WSAEACCES                   10013
#define WSAEFAULT                   10014
#define WSAEINVAL                   10022
#define WSAEMFILE                   10024
#define WSAEWOULDBLOCK              10035
#define WSAEINPROGRESS              10036
#define WSAEALREADY                 10037
#define WSAENOTSOCK                 10038
#define WSAEDESTADDRREQ             10039
#define WSAEMSGSIZE                 10040
#define WSAEPROTOTYPE               10041
#define WSAENOPROTOOPT              10042
#define WSAEPROTONOSUPPORT          10043
#define WSAESOCKTNOSUPPORT          10044
#define WSAEOPNOTSUPP               10045
#define WSAEPFNOSUPPORT             10046
#define WSAEAFNOSUPPORT             10047
#define WSAEADDRINUSE               10048
#define WSAEADDRNOTAVAIL            10049
#define WSAENETDOWN                 10050
#define WSAENETUNREACH              10051
#define WSAENETRESET                10052
#define WSAECONNABORTED             10053
#define WSAECONNRESET               10054
#define WSAENOBUFS                  10055
#define WSAEISCONN                  10056
#define WSAENOTCONN                 10057
#define WSAESHUTDOWN                10058
#define WSAETOOMANYREFS             10059
#define WSAETIMEDOUT                10060
#define WSAECONNREFUSED             10061
#define WSAELOOP                    10062
#define WSAENAMETOOLONG             10063
#define WSAEHOSTDOWN                10064
#define WSAEHOSTUNREACH             10065
#define WSAENOTEMPTY                10066
#define WSAEPROCLIM                 10067
#define WSAEUSERS                   10068
#define WSAEDQUOT                   10069
#define WSAESTALE                   10070
#define WSAEREMOTE                  10071
#define WSASYSNOTREADY              10091
#define WSAVERNOTSUPPORTED          10092
#define WSANOTINITIALISED           10093
#define WSAEDISCON                  10101
#define WSAENOMORE                  10102
#define WSAECANCELLED               10103
#define WSAEINVALIDPROCTABLE        10104
#define WSAEINVALIDPROVIDER         10105
#define WSAEPROVIDERFAILEDINIT      10106
#define WSASYSCALLFAILURE           10107
#define WSASERVICE_NOT_FOUND        10108
#define WSATYPE_NOT_FOUND           10109
#define WSA_E_NO_MORE               10110
#define WSA_E_CANCELLED             10111
#define WSAEREFUSED                 10112
#define WSAHOST_NOT_FOUND           11001
#define WSATRY_AGAIN                11002
#define WSANO_RECOVERY              11003
#define WSANO_DATA                  11004
#define WSA_QOS_RECEIVERS           11005
#define WSA_QOS_SENDERS             11006
#define WSA_QOS_NO_SENDERS          11007
#define WSA_QOS_NO_RECEIVERS        11008
#define WSA_QOS_REQUEST_CONFIRMED   11009
#define WSA_QOS_ADMISSION_FAILURE   11010
#define WSA_QOS_POLICY_FAILURE      11011
#define WSA_QOS_BAD_STYLE           11012
#define WSA_QOS_BAD_OBJECT          11013
#define WSA_QOS_TRAFFIC_CTRL_ERROR  11014
#define WSA_QOS_GENERIC_ERROR       11015
#define WSA_QOS_ESERVICETYPE        11016
#define WSA_QOS_EFLOWSPEC           11017
#define WSA_QOS_EPROVSPECBUF        11018
#define WSA_QOS_EFILTERSTYLE        11019
#define WSA_QOS_EFILTERTYPE         11020
#define WSA_QOS_EFILTERCOUNT        11021
#define WSA_QOS_EOBJLENGTH          11022
#define WSA_QOS_EFLOWCOUNT          11023
#define WSA_QOS_EUNKOWNPSOBJ        11024
#define WSA_QOS_EPOLICYOBJ          11025
#define WSA_QOS_EFLOWDESC           11026
#define WSA_QOS_EPSFLOWSPEC         11027
#define WSA_QOS_EPSFILTERSPEC       11028
#define WSA_QOS_ESDMODEOBJ          11029
#define WSA_QOS_ESHAPERATEOBJ       11030
#define WSA_QOS_RESERVED_PETYPE     11031
#define WSA_SECURE_HOST_NOT_FOUND   11032
#define WSA_IPSEC_NAME_POLICY_ERROR 11033

#define WSA_WAIT_FAILED         -1u
#define WSA_WAIT_EVENT_0        0
#define WSA_WAIT_IO_COMPLETION  0xc0
#define WSA_WAIT_TIMEOUT        258
#define WSA_MAXIMUM_WAIT_EVENTS 64
#define WSA_IO_PENDING          997


#define kNtWsaInvalidHandle    kNtErrorInvalidHandle
#define kNtWsaNotEnoughMemory  kNtErrorNotEnoughMemory
#define kNtWsaInvalidParameter kNtErrorInvalidParameter
#define kNtWsaIoPending        kNtErrorIoPending
#define kNtWsaIoIncomplete     kNtErrorIoIncomplete
#define kNtWsaOperationAborted kNtErrorOperationAborted



/*!BEGIN libc/nt/enum/wsaid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSAID_H_
COSMOPOLITAN_C_START_

#define WSAID_WSAPOLL                                \
  {                                                  \
    0x18C76F85, 0xDC66, 0x4964, {                    \
      0x97, 0x2E, 0x23, 0xC2, 0x72, 0x38, 0x31, 0x2B \
    }                                                \
  }

#define WSAID_WSARECVMSG                             \
  {                                                  \
    0xf689d7c8, 0x6f1f, 0x436b, {                    \
      0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22 \
    }                                                \
  }

#define WSAID_WSASENDMSG                             \
  {                                                  \
    0xa441e712, 0x754f, 0x43ca, {                    \
      0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d \
    }                                                \
  }

#define WSAID_CONNECTEX                              \
  {                                                  \
    0x25a207b9, 0xddf3, 0x4660, {                    \
      0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e \
    }                                                \
  }

#define WSAID_ACCEPTEX                               \
  {                                                  \
    0xb5367df1, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_GETACCEPTEXSOCKADDRS                   \
  {                                                  \
    0xb5367df2, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITFILE                           \
  {                                                  \
    0xb5367df0, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITPACKETS                        \
  {                                                  \
    0xd9689da0, 0x1f90, 0x11d3, {                    \
      0x99, 0x71, 0x00, 0xc0, 0x4f, 0x68, 0xc8, 0x76 \
    }                                                \
  }

#define WSAID_DISCONNECTEX                           \
  {                                                  \
    0x7fda2e11, 0x8630, 0x436f, {                    \
      0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57 \
    }                                                \
  }

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/wt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WT_H_

#define kNtWtExecutedefault            0x00000000u
#define kNtWtExecuteonlyonce           0x00000008u
#define kNtWtExecuteintimerthread      0x00000020u
#define kNtWtExecuteinpersistentthread 0x00000080u
#define kNtWtExecutelongfunction       0x00000010u
#define kNtWtTransferImpersonation     0𝔵00000100𝔲



/*!BEGIN libc/nt/struct/acl.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ACL_H_

struct NtAcl {
  uint8_t AclRevision;
  uint8_t Sbz1;
  uint16_t AclSize;
  uint16_t AceCount;
  uint16_t Sbz2;
};



/*!BEGIN libc/nt/struct/afd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_AFD_H_
COSMOPOLITAN_C_START_

struct NtAfdPollHandleInfo {
  int64_t Handle;
  uint32_t Events;
  NtStatus Status;
};

struct NtAfdPollInfo {
  int64_t Timeout;
  uint32_t NumberOfHandles;
  uint32_t Exclusive;
  struct NtAfdPollHandleInfo Handles[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ansistring.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ANSISTRING_H_

struct NtAnsiString {
  unsigned short Length;
  unsigned short MaximumLength;
  char *Buffer;
};



/*!BEGIN libc/nt/struct/byhandlefileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_BYHANDLEFILEINFORMATION_H_


/*!BEGIN libc/nt/struct/filetime.h */

#define COSMOPOLITAN_LIBC_NT_FILETIME_H_

struct NtFileTime {
  uint32_t dwLowDateTime;
  uint32_t dwHighDateTime;
};


struct NtByHandleFileInformation {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationFileTime;
  struct NtFileTime ftLastAccessFileTime;
  struct NtFileTime ftLastWriteFileTime;
  uint32_t dwVolumeSerialNumber;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t nNumberOfLinks;
  uint32_t nFileIndexHigh;
  uint32_t nFileIndexLow;
};



/*!BEGIN libc/nt/struct/charinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CHARINFO_H_

struct NtCharInfo {
  union {
    char16_t UnicodeChar;
    char AsciiChar;
  } Char;
  uint16_t Attributes;
};



/*!BEGIN libc/nt/struct/clientid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CLIENTID_H_

struct NtClientId {
  void *UniqueProcess;
  void *UniqueThread;
};



/*!BEGIN libc/nt/struct/consolecursorinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLECURSORINFO_H_

struct NtConsoleCursorInfo {
  uint32_t dwSize;
  bool32 bVisible;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFO_H_


/*!BEGIN libc/nt/struct/coord.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COORD_H_

struct NtCoord {
  int16_t X;
  int16_t Y;
};



/*!BEGIN libc/nt/struct/smallrect.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SMALLRECT_H_

struct NtSmallRect {
  int16_t Left;
  int16_t Top;
  int16_t Right;
  int16_t Bottom;
};


struct NtConsoleScreenBufferInfo {
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes;
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFOEX_H_

struct NtConsoleScreenBufferInfoEx {
  uint32_t cbSize; /* sizeof(struct NtConsoleScreenBufferInfoEx) */
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes; /* kNt{Foreground,Background}... */
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
  uint16_t wPopupAttributes;
  bool32 bFullscreenSupported;
  uint32_t ColorTable[16]; /* 0x00BBGGRR */
};



/*!BEGIN libc/nt/struct/consoleselectioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESELECTIONINFO_H_

struct NtConsoleSelectionInfo {
  uint32_t dwFlags;
  struct NtCoord dwSelectionAnchor;
  struct NtSmallRect srSelection;
};



/*!BEGIN libc/nt/struct/context.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONTEXT_H_

struct NtM128A {
  uint64_t Low;
  int64_t High;
};

struct NtXmmSaveArea32 { /* basically same as struct FpuState */
  uint16_t ControlWord;
  uint16_t StatusWord;
  uint8_t TagWord;
  uint8_t Reserved1;
  uint16_t ErrorOpcode;
  uint32_t ErrorOffset;
  uint16_t ErrorSelector;
  uint16_t Reserved2;
  uint32_t DataOffset;
  uint16_t DataSelector;
  uint16_t Reserved3;
  uint32_t MxCsr;
  uint32_t MxCsr_Mask;
  struct NtM128A FloatRegisters[8];
  struct NtM128A XmmRegisters[16];
  uint8_t Reserved4[96];
};

struct NtContext {
  uint64_t P1Home, P2Home, P3Home, P4Home, P5Home, P6Home;
  uint32_t ContextFlags;
  uint32_t MxCsr;
  uint16_t SegCs, SegDs, SegEs, SegFs, SegGs, SegSs;
  uint32_t EFlags;
  uint64_t Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
  uint64_t Rax, Rcx, Rdx, Rbx, Rsp, Rbp, Rsi, Rdi;
  uint64_t R8, R9, R10, R11, R12, R13, R14, R15;
  uint64_t Rip;
  union {
    struct NtXmmSaveArea32 FltSave;
    struct NtXmmSaveArea32 FloatSave;
    struct {
      struct NtM128A Header[2];
      struct NtM128A Legacy[8];
      struct NtM128A Xmm0, Xmm1, Xmm2, Xmm3, Xmm4, Xmm5, Xmm6, Xmm7;
      struct NtM128A Xmm8, Xmm9, Xmm10, Xmm11, Xmm12, Xmm13, Xmm14, Xmm15;
    };
  };
  struct NtM128A VectorRegister[26];
  uint64_t VectorControl;
  uint64_t DebugControl;
  uint64_t LastBranchToRip;
  uint64_t LastBranchFromRip;
  uint64_t LastExceptionToRip;
  uint64_t LastExceptionFromRip;
} forcealign(16);



/*!BEGIN libc/nt/struct/criticalsection.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTION_H_


/*!BEGIN libc/nt/struct/criticalsectiondebug.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTIONDEBUG_H_


/*!BEGIN libc/nt/struct/linkedlist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINKEDLIST_H_

/**
 * Dynamic linked list overlay.
 */
struct NtLinkedList {
  struct NtLinkedList *Next;
  struct NtLinkedList *Prev;
};


struct NtCriticalSectionDebug {
  uint16_t Type;
  uint16_t CreatorBackTraceIndex;
  struct NtCriticalSection *CriticalSection;
  struct NtLinkedList ProcessLocksList;
  uint32_t EntryCount;
  uint32_t ContentionCount;
  uint32_t Spare[2];
};


struct NtCriticalSection {
  struct NtCriticalSectionDebug *DebugInfo;
  int32_t LockCount;
  int32_t RecursionCount;
  void *OwningThread;
  void *LockSemaphore;
  uintptr_t SpinCount;
};



/*!BEGIN libc/nt/struct/drawtextparams.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DRAWTEXTPARAMS_H_
COSMOPOLITAN_C_START_

struct NtDrawTextParams {
  uint32_t cbSize;
  int32_t iTabLength;
  int32_t iLeftMargin;
  int32_t iRightMargin;
  uint32_t uiLengthDrawn;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/dynamictimezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DYNAMICTIMEZONEINFORMATION_H_


/*!BEGIN libc/nt/struct/systemtime.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIME_H_

struct NtSystemTime {
  uint16_t wYear;
  uint16_t wMonth;
  uint16_t wDayOfWeek;
  uint16_t wDay;
  uint16_t wHour;
  uint16_t wMinute;
  uint16_t wSecond;
  uint16_t wMilliseconds;
};


struct NtDynamicTimeZoneInformation {
  int32_t Bias;
  char16_t StandardName[32];
  struct NtSystemTime StandardDate;
  int32_t StandardBias;
  char16_t DaylightName[32];
  struct NtSystemTime DaylightDate;
  int32_t DaylightBias;
  char16_t TimeZoneKeyName[128];
  bool32 DynamicDaylightTimeDisabled;
};



/*!BEGIN libc/nt/struct/editmenu.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EDITMENU_H_

struct NtEditMenu {
  int64_t hmenu;
  uint16_t idEdit;
  uint16_t idCut;
  uint16_t idCopy;
  uint16_t idPaste;
  uint16_t idClear;
  uint16_t idUndo;
};



/*!BEGIN libc/nt/struct/exceptionframe.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EXCEPTIONFRAME_H_

struct NtExceptionFrame {
  struct NtExceptionFrame *Prev;
};



/*!BEGIN libc/nt/struct/fdset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FDSET_H_
COSMOPOLITAN_C_START_

struct NtFdSet {
  uint32_t fd_count;
  int64_t fd_array[64];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/fileaccessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEACCESSINFORMATION_H_

struct NtFileAccessInformation {
  uint32_t AccessFlags;
};



/*!BEGIN libc/nt/struct/filealignmentinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALIGNMENTINFORMATION_H_

struct NtFileAlignmentInformation {
  uint32_t AlignmentRequirement;
};



/*!BEGIN libc/nt/struct/fileallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLINFORMATION_H_


/*!BEGIN libc/nt/struct/filebasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFORMATION_H_

struct NtFileBasicInformation {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/fileeainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEEAINFORMATION_H_

struct NtFileEaInformation {
  uint32_t EaSize;
};



/*!BEGIN libc/nt/struct/fileinternalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEINTERNALINFORMATION_H_

struct NtFileInternalInformation {
  int64_t IndexNumber;
};



/*!BEGIN libc/nt/struct/filemodeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMODEINFORMATION_H_

struct NtFileModeInformation {
  uint32_t Mode;
};



/*!BEGIN libc/nt/struct/filenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMEINFORMATION_H_

struct NtFileNameInformation {
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filepositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPOSITIONINFORMATION_H_

struct NtFilePositionInformation {
  int64_t CurrentByteOffset;
};



/*!BEGIN libc/nt/struct/filestandardinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTANDARDINFORMATION_H_

struct NtFileStandardInformation {
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t NumberOfLinks;
  bool32 DeletePending;
  bool32 Directory;
};


struct NtFileAllInformation {
  struct NtFileBasicInformation BasicInformation;
  struct NtFileStandardInformation StandardInformation;
  struct NtFileInternalInformation InternalInformation;
  struct NtFileEaInformation EaInformation;
  struct NtFileAccessInformation AccessInformation;
  struct NtFilePositionInformation PositionInformation;
  struct NtFileModeInformation ModeInformation;
  struct NtFileAlignmentInformation AlignmentInformation;
  struct NtFileNameInformation NameInformation;
};



/*!BEGIN libc/nt/struct/fileallocationinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLOCATIONINFORMATION_H_

struct NtFileAllocationInformation {
  int64_t AllocationSize;
};



/*!BEGIN libc/nt/struct/fileattributetaginformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEATTRIBUTETAGINFORMATION_H_

struct NtFileAttributeTagInformation {
  uint32_t FileAttributes;
  uint32_t ReparseTag;
};



/*!BEGIN libc/nt/struct/filebasicinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFO_H_

struct NtFileBasicInfo {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/filebothdirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBOTHDIRECTORYINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileBothDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  unsigned char ShortNameLength;
  char16_t ShortName[12];
  char16_t FileName[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filecompressioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILECOMPRESSIONINFO_H_

struct NtFileCompressionInfo {
  int64_t CompressedFileSize;
  uint16_t CompressionFormat;
  uint8_t CompressionUnitShift;
  uint8_t ChunkShift;
  uint8_t ClusterShift;
  uint8_t Reserved[3];
};



/*!BEGIN libc/nt/struct/filedirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDIRECTORYINFORMATION_H_

struct NtFileDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filedispositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDISPOSITIONINFORMATION_H_

struct NtFileDispositionInformation {
  bool32 DoDeleteFile;
};



/*!BEGIN libc/nt/struct/fileendoffileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEENDOFFILEINFORMATION_H_

struct FileEndOfFileInformation {
  int64_t EndOfFile;
};



/*!BEGIN libc/nt/struct/filefsfullsizeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFSFULLSIZEINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileFsFullSizeInformation {
  int64_t TotalAllocationUnits;
  int64_t CallerAvailableAllocationUnits;
  int64_t ActualAvailableAllocationUnits;
  uint32_t SectorsPerAllocationUnit;
  uint32_t BytesPerSector;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filefulldirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLDIRECTORYINFORMATION_H_

struct NtFileFullDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filefulleainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLEAINFORMATION_H_

struct NtFileFullEaInformation {
  uint32_t NextEntryOffset;
  uint8_t Flags;
  uint8_t EaNameLength;
  uint16_t EaValueLength;
  char EaName[1];
};



/*!BEGIN libc/nt/struct/filemailslotqueryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTQUERYINFORMATION_H_

struct NtFileMailslotQueryInformation {
  uint32_t MaximumMessageSize;
  uint32_t MailslotQuota;
  uint32_t NextMessageSize;
  uint32_t MessagesAvailable;
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filemailslotsetinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTSETINFORMATION_H_

struct NtFileMailslotSetInformation {
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filenamesinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMESINFORMATION_H_

struct NtFileNamesInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filenetworkopeninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENETWORKOPENINFORMATION_H_

struct NtFileNetworkOpenInformation {
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t FileAttributes;
};



/*!BEGIN libc/nt/struct/filepipelocalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPIPELOCALINFORMATION_H_

struct NtFilePipeLocalInformation {
  uint32_t NamedPipeType;
  uint32_t NamedPipeConfiguration;
  uint32_t MaximumInstances;
  uint32_t CurrentInstances;
  uint32_t InboundQuota;
  uint32_t ReadDataAvailable;
  uint32_t OutboundQuota;
  uint32_t WriteQuotaAvailable;
  uint32_t NamedPipeState;
  uint32_t NamedPipeEnd;
};



/*!BEGIN libc/nt/struct/filerenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILERENAMEINFORMATION_H_

struct NtFileRenameInformation {
  bool32 Replace;
  void *RootDir;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filesegmentelement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESEGMENTELEMENT_H_

union NtFileSegmentElement {
  void *Buffer;
  uint64_t Alignment;
};



/*!BEGIN libc/nt/struct/filestreaminformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTREAMINFORMATION_H_

struct NtFileStreamInformation {
  uint32_t NextEntryOffset;
  uint32_t StreamNameLength;
  int64_t StreamSize;
  int64_t StreamAllocationSize;
  char16_t StreamName[1];
};



/*!BEGIN libc/nt/struct/filezerodatainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEZERODATAINFORMATION_H_

struct NtFileZeroDataInformation {
  uint64_t FileOffset;
  uint64_t BeyondFinalZero;
};



/*!BEGIN libc/nt/struct/fpodata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FPODATA_H_

struct NtFpoData {
  /* TODO(jart): No bitfields. */
  uint32_t ulOffStart;
  uint32_t cbProcSize;
  uint32_t cdwLocals;
  uint16_t cdwParams;
  uint16_t cbProlog : 8;
  uint16_t cbRegs : 3;
  uint16_t fHasSEH : 1;
  uint16_t fUseBP : 1;
  uint16_t reserved : 1;
  uint16_t cbFrame : 2;
};



/*!BEGIN libc/nt/struct/genericmapping.h */

#define COSMOPOLITAN_LIBC_NT_GENERICMAPPING_H_

struct NtGenericMapping {
  unsigned int GenericRead;
  unsigned int GenericWrite;
  unsigned int GenericExecute;
  unsigned int GenericAll;
};



/*!BEGIN libc/nt/struct/guid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_GUID_H_
COSMOPOLITAN_C_START_

struct NtGuid {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/inputrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_INPUTRECORD_H_

struct NtKeyEventRecord {
  bool32 bKeyDown;
  uint16_t wRepeatCount;
  uint16_t wVirtualKeyCode;
  uint16_t wVirtualScanCode;
  union {
    uint16_t UnicodeChar;
    char AsciiChar;
  } uChar;
  unsigned int dwControlKeyState;
#define kNtRightAltPressed  0x0001
#define kNtLeftAltPressed   0x0002
#define kNtRightCtrlPressed 0x0004
#define kNtLeftCtrlPressed  0x0008
#define kNtShiftPressed     0x0010
#define kNtNumlockOn        0x0020
#define kNtScrolllockOn     0x0040
#define kNtCapslockOn       0x0080
#define kNtEnhancedKey      0x0100
};

struct NtMouseEventRecord {
  struct NtCoord dwMousePosition;
  uint32_t dwButtonState;
#define kNtFromLeft1stButtonPressed 0x0001
#define kNtRightmostButtonPressed   0x0002
#define kNtFromLeft2ndButtonPressed 0x0004
#define kNtFromLeft3rdButtonPressed 0x0008
#define kNtFromLeft4thButtonPressed 0x0010
  uint32_t dwControlKeyState;
  uint32_t dwEventFlags;
#define kNtMouseMoved    0x0001
#define kNtDoubleClick   0x0002
#define kNtMouseWheeled  0x0004
#define kNtMouseHwheeled 0x0008
};

struct NtWindowBufferSizeRecord {
  struct NtCoord dwSize;
};

struct NtMenuEventRecord {
  uint32_t dwCommandId;
};

struct NtFocusEventRecord {
  bool32 bSetFocus;
};

struct NtInputRecord {
  uint16_t EventType;
#define kNtKeyEvent              0x0001
#define kNtMouseEvent            0x0002
#define kNtWindowBufferSizeEvent 0x0004
#define kNtMenuEvent             0x0008
#define kNtFocusEvent            0x0010
  union {
    struct NtKeyEventRecord KeyEvent;
    struct NtMouseEventRecord MouseEvent;
    struct NtWindowBufferSizeRecord WindowBufferSizeEvent;
    struct NtMenuEventRecord MenuEvent;
    struct NtFocusEventRecord FocusEvent;
  } Event;
};



/*!BEGIN libc/nt/struct/iocounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOCOUNTERS_H_

struct NtIoCounters {
  uint64_t ReadOperationCount;
  uint64_t WriteOperationCount;
  uint64_t OtherOperationCount;
  uint64_t ReadTransferCount;
  uint64_t WriteTransferCount;
  uint64_t OtherTransferCount;
};



/*!BEGIN libc/nt/struct/iostatusblock.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOSTATUSBLOCK_H_

struct NtIoStatusBlock {
  union {
    NtStatus Status;
    void *Pointer; /* reserved for internal use */
  };
  uint32_t *Information; /* request dependent */
};



/*!BEGIN libc/nt/struct/iovec.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct NtIovec {
  uint32_t len;
  char *buf;
};

void DescribeIovNt(const struct NtIovec *, uint32_t, ssize_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ipadapteraddresses.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IP_ADAPTER_ADDRESSES_H_


/*!BEGIN libc/nt/winsock.h */

#define COSMOPOLITAN_LIBC_NT_WINSOCK_H_


/*!BEGIN libc/nt/struct/overlapped.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPED_H_

struct NtOverlapped {
  uintptr_t Internal;
  uintptr_t InternalHigh;
  union {
    struct {
      uint32_t Offset;
      uint32_t OffsetHigh;
    };
    int64_t Pointer;
  };
  int64_t hEvent;
};



/*!BEGIN libc/nt/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POLLFD_H_

struct sys_pollfd_nt {
  int64_t handle;
  int16_t events;
  int16_t revents;
};



/*!BEGIN libc/nt/struct/timeval.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEVAL_H_
COSMOPOLITAN_C_START_

struct NtTimeval {
  int32_t tv_sec; /* [sic] */
  int32_t tv_usec;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thunk/msabi.h */

#define COSMOPOLITAN_LIBC_NT_THUNK_MSABI_H_
#ifdef __x86_64__

#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
     (__has_attribute(__ms_abi__) || defined(__llvm__)))
/**
 * Defines function as using Microsoft x64 calling convention.
 *
 * This can be used to define prototypes that allow modern compilers to
 * generate code that calls MS ABI functions directly, without needing
 * to jump through the assembly thunks.
 */
#define __msabi __attribute__((__ms_abi__))
#endif

/*
 * Returns true if header should provide MS-ABI overrides.
 */
#ifndef ShouldUseMsabiAttribute
#if defined(__msabi) && defined(NDEBUG) && !defined(__PG__) && !defined(FTRACE)
#define ShouldUseMsabiAttribute() 1
#else
#define ShouldUseMsabiAttribute() 0
#endif
#endif

#else
#define __msabi
#ifndef ShouldUseMsabiAttribute
#define ShouldUseMsabiAttribute() 0
#endif
#endif /* __x86_64__ */


/*!BEGIN libc/sock/sock.h */

#define COSMOPOLITAN_LIBC_SOCK_SOCK_H_
COSMOPOLITAN_C_START_

#define INET_ADDRSTRLEN 22
#define IFHWADDRLEN     6

libcesque uint16_t htons(uint16_t) pureconst;
libcesque uint16_t ntohs(uint16_t) pureconst;
libcesque uint32_t htonl(uint32_t) pureconst;
libcesque uint32_t ntohl(uint32_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define htons(x) __builtin_bswap16(x)
#define ntohs(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define ntohl(x) __builtin_bswap32(x)
#endif

const char *inet_ntop(int, const void *, char *, uint32_t) libcesque;
int inet_pton(int, const char *, void *) libcesque;
uint32_t inet_addr(const char *) libcesque;
libcesque uint32_t *GetHostIps(void) __wur;

int socket(int, int, int) libcesque;
int listen(int, int) libcesque;
int shutdown(int, int) libcesque;
ssize_t send(int, const void *, size_t, int) libcesque;
ssize_t recv(int, void *, size_t, int) libcesque;
ssize_t sendfile(int, int, int64_t *, size_t) libcesque;
int getsockopt(int, int, int, void *, uint32_t *) libcesque;
int setsockopt(int, int, int, const void *, uint32_t) libcesque;
int socketpair(int, int, int, int[2]) libcesque;
int sockatmark(int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/sockaddr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_H_
COSMOPOLITAN_C_START_

struct sockaddr {     /* Linux+NT ABI */
  uint16_t sa_family; /* AF_XXX */
  char sa_data[14];
};

struct in_addr { /* ARPA ABI */
  /* e.g. 127|0<<8|0<<16|1<<24 or inet_pton(AF_INET, "127.0.0.1", &s_addr) */
  uint32_t s_addr;
};

struct sockaddr_in {   /* Linux+NT ABI */
  uint16_t sin_family; /* AF_XXX */
  uint16_t sin_port;   /* htons(XXX) i.e. big endian */
  struct in_addr sin_addr;
  uint8_t sin_zero[8];
};

struct sockaddr_un {
  uint16_t sun_family; /* AF_UNIX */
  char sun_path[108];  /* path */
};

struct sockaddr_storage {
  union {
    uint16_t ss_family;
    intptr_t __ss_align;
    char __ss_storage[128];
  };
};

int inet_aton(const char *, struct in_addr *);
char *inet_ntoa(struct in_addr);
int accept(int, struct sockaddr *, uint32_t *);
int accept4(int, struct sockaddr *, uint32_t *, int);
int bind(int, const struct sockaddr *, uint32_t);
int connect(int, const struct sockaddr *, uint32_t);
int getsockname(int, struct sockaddr *, uint32_t *);
int getpeername(int, struct sockaddr *, uint32_t *);
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, uint32_t *);
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
               uint32_t);

COSMOPOLITAN_C_END_
/* ░▓█████████████████████████████████████████████▓▒
   ░█▓░░░░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒░
   ░█▓░ ░▒▒▒▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░ ░▓▓▓▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░       ░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒▒
   ░███████████████████████████████████████████████▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░          ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░             ▒█▓▒▒
   ░█▓░        ░▒░                 ▒█▓░          ▒█▓▒▒
   ░█▓░      ░░░░    ░░░░░░░░      ▒▓▓▓▒░        ▒█▓▒▒
   ░█▓░    ░░░░  ░░░░░▒▒▓███▓░░░░░░░░▒▓▓▓▓▒      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒████▓░░░░░░░░░░▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒▓▓▓▓▓░░░░░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▒▒▒░░░░░ ░▒▒▒▒░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓   ░▓█▓▒▒▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░░▒██▓   ░████▓▒░
   ░█▓░     ░░░░░░░░▒▒░░░░░░░░░▒▒░░░▒▒▓▓▒░░    ░░▓███▓▒░
   ░█▓░      ░░░░░░░░░░░░░░░░░░░░░░▒▓▓▓▒░        ▒████▓▒░░░░░░
   ░█▓░        ░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░        ░▓▓▓▓██▒░░░░░░░░
   ░█▓░          ▒█████████████████▒  ▓█▓▒░      ▒█▓ ░█▓      ░▓▓░
   ░█▓░                              ░▓████▒░    ▒█▓▒░  ░░░░░░░  ▓█▓░
   ░█▓░                                ░▓████▒░  ░▒░  ░░░░░░░░░░░  ░█▓
   ░█▓                                    ▒███▓▒▒░  ░░░░░░░░░░░░░░░  ▒▓▓
   ░██████████████████████████████████████▓▒▓█▓░  ░░░░░░░░░░░░░░░░░░ ▒█▓
    ▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░ ░░░░░░░░░░░░░░░░░░░░▒█▓
         ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒██▒▒▒░░░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░██▒▒▒▒▒░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░▒▓█▓
                                            ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░▒▒▒▒▓▓▒
                                              ░██▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  ░█▓
                                                 ▒█▓▒▒▒▒▒▒▒▒▒▒▒██▓▒░ ░█▓
                                                   ▒█████████████▓▒▒░  ░██▒
╔────────────────────────────────────────────────────────────────▀▀▀▀───▀▀▀▀─│─╗
│ cosmopolitan § new technology » winsock                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtWsaFlagOverlapped      0x01
#define kNtWsaFlagNoHandleInherit 0x80

#define kNtCompEqual   0
#define kNtCompNotless 1

#define kNtTfDisconnect       0x01
#define kNtTfReuseSocket      0x02
#define kNtTfWriteBehind      0x04
#define kNtTfUseDefaultWorker 0x00
#define kNtTfUseSystemThread  0x10
#define kNtTfUseKernelApc     0x20

#define kNtSoConnectTime          0x700C
#define kNtSoUpdateAcceptContext  0x700B
#define kNtSoUpdateConnectContext 0x7010

#define kNtNspNotifyImmediately 0
#define kNtNspNotifyHwnd        1
#define kNtNspNotifyEvent       2
#define kNtNspNotifyPort        3
#define kNtNspNotifyApc         4

COSMOPOLITAN_C_START_

struct NtMsgHdr {
  struct sockaddr *name;
  int32_t namelen;
  struct NtIovec *lpBuffers;
  uint32_t dwBufferCount;
  struct NtIovec Control;
  uint32_t dwFlags;
};

struct NtWsaData {
  uint16_t wVersion;
  uint16_t wHighVersion;
  uint16_t iMaxSockets;
  uint16_t iMaxUdpDg;
  char *lpVendorInfo;
  char szDescription[257];
  char szSystemStatus[129];
};

struct NtSocketAddress {
  struct sockaddr *lpSockaddr;
  int32_t iSockaddrLength;
};

struct NtSocketAddressList {
  int32_t iAddressCount;
  struct NtSocketAddress Address[1];
};

struct NtAddrInfoEx {  /* win8+ */
  int32_t ai_flags;    /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
  int32_t ai_family;   /* PF_XXX */
  int32_t ai_socktype; /* SOCK_XXX */
  int32_t ai_protocol;
  uint64_t ai_addrlen;
  char16_t *ai_canonname;
  struct sockaddr *ai_addr;
  void *ai_blob;
  uint64_t ai_bloblen;
  struct NtGuid *ai_provider;
  struct NtAddrInfoEx *ai_next;
  int32_t ai_version;          /* v2 */
  char16_t *ai_fqdn;           /* v2 */
  int32_t ai_interfaceindex;   /* v3 */
  int64_t ai_resolutionhandle; /* v4 */
};

struct NtWsaProtocolChain {
  int32_t ChainLen;
  uint32_t ChainEntries[7];
};

struct NtWsaProtocolInfo {
  uint32_t dwServiceFlags1;
  uint32_t dwServiceFlags2;
  uint32_t dwServiceFlags3;
  uint32_t dwServiceFlags4;
  uint32_t dwProviderFlags;
  struct NtGuid ProviderId;
  uint32_t dwCatalogEntryId;
  struct NtWsaProtocolChain ProtocolChain;
  int32_t iVersion;
  int32_t iAddressFamily;
  int32_t iMaxSockAddr;
  int32_t iMinSockAddr;
  int32_t iSocketType;
  int32_t iProtocol;
  int32_t iProtocolMaxOffset;
  int32_t iNetworkByteOrder;
  int32_t iSecurityScheme;
  uint32_t dwMessageSize;
  uint32_t dwProviderReserved;
  char16_t szProtocol[256];
};

struct NtFlowSpec {
  uint32_t TokenRate;          /* bytes/sec */
  uint32_t TokenBucketSize;    /* bytes */
  uint32_t PeakBandwidth;      /* bytes/sec */
  uint32_t Latency;            /* µs */
  uint32_t DelayVariation;     /* µs */
  uint32_t ServiceType;        /* kNtServicetypeXxx */
  uint32_t MaxSduSize;         /* bytes */
  uint32_t MinimumPolicedSize; /* bytes */
};

struct NtQos {
  struct NtFlowSpec SendingFlowspec;
  struct NtFlowSpec ReceivingFlowspec;
  struct NtIovec ProviderSpecific;
};

struct NtWsaVersion {
  uint32_t dwVersion;
  int ecHow;
};

struct NtAfProtocols {
  int32_t iAddressFamily;
  int32_t iProtocol;
};

struct NtBlob {
  uint32_t cbSize;
  uint8_t pBlobData;
};

struct NtCsAddrInfo {
  struct NtSocketAddress LocalAddr;
  struct NtSocketAddress RemoteAddr;
  int32_t iSocketType;
  int32_t iProtocol;
};

struct NtWsaQuerySet {
  uint32_t dwSize; /* of this */
  char16_t *lpszServiceInstanceName;
  struct NtGuid *lpServiceClassId;
  struct NtWsaVersion *lpVersion;
  char16_t *lpszComment;
  uint32_t dwNameSpace;
  struct NtGuid *lpNSProviderId;
  char16_t *lpszContext;
  uint32_t dwNumberOfProtocols;
  struct NtAfProtocols *lpafpProtocols /*[dwNumberOfProtocols]*/;
  char16_t *lpszQueryString;
  uint32_t dwNumberOfCsAddrs;
  struct NtCsAddrInfo *lpcsaBuffer /*[dwNumberOfCsAddrs]*/;
  uint32_t dwOutputFlags;
  struct NtBlob *lpBlob;
};

struct NtWsaNamespaceInfoEx {
  struct NtGuid NSProviderId;
  uint32_t dwNameSpace;
  bool32 fActive;
  uint32_t dwVersion;
  char16_t *lpszIdentifier;
  struct NtBlob *ProviderSpecific;
};

struct NtWsansClassInfo {
  char16_t *lpszName;
  uint32_t dwNameSpace;
  uint32_t dwValueType;
  uint32_t dwValueSize;
  void *lpValue;
};

struct NtWsaServiceClassInfo {
  struct NtGuid *lpServiceClassId;
  char16_t *lpszServiceClassName;
  uint32_t dwCount;
  struct NtWsansClassInfo *lpClassInfos;
};

struct NtWsaNetworkEvents {
  int32_t lNetworkEvents;
  int32_t iErrorCode[10];
};

struct NtTransmitFileBuffers {
  void *Head;
  uint32_t HeadLength;
  void *Tail;
  uint32_t TailLength;
};

typedef int (*NtConditionProc)(
    const struct NtIovec *lpCallerId, const struct NtIovec *lpCallerData,
    struct NtQos *inout_lpSQOS, struct NtQos *inout_lpGQOS,
    const struct NtIovec *lpCalleeId, const struct NtIovec *lpCalleeData,
    uint32_t *out_group, const uint32_t *dwCallbackData);

typedef void (*NtWsaOverlappedCompletionRoutine)(
    uint32_t dwError, uint32_t cbTransferred,
    const struct NtOverlapped *lpOverlapped, uint32_t dwFlags);

struct NtWsaCompletion {
  int Type;
  union {
    struct {
      int64_t hWnd;
      uint32_t uMsg;
      uintptr_t context;
    } WindowMessage;
    struct {
      struct NtOverlapped *lpOverlapped;
    } Event;
    struct {
      struct NtOverlapped *lpOverlapped;
      NtWsaOverlappedCompletionRoutine lpfnCompletionProc;
    } Apc;
    struct {
      struct NtOverlapped *lpOverlapped;
      int64_t hPort;
      uint32_t Key;
    } Port;
  } Parameters;
};

struct NtInterfaceInfo {
  uint64_t iiFlags;
  struct sockaddr_in iiAddress;
  struct sockaddr_in iiBroadcastAddress;
  struct sockaddr_in iiNetmask;
};

/**
 * Winsock2 prototypes.
 *
 * @note Some of the functions exported by WS2_32.DLL, e.g. bind(),
 *       overlap with the names used by System V. Prototypes for these
 *       functions are declared within their respective wrappers.
 */

int32_t WSAStartup(uint16_t wVersionRequested, struct NtWsaData *lpWSAData)
    paramsnonnull();

int WSACleanup(void);
int WSAGetLastError(void) nosideeffect;
void WSASetLastError(int);

int64_t __sys_socket_nt(int, int, int);
int __sys_bind_nt(uint64_t, const void *, int);
int __sys_closesocket_nt(uint64_t);
int __sys_getpeername_nt(uint64_t, void *, uint32_t *);
int __sys_getsockname_nt(uint64_t, void *, uint32_t *);
int __sys_getsockopt_nt(uint64_t, int, int, void *, uint32_t *);
int __sys_ioctlsocket_nt(uint64_t, int32_t, uint32_t *);
int __sys_listen_nt(uint64_t, int);
int __sys_setsockopt_nt(uint64_t, int, int, const void *, int);
int __sys_shutdown_nt(uint64_t, int);
int __sys_select_nt(int, struct NtFdSet *, struct NtFdSet *, struct NtFdSet *,
                    struct NtTimeval *);

uint64_t WSASocket(int af, int type, int protocol,
                   const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                   const uint32_t opt_group, uint32_t dwFlags) __wur;

int WSAConnect(uint64_t s, const struct sockaddr *name, const int namelen,
               const struct NtIovec *opt_lpCallerData,
               struct NtIovec *opt_out_lpCalleeData,
               const struct NtQos *opt_lpSQOS, const struct NtQos *opt_lpGQOS)
    paramsnonnull((2));

bool32 WSAConnectByName(uint64_t s, const char16_t *nodename,
                        const char16_t *servicename,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2, 3));

bool32 WSAConnectByList(uint64_t s,
                        const struct NtSocketAddressList *SocketAddress,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2));

int64_t WSAAccept(uint64_t s, struct sockaddr *out_addr,
                  int32_t *opt_inout_addrlen,
                  const NtConditionProc opt_lpfnCondition,
                  const uint32_t *opt_dwCallbackData) paramsnonnull((2)) __wur;

int WSASend(uint64_t s, const struct NtIovec *lpBuffers, uint32_t dwBufferCount,
            uint32_t *opt_out_lpNumberOfBytesSent, uint32_t dwFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendMsg(int64_t Handle, const struct NtMsgHdr *lpMsg, uint32_t dwFlags,
               uint32_t *opt_out_lpNumberOfBytesSent,
               struct NtOverlapped *opt_inout_lpOverlapped,
               const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendTo(uint64_t s, const struct NtIovec *lpBuffers,
              uint32_t dwBufferCount,
              uint32_t *opt_out_lpNumberOfBytesSent /* opt if !overlapped */,
              uint32_t dwFlags, const void *opt_tosockaddr,
              int32_t tosockaddrlen,
              struct NtOverlapped *opt_inout_lpOverlapped,
              const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSAPoll(struct sys_pollfd_nt *inout_fdArray, uint32_t nfds,
            signed timeout_ms) paramsnonnull();

int WSARecv(uint64_t s, const struct NtIovec *inout_lpBuffers,
            uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
            uint32_t *inout_lpFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvFrom(uint64_t s, const struct NtIovec *inout_lpBuffers,
                uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
                uint32_t *inout_lpFlags, void *out_fromsockaddr,
                uint32_t *opt_inout_fromsockaddrlen,
                struct NtOverlapped *opt_inout_lpOverlapped,
                const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvDisconnect(uint64_t s, struct NtIovec *out_InboundDisconnectData);
int WSASendDisconnect(int64_t s, struct NtIovec *opt_OutboundDisconnectData);

int WSADuplicateSocket(uint64_t s, uint32_t dwProcessId,
                       struct NtWsaProtocolInfo *out_lpProtocolInfo)
    paramsnonnull((3));

int WSAIoctl(uint64_t s, uint32_t dwIoControlCode, const void *lpvInBuffer,
             uint32_t cbInBuffer, void *out_lpvOutBuffer, uint32_t cbOutBuffer,
             uint32_t *out_lpcbBytesReturned,
             struct NtOverlapped *opt_inout_lpOverlapped,
             const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((5, 7));

int WSANSPIoctl(int64_t hLookup, uint32_t dwControlCode,
                const void *lpvInBuffer, uint32_t cbInBuffer,
                void *out_lpvOutBuffer, uint32_t cbOutBuffer,
                uint32_t *out_lpcbBytesReturned,
                const struct NtWsaCompletion *opt_lpCompletion)
    paramsnonnull((3, 5, 7));

int64_t WSACreateEvent(void) __wur;
bool32 WSACloseEvent(const int64_t hEvent);
bool32 WSAResetEvent(const int64_t hEvent);
bool32 WSASetEvent(const int64_t hEvent);

int WSAEventSelect(uint64_t s, const int64_t opt_hEventObject,
                   long lNetworkEvents);

uint32_t WSAWaitForMultipleEvents(uint32_t cEvents, const int64_t *lphEvents,
                                  bool32 fWaitAll, uint32_t dwTimeout_ms,
                                  bool32 fAlertable) paramsnonnull();

int WSAEnumNetworkEvents(uint64_t s, const int64_t hEventObject,
                         struct NtWsaNetworkEvents *out_lpNetworkEvents)
    paramsnonnull();

bool32 WSAGetOverlappedResult(uint64_t s,
                              const struct NtOverlapped *lpOverlapped,
                              uint32_t *out_lpcbTransfer, bool32 fWait,
                              uint32_t *out_lpdwFlags) paramsnonnull();

int WSAEnumProtocols(const int32_t *opt_lpiProtocols,
                     struct NtWsaProtocolInfo *out_lpProtocolBuffer,
                     uint32_t *inout_lpdwBufferLength) paramsnonnull();

bool32 WSAGetQOSByName(uint64_t s, const struct NtIovec *lpQOSName,
                       struct NtQos *out_lpQOS) paramsnonnull();

uint64_t WSAJoinLeaf(uint64_t s, const struct sockaddr *name, const int namelen,
                     const struct NtIovec *opt_lpCallerData,
                     struct NtIovec *opt_out_lpCalleeData,
                     const struct NtQos *opt_lpSQOS,
                     const struct NtQos *opt_lpGQOS, uint32_t dwFlags)
    paramsnonnull((2, 4));

int WSALookupServiceBegin(const struct NtWsaQuerySet *lpqsRestrictions,
                          uint32_t dwControlFlags, int64_t *out_lphLookup)
    paramsnonnull();

int WSALookupServiceNext(const int64_t hLookup, uint32_t dwControlFlags,
                         uint32_t *inout_lpdwBufferLength,
                         struct NtWsaQuerySet *out_lpqsResults) paramsnonnull();

int WSALookupServiceEnd(int64_t hLookup);

int WSAAddressToString(const struct sockaddr *lpsaAddress,
                       uint32_t dwAddressLength,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       char16_t *out_lpszAddressString,
                       uint32_t *inout_lpdwAddressStringLength)
    paramsnonnull((1, 4, 5));

int WSAStringToAddress(const char16_t *AddressString, int AddressFamily,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       struct sockaddr *out_lpAddress,
                       int *inout_lpAddressLength) paramsnonnull((1, 3, 4));

int WSAEnumNameSpaceProvidersEx(uint32_t *inout_lpdwBufferLength,
                                struct NtWsaNamespaceInfoEx *out_lpnspBuffer)
    paramsnonnull();

int WSAProviderConfigChange(
    int64_t *inout_lpNotificationHandle,
    struct NtOverlapped *opt_inout_lpOverlapped,
    NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((1));

int WSAInstallServiceClass(
    const struct NtWsaServiceClassInfo *lpServiceClassInfo) paramsnonnull();

int WSARemoveServiceClass(const struct NtGuid *lpServiceClassId)
    paramsnonnull();

int WSAGetServiceClassInfo(const struct NtGuid *lpProviderId,
                           const struct NtGuid *lpServiceClassId,
                           uint32_t *inout_lpdwBufSize,
                           struct NtWsaServiceClassInfo *out_lpServiceClassInfo)
    paramsnonnull((1, 2, 3));

int WSASetService(const struct NtWsaQuerySet *lpqsRegInfo, int essoperation,
                  uint32_t dwControlFlags) paramsnonnull();

int /* success==0 */ WSAGetServiceClassNameByClassId(
    const struct NtGuid *lpServiceClassId, char16_t *out_lpszServiceClassName,
    uint32_t *inout_lpdwBufferLength) paramsnonnull();

void GetAcceptExSockaddrs(
    const void *lpOutputBuffer /*[recvsize+addrsize+addrlen]*/,
    uint32_t dwReceiveDataLength, uint32_t dwLocalAddressLength,
    uint32_t dwRemoteAddressLength,
    struct sockaddr **out_LocalSockaddr /*[*LocalSockaddrLength]*/,
    int *out_LocalSockaddrLength,
    struct sockaddr **out_RemoteSockaddr /*[*RemoteSockaddrLength]*/,
    int *out_RemoteSockaddrLength);

bool32 DisconnectEx(int64_t s, struct NtOverlapped *inout_opt_lpOverlapped,
                    uint32_t dwFlags, uint32_t dwReserved);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/winsock.inc */

extern typeof(WSAGetLastError) *const __imp_WSAGetLastError __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_

/* Constants ----------------------------------------------------------- */

#define kNtMaxAdapterAddressLength  8
#define kNtMaxDnsSuffixStringLength 256
#define kNtMaxDhcpv6DuidLength      130

/* Values for the 'Flags' parameter of GetAdaptersAddresses */
#define kNtGaaFlagSkipUnicast               0x0001
#define kNtGaaFlagSkipAnycast               0x0002
#define kNtGaaFlagSkipMulticast             0x0004
#define kNtGaaFlagSkipDnsServer             0x0008
#define kNtGaaFlagIncludePrefix             0x0010
#define kNtGaaFlagSkipFriendlyName          0x0020
#define kNtGaaFlagIncludeWinsInfo           0x0040
#define kNtGaaFlagIncludeGateways           0x0080
#define kNtGaaFlagIncludeAllInterfaces      0x0100
#define kNtGaaFlagIncludeAllCompartments    0x0200
#define kNtGaaFlagIncludeTunnelBindingorder 0x0400
#define kNtGaaFlagSkipDnsInfo               0x0800

/* Values for the IfType parameter
 * See:
 * https://docs.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_addresses_lh
 */
#define kNtIfTypeOther             1
#define kNtIfTypeEthernetCsmacd    6
#define kNtIfTypeIso88025Tokenring 9
#define kNtIfTypePpp               23
#define kNtIfTypeSoftwareLoopback  24
#define kNtIfTypeAtm               37
#define kNtIfTypeIeee80211         71 /* wifi */
#define kNtIfTypeTunnel            131
#define kNtIfTypeIeee1394          144 /* firewire */

#define kNtIpAdapterDdnsEnabled             0x0001
#define kNtIpAdapterRegisterAdapterSuffix   0x0002
#define kNtIpAdapterDhcpv4Enabled           0x0004
#define kNtIpAdapterReceiveOnly             0x0008
#define kNtIpAdapterNoMulticast             0x0010
#define kNtIpAdapterIpv6OtherStatefulConfig 0x0020
#define kNtIpAdapterNetbiosOverTcpipEnabled 0x0040
#define kNtIpAdapterIpv4Enabled             0x0080
#define kNtIpAdapterIpv6Enabled             0x0100
#define kNtIpAdapterIpv6Managed             0x0200

#define kNtIpPrefixOriginOther               0
#define kNtIpPrefixOriginManual              1
#define kNtIpPrefixOriginWellKnown           2
#define kNtIpPrefixOriginDhcp                3
#define kNtIpPrefixOriginRouterAdvertisement 4
#define kNtIpPrefixOriginUnchanged           16

#define kNtIpSuffixOriginOther            0
#define kNtIpSuffixOriginManual           1
#define kNtIpSuffixOriginWellKnown        2
#define kNtIpSuffixOriginDhcp             3
#define kNtIpSuffixOriginLinkLayerAddress 4
#define kNtIpSuffixOriginRandom           5
#define kNtIpSuffixOriginUnchanged        16

#define kNtIpDadStateInvalid    0
#define kNtIpDadStateTentative  1
#define kNtIpDadStateDuplicate  2
#define kNtIpDadStateDeprecated 3
#define kNtIpDadStatePreferred  4

#define kNtIfOperStatusUp             1
#define kNtIfOperStatusDown           2
#define kNtIfOperStatusTesting        3
#define kNtIfOperStatusUnknown        4
#define kNtIfOperStatusDormant        5
#define kNtIfOperStatusNotPresent     6
#define kNtIfOperStatusLowerLayerDown 7

#define kNtNetIfConnectionDedicated 1
#define kNtNetIfConnectionPassive   2
#define kNtNetIfConnectionDemand    3
#define kNtNetIfConnectionMaximum   4

#define kNtTunnelTypeNone    0
#define kNtTunnelTypeOther   1
#define kNtTunnelTypeDirect  2
#define kNtTunnelType6to4    11
#define kNtTunnelTypeIsatap  13
#define kNtTunnelTypeTeredo  14
#define kNtTunnelTypeIphttps 15

COSMOPOLITAN_C_START_

/* Inner Types --------------------------------------------------------- */

struct NtIpAdapterUnicastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterUnicastAddress *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixOrigin; /* kNtIpPrefixOrigin... */
  uint32_t SuffixOrigin; /* kNtIpSuffixOrigin... */
  uint32_t DadState;     /* kNtIpDadState... */
  uint32_t ValidLifetime;
  uint32_t PreferredLifetime;
  uint32_t LeaseLifetime;
  uint8_t OnLinkPrefixLength;
};

struct NtIpAdapterAnycastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterAnycastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterMulticastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterMulticastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterDnsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterPrefix {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterPrefix *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixLength;
};

struct NtIpAdapterWinsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterWinsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterGatewayAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterGatewayAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsSuffix {
  struct NtIpAdapterDnsSuffix *Next;
  uint16_t String[kNtMaxDnsSuffixStringLength];
};

/* Top level ----------------------------------------------------------- */

struct NtIpAdapterAddresses {
  uint32_t Length;
  uint32_t IfIndex;
  struct NtIpAdapterAddresses *Next;
  char *AdapterName;
  struct NtIpAdapterUnicastAddress *FirstUnicastAddress;
  struct NtIpAdapterAnycastAddress *FirstAnycastAddress;
  struct NtIpAdapterMulticastAddress *FirstMulticastAddress;
  struct NtIpAdapterDnsServerAddress *FirstDnsServerAddress;
  uint16_t *DnsSuffix;
  uint16_t *Description;
  uint16_t *FriendlyName;
  uint8_t PhysicalAddress[kNtMaxAdapterAddressLength];
  uint32_t PhysicalAddressLength;
  uint32_t Flags; /* kNtIpAdapter... */
  uint32_t Mtu;
  uint32_t IfType;     /* kNtIfType... */
  uint32_t OperStatus; /* kNtIfOperStatus... */
  uint32_t Ipv6IfIndex;
  uint32_t ZoneIndices[16];
  struct NtIpAdapterPrefix *FirstPrefix;
  uint64_t TransmitLinkSpeed;
  uint64_t ReceiveLinkSpeed;
  struct NtIpAdapterWinsServerAddress *FirstWinsServerAddress;
  struct NtIpAdapterGatewayAddress *FirstGatewayAddress;
  uint32_t Ipv4Metric;
  uint32_t Ipv6Metric;
  uint64_t Luid; /* reserved(24bits),NetLuidIndex(24b),IfType(16b) */
  struct NtSocketAddress Dhcpv4Server;
  uint32_t CompartmentId;
  struct NtGuid NetworkGuid;
  uint32_t ConnectionType; /* kNtNetIfConnection... */
  uint32_t TunnelType;     /* kNtTunnelType... */
  struct NtSocketAddress Dhcpv6Server;
  uint8_t Dhcpv6ClientDuid[kNtMaxDhcpv6DuidLength];
  uint32_t Dhcpv6ClientDuidLength;
  uint32_t Dhcpv6Iaid;
  struct NtIpAdapterDnsSuffix *FirstDnsSuffix;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/kernelusertimes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_KERNELUSERTIMES_H_

struct NtKernelUserTimes {
  uint64_t CreateFileTime;
  uint64_t ExitFileTime;
  int64_t KernelTime;
  int64_t UserTime;
};



/*!BEGIN libc/nt/struct/ldr.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDR_H_

struct NtLdr {
  uint32_t SizeOfThis;                       /* msdn:reserved */
  uint32_t IsInitialized;                    /* msdn:reserved */
  void *SsHandle;                            /* msdn:reserved */
  struct NtLinkedList InLoadOrderModuleList; /* msdn:reserved */
  struct NtLinkedList /*∩NtLdrDataTableEntry*/ InMemoryOrderModuleList;
  struct NtLinkedList InInitOrderModuleList; /* msdn:reserved */
};



/*!BEGIN libc/nt/struct/ldrdatatableentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDRDATATABLEENTRY_H_


/*!BEGIN libc/nt/struct/unicodestring.h */

#define COSMOPOLITAN_LIBC_NT_UNICODE_H_

struct NtUnicodeString {
  uint16_t Length;
  uint16_t MaxLength;
  char16_t *Data;
};


struct NtLdrDataTableEntry {
  struct NtLinkedList InLoadOrderLinks; /* msdn:reserved */
  struct NtLinkedList InMemoryOrderLinks;
  struct NtLinkedList InInitOrderLinks; /* msdn:reserved */
  void *DllBase;
  void *EntryPoint;
  union {
    uint32_t SizeOfImage;
    unsigned char SizeOfImagePadding[__SIZEOF_POINTER__];
  };
  struct NtUnicodeString FullDllName;
  struct NtUnicodeString BaseDllName;
  uint32_t Flags;
  uint16_t Load_Count;
  uint16_t TlsIndex;
  union {
    struct NtLinkedList HashLinks;
    struct {
      void *SectionPointer;
      uint32_t CheckSum;
    };
  };
  union {
    void *LoadedImports;
    uint32_t TimeDateStamp;
  };
  void *EntryPointActivationContext;
  void *PatchInformation;
  struct NtLinkedList ForwarderLinks;
  struct NtLinkedList ServiceTagLinks;
  struct NtLinkedList StaticLinks;
  void *ContextInformation;
  uintptr_t OriginalBase;
  int64_t LoadTime;
};



/*!BEGIN libc/nt/struct/linger.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger_nt {
  uint16_t l_onoff;  /* on/off */
  uint16_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/luid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUID_H_

struct NtLuid {
  uint32_t LowPart;
  int32_t HighPart;
};



/*!BEGIN libc/nt/struct/luidandattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUIDANDATTRIBUTES_H_

struct NtLuidAndAttributes {
  struct NtLuid Luid;
  uint32_t Attributes;
};



/*!BEGIN libc/nt/struct/memextendedparameter.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMEXTENDEDPARAMETER_H_

#define kNtMemExtendedParameterTypeBits 8

#define kNtMemExtendedParameterInvalidType         0
#define kNtMemExtendedParameterAddressRequirements 1
#define kNtMemExtendedParameterNumaNode            2
#define kNtMemExtendedParameterPartitionHandle     3
#define kNtMemExtendedParameterUserPhysicalHandle  4
#define kNtMemExtendedParameterAttributeFlags      5
#define kNtMemExtendedParameterMax                 6

#define kNtMemExtendedParameterGraphics          0x00000001
#define kNtMemExtendedParameterNonpaged          0x00000002
#define kNtMemExtendedParameterZeroPagesOptional 0x00000004
#define kNtMemExtendedParameterNonpagedLarge     0x00000008
#define kNtMemExtendedParameterNonpagedHuge      0x00000010

struct NtMemExtendedParameter {
  struct {
    uint64_t Type : kNtMemExtendedParameterTypeBits;
    uint64_t Reserved : 64 - kNtMemExtendedParameterTypeBits;
  } DUMMYSTRUCTNAME;
  union {
    uint64_t ULong64;
    void *Pointer;
    size_t Size;
    intptr_t Handle;
    unsigned ULong;
  } DUMMYUNIONNAME;
};



/*!BEGIN libc/nt/struct/memorybasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYBASICINFORMATION_H_

struct NtMemoryBasicInformation {
  void *BaseAddress;
  void *AllocationBase;
  uint32_t AllocationProtect;
  uint64_t RegionSize;
  uint32_t State;
  uint32_t Protect;
  uint32_t Type;
};



/*!BEGIN libc/nt/struct/memoryrangeentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYRANGEENTRY_H_

struct NtMemoryRangeEntry {
  void *VirtualAddress;
  size_t NumberOfBytes;
};



/*!BEGIN libc/nt/struct/memorystatusex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYSTATUSEX_H_

struct NtMemoryStatusEx {
  uint32_t dwLength;
  uint32_t dwMemoryLoad;
  uint64_t ullTotalPhys;
  uint64_t ullAvailPhys;
  uint64_t ullTotalPageFile;
  uint64_t ullAvailPageFile;
  uint64_t ullTotalVirtual;
  uint64_t ullAvailVirtual;
  uint64_t ullAvailExtendedVirtual;
};



/*!BEGIN libc/nt/struct/msg.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MSG_H_


/*!BEGIN libc/nt/struct/point.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POINT_H_

struct NtPoint {
  int32_t x;
  int32_t y;
};


struct NtMsg {
  int64_t hwnd;
  uint32_t dwMessage;
  uint64_t wParam;
  int64_t lParam;
  uint32_t dwTime;
  struct NtPoint pt;
};



/*!BEGIN libc/nt/struct/nonpageddebuginfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NONPAGEDDEBUGINFO_H_

struct NtNonPagedDebugInfo {
  uint16_t Signature;
  uint16_t Flags;
  uint32_t Size;
  uint16_t Machine;
  uint16_t Characteristics;
  uint32_t TimeDateStamp;
  uint32_t CheckSum;
  uint32_t SizeOfImage;
  uint64_t ImageBase;
};



/*!BEGIN libc/nt/struct/ntexceptionpointers.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONPOINTERS_H_


/*!BEGIN libc/nt/struct/ntexceptionrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONRECORD_H_

#define kNtExceptionMaximumParameters 15
#define kNtExceptionNoncontinuable    1


struct NtExceptionRecord {
  uint32_t ExceptionCode;                    /* kNtException... */
  uint32_t ExceptionFlags;                   /* kNtExceptionNoncontinuable */
  struct NtExceptionRecord *ExceptionRecord; /* nested exceptions */
  void *ExceptionAddress;                    /* %rip */
  uint32_t NumberParameters;                 /* #ExceptionInformation */
  uint64_t ExceptionInformation[kNtExceptionMaximumParameters];
};


struct NtExceptionPointers {
  struct NtExceptionRecord *ExceptionRecord;
  struct NtContext *ContextRecord;
};



/*!BEGIN libc/nt/struct/objectallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTALLINFORMATION_H_


/*!BEGIN libc/nt/struct/objecttypeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTTYPEINFORMATION_H_

struct NtObjectTypeInformation {
  struct NtUnicodeString TypeName;
  uint32_t TotalNumberOfObjects;
  uint32_t TotalNumberOfHandles;
  uint32_t TotalPagedPoolUsage;
  uint32_t TotalNonPagedPoolUsage;
  uint32_t TotalNamePoolUsage;
  uint32_t TotalHandleTableUsage;
  uint32_t HighWaterNumberOfObjects;
  uint32_t HighWaterNumberOfHandles;
  uint32_t HighWaterPagedPoolUsage;
  uint32_t HighWaterNonPagedPoolUsage;
  uint32_t HighWaterNamePoolUsage;
  uint32_t HighWaterHandleTableUsage;
  uint32_t InvalidAttributes;
  struct NtGenericMapping GenericMapping;
  uint32_t ValidAccessMask;
  bool32 SecurityRequired;
  bool32 MaintainHandleCount;
  uint32_t PoolType;
  uint32_t DefaultPagedPoolCharge;
  uint32_t DefaultNonPagedPoolCharge;
};


struct NtObjectAllInformation {
  uint32_t NumberOfObjects;
  struct NtObjectTypeInformation ObjectTypeInformation[1];
};



/*!BEGIN libc/nt/struct/objectattributes.h */

#define COSMOPOLITAN_LIBC_NT_I_OBJECTATTRIBUTES_H_


/*!BEGIN libc/nt/struct/rtluserprocessparameters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSPARAMETERS_H_

struct NtRtlUserProcessParameters {
  uint32_t MaximumLength;
  uint32_t Length;
  uint32_t Flags;
  uint32_t DebugFlags;
  int64_t ConsoleHandle;
  uint32_t ConsoleFlags;
  int64_t StdInputHandle;
  int64_t StdOutputHandle;
  int64_t StdErrorHandle;
  struct NtUnicodeString *CurrentDirectoryPath;
  int64_t CurrentDirectoryHandle;
  struct NtUnicodeString *DllPath;
  struct NtUnicodeString *ImagePathName;
  struct NtUnicodeString *CommandLine;
  void *Environment;
  uint32_t StartingPositionLeft;
  uint32_t StartingPositionTop;
  uint32_t Width;
  uint32_t Height;
  uint32_t CharWidth;
  uint32_t CharHeight;
  uint32_t ConsoleTextAttributes;
  uint32_t WindowFlags;
  uint32_t ShowWindowFlags;
  struct NtUnicodeString *WindowTitle;
  struct NtUnicodeString *DesktopName;
  struct NtUnicodeString *ShellInfo;
  struct NtUnicodeString *RuntimeData;
};



/*!BEGIN libc/nt/struct/securityattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYATTRIBUTES_H_


/*!BEGIN libc/nt/struct/securitydescriptor.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYDESCRIPTOR_H_

struct NtSecurityDescriptor {
  uint8_t Revision;
  uint8_t Sbz1;
  uint16_t Control;
  void *Owner;
  void *Group;
  struct NtAcl *Sacl;
  struct NtAcl *Dacl;
};


struct NtSecurityAttributes {
  uint32_t nLength;
  struct NtSecurityDescriptor *lpSecurityDescriptor;
  bool32 bInheritHandle;
};

const char *DescribeNtSecurityAttributes(char[32],
                                         const struct NtSecurityAttributes *);
#define DescribeNtSecurityAttributes(x) \
  DescribeNtSecurityAttributes(alloca(32), x)


struct NtObjectAttributes {
  uint32_t Length;
  int64_t RootDirectory;
  const struct NtUnicodeString *ObjectName;
  uint32_t Attributes; /* OBJ_INHERIT, etc. */
  struct NtSecurityDescriptor *SecurityDescriptor;
  void *SecurityQualityOfService;
};



/*!BEGIN libc/nt/struct/objectbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTBASICINFORMATION_H_

struct NtObjectBasicInformation {
  uint32_t Attributes;
  uint32_t GrantedAccess;
  uint32_t HandleCount;
  uint32_t PointerCount;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t Reserved[3];
  uint32_t NameInformationLength;
  uint32_t TypeInformationLength;
  uint32_t SecurityDescriptorLength;
  int64_t CreateTime;
};



/*!BEGIN libc/nt/struct/objectnameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTNAMEINFORMATION_H_

struct NtObjectNameInformation {
  struct NtUnicodeString Name;
};



/*!BEGIN libc/nt/struct/openfilename.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OPENFILENAME_H_

struct NtOpenFilename {
  uint32_t lStructSize;
  int64_t hwndOwner;
  int64_t hInstance;
  const char16_t *lpstrFilter;
  char16_t *lpstrCustomFilter;
  uint32_t nMaxCustFilter;
  uint32_t nFilterIndex;
  char16_t *lpstrFile;
  uint32_t nMaxFile;
  char16_t *lpstrFileTitle;
  uint32_t nMaxFileTitle;
  const char16_t *lpstrInitialDir;
  const char16_t *lpstrTitle;
  uint32_t Flags;
  uint16_t nFileOffset;
  uint16_t nFileExtension;
  const char16_t *lpstrDefExt;
  intptr_t lCustData;
  uint64_t (*lpfnHook)(int64_t, uint32_t, uint64_t, int64_t);
  const char16_t *lpTemplateName;
  void *pvReserved;
  uint32_t dwReserved;
  uint32_t FlagsEx;
};



/*!BEGIN libc/nt/struct/osversioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OSVERSIONINFO_H_
COSMOPOLITAN_C_START_

struct NtOsVersionInfo {
  uint32_t dwOSVersionInfoSize;
  uint32_t dwMajorVersion;
  uint32_t dwMinorVersion;
  uint32_t dwBuildNumber;
  uint32_t dwPlatformId;
  char16_t szCSDVersion[128];
  uint16_t wServicePackMajor;
  uint16_t wServicePackMinor;
  uint16_t wSuiteMask;
  uint8_t wProductType;
  uint8_t wReserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/overlappedentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPEDENTRY_H_
COSMOPOLITAN_C_START_

struct NtOverlappedEntry {
  uint64_t lpCompletionKey;
  struct NtOverlapped *lpOverlapped;
  uint32_t *Internal;
  uint32_t dwNumberOfBytesTransferred;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/paintstruct.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PAINTSTRUCT_H_


/*!BEGIN libc/nt/struct/rect.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RECT_H_

struct NtRect {
  int32_t left;
  int32_t top;
  int32_t right;
  int32_t bottom;
};


struct NtPaintStruct {
  int64_t hdc;
  bool32 fErase;
  struct NtRect rcPaint;
  bool32 fRestore;
  bool32 fIncUpdate;
  uint8_t rgbReserved[32];
};



/*!BEGIN libc/nt/struct/pdhfmtcountervalue.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PDHFMTCOUNTERVALUE_H_
COSMOPOLITAN_C_START_

struct NtPdhFmtCountervalue {
  uint32_t CStatus;
  union {
    int32_t longValue;
    double doubleValue;
    int64_t largeValue;
    const char *AnsiStringValue;
    const char16_t *WideStringValue;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/peb.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PEB_H_

struct NtPeb {
  union {
    struct {
      unsigned char InheritedAddressSpace;
      unsigned char ReadImageFileExecOptions;
      unsigned char BeingDebugged;
      unsigned char __wut1;
    };
    uint64_t __wut2;
  };
  uint64_t Mutant;
  uint64_t ImageBaseAddress;
  struct NtLdr *Ldr;
  uint64_t ProcessParameters;
  uint64_t SubSystemData;
  uint64_t ProcessHeap;
  uint64_t FastPebLock;
  uint64_t __wut3;
  uint64_t __wut4;
  uint64_t __wut5;
  union {
    uint64_t KernelCallbackTable;
    uint64_t UserSharedInfoPtr;
  };
  uint32_t SystemReserved;
  uint32_t __wut6;
  uint64_t __wut7;
  uint64_t TlsExpansionCounter;
  uint64_t TlsBitmap;
  uint32_t TlsBitmapBits[2];
  uint64_t ReadOnlySharedMemoryBase;
  uint64_t __wut8;
  uint64_t ReadOnlyStaticServerData;
  uint64_t AnsiCodePageData;
  uint64_t OemCodePageData;
  uint64_t UnicodeCaseTableData;
  uint32_t NumberOfProcessors;
#ifdef __x86_64__
  uint32_t NtGlobalFlag;
#else
  uint64_t NtGlobalFlag;
#endif
  int64_t CriticalSectionTimeout;
  uint64_t HeapSegmentReserve;
  uint64_t HeapSegmentCommit;
  uint64_t HeapDeCommitTotalFreeThreshold;
  uint64_t HeapDeCommitFreeBlockThreshold;
  uint32_t NumberOfHeaps;
  uint32_t MaximumNumberOfHeaps;
  uint64_t ProcessHeaps;
  uint64_t GdiSharedHandleTable;
  uint64_t ProcessStarterHelper;
  uint64_t GdiDCAttributeList;
  uint64_t LoaderLock;
  union {
    struct {
      uint32_t OSMajorVersion;
      uint32_t OSMinorVersion;
    };
    uint64_t OSVersion;
  };
  uint16_t OSBuildNumber;
  uint16_t OSCSDVersion;
  uint32_t OSPlatformId;
  uint32_t ImageSubsystem;
  uint32_t ImageSubsystemMajorVersion;
  uint64_t ImageSubsystemMinorVersion;
  union {
    uint64_t ImageProcessAffinityMask;
    uint64_t ActiveProcessAffinityMask;
  };
  uint64_t GdiHandleBuffer[38 - __SIZEOF_POINTER__];
  uint64_t PostProcessInitRoutine;
  uint64_t TlsExpansionBitmap;
  uint32_t TlsExpansionBitmapBits[32];
  uint64_t SessionId;
  uint64_t AppCompatFlags;
  uint64_t AppCompatFlagsUser;
  uint64_t pShimData;
  uint64_t AppCompatInfo;
  struct NtUnicodeString CSDVersion;
  uint64_t ActivationContextData;
  uint64_t ProcessAssemblyStorageMap;
  uint64_t SystemDefaultActivationContextData;
  uint64_t SystemAssemblyStorageMap;
  uint64_t MinimumStackCommit;
};



/*!BEGIN libc/nt/struct/privilegeset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PRIVILEGESET_H_

struct NtPrivilegeSet {
  uint32_t PrivilegeCount;
  uint32_t Control;
  struct NtLuidAndAttributes Privilege[1];
};



/*!BEGIN libc/nt/struct/processbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSBASICINFORMATION_H_

struct NtProcessBasicInformation {
  int32_t ExitStatus;
  struct NtPeb *PebBaseAddress;
  uint32_t *AffinityMask;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
};



/*!BEGIN libc/nt/struct/processentry32.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSENTRY32_H_

struct NtProcessEntry32 {
  uint32_t dwSize;
  uint32_t cntUsage; /* unused */
  uint32_t th32ProcessID;
  uint64_t th32DefaultHeapID; /* unused */
  uint32_t th32ModuleID;      /* unused */
  uint32_t cntThreads;
  uint32_t th32ParentProcessID;
  int32_t cPriClassBase;
  uint32_t dwFlags; /* unused */
  char16_t szExeFile[260];
};



/*!BEGIN libc/nt/struct/processinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSINFORMATION_H_

struct NtProcessInformation {
  int64_t hProcess;
  int64_t hThread;
  uint32_t dwProcessId;
  uint32_t dwThreadId;
};



/*!BEGIN libc/nt/struct/processmemorycounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSMEMORYCOUNTERS_H_
COSMOPOLITAN_C_START_

struct NtProcessMemoryCountersEx {
  uint32_t cb; /* count bytes */
  uint32_t PageFaultCount;
  uint64_t PeakWorkingSetSize;
  uint64_t WorkingSetSize;
  uint64_t QuotaPeakPagedPoolUsage;
  uint64_t QuotaPagedPoolUsage;
  uint64_t QuotaPeakNonPagedPoolUsage;
  uint64_t QuotaNonPagedPoolUsage;
  uint64_t PagefileUsage;
  uint64_t PeakPagefileUsage;
  uint64_t PrivateUsage;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/processornumber.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSORNUMBER_H_
COSMOPOLITAN_C_START_

struct NtProcessorNumber {
  uint16_t Group;
  uint8_t Number;
  uint8_t Reserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/procthreadattributelist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCTHREADATTRIBUTELIST_H_

struct NtProcThreadAttributeList;



/*!BEGIN libc/nt/struct/reparsedatabuffer.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_REPARSEDATABUFFER_H_
COSMOPOLITAN_C_START_

struct NtReparseDataBuffer {
  uint32_t ReparseTag;
  uint16_t ReparseDataLength;
  uint16_t Reserved;
  union {
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      uint32_t Flags;
      char16_t PathBuffer[1];
    } SymbolicLinkReparseBuffer;
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      char16_t PathBuffer[1];
    } MountPointReparseBuffer;
    struct {
      uint8_t DataBuffer[1];
    } GenericReparseBuffer;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/rtluserprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/sectionimageinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECTIONIMAGEINFORMATION_H_

struct NtSectionImageInformation {
  void *EntryPoint;
  uint32_t Unknown1;
  uint32_t StackReserve;
  uint32_t StackCommit;
  uint32_t Subsystem;
  uint16_t MinorSubsystemVersion;
  uint16_t MajorSubsystemVersion;
  uint32_t Unknown2;
  uint32_t Characteristics;
  uint16_t ImageNumber;
  uint32_t IsExecutable;
  uint8_t __wut1;
  uint32_t __wut2[3];
};


struct NtRtlUserProcessInformation {
  uint32_t SizeOfThis;
  int64_t ProcessHandle;
  int64_t ThreadHandle;
  struct NtClientId ClientId;
  struct NtSectionImageInformation ImageInformation;
};



/*!BEGIN libc/nt/struct/size.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SIZE_H_
COSMOPOLITAN_C_START_

struct NtSize {
  int32_t cx;
  int32_t cy;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFO_H_

struct NtStartupInfo {
  uint32_t cb /* = sizeof(struct NtStartupInfo) */;
  uint16_t *lpReserved;
  char16_t *lpDesktop;
  char16_t *lpTitle; /* title of *new* console window only */
  uint32_t dwX;      /* position of window on screen */
  uint32_t dwY;
  uint32_t dwXSize;
  uint32_t dwYSize;
  uint32_t dwXCountChars; /* used to dimension the dos terminal */
  uint32_t dwYCountChars;
  uint32_t dwFillAttribute;
  uint32_t dwFlags;
  uint16_t wShowWindow;
  uint16_t cbReserved2;
  uint8_t *lpReserved2;
  union {
    struct {
      int64_t hStdInput;
      int64_t hStdOutput;
      int64_t hStdError;
    };
    int64_t stdiofds[3];
  };
};



/*!BEGIN libc/nt/struct/startupinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFOEX_H_

struct NtStartupInfoEx {
  struct NtStartupInfo StartupInfo;
  struct NtProcThreadAttributeList *lpAttributeList;
};



/*!BEGIN libc/nt/struct/systembasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMBASICINFORMATION_H_

struct NtSystemBasicInformation {
  unsigned char Reserved1[4];
  uint32_t MaximumIncrement;
  uint32_t PhysicalPageSize;
  uint32_t NumberOfPhysicalPages;
  uint32_t LowestPhysicalPage;
  uint32_t HighestPhysicalPage;
  uint32_t AllocationGranularity;
  uint32_t LowestUserAddress;
  uint32_t HighestUserAddress;
  uint32_t ActiveProcessors;
  char NumberOfProcessors;
};



/*!BEGIN libc/nt/struct/systemexceptioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMEXCEPTIONINFORMATION_H_

struct NtSystemExceptionInformation {
  unsigned char Reserved1[16];
};



/*!BEGIN libc/nt/struct/systemhandleentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEENTRY_H_

struct NtSystemHandleEntry {
  uint32_t OwnerPid;
  unsigned char ObjectType;
  unsigned char HandleFlags;
  unsigned short HandleValue;
  void *ObjectPointer;
  uint32_t AccessMask;
};



/*!BEGIN libc/nt/struct/systemhandleinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEINFORMATION_H_

struct NtSystemHandleInformation {
  uint32_t Count;
  struct NtSystemHandleEntry Handle[1];
};



/*!BEGIN libc/nt/struct/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINFO_H_

struct NtSystemInfo {
  union {
    uint32_t dwOemId;
    struct {
      uint16_t wProcessorArchitecture;
      uint16_t wReserved;
    };
  };
  uint32_t dwPageSize;
  void *lpMinimumApplicationAddress;
  void *lpMaximumApplicationAddress;
  uintptr_t dwActiveProcessorMask;
  uint32_t dwNumberOfProcessors;
  uint32_t dwProcessorType;
  uint32_t dwAllocationGranularity;
  uint16_t wProcessorLevel;
  uint16_t wProcessorRevision;
};



/*!BEGIN libc/nt/struct/systeminterruptinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINTERRUPTINFORMATION_H_

struct NtSystemInterruptInformation {
  unsigned char Reserved1[24];
};



/*!BEGIN libc/nt/struct/systemlookasideinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMLOOKASIDEINFORMATION_H_

struct NtSystemLookasideInformation {
  unsigned char Reserved1[32];
};



/*!BEGIN libc/nt/struct/systemperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPERFORMANCEINFORMATION_H_

struct NtSystemPerformanceInformation {
  int64_t IdleTime;
  int64_t ReadTransferCount;
  int64_t WriteTransferCount;
  int64_t OtherTransferCount;
  uint32_t ReadOperationCount;
  uint32_t WriteOperationCount;
  uint32_t OtherOperationCount;
  uint32_t AvailablePages;
  uint32_t TotalCommittedPages;
  uint32_t TotalCommitLimit;
  uint32_t PeakCommitment;
  uint32_t PageFaults;
  uint32_t WriteCopyFaults;
  uint32_t TransitionFaults;
  uint32_t CacheTransitionFaults;
  uint32_t DemandZeroFaults;
  uint32_t PagesRead;
  uint32_t PageReadIos;
  uint32_t CacheReads;
  uint32_t CacheIos;
  uint32_t PagefilePagesWritten;
  uint32_t PagefilePageWriteIos;
  uint32_t MappedFilePagesWritten;
  uint32_t MappedFilePageWriteIos;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t PagedPoolAllocs;
  uint32_t PagedPoolFrees;
  uint32_t NonPagedPoolAllocs;
  uint32_t NonPagedPoolFrees;
  uint32_t TotalFreeSystemPtes;
  uint32_t SystemCodePage;
  uint32_t TotalSystemDriverPages;
  uint32_t TotalSystemCodePages;
  uint32_t SmallNonPagedLookasideListAllocateHits;
  uint32_t SmallPagedLookasideListAllocateHits;
  uint32_t Reserved3;
  uint32_t MmSystemCachePage;
  uint32_t PagedPoolPage;
  uint32_t SystemDriverPage;
  uint32_t FastReadNoWait;
  uint32_t FastReadWait;
  uint32_t FastReadResourceMiss;
  uint32_t FastReadNotPossible;
  uint32_t FastMdlReadNoWait;
  uint32_t FastMdlReadWait;
  uint32_t FastMdlReadResourceMiss;
  uint32_t FastMdlReadNotPossible;
  uint32_t MapDataNoWait;
  uint32_t MapDataWait;
  uint32_t MapDataNoWaitMiss;
  uint32_t MapDataWaitMiss;
  uint32_t PinMappedDataCount;
  uint32_t PinReadNoWait;
  uint32_t PinReadWait;
  uint32_t PinReadNoWaitMiss;
  uint32_t PinReadWaitMiss;
  uint32_t CopyReadNoWait;
  uint32_t CopyReadWait;
  uint32_t CopyReadNoWaitMiss;
  uint32_t CopyReadWaitMiss;
  uint32_t MdlReadNoWait;
  uint32_t MdlReadWait;
  uint32_t MdlReadNoWaitMiss;
  uint32_t MdlReadWaitMiss;
  uint32_t ReadAheadIos;
  uint32_t LazyWriteIos;
  uint32_t LazyWritePages;
  uint32_t DataFlushes;
  uint32_t DataPages;
  uint32_t ContextSwitches;
  uint32_t FirstLevelTbFills;
  uint32_t SecondLevelTbFills;
  uint32_t SystemCalls;
};



/*!BEGIN libc/nt/struct/systemprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/vmcounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VMCOUNTERS_H_

struct NtVmCounters {
  size_t PeakVirtualSize;
  size_t VirtualSize;
  uint32_t PageFaultCount;
  size_t PeakWorkingSetSize;
  size_t WorkingSetSize;
  size_t QuotaPeakPagedPoolUsage;
  size_t QuotaPagedPoolUsage;
  size_t QuotaPeakNonPagedPoolUsage;
  size_t QuotaNonPagedPoolUsage;
  size_t PagefileUsage;
  size_t PeakPagefileUsage;
};


struct NtSystemProcessInformation {
  uint32_t NextEntryOffset;
  uint32_t NumberOfThreads;
  int64_t Reserved[3];
  int64_t CreateTime;
  int64_t UserTime;
  int64_t KernelTime;
  struct NtUnicodeString ImageName;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
  uint32_t HandleCount;
  uint32_t SessionId;
  uint32_t PageDirectoryBase;
  struct NtVmCounters VirtualMemoryCounters;
  size_t PrivatePageCount;
  struct NtIoCounters IoCounters;
};



/*!BEGIN libc/nt/struct/systemprocessorinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORINFORMATION_H_

struct NtSystemProcessorInformation {
  unsigned short ProcessorArchitecture;
  unsigned short ProcessorLevel;
  unsigned short ProcessorRevision;
  unsigned short Unknown;
  uint32_t FeatureBits;
};



/*!BEGIN libc/nt/struct/systemprocessorperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORPERFORMANCEINFORMATION_H_

struct NtSystemProcessorPerformanceInformation {
  int64_t IdleTime;
  int64_t KernelTime;
  int64_t UserTime;
  int64_t Reserved1[2];
  uint32_t Reserved2;
};



/*!BEGIN libc/nt/struct/systemregistryquotainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMREGISTRYQUOTAINFORMATION_H_

struct NtSystemRegistryQuotaInformation {
  uint32_t RegistryQuotaAllowed;
  uint32_t RegistryQuotaUsed;
  void *Reserved1;
};



/*!BEGIN libc/nt/struct/systemthreads.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTHREADS_H_

struct NtSystemThreads {
  int64_t KernelTime;
  int64_t UserTime;
  int64_t CreateTime;
  uint32_t WaitTime;
  void *StartAddress;
  struct NtClientId ClientId;
  int32_t Priority;
  int32_t BasePriority;
  uint32_t ContextSwitchCount;
  int State;
  uint32_t WaitReason;
};



/*!BEGIN libc/nt/struct/systemtimeofdayinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIMEOFDAYINFORMATION_H_

struct NtSystemTimeofdayInformation {
  int64_t BootTime;
  int64_t CurrentTime;
  int64_t TimeZoneBias;
  uint32_t CurrentTimeZoneId;
  unsigned char Reserved1[20];
};



/*!BEGIN libc/nt/struct/teb.h */

#define COSMOPOLITAN_LIBC_NT_TEB_H_
#ifdef __GNUC__

/*
 * These macros address directly into NT's TEB a.k.a. TIB
 * Any function that does this needs the `dontasan` keyword
 */
#define NtGetPeb()           ((__seg_gs struct NtPeb *)0x60)
#define NtGetTeb()           ((void *)*(__seg_gs uintptr_t *)0x30)
#define NtGetPid()           (*(__seg_gs uint32_t *)0x40)
#define NtGetTid()           (*(__seg_gs uint32_t *)0x48)
#define NtGetErr()           (*(__seg_gs int *)0x68)
#define _NtGetSeh()          ((void *)*(__seg_gs uintptr_t *)0x00)
#define _NtGetStackHigh()    ((void *)*(__seg_gs uintptr_t *)0x08)
#define _NtGetStackLow()     ((void *)*(__seg_gs uintptr_t *)0x10)
#define _NtGetSubsystemTib() ((void *)*(__seg_gs uintptr_t *)0x18)
#define _NtGetFib()          ((void *)*(__seg_gs uintptr_t *)0x20)
#define _NtGetEnv()          ((char16_t *)*(__seg_gs intptr_t *)0x38)
#define _NtGetRpc()          ((void *)*(__seg_gs uintptr_t *)0x50)
#define _NtGetTls()          ((void *)*(__seg_gs uintptr_t *)0x58)

#endif /* __GNUC__ */


/*!BEGIN libc/nt/struct/timezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEZONEINFORMATION_H_

struct NtTimeZoneInformation {
  int Bias;                  /* in minutes e.g. +480 for -8:00 */
  char16_t StandardName[32]; /* e.g. "Pacific Standard Time" */
  struct NtSystemTime StandardDate;
  int StandardBias;
  char16_t DaylightName[32]; /* e.g. "Pacific Daylight Time" */
  struct NtSystemTime DaylightDate;
  int DaylightBias; /* e.g. -60 */
};



/*!BEGIN libc/nt/struct/tokenprivileges.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TOKENPRIVILEGES_H_

struct NtTokenPrivileges {
  uint32_t PrivilegeCount;
  struct NtLuidAndAttributes Privileges[1];
};



/*!BEGIN libc/nt/struct/userstack.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTUSERSTACK_H_

struct NtUserStack {
  void *FixedStackBase;
  void *FixedStackLimit;
  void *ExpandableStackBase;
  void *ExpandableStackLimit;
  void *ExpandableStackBottom;
};



/*!BEGIN libc/nt/struct/valent.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VALENT_H_

struct NtValent {
  char16_t *ve_valuename;
  uint32_t ve_valuelen;
  uintptr_t ve_valueptr;
  uint32_t ve_type;
};



/*!BEGIN libc/nt/struct/win32fileattributedata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FILEATTRIBUTEDATA_H_

struct NtWin32FileAttributeData {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
};



/*!BEGIN libc/nt/struct/win32finddata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FINDDATA_H_

struct NtWin32FindData {
  uint32_t dwFileAttributes;
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t dwReserved0;
  uint32_t dwReserved1;
  char16_t cFileName[260];
  char16_t cAlternateFileName[14];
  uint32_t dwFileType;    /* obsolete */
  uint32_t dwCreatorType; /* obsolete */
  uint16_t wFinderFlags;  /* obsolete */
};



/*!BEGIN libc/nt/struct/windowplacement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WINDOWPLACEMENT_H_

struct NtWindowPlacement {
  uint32_t length;
  uint32_t flags;
  uint32_t showCmd;
  struct NtPoint ptMinPosition;
  struct NtPoint ptMaxPosition;
  struct NtRect rcNormalPosition;
  struct NtRect rcDevice;
};



/*!BEGIN libc/nt/struct/wndclass.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASS_H_


/*!BEGIN libc/nt/typedef/wndproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDPROC_H_
COSMOPOLITAN_C_START_

typedef int64_t (*NtWndProc)(int64_t, uint32_t, uint64_t, int64_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct NtWndClass {
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/wndclassex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASSEX_H_
COSMOPOLITAN_C_START_

struct NtWndClassEx {
  uint32_t cbSize;
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
  int64_t hIconSm;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/exceptionhandler.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_EXCEPTIONHANDLER_H_
COSMOPOLITAN_C_START_

typedef unsigned (*NtExceptionHandler)(struct NtExceptionRecord *,
                                       struct NtExceptionFrame *,
                                       struct NtContext *, void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/handlerroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HANDLERROUTINE_H_

typedef bool32 (*NtHandlerRoutine)(uint32_t);



/*!BEGIN libc/nt/typedef/hookproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HOOKPROC_H_

typedef intptr_t (*NtHookProc)(int code, uintptr_t wParam, intptr_t lParam);



/*!BEGIN libc/nt/typedef/imagetlscallback.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IMAGETLSCALLBACK_H_

typedef void (*NtImageTlsCallback)(void *DllHandle, uint32_t Reason,
                                   void *Reserved);



/*!BEGIN libc/nt/typedef/ioapcroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IOAPCROUTINE_H_

typedef void (*NtIoApcRoutine)(void *ApcContext,
                               struct NtIoStatusBlock *IoStatusBlock,
                               uint32_t Reserved);



/*!BEGIN libc/nt/typedef/pknormalroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_PKNORMALROUTINE_H_

typedef void (*NtPkNormalRoutine)(void *NormalContext, void *SystemArgument1,
                                  void *SystemArgument2);



/*!BEGIN libc/nt/typedef/timerproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_TIMERPROC_H_

typedef void (*NtTimerProc)(int64_t, uint32_t, uintptr_t, uint32_t);



/*!BEGIN libc/nt/typedef/wambda.h */

#define COSMOPOLITAN_LIBC_NT_WAMBDA_H_
COSMOPOLITAN_C_START_

typedef intptr_t (*wambda)();

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/wndenumproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDENUMPROC_H_

typedef int (*NtWndEnumProc)(int64_t foo, intptr_t bar);



/*!BEGIN libc/nt/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » debugging              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtContinue(struct NtContext *Context, int32_t TestAlert);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/file.h */

#define COSMOPOLITAN_LIBC_NT_NT_FILE_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtClose(int64_t handle);

NtStatus NtCreateFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                      const struct NtObjectAttributes *ObjectAttributes,
                      struct NtIoStatusBlock *out_IoStatusBlock,
                      int64_t *opt_AllocationSize, uint32_t FileAttributes,
                      uint32_t ShareAccess, uint32_t CreateDisposition,
                      uint32_t CreateOptions, void *opt_EaBuffer,
                      uint32_t EaLength);

NtStatus NtReadFile(int64_t FileHandle, void *opt_Event,
                    NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                    struct NtIoStatusBlock *out_IoStatusBlock, void *out_Buffer,
                    uint32_t Length, int64_t *opt_ByteOffset,
                    uint32_t *opt_Key);

NtStatus NtWriteFile(int64_t FileHandle, void *opt_Event,
                     NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                     struct NtIoStatusBlock *out_IoStatusBlock,
                     const void *Buffer, uint32_t Length,
                     int64_t *opt_ByteOffset, uint32_t *opt_Key);

NtStatus NtDuplicateObject(int64_t SourceProcessHandle, void *SourceHandle,
                           void *TargetProcessHandle,
                           void **opt_out_TargetHandle, uint32_t DesiredAcess,
                           uint32_t Attributes, uint32_t options_t);

NtStatus NtQueryInformationFile(int64_t FileHandle,
                                struct NtIoStatusBlock *out_IoStatusBlock,
                                void *out_FileInformation,
                                uint32_t FileInformationLength,
                                uint32_t FileInformationClass);

NtStatus NtSetInformationFile(int64_t FileHandle,
                              struct NtIoStatusBlock *out_IoStatusBlock,
                              void *FileInformation,
                              uint32_t FileInformationLength,
                              uint32_t FileInformationClass);

NtStatus NtDeviceIoControlFile(
    int64_t FileHandle, int64_t opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    uint32_t IoControlCode, void *opt_InputBuffer, uint32_t InputBufferLength,
    void *opt_out_OutputBuffer, uint32_t OutputBufferLength);

NtStatus NtCancelIoFileEx(int64_t FileHandle,
                          struct NtIoStatusBlock *IoRequestToCancel,
                          struct NtIoStatusBlock *IoStatusBlock);

NtStatus RtlNtStatusToDosError(NtStatus Status);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntfile.inc */

#define NtQueryInformationFile(...) __imp_NtQueryInformationFile(__VA_ARGS__)

extern typeof(NtQueryInformationFile) *const
    __imp_NtQueryInformationFile __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_NT_IPC_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » ipc                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtCreateNamedPipeFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes,
                               struct NtIoStatusBlock *out_IoStatusBlock,
                               uint32_t ShareAccess, uint32_t CreateDisposition,
                               uint32_t CreateOptions, int32_t TypeMessage,
                               int32_t ReadmodeMessage, int32_t Nonblocking,
                               uint32_t MaxInstances, uint32_t InBufferSize,
                               uint32_t OutBufferSize,
                               int64_t *opt_DefaultTimeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/key.h */

#define COSMOPOLITAN_LIBC_NT_NT_EVENT_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtCreateKeyedEvent(int64_t *KeyedEventHandle, uint32_t DesiredAccess,
                            struct NtObjectAttributes *ObjectAttributes,
                            uint32_t Flags);

NtStatus NtReleaseKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

NtStatus NtWaitForKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/loader.h */

#define COSMOPOLITAN_LIBC_NT_NT_LOADER_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » loader                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtAnsiString;
struct NtLdrDataTableEntry;
struct NtUnicodeString;

NtStatus LdrLoadDll(const char16_t *opt_PathToFile, uint32_t *opt_Flags,
                    struct NtUnicodeString *ModuleFileName,
                    void **out_ModuleHandle);
NtStatus LdrUnloadDll(void *ModuleHandle);
NtStatus LdrGetProcedureAddress(void *ModuleHandle,
                                struct NtAnsiString *opt_ProcedureName,
                                uint32_t opt_Ordinal,
                                wambda *out_ProcedureAddress);
NtStatus LdrGetDllHandle(const char16_t *opt_PathToFile, uint32_t opt_Unused,
                         struct NtUnicodeString *ModuleFileName,
                         void **out_ModuleHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_NT_MEMORY_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » memory                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtAllocateVirtualMemory(int64_t ProcessHandle,
                                 void **inout_BaseAddress, uint32_t dwZeroBits,
                                 uint32_t *inout_AllocationSize,
                                 uint32_t dwMemAllocationType,
                                 uint32_t dwPageProtect);
NtStatus NtFreeVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                             size_t *inout_FreeSize, uint32_t FreeType);
NtStatus NtQueryVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                              int MemoryInformationClass,
                              void *out_MemoryInformation,
                              size_t MemoryInformationLength,
                              size_t *opt_out_ReturnLength);
NtStatus NtProtectVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                                uint32_t *inout_ProtectSize,
                                uint32_t NewProtect, uint32_t *out_OldProtect);
NtStatus NtWriteVirtualMemory(int64_t ProcessHandle, void *BaseAddress,
                              const void *Buffer, size_t BufferLength,
                              size_t *opt_out_ReturnLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_NT_PROCESS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » processes              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtObjectAttributes;
struct NtRtlUserProcessInformation;
struct NtRtlUserProcessParameters;
struct NtSecurityDescriptor;
struct NtUnicodeString;

NtStatus NtCreateProcess(int64_t *out_ProcessHandle, uint32_t dwDesiredAccess,
                         struct NtObjectAttributes *opt_ObjectAttributes,
                         void *InheritFromProcessHandle, int32_t InheritHandles,
                         void *opt_SectionHandle, void *opt_DebugPort,
                         void *opt_ExceptionPort);
NtStatus NtTerminateProcess(int64_t opt_ProcessHandle, int32_t ExitStatus);

NtStatus NtQueryInformationProcess(int64_t ProcessHandle,
                                   int ProcessInformationClass,
                                   void *out_ProcessInformation,
                                   uint32_t ProcessInformationLength,
                                   uint32_t *opt_out_ReturnLength);
NtStatus NtOpenProcessToken(int64_t ProcessToken, uint32_t DesiredAccess,
                            int64_t *out_TokenHandle);
NtStatus NtOpenProcess(int64_t *out_ProcessHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       struct NtClientId *ClientId);

NtStatus RtlCreateProcessParameters(
    struct NtRtlUserProcessParameters **out_ProcessParameters,
    struct NtUnicodeString *ImageFile, struct NtUnicodeString *opt_DllPath,
    struct NtUnicodeString *opt_CurrentDirectory,
    struct NtUnicodeString *opt_CommandLine, uint32_t CreationFlags,
    struct NtUnicodeString *opt_WindowTitle,
    struct NtUnicodeString *opt_Desktop, struct NtUnicodeString *opt_Reserved,
    struct NtUnicodeString *opt_Reserved2);

NtStatus RtlDestroyProcessParameters(
    struct NtRtlUserProcessParameters *ProcessParameters);

NtStatus RtlCloneUserProcess(
    uint32_t ProcessFlags,
    struct NtSecurityDescriptor *opt_ProcessSecurityDescriptor,
    struct NtSecurityDescriptor *opt_ThreadSecurityDescriptor,
    void *opt_DebugPort,
    struct NtRtlUserProcessInformation *ProcessInformation);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/process.inc */

#define NtQueryInformationProcess(...) \
  __imp_NtQueryInformationProcess(__VA_ARGS__)

extern typeof(NtQueryInformationProcess) *const
    __imp_NtQueryInformationProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/sections.h */

#define COSMOPOLITAN_LIBC_NT_NT_SECTIONS_H_
COSMOPOLITAN_C_START_

NtStatus NtCreateSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                         struct NtObjectAttributes *ObjectAttributes,
                         int64_t *opt_SectionSize, uint32_t Protect,
                         uint32_t Attributes, int64_t FileHandle);
NtStatus NtOpenSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes);
NtStatus NtMapViewOfSection(int64_t SectionHandle, int64_t ProcessHandle,
                            void **inout_BaseAddress, uint32_t *ZeroBits,
                            size_t CommitSize, int64_t *opt_inout_SectionOffset,
                            size_t *inout_ViewSize, int InheritDisposition,
                            uint32_t AllocationType, uint32_t Protect);
NtStatus NtUnmapViewOfSection(int64_t ProcessHandle, void *BaseAddress);
NtStatus NtQuerySection(int64_t SectionHandle, int SectionInformationClass,
                        void *out_SectionInformation,
                        uint32_t SectionInformationLength,
                        uint32_t *opt_out_ResultLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/signing.h */

#define COSMOPOLITAN_LIBC_NT_NT_SIGNING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » code signing           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus CsrClientCallServer(void *inout_Message, void *unknown,
                             uint32_t Opcode, uint32_t Size);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » threads                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtContext;
struct NtObjectAttributes;
struct NtUserStack;

NtStatus NtCreateThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                        struct NtObjectAttributes *ObjectAttributes,
                        int64_t ProcessHandle, struct NtClientId *out_ClientId,
                        struct NtContext *ThreadContext,
                        struct NtUserStack *UserStack, int32_t CreateSuspended);

NtStatus NtTerminateThread(void *opt_ThreadHandle, int32_t ExitStatus);

NtStatus NtOpenThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                      struct NtObjectAttributes *ObjectAttributes,
                      struct NtClientId *ClientId);

NtStatus NtQueryInformationThread(int64_t ThreadHandle,
                                  enum NtThreadInfoClass ThreadInformationClass,
                                  void *out_ThreadInformation,
                                  uint32_t ThreadInformationLength,
                                  uint32_t *opt_out_ReturnLength);

NtStatus NtGetContextThread(int64_t ThreadHandle,
                            struct NtContext *out_Context);
NtStatus NtSetContextThread(int64_t ThreadHandle, struct NtContext *Context);
NtStatus NtSuspendThread(int64_t ThreadHandle,
                         uint32_t *opt_out_PreviousSuspendCount);
NtStatus NtResumeThread(int64_t ThreadHandle,
                        uint32_t *opt_out_PreviousSuspendCount);

NtStatus NtOpenThreadToken(int64_t ThreadHandle, uint32_t DesiredAccess,
                           int32_t OpenAsSelf, int64_t *out_TokenHandle);

NtStatus NtSetInformationThread(int64_t ThreadHandle,
                                enum NtThreadInfoClass ThreadInformationClass,
                                void *ThreadInformation,
                                uint32_t ThreadInformationLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » time                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtDelayExecution(bool32 alertable, int64_t *AbsCobolOrNegRelHectoNano);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/time.inc */

#define NtDelayExecution(...) __imp_NtDelayExecution(__VA_ARGS__)

extern typeof(NtDelayExecution) *const __imp_NtDelayExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/accounting.h */

#define COSMOPOLITAN_LIBC_NT_ACCOUNTING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » accounting                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetMaximumProcessorCount(uint16_t GroupNumber);
int GetUserName(char16_t (*buf)[257], uint32_t *in_out_size);
bool32 GlobalMemoryStatusEx(struct NtMemoryStatusEx *lpBuffer);
int32_t GetExitCodeProcess(int64_t hProcess, uint32_t *lpExitCode);
int32_t GetProcessHandleCount(int64_t hProcess, uint32_t *pdwHandleCount);
bool32 GetSystemTimes(struct NtFileTime *opt_out_lpIdleTime,
                      struct NtFileTime *opt_out_lpKernelTime,
                      struct NtFileTime *opt_out_lpUserTime);
bool32 GetProcessTimes(int64_t hProcess,
                       struct NtFileTime *out_lpCreationFileTime,
                       struct NtFileTime *out_lpExitFileTime,
                       struct NtFileTime *out_lpKernelFileTime,
                       struct NtFileTime *out_lpUserFileTime);
bool32 GetThreadTimes(int64_t hThread,
                      struct NtFileTime *out_lpCreationFileTime,
                      struct NtFileTime *out_lpExitFileTime,
                      struct NtFileTime *out_lpKernelFileTime,
                      struct NtFileTime *out_lpUserFileTime);
int32_t GetProcessIoCounters(int64_t hProcess,
                             struct NtIoCounters *lpIoCounters);
int32_t GetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t *lpMinimumWorkingSetSize,
                                 uint64_t *lpMaximumWorkingSetSize);
int32_t GetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t *lpMinimumWorkingSetSize,
                                   uint64_t *lpMaximumWorkingSetSize,
                                   uint32_t *Flags);
int32_t SetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t dwMinimumWorkingSetSize,
                                 uint64_t dwMaximumWorkingSetSize);
int32_t SetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t dwMinimumWorkingSetSize,
                                   uint64_t dwMaximumWorkingSetSize,
                                   uint32_t Flags);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/accounting.inc */

#define GetProcessTimes(...) __imp_GetProcessTimes(__VA_ARGS__)
extern typeof(GetProcessTimes) *const __imp_GetProcessTimes __msabi;

#define GetThreadTimes(...) __imp_GetThreadTimes(__VA_ARGS__)
extern typeof(GetThreadTimes) *const __imp_GetThreadTimes __msabi;

#define GetUserName(...) __imp_GetUserNameW(__VA_ARGS__)
extern typeof(GetUserName) *const __imp_GetUserNameW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/automation.h */

#define COSMOPOLITAN_LIBC_NT_AUTOMATION_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » aol hacking                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int64_t GetShellWindow(void);
int64_t GetDesktopWindow(void);
int64_t GetParent(int64_t hWnd);
int64_t SetParent(int64_t hWndChild, int64_t hWndNewParent);
int32_t EnumChildWindows(int64_t hWndParent, NtWndEnumProc lpEnumFunc,
                         intptr_t lParam);
int64_t FindWindow(const char16_t *lpClassName, const char16_t *lpWindowName);
int64_t FindWindowEx(int64_t hWndParent, int64_t hWndChildAfter,
                     const char16_t *lpszClass, const char16_t *lpszWindow);
int64_t GetWindow(int64_t hWnd, uint32_t uCmd);
int64_t SetWindowsHook(int nFilterType, NtHookProc pfnFilterProc);
int32_t UnhookWindowsHook(int nCode, NtHookProc pfnFilterProc);
int64_t SetWindowsHookEx(int idHook, NtHookProc lpfn, int64_t hmod,
                         uint32_t dwThreadId);
int32_t UnhookWindowsHookEx(int64_t hhk);
intptr_t CallNextHookEx(int64_t hhk, int nCode, uintptr_t wParam,
                        intptr_t lParam);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/codegen.h */

#define COSMOPOLITAN_LIBC_NT_CODEGEN_H_


/*!BEGIN libc/nt/comdlg.h */

#define COSMOPOLITAN_LIBC_NT_COMDLG_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » common dialogs                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 GetOpenFileName(struct NtOpenFilename *arg);
bool32 GetSaveFileName(struct NtOpenFilename *arg);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/comms.h */

#define COSMOPOLITAN_LIBC_NT_COMMS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » communications                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

bool32 PurgeComm(int64_t hFile, uint32_t dwFlags);
bool32 TransmitCommChar(int64_t hFile, char cChar);
bool32 ClearCommBreak(int64_t hFile);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/console.h */

#define COSMOPOLITAN_LIBC_NT_CONSOLE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » console                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtAttachParentProcess -1u

COSMOPOLITAN_C_START_

bool32 WriteConsoleOutput(int64_t hConsoleOutput,
                          const struct NtCharInfo *lpBuffer,
                          struct NtCoord dwBufferSize,
                          struct NtCoord dwBufferCoord,
                          struct NtSmallRect *lpWriteRegion);
bool32 ReadConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 PeekConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 GetNumberOfConsoleInputEvents(int64_t hConsoleInput,
                                     uint32_t *lpNumberOfEvents);
bool32 ReadConsoleOutput(int64_t hConsoleOutput, struct NtCharInfo *lpBuffer,
                         struct NtCoord dwBufferSize,
                         struct NtCoord dwBufferCoord,
                         struct NtSmallRect *lpReadRegion);
bool32 WriteConsoleInput(int64_t hConsoleInput,
                         const struct NtInputRecord *lpBuffer, uint32_t nLength,
                         uint32_t *lpNumberOfEventsWritten);
bool32 FlushConsoleInputBuffer(int64_t hConsoleInput);

int64_t GetConsoleWindow(void);
bool32 GetConsoleMode(int64_t hConsoleHandle, uint32_t *lpMode);
bool32 SetConsoleMode(int64_t hConsoleHandle, uint32_t dwMode);
int32_t AllocConsole(void);
int32_t FreeConsole(void);
int32_t AttachConsole(uint32_t dwProcessId);
uint32_t GetConsoleTitle(char16_t *lpConsoleTitle, uint32_t nSize);
int32_t SetConsoleTitle(const char16_t *lpConsoleTitle);
bool32 GetConsoleScreenBufferInfo(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfo *out_lpConsoleScreenBufferInfo);
bool32 GetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfoEx *in_out_lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    const struct NtConsoleScreenBufferInfoEx *lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferSize(int64_t lpConsoleOutput,
                                  struct NtCoord dwSize);
struct NtCoord GetLargestConsoleWindowSize(int64_t hConsoleHandle);
int32_t ReadConsole(int64_t hConsoleInput, void *lpBuffer,
                    uint32_t nNumberOfCharsToRead,
                    uint32_t *lpNumberOfCharsRead, void *lpReserved);
int32_t WriteConsole(int64_t hConsoleOutput, const void *lpBuffer,
                     uint32_t nNumberOfCharsToWrite,
                     uint32_t *lpNumberOfCharsWritten, void *lpReserved)
    paramsnonnull((2, 4));
bool32 GetNumberOfConsoleMouseButtons(uint32_t *out_lpNumberOfMouseButtons)
    paramsnonnull();
bool32 GetConsoleSelectionInfo(
    struct NtConsoleSelectionInfo *out_lpConsoleSelectionInfo);
uint32_t WaitForInputIdle(int64_t hProcess, uint32_t dwMilliseconds);
uint32_t GetConsoleCP(void);
bool32 SetConsoleCP(uint32_t wCodePageID);
bool32 SetConsoleOutputCP(uint32_t wCodePageID);
uint32_t GetConsoleOutputCP(void);
bool32 SetConsoleCtrlHandler(NtHandlerRoutine opt_HandlerRoutine, bool32 Add);
bool32 GenerateConsoleCtrlEvent(uint32_t dwCtrlEvent,
                                uint32_t dwProcessGroupId);

bool32 GetConsoleCursorInfo(
    int64_t hConsoleOutput,
    struct NtConsoleCursorInfo *out_lpConsoleCursorInfo);
bool32 SetConsoleCursorInfo(
    int64_t hConsoleOutput,
    const struct NtConsoleCursorInfo *lpConsoleCursorInfo);

long CreatePseudoConsole(struct NtCoord size, int64_t hInput, int64_t hOutput,
                         uint32_t dwFlags, int64_t *out_phPC);
long ResizePseudoConsole(int64_t hPC, struct NtCoord size);
void ClosePseudoConsole(int64_t hPC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/console.inc */

#define GetConsoleMode(...) __imp_GetConsoleMode(__VA_ARGS__)
extern typeof(GetConsoleMode) *const __imp_GetConsoleMode __msabi;

#define SetConsoleCP(...) __imp_SetConsoleCP(__VA_ARGS__)
extern typeof(SetConsoleCP) *const __imp_SetConsoleCP __msabi;

#define GetConsoleCP(...) __imp_GetConsoleCP(__VA_ARGS__)
extern typeof(GetConsoleCP) *const __imp_GetConsoleCP __msabi;

#define SetConsoleCtrlHandler(...) __imp_SetConsoleCtrlHandler(__VA_ARGS__)
extern typeof(SetConsoleCtrlHandler) *const __imp_SetConsoleCtrlHandler __msabi;

#define SetConsoleMode(...) __imp_SetConsoleMode(__VA_ARGS__)
extern typeof(SetConsoleMode) *const __imp_SetConsoleMode __msabi;

#define SetConsoleOutputCP(...) __imp_SetConsoleOutputCP(__VA_ARGS__)
extern typeof(SetConsoleOutputCP) *const __imp_SetConsoleOutputCP __msabi;

#define GetConsoleOutputCP(...) __imp_GetConsoleOutputCP(__VA_ARGS__)
extern typeof(GetConsoleOutputCP) *const __imp_GetConsoleOutputCP __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/createfile.h */

#define COSMOPOLITAN_LIBC_NT_CREATEFILE_H_
COSMOPOLITAN_C_START_

int64_t CreateFile(
    const char16_t *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int64_t CreateFileA(
    const char *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int GetNtOpenFlags(int, int, uint32_t *, uint32_t *, uint32_t *, uint32_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » debugging                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* Some of these APIs were moved to system.h and libc.h */
int32_t DebugBreakProcess(void *Process);
int32_t DebugActiveProcess(uint32_t dwProcessId);
int32_t DebugActiveProcessStop(uint32_t dwProcessId);
int32_t CheckRemoteDebuggerPresent(int64_t hProcess, int *pbDebuggerPresent);
int32_t ContinueDebugEvent(uint32_t dwProcessId, uint32_t dwThreadId,
                           uint32_t dwContinueStatus);
void FatalExit(int uExitCode);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/dll.h */

#define COSMOPOLITAN_LIBC_NT_DLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » dynamic link libraries                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t LoadLibrary(const char16_t *lpLibFileName);
int64_t LoadLibraryA(const char *lpLibFileName);
int64_t LoadLibraryEx(const char16_t *lpLibFileName, int64_t hFile,
                      uint32_t dwFlags);
uint32_t GetModuleFileNameA(int64_t hModule, char *lpFilename, uint32_t nSize);
intptr_t GetModuleHandle(const char *opt_lpModuleName);
intptr_t GetModuleHandleW(const char16_t *opt_lpModuleName);
void *GetProcAddress(int64_t hModule, const char *lpProcName);
int32_t FreeResource(int64_t hResData);
intptr_t LockResource(int64_t hResData);
int32_t FreeLibrary(int64_t hLibModule);
void *AddDllDirectory(const char16_t *NewDirectory);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/efi.h */

#define COSMOPOLITAN_LIBC_NT_EFI_H_
/*
    ▐██ ░█████████▓   ▐██▌     ██▓░   ▐█▌  ▐██  ░██░    ▓█▌  ▓██▒     ▓██
    ▐██     ░██░     ▒█▓██░    ████░  ▐█▌  ▐██  ░██░    ▓█▌  ▓███░   ▓███
    ▐██     ░██░     ██░▐█▓    ██▒▓█░ ▐█▌  ▐██  ░██░    ▓█▌  ▓█▌▓█░ ▓█▒██
    ▐██     ░██░    ▐█▌  ▓█▌   ██░░▓█░▐█▌  ▐██  ░██░    ▓█▌  ▓█▌░█▓▓█▒░██
    ▐██     ░██░   ▒██▓█████░  ██░ ░▓▓▓█▌  ▐██  ░██░    ██░  ▓█▌ ░██▌ ░██
    ▐██     ░██░   ▓█▌    ▓█▓  ██░  ░███▌  ▐██   ▐██▄▄▄▓█▓   ▓█▌      ░██
╔────────────────────────────────────────────────────────────────────────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § the unified extensible firmware interface ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define EFI_SUCCESS           0x8000000000000000
#define EFI_LOAD_ERROR        0x8000000000000001
#define EFI_INVALID_PARAMETER 0x8000000000000002
#define EFI_UNSUPPORTED       0x8000000000000003
#define EFI_BAD_BUFFER_SIZE   0x8000000000000004
#define EFI_BUFFER_TOO_SMALL  0x8000000000000005
#define EFI_NOT_READY         0x8000000000000006
#define EFI_DEVICE_ERROR      0x8000000000000007
#define EFI_WRITE_PROTECTED   0x8000000000000008
#define EFI_OUT_OF_RESOURCES  0x8000000000000009
#define EFI_VOLUME_CORRUPTED  0x800000000000000a
#define EFI_VOLUME_FULL       0x800000000000000b
#define EFI_NO_MEDIA          0x800000000000000c
#define EFI_MEDIA_CHANGED     0x800000000000000d
#define EFI_NOT_FOUND         0x800000000000000e
#define EFI_ACCESS_DENIED     0x800000000000000f
#define EFI_NO_RESPONSE       0x8000000000000010
#define EFI_NO_MAPPING        0x8000000000000011
#define EFI_TIMEOUT           0x8000000000000012
#define EFI_NOT_STARTED       0x8000000000000013
#define EFI_ALREADY_STARTED   0x8000000000000014
#define EFI_ABORTED           0x8000000000000015
#define EFI_ICMP_ERROR        0x8000000000000016
#define EFI_TFTP_ERROR        0x8000000000000017
#define EFI_PROTOCOL_ERROR    0x8000000000000018

#define EFI_VARIABLE_NON_VOLATILE                          0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS                    0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS                        0x00000004
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD                 0x00000008
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS            0x00000010
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
#define EFI_VARIABLE_APPEND_WRITE                          0x00000040

#define EFI_MEMORY_UC            0x0000000000000001U
#define EFI_MEMORY_WC            0x0000000000000002U
#define EFI_MEMORY_WT            0x0000000000000004U
#define EFI_MEMORY_WB            0x0000000000000008U
#define EFI_MEMORY_UCE           0x0000000000000010U
#define EFI_MEMORY_WP            0x0000000000001000U
#define EFI_MEMORY_RP            0x0000000000002000U
#define EFI_MEMORY_XP            0x0000000000004000U
#define EFI_MEMORY_RO            0x0000000000020000U
#define EFI_MEMORY_NV            0x0000000000008000U
#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000U
#define EFI_MEMORY_RUNTIME       0x8000000000000000U

#define EFI_OPTIONAL_PTR 0x00000001

#define EFI_SCAN_NULL      0x0000
#define EFI_SCAN_UP        0x0001
#define EFI_SCAN_DOWN      0x0002
#define EFI_SCAN_RIGHT     0x0003
#define EFI_SCAN_LEFT      0x0004
#define EFI_SCAN_HOME      0x0005
#define EFI_SCAN_END       0x0006
#define EFI_SCAN_INSERT    0x0007
#define EFI_SCAN_DELETE    0x0008
#define EFI_SCAN_PAGE_UP   0x0009
#define EFI_SCAN_PAGE_DOWN 0x000A
#define EFI_SCAN_F1        0x000B
#define EFI_SCAN_F2        0x000C
#define EFI_SCAN_F3        0x000D
#define EFI_SCAN_F4        0x000E
#define EFI_SCAN_F5        0x000F
#define EFI_SCAN_F6        0x0010
#define EFI_SCAN_F7        0x0011
#define EFI_SCAN_F8        0x0012
#define EFI_SCAN_F9        0x0013
#define EFI_SCAN_F10       0x0014
#define EFI_SCAN_ESC       0x0017

#define EFI_EVT_TIMER                         0x80000000
#define EFI_EVT_RUNTIME                       0x40000000
#define EFI_EVT_NOTIFY_WAIT                   0x00000100
#define EFI_EVT_NOTIFY_SIGNAL                 0x00000200
#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES     0x00000201
#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
#define EFI_EVT_RUNTIME_CONTEXT               0x20000000

#define LOADED_IMAGE_PROTOCOL                        \
  {                                                  \
    0x5B1B31A1, 0x9562, 0x11d2, {                    \
      0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \
    }                                                \
  }
#define GRAPHICS_OUTPUT_PROTOCOL                     \
  {                                                  \
    0x9042A9DE, 0x23DC, 0x4A38, {                    \
      0x96, 0xFB, 0x7A, 0xDE, 0xD0, 0x80, 0x51, 0x6A \
    }                                                \
  }
#define ACPI_20_TABLE_GUID                           \
  {                                                  \
    0x8868E871, 0xE4F1, 0x11D3, {                    \
      0xBC, 0x22, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 \
    }                                                \
  }
#define ACPI_10_TABLE_GUID                           \
  {                                                  \
    0xEB9D2D30, 0x2D88, 0x11D3, {                    \
      0x9A, 0x16, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D \
    }                                                \
  }

COSMOPOLITAN_C_START_

#if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__chibicc__) && \
    defined(__x86_64__)
#define EFIAPI __attribute__((__ms_abi__))
#else
#define EFIAPI /* TODO(jart): fix me */
#endif

#define EFI_STATUS uint64_t
#define EFI_EVENT  uintptr_t
#define EFI_HANDLE uintptr_t

typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
typedef struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL;

typedef enum {
  EfiReservedMemoryType,
  EfiLoaderCode,
  EfiLoaderData,
  EfiBootServicesCode,
  EfiBootServicesData,
  EfiRuntimeServicesCode,
  EfiRuntimeServicesData,
  EfiConventionalMemory,
  EfiUnusableMemory,
  EfiACPIReclaimMemory,
  EfiACPIMemoryNVS,
  EfiMemoryMappedIO,
  EfiMemoryMappedIOPortSpace,
  EfiPalCode,
  EfiPersistentMemory,
  EfiMaxMemoryType
} EFI_MEMORY_TYPE;

typedef enum {
  EfiResetCold,
  EfiResetWarm,
  EfiResetShutdown,
  EfiResetPlatformSpecific
} EFI_RESET_TYPE;

typedef enum {
  AllocateAnyPages,
  AllocateMaxAddress,
  AllocateAddress,
  MaxAllocateType
} EFI_ALLOCATE_TYPE;

typedef enum {
  TimerCancel,
  TimerPeriodic,
  TimerRelative,
} EFI_TIMER_DELAY;

typedef struct {
  uint32_t Resolution;
  uint32_t Accuracy;
  bool32 SetsToZero;
} EFI_TIME_CAPABILITIES;

typedef struct {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
} EFI_GUID;

typedef struct {
  uint16_t Year;
  uint8_t Month;
  uint8_t Day;
  uint8_t Hour;
  uint8_t Minute;
  uint8_t Second;
  uint8_t Pad1;
  uint32_t Nanosecond;
  int16_t TimeZone;
  uint8_t Daylight;
  uint8_t Pad2;
} EFI_TIME;

typedef struct {
  uint32_t Type;
  uint64_t PhysicalStart;
  uint64_t VirtualStart;
  uint64_t NumberOfPages;
  uint64_t Attribute;
} EFI_MEMORY_DESCRIPTOR;

typedef struct {
  EFI_GUID VendorGuid;
  void *VendorTable;
} EFI_CONFIGURATION_TABLE;

typedef struct {
  EFI_GUID CapsuleGuid;
  uint32_t HeaderSize;
  uint32_t Flags;
  uint32_t CapsuleImageSize;
} EFI_CAPSULE_HEADER;

typedef struct {
  uint16_t ScanCode;
  char16_t UnicodeChar;
} EFI_INPUT_KEY;

typedef struct {
  int32_t MaxMode;
  int32_t Mode;
  int32_t Attribute;
  int32_t CursorColumn;
  int32_t CursorRow;
  bool32 CursorVisible;
} EFI_SIMPLE_TEXT_OUTPUT_MODE;

typedef enum {
  PixelRedGreenBlueReserved8BitPerColor,
  PixelBlueGreenRedReserved8BitPerColor,
  PixelBitMask,
  PixelBltOnly,
  PixelFormatMax
} EFI_GRAPHICS_PIXEL_FORMAT;

typedef struct {
  uint32_t RedMask;
  uint32_t GreenMask;
  uint32_t BlueMask;
  uint32_t ReservedMask;
} EFI_PIXEL_BITMASK;

typedef struct {
  uint32_t Version;
  uint32_t HorizontalResolution;
  uint32_t VerticalResolution;
  EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
  EFI_PIXEL_BITMASK PixelInformation;
  uint32_t PixelsPerScanLine;
} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;

typedef struct {
  uint8_t Blue;
  uint8_t Green;
  uint8_t Red;
  uint8_t Reserved;
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;

typedef enum {
  EfiBltVideoFill,
  EfiBltVideoToBltBuffer,
  EfiBltBufferToVideo,
  EfiBltVideoToVideo,
  EfiGraphicsOutputBltOperationMax
} EFI_GRAPHICS_OUTPUT_BLT_OPERATION;

typedef struct {
  uint32_t MaxMode;
  uint32_t Mode;
  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
  uint32_t SizeOfInfo;
  uint64_t FrameBufferBase;
  uint32_t FrameBufferSize;
} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;

typedef struct {
  uint64_t Signature;
  uint32_t Revision;
  uint32_t HeaderSize;
  uint32_t CRC32;
  uint32_t Reserved;
} EFI_TABLE_HEADER;

typedef struct {
  uint8_t Type;
  uint8_t SubType;
  uint8_t Length[2];
} EFI_DEVICE_PATH_PROTOCOL;

typedef EFI_STATUS(EFIAPI *EFI_EXIT)(EFI_HANDLE ImageHandle,
                                     EFI_STATUS ExitStatus,
                                     uintptr_t ExitDataSize,
                                     char16_t *opt_ExitData);

typedef EFI_STATUS(EFIAPI *EFI_GET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t *outopt_Attributes,
                                             uintptr_t *inout_DataSize,
                                             void *outopt_Data);
typedef EFI_STATUS(EFIAPI *EFI_SET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t Attributes,
                                             uintptr_t DataSize, void *Data);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME)(
    uintptr_t *inout_VariableNameSize, char16_t *inout_VariableName,
    EFI_GUID *inout_VendorGuid);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_VARIABLE_INFO)(
    uint32_t Attributes, uint64_t *out_MaximumVariableStorageSize,
    uint64_t *out_RemainingVariableStorageSize,
    uint64_t *out_MaximumVariableSize);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_PAGES)(EFI_ALLOCATE_TYPE Type,
                                               EFI_MEMORY_TYPE MemoryType,
                                               uintptr_t Pages,
                                               uint64_t *inout_Memory);
typedef EFI_STATUS(EFIAPI *EFI_FREE_PAGES)(uint64_t Memory, uintptr_t Pages);
typedef EFI_STATUS(EFIAPI *EFI_GET_MEMORY_MAP)(
    uintptr_t *inout_MemoryMapSize, EFI_MEMORY_DESCRIPTOR *inout_MemoryMap,
    uintptr_t *out_MapKey, uintptr_t *out_DescriptorSize,
    uint32_t *out_DescriptorVersion);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_POOL)(EFI_MEMORY_TYPE PoolType,
                                              uintptr_t Size, void *out_Buffer);
typedef EFI_STATUS(EFIAPI *EFI_FREE_POOL)(void *Buffer);
typedef void(EFIAPI *EFI_SET_MEM)(void *Buffer, uintptr_t Size, uint8_t Value);
typedef void(EFIAPI *EFI_COPY_MEM)(void *Destination, void *Source,
                                   uintptr_t Length);

typedef EFI_STATUS(EFIAPI *EFI_CHECK_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_CLOSE_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_SIGNAL_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_WAIT_FOR_EVENT)(uintptr_t NumberOfEvents,
                                               EFI_EVENT *Events,
                                               uintptr_t *out_Index);
typedef EFI_STATUS(EFIAPI *EFI_SET_TIMER)(EFI_EVENT Event, EFI_TIMER_DELAY Type,
                                          uint64_t TriggerTime);
typedef void(EFIAPI *EFI_EVENT_NOTIFY)(EFI_EVENT Event, void *Context);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT)(uint32_t Type, uintptr_t NotifyTpl,
                                             EFI_EVENT_NOTIFY NotifyFunction,
                                             void *NotifyContext,
                                             EFI_EVENT *out_Event);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT_EX)(
    uint32_t Type, uintptr_t NotifyTpl, EFI_EVENT_NOTIFY opt_NotifyFunction,
    const void *opt_NotifyContext, const EFI_GUID *opt_EventGroup,
    EFI_EVENT *out_Event);

typedef EFI_STATUS(EFIAPI *EFI_UPDATE_CAPSULE)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t opt_ScatterGatherList);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t *out_MaximumCapsuleSize, EFI_RESET_TYPE *out_ResetType);
typedef EFI_STATUS(EFIAPI *EFI_GET_WAKEUP_TIME)(bool32 *out_Enabled,
                                                bool32 *out_Pending,
                                                EFI_TIME *out_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WAKEUP_TIME)(bool32 Enable,
                                                EFI_TIME *opt_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WATCHDOG_TIMER)(uintptr_t Timeout,
                                                   uint64_t WatchdogCode,
                                                   uintptr_t DataSize,
                                                   char16_t *opt_WatchdogData);
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)(EFI_GUID *Protocol,
                                                void *Registration,
                                                void *Interface);

typedef EFI_STATUS(EFIAPI *EFI_SET_TIME)(EFI_TIME *Time);
typedef EFI_STATUS(EFIAPI *EFI_GET_TIME)(
    EFI_TIME *out_Time, EFI_TIME_CAPABILITIES *outopt_Capabilities);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT)(
    uint32_t *out_HighCount);
typedef EFI_STATUS(EFIAPI *EFI_STALL)(uintptr_t Microseconds);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT)(uint64_t *out_Count);

typedef EFI_STATUS(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP)(
    uintptr_t MemoryMapSize, uintptr_t DescriptorSize,
    uint32_t DescriptorVersion, EFI_MEMORY_DESCRIPTOR *VirtualMap);
typedef void(EFIAPI *EFI_RESET_SYSTEM)(EFI_RESET_TYPE ResetType,
                                       EFI_STATUS ResetStatus,
                                       uintptr_t DataSize, void *opt_ResetData);
typedef EFI_STATUS(EFIAPI *EFI_CONVERT_POINTER)(uintptr_t DebugDisposition,
                                                void **inout_Address);

typedef EFI_STATUS(EFIAPI *EFI_INPUT_RESET)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_INPUT_READ_KEY)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, EFI_INPUT_KEY *out_Key);

typedef EFI_STATUS(EFIAPI *EFI_TEXT_RESET)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_TEST_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_QUERY_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber,
    uint64_t *out_Columns, uint64_t *out_Rows);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_ATTRIBUTE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Attribute);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_CLEAR_SCREEN)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_CURSOR_POSITION)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Column, uint64_t Row);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_ENABLE_CURSOR)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 Visible);

typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber,
    uint32_t *SizeOfInfo, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
    EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
    EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, uint32_t SourceX,
    uint32_t SourceY, uint32_t DestinationX, uint32_t DestinationY,
    uint32_t Width, uint32_t Height, uint32_t Delta);

typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(EFI_HANDLE Handle,
                                                EFI_GUID *Protocol,
                                                void *out_Interface);

typedef EFI_STATUS(EFIAPI *EFI_IMAGE_LOAD)(bool32 BootPolicy,
                                           EFI_HANDLE ParentImageHandle,
                                           EFI_DEVICE_PATH_PROTOCOL *DevicePath,
                                           void *opt_SourceBuffer,
                                           uintptr_t SourceSize,
                                           EFI_HANDLE *out_ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_UNLOAD)(EFI_HANDLE ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_EXIT_BOOT_SERVICES)(EFI_HANDLE ImageHandle,
                                                   uintptr_t MapKey);

typedef struct {
  EFI_TABLE_HEADER Hdr;
  EFI_GET_TIME GetTime;
  EFI_SET_TIME SetTime;
  EFI_GET_WAKEUP_TIME GetWakeupTime;
  EFI_SET_WAKEUP_TIME SetWakeupTime;
  EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap;
  EFI_CONVERT_POINTER ConvertPointer;
  EFI_GET_VARIABLE GetVariable;
  EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName;
  EFI_SET_VARIABLE SetVariable;
  EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount;
  EFI_RESET_SYSTEM ResetSystem;
  EFI_UPDATE_CAPSULE UpdateCapsule;
  EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;
  EFI_QUERY_VARIABLE_INFO QueryVariableInfo;
} EFI_RUNTIME_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  void *RaiseTPL;
  void *RestoreTPL;
  EFI_ALLOCATE_PAGES AllocatePages;
  EFI_FREE_PAGES FreePages;
  EFI_GET_MEMORY_MAP GetMemoryMap;
  EFI_ALLOCATE_POOL AllocatePool;
  EFI_FREE_POOL FreePool;
  EFI_CREATE_EVENT CreateEvent;
  EFI_SET_TIMER SetTimer;
  EFI_WAIT_FOR_EVENT WaitForEvent;
  EFI_SIGNAL_EVENT SignalEvent;
  EFI_CLOSE_EVENT CloseEvent;
  EFI_CHECK_EVENT CheckEvent;
  void *InstallProtocolInterface;
  void *ReinstallProtocolInterface;
  void *UninstallProtocolInterface;
  EFI_HANDLE_PROTOCOL HandleProtocol;
  void *Reserved;
  void *RegisterProtocolNotify;
  void *LocateHandle;
  void *LocateDevicePath;
  void *InstallConfigurationTable;
  EFI_IMAGE_LOAD LoadImage;
  void *StartImage;
  EFI_EXIT Exit;
  EFI_IMAGE_UNLOAD UnloadImage;
  EFI_EXIT_BOOT_SERVICES ExitBootServices;
  EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount;
  EFI_STALL Stall;
  EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;
  void *ConnectController;
  void *DisconnectController;
  void *OpenProtocol;
  void *CloseProtocol;
  void *OpenProtocolInformation;
  void *ProtocolsPerHandle;
  void *LocateHandleBuffer;
  EFI_LOCATE_PROTOCOL LocateProtocol;
  void *InstallMultipleProtocolInterfaces;
  void *UninstallMultipleProtocolInterfaces;
  void *CalculateCrc32;
  EFI_COPY_MEM CopyMem;
  EFI_SET_MEM SetMem;
  EFI_CREATE_EVENT_EX CreateEventEx;
} EFI_BOOT_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  char16_t *FirmwareVendor;
  uint32_t FirmwareRevision;
  EFI_HANDLE ConsoleInHandle;
  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
  EFI_HANDLE ConsoleOutHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
  EFI_HANDLE StandardErrorHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
  EFI_RUNTIME_SERVICES *RuntimeServices;
  EFI_BOOT_SERVICES *BootServices;
  uintptr_t NumberOfTableEntries;
  EFI_CONFIGURATION_TABLE *ConfigurationTable;
} EFI_SYSTEM_TABLE;

struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
  EFI_INPUT_RESET Reset;
  EFI_INPUT_READ_KEY ReadKeyStroke;
  EFI_EVENT WaitForKey;
};

struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
  EFI_TEXT_RESET Reset;
  EFI_TEXT_STRING OutputString;
  EFI_TEXT_TEST_STRING TestString;
  EFI_TEXT_QUERY_MODE QueryMode;
  EFI_TEXT_SET_MODE SetMode;
  EFI_TEXT_SET_ATTRIBUTE SetAttribute;
  EFI_TEXT_CLEAR_SCREEN ClearScreen;
  EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition;
  EFI_TEXT_ENABLE_CURSOR EnableCursor;
  EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;
};

struct _EFI_GRAPHICS_OUTPUT_PROTOCOL {
  EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
};

typedef struct {
  uint32_t Revision;
  EFI_HANDLE ParentHandle;
  EFI_SYSTEM_TABLE *SystemTable;
  EFI_HANDLE DeviceHandle;
  EFI_DEVICE_PATH_PROTOCOL *FilePath;
  void *Reserved;
  uint32_t LoadOptionsSize;
  void *LoadOptions;
  void *ImageBase;
  uint64_t ImageSize;
  EFI_MEMORY_TYPE ImageCodeType;
  EFI_MEMORY_TYPE ImageDataType;
  EFI_IMAGE_UNLOAD Unload;
} EFI_LOADED_IMAGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/events.h */

#define COSMOPOLITAN_LIBC_NT_EVENTS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » events                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int32_t GetMessage(struct NtMsg *lpMsg, int64_t hWnd, uint32_t wMsgFilterMin,
                   uint32_t wMsgFilterMax);
int32_t TranslateMessage(const struct NtMsg *lpMsg);
intptr_t DispatchMessage(const struct NtMsg *lpMsg);
void PostQuitMessage(int nExitCode);
bool32 GetCursorPos(struct NtPoint *lpPoint);
int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                    int64_t lParam);

#define EVENTLOG_SUCCESS          0x00000000
#define EVENTLOG_ERROR_TYPE       0x00000001
#define EVENTLOG_WARNING_TYPE     0x00000002
#define EVENTLOG_INFORMATION_TYPE 0x00000004
#define EVENTLOG_AUDIT_SUCCESS    0x00000008
#define EVENTLOG_AUDIT_FAILURE    0x00000010

int32_t ReportEventA(int64_t handle, uint16_t wType, uint16_t wCategory,
                     uint32_t dwEventID, const char *lpUserId,
                     uint16_t wNumStrings, uint32_t dwDataSize,
                     const char **lpStrings, void **lpRawData);
int64_t RegisterEventSource(const char16_t *lpUNCServerName,
                            const char16_t *lpSourceName);
int32_t DeregisterEventSource(uint64_t handle);

int64_t CreateEvent(const struct NtSecurityAttributes *opt_lpEventAttributes,
                    bool32 bManualReset, bool32 bInitialState,
                    const char16_t *opt_lpName);
int64_t CreateEventA(const struct NtSecurityAttributes *opt_lpEventAttributes,
                     bool32 bManualReset, bool32 bInitialState,
                     const char *opt_lpName);
int64_t CreateEventEx(const struct NtSecurityAttributes *lpEventAttributes,
                      const char16_t *lpName, uint32_t dwFlags,
                      uint32_t dwDesiredAccess);

int32_t SetEvent(int64_t hEvent);
int32_t ResetEvent(int64_t hEvent);
int32_t PulseEvent(int64_t hEvent);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/files.h */

#define COSMOPOLITAN_LIBC_NT_FILES_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » files                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtHandleFlagInherit          1 /* SetHandleInformation */
#define kNtHandleFlagProtectFromClose 2

#define kNtFindFirstExCaseSensitive 1
#define kNtFindFirstExLargeFetch    2

#define kNtDuplicateCloseSource 1
#define kNtDuplicateSameAccess  2

COSMOPOLITAN_C_START_

intptr_t LoadResource(int64_t hModule, int64_t hResInfo);
uint32_t SetHandleCount(uint32_t uNumber);
uint32_t GetLogicalDrives(void);
bool32 FlushFileBuffers(int64_t hFile);

int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess,
                   uint32_t dwShareMode, uint32_t dwFlagsAndAttributes);

bool32 DeleteFile(const char16_t *lpFileName) paramsnonnull();

bool32 CopyFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName, bool32 bFailIfExists)
    paramsnonnull();

bool32 MoveFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName) paramsnonnull();
bool32 MoveFileEx(const char16_t *lpExistingFileName,
                  const char16_t *opt_lpNewFileName, int dwFlags)
    paramsnonnull((1));

bool32 SetCurrentDirectory(const char16_t *lpPathName);
uint32_t GetCurrentDirectory(uint32_t nBufferLength, char16_t *out_lpBuffer);

bool32 CreateDirectory(const char16_t *lpPathName,
                       const struct NtSecurityAttributes *lpSecurityAttributes);
bool32 RemoveDirectory(const char16_t *lpPathName);

bool32 DuplicateHandle(int64_t hSourceProcessHandle, int64_t hSourceHandle,
                       int64_t hTargetProcessHandle, int64_t *lpTargetHandle,
                       uint32_t dwDesiredAccess, bool32 bInheritHandle,
                       uint32_t dwOptions);

bool32 GetHandleInformation(int64_t hObject, uint32_t *out_lpdwFlags);
bool32 SetHandleInformation(int64_t hObject, uint32_t dwMask, uint32_t dwFlags);
int GetFileType(int64_t hFile);

bool32 GetFileInformationByHandleEx(int64_t hFile,
                                    uint32_t FileInformationClass,
                                    void *out_lpFileInformation,
                                    uint32_t dwBufferSize);

bool32 GetFileInformationByHandle(
    int64_t hFile, struct NtByHandleFileInformation *lpFileInformation);
bool32 SetFileInformationByHandle(int64_t hFile, int FileInformationClass,
                                  const void *lpFileInformation,
                                  uint32_t dwBufferSize);

uint32_t GetFileAttributes(const char16_t *lpFileName);
bool32 GetFileAttributesEx(
    const char16_t *lpFileName, int fInfoLevelId /* kNtGetFileExInfoStandard */,
    void *out_lpFileInformation /* → struct NtWin32FileAttributeData * */)
    paramsnonnull();

uint32_t GetCompressedFileSize(const char16_t *lpFileName,
                               uint32_t *lpFileSizeHigh);
bool32 SetFileAttributes(const char16_t *lpFileName, uint32_t dwFileAttributes);
bool32 GetFileTime(int64_t hFile, struct NtFileTime *opt_lpCreationFileTime,
                   struct NtFileTime *opt_lpLastAccessFileTime,
                   struct NtFileTime *opt_lpLastWriteFileTime);
bool32 SetFileTime(int64_t hFile,
                   const struct NtFileTime *opt_lpCreationFileTime,
                   const struct NtFileTime *opt_lpLastAccessFileTime,
                   const struct NtFileTime *opt_lpLastWriteFileTime);

bool32 DeviceIoControl(int64_t hDevice, uint32_t dwIoControlCode,
                       void *lpInBuffer, uint32_t nInBufferSize,
                       void *lpOutBuffer, uint32_t nOutBufferSize,
                       uint32_t *lpBytesReturned,
                       struct NtOverlapped *lpOverlapped);

bool32 LockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToLockLow,
                uint32_t nNumberOfBytesToLockHigh);
bool32 UnlockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                  uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToUnlockLow,
                  uint32_t nNumberOfBytesToUnlockHigh);
bool32 LockFileEx(int64_t hFile, uint32_t dwFlags, uint32_t dwReserved,
                  uint32_t nNumberOfBytesToLockLow,
                  uint32_t nNumberOfBytesToLockHigh,
                  struct NtOverlapped *lpOverlapped) paramsnonnull();
bool32 UnlockFileEx(int64_t hFile, uint32_t dwReserved,
                    uint32_t nNumberOfBytesToUnlockLow,
                    uint32_t nNumberOfBytesToUnlockHigh,
                    struct NtOverlapped *lpOverlapped) paramsnonnull();

bool32 CreateHardLink(const char16_t *lpFileName,
                      const char16_t *lpExistingFileName,
                      const struct NtSecurityAttributes *reserved)
    paramsnonnull((1, 2));
bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName,
                          const char16_t *lpTargetPathName, uint32_t dwFlags)
    paramsnonnull();

bool32 SetEndOfFile(int64_t hFile);
bool32 SetFileValidData(int64_t hFile, int64_t ValidDataLength);

bool32 GetFileSecurity(const char16_t *lpFileName,
                       uint32_t RequestedInformation,
                       struct NtSecurityDescriptor *pSecurityDescriptor,
                       uint32_t nLength, uint32_t *lpnLengthNeeded);

bool32 OpenProcessToken(int64_t hProcessHandle, uint32_t dwDesiredAccess,
                        int64_t *out_hTokenHandle);
bool32 DuplicateToken(int64_t hExistingTokenHandle, int dwImpersonationLevel,
                      int64_t *out_hDuplicateTokenHandle);
bool32 DuplicateTokenEx(int64_t hExistingToken, unsigned int dwDesiredAccess,
                        const struct NtSecurityAttributes *lpTokenAttributes,
                        int ImpersonationLevel, int TokenType,
                        int64_t *out_phNewToken);

bool32 AccessCheck(struct NtSecurityDescriptor *pSecurityDescriptor,
                   int64_t ClientToken, unsigned int DesiredAccess,
                   struct NtGenericMapping *lpGenericMapping,
                   struct NtPrivilegeSet *lpPrivilegeSet,
                   unsigned int *PrivilegeSetLength,
                   unsigned int *GrantedAccess, bool32 *AccessStatus);

void MapGenericMask(uint32_t *AccessMask,
                    struct NtGenericMapping *GenericMapping);

int64_t FindFirstFile(const char16_t *lpFileName,
                      struct NtWin32FindData *out_lpFindFileData);
int64_t FindFirstFileEx(const char16_t *lpFileName, int fInfoLevelId,
                        void *out_lpFindFileData, int fSearchOp,
                        void *reserved_lpSearchFilter,
                        uint32_t dwAdditionalFlags);
bool32 FindNextFile(int64_t hFindFile,
                    struct NtWin32FindData *out_lpFindFileData);
bool32 FindClose(int64_t hFindFile);

int64_t FindFirstVolume(char16_t *out_lpszVolumeName, uint32_t cchBufferLength);
bool32 FindNextVolume(int64_t inout_hFindVolume, char16_t *out_lpszVolumeName,
                      uint32_t cchBufferLength);
bool32 FindVolumeClose(int64_t hFindVolume);

bool32 ReadFileScatter(
    int64_t hFileOpenedWithOverlappedAndNoBuffering,
    const union NtFileSegmentElement
        aNullTerminatedPageAlignedSizedSegmentArray[],
    uint32_t nNumberOfBytesToReadThatsMultipleOfFileVolumeSectorSize,
    uint32_t *lpReserved, struct NtOverlapped *inout_lpOverlapped)
    paramsnonnull();

bool32 WriteFileGather(int64_t hFileOpenedWithOverlappedAndNoBuffering,
                       const union NtFileSegmentElement aSegmentArray[],
                       uint32_t nNumberOfBytesToWrite, uint32_t *lpReserved,
                       struct NtOverlapped inout_lpOverlapped) paramsnonnull();

#define kNtFileNameNormalized 0x0
#define kNtFileNameOpened     0x8
#define kNtVolumeNameDos      0x0 /* e.g. \\?\C:\Users\jart */
#define kNtVolumeNameGuid     0x1 /* e.g. \\?\Volume{ea38-etc.}\Users\jart */
#define kNtVolumeNameNt       0x2 /* e.g. \Device\HarddiskVolume4\Users\jart */
#define kNtVolumeNameNone     0x4 /* e.g. \Users\jart */
uint32_t GetFinalPathNameByHandle(int64_t hFile, char16_t *out_path,
                                  uint32_t arraylen, uint32_t flags);

uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength,
                         char16_t *lpBuffer, char16_t **lpFilePart);

bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped,
                           uint32_t *lpNumberOfBytesTransferred, bool32 bWait);
bool32 GetOverlappedResultEx(int64_t hFile, struct NtOverlapped *lpOverlapped,
                             uint32_t *lpNumberOfBytesTransferred,
                             uint32_t dwMilliseconds, bool32 bAlertable);

bool32 GetVolumePathName(const char16_t *lpszFileName,
                         char16_t *lpszVolumePathName,
                         uint32_t cchBufferLength);

bool32 GetVolumeInformationByHandle(int64_t hFile,
                                    char16_t *opt_out_lpVolumeNameBuffer,
                                    uint32_t nVolumeNameSize,
                                    uint32_t *opt_out_lpVolumeSerialNumber,
                                    uint32_t *opt_out_lpMaximumComponentLength,
                                    uint32_t *opt_out_lpFileSystemFlags,
                                    char16_t *opt_out_lpFileSystemNameBuffer,
                                    uint32_t nFileSystemNameSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/files.inc */

#define CopyFile(...) __imp_CopyFileW(__VA_ARGS__)
extern typeof(CopyFile) *const __imp_CopyFileW __msabi;

#define GetFileType(...) __imp_GetFileType(__VA_ARGS__)
extern typeof(GetFileType) *const __imp_GetFileType __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iocp.h */

#define COSMOPOLITAN_LIBC_NT_IOCP_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » i/o completion ports                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtFileSkipCompletionPortOnSuccess 1
#define kNtFileSkipSetEventOnHandle        2

COSMOPOLITAN_C_START_

typedef void (*NtOverlappedCompletionRoutine)(
    uint32_t dwErrorCode, uint32_t dwNumberOfBytesTransfered,
    struct NtOverlapped *inout_lpOverlapped);

int64_t CreateIoCompletionPort(int64_t FileHandleOrNeg1,
                               int64_t opt_ExistingCompletionPortOrZero,
                               uint64_t CompletionKey,
                               uint32_t NumberOfConcurrentThreads);

bool32 GetQueuedCompletionStatus(int64_t CompletionPort,
                                 uint32_t *lpNumberOfBytesTransferred,
                                 uint64_t *out_lpCompletionKey,
                                 struct NtOverlapped **out_lpOverlapped,
                                 uint32_t dwMilliseconds);

bool32 GetQueuedCompletionStatusEx(
    int64_t CompletionPort,
    struct NtOverlappedEntry *out_lpCompletionPortEntries, uint32_t ulCount,
    uint32_t *out_ulNumEntriesRemoved, uint32_t dwMilliseconds,
    bool32 fAlertable);

bool32 PostQueuedCompletionStatus(int64_t CompletionPort,
                                  uint32_t dwNumberOfBytesTransferred,
                                  uint64_t dwCompletionKey,
                                  struct NtOverlapped *opt_lpOverlapped);

bool32 SetFileCompletionNotificationModes(int64_t FileHandle,
                                          unsigned char Flags);

bool32 ReadFileEx(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                  uint32_t *lpNumberOfBytesRead,
                  struct NtOverlapped *opt_lpOverlapped,
                  NtOverlappedCompletionRoutine lpCompletionRoutine);

bool32 WriteFileEx(int64_t hFile, const void *lpBuffer,
                   uint32_t nNumberOfBytesToWrite,
                   struct NtOverlapped *lpOverlapped,
                   NtOverlappedCompletionRoutine lpCompletionRoutine);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_IPC_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ipc                                      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* CreateNamedPipe:dwOpenMode */
#define kNtPipeAccessInbound  0x00000001
#define kNtPipeAccessOutbound 0x00000002
#define kNtPipeAccessDuplex   0x00000003

/* CreateNamedPipe::dwPipeMode */
#define kNtPipeWait                0x00000000
#define kNtPipeNowait              0x00000001
#define kNtPipeReadmodeByte        0x00000000
#define kNtPipeReadmodeMessage     0x00000002
#define kNtPipeTypeByte            0x00000000
#define kNtPipeTypeMessage         0x00000004
#define kNtPipeAcceptRemoteClients 0x00000000
#define kNtPipeRejectRemoteClients 0x00000008

/* CreateNamedPipe::nMaxInstances */
#define kNtPipeUnlimitedInstances 255

/* GetNamedPipeInfo */
#define kNtPipeClientEnd 0x00000000
#define kNtPipeServerEnd 0x00000001

COSMOPOLITAN_C_START_

bool32 CreatePipe(int64_t *out_hReadPipe, int64_t *out_hWritePipe,
                  const struct NtSecurityAttributes *opt_lpPipeAttributes,
                  uint32_t nSize) paramsnonnull((1, 2));

int64_t CreateNamedPipe(
    const char16_t *lpName, uint32_t dwOpenMode, uint32_t dwPipeMode,
    uint32_t nMaxInstances, uint32_t nOutBufferSize, uint32_t nInBufferSize,
    uint32_t nDefaultTimeOut,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes)
    paramsnonnull((1));

bool32 CallNamedPipe(const char16_t *lpNamedPipeName, void *lpInBuffer,
                     uint32_t nInBufferSize, void *lpOutBuffer,
                     uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                     uint32_t nTimeOut);

bool32 ConnectNamedPipe(int64_t hNamedPipe, struct NtOverlapped *lpOverlapped);
bool32 WaitNamedPipe(const char16_t *lpNamedPipeName, uint32_t nTimeOut);
bool32 DisconnectNamedPipe(int64_t hNamedPipe);

bool32 SetNamedPipeHandleState(int64_t hNamedPipe, uint32_t *lpMode,
                               uint32_t *lpMaxCollectionCount,
                               uint32_t *lpCollectDataTimeout);

bool32 PeekNamedPipe(int64_t hNamedPipe, void *lpBuffer, uint32_t nBufferSize,
                     uint32_t *opt_lpBytesRead, uint32_t *opt_lpTotalBytesAvail,
                     uint32_t *opt_lpBytesLeftThisMessage);

bool32 TransactNamedPipe(int64_t hNamedPipe, void *lpInBuffer,
                         uint32_t nInBufferSize, void *lpOutBuffer,
                         uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                         struct NtOverlapped *lpOverlapped);

bool32 GetNamedPipeInfo(int64_t hNamedPipe, uint32_t *opt_out_lpFlags,
                        uint32_t *opt_out_lpOutBufferSize,
                        uint32_t *opt_out_lpInBufferSize,
                        uint32_t *opt_out_lpMaxInstances);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iphlpapi.h */

#define COSMOPOLITAN_LIBC_NT_IPHLPAPI_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ip helper api                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetAdaptersAddresses(uint32_t Family, uint32_t Flags, void *Reserved,
                              struct NtIpAdapterAddresses *AdapterAddresses,
                              uint32_t *SizePointer);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_MEMORY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » memory                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtNumaNoPreferredNode 0xffffffffu

COSMOPOLITAN_C_START_

void *LocalFree(void *hMem);

int64_t CreateFileMapping(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName);
int64_t CreateFileMappingNuma(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName, uint32_t nndDesiredNumaNode);

void *MapViewOfFileEx(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                      uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                      size_t dwNumberOfBytesToMap,
                      void *opt_lpDesiredBaseAddress);
void *MapViewOfFileExNuma(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                          uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                          size_t dwNumberOfBytesToMap,
                          void *opt_lpDesiredBaseAddress,
                          uint32_t nndDesiredNumaNode);

bool32 UnmapViewOfFile(const void *lpBaseAddress);
bool32 FlushViewOfFile(const void *lpBaseAddress,
                       size_t dwNumberOfBytesToFlush);

void *VirtualAlloc(void *opt_lpAddress, uint64_t dwSize,
                   uint32_t flAllocationType, uint32_t flProtect);
bool32 VirtualFree(void *lpAddress, uint64_t dwSize, uint32_t dwFreeType);
bool32 VirtualProtect(void *lpAddress, uint64_t dwSize, uint32_t flNewProtect,
                      uint32_t *lpflOldProtect) paramsnonnull();
bool32 VirtualLock(const void *lpAddress, size_t dwSize);
bool32 VirtualUnlock(const void *lpAddress, size_t dwSize);
uint64_t VirtualQuery(const void *lpAddress,
                      struct NtMemoryBasicInformation *lpBuffer,
                      uint64_t dwLength);
void *VirtualAllocEx(int64_t hProcess, void *lpAddress, uint64_t dwSize,
                     uint32_t flAllocationType, uint32_t flProtect);

int64_t GetProcessHeap(void);
void *HeapAlloc(int64_t hHeap, uint32_t dwFlags, size_t dwBytes) __wur;
bool32 HeapFree(int64_t hHeap, uint32_t dwFlags, void *opt_lpMem);
void *HeapReAlloc(int64_t hHeap, uint32_t dwFlags, void *lpMem,
                  size_t dwBytes) __wur;

void *GlobalAlloc(uint32_t uFlags, uint64_t dwBytes) __wur;
void *GlobalFree(void *hMem);

/**
 * @param AllocationType
 *     - kNtMemReserve
 *     - kNtMemReplacePlaceholder
 *     - kNtMemLargePages
 */
void *MapViewOfFile3(
    intptr_t FileMapping, intptr_t Process, void *opt_BaseAddress,
    uint64_t Offset, size_t ViewSize, unsigned AllocationType,
    unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

void *VirtualAlloc2(
    intptr_t opt_Process, void *opt_BaseAddress, size_t Size,
    unsigned AllocationType, unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/memory.inc */

extern typeof(LocalFree) *const __imp_LocalFree __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/messagebox.h */

#define COSMOPOLITAN_LIBC_NT_MESSAGEBOX_H_
COSMOPOLITAN_C_START_

int MessageBox(int64_t hWnd, const char16_t *lpText, const char16_t *lpCaption,
               uint32_t mbType);
int MessageBoxEx(int64_t hWnd, const char16_t *lpText,
                 const char16_t *lpCaption, uint32_t mbType,
                 uint16_t wLanguageId);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdll.h */

#define COSMOPOLITAN_LIBC_NT_NTDLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

#define __nt_system_call_dispatcher (wambda *)0x7ffe0308

extern const struct NtUnicodeString *const RtlNtdllName;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » eponymous runtime      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define NT_PROCESS_FLAGS_CREATE_SUSPENDED 0x00000001
#define NT_PROCESS_FLAGS_INHERIT_HANDLES  0x00000002
#define NT_PROCESS_FLAGS_NO_SYNCHRONIZE   0x00000004
#define NT_RTL_CLONE_PARENT               0
#define NT_RTL_CLONE_CHILD                297

NtStatus NtCallbackReturn(void *opt_Result, uint32_t ResultLength,
                          int32_t Status);
NtStatus NtTestAlert(void);

NtStatus NtOpenFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                    struct NtObjectAttributes *ObjectAttributes,
                    struct NtIoStatusBlock *out_IoStatusBlock,
                    uint32_t ShareAccess, uint32_t OpenOptions);

NtStatus NtQueryInformationToken(int64_t TokenHandle,
                                 uint32_t TokenInformationClass,
                                 void *out_TokenInformation,
                                 uint32_t TokenInformationLength,
                                 uint32_t *out_ReturnLength);
NtStatus NtYieldExecution(void);
NtStatus NtQuerySystemInformation(uint32_t info_class, void *out_info,
                                  uint32_t info_size,
                                  uint32_t *out_bytes_received);
NtStatus NtReadVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                             void *out_Buffer, size_t BufferLength,
                             size_t *opt_out_ReturnLength);
NtStatus NtCreateTimer(void **out_TimerHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       uint32_t TimerType);
NtStatus NtSetTimer(void *TimerHandle, int64_t *DueTime, void *TimerApcRoutine,
                    void *TimerContext, int32_t Resume, int32_t Period,
                    int32_t *out_PreviousState);
NtStatus NtQueryObject(void *ObjectHandle, int ObjectInformationClass,
                       void *out_ObjectInformation,
                       uint32_t ObjectInformationLength,
                       uint32_t *opt_out_ReturnLength);
NtStatus NtQueryFullAttributesFile(
    struct NtObjectAttributes *attributes,
    struct NtFileNetworkOpenInformation *out_info);
NtStatus NtCreateKey(void **out_KeyHandle, uint32_t DesiredAccess,
                     struct NtObjectAttributes *ObjectAttributes,
                     uint32_t TitleIndex, struct NtUnicodeString *opt_Class,
                     uint32_t CreateOptions, uint32_t *opt_out_Disposition);
NtStatus NtOpenKey(void **out_KeyHandle, uint32_t DesiredAccess,
                   struct NtObjectAttributes *ObjectAttributes);
NtStatus NtSetValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                       uint32_t opt_TitleIndex, uint32_t Type, void *Data,
                       uint32_t DataSize);
NtStatus NtDeleteKey(void *KeyHandle);
NtStatus NtQueryValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                         int KeyValueInformationClass,
                         void *out_KeyValueInformation, uint32_t Length,
                         uint32_t *out_ResultLength);
NtStatus NtFlushKey(void *KeyHandle);
NtStatus NtEnumerateKey(int64_t hkey, uint32_t index, int info_class,
                        void *out_key_info, uint32_t key_info_size,
                        uint32_t *out_bytes_received);
NtStatus NtEnumerateValueKey(int64_t hKey, uint32_t index, int info_class,
                             void *out_key_info, uint32_t key_info_size,
                             uint32_t *out_bytes_received);
NtStatus NtQuerySystemTime(int64_t *SystemTime);
NtStatus NtDeleteFile(struct NtObjectAttributes *ObjectAttributes);
NtStatus NtFlushBuffersFile(int64_t FileHandle,
                            struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateIoCompletion(void **out_IoCompletionHandle,
                              uint32_t DesiredAccess,
                              struct NtObjectAttributes *ObjectAttributes,
                              uint32_t NumberOfConcurrentThreads);
NtStatus NtRaiseHardError(int32_t ErrorStatus, uint32_t NumberOfArguments,
                          uint32_t UnicodeStringArgumentsMask, void *Arguments,
                          uint32_t MessageBoxType,
                          uint32_t *out_MessageBoxResult);
NtStatus NtRaiseException(struct NtExceptionRecord *ExceptionRecord,
                          struct NtContext *Context, int32_t SearchFrames);
NtStatus NtCreateEvent(void **out_EventHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       int EventType, int32_t InitialState);
NtStatus NtWaitForSingleObject(void *ObjectHandle, int32_t Alertable,
                               int64_t *TimeOut);
NtStatus NtSetEvent(void *EventHandle, int32_t *opt_out_PreviousState);
NtStatus NtClearEvent(void *EventHandle);
NtStatus NtSignalAndWaitForSingleObject(void *ObjectToSignal,
                                        void *WaitableObject, int32_t Alertable,
                                        int64_t *opt_Time);
NtStatus NtQueryPerformanceCounter(int64_t *out_PerformanceCount,
                                   int64_t *opt_out_PerformanceFrequency);
NtStatus NtFsControlFile(int64_t FileHandle, void *opt_Event,
                         NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                         struct NtIoStatusBlock *out_IoStatusBlock,
                         uint32_t FsControlCode, void *opt_InputBuffer,
                         uint32_t InputBufferLength, void *opt_out_OutputBuffer,
                         uint32_t OutputBufferLength);
NtStatus NtCancelIoFile(int64_t FileHandle,
                        struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateProfile(void **out_ProfileHandle, int64_t ProcessHandle,
                         void *Base, uint32_t Size, uint32_t BucketShift,
                         uint32_t *Buffer, uint32_t BufferLength, int Source,
                         uint32_t ProcessorMask);
NtStatus NtSetIntervalProfile(uint32_t Interval, int Source);
NtStatus NtQueryIntervalProfile(int Source, uint32_t *out_Interval);
NtStatus NtStartProfile(void *ProfileHandle);
NtStatus NtStopProfile(void *ProfileHandle);
NtStatus NtCreateDirectoryObject(int64_t *out_DirectoryHandle,
                                 uint32_t DesiredAccess,
                                 struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenDirectoryObject(int64_t *out_DirectoryHandle,
                               uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenSymbolicLinkObject(int64_t *out_DirectoryHandle,
                                  uint32_t DesiredAccess,
                                  struct NtObjectAttributes *ObjectAttributes);
NtStatus NtQuerySymbolicLinkObject(int64_t DirectoryHandle,
                                   struct NtUnicodeString *inout_TargetName,
                                   uint32_t *opt_out_ReturnLength);
NtStatus ZwAreMappedFilesTheSame(void *Address1, void *Address2);
NtStatus NtQueryVolumeInformationFile(int64_t FileHandle,
                                      struct NtIoStatusBlock *out_IoStatusBlock,
                                      void *out_FsInformation, uint32_t Length,
                                      uint32_t FsInformationClass);
NtStatus NtQuerySecurityObject(
    int64_t handle, int RequestedInformation,
    struct NtSecurityDescriptor *out_SecurityDescriptor,
    uint32_t SecurityDescriptorLength, uint32_t *out_ReturnLength);
NtStatus NtQueueApcThread(int64_t ThreadHandle, NtPkNormalRoutine ApcRoutine,
                          void *opt_ApcContext, void *opt_Argument1,
                          void *opt_Argument2);
NtStatus NtFlushInstructionCache(int64_t ProcessHandle, void *opt_BaseAddress,
                                 size_t FlushSize);
NtStatus NtQueryAttributesFile(const struct NtObjectAttributes *object,
                               struct NtFileBasicInformation *file_information);
NtStatus NtQueryDirectoryFile(
    int64_t FileHandle, void *opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    void *out_FileInformation, uint32_t FileInformationLength,
    uint32_t FileInformationClass, int32_t ReturnSingleEntry,
    struct NtUnicodeString *opt_FileName, int32_t RestartScan);
NtStatus NtFlushVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                              uint32_t **inout_FlushSize,
                              struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtQueryInformationJobObject(void *JobHandle, int JobInformationClass,
                                     void *out_JobInformation,
                                     uint32_t JobInformationLength,
                                     uint32_t *opt_out_ReturnLength);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » runtime library        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

NtStatus RtlInitializeCriticalSection(struct NtCriticalSection *out_crit);
NtStatus RtlDeleteCriticalSection(struct NtCriticalSection *crit);
NtStatus RtlEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlLeaveCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlTryEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlInitUnicodeString(struct NtUnicodeString *inout_DestinationString,
                              const char16_t *SourceString);
void RtlFreeUnicodeString(struct NtUnicodeString **string);
NtStatus RtlQueryEnvironmentVariable_U(char16_t *Environment,
                                       struct NtUnicodeString *Name,
                                       struct NtUnicodeString *Value);
NtStatus RtlConvertSidToUnicodeString(struct NtUnicodeString *out_UnicodeString,
                                      void *Sid,
                                      int32_t AllocateDestinationString);
void *RtlCreateHeap(uint32_t flags, void *base, size_t reserve_sz,
                    size_t commit_sz, void *lock, void *params);
NtStatus RtlDestroyHeap(void *base);
void *RtlAllocateHeap(int64_t heap, uint32_t flags, size_t size);
void *RtlReAllocateHeap(int64_t heap, uint32_t flags, void *ptr, size_t size);
NtStatus RtlFreeHeap(int64_t heap, uint32_t flags, void *ptr);
size_t RtlSizeHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlValidateHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlLockHeap(int64_t heap);
NtStatus RtlUnlockHeap(int64_t heap);
NtStatus RtlGetProcessHeaps(uint32_t count, void **out_Heaps);
NtStatus RtlWalkHeap(int64_t heap, void *out_Info);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntdll.inc */

#define NtYieldExecution(...) __imp_NtYieldExecution(__VA_ARGS__)

extern typeof(NtYieldExecution) *const __imp_NtYieldExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdllimport.h */

/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8     -*-│
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8                                 :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney                              │
│                                                                              │
│ Permission to use, copy, modify, and/or distribute this software for         │
│ any purpose with or without fee is hereby granted, provided that the         │
│ above copyright notice and this permission notice appear in all copies.      │
│                                                                              │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             │
│ PERFORMANCE OF THIS SOFTWARE.                                                │
╚─────────────────────────────────────────────────────────────────────────────*/
#define COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_
#ifdef __ASSEMBLER__
/* clang-format off */

.macro	.ntimp	fn:req name:req
#ifdef __x86_64__
	.yoink	_init_ntdll
	.initbss 202,_init_ntdll.\fn
__imp_\fn:
	.quad	0
	.endobj	__imp_\fn,globl,hidden
	.previous
	.initro 202,_init_ntdll.2.\fn
	.quad	RVA(.L\fn)
	.previous
	.section .rodata.str1.1,"aSM",@progbits,1
.L\fn:
	.asciz	"\fn"
	.previous
#elif defined(__aarch64__)
	.section .data.nt.\fn,"aw",@progbits
	.globl	__imp_\fn
	.balign	8
__imp_\fn:
	.quad	\name
	.weak	\name
#endif
.endm

/* clang-format on */
#endif /* __ASSEMBLER__ */


/*!BEGIN libc/nt/paint.h */

#define COSMOPOLITAN_LIBC_NT_PAINT_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » cpu graphics                             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t BeginPaint(int64_t hWnd, struct NtPaintStruct *lpPaint);
int32_t EndPaint(int64_t hWnd, const struct NtPaintStruct *lpPaint);
int32_t BitBlt(int64_t hdc, int x, int y, int cx, int cy, int64_t hdcSrc,
               int x1, int y1, uint32_t rop);
int32_t GetClientRect(int64_t hWnd, struct NtRect *lpRect);
int32_t GetWindowRect(int64_t hWnd, struct NtRect *lpRect);
int32_t SetBkMode(int64_t hdc, int mode);
uint32_t SetTextColor(int64_t hdc, uint32_t color);
uint32_t SetTextAlign(int64_t hdc, uint32_t align);
int32_t SetTextJustification(int64_t hdc, int extra, int count);
int32_t DrawText(int64_t hdc, const char16_t *lpchText, int cchText,
                 struct NtRect *lprc, uint32_t format);
int32_t DrawTextEx(int64_t hdc, char16_t *lpchText, int cchText,
                   struct NtRect *lprc, uint32_t format,
                   struct NtDrawTextParams *lpdtp);
int32_t FillRect(int64_t hDC, const struct NtRect *lpRC, int64_t hBrush);
uint32_t GetPixel(int64_t hdc, int x, int y);
uint32_t SetPixel(int64_t hdc, int x, int y, uint32_t color);
bool32 RedrawWindow(int64_t hWnd, const struct NtRect *opt_lprcUpdate,
                    int64_t opt_hrgnUpdate, uint32_t rdwFlags);
int64_t CreateCompatibleDC(int64_t hdc);
int64_t CreateCompatibleBitmap(int64_t hdc, int cx, int cy);
int64_t SelectObject(int64_t hdc, int64_t h);
bool32 DeleteObject(int64_t ho);
bool32 DeleteDC(int64_t hdc);
int SaveDC(int64_t hdc);
bool32 RestoreDC(int64_t hdc, int nSavedDC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/paint.inc */

#define SetPixel(...) __imp_SetPixel(__VA_ARGS__)
#define GetPixel(...) __imp_GetPixel(__VA_ARGS__)

extern typeof(SetPixel) *const __imp_SetPixel __msabi;
extern typeof(GetPixel) *const __imp_GetPixel __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/pdh.h */

#define COSMOPOLITAN_LIBC_NT_PDH_H_

/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » performance counters                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int PdhOpenQuery(const char16_t *opt_szDataSource, uint32_t *dwUserData,
                 int64_t *out_phQuery);

int PdhAddEnglishCounter(int64_t hQuery, const char16_t *szFullCounterPath,
                         uint32_t *dwUserData, int64_t *out_phCounter);

int PdhCollectQueryDataEx(int64_t hQuery, uint32_t dwIntervalTime,
                          int64_t hNewDataEvent);

int PdhGetFormattedCounterValue(int64_t hCounter, uint32_t dwFormat,
                                uint32_t *out_opt_lpdwType,
                                struct NtPdhFmtCountervalue *out_pValue);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/privilege.h */

#define COSMOPOLITAN_LIBC_NT_PRIVILEGE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » check your privilege                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtSePrivilegeEnabledByDefault 0x00000001u
#define kNtSePrivilegeEnabled          0x00000002u
#define kNtSePrivilegeRemoved          0x00000004u
#define kNtSePrivilegeUsedForAccess    0x80000000u

COSMOPOLITAN_C_START_

bool32 LookupPrivilegeValue(const char16_t *opt_lpSystemName,
                            const char16_t *lpName, struct NtLuid *out_lpLuid);

bool32 AdjustTokenPrivileges(int64_t TokenHandle, bool32 DisableAllPrivileges,
                             const struct NtTokenPrivileges *opt_NewState,
                             uint32_t BufferLength,
                             struct NtTokenPrivileges *opt_out_PreviousState,
                             uint32_t *opt_out_ReturnLength);

bool32 ImpersonateSelf(int kNtSecurityImpersonationLevel);
bool32 RevertToSelf(void);

bool32 OpenThreadToken(intptr_t ThreadHandle, uint32_t DesiredAccess,
                       bool32 OpenAsSelf, intptr_t *TokenHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_PROCESS_H_


/*!BEGIN libc/nt/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_NTSTARTUPINFO_H_
COSMOPOLITAN_C_START_

#define kNtProcThreadAttributeParentProcess 0x00020000
#define kNtProcThreadAttributeHandleList    0x00020002

void GetStartupInfo(struct NtStartupInfo *lpStartupInfo);

bool32 InitializeProcThreadAttributeList(
    struct NtProcThreadAttributeList *opt_inout_lpAttributeList,
    uint32_t dwAttributeCount, uint32_t reserved_dwFlags, size_t *inout_lpSize);
bool32 UpdateProcThreadAttribute(
    struct NtProcThreadAttributeList *inout_lpAttributeList, uint32_t dwFlags,
    uint64_t Attribute, const void *lpValue, size_t cbSize,
    void *reserved_lpPreviousValue, size_t *reserved_lpReturnSize);
void DeleteProcThreadAttributeList(
    struct NtProcThreadAttributeList *inout_lpAttributeList);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/startupinfo.inc */

#define GetStartupInfo(...) __imp_GetStartupInfoW(__VA_ARGS__)

extern typeof(GetStartupInfo) *const __imp_GetStartupInfoW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » processes                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 CreateProcess(const char16_t *opt_lpApplicationName,
                     char16_t *lpCommandLine,
                     const struct NtSecurityAttributes *opt_lpProcessAttributes,
                     const struct NtSecurityAttributes *opt_lpThreadAttributes,
                     bool32 bInheritHandles, uint32_t dwCreationFlags,
                     void *opt_lpEnvironment,
                     const char16_t *opt_lpCurrentDirectory,
                     const struct NtStartupInfo *lpStartupInfo,
                     struct NtProcessInformation *opt_out_lpProcessInformation)
    paramsnonnull((9));

uint32_t GetThreadId(int64_t hThread);   /* cf. NT_TID */
uint32_t GetProcessId(int64_t hProcess); /* cf. NT_PID */
void SetLastError(uint32_t dwErrCode);
uint32_t FormatMessage(uint32_t dwFlags, const void *lpSource,
                       uint32_t dwMessageId, uint32_t dwLanguageId,
                       char16_t *lpBuffer, uint32_t nSize, va_list *Arguments);
uint32_t FormatMessageA(uint32_t dwFlags, const void *lpSource,
                        uint32_t dwMessageId, uint32_t dwLanguageId,
                        char *lpBuffer, uint32_t nSize, va_list *Arguments);
int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                    uint32_t dwProcessId);
uint32_t GetCurrentProcessId(void); /* %gs:0x40 */
uint32_t GetEnvironmentVariable(const char16_t *lpName, char16_t *lpBuffer,
                                uint32_t nSize);
uint32_t SetEnvironmentVariable(const char16_t *lpName,
                                const char16_t *lpValue);
int32_t SetEnvironmentStrings(char16_t *NewEnvironment);
bool32 GetProcessAffinityMask(int64_t hProcess, uint64_t *lpProcessAffinityMask,
                              uint64_t *lpSystemAffinityMask);
uint64_t /*bool32*/ SetProcessAffinityMask(int64_t hProcess,
                                           uint64_t dwProcessAffinityMask);

/* e.g. kNtAboveNormalPriorityClass, kNtHighPriorityClass */
uint32_t GetPriorityClass(int64_t hProcess);
bool32 SetPriorityClass(int64_t hProcess, uint32_t dwPriorityClass);
bool32 SetProcessPriorityBoost(int64_t hProcess, bool32 bDisablePriorityBoost);
bool32 GetProcessPriorityBoost(int64_t hProcess, bool32 *pDisablePriorityBoost);

bool32 GetProcessMemoryInfo(
    int64_t hProcess, struct NtProcessMemoryCountersEx *out_ppsmemCounters,
    uint32_t cb);

int64_t CreateToolhelp32Snapshot(uint32_t dwFlags, uint32_t th32ProcessID);
bool32 Process32First(int64_t hSnapshot, struct NtProcessEntry32 *in_out_lppe);
bool32 Process32Next(int64_t hSnapshot, struct NtProcessEntry32 *out_lppe);

bool32 EnumProcesses(uint32_t *out_lpidProcess, uint32_t cb,
                     uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModules(int64_t hProcess, int64_t *out_lphModule, uint32_t cb,
                          uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModulesEx(int64_t hProcess, int64_t *out_lphModule,
                            uint32_t cb, uint32_t *out_lpcbNeeded,
                            uint32_t dwFilterFlag) paramsnonnull();
uint32_t GetModuleBaseName(int64_t hProcess, int64_t opt_hModule,
                           char16_t *out_lpBaseName, uint32_t nSize)
    paramsnonnull();

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/process.inc */

#define GetEnvironmentVariable(...) __imp_GetEnvironmentVariableW(__VA_ARGS__)
extern typeof(GetEnvironmentVariable) *const __imp_GetEnvironmentVariableW
    __msabi;

#define SetEnvironmentVariable(...) __imp_SetEnvironmentVariableW(__VA_ARGS__)
extern typeof(SetEnvironmentVariable) *const __imp_SetEnvironmentVariableW
    __msabi;

#define GetPriorityClass(...) __imp_GetPriorityClass(__VA_ARGS__)
extern typeof(GetPriorityClass) *const __imp_GetPriorityClass __msabi;

#define SetPriorityClass(...) __imp_SetPriorityClass(__VA_ARGS__)
extern typeof(SetPriorityClass) *const __imp_SetPriorityClass __msabi;

#define GetCurrentProcessId(...) __imp_GetCurrentProcessId(__VA_ARGS__)
extern typeof(GetCurrentProcessId) *const __imp_GetCurrentProcessId __msabi;

extern typeof(FormatMessage) *const __imp_FormatMessageW __msabi;
extern typeof(SetLastError) *const __imp_SetLastError __msabi;
extern typeof(FormatMessage) *const __imp_FormatMessage __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/registry.h */

#define COSMOPOLITAN_LIBC_NT_REGISTRY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » registry                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtMaxKeyNameChars   255
#define kNtMaxValueNameChars 16383
#define kNtMaxValueBytes     0x100000

#define kNtHkeyClassesRoot              0x80000000l
#define kNtHkeyCurrentUser              0x80000001l
#define kNtHkeyLocalMachine             0x80000002l
#define kNtHkeyUsers                    0x80000003l
#define kNtHkeyPerformanceData          0x80000004l
#define kNtHkeyPerformanceText          0x80000050l
#define kNtHkeyPerformanceNlstext       0x80000060l
#define kNtHkeyCurrentConfig            0x80000005l
#define kNtHkeyDynData                  0x80000006l
#define kNtHkeyCurrentUserLocalSettings 0x80000007l

COSMOPOLITAN_C_START_

int RegOpenKey(int64_t hKey, const char16_t *opt_lpSubKey,
               int64_t *out_phkResult) paramsnonnull((3));
int RegOpenKeyEx(int64_t hKey, const char16_t *opt_lpSubKey,
                 uint32_t opt_ulOptions, int samDesired, int64_t *out_phkResult)
    paramsnonnull((5));
int RegCloseKey(int64_t hKey);

int RegGetValue(int64_t hkey, const char16_t *opt_lpSubKey,
                const char16_t *opt_lpValue, unsigned dwFlags, int *opt_pdwType,
                void *opt_out_pvData, uint32_t *opt_inout_pcbDataBytes);
int RegSetValue(int64_t hKey, const char16_t *lpSubKey, int dwType,
                const char16_t *lpData, uint32_t cbData);
int RegSetValueEx(int64_t hKey, const char16_t *lpValueName, uint32_t Reserved,
                  int dwType, const unsigned char *lpData, uint32_t cbData);

int RegQueryInfoKey(int64_t hKey, char16_t *opt_out_lpClass,
                    uint32_t *opt_inout_lpClassLen, uint32_t *lpReserved,
                    uint32_t *opt_out_lpcSubKeys,
                    uint32_t *opt_out_lpcbMaxSubKeyBytes,
                    uint32_t *opt_out_lpcbMaxClassBytes,
                    uint32_t *opt_out_lpcValues,
                    uint32_t *opt_out_lpcbMaxValueNameBytes,
                    uint32_t *opt_out_lpcbMaxValueBytes,
                    uint32_t *opt_out_lpcbSecurityDescriptorBytes,
                    struct NtFileTime *opt_out_lpftLastWriteTime);
int RegEnumKey(int64_t hKey, uint32_t dwIndex, char16_t *opt_lpName,
               uint32_t NameLen);
int RegEnumKeyEx(int64_t hKey, uint32_t dwIndex, char16_t *out_lpName,
                 uint32_t *inout_lpcchName, uint32_t *lpReserved,
                 char16_t *opt_out_lpClass, uint32_t *opt_inout_lpcchClassLen,
                 struct NtFileTime *opt_out_lpftLastWriteTime);

int RegEnumValue(int64_t hKey, uint32_t dwIndex, char16_t *lpValueName,
                 uint32_t *lpValueNameLen, uint32_t *lpReserved,
                 int *opt_out_lpType, unsigned char *opt_out_lpData,
                 uint32_t *opt_inout_lpcbDataBytes);
int RegQueryValue(int64_t hKey, const char16_t *opt_lpSubKey,
                  char16_t *opt_out_lpData, int32_t *opt_inout_lpcbDataBytes);
int RegQueryValueEx(int64_t hKey, const char16_t *opt_lpValueName,
                    uint32_t *lpReserved, int *opt_out_lpType,
                    unsigned char *opt_out_lpData,
                    uint32_t *opt_inout_lpcbDataBytes);

int RegOverridePredefKey(int64_t hKey, int64_t hNewHKey);
int RegOpenUserClassesRoot(void *hToken, uint32_t dwOptions, int samDesired,
                           int64_t *phkResult);
int RegOpenCurrentUser(int samDesired, int64_t *phkResult);
int RegDisablePredefinedCache();
int RegConnectRegistry(const char16_t *lpMachineName, int64_t hKey,
                       int64_t *phkResult);
int RegConnectRegistryEx(const char16_t *lpMachineName, int64_t hKey,
                         uint32_t Flags, int64_t *phkResult);
int RegCreateKey(int64_t hKey, const char16_t *lpSubKey, int64_t *phkResult);
int RegCreateKeyEx(int64_t hKey, const char16_t *lpSubKey, uint32_t Reserved,
                   int16_t *lpClass, uint32_t dwOptions, int samDesired,
                   const struct NtSecurityAttributes *lpSecurityAttributes,
                   int64_t *phkResult, uint32_t *lpdwDisposition);
int RegDeleteKey(int64_t hKey, const char16_t *lpSubKey);
int RegDeleteKeyEx(int64_t hKey, const char16_t *lpSubKey, int samDesired,
                   uint32_t Reserved);
int RegDeleteTree(int64_t hKey, const char16_t *opt_lpSubKey);
int RegDisableReflectionKey(int64_t hBase);
int RegEnableReflectionKey(int64_t hBase);
int RegQueryReflectionKey(int64_t hBase, bool32 *bIsReflectionDisabled);
int RegDeleteValue(int64_t hKey, const char16_t *lpValueName);
int RegFlushKey(int64_t hKey);
int RegGetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor,
                      uint32_t *lpcbSecurityDescriptorBytes);
int RegLoadKey(int64_t hKey, const char16_t *lpSubKey, const char16_t *lpFile);
int RegNotifyChangeKeyValue(int64_t hKey, bool32 bWatchSubtree,
                            uint32_t dwNotifyFilter, void *hEvent,
                            int fAsynchronous);
int RegQueryMultipleValues(int64_t hKey, struct NtValent *inout_val_list,
                           uint32_t num_vals, int16_t *out_lpValueBuf,
                           uint32_t *inout_ldwTotsize) paramsnonnull();
int RegReplaceKey(int64_t hKey, const char16_t *lpSubKey,
                  const char16_t *lpNewFile, const char16_t *lpOldFile);
int RegRestoreKey(int64_t hKey, const char16_t *lpFile, uint32_t dwFlags);
int RegSaveKey(int64_t hKey, const char16_t *lpFile,
               const struct NtSecurityAttributes *lpSecurityAttributes);
int RegSetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor);
int RegUnLoadKey(int64_t hKey, const char16_t *lpSubKey);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/runtime.h */

#define COSMOPOLITAN_LIBC_NT_RUNTIME_H_

/**
 * @fileoverview NT Obligatory Runtime Functions.
 *
 * These functions are placed in their own file because they're (a)
 * abstracted by the Cosmopolitan runtime; and (b) it helps GCC avoid
 * bloating binaries with debug information the user doesn't need.
 */

#define kNtCpUtf8             65001
#define kNtInvalidHandleValue -1L
#define kNtStdInputHandle     -10u
#define kNtStdOutputHandle    -11u
#define kNtStdErrorHandle     -12u

#define GetCurrentProcess() -1

COSMOPOLITAN_C_START_

char16_t *GetCommandLine(void) nosideeffect;
char16_t *GetEnvironmentStrings(void) __wur;
bool32 FreeEnvironmentStrings(char16_t *) paramsnonnull();
bool32 ReadFile(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                uint32_t *lpNumberOfBytesRead,
                struct NtOverlapped *opt_lpOverlapped);
bool32 WriteFile(int64_t hFile, const void *lpBuffer,
                 uint32_t nNumberOfBytesToWrite,
                 uint32_t *lpNumberOfBytesWritten,
                 struct NtOverlapped *opt_lpOverlapped);
bool32 TerminateProcess(int64_t hProcess, uint32_t uExitCode);
void TerminateThisProcess(uint32_t dwWaitStatus) wontreturn;
void ExitProcess(uint32_t uExitCode) wontreturn;
uint32_t GetLastError(void) nosideeffect;
bool32 CloseHandle(int64_t hObject) dontthrow dontcallback;
intptr_t GetStdHandle(uint32_t nStdHandle) nosideeffect;
bool32 SetStdHandle(uint32_t nStdHandle, int64_t hHandle);
bool32 SetDefaultDllDirectories(unsigned dirflags);
bool32 ProcessPrng(void *RandomBuffer, uint32_t RandomBufferLength);
uint32_t GetModuleFileName(int64_t hModule, char16_t *lpFilename,
                           uint32_t nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/runtime.inc */

#define FreeEnvironmentStrings(...) __imp_FreeEnvironmentStringsW(__VA_ARGS__)
extern typeof(FreeEnvironmentStrings) *const __imp_FreeEnvironmentStringsW
    __msabi;

#define GetCommandLine(...) __imp_GetCommandLineW(__VA_ARGS__)
extern typeof(GetCommandLine) *const __imp_GetCommandLineW __msabi;

#define GetEnvironmentStrings(...) __imp_GetEnvironmentStringsW(__VA_ARGS__)
extern typeof(GetEnvironmentStrings) *const __imp_GetEnvironmentStringsW
    __msabi;

#define GetStdHandle(...) __imp_GetStdHandle(__VA_ARGS__)
extern typeof(GetStdHandle) *const __imp_GetStdHandle __msabi;

#define SetStdHandle(...) __imp_SetStdHandle(__VA_ARGS__)
extern typeof(SetStdHandle) *const __imp_SetStdHandle __msabi;

#define ReadFile(...) __imp_ReadFile(__VA_ARGS__)
extern typeof(ReadFile) *const __imp_ReadFile __msabi;

#define WriteFile(...) __imp_WriteFile(__VA_ARGS__)
extern typeof(WriteFile) *const __imp_WriteFile __msabi;

#define SetDefaultDllDirectories(...) \
  __imp_SetDefaultDllDirectories(__VA_ARGS__)
extern typeof(SetDefaultDllDirectories) *const __imp_SetDefaultDllDirectories
    __msabi;

#define GetModuleFileName(...) __imp_GetModuleFileNameW(__VA_ARGS__)
extern typeof(GetModuleFileName) *const __imp_GetModuleFileNameW __msabi;

extern typeof(GetLastError) *const __imp_GetLastError __msabi;
extern typeof(ExitProcess) *const __imp_ExitProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/signals.h */

#define COSMOPOLITAN_LIBC_NT_EXCEPTIONS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » signals                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

typedef int (*NtTopLevelExceptionFilter)(const struct NtExceptionPointers *);
typedef int32_t (*NtVectoredExceptionHandler)(struct NtExceptionPointers *);

int SetErrorMode(int uMode);

int64_t AddVectoredExceptionHandler(uint32_t First,
                                    NtVectoredExceptionHandler pHandler);
int64_t AddVectoredContinueHandler(uint32_t First,
                                   NtVectoredExceptionHandler pHandler);

uint32_t RemoveVectoredExceptionHandler(int64_t hHandle);
uint32_t RemoveVectoredContinueHandler(int64_t hHandle);

NtTopLevelExceptionFilter SetUnhandledExceptionFilter(
    NtTopLevelExceptionFilter opt_lpTopLevelExceptionFilter);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/signals.inc */

#define SetErrorMode(...) __imp_SetErrorMode(__VA_ARGS__)
#define AddVectoredExceptionHandler(...) \
  __imp_AddVectoredExceptionHandler(__VA_ARGS__)
#define AddVectoredContinueHandler(...) \
  __imp_AddVectoredContinueHandler(__VA_ARGS__)
#define RemoveVectoredExceptionHandler(...) \
  __imp_RemoveVectoredExceptionHandler(__VA_ARGS__)
#define RemoveVectoredContinueHandler(...) \
  __imp_RemoveVectoredContinueHandler(__VA_ARGS__)
#define SetUnhandledExceptionFilter(...) \
  __imp_SetUnhandledExceptionFilter(__VA_ARGS__)

extern typeof(SetErrorMode) *const __imp_SetErrorMode __msabi;
extern typeof(AddVectoredExceptionHandler) *const
    __imp_AddVectoredExceptionHandler __msabi;
extern typeof(AddVectoredContinueHandler) *const
    __imp_AddVectoredContinueHandler __msabi;
extern typeof(RemoveVectoredExceptionHandler) *const
    __imp_RemoveVectoredExceptionHandler __msabi;
extern typeof(RemoveVectoredContinueHandler) *const
    __imp_RemoveVectoredContinueHandler __msabi;
extern typeof(SetUnhandledExceptionFilter) *const
    __imp_SetUnhandledExceptionFilter __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/synchronization.h */

#define COSMOPOLITAN_LIBC_NT_SYNCHRONIZATION_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » synchronization                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

static inline int32_t InterlockedAdd(int32_t volatile *p, int32_t x) {
  return atomic_fetch_add((_Atomic(int32_t) *)p, x) + x;
}

static inline int32_t InterlockedExchange(int32_t volatile *p, int32_t x) {
  return atomic_exchange((_Atomic(int32_t) *)p, x);
}

typedef void (*NtTimerapcroutine)(void *lpArgToCompletionRoutine,
                                  uint32_t dwTimerLowValue,
                                  uint32_t dwTimerHighValue);
typedef void (*NtWaitOrTimerCallback)(void *lpParameter,
                                      bool32 TimerOrWaitFired);

void WakeByAddressAll(void *Address);
void WakeByAddressSingle(void *Address);
bool32 WaitOnAddress(const volatile void *Address, void *CompareAddress,
                     size_t AddressSize, uint32_t opt_dwMilliseconds);

void Sleep(uint32_t dwMilliseconds);
uint32_t SleepEx(uint32_t dwMilliseconds, bool32 bAlertable);

void GetSystemTime(struct NtSystemTime *lpSystemTime);
bool32 SystemTimeToFileTime(const struct NtSystemTime *lpSystemTime,
                            struct NtFileTime *lpFileTime);
void GetSystemTimeAsFileTime(struct NtFileTime *);
void GetSystemTimePreciseAsFileTime(struct NtFileTime *); /* win8+ */

uint32_t WaitForSingleObject(int64_t hHandle, uint32_t dwMilliseconds);
uint32_t WaitForMultipleObjects(uint32_t nCount, const int64_t *lpHandles,
                                bool32 bWaitAll, uint32_t dwMilliseconds);
uint32_t WaitForSingleObjectEx(int64_t hHandle, uint32_t dwMilliseconds,
                               bool32 bAlertable);
uint32_t WaitForMultipleObjectsEx(unsigned int nCount, const int64_t *lpHandles,
                                  bool32 bWaitAll, uint32_t dwMilliseconds,
                                  bool32 bAlertable);
bool32 RegisterWaitForSingleObject(int64_t *phNewWaitObject, int64_t hObject,
                                   NtWaitOrTimerCallback Callback,
                                   void *Context, uint32_t dwMilliseconds,
                                   uint32_t dwFlags);

int64_t CreateWaitableTimer(
    const struct NtSecurityAttributes *lpTimerAttributes, bool32 bManualReset,
    const char16_t *lpTimerName);
bool32 SetWaitableTimer(int64_t hTimer, const int64_t *lpDueTimeAsFtOrNegRela,
                        int32_t opt_lPeriodMs, NtTimerapcroutine opt_callback,
                        void *lpArgToCallback, bool32 fUnsleepSystem);

int64_t CreateSemaphore(
    const struct NtSecurityAttributes *opt_lpSemaphoreAttributes,
    uint32_t lInitialCount, uint32_t lMaximumCount, const char16_t *opt_lpName);

int32_t ReleaseMutex(int64_t hMutex);
int32_t ReleaseSemaphore(int64_t hSemaphore, int32_t lReleaseCount,
                         int *lpPreviousCount);

void InitializeCriticalSection(struct NtCriticalSection *lpCriticalSection);
void EnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void LeaveCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t TryEnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void DeleteCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t InitializeCriticalSectionAndSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);
uint32_t SetCriticalSectionSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);

void InitializeSRWLock(intptr_t *);
void AcquireSRWLockExclusive(intptr_t *);
void AcquireSRWLockShared(intptr_t *);
void ReleaseSRWLockExclusive(intptr_t *);
void ReleaseSRWLockShared(intptr_t *);
void TryAcquireSRWLockExclusive(intptr_t *);
void TryAcquireSRWLockShared(intptr_t *);

uint64_t GetTickCount64(void);

bool32 QueryPerformanceFrequency(uint64_t *lpFrequency);
bool32 QueryPerformanceCounter(uint64_t *lpPerformanceCount);
bool32 GetSystemTimeAdjustment(uint32_t *lpTimeAdjustment,
                               uint32_t *lpTimeIncrement,
                               bool32 *lpTimeAdjustmentDisabled);

void GetCurrentProcessorNumberEx(struct NtProcessorNumber *out_ProcNumber);

bool32 GetNumaProcessorNodeEx(const struct NtProcessorNumber *Processor,
                              unsigned short *out_NodeNumber);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/synchronization.inc */

extern typeof(SleepEx) *const __imp_SleepEx __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/system.h */

#define COSMOPOLITAN_LIBC_NT_SYSTEM_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » system control                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

bool32 SetSuspendState(bool32 bHibernate, bool32 bForce,
                       bool32 bWakeupEventsDisabled);

uint32_t InitiateShutdown(const char16_t *lpMachineName,
                          const char16_t *lpMessage, uint32_t dwGracePeriod,
                          uint32_t dwShutdownFlags, uint32_t dwReason);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_INFO_H_
COSMOPOLITAN_C_START_

void GetSystemInfo(struct NtSystemInfo *lpSystemInfo);
uint32_t GetSystemDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetSystemDirectoryA(char *lpBuffer, uint32_t uSize);
uint32_t GetWindowsDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetTempPath(uint32_t uSize, char16_t *lpBuffer);

bool32 GetComputerNameEx(/* enum/computernameformat.h */ int NameType,
                         char16_t *opt_lpBuffer, uint32_t *nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/systeminfo.inc */

#define GetSystemInfo(...) __imp_GetSystemInfo(__VA_ARGS__)
#define GetTempPath(...) __imp_GetTempPathW(__VA_ARGS__)

extern typeof(GetSystemInfo) *const __imp_GetSystemInfo __msabi;
extern typeof(GetTempPath) *const __imp_GetTempPathW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_THREADS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » threads                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t CreateThread(const struct NtSecurityAttributes *lpThreadAttributes,
                     size_t dwStackSize, void *lpStartAddress,
                     void *lpParameter, uint32_t dwCreationFlags,
                     uint32_t *opt_lpThreadId) paramsnonnull((3));

void ExitThread(uint32_t dwExitCode) wontreturn;
int64_t GetCurrentThread(void);
uint32_t GetCurrentThreadId(void);
uint64_t SetThreadAffinityMask(int64_t hThread, uintptr_t dwThreadAffinityMask);
int64_t OpenThread(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                   uint32_t dwThreadId);
bool32 TerminateThread(int64_t hThread, uint32_t dwExitCode);
bool32 GetExitCodeThread(int64_t hThread, uint32_t *lpExitCode);

/* e.g. kNtThreadPriorityAboveNormal, -1u on error */
uint32_t GetThreadPriority(int64_t hThread);
bool32 SetThreadPriority(int64_t hThread, int32_t nPriority);
bool32 SetThreadPriorityBoost(int64_t hThread, bool32 bDisablePriorityBoost);
bool32 GetThreadPriorityBoost(int64_t hThread, bool32 *pDisablePriorityBoost);
bool32 GetThreadIOPendingFlag(int64_t hThread, bool32 *lpIOIsPending);

bool32 CancelSynchronousIo(int64_t hThread);
bool32 CancelIo(int64_t hFile);
bool32 CancelIoEx(int64_t hFile, struct NtOverlapped *opt_lpOverlapped);

uint32_t TlsAlloc(void);
bool32 TlsFree(uint32_t);
bool32 TlsSetValue(uint32_t, void *);
void *TlsGetValue(uint32_t);

uint32_t SuspendThread(int64_t hThread);
uint32_t ResumeThread(int64_t hThread);
bool32 GetThreadContext(int64_t hThread, struct NtContext *in_out_lpContext);
bool32 SetThreadContext(int64_t hThread, const struct NtContext *lpContext);

void *SetThreadDescription(int64_t hThread,
                           const char16_t *lpThreadDescription);
void *GetThreadDescription(int64_t hThread,
                           char16_t *out_ppszThreadDescription);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/thread.inc */

#define GetCurrentThread(...)  __imp_GetCurrentThread(__VA_ARGS__)
#define GetThreadPriority(...) __imp_GetThreadPriority(__VA_ARGS__)
#define SetThreadPriority(...) __imp_SetThreadPriority(__VA_ARGS__)

extern typeof(GetCurrentThread) *const __imp_GetCurrentThread __msabi;
extern typeof(GetThreadPriority) *const __imp_GetThreadPriority __msabi;
extern typeof(SetThreadPriority) *const __imp_SetThreadPriority __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_TIME_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » time                                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetTimeZoneInformation(
    struct NtTimeZoneInformation *out_lpTimeZoneInformation);
uint32_t GetDynamicTimeZoneInformation(
    struct NtDynamicTimeZoneInformation *out_lpTimeZoneInformation);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/version.h */

#define COSMOPOLITAN_LIBC_NT_VERSION_H_
COSMOPOLITAN_C_START_

bool32 IsAtLeastWindows10(void) pureconst;
bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
#define GetNtMajorVersion()        \
  __extension__({                  \
    uintptr_t __x;                 \
    __asm__("mov\t%%gs:96,%q0\r\n" \
            "mov\t280(%q0),%b0"    \
            : "=q"(__x));          \
    (unsigned char)__x;            \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/windows.h */

#define COSMOPOLITAN_LIBC_NT_WINDOWS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » windows                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

int64_t CreateWindowEx(uint32_t dwExStyle, const char16_t *lpClassName,
                       const char16_t *lpWindowName, uint32_t dwStyle, int X,
                       int Y, int nWidth, int nHeight, int64_t hWndParent,
                       int64_t hMenu, int64_t hInstance, int64_t lpParam);

uint16_t RegisterClass(const struct NtWndClass *lpWndClass);

int64_t DefWindowProc(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                      int64_t lParam);

int32_t CloseWindow(int64_t hWnd);
int32_t DestroyWindow(int64_t hWnd);
int32_t ShowWindow(int64_t hWnd, int sw);
int32_t ShowCaret(bool32 bShow);
int32_t AnimateWindow(int64_t hWnd, uint32_t dwTime, uint32_t dwFlags);
int64_t LoadIcon(int64_t hInstance, const char16_t *lpIconName);
int32_t MoveWindow(int64_t hWnd, int X, int Y, int nWidth, int nHeight,
                   bool32 bRepaint);
int32_t BringWindowToTop(int64_t hWnd);
int32_t IsWindowVisible(int64_t hWnd);
int32_t SetWindowText(int64_t hWnd, const char16_t *lpString);
int32_t GetWindowText(int64_t hWnd, char16_t *lpString, int nMaxCount);
int32_t SetWindowPos(int64_t hWnd, int64_t hWndInsertAfter, int X, int Y,
                     int cx, int cy, uint32_t uFlags);
bool32 GetWindowPlacement(int64_t hWnd, struct NtWindowPlacement *lpwndpl);
bool32 SetWindowPlacement(int64_t hWnd,
                          const struct NtWindowPlacement *lpwndpl);

int64_t GetCursor(void);
int64_t SetCursor(int64_t hCursor);
int32_t ShowCursor(bool32 bShow);
int64_t LoadCursor(int64_t opt_hInstance, const char16_t *lpCursorNameOrIdc);

bool32 IsWindow(int64_t hWnd);
bool32 IsMenu(int64_t hMenu);
bool32 IsChild(int64_t hWndParent, int64_t hWnd);
bool32 IsZoomed(int64_t hWnd);
bool32 IsIconic(int64_t hWnd);

uintptr_t SetTimer(int64_t opt_hWnd, uintptr_t nIDEvent, uint32_t uElapseMs,
                   NtTimerProc lpTimerFunc);
int32_t KillTimer(int64_t hWnd, uintptr_t uIDEvent);

int64_t SetCapture(int64_t hWnd);
bool32 ReleaseCapture(void);
int16_t GetKeyState(int32_t nVirtKey);

int64_t CreateMenu(void);
int64_t CreatePopupMenu(void);
int64_t GetMenu(int64_t hWnd);
bool32 DestroyMenu(int64_t hMenu);
int64_t GetSystemMenu(int64_t hWnd, bool32 bRevert);
bool32 AppendMenu(int64_t hMenu, uint32_t mfFlags, uintptr_t uIDNewItem,
                  const char16_t *lpNewItem);
bool32 InsertMenu(int64_t hMenu, uint32_t uPosition, uint32_t uFlags,
                  uintptr_t uIDNewItem, const char16_t *lpNewItem);
bool32 TrackPopupMenu(int64_t hMenu, uint32_t uFlags, int32_t x, int32_t y,
                      int32_t nReserved, int64_t hWnd,
                      const struct NtRect *prcRect);

int WideCharToMultiByte(unsigned int CodePage, uint32_t dwFlags,
                        uint16_t *lpWideCharStr, int cchWideChar,
                        char *lpMultiByteStr, int cbMultiByte,
                        uint16_t *lpDefaultChar, int *lpUsedDefaultChar);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/clktck.h */

#define COSMOPOLITAN_LIBC_RUNTIME_CLKTCK_H_
COSMOPOLITAN_C_START_

#define CLK_TCK (__clk_tck())

int __clk_tck(void) pureconst;

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/fenv.h */

#define COSMOPOLITAN_LIBC_RUNTIME_FENV_H_

#ifdef __x86_64__
#define FE_INVALID    1
#define __FE_DENORM   2
#define FE_DIVBYZERO  4
#define FE_OVERFLOW   8
#define FE_UNDERFLOW  16
#define FE_INEXACT    32
#define FE_ALL_EXCEPT 63
#define FE_TONEAREST  0x0000
#define FE_DOWNWARD   0x0400
#define FE_UPWARD     0x0800
#define FE_TOWARDZERO 0x0c00
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint16_t fexcept_t;

#elif defined(__aarch64__)
#define FE_INVALID    1
#define FE_DIVBYZERO  2
#define FE_OVERFLOW   4
#define FE_UNDERFLOW  8
#define FE_INEXACT    16
#define FE_ALL_EXCEPT 31
#define FE_TONEAREST  0
#define FE_DOWNWARD   0x800000
#define FE_UPWARD     0x400000
#define FE_TOWARDZERO 0xc00000
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint32_t fexcept_t;

#elif defined(__powerpc64__)
#define FE_TONEAREST                  0
#define FE_TOWARDZERO                 1
#define FE_UPWARD                     2
#define FE_DOWNWARD                   3
#define FE_INEXACT                    0x02000000
#define FE_DIVBYZERO                  0x04000000
#define FE_UNDERFLOW                  0x08000000
#define FE_OVERFLOW                   0x10000000
#define FE_INVALID                    0x20000000
#define FE_ALL_EXCEPT                 0x3e000000
#define FE_INVALID_SNAN               0x01000000
#define FE_INVALID_ISI                0x00800000
#define FE_INVALID_IDI                0x00400000
#define FE_INVALID_ZDZ                0x00200000
#define FE_INVALID_IMZ                0x00100000
#define FE_INVALID_COMPARE            0x00080000
#define FE_INVALID_SOFTWARE           0x00000400
#define FE_INVALID_SQRT               0x00000200
#define FE_INVALID_INTEGER_CONVERSION 0x00000100
#define FE_ALL_INVALID                0x01f80700
#define FE_DFL_ENV                    ((const fenv_t *)-1)
typedef unsigned fexcept_t;
typedef double fenv_t;

#endif /* __x86_64__ */

#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD_TS_18661_3__
#elif defined(__FLT_EVAL_METHOD__)
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#else
#define FLT_EVAL_METHOD 0
#endif

COSMOPOLITAN_C_START_

#define FLT_ROUNDS (__flt_rounds())

int feclearexcept(int);
int fegetenv(fenv_t *);
int fegetexceptflag(fexcept_t *, int);
int fegetround(void);
int feholdexcept(fenv_t *);
int feraiseexcept(int);
int fesetenv(const fenv_t *);
int fesetexceptflag(const fexcept_t *, int);
int fesetround(int);
int fetestexcept(int);
int feenableexcept(int);
int fedisableexcept(int);
int feupdateenv(const fenv_t *);
int __flt_rounds(void);
int __fesetround(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/pathconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_PATHCONF_H_

#define _PC_LINK_MAX           0
#define _PC_MAX_CANON          1
#define _PC_MAX_INPUT          2
#define _PC_NAME_MAX           3
#define _PC_PATH_MAX           4
#define _PC_PIPE_BUF           5
#define _PC_CHOWN_RESTRICTED   6
#define _PC_NO_TRUNC           7
#define _PC_VDISABLE           8
#define _PC_SYNC_IO            9
#define _PC_ASYNC_IO           10
#define _PC_PRIO_IO            11
#define _PC_SOCK_MAXBUF        12
#define _PC_FILESIZEBITS       13
#define _PC_REC_INCR_XFER_SIZE 14
#define _PC_REC_MAX_XFER_SIZE  15
#define _PC_REC_MIN_XFER_SIZE  16
#define _PC_REC_XFER_ALIGN     17
#define _PC_ALLOC_SIZE_MIN     18
#define _PC_SYMLINK_MAX        19
#define _PC_2_SYMLINKS         20

COSMOPOLITAN_C_START_

long fpathconf(int, int);
long pathconf(const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/runtime.h */

#define COSMOPOLITAN_LIBC_RUNTIME_RUNTIME_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § runtime                                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#ifdef __x86_64__
typedef long jmp_buf[8];
typedef long sigjmp_buf[11];
#elif defined(__aarch64__)
typedef long jmp_buf[22];
typedef long sigjmp_buf[25];
#elif defined(__powerpc64__)
typedef unsigned __int128 jmp_buf[32];
#elif defined(__s390x__)
typedef unsigned long jmp_buf[18];
#elif defined(__riscv)
typedef unsigned long jmp_buf[26];
#endif

void mcount(void);
int daemon(int, int);
unsigned long getauxval(unsigned long);
int setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
int _setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
void siglongjmp(sigjmp_buf, int) libcesque wontreturn paramsnonnull();
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
void exit(int) wontreturn;
void _exit(int) libcesque wontreturn;
void _Exit(int) libcesque wontreturn;
void quick_exit(int) wontreturn;
void abort(void) wontreturn;
int atexit(void (*)(void)) paramsnonnull() libcesque;
char *getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
int putenv(char *);
int setenv(const char *, const char *, int);
int unsetenv(const char *);
int clearenv(void);
void fpreset(void);
void *mmap(void *, uint64_t, int32_t, int32_t, int32_t, int64_t);
int munmap(void *, uint64_t);
int mprotect(void *, uint64_t, int);
int msync(void *, size_t, int);
int mlock(const void *, size_t);
int munlock(const void *, size_t);
long gethostid(void);
int sethostid(long);
char *getlogin(void);
int getlogin_r(char *, size_t);
int login_tty(int);
int getpagesize(void);
int syncfs(int) dontthrow;
int vhangup(void);
int getdtablesize(void);
int sethostname(const char *, size_t);
int acct(const char *);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
extern char **environ;
char *secure_getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
#endif

#ifdef _COSMO_SOURCE
extern int __argc;
extern char **__argv;
extern char **__envp;
extern unsigned long *__auxv;
extern intptr_t __oldstack;
extern char *__program_executable_name;
extern uint64_t __nosync;
extern int __strace;
extern int __ftrace;
extern uint64_t __syscount;
extern uint64_t kStartTsc;
extern const char kNtSystemDirectory[];
extern const char kNtWindowsDirectory[];
extern size_t __virtualmax;
extern size_t __stackmax;
extern bool32 __isworker;
/* utilities */
void _intsort(int *, size_t);
void _longsort(long *, size_t);
/* diagnostics */
void ShowCrashReports(void);
int ftrace_install(void);
int ftrace_enabled(int);
int strace_enabled(int);
void __print_maps(void);
void __printargs(const char *);
/* builtin sh-like system/popen dsl */
int _cocmd(int, char **, char **);
/* executable program */
char *GetProgramExecutableName(void);
char *GetInterpreterExecutableName(char *, size_t);
int __open_executable(void);
/* execution control */
int verynice(void);
void __warn_if_powersave(void);
void _Exit1(int) libcesque wontreturn;
void __paginate(int, const char *);
void __paginate_file(int, const char *);
/* memory management */
void _weakfree(void *);
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
void CheckForMemoryLeaks(void);
void CheckForFileLeaks(void);
bool32 _isheap(const void *);
void __enable_threads(void);
void __oom_hook(size_t);
/* code morphing */
void __morph_begin(void);
void __morph_end(void);
void __jit_begin(void);
void __jit_end(void);
void __clear_cache(void *, void *);
/* portability */
int NtGetVersion(void) pureconst;
bool32 IsGenuineBlink(void);
bool32 IsCygwin(void);
const char *GetCpuidOs(void);
const char *GetCpuidEmulator(void);
void GetCpuidBrand(char[13], uint32_t);
long __get_rlimit(int);
const char *__describe_os(void);
long __get_sysctl(int, int);
int __get_arg_max(void) pureconst;
int __get_cpu_count(void) pureconst;
long __get_avphys_pages(void) pureconst;
long __get_phys_pages(void) pureconst;
long __get_minsigstksz(void) pureconst;
void __get_main_stack(void **, size_t *, int *);
long __get_safe_size(long, long);
char *__get_tmpdir(void);
forceinline int __trace_disabled(int x) {
  return 0;
}
#ifndef FTRACE
#define ftrace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#ifndef SYSDEBUG
#define strace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/stack.h */

#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_

/**
 * Returns preferred size and alignment of thread stack.
 */
#define GetStackSize() 262144

/**
 * Returns preferred stack guard size.
 *
 * This is the max cpu page size of supported architectures.
 */
#define GetGuardSize() 16384

/**
 * Align APE main thread stack at startup.
 *
 * You need this in your main program module:
 *
 *     STATIC_STACK_ALIGN(GetStackSize());
 *
 * If you want to use GetStackAddr() and HaveStackMemory() safely on
 * your main thread in your process. It causes crt.S to waste a tiny
 * amount of memory to ensure those macros go extremely fast.
 */
#define STATIC_STACK_ALIGN(BYTES) \
  _STACK_SYMBOL("ape_stack_align", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Makes program stack executable if declared, e.g.
 *
 *     STATIC_EXEC_STACK();
 *     int main() {
 *       char code[16] = {
 *           0x55,                          // push %rbp
 *           0xb8, 0007, 0x00, 0x00, 0x00,  // mov  $7,%eax
 *           0x5d,                          // push %rbp
 *           0xc3,                          // ret
 *       };
 *       int (*func)(void) = (void *)code;
 *       printf("result %d should be 7\n", func());
 *     }
 */
#define STATIC_EXEC_STACK() _STACK_SYMBOL("ape_stack_pf", "7")

#define _STACK_STRINGIFY(ADDR) #ADDR
#define _STACK_SYMBOL(NAME, VALUE)       \
  __asm__(".equ\t" NAME "," VALUE "\n\t" \
          ".globl\t" NAME)

#ifdef __SANITIZE_ADDRESS__
#define _STACK_EXTRA "*2"
#else
#define _STACK_EXTRA ""
#endif

#if defined(__GNUC__) && defined(__ELF__)
COSMOPOLITAN_C_START_

extern char ape_stack_prot[] __attribute__((__weak__));
extern char ape_stack_memsz[] __attribute__((__weak__));
extern char ape_stack_align[] __attribute__((__weak__));

/**
 * Returns address of bottom of current stack.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants.
 */
#define GetStackAddr() ((GetStackPointer() - 1) & -GetStackSize())

#define GetStaticStackSize() ((uintptr_t)ape_stack_memsz)

/**
 * Returns true if at least `n` bytes of stack are available.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants,
 * which make this check exceedingly fast.
 */
#define HaveStackMemory(n) \
  (GetStackPointer() >= GetStackAddr() + GetGuardSize() + (n))

/**
 * Extends stack memory by poking large allocations.
 *
 * This can be particularly useful depending on how your system
 * implements guard pages. For example, Windows can make stacks
 * that aren't fully committed, in which case there's only 4096
 * bytes of grows-down guard pages made by portable executable.
 * If you alloca() more memory than that, you should call this,
 * since it'll not only ensure stack overflows are detected, it
 * will also trigger the stack to grow down safely.
 */
forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
  for (; n > 0; n -= 4096) {
    ((char *)p)[n - 1] = 0;
  }
}

void *NewCosmoStack(void) vallocesque;
int FreeCosmoStack(void *) libcesque;

/**
 * Tunes stack size of main thread on Windows.
 *
 * On UNIX systems use `RLIMIT_STACK` to tune the main thread size.
 */
#define STATIC_STACK_SIZE(BYTES) \
  _STACK_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Tunes main thread stack address on Windows.
 */
#define STATIC_STACK_ADDR(ADDR) \
  _STACK_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))

#ifdef __x86_64__
/**
 * Returns preferred bottom address of main thread stack.
 *
 * On UNIX systems we favor the system provided stack, so this only
 * really applies to Windows. It's configurable at link time. It is
 * needed because polyfilling fork requires that we know, precicely
 * where the stack memory begins and ends.
 */
#define GetStaticStackAddr(ADDEND)          \
  ({                                        \
    intptr_t vAddr;                         \
    __asm__(".weak\tape_stack_vaddr\n\t"    \
            "movabs\t%1+ape_stack_vaddr,%0" \
            : "=r"(vAddr)                   \
            : "i"(ADDEND));                 \
    vAddr;                                  \
  })
#else
#define GetStaticStackAddr(ADDEND) (GetStackAddr() + ADDEND)
#endif

#define GetStackPointer()           \
  ({                                \
    uintptr_t __sp;                 \
    __asm__(__mov_sp : "=r"(__sp)); \
    __sp;                           \
  })

#ifdef __x86_64__
#define __mov_sp "mov\t%%rsp,%0"
#elif defined(__aarch64__)
#define __mov_sp "mov\t%0,sp"
#endif

COSMOPOLITAN_C_END_
#endif /* GNU ELF */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_STACK_H_ */


/*!BEGIN libc/runtime/sysconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_SYSCONF_H_

#define _SC_ARG_MAX                      0
#define _SC_CHILD_MAX                    1
#define _SC_CLK_TCK                      2
#define _SC_NGROUPS_MAX                  3
#define _SC_OPEN_MAX                     4
#define _SC_STREAM_MAX                   5
#define _SC_TZNAME_MAX                   6
#define _SC_JOB_CONTROL                  7
#define _SC_SAVED_IDS                    8
#define _SC_REALTIME_SIGNALS             9
#define _SC_PRIORITY_SCHEDULING          10
#define _SC_TIMERS                       11
#define _SC_ASYNCHRONOUS_IO              12
#define _SC_PRIORITIZED_IO               13
#define _SC_SYNCHRONIZED_IO              14
#define _SC_FSYNC                        15
#define _SC_MAPPED_FILES                 16
#define _SC_MEMLOCK                      17
#define _SC_MEMLOCK_RANGE                18
#define _SC_MEMORY_PROTECTION            19
#define _SC_MESSAGE_PASSING              20
#define _SC_SEMAPHORES                   21
#define _SC_SHARED_MEMORY_OBJECTS        22
#define _SC_AIO_LISTIO_MAX               23
#define _SC_AIO_MAX                      24
#define _SC_AIO_PRIO_DELTA_MAX           25
#define _SC_DELAYTIMER_MAX               26
#define _SC_MQ_OPEN_MAX                  27
#define _SC_MQ_PRIO_MAX                  28
#define _SC_VERSION                      29
#define _SC_PAGE_SIZE                    30
#define _SC_PAGESIZE                     30 /* !! */
#define _SC_RTSIG_MAX                    31
#define _SC_SEM_NSEMS_MAX                32
#define _SC_SEM_VALUE_MAX                33
#define _SC_SIGQUEUE_MAX                 34
#define _SC_TIMER_MAX                    35
#define _SC_BC_BASE_MAX                  36
#define _SC_BC_DIM_MAX                   37
#define _SC_BC_SCALE_MAX                 38
#define _SC_BC_STRING_MAX                39
#define _SC_COLL_WEIGHTS_MAX             40
#define _SC_EXPR_NEST_MAX                42
#define _SC_LINE_MAX                     43
#define _SC_RE_DUP_MAX                   44
#define _SC_2_VERSION                    46
#define _SC_2_C_BIND                     47
#define _SC_2_C_DEV                      48
#define _SC_2_FORT_DEV                   49
#define _SC_2_FORT_RUN                   50
#define _SC_2_SW_DEV                     51
#define _SC_2_LOCALEDEF                  52
#define _SC_UIO_MAXIOV                   60 /* !! */
#define _SC_IOV_MAX                      60
#define _SC_THREADS                      67
#define _SC_THREAD_SAFE_FUNCTIONS        68
#define _SC_GETGR_R_SIZE_MAX             69
#define _SC_GETPW_R_SIZE_MAX             70
#define _SC_LOGIN_NAME_MAX               71
#define _SC_TTY_NAME_MAX                 72
#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73
#define _SC_THREAD_KEYS_MAX              74
#define _SC_THREAD_STACK_MIN             75
#define _SC_THREAD_THREADS_MAX           76
#define _SC_THREAD_ATTR_STACKADDR        77
#define _SC_THREAD_ATTR_STACKSIZE        78
#define _SC_THREAD_PRIORITY_SCHEDULING   79
#define _SC_THREAD_PRIO_INHERIT          80
#define _SC_THREAD_PRIO_PROTECT          81
#define _SC_THREAD_PROCESS_SHARED        82
#define _SC_NPROCESSORS_CONF             83
#define _SC_NPROCESSORS_ONLN             84
#define _SC_PHYS_PAGES                   85
#define _SC_AVPHYS_PAGES                 86
#define _SC_ATEXIT_MAX                   87
#define _SC_PASS_MAX                     88
#define _SC_XOPEN_VERSION                89
#define _SC_XOPEN_XCU_VERSION            90
#define _SC_XOPEN_UNIX                   91
#define _SC_XOPEN_CRYPT                  92
#define _SC_XOPEN_ENH_I18N               93
#define _SC_XOPEN_SHM                    94
#define _SC_2_CHAR_TERM                  95
#define _SC_2_UPE                        97
#define _SC_XOPEN_XPG2                   98
#define _SC_XOPEN_XPG3                   99
#define _SC_XOPEN_XPG4                   100
#define _SC_NZERO                        109
#define _SC_XBS5_ILP32_OFF32             125
#define _SC_XBS5_ILP32_OFFBIG            126
#define _SC_XBS5_LP64_OFF64              127
#define _SC_XBS5_LPBIG_OFFBIG            128
#define _SC_XOPEN_LEGACY                 129
#define _SC_XOPEN_REALTIME               130
#define _SC_XOPEN_REALTIME_THREADS       131
#define _SC_ADVISORY_INFO                132
#define _SC_BARRIERS                     133
#define _SC_CLOCK_SELECTION              137
#define _SC_CPUTIME                      138
#define _SC_THREAD_CPUTIME               139
#define _SC_MONOTONIC_CLOCK              149
#define _SC_READER_WRITER_LOCKS          153
#define _SC_SPIN_LOCKS                   154
#define _SC_REGEXP                       155
#define _SC_SHELL                        157
#define _SC_SPAWN                        159
#define _SC_SPORADIC_SERVER              160
#define _SC_THREAD_SPORADIC_SERVER       161
#define _SC_TIMEOUTS                     164
#define _SC_TYPED_MEMORY_OBJECTS         165
#define _SC_2_PBS                        168
#define _SC_2_PBS_ACCOUNTING             169
#define _SC_2_PBS_LOCATE                 170
#define _SC_2_PBS_MESSAGE                171
#define _SC_2_PBS_TRACK                  172
#define _SC_SYMLOOP_MAX                  173
#define _SC_STREAMS                      174
#define _SC_2_PBS_CHECKPOINT             175
#define _SC_V6_ILP32_OFF32               176
#define _SC_V6_ILP32_OFFBIG              177
#define _SC_V6_LP64_OFF64                178
#define _SC_V6_LPBIG_OFFBIG              179
#define _SC_HOST_NAME_MAX                180
#define _SC_TRACE                        181
#define _SC_TRACE_EVENT_FILTER           182
#define _SC_TRACE_INHERIT                183
#define _SC_TRACE_LOG                    184
#define _SC_IPV6                         235
#define _SC_RAW_SOCKETS                  236
#define _SC_V7_ILP32_OFF32               237
#define _SC_V7_ILP32_OFFBIG              238
#define _SC_V7_LP64_OFF64                239
#define _SC_V7_LPBIG_OFFBIG              240
#define _SC_SS_REPL_MAX                  241
#define _SC_TRACE_EVENT_NAME_MAX         242
#define _SC_TRACE_NAME_MAX               243
#define _SC_TRACE_SYS_MAX                244
#define _SC_TRACE_USER_EVENT_MAX         245
#define _SC_XOPEN_STREAMS                246
#define _SC_THREAD_ROBUST_PRIO_INHERIT   247
#define _SC_THREAD_ROBUST_PRIO_PROTECT   248
#define _SC_SIGSTKSZ                     249
#define _SC_MINSIGSTKSZ                  250

COSMOPOLITAN_C_START_

long sysconf(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/utmp.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMP_H_


/*!BEGIN libc/runtime/utmpx.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMPX_H_
COSMOPOLITAN_C_START_

struct utmpx {
  short ut_type;
  pid_t ut_pid;
  char ut_line[32];
  char ut_id[4];
  char ut_user[32];
  char ut_host[256];
  struct {
    short __e_termination;
    short __e_exit;
  } ut_exit;
  long ut_session;
  struct timeval ut_tv;
  unsigned ut_addr_v6[4];
  char __unused[20];
};

void endutxent(void);
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *);
struct utmpx *getutxline(const struct utmpx *);
struct utmpx *pututxline(const struct utmpx *);
void setutxent(void);

#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define e_exit        __e_exit
#define e_termination __e_termination
void updwtmpx(const char *, const struct utmpx *);
int utmpxname(const char *);
#endif

#define EMPTY         0
#define RUN_LVL       1
#define BOOT_TIME     2
#define NEW_TIME      3
#define OLD_TIME      4
#define INIT_PROCESS  5
#define LOGIN_PROCESS 6
#define USER_PROCESS  7
#define DEAD_PROCESS  8

COSMOPOLITAN_C_END_

#define ACCOUNTING  9
#define UT_NAMESIZE 32
#define UT_HOSTSIZE 256
#define UT_LINESIZE 32

COSMOPOLITAN_C_START_

struct lastlog {
  time_t ll_time;
  char ll_line[UT_LINESIZE];
  char ll_host[UT_HOSTSIZE];
};

#define ut_time       ut_tv.tv_sec
#define ut_name       ut_user
#define ut_addr       ut_addr_v6[0]
#define utmp          utmpx
#define e_exit        __e_exit
#define e_termination __e_termination

int login_tty(int);
int utmpname(const char *);
struct utmp *getutent(void);
struct utmp *getutid(const struct utmp *);
struct utmp *getutline(const struct utmp *);
struct utmp *pututline(const struct utmp *);
void endutent(void);
void setutent(void);
void updwtmp(const char *, const struct utmp *);

#define _PATH_UTMP "/dev/null/utmp"
#define _PATH_WTMP "/dev/null/wtmp"

#define UTMP_FILE     _PATH_UTMP
#define WTMP_FILE     _PATH_WTMP
#define UTMP_FILENAME _PATH_UTMP
#define WTMP_FILENAME _PATH_WTMP

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/alg.h */

#define COSMOPOLITAN_LIBC_SOCK_ALG_H_
COSMOPOLITAN_C_START_

struct sockaddr_alg {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[64];
};

struct sockaddr_alg_new {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[]; /* Linux v4.12+ */
};

struct af_alg_iv {
  uint32_t ivlen;
  uint8_t iv[0];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/epoll.h */

#define COSMOPOLITAN_LIBC_SOCK_WEPOLL_H_
COSMOPOLITAN_C_START_

typedef union epoll_data {
  void *ptr;
  int fd;
  uint32_t u32;
  uint64_t u64;
} epoll_data_t;

struct thatispacked epoll_event {
  uint32_t events;
  epoll_data_t data;
};

int epoll_create(int) libcesque;
int epoll_create1(int) libcesque;
int epoll_ctl(int, int, int, struct epoll_event *) libcesque;
int epoll_wait(int, struct epoll_event *, int, int) libcesque;
int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/ifaddrs.h */

#define COSMOPOLITAN_LIBC_SOCK_IFADDRS_H_
COSMOPOLITAN_C_START_

struct ifaddrs {
  struct ifaddrs *ifa_next;
  char *ifa_name;
  unsigned ifa_flags;
  struct sockaddr *ifa_addr;
  struct sockaddr *ifa_netmask;
  union {
    struct sockaddr *ifa_broadaddr;
    struct sockaddr *ifa_dstaddr;
  };
  void *ifa_data;
};

void freeifaddrs(struct ifaddrs *) libcesque;
int getifaddrs(struct ifaddrs **) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/in.h */

#define COSMOPOLITAN_LIBC_SOCK_IN_H_

#define IN_CLASSA(a)       ((((in_addr_t)(a)) & 0x80000000) == 0)
#define IN_CLASSA_NET      0xff000000
#define IN_CLASSA_NSHIFT   24
#define IN_CLASSA_HOST     (0xffffffff & ~IN_CLASSA_NET)
#define IN_CLASSA_MAX      128
#define IN_CLASSB(a)       ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET      0xffff0000
#define IN_CLASSB_NSHIFT   16
#define IN_CLASSB_HOST     (0xffffffff & ~IN_CLASSB_NET)
#define IN_CLASSB_MAX      65536
#define IN_CLASSC(a)       ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET      0xffffff00
#define IN_CLASSC_NSHIFT   8
#define IN_CLASSC_HOST     (0xffffffff & ~IN_CLASSC_NET)
#define IN_CLASSD(a)       ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
#define IN_MULTICAST(a)    IN_CLASSD(a)
#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
#define IN_BADCLASS(a)     ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)

#define IN6_IS_ADDR_UNSPECIFIED(a)                           \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint32_t *)(a))[3] == 0)

#define IN6_IS_ADDR_LOOPBACK(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[12] == 0 && \
   ((uint8_t *)(a))[13] == 0 && ((uint8_t *)(a))[14] == 0 && \
   ((uint8_t *)(a))[15] == 1)

#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *)(a))[0] == 0xff)

#define IN6_IS_ADDR_LINKLOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0x80)

#define IN6_IS_ADDR_SITELOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0xc0)

#define IN6_IS_ADDR_V4MAPPED(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint8_t *)(a))[8] == 0 && ((uint8_t *)(a))[9] == 0 &&   \
   ((uint8_t *)(a))[10] == 0xff && ((uint8_t *)(a))[11] == 0xff)

#define IN6_IS_ADDR_V4COMPAT(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[15] > 1)

#define IN6_IS_ADDR_MC_NODELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x1))

#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x2))

#define IN6_IS_ADDR_MC_SITELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x5))

#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x8))

#define IN6_IS_ADDR_MC_GLOBAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0xe))

#define __ARE_4_EQUAL(a, b) \
  (!((0 [a] - 0 [b]) | (1 [a] - 1 [b]) | (2 [a] - 2 [b]) | (3 [a] - 3 [b])))
#define IN6_ARE_ADDR_EQUAL(a, b) \
  __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))



/*!BEGIN libc/sock/select.h */

#define COSMOPOLITAN_LIBC_SOCK_SELECT_H_

#define FD_SETSIZE 1024 /* it's 64 on windows */

COSMOPOLITAN_C_START_

typedef struct fd_set {
  unsigned long fds_bits[FD_SETSIZE / (sizeof(long) * 8)];
} fd_set;

#define FD_ISSET(FD, SET) (((SET)->fds_bits[(FD) >> 6] >> ((FD)&63)) & 1)
#define FD_SET(FD, SET)   ((SET)->fds_bits[(FD) >> 6] |= 1ull << ((FD)&63))
#define FD_CLR(FD, SET)   ((SET)->fds_bits[(FD) >> 6] &= ~(1ull << ((FD)&63)))
#define FD_ZERO(SET)      bzero((SET)->fds_bits, sizeof((SET)->fds_bits))
#define FD_SIZE(bits)     (((bits) + (sizeof(long) * 8) - 1) / sizeof(long))

int select(int, fd_set *, fd_set *, fd_set *, struct timeval *) libcesque;
int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
            const sigset_t *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/syslog.h */

#define COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_
COSMOPOLITAN_C_START_

int setlogmask(int) libcesque;
void openlog(const char *, int, int) libcesque;
void syslog(int, const char *, ...) libcesque;
void closelog(void) libcesque;
void vsyslog(int, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arphdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPHDR_H_
COSMOPOLITAN_C_START_

struct arphdr {
  uint16_t ar_hrd;
  uint16_t ar_pro;
  uint8_t ar_hln;
  uint8_t ar_pln;
  uint16_t ar_op;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arpreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPREQ_H_
COSMOPOLITAN_C_START_

struct arpreq {
  struct sockaddr arp_pa;
  struct sockaddr arp_ha;
  int arp_flags;
  struct sockaddr arp_netmask;
  char arp_dev[16];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/cmsghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_H_
COSMOPOLITAN_C_START_

#define CMSG_DATA(cmsg) ((unsigned char *)(((struct cmsghdr *)(cmsg)) + 1))

#define CMSG_FIRSTHDR(mhdr)                                 \
  ((size_t)(mhdr)->msg_controllen >= sizeof(struct cmsghdr) \
       ? (struct cmsghdr *)(mhdr)->msg_control              \
       : (struct cmsghdr *)0)

#define CMSG_NXTHDR(mhdr, cmsg)                           \
  ((cmsg)->cmsg_len < sizeof(struct cmsghdr) ||           \
           __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >=   \
               __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
       ? 0                                                \
       : (struct cmsghdr *)__CMSG_NEXT(cmsg))

#define CMSG_ALIGN(len) \
  (((len) + sizeof(size_t) - 1) & (size_t) ~(sizeof(size_t) - 1))

#define CMSG_SPACE(len) (CMSG_ALIGN(len) + CMSG_ALIGN(sizeof(struct cmsghdr)))

#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))

#define __CMSG_LEN(cmsg) \
  (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
#define __MHDR_END(mhdr) \
  ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)

struct cmsghdr { /* linux abi */
  uint32_t cmsg_len;
  uint32_t __pad1;
  int32_t cmsg_level;
  int32_t cmsg_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ether_header.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ETHER_HEADER_H_

#define ETH_ALEN 6

COSMOPOLITAN_C_START_

struct ether_addr {
  uint8_t ether_addr_octet[ETH_ALEN];
};

struct ether_header {
  uint8_t ether_dhost[ETH_ALEN];
  uint8_t ether_shost[ETH_ALEN];
  uint16_t ether_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ifconf.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFCONF_H_


/*!BEGIN libc/sock/struct/ifreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFREQ_H_
COSMOPOLITAN_C_START_

#define IF_NAMESIZE 16
#define IFNAMSIZ    IF_NAMESIZE

struct ifreq {
  union {
    char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0".  */
  } ifr_ifrn;
  union {
    struct sockaddr ifru_addr;      /* SIOCGIFADDR */
    struct sockaddr ifru_dstaddr;   /* SIOCGIFDSTADDR */
    struct sockaddr ifru_netmask;   /* SIOCGIFNETMASK */
    struct sockaddr ifru_broadaddr; /* SIOCGIFBRDADDR */
    short ifru_flags;               /* SIOCGIFFLAGS */
    int ifru_ivalue;                /* todo(jart) */
    char ifru_pad[24];              /* ifru_map is the largest, just pad */
  } ifr_ifru;
};

#define ifr_name      ifr_ifrn.ifrn_name      /* interface name */
#define ifr_addr      ifr_ifru.ifru_addr      /* address */
#define ifr_netmask   ifr_ifru.ifru_netmask   /* netmask */
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
#define ifr_dstaddr   ifr_ifru.ifru_dstaddr   /* destination address */
#define ifr_flags     ifr_ifru.ifru_flags     /* flags */
#define ifr_ifindex   ifr_ifru.ifru_ivalue

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/*
 * Structure used in SIOCGIFCONF request.
 * Used to retrieve interface configuration
 * for machine (useful for programs which
 * must know all networks accessible).
 */
struct ifconf {
  int32_t ifc_len; /* size of buffer */
  int32_t padding;
  union {
    char *ifcu_buf;
    struct ifreq *ifcu_req;
  } ifc_ifcu;
};

/* Shortcuts to the ifconf buffer or ifreq array */
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address   */
#define ifc_req ifc_ifcu.ifcu_req /* array of structures  */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in6_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN6_PKTINFO_H_


/*!BEGIN libc/sock/struct/sockaddr6.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SOCKADDR6_H_

struct in6_addr {
  union {
    uint8_t s6_addr[16];
    uint16_t s6_addr16[8];
    uint32_t s6_addr32[4];
  };
};

struct sockaddr_in6 { /* Linux+NT ABI */
  uint16_t sin6_family;
  uint16_t sin6_port;
  uint32_t sin6_flowinfo;
  struct in6_addr sin6_addr;
  uint32_t sin6_scope_id; /* rfc2553 */
};

extern const struct in6_addr in6addr_any;
extern const struct in6_addr in6addr_loopback;

COSMOPOLITAN_C_START_

struct in6_pktinfo {
  struct in6_addr ipi6_addr;
  unsigned ipi6_ifindex;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN_PKTINFO_H_
COSMOPOLITAN_C_START_

struct in_pktinfo {
  int ipi_ifindex;
  struct in_addr ipi_spec_dst;
  struct in_addr ipi_addr;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ip_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IP_MREQ_H_
COSMOPOLITAN_C_START_

struct ip_mreq {
  struct in_addr imr_multiaddr; /* IP multicast address of group */
  struct in_addr imr_interface; /* local IP address of interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ipv6_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IPV6_MREQ_H_
COSMOPOLITAN_C_START_

struct ipv6_mreq {
  struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address of group */
  unsigned ipv6mr_interface;        /* local interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/linger.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger {     /* Linux+XNU+BSD ABI */
  int32_t l_onoff;  /* on/off */
  int32_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/msghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_H_
COSMOPOLITAN_C_START_

struct msghdr {            /* Linux+NT ABI */
  void *msg_name;          /* optional address */
  uint32_t msg_namelen;    /* size of msg_name */
  struct iovec *msg_iov;   /* scatter/gather array */
  uint64_t msg_iovlen;     /* # elements in msg_iov */
  void *msg_control;       /* ancillary data c. cmsghdr */
  uint64_t msg_controllen; /* ancillary data buffer len */
  uint32_t msg_flags;      /* MSG_XXX */
};

ssize_t recvmsg(int, struct msghdr *, int);
ssize_t sendmsg(int, const struct msghdr *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_
COSMOPOLITAN_C_START_

struct pollfd {
  int32_t fd;
  int16_t events;
  int16_t revents;
};

int poll(struct pollfd *, uint64_t, int32_t);
int ppoll(struct pollfd *, uint64_t, const struct timespec *, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/append.h */

#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_

#define APPEND_COOKIE 21578

#define appendz   __appendz
#define appendr   __appendr
#define appendd   __appendd
#define appendw   __appendw
#define appends   __appends
#define appendf   __appendf
#define vappendf  __vappendf
#define kappendf  __kappendf
#define kvappendf __kvappendf

COSMOPOLITAN_C_START_

struct appendz {
  size_t i;
  size_t n;
};

struct appendz appendz(char *) libcesque;
ssize_t appendr(char **, size_t) libcesque;
ssize_t appendd(char **, const void *, size_t) libcesque;
ssize_t appendw(char **, uint64_t) libcesque;
ssize_t appends(char **, const char *) libcesque;
ssize_t appendf(char **, const char *, ...) libcesque;
ssize_t vappendf(char **, const char *, va_list) libcesque;
ssize_t kappendf(char **, const char *, ...) libcesque;
ssize_t kvappendf(char **, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_STDIO_APPEND_H_ */


/*!BEGIN libc/stdio/dprintf.h */

#define COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_
COSMOPOLITAN_C_START_

libcesque int dprintf(int, const char *, ...) paramsnonnull((2));
libcesque int vdprintf(int, const char *, va_list) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/ftw.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_FTW_H_
COSMOPOLITAN_C_START_

/**
 * Type for file.
 */
#define FTW_F 1

/**
 * Type for directory.
 */
#define FTW_D 2

/**
 * Type for directory that cannot be read.
 */
#define FTW_DNR 3

/**
 * Type for stat() failed and not a symbolic link.
 */
#define FTW_NS 4

/**
 * Type for symbolic link when `FTW_PHYS` is in flags.
 */
#define FTW_SL 5

/**
 * Directory and `FTW_DEPTH` in flags.
 */
#define FTW_DP 6

/**
 * Type for broken symbolic link when `FTW_PHYS` is not in flags.
 */
#define FTW_SLN 7

/**
 * Flag to prevent following symbolic links (recommended).
 * @see nftw() flags
 */
#define FTW_PHYS 1

/**
 * Flag to prevent crossing mount points.
 * @see nftw() flags
 */
#define FTW_MOUNT 2

/**
 * Unsupported.
 * @see nftw() flags
 */
#define FTW_CHDIR 4

/**
 * Flag for post-order traversal.
 *
 * 1. Will use `FTW_DP` instead of `FTW_D` as type.
 * 2. Directory callback happens *after* rather than before.
 *
 * @see nftw() flags
 */
#define FTW_DEPTH 8

struct FTW {

  /**
   * Byte offset of basename component in `fpath` passed to callback.
   */
  int base;

  /**
   * Depth relative to `dirpath` whose level is zero.
   */
  int level;
};

int ftw(const char *, int (*)(const char *, const struct stat *, int),
        int) dontthrow;

int nftw(const char *,
         int (*)(const char *, const struct stat *, int, struct FTW *), int,
         int) dontthrow;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/iconv.h */

#define COSMOPOLITAN_LIBC_STDIO_ICONV_H_
COSMOPOLITAN_C_START_

typedef void *iconv_t;

iconv_t iconv_open(const char *, const char *);
size_t iconv(iconv_t, char **, size_t *, char **, size_t *);
int iconv_close(iconv_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/rand.h */

#define COSMOPOLITAN_LIBC_RAND_RAND_H_
#define RAND_MAX __INT_MAX__
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § random                                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int rand(void) libcesque;
void srand(unsigned) libcesque;
char *strfry(char *) libcesque;
int getentropy(void *, size_t) libcesque;
ssize_t getrandom(void *, size_t, unsigned) libcesque;
char *initstate(unsigned, char *, size_t) libcesque;
char *setstate(char *) libcesque;
long random(void) libcesque;
void srandom(unsigned) libcesque;

#ifdef _COSMO_SOURCE
#define vigna   __vigna
#define vigna_r __vigna_r
#define rngset  __rngset
#define rdrand  __rdrand
#define rdseed  __rdseed
double poz(double) libcesque;
double pochisq(double, int) libcesque;
uint64_t lemur64(void) libcesque;
uint64_t _rand64(void) libcesque;
uint64_t vigna(void) libcesque;
uint64_t vigna_r(uint64_t[hasatleast 1]) libcesque;
void svigna(uint64_t) libcesque;
uint64_t rdrand(void) libcesque;
uint64_t rdseed(void) libcesque;
void _smt19937(uint64_t) libcesque;
void _Smt19937(uint64_t[], size_t) libcesque;
uint64_t _mt19937(void) libcesque;
double _real1(uint64_t) libcesque;
double _real2(uint64_t) libcesque;
double _real3(uint64_t) libcesque;
double MeasureEntropy(const char *, size_t) libcesque;
void *rngset(void *, size_t, uint64_t (*)(void), size_t) libcesque;
void rt_init(int) libcesque;
void rt_add(void *, int) libcesque;
void rt_end(double *, double *, double *, double *, double *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/readpassphrase.h */

#define COSMOPOLITAN_LIBC_STDIO_READPASSPHRASE_H_

#define RPP_ECHO_OFF    0x00
#define RPP_ECHO_ON     0x01
#define RPP_REQUIRE_TTY 0x02
#define RPP_FORCELOWER  0x04
#define RPP_FORCEUPPER  0x08
#define RPP_SEVENBIT    0x10
#define RPP_STDIN       0x20

COSMOPOLITAN_C_START_

char *readpassphrase(const char *, char *, size_t, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/stdio_ext.h */

#define COSMOPOLITAN_LIBC_STDIO_STDIO_EXT_H_

#define FSETLOCKING_QUERY    0
#define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_BYCALLER 2

COSMOPOLITAN_C_START_

size_t __fbufsize(FILE *) libcesque;
size_t __fpending(FILE *) libcesque;
int __flbf(FILE *) libcesque;
int __freadable(FILE *) libcesque;
int __fwritable(FILE *) libcesque;
int __freading(FILE *) libcesque;
int __fwriting(FILE *) libcesque;
int __fsetlocking(FILE *, int) libcesque;
void _flushlbf(void) libcesque;
void __fpurge(FILE *) libcesque;
void __fseterr(FILE *) libcesque;
const char *__freadptr(FILE *, size_t *) libcesque;
size_t __freadahead(FILE *) libcesque;
void __freadptrinc(FILE *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/syscall.h */

#define COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_
COSMOPOLITAN_C_START_

#define SYS_gettid    1
#define SYS_getrandom 2
#define SYS_getcpu    3

long syscall(long, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/sysparam.h */

#define COSMOPOLITAN_LIBC_SYSPARAM_H_

#define MAXSYMLINKS    20
#define MAXHOSTNAMELEN 64
#define MAXNAMLEN      255
#define MAXPATHLEN     PATH_MAX
#define NBBY           8
#define NGROUPS        32
#define CANBSIZ        255
#define NOFILE         256
#define NCARGS         131072
#define DEV_BSIZE      512
#define NOGROUP        (-1)

COSMOPOLITAN_C_START_

#define __bitop(x, i, o) ((x)[(i) / 8] o(1 << (i) % 8))
#define setbit(x, i)     __bitop(x, i, |=)
#define clrbit(x, i)     __bitop(x, i, &= ~)
#define isset(x, i)      __bitop(x, i, &)
#define isclr(x, i)      !isset(x, i)

#undef roundup
#define roundup(n, d) (howmany(n, d) * (d))
#define powerof2(n)   !(((n)-1) & (n))
#define howmany(n, d) (((n) + ((d)-1)) / (d))

#ifdef MIN
#undef MIN
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

#ifdef MAX
#undef MAX
#endif
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/ntspawn.h */

#define COSMOPOLITAN_NTSPAWN_H_
COSMOPOLITAN_C_START_

struct NtSpawnArgs {
  int64_t dirhand;
  const char *prog;
  char *const *argv;
  char *const *envp;
  char *const *extravars;
  uint32_t dwCreationFlags;
  const char16_t *opt_lpCurrentDirectory;
  int64_t opt_hParentProcess;
  int64_t *opt_lpExplicitHandleList;
  uint32_t dwExplicitHandleCount;
  const struct NtStartupInfo *lpStartupInfo;
  struct NtProcessInformation *opt_out_lpProcessInformation;
};

int mkntenvblock(char16_t[32767], char *const[], char *const[], char[32767]);
int ntspawn(struct NtSpawnArgs *);
size_t mkntcmdline(char16_t *, char *const[], size_t);
void mungentpath(char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/posix_spawn.h */

#define COSMOPOLITAN_LIBC_STDIO_SPAWN_H_

#define POSIX_SPAWN_USEVFORK      0
#define POSIX_SPAWN_RESETIDS      1
#define POSIX_SPAWN_SETPGROUP     2
#define POSIX_SPAWN_SETSIGDEF     4
#define POSIX_SPAWN_SETSIGMASK    8
#define POSIX_SPAWN_SETSCHEDPARAM 16
#define POSIX_SPAWN_SETSCHEDULER  32
#define POSIX_SPAWN_SETSID        128
#define POSIX_SPAWN_SETRLIMIT     256

COSMOPOLITAN_C_START_

typedef struct _posix_spawna *posix_spawnattr_t;
typedef struct _posix_faction *posix_spawn_file_actions_t;

int posix_spawn(int *, const char *, const posix_spawn_file_actions_t *,
                const posix_spawnattr_t *, char *const[], char *const[]);
int posix_spawnp(int *, const char *, const posix_spawn_file_actions_t *,
                 const posix_spawnattr_t *, char *const[], char *const[]);

int posix_spawn_file_actions_init(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *,
                                      int) libcesque;
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int,
                                     int) libcesque;
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *, int,
                                     const char *, int, unsigned) libcesque;
int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *,
                                         const char *) libcesque;
int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
                                          int) libcesque;

int posix_spawnattr_init(posix_spawnattr_t *) libcesque;
int posix_spawnattr_destroy(posix_spawnattr_t *) libcesque;
int posix_spawnattr_getflags(const posix_spawnattr_t *, short *) libcesque;
int posix_spawnattr_setflags(posix_spawnattr_t *, short) libcesque;
int posix_spawnattr_getpgroup(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setpgroup(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedparam(const posix_spawnattr_t *,
                                  struct sched_param *) libcesque;
int posix_spawnattr_setschedparam(posix_spawnattr_t *,
                                  const struct sched_param *) libcesque;
int posix_spawnattr_getsigmask(const posix_spawnattr_t *, sigset_t *) libcesque;
int posix_spawnattr_setsigmask(posix_spawnattr_t *, const sigset_t *) libcesque;
int posix_spawnattr_getsigdefault(const posix_spawnattr_t *,
                                  sigset_t *) libcesque;
int posix_spawnattr_setsigdefault(posix_spawnattr_t *,
                                  const sigset_t *) libcesque;
int posix_spawnattr_getrlimit(const posix_spawnattr_t *, int,
                              struct rlimit *) libcesque;
int posix_spawnattr_setrlimit(posix_spawnattr_t *, int,
                              const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/atomic.h */

#define NSYNC_ATOMIC_H_
COSMOPOLITAN_C_START_

#define nsync_atomic_uint32_ atomic_uint

#define NSYNC_ATOMIC_UINT32_INIT_        0
#define NSYNC_ATOMIC_UINT32_LOAD_(p)     (*(p))
#define NSYNC_ATOMIC_UINT32_STORE_(p, v) (*(p) = (v))
#define NSYNC_ATOMIC_UINT32_PTR_(p)      (p)

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/counter.h */

#define NSYNC_COUNTER_H_


/*!BEGIN third_party/nsync/time.h */

#define NSYNC_TIME_H_
COSMOPOLITAN_C_START_

#define NSYNC_TIME_SEC(t)  ((t).tv_sec)
#define NSYNC_TIME_NSEC(t) ((t).tv_nsec)
#define NSYNC_TIME_STATIC_INIT(t, ns) \
  { (t), (ns) }

/* The type nsync_time represents the interval elapsed between two
   moments in time. Often the first such moment is an address-space-wide
   epoch, such as the Unix epoch, but clients should not rely on the
   epoch in one address space being the same as that in another.
   Intervals relative to the epoch are known as absolute times. */
typedef struct timespec nsync_time;

/* A deadline infinitely far in the future. */
#define nsync_time_no_deadline timespec_max

/* The zero delay, or an expired deadline. */
#define nsync_time_zero timespec_zero

/* Return the current time since the epoch.  */
#define nsync_time_now() timespec_real()

/* Sleep for the specified delay. Returns the unslept time which may be
   non-zero if the call was interrupted. */
#define nsync_time_sleep(a) timespec_sleep(a)

/* Sleep until the specified time.  Returns 0 on success, and EINTR
   if the call was interrupted. */
#define nsync_time_sleep_until(a) timespec_sleep_until(a)

/* Return a+b */
#define nsync_time_add(a, b) timespec_add(a, b)

/* Return a-b */
#define nsync_time_sub(a, b) timespec_sub(a, b)

/* Return +ve, 0, or -ve according to whether a>b, a==b, or a<b. */
#define nsync_time_cmp(a, b) timespec_cmp(a, b)

/* Return the specified number of milliseconds as a time. */
#define nsync_time_ms(a) timespec_frommillis(a)

/* Return the specified number of microseconds as a time. */
#define nsync_time_us(a) timespec_frommicros(a)

/* Return the specified number of nanoseconds as a time. */
#define nsync_time_ns(a) timespec_fromnanos(a)

/* Return an nsync_time constructed from second and nanosecond
   components */
#define nsync_time_s_ns(s, ns) ((nsync_time){(int64_t)(s), (unsigned)(ns)})

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/* An nsync_counter represents an unsigned integer that can count up and down,
   and wake waiters when zero.  */
typedef struct nsync_counter_s_ *nsync_counter;

/* Return a freshly allocated nsync_counter with the specified value,
   of NULL if an nsync_counter cannot be created.

   Any non-NULL returned value should be passed to nsync_counter_free() when no
   longer needed.  */
nsync_counter nsync_counter_new(uint32_t value);

/* Free resources associated with c.  Requires that c was allocated by
   nsync_counter_new(), and no concurrent or future operations are applied to
   c.  */
void nsync_counter_free(nsync_counter c);

/* Add delta to c, and return its new value.  It is a checkable runtime error
   to decrement c below 0, or to increment c (i.e., apply a delta > 0) after a
   waiter has waited.  */
uint32_t nsync_counter_add(nsync_counter c, int32_t delta);

/* Return the current value of c.  */
uint32_t nsync_counter_value(nsync_counter c);

/* Wait until c has value 0, or until abs_deadline, then return
   the value of c.  It is a checkable runtime error to increment c after
   a waiter may have been woken due to the counter reaching zero.
   If abs_deadline==nsync_time_no_deadline, the deadline
   is far in the future. */
uint32_t nsync_counter_wait(nsync_counter c, nsync_time abs_deadline);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/cv.h */

#define NSYNC_CV_H_


/*!BEGIN third_party/nsync/mu.h */

#define NSYNC_MU_H_
COSMOPOLITAN_C_START_

/* An nsync_mu is a lock. If initialized to zero, it's valid and unlocked.

   An nsync_mu can be "free", held by a single thread (aka fiber,
   goroutine) in "write" (exclusive) mode, or by many threads in "read"
   (shared) mode. A thread that acquires it should eventually release
   it. It is illegal to acquire an nsync_mu in one thread and release it
   in another. It is illegal for a thread to reacquire an nsync_mu while
   holding it (even a second share of a "read" lock).

   Example usage:

       static struct foo {
         nsync_mu mu; // protects invariant a+b==0 on fields below.
         int a;
         int b;
       } p = { NSYNC_MU_INIT, 0, 0 };
       // ....
       nsync_mu_lock (&p.mu);
       // The current thread now has exclusive access to p.a and p.b;
       // invariant assumed true.
       p.a++;
       p.b--; // restore invariant p.a+p.b==0 before releasing p.mu
       nsync_mu_unlock (&p.mu)

   Mutexes can be used with condition variables; see nsync_cv.h.

   nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. See nsync_mu_wait.h for more details. Example
   use of nsync_mu_wait() to wait for p.a==0, using definition above:

        int a_is_zero (const void *condition_arg) {
                return (((const struct foo *)condition_arg)->a == 0);
        }
        ...
        nsync_mu_lock (&p.mu);
        nsync_mu_wait (&p.mu, &a_is_zero, &p, NULL);
        // The current thread now has exclusive access to
        // p.a and p.b, and p.a==0.
        ...
        nsync_mu_unlock (&p.mu);

*/
typedef struct nsync_mu_s_ {
  nsync_atomic_uint32_ word; /* internal use only */
  int _zero;                 /* c pthread_mutex_t */
  struct Dll *waiters;       /* internal use only */
} nsync_mu;

/* An nsync_mu should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_MU_INIT, or by setting
   the entire structure to all zeroes, or using nsync_mu_init(). */
#define NSYNC_MU_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }
void nsync_mu_init(nsync_mu *mu);

/* Block until *mu is free and then acquire it in writer mode. Requires
   that the calling thread not already hold *mu in any mode. */
void nsync_mu_lock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in write mode by the
   calling thread, and wake waiters, if appropriate. */
void nsync_mu_unlock(nsync_mu *mu);

/* Attempt to acquire *mu in writer mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. */
int nsync_mu_trylock(nsync_mu *mu);

/* Block until *mu can be acquired in reader mode and then acquire it.
   Requires that the calling thread not already hold *mu in any mode. */
void nsync_mu_rlock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in read mode by the calling
   thread, and wake waiters, if appropriate. */
void nsync_mu_runlock(nsync_mu *mu);

/* Attempt to acquire *mu in reader mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. Perhaps fail to acquire if a writer is waiting, to
   avoid starvation. */
int nsync_mu_rtrylock(nsync_mu *mu);

/* May abort if *mu is not held in write mode by the calling thread. */
void nsync_mu_assert_held(const nsync_mu *mu);

/* May abort if *mu is not held in read or write mode
   by the calling thread.  */
void nsync_mu_rassert_held(const nsync_mu *mu);

/* Return whether *mu is held in read mode.
   Requires that the calling thread holds *mu in some mode. */
int nsync_mu_is_reader(const nsync_mu *mu);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

#define NSYNC_CV_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }

struct nsync_note_s_;

/* An nsync_cv is a condition variable in the style of Mesa, Java,
   POSIX, and Go's sync.Cond. It allows a thread to wait for a condition
   on state protected by a mutex, and to proceed with the mutex held and
   the condition true.

   See also nsync_mu_wait() and nsync_mu_wait_with_deadline(), which
   implement conditional critical sections. In many cases, they are
   easier to use than condition variables.

   Usage

   After making the desired predicate true, call:

       nsync_cv_signal (&cv);    // If at most one thread can make use
                                 // of the predicate becoming true.

   or

       nsync_cv_broadcast (&cv); // If multiple threads can make use
                                 // of the predicate becoming true.

   To wait for a predicate with no deadline (assuming
   nsync_cv_broadcast() or nsync_cv_signal() is called whenever the
   predicate becomes true):

       nsync_mu_lock (&mu;)
       while (!some_predicate_protected_by_mu) { // while-loop required
         nsync_cv_wait (&cv, &mu);
       }
       // predicate is now true
       nsync_mu_unlock (&mu);

   To wait for a predicate with a deadline (assuming nsync_cv_broadcast() or
   nsync_cv_signal() is called whenever the predicate becomes true):

       nsync_mu_lock (&mu);
       while (!some_predicate_protected_by_mu &&
         nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                      cancel_note) == 0) {
       }
       if (some_predicate_protected_by_mu) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   or, if the predicate is complex and you wish to write it just once
   and inline, you could use the following instead of the for-loop
   above:

       nsync_mu_lock (&mu);
       int pred_is_true = 0;
       int outcome = 0;
       while (!(pred_is_true = some_predicate_protected_by_mu) &&
              outcome == 0) {
         outcome = nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                                cancel_note);
       }
       if (pred_is_true) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   As the examples show, Mesa-style condition variables require that
   waits use a loop that tests the predicate anew after each wait. It
   may be surprising that these are preferred over the precise wakeups
   offered by the condition variables in Hoare monitors. Imprecise
   wakeups make more efficient use of the critical section, because
   threads can enter it while a woken thread is still emerging from the
   scheduler, which may take thousands of cycles. Further, they make the
   programme easier to read and debug by making the predicate explicit
   locally at the wait, where the predicate is about to be assumed; the
   reader does not have to infer the predicate by examining all the
   places where wakeups may occur. */
typedef struct nsync_cv_s_ {
  /* see bits below */
  nsync_atomic_uint32_ word;
  /* points to tail of list of waiters; under mu. */
  struct Dll *waiters;
} nsync_cv;

/* An nsync_cv should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_CV_INIT, or by setting
   the entire struct to 0, or using nsync_cv_init(). */
void nsync_cv_init(nsync_cv *cv);

/* Wake at least one thread if any are currently blocked on *cv. If the
   chosen thread is a reader on an nsync_mu, wake all readers and, if
   possible, a writer. */
void nsync_cv_signal(nsync_cv *cv);

/* Wake all threads currently blocked on *cv. */
void nsync_cv_broadcast(nsync_cv *cv);

/* Atomically release "mu" (which must be held on entry) and block the
   caller on *cv. Wait until awakened by a call to nsync_cv_signal() or
   nsync_cv_broadcast(), or a spurious wakeup; then reacquire "mu", and
   return. Equivalent to a call to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL. Callers
   should use nsync_cv_wait() in a loop, as with all standard Mesa-style
   condition variables. See examples above. Returns 0 normally, otherwise
   ECANCELED may be returned if calling POSIX thread is cancelled only when
   the PTHREAD_CANCEL_MASKED mode is in play. */
int nsync_cv_wait(nsync_cv *cv, nsync_mu *mu);

/* Atomically release "mu" (which must be held on entry) and block the
   calling thread on *cv. It then waits until awakened by a call to
   nsync_cv_signal() or nsync_cv_broadcast() (or a spurious wakeup), or
   by the time reaching abs_deadline, or by cancel_note being notified.
   In all cases, it reacquires "mu", and returns the reason for the call
   returned (0, ETIMEDOUT, or ECANCELED). Use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no nsync cancellations (however POSIX thread
   cancellations may still happen, and ECANCELED could still be returned
   when the calling thread is cancelled only if PTHREAD_CANCEL_MASKED is
   in play). wait_with_deadline() should be used in a loop, as with all
   Mesa-style condition variables. See examples above.

   There are two reasons for using an absolute deadline, rather than a
   relative timeout---these are why pthread_cond_timedwait() also uses
   an absolute deadline. First, condition variable waits have to be used
   in a loop; with an absolute times, the deadline does not have to be
   recomputed on each iteration. Second, in most real programmes, some
   activity (such as an RPC to a server, or when guaranteeing response
   time in a UI), there is a deadline imposed by the specification or
   the caller/user; relative delays can shift arbitrarily with
   scheduling delays, and so after multiple waits might extend beyond
   the expected deadline. Relative delays tend to be more convenient
   mostly in tests and trivial examples than they are in real
   programmes. */
int nsync_cv_wait_with_deadline(nsync_cv *cv, nsync_mu *mu,
                                nsync_time abs_deadline,
                                struct nsync_note_s_ *cancel_note);

/* Like nsync_cv_wait_with_deadline(), but allow an arbitrary lock *v to be
   used, given its (*lock)(mu) and (*unlock)(mu) routines.  */
int nsync_cv_wait_with_deadline_generic(nsync_cv *cv, void *mu,
                                        void (*lock)(void *),
                                        void (*unlock)(void *),
                                        nsync_time abs_deadline,
                                        struct nsync_note_s_ *cancel_note);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/debug.h */

#define NSYNC_DEBUG_H_
COSMOPOLITAN_C_START_

/* Debugging operations for mutexes and condition variables.

   These operations should not be relied upon for normal functionality.
   The implementation may be slow, output formats may change, and the
   implementation is free to yield the empty string. */

/* Place in buf[0,..,n-1] a nul-terminated, human readable string
   indicative of some of the internal state of the mutex or condition
   variable, and return buf. If n>=4, buffer overflow is indicated by
   placing the characters "..." at the end of the string.

   The *_and_waiters() variants attempt to output the waiter lists in
   addition to the basic state. These variants may acquire internal
   locks and follow internal pointers. Thus, they are riskier if invoked
   in an address space whose overall health is uncertain. */
char *nsync_mu_debug_state(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state(nsync_cv *cv, char *buf, int n);
char *nsync_mu_debug_state_and_waiters(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state_and_waiters(nsync_cv *cv, char *buf, int n);

/* Like nsync_*_debug_state_and_waiters(), but ignoring all locking and
   safety considerations, and using an internal, possibly static buffer
   that may be overwritten by subsequent or concurrent calls to these
   routines. These variants should be used only from an interactive
   debugger, when all other threads are stopped; the debugger is
   expected to recover from errors. */
char *nsync_mu_debugger(nsync_mu *mu);
char *nsync_cv_debugger(nsync_cv *cv);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_semaphore.h */

#define NSYNC_SEM_H_
COSMOPOLITAN_C_START_

typedef struct nsync_semaphore_s_ {
  void *sem_space[3];
} nsync_semaphore;

/* Initialize *s; the initial value is 0. */
void nsync_mu_semaphore_init(nsync_semaphore *s);

/* Wait until the count of *s exceeds 0, and decrement it. */
errno_t nsync_mu_semaphore_p(nsync_semaphore *s);

/* Wait until one of: the count of *s is non-zero, in which case
   decrement *s and return 0; or abs_deadline expires, in which case
   return ETIMEDOUT. */
errno_t nsync_mu_semaphore_p_with_deadline(nsync_semaphore *s,
                                           nsync_time abs_deadline);

/* Ensure that the count of *s is at least 1. */
void nsync_mu_semaphore_v(nsync_semaphore *s);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_wait.h */

#define NSYNC_MU_WAIT_H_
COSMOPOLITAN_C_START_

/* nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. In many straightforward situations they are
   of equivalent performance and are somewhat easier to use, because
   unlike condition variables, they do not require that the waits be
   placed in a loop, and they do not require explicit wakeup calls.
   Example:

   Definitions:

       static nsync_mu mu = NSYNC_MU_INIT;
       static int i = 0;  // protected by mu
       // Condition for use with nsync_mu_wait().
       static int int_is_zero (const void *v) {
         return (*(const int *)v == 0);
       }

   Waiter:

       nsync_mu_lock (&mu);
       // Wait until i is zero.
       nsync_mu_wait (&mu, &int_is_zero, &i, NULL);
       // i is known to be zero here.
       // ...
       nsync_mu_unlock (&mu);

   Thread potentially making i zero:

       nsync_mu_lock (&mu);
       i--;
       // No need to signal that i may have become zero.  The unlock call
       // below will evaluate waiters' conditions to decide which to wake.
       nsync_mu_unlock (&mu);

   It is legal to use conditional critical sections and condition
   variables on the same mutex.

                              --------------

   The implementation benefits from determining whether waiters are
   waiting for the same condition; it may then evaluate a condition once
   on behalf of several waiters. Two waiters have equal condition if
   their "condition" pointers are equal, and either:

     - their "condition_arg" pointers are equal, or

     - "condition_arg_eq" is non-null and (*condition_arg_eq)
       (condition_arg0, condition_arg1) returns non-zero.

   *condition_arg_eq will not be invoked unless the "condition" pointers
   are equal, and the "condition_arg" pointers are unequal.

   If many waiters wait for distinct conditions simultaneously,
   condition variables may be faster.
 */

struct nsync_note_s_; /* forward declaration for an nsync_note */

/* Return when (*condition) (condition_arg) is true. Perhaps unlock and
   relock *mu while blocked waiting for the condition to become true.
   nsync_mu_wait() is equivalent to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL.

   Requires that *mu be held on entry. See nsync_mu_wait_with_deadline()
   for more details on *condition and *condition_arg_eq. */
void nsync_mu_wait(nsync_mu *mu, int (*condition)(const void *condition_arg),
                   const void *condition_arg,
                   int (*condition_arg_eq)(const void *a, const void *b));

/* Return when at least one of: (*condition) (condition_arg) is true,
   the deadline expires, or *cancel_note is notified. Perhaps unlock and
   relock *mu while blocked waiting for one of these events, but always
   return with *mu held. Return 0 iff the (*condition) (condition_arg)
   is true on return, and otherwise either ETIMEDOUT or ECANCELED,
   depending on why the call returned early. Callers should use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no cancellation.

   Requires that *mu be held on entry.

   The implementation may call *condition from any thread using the
   mutex, and while holding *mu in either read or write mode; it
   guarantees that any thread calling *condition will hold *mu in some
   mode. Requires that (*condition) (condition_arg) neither modify state
   protected by *mu, nor return a value dependent on state not protected
   by *mu. To depend on time, use the abs_deadline parameter.
   (Conventional use of condition variables have the same restrictions
   on the conditions tested by the while-loop.) If non-null,
   condition_arg_eq should return whether two condition_arg calls with
   the same "condition" pointer are considered equivalent; it should
   have no side-effects. */
int nsync_mu_wait_with_deadline(
    nsync_mu *mu, int (*condition)(const void *condition_arg),
    const void *condition_arg,
    int (*condition_arg_eq)(const void *a, const void *b),
    nsync_time abs_deadline, struct nsync_note_s_ *cancel_note);

/* Unlock *mu, which must be held in write mode, and wake waiters, if
   appropriate. Unlike nsync_mu_unlock(), this call is not required to
   wake nsync_mu_wait/nsync_mu_wait_with_deadline calls on conditions
   that were false before this thread acquired the lock. This call
   should be used only at the end of critical sections for which:
   - nsync_mu_wait and/or nsync_mu_wait_with_deadline are in use on the same
     mutex,
   - this critical section cannot make the condition true for any of those
     nsync_mu_wait/nsync_mu_wait_with_deadline waits, and
   - when performance is significantly improved by using this call. */
void nsync_mu_unlock_without_wakeup(nsync_mu *mu);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/note.h */

#define NSYNC_NOTE_H_
COSMOPOLITAN_C_START_

/* An nsync_note represents a single bit that can transition from 0 to 1
   at most once. When 1, the note is said to be notified. There are
   operations to wait for the transition, which can be triggered either
   by an explicit call, or timer expiry. Notes can have parent notes; a
   note becomes notified if its parent becomes notified. */
typedef struct nsync_note_s_ *nsync_note;

/* Return a freshly allocated nsync_note, or NULL if an nsync_note
   cannot be created.

   If parent!=NULL, the allocated nsync_note's parent will be parent.
   The newaly allocated note will be automatically notified at
   abs_deadline, and is notified at initialization if
   abs_deadline==nsync_zero_time.

   nsync_notes should be passed to nsync_note_free() when no longer needed. */
nsync_note nsync_note_new(nsync_note parent, nsync_time abs_deadline);

/* Free resources associated with n. Requires that n was allocated by
   nsync_note_new(), and no concurrent or future operations are applied
   to n directly.

   It is legal to call nsync_note_free() on a node even if it has a
   parent or children that are in use; if n has both a parent and
   children, n's parent adopts its children. */
void nsync_note_free(nsync_note n);

/* Notify n and all its descendants. */
void nsync_note_notify(nsync_note n);

/* Return whether n has been notified.  */
int nsync_note_is_notified(nsync_note n);

/* Wait until n has been notified or abs_deadline is reached, and return
   whether n has been notified. If abs_deadline==nsync_time_no_deadline,
   the deadline is far in the future. */
int nsync_note_wait(nsync_note n, nsync_time abs_deadline);

/* Return the expiry time associated with n. This is the minimum of the
   abs_deadline passed on creation and that of any of its ancestors. */
nsync_time nsync_note_expiry(nsync_note n);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/once.h */

#define NSYNC_ONCE_H_
COSMOPOLITAN_C_START_

/* An nsync_once allows a function to be called exactly once, when first
   referenced. */
typedef nsync_atomic_uint32_ nsync_once;

/* An initializer for nsync_once; it is guaranteed to be all zeroes. */
#define NSYNC_ONCE_INIT NSYNC_ATOMIC_UINT32_INIT_

/* The first time nsync_run_once() or nsync_run_once_arg() is applied to
   *once, the supplied function is run (with argument, in the case of
   nsync_run_once_arg()). Other callers will wait until the run of the
   function is complete, and then return without running the function
   again. */
void nsync_run_once(nsync_once *once, void (*f)(void));
void nsync_run_once_arg(nsync_once *once, void (*farg)(void *arg), void *arg);

/* Same as nsync_run_once()/nsync_run_once_arg() but uses a spinloop.
   Can be used on the same nsync_once as
   nsync_run_once/nsync_run_once_arg().

   These *_spin variants should be used only in contexts where normal
   blocking is disallowed, such as within user-space schedulers, when
   the runtime is not fully initialized, etc. They provide no
   significant performance benefit, and they should be avoided in normal
   code. */
void nsync_run_once_spin(nsync_once *once, void (*f)(void));
void nsync_run_once_arg_spin(nsync_once *once, void (*farg)(void *arg),
                             void *arg);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/waiter.h */

#define NSYNC_WAITER_H_
COSMOPOLITAN_C_START_

/* nsync_wait_n() allows the client to wait on multiple objects
   (condition variables, nsync_notes, nsync_counters, etc.) until at
   least one of them becomes ready, or a deadline expires.

   It can be thought of as rather like Unix's select() or poll(), except
   the the objects being waited for are synchronization data structures,
   rather than file descriptors.

   The client can construct new objects that can be waited for by
   implementing three routines.

   Examples:

   To wait on two nsync_notes n0, n1, and a nsync_counter c0, with a
   deadline of abs_deadline:

       // Form an array of struct nsync_waitable_s, identifying the
       // objects and the corresponding descriptors. (Static
       // initialization syntax is used for brevity.)
       static struct nsync_waitable_s w[] = {
         { &n0, &nsync_note_waitable_funcs },
         { &n1, &nsync_note_waitable_funcs },
         { &c0, &nsync_counter_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1], &w[2] };
       int n = sizeof (w) / sizeof (w[0]);

       // Wait. The mu, lock, and unlock arguments are NULL because no
       // condition variables are invovled.
       int i = nsync_wait_n (NULL, NULL, NULL, abs_deadline, n, pw);
       if (i == n) {
         // timeout
       } else {
         // w[i].v became ready.
       }

    To wait on multiple condition variables, the mu/lock/unlock
    parameters are used. Imagine cv0 and cv1 are signalled when
    predicates pred0() (under lock mu0) and pred1() (under lock mu1)
    become true respectively. Assume that mu0 is acquired before mu1.

       static void lock2 (void *v) {  // lock two mutexes in order
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_lock (mu[0]);
         nsync_mu_lock (mu[1]);
       }
       static void unlock2 (void *v) { // unlock two mutexes.
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_unlock (mu[1]);
         nsync_mu_unlock (mu[0]);
       }

       // Describe the condition variables and the locks.
       static struct nsync_waitable_s w[] = {
         { &cv0, &nsync_cv_waitable_funcs },
         { &cv1, &nsync_cv_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1] };
       nsync_mu *lock_list[] = { &mu0, &mu1 };
       int n = sizeof (w) / sizeof (w[0]);

       lock2 (list_list);
       while (!pred0 () && !pred1 ()) {
         // Wait for one of the condition variables to be signalled,
         // with no timeout.
         nsync_wait_n (lock_list, &lock2, &unlock2,
                       nsync_time_no_deadline, n, pw);
       }
       if (pred0 ()) { ... }
       if (pred1 ()) { ... }
       unlock2 (list_list);

   */

/* forward declaration of struct that contains type dependent wait
   operations */
struct nsync_waitable_funcs_s;

/* Clients wait on objects by forming an array of struct
   nsync_waitable_s. Each each element points to one object and its
   type-dependent functions. */
struct nsync_waitable_s {
  /* pointer to object */
  void *v;
  /* pointer to type-dependent functions. Use
     &nsync_note_waitable_funcs for an nsync_note,
     &nsync_counternote_waitable_funcs for an nsync_counter,
     &nsync_cv_waitable_funcs for an nsync_cv. */
  const struct nsync_waitable_funcs_s *funcs;
};

/* Wait until at least one of *waitable[0,..,count-1] is has been
   notified, or abs_deadline is reached. Return the index of the
   notified element of waitable[], or count if no such element exists.
   If mu!=NULL, (*unlock)(mu) is called after the thread is queued on
   the various waiters, and (*lock)(mu) is called before return;
   mu/lock/unlock are used to acquire and release the relevant locks
   whan waiting on condition variables. */
int nsync_wait_n(void *mu, void (*lock)(void *), void (*unlock)(void *),
                 nsync_time abs_deadline, int count,
                 struct nsync_waitable_s *waitable[]);

/* A "struct nsync_waitable_s" implementation must implement these
   functions. Clients should ignore the internals. */
struct nsync_waiter_s;
struct nsync_waitable_funcs_s {

  /* Return the time when *v will be ready (max time if unknown), or 0
     if it is already ready. The parameter nw may be passed as NULL, in
     which case the result should indicate whether the thread would
     block if it were to wait on *v. All calls with the same *v must
     report the same result until the object becomes ready, from which
     point calls must report 0. */
  nsync_time (*ready_time)(void *v, struct nsync_waiter_s *nw);

  /* If *v is ready, return zero; otherwise enqueue *nw on *v and return
     non-zero. */
  int (*enqueue)(void *v, struct nsync_waiter_s *nw);

  /* If nw has been previously dequeued, return zero; otherwise dequeue
   *nw from *v and return non-zero.  */
  int (*dequeue)(void *v, struct nsync_waiter_s *nw);
};

/* The "struct nsync_waitable_s" for nsync_note, nsync_counter, and nsync_cv. */
extern const struct nsync_waitable_funcs_s nsync_note_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_counter_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_cv_waitable_funcs;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/avx512.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
COSMOPOLITAN_C_START_

union XedAvx512Payload1 {
  struct {
    unsigned map : 4;
    unsigned rr_inv : 1;
    unsigned b_inv : 1;
    unsigned x_inv : 1;
    unsigned r_inv : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload2 {
  struct {
    unsigned pp : 2;
    unsigned ubit : 1;
    unsigned vexdest210 : 3;
    unsigned vexdest3 : 1;
    unsigned rexw : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload3 {
  struct {
    unsigned mask : 3;
    unsigned vexdest4p : 1;
    unsigned bcrc : 1;
    unsigned llrc : 2;
    unsigned z : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/private.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_PRIVATE_H_


/*!BEGIN third_party/xed/x86.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86_H_
/*           ▓▓▓▓▓▓▓▓▓▓▓▓▓                      ▄▄▄▄
             ▓▓▓▓▓▓▓▓▓▓▓▓▓     ▄▓▓▓▓▓▓▄      ▄▓▓▓▓▓▓▓▓            ▄▓▓▓▀
             ▓▓▓▓    ▓▓▓▓▓    ▓     ▓▓▓▓    ▓▓       ▓▓▓      ▄▓▓▓▓
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▬▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▬▬▬▬▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓     ▓▓▓▄     ▓▓▓   ▓▓▓▓             │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▀▓▓▓▓▄▄▄▓▓▓▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓▓▓▄   ▄▄▓▓▓▓▓▓▓▓▓  ▓▓▓▓      ▓▓▓▄    │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▄▄▓▓▀  ▀▀▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬║▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▓▓▓ ▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬║▬▬▬
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▓▓▓▓▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
■■■■■■■■║■■■■▓▓▓▓    ▓▓▓▓▓■■■▓▓▓▄▄▄▓▓▓▓■■■■▬▓▓▓▓▄▄▄▄▓▓▓■■■■▬▓▓▓▓▄▄▄▓▓▓▓▀■■■■║■■■
■■■■■■■■■■■■■▓▓▓▓▓▓▓▓▓▓▓▓▓■■■■■▀▓▓▓■■■■■■■■■■■■■■▀▀■■■■■■■■■■■■▀▓▓▀■■■■■■■■■■■■■
        ║▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓║
╔───────╨───────────────────────────────────────────────────────────────────╨──╗
│ cosmopolitan § virtual machine » byte code language                          │
╚─────────────────────────────────────────────────────────────────────────────*/

#define XED_MAX_INSTRUCTION_BYTES 15

#define XED_MODE_REAL   0
#define XED_MODE_LEGACY 1
#define XED_MODE_LONG   2

#define XED_HINT_NTAKEN 2
#define XED_HINT_TAKEN  4
#define XED_HINT_ALTER  6

#define XED_SEG_ES 1
#define XED_SEG_CS 2
#define XED_SEG_SS 3
#define XED_SEG_DS 4
#define XED_SEG_FS 5
#define XED_SEG_GS 6

#define xed_modrm_mod(M)           (((M)&0xff) >> 6)
#define xed_modrm_reg(M)           (((M)&0b00111000) >> 3)
#define xed_modrm_rm(M)            ((M)&7)
#define xed_sib_base(M)            ((M)&7)
#define xed_sib_index(M)           (((M)&0b00111000) >> 3)
#define xed_sib_scale(M)           (((M)&0xff) >> 6)
#define xed_get_modrm_reg_field(M) (((M)&0x38) >> 3)

COSMOPOLITAN_C_START_

#define XED_MACHINE_MODE_REAL           XED_MODE_REAL
#define XED_MACHINE_MODE_LEGACY_32      XED_MODE_LEGACY
#define XED_MACHINE_MODE_LONG_64        XED_MODE_LONG
#define XED_MACHINE_MODE_UNREAL         (1 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LEGACY_16      (2 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_16 (3 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_32 (4 << 2 | XED_MODE_LEGACY)
#define XED_MACHINE_MODE_LAST           (XED_MACHINE_MODE_LONG_COMPAT_32 + 1)

#define XED_ERROR_NONE                         0
#define XED_ERROR_BUFFER_TOO_SHORT             1
#define XED_ERROR_GENERAL_ERROR                2
#define XED_ERROR_INVALID_FOR_CHIP             3
#define XED_ERROR_BAD_REGISTER                 4
#define XED_ERROR_BAD_LOCK_PREFIX              5
#define XED_ERROR_BAD_REP_PREFIX               6
#define XED_ERROR_BAD_LEGACY_PREFIX            7
#define XED_ERROR_BAD_REX_PREFIX               8
#define XED_ERROR_BAD_EVEX_UBIT                9
#define XED_ERROR_BAD_MAP                      10
#define XED_ERROR_BAD_EVEX_V_PRIME             11
#define XED_ERROR_BAD_EVEX_Z_NO_MASKING        12
#define XED_ERROR_NO_OUTPUT_POINTER            13
#define XED_ERROR_NO_AGEN_CALL_BACK_REGISTERED 14
#define XED_ERROR_BAD_MEMOP_INDEX              15
#define XED_ERROR_CALLBACK_PROBLEM             16
#define XED_ERROR_GATHER_REGS                  17
#define XED_ERROR_INSTR_TOO_LONG               18
#define XED_ERROR_INVALID_MODE                 19
#define XED_ERROR_BAD_EVEX_LL                  20
#define XED_ERROR_UNIMPLEMENTED                21
#define XED_ERROR_LAST                         22

#define XED_ADDRESS_WIDTH_INVALID 0
#define XED_ADDRESS_WIDTH_16b     2
#define XED_ADDRESS_WIDTH_32b     4
#define XED_ADDRESS_WIDTH_64b     8
#define XED_ADDRESS_WIDTH_LAST    9

#define XED_ILD_MAP0        0 /* 8086+  ... */
#define XED_ILD_MAP1        1 /* 286+   0x0F,... */
#define XED_ILD_MAP2        2 /* Core2+ 0x0F,0x38,... */
#define XED_ILD_MAP3        3 /* Core2+ 0x0F,0x3A,... */
#define XED_ILD_MAP4        4
#define XED_ILD_MAP5        5
#define XED_ILD_MAP6        6
#define XED_ILD_MAPAMD      7
#define XED_ILD_MAP_XOP8    8
#define XED_ILD_MAP_XOP9    9
#define XED_ILD_MAP_XOPA    10
#define XED_ILD_MAP_LAST    11
#define XED_ILD_MAP_INVALID 12

struct XedOperands { /*
  ┌rep
  │ ┌log₂𝑏
  │ │ ┌mode
  │ │ │ ┌eamode
  │ │ │ │ ┌mod
  │ │ │ │ │
  │ │ │ │ │  ┌sego
  │ │ │ │ │  │
  │ │ │ │ │  │   ┌rex         REGISTER
  │ │ │ │ │  │   │┌rexb       DISPATCH
  │ │ │ │ │  │   ││┌srm       ENCODING
  │ │ │ │ │  │   │││  ┌rex
  │ │ │ │ │  │   │││  │┌rexb
  │ │ │ │ │  │   │││  ││┌rm
  │ │ │ │ │  │   │││  │││  ┌rexw
  │ │ │ │ │  │   │││  │││  │┌osz
  │ │ │ │ │  │   │││  │││  ││┌rex
  │ │ │ │ │  │   │││  │││  │││┌rexr
  │ │ │ │ │  │   │││  │││  ││││┌reg
  │3│2│2│2│2 │   │││  │││  │││││
  │0│8│6│4│2 │18 │││12│││ 7│││││ 0
  ├┐├┐├┐├┐├┐ ├─┐ ││├─┐││├─┐││││├─┐
  00000000000000000000000000000000*/
  uint32_t rde;
  union {
    struct {
      union {
        uint8_t opcode;
        uint8_t srm : 3;
      };
      uint8_t map : 4;
    };
    uint16_t dispatch;
  };
  union {
    uint8_t sib;
    struct {
      uint8_t base : 3;
      uint8_t index : 3;
      uint8_t scale : 2;
    };
  };
  bool osz : 1;   /* operand size override prefix */
  bool rexw : 1;  /* rex.w or rex.wb or etc. 64-bit override */
  bool rexb : 1;  /* rex.b or rex.wb or etc. see modrm table */
  bool rexr : 1;  /* rex.r or rex.wr or etc. see modrm table */
  bool rex : 1;   /* any rex prefix including rex */
  bool rexx : 1;  /* rex.x or rex.wx or etc. see sib table */
  bool rexrr : 1; /* evex */
  bool asz : 1;   /* address size override */
  int64_t disp;   /* displacement(%xxx) mostly sign-extended */
  uint64_t uimm0; /* $immediate mostly sign-extended */
  bool out_of_bytes : 1;
  bool is_intel_specific : 1;
  bool ild_f2 : 1;
  bool ild_f3 : 1;
  bool has_sib : 1;
  bool realmode : 1;
  bool amd3dnow : 1;
  bool lock : 1;
  union {
    uint8_t modrm; /* selects address register */
    struct {
      uint8_t rm : 3;
      uint8_t reg : 3;
      uint8_t mod : 2;
    };
  };
  uint8_t max_bytes;
  uint8_t rep : 2; /* 0, 2 (0xf2 repnz), 3 (0xf3 rep/repe) */
  uint8_t has_modrm : 2;
  bool imm_signed : 1;       /* internal */
  bool disp_unsigned : 1;    /* internal */
  uint8_t seg_ovd : 3;       /* XED_SEG_xx */
  uint8_t error : 5;         /* enum XedError */
  uint8_t mode : 2;          /* real,legacy,long */
  uint8_t hint : 3;          /* static branch prediction */
  uint8_t uimm1;             /* enter $x,$y */
  uint8_t disp_width;        /* in bits */
  uint8_t imm_width;         /* in bits */
  uint8_t mode_first_prefix; /* see xed_set_chip_modes() */
  uint8_t nrexes;
  uint8_t nprefixes;
  uint8_t nseg_prefixes;
  uint8_t ubit;       /* vex */
  uint8_t vexvalid;   /* vex */
  uint8_t vexdest3;   /* vex */
  uint8_t vexdest4;   /* vex */
  uint8_t vexdest210; /* vex */
  uint8_t vex_prefix; /* vex */
  uint8_t zeroing;    /* evex */
  uint8_t bcrc;       /* evex */
  uint8_t llrc;       /* evex */
  uint8_t vl;         /* evex */
  uint8_t mask;       /* evex */
  uint8_t imm1_bytes; /* evex */
  uint8_t pos_disp;
  uint8_t pos_imm;
  uint8_t pos_imm1;
  uint8_t pos_modrm;
  uint8_t pos_opcode;
  uint8_t pos_sib;
};

struct XedDecodedInst {
  unsigned char length;
  uint8_t bytes[15];
  struct XedOperands op;
};

#define xed_operands_set_mode(p, machine_mode) \
  do {                                         \
    struct XedOperands *__p = p;               \
    __p->realmode = false;                     \
    switch (machine_mode) {                    \
      default:                                 \
      case XED_MACHINE_MODE_LONG_64:           \
        __p->mode = XED_MODE_LONG;             \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_32:         \
      case XED_MACHINE_MODE_LONG_COMPAT_32:    \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_REAL:              \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
      case XED_MACHINE_MODE_UNREAL:            \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_16:         \
      case XED_MACHINE_MODE_LONG_COMPAT_16:    \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
    }                                          \
  } while (0)

extern const char kXedErrorNames[];
extern const uint8_t kXedEamode[2][3];

struct XedDecodedInst *xed_decoded_inst_zero_set_mode(struct XedDecodedInst *,
                                                      int);
int xed_instruction_length_decode(struct XedDecodedInst *, const void *,
                                  size_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef int xed_int_t;
typedef unsigned int xed_uint_t;
typedef unsigned int xed_uint_t;
typedef unsigned char xed_bits_t;
typedef intptr_t xed_addr_t;
typedef bool xed_bool_t;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/x86isa.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_
COSMOPOLITAN_C_START_

#define XED_CHIP_INVALID           1
#define XED_CHIP_I86               2
#define XED_CHIP_I86FP             3
#define XED_CHIP_I186              4
#define XED_CHIP_I186FP            5
#define XED_CHIP_I286REAL          6
#define XED_CHIP_I286              7
#define XED_CHIP_I2186FP           8
#define XED_CHIP_I386REAL          9
#define XED_CHIP_I386              10
#define XED_CHIP_I386FP            11
#define XED_CHIP_I486REAL          12
#define XED_CHIP_I486              13
#define XED_CHIP_PENTIUMREAL       14
#define XED_CHIP_PENTIUM           15
#define XED_CHIP_QUARK             16
#define XED_CHIP_PENTIUMMMXREAL    17
#define XED_CHIP_PENTIUMMMX        18
#define XED_CHIP_ALLREAL           19
#define XED_CHIP_PENTIUMPRO        20
#define XED_CHIP_PENTIUM2          21
#define XED_CHIP_PENTIUM3          22
#define XED_CHIP_PENTIUM4          23
#define XED_CHIP_P4PRESCOTT        24
#define XED_CHIP_P4PRESCOTT_NOLAHF 25
#define XED_CHIP_P4PRESCOTT_VTX    26
#define XED_CHIP_CORE2             27
#define XED_CHIP_PENRYN            28
#define XED_CHIP_PENRYN_E          29
#define XED_CHIP_NEHALEM           30
#define XED_CHIP_WESTMERE          31
#define XED_CHIP_BONNELL           32
#define XED_CHIP_SALTWELL          33
#define XED_CHIP_SILVERMONT        34
#define XED_CHIP_AMD               35
#define XED_CHIP_GOLDMONT          36
#define XED_CHIP_GOLDMONT_PLUS     37
#define XED_CHIP_TREMONT           38
#define XED_CHIP_SANDYBRIDGE       39
#define XED_CHIP_IVYBRIDGE         40
#define XED_CHIP_HASWELL           41
#define XED_CHIP_BROADWELL         42
#define XED_CHIP_SKYLAKE           43
#define XED_CHIP_SKYLAKE_SERVER    44
#define XED_CHIP_CASCADE_LAKE      45
#define XED_CHIP_KNL               46
#define XED_CHIP_KNM               47
#define XED_CHIP_CANNONLAKE        48
#define XED_CHIP_ICELAKE           49
#define XED_CHIP_ICELAKE_SERVER    50
#define XED_CHIP_FUTURE            51
#define XED_CHIP_ALL               52
#define XED_CHIP_LAST              53

#define XED_ISA_SET_INVALID               0
#define XED_ISA_SET_3DNOW                 1
#define XED_ISA_SET_ADOX_ADCX             2
#define XED_ISA_SET_AES                   3
#define XED_ISA_SET_AMD                   4
#define XED_ISA_SET_AVX                   5
#define XED_ISA_SET_AVX2                  6
#define XED_ISA_SET_AVX2GATHER            7
#define XED_ISA_SET_AVX512BW_128          8
#define XED_ISA_SET_AVX512BW_128N         9
#define XED_ISA_SET_AVX512BW_256          10
#define XED_ISA_SET_AVX512BW_512          11
#define XED_ISA_SET_AVX512BW_KOP          12
#define XED_ISA_SET_AVX512CD_128          13
#define XED_ISA_SET_AVX512CD_256          14
#define XED_ISA_SET_AVX512CD_512          15
#define XED_ISA_SET_AVX512DQ_128          16
#define XED_ISA_SET_AVX512DQ_128N         17
#define XED_ISA_SET_AVX512DQ_256          18
#define XED_ISA_SET_AVX512DQ_512          19
#define XED_ISA_SET_AVX512DQ_KOP          20
#define XED_ISA_SET_AVX512DQ_SCALAR       21
#define XED_ISA_SET_AVX512ER_512          22
#define XED_ISA_SET_AVX512ER_SCALAR       23
#define XED_ISA_SET_AVX512F_128           24
#define XED_ISA_SET_AVX512F_128N          25
#define XED_ISA_SET_AVX512F_256           26
#define XED_ISA_SET_AVX512F_512           27
#define XED_ISA_SET_AVX512F_KOP           28
#define XED_ISA_SET_AVX512F_SCALAR        29
#define XED_ISA_SET_AVX512PF_512          30
#define XED_ISA_SET_AVX512_4FMAPS_512     31
#define XED_ISA_SET_AVX512_4FMAPS_SCALAR  32
#define XED_ISA_SET_AVX512_4VNNIW_512     33
#define XED_ISA_SET_AVX512_BITALG_128     34
#define XED_ISA_SET_AVX512_BITALG_256     35
#define XED_ISA_SET_AVX512_BITALG_512     36
#define XED_ISA_SET_AVX512_GFNI_128       37
#define XED_ISA_SET_AVX512_GFNI_256       38
#define XED_ISA_SET_AVX512_GFNI_512       39
#define XED_ISA_SET_AVX512_IFMA_128       40
#define XED_ISA_SET_AVX512_IFMA_256       41
#define XED_ISA_SET_AVX512_IFMA_512       42
#define XED_ISA_SET_AVX512_VAES_128       43
#define XED_ISA_SET_AVX512_VAES_256       44
#define XED_ISA_SET_AVX512_VAES_512       45
#define XED_ISA_SET_AVX512_VBMI2_128      46
#define XED_ISA_SET_AVX512_VBMI2_256      47
#define XED_ISA_SET_AVX512_VBMI2_512      48
#define XED_ISA_SET_AVX512_VBMI_128       49
#define XED_ISA_SET_AVX512_VBMI_256       50
#define XED_ISA_SET_AVX512_VBMI_512       51
#define XED_ISA_SET_AVX512_VNNI_128       52
#define XED_ISA_SET_AVX512_VNNI_256       53
#define XED_ISA_SET_AVX512_VNNI_512       54
#define XED_ISA_SET_AVX512_VPCLMULQDQ_128 55
#define XED_ISA_SET_AVX512_VPCLMULQDQ_256 56
#define XED_ISA_SET_AVX512_VPCLMULQDQ_512 57
#define XED_ISA_SET_AVX512_VPOPCNTDQ_128  58
#define XED_ISA_SET_AVX512_VPOPCNTDQ_256  59
#define XED_ISA_SET_AVX512_VPOPCNTDQ_512  60
#define XED_ISA_SET_AVXAES                61
#define XED_ISA_SET_AVX_GFNI              62
#define XED_ISA_SET_BMI1                  63
#define XED_ISA_SET_BMI2                  64
#define XED_ISA_SET_CET                   65
#define XED_ISA_SET_CLDEMOTE              66
#define XED_ISA_SET_CLFLUSHOPT            67
#define XED_ISA_SET_CLFSH                 68
#define XED_ISA_SET_CLWB                  69
#define XED_ISA_SET_CLZERO                70
#define XED_ISA_SET_CMOV                  71
#define XED_ISA_SET_CMPXCHG16B            72
#define XED_ISA_SET_F16C                  73
#define XED_ISA_SET_FAT_NOP               74
#define XED_ISA_SET_FCMOV                 75
#define XED_ISA_SET_FMA                   76
#define XED_ISA_SET_FMA4                  77
#define XED_ISA_SET_FXSAVE                78
#define XED_ISA_SET_FXSAVE64              79
#define XED_ISA_SET_GFNI                  80
#define XED_ISA_SET_I186                  81
#define XED_ISA_SET_I286PROTECTED         82
#define XED_ISA_SET_I286REAL              83
#define XED_ISA_SET_I386                  84
#define XED_ISA_SET_I486                  85
#define XED_ISA_SET_I486REAL              86
#define XED_ISA_SET_I86                   87
#define XED_ISA_SET_INVPCID               88
#define XED_ISA_SET_LAHF                  89
#define XED_ISA_SET_LONGMODE              90
#define XED_ISA_SET_LZCNT                 91
#define XED_ISA_SET_MONITOR               92
#define XED_ISA_SET_MONITORX              93
#define XED_ISA_SET_MOVBE                 94
#define XED_ISA_SET_MOVDIR                95
#define XED_ISA_SET_MPX                   96
#define XED_ISA_SET_PAUSE                 97
#define XED_ISA_SET_PCLMULQDQ             98
#define XED_ISA_SET_PCONFIG               99
#define XED_ISA_SET_PENTIUMMMX            100
#define XED_ISA_SET_PENTIUMREAL           101
#define XED_ISA_SET_PKU                   102
#define XED_ISA_SET_POPCNT                103
#define XED_ISA_SET_PPRO                  104
#define XED_ISA_SET_PREFETCHW             105
#define XED_ISA_SET_PREFETCHWT1           106
#define XED_ISA_SET_PREFETCH_NOP          107
#define XED_ISA_SET_PT                    108
#define XED_ISA_SET_RDPID                 109
#define XED_ISA_SET_RDPMC                 110
#define XED_ISA_SET_RDRAND                111
#define XED_ISA_SET_RDSEED                112
#define XED_ISA_SET_RDTSCP                113
#define XED_ISA_SET_RDWRFSGS              114
#define XED_ISA_SET_RTM                   115
#define XED_ISA_SET_SGX                   116
#define XED_ISA_SET_SGX_ENCLV             117
#define XED_ISA_SET_SHA                   118
#define XED_ISA_SET_SMAP                  119
#define XED_ISA_SET_SMX                   120
#define XED_ISA_SET_SSE                   121
#define XED_ISA_SET_SSE2                  122
#define XED_ISA_SET_SSE2MMX               123
#define XED_ISA_SET_SSE3                  124
#define XED_ISA_SET_SSE3X87               125
#define XED_ISA_SET_SSE4                  126
#define XED_ISA_SET_SSE42                 127
#define XED_ISA_SET_SSE4A                 128
#define XED_ISA_SET_SSEMXCSR              129
#define XED_ISA_SET_SSE_PREFETCH          130
#define XED_ISA_SET_SSSE3                 131
#define XED_ISA_SET_SSSE3MMX              132
#define XED_ISA_SET_SVM                   133
#define XED_ISA_SET_TBM                   134
#define XED_ISA_SET_VAES                  135
#define XED_ISA_SET_VMFUNC                136
#define XED_ISA_SET_VPCLMULQDQ            137
#define XED_ISA_SET_VTX                   138
#define XED_ISA_SET_WAITPKG               139
#define XED_ISA_SET_WBNOINVD              140
#define XED_ISA_SET_X87                   141
#define XED_ISA_SET_XOP                   142
#define XED_ISA_SET_XSAVE                 143
#define XED_ISA_SET_XSAVEC                144
#define XED_ISA_SET_XSAVEOPT              145
#define XED_ISA_SET_XSAVES                146
#define XED_ISA_SET_LAST                  147

struct XedChipFeatures {
  uint64_t f[3];
};

#define xed_set_chip_modes(d, chip)    \
  do {                                 \
    struct XedDecodedInst *__d = d;    \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
        break;                         \
      case XED_CHIP_I86:               \
      case XED_CHIP_I86FP:             \
      case XED_CHIP_I186:              \
      case XED_CHIP_I186FP:            \
      case XED_CHIP_I286REAL:          \
      case XED_CHIP_I286:              \
      case XED_CHIP_I2186FP:           \
      case XED_CHIP_I386REAL:          \
      case XED_CHIP_I386:              \
      case XED_CHIP_I386FP:            \
      case XED_CHIP_I486REAL:          \
      case XED_CHIP_I486:              \
      case XED_CHIP_QUARK:             \
      case XED_CHIP_PENTIUM:           \
      case XED_CHIP_PENTIUMREAL:       \
      case XED_CHIP_PENTIUMMMX:        \
      case XED_CHIP_PENTIUMMMXREAL:    \
        __d->op.mode_first_prefix = 1; \
        break;                         \
      default:                         \
        break;                         \
    }                                  \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
      case XED_CHIP_ALL:               \
      case XED_CHIP_AMD:               \
        break;                         \
      default:                         \
        __d->op.is_intel_specific = 1; \
        break;                         \
    }                                  \
  } while (0)

extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];

bool xed_test_chip_features(struct XedChipFeatures *, int);
void xed_get_chip_features(struct XedChipFeatures *, int);
bool xed_isa_set_is_valid_for_chip(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/blake2.h */

#define COSMOPOLITAN_LIBC_STR_BLAKE2_H_

#define BLAKE2B256_DIGEST_LENGTH 32
#define BLAKE2B_CBLOCK           128

#define BLAKE2B256_Init    __BLAKE2B256_Init
#define BLAKE2B256_Update  __BLAKE2B256_Update
#define BLAKE2B256_Process __BLAKE2B256_Process
#define BLAKE2B256_Final   __BLAKE2B256_Final
#define BLAKE2B256         __BLAKE2B256

COSMOPOLITAN_C_START_

struct Blake2b {
  uint64_t h[8];
  uint64_t t_low;
  uint64_t t_high;
  union {
    uint8_t bytes[BLAKE2B_CBLOCK];
    uint64_t words[16];
  } block;
  size_t block_used;
};

int BLAKE2B256_Init(struct Blake2b *);
int BLAKE2B256_Update(struct Blake2b *, const void *, size_t);
int BLAKE2B256_Process(struct Blake2b *, const uint64_t[BLAKE2B_CBLOCK / 8]);
int BLAKE2B256_Final(struct Blake2b *, uint8_t[BLAKE2B256_DIGEST_LENGTH]);
int BLAKE2B256(const void *, size_t, uint8_t[BLAKE2B256_DIGEST_LENGTH]);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/highwayhash64.h */

#define COSMOPOLITAN_LIBC_STR_HIGHWAYHASH64_H_
COSMOPOLITAN_C_START_

uint64_t HighwayHash64(const void *, size_t, const uint64_t[4]) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/langinfo.h */

#define COSMOPOLITAN_LIBC_STR_LANGINFO_H_
COSMOPOLITAN_C_START_

#define ABDAY_1 0x20000
#define ABDAY_2 0x20001
#define ABDAY_3 0x20002
#define ABDAY_4 0x20003
#define ABDAY_5 0x20004
#define ABDAY_6 0x20005
#define ABDAY_7 0x20006

#define DAY_1 0x20007
#define DAY_2 0x20008
#define DAY_3 0x20009
#define DAY_4 0x2000A
#define DAY_5 0x2000B
#define DAY_6 0x2000C
#define DAY_7 0x2000D

#define ABMON_1  0x2000E
#define ABMON_2  0x2000F
#define ABMON_3  0x20010
#define ABMON_4  0x20011
#define ABMON_5  0x20012
#define ABMON_6  0x20013
#define ABMON_7  0x20014
#define ABMON_8  0x20015
#define ABMON_9  0x20016
#define ABMON_10 0x20017
#define ABMON_11 0x20018
#define ABMON_12 0x20019

#define MON_1  0x2001A
#define MON_2  0x2001B
#define MON_3  0x2001C
#define MON_4  0x2001D
#define MON_5  0x2001E
#define MON_6  0x2001F
#define MON_7  0x20020
#define MON_8  0x20021
#define MON_9  0x20022
#define MON_10 0x20023
#define MON_11 0x20024
#define MON_12 0x20025

#define AM_STR 0x20026
#define PM_STR 0x20027

#define D_T_FMT    0x20028
#define D_FMT      0x20029
#define T_FMT      0x2002A
#define T_FMT_AMPM 0x2002B

#define ERA         0x2002C
#define ERA_D_FMT   0x2002E
#define ALT_DIGITS  0x2002F
#define ERA_D_T_FMT 0x20030
#define ERA_T_FMT   0x20031

#define CODESET 14

#define CRNCYSTR 0x4000F

#define RADIXCHAR 0x10000
#define THOUSEP   0x10001
#define YESEXPR   0x50000
#define NOEXPR    0x50001

#define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff)

#if defined(_GNU_SOURCE)
#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat)
#endif

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define YESSTR 0x50002
#define NOSTR  0x50003
#endif

char *nl_langinfo(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/locale.h */

#define COSMOPOLITAN_LIBC_STR_LOCALE_H_

#define LC_CTYPE         0
#define LC_NUMERIC       1
#define LC_CTYPE_MASK    1
#define LC_TIME          2
#define LC_NUMERIC_MASK  2
#define LC_COLLATE       3
#define LC_MONETARY      4
#define LC_TIME_MASK     4
#define LC_MESSAGES      5
#define LC_ALL           6
#define LC_COLLATE_MASK  8
#define LC_MONETARY_MASK 16
#define LC_MESSAGES_MASK 32
#define LC_ALL_MASK      0x1fbf
#define LOCALE_NAME_MAX  23

COSMOPOLITAN_C_START_

#define LC_GLOBAL_LOCALE ((locale_t) - 1)

struct __locale_map {
  const void *map;
  size_t map_size;
  char name[LOCALE_NAME_MAX + 1];
  const struct __locale_map *next;
};

struct __locale_struct {
  const struct __locale_map *cat[6];
};

typedef struct __locale_struct *locale_t;

extern const struct __locale_map __c_dot_utf8;
extern const struct __locale_struct __c_locale;
extern const struct __locale_struct __c_dot_utf8_locale;

char *nl_langinfo_l(int, locale_t) libcesque;
char *setlocale(int, const char *) libcesque;
double strtod_l(const char *, char **, locale_t) libcesque;
double wcstod_l(const wchar_t *, wchar_t **, locale_t) libcesque;
float strtof_l(const char *, char **, locale_t) libcesque;
float wcstof_l(const wchar_t *, wchar_t **, locale_t) libcesque;
int isdigit_l(int, locale_t) libcesque;
int islower_l(int, locale_t) libcesque;
int isupper_l(int, locale_t) libcesque;
int iswalpha_l(wint_t, locale_t) libcesque;
int iswblank_l(wint_t, locale_t) libcesque;
int iswcntrl_l(wint_t, locale_t) libcesque;
int iswdigit_l(wint_t, locale_t) libcesque;
int iswlower_l(wint_t, locale_t) libcesque;
int iswprint_l(wint_t, locale_t) libcesque;
int iswpunct_l(wint_t, locale_t) libcesque;
int iswspace_l(wint_t, locale_t) libcesque;
int iswupper_l(wint_t, locale_t) libcesque;
int iswxdigit_l(wint_t, locale_t) libcesque;
int isxdigit_l(int, locale_t) libcesque;
int strcoll_l(const char *, const char *, locale_t) libcesque;
int tolower_l(int, locale_t) libcesque;
int toupper_l(int, locale_t) libcesque;
int wcscoll_l(const wchar_t *, const wchar_t *, locale_t) libcesque;
locale_t duplocale(locale_t) libcesque;
locale_t newlocale(int, const char *, locale_t) libcesque;
locale_t uselocale(locale_t) libcesque;
long double strtold_l(const char *, char **, locale_t) libcesque;
long double wcstold_l(const wchar_t *, wchar_t **, locale_t) libcesque;
long long strtoll_l(const char *, char **, int, locale_t) libcesque;
long long wcstoll_l(const wchar_t *, wchar_t **, int, locale_t) libcesque;
size_t strftime_l(char *, size_t, char const *, struct tm const *, locale_t);
size_t strxfrm_l(char *, const char *, size_t, locale_t) libcesque;
size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t) libcesque;
unsigned long long strtoull_l(const char *, char **, int, locale_t) libcesque;
unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t);
void freelocale(locale_t) libcesque;
wint_t towlower_l(wint_t, locale_t) libcesque;
wint_t towupper_l(wint_t, locale_t) libcesque;
int strcasecmp_l(const char *, const char *, locale_t) libcesque;
int strncasecmp_l(const char *, const char *, size_t, locale_t) libcesque;
ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/nltypes.h */

#define COSMOPOLITAN_LIBC_STR_NLTYPES_H_

#define NL_SETD       1
#define NL_CAT_LOCALE 1

COSMOPOLITAN_C_START_

typedef int nl_item;
typedef void *nl_catd;

nl_catd catopen(const char *, int);
char *catgets(nl_catd, int, int, const char *);
int catclose(nl_catd);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/slice.h */

#define COSMOPOLITAN_LIBC_STR_SLICE_H_
COSMOPOLITAN_C_START_

#define SlicesEqual(a, n, b, m)       \
  ({                                  \
    size_t __n = (n);                 \
    __n == (m) && !memcmp(a, b, __n); \
  })

#define SlicesEqualCase(a, n, b, m)       \
  ({                                      \
    size_t __n = (n);                     \
    __n == (m) && !memcasecmp(a, b, __n); \
  })

int CompareSlices(const char *, size_t, const char *, size_t) libcesque;
int CompareSlicesCase(const char *, size_t, const char *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/strwidth.h */

#define COSMOPOLITAN_LIBC_STR_STRWIDTH_H_
COSMOPOLITAN_C_START_

int strwidth(const char *, size_t) strlenesque;
int strnwidth(const char *, size_t, size_t) strlenesque;
int strwidth16(const char16_t *, size_t) strlenesque;
int strnwidth16(const char16_t *, size_t, size_t) strlenesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/thompike.h */

#define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_

#define ThomPikeCont(x)     (0200 == (0300 & (x)))
#define ThomPikeByte(x)     ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
#define ThomPikeLen(x)      (7 - ThomPikeMsb(x))
#define ThomPikeMsb(x)      ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1)
#define ThomPikeMerge(x, y) ((x) << 6 | (077 & (y)))



/*!BEGIN libc/str/unicode.h */

#define COSMOPOLITAN_LIBC_STR_UNICODE_H_
COSMOPOLITAN_C_START_

struct lconv {
  char *decimal_point;
  char *thousands_sep;
  char *grouping;
  char *int_curr_symbol;
  char *currency_symbol;
  char *mon_decimal_point;
  char *mon_thousands_sep;
  char *mon_grouping;
  char *positive_sign;
  char *negative_sign;
  char int_frac_digits;
  char frac_digits;
  char p_cs_precedes;
  char p_sep_by_space;
  char n_cs_precedes;
  char n_sep_by_space;
  char p_sign_posn;
  char n_sign_posn;
  char int_p_cs_precedes;
  char int_n_cs_precedes;
  char int_p_sep_by_space;
  char int_n_sep_by_space;
  char int_p_sign_posn;
  char int_n_sign_posn;
};

pureconst int wcwidth(wchar_t) libcesque;
int wcswidth(const wchar_t *, size_t) strlenesque;
struct lconv *localeconv(void) libcesque;

#ifdef _COSMO_SOURCE
int wcsnwidth(const wchar_t *, size_t, size_t) strlenesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/utf16.h */

#define COSMOPOLITAN_LIBC_STR_UTF16_H_

#define UTF16_MASK 0xfc00
#define UTF16_MOAR 0xd800 /* 0xD800..0xDBFF */
#define UTF16_CONT 0xdc00 /* 0xDC00..0xDFFF */

COSMOPOLITAN_C_START_

#define IsSurrogate(wc)     ((0xf800 & (wc)) == 0xd800)
#define IsHighSurrogate(wc) ((UTF16_MASK & (wc)) == UTF16_MOAR)
#define IsLowSurrogate(wc)  ((UTF16_MASK & (wc)) == UTF16_CONT)
#define IsUcs2(wc)          (((65535 & (wc)) >> 11) != 27)
#define IsUtf16Cont(wc)     IsLowSurrogate(wc) /* TODO: DELETE */
#define MergeUtf16(hi, lo)  ((((hi)-0xD800) << 10) + ((lo)-0xDC00) + 0x10000)
#define EncodeUtf16(wc)                                       \
  (LIKELY((0x0000 <= (wc) && (wc) <= 0xFFFF) ||               \
          (0xE000 <= (wc) && (wc) <= 0xFFFF))                 \
       ? (wc)                                                 \
   : 0x10000 <= (wc) && (wc) <= 0x10FFFF                      \
       ? (((((wc)-0x10000) >> 10) + 0xD800) |                 \
          (unsigned)((((wc)-0x10000) & 1023) + 0xDC00) << 16) \
       : 0xFFFD)

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/errfuns.h */

#define COSMOPOLITAN_LIBC_SYSV_ERRFUNS_H_

/**
 * @fileoverview Optimized error return paths.
 *
 * Saying this:
 *
 *     return einval();
 *
 * Instead of this:
 *
 *     errno = EINVAL;
 *     return -1;
 *
 * Allows the compiler to generate 11 fewer bytes of code each time.
 *
 * @return always -1
 * @see libc/sysv/errfuns.inc (for implementation)
 */

libcesque intptr_t einval(void) relegated;
libcesque intptr_t eperm(void) relegated;
libcesque intptr_t enoent(void) relegated;
libcesque intptr_t esrch(void) relegated;
libcesque intptr_t eintr(void) relegated;
libcesque intptr_t eio(void) relegated;
libcesque intptr_t enxio(void) relegated;
libcesque intptr_t e2big(void) relegated;
libcesque intptr_t enoexec(void) relegated;
libcesque intptr_t ebadf(void) relegated;
libcesque intptr_t echild(void) relegated;
libcesque intptr_t eagain(void) relegated;
libcesque intptr_t enomem(void) relegated;
libcesque intptr_t eacces(void) relegated;
libcesque intptr_t efault(void) relegated;
libcesque intptr_t enotblk(void) relegated;
libcesque intptr_t ebusy(void) relegated;
libcesque intptr_t eexist(void) relegated;
libcesque intptr_t exdev(void) relegated;
libcesque intptr_t enodev(void) relegated;
libcesque intptr_t enotdir(void) relegated;
libcesque intptr_t eisdir(void) relegated;
libcesque intptr_t enfile(void) relegated;
libcesque intptr_t emfile(void) relegated;
libcesque intptr_t enotty(void) relegated;
libcesque intptr_t enotsup(void) relegated;
libcesque intptr_t etxtbsy(void) relegated;
libcesque intptr_t efbig(void) relegated;
libcesque intptr_t enospc(void) relegated;
libcesque intptr_t espipe(void) relegated;
libcesque intptr_t erofs(void) relegated;
libcesque intptr_t emlink(void) relegated;
libcesque intptr_t epipe(void) relegated;
libcesque intptr_t edom(void) relegated;
libcesque intptr_t erange(void) relegated;
libcesque intptr_t edeadlk(void) relegated;
libcesque intptr_t enametoolong(void) relegated;
libcesque intptr_t enolck(void) relegated;
libcesque intptr_t enosys(void) relegated;
libcesque intptr_t enotempty(void) relegated;
libcesque intptr_t eloop(void) relegated;
libcesque intptr_t enomsg(void) relegated;
libcesque intptr_t eidrm(void) relegated;
libcesque intptr_t echrng(void) relegated;
libcesque intptr_t el2nsync(void) relegated;
libcesque intptr_t el3hlt(void) relegated;
libcesque intptr_t el3rst(void) relegated;
libcesque intptr_t elnrng(void) relegated;
libcesque intptr_t eunatch(void) relegated;
libcesque intptr_t enocsi(void) relegated;
libcesque intptr_t el2hlt(void) relegated;
libcesque intptr_t ebade(void) relegated;
libcesque intptr_t ebadr(void) relegated;
libcesque intptr_t exfull(void) relegated;
libcesque intptr_t enoano(void) relegated;
libcesque intptr_t ebadrqc(void) relegated;
libcesque intptr_t ebadslt(void) relegated;
libcesque intptr_t enostr(void) relegated;
libcesque intptr_t enodata(void) relegated;
libcesque intptr_t etime(void) relegated;
libcesque intptr_t enosr(void) relegated;
libcesque intptr_t enonet(void) relegated;
libcesque intptr_t enopkg(void) relegated;
libcesque intptr_t eremote(void) relegated;
libcesque intptr_t enolink(void) relegated;
libcesque intptr_t eadv(void) relegated;
libcesque intptr_t esrmnt(void) relegated;
libcesque intptr_t ecomm(void) relegated;
libcesque intptr_t eproto(void) relegated;
libcesque intptr_t emultihop(void) relegated;
libcesque intptr_t edotdot(void) relegated;
libcesque intptr_t ebadmsg(void) relegated;
libcesque intptr_t eoverflow(void) relegated;
libcesque intptr_t enotuniq(void) relegated;
libcesque intptr_t ebadfd(void) relegated;
libcesque intptr_t eremchg(void) relegated;
libcesque intptr_t elibacc(void) relegated;
libcesque intptr_t elibbad(void) relegated;
libcesque intptr_t elibscn(void) relegated;
libcesque intptr_t elibmax(void) relegated;
libcesque intptr_t elibexec(void) relegated;
libcesque intptr_t eilseq(void) relegated;
libcesque intptr_t erestart(void) relegated;
libcesque intptr_t estrpipe(void) relegated;
libcesque intptr_t eusers(void) relegated;
libcesque intptr_t enotsock(void) relegated;
libcesque intptr_t edestaddrreq(void) relegated;
libcesque intptr_t emsgsize(void) relegated;
libcesque intptr_t eprototype(void) relegated;
libcesque intptr_t enoprotoopt(void) relegated;
libcesque intptr_t eprotonosupport(void) relegated;
libcesque intptr_t esocktnosupport(void) relegated;
libcesque intptr_t eopnotsupp(void) relegated;
libcesque intptr_t epfnosupport(void) relegated;
libcesque intptr_t eafnosupport(void) relegated;
libcesque intptr_t eaddrinuse(void) relegated;
libcesque intptr_t eaddrnotavail(void) relegated;
libcesque intptr_t enetdown(void) relegated;
libcesque intptr_t enetunreach(void) relegated;
libcesque intptr_t enetreset(void) relegated;
libcesque intptr_t econnaborted(void) relegated;
libcesque intptr_t econnreset(void) relegated;
libcesque intptr_t enobufs(void) relegated;
libcesque intptr_t eisconn(void) relegated;
libcesque intptr_t enotconn(void) relegated;
libcesque intptr_t eshutdown(void) relegated;
libcesque intptr_t etoomanyrefs(void) relegated;
libcesque intptr_t etimedout(void) relegated;
libcesque intptr_t econnrefused(void) relegated;
libcesque intptr_t ehostdown(void) relegated;
libcesque intptr_t ehostunreach(void) relegated;
libcesque intptr_t ealready(void) relegated;
libcesque intptr_t einprogress(void) relegated;
libcesque intptr_t estale(void) relegated;
libcesque intptr_t euclean(void) relegated;
libcesque intptr_t enotnam(void) relegated;
libcesque intptr_t enavail(void) relegated;
libcesque intptr_t eisnam(void) relegated;
libcesque intptr_t eremoteio(void) relegated;
libcesque intptr_t edquot(void) relegated;
libcesque intptr_t enomedium(void) relegated;
libcesque intptr_t emediumtype(void) relegated;
libcesque intptr_t ecanceled(void) relegated;
libcesque intptr_t enokey(void) relegated;
libcesque intptr_t ekeyexpired(void) relegated;
libcesque intptr_t ekeyrevoked(void) relegated;
libcesque intptr_t ekeyrejected(void) relegated;
libcesque intptr_t eownerdead(void) relegated;
libcesque intptr_t enotrecoverable(void) relegated;
libcesque intptr_t erfkill(void) relegated;
libcesque intptr_t ehwpoison(void) relegated;

#if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __ERRFUN(FUNC)               \
  ({                                 \
    intptr_t NegOne;                 \
    asm volatile("call\t" FUNC       \
                 : "=a"(NegOne)      \
                 : /* no outputs */  \
                 : "rcx", "memory"); \
    NegOne;                          \
  })
#define einval()          __ERRFUN("einval")
#define eperm()           __ERRFUN("eperm")
#define enoent()          __ERRFUN("enoent")
#define esrch()           __ERRFUN("esrch")
#define eintr()           __ERRFUN("eintr")
#define eio()             __ERRFUN("eio")
#define enxio()           __ERRFUN("enxio")
#define e2big()           __ERRFUN("e2big")
#define enoexec()         __ERRFUN("enoexec")
#define ebadf()           __ERRFUN("ebadf")
#define echild()          __ERRFUN("echild")
#define eagain()          __ERRFUN("eagain")
#define enomem()          __ERRFUN("enomem")
#define eacces()          __ERRFUN("eacces")
#define efault()          __ERRFUN("efault")
#define enotblk()         __ERRFUN("enotblk")
#define ebusy()           __ERRFUN("ebusy")
#define eexist()          __ERRFUN("eexist")
#define exdev()           __ERRFUN("exdev")
#define enodev()          __ERRFUN("enodev")
#define enotdir()         __ERRFUN("enotdir")
#define eisdir()          __ERRFUN("eisdir")
#define enfile()          __ERRFUN("enfile")
#define emfile()          __ERRFUN("emfile")
#define enotty()          __ERRFUN("enotty")
#define enotsup()         __ERRFUN("enotsup")
#define etxtbsy()         __ERRFUN("etxtbsy")
#define efbig()           __ERRFUN("efbig")
#define enospc()          __ERRFUN("enospc")
#define espipe()          __ERRFUN("espipe")
#define erofs()           __ERRFUN("erofs")
#define emlink()          __ERRFUN("emlink")
#define epipe()           __ERRFUN("epipe")
#define edom()            __ERRFUN("edom")
#define erange()          __ERRFUN("erange")
#define edeadlk()         __ERRFUN("edeadlk")
#define enametoolong()    __ERRFUN("enametoolong")
#define enolck()          __ERRFUN("enolck")
#define enosys()          __ERRFUN("enosys")
#define enotempty()       __ERRFUN("enotempty")
#define eloop()           __ERRFUN("eloop")
#define enomsg()          __ERRFUN("enomsg")
#define eidrm()           __ERRFUN("eidrm")
#define echrng()          __ERRFUN("echrng")
#define el2nsync()        __ERRFUN("el2nsync")
#define el3hlt()          __ERRFUN("el3hlt")
#define el3rst()          __ERRFUN("el3rst")
#define elnrng()          __ERRFUN("elnrng")
#define eunatch()         __ERRFUN("eunatch")
#define enocsi()          __ERRFUN("enocsi")
#define el2hlt()          __ERRFUN("el2hlt")
#define ebade()           __ERRFUN("ebade")
#define ebadr()           __ERRFUN("ebadr")
#define exfull()          __ERRFUN("exfull")
#define enoano()          __ERRFUN("enoano")
#define ebadrqc()         __ERRFUN("ebadrqc")
#define ebadslt()         __ERRFUN("ebadslt")
#define enostr()          __ERRFUN("enostr")
#define enodata()         __ERRFUN("enodata")
#define etime()           __ERRFUN("etime")
#define enosr()           __ERRFUN("enosr")
#define enonet()          __ERRFUN("enonet")
#define enopkg()          __ERRFUN("enopkg")
#define eremote()         __ERRFUN("eremote")
#define enolink()         __ERRFUN("enolink")
#define eadv()            __ERRFUN("eadv")
#define esrmnt()          __ERRFUN("esrmnt")
#define ecomm()           __ERRFUN("ecomm")
#define eproto()          __ERRFUN("eproto")
#define emultihop()       __ERRFUN("emultihop")
#define edotdot()         __ERRFUN("edotdot")
#define ebadmsg()         __ERRFUN("ebadmsg")
#define eoverflow()       __ERRFUN("eoverflow")
#define enotuniq()        __ERRFUN("enotuniq")
#define ebadfd()          __ERRFUN("ebadfd")
#define eremchg()         __ERRFUN("eremchg")
#define elibacc()         __ERRFUN("elibacc")
#define elibbad()         __ERRFUN("elibbad")
#define elibscn()         __ERRFUN("elibscn")
#define elibmax()         __ERRFUN("elibmax")
#define elibexec()        __ERRFUN("elibexec")
#define eilseq()          __ERRFUN("eilseq")
#define erestart()        __ERRFUN("erestart")
#define estrpipe()        __ERRFUN("estrpipe")
#define eusers()          __ERRFUN("eusers")
#define enotsock()        __ERRFUN("enotsock")
#define edestaddrreq()    __ERRFUN("edestaddrreq")
#define emsgsize()        __ERRFUN("emsgsize")
#define eprototype()      __ERRFUN("eprototype")
#define enoprotoopt()     __ERRFUN("enoprotoopt")
#define eprotonosupport() __ERRFUN("eprotonosupport")
#define esocktnosupport() __ERRFUN("esocktnosupport")
#define eopnotsupp()      __ERRFUN("eopnotsupp")
#define epfnosupport()    __ERRFUN("epfnosupport")
#define eafnosupport()    __ERRFUN("eafnosupport")
#define eaddrinuse()      __ERRFUN("eaddrinuse")
#define eaddrnotavail()   __ERRFUN("eaddrnotavail")
#define enetdown()        __ERRFUN("enetdown")
#define enetunreach()     __ERRFUN("enetunreach")
#define enetreset()       __ERRFUN("enetreset")
#define econnaborted()    __ERRFUN("econnaborted")
#define econnreset()      __ERRFUN("econnreset")
#define enobufs()         __ERRFUN("enobufs")
#define eisconn()         __ERRFUN("eisconn")
#define enotconn()        __ERRFUN("enotconn")
#define eshutdown()       __ERRFUN("eshutdown")
#define etoomanyrefs()    __ERRFUN("etoomanyrefs")
#define etimedout()       __ERRFUN("etimedout")
#define econnrefused()    __ERRFUN("econnrefused")
#define ehostdown()       __ERRFUN("ehostdown")
#define ehostunreach()    __ERRFUN("ehostunreach")
#define ealready()        __ERRFUN("ealready")
#define einprogress()     __ERRFUN("einprogress")
#define estale()          __ERRFUN("estale")
#define euclean()         __ERRFUN("euclean")
#define enotnam()         __ERRFUN("enotnam")
#define enavail()         __ERRFUN("enavail")
#define eisnam()          __ERRFUN("eisnam")
#define eremoteio()       __ERRFUN("eremoteio")
#define edquot()          __ERRFUN("edquot")
#define enomedium()       __ERRFUN("enomedium")
#define emediumtype()     __ERRFUN("emediumtype")
#define ecanceled()       __ERRFUN("ecanceled")
#define enokey()          __ERRFUN("enokey")
#define ekeyexpired()     __ERRFUN("ekeyexpired")
#define ekeyrevoked()     __ERRFUN("ekeyrevoked")
#define ekeyrejected()    __ERRFUN("ekeyrejected")
#define eownerdead()      __ERRFUN("eownerdead")
#define enotrecoverable() __ERRFUN("enotrecoverable")
#define erfkill()         __ERRFUN("erfkill")
#define ehwpoison()       __ERRFUN("ehwpoison")
#endif



/*!BEGIN libc/sysv/consts/_posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS__POSIX_H_

/* The Open Group Base Specifications Issue 7, 2018 edition */
/* IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)  */

#define _POSIX_AIO_LISTIO_MAX               2
#define _POSIX_CLOCKRES_MIN                 20000000
#define _POSIX_AIO_MAX                      1
#define _POSIX_ARG_MAX                      4096
#define _POSIX_CHILD_MAX                    25
#define _POSIX_DELAYTIMER_MAX               32
#define _POSIX_HOST_NAME_MAX                255
#define _POSIX_LINK_MAX                     8
#define _POSIX_LOGIN_NAME_MAX               9
#define _POSIX_MAX_CANON                    255
#define _POSIX_MAX_INPUT                    255
#define _POSIX_MQ_OPEN_MAX                  8
#define _POSIX_MQ_PRIO_MAX                  32
#define _POSIX_NAME_MAX                     14
#define _POSIX_NGROUPS_MAX                  8
#define _POSIX_OPEN_MAX                     20
#define _POSIX_PATH_MAX                     256
#define _POSIX_PIPE_BUF                     512
#define _POSIX_RE_DUP_MAX                   255
#define _POSIX_RTSIG_MAX                    8
#define _POSIX_SEM_NSEMS_MAX                256
#define _POSIX_SEM_VALUE_MAX                32767
#define _POSIX_SIGQUEUE_MAX                 32
#define _POSIX_SSIZE_MAX                    32767
#define _POSIX_SS_REPL_MAX                  4
#define _POSIX_STREAM_MAX                   8
#define _POSIX_SYMLINK_MAX                  255
#define _POSIX_SYMLOOP_MAX                  8
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
#define _POSIX_THREAD_KEYS_MAX              128
#define _POSIX_THREAD_THREADS_MAX           64
#define _POSIX_TIMER_MAX                    32
#define _POSIX_TRACE_EVENT_NAME_MAX         30
#define _POSIX_TRACE_NAME_MAX               8
#define _POSIX_TRACE_SYS_MAX                8
#define _POSIX_TRACE_USER_EVENT_MAX         32
#define _POSIX_TTY_NAME_MAX                 9
#define _POSIX_TZNAME_MAX                   6

#define _POSIX2_BC_BASE_MAX        99
#define _POSIX2_BC_DIM_MAX         2048
#define _POSIX2_BC_SCALE_MAX       99
#define _POSIX2_BC_STRING_MAX      1000
#define _POSIX2_CHARCLASS_NAME_MAX 14
#define _POSIX2_COLL_WEIGHTS_MAX   2
#define _POSIX2_EXPR_NEST_MAX      32
#define _POSIX2_LINE_MAX           2048
#define _POSIX2_RE_DUP_MAX         255



/*!BEGIN libc/sysv/consts/af.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AF_H_
COSMOPOLITAN_C_START_

extern const int AF_ALG;
extern const int AF_APPLETALK;
extern const int AF_ASH;
extern const int AF_ATMPVC;
extern const int AF_ATMSVC;
extern const int AF_AX25;
extern const int AF_BLUETOOTH;
extern const int AF_BRIDGE;
extern const int AF_CAIF;
extern const int AF_CAN;
extern const int AF_ECONET;
extern const int AF_FILE;
extern const int AF_IB;
extern const int AF_IEEE802154;
extern const int AF_INET6;
extern const int AF_INET;
extern const int AF_IPX;
extern const int AF_IRDA;
extern const int AF_ISDN;
extern const int AF_IUCV;
extern const int AF_KCM;
extern const int AF_KEY;
extern const int AF_LINK;
extern const int AF_LLC;
extern const int AF_LOCAL;
extern const int AF_MAX;
extern const int AF_MPLS;
extern const int AF_NETBEUI;
extern const int AF_NETLINK;
extern const int AF_NETROM;
extern const int AF_NFC;
extern const int AF_PACKET;
extern const int AF_PHONET;
extern const int AF_PPPOX;
extern const int AF_ROSE;
extern const int AF_ROUTE;
extern const int AF_RXRPC;
extern const int AF_SECURITY;
extern const int AF_SNA;
extern const int AF_TIPC;
extern const int AF_UNIX;
extern const int AF_UNSPEC;
extern const int AF_VSOCK;
extern const int AF_WANPIPE;
extern const int AF_X25;

#define AF_ALG        AF_ALG
#define AF_LINK       AF_LINK
#define AF_APPLETALK  AF_APPLETALK
#define AF_ASH        AF_ASH
#define AF_ATMPVC     AF_ATMPVC
#define AF_ATMSVC     AF_ATMSVC
#define AF_AX25       AF_AX25
#define AF_BLUETOOTH  AF_BLUETOOTH
#define AF_BRIDGE     AF_BRIDGE
#define AF_CAIF       AF_CAIF
#define AF_CAN        AF_CAN
#define AF_ECONET     AF_ECONET
#define AF_FILE       AF_FILE
#define AF_IB         AF_IB
#define AF_IEEE802154 AF_IEEE802154
#define AF_INET       2
#define AF_INET6      AF_INET6
#define AF_IPX        AF_IPX
#define AF_IRDA       AF_IRDA
#define AF_ISDN       AF_ISDN
#define AF_IUCV       AF_IUCV
#define AF_KCM        AF_KCM
#define AF_KEY        AF_KEY
#define AF_LLC        AF_LLC
#define AF_LOCAL      AF_LOCAL
#define AF_MAX        AF_MAX
#define AF_MPLS       AF_MPLS
#define AF_NETBEUI    AF_NETBEUI
#define AF_NETLINK    AF_NETLINK
#define AF_NETROM     AF_NETROM
#define AF_NFC        AF_NFC
#define AF_PACKET     AF_PACKET
#define AF_PHONET     AF_PHONET
#define AF_PPPOX      AF_PPPOX
#define AF_ROSE       AF_ROSE
#define AF_ROUTE      AF_ROUTE
#define AF_RXRPC      AF_RXRPC
#define AF_SECURITY   AF_SECURITY
#define AF_SNA        AF_SNA
#define AF_TIPC       AF_TIPC
#define AF_UNIX       1
#define AF_UNSPEC     0
#define AF_VSOCK      AF_VSOCK
#define AF_WANPIPE    AF_WANPIPE
#define AF_X25        AF_X25

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/arch.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARCH_H_

#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004



/*!BEGIN libc/sysv/consts/arp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARP_H_

#define ARPHRD_ETHER 1



/*!BEGIN libc/sysv/consts/at.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AT_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview AT_xxx constants for fcntl(), fopenat(), etc..
 * @see libc/sysv/consts/auxv.h for getauxval() constants
 */

extern const int AT_FDCWD;
extern const int AT_SYMLINK_FOLLOW;
extern const int AT_SYMLINK_NOFOLLOW;
extern const int AT_REMOVEDIR;
extern const int AT_EACCESS;
extern const int AT_EMPTY_PATH;

COSMOPOLITAN_C_END_

#define AT_FDCWD            AT_FDCWD
#define AT_SYMLINK_FOLLOW   AT_SYMLINK_FOLLOW
#define AT_SYMLINK_NOFOLLOW AT_SYMLINK_NOFOLLOW
#define AT_REMOVEDIR        AT_REMOVEDIR
#define AT_EACCESS          AT_EACCESS



/*!BEGIN libc/sysv/consts/audit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AUDIT_H_

#define __AUDIT_ARCH_64BIT                 0x80000000
#define __AUDIT_ARCH_LE                    0x40000000
#define __AUDIT_ARCH_CONVENTION_MASK       0x30000000
#define __AUDIT_ARCH_CONVENTION_MIPS64_N32 0x20000000

#define AUDIT_ARCH_X86_64  (EM_X86_64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_I386    (EM_386 | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_AARCH64 (EM_AARCH64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_PPC64LE (EM_PPC64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_RISCV64 (EM_RISCV | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_S390X   (EM_S390 | __AUDIT_ARCH_64BIT)



/*!BEGIN libc/sysv/consts/auxv.h */

#define COSMOPOLITAN_LIBC_CALLS_AUXV_H_

/*
 * integral getauxval() keys
 */
#define AT_PHDR                     3
#define AT_PHENT                    4
#define AT_PHNUM                    5
#define AT_PAGESZ                   6
#define AT_BASE                     7
#define AT_FLAGS                    8
#define AT_FLAGS_PRESERVE_ARGV0_BIT 0
#define AT_FLAGS_PRESERVE_ARGV0     (1 << AT_FLAGS_PRESERVE_ARGV0_BIT)
#define AT_ENTRY                    9

COSMOPOLITAN_C_START_

/*
 * portable getauxval() keys
 */
extern const unsigned long AT_EXECFN;
extern const unsigned long AT_SECURE;
extern const unsigned long AT_RANDOM;
extern const unsigned long AT_HWCAP;
extern const unsigned long AT_HWCAP2;
extern const unsigned long AT_UID;
extern const unsigned long AT_EUID;
extern const unsigned long AT_GID;
extern const unsigned long AT_EGID;
#define AT_EXECFN AT_EXECFN
#define AT_SECURE AT_SECURE
#define AT_RANDOM AT_RANDOM
#define AT_HWCAP  AT_HWCAP
#define AT_HWCAP2 AT_HWCAP2
#define AT_UID    AT_UID
#define AT_EUID   AT_EUID
#define AT_GID    AT_GID
#define AT_EGID   AT_EGID

/*
 * platform-specific getauxval() keys
 */
extern const unsigned long AT_BASE_PLATFORM;
extern const unsigned long AT_CANARY;
extern const unsigned long AT_CANARYLEN;
extern const unsigned long AT_CLKTCK;
extern const unsigned long AT_DCACHEBSIZE;
extern const unsigned long AT_EHDRFLAGS;
extern const unsigned long AT_EXECFD;
extern const unsigned long AT_EXECPATH;
extern const unsigned long AT_ICACHEBSIZE;
extern const unsigned long AT_MINSIGSTKSZ;
extern const unsigned long AT_NCPUS;
extern const unsigned long AT_NOTELF;
extern const unsigned long AT_NO_AUTOMOUNT;
extern const unsigned long AT_OSRELDATE;
extern const unsigned long AT_PAGESIZES;
extern const unsigned long AT_PAGESIZESLEN;
extern const unsigned long AT_PLATFORM;
extern const unsigned long AT_STACKBASE;
extern const unsigned long AT_STACKPROT;
extern const unsigned long AT_SYSINFO_EHDR;
extern const unsigned long AT_TIMEKEEP;
extern const unsigned long AT_UCACHEBSIZE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/c.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CPIO_H_

#define MAGIC "070707"

#define C_IRUSR 000400
#define C_IWUSR 000200
#define C_IXUSR 000100
#define C_IRGRP 000040
#define C_IWGRP 000020
#define C_IXGRP 000010
#define C_IROTH 000004
#define C_IWOTH 000002
#define C_IXOTH 000001

#define C_ISUID 004000
#define C_ISGID 002000
#define C_ISVTX 001000

#define C_ISBLK  060000
#define C_ISCHR  020000
#define C_ISDIR  040000
#define C_ISFIFO 010000
#define C_ISSOCK 0140000
#define C_ISLNK  0120000
#define C_ISCTG  0110000
#define C_ISREG  0100000



/*!BEGIN libc/sysv/consts/cap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CAP_H_

#define CAP_CHOWN              0
#define CAP_DAC_OVERRIDE       1
#define CAP_DAC_READ_SEARCH    2
#define CAP_FOWNER             3
#define CAP_FSETID             4
#define CAP_KILL               5
#define CAP_SETGID             6
#define CAP_SETUID             7
#define CAP_SETPCAP            8
#define CAP_LINUX_IMMUTABLE    9
#define CAP_NET_BIND_SERVICE   10
#define CAP_NET_BROADCAST      11
#define CAP_NET_ADMIN          12
#define CAP_NET_RAW            13
#define CAP_IPC_LOCK           14
#define CAP_IPC_OWNER          15
#define CAP_SYS_MODULE         16
#define CAP_SYS_RAWIO          17
#define CAP_SYS_CHROOT         18
#define CAP_SYS_PTRACE         19
#define CAP_SYS_PACCT          20
#define CAP_SYS_ADMIN          21
#define CAP_SYS_BOOT           22
#define CAP_SYS_NICE           23
#define CAP_SYS_RESOURCE       24
#define CAP_SYS_TIME           25
#define CAP_SYS_TTY_CONFIG     26
#define CAP_MKNOD              27
#define CAP_LEASE              28
#define CAP_AUDIT_WRITE        29
#define CAP_AUDIT_CONTROL      30
#define CAP_SETFCAP            31
#define CAP_MAC_OVERRIDE       32
#define CAP_MAC_ADMIN          33
#define CAP_SYSLOG             34
#define CAP_WAKE_ALARM         35
#define CAP_BLOCK_SUSPEND      36
#define CAP_AUDIT_READ         37
#define CAP_PERFMON            38
#define CAP_BPF                39
#define CAP_CHECKPOINT_RESTORE 40
#define CAP_LAST_CAP           CAP_CHECKPOINT_RESTORE



/*!BEGIN libc/sysv/consts/clock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOCK_H_
COSMOPOLITAN_C_START_

extern const int CLOCK_BOOTTIME;
extern const int CLOCK_BOOTTIME_ALARM;
extern const int CLOCK_MONOTONIC;
extern const int CLOCK_MONOTONIC_COARSE;
extern const int CLOCK_MONOTONIC_FAST;
extern const int CLOCK_MONOTONIC_PRECISE;
extern const int CLOCK_MONOTONIC_RAW;
extern const int CLOCK_PROCESS_CPUTIME_ID;
extern const int CLOCK_PROF;
extern const int CLOCK_REALTIME_ALARM;
extern const int CLOCK_REALTIME_COARSE;
extern const int CLOCK_REALTIME_FAST;
extern const int CLOCK_REALTIME_PRECISE;
extern const int CLOCK_SECOND;
extern const int CLOCK_TAI;
extern const int CLOCK_THREAD_CPUTIME_ID;
extern const int CLOCK_UPTIME;
extern const int CLOCK_UPTIME_FAST;
extern const int CLOCK_UPTIME_PRECISE;

COSMOPOLITAN_C_END_

#define CLOCK_REALTIME  0
#define CLOCK_MONOTONIC CLOCK_MONOTONIC



/*!BEGIN libc/sysv/consts/clone.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLONE_H_
#ifdef _COSMO_SOURCE

#define CSIGNAL              0x000000ff
#define CLONE_VM             0x00000100
#define CLONE_FS             0x00000200
#define CLONE_FILES          0x00000400
#define CLONE_SIGHAND        0x00000800
#define CLONE_PIDFD          0x00001000
#define CLONE_PTRACE         0x00002000
#define CLONE_VFORK          0x00004000
#define CLONE_PARENT         0x00008000
#define CLONE_THREAD         0x00010000
#define CLONE_NEWNS          0x00020000
#define CLONE_SYSVSEM        0x00040000
#define CLONE_SETTLS         0x00080000
#define CLONE_PARENT_SETTID  0x00100000
#define CLONE_CHILD_CLEARTID 0x00200000
#define CLONE_DETACHED       0x00400000
#define CLONE_UNTRACED       0x00800000
#define CLONE_CHILD_SETTID   0x01000000
#define CLONE_NEWCGROUP      0x02000000
#define CLONE_NEWUTS         0x04000000
#define CLONE_NEWIPC         0x08000000
#define CLONE_NEWUSER        0x10000000
#define CLONE_NEWPID         0x20000000
#define CLONE_NEWNET         0x40000000
#define CLONE_IO             0x80000000

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/close.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOSE_H_
COSMOPOLITAN_C_START_

extern const unsigned int CLOSE_RANGE_UNSHARE;
extern const unsigned int CLOSE_RANGE_CLOEXEC;

COSMOPOLITAN_C_END_

#define CLOSE_RANGE_UNSHARE CLOSE_RANGE_UNSHARE
#define CLOSE_RANGE_CLOEXEC CLOSE_RANGE_CLOEXEC



/*!BEGIN libc/sysv/consts/dn.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DN_H_

#define DN_ACCESS    0x00000001 /* file accessed */
#define DN_MODIFY    0x00000002 /* file modified */
#define DN_CREATE    0x00000004 /* file created */
#define DN_DELETE    0x00000008 /* file removed */
#define DN_RENAME    0x00000010 /* file renamed */
#define DN_ATTRIB    0x00000020 /* file changed attibutes */
#define DN_MULTISHOT 0x80000000 /* don't remove notifier */



/*!BEGIN libc/sysv/consts/dt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DT_H_

#define DT_UNKNOWN 0
#define DT_FIFO    1
#define DT_CHR     2
#define DT_DIR     4
#define DT_BLK     6
#define DT_REG     8
#define DT_LNK     10
#define DT_SOCK    12



/*!BEGIN libc/sysv/consts/endian.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ENDIAN_H_

#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define __BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define __PDP_ENDIAN    __ORDER_PDP_ENDIAN__
#define __BYTE_ORDER    __BYTE_ORDER__



/*!BEGIN libc/sysv/consts/epoll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EPOLL_H_


/*!BEGIN libc/sysv/consts/o.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_

#define O_RDONLY  0
#define O_WRONLY  1
#define O_RDWR    2
#define O_ACCMODE 3

COSMOPOLITAN_C_START_

extern const unsigned O_APPEND;
extern const unsigned O_ASYNC;
extern const unsigned O_CLOEXEC;
extern const unsigned O_COMPRESSED;
extern const unsigned O_CREAT;
extern const unsigned O_DIRECT;
extern const unsigned O_DIRECTORY;
extern const unsigned O_DSYNC;
extern const unsigned O_EXCL;
extern const unsigned O_EXEC;
extern const unsigned O_EXLOCK;
extern const unsigned O_INDEXED;
extern const unsigned O_LARGEFILE;
extern const unsigned O_NOATIME;
extern const unsigned O_NOCTTY;
extern const unsigned O_NOFOLLOW;
extern const unsigned O_NOFOLLOW_ANY;
extern const unsigned O_NONBLOCK;
extern const unsigned O_PATH;
extern const unsigned O_RANDOM;
extern const unsigned O_RSYNC;
extern const unsigned O_SEARCH;
extern const unsigned O_SEQUENTIAL;
extern const unsigned O_SHLOCK;
extern const unsigned O_SYNC;
extern const unsigned O_TMPFILE; /* use tmpfd() or tmpfile() */
extern const unsigned O_TRUNC;
extern const unsigned O_TTY_INIT;
extern const unsigned O_UNLINK;
extern const unsigned O_VERIFY;

#define O_APPEND     O_APPEND
#define O_ASYNC      O_ASYNC
#define O_CLOEXEC    O_CLOEXEC
#define O_COMPRESSED O_COMPRESSED
#define O_CREAT      O_CREAT
#define O_DIRECTORY  O_DIRECTORY
#define O_EXCL       O_EXCL
#define O_EXEC       O_EXEC
#define O_INDEXED    O_INDEXED
#define O_LARGEFILE  O_LARGEFILE
#define O_NDELAY     O_NONBLOCK
#define O_NOATIME    O_NOATIME
#define O_NOCTTY     O_NOCTTY
#define O_NOFOLLOW   O_NOFOLLOW
#define O_NONBLOCK   O_NONBLOCK
#define O_RANDOM     O_RANDOM
#define O_SEQUENTIAL O_SEQUENTIAL
#define O_SYNC       O_SYNC
#define O_TRUNC      O_TRUNC
#define O_UNLINK     O_UNLINK

COSMOPOLITAN_C_END_

#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_DEL 2
#define EPOLL_CTL_MOD 3

#define EPOLLIN        1
#define EPOLLPRI       2
#define EPOLLOUT       4
#define EPOLLERR       8
#define EPOLLHUP       0x10
#define EPOLLRDNORM    0x40
#define EPOLLRDBAND    0x80
#define EPOLLWRNORM    0x0100
#define EPOLLWRBAND    0x0200
#define EPOLLMSG       0x0400
#define EPOLLRDHUP     0x2000
#define EPOLLEXCLUSIVE 0x10000000
#define EPOLLWAKEUP    0x20000000
#define EPOLLONESHOT   0x40000000
#define EPOLLET        0x80000000

COSMOPOLITAN_C_START_

extern const int EPOLL_CLOEXEC;
#define EPOLL_CLOEXEC O_CLOEXEC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ethernet.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ETHERNET_H_

#define ETHERTYPE_PUP      0x0200
#define ETHERTYPE_SPRITE   0x0500
#define ETHERTYPE_IP       0x0800
#define ETHERTYPE_ARP      0x0806
#define ETHERTYPE_REVARP   0x8035
#define ETHERTYPE_AT       0x809B
#define ETHERTYPE_AARP     0x80F3
#define ETHERTYPE_VLAN     0x8100
#define ETHERTYPE_IPX      0x8137
#define ETHERTYPE_IPV6     0x86dd
#define ETHERTYPE_LOOPBACK 0x9000

#define ETHER_ADDR_LEN ETH_ALEN
#define ETHER_TYPE_LEN 2
#define ETHER_CRC_LEN  4
#define ETHER_HDR_LEN  ETH_HLEN
#define ETHER_MIN_LEN  (ETH_ZLEN + ETHER_CRC_LEN)
#define ETHER_MAX_LEN  (ETH_FRAME_LEN + ETHER_CRC_LEN)

#define ETHER_IS_VALID_LEN(foo) \
  ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)

#define ETHERTYPE_TRAIL    0x1000
#define ETHERTYPE_NTRAILER 16

#define ETHERMTU ETH_DATA_LEN
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)



/*!BEGIN libc/sysv/consts/ex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EX_H_

/**
 * @fileoverview Eric Allman's exit() codes
 *
 * - Broadly supported style guideline;
 * - Dating back to 1980 in 4.0BSD;
 * - That won't be standardized.
 *
 */

#define EX_CANTCREAT   73
#define EX_CONFIG      78
#define EX_DATAERR     65
#define EX_IOERR       74
#define EX_NOHOST      68
#define EX_NOINPUT     66
#define EX_NOPERM      77
#define EX_NOUSER      67
#define EX_OK          0
#define EX_OSERR       71
#define EX_OSFILE      72
#define EX_PROTOCOL    76
#define EX_SOFTWARE    70
#define EX_TEMPFAIL    75
#define EX_UNAVAILABLE 69
#define EX_USAGE       64
#define EX__BASE       64
#define EX__MAX        78



/*!BEGIN libc/sysv/consts/exit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EXIT_H_

#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0



/*!BEGIN libc/sysv/consts/f.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_F_H_
COSMOPOLITAN_C_START_

/*
 * full set of fcntl() commands
 * many are only provided by a single platform
 * will be equal to -1 when not available on host
 */
extern const int F_BARRIERFSYNC;
extern const int F_DUPFD;
extern const int F_DUPFD_CLOEXEC;
extern const int F_FULLFSYNC;
extern const int F_GETFD;
extern const int F_GETFL;
extern const int F_GETLEASE;
extern const int F_GETLK;
extern const int F_GETNOSIGPIPE;
extern const int F_GETOWN;
extern const int F_GETPATH;
extern const int F_GETPIPE_SZ;
extern const int F_GETSIG;
extern const int F_MAXFD;
extern const int F_NOCACHE;
extern const int F_NOTIFY;
extern const int F_OFD_GETLK;
extern const int F_OFD_SETLK;
extern const int F_OFD_SETLKW;
extern const int F_RDLCK;
extern const int F_SETFD;
extern const int F_SETFL;
extern const int F_SETLEASE;
extern const int F_SETLK;
extern const int F_SETLKW;
extern const int F_SETNOSIGPIPE;
extern const int F_SETOWN;
extern const int F_SETPIPE_SZ;
extern const int F_SETSIG;
extern const int F_UNLCK;
extern const int F_WRLCK;

COSMOPOLITAN_C_END_

/*
 * portable fcntl() commands
 */
#define F_DUPFD         0
#define F_GETFD         1
#define F_SETFD         2
#define F_GETFL         3
#define F_SETFL         4
#define F_DUPFD_CLOEXEC F_DUPFD_CLOEXEC

/*
 * posix advisory locks
 * polyfilled poorly on windows
 */
#define F_SETLK  F_SETLK
#define F_SETLKW F_SETLKW
#define F_GETLK  F_GETLK
#define F_RDLCK  F_RDLCK
#define F_UNLCK  F_UNLCK
#define F_WRLCK  F_WRLCK



/*!BEGIN libc/sysv/consts/falloc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FALLOC_H_
COSMOPOLITAN_C_START_

extern const int FALLOC_FL_KEEP_SIZE;
extern const int FALLOC_FL_PUNCH_HOLE;
extern const int FALLOC_FL_NO_HIDE_STALE;
extern const int FALLOC_FL_COLLAPSE_RANGE;
extern const int FALLOC_FL_ZERO_RANGE;
extern const int FALLOC_FL_INSERT_RANGE;
extern const int FALLOC_FL_UNSHARE_RANGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fan.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FAN_H_

#define FAN_CLASS_NOTIF              0
#define FAN_ACCESS                   1
#define FAN_ACCESS_PERM              0x020000
#define FAN_ALLOW                    1
#define FAN_ALL_CLASS_BITS           12
#define FAN_ALL_EVENTS               59
#define FAN_ALL_INIT_FLAGS           63
#define FAN_ALL_MARK_FLAGS           255
#define FAN_ALL_OUTGOING_EVENTS      0x03403b
#define FAN_ALL_PERM_EVENTS          0x030000
#define FAN_CLASS_CONTENT            4
#define FAN_CLASS_PRE_CONTENT        8
#define FAN_CLOEXEC                  1
#define FAN_CLOSE                    24
#define FAN_CLOSE_NOWRITE            0x10
#define FAN_CLOSE_WRITE              8
#define FAN_DENY                     2
#define FAN_EVENT_METADATA_LEN       24
#define FAN_EVENT_ON_CHILD           0x08000000
#define FAN_MARK_ADD                 1
#define FAN_MARK_DONT_FOLLOW         4
#define FAN_MARK_FLUSH               0x80
#define FAN_MARK_IGNORED_MASK        0x20
#define FAN_MARK_IGNORED_SURV_MODIFY 0x40
#define FAN_MARK_MOUNT               0x10
#define FAN_MARK_ONLYDIR             8
#define FAN_MARK_REMOVE              2
#define FAN_MODIFY                   2
#define FAN_NOFD                     -1
#define FAN_NONBLOCK                 2
#define FAN_ONDIR                    0x40000000
#define FAN_OPEN                     0x20
#define FAN_OPEN_PERM                0x010000
#define FAN_Q_OVERFLOW               0x4000
#define FAN_UNLIMITED_MARKS          0x20
#define FAN_UNLIMITED_QUEUE          0x10



/*!BEGIN libc/sysv/consts/fbio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FB_H_
COSMOPOLITAN_C_START_

extern const uint64_t FBIOGET_VSCREENINFO;
extern const uint64_t FBIOPUT_VSCREENINFO;
extern const uint64_t FBIOGET_FSCREENINFO;
extern const uint64_t FBIOGETCMAP;
extern const uint64_t FBIOPUTCMAP;
extern const uint64_t FBIOPAN_DISPLAY;
extern const uint64_t FBIO_WAITFORVSYNC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FD_H_
COSMOPOLITAN_C_START_

extern const int FD_CLOEXEC;

#define FD_CLOEXEC 1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fileno.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FILENO_H_

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2



/*!BEGIN libc/sysv/consts/fio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FIO_H_
COSMOPOLITAN_C_START_

extern const uint32_t FIONREAD; /* one of the few encouraged ioctls */
extern const uint32_t FIONBIO;  /* use fcntl(fd, F_SETFL, O_NONBLOCK) */
extern const uint32_t FIOCLEX;  /* use fcntl(fd, F_SETFD, FD_CLOEXEC) */
extern const uint32_t FIONCLEX; /* use fcntl(fd, F_SETFD, 0) */
extern const uint32_t FIOASYNC; /* todo: fcntl(fd, F_SETOWN, pid) */

#define FIONREAD FIONREAD

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fs.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FS_H_

#define FS_IOC_GETFLAGS   0x80086601
#define FS_IOC_SETFLAGS   0x40086602
#define FS_IOC_GETVERSION 0x80087601
#define FS_IOC_SETVERSION 0x40087602
#define FS_IOC_FIEMAP     0xc020660b
#define FS_IOC_FSGETXATTR 0x801c581f
#define FS_IOC_FSSETXATTR 0x401c5820
#define FS_IOC_GETFSLABEL 0x81009431
#define FS_IOC_SETFSLABEL 0x41009432

#define FS_FL_USER_VISIBLE    0x0003DFFF /* user visible flags */
#define FS_FL_USER_MODIFIABLE 0x000380FF /* user modifiable flags */
#define FS_SECRM_FL           0x00000001 /* secure deletion */
#define FS_UNRM_FL            0x00000002 /* undelete */
#define FS_COMPR_FL           0x00000004 /* compress */
#define FS_SYNC_FL            0x00000008 /* synchronous */
#define FS_IMMUTABLE_FL       0x00000010
#define FS_APPEND_FL          0x00000020 /* append-only */
#define FS_NODUMP_FL          0x00000040
#define FS_NOATIME_FL         0x00000080
#define FS_DIRTY_FL           0x00000100
#define FS_COMPRBLK_FL        0x00000200
#define FS_NOCOMP_FL          0x00000400
#define FS_ENCRYPT_FL         0x00000800 /* encrypted file */
#define FS_BTREE_FL           0x00001000
#define FS_INDEX_FL           0x00001000 /* hash-indexed directory */
#define FS_IMAGIC_FL          0x00002000
#define FS_JOURNAL_DATA_FL    0x00004000
#define FS_NOTAIL_FL          0x00008000
#define FS_DIRSYNC_FL         0x00010000
#define FS_TOPDIR_FL          0x00020000
#define FS_HUGE_FILE_FL       0x00040000
#define FS_EXTENT_FL          0x00080000



/*!BEGIN libc/sysv/consts/futex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FUTEX_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_

extern const int FUTEX_WAIT;
extern const int FUTEX_WAKE;
extern const int FUTEX_REQUEUE;

#define FUTEX_WAIT         FUTEX_WAIT
#define FUTEX_WAKE         FUTEX_WAKE
#define FUTEX_REQUEUE      FUTEX_REQUEUE
#define FUTEX_PRIVATE_FLAG 128

#define FUTEX_WAIT_PRIVATE    (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAKE_PRIVATE    (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)

#define FUTEX_WAIT_BITSET      9
#define FUTEX_CLOCK_REALTIME   256
#define FUTEX_BITSET_MATCH_ANY 0xffffffff

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/grnd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_GRND_H_

#define GRND_NONBLOCK 1
#define GRND_RANDOM   2



/*!BEGIN libc/sysv/consts/hwcap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_HWCAP_H_
#ifdef __aarch64__

// Feature bits for getauxval(AT_HWCAP) on AARCH64 GNU/SystemD.

#define HWCAP_FP       (1 << 0)
#define HWCAP_ASIMD    (1 << 1)
#define HWCAP_EVTSTRM  (1 << 2)
#define HWCAP_AES      (1 << 3)
#define HWCAP_PMULL    (1 << 4)
#define HWCAP_SHA1     (1 << 5)
#define HWCAP_SHA2     (1 << 6)
#define HWCAP_CRC32    (1 << 7)
#define HWCAP_ATOMICS  (1 << 8)
#define HWCAP_FPHP     (1 << 9)
#define HWCAP_ASIMDHP  (1 << 10)
#define HWCAP_CPUID    (1 << 11)
#define HWCAP_ASIMDRDM (1 << 12)
#define HWCAP_JSCVT    (1 << 13)
#define HWCAP_FCMA     (1 << 14)
#define HWCAP_LRCPC    (1 << 15)
#define HWCAP_DCPOP    (1 << 16)
#define HWCAP_SHA3     (1 << 17)
#define HWCAP_SM3      (1 << 18)
#define HWCAP_SM4      (1 << 19)
#define HWCAP_ASIMDDP  (1 << 20)
#define HWCAP_SHA512   (1 << 21)
#define HWCAP_SVE      (1 << 22)
#define HWCAP_ASIMDFHM (1 << 23)
#define HWCAP_DIT      (1 << 24)
#define HWCAP_USCAT    (1 << 25)
#define HWCAP_ILRCPC   (1 << 26)
#define HWCAP_FLAGM    (1 << 27)
#define HWCAP_SSBS     (1 << 28)
#define HWCAP_SB       (1 << 29)
#define HWCAP_PACA     (1 << 30)
#define HWCAP_PACG     (1UL << 31)

#define HWCAP2_DCPODP     (1 << 0)
#define HWCAP2_SVE2       (1 << 1)
#define HWCAP2_SVEAES     (1 << 2)
#define HWCAP2_SVEPMULL   (1 << 3)
#define HWCAP2_SVEBITPERM (1 << 4)
#define HWCAP2_SVESHA3    (1 << 5)
#define HWCAP2_SVESM4     (1 << 6)
#define HWCAP2_FLAGM2     (1 << 7)
#define HWCAP2_FRINT      (1 << 8)
#define HWCAP2_SVEI8MM    (1 << 9)
#define HWCAP2_SVEF32MM   (1 << 10)
#define HWCAP2_SVEF64MM   (1 << 11)
#define HWCAP2_SVEBF16    (1 << 12)
#define HWCAP2_I8MM       (1 << 13)
#define HWCAP2_BF16       (1 << 14)
#define HWCAP2_DGH        (1 << 15)
#define HWCAP2_RNG        (1 << 16)
#define HWCAP2_BTI        (1 << 17)
#define HWCAP2_MTE        (1 << 18)

#endif /* __aarch64__ */


/*!BEGIN libc/sysv/consts/icmp6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ICMP6_H_

#define ICMP6_DST_UNREACH ICMP6_DST_UNREACH
#define ICMP6_DST_UNREACH_ADDR ICMP6_DST_UNREACH_ADDR
#define ICMP6_DST_UNREACH_ADMIN ICMP6_DST_UNREACH_ADMIN
#define ICMP6_DST_UNREACH_BEYONDSCOPE ICMP6_DST_UNREACH_BEYONDSCOPE
#define ICMP6_DST_UNREACH_NOPORT ICMP6_DST_UNREACH_NOPORT
#define ICMP6_DST_UNREACH_NOROUTE ICMP6_DST_UNREACH_NOROUTE
#define ICMP6_ECHO_REPLY ICMP6_ECHO_REPLY
#define ICMP6_ECHO_REQUEST ICMP6_ECHO_REQUEST
#define ICMP6_FILTER ICMP6_FILTER
#define ICMP6_INFOMSG_MASK ICMP6_INFOMSG_MASK
#define ICMP6_PACKET_TOO_BIG ICMP6_PACKET_TOO_BIG
#define ICMP6_PARAMPROB_HEADER ICMP6_PARAMPROB_HEADER
#define ICMP6_PARAMPROB_NEXTHEADER ICMP6_PARAMPROB_NEXTHEADER
#define ICMP6_PARAMPROB_OPTION ICMP6_PARAMPROB_OPTION
#define ICMP6_PARAM_PROB ICMP6_PARAM_PROB
#define ICMP6_ROUTER_RENUMBERING ICMP6_ROUTER_RENUMBERING
#define ICMP6_RR_FLAGS_FORCEAPPLY ICMP6_RR_FLAGS_FORCEAPPLY
#define ICMP6_RR_FLAGS_PREVDONE ICMP6_RR_FLAGS_PREVDONE
#define ICMP6_RR_FLAGS_REQRESULT ICMP6_RR_FLAGS_REQRESULT
#define ICMP6_RR_FLAGS_SPECSITE ICMP6_RR_FLAGS_SPECSITE
#define ICMP6_RR_FLAGS_TEST ICMP6_RR_FLAGS_TEST
#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO ICMP6_RR_PCOUSE_RAFLAGS_AUTO
#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN \
  ICMP6_RR_RESULT_FLAGS_FORBIDDEN
#define ICMP6_RR_RESULT_FLAGS_OOB ICMP6_RR_RESULT_FLAGS_OOB
#define ICMP6_TIME_EXCEEDED ICMP6_TIME_EXCEEDED
#define ICMP6_TIME_EXCEED_REASSEMBLY ICMP6_TIME_EXCEED_REASSEMBLY
#define ICMP6_TIME_EXCEED_TRANSIT ICMP6_TIME_EXCEED_TRANSIT

COSMOPOLITAN_C_START_

extern const uint8_t ICMP6_DST_UNREACH;
extern const uint8_t ICMP6_DST_UNREACH_ADDR;
extern const uint8_t ICMP6_DST_UNREACH_ADMIN;
extern const uint8_t ICMP6_DST_UNREACH_BEYONDSCOPE;
extern const uint8_t ICMP6_DST_UNREACH_NOPORT;
extern const uint8_t ICMP6_DST_UNREACH_NOROUTE;
extern const uint8_t ICMP6_ECHO_REPLY;
extern const uint8_t ICMP6_ECHO_REQUEST;
extern const uint8_t ICMP6_FILTER;
extern const uint8_t ICMP6_INFOMSG_MASK;
extern const uint8_t ICMP6_PACKET_TOO_BIG;
extern const uint8_t ICMP6_PARAMPROB_HEADER;
extern const uint8_t ICMP6_PARAMPROB_NEXTHEADER;
extern const uint8_t ICMP6_PARAMPROB_OPTION;
extern const uint8_t ICMP6_PARAM_PROB;
extern const uint8_t ICMP6_ROUTER_RENUMBERING;
extern const uint8_t ICMP6_RR_FLAGS_FORCEAPPLY;
extern const uint8_t ICMP6_RR_FLAGS_PREVDONE;
extern const uint8_t ICMP6_RR_FLAGS_REQRESULT;
extern const uint8_t ICMP6_RR_FLAGS_SPECSITE;
extern const uint8_t ICMP6_RR_FLAGS_TEST;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_AUTO;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_ONLINK;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_FORBIDDEN;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_OOB;
extern const uint8_t ICMP6_TIME_EXCEEDED;
extern const uint8_t ICMP6_TIME_EXCEED_REASSEMBLY;
extern const uint8_t ICMP6_TIME_EXCEED_TRANSIT;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/iff.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IFF_H_
COSMOPOLITAN_C_START_

extern const int IFF_UP;
extern const int IFF_ALLMULTI;
extern const int IFF_AUTOMEDIA;
extern const int IFF_BROADCAST;
extern const int IFF_DEBUG;
extern const int IFF_DYNAMIC;
extern const int IFF_LOOPBACK;
extern const int IFF_MASTER;
extern const int IFF_MULTICAST;
extern const int IFF_NOARP;
extern const int IFF_NOTRAILERS;
extern const int IFF_POINTOPOINT;
extern const int IFF_PORTSEL;
extern const int IFF_PROMISC;
extern const int IFF_RUNNING;
extern const int IFF_SLAVE;

COSMOPOLITAN_C_END_

#define IFF_UP          1
#define IFF_BROADCAST   2
#define IFF_DEBUG       4
#define IFF_LOOPBACK    8
#define IFF_ALLMULTI    IFF_ALLMULTI
#define IFF_AUTOMEDIA   IFF_AUTOMEDIA
#define IFF_DYNAMIC     IFF_DYNAMIC
#define IFF_MASTER      IFF_MASTER
#define IFF_MULTICAST   IFF_MULTICAST
#define IFF_NOARP       IFF_NOARP
#define IFF_NOTRAILERS  IFF_NOTRAILERS
#define IFF_POINTOPOINT IFF_POINTOPOINT
#define IFF_PORTSEL     IFF_PORTSEL
#define IFF_PROMISC     IFF_PROMISC
#define IFF_RUNNING     IFF_RUNNING
#define IFF_SLAVE       IFF_SLAVE




/*!BEGIN libc/sysv/consts/in.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IN_H_

#define IN_ACCESS        1
#define IN_ALL_EVENTS    0x0fff
#define IN_ATTRIB        4
#define IN_CLOEXEC       0x080000
#define IN_CLOSE         24
#define IN_CLOSE_NOWRITE 0x10
#define IN_CLOSE_WRITE   8
#define IN_CREATE        0x0100
#define IN_DELETE        0x0200
#define IN_DELETE_SELF   0x0400
#define IN_DONT_FOLLOW   0x02000000
#define IN_EXCL_UNLINK   0x04000000
#define IN_IGNORED       0x8000
#define IN_ISDIR         0x40000000
#define IN_MASK_ADD      0x20000000
#define IN_MODIFY        2
#define IN_MOVE          192
#define IN_MOVED_FROM    0x40
#define IN_MOVED_TO      0x80
#define IN_MOVE_SELF     0x0800
#define IN_NONBLOCK      0x0800
#define IN_ONESHOT       0x80000000
#define IN_ONLYDIR       0x01000000
#define IN_OPEN          0x20
#define IN_Q_OVERFLOW    0x4000
#define IN_UNMOUNT       0x2000
#define IN_CLASSA_NSHIFT 24



/*!BEGIN libc/sysv/consts/inaddr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INADDR_H_

/**
 * @fileoverview Well-known Internet addresses.
 * These need to be hard-coded as little-endian, so htonl() is needed.
 */

#define INADDR_ANY       0x00000000u /* 0.0.0.0 */
#define INADDR_BROADCAST 0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_NONE      0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_LOOPBACK  0x7F000001u /* 127.0.0.1 */
#define INADDR_TESTNET1  0xC0000200u /* 192.0.2.0/24 (RFC5737§3) */
#define INADDR_TESTNET2  0xC6336400u /* 198.51.100.0/24 */
#define INADDR_TESTNET3  0xCB007100u /* 203.0.113.0/24 */

#define INADDR_ALLHOSTS_GROUP  0xE0000001u
#define INADDR_ALLRTRS_GROUP   0xE0000002u
#define INADDR_MAX_LOCAL_GROUP 0xE00000FFu
#define INADDR_UNSPEC_GROUP    0xE0000000u

#define IN_LOOPBACKNET 127

/* clang-format off */
#define IN6ADDR_ANY_INIT      { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
/* clang-format on */



/*!BEGIN libc/sysv/consts/inet6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INET6_H_

#define INET6_ADDRSTRLEN 48



/*!BEGIN libc/sysv/consts/io.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IO_H_
COSMOPOLITAN_C_START_

#define _IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16))
#define _IOC_NONE        0U
#define _IOC_WRITE       1U
#define _IOC_READ        2U

#define _IO(a, b)      _IOC(_IOC_NONE, (a), (b), 0)
#define _IOW(a, b, c)  _IOC(_IOC_WRITE, (a), (b), sizeof(c))
#define _IOR(a, b, c)  _IOC(_IOC_READ, (a), (b), sizeof(c))
#define _IOWR(a, b, c) _IOC(_IOC_READ | _IOC_WRITE, (a), (b), sizeof(c))

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ioprio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOPRIO_H_
#ifdef _COSMO_SOURCE

#define IOPRIO_WHO_PROCESS 1
#define IOPRIO_WHO_PGRP    2
#define IOPRIO_WHO_USER    3

#define IOPRIO_CLASS_SHIFT 13
#define IOPRIO_CLASS_MASK  0x07
#define IOPRIO_PRIO_MASK   ((1UL << IOPRIO_CLASS_SHIFT) - 1)

#define IOPRIO_PRIO_CLASS(ioprio) \
  (((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)
#define IOPRIO_PRIO_DATA(ioprio) ((ioprio)&IOPRIO_PRIO_MASK)
#define IOPRIO_PRIO_VALUE(class, data)                     \
  ((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \
   ((data)&IOPRIO_PRIO_MASK))

#define IOPRIO_CLASS_NONE 0
#define IOPRIO_CLASS_RT   1
#define IOPRIO_CLASS_BE   2
#define IOPRIO_CLASS_IDLE 3

#define IOPRIO_NR_LEVELS 8
#define IOPRIO_BE_NR     IOPRIO_NR_LEVELS

#define IOPRIO_NORM    4
#define IOPRIO_BE_NORM IOPRIO_NORM

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/iov.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOV_H_
COSMOPOLITAN_C_START_

extern const int IOV_MAX;

COSMOPOLITAN_C_END_

#define IOV_MAX IOV_MAX



/*!BEGIN libc/sysv/consts/ip.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IP_H_
COSMOPOLITAN_C_START_

extern const int IP_ADD_MEMBERSHIP;
extern const int IP_ADD_SOURCE_MEMBERSHIP;
extern const int IP_BIND_ADDRESS_NO_PORT;
extern const int IP_BLOCK_SOURCE;
extern const int IP_CHECKSUM;
extern const int IP_DEFAULT_MULTICAST_LOOP;
extern const int IP_DEFAULT_MULTICAST_TTL;
extern const int IP_DROP_MEMBERSHIP;
extern const int IP_DROP_SOURCE_MEMBERSHIP;
extern const int IP_FREEBIND;
extern const int IP_HDRINCL;
extern const int IP_IPSEC_POLICY;
extern const int IP_MAX_MEMBERSHIPS;
extern const int IP_MINTTL;
extern const int IP_MSFILTER;
extern const int IP_MTU;
extern const int IP_MTU_DISCOVER;
extern const int IP_MULTICAST_ALL;
extern const int IP_MULTICAST_IF;
extern const int IP_MULTICAST_LOOP;
extern const int IP_MULTICAST_TTL;
extern const int IP_NODEFRAG;
extern const int IP_OPTIONS;
extern const int IP_ORIGDSTADDR;
extern const int IP_PASSSEC;
extern const int IP_PKTINFO;
extern const int IP_PKTOPTIONS;
extern const int IP_PMTUDISC;
extern const int IP_PMTUDISC_DO;
extern const int IP_PMTUDISC_DONT;
extern const int IP_PMTUDISC_INTERFACE;
extern const int IP_PMTUDISC_OMIT;
extern const int IP_PMTUDISC_PROBE;
extern const int IP_PMTUDISC_WANT;
extern const int IP_RECVDSTADDR;
extern const int IP_RECVERR;
extern const int IP_RECVOPTS;
extern const int IP_RECVORIGDSTADDR;
extern const int IP_RECVRETOPTS;
extern const int IP_RECVTOS;
extern const int IP_RECVTTL;
extern const int IP_RETOPTS;
extern const int IP_ROUTER_ALERT;
extern const int IP_TOS;
extern const int IP_TRANSPARENT;
extern const int IP_TTL;
extern const int IP_UNBLOCK_SOURCE;
extern const int IP_UNICAST_IF;
extern const int IP_XFRM_POLICY;

#define IP_ADD_MEMBERSHIP         IP_ADD_MEMBERSHIP
#define IP_ADD_SOURCE_MEMBERSHIP  IP_ADD_SOURCE_MEMBERSHIP
#define IP_BIND_ADDRESS_NO_PORT   IP_BIND_ADDRESS_NO_PORT
#define IP_BLOCK_SOURCE           IP_BLOCK_SOURCE
#define IP_CHECKSUM               IP_CHECKSUM
#define IP_DEFAULT_MULTICAST_LOOP IP_DEFAULT_MULTICAST_LOOP
#define IP_DEFAULT_MULTICAST_TTL  IP_DEFAULT_MULTICAST_TTL
#define IP_DROP_MEMBERSHIP        IP_DROP_MEMBERSHIP
#define IP_DROP_SOURCE_MEMBERSHIP IP_DROP_SOURCE_MEMBERSHIP
#define IP_FREEBIND               IP_FREEBIND
#define IP_HDRINCL                IP_HDRINCL
#define IP_IPSEC_POLICY           IP_IPSEC_POLICY
#define IP_MAX_MEMBERSHIPS        IP_MAX_MEMBERSHIPS
#define IP_MINTTL                 IP_MINTTL
#define IP_MSFILTER               IP_MSFILTER
#define IP_MTU                    IP_MTU
#define IP_MTU_DISCOVER           IP_MTU_DISCOVER
#define IP_MULTICAST_ALL          IP_MULTICAST_ALL
#define IP_MULTICAST_IF           IP_MULTICAST_IF
#define IP_MULTICAST_LOOP         IP_MULTICAST_LOOP
#define IP_MULTICAST_TTL          IP_MULTICAST_TTL
#define IP_NODEFRAG               IP_NODEFRAG
#define IP_OPTIONS                IP_OPTIONS
#define IP_ORIGDSTADDR            IP_ORIGDSTADDR
#define IP_PASSSEC                IP_PASSSEC
#define IP_PKTINFO                IP_PKTINFO
#define IP_PKTOPTIONS             IP_PKTOPTIONS
#define IP_PMTUDISC               IP_PMTUDISC
#define IP_PMTUDISC_DO            IP_PMTUDISC_DO
#define IP_PMTUDISC_DONT          IP_PMTUDISC_DONT
#define IP_PMTUDISC_INTERFACE     IP_PMTUDISC_INTERFACE
#define IP_PMTUDISC_OMIT          IP_PMTUDISC_OMIT
#define IP_PMTUDISC_PROBE         IP_PMTUDISC_PROBE
#define IP_PMTUDISC_WANT          IP_PMTUDISC_WANT
#define IP_RECVDSTADDR            IP_RECVDSTADDR
#define IP_RECVERR                IP_RECVERR
#define IP_RECVOPTS               IP_RECVOPTS
#define IP_RECVORIGDSTADDR        IP_RECVORIGDSTADDR
#define IP_RECVRETOPTS            IP_RECVRETOPTS
#define IP_RECVTOS                IP_RECVTOS
#define IP_RECVTTL                IP_RECVTTL
#define IP_RETOPTS                IP_RETOPTS
#define IP_ROUTER_ALERT           IP_ROUTER_ALERT
#define IP_TOS                    IP_TOS
#define IP_TRANSPARENT            IP_TRANSPARENT
#define IP_TTL                    IP_TTL
#define IP_UNBLOCK_SOURCE         IP_UNBLOCK_SOURCE
#define IP_UNICAST_IF             IP_UNICAST_IF
#define IP_XFRM_POLICY            IP_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipport.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPORT_H_

/**
 * ARPA network ports.
 */
#define IPPORT_ECHO         7
#define IPPORT_DISCARD      9
#define IPPORT_SYSTAT       11
#define IPPORT_DAYTIME      13
#define IPPORT_NETSTAT      15
#define IPPORT_FTP          21
#define IPPORT_TELNET       23
#define IPPORT_SMTP         25
#define IPPORT_TIMESERVER   37
#define IPPORT_NAMESERVER   42
#define IPPORT_WHOIS        43
#define IPPORT_MTP          57
#define IPPORT_TFTP         69
#define IPPORT_RJE          77
#define IPPORT_FINGER       79
#define IPPORT_TTYLINK      87
#define IPPORT_SUPDUP       95
#define IPPORT_EXECSERVER   512
#define IPPORT_LOGINSERVER  513
#define IPPORT_CMDSERVER    514
#define IPPORT_EFSSERVER    520
#define IPPORT_BIFFUDP      512
#define IPPORT_WHOSERVER    513
#define IPPORT_ROUTESERVER  520
#define IPPORT_RESERVED     1024
#define IPPORT_USERRESERVED IPPORT_USERRESERVED

/**
 * Modern network ports.
 */
#define IPPORT_SSH         22
#define IPPORT_DOMAIN      53
#define IPPORT_HTTP        80
#define IPPORT_POP3        110
#define IPPORT_SFTP        115
#define IPPORT_NTP         123
#define IPPORT_IMAP2       143
#define IPPORT_NETBIOS_NS  137
#define IPPORT_NETBIOS_DGM 138
#define IPPORT_NETBIOS_SSN 139
#define IPPORT_BGP         179
#define IPPORT_IRC         194
#define IPPORT_HTTPS       443
#define IPPORT_PRINTER     515
#define IPPORT_NFS         2049
#define IPPORT_DISTCC      3632
#define IPPORT_SIP         5060
#define IPPORT_POSTGRESQL  5432
#define IPPORT_X11         6000
#define IPPORT_GIT         9418
#define IPPORT_IRCD        6667
#define IPPORT_IMAPS       993
#define IPPORT_POP3S       995

COSMOPOLITAN_C_START_

extern const int IPPORT_USERRESERVED;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipproto.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPROTO_H_

#define IPPROTO_IP     0
#define IPPROTO_ICMP   1
#define IPPROTO_TCP    6
#define IPPROTO_UDP    17
#define IPPROTO_IPV6   41
#define IPPROTO_ICMPV6 58
#define IPPROTO_RAW    255
#define IPPROTO_MAX    263 /* xxx */



/*!BEGIN libc/sysv/consts/ipv6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPV6_H_
COSMOPOLITAN_C_START_

extern const int IPV6_2292DSTOPTS;
extern const int IPV6_2292HOPLIMIT;
extern const int IPV6_2292HOPOPTS;
extern const int IPV6_2292PKTINFO;
extern const int IPV6_2292PKTOPTIONS;
extern const int IPV6_2292RTHDR;
extern const int IPV6_ADDRFORM;
extern const int IPV6_ADD_MEMBERSHIP;
extern const int IPV6_AUTHHDR;
extern const int IPV6_AUTOFLOWLABEL;
extern const int IPV6_CHECKSUM;
extern const int IPV6_DONTFRAG;
extern const int IPV6_DROP_MEMBERSHIP;
extern const int IPV6_DSTOPTS;
extern const int IPV6_HDRINCL;
extern const int IPV6_HOPLIMIT;
extern const int IPV6_HOPOPTS;
extern const int IPV6_IPSEC_POLICY;
extern const int IPV6_JOIN_ANYCAST;
extern const int IPV6_JOIN_GROUP;
extern const int IPV6_LEAVE_ANYCAST;
extern const int IPV6_LEAVE_GROUP;
extern const int IPV6_MINHOPCOUNT;
extern const int IPV6_MTU;
extern const int IPV6_MTU_DISCOVER;
extern const int IPV6_MULTICAST_HOPS;
extern const int IPV6_MULTICAST_IF;
extern const int IPV6_MULTICAST_LOOP;
extern const int IPV6_NEXTHOP;
extern const int IPV6_ORIGDSTADDR;
extern const int IPV6_PATHMTU;
extern const int IPV6_PKTINFO;
extern const int IPV6_PMTUDISC_DO;
extern const int IPV6_PMTUDISC_DONT;
extern const int IPV6_PMTUDISC_INTERFACE;
extern const int IPV6_PMTUDISC_OMIT;
extern const int IPV6_PMTUDISC_PROBE;
extern const int IPV6_PMTUDISC_WANT;
extern const int IPV6_RECVDSTOPTS;
extern const int IPV6_RECVERR;
extern const int IPV6_RECVHOPLIMIT;
extern const int IPV6_RECVHOPOPTS;
extern const int IPV6_RECVORIGDSTADDR;
extern const int IPV6_RECVPATHMTU;
extern const int IPV6_RECVPKTINFO;
extern const int IPV6_RECVRTHDR;
extern const int IPV6_RECVTCLASS;
extern const int IPV6_ROUTER_ALERT;
extern const int IPV6_RTHDR;
extern const int IPV6_RTHDRDSTOPTS;
extern const int IPV6_RTHDR_LOOSE;
extern const int IPV6_RTHDR_STRICT;
extern const int IPV6_RTHDR_TYPE_0;
extern const int IPV6_RXDSTOPTS;
extern const int IPV6_RXHOPOPTS;
extern const int IPV6_TCLASS;
extern const int IPV6_UNICAST_HOPS;
extern const int IPV6_V6ONLY;
extern const int IPV6_XFRM_POLICY;

#define IPV6_2292DSTOPTS        IPV6_2292DSTOPTS
#define IPV6_2292HOPLIMIT       IPV6_2292HOPLIMIT
#define IPV6_2292HOPOPTS        IPV6_2292HOPOPTS
#define IPV6_2292PKTINFO        IPV6_2292PKTINFO
#define IPV6_2292PKTOPTIONS     IPV6_2292PKTOPTIONS
#define IPV6_2292RTHDR          IPV6_2292RTHDR
#define IPV6_ADDRFORM           IPV6_ADDRFORM
#define IPV6_ADD_MEMBERSHIP     IPV6_ADD_MEMBERSHIP
#define IPV6_AUTHHDR            IPV6_AUTHHDR
#define IPV6_AUTOFLOWLABEL      IPV6_AUTOFLOWLABEL
#define IPV6_CHECKSUM           IPV6_CHECKSUM
#define IPV6_DONTFRAG           IPV6_DONTFRAG
#define IPV6_DROP_MEMBERSHIP    IPV6_DROP_MEMBERSHIP
#define IPV6_DSTOPTS            IPV6_DSTOPTS
#define IPV6_HDRINCL            IPV6_HDRINCL
#define IPV6_HOPLIMIT           IPV6_HOPLIMIT
#define IPV6_HOPOPTS            IPV6_HOPOPTS
#define IPV6_IPSEC_POLICY       IPV6_IPSEC_POLICY
#define IPV6_JOIN_ANYCAST       IPV6_JOIN_ANYCAST
#define IPV6_JOIN_GROUP         IPV6_JOIN_GROUP
#define IPV6_LEAVE_ANYCAST      IPV6_LEAVE_ANYCAST
#define IPV6_LEAVE_GROUP        IPV6_LEAVE_GROUP
#define IPV6_MINHOPCOUNT        IPV6_MINHOPCOUNT
#define IPV6_MTU                IPV6_MTU
#define IPV6_MTU_DISCOVER       IPV6_MTU_DISCOVER
#define IPV6_MULTICAST_HOPS     IPV6_MULTICAST_HOPS
#define IPV6_MULTICAST_IF       IPV6_MULTICAST_IF
#define IPV6_MULTICAST_LOOP     IPV6_MULTICAST_LOOP
#define IPV6_NEXTHOP            IPV6_NEXTHOP
#define IPV6_ORIGDSTADDR        IPV6_ORIGDSTADDR
#define IPV6_PATHMTU            IPV6_PATHMTU
#define IPV6_PKTINFO            IPV6_PKTINFO
#define IPV6_PMTUDISC_DO        IPV6_PMTUDISC_DO
#define IPV6_PMTUDISC_DONT      IPV6_PMTUDISC_DONT
#define IPV6_PMTUDISC_INTERFACE IPV6_PMTUDISC_INTERFACE
#define IPV6_PMTUDISC_OMIT      IPV6_PMTUDISC_OMIT
#define IPV6_PMTUDISC_PROBE     IPV6_PMTUDISC_PROBE
#define IPV6_PMTUDISC_WANT      IPV6_PMTUDISC_WANT
#define IPV6_RECVDSTOPTS        IPV6_RECVDSTOPTS
#define IPV6_RECVERR            IPV6_RECVERR
#define IPV6_RECVHOPLIMIT       IPV6_RECVHOPLIMIT
#define IPV6_RECVHOPOPTS        IPV6_RECVHOPOPTS
#define IPV6_RECVORIGDSTADDR    IPV6_RECVORIGDSTADDR
#define IPV6_RECVPATHMTU        IPV6_RECVPATHMTU
#define IPV6_RECVPKTINFO        IPV6_RECVPKTINFO
#define IPV6_RECVRTHDR          IPV6_RECVRTHDR
#define IPV6_RECVTCLASS         IPV6_RECVTCLASS
#define IPV6_ROUTER_ALERT       IPV6_ROUTER_ALERT
#define IPV6_RTHDR              IPV6_RTHDR
#define IPV6_RTHDRDSTOPTS       IPV6_RTHDRDSTOPTS
#define IPV6_RTHDR_LOOSE        IPV6_RTHDR_LOOSE
#define IPV6_RTHDR_STRICT       IPV6_RTHDR_STRICT
#define IPV6_RTHDR_TYPE_0       IPV6_RTHDR_TYPE_0
#define IPV6_RXDSTOPTS          IPV6_RXDSTOPTS
#define IPV6_RXHOPOPTS          IPV6_RXHOPOPTS
#define IPV6_TCLASS             IPV6_TCLASS
#define IPV6_UNICAST_HOPS       IPV6_UNICAST_HOPS
#define IPV6_V6ONLY             IPV6_V6ONLY
#define IPV6_XFRM_POLICY        IPV6_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/itimer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ITIMER_H_

#define ITIMER_REAL    0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF    2



/*!BEGIN libc/sysv/consts/kd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KD_H_
COSMOPOLITAN_C_START_

extern const uint64_t GIO_FONT;
extern const uint64_t PIO_FONT;
extern const uint64_t GIO_FONTX;
extern const uint64_t PIO_FONTX;
extern const uint64_t PIO_FONT8x8;
extern const uint64_t PIO_FONT8x14;
extern const uint64_t PIO_FONT8x16;
extern const uint64_t PIO_VFONT;
extern const uint64_t PIO_FONTRESET;
extern const uint64_t KDFONTOP;

COSMOPOLITAN_C_END_

#define GIO_FONT      GIO_FONT
#define PIO_FONT      PIO_FONT
#define GIO_FONTX     GIO_FONTX
#define PIO_FONTX     PIO_FONTX
#define PIO_FONT8x8   PIO_FONT8x8
#define PIO_FONT8x14  PIO_FONT8x14
#define PIO_FONT8x16  PIO_FONT8x14
#define PIO_VFONT     PIO_VFONT
#define PIO_FONTRESET PIO_FONTRESET
#define KDFONTOP      KDFONTOP

#ifdef _BSD_SOURCE
#define PIO_VFONT_DEFAULT PIO_FONTRESET
#endif



/*!BEGIN libc/sysv/consts/kern.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KERN_H_
COSMOPOLITAN_C_START_

#define KERN_SOH       "\001"
#define KERN_SOH_ASCII '\001'
#define KERN_EMERG     KERN_SOH "0"
#define KERN_ALERT     KERN_SOH "1"
#define KERN_CRIT      KERN_SOH "2"
#define KERN_ERR       KERN_SOH "3"
#define KERN_WARNING   KERN_SOH "4"
#define KERN_NOTICE    KERN_SOH "5"
#define KERN_INFO      KERN_SOH "6"
#define KERN_DEBUG     KERN_SOH "7"
#define KERN_DEFAULT   ""
#define KERN_CONT      KERN_SOH "c"

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/l.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_L_H_

#define L_SET  SEEK_SET
#define L_INCR SEEK_CUR
#define L_XTND SEEK_END



/*!BEGIN libc/sysv/consts/limits.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIMITS_H_
COSMOPOLITAN_C_START_

extern const int NGROUPS_MAX;
extern const int PIPE_BUF;
extern const int SOMAXCONN;
extern const int _ARG_MAX;
extern const int _NAME_MAX;
extern const int _NSIG;
extern const int _PATH_MAX;
extern const int LINK_MAX;
extern const int MAX_CANON;
extern const int MAX_INPUT;

#define NGROUPS_MAX NGROUPS_MAX
#define PIPE_BUF    PIPE_BUF
#define SOMAXCONN   SOMAXCONN
#define _ARG_MAX    _ARG_MAX
#define _NAME_MAX   _NAME_MAX
#define _NSIG       _NSIG
#define _PATH_MAX   _PATH_MAX
#define LINK_MAX    LINK_MAX
#define MAX_CANON   MAX_CANON
#define MAX_INPUT   MAX_INPUT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIO_H_

#define LIO_NOP LIO_NOP
#define LIO_NOWAIT LIO_NOWAIT
#define LIO_READ LIO_READ
#define LIO_WAIT LIO_WAIT
#define LIO_WRITE LIO_WRITE

COSMOPOLITAN_C_START_

extern const int LIO_NOP;
extern const int LIO_NOWAIT;
extern const int LIO_READ;
extern const int LIO_WAIT;
extern const int LIO_WRITE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOCK_H_
COSMOPOLITAN_C_START_

extern const int LOCK_EX;
extern const int LOCK_NB;
extern const int LOCK_SH;
extern const int LOCK_UN;
extern const int LOCK_UNLOCK_CACHE;

COSMOPOLITAN_C_END_

#define LOCK_EX 2
#define LOCK_NB LOCK_NB
#define LOCK_SH LOCK_SH
#define LOCK_UN LOCK_UN




/*!BEGIN libc/sysv/consts/log.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOG_H_

#define LOG_MASK(pri) (1 << (pri))
#define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)

#define LOG_EMERG   0
#define LOG_ALERT   1
#define LOG_CRIT    2
#define LOG_ERR     3
#define LOG_WARNING 4
#define LOG_NOTICE  5
#define LOG_INFO    6
#define LOG_DEBUG   7

#define LOG_KERN     0000
#define LOG_USER     0010
#define LOG_MAIL     0020
#define LOG_DAEMON   0030
#define LOG_AUTH     0040
#define LOG_SYSLOG   0050
#define LOG_LPR      0060
#define LOG_NEWS     0070
#define LOG_UUCP     0100
#define LOG_CRON     0110
#define LOG_AUTHPRIV 0120
#define LOG_FTP      0130

#define LOG_PID    1
#define LOG_CONS   2
#define LOG_ODELAY 4
#define LOG_NDELAY 8
#define LOG_NOWAIT 16
#define LOG_PERROR 32

#define LOG_LOCAL0 128
#define LOG_LOCAL1 136
#define LOG_LOCAL2 144
#define LOG_LOCAL3 152
#define LOG_LOCAL4 160
#define LOG_LOCAL5 168
#define LOG_LOCAL6 176
#define LOG_LOCAL7 184

#define LOG_NFACILITIES 24
#define LOG_FACMASK     0x03f8
#define LOG_FAC(p)      ((LOG_FACMASK & (p)) >> 3)

#define LOG_PRIMASK       7
#define LOG_PRI(p)        (LOG_PRIMASK & (p))
#define LOG_MAKEPRI(f, p) (((f) << 3) | (p))



/*!BEGIN libc/sysv/consts/loglevel.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOGLEVEL_H_
COSMOPOLITAN_C_START_

#define LOGLEVEL_SCHED   -2
#define LOGLEVEL_DEFAULT -1
#define LOGLEVEL_EMERG   0
#define LOGLEVEL_ALERT   1
#define LOGLEVEL_CRIT    2
#define LOGLEVEL_ERR     3
#define LOGLEVEL_WARNING 4
#define LOGLEVEL_NOTICE  5
#define LOGLEVEL_INFO    6
#define LOGLEVEL_DEBUG   7

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/madv.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MADV_H_
COSMOPOLITAN_C_START_

extern const unsigned MADV_DODUMP;
extern const unsigned MADV_DOFORK;
extern const unsigned MADV_DONTDUMP;
extern const unsigned MADV_DONTFORK;
extern const unsigned MADV_DONTNEED;
extern const unsigned MADV_FREE;
extern const unsigned MADV_HUGEPAGE;
extern const unsigned MADV_HWPOISON;
extern const unsigned MADV_MERGEABLE;
extern const unsigned MADV_NOHUGEPAGE;
extern const unsigned MADV_NORMAL;
extern const unsigned MADV_RANDOM;
extern const unsigned MADV_REMOVE;
extern const unsigned MADV_SEQUENTIAL;
extern const unsigned MADV_UNMERGEABLE;
extern const unsigned MADV_WILLNEED;
extern const unsigned MADV_SOFT_OFFLINE;
extern const unsigned MADV_WIPEONFORK;
extern const unsigned MADV_KEEPONFORK;
extern const unsigned MADV_COLD;
extern const unsigned MADV_PAGEOUT;
extern const unsigned MADV_POPULATE_READ;
extern const unsigned MADV_POPULATE_WRITE;
extern const unsigned MADV_DONTNEED_LOCKED;
extern const unsigned MADV_COLLAPSE;

#define MADV_NORMAL     0
#define MADV_RANDOM     1
#define MADV_SEQUENTIAL 2
#define MADV_WILLNEED   3

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/map.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MAP_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int MAP_32BIT;
extern const int MAP_ANON;
extern const int MAP_ANONYMOUS;
extern const int MAP_CONCEAL;
extern const int MAP_DENYWRITE;
extern const int MAP_EXECUTABLE;
extern const int MAP_FILE;
extern const int MAP_FIXED;
extern const int MAP_FIXED_NOREPLACE;
extern const int MAP_HASSEMAPHORE;
extern const int MAP_HUGETLB;
extern const int MAP_INHERIT;
extern const int MAP_JIT;
extern const int MAP_LOCKED;
extern const int MAP_NOCACHE;
extern const int MAP_NOEXTEND;
extern const int MAP_NONBLOCK;
extern const int MAP_NORESERVE;
extern const int MAP_NOSYNC;
extern const int MAP_POPULATE;
extern const int MAP_PRIVATE;
extern const int MAP_SHARED;
extern const int MAP_SHARED_VALIDATE;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define MAP_FILE    0
#define MAP_SHARED  1
#define MAP_PRIVATE 2
#define MAP_STACK   6
#define MAP_TYPE    15
#define MAP_FIXED   16

#define MAP_ANONYMOUS       MAP_ANONYMOUS
#define MAP_CONCEAL         MAP_CONCEAL
#define MAP_EXECUTABLE      MAP_EXECUTABLE
#define MAP_FIXED_NOREPLACE MAP_FIXED_NOREPLACE
#define MAP_HASSEMAPHORE    MAP_HASSEMAPHORE
#define MAP_POPULATE        MAP_POPULATE
#define MAP_NORESERVE       MAP_NORESERVE

#define MAP_ANON   MAP_ANONYMOUS
#define MAP_NOCORE MAP_CONCEAL



/*!BEGIN libc/sysv/consts/mcast.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MCAST_H_

#define MCAST_BLOCK_SOURCE MCAST_BLOCK_SOURCE
#define MCAST_EXCLUDE MCAST_EXCLUDE
#define MCAST_INCLUDE MCAST_INCLUDE
#define MCAST_JOIN_GROUP MCAST_JOIN_GROUP
#define MCAST_JOIN_SOURCE_GROUP MCAST_JOIN_SOURCE_GROUP
#define MCAST_LEAVE_GROUP MCAST_LEAVE_GROUP
#define MCAST_LEAVE_SOURCE_GROUP MCAST_LEAVE_SOURCE_GROUP
#define MCAST_MSFILTER MCAST_MSFILTER
#define MCAST_UNBLOCK_SOURCE MCAST_UNBLOCK_SOURCE

COSMOPOLITAN_C_START_

extern const int MCAST_BLOCK_SOURCE;
extern const int MCAST_EXCLUDE;
extern const int MCAST_INCLUDE;
extern const int MCAST_JOIN_GROUP;
extern const int MCAST_JOIN_SOURCE_GROUP;
extern const int MCAST_LEAVE_GROUP;
extern const int MCAST_LEAVE_SOURCE_GROUP;
extern const int MCAST_MSFILTER;
extern const int MCAST_UNBLOCK_SOURCE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mfd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MFD_H_

#define MFD_CLOEXEC       1
#define MFD_ALLOW_SEALING 2



/*!BEGIN libc/sysv/consts/mlock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MLOCK_H_
COSMOPOLITAN_C_START_

extern const int MCL_CURRENT;
extern const int MCL_FUTURE;
extern const int MCL_ONFAULT;

COSMOPOLITAN_C_END_

#define MCL_CURRENT 1
#define MCL_FUTURE  2
#define MCL_ONFAULT MCL_ONFAULT



/*!BEGIN libc/sysv/consts/modem.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MODEM_H_
COSMOPOLITAN_C_START_

extern const uint64_t TIOCMGET;
extern const uint64_t TIOCMSET;
extern const uint64_t TIOCMBIC;
extern const uint64_t TIOCMBIS;

extern const int TIOCM_CAR;
extern const int TIOCM_CD;
extern const int TIOCM_CTS;
extern const int TIOCM_DSR;
extern const int TIOCM_DTR;
extern const int TIOCM_LE;
extern const int TIOCM_RI;
extern const int TIOCM_RNG;
extern const int TIOCM_RTS;
extern const int TIOCM_SR;
extern const int TIOCM_ST;

#define TIOCM_LE  0x01
#define TIOCM_DTR 0x02
#define TIOCM_RTS 0x04
#define TIOCM_ST  0x08
#define TIOCM_SR  0x10
#define TIOCM_CTS 0x20
#define TIOCM_CAR 0x40
#define TIOCM_CD  0x40
#define TIOCM_RI  0x80
#define TIOCM_RNG 0x80
#define TIOCM_DSR 0x0100

#define TIOCMGET TIOCMGET
#define TIOCMSET TIOCMSET
#define TIOCMBIC TIOCMBIC
#define TIOCMBIS TIOCMBIS


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const unsigned long MS_RDONLY;
extern const int MNT_RDONLY;
extern const unsigned long MS_NOSUID;
extern const int MNT_NOSUID;
extern const unsigned long MS_NODEV;
extern const int MNT_NODEV;
extern const unsigned long MS_NOEXEC;
extern const int MNT_NOEXEC;
extern const unsigned long MS_SYNCHRONOUS;
extern const int MNT_SYNCHRONOUS;
extern const unsigned long MS_REMOUNT;
extern const int MNT_UPDATE;
extern const unsigned long MS_MANDLOCK;
extern const unsigned long MS_DIRSYNC;
extern const unsigned long MS_NOATIME;
extern const int MNT_NOATIME;
extern const unsigned long MS_NODIRATIME;
extern const unsigned long MS_BIND;
extern const unsigned long MS_MOVE;
extern const unsigned long MS_REC;
extern const unsigned long MS_SILENT;
extern const unsigned long MS_POSIXACL;
extern const unsigned long MS_UNBINDABLE;
extern const unsigned long MS_PRIVATE;
extern const unsigned long MS_SLAVE;
extern const unsigned long MS_SHARED;
extern const unsigned long MS_RELATIME;
extern const int MNT_RELATIME;
extern const unsigned long MS_KERNMOUNT;
extern const unsigned long MS_I_VERSION;
extern const unsigned long MS_STRICTATIME;
extern const int MNT_STRICTATIME;
extern const unsigned long MS_LAZYTIME;
extern const unsigned long MS_ACTIVE;
extern const unsigned long MS_NOUSER;
extern const unsigned long MS_RMT_MASK;
extern const unsigned long MS_MGC_VAL;
extern const unsigned long MS_MGC_MSK;
extern const int MNT_ASYNC;
extern const int MNT_RELOAD;
extern const int MNT_SUIDDIR;
extern const int MNT_NOCLUSTERR;
extern const int MNT_NOCLUSTERW;
extern const int MNT_SNAPSHOT;

#define MS_RDONLY       0x00000001
#define MNT_RDONLY      0x00000001
#define MS_NOSUID       MS_NOSUID
#define MNT_NOSUID      MNT_NOSUID
#define MS_NODEV        MS_NODEV
#define MNT_NODEV       MNT_NODEV
#define MS_NOEXEC       MS_NOEXEC
#define MNT_NOEXEC      MNT_NOEXEC
#define MS_SYNCHRONOUS  MS_SYNCHRONOUS
#define MNT_SYNCHRONOUS MNT_SYNCHRONOUS
#define MS_REMOUNT      MS_REMOUNT
#define MNT_UPDATE      MNT_UPDATE
#define MS_MANDLOCK     MS_MANDLOCK
#define MS_DIRSYNC      MS_DIRSYNC
#define MS_NOATIME      MS_NOATIME
#define MNT_NOATIME     MNT_NOATIME
#define MS_NODIRATIME   MS_NODIRATIME
#define MS_BIND         MS_BIND
#define MS_MOVE         MS_MOVE
#define MS_REC          MS_REC
#define MS_SILENT       MS_SILENT
#define MS_POSIXACL     MS_POSIXACL
#define MS_UNBINDABLE   MS_UNBINDABLE
#define MS_PRIVATE      MS_PRIVATE
#define MS_SLAVE        MS_SLAVE
#define MS_SHARED       MS_SHARED
#define MS_RELATIME     MS_RELATIME
#define MNT_RELATIME    MNT_RELATIME
#define MS_KERNMOUNT    MS_KERNMOUNT
#define MS_I_VERSION    MS_I_VERSION
#define MS_STRICTATIME  MS_STRICTATIME
#define MNT_STRICTATIME MNT_STRICTATIME
#define MS_LAZYTIME     MS_LAZYTIME
#define MS_ACTIVE       MS_ACTIVE
#define MS_NOUSER       MS_NOUSER
#define MS_RMT_MASK     MS_RMT_MASK
#define MS_MGC_VAL      MS_MGC_VAL
#define MS_MGC_MSK      MS_MGC_MSK
#define MNT_ASYNC       MNT_ASYNC
#define MNT_RELOAD      MNT_RELOAD
#define MNT_SUIDDIR     MNT_SUIDDIR
#define MNT_NOCLUSTERR  MNT_NOCLUSTERR
#define MNT_NOCLUSTERW  MNT_NOCLUSTERW
#define MNT_SNAPSHOT    MNT_SNAPSHOT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mremap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MREMAP_H_

#define MREMAP_MAYMOVE 1
#define MREMAP_FIXED   2



/*!BEGIN libc/sysv/consts/msg.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSG_H_
COSMOPOLITAN_C_START_

extern const int MSG_BATCH;
extern const int MSG_BCAST;
extern const int MSG_CMSG_CLOEXEC;
extern const int MSG_CONFIRM;
extern const int MSG_CTRUNC;
extern const int MSG_DONTROUTE;
extern const int MSG_DONTWAIT;
extern const int MSG_EOF;
extern const int MSG_EOR;
extern const int MSG_ERRQUEUE;
extern const int MSG_EXCEPT;
extern const int MSG_FASTOPEN;
extern const int MSG_FIN;
extern const int MSG_INFO;
extern const int MSG_MCAST;
extern const int MSG_MORE;
extern const int MSG_NOERROR;
extern const int MSG_NOSIGNAL;
extern const int MSG_NOTIFICATION;
extern const int MSG_OOB;
extern const int MSG_PARITY_ERROR;
extern const int MSG_PEEK;
extern const int MSG_PROXY;
extern const int MSG_RST;
extern const int MSG_STAT;
extern const int MSG_SYN;
extern const int MSG_TRUNC;
extern const int MSG_WAITALL;
extern const int MSG_WAITFORONE;

#define MSG_OOB       1
#define MSG_PEEK      2
#define MSG_DONTROUTE 4
#define MSG_DONTWAIT  MSG_DONTWAIT
#define MSG_FASTOPEN  MSG_FASTOPEN
#define MSG_WAITALL   MSG_WAITALL
#define MSG_TRUNC     MSG_TRUNC
#define MSG_CTRUNC    MSG_CTRUNC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/msync.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSYNC_H_
COSMOPOLITAN_C_START_

extern const int MS_SYNC;
extern const int MS_ASYNC;
extern const int MS_INVALIDATE;

#define MS_SYNC       MS_SYNC
#define MS_ASYNC      MS_ASYNC
#define MS_INVALIDATE MS_INVALIDATE

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/nrlinux.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NRLINUX_H_
#ifdef _COSMO_SOURCE

#ifdef __x86_64__

#define __NR_linux_exit                    0x003c
#define __NR_linux_exit_group              0x00e7
#define __NR_linux_read                    0x0000
#define __NR_linux_write                   0x0001
#define __NR_linux_open                    0x0002
#define __NR_linux_close                   0x0003
#define __NR_linux_stat                    0x0004
#define __NR_linux_fstat                   0x0005
#define __NR_linux_lstat                   0x0006
#define __NR_linux_poll                    0x0007
#define __NR_linux_ppoll                   0x010f
#define __NR_linux_brk                     0x000c
#define __NR_linux_sigreturn               0x000f
#define __NR_linux_lseek                   0x0008
#define __NR_linux_mmap                    0x0009
#define __NR_linux_msync                   0x001a
#define __NR_linux_mprotect                0x000a
#define __NR_linux_munmap                  0x000b
#define __NR_linux_sigaction               0x000d
#define __NR_linux_sigprocmask             0x000e
#define __NR_linux_ioctl                   0x0010
#define __NR_linux_pread                   0x0011
#define __NR_linux_pwrite                  0x0012
#define __NR_linux_readv                   0x0013
#define __NR_linux_writev                  0x0014
#define __NR_linux_access                  0x0015
#define __NR_linux_pipe                    0x0016
#define __NR_linux_select                  0x0017
#define __NR_linux_pselect6                0x010e
#define __NR_linux_sched_yield             0x0018
#define __NR_linux_mremap                  0x0019
#define __NR_linux_mincore                 0x001b
#define __NR_linux_madvise                 0x001c
#define __NR_linux_shmget                  0x001d
#define __NR_linux_shmat                   0x001e
#define __NR_linux_shmctl                  0x001f
#define __NR_linux_dup                     0x0020
#define __NR_linux_dup2                    0x0021
#define __NR_linux_pause                   0x0022
#define __NR_linux_nanosleep               0x0023
#define __NR_linux_getitimer               0x0024
#define __NR_linux_setitimer               0x0026
#define __NR_linux_alarm                   0x0025
#define __NR_linux_getpid                  0x0027
#define __NR_linux_sendfile                0x0028
#define __NR_linux_socket                  0x0029
#define __NR_linux_connect                 0x002a
#define __NR_linux_accept                  0x002b
#define __NR_linux_sendto                  0x002c
#define __NR_linux_recvfrom                0x002d
#define __NR_linux_sendmsg                 0x002e
#define __NR_linux_recvmsg                 0x002f
#define __NR_linux_shutdown                0x0030
#define __NR_linux_bind                    0x0031
#define __NR_linux_listen                  0x0032
#define __NR_linux_getsockname             0x0033
#define __NR_linux_getpeername             0x0034
#define __NR_linux_socketpair              0x0035
#define __NR_linux_setsockopt              0x0036
#define __NR_linux_getsockopt              0x0037
#define __NR_linux_fork                    0x0039
#define __NR_linux_vfork                   0x003a
#define __NR_linux_execve                  0x003b
#define __NR_linux_wait4                   0x003d
#define __NR_linux_kill                    0x003e
#define __NR_linux_clone                   0x0038
#define __NR_linux_tkill                   0x00c8
#define __NR_linux_futex                   0x00ca
#define __NR_linux_set_robust_list         0x0111
#define __NR_linux_get_robust_list         0x0112
#define __NR_linux_uname                   0x003f
#define __NR_linux_semget                  0x0040
#define __NR_linux_semop                   0x0041
#define __NR_linux_semctl                  0x0042
#define __NR_linux_shmdt                   0x0043
#define __NR_linux_msgget                  0x0044
#define __NR_linux_msgsnd                  0x0045
#define __NR_linux_msgrcv                  0x0046
#define __NR_linux_msgctl                  0x0047
#define __NR_linux_fcntl                   0x0048
#define __NR_linux_flock                   0x0049
#define __NR_linux_fsync                   0x004a
#define __NR_linux_fdatasync               0x004b
#define __NR_linux_truncate                0x004c
#define __NR_linux_ftruncate               0x004d
#define __NR_linux_getcwd                  0x004f
#define __NR_linux_chdir                   0x0050
#define __NR_linux_fchdir                  0x0051
#define __NR_linux_rename                  0x0052
#define __NR_linux_mkdir                   0x0053
#define __NR_linux_rmdir                   0x0054
#define __NR_linux_creat                   0x0055
#define __NR_linux_link                    0x0056
#define __NR_linux_unlink                  0x0057
#define __NR_linux_symlink                 0x0058
#define __NR_linux_readlink                0x0059
#define __NR_linux_chmod                   0x005a
#define __NR_linux_fchmod                  0x005b
#define __NR_linux_chown                   0x005c
#define __NR_linux_fchown                  0x005d
#define __NR_linux_lchown                  0x005e
#define __NR_linux_umask                   0x005f
#define __NR_linux_gettimeofday            0x0060
#define __NR_linux_getrlimit               0x0061
#define __NR_linux_getrusage               0x0062
#define __NR_linux_sysinfo                 0x0063
#define __NR_linux_times                   0x0064
#define __NR_linux_ptrace                  0x0065
#define __NR_linux_syslog                  0x0067
#define __NR_linux_getuid                  0x0066
#define __NR_linux_getgid                  0x0068
#define __NR_linux_getppid                 0x006e
#define __NR_linux_getpgrp                 0x006f
#define __NR_linux_setsid                  0x0070
#define __NR_linux_getsid                  0x007c
#define __NR_linux_getpgid                 0x0079
#define __NR_linux_setpgid                 0x006d
#define __NR_linux_geteuid                 0x006b
#define __NR_linux_getegid                 0x006c
#define __NR_linux_getgroups               0x0073
#define __NR_linux_setgroups               0x0074
#define __NR_linux_setreuid                0x0071
#define __NR_linux_setregid                0x0072
#define __NR_linux_setuid                  0x0069
#define __NR_linux_setgid                  0x006a
#define __NR_linux_setresuid               0x0075
#define __NR_linux_setresgid               0x0077
#define __NR_linux_getresuid               0x0076
#define __NR_linux_getresgid               0x0078
#define __NR_linux_sigpending              0x007f
#define __NR_linux_sigsuspend              0x0082
#define __NR_linux_sigaltstack             0x0083
#define __NR_linux_mknod                   0x0085
#define __NR_linux_mknodat                 0x0103
#define __NR_linux_statfs                  0x0089
#define __NR_linux_fstatfs                 0x008a
#define __NR_linux_getpriority             0x008c
#define __NR_linux_setpriority             0x008d
#define __NR_linux_mlock                   0x0095
#define __NR_linux_munlock                 0x0096
#define __NR_linux_mlockall                0x0097
#define __NR_linux_munlockall              0x0098
#define __NR_linux_setrlimit               0x00a0
#define __NR_linux_chroot                  0x00a1
#define __NR_linux_sync                    0x00a2
#define __NR_linux_acct                    0x00a3
#define __NR_linux_settimeofday            0x00a4
#define __NR_linux_mount                   0x00a5
#define __NR_linux_reboot                  0x00a9
#define __NR_linux_quotactl                0x00b3
#define __NR_linux_setfsuid                0x007a
#define __NR_linux_setfsgid                0x007b
#define __NR_linux_capget                  0x007d
#define __NR_linux_capset                  0x007e
#define __NR_linux_sigtimedwait            0x0080
#define __NR_linux_sigqueueinfo            0x0081
#define __NR_linux_personality             0x0087
#define __NR_linux_ustat                   0x0088
#define __NR_linux_sysfs                   0x008b
#define __NR_linux_sched_setparam          0x008e
#define __NR_linux_sched_getparam          0x008f
#define __NR_linux_sched_setscheduler      0x0090
#define __NR_linux_sched_getscheduler      0x0091
#define __NR_linux_sched_get_priority_max  0x0092
#define __NR_linux_sched_get_priority_min  0x0093
#define __NR_linux_sched_rr_get_interval   0x0094
#define __NR_linux_vhangup                 0x0099
#define __NR_linux_modify_ldt              0x009a
#define __NR_linux_pivot_root              0x009b
#define __NR_linux__sysctl                 0x009c
#define __NR_linux_prctl                   0x009d
#define __NR_linux_arch_prctl              0x009e
#define __NR_linux_adjtimex                0x009f
#define __NR_linux_umount2                 0x00a6
#define __NR_linux_swapon                  0x00a7
#define __NR_linux_swapoff                 0x00a8
#define __NR_linux_sethostname             0x00aa
#define __NR_linux_setdomainname           0x00ab
#define __NR_linux_iopl                    0x00ac
#define __NR_linux_ioperm                  0x00ad
#define __NR_linux_init_module             0x00af
#define __NR_linux_delete_module           0x00b0
#define __NR_linux_gettid                  0x00ba
#define __NR_linux_readahead               0x00bb
#define __NR_linux_setxattr                0x00bc
#define __NR_linux_fsetxattr               0x00be
#define __NR_linux_getxattr                0x00bf
#define __NR_linux_fgetxattr               0x00c1
#define __NR_linux_listxattr               0x00c2
#define __NR_linux_flistxattr              0x00c4
#define __NR_linux_removexattr             0x00c5
#define __NR_linux_fremovexattr            0x00c7
#define __NR_linux_lsetxattr               0x00bd
#define __NR_linux_lgetxattr               0x00c0
#define __NR_linux_llistxattr              0x00c3
#define __NR_linux_lremovexattr            0x00c6
#define __NR_linux_sched_setaffinity       0x00cb
#define __NR_linux_sched_getaffinity       0x00cc
#define __NR_linux_io_setup                0x00ce
#define __NR_linux_io_destroy              0x00cf
#define __NR_linux_io_getevents            0x00d0
#define __NR_linux_io_submit               0x00d1
#define __NR_linux_io_cancel               0x00d2
#define __NR_linux_lookup_dcookie          0x00d4
#define __NR_linux_epoll_create            0x00d5
#define __NR_linux_epoll_wait              0x00e8
#define __NR_linux_epoll_ctl               0x00e9
#define __NR_linux_getdents                0x00d9
#define __NR_linux_oldgetdents             0x004e
#define __NR_linux_set_tid_address         0x00da
#define __NR_linux_restart_syscall         0x00db
#define __NR_linux_semtimedop              0x00dc
#define __NR_linux_fadvise                 0x00dd
#define __NR_linux_timer_create            0x00de
#define __NR_linux_timer_settime           0x00df
#define __NR_linux_timer_gettime           0x00e0
#define __NR_linux_timer_getoverrun        0x00e1
#define __NR_linux_timer_delete            0x00e2
#define __NR_linux_clock_settime           0x00e3
#define __NR_linux_clock_gettime           0x00e4
#define __NR_linux_clock_getres            0x00e5
#define __NR_linux_clock_nanosleep         0x00e6
#define __NR_linux_tgkill                  0x00ea
#define __NR_linux_mbind                   0x00ed
#define __NR_linux_set_mempolicy           0x00ee
#define __NR_linux_get_mempolicy           0x00ef
#define __NR_linux_mq_open                 0x00f0
#define __NR_linux_mq_unlink               0x00f1
#define __NR_linux_mq_timedsend            0x00f2
#define __NR_linux_mq_timedreceive         0x00f3
#define __NR_linux_mq_notify               0x00f4
#define __NR_linux_mq_getsetattr           0x00f5
#define __NR_linux_kexec_load              0x00f6
#define __NR_linux_waitid                  0x00f7
#define __NR_linux_add_key                 0x00f8
#define __NR_linux_request_key             0x00f9
#define __NR_linux_keyctl                  0x00fa
#define __NR_linux_ioprio_set              0x00fb
#define __NR_linux_ioprio_get              0x00fc
#define __NR_linux_inotify_init            0x00fd
#define __NR_linux_inotify_add_watch       0x00fe
#define __NR_linux_inotify_rm_watch        0x00ff
#define __NR_linux_openat                  0x0101
#define __NR_linux_mkdirat                 0x0102
#define __NR_linux_fchownat                0x0104
#define __NR_linux_utime                   0x0084
#define __NR_linux_utimes                  0x00eb
#define __NR_linux_futimesat               0x0105
#define __NR_linux_fstatat                 0x0106
#define __NR_linux_unlinkat                0x0107
#define __NR_linux_renameat                0x0108
#define __NR_linux_linkat                  0x0109
#define __NR_linux_symlinkat               0x010a
#define __NR_linux_readlinkat              0x010b
#define __NR_linux_fchmodat                0x010c
#define __NR_linux_faccessat               0x010d
#define __NR_linux_unshare                 0x0110
#define __NR_linux_splice                  0x0113
#define __NR_linux_tee                     0x0114
#define __NR_linux_sync_file_range         0x0115
#define __NR_linux_vmsplice                0x0116
#define __NR_linux_migrate_pages           0x0100
#define __NR_linux_move_pages              0x0117
#define __NR_linux_preadv                  0x0127
#define __NR_linux_pwritev                 0x0128
#define __NR_linux_utimensat               0x0118
#define __NR_linux_fallocate               0x011d
#define __NR_linux_accept4                 0x0120
#define __NR_linux_dup3                    0x0124
#define __NR_linux_pipe2                   0x0125
#define __NR_linux_epoll_pwait             0x0119
#define __NR_linux_epoll_create1           0x0123
#define __NR_linux_perf_event_open         0x012a
#define __NR_linux_inotify_init1           0x0126
#define __NR_linux_tgsigqueueinfo          0x0129
#define __NR_linux_signalfd                0x011a
#define __NR_linux_signalfd4               0x0121
#define __NR_linux_eventfd                 0x011c
#define __NR_linux_eventfd2                0x0122
#define __NR_linux_timerfd_create          0x011b
#define __NR_linux_timerfd_settime         0x011e
#define __NR_linux_timerfd_gettime         0x011f
#define __NR_linux_recvmmsg                0x012b
#define __NR_linux_fanotify_init           0x012c
#define __NR_linux_fanotify_mark           0x012d
#define __NR_linux_prlimit                 0x012e
#define __NR_linux_name_to_handle_at       0x012f
#define __NR_linux_open_by_handle_at       0x0130
#define __NR_linux_clock_adjtime           0x0131
#define __NR_linux_syncfs                  0x0132
#define __NR_linux_sendmmsg                0x0133
#define __NR_linux_setns                   0x0134
#define __NR_linux_getcpu                  0x0135
#define __NR_linux_process_vm_readv        0x0136
#define __NR_linux_process_vm_writev       0x0137
#define __NR_linux_kcmp                    0x0138
#define __NR_linux_finit_module            0x0139
#define __NR_linux_sched_setattr           0x013a
#define __NR_linux_sched_getattr           0x013b
#define __NR_linux_renameat2               0x013c
#define __NR_linux_seccomp                 0x013d
#define __NR_linux_getrandom               0x013e
#define __NR_linux_memfd_create            0x013f
#define __NR_linux_kexec_file_load         0x0140
#define __NR_linux_bpf                     0x0141
#define __NR_linux_execveat                0x0142
#define __NR_linux_userfaultfd             0x0143
#define __NR_linux_membarrier              0x0144
#define __NR_linux_mlock2                  0x0145
#define __NR_linux_copy_file_range         0x0146
#define __NR_linux_preadv2                 0x0147
#define __NR_linux_pwritev2                0x0148
#define __NR_linux_pkey_mprotect           0x0149
#define __NR_linux_pkey_alloc              0x014a
#define __NR_linux_pkey_free               0x014b
#define __NR_linux_statx                   0x014c
#define __NR_linux_io_pgetevents           0x014d
#define __NR_linux_rseq                    0x014e
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_quotactl_fd             0x01bb
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be
#define __NR_linux_memfd_secret            0x01bf
#define __NR_linux_process_mrelease        0x01c0
#define __NR_linux_futex_waitv             0x01c1
#define __NR_linux_set_mempolicy_home_node 0x01c2

#elif defined(__aarch64__)

#define __NR_linux_exit                    0x005d
#define __NR_linux_exit_group              0x005e
#define __NR_linux_read                    0x003f
#define __NR_linux_write                   0x0040
#define __NR_linux_open                    0x00b4
#define __NR_linux_close                   0x0039
#define __NR_linux_stat                    0x004f
#define __NR_linux_fstat                   0x0050
#define __NR_linux_ppoll                   0x0049
#define __NR_linux_brk                     0x00d6
#define __NR_linux_sigreturn               0x008b
#define __NR_linux_lseek                   0x003e
#define __NR_linux_mmap                    0x00de
#define __NR_linux_msync                   0x00e3
#define __NR_linux_mprotect                0x00e2
#define __NR_linux_munmap                  0x00d7
#define __NR_linux_sigaction               0x0086
#define __NR_linux_sigprocmask             0x0087
#define __NR_linux_ioctl                   0x001d
#define __NR_linux_pread                   0x0043
#define __NR_linux_pwrite                  0x0044
#define __NR_linux_readv                   0x0041
#define __NR_linux_writev                  0x0042
#define __NR_linux_pselect6                0x0048
#define __NR_linux_sched_yield             0x007c
#define __NR_linux_mremap                  0x00d8
#define __NR_linux_mincore                 0x00e8
#define __NR_linux_madvise                 0x00e9
#define __NR_linux_shmget                  0x00c2
#define __NR_linux_shmat                   0x00c4
#define __NR_linux_shmctl                  0x00c3
#define __NR_linux_dup                     0x0017
#define __NR_linux_nanosleep               0x0065
#define __NR_linux_getitimer               0x0066
#define __NR_linux_setitimer               0x0067
#define __NR_linux_getpid                  0x00ac
#define __NR_linux_sendfile                0x0047
#define __NR_linux_socket                  0x00c6
#define __NR_linux_connect                 0x00cb
#define __NR_linux_accept                  0x00ca
#define __NR_linux_sendto                  0x00ce
#define __NR_linux_recvfrom                0x00cf
#define __NR_linux_sendmsg                 0x00d3
#define __NR_linux_recvmsg                 0x00d4
#define __NR_linux_shutdown                0x00d2
#define __NR_linux_bind                    0x00c8
#define __NR_linux_listen                  0x00c9
#define __NR_linux_getsockname             0x00cc
#define __NR_linux_getpeername             0x00cd
#define __NR_linux_socketpair              0x00c7
#define __NR_linux_setsockopt              0x00d0
#define __NR_linux_getsockopt              0x00d1
#define __NR_linux_execve                  0x00dd
#define __NR_linux_wait4                   0x0104
#define __NR_linux_kill                    0x0081
#define __NR_linux_clone                   0x00dc
#define __NR_linux_tkill                   0x0082
#define __NR_linux_futex                   0x0062
#define __NR_linux_set_robust_list         0x0063
#define __NR_linux_get_robust_list         0x0064
#define __NR_linux_uname                   0x00a0
#define __NR_linux_semget                  0x00be
#define __NR_linux_semop                   0x00c1
#define __NR_linux_semctl                  0x00bf
#define __NR_linux_shmdt                   0x00c5
#define __NR_linux_msgget                  0x00ba
#define __NR_linux_msgsnd                  0x00bd
#define __NR_linux_msgrcv                  0x00bc
#define __NR_linux_msgctl                  0x00bb
#define __NR_linux_fcntl                   0x0019
#define __NR_linux_flock                   0x0020
#define __NR_linux_fsync                   0x0052
#define __NR_linux_fdatasync               0x0053
#define __NR_linux_truncate                0x002d
#define __NR_linux_ftruncate               0x002e
#define __NR_linux_getcwd                  0x0011
#define __NR_linux_chdir                   0x0031
#define __NR_linux_fchdir                  0x0032
#define __NR_linux_unlink                  0x00b5
#define __NR_linux_fchmod                  0x0034
#define __NR_linux_fchown                  0x0037
#define __NR_linux_umask                   0x00a6
#define __NR_linux_gettimeofday            0x00a9
#define __NR_linux_getrlimit               0x00a3
#define __NR_linux_getrusage               0x00a5
#define __NR_linux_sysinfo                 0x00b3
#define __NR_linux_times                   0x0099
#define __NR_linux_ptrace                  0x0075
#define __NR_linux_syslog                  0x0074
#define __NR_linux_getuid                  0x00ae
#define __NR_linux_getgid                  0x00b0
#define __NR_linux_getppid                 0x00ad
#define __NR_linux_setsid                  0x009d
#define __NR_linux_getsid                  0x009c
#define __NR_linux_getpgid                 0x009b
#define __NR_linux_setpgid                 0x009a
#define __NR_linux_geteuid                 0x00af
#define __NR_linux_getegid                 0x00b1
#define __NR_linux_getgroups               0x009e
#define __NR_linux_setgroups               0x009f
#define __NR_linux_setreuid                0x0091
#define __NR_linux_setregid                0x008f
#define __NR_linux_setuid                  0x0092
#define __NR_linux_setgid                  0x0090
#define __NR_linux_setresuid               0x0093
#define __NR_linux_setresgid               0x0095
#define __NR_linux_getresuid               0x0094
#define __NR_linux_getresgid               0x0096
#define __NR_linux_sigpending              0x0088
#define __NR_linux_sigsuspend              0x0085
#define __NR_linux_sigaltstack             0x0084
#define __NR_linux_mknodat                 0x0021
#define __NR_linux_statfs                  0x002b
#define __NR_linux_fstatfs                 0x002c
#define __NR_linux_getpriority             0x008d
#define __NR_linux_setpriority             0x008c
#define __NR_linux_mlock                   0x00e4
#define __NR_linux_munlock                 0x00e5
#define __NR_linux_mlockall                0x00e6
#define __NR_linux_munlockall              0x00e7
#define __NR_linux_setrlimit               0x00a4
#define __NR_linux_chroot                  0x0033
#define __NR_linux_sync                    0x0051
#define __NR_linux_acct                    0x0059
#define __NR_linux_settimeofday            0x00aa
#define __NR_linux_mount                   0x0028
#define __NR_linux_reboot                  0x008e
#define __NR_linux_quotactl                0x003c
#define __NR_linux_setfsuid                0x0097
#define __NR_linux_setfsgid                0x0098
#define __NR_linux_capget                  0x005a
#define __NR_linux_capset                  0x005b
#define __NR_linux_sigtimedwait            0x0089
#define __NR_linux_sigqueueinfo            0x008a
#define __NR_linux_personality             0x005c
#define __NR_linux_sched_setparam          0x0076
#define __NR_linux_sched_getparam          0x0079
#define __NR_linux_sched_setscheduler      0x0077
#define __NR_linux_sched_getscheduler      0x0078
#define __NR_linux_sched_get_priority_max  0x007d
#define __NR_linux_sched_get_priority_min  0x007e
#define __NR_linux_sched_rr_get_interval   0x007f
#define __NR_linux_vhangup                 0x003a
#define __NR_linux_pivot_root              0x0029
#define __NR_linux_prctl                   0x00a7
#define __NR_linux_adjtimex                0x00ab
#define __NR_linux_umount2                 0x0027
#define __NR_linux_swapon                  0x00e0
#define __NR_linux_swapoff                 0x00e1
#define __NR_linux_sethostname             0x00a1
#define __NR_linux_setdomainname           0x00a2
#define __NR_linux_init_module             0x0069
#define __NR_linux_delete_module           0x006a
#define __NR_linux_gettid                  0x00b2
#define __NR_linux_readahead               0x00d5
#define __NR_linux_setxattr                0x0005
#define __NR_linux_fsetxattr               0x0007
#define __NR_linux_getxattr                0x0008
#define __NR_linux_fgetxattr               0x000a
#define __NR_linux_listxattr               0x000b
#define __NR_linux_flistxattr              0x000d
#define __NR_linux_removexattr             0x000e
#define __NR_linux_fremovexattr            0x0010
#define __NR_linux_lsetxattr               0x0006
#define __NR_linux_lgetxattr               0x0009
#define __NR_linux_llistxattr              0x000c
#define __NR_linux_lremovexattr            0x000f
#define __NR_linux_sched_setaffinity       0x007a
#define __NR_linux_sched_getaffinity       0x007b
#define __NR_linux_io_setup                0x0000
#define __NR_linux_io_destroy              0x0001
#define __NR_linux_io_getevents            0x0004
#define __NR_linux_io_submit               0x0002
#define __NR_linux_io_cancel               0x0003
#define __NR_linux_lookup_dcookie          0x0012
#define __NR_linux_epoll_ctl               0x0015
#define __NR_linux_getdents                0x003d
#define __NR_linux_set_tid_address         0x0060
#define __NR_linux_restart_syscall         0x0080
#define __NR_linux_semtimedop              0x00c0
#define __NR_linux_fadvise                 0x00df
#define __NR_linux_timer_create            0x006b
#define __NR_linux_timer_settime           0x006e
#define __NR_linux_timer_gettime           0x006c
#define __NR_linux_timer_getoverrun        0x006d
#define __NR_linux_timer_delete            0x006f
#define __NR_linux_clock_settime           0x0070
#define __NR_linux_clock_gettime           0x0071
#define __NR_linux_clock_getres            0x0072
#define __NR_linux_clock_nanosleep         0x0073
#define __NR_linux_tgkill                  0x0083
#define __NR_linux_mbind                   0x00eb
#define __NR_linux_set_mempolicy           0x00ed
#define __NR_linux_get_mempolicy           0x00ec
#define __NR_linux_mq_open                 0x00b4
#define __NR_linux_mq_unlink               0x00b5
#define __NR_linux_mq_timedsend            0x00b6
#define __NR_linux_mq_timedreceive         0x00b7
#define __NR_linux_mq_notify               0x00b8
#define __NR_linux_mq_getsetattr           0x00b9
#define __NR_linux_kexec_load              0x0068
#define __NR_linux_waitid                  0x005f
#define __NR_linux_add_key                 0x00d9
#define __NR_linux_request_key             0x00da
#define __NR_linux_keyctl                  0x00db
#define __NR_linux_ioprio_set              0x001e
#define __NR_linux_ioprio_get              0x001f
#define __NR_linux_openat                  0x0038
#define __NR_linux_mkdirat                 0x0022
#define __NR_linux_fchownat                0x0036
#define __NR_linux_utime                   0x0062
#define __NR_linux_utimes                  0x0058
#define __NR_linux_fstatat                 0x004f
#define __NR_linux_unlinkat                0x0023
#define __NR_linux_renameat                0x0026
#define __NR_linux_linkat                  0x0025
#define __NR_linux_symlinkat               0x0024
#define __NR_linux_readlinkat              0x004e
#define __NR_linux_fchmodat                0x0035
#define __NR_linux_faccessat               0x0030
#define __NR_linux_unshare                 0x0061
#define __NR_linux_splice                  0x004c
#define __NR_linux_tee                     0x004d
#define __NR_linux_sync_file_range         0x0054
#define __NR_linux_vmsplice                0x004b
#define __NR_linux_migrate_pages           0x00ee
#define __NR_linux_move_pages              0x00ef
#define __NR_linux_preadv                  0x0045
#define __NR_linux_pwritev                 0x0046
#define __NR_linux_utimensat               0x0058
#define __NR_linux_fallocate               0x002f
#define __NR_linux_accept4                 0x00f2
#define __NR_linux_dup3                    0x0018
#define __NR_linux_pipe2                   0x003b
#define __NR_linux_epoll_pwait             0x0016
#define __NR_linux_epoll_create1           0x0014
#define __NR_linux_perf_event_open         0x00f1
#define __NR_linux_inotify_init1           0x001a
#define __NR_linux_tgsigqueueinfo          0x00f0
#define __NR_linux_signalfd4               0x004a
#define __NR_linux_eventfd2                0x0013
#define __NR_linux_timerfd_create          0x0055
#define __NR_linux_timerfd_settime         0x0056
#define __NR_linux_timerfd_gettime         0x0057
#define __NR_linux_recvmmsg                0x00f3
#define __NR_linux_fanotify_init           0x0106
#define __NR_linux_fanotify_mark           0x0107
#define __NR_linux_prlimit                 0x0105
#define __NR_linux_name_to_handle_at       0x0108
#define __NR_linux_open_by_handle_at       0x0109
#define __NR_linux_clock_adjtime           0x010a
#define __NR_linux_syncfs                  0x010b
#define __NR_linux_sendmmsg                0x010d
#define __NR_linux_setns                   0x010c
#define __NR_linux_getcpu                  0x00a8
#define __NR_linux_process_vm_readv        0x010e
#define __NR_linux_process_vm_writev       0x010f
#define __NR_linux_kcmp                    0x0110
#define __NR_linux_finit_module            0x0111
#define __NR_linux_sched_setattr           0x0112
#define __NR_linux_sched_getattr           0x0113
#define __NR_linux_renameat2               0x0114
#define __NR_linux_seccomp                 0x0115
#define __NR_linux_getrandom               0x0116
#define __NR_linux_memfd_create            0x0117
#define __NR_linux_bpf                     0x0118
#define __NR_linux_execveat                0x0119
#define __NR_linux_userfaultfd             0x011a
#define __NR_linux_membarrier              0x011b
#define __NR_linux_mlock2                  0x011c
#define __NR_linux_copy_file_range         0x011d
#define __NR_linux_preadv2                 0x011e
#define __NR_linux_pwritev2                0x011f
#define __NR_linux_pkey_mprotect           0x0120
#define __NR_linux_pkey_alloc              0x0121
#define __NR_linux_pkey_free               0x0122
#define __NR_linux_statx                   0x0123
#define __NR_linux_io_pgetevents           0x0124
#define __NR_linux_rseq                    0x0125
#define __NR_linux_kexec_file_load         0x0126
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be

#endif /* __x86_64__ */

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/ok.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_OK_H_

#define F_OK 0
#define X_OK X_OK
#define W_OK W_OK
#define R_OK R_OK

COSMOPOLITAN_C_START_

extern const int X_OK;
extern const int W_OK;
extern const unsigned R_OK; /* warning: is sign bit on windows */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/personality.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PERSONALITY_H_

#define ADDR_COMPAT_LAYOUT 0x0200000
#define READ_IMPLIES_EXEC  0x0400000
#define ADDR_LIMIT_3GB     0x8000000
#define FDPIC_FUNCPTRS     0x0080000
#define STICKY_TIMEOUTS    0x4000000
#define MMAP_PAGE_ZERO     0x0100000
#define ADDR_LIMIT_32BIT   0x0800000
#define WHOLE_SECONDS      0x2000000
#define ADDR_NO_RANDOMIZE  0x0040000
#define SHORT_INODE        0x1000000
#define UNAME26            0x0020000



/*!BEGIN libc/sysv/consts/pf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PF_H_
COSMOPOLITAN_C_START_

extern const int PF_ALG;
extern const int PF_APPLETALK;
extern const int PF_ASH;
extern const int PF_ATMPVC;
extern const int PF_ATMSVC;
extern const int PF_AX25;
extern const int PF_BLUETOOTH;
extern const int PF_BRIDGE;
extern const int PF_CAIF;
extern const int PF_CAN;
extern const int PF_ECONET;
extern const int PF_FILE;
extern const int PF_IB;
extern const int PF_IEEE802154;
extern const int PF_INET6;
extern const int PF_INET;
extern const int PF_IPX;
extern const int PF_IRDA;
extern const int PF_ISDN;
extern const int PF_IUCV;
extern const int PF_KCM;
extern const int PF_KEY;
extern const int PF_LLC;
extern const int PF_LOCAL;
extern const int PF_MAX;
extern const int PF_MPLS;
extern const int PF_NETBEUI;
extern const int PF_NETLINK;
extern const int PF_NETROM;
extern const int PF_NFC;
extern const int PF_PACKET;
extern const int PF_PHONET;
extern const int PF_PPPOX;
extern const int PF_RDS;
extern const int PF_ROSE;
extern const int PF_ROUTE;
extern const int PF_RXRPC;
extern const int PF_SECURITY;
extern const int PF_SNA;
extern const int PF_TIPC;
extern const int PF_UNIX;
extern const int PF_UNSPEC;
extern const int PF_VSOCK;
extern const int PF_WANPIPE;
extern const int PF_X25;

#define PF_ALG        PF_ALG
#define PF_APPLETALK  PF_APPLETALK
#define PF_ASH        PF_ASH
#define PF_ATMPVC     PF_ATMPVC
#define PF_ATMSVC     PF_ATMSVC
#define PF_AX25       PF_AX25
#define PF_BLUETOOTH  PF_BLUETOOTH
#define PF_BRIDGE     PF_BRIDGE
#define PF_CAIF       PF_CAIF
#define PF_CAN        PF_CAN
#define PF_ECONET     PF_ECONET
#define PF_FILE       PF_FILE
#define PF_IB         PF_IB
#define PF_IEEE802154 PF_IEEE802154
#define PF_INET       PF_INET
#define PF_INET6      PF_INET6
#define PF_IPX        PF_IPX
#define PF_IRDA       PF_IRDA
#define PF_ISDN       PF_ISDN
#define PF_IUCV       PF_IUCV
#define PF_KCM        PF_KCM
#define PF_KEY        PF_KEY
#define PF_LLC        PF_LLC
#define PF_LOCAL      PF_LOCAL
#define PF_MAX        PF_MAX
#define PF_MPLS       PF_MPLS
#define PF_NETBEUI    PF_NETBEUI
#define PF_NETLINK    PF_NETLINK
#define PF_NETROM     PF_NETROM
#define PF_NFC        PF_NFC
#define PF_PACKET     PF_PACKET
#define PF_PHONET     PF_PHONET
#define PF_PPPOX      PF_PPPOX
#define PF_RDS        PF_RDS
#define PF_ROSE       PF_ROSE
#define PF_ROUTE      PF_ROUTE
#define PF_RXRPC      PF_RXRPC
#define PF_SECURITY   PF_SECURITY
#define PF_SNA        PF_SNA
#define PF_TIPC       PF_TIPC
#define PF_UNIX       PF_UNIX
#define PF_UNSPEC     PF_UNSPEC
#define PF_VSOCK      PF_VSOCK
#define PF_WANPIPE    PF_WANPIPE
#define PF_X25        PF_X25


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/poll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POLL_H_
COSMOPOLITAN_C_START_

extern const int16_t POLLERR;
extern const int16_t POLLHUP;
extern const int16_t POLLIN;
extern const int16_t POLLNVAL;
extern const int16_t POLLOUT;
extern const int16_t POLLPRI;
extern const int16_t POLLRDBAND;
extern const int16_t POLLRDHUP;
extern const int16_t POLLRDNORM;
extern const int16_t POLLWRBAND;
extern const int16_t POLLWRNORM;

#define INFTIM     (-1)
#define POLLERR    POLLERR
#define POLLHUP    POLLHUP
#define POLLIN     POLLIN
#define POLLNVAL   POLLNVAL
#define POLLOUT    POLLOUT
#define POLLPRI    POLLPRI
#define POLLRDBAND POLLRDBAND
#define POLLRDHUP  POLLRDHUP
#define POLLRDNORM POLLRDNORM
#define POLLWRBAND POLLWRBAND
#define POLLWRNORM POLLWRNORM


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_
COSMOPOLITAN_C_START_

extern const int POSIX_FADV_DONTNEED;
extern const int POSIX_FADV_NOREUSE;
extern const int POSIX_MADV_DONTNEED;
extern const int POSIX_MADV_DONTNEED;

#define POSIX_FADV_NORMAL     0
#define POSIX_FADV_RANDOM     1
#define POSIX_FADV_SEQUENTIAL 2
#define POSIX_FADV_WILLNEED   3

#define POSIX_FADV_DONTNEED POSIX_FADV_DONTNEED
#define POSIX_FADV_NOREUSE  POSIX_FADV_NOREUSE

#define POSIX_MADV_NORMAL     0
#define POSIX_MADV_RANDOM     1
#define POSIX_MADV_SEQUENTIAL 2
#define POSIX_MADV_WILLNEED   3

#define POSIX_MADV_DONTNEED POSIX_MADV_DONTNEED


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/pr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PR_H_

#define PR_GET_SECCOMP        21
#define PR_SET_SECCOMP        22
#define SECCOMP_MODE_DISABLED 0
#define SECCOMP_MODE_STRICT   1
#define SECCOMP_MODE_FILTER   2

#define PR_CAPBSET_READ 23
#define PR_CAPBSET_DROP 24

#define PR_SET_NO_NEW_PRIVS 38
#define PR_GET_NO_NEW_PRIVS 39

#define PR_SET_NAME 15
#define PR_GET_NAME 16

#define PR_GET_TSC     25
#define PR_SET_TSC     26
#define PR_TSC_ENABLE  1
#define PR_TSC_SIGSEGV 2

#define PR_GET_FPEXC        11
#define PR_SET_FPEXC        12
#define PR_FP_EXC_SW_ENABLE 0x80
#define PR_FP_EXC_DIV       0x010000
#define PR_FP_EXC_OVF       0x020000
#define PR_FP_EXC_UND       0x040000
#define PR_FP_EXC_RES       0x080000
#define PR_FP_EXC_INV       0x100000
#define PR_FP_EXC_DISABLED  0
#define PR_FP_EXC_NONRECOV  1
#define PR_FP_EXC_ASYNC     2
#define PR_FP_EXC_PRECISE   3

#define PR_MCE_KILL_CLEAR           0
#define PR_MCE_KILL_LATE            0
#define PR_SPEC_NOT_AFFECTED        0
#define PR_SPEC_STORE_BYPASS        0
#define PR_CAP_AMBIENT_IS_SET       1
#define PR_FPEMU_NOPRINT            1
#define PR_MCE_KILL_EARLY           1
#define PR_MCE_KILL_SET             1
#define PR_SET_MM_START_CODE        1
#define PR_SET_PDEATHSIG            1
#define PR_SPEC_PRCTL               1
#define PR_CAP_AMBIENT_RAISE        2
#define PR_FPEMU_SIGFPE             2
#define PR_GET_PDEATHSIG            2
#define PR_MCE_KILL_DEFAULT         2
#define PR_SET_MM_END_CODE          2
#define PR_SPEC_ENABLE              2
#define PR_CAP_AMBIENT_LOWER        3
#define PR_GET_DUMPABLE             3
#define PR_SET_MM_START_DATA        3
#define PR_CAP_AMBIENT_CLEAR_ALL    4
#define PR_SET_DUMPABLE             4
#define PR_SET_MM_END_DATA          4
#define PR_SPEC_DISABLE             4
#define PR_SET_MM_START_STACK       5
#define PR_SET_MM_START_BRK         6
#define PR_GET_KEEPCAPS             7
#define PR_SET_MM_BRK               7
#define PR_SET_KEEPCAPS             8
#define PR_SET_MM_ARG_START         8
#define PR_SPEC_FORCE_DISABLE       8
#define PR_GET_FPEMU                9
#define PR_SET_MM_ARG_END           9
#define PR_SET_FPEMU                10
#define PR_SET_MM_ENV_START         10
#define PR_GET_FPEXC                11
#define PR_SET_MM_ENV_END           11
#define PR_SET_FPEXC                12
#define PR_SET_MM_AUXV              12
#define PR_SET_MM_EXE_FILE          13
#define PR_SET_MM_MAP               14
#define PR_SET_MM_MAP_SIZE          15
#define PR_GET_TSC                  25
#define PR_SET_TSC                  26
#define PR_GET_SECUREBITS           27
#define PR_SET_SECUREBITS           28
#define PR_SET_TIMERSLACK           29
#define PR_GET_TIMERSLACK           30
#define PR_TASK_PERF_EVENTS_DISABLE 31
#define PR_TASK_PERF_EVENTS_ENABLE  0x20
#define PR_MCE_KILL                 33
#define PR_MCE_KILL_GET             34
#define PR_SET_MM                   35
#define PR_SET_CHILD_SUBREAPER      36
#define PR_GET_CHILD_SUBREAPER      37
#define PR_GET_TID_ADDRESS          40
#define PR_SET_THP_DISABLE          41
#define PR_GET_THP_DISABLE          42
#define PR_MPX_ENABLE_MANAGEMENT    43
#define PR_MPX_DISABLE_MANAGEMENT   44
#define PR_CAP_AMBIENT              47
#define PR_GET_SPECULATION_CTRL     52
#define PR_SET_SPECULATION_CTRL     53
#define PR_SET_TAGGED_ADDR_CTRL     55
#define PR_GET_TAGGED_ADDR_CTRL     56
#define PR_SET_IO_FLUSHER           57
#define PR_GET_IO_FLUSHER           58
#define PR_SET_PTRACER              0x59616d61
#define PR_SET_PTRACER_ANY          -1
#define PR_SET_VMA                  0x53564d41
#define PR_SET_VMA_ANON_NAME        0



/*!BEGIN libc/sysv/consts/prio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PRIO_H_
COSMOPOLITAN_C_START_

extern const int PRIO_MAX;
extern const int PRIO_MIN;
extern const int PRIO_PGRP;
extern const int PRIO_PROCESS;
extern const int PRIO_USER;

#define PRIO_PROCESS 0
#define PRIO_PGRP    1
#define PRIO_USER    2
#define PRIO_MIN     -20
#define PRIO_MAX     20

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/prot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PROT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int PROT_NONE;
extern const int PROT_READ;
extern const int PROT_WRITE;
extern const int PROT_EXEC;
extern const int PROT_GROWSDOWN;
extern const int PROT_GROWSUP;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define PROT_NONE  0
#define PROT_READ  1
#define PROT_WRITE 2
#define PROT_EXEC  4



/*!BEGIN libc/sysv/consts/pt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PT_H_


/*!BEGIN libc/sysv/consts/ptrace.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTRACE_H_
COSMOPOLITAN_C_START_

extern const int PTRACE_TRACEME;
extern const int PTRACE_PEEKTEXT;
extern const int PTRACE_PEEKDATA;
extern const int PTRACE_PEEKUSER;
extern const int PTRACE_POKETEXT;
extern const int PTRACE_POKEDATA;
extern const int PTRACE_POKEUSER;
extern const int PTRACE_CONT;
extern const int PTRACE_KILL;
extern const int PTRACE_SINGLESTEP;
extern const int PTRACE_GETREGS;
extern const int PTRACE_SETREGS;
extern const int PTRACE_GETFPREGS;
extern const int PTRACE_SETFPREGS;
extern const int PTRACE_ATTACH;
extern const int PTRACE_DETACH;
extern const int PTRACE_GETFPXREGS;
extern const int PTRACE_SETFPXREGS;
extern const int PTRACE_SYSCALL;
extern const int PTRACE_GETEVENTMSG;
extern const int PTRACE_GETSIGINFO;
extern const int PTRACE_SETOPTIONS;
extern const int PTRACE_SETSIGINFO;
extern const int PTRACE_GETREGSET;
extern const int PTRACE_GETSIGMASK;
extern const int PTRACE_INTERRUPT;
extern const int PTRACE_LISTEN;
extern const int PTRACE_PEEKSIGINFO;
extern const int PTRACE_SECCOMP_GET_FILTER;
extern const int PTRACE_SECCOMP_GET_METADATA;
extern const int PTRACE_SEIZE;
extern const int PTRACE_SETREGSET;
extern const int PTRACE_SETSIGMASK;
extern const int PTRACE_O_TRACESYSGOOD;
extern const int PTRACE_O_TRACEFORK;
extern const int PTRACE_O_TRACEVFORK;
extern const int PTRACE_O_TRACECLONE;
extern const int PTRACE_O_TRACEEXEC;
extern const int PTRACE_O_TRACEVFORKDONE;
extern const int PTRACE_O_TRACEEXIT;
extern const int PTRACE_O_TRACESECCOMP;
extern const int PTRACE_O_MASK;
extern const int PTRACE_EVENT_FORK;
extern const int PTRACE_EVENT_VFORK;
extern const int PTRACE_EVENT_CLONE;
extern const int PTRACE_EVENT_EXEC;
extern const int PTRACE_EVENT_VFORK_DONE;
extern const int PTRACE_EVENT_EXIT;
extern const int PTRACE_EVENT_STOP;
extern const int PTRACE_EVENT_SECCOMP;

COSMOPOLITAN_C_END_

#define PTRACE_TRACEME              PTRACE_TRACEME
#define PTRACE_PEEKTEXT             PTRACE_PEEKTEXT
#define PTRACE_PEEKDATA             PTRACE_PEEKDATA
#define PTRACE_PEEKUSER             PTRACE_PEEKUSER
#define PTRACE_POKETEXT             PTRACE_POKETEXT
#define PTRACE_POKEDATA             PTRACE_POKEDATA
#define PTRACE_POKEUSER             PTRACE_POKEUSER
#define PTRACE_CONT                 PTRACE_CONT
#define PTRACE_KILL                 PTRACE_KILL
#define PTRACE_SINGLESTEP           PTRACE_SINGLESTEP
#define PTRACE_GETREGS              PTRACE_GETREGS
#define PTRACE_SETREGS              PTRACE_SETREGS
#define PTRACE_GETFPREGS            PTRACE_GETFPREGS
#define PTRACE_SETFPREGS            PTRACE_SETFPREGS
#define PTRACE_ATTACH               PTRACE_ATTACH
#define PTRACE_DETACH               PTRACE_DETACH
#define PTRACE_GETFPXREGS           PTRACE_GETFPXREGS
#define PTRACE_SETFPXREGS           PTRACE_SETFPXREGS
#define PTRACE_SYSCALL              PTRACE_SYSCALL
#define PTRACE_GETEVENTMSG          PTRACE_GETEVENTMSG
#define PTRACE_GETSIGINFO           PTRACE_GETSIGINFO
#define PTRACE_SETOPTIONS           PTRACE_SETOPTIONS
#define PTRACE_SETSIGINFO           PTRACE_SETSIGINFO
#define PTRACE_GETREGSET            PTRACE_GETREGSET
#define PTRACE_GETSIGMASK           PTRACE_GETSIGMASK
#define PTRACE_INTERRUPT            PTRACE_INTERRUPT
#define PTRACE_LISTEN               PTRACE_LISTEN
#define PTRACE_PEEKSIGINFO          PTRACE_PEEKSIGINFO
#define PTRACE_SECCOMP_GET_FILTER   PTRACE_SECCOMP_GET_FILTER
#define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
#define PTRACE_SEIZE                PTRACE_SEIZE
#define PTRACE_SETREGSET            PTRACE_SETREGSET
#define PTRACE_SETSIGMASK           PTRACE_SETSIGMASK
#define PTRACE_O_TRACESYSGOOD       PTRACE_O_TRACESYSGOOD
#define PTRACE_O_TRACEFORK          PTRACE_O_TRACEFORK
#define PTRACE_O_TRACEVFORK         PTRACE_O_TRACEVFORK
#define PTRACE_O_TRACECLONE         PTRACE_O_TRACECLONE
#define PTRACE_O_TRACEEXEC          PTRACE_O_TRACEEXEC
#define PTRACE_O_TRACEVFORKDONE     PTRACE_O_TRACEVFORKDONE
#define PTRACE_O_TRACEEXIT          PTRACE_O_TRACEEXIT
#define PTRACE_O_TRACESECCOMP       PTRACE_O_TRACESECCOMP
#define PTRACE_O_MASK               PTRACE_O_MASK
#define PTRACE_EVENT_FORK           PTRACE_EVENT_FORK
#define PTRACE_EVENT_VFORK          PTRACE_EVENT_VFORK
#define PTRACE_EVENT_CLONE          PTRACE_EVENT_CLONE
#define PTRACE_EVENT_EXEC           PTRACE_EVENT_EXEC
#define PTRACE_EVENT_VFORK_DONE     PTRACE_EVENT_VFORK_DONE
#define PTRACE_EVENT_EXIT           PTRACE_EVENT_EXIT
#define PTRACE_EVENT_STOP           PTRACE_EVENT_STOP
#define PTRACE_EVENT_SECCOMP        PTRACE_EVENT_SECCOMP


#define PT_ATTACH      PTRACE_ATTACH
#define PT_CONTINUE    PTRACE_CONT
#define PT_DETACH      PTRACE_DETACH
#define PT_GETEVENTMSG PTRACE_GETEVENTMSG
#define PT_GETFPREGS   PTRACE_GETFPREGS
#define PT_GETFPXREGS  PTRACE_GETFPXREGS
#define PT_GETREGS     PTRACE_GETREGS
#define PT_GETSIGINFO  PTRACE_GETSIGINFO
#define PT_KILL        PTRACE_KILL
#define PT_READ_D      PTRACE_PEEKDATA
#define PT_READ_I      PTRACE_PEEKTEXT
#define PT_READ_U      PTRACE_PEEKUSER
#define PT_SETFPREGS   PTRACE_SETFPREGS
#define PT_SETFPXREGS  PTRACE_SETFPXREGS
#define PT_SETOPTIONS  PTRACE_SETOPTIONS
#define PT_SETREGS     PTRACE_SETREGS
#define PT_SETSIGINFO  PTRACE_SETSIGINFO
#define PT_STEP        PTRACE_SINGLESTEP
#define PT_SYSCALL     PTRACE_SYSCALL
#define PT_WRITE_D     PTRACE_POKEDATA
#define PT_WRITE_I     PTRACE_POKETEXT
#define PT_WRITE_U     PTRACE_POKEUSER



/*!BEGIN libc/sysv/consts/pty.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTY_H_
COSMOPOLITAN_C_START_

extern const int TIOCPKT;
extern const int TIOCPKT_DATA;
extern const int TIOCPKT_DOSTOP;
extern const int TIOCPKT_FLUSHREAD;
extern const int TIOCPKT_FLUSHWRITE;
extern const int TIOCPKT_IOCTL;
extern const int TIOCPKT_NOSTOP;
extern const int TIOCPKT_START;
extern const int TIOCPKT_STOP;

#define TIOCPKT_DATA       0x00
#define TIOCPKT_DOSTOP     0x01
#define TIOCPKT_FLUSHREAD  0x02
#define TIOCPKT_FLUSHWRITE 0x04
#define TIOCPKT_IOCTL      0x08
#define TIOCPKT_NOSTOP     0x10
#define TIOCPKT_START      0x20
#define TIOCPKT_STOP       0x40

#define TIOCPKT TIOCPKT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/read.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_READ_H_

#define READ_10 READ_10
#define READ_12 READ_12
#define READ_6 READ_6
#define READ_BLOCK_LIMITS READ_BLOCK_LIMITS
#define READ_BUFFER READ_BUFFER
#define READ_CAPACITY READ_CAPACITY
#define READ_DEFECT_DATA READ_DEFECT_DATA
#define READ_ELEMENT_STATUS READ_ELEMENT_STATUS
#define READ_LONG READ_LONG
#define READ_POSITION READ_POSITION
#define READ_REVERSE READ_REVERSE
#define READ_TOC READ_TOC

COSMOPOLITAN_C_START_

extern const long READ_10;
extern const long READ_12;
extern const long READ_6;
extern const long READ_BLOCK_LIMITS;
extern const long READ_BUFFER;
extern const long READ_CAPACITY;
extern const long READ_DEFECT_DATA;
extern const long READ_ELEMENT_STATUS;
extern const long READ_LONG;
extern const long READ_POSITION;
extern const long READ_REVERSE;
extern const long READ_TOC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/reboot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_REBOOT_H_
COSMOPOLITAN_C_START_

extern const unsigned RB_AUTOBOOT;
extern const unsigned RB_POWER_OFF;
extern const unsigned RB_POWERDOWN;
extern const unsigned RB_POWEROFF;
extern const unsigned RB_HALT_SYSTEM;
extern const unsigned RB_HALT;
extern const unsigned RB_SW_SUSPEND;
extern const unsigned RB_KEXEC;
extern const unsigned RB_ENABLE_CAD;
extern const unsigned RB_DISABLE_CAD;
extern const unsigned RB_NOSYNC;

#define RB_AUTOBOOT    RB_AUTOBOOT
#define RB_POWER_OFF   RB_POWER_OFF
#define RB_POWERDOWN   RB_POWERDOWN
#define RB_POWEROFF    RB_POWEROFF
#define RB_HALT_SYSTEM RB_HALT_SYSTEM
#define RB_HALT        RB_HALT
#define RB_SW_SUSPEND  RB_SW_SUSPEND
#define RB_KEXEC       RB_KEXEC
#define RB_ENABLE_CAD  RB_ENABLE_CAD
#define RB_DISABLE_CAD RB_DISABLE_CAD
#define RB_NOSYNC      RB_NOSYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlim.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIM_H_
COSMOPOLITAN_C_START_

extern const uint64_t RLIM_INFINITY;
extern const uint64_t RLIM_NLIMITS;
extern const uint64_t RLIM_SAVED_CUR;
extern const uint64_t RLIM_SAVED_MAX;

#define RLIM_INFINITY  RLIM_INFINITY
#define RLIM_NLIMITS   RLIM_NLIMITS
#define RLIM_SAVED_CUR RLIM_SAVED_CUR
#define RLIM_SAVED_MAX RLIM_SAVED_MAX


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlimit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIMIT_H_
COSMOPOLITAN_C_START_

extern const unsigned RLIMIT_AS;
extern const unsigned RLIMIT_CORE;
extern const unsigned RLIMIT_CPU;
extern const unsigned RLIMIT_DATA;
extern const unsigned RLIMIT_FSIZE;
extern const unsigned RLIMIT_LOCKS;
extern const unsigned RLIMIT_MEMLOCK;
extern const unsigned RLIMIT_MSGQUEUE;
extern const unsigned RLIMIT_NICE;
extern const unsigned RLIMIT_NOFILE;
extern const unsigned RLIMIT_NPROC;
extern const unsigned RLIMIT_NPTS;
extern const unsigned RLIMIT_RSS;
extern const unsigned RLIMIT_RTPRIO;
extern const unsigned RLIMIT_RTTIME;
extern const unsigned RLIMIT_SBSIZE;
extern const unsigned RLIMIT_SIGPENDING;
extern const unsigned RLIMIT_STACK;
extern const unsigned RLIMIT_SWAP;
extern const unsigned RLIMIT_VMEM;

#define RLIMIT_AS         RLIMIT_AS
#define RLIMIT_CORE       RLIMIT_CORE
#define RLIMIT_CPU        RLIMIT_CPU
#define RLIMIT_DATA       RLIMIT_DATA
#define RLIMIT_FSIZE      RLIMIT_FSIZE
#define RLIMIT_LOCKS      RLIMIT_LOCKS
#define RLIMIT_MEMLOCK    RLIMIT_MEMLOCK
#define RLIMIT_MSGQUEUE   RLIMIT_MSGQUEUE
#define RLIMIT_NICE       RLIMIT_NICE
#define RLIMIT_NOFILE     RLIMIT_NOFILE
#define RLIMIT_NPROC      RLIMIT_NPROC
#define RLIMIT_NPTS       RLIMIT_NPTS
#define RLIMIT_RSS        RLIMIT_RSS
#define RLIMIT_RTPRIO     RLIMIT_RTPRIO
#define RLIMIT_RTTIME     RLIMIT_RTTIME
#define RLIMIT_SBSIZE     RLIMIT_SBSIZE
#define RLIMIT_SIGPENDING RLIMIT_SIGPENDING
#define RLIMIT_STACK      RLIMIT_STACK
#define RLIMIT_SWAP       RLIMIT_SWAP
#define RLIMIT_VMEM       RLIMIT_VMEM

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rusage.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RUSAGE_H_
COSMOPOLITAN_C_START_

extern const int RUSAGE_THREAD;
extern const int RUSAGE_CHILDREN;
extern const int RUSAGE_BOTH;

#define RUSAGE_SELF     0
#define RUSAGE_CHILDREN RUSAGE_CHILDREN

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/s.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_S_H_

#define S_IFIFO  0010000 /* pipe */
#define S_IFCHR  0020000 /* character device */
#define S_IFDIR  0040000 /* directory */
#define S_IFBLK  0060000 /* block device */
#define S_IFREG  0100000 /* regular file */
#define S_IFLNK  0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
#define S_IFMT   0170000 /* mask of file types above */

#define S_ISVTX  0001000 /* THE STICKY BIT */
#define S_ISGID  0002000 /* the setgid bit */
#define S_ISUID  0004000 /* the setuid bit */
#define S_IXUSR  0000100 /* user  --x; just use octal */
#define S_IWUSR  0000200 /* user  -w-; just use octal */
#define S_IRUSR  0000400 /* user  r--; just use octal */
#define S_IRWXU  0000700 /* user  rwx; just use octal */
#define S_IXGRP  0000010 /* group --x; just use octal */
#define S_IWGRP  0000020 /* group -w-; just use octal */
#define S_IRGRP  0000040 /* group r--; just use octal */
#define S_IRWXG  0000070 /* group rwx; just use octal */
#define S_IXOTH  0000001 /* other --x; just use octal */
#define S_IWOTH  0000002 /* other -w-; just use octal */
#define S_IROTH  0000004 /* other r--; just use octal */
#define S_IRWXO  0000007 /* other rwx; just use octal */
#define S_IREAD  0000400 /* just use octal */
#define S_IEXEC  0000100 /* just use octal */
#define S_IWRITE 0000200 /* just use octal */
#define S_ISTXT  0001000 /* just use octal */

#define S_ISDIR(mode)  (((mode)&S_IFMT) == S_IFDIR)
#define S_ISCHR(mode)  (((mode)&S_IFMT) == S_IFCHR)
#define S_ISBLK(mode)  (((mode)&S_IFMT) == S_IFBLK)
#define S_ISREG(mode)  (((mode)&S_IFMT) == S_IFREG)
#define S_ISFIFO(mode) (((mode)&S_IFMT) == S_IFIFO)
#define S_ISLNK(mode)  (((mode)&S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)

#define S_BLKSIZE   512
#define ALLPERMS    (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO)
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)



/*!BEGIN libc/sysv/consts/sa.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SA_H_
COSMOPOLITAN_C_START_

extern const uint64_t SA_NOCLDSTOP;
extern const uint64_t SA_NOCLDWAIT;
extern const uint64_t SA_NODEFER;
extern const uint64_t SA_NOMASK;
extern const uint64_t SA_ONESHOT;
extern const uint64_t SA_ONSTACK;
extern const uint64_t SA_RESETHAND;
extern const uint64_t SA_RESTART;
extern const uint64_t SA_SIGINFO;

#define SA_NOCLDSTOP SA_NOCLDSTOP
#define SA_NOCLDWAIT SA_NOCLDWAIT
#define SA_NODEFER   SA_NODEFER
#define SA_NOMASK    SA_NOMASK
#define SA_ONESHOT   SA_ONESHOT
#define SA_ONSTACK   SA_ONSTACK
#define SA_RESETHAND SA_RESETHAND
#define SA_RESTART   SA_RESTART
#define SA_SIGINFO   SA_SIGINFO


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sched.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCHED_H_
COSMOPOLITAN_C_START_

extern const int SCHED_BATCH;
extern const int SCHED_DEADLINE;
extern const int SCHED_FIFO;
extern const int SCHED_IDLE;
extern const int SCHED_OTHER;
extern const int SCHED_RESET_ON_FORK;
extern const int SCHED_RR;

#define SCHED_BATCH         SCHED_BATCH
#define SCHED_DEADLINE      SCHED_DEADLINE
#define SCHED_FIFO          SCHED_FIFO
#define SCHED_IDLE          SCHED_IDLE
#define SCHED_NORMAL        SCHED_OTHER
#define SCHED_OTHER         SCHED_OTHER
#define SCHED_RESET_ON_FORK SCHED_RESET_ON_FORK
#define SCHED_RR            SCHED_RR


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/scm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCM_H_
COSMOPOLITAN_C_START_

extern const int SCM_TIMESTAMP;
extern const int SCM_CREDENTIALS;
extern const int SCM_TIMESTAMPING;
extern const int SCM_TIMESTAMPNS;
extern const int SCM_WIFI_STATUS;

COSMOPOLITAN_C_END_

#define SCM_RIGHTS       1
#define SCM_TIMESTAMP    SCM_TIMESTAMP
#define SCM_CREDENTIALS  SCM_CREDENTIALS
#define SCM_TIMESTAMPING SCM_TIMESTAMPING
#define SCM_TIMESTAMPNS  SCM_TIMESTAMPNS
#define SCM_WIFI_STATUS  SCM_WIFI_STATUS




/*!BEGIN libc/sysv/consts/seek.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SEEK_H_
COSMOPOLITAN_C_START_

extern const int SEEK_DATA;
extern const int SEEK_HOLE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SF_H_
COSMOPOLITAN_C_START_

struct sf_hdtr {
  struct iovec *headers;
  int hdr_cnt;
  struct iovec *trailers;
  int trl_cnt;
};

extern const int SF_MNOWAIT;
extern const int SF_NODISKIO;
extern const int SF_SYNC;

#define SF_MNOWAIT  SF_MNOWAIT
#define SF_NODISKIO SF_NODISKIO
#define SF_SYNC     SF_SYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHM_H_

#define SHM_ANON      SHM_ANON
#define SHM_DEST      SHM_DEST
#define SHM_EXEC      SHM_EXEC
#define SHM_HUGETLB   SHM_HUGETLB
#define SHM_INFO      SHM_INFO
#define SHM_LOCK      SHM_LOCK
#define SHM_LOCKED    SHM_LOCKED
#define SHM_NORESERVE SHM_NORESERVE
#define SHM_R         SHM_R
#define SHM_RDONLY    SHM_RDONLY
#define SHM_REMAP     SHM_REMAP
#define SHM_RND       SHM_RND
#define SHM_STAT      SHM_STAT
#define SHM_UNLOCK    SHM_UNLOCK
#define SHM_W         SHM_W

COSMOPOLITAN_C_START_

extern const char *SHM_ANON;
extern const int SHM_DEST;
extern const int SHM_EXEC;
extern const int SHM_HUGETLB;
extern const int SHM_INFO;
extern const int SHM_LOCK;
extern const int SHM_LOCKED;
extern const int SHM_NORESERVE;
extern const int SHM_R;
extern const int SHM_RDONLY;
extern const int SHM_REMAP;
extern const int SHM_RND;
extern const int SHM_STAT;
extern const int SHM_UNLOCK;
extern const int SHM_W;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shut.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHUT_H_
COSMOPOLITAN_C_START_

extern const int SHUT_RD;
extern const int SHUT_RDWR;
extern const int SHUT_WR;

#define SHUT_RD   0
#define SHUT_RDWR 2
#define SHUT_WR   1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sicode.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SICODE_H_
COSMOPOLITAN_C_START_

extern const int32_t SI_USER;
extern const int32_t SI_QUEUE;
extern const int32_t SI_TIMER;
extern const int32_t SI_MESGQ;
extern const int32_t SI_ASYNCIO;
extern const int32_t SI_TKILL;
extern const int32_t SI_ASYNCNL;
extern const int32_t SI_KERNEL;
extern const int32_t SI_NOINFO;
extern const int32_t CLD_EXITED;
extern const int32_t CLD_KILLED;
extern const int32_t CLD_DUMPED;
extern const int32_t CLD_TRAPPED;
extern const int32_t CLD_STOPPED;
extern const int32_t CLD_CONTINUED;
extern const int32_t TRAP_BRKPT;
extern const int32_t TRAP_TRACE;
extern const int32_t SEGV_MAPERR;
extern const int32_t SEGV_ACCERR;
extern const int32_t SEGV_PKUERR;
extern const int32_t FPE_INTDIV;
extern const int32_t FPE_INTOVF;
extern const int32_t FPE_FLTDIV;
extern const int32_t FPE_FLTOVF;
extern const int32_t FPE_FLTUND;
extern const int32_t FPE_FLTRES;
extern const int32_t FPE_FLTINV;
extern const int32_t FPE_FLTSUB;
extern const int32_t ILL_ILLOPC;
extern const int32_t ILL_ILLOPN;
extern const int32_t ILL_ILLADR;
extern const int32_t ILL_ILLTRP;
extern const int32_t ILL_PRVOPC;
extern const int32_t ILL_PRVREG;
extern const int32_t ILL_COPROC;
extern const int32_t ILL_BADSTK;
extern const int32_t BUS_ADRALN;
extern const int32_t BUS_ADRERR;
extern const int32_t BUS_OBJERR;
extern const int32_t BUS_MCEERR_AR;
extern const int32_t BUS_MCEERR_AO;
extern const int32_t BUS_OOMERR;
extern const int32_t POLL_IN;
extern const int32_t POLL_OUT;
extern const int32_t POLL_MSG;
extern const int32_t POLL_ERR;
extern const int32_t POLL_PRI;
extern const int32_t POLL_HUP;
extern const int32_t SYS_SECCOMP;
extern const int32_t SYS_USER_DISPATCH;

#define CLD_EXITED    1
#define CLD_KILLED    2
#define CLD_DUMPED    3
#define CLD_TRAPPED   4
#define CLD_STOPPED   5
#define CLD_CONTINUED 6
#define TRAP_BRKPT    1
#define TRAP_TRACE    2
#define SEGV_MAPERR   1
#define SEGV_ACCERR   2
#define ILL_ILLOPC    1
#define ILL_PRVREG    6
#define ILL_COPROC    7
#define ILL_BADSTK    8
#define BUS_ADRALN    1
#define BUS_ADRERR    2
#define BUS_OBJERR    3
#define POLL_IN       1
#define POLL_OUT      2
#define POLL_MSG      3
#define POLL_ERR      4
#define POLL_PRI      5
#define POLL_HUP      6

#define SI_USER           SI_USER
#define SI_QUEUE          SI_QUEUE
#define SI_TIMER          SI_TIMER
#define SI_MESGQ          SI_MESGQ
#define SI_ASYNCIO        SI_ASYNCIO
#define SI_TKILL          SI_TKILL
#define SI_ASYNCNL        SI_ASYNCNL
#define SI_KERNEL         SI_KERNEL
#define SI_NOINFO         SI_NOINFO
#define SEGV_PKUERR       SEGV_PKUERR
#define FPE_INTDIV        FPE_INTDIV
#define FPE_INTOVF        FPE_INTOVF
#define FPE_FLTDIV        FPE_FLTDIV
#define FPE_FLTOVF        FPE_FLTOVF
#define FPE_FLTUND        FPE_FLTUND
#define FPE_FLTRES        FPE_FLTRES
#define FPE_FLTINV        FPE_FLTINV
#define FPE_FLTSUB        FPE_FLTSUB
#define ILL_ILLOPN        ILL_ILLOPN
#define ILL_ILLADR        ILL_ILLADR
#define ILL_ILLTRP        ILL_ILLTRP
#define ILL_PRVOPC        ILL_PRVOPC
#define BUS_OOMERR        BUS_OOMERR
#define BUS_MCEERR_AR     BUS_MCEERR_AR
#define BUS_MCEERR_AO     BUS_MCEERR_AO
#define SYS_SECCOMP       SYS_SECCOMP
#define SYS_USER_DISPATCH SYS_USER_DISPATCH


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sig.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIG_H_
COSMOPOLITAN_C_START_

extern const int SIGABRT;
extern const int SIGALRM;
extern const int SIGBUS;
extern const int SIGTHR;
extern const int SIGCHLD;
extern const int SIGCONT;
extern const int SIGEMT;
extern const int SIGFPE;
extern const int SIGHUP;
extern const int SIGILL;
extern const int SIGINFO;
extern const int SIGINT;
extern const int SIGIO;
extern const int SIGIOT;
extern const int SIGKILL;
extern const int SIGPIPE;
extern const int SIGPOLL;
extern const int SIGPROF;
extern const int SIGPWR;
extern const int SIGQUIT;
extern const int SIGRTMAX;
extern const int SIGRTMIN;
extern const int SIGSEGV;
extern const int SIGSTKFLT;
extern const int SIGSTOP;
extern const int SIGSYS;
extern const int SIGTERM;
extern const int SIGTRAP;
extern const int SIGTSTP;
extern const int SIGTTIN;
extern const int SIGTTOU;
extern const int SIGUNUSED;
extern const int SIGURG;
extern const int SIGUSR1;
extern const int SIGUSR2;
extern const int SIGVTALRM;
extern const int SIGWINCH;
extern const int SIGXCPU;
extern const int SIGXFSZ;

extern const int SIG_BLOCK;
extern const int SIG_SETMASK;
extern const int SIG_UNBLOCK;

COSMOPOLITAN_C_END_

#define SIGABRT   6
#define SIGALRM   14
#define SIGFPE    8
#define SIGHUP    1
#define SIGILL    4
#define SIGINT    2
#define SIGIOT    6
#define SIGKILL   9
#define SIGPIPE   13
#define SIGPROF   27
#define SIGQUIT   3
#define SIGSEGV   11
#define SIGTERM   15
#define SIGTRAP   5
#define SIGTTIN   21
#define SIGTTOU   22
#define SIGVTALRM 26
#define SIGWINCH  28
#define SIGXCPU   24
#define SIGXFSZ   25

/*
 * - No macro is define for SIGIO and SIGPOLL in order to persuade
 *   ./configure scripts to favor using poll() or select() instead of
 *   interrupt-based i/o.
 *
 * - No macros are defined for SIGRTMIN and SIGRTMAX because the project
 *   hasn't fleshed them out yet.
 *
 * - SIGTHR doesn't have a macro since it's internal to posix threads.
 *
 * - SIGSTKFLT is Linux-only so no macro is defined.
 */

#define SIGBUS  SIGBUS
#define SIGCHLD SIGCHLD
#define SIGCONT SIGCONT
#define SIGEMT  SIGEMT
#define SIGINFO SIGINFO
#define SIGPWR  SIGPWR
#define SIGSTOP SIGSTOP
#define SIGSYS  SIGSYS
#define SIGTSTP SIGTSTP
#define SIGURG  SIGURG
#define SIGUSR1 SIGUSR1
#define SIGUSR2 SIGUSR2

#define SIG_BLOCK   SIG_BLOCK
#define SIG_SETMASK SIG_SETMASK
#define SIG_UNBLOCK SIG_UNBLOCK



/*!BEGIN libc/sysv/consts/sio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIO_H_
COSMOPOLITAN_C_START_

extern const unsigned long SIOCADDDLCI;
extern const unsigned long SIOCADDMULTI;
extern const unsigned long SIOCADDRT;
extern const unsigned long SIOCDARP;
extern const unsigned long SIOCDELDLCI;
extern const unsigned long SIOCDELMULTI;
extern const unsigned long SIOCDELRT;
extern const unsigned long SIOCDEVPRIVATE;
extern const unsigned long SIOCDIFADDR;
extern const unsigned long SIOCDRARP;
extern const unsigned long SIOCGARP;
extern const unsigned long SIOCGIFADDR;
extern const unsigned long SIOCGIFBR;
extern const unsigned long SIOCGIFBRDADDR;
extern const unsigned long SIOCGIFCONF;
extern const unsigned long SIOCGIFCOUNT;
extern const unsigned long SIOCGIFDSTADDR;
extern const unsigned long SIOCGIFENCAP;
extern const unsigned long SIOCGIFFLAGS;
extern const unsigned long SIOCGIFHWADDR;
extern const unsigned long SIOCGIFINDEX;
extern const unsigned long SIOCGIFMAP;
extern const unsigned long SIOCGIFMEM;
extern const unsigned long SIOCGIFMETRIC;
extern const unsigned long SIOCGIFMTU;
extern const unsigned long SIOCGIFNAME;
extern const unsigned long SIOCGIFNETMASK;
extern const unsigned long SIOCGIFPFLAGS;
extern const unsigned long SIOCGIFSLAVE;
extern const unsigned long SIOCGIFTXQLEN;
extern const unsigned long SIOCGPGRP;
extern const unsigned long SIOCGRARP;
extern const unsigned long SIOCGSTAMP;
extern const unsigned long SIOCGSTAMPNS;
extern const unsigned long SIOCPROTOPRIVATE;
extern const unsigned long SIOCRTMSG;
extern const unsigned long SIOCSARP;
extern const unsigned long SIOCSIFADDR;
extern const unsigned long SIOCSIFBR;
extern const unsigned long SIOCSIFBRDADDR;
extern const unsigned long SIOCSIFDSTADDR;
extern const unsigned long SIOCSIFENCAP;
extern const unsigned long SIOCSIFFLAGS;
extern const unsigned long SIOCSIFHWADDR;
extern const unsigned long SIOCSIFHWBROADCAST;
extern const unsigned long SIOCSIFLINK;
extern const unsigned long SIOCSIFMAP;
extern const unsigned long SIOCSIFMEM;
extern const unsigned long SIOCSIFMETRIC;
extern const unsigned long SIOCSIFMTU;
extern const unsigned long SIOCSIFNAME;
extern const unsigned long SIOCSIFNETMASK;
extern const unsigned long SIOCSIFPFLAGS;
extern const unsigned long SIOCSIFSLAVE;
extern const unsigned long SIOCSIFTXQLEN;
extern const unsigned long SIOCSPGRP;
extern const unsigned long SIOCSRARP;
extern const unsigned long SIOGIFINDEX;

#define SIOCGIFCONF    SIOCGIFCONF
#define SIOCGIFADDR    SIOCGIFADDR
#define SIOCSIFADDR    SIOCSIFADDR
#define SIOCDIFADDR    SIOCDIFADDR
#define SIOCGIFBRDADDR SIOCGIFBRDADDR
#define SIOCGIFNETMASK SIOCGIFNETMASK
#define SIOCGIFFLAGS   SIOCGIFFLAGS
#define SIOCSIFFLAGS   SIOCSIFFLAGS
#define SIOCGIFMETRIC  SIOCGIFMETRIC
#define SIOCSIFMETRIC  SIOCSIFMETRIC
#define SIOCSIFBRDADDR SIOCSIFBRDADDR
#define SIOCSIFNETMASK SIOCSIFNETMASK
#define SIOCGIFDSTADDR SIOCGIFDSTADDR
#define SIOCSIFDSTADDR SIOCSIFDSTADDR
#define SIOCGIFMTU     SIOCGIFMTU
#define SIOCSIFMTU     SIOCSIFMTU

#define SIOCGPGRP SIOCGPGRP
#define SIOCSPGRP SIOCSPGRP

#define SIOCADDMULTI SIOCADDMULTI
#define SIOCDELMULTI SIOCDELMULTI

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/so.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SO_H_

#define SO_DEBUG 1

COSMOPOLITAN_C_START_

extern const int SO_TYPE;
extern const int SO_ERROR;
extern const int SO_ACCEPTCONN;
extern const int SO_REUSEADDR;
extern const int SO_KEEPALIVE;
extern const int SO_DONTROUTE;
extern const int SO_BROADCAST;
extern const int SO_USELOOPBACK;
extern const int SO_LINGER;
extern const int SO_OOBINLINE;
extern const int SO_SNDBUF;
extern const int SO_RCVBUF;
extern const int SO_RCVTIMEO;
extern const int SO_SNDTIMEO;
extern const int SO_RCVLOWAT;
extern const int SO_SNDLOWAT;

#define SO_TYPE        SO_TYPE
#define SO_ERROR       SO_ERROR
#define SO_ACCEPTCONN  SO_ACCEPTCONN
#define SO_REUSEADDR   SO_REUSEADDR
#define SO_KEEPALIVE   SO_KEEPALIVE
#define SO_DONTROUTE   SO_DONTROUTE
#define SO_BROADCAST   SO_BROADCAST
#define SO_USELOOPBACK SO_USELOOPBACK
#define SO_LINGER      SO_LINGER
#define SO_OOBINLINE   SO_OOBINLINE
#define SO_SNDBUF      SO_SNDBUF
#define SO_RCVBUF      SO_RCVBUF
#define SO_RCVTIMEO    SO_RCVTIMEO
#define SO_SNDTIMEO    SO_SNDTIMEO
#define SO_RCVLOWAT    SO_RCVLOWAT
#define SO_SNDLOWAT    SO_SNDLOWAT

/*
 * this isn't available on windows, but it should be fine to use anyway,
 * setsockopt will return ENOPROTOOPT which is perfectly fine to ignore.
 */
extern const int SO_REUSEPORT;
#define SO_REUSEPORT SO_REUSEPORT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOCK_H_
COSMOPOLITAN_C_START_

extern const int SOCK_CLOEXEC;
extern const int SOCK_DCCP;
extern const int SOCK_DGRAM;
extern const int SOCK_NONBLOCK;
extern const int SOCK_PACKET;
extern const int SOCK_RAW;
extern const int SOCK_RDM;
extern const int SOCK_SEQPACKET;
extern const int SOCK_STREAM;

#define SOCK_STREAM    1
#define SOCK_DGRAM     2
#define SOCK_RAW       3
#define SOCK_RDM       4
#define SOCK_SEQPACKET 5
#define SOCK_CLOEXEC   SOCK_CLOEXEC
#define SOCK_NONBLOCK  SOCK_NONBLOCK

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sol.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOL_H_

#define SOL_IP     0
#define SOL_ICMP   1
#define SOL_TCP    6
#define SOL_UDP    17
#define SOL_IPV6   41
#define SOL_ICMPV6 58
#define SOL_RAW    255

COSMOPOLITAN_C_START_

extern const int SOL_SOCKET;
#define SOL_SOCKET SOL_SOCKET

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/splice.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SPLICE_H_
COSMOPOLITAN_C_START_

extern const unsigned int SPLICE_F_GIFT;
extern const unsigned int SPLICE_F_MORE;
extern const unsigned int SPLICE_F_MOVE;
extern const unsigned int SPLICE_F_NONBLOCK;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ss.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SS_H_
COSMOPOLITAN_C_START_

extern const int SS_DISABLE;
extern const int _SIGSTKSZ;
extern const int _MINSIGSTKSZ;

COSMOPOLITAN_C_END_

#define SIGSTKSZ    32768
#define MINSIGSTKSZ 32768 /* xnu defines the highest minimum */
#define SS_ONSTACK  1
#define SS_DISABLE  SS_DISABLE



/*!BEGIN libc/sysv/consts/st.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ST_H_
COSMOPOLITAN_C_START_

extern const int ST_APPEND;
extern const int ST_IMMUTABLE;
extern const int ST_MANDLOCK;
extern const int ST_NOATIME;
extern const int ST_NODEV;
extern const int ST_NODIRATIME;
extern const int ST_NOEXEC;
extern const int ST_NOSUID;
extern const int ST_RDONLY;
extern const int ST_RELATIME;
extern const int ST_SYNCHRONOUS;
extern const int ST_WRITE;

#define ST_APPEND      ST_APPEND
#define ST_IMMUTABLE   ST_IMMUTABLE
#define ST_MANDLOCK    ST_MANDLOCK
#define ST_NOATIME     ST_NOATIME
#define ST_NODEV       ST_NODEV
#define ST_NODIRATIME  ST_NODIRATIME
#define ST_NOEXEC      ST_NOEXEC
#define ST_NOSUID      ST_NOSUID
#define ST_RDONLY      ST_RDONLY
#define ST_RELATIME    ST_RELATIME
#define ST_SYNCHRONOUS ST_SYNCHRONOUS
#define ST_WRITE       ST_WRITE


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCP_H_
COSMOPOLITAN_C_START_

extern const int TCP_CC_INFO;
extern const int TCP_CONGESTION;
extern const int TCP_COOKIE_TRANSACTIONS;
extern const int TCP_CORK;
extern const int TCP_DEFER_ACCEPT;
extern const int TCP_FASTOPEN;
extern const int TCP_FASTOPEN_CONNECT;
extern const int TCP_INFO;
extern const int TCP_KEEPCNT;
extern const int TCP_KEEPIDLE;
extern const int TCP_KEEPINTVL;
extern const int TCP_LINGER2;
extern const int TCP_MAXSEG;
extern const int TCP_MD5SIG;
extern const int TCP_MD5SIG_MAXKEYLEN;
extern const int TCP_NODELAY;
extern const int TCP_NOTSENT_LOWAT;
extern const int TCP_QUEUE_SEQ;
extern const int TCP_QUICKACK;
extern const int TCP_REPAIR;
extern const int TCP_REPAIR_OPTIONS;
extern const int TCP_REPAIR_QUEUE;
extern const int TCP_SAVED_SYN;
extern const int TCP_SAVE_SYN;
extern const int TCP_SYNCNT;
extern const int TCP_THIN_DUPACK;
extern const int TCP_THIN_LINEAR_TIMEOUTS;
extern const int TCP_TIMESTAMP;
extern const int TCP_ULP;
extern const int TCP_USER_TIMEOUT;
extern const int TCP_WINDOW_CLAMP;

#define TCP_NODELAY              1
#define TCP_CC_INFO              TCP_CC_INFO
#define TCP_CONGESTION           TCP_CONGESTION
#define TCP_COOKIE_TRANSACTIONS  TCP_COOKIE_TRANSACTIONS
#define TCP_CORK                 TCP_CORK
#define TCP_DEFER_ACCEPT         TCP_DEFER_ACCEPT
#define TCP_FASTOPEN             TCP_FASTOPEN
#define TCP_FASTOPEN_CONNECT     TCP_FASTOPEN_CONNECT
#define TCP_INFO                 TCP_INFO
#define TCP_KEEPCNT              TCP_KEEPCNT
#define TCP_KEEPIDLE             TCP_KEEPIDLE
#define TCP_KEEPINTVL            TCP_KEEPINTVL
#define TCP_LINGER2              TCP_LINGER2
#define TCP_MAXSEG               TCP_MAXSEG
#define TCP_MD5SIG               TCP_MD5SIG
#define TCP_MD5SIG_MAXKEYLEN     TCP_MD5SIG_MAXKEYLEN
#define TCP_NOTSENT_LOWAT        TCP_NOTSENT_LOWAT
#define TCP_QUEUE_SEQ            TCP_QUEUE_SEQ
#define TCP_QUICKACK             TCP_QUICKACK
#define TCP_REPAIR               TCP_REPAIR
#define TCP_REPAIR_OPTIONS       TCP_REPAIR_OPTIONS
#define TCP_REPAIR_QUEUE         TCP_REPAIR_QUEUE
#define TCP_SAVED_SYN            TCP_SAVED_SYN
#define TCP_SAVE_SYN             TCP_SAVE_SYN
#define TCP_SYNCNT               TCP_SYNCNT
#define TCP_THIN_DUPACK          TCP_THIN_DUPACK
#define TCP_THIN_LINEAR_TIMEOUTS TCP_THIN_LINEAR_TIMEOUTS
#define TCP_TIMESTAMP            TCP_TIMESTAMP
#define TCP_ULP                  TCP_ULP
#define TCP_USER_TIMEOUT         TCP_USER_TIMEOUT
#define TCP_WINDOW_CLAMP         TCP_WINDOW_CLAMP


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcpopt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCPOPT_H_

#define TCPOPT_EOL            0
#define TCPOPT_NOP            1
#define TCPOPT_MAXSEG         2
#define TCPOPT_WINDOW         3
#define TCPOPT_SACK_PERMITTED 4
#define TCPOPT_SACK           5
#define TCPOPT_TIMESTAMP      8

#define TCPOLEN_SACK_PERMITTED 2
#define TCPOLEN_WINDOW         3
#define TCPOLEN_MAXSEG         4
#define TCPOLEN_TIMESTAMP      10



/*!BEGIN libc/sysv/consts/th.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TH_H_

#define TH_FIN  1
#define TH_SYN  2
#define TH_RST  4
#define TH_PUSH 8
#define TH_URG  32
#define TH_ACK  16



/*!BEGIN libc/sysv/consts/timer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TIMER_H_

#define TIMER_ABSTIME 1



/*!BEGIN libc/sysv/consts/uc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UC_H_
COSMOPOLITAN_C_START_

#define UC_FP_XSTATE         1
#define UC_SIGCONTEXT_SS     2
#define UC_STRICT_RESTORE_SS 4

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/unmount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const int MNT_FORCE;
extern const int MNT_DETACH;
extern const int MNT_EXPIRE;
extern const int UMOUNT_NOFOLLOW;
extern const int MNT_BYFSID;

COSMOPOLITAN_C_END_

#define MNT_FORCE       MNT_FORCE
#define MNT_DETACH      MNT_DETACH
#define MNT_EXPIRE      MNT_EXPIRE
#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW
#define MNT_BYFSID      MNT_BYFSID



/*!BEGIN libc/sysv/consts/utime.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UTIME_H_
COSMOPOLITAN_C_START_

extern const int UTIME_NOW;
extern const int UTIME_OMIT;

COSMOPOLITAN_C_END_

#define UTIME_NOW  UTIME_NOW
#define UTIME_OMIT UTIME_OMIT




/*!BEGIN libc/sysv/consts/waitid.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_WAITID_H_
COSMOPOLITAN_C_START_

extern const int WEXITED;
extern const int WSTOPPED;
extern const int WNOWAIT;

#define WEXITED  WEXITED
#define WSTOPPED WSTOPPED
#define WNOWAIT  WNOWAIT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/xopen.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_XOPEN_H_

#define _XOPEN_IOV_MAX  16
#define _XOPEN_ENH_I18N 1
#define _XOPEN_UNIX     1
#define _XOPEN_NAME_MAX 63
#define _XOPEN_PATH_MAX 1024
#define _XOPEN_SOURCE   700



/*!BEGIN libc/thread/semaphore.h */

#define COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
COSMOPOLITAN_C_START_

#define SEM_FAILED        ((sem_t *)0)
#define SEM_MAGIC_NAMED   0xDEADBEEFu
#define SEM_MAGIC_UNNAMED 0xFEEDABEEu
#define SEM_MAGIC_KERNEL  0xCAFEBABEu

typedef struct {
  union {
    struct {
      _Atomic(int) sem_value;
      _Atomic(int) sem_waiters;
      _Atomic(int) sem_prefs; /* named only */
      unsigned sem_magic;
      int64_t sem_dev;     /* named only */
      int64_t sem_ino;     /* named only */
      int sem_pid;         /* unnamed only */
      char sem_lazydelete; /* named only */
      char sem_pshared;
      int *sem_kernel;
    };
    void *sem_space[32];
  };
} sem_t;

int sem_init(sem_t *, int, unsigned) libcesque;
int sem_destroy(sem_t *) libcesque;
int sem_post(sem_t *) libcesque;
int sem_wait(sem_t *) libcesque;
int sem_trywait(sem_t *) libcesque;
int sem_timedwait(sem_t *, const struct timespec *) libcesque;
int sem_getvalue(sem_t *, int *) libcesque;
sem_t *sem_open(const char *, int, ...) libcesque;
int sem_close(sem_t *) libcesque;
int sem_unlink(const char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/thread.h */

#define COSMOPOLITAN_LIBC_THREAD_THREAD_H_

#define PTHREAD_KEYS_MAX              128
#define PTHREAD_STACK_MIN             65536
#define PTHREAD_DESTRUCTOR_ITERATIONS 4

#define PTHREAD_BARRIER_SERIAL_THREAD 31337

#define PTHREAD_MUTEX_DEFAULT    0
#define PTHREAD_MUTEX_NORMAL     0
#define PTHREAD_MUTEX_RECURSIVE  1
#define PTHREAD_MUTEX_ERRORCHECK 2
#define PTHREAD_MUTEX_STALLED    0
#define PTHREAD_MUTEX_ROBUST     1

#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED  1

#define PTHREAD_CREATE_JOINABLE 0
#define PTHREAD_CREATE_DETACHED 1

#define PTHREAD_INHERIT_SCHED  0
#define PTHREAD_EXPLICIT_SCHED 1

#define PTHREAD_CANCELED ((void *)-1)

#define PTHREAD_CANCEL_ENABLE  0
#define PTHREAD_CANCEL_DISABLE 1
#define PTHREAD_CANCEL_MASKED  2

#define PTHREAD_CANCEL_DEFERRED     0
#define PTHREAD_CANCEL_ASYNCHRONOUS 1

#define PTHREAD_SCOPE_SYSTEM  0
#define PTHREAD_SCOPE_PROCESS 1

#define PTHREAD_ATTR_NO_SIGMASK_NP -1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

#define PTHREAD_ONCE_INIT          _PTHREAD_INIT
#define PTHREAD_COND_INITIALIZER   _PTHREAD_INIT
#define PTHREAD_RWLOCK_INITIALIZER _PTHREAD_INIT
#define PTHREAD_MUTEX_INITIALIZER  _PTHREAD_INIT
#define _PTHREAD_INIT \
  { 0 }

typedef uintptr_t pthread_t;
typedef int pthread_id_np_t;
typedef char pthread_condattr_t;
typedef char pthread_rwlockattr_t;
typedef char pthread_barrierattr_t;
typedef unsigned pthread_key_t;
typedef void (*pthread_key_dtor)(void *);

typedef struct pthread_once_s {
  _Atomic(uint32_t) _lock;
} pthread_once_t;

typedef struct pthread_spinlock_s {
  _Atomic(int) _lock;
} pthread_spinlock_t;

typedef struct pthread_mutex_s {
  _Atomic(int32_t) _lock;
  unsigned _type : 2;
  unsigned _pshared : 1;
  unsigned _depth : 6;
  unsigned _owner : 23;
  long _pid;
} pthread_mutex_t;

typedef struct pthread_mutexattr_s {
  char _type;
  char _pshared;
} pthread_mutexattr_t;

typedef struct pthread_cond_s {
  void *_nsync[2];
} pthread_cond_t;

typedef struct pthread_rwlock_s {
  void *_nsync[2];
  char _iswrite;
} pthread_rwlock_t;

typedef struct pthread_barrier_s {
  void *_nsync;
} pthread_barrier_t;

typedef struct pthread_attr_s {
  char __detachstate;
  char __inheritsched;
  char __havesigmask;
  int __schedparam;
  int __schedpolicy;
  int __contentionscope;
  int __guardsize;
  size_t __stacksize;
  uint64_t __sigmask;
  void *__stackaddr;
} pthread_attr_t;

struct _pthread_cleanup_buffer {
  void (*__routine)(void *);
  void *__arg;
  int __canceltype;
  struct _pthread_cleanup_buffer *__prev;
};

/* clang-format off */

int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) dontthrow;
int pthread_attr_destroy(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_getdetachstate(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getguardsize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_getinheritsched(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getschedpolicy(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getscope(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getstack(const pthread_attr_t *, void **, size_t *) libcesque paramsnonnull();
int pthread_attr_getstacksize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_init(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_setdetachstate(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setguardsize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_attr_setinheritsched(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setschedpolicy(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setscope(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setstack(pthread_attr_t *, void *, size_t) libcesque paramsnonnull((1));
int pthread_attr_setstacksize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_barrier_destroy(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned) libcesque paramsnonnull((1));
int pthread_barrier_wait(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrierattr_destroy(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *) libcesque paramsnonnull();
int pthread_barrierattr_init(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int) libcesque paramsnonnull();
int pthread_cancel(pthread_t) libcesque;
int pthread_cond_broadcast(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_destroy(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *) libcesque paramsnonnull((1));
int pthread_cond_signal(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *) libcesque paramsnonnull();
int pthread_condattr_destroy(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_getpshared(const pthread_condattr_t *, int *) libcesque paramsnonnull();
int pthread_condattr_init(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_setpshared(pthread_condattr_t *, int) libcesque paramsnonnull();
int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *) dontthrow paramsnonnull((1));
int pthread_detach(pthread_t) libcesque;
int pthread_equal(pthread_t, pthread_t) libcesque;
int pthread_getattr_np(pthread_t, pthread_attr_t *) libcesque paramsnonnull();
int pthread_getname_np(pthread_t, char *, size_t) libcesque paramsnonnull();
int pthread_getunique_np(pthread_t, pthread_id_np_t *) libcesque paramsnonnull();
int pthread_join(pthread_t, void **) libcesque;
int pthread_key_create(pthread_key_t *, pthread_key_dtor) libcesque paramsnonnull((1));
int pthread_key_delete(pthread_key_t) libcesque;
int pthread_kill(pthread_t, int) libcesque;
int pthread_mutex_consistent(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_destroy(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *) libcesque paramsnonnull((1));
int pthread_mutex_lock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_trylock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_unlock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutexattr_destroy(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_init(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_mutexattr_settype(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_once(pthread_once_t *, void (*)(void)) paramsnonnull();
int pthread_orphan_np(void) libcesque;
int pthread_rwlock_destroy(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *) libcesque paramsnonnull((1));
int pthread_rwlock_rdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_tryrdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_trywrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_unlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_wrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, int *) libcesque paramsnonnull();
int pthread_rwlockattr_init(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int) libcesque paramsnonnull();
int pthread_setcancelstate(int, int *) libcesque;
int pthread_setcanceltype(int, int *) libcesque;
int pthread_setname_np(pthread_t, const char *) libcesque paramsnonnull();
int pthread_setschedprio(pthread_t, int) libcesque;
int pthread_setspecific(pthread_key_t, const void *) libcesque;
int pthread_spin_destroy(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_init(pthread_spinlock_t *, int) libcesque paramsnonnull();
int pthread_spin_lock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_trylock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_unlock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_testcancel_np(void) libcesque;
int pthread_tryjoin_np(pthread_t, void **) libcesque;
int pthread_yield_np(void) libcesque;
int pthread_yield(void) libcesque;
pthread_id_np_t pthread_getthreadid_np(void) libcesque;
pthread_t pthread_self(void) libcesque pureconst;
void *pthread_getspecific(pthread_key_t) libcesque;
void pthread_cleanup_pop(struct _pthread_cleanup_buffer *, int) libcesque paramsnonnull();
void pthread_cleanup_push(struct _pthread_cleanup_buffer *, void (*)(void *), void *) libcesque paramsnonnull((1));
void pthread_exit(void *) libcesque wontreturn;
void pthread_testcancel(void) libcesque;
void pthread_pause_np(void) libcesque;

/* clang-format on */

#define pthread_cleanup_push(routine, arg)  \
  {                                         \
    struct _pthread_cleanup_buffer _buffer; \
    pthread_cleanup_push(&_buffer, (routine), (arg));

#define pthread_cleanup_pop(execute)        \
  pthread_cleanup_pop(&_buffer, (execute)); \
  }

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/thread/thread2.h */

#define COSMOPOLITAN_LIBC_INTRIN_PTHREAD2_H_
COSMOPOLITAN_C_START_
/* clang-format off */

int pthread_attr_getschedparam(const pthread_attr_t *, struct sched_param *) libcesque paramsnonnull();
int pthread_attr_getsigmask_np(const pthread_attr_t *, sigset_t *) libcesque paramsnonnull((1));
int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *) libcesque paramsnonnull();
int pthread_attr_setsigmask_np(pthread_attr_t *, const sigset_t *) libcesque paramsnonnull((1));
int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *) libcesque paramsnonnull((1, 2));
int pthread_getaffinity_np(pthread_t, size_t, cpu_set_t *) libcesque paramsnonnull();
int pthread_getschedparam(pthread_t, int *, struct sched_param *) libcesque paramsnonnull();
int pthread_setaffinity_np(pthread_t, size_t, const cpu_set_t *) libcesque paramsnonnull();
int pthread_setschedparam(pthread_t, int, const struct sched_param *) libcesque paramsnonnull();
int pthread_timedjoin_np(pthread_t, void **, struct timespec *) libcesque;

/* clang-format off */
COSMOPOLITAN_C_END_
/* clang-format on */


/*!BEGIN libc/thread/threads.h */

#define COSMOPOLITAN_LIBC_THREAD_THREADS_H_
COSMOPOLITAN_C_START_

#if !defined(__cplusplus) &&                   \
    (!(defined(__GNUC__) && __GNUC__ >= 13) || \
     !(defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L))
#define thread_local _Thread_local
#endif

#define TSS_DTOR_ITERATIONS 4

enum {
  thrd_success = 0,
  thrd_busy = 1,
  thrd_error = 2,
  thrd_nomem = 3,
  thrd_timedout = 4,
};

enum {
  mtx_plain = 0,
  mtx_recursive = 1,
  mtx_timed = 2,
};

typedef uintptr_t thrd_t;
typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *);
typedef _Atomic(uint32_t) once_flag;

void call_once(once_flag *, void (*)(void));
int thrd_create(thrd_t *, thrd_start_t, void *);
void thrd_exit(int) wontreturn;
int thrd_join(thrd_t, int *);
int thrd_detach(thrd_t);
int thrd_equal(thrd_t, thrd_t);
thrd_t thrd_current(void);
void thrd_yield(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/tls.h */

#define COSMOPOLITAN_LIBC_THREAD_TLS_H_

#define TLS_ALIGNMENT 64

#define TIB_FLAG_VFORKED 1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct CosmoFtrace {   /* 16 */
  char ft_once;        /*  0 */
  char ft_noreentry;   /*  1 */
  int ft_skew;         /*  4 */
  int64_t ft_lastaddr; /*  8 */
};

/* NOTE: update aarch64 libc/errno.h if sizeof changes */
/* NOTE: update aarch64 libc/proc/vfork.S if sizeof changes */
/* NOTE: update aarch64 libc/nexgen32e/gc.S if sizeof changes */
struct CosmoTib {
  struct CosmoTib *tib_self;      /* 0x00 */
  struct CosmoFtrace tib_ftracer; /* 0x08 */
  void *tib_garbages;             /* 0x18 */
  intptr_t tib_locale;            /* 0x20 */
  intptr_t tib_pthread;           /* 0x28 */
  struct CosmoTib *tib_self2;     /* 0x30 */
  _Atomic(int32_t) tib_tid;       /* 0x38 transitions -1 → tid → 0 */
  int32_t tib_errno;              /* 0x3c */
  uint64_t tib_flags;             /* 0x40 */
  int tib_ftrace;                 /* inherited */
  int tib_strace;                 /* inherited */
  _Atomic(uint64_t) tib_sigmask;  /* inherited */
  _Atomic(uint64_t) tib_sigpending;
  _Atomic(uint64_t) tib_syshand; /* win32=kThread, xnusilicon=pthread_t */
  char *tib_sigstack_addr;
  uint32_t tib_sigstack_size;
  uint32_t tib_sigstack_flags;
  void **tib_keys;
  void *tib_nsync;
  void *tib_todo[7];
} __attribute__((__aligned__(64)));

extern int __threaded;
extern char __tls_morphed;
extern unsigned __tls_index;

char *_mktls(struct CosmoTib **) libcesque;
void __bootstrap_tls(struct CosmoTib *, char *) libcesque;

#ifdef __x86_64__
extern char __tls_enabled;
#define __tls_enabled_set(x) __tls_enabled = x
#elif defined(__aarch64__)
#define __tls_enabled        true
#define __tls_enabled_set(x) (void)0
#else
#error "unsupported architecture"
#endif

void __set_tls(struct CosmoTib *) libcesque;

/**
 * Returns location of thread information block.
 *
 * This can't be used in privileged functions.
 */
forceinline pureconst struct CosmoTib *__get_tls(void) {
#ifdef __chibicc__
  return 0;
#elif __x86_64__
  struct CosmoTib *__tib;
  __asm__("mov\t%%gs:0x30,%0" : "=r"(__tib));
  return __tib;
#elif defined(__aarch64__)
  register struct CosmoTib *__tls __asm__("x28");
  return __tls - 1;
#endif
}

#ifdef __x86_64__
#define __adj_tls(tib) (tib)
#elif defined(__aarch64__)
#define __adj_tls(tib) ((struct CosmoTib *)(tib) + 1)
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/tinymath/emod.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMOD_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmod()
 */
#define emod(x, y)                            \
  ({                                          \
    double __x = x;                           \
    double __y = y;                           \
    __x - fabs(__y) * floor(__x / fabs(__y)); \
  })



/*!BEGIN libc/tinymath/emodl.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmodl()
 */
#define emodl(x, y)                              \
  ({                                             \
    long double __x = x;                         \
    long double __y = y;                         \
    __x - fabsl(__y) * floorl(__x / fabsl(__y)); \
  })



/*!BEGIN libc/tinymath/magicu.h */

#define COSMOPOLITAN_LIBC_TINYMATH_MAGICU_H_
COSMOPOLITAN_C_START_

struct magicu {
  uint32_t M;
  uint32_t s;
};

struct magicu __magicu_get(uint32_t);

/**
 * Performs fast division using precomputed magic for constant divisor.
 *
 * @param x is unsigned integer that shall be divided
 * @param d should be `__magicu_get(y)` if computing `x / y`
 * @return result of unsigned integer division
 */
forceinline uint32_t __magicu_div(uint32_t x, struct magicu d) {
  return ((((uint64_t)x * d.M) >> 32) + ((d.s & 64) ? x : 0)) >> (d.s & 63);
}

/**
 * Checks if 𝑑 contains a valid initialized divisor.
 */
static inline bool32 __magicu_valid(struct magicu d) {
  if (!d.M && !d.s) return false;     /* uninitialized */
  if (d.s & ~(64 | 63)) return false; /* corrupted */
  return true;
}

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/x.h */

#ifndef COSMOPOLITAN_LIBC_X_H_
#define COSMOPOLITAN_LIBC_X_H_

#define xwrite        __xwrite
#define xdie          __xdie
#define xmalloc       __xmalloc
#define xrealloc      __xrealloc
#define xcalloc       __xcalloc
#define xvalloc       __xvalloc
#define xmemalign     __xmemalign
#define xmemalignzero __xmemalignzero
#define xstrdup       __xstrdup
#define xstrndup      __xstrndup
#define xstrmul       __xstrmul
#define xinet_ntop    __xinet_ntop
#define xunbinga      __xunbinga
#define xunbing       __xunbing
#define utf8to16      __utf8to16
#define utf16to8      __utf16to8
#define utf8to32      __utf8to32
#define utf16to32     __utf16to32
#define utf32to8      __utf32to8
#define xhomedir      __xhomedir
#define xstripext     __xstripext
#define xstripexts    __xstripexts
#define xload         __xload
#define rmrf          __rmrf
#define xbasename     __xbasename
#define xdirname      __xdirname
#define xjoinpaths    __xjoinpaths
#define xfixpath      __xfixpath
#define xslurp        __xslurp
#define xbarf         __xbarf

COSMOPOLITAN_C_START_

int xwrite(int, const void *, uint64_t);
void xdie(void) wontreturn;
char *xdtoa(double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoaf(float)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoal(long double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmalloc(size_t) attributeallocsize((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xrealloc(void *, size_t)
    attributeallocsize((2)) dontthrow dontcallback __wur;
void *xcalloc(size_t, size_t) attributeallocsize((1, 2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xvalloc(size_t) attributeallocsize((1)) returnsaligned((65536))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalign(size_t, size_t) attributeallocalign((1)) attributeallocsize((2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalignzero(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2))
        returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrdup(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrndup(const char *, size_t) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrcat(const char *, ...) paramsnonnull((1)) nullterminated()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
#define xstrcat(...) (xstrcat)(__VA_ARGS__, NULL)
char *xstrmul(const char *, size_t) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xinet_ntop(int, const void *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xunbinga(size_t, const char16_t *)
    attributeallocalign((1)) returnspointerwithnoaliases dontthrow dontcallback
    __wur returnsnonnull dontthrow dontcallback __wur returnsnonnull;
void *xunbing(const char16_t *)
    returnspointerwithnoaliases dontthrow dontcallback __wur
    returnsnonnull dontthrow dontcallback __wur returnsnonnull;
char16_t *utf8to16(const char *, size_t, size_t *) __wur;
char *utf16to8(const char16_t *, size_t, size_t *) __wur;
wchar_t *utf8to32(const char *, size_t, size_t *) __wur;
wchar_t *utf16to32(const char16_t *, size_t, size_t *) __wur;
char *utf32to8(const wchar_t *, size_t, size_t *) __wur;
char *xhomedir(void) __wur;
char *xstripext(const char *) __wur;
char *xstripexts(const char *) __wur;
void *xload(_Atomic(void *) *, const void *, size_t, size_t);
int rmrf(const char *);
char *xbasename(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdirname(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xjoinpaths(const char *, const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void xfixpath(void);
void *xslurp(const char *, size_t *)
    paramsnonnull((1)) returnspointerwithnoaliases returnsaligned((4096)) __wur;
int xbarf(const char *, const void *, size_t);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_X_H_ */


/*!BEGIN libc/x/xasprintf.h */

#define COSMOPOLITAN_LIBC_X_XASPRINTF_H_
COSMOPOLITAN_C_START_

char *xasprintf(const char *, ...) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xvasprintf(const char *, va_list) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xgetline.h */

#define COSMOPOLITAN_LIBC_X_XGETLINE_H_
COSMOPOLITAN_C_START_

char *xgetline(FILE *) paramsnonnull() mallocesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xsigaction.h */

#define COSMOPOLITAN_LIBC_X_XSIGACTION_H_
COSMOPOLITAN_C_START_

int xsigaction(int, void *, uint64_t, uint64_t, struct sigaction *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xspawn.h */

#define COSMOPOLITAN_LIBC_X_XSPAWN_H_
COSMOPOLITAN_C_START_

int xspawn(struct rusage *);
int xvspawn(void (*)(void *), void *, struct rusage *) returnstwice;

COSMOPOLITAN_C_END_


/*!BEGIN net/http/csscolor.h */

#define COSMOPOLITAN_NET_HTTP_CSSCOLOR_H_

#define ALICEBLUE            0xFFFFF8F0u
#define ANTIQUEWHITE         0xFFD7EBFAu
#define ANTIQUEWHITE1        0xFFDBEFFFu
#define ANTIQUEWHITE2        0xFFCCDFEEu
#define ANTIQUEWHITE3        0xFFB0C0CDu
#define ANTIQUEWHITE4        0xFF78838Bu
#define AQUAMARINE           0xFFD4FF7Fu
#define AQUAMARINE1          0xFFD4FF7Fu
#define AQUAMARINE2          0xFFC6EE76u
#define AQUAMARINE3          0xFFAACD66u
#define AQUAMARINE4          0xFF748B45u
#define AZURE                0xFFFFFFF0u
#define AZURE1               0xFFFFFFF0u
#define AZURE2               0xFFEEEEE0u
#define AZURE3               0xFFCDCDC1u
#define AZURE4               0xFF8B8B83u
#define BEIGE                0xFFDCF5F5u
#define BISQUE               0xFFC4E4FFu
#define BISQUE1              0xFFC4E4FFu
#define BISQUE2              0xFFB7D5EEu
#define BISQUE3              0xFF9EB7CDu
#define BISQUE4              0xFF6B7D8Bu
#define BLACK                0xFF000000u
#define BLANCHEDALMOND       0xFFCDEBFFu
#define BLUE                 0xFFFF0000u
#define BLUE1                0xFFFF0000u
#define BLUE2                0xFFEE0000u
#define BLUE3                0xFFCD0000u
#define BLUE4                0xFF8B0000u
#define BLUEVIOLET           0xFFE22B8Au
#define BROWN                0xFF2A2AA5u
#define BROWN1               0xFF4040FFu
#define BROWN2               0xFF3B3BEEu
#define BROWN3               0xFF3333CDu
#define BROWN4               0xFF23238Bu
#define BURLYWOOD            0xFF87B8DEu
#define BURLYWOOD1           0xFF9BD3FFu
#define BURLYWOOD2           0xFF91C5EEu
#define BURLYWOOD3           0xFF7DAACDu
#define BURLYWOOD4           0xFF55738Bu
#define CADETBLUE            0xFFA09E5Fu
#define CADETBLUE1           0xFFFFF598u
#define CADETBLUE2           0xFFEEE58Eu
#define CADETBLUE3           0xFFCDC57Au
#define CADETBLUE4           0xFF8B8653u
#define CHARTREUSE           0xFF00FF7Fu
#define CHARTREUSE1          0xFF00FF7Fu
#define CHARTREUSE2          0xFF00EE76u
#define CHARTREUSE3          0xFF00CD66u
#define CHARTREUSE4          0xFF008B45u
#define CHOCOLATE            0xFF1E69D2u
#define CHOCOLATE1           0xFF247FFFu
#define CHOCOLATE2           0xFF2176EEu
#define CHOCOLATE3           0xFF1D66CDu
#define CHOCOLATE4           0xFF13458Bu
#define CORAL                0xFF507FFFu
#define CORAL1               0xFF5672FFu
#define CORAL2               0xFF506AEEu
#define CORAL3               0xFF455BCDu
#define CORAL4               0xFF2F3E8Bu
#define CORNFLOWERBLUE       0xFFED9564u
#define CORNSILK             0xFFDCF8FFu
#define CORNSILK1            0xFFDCF8FFu
#define CORNSILK2            0xFFCDE8EEu
#define CORNSILK3            0xFFB1C8CDu
#define CORNSILK4            0xFF78888Bu
#define CYAN                 0xFFFFFF00u
#define CYAN1                0xFFFFFF00u
#define CYAN2                0xFFEEEE00u
#define CYAN3                0xFFCDCD00u
#define CYAN4                0xFF8B8B00u
#define DARKBLUE             0xFF8B0000u
#define DARKCYAN             0xFF8B8B00u
#define DARKGOLDENROD        0xFF0B86B8u
#define DARKGOLDENROD1       0xFF0FB9FFu
#define DARKGOLDENROD2       0xFF0EADEEu
#define DARKGOLDENROD3       0xFF0C95CDu
#define DARKGOLDENROD4       0xFF08658Bu
#define DARKGRAY             0xFFA9A9A9u
#define DARKGREEN            0xFF006400u
#define DARKGREY             0xFFA9A9A9u
#define DARKKHAKI            0xFF6BB7BDu
#define DARKMAGENTA          0xFF8B008Bu
#define DARKOLIVEGREEN       0xFF2F6B55u
#define DARKOLIVEGREEN1      0xFF70FFCAu
#define DARKOLIVEGREEN2      0xFF68EEBCu
#define DARKOLIVEGREEN3      0xFF5ACDA2u
#define DARKOLIVEGREEN4      0xFF3D8B6Eu
#define DARKORANGE           0xFF008CFFu
#define DARKORANGE1          0xFF007FFFu
#define DARKORANGE2          0xFF0076EEu
#define DARKORANGE3          0xFF0066CDu
#define DARKORANGE4          0xFF00458Bu
#define DARKORCHID           0xFFCC3299u
#define DARKORCHID1          0xFFFF3EBFu
#define DARKORCHID2          0xFFEE3AB2u
#define DARKORCHID3          0xFFCD329Au
#define DARKORCHID4          0xFF8B2268u
#define DARKRED              0xFF00008Bu
#define DARKSALMON           0xFF7A96E9u
#define DARKSEAGREEN         0xFF8FBC8Fu
#define DARKSEAGREEN1        0xFFC1FFC1u
#define DARKSEAGREEN2        0xFFB4EEB4u
#define DARKSEAGREEN3        0xFF9BCD9Bu
#define DARKSEAGREEN4        0xFF698B69u
#define DARKSLATEBLUE        0xFF8B3D48u
#define DARKSLATEGRAY        0xFF4F4F2Fu
#define DARKSLATEGRAY1       0xFFFFFF97u
#define DARKSLATEGRAY2       0xFFEEEE8Du
#define DARKSLATEGRAY3       0xFFCDCD79u
#define DARKSLATEGRAY4       0xFF8B8B52u
#define DARKSLATEGREY        0xFF4F4F2Fu
#define DARKTURQUOISE        0xFFD1CE00u
#define DARKVIOLET           0xFFD30094u
#define DEEPPINK             0xFF9314FFu
#define DEEPPINK1            0xFF9314FFu
#define DEEPPINK2            0xFF8912EEu
#define DEEPPINK3            0xFF7610CDu
#define DEEPPINK4            0xFF500A8Bu
#define DEEPSKYBLUE          0xFFFFBF00u
#define DEEPSKYBLUE1         0xFFFFBF00u
#define DEEPSKYBLUE2         0xFFEEB200u
#define DEEPSKYBLUE3         0xFFCD9A00u
#define DEEPSKYBLUE4         0xFF8B6800u
#define DIMGRAY              0xFF696969u
#define DIMGREY              0xFF696969u
#define DODGERBLUE           0xFFFF901Eu
#define DODGERBLUE1          0xFFFF901Eu
#define DODGERBLUE2          0xFFEE861Cu
#define DODGERBLUE3          0xFFCD7418u
#define DODGERBLUE4          0xFF8B4E10u
#define FIREBRICK            0xFF2222B2u
#define FIREBRICK1           0xFF3030FFu
#define FIREBRICK2           0xFF2C2CEEu
#define FIREBRICK3           0xFF2626CDu
#define FIREBRICK4           0xFF1A1A8Bu
#define FLORALWHITE          0xFFF0FAFFu
#define FORESTGREEN          0xFF228B22u
#define GAINSBORO            0xFFDCDCDCu
#define GHOSTWHITE           0xFFFFF8F8u
#define GOLD                 0xFF00D7FFu
#define GOLD1                0xFF00D7FFu
#define GOLD2                0xFF00C9EEu
#define GOLD3                0xFF00ADCDu
#define GOLD4                0xFF00758Bu
#define GOLDENROD            0xFF20A5DAu
#define GOLDENROD1           0xFF25C1FFu
#define GOLDENROD2           0xFF22B4EEu
#define GOLDENROD3           0xFF1D9BCDu
#define GOLDENROD4           0xFF14698Bu
#define GRAY                 0xFFBEBEBEu
#define GRAY0                0xFF000000u
#define GRAY1                0xFF030303u
#define GRAY10               0xFF1A1A1Au
#define GRAY100              0xFFFFFFFFu
#define GRAY11               0xFF1C1C1Cu
#define GRAY12               0xFF1F1F1Fu
#define GRAY13               0xFF212121u
#define GRAY14               0xFF242424u
#define GRAY15               0xFF262626u
#define GRAY16               0xFF292929u
#define GRAY17               0xFF2B2B2Bu
#define GRAY18               0xFF2E2E2Eu
#define GRAY19               0xFF303030u
#define GRAY2                0xFF050505u
#define GRAY20               0xFF333333u
#define GRAY21               0xFF363636u
#define GRAY22               0xFF383838u
#define GRAY23               0xFF3B3B3Bu
#define GRAY24               0xFF3D3D3Du
#define GRAY25               0xFF404040u
#define GRAY26               0xFF424242u
#define GRAY27               0xFF454545u
#define GRAY28               0xFF474747u
#define GRAY29               0xFF4A4A4Au
#define GRAY3                0xFF080808u
#define GRAY30               0xFF4D4D4Du
#define GRAY31               0xFF4F4F4Fu
#define GRAY32               0xFF525252u
#define GRAY33               0xFF545454u
#define GRAY34               0xFF575757u
#define GRAY35               0xFF595959u
#define GRAY36               0xFF5C5C5Cu
#define GRAY37               0xFF5E5E5Eu
#define GRAY38               0xFF616161u
#define GRAY39               0xFF636363u
#define GRAY4                0xFF0A0A0Au
#define GRAY40               0xFF666666u
#define GRAY41               0xFF696969u
#define GRAY42               0xFF6B6B6Bu
#define GRAY43               0xFF6E6E6Eu
#define GRAY44               0xFF707070u
#define GRAY45               0xFF737373u
#define GRAY46               0xFF757575u
#define GRAY47               0xFF787878u
#define GRAY48               0xFF7A7A7Au
#define GRAY49               0xFF7D7D7Du
#define GRAY5                0xFF0D0D0Du
#define GRAY50               0xFF7F7F7Fu
#define GRAY51               0xFF828282u
#define GRAY52               0xFF858585u
#define GRAY53               0xFF878787u
#define GRAY54               0xFF8A8A8Au
#define GRAY55               0xFF8C8C8Cu
#define GRAY56               0xFF8F8F8Fu
#define GRAY57               0xFF919191u
#define GRAY58               0xFF949494u
#define GRAY59               0xFF969696u
#define GRAY6                0xFF0F0F0Fu
#define GRAY60               0xFF999999u
#define GRAY61               0xFF9C9C9Cu
#define GRAY62               0xFF9E9E9Eu
#define GRAY63               0xFFA1A1A1u
#define GRAY64               0xFFA3A3A3u
#define GRAY65               0xFFA6A6A6u
#define GRAY66               0xFFA8A8A8u
#define GRAY67               0xFFABABABu
#define GRAY68               0xFFADADADu
#define GRAY69               0xFFB0B0B0u
#define GRAY7                0xFF121212u
#define GRAY70               0xFFB3B3B3u
#define GRAY71               0xFFB5B5B5u
#define GRAY72               0xFFB8B8B8u
#define GRAY73               0xFFBABABAu
#define GRAY74               0xFFBDBDBDu
#define GRAY75               0xFFBFBFBFu
#define GRAY76               0xFFC2C2C2u
#define GRAY77               0xFFC4C4C4u
#define GRAY78               0xFFC7C7C7u
#define GRAY79               0xFFC9C9C9u
#define GRAY8                0xFF141414u
#define GRAY80               0xFFCCCCCCu
#define GRAY81               0xFFCFCFCFu
#define GRAY82               0xFFD1D1D1u
#define GRAY83               0xFFD4D4D4u
#define GRAY84               0xFFD6D6D6u
#define GRAY85               0xFFD9D9D9u
#define GRAY86               0xFFDBDBDBu
#define GRAY87               0xFFDEDEDEu
#define GRAY88               0xFFE0E0E0u
#define GRAY89               0xFFE3E3E3u
#define GRAY9                0xFF171717u
#define GRAY90               0xFFE5E5E5u
#define GRAY91               0xFFE8E8E8u
#define GRAY92               0xFFEBEBEBu
#define GRAY93               0xFFEDEDEDu
#define GRAY94               0xFFF0F0F0u
#define GRAY95               0xFFF2F2F2u
#define GRAY96               0xFFF5F5F5u
#define GRAY97               0xFFF7F7F7u
#define GRAY98               0xFFFAFAFAu
#define GRAY99               0xFFFCFCFCu
#define GREEN                0xFF00FF00u
#define GREEN1               0xFF00FF00u
#define GREEN2               0xFF00EE00u
#define GREEN3               0xFF00CD00u
#define GREEN4               0xFF008B00u
#define GREENYELLOW          0xFF2FFFADu
#define GREY                 0xFFBEBEBEu
#define GREY0                0xFF000000u
#define GREY1                0xFF030303u
#define GREY10               0xFF1A1A1Au
#define GREY100              0xFFFFFFFFu
#define GREY11               0xFF1C1C1Cu
#define GREY12               0xFF1F1F1Fu
#define GREY13               0xFF212121u
#define GREY14               0xFF242424u
#define GREY15               0xFF262626u
#define GREY16               0xFF292929u
#define GREY17               0xFF2B2B2Bu
#define GREY18               0xFF2E2E2Eu
#define GREY19               0xFF303030u
#define GREY2                0xFF050505u
#define GREY20               0xFF333333u
#define GREY21               0xFF363636u
#define GREY22               0xFF383838u
#define GREY23               0xFF3B3B3Bu
#define GREY24               0xFF3D3D3Du
#define GREY25               0xFF404040u
#define GREY26               0xFF424242u
#define GREY27               0xFF454545u
#define GREY28               0xFF474747u
#define GREY29               0xFF4A4A4Au
#define GREY3                0xFF080808u
#define GREY30               0xFF4D4D4Du
#define GREY31               0xFF4F4F4Fu
#define GREY32               0xFF525252u
#define GREY33               0xFF545454u
#define GREY34               0xFF575757u
#define GREY35               0xFF595959u
#define GREY36               0xFF5C5C5Cu
#define GREY37               0xFF5E5E5Eu
#define GREY38               0xFF616161u
#define GREY39               0xFF636363u
#define GREY4                0xFF0A0A0Au
#define GREY40               0xFF666666u
#define GREY41               0xFF696969u
#define GREY42               0xFF6B6B6Bu
#define GREY43               0xFF6E6E6Eu
#define GREY44               0xFF707070u
#define GREY45               0xFF737373u
#define GREY46               0xFF757575u
#define GREY47               0xFF787878u
#define GREY48               0xFF7A7A7Au
#define GREY49               0xFF7D7D7Du
#define GREY5                0xFF0D0D0Du
#define GREY50               0xFF7F7F7Fu
#define GREY51               0xFF828282u
#define GREY52               0xFF858585u
#define GREY53               0xFF878787u
#define GREY54               0xFF8A8A8Au
#define GREY55               0xFF8C8C8Cu
#define GREY56               0xFF8F8F8Fu
#define GREY57               0xFF919191u
#define GREY58               0xFF949494u
#define GREY59               0xFF969696u
#define GREY6                0xFF0F0F0Fu
#define GREY60               0xFF999999u
#define GREY61               0xFF9C9C9Cu
#define GREY62               0xFF9E9E9Eu
#define GREY63               0xFFA1A1A1u
#define GREY64               0xFFA3A3A3u
#define GREY65               0xFFA6A6A6u
#define GREY66               0xFFA8A8A8u
#define GREY67               0xFFABABABu
#define GREY68               0xFFADADADu
#define GREY69               0xFFB0B0B0u
#define GREY7                0xFF121212u
#define GREY70               0xFFB3B3B3u
#define GREY71               0xFFB5B5B5u
#define GREY72               0xFFB8B8B8u
#define GREY73               0xFFBABABAu
#define GREY74               0xFFBDBDBDu
#define GREY75               0xFFBFBFBFu
#define GREY76               0xFFC2C2C2u
#define GREY77               0xFFC4C4C4u
#define GREY78               0xFFC7C7C7u
#define GREY79               0xFFC9C9C9u
#define GREY8                0xFF141414u
#define GREY80               0xFFCCCCCCu
#define GREY81               0xFFCFCFCFu
#define GREY82               0xFFD1D1D1u
#define GREY83               0xFFD4D4D4u
#define GREY84               0xFFD6D6D6u
#define GREY85               0xFFD9D9D9u
#define GREY86               0xFFDBDBDBu
#define GREY87               0xFFDEDEDEu
#define GREY88               0xFFE0E0E0u
#define GREY89               0xFFE3E3E3u
#define GREY9                0xFF171717u
#define GREY90               0xFFE5E5E5u
#define GREY91               0xFFE8E8E8u
#define GREY92               0xFFEBEBEBu
#define GREY93               0xFFEDEDEDu
#define GREY94               0xFFF0F0F0u
#define GREY95               0xFFF2F2F2u
#define GREY96               0xFFF5F5F5u
#define GREY97               0xFFF7F7F7u
#define GREY98               0xFFFAFAFAu
#define GREY99               0xFFFCFCFCu
#define HONEYDEW             0xFFF0FFF0u
#define HONEYDEW1            0xFFF0FFF0u
#define HONEYDEW2            0xFFE0EEE0u
#define HONEYDEW3            0xFFC1CDC1u
#define HONEYDEW4            0xFF838B83u
#define HOTPINK              0xFFB469FFu
#define HOTPINK1             0xFFB46EFFu
#define HOTPINK2             0xFFA76AEEu
#define HOTPINK3             0xFF9060CDu
#define HOTPINK4             0xFF623A8Bu
#define INDIANRED            0xFF5C5CCDu
#define INDIANRED1           0xFF6A6AFFu
#define INDIANRED2           0xFF6363EEu
#define INDIANRED3           0xFF5555CDu
#define INDIANRED4           0xFF3A3A8Bu
#define IVORY                0xFFF0FFFFu
#define IVORY1               0xFFF0FFFFu
#define IVORY2               0xFFE0EEEEu
#define IVORY3               0xFFC1CDCDu
#define IVORY4               0xFF838B8Bu
#define KHAKI                0xFF8CE6F0u
#define KHAKI1               0xFF8FF6FFu
#define KHAKI2               0xFF85E6EEu
#define KHAKI3               0xFF73C6CDu
#define KHAKI4               0xFF4E868Bu
#define LAVENDER             0xFFFAE6E6u
#define LAVENDERBLUSH        0xFFF5F0FFu
#define LAVENDERBLUSH1       0xFFF5F0FFu
#define LAVENDERBLUSH2       0xFFE5E0EEu
#define LAVENDERBLUSH3       0xFFC5C1CDu
#define LAVENDERBLUSH4       0xFF86838Bu
#define LAWNGREEN            0xFF00FC7Cu
#define LEMONCHIFFON         0xFFCDFAFFu
#define LEMONCHIFFON1        0xFFCDFAFFu
#define LEMONCHIFFON2        0xFFBFE9EEu
#define LEMONCHIFFON3        0xFFA5C9CDu
#define LEMONCHIFFON4        0xFF70898Bu
#define LIGHTBLUE            0xFFE6D8ADu
#define LIGHTBLUE1           0xFFFFEFBFu
#define LIGHTBLUE2           0xFFEEDFB2u
#define LIGHTBLUE3           0xFFCDC09Au
#define LIGHTBLUE4           0xFF8B8368u
#define LIGHTCORAL           0xFF8080F0u
#define LIGHTCYAN            0xFFFFFFE0u
#define LIGHTCYAN1           0xFFFFFFE0u
#define LIGHTCYAN2           0xFFEEEED1u
#define LIGHTCYAN3           0xFFCDCDB4u
#define LIGHTCYAN4           0xFF8B8B7Au
#define LIGHTGOLDENROD       0xFF82DDEEu
#define LIGHTGOLDENROD1      0xFF8BECFFu
#define LIGHTGOLDENROD2      0xFF82DCEEu
#define LIGHTGOLDENROD3      0xFF70BECDu
#define LIGHTGOLDENROD4      0xFF4C818Bu
#define LIGHTGOLDENRODYELLOW 0xFFD2FAFAu
#define LIGHTGRAY            0xFFD3D3D3u
#define LIGHTGREEN           0xFF90EE90u
#define LIGHTGREY            0xFFD3D3D3u
#define LIGHTPINK            0xFFC1B6FFu
#define LIGHTPINK1           0xFFB9AEFFu
#define LIGHTPINK2           0xFFADA2EEu
#define LIGHTPINK3           0xFF958CCDu
#define LIGHTPINK4           0xFF655F8Bu
#define LIGHTSALMON          0xFF7AA0FFu
#define LIGHTSALMON1         0xFF7AA0FFu
#define LIGHTSALMON2         0xFF7295EEu
#define LIGHTSALMON3         0xFF6281CDu
#define LIGHTSALMON4         0xFF42578Bu
#define LIGHTSEAGREEN        0xFFAAB220u
#define LIGHTSKYBLUE         0xFFFACE87u
#define LIGHTSKYBLUE1        0xFFFFE2B0u
#define LIGHTSKYBLUE2        0xFFEED3A4u
#define LIGHTSKYBLUE3        0xFFCDB68Du
#define LIGHTSKYBLUE4        0xFF8B7B60u
#define LIGHTSLATEBLUE       0xFFFF7084u
#define LIGHTSLATEGRAY       0xFF998877u
#define LIGHTSLATEGREY       0xFF998877u
#define LIGHTSTEELBLUE       0xFFDEC4B0u
#define LIGHTSTEELBLUE1      0xFFFFE1CAu
#define LIGHTSTEELBLUE2      0xFFEED2BCu
#define LIGHTSTEELBLUE3      0xFFCDB5A2u
#define LIGHTSTEELBLUE4      0xFF8B7B6Eu
#define LIGHTYELLOW          0xFFE0FFFFu
#define LIGHTYELLOW1         0xFFE0FFFFu
#define LIGHTYELLOW2         0xFFD1EEEEu
#define LIGHTYELLOW3         0xFFB4CDCDu
#define LIGHTYELLOW4         0xFF7A8B8Bu
#define LIMEGREEN            0xFF32CD32u
#define LINEN                0xFFE6F0FAu
#define MAGENTA              0xFFFF00FFu
#define MAGENTA1             0xFFFF00FFu
#define MAGENTA2             0xFFEE00EEu
#define MAGENTA3             0xFFCD00CDu
#define MAGENTA4             0xFF8B008Bu
#define MAROON               0xFF6030B0u
#define MAROON1              0xFFB334FFu
#define MAROON2              0xFFA730EEu
#define MAROON3              0xFF9029CDu
#define MAROON4              0xFF621C8Bu
#define MEDIUMAQUAMARINE     0xFFAACD66u
#define MEDIUMBLUE           0xFFCD0000u
#define MEDIUMORCHID         0xFFD355BAu
#define MEDIUMORCHID1        0xFFFF66E0u
#define MEDIUMORCHID2        0xFFEE5FD1u
#define MEDIUMORCHID3        0xFFCD52B4u
#define MEDIUMORCHID4        0xFF8B377Au
#define MEDIUMPURPLE         0xFFDB7093u
#define MEDIUMPURPLE1        0xFFFF82ABu
#define MEDIUMPURPLE2        0xFFEE799Fu
#define MEDIUMPURPLE3        0xFFCD6889u
#define MEDIUMPURPLE4        0xFF8B475Du
#define MEDIUMSEAGREEN       0xFF71B33Cu
#define MEDIUMSLATEBLUE      0xFFEE687Bu
#define MEDIUMSPRINGGREEN    0xFF9AFA00u
#define MEDIUMTURQUOISE      0xFFCCD148u
#define MEDIUMVIOLETRED      0xFF8515C7u
#define MIDNIGHTBLUE         0xFF701919u
#define MINTCREAM            0xFFFAFFF5u
#define MISTYROSE            0xFFE1E4FFu
#define MISTYROSE1           0xFFE1E4FFu
#define MISTYROSE2           0xFFD2D5EEu
#define MISTYROSE3           0xFFB5B7CDu
#define MISTYROSE4           0xFF7B7D8Bu
#define MOCCASIN             0xFFB5E4FFu
#define NAVAJOWHITE          0xFFADDEFFu
#define NAVAJOWHITE1         0xFFADDEFFu
#define NAVAJOWHITE2         0xFFA1CFEEu
#define NAVAJOWHITE3         0xFF8BB3CDu
#define NAVAJOWHITE4         0xFF5E798Bu
#define NAVY                 0xFF800000u
#define NAVYBLUE             0xFF800000u
#define OLDLACE              0xFFE6F5FDu
#define OLIVEDRAB            0xFF238E6Bu
#define OLIVEDRAB1           0xFF3EFFC0u
#define OLIVEDRAB2           0xFF3AEEB3u
#define OLIVEDRAB3           0xFF32CD9Au
#define OLIVEDRAB4           0xFF228B69u
#define ORANGE               0xFF00A5FFu
#define ORANGE1              0xFF00A5FFu
#define ORANGE2              0xFF009AEEu
#define ORANGE3              0xFF0085CDu
#define ORANGE4              0xFF005A8Bu
#define ORANGERED            0xFF0045FFu
#define ORANGERED1           0xFF0045FFu
#define ORANGERED2           0xFF0040EEu
#define ORANGERED3           0xFF0037CDu
#define ORANGERED4           0xFF00258Bu
#define ORCHID               0xFFD670DAu
#define ORCHID1              0xFFFA83FFu
#define ORCHID2              0xFFE97AEEu
#define ORCHID3              0xFFC969CDu
#define ORCHID4              0xFF89478Bu
#define PALEGOLDENROD        0xFFAAE8EEu
#define PALEGREEN            0xFF98FB98u
#define PALEGREEN1           0xFF9AFF9Au
#define PALEGREEN2           0xFF90EE90u
#define PALEGREEN3           0xFF7CCD7Cu
#define PALEGREEN4           0xFF548B54u
#define PALETURQUOISE        0xFFEEEEAFu
#define PALETURQUOISE1       0xFFFFFFBBu
#define PALETURQUOISE2       0xFFEEEEAEu
#define PALETURQUOISE3       0xFFCDCD96u
#define PALETURQUOISE4       0xFF8B8B66u
#define PALEVIOLETRED        0xFF9370DBu
#define PALEVIOLETRED1       0xFFAB82FFu
#define PALEVIOLETRED2       0xFF9F79EEu
#define PALEVIOLETRED3       0xFF8968CDu
#define PALEVIOLETRED4       0xFF5D478Bu
#define PAPAYAWHIP           0xFFD5EFFFu
#define PEACHPUFF            0xFFB9DAFFu
#define PEACHPUFF1           0xFFB9DAFFu
#define PEACHPUFF2           0xFFADCBEEu
#define PEACHPUFF3           0xFF95AFCDu
#define PEACHPUFF4           0xFF65778Bu
#define PERU                 0xFF3F85CDu
#define PINK                 0xFFCBC0FFu
#define PINK1                0xFFC5B5FFu
#define PINK2                0xFFB8A9EEu
#define PINK3                0xFF9E91CDu
#define PINK4                0xFF6C638Bu
#define PLUM                 0xFFDDA0DDu
#define PLUM1                0xFFFFBBFFu
#define PLUM2                0xFFEEAEEEu
#define PLUM3                0xFFCD96CDu
#define PLUM4                0xFF8B668Bu
#define POWDERBLUE           0xFFE6E0B0u
#define PURPLE               0xFFF020A0u
#define PURPLE1              0xFFFF309Bu
#define PURPLE2              0xFFEE2C91u
#define PURPLE3              0xFFCD267Du
#define PURPLE4              0xFF8B1A55u
#define RED                  0xFF0000FFu
#define RED1                 0xFF0000FFu
#define RED2                 0xFF0000EEu
#define RED3                 0xFF0000CDu
#define RED4                 0xFF00008Bu
#define ROSYBROWN            0xFF8F8FBCu
#define ROSYBROWN1           0xFFC1C1FFu
#define ROSYBROWN2           0xFFB4B4EEu
#define ROSYBROWN3           0xFF9B9BCDu
#define ROSYBROWN4           0xFF69698Bu
#define ROYALBLUE            0xFFE16941u
#define ROYALBLUE1           0xFFFF7648u
#define ROYALBLUE2           0xFFEE6E43u
#define ROYALBLUE3           0xFFCD5F3Au
#define ROYALBLUE4           0xFF8B4027u
#define SADDLEBROWN          0xFF13458Bu
#define SALMON               0xFF7280FAu
#define SALMON1              0xFF698CFFu
#define SALMON2              0xFF6282EEu
#define SALMON3              0xFF5470CDu
#define SALMON4              0xFF394C8Bu
#define SANDYBROWN           0xFF60A4F4u
#define SEAGREEN             0xFF578B2Eu
#define SEAGREEN1            0xFF9FFF54u
#define SEAGREEN2            0xFF94EE4Eu
#define SEAGREEN3            0xFF80CD43u
#define SEAGREEN4            0xFF578B2Eu
#define SEASHELL             0xFFEEF5FFu
#define SEASHELL1            0xFFEEF5FFu
#define SEASHELL2            0xFFDEE5EEu
#define SEASHELL3            0xFFBFC5CDu
#define SEASHELL4            0xFF82868Bu
#define SIENNA               0xFF2D52A0u
#define SIENNA1              0xFF4782FFu
#define SIENNA2              0xFF4279EEu
#define SIENNA3              0xFF3968CDu
#define SIENNA4              0xFF26478Bu
#define SKYBLUE              0xFFEBCE87u
#define SKYBLUE1             0xFFFFCE87u
#define SKYBLUE2             0xFFEEC07Eu
#define SKYBLUE3             0xFFCDA66Cu
#define SKYBLUE4             0xFF8B704Au
#define SLATEBLUE            0xFFCD5A6Au
#define SLATEBLUE1           0xFFFF6F83u
#define SLATEBLUE2           0xFFEE677Au
#define SLATEBLUE3           0xFFCD5969u
#define SLATEBLUE4           0xFF8B3C47u
#define SLATEGRAY            0xFF908070u
#define SLATEGRAY1           0xFFFFE2C6u
#define SLATEGRAY2           0xFFEED3B9u
#define SLATEGRAY3           0xFFCDB69Fu
#define SLATEGRAY4           0xFF8B7B6Cu
#define SLATEGREY            0xFF908070u
#define SNOW                 0xFFFAFAFFu
#define SNOW1                0xFFFAFAFFu
#define SNOW2                0xFFE9E9EEu
#define SNOW3                0xFFC9C9CDu
#define SNOW4                0xFF89898Bu
#define SPRINGGREEN          0xFF7FFF00u
#define SPRINGGREEN1         0xFF7FFF00u
#define SPRINGGREEN2         0xFF76EE00u
#define SPRINGGREEN3         0xFF66CD00u
#define SPRINGGREEN4         0xFF458B00u
#define STEELBLUE            0xFFB48246u
#define STEELBLUE1           0xFFFFB863u
#define STEELBLUE2           0xFFEEAC5Cu
#define STEELBLUE3           0xFFCD944Fu
#define STEELBLUE4           0xFF8B6436u
#define TAN                  0xFF8CB4D2u
#define TAN1                 0xFF4FA5FFu
#define TAN2                 0xFF499AEEu
#define TAN3                 0xFF3F85CDu
#define TAN4                 0xFF2B5A8Bu
#define THISTLE              0xFFD8BFD8u
#define THISTLE1             0xFFFFE1FFu
#define THISTLE2             0xFFEED2EEu
#define THISTLE3             0xFFCDB5CDu
#define THISTLE4             0xFF8B7B8Bu
#define TOMATO               0xFF4763FFu
#define TOMATO1              0xFF4763FFu
#define TOMATO2              0xFF425CEEu
#define TOMATO3              0xFF394FCDu
#define TOMATO4              0xFF26368Bu
#define TURQUOISE            0xFFD0E040u
#define TURQUOISE1           0xFFFFF500u
#define TURQUOISE2           0xFFEEE500u
#define TURQUOISE3           0xFFCDC500u
#define TURQUOISE4           0xFF8B8600u
#define VIOLET               0xFFEE82EEu
#define VIOLETRED            0xFF9020D0u
#define VIOLETRED1           0xFF963EFFu
#define VIOLETRED2           0xFF8C3AEEu
#define VIOLETRED3           0xFF7832CDu
#define VIOLETRED4           0xFF52228Bu
#define WHEAT                0xFFB3DEF5u
#define WHEAT1               0xFFBAE7FFu
#define WHEAT2               0xFFAED8EEu
#define WHEAT3               0xFF96BACDu
#define WHEAT4               0xFF667E8Bu
#define WHITE                0xFFFFFFFFu
#define WHITESMOKE           0xFFF5F5F5u
#define YELLOW               0xFF00FFFFu
#define YELLOW1              0xFF00FFFFu
#define YELLOW2              0xFF00EEEEu
#define YELLOW3              0xFF00CDCDu
#define YELLOW4              0xFF008B8Bu
#define YELLOWGREEN          0xFF32CD9Au



/*!BEGIN net/http/escape.h */

#define COSMOPOLITAN_NET_HTTP_ESCAPE_H_

#define kControlWs 1
#define kControlC0 2
#define kControlC1 4

COSMOPOLITAN_C_START_

extern const char kEscapeAuthority[256];
extern const char kEscapeIp[256];
extern const char kEscapePath[256];
extern const char kEscapeSegment[256];
extern const char kEscapeParam[256];
extern const char kEscapeFragment[256];

char *EscapeHtml(const char *, size_t, size_t *);
char *EscapeUrl(const char *, size_t, size_t *, const char[256]);
char *EscapeUser(const char *, size_t, size_t *);
char *EscapePass(const char *, size_t, size_t *);
char *EscapeIp(const char *, size_t, size_t *);
char *EscapeHost(const char *, size_t, size_t *);
char *EscapePath(const char *, size_t, size_t *);
char *EscapeParam(const char *, size_t, size_t *);
char *EscapeFragment(const char *, size_t, size_t *);
char *EscapeSegment(const char *, size_t, size_t *);
char *EscapeJsStringLiteral(char **, size_t *, const char *, size_t, size_t *);

ssize_t HasControlCodes(const char *, size_t, int);
char *Underlong(const char *, size_t, size_t *);
char *DecodeLatin1(const char *, size_t, size_t *);
char *EncodeLatin1(const char *, size_t, size_t *, int);
char *EncodeHttpHeaderValue(const char *, size_t, size_t *);
char *VisualizeControlCodes(const char *, size_t, size_t *);
char *IndentLines(const char *, size_t, size_t *, size_t);
char *EncodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *DecodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *EncodeBase64(const char *, size_t, size_t *);
char *DecodeBase64(const char *, size_t, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/http.h */

#define COSMOPOLITAN_LIBC_HTTP_HTTP_H_

#define kHttpRequest  0
#define kHttpResponse 1

#define kHttpGet     READ32LE("GET")
#define kHttpHead    READ32LE("HEAD")
#define kHttpPost    READ32LE("POST")
#define kHttpPut     READ32LE("PUT")
#define kHttpDelete  READ64LE("DELETE\0")
#define kHttpOptions READ64LE("OPTIONS")
#define kHttpConnect READ64LE("CONNECT")
#define kHttpTrace   READ64LE("TRACE\0\0")

#define kHttpStateStart   0
#define kHttpStateMethod  1
#define kHttpStateUri     2
#define kHttpStateVersion 3
#define kHttpStateStatus  4
#define kHttpStateMessage 5
#define kHttpStateName    6
#define kHttpStateColon   7
#define kHttpStateValue   8
#define kHttpStateCr      9
#define kHttpStateLf1     10
#define kHttpStateLf2     11

#define kHttpClientStateHeaders      0
#define kHttpClientStateBody         1
#define kHttpClientStateBodyChunked  2
#define kHttpClientStateBodyLengthed 3

#define kHttpStateChunkStart   0
#define kHttpStateChunkSize    1
#define kHttpStateChunkExt     2
#define kHttpStateChunkLf1     3
#define kHttpStateChunk        4
#define kHttpStateChunkCr2     5
#define kHttpStateChunkLf2     6
#define kHttpStateTrailerStart 7
#define kHttpStateTrailer      8
#define kHttpStateTrailerLf1   9
#define kHttpStateTrailerLf2   10

#define kHttpHost                          0
#define kHttpCacheControl                  1
#define kHttpConnection                    2
#define kHttpAccept                        3
#define kHttpAcceptLanguage                4
#define kHttpAcceptEncoding                5
#define kHttpUserAgent                     6
#define kHttpReferer                       7
#define kHttpXForwardedFor                 8
#define kHttpOrigin                        9
#define kHttpUpgradeInsecureRequests       10
#define kHttpPragma                        11
#define kHttpCookie                        12
#define kHttpDnt                           13
#define kHttpSecGpc                        14
#define kHttpFrom                          15
#define kHttpIfModifiedSince               16
#define kHttpXRequestedWith                17
#define kHttpXForwardedHost                18
#define kHttpXForwardedProto               19
#define kHttpXCsrfToken                    20
#define kHttpSaveData                      21
#define kHttpRange                         22
#define kHttpContentLength                 23
#define kHttpContentType                   24
#define kHttpVary                          25
#define kHttpDate                          26
#define kHttpServer                        27
#define kHttpExpires                       28
#define kHttpContentEncoding               29
#define kHttpLastModified                  30
#define kHttpEtag                          31
#define kHttpAllow                         32
#define kHttpContentRange                  33
#define kHttpAcceptCharset                 34
#define kHttpAccessControlAllowCredentials 35
#define kHttpAccessControlAllowHeaders     36
#define kHttpAccessControlAllowMethods     37
#define kHttpAccessControlAllowOrigin      38
#define kHttpAccessControlMaxAge           39
#define kHttpAccessControlMethod           40
#define kHttpAccessControlRequestHeaders   41
#define kHttpAccessControlRequestMethod    42
#define kHttpAccessControlRequestMethods   43
#define kHttpAge                           44
#define kHttpAuthorization                 45
#define kHttpContentBase                   46
#define kHttpContentDescription            47
#define kHttpContentDisposition            48
#define kHttpContentLanguage               49
#define kHttpContentLocation               50
#define kHttpContentMd5                    51
#define kHttpExpect                        52
#define kHttpIfMatch                       53
#define kHttpIfNoneMatch                   54
#define kHttpIfRange                       55
#define kHttpIfUnmodifiedSince             56
#define kHttpKeepAlive                     57
#define kHttpLink                          58
#define kHttpLocation                      59
#define kHttpMaxForwards                   60
#define kHttpProxyAuthenticate             61
#define kHttpProxyAuthorization            62
#define kHttpProxyConnection               63
#define kHttpPublic                        64
#define kHttpRetryAfter                    65
#define kHttpTe                            66
#define kHttpTrailer                       67
#define kHttpTransferEncoding              68
#define kHttpUpgrade                       69
#define kHttpWarning                       70
#define kHttpWwwAuthenticate               71
#define kHttpVia                           72
#define kHttpStrictTransportSecurity       73
#define kHttpXFrameOptions                 74
#define kHttpXContentTypeOptions           75
#define kHttpAltSvc                        76
#define kHttpReferrerPolicy                77
#define kHttpXXssProtection                78
#define kHttpAcceptRanges                  79
#define kHttpSetCookie                     80
#define kHttpSecChUa                       81
#define kHttpSecChUaMobile                 82
#define kHttpSecFetchSite                  83
#define kHttpSecFetchMode                  84
#define kHttpSecFetchUser                  85
#define kHttpSecFetchDest                  86
#define kHttpCfRay                         87
#define kHttpCfVisitor                     88
#define kHttpCfConnectingIp                89
#define kHttpCfIpcountry                   90
#define kHttpSecChUaPlatform               91
#define kHttpCdnLoop                       92
#define kHttpHeadersMax                    93

COSMOPOLITAN_C_START_

struct HttpSlice {
  short a, b;
};

struct HttpHeader {
  struct HttpSlice k;
  struct HttpSlice v;
};

struct HttpHeaders {
  unsigned n, c;
  struct HttpHeader *p;
};

struct HttpMessage {
  int i, a, status;
  unsigned char t;
  unsigned char type;
  unsigned char version;
  uint64_t method;
  struct HttpSlice k;
  struct HttpSlice uri;
  struct HttpSlice scratch;
  struct HttpSlice message;
  struct HttpSlice headers[kHttpHeadersMax];
  struct HttpHeaders xheaders;
};

struct HttpUnchunker {
  int t;
  size_t i;
  size_t j;
  ssize_t m;
};

extern const char kHttpToken[256];
extern const bool kHttpRepeatable[kHttpHeadersMax];

const char *GetHttpReason(int);
const char *GetHttpHeaderName(int);
int GetHttpHeader(const char *, size_t);
void InitHttpMessage(struct HttpMessage *, int);
void DestroyHttpMessage(struct HttpMessage *);
int ParseHttpMessage(struct HttpMessage *, const char *, size_t);
bool HeaderHas(struct HttpMessage *, const char *, int, const char *, size_t);
int64_t ParseContentLength(const char *, size_t);
char *FormatHttpDateTime(char[hasatleast 30], struct tm *);
bool ParseHttpRange(const char *, size_t, long, long *, long *);
int64_t ParseHttpDateTime(const char *, size_t);
uint64_t ParseHttpMethod(const char *, size_t);
bool IsValidHttpToken(const char *, size_t);
bool IsValidCookieValue(const char *, size_t);
bool IsAcceptablePath(const char *, size_t);
bool IsAcceptableHost(const char *, size_t);
bool IsAcceptablePort(const char *, size_t);
bool IsReasonablePath(const char *, size_t);
int ParseForwarded(const char *, size_t, uint32_t *, uint16_t *);
bool IsMimeType(const char *, size_t, const char *);
ssize_t Unchunk(struct HttpUnchunker *, char *, size_t, size_t *);
const char *FindContentType(const char *, size_t);
bool IsNoCompressExt(const char *, size_t);
char *FoldHeader(struct HttpMessage *, const char *, int, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/ip.h */

#define COSMOPOLITAN_NET_HTTP_IP_H_

#define kIpUnknown    0
#define kIpMulticast  1
#define kIpLoopback   2
#define kIpPrivate    3
#define kIpTestnet    4
#define kIpAfrinic    5
#define kIpLacnic     6
#define kIpApnic      7
#define kIpArin       8
#define kIpRipe       9
#define kIpDod        10
#define kIpAtt        11
#define kIpApple      12
#define kIpFord       13
#define kIpCogent     14
#define kIpPrudential 15
#define kIpUsps       16
#define kIpComcast    17
#define kIpFuture     18
#define kIpAnonymous  19

COSMOPOLITAN_C_START_

struct Cidr {
  int64_t addr;
  int cidr;
};

int64_t ParseIp(const char *, size_t);
struct Cidr ParseCidr(const char *, size_t);
bool IsDodIp(uint32_t);
bool IsArinIp(uint32_t);
bool IsRipeIp(uint32_t);
bool IsApnicIp(uint32_t);
bool IsLacnicIp(uint32_t);
bool IsPublicIp(uint32_t);
bool IsPrivateIp(uint32_t);
bool IsAfrinicIp(uint32_t);
bool IsTestnetIp(uint32_t);
bool IsLoopbackIp(uint32_t);
bool IsMulticastIp(uint32_t);
bool IsAnonymousIp(uint32_t);
int CategorizeIp(uint32_t);
const char *GetIpCategoryName(int);
bool IsCloudflareIp(uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/tokenbucket.h */

#define COSMOPOLITAN_NET_HTTP_TOKENBUCKET_H_
COSMOPOLITAN_C_START_

void ReplenishTokens(atomic_uint_fast64_t *, size_t);
int AcquireToken(atomic_schar *, uint32_t, int);
int CountTokens(atomic_schar *, uint32_t, int);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/url.h */

#define COSMOPOLITAN_NET_HTTP_URL_H_

#define kUrlPlus   1
#define kUrlLatin1 2
#define kUrlOpaque 4

COSMOPOLITAN_C_START_

struct UrlView {
  size_t n;
  char *p;
};

struct UrlParams {
  size_t n;
  struct UrlParam {
    struct UrlView key;
    struct UrlView val;
  } * p;
};

struct Url {
  struct UrlView scheme; /* must be [A-Za-z][-+.0-9A-Za-z]* or empty */
  struct UrlView user;   /* depends on host non-absence */
  struct UrlView pass;   /* depends on user non-absence */
  struct UrlView host;   /* or reg_name */
  struct UrlView port;   /* depends on host non-absence */
  struct UrlView path;   /* or opaque_part */
  struct UrlParams params;
  struct UrlView fragment;
};

char *EncodeUrl(struct Url *, size_t *);
char *ParseUrl(const char *, size_t, struct Url *, int);
char *ParseParams(const char *, size_t, struct UrlParams *);
char *ParseHost(const char *, size_t, struct Url *);
char *EscapeUrlView(char *, struct UrlView *, const char[256]);

COSMOPOLITAN_C_END_


/*!BEGIN tool/args/args.h */

#define COSMOPOLITAN_TOOL_ARGS_ARGS_H_
COSMOPOLITAN_C_START_

int LoadZipArgs(int *, char ***);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/dlmalloc/dlmalloc.h */

#define COSMOPOLITAN_THIRD_PARTY_DLMALLOC_DLMALLOC_H_

#define dlbulk_free                  __dlbulk_free
#define dlcalloc                     __dlcalloc
#define dlfree                       __dlfree
#define dlindependent_calloc         __dlindependent_calloc
#define dlindependent_comalloc       __dlindependent_comalloc
#define dlmallinfo                   __dlmallinfo
#define dlmalloc                     __dlmalloc
#define dlmalloc_abort               __dlmalloc_abort
#define dlmalloc_atfork              __dlmalloc_atfork
#define dlmalloc_footprint           __dlmalloc_footprint
#define dlmalloc_footprint_limit     __dlmalloc_footprint_limit
#define dlmalloc_inspect_all         __dlmalloc_inspect_all
#define dlmalloc_max_footprint       __dlmalloc_max_footprint
#define dlmalloc_set_footprint_limit __dlmalloc_set_footprint_limit
#define dlmalloc_stats               __dlmalloc_stats
#define dlmalloc_trim                __dlmalloc_trim
#define dlmalloc_usable_size         __dlmalloc_usable_size
#define dlmallopt                    __dlmallopt
#define dlmallopt                    __dlmallopt
#define dlmemalign                   __dlmemalign
#define dlrealloc                    __dlrealloc
#define dlrealloc_in_place           __dlrealloc_in_place
#define dlrealloc_in_place           __dlrealloc_in_place

COSMOPOLITAN_C_START_

/*
  malloc(size_t n)
  Returns a pointer to a newly allocated chunk of at least n bytes, or
  null if no space is available, in which case errno is set to ENOMEM
  on ANSI C systems.

  If n is zero, malloc returns a minimum-sized chunk. (The minimum
  size is 16 bytes on most 32bit systems, and 32 bytes on 64bit
  systems.)  Note that size_t is an unsigned type, so calls with
  arguments that would be negative if signed are interpreted as
  requests for huge amounts of space, which will often fail. The
  maximum supported value of n differs across systems, but is in all
  cases less than the maximum representable value of a size_t.
*/
void* dlmalloc(size_t);

/*
  free(void* p)
  Releases the chunk of memory pointed to by p, that had been previously
  allocated using malloc or a related routine such as realloc.
  It has no effect if p is null. If p was not malloced or already
  freed, free(p) will by default cuase the current program to abort.
*/
void dlfree(void*);

/*
  calloc(size_t n_elements, size_t element_size);
  Returns a pointer to n_elements * element_size bytes, with all locations
  set to zero.
*/
void* dlcalloc(size_t, size_t);

/*
  realloc(void* p, size_t n)
  Returns a pointer to a chunk of size n that contains the same data
  as does chunk p up to the minimum of (n, p's size) bytes, or null
  if no space is available.

  The returned pointer may or may not be the same as p. The algorithm
  prefers extending p in most cases when possible, otherwise it
  employs the equivalent of a malloc-copy-free sequence.

  If p is null, realloc is equivalent to malloc.

  If space is not available, realloc returns null, errno is set (if on
  ANSI) and p is NOT freed.

  if n is for fewer bytes than already held by p, the newly unused
  space is lopped off and freed if possible.  realloc with a size
  argument of zero (re)allocates a minimum-sized chunk.

  The old unix realloc convention of allowing the last-free'd chunk
  to be used as an argument to realloc is not supported.
*/
void* dlrealloc(void*, size_t);

/*
  realloc_in_place(void* p, size_t n)
  Resizes the space allocated for p to size n, only if this can be
  done without moving p (i.e., only if there is adjacent space
  available if n is greater than p's current allocated size, or n is
  less than or equal to p's size). This may be used instead of plain
  realloc if an alternative allocation strategy is needed upon failure
  to expand space; for example, reallocation of a buffer that must be
  memory-aligned or cleared. You can use realloc_in_place to trigger
  these alternatives only when needed.

  Returns p if successful; otherwise null.
*/
void* dlrealloc_in_place(void*, size_t);

/*
  memalign(size_t alignment, size_t n);
  Returns a pointer to a newly allocated chunk of n bytes, aligned
  in accord with the alignment argument.

  The alignment argument should be a power of two. If the argument is
  not a power of two, the nearest greater power is used.
  8-byte alignment is guaranteed by normal malloc calls, so don't
  bother calling memalign with an argument of 8 or less.

  Overreliance on memalign is a sure way to fragment space.
*/
void* dlmemalign(size_t, size_t);

/*
  mallopt(int parameter_number, int parameter_value)
  Sets tunable parameters The format is to provide a
  (parameter-number, parameter-value) pair.  mallopt then sets the
  corresponding parameter to the argument value if it can (i.e., so
  long as the value is meaningful), and returns 1 if successful else
  0.  SVID/XPG/ANSI defines four standard param numbers for mallopt,
  normally defined in malloc.h.  None of these are use in this malloc,
  so setting them has no effect. But this malloc also supports other
  options in mallopt:

  Symbol            param #  default    allowed param values
  M_TRIM_THRESHOLD     -1   2*1024*1024   any   (-1U disables trimming)
  M_GRANULARITY        -2     page size   any power of 2 >= page size
  M_MMAP_THRESHOLD     -3      256*1024   any   (or 0 if no MMAP support)
*/
int dlmallopt(int, int);

/*
  malloc_footprint();
  Returns the number of bytes obtained from the system.  The total
  number of bytes allocated by malloc, realloc etc., is less than this
  value. Unlike mallinfo, this function returns only a precomputed
  result, so can be called frequently to monitor memory consumption.
  Even if locks are otherwise defined, this function does not use them,
  so results might not be up to date.
*/
size_t dlmalloc_footprint(void);

/*
  malloc_max_footprint();
  Returns the maximum number of bytes obtained from the system. This
  value will be greater than current footprint if deallocated space
  has been reclaimed by the system. The peak number of bytes allocated
  by malloc, realloc etc., is less than this value. Unlike mallinfo,
  this function returns only a precomputed result, so can be called
  frequently to monitor memory consumption.  Even if locks are
  otherwise defined, this function does not use them, so results might
  not be up to date.
*/
size_t dlmalloc_max_footprint(void);

/*
  malloc_footprint_limit();
  Returns the number of bytes that the heap is allowed to obtain from
  the system, returning the last value returned by
  malloc_set_footprint_limit, or the maximum size_t value if
  never set. The returned value reflects a permission. There is no
  guarantee that this number of bytes can actually be obtained from
  the system.
*/
size_t dlmalloc_footprint_limit(void);

/*
  malloc_set_footprint_limit();
  Sets the maximum number of bytes to obtain from the system, causing
  failure returns from malloc and related functions upon attempts to
  exceed this value. The argument value may be subject to page
  rounding to an enforceable limit; this actual value is returned.
  Using an argument of the maximum possible size_t effectively
  disables checks. If the argument is less than or equal to the
  current malloc_footprint, then all future allocations that require
  additional system memory will fail. However, invocation cannot
  retroactively deallocate existing used memory.
*/
size_t dlmalloc_set_footprint_limit(size_t bytes);

/*
  malloc_inspect_all(void(*handler)(void *start,
                                    void *end,
                                    size_t used_bytes,
                                    void* callback_arg),
                      void* arg);
  Traverses the heap and calls the given handler for each managed
  region, skipping all bytes that are (or may be) used for bookkeeping
  purposes.  Traversal does not include include chunks that have been
  directly memory mapped. Each reported region begins at the start
  address, and continues up to but not including the end address.  The
  first used_bytes of the region contain allocated data. If
  used_bytes is zero, the region is unallocated. The handler is
  invoked with the given callback argument. If locks are defined, they
  are held during the entire traversal. It is a bad idea to invoke
  other malloc functions from within the handler.

  For example, to count the number of in-use chunks with size greater
  than 1000, you could write:
  static int count = 0;
  void count_chunks(void* start, void* end, size_t used, void* arg) {
    if (used >= 1000) ++count;
  }
  then:
    malloc_inspect_all(count_chunks, NULL);

  malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined.
*/
void dlmalloc_inspect_all(void (*handler)(void*, void*, size_t, void*),
                          void* arg);

/*
  mallinfo()
  Returns (by copy) a struct containing various summary statistics:

  arena:     current total non-mmapped bytes allocated from system
  ordblks:   the number of free chunks
  smblks:    always zero.
  hblks:     current number of mmapped regions
  hblkhd:    total bytes held in mmapped regions
  usmblks:   the maximum total allocated space. This will be greater
                than current total if trimming has occurred.
  fsmblks:   always zero
  uordblks:  current total allocated space (normal or mmapped)
  fordblks:  total free space
  keepcost:  the maximum number of bytes that could ideally be released
               back to system via malloc_trim. ("ideally" means that
               it ignores page restrictions etc.)

  Because these fields are ints, but internal bookkeeping may
  be kept as longs, the reported values may wrap around zero and
  thus be inaccurate.
*/

struct mallinfo dlmallinfo(void);

/*
  independent_calloc(size_t n_elements, size_t element_size, void* chunks[]);

  independent_calloc is similar to calloc, but instead of returning a
  single cleared space, it returns an array of pointers to n_elements
  independent elements that can hold contents of size elem_size, each
  of which starts out cleared, and can be independently freed,
  realloc'ed etc. The elements are guaranteed to be adjacently
  allocated (this is not guaranteed to occur with multiple callocs or
  mallocs), which may also improve cache locality in some
  applications.

  The "chunks" argument is optional (i.e., may be null, which is
  probably the most typical usage). If it is null, the returned array
  is itself dynamically allocated and should also be freed when it is
  no longer needed. Otherwise, the chunks array must be of at least
  n_elements in length. It is filled in with the pointers to the
  chunks.

  In either case, independent_calloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and "chunks"
  is null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_calloc simplifies and speeds up implementations of many
  kinds of pools.  It may also be useful when constructing large data
  structures that initially have a fixed number of fixed-sized nodes,
  but the number is not known at compile time, and some of the nodes
  may later need to be freed. For example:

  struct Node { int item; struct Node* next; };

  struct Node* build_list() {
    struct Node** pool;
    int n = read_number_of_nodes_needed();
    if (n <= 0) return 0;
    pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
    if (pool == 0) die();
    // organize into a linked list...
    struct Node* first = pool[0];
    for (i = 0; i < n-1; ++i)
      pool[i]->next = pool[i+1];
    free(pool);     // Can now free the array (or not, if it is needed later)
    return first;
  }
*/
void** dlindependent_calloc(size_t, size_t, void**);

/*
  independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);

  independent_comalloc allocates, all at once, a set of n_elements
  chunks with sizes indicated in the "sizes" array.    It returns
  an array of pointers to these elements, each of which can be
  independently freed, realloc'ed etc. The elements are guaranteed to
  be adjacently allocated (this is not guaranteed to occur with
  multiple callocs or mallocs), which may also improve cache locality
  in some applications.

  The "chunks" argument is optional (i.e., may be null). If it is null
  the returned array is itself dynamically allocated and should also
  be freed when it is no longer needed. Otherwise, the chunks array
  must be of at least n_elements in length. It is filled in with the
  pointers to the chunks.

  In either case, independent_comalloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and chunks is
  null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_comallac differs from independent_calloc in that each
  element may have a different size, and also that it does not
  automatically clear elements.

  independent_comalloc can be used to speed up allocation in cases
  where several structs or objects must always be allocated at the
  same time.  For example:

  struct Head { ... }
  struct Foot { ... }

  void send_message(char* msg) {
    int msglen = strlen(msg);
    size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
    void* chunks[3];
    if (independent_comalloc(3, sizes, chunks) == 0)
      die();
    struct Head* head = (struct Head*)(chunks[0]);
    char*        body = (char*)(chunks[1]);
    struct Foot* foot = (struct Foot*)(chunks[2]);
    // ...
  }

  In general though, independent_comalloc is worth using only for
  larger values of n_elements. For small values, you probably won't
  detect enough difference from series of malloc calls to bother.

  Overuse of independent_comalloc can increase overall memory usage,
  since it cannot reuse existing noncontiguous small chunks that
  might be available for some of the elements.
*/
void** dlindependent_comalloc(size_t, size_t*, void**);

/*
  bulk_free(void* array[], size_t n_elements)
  Frees and clears (sets to null) each non-null pointer in the given
  array.  This is likely to be faster than freeing them one-by-one.
  If footers are used, pointers that have been allocated in different
  mspaces are not freed or cleared, and the count of all such pointers
  is returned.  For large arrays of pointers with poor locality, it
  may be worthwhile to sort this array before calling bulk_free.
*/
size_t dlbulk_free(void**, size_t n_elements);

/*
  malloc_trim(size_t pad);

  If possible, gives memory back to the system (via negative arguments
  to sbrk) if there is unused memory at the `high' end of the malloc
  pool or in unused MMAP segments. You can call this after freeing
  large blocks of memory to potentially reduce the system-level memory
  requirements of a program. However, it cannot guarantee to reduce
  memory. Under some allocation patterns, some large free blocks of
  memory will be locked between two used chunks, so they cannot be
  given back to the system.

  The `pad' argument to malloc_trim represents the amount of free
  trailing space to leave untrimmed. If this argument is zero, only
  the minimum amount of memory to maintain internal data structures
  will be left. Non-zero arguments can be supplied to maintain enough
  trailing space to service future expected allocations without having
  to re-obtain memory from the system.

  Malloc_trim returns 1 if it actually released any memory, else 0.
*/
int dlmalloc_trim(size_t);

/*
  malloc_stats();
  Prints on stderr the amount of space obtained from the system (both
  via sbrk and mmap), the maximum amount (which may be more than
  current if malloc_trim and/or munmap got called), and the current
  number of bytes allocated via malloc (or realloc, etc) but not yet
  freed. Note that this is the number of bytes allocated, not the
  number requested. It will be larger than the number requested
  because of alignment and bookkeeping overhead. Because it includes
  alignment wastage as being in use, this figure may be greater than
  zero even when no user-level chunks are allocated.

  The reported current and maximum system memory can be inaccurate if
  a program makes other calls to system memory allocation functions
  (normally sbrk) outside of malloc.

  malloc_stats prints only the most commonly interesting statistics.
  More information can be obtained by calling mallinfo.

  malloc_stats is not compiled if NO_MALLOC_STATS is defined.
*/
void dlmalloc_stats(void);

/*
  malloc_usable_size(void* p);

  Returns the number of bytes you can actually use in
  an allocated chunk, which may be more than you requested (although
  often not) due to alignment and minimum size constraints.
  You can use this many bytes without worrying about
  overwriting other allocated objects. This is not a particularly great
  programming practice. malloc_usable_size can be more useful in
  debugging and assertions, for example:

  p = malloc(n);
  assert(malloc_usable_size(p) >= 256);
*/
size_t dlmalloc_usable_size(void*);

/*
  mspace is an opaque type representing an independent
  region of space that supports mspace_malloc, etc.
*/
typedef void* mspace;

/*
  create_mspace creates and returns a new independent space with the
  given initial capacity, or, if 0, the default granularity size.  It
  returns null if there is no system memory available to create the
  space.  If argument locked is non-zero, the space uses a separate
  lock to control access. The capacity of the space will grow
  dynamically as needed to service mspace_malloc requests.  You can
  control the sizes of incremental increases of this space by
  compiling with a different DEFAULT_GRANULARITY or dynamically
  setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
  destroy_mspace destroys the given space, and attempts to return all
  of its memory back to the system, returning the total number of
  bytes freed. After destruction, the results of access to all memory
  used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

/*
  create_mspace_with_base uses the memory supplied as the initial base
  of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this
  space is used for bookkeeping, so the capacity must be at least this
  large. (Otherwise 0 is returned.) When this initial space is
  exhausted, additional memory will be obtained from the system.
  Destroying this space will deallocate all additionally allocated
  space (if possible) but not the initial base.
*/
mspace create_mspace_with_base(void* base, size_t capacity, int locked);

/*
  mspace_track_large_chunks controls whether requests for large chunks
  are allocated in their own untracked mmapped regions, separate from
  others in this mspace. By default large chunks are not tracked,
  which reduces fragmentation. However, such chunks are not
  necessarily released to the system upon destroy_mspace.  Enabling
  tracking by setting to true may increase fragmentation, but avoids
  leakage when relying on destroy_mspace to release all memory
  allocated using this space.  The function returns the previous
  setting.
*/
int mspace_track_large_chunks(mspace msp, int enable);

/*
  mspace_mallinfo behaves as mallinfo, but reports properties of
  the given space.
*/
struct mallinfo mspace_mallinfo(mspace msp);

/*
  An alias for mallopt.
*/
int mspace_mallopt(int, int);

/*
  The following operate identically to their malloc counterparts
  but operate only for the given mspace argument
*/
void* mspace_malloc(mspace msp, size_t bytes);
void mspace_free(mspace msp, void* mem);
void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
void* mspace_realloc(mspace msp, void* mem, size_t newsize);
void* mspace_realloc_in_place(mspace msp, void* mem, size_t newsize);
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
void** mspace_independent_calloc(mspace msp, size_t n_elements,
                                 size_t elem_size, void* chunks[]);
void** mspace_independent_comalloc(mspace msp, size_t n_elements,
                                   size_t sizes[], void* chunks[]);
size_t mspace_bulk_free(mspace msp, void**, size_t n_elements);
size_t mspace_usable_size(const void* mem);
void mspace_malloc_stats(mspace msp);
int mspace_trim(mspace msp, size_t pad);
size_t mspace_footprint(mspace msp);
size_t mspace_max_footprint(mspace msp);
size_t mspace_footprint_limit(mspace msp);
size_t mspace_set_footprint_limit(mspace msp, size_t bytes);
void mspace_inspect_all(mspace msp,
                        void (*handler)(void*, void*, size_t, void*),
                        void* arg);

void dlmalloc_atfork(void);
void dlmalloc_abort(void) relegated wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/gdtoa/gdtoa.h */

#define COSMOPOLITAN_THIRD_PARTY_GDTOA_GDTOA_H_
COSMOPOLITAN_C_START_

#define dtoa      __dtoa
#define gdtoa     __gdtoa
#define strtodg   __strtodg
#define freedtoa  __freedtoa
#define g_ddfmt   __g_ddfmt
#define g_ddfmt_p __g_ddfmt_p
#define g_dfmt    __g_dfmt
#define g_dfmt_p  __g_dfmt_p
#define g_ffmt    __g_ffmt
#define g_ffmt_p  __g_ffmt_p
#define g_Qfmt    __g_Qfmt
#define g_Qfmt_p  __g_Qfmt_p
#define g_xfmt    __g_xfmt
#define g_xfmt_p  __g_xfmt_p
#define g_xLfmt   __g_xLfmt
#define g_xLfmt_p __g_xLfmt_p
#define strtoId   __strtoId
#define strtoIdd  __strtoIdd
#define strtoIf   __strtoIf
#define strtoIQ   __strtoIQ
#define strtoIx   __strtoIx
#define strtoIxL  __strtoIxL
#define strtord   __strtord
#define strtordd  __strtordd
#define strtorf   __strtorf
#define strtorQ   __strtorQ
#define strtorx   __strtorx
#define strtorxL  __strtorxL
#define strtodI   __strtodI
#define strtopd   __strtopd
#define strtopdd  __strtopdd
#define strtopf   __strtopf
#define strtopQ   __strtopQ
#define strtopx   __strtopx
#define strtopxL  __strtopxL

/**
 * Configures g_*fmt()
 *
 * @param ic
 * 	0 ==> Infinity or NaN
 * 	1 ==> infinity or nan
 * 	2 ==> INFINITY or NAN
 * 	3 ==> Inf or NaN
 * 	4 ==> inf or nan
 * 	5 ==> INF or NAN
 * @param ic determines if NaNs are rendered as NaN(...)
 * 	0 ==> no
 * 	1 ==> yes
 * 	2 ==> no for default NaN values; yes otherwise
 * @param ns determines sign of NaN values reported
 * 	0 ==> distinguish NaN and -NaN
 * 	1 ==> report both as NaN
 */
#define NIK(ic, nb, ns) (ic + 6 * (nb + 3 * ns))

enum {
  /* return values from strtodg */
  STRTOG_Zero = 0,
  STRTOG_Normal = 1,
  STRTOG_Denormal = 2,
  STRTOG_Infinite = 3,
  STRTOG_NaN = 4,
  STRTOG_NaNbits = 5,
  STRTOG_NoNumber = 6,
  STRTOG_Retmask = 7,
  /* The following may be or-ed into one of the above values. */
  STRTOG_Neg = 0x08,    /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
  STRTOG_Inexlo = 0x10, /* returned result rounded toward zero */
  STRTOG_Inexhi = 0x20, /* returned result rounded away from zero */
  STRTOG_Inexact = 0x30,
  STRTOG_Underflow = 0x40,
  STRTOG_Overflow = 0x80
};

typedef struct FPI {
  int nbits;
  int emin;
  int emax;
  int rounding;
  int sudden_underflow;
  int int_max;
} FPI;

enum {
  /* FPI.rounding values: same as FLT_ROUNDS */
  FPI_Round_zero = 0,
  FPI_Round_near = 1,
  FPI_Round_up = 2,
  FPI_Round_down = 3
};

char *dtoa(double, int, int, int *, int *, char **);
char *gdtoa(const FPI *, int, unsigned *, int *, int, int, int *, char **);
int strtodg(const char *, char **, const FPI *, int *, unsigned *);
void freedtoa(char *);

char *g_ddfmt(char *, double *, int, size_t);
char *g_ddfmt_p(char *, double *, int, size_t, int);
char *g_dfmt(char *, double *, int, size_t);
char *g_dfmt_p(char *, double *, int, size_t, int);
char *g_ffmt(char *, float *, int, size_t);
char *g_ffmt_p(char *, float *, int, size_t, int);
char *g_Qfmt(char *, void *, int, size_t);
char *g_Qfmt_p(char *, void *, int, size_t, int);
char *g_xfmt(char *, void *, int, size_t);
char *g_xfmt_p(char *, void *, int, size_t, int);
char *g_xLfmt(char *, void *, int, size_t);
char *g_xLfmt_p(char *, void *, int, size_t, int);

int strtoId(const char *, char **, double *, double *);
int strtoIdd(const char *, char **, double *, double *);
int strtoIf(const char *, char **, float *, float *);
int strtoIQ(const char *, char **, void *, void *);
int strtoIx(const char *, char **, void *, void *);
int strtoIxL(const char *, char **, void *, void *);
int strtord(const char *, char **, int, double *);
int strtordd(const char *, char **, int, double *);
int strtorf(const char *, char **, int, float *);
int strtorQ(const char *, char **, int, void *);
int strtorx(const char *, char **, int, void *);
int strtorxL(const char *, char **, int, void *);

int strtodI(const char *, char **, double *);
int strtopd(const char *, char **, double *);
int strtopdd(const char *, char **, double *);
int strtopf(const char *, char **, float *);
int strtopQ(const char *, char **, void *);
int strtopx(const char *, char **, void *);
int strtopxL(const char *, char **, void *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long1.h */

#define _GETOPT_CORE_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif
COSMOPOLITAN_C_START_

extern char *optarg;
extern int optind, opterr, optopt, optreset;

int getopt(int, char *const *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long2.h */

#define _GETOPT_EXT_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif

#define no_argument       0
#define required_argument 1
#define optional_argument 2

COSMOPOLITAN_C_START_

struct option {
  const char *name;
  int has_arg;
  int *flag;
  int val;
};

int getopt_long(int, char *const *, const char *, const struct option *, int *);
int getopt_long_only(int, char *const *, const char *, const struct option *,
                     int *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/crypt.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_CRYPT_H_
COSMOPOLITAN_C_START_

struct crypt_data {
  int initialized;
  char __buf[256];
};

char *crypt(const char *, const char *) libcesque;
char *crypt_r(const char *, const char *, struct crypt_data *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/fnmatch.h */

#define COSMOPOLITAN_THIRD_PARTY_REGEX_FNMATCH_H_
COSMOPOLITAN_C_START_

#define FNM_PATHNAME    0x1
#define FNM_NOESCAPE    0x2
#define FNM_PERIOD      0x4
#define FNM_LEADING_DIR 0x8
#define FNM_CASEFOLD    0x10
#define FNM_FILE_NAME   FNM_PATHNAME

#define FNM_NOMATCH 1
#define FNM_NOSYS   (-1)

int fnmatch(const char *, const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/glob.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_GLOB_H_
COSMOPOLITAN_C_START_

#define GLOB_ERR      0x01
#define GLOB_MARK     0x02
#define GLOB_NOSORT   0x04
#define GLOB_DOOFFS   0x08 /* reserves null slots at start of gl_pathv */
#define GLOB_NOCHECK  0x10 /* just yield pattern if GLOB_NOMATCH happens */
#define GLOB_APPEND   0x20 /* enables us to call glob() multiple times */
#define GLOB_NOESCAPE 0x40 /* don't allow things like \*\?\[\] escaping */
#define GLOB_PERIOD   0x80

#define GLOB_TILDE       0x1000
#define GLOB_TILDE_CHECK 0x4000

#define GLOB_NOSPACE 1
#define GLOB_ABORTED 2
#define GLOB_NOMATCH 3
#define GLOB_NOSYS   4

typedef struct {
  size_t gl_pathc;
  char **gl_pathv;
  size_t gl_offs;
  int __dummy1;
  void *__dummy2[5];
} glob_t;

int glob(const char *, int, int (*)(const char *, int), glob_t *);
void globfree(glob_t *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/lockf.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_LOCKF_H_

#define F_ULOCK 0
#define F_LOCK  1
#define F_TLOCK 2
#define F_TEST  3

COSMOPOLITAN_C_START_

int lockf(int, int, int64_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/mntent.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_MNTENT_H_
COSMOPOLITAN_C_START_

#define MOUNTED "/etc/mtab"

#define MNTTYPE_IGNORE  "ignore"
#define MNTTYPE_NFS     "nfs"
#define MNTTYPE_SWAP    "swap"
#define MNTOPT_DEFAULTS "defaults"
#define MNTOPT_RO       "ro"
#define MNTOPT_RW       "rw"
#define MNTOPT_SUID     "suid"
#define MNTOPT_NOSUID   "nosuid"
#define MNTOPT_NOAUTO   "noauto"

struct mntent {
  char *mnt_fsname;
  char *mnt_dir;
  char *mnt_type;
  char *mnt_opts;
  int mnt_freq;
  int mnt_passno;
};

FILE *setmntent(const char *, const char *);
int endmntent(FILE *);
struct mntent *getmntent(FILE *);
struct mntent *getmntent_r(FILE *, struct mntent *, char *, int);
int addmntent(FILE *, const struct mntent *);
char *hasmntopt(const struct mntent *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/nameser.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NAMESER_H_
COSMOPOLITAN_C_START_

#define __NAMESER	19991006
#define NS_PACKETSZ	512
#define NS_MAXDNAME	1025
#define NS_MAXMSG	65535
#define NS_MAXCDNAME	255
#define NS_MAXLABEL	63
#define NS_HFIXEDSZ	12
#define NS_QFIXEDSZ	4
#define NS_RRFIXEDSZ	10
#define NS_INT32SZ	4
#define NS_INT16SZ	2
#define NS_INT8SZ	1
#define NS_INADDRSZ	4
#define NS_IN6ADDRSZ	16
#define NS_CMPRSFLGS	0xc0
#define NS_DEFAULTPORT	53

typedef enum __ns_sect {
	ns_s_qd = 0,
	ns_s_zn = 0,
	ns_s_an = 1,
	ns_s_pr = 1,
	ns_s_ns = 2,
	ns_s_ud = 2,
	ns_s_ar = 3,
	ns_s_max = 4
} ns_sect;

typedef struct __ns_msg {
	const unsigned char *_msg, *_eom;
	uint16_t _id, _flags, _counts[ns_s_max];
	const unsigned char *_sections[ns_s_max];
	ns_sect _sect;
	int _rrnum;
	const unsigned char *_msg_ptr;
} ns_msg;

struct _ns_flagdata {  int mask, shift;  };
extern const struct _ns_flagdata _ns_flagdata[];

#define ns_msg_id(handle) ((handle)._id + 0)
#define ns_msg_base(handle) ((handle)._msg + 0)
#define ns_msg_end(handle) ((handle)._eom + 0)
#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
#define ns_msg_getflag(handle, flag) \
	(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)

typedef	struct __ns_rr {
	char		name[NS_MAXDNAME];
	uint16_t	type;
	uint16_t	rr_class;
	uint32_t	ttl;
	uint16_t	rdlength;
	const unsigned char *rdata;
} ns_rr;

#define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
#define ns_rr_type(rr)	((ns_type)((rr).type + 0))
#define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0))
#define ns_rr_ttl(rr)	((rr).ttl + 0)
#define ns_rr_rdlen(rr)	((rr).rdlength + 0)
#define ns_rr_rdata(rr)	((rr).rdata + 0)

typedef enum __ns_flag {
	ns_f_qr,
	ns_f_opcode,
	ns_f_aa,
	ns_f_tc,
	ns_f_rd,
	ns_f_ra,
	ns_f_z,
	ns_f_ad,
	ns_f_cd,
	ns_f_rcode,
	ns_f_max
} ns_flag;

typedef enum __ns_opcode {
	ns_o_query = 0,
	ns_o_iquery = 1,
	ns_o_status = 2,
	ns_o_notify = 4,
	ns_o_update = 5,
	ns_o_max = 6
} ns_opcode;

typedef	enum __ns_rcode {
	ns_r_noerror = 0,
	ns_r_formerr = 1,
	ns_r_servfail = 2,
	ns_r_nxdomain = 3,
	ns_r_notimpl = 4,
	ns_r_refused = 5,
	ns_r_yxdomain = 6,
	ns_r_yxrrset = 7,
	ns_r_nxrrset = 8,
	ns_r_notauth = 9,
	ns_r_notzone = 10,
	ns_r_max = 11,
	ns_r_badvers = 16,
	ns_r_badsig = 16,
	ns_r_badkey = 17,
	ns_r_badtime = 18
} ns_rcode;

typedef enum __ns_update_operation {
	ns_uop_delete = 0,
	ns_uop_add = 1,
	ns_uop_max = 2
} ns_update_operation;

struct ns_tsig_key {
        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
        unsigned char *data;
        int len;
};
typedef struct ns_tsig_key ns_tsig_key;

struct ns_tcp_tsig_state {
	int counter;
	struct dst_key *key;
	void *ctx;
	unsigned char sig[NS_PACKETSZ];
	int siglen;
};
typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;

#define NS_TSIG_FUDGE 300
#define NS_TSIG_TCP_COUNT 100
#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"

#define NS_TSIG_ERROR_NO_TSIG -10
#define NS_TSIG_ERROR_NO_SPACE -11
#define NS_TSIG_ERROR_FORMERR -12

typedef enum __ns_type {
	ns_t_invalid = 0,
	ns_t_a = 1,
	ns_t_ns = 2,
	ns_t_md = 3,
	ns_t_mf = 4,
	ns_t_cname = 5,
	ns_t_soa = 6,
	ns_t_mb = 7,
	ns_t_mg = 8,
	ns_t_mr = 9,
	ns_t_null = 10,
	ns_t_wks = 11,
	ns_t_ptr = 12,
	ns_t_hinfo = 13,
	ns_t_minfo = 14,
	ns_t_mx = 15,
	ns_t_txt = 16,
	ns_t_rp = 17,
	ns_t_afsdb = 18,
	ns_t_x25 = 19,
	ns_t_isdn = 20,
	ns_t_rt = 21,
	ns_t_nsap = 22,
	ns_t_nsap_ptr = 23,
	ns_t_sig = 24,
	ns_t_key = 25,
	ns_t_px = 26,
	ns_t_gpos = 27,
	ns_t_aaaa = 28,
	ns_t_loc = 29,
	ns_t_nxt = 30,
	ns_t_eid = 31,
	ns_t_nimloc = 32,
	ns_t_srv = 33,
	ns_t_atma = 34,
	ns_t_naptr = 35,
	ns_t_kx = 36,
	ns_t_cert = 37,
	ns_t_a6 = 38,
	ns_t_dname = 39,
	ns_t_sink = 40,
	ns_t_opt = 41,
	ns_t_apl = 42,
	ns_t_tkey = 249,
	ns_t_tsig = 250,
	ns_t_ixfr = 251,
	ns_t_axfr = 252,
	ns_t_mailb = 253,
	ns_t_maila = 254,
	ns_t_any = 255,
	ns_t_zxfr = 256,
	ns_t_max = 65536
} ns_type;

#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
		      (t) == ns_t_mailb || (t) == ns_t_maila)
#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
		       (t) == ns_t_zxfr)

typedef enum __ns_class {
	ns_c_invalid = 0,
	ns_c_in = 1,
	ns_c_2 = 2,
	ns_c_chaos = 3,
	ns_c_hs = 4,
	ns_c_none = 254,
	ns_c_any = 255,
	ns_c_max = 65536
} ns_class;

typedef enum __ns_key_types {
	ns_kt_rsa = 1,
	ns_kt_dh  = 2,
	ns_kt_dsa = 3,
	ns_kt_private = 254
} ns_key_types;

typedef enum __ns_cert_types {
	cert_t_pkix = 1,
	cert_t_spki = 2,
	cert_t_pgp  = 3,
	cert_t_url  = 253,
	cert_t_oid  = 254
} ns_cert_types;

#define	NS_KEY_TYPEMASK		0xC000
#define	NS_KEY_TYPE_AUTH_CONF	0x0000
#define	NS_KEY_TYPE_CONF_ONLY	0x8000
#define	NS_KEY_TYPE_AUTH_ONLY	0x4000
#define	NS_KEY_TYPE_NO_KEY	0xC000
#define	NS_KEY_NO_AUTH		0x8000
#define	NS_KEY_NO_CONF		0x4000
#define	NS_KEY_RESERVED2	0x2000
#define	NS_KEY_EXTENDED_FLAGS	0x1000
#define	NS_KEY_RESERVED4	0x0800
#define	NS_KEY_RESERVED5	0x0400
#define	NS_KEY_NAME_TYPE	0x0300
#define	NS_KEY_NAME_USER	0x0000
#define	NS_KEY_NAME_ENTITY	0x0200
#define	NS_KEY_NAME_ZONE	0x0100
#define	NS_KEY_NAME_RESERVED	0x0300
#define	NS_KEY_RESERVED8	0x0080
#define	NS_KEY_RESERVED9	0x0040
#define	NS_KEY_RESERVED10	0x0020
#define	NS_KEY_RESERVED11	0x0010
#define	NS_KEY_SIGNATORYMASK	0x000F
#define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
				  NS_KEY_RESERVED4 | \
				  NS_KEY_RESERVED5 | \
				  NS_KEY_RESERVED8 | \
				  NS_KEY_RESERVED9 | \
				  NS_KEY_RESERVED10 | \
				  NS_KEY_RESERVED11 )
#define NS_KEY_RESERVED_BITMASK2 0xFFFF
#define	NS_ALG_MD5RSA		1
#define	NS_ALG_DH               2
#define	NS_ALG_DSA              3
#define	NS_ALG_DSS              NS_ALG_DSA
#define	NS_ALG_EXPIRE_ONLY	253
#define	NS_ALG_PRIVATE_OID	254

#define NS_KEY_PROT_TLS         1
#define NS_KEY_PROT_EMAIL       2
#define NS_KEY_PROT_DNSSEC      3
#define NS_KEY_PROT_IPSEC       4
#define NS_KEY_PROT_ANY		255

#define	NS_MD5RSA_MIN_BITS	 512
#define	NS_MD5RSA_MAX_BITS	4096
#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
#define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
#define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
#define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)

#define NS_DSA_SIG_SIZE         41
#define NS_DSA_MIN_SIZE         213
#define NS_DSA_MAX_BYTES        405

#define	NS_SIG_TYPE	0
#define	NS_SIG_ALG	2
#define	NS_SIG_LABELS	3
#define	NS_SIG_OTTL	4
#define	NS_SIG_EXPIR	8
#define	NS_SIG_SIGNED	12
#define	NS_SIG_FOOT	16
#define	NS_SIG_SIGNER	18
#define	NS_NXT_BITS 8
#define	NS_NXT_BIT_SET(  n,p) (p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
#define NS_NXT_MAX 127

#define NS_OPT_DNSSEC_OK        0x8000U
#define NS_OPT_NSID		3

#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2))
#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4))
#define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2)
#define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4)

unsigned ns_get16(const unsigned char *);
unsigned long ns_get32(const unsigned char *);
void ns_put16(unsigned, unsigned char *);
void ns_put32(unsigned long, unsigned char *);

int ns_initparse(const unsigned char *, int, ns_msg *);
int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int);
int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t);


#define	__BIND		19950621

typedef struct {
	unsigned	id :16;
#if __BYTE_ORDER == __BIG_ENDIAN
	unsigned	qr: 1;
	unsigned	opcode: 4;
	unsigned	aa: 1;
	unsigned	tc: 1;
	unsigned	rd: 1;
	unsigned	ra: 1;
	unsigned	unused :1;
	unsigned	ad: 1;
	unsigned	cd: 1;
	unsigned	rcode :4;
#else
	unsigned	rd :1;
	unsigned	tc :1;
	unsigned	aa :1;
	unsigned	opcode :4;
	unsigned	qr :1;
	unsigned	rcode :4;
	unsigned	cd: 1;
	unsigned	ad: 1;
	unsigned	unused :1;
	unsigned	ra :1;
#endif
	unsigned	qdcount :16;
	unsigned	ancount :16;
	unsigned	nscount :16;
	unsigned	arcount :16;
} HEADER;

#define PACKETSZ	NS_PACKETSZ
#define MAXDNAME	NS_MAXDNAME
#define MAXCDNAME	NS_MAXCDNAME
#define MAXLABEL	NS_MAXLABEL
#define	HFIXEDSZ	NS_HFIXEDSZ
#define QFIXEDSZ	NS_QFIXEDSZ
#define RRFIXEDSZ	NS_RRFIXEDSZ
#define	INT32SZ		NS_INT32SZ
#define	INT16SZ		NS_INT16SZ
#define INT8SZ		NS_INT8SZ
#define	INADDRSZ	NS_INADDRSZ
#define	IN6ADDRSZ	NS_IN6ADDRSZ
#define	INDIR_MASK	NS_CMPRSFLGS
#define NAMESERVER_PORT	NS_DEFAULTPORT

#define S_ZONE		ns_s_zn
#define S_PREREQ	ns_s_pr
#define S_UPDATE	ns_s_ud
#define S_ADDT		ns_s_ar

#define QUERY		ns_o_query
#define IQUERY		ns_o_iquery
#define STATUS		ns_o_status
#define	NS_NOTIFY_OP	ns_o_notify
#define	NS_UPDATE_OP	ns_o_update

#define NOERROR		ns_r_noerror
#define FORMERR		ns_r_formerr
#define SERVFAIL	ns_r_servfail
#define NXDOMAIN	ns_r_nxdomain
#define NOTIMP		ns_r_notimpl
#define REFUSED		ns_r_refused
#define YXDOMAIN	ns_r_yxdomain
#define YXRRSET		ns_r_yxrrset
#define NXRRSET		ns_r_nxrrset
#define NOTAUTH		ns_r_notauth
#define NOTZONE		ns_r_notzone

#define DELETE		ns_uop_delete
#define ADD		ns_uop_add

#define T_A		ns_t_a
#define T_NS		ns_t_ns
#define T_MD		ns_t_md
#define T_MF		ns_t_mf
#define T_CNAME		ns_t_cname
#define T_SOA		ns_t_soa
#define T_MB		ns_t_mb
#define T_MG		ns_t_mg
#define T_MR		ns_t_mr
#define T_NULL		ns_t_null
#define T_WKS		ns_t_wks
#define T_PTR		ns_t_ptr
#define T_HINFO		ns_t_hinfo
#define T_MINFO		ns_t_minfo
#define T_MX		ns_t_mx
#define T_TXT		ns_t_txt
#define	T_RP		ns_t_rp
#define T_AFSDB		ns_t_afsdb
#define T_X25		ns_t_x25
#define T_ISDN		ns_t_isdn
#define T_RT		ns_t_rt
#define T_NSAP		ns_t_nsap
#define T_NSAP_PTR	ns_t_nsap_ptr
#define	T_SIG		ns_t_sig
#define	T_KEY		ns_t_key
#define	T_PX		ns_t_px
#define	T_GPOS		ns_t_gpos
#define	T_AAAA		ns_t_aaaa
#define	T_LOC		ns_t_loc
#define	T_NXT		ns_t_nxt
#define	T_EID		ns_t_eid
#define	T_NIMLOC	ns_t_nimloc
#define	T_SRV		ns_t_srv
#define T_ATMA		ns_t_atma
#define T_NAPTR		ns_t_naptr
#define T_A6		ns_t_a6
#define T_DNAME		ns_t_dname
#define	T_TSIG		ns_t_tsig
#define	T_IXFR		ns_t_ixfr
#define T_AXFR		ns_t_axfr
#define T_MAILB		ns_t_mailb
#define T_MAILA		ns_t_maila
#define T_ANY		ns_t_any

#define C_IN		ns_c_in
#define C_CHAOS		ns_c_chaos
#define C_HS		ns_c_hs
#define C_NONE		ns_c_none
#define C_ANY		ns_c_any

#define	GETSHORT		NS_GET16
#define	GETLONG			NS_GET32
#define	PUTSHORT		NS_PUT16
#define	PUTLONG			NS_PUT32

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/netdb.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NETDB_H_
COSMOPOLITAN_C_START_

struct addrinfo {
	int ai_flags;
	int ai_family;
	int ai_socktype;
	int ai_protocol;
	uint32_t ai_addrlen;
	struct sockaddr *ai_addr;
	char *ai_canonname;
	struct addrinfo *ai_next;
};

#define AI_PASSIVE      0x01
#define AI_CANONNAME    0x02
#define AI_NUMERICHOST  0x04
#define AI_V4MAPPED     0x08
#define AI_ALL          0x10
#define AI_ADDRCONFIG   0x20
#define AI_NUMERICSERV  0x400

#define NI_NUMERICHOST  0x01
#define NI_NUMERICSERV  0x02
#define NI_NOFQDN       0x04
#define NI_NAMEREQD     0x08
#define NI_DGRAM        0x10
#define NI_NUMERICSCOPE 0x100

#define EAI_BADFLAGS   -1
#define EAI_NONAME     -2
#define EAI_AGAIN      -3
#define EAI_FAIL       -4
#define EAI_FAMILY     -6
#define EAI_SOCKTYPE   -7
#define EAI_SERVICE    -8
#define EAI_MEMORY     -10
#define EAI_SYSTEM     -11
#define EAI_OVERFLOW   -12

int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
void freeaddrinfo (struct addrinfo *);
int getnameinfo (const struct sockaddr *, uint32_t, char *, uint32_t, char *, uint32_t, int);
const char *gai_strerror(int);


/* Legacy functions follow (marked OBsolete in SUS) */

struct netent {
	char *n_name;
	char **n_aliases;
	int n_addrtype;
	uint32_t n_net;
};

struct hostent {
	char *h_name;
	char **h_aliases;
	int h_addrtype;
	int h_length;
	char **h_addr_list;
};
#define h_addr h_addr_list[0]

struct servent {
	char *s_name;
	char **s_aliases;
	int s_port;
	char *s_proto;
};

struct protoent {
	char *p_name;
	char **p_aliases;
	int p_proto;
};

void sethostent (int);
void endhostent (void);
struct hostent *gethostent (void);

void setnetent (int);
void endnetent (void);
struct netent *getnetent (void);
struct netent *getnetbyaddr (uint32_t, int);
struct netent *getnetbyname (const char *);

void setservent (int);
void endservent (void);
struct servent *getservent (void);
struct servent *getservbyname (const char *, const char *);
struct servent *getservbyport (int, const char *);

void setprotoent (int);
void endprotoent (void);
struct protoent *getprotoent (void);
struct protoent *getprotobyname (const char *);
struct protoent *getprotobynumber (int);

#define NI_MAXHOST 255
#define NI_MAXSERV 32

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
struct hostent *gethostbyname (const char *);
struct hostent *gethostbyaddr (const void *, uint32_t, int);
errno_t *__h_errno_location(void) dontthrow pureconst;
#define h_errno (*__h_errno_location())
#define HOST_NOT_FOUND 1
#define TRY_AGAIN      2
#define NO_RECOVERY    3
#define NO_DATA        4
#define NO_ADDRESS     NO_DATA
#endif

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
void herror(const char *);
const char *hstrerror(int);
int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
struct hostent *gethostbyname2(const char *, int);
int gethostbyaddr_r(const void *, uint32_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
#define EAI_NODATA     -5
#define EAI_ADDRFAMILY -9
#define EAI_INPROGRESS -100
#define EAI_CANCELED   -101
#define EAI_NOTCANCELED -102
#define EAI_ALLDONE    -103
#define EAI_INTR       -104
#define EAI_IDN_ENCODE -105
#endif

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/passwd.h */

#define COSMOPOLITAN_LIBC_PASSWD_H_
COSMOPOLITAN_C_START_

struct passwd {
  char *pw_name;
  char *pw_passwd;
  uid_t pw_uid;
  gid_t pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};

void setpwent(void);
void endpwent(void);
struct passwd *getpwent(void);
struct passwd *getpwuid(uid_t);
struct passwd *getpwnam(const char *);
int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
struct passwd *fgetpwent(FILE *);
int putpwent(const struct passwd *, FILE *);

struct group {
  char *gr_name;
  char *gr_passwd;
  gid_t gr_gid;
  char **gr_mem;
};

struct group *getgrgid(gid_t);
struct group *getgrnam(const char *);
int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
struct group *getgrent(void);
void endgrent(void);
void setgrent(void);
struct group *fgetgrent(FILE *);
int putgrent(const struct group *, FILE *);
int getgrouplist(const char *, gid_t, gid_t *, int *);
int initgroups(const char *, gid_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/rand48.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RAND48_H_
COSMOPOLITAN_C_START_

double drand48(void);
double erand48(unsigned short[3]);
long int lrand48(void);
long int nrand48(unsigned short[3]);
long mrand48(void);
long jrand48(unsigned short[3]);
void srand48(long);
unsigned short *seed48(unsigned short[3]);
void lcong48(unsigned short[7]);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/resolv.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RESOLV_H_
COSMOPOLITAN_C_START_

#define MAXNS			3
#define MAXDFLSRCH		3
#define MAXDNSRCH		6
#define LOCALDOMAINPARTS	2

#define RES_TIMEOUT		5
#define MAXRESOLVSORT		10
#define RES_MAXNDOTS		15
#define RES_MAXRETRANS		30
#define RES_MAXRETRY		5
#define RES_DFLRETRY		2
#define RES_MAXTIME		65535

/* unused; purely for broken apps */
typedef struct __res_state {
	int retrans;
	int retry;
	unsigned long options;
	int nscount;
	struct sockaddr_in nsaddr_list[MAXNS];
# define nsaddr	nsaddr_list[0]
	unsigned short id;
	char *dnsrch[MAXDNSRCH+1];
	char defdname[256];
	unsigned long pfcode;
	unsigned ndots:4;
	unsigned nsort:4;
	unsigned ipv6_unavail:1;
	unsigned unused:23;
	struct {
		struct in_addr addr;
		uint32_t mask;
	} sort_list[MAXRESOLVSORT];
	void *qhook;
	void *rhook;
	int res_h_errno;
	int _vcsock;
	unsigned _flags;
	union {
		char pad[52];
		struct {
			uint16_t		nscount;
			uint16_t		nsmap[MAXNS];
			int			nssocks[MAXNS];
			uint16_t		nscount6;
			uint16_t		nsinit;
			struct sockaddr_in6	*nsaddrs[MAXNS];
			unsigned int		_initstamp[2];
		} _ext;
	} _u;
} *res_state;

#define	__RES	19960801

#ifndef _PATH_RESCONF
#define _PATH_RESCONF        "/etc/resolv.conf"
#endif

struct res_sym {
	int number;
	char *name;
	char *humanname;
};

#define	RES_F_VC	0x00000001
#define	RES_F_CONN	0x00000002
#define RES_F_EDNS0ERR	0x00000004

#define	RES_EXHAUSTIVE	0x00000001

#define RES_INIT	0x00000001
#define RES_DEBUG	0x00000002
#define RES_AAONLY	0x00000004
#define RES_USEVC	0x00000008
#define RES_PRIMARY	0x00000010
#define RES_IGNTC	0x00000020
#define RES_RECURSE	0x00000040
#define RES_DEFNAMES	0x00000080
#define RES_STAYOPEN	0x00000100
#define RES_DNSRCH	0x00000200
#define	RES_INSECURE1	0x00000400
#define	RES_INSECURE2	0x00000800
#define	RES_NOALIASES	0x00001000
#define	RES_USE_INET6	0x00002000
#define RES_ROTATE	0x00004000
#define	RES_NOCHECKNAME	0x00008000
#define	RES_KEEPTSIG	0x00010000
#define	RES_BLAST	0x00020000
#define RES_USEBSTRING	0x00040000
#define RES_NOIP6DOTINT	0x00080000
#define RES_USE_EDNS0	0x00100000
#define RES_SNGLKUP	0x00200000
#define RES_SNGLKUPREOP	0x00400000
#define RES_USE_DNSSEC	0x00800000

#define RES_DEFAULT	(RES_RECURSE|RES_DEFNAMES|RES_DNSRCH|RES_NOIP6DOTINT)

#define RES_PRF_STATS	0x00000001
#define RES_PRF_UPDATE	0x00000002
#define RES_PRF_CLASS   0x00000004
#define RES_PRF_CMD	0x00000008
#define RES_PRF_QUES	0x00000010
#define RES_PRF_ANS	0x00000020
#define RES_PRF_AUTH	0x00000040
#define RES_PRF_ADD	0x00000080
#define RES_PRF_HEAD1	0x00000100
#define RES_PRF_HEAD2	0x00000200
#define RES_PRF_TTLID	0x00000400
#define RES_PRF_HEADX	0x00000800
#define RES_PRF_QUERY	0x00001000
#define RES_PRF_REPLY	0x00002000
#define RES_PRF_INIT	0x00004000

struct __res_state *__res_state(void);
#define _res (*__res_state())

int res_init(void);
int res_query(const char *, int, int, unsigned char *, int);
int res_querydomain(const char *, const char *, int, int, unsigned char *, int);
int res_search(const char *, int, int, unsigned char *, int);
int res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
int res_send(const unsigned char *, int, unsigned char *, int);
int dn_comp(const char *, unsigned char *, int, unsigned char **, unsigned char **);
int dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
int dn_skipname(const unsigned char *, const unsigned char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/search.h */

#define COSMOPOLITAN_THIRDPARTY_MUSL_SEARCH_H

typedef enum { FIND, ENTER } ACTION;
typedef enum { preorder, postorder, endorder, leaf } VISIT;

typedef struct entry {
	char *key;
	void *data;
} ENTRY;

int hcreate(size_t);
void hdestroy(void);
ENTRY *hsearch(ENTRY, ACTION);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct hsearch_data {
	struct __tab *__tab;
	unsigned int __unused1;
	unsigned int __unused2;
};

int hcreate_r(size_t, struct hsearch_data *);
void hdestroy_r(struct hsearch_data *);
int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *);
#endif

void insque(void *, void *);
void remque(void *);

void *lsearch(const void *, void *, size_t *, size_t,
	int (*)(const void *, const void *));
void *lfind(const void *, const void *, size_t *, size_t,
	int (*)(const void *, const void *));

void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *));
void *tfind(const void *, void *const *, int(*)(const void *, const void *));
void *tsearch(const void *, void **, int (*)(const void *, const void *));
void twalk(const void *, void (*)(const void *, VISIT, int));

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct qelem {
	struct qelem *q_forw, *q_back;
	char q_data[1];
};

void tdestroy(void *, void (*)(void *));
#endif



/*!BEGIN third_party/musl/shadow.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_SHADOW_H_
COSMOPOLITAN_C_START_

#define	SHADOW "/etc/shadow"

struct spwd {
	char *sp_namp;
	char *sp_pwdp;
	long sp_lstchg;
	long sp_min;
	long sp_max;
	long sp_warn;
	long sp_inact;
	long sp_expire;
	unsigned long sp_flag;
};

void setspent(void);
void endspent(void);
struct spwd *getspent(void);
struct spwd *fgetspent(FILE *);
struct spwd *sgetspent(const char *);
int putspent(const struct spwd *, FILE *);

struct spwd *getspnam(const char *);
int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **);

int lckpwdf(void);
int ulckpwdf(void);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/tempnam.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_TEMPNAM_H_
COSMOPOLITAN_C_START_

char *tempnam(const char *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/zlib/zconf.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZCONF_H_

#define STDC
#define STDC99
#define MAX_MEM_LEVEL 9
#define DEF_MEM_LEVEL 8
#define MAX_WBITS     15 /* 32K LZ77 window */

#ifdef MODE_DBG
#define ZLIB_DEBUG
#endif

#define z_const const

#define Z_COSMO_PREFIX_SET

#define Bytef                    _Cz_Bytef
#define _dist_code               _Cz__dist_code
#define _length_code             _Cz__length_code
#define _tr_align                _Cz__tr_align
#define _tr_flush_bits           _Cz__tr_flush_bits
#define _tr_flush_block          _Cz__tr_flush_block
#define _tr_init                 _Cz__tr_init
#define _tr_stored_block         _Cz__tr_stored_block
#define _tr_tally                _Cz__tr_tally
#define adler32                  _Cz_adler32
#define adler32_combine          _Cz_adler32_combine
#define adler32_combine64        _Cz_adler32_combine64
#define adler32_simd_            _Cz_adler32_simd_
#define adler32_z                _Cz_adler32_z
#define alloc_func               _Cz_alloc_func
#define arm_check_features       _Cz_arm_check_features
#define arm_cpu_enable_crc32     _Cz_arm_cpu_enable_crc32
#define arm_cpu_enable_pmull     _Cz_arm_cpu_enable_pmull
#define armv8_crc32_little       _Cz_armv8_crc32_little
#define armv8_crc32_pmull_little _Cz_armv8_crc32_pmull_little
#define charf                    _Cz_charf
#define compress                 _Cz_compress
#define compress2                _Cz_compress2
#define compressBound            _Cz_compressBound
#define copy_with_crc            _Cz_copy_with_crc
#define cpu_check_features       _Cz_cpu_check_features
#define crc32                    _Cz_crc32
#define crc32_combine            _Cz_crc32_combine
#define crc32_combine64          _Cz_crc32_combine64
#define crc32_combine_gen        _Cz_crc32_combine_gen
#define crc32_combine_gen64      _Cz_crc32_combine_gen64
#define crc32_combine_op         _Cz_crc32_combine_op
#define crc32_sse42_simd_        _Cz_crc32_sse42_simd_
#define crc32_z                  _Cz_crc32_z
#define crc_finalize             _Cz_crc_finalize
#define crc_fold_512to32         _Cz_crc_fold_512to32
#define crc_fold_copy            _Cz_crc_fold_copy
#define crc_fold_init            _Cz_crc_fold_init
#define crc_reset                _Cz_crc_reset
#define deflate                  _Cz_deflate
#define deflateBound             _Cz_deflateBound
#define deflateCopy              _Cz_deflateCopy
#define deflateEnd               _Cz_deflateEnd
#define deflateGetDictionary     _Cz_deflateGetDictionary
#define deflateInit              _Cz_deflateInit
#define deflateInit2             _Cz_deflateInit2
#define deflateParams            _Cz_deflateParams
#define deflatePending           _Cz_deflatePending
#define deflatePrime             _Cz_deflatePrime
#define deflateReset             _Cz_deflateReset
#define deflateResetKeep         _Cz_deflateResetKeep
#define deflateSetDictionary     _Cz_deflateSetDictionary
#define deflateSetHeader         _Cz_deflateSetHeader
#define deflateTune              _Cz_deflateTune
#define deflate_copyright        _Cz_deflate_copyright
#define deflate_read_buf         _Cz_deflate_read_buf
#define fill_window_sse          _Cz_fill_window_sse
#define free_func                _Cz_free_func
#define get_crc_table            _Cz_get_crc_table
#define gzFile                   _Cz_gzFile
#define gz_error                 _Cz_gz_error
#define gz_header                _Cz_gz_header
#define gz_header_s              _Cz_gz_header_s
#define gz_headerp               _Cz_gz_headerp
#define gz_intmax                _Cz_gz_intmax
#define gz_strwinerror           _Cz_gz_strwinerror
#define gzbuffer                 _Cz_gzbuffer
#define gzclearerr               _Cz_gzclearerr
#define gzclose                  _Cz_gzclose
#define gzclose_r                _Cz_gzclose_r
#define gzclose_w                _Cz_gzclose_w
#define gzdirect                 _Cz_gzdirect
#define gzdopen                  _Cz_gzdopen
#define gzeof                    _Cz_gzeof
#define gzerror                  _Cz_gzerror
#define gzflush                  _Cz_gzflush
#define gzfread                  _Cz_gzfread
#define gzfwrite                 _Cz_gzfwrite
#define gzgetc                   _Cz_gzgetc
#define gzgetc_                  _Cz_gzgetc_
#define gzgets                   _Cz_gzgets
#define gzoffset                 _Cz_gzoffset
#define gzoffset64               _Cz_gzoffset64
#define gzopen                   _Cz_gzopen
#define gzopen64                 _Cz_gzopen64
#define gzopen_w                 _Cz_gzopen_w
#define gzprintf                 _Cz_gzprintf
#define gzputc                   _Cz_gzputc
#define gzputs                   _Cz_gzputs
#define gzread                   _Cz_gzread
#define gzrewind                 _Cz_gzrewind
#define gzseek                   _Cz_gzseek
#define gzseek64                 _Cz_gzseek64
#define gzsetparams              _Cz_gzsetparams
#define gztell                   _Cz_gztell
#define gztell64                 _Cz_gztell64
#define gzungetc                 _Cz_gzungetc
#define gzvprintf                _Cz_gzvprintf
#define gzwrite                  _Cz_gzwrite
#define in_func                  _Cz_in_func
#define inflate                  _Cz_inflate
#define inflateBack              _Cz_inflateBack
#define inflateBackEnd           _Cz_inflateBackEnd
#define inflateBackInit_         _Cz_inflateBackInit_
#define inflateCodesUsed         _Cz_inflateCodesUsed
#define inflateCopy              _Cz_inflateCopy
#define inflateEnd               _Cz_inflateEnd
#define inflateGetDictionary     _Cz_inflateGetDictionary
#define inflateGetHeader         _Cz_inflateGetHeader
#define inflateInit              _Cz_inflateInit
#define inflateInit2             _Cz_inflateInit2
#define inflateMark              _Cz_inflateMark
#define inflatePrime             _Cz_inflatePrime
#define inflateReset             _Cz_inflateReset
#define inflateReset2            _Cz_inflateReset2
#define inflateResetKeep         _Cz_inflateResetKeep
#define inflateSetDictionary     _Cz_inflateSetDictionary
#define inflateSync              _Cz_inflateSync
#define inflateSyncPoint         _Cz_inflateSyncPoint
#define inflateUndermine         _Cz_inflateUndermine
#define inflateValidate          _Cz_inflateValidate
#define inflate_copyright        _Cz_inflate_copyright
#define inflate_fast             _Cz_inflate_fast
#define inflate_fast_chunk_      _Cz_inflate_fast_chunk_
#define inflate_table            _Cz_inflate_table
#define intf                     _Cz_intf
#define out_func                 _Cz_out_func
#define uInt                     _Cz_uInt
#define uIntf                    _Cz_uIntf
#define uLong                    _Cz_uLong
#define uLongf                   _Cz_uLongf
#define uncompress               _Cz_uncompress
#define uncompress2              _Cz_uncompress2
#define voidp                    _Cz_voidp
#define voidpc                   _Cz_voidpc
#define voidpf                   _Cz_voidpf
#define x86_check_features       _Cz_x86_check_features
#define x86_cpu_enable_simd      _Cz_x86_cpu_enable_simd
#define x86_cpu_enable_sse2      _Cz_x86_cpu_enable_sse2
#define x86_cpu_enable_ssse3     _Cz_x86_cpu_enable_ssse3
#define zError                   _Cz_zError
#define z_errmsg                 _Cz_z_errmsg
#define zcalloc                  _Cz_zcalloc
#define zcfree                   _Cz_zcfree
#define zlibCompileFlags         _Cz_zlibCompileFlags
#define zlibVersion              _Cz_zlibVersion


typedef unsigned char Byte;
typedef unsigned int uInt;   /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef Byte Bytef;
typedef char charf;
typedef int intf;
typedef uInt uIntf;
typedef uLong uLongf;
typedef void const *voidpc;
typedef void *voidpf;
typedef void *voidp;
typedef uint32_t z_crc_t;
typedef int64_t z_off64_t;
typedef size_t z_size_t;



/*!BEGIN third_party/zlib/zlib.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZLIB_H_

/**
 * @fileoverview zlib
 *
 * The 'zlib' compression library provides in-memory
 * compression and decompression functions, including integrity checks
 * of the uncompressed data. This version of the library supports only
 * one compression method (deflation) but other algorithms will be added
 * later and will have the same stream interface.
 *
 * Compression can be done in a single step if the buffers are large enough,
 * or can be done by repeated calls of the compression function.  In the latter
 * case, the application must provide more input and/or consume the output
 * (providing more output space) before each call.
 *
 * The compressed data format used by default by the in-memory functions is
 * the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
 * around a deflate stream, which is itself documented in RFC 1951.
 *
 * The library also supports reading and writing files in gzip (.gz) format
 * with an interface similar to that of stdio using the functions that start
 * with "gz".  The gzip format is different from the zlib format.  gzip is a
 * gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
 *
 * This library can optionally read and write gzip and raw deflate streams in
 * memory as well.
 *
 * The zlib format was designed to be compact and fast for use in memory
 * and on communications channels.  The gzip format was designed for single-
 * file compression on file systems, has a larger header than zlib to maintain
 * directory information, and uses a different, slower check method than zlib.
 *
 * The library does not install any signal handler.  The decoder checks
 * the consistency of the compressed data, so the library should never crash
 * even in the case of corrupted input.
 */

#define ZLIB_VERSION         "1.2.11"
#define ZLIB_VERNUM          0x12b0
#define ZLIB_VER_MAJOR       1
#define ZLIB_VER_MINOR       2
#define ZLIB_VER_REVISION    11
#define ZLIB_VER_SUBREVISION 0

/**
 * The application must update next_in and avail_in when avail_in has
 * dropped to zero. It must update next_out and avail_out when avail_out
 * has dropped to zero. The application must initialize zalloc, zfree
 * and opaque before calling the init function. All other fields are set
 * by the compression library and must not be updated by the
 * application.
 *
 * The opaque value provided by the application will be passed as the
 * first parameter for calls of zalloc and zfree. This can be useful for
 * custom memory management. The compression library attaches no meaning
 * to the opaque value.
 *
 * zalloc must return Z_NULL if there is not enough memory for the
 * object. If zlib is used in a multi-threaded application, zalloc and
 * zfree must be thread safe. In that case, zlib is thread-safe. When
 * zalloc and zfree are Z_NULL on entry to the initialization function,
 * they are set to internal routines that use the standard library
 * functions malloc() and free().
 *
 * On 16-bit systems, the functions zalloc and zfree must be able to
 * allocate exactly 65536 bytes, but will not be required to allocate
 * more than this if the symbol MAXSEG_64K is defined (see zconf.h).
 * WARNING: On MSDOS, pointers returned by zalloc for objects of exactly
 * 65536 bytes *must* have their offset normalized to zero. The default
 * allocation function provided by this library ensures this (see
 * zutil.c). To reduce memory requirements and avoid any allocation of
 * 64K objects, at the expense of compression ratio, compile the library
 * with -DMAX_WBITS=14 (see zconf.h).
 *
 * The fields total_in and total_out can be used for statistics or
 * progress reports. After compression, total_in holds the total size of
 * the uncompressed data and may be saved for use by the decompressor
 * (particularly if the decompressor wants to decompress everything in a
 * single step).
 */
#define Z_NO_FLUSH      0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH    2
#define Z_FULL_FLUSH    3
#define Z_FINISH        4
#define Z_BLOCK         5
#define Z_TREES         6

/**
 * Allowed flush values; see deflate() and inflate() below for details.
 */
#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO         (-1)
#define Z_STREAM_ERROR  (-2)
#define Z_DATA_ERROR    (-3)
#define Z_MEM_ERROR     (-4)
#define Z_BUF_ERROR     (-5)
#define Z_VERSION_ERROR (-6)

/**
 * Return codes for the compression/decompression functions. Negative
 * values are errors, positive values are used for special but normal
 * events.
 */
#define Z_NO_COMPRESSION      0
#define Z_BEST_SPEED          1
#define Z_BEST_COMPRESSION    9
#define Z_DEFAULT_COMPRESSION (-1)

/**
 * Compression levels.
 */
#define Z_FILTERED         1
#define Z_HUFFMAN_ONLY     2
#define Z_RLE              3
#define Z_FIXED            4
#define Z_DEFAULT_STRATEGY 0

/**
 * Compression strategy; see deflateInit2() below for details
 */
#define Z_BINARY  0
#define Z_TEXT    1
#define Z_ASCII   Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN 2

/**
 * Possible values of the data_type field for deflate()
 */
#define Z_DEFLATED 8

/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */

COSMOPOLITAN_C_START_

typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
typedef void (*free_func)(voidpf opaque, voidpf address);

struct internal_state;

typedef struct z_stream_s {
  const Bytef *next_in;         /* next input byte */
  uInt avail_in;                /* number of bytes available at next_in */
  uLong total_in;               /* total number of input bytes read so far */
  Bytef *next_out;              /* next output byte will go here */
  uInt avail_out;               /* remaining free space at next_out */
  uLong total_out;              /* total number of bytes output so far */
  const char *msg;              /* last error message, NULL if no error */
  struct internal_state *state; /* not visible by applications */
  alloc_func zalloc;            /* used to allocate the internal state */
  free_func zfree;              /* used to free the internal state */
  voidpf opaque;  /* private data object passed to zalloc and zfree */
  int data_type;  /* best guess about the data type: binary or text
                     for deflate, or the decoding state for inflate */
  uLong adler;    /* Adler-32 or CRC-32 value of the uncompressed data */
  uLong reserved; /* reserved for future use */
} z_stream;

typedef z_stream *z_streamp;

/**
 * gzip header information passed to and from zlib routines. See RFC
 * 1952 for more details on the meanings of these fields.
 */
typedef struct gz_header_s {
  int text;       /* true if compressed data believed to be text */
  uLong time_;    /* modification time */
  int xflags;     /* extra flags (not used when writing a gzip file) */
  int os;         /* operating system */
  Bytef *extra;   /* pointer to extra field or Z_NULL if none */
  uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  uInt extra_max; /* space at extra (only when reading header) */
  Bytef *name;    /* pointer to zero-terminated file name or Z_NULL */
  uInt name_max;  /* space at name (only when reading header) */
  Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  uInt comm_max;  /* space at comment (only when reading header) */
  int hcrc;       /* true if there was or will be a header crc */
  int done;       /* true when done reading gzip header (not used
                     when writing a gzip file) */
} gz_header;

typedef gz_header *gz_headerp;

#define zlib_version zlibVersion()

/**
 * The application can compare zlibVersion and ZLIB_VERSION for consistency.
 * If the first character differs, the library code actually used is not
 * compatible with the zlib.h header file used by the application.  This check
 * is automatically made by deflateInit and inflateInit.
 */
const char *zlibVersion(void);

/**
 * Initializes the internal stream state for compression.  The fields
 * zalloc, zfree and opaque must be initialized before by the caller.  If
 * zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
 * allocation functions.
 *
 * The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
 * 1 gives best speed, 9 gives best compression, 0 gives no compression at all
 * (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION
 * requests a default compromise between speed and compression (currently
 * equivalent to level 6).
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if level is not a valid compression level. msg
 *     is set to null if there is no error message. deflateInit does not
 *     perform any compression: this will be done by deflate().
 */
int deflateInit(z_streamp strm, int level);

/**
 * deflate compresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full. It may
 * introduce some output latency (reading input without producing any
 * output) except when forced to flush.
 *
 * The detailed semantics are as follows. deflate performs one or both
 * of the following actions:
 *
 * - Compress more input starting at next_in and update next_in and
 *  avail_in accordingly. If not all input can be processed (because
 *  there is not enough room in the output buffer), next_in and avail_in
 *  are updated and processing will resume at this point for the next
 *  call of deflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *  avail_out accordingly. This action is forced if the parameter flush
 *  is non zero. Forcing flush frequently degrades the compression
 *  ratio, so this parameter should be set only when necessary. Some
 *  output may be provided even if flush is zero.
 *
 * Before the call of deflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating avail_in or avail_out
 * accordingly; avail_out should never be zero before the call. The
 * application can consume the compressed output when it wants, for
 * example when the output buffer is full (avail_out == 0), or after
 * each call of deflate(). If deflate returns Z_OK and with zero
 * avail_out, it must be called again after making room in the output
 * buffer because there might be more output pending. See
 * deflatePending(), which can be used if desired to determine whether
 * or not there is more ouput in that case.
 *
 * Normally the parameter flush is set to Z_NO_FLUSH, which allows
 * deflate to decide how much data to accumulate before producing
 * output, in order to maximize compression.
 *
 * If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
 * flushed to the output buffer and the output is aligned on a byte
 * boundary, so that the decompressor can get all input data available
 * so far. (In particular avail_in is zero after the call if enough
 * output space has been provided before the call.) Flushing may degrade
 * compression for some compression algorithms and so it should be used
 * only when necessary. This completes the current deflate block and
 * follows it with an empty stored block that is three bits plus filler
 * bits to the next byte, followed by four bytes (00 00 ff ff).
 *
 * If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to
 * the output buffer, but the output is not aligned to a byte boundary.
 * All of the input data so far will be available to the decompressor,
 * as for Z_SYNC_FLUSH. This completes the current deflate block and
 * follows it with an empty fixed codes block that is 10 bits long. This
 * assures that enough bytes are output in order for the decompressor to
 * finish the block before the empty fixed codes block.
 *
 * If flush is set to Z_BLOCK, a deflate block is completed and emitted,
 * as for Z_SYNC_FLUSH, but the output is not aligned on a byte
 * boundary, and up to seven bits of the current block are held to be
 * written as the next byte after the next deflate block is completed.
 * In this case, the decompressor may not be provided enough bits at
 * this point in order to complete decompression of the data provided so
 * far to the compressor. It may need to wait for the next block to be
 * emitted. This is for advanced applications that need to control the
 * emission of deflate blocks.
 *
 * If flush is set to Z_FULL_FLUSH, all output is flushed as with
 * Z_SYNC_FLUSH, and the compression state is reset so that
 * decompression can restart from this point if previous compressed data
 * has been damaged or if random access is desired. Using Z_FULL_FLUSH
 * too often can seriously degrade compression.
 *
 * If deflate returns with avail_out == 0, this function must be called
 * again with the same value of the flush parameter and more output
 * space (updated avail_out), until the flush is complete (deflate
 * returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or
 * Z_SYNC_FLUSH, make sure that avail_out is greater than six to avoid
 * repeated flush markers due to avail_out == 0 on return.
 *
 * If the parameter flush is set to Z_FINISH, pending input is
 * processed, pending output is flushed and deflate returns with
 * Z_STREAM_END if there was enough output space. If deflate returns
 * with Z_OK or Z_BUF_ERROR, this function must be called again with
 * Z_FINISH and more output space (updated avail_out) but no more input
 * data, until it returns with Z_STREAM_END or an error. After deflate
 * has returned Z_STREAM_END, the only possible operations on the stream
 * are deflateReset or deflateEnd.
 *
 * Z_FINISH can be used in the first deflate call after deflateInit if
 * all the compression is to be done in a single step. In order to
 * complete in one call, avail_out must be at least the value returned
 * by deflateBound (see below). Then deflate is guaranteed to return
 * Z_STREAM_END. If not enough output space is provided, deflate will
 * not return Z_STREAM_END, and it must be called again as described
 * above.
 *
 * deflate() sets strm->adler to the Adler-32 checksum of all input read
 * so far (that is, total_in bytes). If a gzip stream is being
 * generated, then strm->adler will be the CRC-32 checksum of the input
 * read so far. (See deflateInit2 below.)
 *
 * deflate() may update strm->data_type if it can make a good guess about
 * the input data type (Z_BINARY or Z_TEXT).  If in doubt, the data is
 * considered binary.  This field is only for information purposes and does not
 * affect the compression algorithm in any manner.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if all input has been
 *     consumed and all output has been produced (only when flush is set
 *     to Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent
 *     (for example if next_in or next_out was Z_NULL or the state was
 *     inadvertently written over by the application), or Z_BUF_ERROR if
 *     no progress is possible (for example avail_in or avail_out was
 *     zero). Note that Z_BUF_ERROR is not fatal, and deflate() can be
 *     called again with more input and more output space to continue
 *     compressing.
 */
int deflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the stream state was
 *     inconsistent, Z_DATA_ERROR if the stream was freed prematurely
 *     (some input or output was discarded). In the error case, msg may
 *     be set but then points to a static string (which must not be
 *     deallocated).
 */
int deflateEnd(z_streamp strm);

/**
 * Initializes the internal stream state for decompression. The fields
 * next_in, avail_in, zalloc, zfree and opaque must be initialized
 * before by the caller. In the current version of inflate, the provided
 * input is not read or consumed. The allocation of a sliding window
 * will be deferred to the first call of inflate (if the decompression
 * does not complete on the first call). If zalloc and zfree are set to
 * Z_NULL, inflateInit updates them to use default allocation functions.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit does not perform any decompression. Actual
 *     decompression will be done by inflate(). So next_in, and
 *     avail_in, next_out, and avail_out are unused and unchanged. The
 *     current implementation of inflateInit() does not process any
 *     header information -- that is deferred until inflate() is called.
 */
int inflateInit(z_streamp strm);

/**
 * inflate decompresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full.  It may introduce
 * some output latency (reading input without producing any output) except when
 * forced to flush.
 *
 * The detailed semantics are as follows.  inflate performs one or both of the
 * following actions:
 *
 * - Decompress more input starting at next_in and update next_in and
 *   avail_in accordingly. If not all input can be processed (because
 *   there is not enough room in the output buffer), then next_in and
 *   avail_in are updated accordingly, and processing will resume at
 *   this point for the next call of inflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *   avail_out accordingly. inflate() provides as much output as
 *   possible, until there is no more input data or no more space in the
 *   output buffer (see below about the flush parameter).
 *
 * Before the call of inflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating the next_* and avail_* values
 * accordingly. If the caller of inflate() does not provide both
 * available input and available output space, it is possible that there
 * will be no progress made. The application can consume the
 * uncompressed output when it wants, for example when the output buffer
 * is full (avail_out == 0), or after each call of inflate(). If inflate
 * returns Z_OK and with zero avail_out, it must be called again after
 * making room in the output buffer because there might be more output
 * pending.
 *
 * The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
 * Z_FINISH, Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate()
 * flush as much output as possible to the output buffer. Z_BLOCK
 * requests that inflate() stop if and when it gets to the next deflate
 * block boundary. When decoding the zlib or gzip format, this will
 * cause inflate() to return immediately after the header and before the
 * first block. When doing a raw inflate, inflate() will go ahead and
 * process the first block, and will return when it gets to the end of
 * that block, or when it runs out of data.
 *
 * The Z_BLOCK option assists in appending to or combining deflate
 * streams. To assist in this, on return inflate() always sets
 * strm->data_type to the number of unused bits in the last byte taken
 * from strm->next_in, plus 64 if inflate() is currently decoding the
 * last block in the deflate stream, plus 128 if inflate() returned
 * immediately after decoding an end-of-block code or decoding the
 * complete header up to just before the first byte of the deflate
 * stream. The end-of-block will not be indicated until all of the
 * uncompressed data from that block has been written to strm->next_out.
 * The number of unused bits may in general be greater than seven,
 * except when bit 7 of data_type is set, in which case the number of
 * unused bits will be less than eight. data_type is set as noted here
 * every time inflate() returns for all flush options, and so can be
 * used to determine the amount of currently consumed input in bits.
 *
 * The Z_TREES option behaves as Z_BLOCK does, but it also returns when
 * the end of each deflate block header is reached, before any actual
 * data in that block is decoded. This allows the caller to determine
 * the length of the deflate block header for later use in random access
 * within a deflate block. 256 is added to the value of strm->data_type
 * when inflate() returns immediately after reaching the end of the
 * deflate block header.
 *
 * inflate() should normally be called until it returns Z_STREAM_END or
 * an error. However if all decompression is to be performed in a single
 * step (a single call of inflate), the parameter flush should be set to
 * Z_FINISH. In this case all pending input is processed and all pending
 * output is flushed; avail_out must be large enough to hold all of the
 * uncompressed data for the operation to complete. (The size of the
 * uncompressed data may have been saved by the compressor for this
 * purpose.) The use of Z_FINISH is not required to perform an inflation
 * in one step. However it may be used to inform inflate that a faster
 * approach can be used for the single inflate() call. Z_FINISH also
 * informs inflate to not maintain a sliding window if the stream
 * completes, which reduces inflate's memory footprint. If the stream
 * does not complete, either because not all of the stream is provided
 * or not enough output space is provided, then a sliding window will be
 * allocated and inflate() can be called again to continue the operation
 * as if Z_NO_FLUSH had been used.
 *
 * In this implementation, inflate() always flushes as much output as
 * possible to the output buffer, and always uses the faster approach on
 * the first call. So the effects of the flush parameter in this
 * implementation are on the return value of inflate() as noted below,
 * when inflate() returns early when Z_BLOCK or Z_TREES is used, and
 * when inflate() avoids the allocation of memory for a sliding window
 * when Z_FINISH is used.
 *
 * If a preset dictionary is needed after this call (see
 * inflateSetDictionary below), inflate sets strm->adler to the Adler-32
 * checksum of the dictionary chosen by the compressor and returns
 * Z_NEED_DICT; otherwise it sets strm->adler to the Adler-32 checksum
 * of all output produced so far (that is, total_out bytes) and returns
 * Z_OK, Z_STREAM_END or an error code as described below. At the end of
 * the stream, inflate() checks that its computed Adler-32 checksum is
 * equal to that saved by the compressor and returns Z_STREAM_END only
 * if the checksum is correct.
 *
 * inflate() can decompress and check either zlib-wrapped or
 * gzip-wrapped deflate data. The header type is detected automatically,
 * if requested when initializing with inflateInit2(). Any information
 * contained in the gzip header is not retained unless
 * inflateGetHeader() is used. When processing gzip-wrapped deflate
 * data, strm->adler32 is set to the CRC-32 of the output produced so
 * far. The CRC-32 is checked against the gzip trailer, as is the
 * uncompressed length, modulo 2^32.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if the end of the compressed
 *     data has been reached and all uncompressed output has been
 *     produced, Z_NEED_DICT if a preset dictionary is needed at this
 *     point, Z_DATA_ERROR if the input data was corrupted (input stream
 *     not conforming to the zlib format or incorrect check value, in
 *     which case strm->msg points to a string with a more specific
 *     error), Z_STREAM_ERROR if the stream structure was inconsistent
 *     (for example next_in or next_out was Z_NULL, or the state was
 *     inadvertently written over by the application), Z_MEM_ERROR if
 *     there was not enough memory, Z_BUF_ERROR if no progress was
 *     possible or if there was not enough room in the output buffer
 *     when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
 *     inflate() can be called again with more input and more output
 *     space to continue decompressing. If Z_DATA_ERROR is returned, the
 *     application may then call inflateSync() to look for a good
 *     compression block if a partial recovery of the data is to be
 *     attempted.
 */
int inflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK or Z_STREAM_ERROR if stream state inconsistent
 */
int inflateEnd(z_streamp strm);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » special functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  the following functions are needed only in some special applications */

/**
 * This is another version of deflateInit with more compression options.
 * The fields next_in, zalloc, zfree and opaque must be initialized
 * before by the caller.
 *
 * The method parameter is the compression method. It must be Z_DEFLATED
 * in this version of the library.
 *
 * The windowBits parameter is the base two logarithm of the window size
 * (the size of the history buffer). It should be in the range 8..15 for
 * this version of the library. Larger values of this parameter result
 * in better compression at the expense of memory usage. The default
 * value is 15 if deflateInit is used instead.
 *
 * For the current implementation of deflate(), a windowBits value of 8
 * (a window size of 256 bytes) is not supported. As a result, a request
 * for 8 will result in 9 (a 512-byte window). In that case, providing 8
 * to inflateInit2() will result in an error when the zlib header with 9
 * is checked against the initialization of inflate(). The remedy is to
 * not use 8 with deflateInit2() with this initialization, or at least
 * in that case use 9 with inflateInit2().
 *
 * windowBits can also be -8..-15 for raw deflate. In this case,
 * -windowBits determines the window size. deflate() will then generate
 * raw deflate data with no zlib header or trailer, and will not compute
 * a check value.
 *
 * windowBits can also be greater than 15 for optional gzip encoding.
 * Add 16 to windowBits to write a simple gzip header and trailer around
 * the compressed data instead of a zlib wrapper. The gzip header will
 * have no file name, no extra data, no comment, no modification time
 * (set to zero), no header crc, and the operating system will be set to
 * the appropriate value, if the operating system was determined at
 * compile time. If a gzip stream is being written, strm->adler is a
 * CRC-32 instead of an Adler-32.
 *
 * For raw deflate or gzip encoding, a request for a 256-byte window is
 * rejected as invalid, since only the zlib header provides a means of
 * transmitting the window size to the decompressor.
 *
 * The memLevel parameter specifies how much memory should be allocated
 * for the internal compression state. memLevel=1 uses minimum memory
 * but is slow and reduces compression ratio; memLevel=9 uses maximum
 * memory for optimal speed. The default value is 8. See zconf.h for
 * total memory usage as a function of windowBits and memLevel.
 *
 * The strategy parameter is used to tune the compression algorithm. Use
 * the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
 * produced by a filter (or predictor), Z_HUFFMAN_ONLY to force Huffman
 * encoding only (no string match), or Z_RLE to limit match distances to
 * one (run-length encoding). Filtered data consists mostly of small
 * values with a somewhat random distribution. In this case, the
 * compression algorithm is tuned to compress them better. The effect of
 * Z_FILTERED is to force more Huffman coding and less string matching;
 * it is somewhat intermediate between Z_DEFAULT_STRATEGY and
 * Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
 * Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
 * strategy parameter only affects the compression ratio but not the
 * correctness of the compressed output even if it is not set
 * appropriately. Z_FIXED prevents the use of dynamic Huffman codes,
 * allowing for a simpler decoder for special applications.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if any parameter is invalid (such as an invalid
 *     method). msg is set to null if there is no error message.
 *     deflateInit2 does not perform any compression: this will be done
 *     by deflate().
 */
int deflateInit2(z_streamp strm, int level, int method, int windowBits,
                 int memLevel, int strategy);

/**
 * Initializes the compression dictionary from the given byte sequence
 * without producing any compressed output. When using the zlib format,
 * this function must be called immediately after deflateInit,
 * deflateInit2 or deflateReset, and before any call of deflate. When
 * doing raw deflate, this function must be called either before any
 * call of deflate, or immediately after the completion of a deflate
 * block, i.e. after all input has been consumed and all output has been
 * delivered when using any of the flush options Z_BLOCK,
 * Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The compressor and
 * decompressor must use exactly the same dictionary (see
 * inflateSetDictionary).
 *
 * The dictionary should consist of strings (byte sequences) that are
 * likely to be encountered later in the data to be compressed, with the
 * most commonly used strings preferably put towards the end of the
 * dictionary. Using a dictionary is most useful when the data to be
 * compressed is short and can be predicted with good accuracy; the data
 * can then be compressed better than with the default empty dictionary.
 *
 * Depending on the size of the compression data structures selected by
 * deflateInit or deflateInit2, a part of the dictionary may in effect
 * be discarded, for example if the dictionary is larger than the window
 * size provided in deflateInit or deflateInit2. Thus the strings most
 * likely to be useful should be put at the end of the dictionary, not
 * at the front. In addition, the current implementation of deflate will
 * use at most the window size minus 262 bytes of the provided
 * dictionary.
 *
 * Upon return of this function, strm->adler is set to the Adler-32
 * value of the dictionary; the decompressor may later use this value to
 * determine which dictionary has been used by the compressor. (The
 * Adler-32 value applies to the whole dictionary even if only a subset
 * of the dictionary is actually used by the compressor.) If a raw
 * deflate was requested, then the Adler-32 value is not computed and
 * strm->adler is not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent (for example if deflate has already been called for
 *     this stream or if not at a block boundary for raw deflate).
 *     deflateSetDictionary does not perform any compression: this will
 *     be done by deflate().
 */
int deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by deflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If deflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * deflateGetDictionary() may return a length less than the window size, even
 * when more than the window size in input has been provided. It may return up
 * to 258 bytes less in that case, due to how zlib's implementation of deflate
 * manages the sliding window and lookahead for matches, where matches can be
 * up to 258 bytes long. If the application needs the last window-size bytes of
 * input, then that would need to be saved by the application outside of zlib.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int deflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Sets destination stream as a complete copy of the source stream.
 *
 * This function can be useful when several compression strategies will be
 * tried, for example when there are several ways of pre-processing the input
 * data with a filter.  The streams that will be discarded should then be freed
 * by calling deflateEnd.  Note that deflateCopy duplicates the internal
 * compression state which can be quite large, so this strategy is slow and can
 * consume lots of memory.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int deflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to deflateEnd followed by deflateInit, but
 * does not free and reallocate the internal compression state.  The stream
 * will leave the compression level and any other attributes that may have been
 * set unchanged.
 *
 * deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 * stream state was inconsistent (such as zalloc or state being Z_NULL).
 */
int deflateReset(z_streamp strm);

/**
 * Dynamically update the compression level and compression strategy.  The
 * interpretation of level and strategy is as in deflateInit2().  This can be
 * used to switch between compression and straight copy of the input data, or
 * to switch to a different kind of input data requiring a different strategy.
 * If the compression approach (which is a function of the level) or the
 * strategy is changed, and if any input has been consumed in a previous
 * deflate() call, then the input available so far is compressed with the old
 * level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
 * for the compression levels 0, 1..3, and 4..9 respectively.  The new level
 * and strategy will take effect at the next call of deflate().
 *
 * If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
 * not have enough output space to complete, then the parameter change will not
 * take effect.  In this case, deflateParams() can be called again with the
 * same parameters and more output space to try again.
 *
 * In order to assure a change in the parameters on the first try, the
 * deflate stream should be flushed using deflate() with Z_BLOCK or other flush
 * request until strm.avail_out is not zero, before calling deflateParams().
 * Then no more input data should be provided before the deflateParams() call.
 * If this is done, the old level and strategy will be applied to the data
 * compressed before deflateParams(), and the new level and strategy will be
 * applied to the the data compressed after deflateParams().
 *
 * deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
 * state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
 * there was not enough output space to complete the compression of the
 * available input data before a change in the strategy or approach.  Note that
 * in the case of a Z_BUF_ERROR, the parameters are not changed.  A return
 * value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
 * retried with more output space.
 */
int deflateParams(z_streamp strm, int level, int strategy);

/**
 * Fine tune deflate's internal compression parameters. This should only
 * be used by someone who understands the algorithm used by zlib's
 * deflate for searching for the best matching string, and even then
 * only by the most fanatic optimizer trying to squeeze out the last
 * compressed bit for their specific input data. Read the deflate.c
 * source code for the meaning of the max_lazy, good_length,
 * nice_length, and max_chain parameters.
 *
 * deflateTune() can be called after deflateInit() or deflateInit2(), and
 * returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
 */
int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
                int max_chain);

/**
 * deflateBound() returns an upper bound on the compressed size after
 * deflation of sourceLen bytes. It must be called after deflateInit()
 * or deflateInit2(), and after deflateSetHeader(), if used. This would
 * be used to allocate an output buffer for deflation in a single pass,
 * and so would be called before deflate(). If that first deflate() call
 * is provided the sourceLen input bytes, an output buffer allocated to
 * the size returned by deflateBound(), and the flush value Z_FINISH,
 * then deflate() is guaranteed to return Z_STREAM_END. Note that it is
 * possible for the compressed size to be larger than the value returned
 * by deflateBound() if flush options other than Z_FINISH or Z_NO_FLUSH
 * are used.
 */
uLong deflateBound(z_streamp strm, uLong sourceLen);

/**
 * deflatePending() returns the number of bytes and bits of output that
 * have been generated, but not yet provided in the available output.
 * The bytes not provided would be due to the available output space
 * having being consumed. The number of bits of output not provided are
 * between 0 and 7, where they await more bits to join them in order to
 * fill out a full byte. If pending or bits are Z_NULL, then those
 * values are not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int deflatePending(z_streamp strm, unsigned *pending, int *bits);

/**
 * deflatePrime() inserts bits in the deflate output stream.  The intent
 * is that this function is used to start off the deflate output with the bits
 * leftover from a previous deflate stream when appending to it.  As such, this
 * function can only be used for raw deflate, and must be used before the first
 * deflate() call after a deflateInit2() or deflateReset().  bits must be less
 * than or equal to 16, and that many of the least significant bits of value
 * will be inserted in the output.
 *
 * @return Z_OK if success, Z_BUF_ERROR if there was not enough room in
 *     the internal buffer to insert the bits, or Z_STREAM_ERROR if the
 *     source stream state was inconsistent.
 */
int deflatePrime(z_streamp strm, int bits, int value);

/**
 * Provides gzip header information for when a gzip stream is requested
 * by deflateInit2(). deflateSetHeader() may be called after
 * deflateInit2() or deflateReset() and before the first call of
 * deflate(). The text, time, os, extra field, name, and comment
 * information in the provided gz_header structure are written to the
 * gzip header (xflag is ignored -- the extra flags are set according to
 * the compression level). The caller must assure that, if not Z_NULL,
 * name and comment are terminated with a zero byte, and that if extra
 * is not Z_NULL, that extra_len bytes are available there. If hcrc is
 * true, a gzip header crc is included. Note that the current versions
 * of the command-line version of gzip (up through version 1.3.x) do not
 * support header crc's, and will report that it is a "multi-part gzip
 * file" and give up.
 *
 * If deflateSetHeader is not used, the default gzip header has text
 * false, the time set to zero, and os set to 255, with no extra, name,
 * or comment fields. The gzip header is returned to the default state
 * by deflateReset().
 *
 * deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the
 * source stream state was inconsistent.
 */
int deflateSetHeader(z_streamp strm, gz_headerp head);

/**
 * This is another version of inflateInit with an extra parameter. The
 * fields next_in, avail_in, zalloc, zfree and opaque must be
 * initialized before by the caller.
 *
 * The windowBits parameter is the base two logarithm of the maximum
 * window size (the size of the history buffer). It should be in the
 * range 8..15 for this version of the library. The default value is 15
 * if inflateInit is used instead. windowBits must be greater than or
 * equal to the windowBits value provided to deflateInit2() while
 * compressing, or it must be equal to 15 if deflateInit2() was not
 * used. If a compressed stream with a larger window size is given as
 * input, inflate() will return with the error code Z_DATA_ERROR instead
 * of trying to allocate a larger window.
 *
 * windowBits can also be zero to request that inflate use the window
 * size in the zlib header of the compressed stream.
 *
 * windowBits can also be -8..-15 for raw inflate. In this case,
 * -windowBits determines the window size. inflate() will then process
 * raw deflate data, not looking for a zlib or gzip header, not
 * generating a check value, and not looking for any check values for
 * comparison at the end of the stream. This is for use with other
 * formats that use the deflate compressed data format such as zip.
 * Those formats provide their own check values. If a custom format is
 * developed using the raw deflate format for compressed data, it is
 * recommended that a check value such as an Adler-32 or a CRC-32 be
 * applied to the uncompressed data as is done in the zlib, gzip, and
 * zip formats. For most applications, the zlib format should be used as
 * is. Note that comments above on the use in deflateInit2() applies to
 * the magnitude of windowBits.
 *
 * windowBits can also be greater than 15 for optional gzip decoding.
 * Add 32 to windowBits to enable zlib and gzip decoding with automatic
 * header detection, or add 16 to decode only the gzip format (the zlib
 * format will return a Z_DATA_ERROR). If a gzip stream is being
 * decoded, strm->adler is a CRC-32 instead of an Adler-32. Unlike the
 * gunzip utility and gzread() (see below), inflate() will not
 * automatically decode concatenated gzip streams. inflate() will return
 * Z_STREAM_END at the end of the gzip stream. The state would need to
 * be reset to continue decoding a subsequent gzip stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit2 does not perform any decompression apart
 *     from possibly reading the zlib header if present: actual
 *     decompression will be done by inflate(). (So next_in and avail_in
 *     may be modified, but next_out and avail_out are unused and
 *     unchanged.) The current implementation of inflateInit2() does not
 *     process any header information -- that is deferred until
 *     inflate() is called.
 */
int inflateInit2(z_streamp strm, int windowBits);

/**
 * Initializes the decompression dictionary from the given uncompressed
 * byte sequence. This function must be called immediately after a call
 * of inflate, if that call returned Z_NEED_DICT. The dictionary chosen
 * by the compressor can be determined from the Adler-32 value returned
 * by that call of inflate. The compressor and decompressor must use
 * exactly the same dictionary (see deflateSetDictionary). For raw
 * inflate, this function can be called at any time to set the
 * dictionary. If the provided dictionary is smaller than the window and
 * there is already data in the window, then the provided dictionary
 * will amend what's there. The application must insure that the
 * dictionary that was used for compression is provided.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent, Z_DATA_ERROR if the given dictionary doesn't match
 *     the expected one (incorrect Adler-32 value). inflateSetDictionary
 *     does not perform any decompression: this will be done by
 *     subsequent calls of inflate().
 */
int inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by inflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If inflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Skips invalid compressed data until a possible full flush point (see
 * above for the description of deflate with Z_FULL_FLUSH) can be found,
 * or until all available input is skipped. No output is provided.
 *
 * inflateSync searches for a 00 00 FF FF pattern in the compressed
 * data. All full flush points have this pattern, but not all
 * occurrences of this pattern are full flush points.
 *
 * @return Z_OK if a possible full flush point has been found,
 *     Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no
 *     flush point has been found, or Z_STREAM_ERROR if the stream
 *     structure was inconsistent. In the success case, the application
 *     may save the current current value of total_in which indicates
 *     where valid compressed data was found. In the error case, the
 *     application may repeatedly call inflateSync, providing more input
 *     each time, until success or end of the input data.
 */
int inflateSync(z_streamp strm);

/**
 * Sets the destination stream as a complete copy of the source stream.
 *
 * This function can be useful when randomly accessing a large stream.
 * The first pass through the stream can periodically record the inflate
 * state, allowing restarting inflate at those points when randomly
 * accessing the stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int inflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to inflateEnd followed by inflateInit,
 * but does not free and reallocate the internal decompression state.  The
 * stream will keep attributes that may have been set by inflateInit2.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL).
 */
int inflateReset(z_streamp strm);

/**
 * This function is the same as inflateReset, but it also permits changing
 * the wrap and window size requests.  The windowBits parameter is interpreted
 * the same as it is for inflateInit2.  If the window size is changed, then the
 * memory allocated for the window is freed, and the window will be reallocated
 * by inflate() if needed.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL), or if
 *     the windowBits parameter is invalid.
 */
int inflateReset2(z_streamp strm, int windowBits);

/**
 * This function inserts bits in the inflate input stream.  The intent is
 * that this function is used to start inflating at a bit position in the
 * middle of a byte.  The provided bits will be used before any bytes are used
 * from next_in.  This function should only be used with raw inflate, and
 * should be used before the first inflate() call after inflateInit2() or
 * inflateReset().  bits must be less than or equal to 16, and that many of the
 * least significant bits of value will be inserted in the input.
 *
 * If bits is negative, then the input stream bit buffer is emptied.  Then
 * inflatePrime() can be called again to put bits in the buffer.  This is used
 * to clear out bits leftover after feeding inflate a block description prior
 * to feeding inflate codes.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflatePrime(z_streamp strm, int bits, int value);

/**
 * Returns two values, one in the lower 16 bits of the return value, and
 * the other in the remaining upper bits, obtained by shifting the
 * return value down 16 bits. If the upper value is -1 and the lower
 * value is zero, then inflate() is currently decoding information
 * outside of a block. If the upper value is -1 and the lower value is
 * non-zero, then inflate is in the middle of a stored block, with the
 * lower value equaling the number of bytes from the input remaining to
 * copy. If the upper value is not -1, then it is the number of bits
 * back from the current bit position in the input of the code (literal
 * or length/distance pair) currently being processed. In that case the
 * lower value is the number of bytes already emitted for that code.
 *
 * A code is being processed if inflate is waiting for more input to
 * complete decoding of the code, or if it has completed decoding but is
 * waiting for more output space to write the literal or match data.
 *
 * inflateMark() is used to mark locations in the input data for random
 * access, which may be at bit positions, and to note those cases where
 * the output of a code may span boundaries of random access blocks. The
 * current location in the input stream can be determined from avail_in
 * and data_type as noted in the description for the Z_BLOCK flush
 * parameter for inflate.
 *
 * @return the value noted above, or -65536 if the provided source
 *     stream state was inconsistent.
 */
long inflateMark(z_streamp strm);

/**
 * inflateGetHeader() requests that gzip header information be stored in
 * the provided gz_header structure. inflateGetHeader() may be called
 * after inflateInit2() or inflateReset(), and before the first call of
 * inflate(). As inflate() processes the gzip stream, head->done is zero
 * until the header is completed, at which time head->done is set to
 * one. If a zlib stream is being decoded, then head->done is set to -1
 * to indicate that there will be no gzip header information
 * forthcoming. Note that Z_BLOCK or Z_TREES can be used to force
 * inflate() to return immediately after header processing is complete
 * and before any actual data is decompressed.
 *
 * The text, time, xflags, and os fields are filled in with the gzip
 * header contents. hcrc is set to true if there is a header CRC. (The
 * header CRC was valid if done is set to one.) If extra is not Z_NULL,
 * then extra_max contains the maximum number of bytes to write to
 * extra. Once done is true, extra_len contains the actual extra field
 * length, and extra contains the extra field, or that field truncated
 * if extra_max is less than extra_len. If name is not Z_NULL, then up
 * to name_max characters are written there, terminated with a zero
 * unless the length is greater than name_max. If comment is not Z_NULL,
 * then up to comm_max characters are written there, terminated with a
 * zero unless the length is greater than comm_max. When any of extra,
 * name, or comment are not Z_NULL and the respective field is not
 * present in the header, then that field is set to Z_NULL to signal its
 * absence. This allows the use of deflateSetHeader() with the returned
 * structure to duplicate the header. However if those fields are set to
 * allocated memory, then the application will need to save those
 * pointers elsewhere so that they can be eventually freed.
 *
 * If inflateGetHeader is not used, then the header information is
 * simply discarded. The header is always checked for validity,
 * including the header CRC if present. inflateReset() will reset the
 * process to discard the header information. The application would need
 * to call inflateGetHeader() again to retrieve the header from the next
 * gzip stream.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflateGetHeader(z_streamp strm, gz_headerp head);

/**
 * Initialize internal stream state for decompression using
 * inflateBack() calls. The fields zalloc, zfree and opaque in strm must
 * be initialized before the call. If zalloc and zfree are Z_NULL, then
 * the default library- derived memory allocation routines are used.
 * windowBits is the base two logarithm of the window size, in the range
 * 8..15. window is a caller supplied buffer of that size. Except for
 * special applications where it is assured that deflate was used with
 * small window sizes, windowBits must be 15 and a 32K byte window must
 * be supplied to be able to decompress general deflate streams.
 *
 * See inflateBack() for the usage of these routines.
 *
 * @return Z_OK on success, Z_STREAM_ERROR if any of the parameters are
 *     invalid, or Z_MEM_ERROR if the internal state could not be
 *     allocated.
 */
int inflateBackInit(z_streamp strm, int windowBits, unsigned char *window);

typedef unsigned (*in_func)(void *, const unsigned char **);
typedef int (*out_func)(void *, unsigned char *, unsigned);

/**
 * inflateBack() does a raw inflate with a single call using a call-back
 * interface for input and output. This is potentially more efficient
 * than inflate() for file i/o applications, in that it avoids copying
 * between the output and the sliding window by simply making the window
 * itself the output buffer. inflate() can be faster on modern CPUs when
 * used with large buffers. inflateBack() trusts the application to not
 * change the output buffer passed by the output function, at least
 * until inflateBack() returns.
 *
 * inflateBackInit() must be called first to allocate the internal state
 * and to initialize the state with the user-provided window buffer.
 * inflateBack() may then be used multiple times to inflate a complete,
 * raw deflate stream with each call. inflateBackEnd() is then called to
 * free the allocated state.
 *
 * A raw deflate stream is one with no zlib or gzip header or trailer.
 * This routine would normally be used in a utility that reads zip or
 * gzip files and writes out uncompressed files. The utility would
 * decode the header and process the trailer on its own, hence this
 * routine expects only the raw deflate stream to decompress. This is
 * different from the default behavior of inflate(), which expects a
 * zlib header and trailer around the deflate stream.
 *
 * inflateBack() uses two subroutines supplied by the caller that are
 * then called by inflateBack() for input and output. inflateBack()
 * calls those routines until it reads a complete deflate stream and
 * writes out all of the uncompressed data, or until it encounters an
 * error. The function's parameters and return types are defined above
 * in the in_func and out_func typedefs. inflateBack() will call
 * in(in_desc, &buf) which should return the number of bytes of provided
 * input, and a pointer to that input in buf. If there is no input
 * available, in() must return zero -- buf is ignored in that case --
 * and inflateBack() will return a buffer error. inflateBack() will call
 * out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
 * out() should return zero on success, or non-zero on failure. If out()
 * returns non-zero, inflateBack() will return with an error. Neither
 * in() nor out() are permitted to change the contents of the window
 * provided to inflateBackInit(), which is also the buffer that out()
 * uses to write from. The length written by out() will be at most the
 * window size. Any non-zero amount of input may be provided by in().
 *
 * For convenience, inflateBack() can be provided input on the first
 * call by setting strm->next_in and strm->avail_in. If that input is
 * exhausted, then in() will be called. Therefore strm->next_in must be
 * initialized before calling inflateBack(). If strm->next_in is Z_NULL,
 * then in() will be called immediately for input. If strm->next_in is
 * not Z_NULL, then strm->avail_in must also be initialized, and then if
 * strm->avail_in is not zero, input will initially be taken from
 * strm->next_in[0 .. strm->avail_in - 1].
 *
 * The in_desc and out_desc parameters of inflateBack() is passed as the
 * first parameter of in() and out() respectively when they are called.
 * These descriptors can be optionally used to pass any information that
 * the caller- supplied in() and out() functions need to do their job.
 *
 * On return, inflateBack() will set strm->next_in and strm->avail_in to
 * pass back any unused input that was provided by the last in() call.
 * The return values of inflateBack() can be Z_STREAM_END on success,
 * Z_BUF_ERROR if in() or out() returned an error, Z_DATA_ERROR if there
 * was a format error in the deflate stream (in which case strm->msg is
 * set to indicate the nature of the error), or Z_STREAM_ERROR if the
 * stream was not properly initialized. In the case of Z_BUF_ERROR, an
 * input or output error can be distinguished using strm->next_in which
 * will be Z_NULL only if in() returned an error. If strm->next_in is
 * not Z_NULL, then the Z_BUF_ERROR was due to out() returning non-zero.
 * (in() will always be called before out(), so strm->next_in is assured
 * to be defined if out() returns non-zero.) Note that inflateBack()
 * cannot return Z_OK.
 */
int inflateBack(z_streamp strm, in_func in, void *in_desc, out_func out,
                void *out_desc);

/**
 * All memory allocated by inflateBackInit() is freed.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state was
 *     inconsistent.
 */
int inflateBackEnd(z_streamp strm);

/*
 * Return flags indicating compile-time options.
 *
 * Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
 *   1.0: size of uInt
 *   3.2: size of uLong
 *   5.4: size of voidpf (pointer)
 *   7.6: size of off_t
 *
 * Compiler, assembler, and debug options:
 *   8: ZLIB_DEBUG
 *   9: ASMV or ASMINF -- use ASM code
 *   10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
 *   11: 0 (reserved)
 *
 * One-time table building (smaller code, but not thread-safe if true):
 *   12: BUILDFIXED -- build static block decoding tables when needed
 *   13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
 *   14,15: 0 (reserved)
 *
 * Library content (indicates missing functionality):
 *
 *   16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
 *   deflate code when not needed)
 *
 *   17: NO_GZIP -- deflate can't write gzip streams, and inflate can't
 *   detect and decode gzip streams (to avoid linking crc code)
 *
 *   18-19: 0 (reserved)
 *
 * Operation variations (changes in library functionality):
 *   20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
 *   21: FASTEST -- deflate algorithm with only one, lowest compression level
 *   22,23: 0 (reserved)
 *
 * The sprintf variant used by gzprintf (zero is best):
 *   24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
 *   25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
 *   26: 0 = returns value, 1 = void -- 1 means inferred string length returned
 *
 * Remainder is:
 *   27-31: 0 (reserved)
 */
uLong zlibCompileFlags(void);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » utility functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  The following utility functions are implemented on top of the basic
  stream-oriented functions. To simplify the interface, some default
  options are assumed (compression level and memory usage, standard
  memory allocation functions). The source code of these utility
  functions can be modified if you need special options. */

/**
 * Compresses source buffer into the destination buffer. sourceLen is
 * the byte length of the source buffer. Upon entry, destLen is the
 * total size of the destination buffer, which must be at least the
 * value returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data. compress() is equivalent to
 * compress2() with a level parameter of Z_DEFAULT_COMPRESSION.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer.
 */
int compress(Bytef *dest, uLongf *destLen, const Bytef *source,
             uLong sourceLen);

/**
 * Compresses source buffer into the destination buffer. The level
 * parameter has the same meaning as in deflateInit. sourceLen is the
 * byte length of the source buffer. Upon entry, destLen is the total
 * size of the destination buffer, which must be at least the value
 * returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer,
 *     Z_STREAM_ERROR if the level parameter is invalid.
 */
int compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
              uLong sourceLen, int level);

/**
 * Returns an upper bound on the compressed size after compress() or
 * compress2() on sourceLen bytes. It would be used before a compress()
 * or compress2() call to allocate the destination buffer.
 */
uLong compressBound(uLong sourceLen);

/**
 * Decompresses the source buffer into the destination buffer.  sourceLen is
 * the byte length of the source buffer.  Upon entry, destLen is the total size
 * of the destination buffer, which must be large enough to hold the entire
 * uncompressed data.  (The size of the uncompressed data must have been saved
 * previously by the compressor and transmitted to the decompressor by some
 * mechanism outside the scope of this compression library.) Upon exit, destLen
 * is the actual size of the uncompressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer, or
 *     Z_DATA_ERROR if the input data was corrupted or incomplete. In
 *     the case where there is not enough room, uncompress() will fill
 *     the output buffer with the uncompressed data up to that point.
 */
int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
               uLong sourceLen);

/**
 * Same as uncompress, except that sourceLen is a pointer, where the
 * length of the source is *sourceLen.  On return, *sourceLen is the number of
 * source bytes consumed.
 */
int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
                uLong *sourceLen);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » gzip                                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  This library supports reading and writing files in gzip (.gz) format
  with an interface similar to that of stdio, using the functions that
  start with "gz". The gzip format is different from the zlib format.
  gzip is a gzip wrapper, documented in RFC 1952, wrapped around a
  deflate stream. */

typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */

/**
 * Opens a gzip (.gz) file for reading or writing.
 *
 * The mode parameter is as in fopen ("rb" or "wb") but can also include
 * a compression level ("wb9") or a strategy: 'f' for filtered data as
 * in "wb6f", 'h' for Huffman-only compression as in "wb1h", 'R' for
 * run-length encoding as in "wb1R", or 'F' for fixed code compression
 * as in "wb9F". (See the description of deflateInit2 for more
 * information about the strategy parameter.) 'T' will request
 * transparent writing or appending with no compression and not using
 * the gzip format.
 *
 * "a" can be used instead of "w" to request that the gzip stream that
 * will be written be appended to the file. "+" will result in an error,
 * since reading and writing to the same gzip file is not supported. The
 * addition of "x" when writing will create the file exclusively, which
 * fails if the file already exists. On systems that support it, the
 * addition of "e" when reading or writing will set the flag to close
 * the file on an execve() call.
 *
 * These functions, as well as gzip, will read and decode a sequence of
 * gzip streams in a file. The append function of gzopen() can be used
 * to create such a file. (Also see gzflush() for another way to do
 * this.) When appending, gzopen does not test whether the file begins
 * with a gzip stream, nor does it look for the end of the gzip streams
 * to begin appending. gzopen will simply append a gzip stream to the
 * existing file.
 *
 * gzopen can be used to read a file which is not in gzip format; in
 * this case gzread will directly read from the file without
 * decompression. When reading, this will be detected automatically by
 * looking for the magic two- byte gzip header.
 *
 * @return Z_OK if the file could not be opened, if there was insufficient
 *     memory to allocate the gzFile state, or if an invalid mode was
 *     specified (an 'r', 'w', or 'a' was not provided, or '+' was
 *     provided). errno can be checked to determine if the reason gzopen
 *     failed was that the file could not be opened.
 */
gzFile gzopen(const char *path, const char *mode);

/**
 * Associates gzFile with the file descriptor.
 *
 * File descriptors are obtained from calls like open, dup, creat, pipe
 * or fileno (if the file has been previously opened with fopen). The
 * mode parameter is as in gzopen.
 *
 * The next call of gzclose on the returned gzFile will also close the file
 * descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
 * fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
 * mode);.  The duplicated descriptor should be saved to avoid a leak, since
 * gzdopen does not close fd if it fails.  If you are using fileno() to get the
 * file descriptor from a FILE *, then you will have to use dup() to avoid
 * double-close()ing the file descriptor.  Both gzclose() and fclose() will
 * close the associated file descriptor, so they need to have different file
 * descriptors.
 *
 * @return Z_OK if there was insufficient memory to allocate the gzFile
 *     state, if an invalid mode was specified (an 'r', 'w', or 'a' was
 *     not provided, or '+' was provided), or if fd is -1. The file
 *     descriptor is not used until the next gz* read, write, seek, or
 *     close operation, so gzdopen will not detect if fd is invalid
 *     (unless fd is -1).
 */
gzFile gzdopen(int fd, const char *mode);

/**
 * Sets internal buffer size used by this library's functions. The
 * default buffer size is 8192 bytes. This function must be called after
 * gzopen() or gzdopen(), and before any other calls that read or write
 * the file. The buffer memory allocation is always deferred to the
 * first read or write. Three times that size in buffer space is
 * allocated. A larger buffer size of, for example, 64K or 128K bytes
 * will noticeably increase the speed of decompression (reading).
 *
 * The new buffer size also affects the maximum length for gzprintf().
 *
 * @return Z_OK on success, or -1 on failure, such as being called too
 *     late.
 */
int gzbuffer(gzFile file, unsigned size);

/**
 * Dynamically update the compression level or strategy.  See the description
 * of deflateInit2 for the meaning of these parameters.  Previously provided
 * data is flushed before the parameter change.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the file was not opened for
 *     writing, Z_ERRNO if there is an error writing the flushed data,
 *     or Z_MEM_ERROR if there is a memory allocation error.
 */
int gzsetparams(gzFile file, int level, int strategy);

/**
 * Reads given number of uncompressed bytes from the compressed file. If
 * the input file is not in gzip format, gzread copies the given number
 * of bytes into the buffer directly from the file.
 *
 * After reaching the end of a gzip stream in the input, gzread will continue
 * to read, looking for another gzip stream.  Any number of gzip streams may be
 * concatenated in the input file, and will all be decompressed by gzread().
 * If something other than a gzip stream is encountered after a gzip stream,
 * that remaining trailing garbage is ignored (and no error is returned).
 *
 * gzread can be used to read a gzip file that is being concurrently written.
 * Upon reaching the end of the input, gzread will return with the available
 * data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
 * gzclearerr can be used to clear the end of file indicator in order to permit
 * gzread to be tried again.  Z_OK indicates that a gzip stream was completed
 * on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
 * middle of a gzip stream.  Note that gzread does not return -1 in the event
 * of an incomplete gzip stream.  This error is deferred until gzclose(), which
 * will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
 * stream.  Alternatively, gzerror can be used before gzclose to detect this
 * case.
 *
 * @return Z_OK number of uncompressed bytes actually read, less than
 *     len for end of file, or -1 for error. If len is too large to fit
 *     in an int, then nothing is read, -1 is returned, and the error
 *     state is set to Z_STREAM_ERROR.
 */
int gzread(gzFile file, voidp buf, unsigned len);

/**
 * Read up to nitems items of size size from file to buf, otherwise operating
 * as gzread() does.  This duplicates the interface of stdio's fread(), with
 * size_t request and return types.  If the library defines size_t, then
 * size_t is identical to size_t.  If not, then size_t is an unsigned
 * integer type that can contain a pointer.
 *
 * gzfread() returns the number of full items read of size size, or zero if
 * the end of the file was reached and a full item could not be read, or if
 * there was an error.  gzerror() must be consulted if zero is returned in
 * order to determine if there was an error.  If the multiplication of size and
 * nitems overflows, i.e. the product does not fit in a size_t, then nothing
 * is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
 *
 * In the event that the end of file is reached and only a partial item is
 * available at the end, i.e. the remaining uncompressed data length is not a
 * multiple of size, then the final partial item is nevetheless read into buf
 * and the end-of-file flag is set.  The length of the partial item read is not
 * provided, but could be inferred from the result of gztell().  This behavior
 * is the same as the behavior of fread() implementations in common libraries,
 * but it prevents the direct use of gzfread() to read a concurrently written
 * file, reseting and retrying on end-of-file, when size is not 1.
 */
size_t gzfread(voidp buf, size_t size, size_t nitems, gzFile file);

/**
 * Writes given number of uncompressed bytes into the compressed file.
 * gzwrite returns the number of uncompressed bytes written or 0 in case
 * of error.
 */
int gzwrite(gzFile file, voidpc buf, unsigned len);

/**
 * Writes nitems items of size size from buf to file, duplicating the
 * interface of stdio's fwrite(), with size_t request and return types.
 * If the library defines size_t, then size_t is identical to size_t. If
 * not, then size_t is an unsigned integer type that can contain a
 * pointer.
 *
 * gzfwrite() returns the number of full items written of size size, or zero
 * if there was an error.  If the multiplication of size and nitems overflows,
 * i.e. the product does not fit in a size_t, then nothing is written, zero
 * is returned, and the error state is set to Z_STREAM_ERROR.
 */
size_t gzfwrite(voidpc buf, size_t size, size_t nitems, gzFile file);

/**
 * Converts, formats, and writes the arguments to the compressed file
 * under control of the format string, as in fprintf. gzprintf returns
 * the number of uncompressed bytes actually written, or a negative zlib
 * error code in case of error. The number of uncompressed bytes written
 * is limited to 8191, or one less than the buffer size given to
 * gzbuffer(). The caller should assure that this limit is not exceeded.
 * If it is exceeded, then gzprintf() will return an error (0) with
 * nothing written. In this case, there may also be a buffer overflow
 * with unpredictable consequences, which is possible only if zlib was
 * compiled with the insecure functions sprintf() or vsprintf() because
 * the secure snprintf() or vsnprintf() functions were not available.
 * This can be determined using zlibCompileFlags().
 */
int gzprintf(gzFile file, const char *format, ...);

/**
 * Writes the given null-terminated string to the compressed file, excluding
 * the terminating null character.
 *
 * @return Z_OK number of characters written, or -1 in case of error.
 */
int gzputs(gzFile file, const char *s);

/**
 * Reads bytes from the compressed file until len-1 characters are read,
 * or a newline character is read and transferred to buf, or an
 * end-of-file condition is encountered. If any characters are read or
 * if len == 1, the string is terminated with a null character. If no
 * characters are read due to an end-of-file or len < 1, then the buffer
 * is left untouched.
 *
 * @return buf which is a null-terminated string, or it returns NULL for
 *     end-of-file or in case of error. If there was an error, the
 *     contents at buf are indeterminate.
 */
char *gzgets(gzFile file, char *buf, int len);

/**
 * Writes character converted to an unsigned char into compressed file.
 * @return value that was written, or -1 on error
 */
int gzputc(gzFile file, int c);

/**
 * Reads one byte from the compressed file. gzgetc returns this byte or
 * -1 in case of end of file or error. This is implemented as a macro
 * for speed. As such, it does not do all of the checking the other
 * functions do. I.e. it does not check to see if file is NULL, nor
 * whether the structure file points to has been clobbered or not.
 */
int gzgetc(gzFile file);

/**
 * Pushes one character back onto the stream to be read as the first
 * character on the next read. At least one character of push-back is
 * allowed. gzungetc() returns the character pushed, or -1 on failure.
 * gzungetc() will fail if c is -1, and may fail if a character has been
 * pushed but not read yet. If gzungetc is used immediately after gzopen
 * or gzdopen, at least the output buffer size of pushed characters is
 * allowed. (See gzbuffer above.) The pushed character will be discarded
 * if the stream is repositioned with gzseek() or gzrewind().
 */
int gzungetc(int c, gzFile file);

/**
 * Flushes all pending output into the compressed file. The parameter
 * flush is as in the deflate() function. The return value is the zlib
 * error number (see function gzerror below). gzflush is only permitted
 * when writing.
 *
 * If the flush parameter is Z_FINISH, the remaining data is written and
 * the gzip stream is completed in the output. If gzwrite() is called
 * again, a new gzip stream will be started in the output. gzread() is
 * able to read such concatenated gzip streams.
 *
 * gzflush should be called only when strictly necessary because it will
 * degrade compression if called too often.
 */
int gzflush(gzFile file, int flush);

/**
 * Sets starting position for the next gzread or gzwrite on the given
 * compressed file. The offset represents a number of bytes in the
 * uncompressed data stream. The whence parameter is defined as in
 * lseek(2); the value SEEK_END is not supported.
 *
 * If the file is opened for reading, this function is emulated but can be
 * extremely slow.  If the file is opened for writing, only forward seeks are
 * supported; gzseek then compresses a sequence of zeroes up to the new
 * starting position.
 *
 * @return resulting offset location as measured in bytes from the
 *     beginning of the uncompressed stream, or -1 in case of error, in
 *     particular if the file is opened for writing and the new starting
 *     position would be before the current position.
 */
ssize_t gzseek(gzFile file, int64_t offset, int whence);

/**
 * Rewinds file.
 *
 * This function is supported only for reading.
 *
 * @note gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
 */
int gzrewind(gzFile file);

/**
 * Returns starting position for the next gzread or gzwrite on the given
 * compressed file. This position represents a number of bytes in the
 * uncompressed data stream, and is zero when starting, even if
 * appending or reading a gzip stream from the middle of a file using
 * gzdopen().
 *
 * @note gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 */
ssize_t gztell(gzFile file);

/**
 * Returns current offset in the file being read or written. This offset
 * includes the count of bytes that precede the gzip stream, for example
 * when appending or when using gzdopen() for reading. When reading, the
 * offset does not include as yet unused buffered input. This
 * information can be used for a progress indicator. On error,
 * gzoffset() returns -1.
 */
ssize_t gzoffset(gzFile file);

/**
 * Returns true (1) if the end-of-file indicator has been set while
 * reading, false (0) otherwise. Note that the end-of-file indicator is
 * set only if the read tried to go past the end of the input, but came
 * up short. Therefore, just like feof(), gzeof() may return false even
 * if there is no more data to read, in the event that the last read
 * request was for the exact number of bytes remaining in the input
 * file. This will happen if the input file size is an exact multiple of
 * the buffer size.
 *
 * If gzeof() returns true, then the read functions will return no more
 * data, unless the end-of-file indicator is reset by gzclearerr() and
 * the input file has grown since the previous end of file was detected.
 */
int gzeof(gzFile file);

/**
 * Returns true (1) if file is being copied directly while reading, or
 * false (0) if file is a gzip stream being decompressed.
 *
 * If the input file is empty, gzdirect() will return true, since the
 * input does not contain a gzip stream.
 *
 * If gzdirect() is used immediately after gzopen() or gzdopen() it will
 * cause buffers to be allocated to allow reading the file to determine
 * if it is a gzip file. Therefore if gzbuffer() is used, it should be
 * called before gzdirect().
 *
 * When writing, gzdirect() returns true (1) if transparent writing was
 * requested ("wT" for the gzopen() mode), or false (0) otherwise.
 * (Note: gzdirect() is not needed when writing. Transparent writing
 * must be explicitly requested, so the application already knows the
 * answer. When linking statically, using gzdirect() will include all of
 * the zlib code for gzip file reading and decompression, which may not
 * be desired.)
 */
int gzdirect(gzFile file);

/**
 * Flushes all pending output if necessary, closes the compressed file
 * and deallocates the (de)compression state. Note that once file is
 * closed, you cannot call gzerror with file, since its structures have
 * been deallocated. gzclose must not be called more than once on the
 * same file, just as free must not be called more than once on the same
 * allocation.
 *
 * @return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a file
 *     operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
 *     last read ended in the middle of a gzip stream, or Z_OK on
 *     success.
 */
int gzclose(gzFile file);

/**
 * Same as gzclose(), but gzclose_r() is only for use when reading, and
 * gzclose_w() is only for use when writing or appending. The advantage
 * to using these instead of gzclose() is that they avoid linking in
 * zlib compression or decompression code that is not used when only
 * reading or only writing respectively. If gzclose() is used, then both
 * compression and decompression code will be included the application
 * when linking to a static zlib library.
 */
int gzclose_r(gzFile file);
int gzclose_w(gzFile file);

/**
 * Returns the error message for the last error which occurred on the given
 * compressed file.  errnum is set to zlib error number.  If an error occurred
 * in the file system and not in the compression library, errnum is set to
 * Z_ERRNO and the application may consult errno to get the exact error code.
 *
 * The application must not modify the returned string.  Future calls to
 * this function may invalidate the previously returned string.  If file is
 * closed, then the string previously returned by gzerror will no longer be
 * available.
 *
 * gzerror() should be used to distinguish errors from end-of-file for those
 * functions above that do not distinguish those cases in their return values.
 */
const char *gzerror(gzFile file, int *errnum);

/**
 * Clears the error and end-of-file flags for file.  This is analogous to the
 * clearerr() function in stdio.  This is useful for continuing to read a gzip
 * file that is being written concurrently.
 */
void gzclearerr(gzFile file);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » checksums                                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/**
 * Updates running Adler-32 checksum with the bytes buf[0..len-1] and
 * return the updated checksum. If buf is Z_NULL, this function returns
 * the required initial value for the checksum.
 */
uLong adler32(uLong adler, const Bytef *buf, uInt len);

/**
 * Same as adler32(), but with a size_t length.
 */
uLong adler32_z(uLong adler, const Bytef *buf, size_t len);

/**
 * Combine two Adler-32 checksums into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were
 * calculated for each, adler1 and adler2. adler32_combine() returns the
 * Adler-32 checksum of seq1 and seq2 concatenated, requiring only
 * adler1, adler2, and len2. Note that the off_t type (like off_t) is a
 * signed integer. If len2 is negative, the result has no meaning or
 * utility.
 */
uLong adler32_combine(uLong adler1, uLong adler2, int64_t len2);

/**
 * Update a running CRC-32 with the bytes buf[0..len-1] and return the
 * updated CRC-32.  If buf is Z_NULL, this function returns the required
 * initial value for the crc.  Pre- and post-conditioning (one's complement) is
 * performed within this function so it shouldn't be done by the application.
 *
 * Usage example:
 *
 *     uLong crc = crc32(0L, Z_NULL, 0);
 *     while (read_buffer(buffer, length) != EOF) {
 *       crc = crc32(crc, buffer, length);
 *     }
 *     if (crc != original_crc) error();
 */
uLong crc32(uLong crc, const Bytef *buf, uInt len);

/**
 * Same as crc32(), but with a size_t length.
 */
uint32_t crc32_z(uint32_t crc, const void *buf, size_t len);

/**
 * Combine two CRC-32 check values into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
 * calculated for each, crc1 and crc2. crc32_combine() returns the
 * CRC-32 check value of seq1 and seq2 concatenated, requiring only
 * crc1, crc2, and len2.
 */
uLong crc32_combine(uLong crc1, uLong crc2, int64_t len2);

/**
 * gzgetc() macro and its supporting function and exposed data
 * structure. Note that the real internal state is much larger than the
 * exposed structure. This abbreviated structure exposes just enough for
 * the gzgetc() macro. The user should not mess with these exposed
 * elements, since their names or behavior could change in the future,
 * perhaps even capriciously. They can only be used by the gzgetc()
 * macro. You have been warned.
 */
struct gzFile_s {
  unsigned have;
  unsigned char *next;
  int64_t pos;
};

int gzgetc_(gzFile file); /* backward compatibility */
#ifdef Z_PREFIX_SET
#undef z_gzgetc
#define z_gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#elif defined(Z_COSMO_PREFIX_SET)
#undef gzgetc
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (__gzgetc)(g))
#else
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#endif

/* undocumented functions */
const char *zError(int);
int inflateSyncPoint(z_streamp);
int inflateUndermine(z_streamp, int);
int inflateValidate(z_streamp, int);
unsigned long inflateCodesUsed(z_streamp);
int inflateResetKeep(z_streamp);
int deflateResetKeep(z_streamp);
int gzvprintf(gzFile file, const char *format, va_list va);
void inflate_fast_chunk(z_streamp strm, unsigned start);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/regex/regex.h */

#define COSMOPOLITAN_LIBC_REGEX_REGEX_H_
COSMOPOLITAN_C_START_

#if 0
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § regular expressions                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
#endif

#define REG_EXTENDED 1
#define REG_ICASE    2
#define REG_NEWLINE  4
#define REG_NOSUB    8

#define REG_NOTBOL 1 /* ^ should not match beginning of string */
#define REG_NOTEOL 2 /* $ should not match end of string */

#define REG_OK       0
#define REG_NOMATCH  1
#define REG_BADPAT   2
#define REG_ECOLLATE 3
#define REG_ECTYPE   4
#define REG_EESCAPE  5
#define REG_ESUBREG  6
#define REG_EBRACK   7
#define REG_EPAREN   8
#define REG_EBRACE   9
#define REG_BADBR    10
#define REG_ERANGE   11
#define REG_ESPACE   12
#define REG_BADRPT   13

#define REG_ENOSYS -1

typedef long regoff_t;

struct PosixRegex {
  size_t re_nsub;
  void *__opaque, *__padding[4];
  size_t __nsub2;
  char __padding2;
};

struct PosixRegexMatch {
  regoff_t rm_so;
  regoff_t rm_eo;
};

typedef struct PosixRegex regex_t;
typedef struct PosixRegexMatch regmatch_t;

int regcomp(regex_t *, const char *, int);
int regexec(const regex_t *, const char *, size_t, regmatch_t *, int);
size_t regerror(int, const regex_t *, char *, size_t);
void regfree(regex_t *);

COSMOPOLITAN_C_END_

#endif /* COSMOPOLITAN_H_ */
#ifndef COSMOPOLITAN_H_
#define COSMOPOLITAN_H_


/*!BEGIN libc/integral/normalize.inc */

#ifdef __COSMOPOLITAN__
#undef __COSMOPOLITAN__
#endif

#define __COSMOPOLITAN_MAJOR__ 3
#define __COSMOPOLITAN_MINOR__ 3
#define __COSMOPOLITAN_PATCH__ 9
#define __COSMOPOLITAN__                                                   \
  (100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
   __COSMOPOLITAN_PATCH__)

#ifndef __COUNTER__
#define __COUNTER__ __LINE__
#endif

#if __GNUC__ + 0 < 2
#undef __GNUC__
#elif defined(__GNUC__) && defined(SWIG) /* lool */
#undef __GNUC__
#elif defined(__GNUC__) && defined(__NVCC__) /* lool */
#undef __GNUC__
#elif !defined(__GNUC__) && defined(__APPLE__) /* modesty */
#define __GNUC__            4
#define __GNUC_MINOR__      2
#define __GNUC_PATCHLEVEL__ 1
#elif !defined(__GNUC__) && defined(__TINYC__)
#define __GNUC__            2
#define __GNUC_MINOR__      0
#define __GNUC_PATCHLEVEL__ 0
#endif

#if !defined(__x86_64__) && \
    (defined(__amd64__) || (defined(_M_AMD64) && defined(_M_X64)))
#define __x86_64__ 1
#elif !defined(__i386__) && ((defined(__i486__) || defined(__i586__) ||  \
                              defined(__i686__) || defined(__i786__)) || \
                             _M_IX86 + 0 >= 400)
#define __i386__ 1
#elif !defined(__ia16__) && (defined(__MSDOS__) || defined(__BCC__))
#define __ia16__ 1
#endif
#if __ia16__ + __i386__ + __x86_64__ + 0
#define __x86__ 1
#endif

#ifdef _MSC_VER
#define __STRICT_ANSI__
#ifndef __STDC__
#define __STDC__
#endif
#endif

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif
#ifndef __has_extension
#define __has_extension(x) 0
#endif

#ifdef unix
#undef unix
#endif

#ifdef linux
#undef linux
#endif

#ifdef __linux
#undef __linux
#endif

#ifdef __linux__
#undef __linux__
#endif

#ifndef __BIGGEST_ALIGNMENT__
#define __BIGGEST_ALIGNMENT__ 16
#endif

#ifdef _COSMO_SOURCE
#define FRAMESIZE 65536
#define _PAGESIZE 4096
#endif

#if defined(__LP64__) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/lp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xfffffffffffffffful
#define __SIZE_MAX__    0xfffffffffffffffful
#define __INTPTR_MAX__  0x7fffffffffffffffl
#define __UINTPTR_MAX__ 0xfffffffffffffffful
#define __WINT_MAX__    0xffffffffu
#define __UINTMAX_MAX__ 0xffffffffffffffffUL
#define __INTMAX_MAX__  0x7fffffffffffffffL

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        8
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      8
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __INT16_TYPE__   short int
#define __INT32_TYPE__   int
#define __INT64_TYPE__   long int
#define __INT8_TYPE__    signed char
#define __INTMAX_TYPE__  long int
#define __INTPTR_TYPE__  long int
#define __PTRDIFF_TYPE__ long int
#define __SIZE_TYPE__    long unsigned int
#define __UINT16_TYPE__  short unsigned int
#define __UINT32_TYPE__  unsigned int
#define __UINT64_TYPE__  long unsigned int
#define __UINT8_TYPE__   unsigned char
#define __UINTMAX_TYPE__ long unsigned int
#define __UINTPTR_TYPE__ long unsigned int
#define __WCHAR_TYPE__   int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#elif defined(_MSC_VER) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/llp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xffffffffffffffffull
#define __SIZE_MAX__    0xffffffffffffffffull
#define __INTPTR_MAX__  0x7fffffffffffffffll
#define __UINTPTR_MAX__ 0xffffffffffffffffull
#define __WINT_MAX__    0xffffffffu

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        4
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      4
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#define __INT8_C(c)   c
#define __UINT8_C(c)  c
#define __INT16_C(c)  c
#define __UINT16_C(c) c
#define __INT32_C(c)  c
#define __UINT32_C(c) c##U
#define __INT64_C(c)  c##LL
#define __UINT64_C(c) c##ULL

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __INT8_TYPE__    signed char
#define __UINT8_TYPE__   unsigned char
#define __INT16_TYPE__   short int
#define __UINT16_TYPE__  short unsigned int
#define __INT32_TYPE__   int
#define __UINT32_TYPE__  unsigned int
#define __INT64_TYPE__   long long int
#define __UINT64_TYPE__  long long unsigned int
#define __INTPTR_TYPE__  long long int
#define __UINTPTR_TYPE__ long long unsigned int
#define __PTRDIFF_TYPE__ long long int
#define __SIZE_TYPE__    unsigned int
#define __WCHAR_TYPE__   int
#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef __STDC__


/*!BEGIN libc/integral/c.inc */

#if __GNUC__ + 0 < 2
#define __attribute__(x)
#endif

#ifndef __cplusplus
#define COSMOPOLITAN_C_START_
#define COSMOPOLITAN_C_END_
#define COSMOPOLITAN_CXX_START_
#define COSMOPOLITAN_CXX_END_
#define COSMOPOLITAN_CXX_USING_
#endif

#ifndef __ia16__
#define __far
#endif

#if !defined(__GNUC__) && __cplusplus + 0 >= 201103L
#define typeof(x) decltype(x)
#elif !defined(__GNUC__) && __STDC_VERSION__ + 0 < 201112
#define typeof(x) __typeof(x)
#endif

#ifdef __cplusplus
#if __cplusplus >= 201103L
#define _Alignof(x) alignof(x)
#endif /* C++11 */
#else  /* __cplusplus */
#if __STDC_VERSION__ + 0 < 201112
#if __GNUC__ + _MSC_VER + 0
#define _Alignof(x) __alignof(x)
#else
#define _Alignof(x) /* basically all it ever did lool */ sizeof(x)
#endif /* GNU/MSVC/!ANSI */
#endif /* C11 */
#endif /* __cplusplus */

#if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901
#if defined(__GNUC__) || defined(_MSC_VER)
#define inline __inline
#else
#define inline
#define __inline
#endif
#endif

#ifdef __chibicc__
#define __extension__
#endif

#if __STDC_VERSION__ + 0 < 201112
#ifdef __GNUC__
#define _Alignas(x) __attribute__((__aligned__(x)))
#elif defined(_MSC_VER)
#define _Alignas(x) __declspec(align(x))
#endif
#endif

#ifdef _MSC_VER
#define __builtin_unreachable() __assume(false)
#elif !((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
        defined(__clang__) || defined(__INTEL_COMPILER) ||    \
        __has_builtin(__builtin_unreachable))
#define __builtin_unreachable() \
  for (;;) {                    \
  }
#endif

#if (!defined(__llvm__) && !__has_builtin(__builtin_assume))
#define __builtin_assume(x)    \
  do {                         \
    if (!(x))                  \
      __builtin_unreachable(); \
  } while (0)
#endif

#if __STDC_VERSION__ + 0 < 201112
#define _Atomic(TYPE) TYPE volatile
#endif

#ifdef __llvm__
#define __gnu_printf__ __printf__
#define __gnu_scanf__  __scanf__
#endif

#if __cplusplus + 0 >= 201103L
#define NULL nullptr
#elif !defined(__cplusplus)
#define NULL ((void *)0)
#else
#define NULL 0
#endif

#ifndef __cplusplus
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wc++-compat"
#endif
typedef __WCHAR_TYPE__ wchar_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC pop_options
#endif
#endif /* __cplusplus */

#ifndef __COSMOCC__


/*!BEGIN libc/stdbool.h */

#define COSMOPOLITAN_LIBC_STDBOOL_H_

#ifndef __cplusplus

#define bool _Bool
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
#define true  ((_Bool) + 1u)
#define false ((_Bool) + 0u)
#else
#define true  1
#define false 0
#endif

#else /* __cplusplus */

#define _Bool bool

#endif /* __cplusplus */

#define __bool_true_false_are_defined 1

#endif

#define _LIBCPP_STDINT_H

typedef int errno_t;
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __WINT_TYPE__ wint_t; /* uint32_t on linux but int32_t on xnu */
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ bool32;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;

#define __DEFINED_max_align_t
typedef long double max_align_t;

#ifdef _COSMO_SOURCE
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || defined(__llvm__)
typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t;
#endif
#endif /* _COSMO_SOURCE */

#ifndef __AXDX_T
#define __AXDX_T
typedef struct {
  intptr_t ax, dx;
} axdx_t;
#endif

#ifndef __chibicc__
#define va_list            __builtin_va_list
#define va_arg(ap, type)   __builtin_va_arg(ap, type)
#define va_copy(dest, src) __builtin_va_copy(dest, src)
#define va_end(ap)         __builtin_va_end(ap)
#define va_start(ap, last) __builtin_va_start(ap, last)
#else


/*!BEGIN libc/integral/lp64arg.inc */

/* variadic arguments for chibicc */

/* <sync libc/runtime/valist.c> */
struct __va_list {
  uint32_t gp_offset;
  uint32_t fp_offset;
  void *overflow_arg_area;
  void *reg_save_area;
};
/* </sync libc/runtime/valist.c> */

void *__va_arg(struct __va_list *, size_t, unsigned, unsigned);

#define __GNUC_VA_LIST 1
#define __gnuc_va_list va_list

#define va_end(AP)
#define va_copy(DST, SRC) ((DST)[0] = (SRC)[0])
#define va_start(AP, LAST)                    \
  do {                                        \
    *(AP) = *(struct __va_list *)__va_area__; \
  } while (0)

#define va_arg(AP, TYPE)                               \
  (*(TYPE *)__va_arg(AP, sizeof(TYPE), _Alignof(TYPE), \
                     __builtin_reg_class(TYPE)))

typedef struct __va_list va_list[1];
#endif

#define libcesque   dontthrow dontcallback
#define memcpyesque libcesque
#define strlenesque libcesque nosideeffect paramsnonnull()
#define vallocesque \
  libcesque __wur returnsaligned((65536)) returnspointerwithnoaliases
#define reallocesque libcesque returnsaligned((16))
#define mallocesque  reallocesque returnspointerwithnoaliases
#define interruptfn  nocallersavedregisters forcealignargpointer

#ifndef pureconst
#define pureconst __attribute__((__const__))
#endif

#ifndef forcealign
#define forcealign(bytes) __attribute__((__aligned__(bytes)))
#endif
#define thatispacked __attribute__((__packed__))

#define printfesque(n)   __attribute__((__format__(__gnu_printf__, n, n + 1)))
#define scanfesque(n)    __attribute__((__format__(__gnu_scanf__, n, n + 1)))
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))

#ifndef privileged
#define privileged \
  _Section(".privileged") dontinline dontinstrument dontubsan dontasan
#endif

#ifndef wontreturn
#if (__has_attribute(__noreturn__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208)
#define wontreturn __attribute__((__noreturn__))
#else
#define wontreturn
#endif
#endif

#ifndef nosideeffect
#if (__has_attribute(__pure__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296)
#define nosideeffect __attribute__((__pure__))
#else
#define nosideeffect
#endif
#endif

#ifndef dontinline
#ifdef _MSC_VER
#define dontinline __declspec(noinline)
#elif (__has_attribute(__noinline__) || \
       (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
#define dontinline __attribute__((__noinline__))
#else
#define dontinline
#endif
#endif

#ifndef dontclone
#if (__has_attribute(__noclone__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405)
#define dontclone __attribute__((__noclone__))
#else
#define dontclone
#endif
#endif

#ifndef forceinline
#ifdef __cplusplus
#define forceinline inline
#else
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
    !defined(__cplusplus) ||                              \
    (defined(__clang__) &&                                \
     (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define forceinline                                                 \
  static __inline __attribute__((__always_inline__, __gnu_inline__, \
                                 __no_instrument_function__, __unused__))
#else
#define forceinline                                 \
  static __inline __attribute__((__always_inline__, \
                                 __no_instrument_function__, __unused__))
#endif /* __GNUC_STDC_INLINE__ */
#endif /* GCC >= 4.3 */
#elif defined(_MSC_VER)
#define forceinline __forceinline
#else
#define forceinline static inline
#endif /* !ANSI && GCC >= 3.2 */
#endif /* __cplusplus */
#endif /* forceinline */

#ifndef __wur
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
     __has_attribute(__warn_unused_result__))
#define __wur __attribute__((__warn_unused_result__))
#else
#define __wur
#endif
#endif

#ifndef nullterminated
#if __has_attribute(__sentinel__) || __GNUC__ + 0 >= 4
#define nullterminated(x) __attribute__((__sentinel__ x))
#else
#define nullterminated(x)
#endif
#endif

#ifndef flattenout
#if __has_attribute(__flatten__) || \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401 && !defined(__llvm__))
#define flattenout __attribute__((__flatten__))
#else
#define flattenout
#endif
#endif

#ifndef externinline
#if (!defined(__cplusplus) ||                              \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
     (defined(__clang__) &&                                \
      (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__))))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define externinline extern __inline __attribute__((__gnu_inline__))
#else
#define externinline extern __inline __attribute__((__always_inline__))
#endif
#else
#define externinline inline
#endif
#endif

#ifndef relegated
#if (__has_attribute(__cold__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define relegated __attribute__((__cold__))
#else
#define relegated
#endif
#endif

#if (__has_attribute(__warning__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define warnifused(s) __attribute__((__warning__(s)))
#else
#define warnifused(s)
#endif

#ifndef firstclass
#if (__has_attribute(__hot__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define firstclass __attribute__((__hot__))
#else
#define firstclass
#endif
#endif

#ifndef paramsnonnull
#if (__has_attribute(__nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs))
#else
#define paramsnonnull(opt_1idxs)
#endif
#endif

#if __STDC_VERSION__ + 0 >= 199901L
#define hasatleast static
#else
#define hasatleast
#endif

#if __STDC_VERSION__ + 0 < 199901L && !defined(restrict)
#if !defined(__cplusplus) && \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER))
#define restrict __restrict__
#else
#define restrict
#define __restrict
#endif
#endif

#ifndef dontcallback
#if (__has_attribute(__leaf__) || \
     (!defined(__llvm__) &&       \
      (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406))
#define dontcallback __attribute__((__leaf__))
#else
#define dontcallback
#endif
#endif

#ifndef dontthrow
#if defined(__cplusplus) &&        \
    (__has_attribute(dontthrow) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define dontthrow __attribute__((__nothrow__))
#elif defined(_MSC_VER)
#define dontthrow __declspec(nothrow)
#else
#define dontthrow
#endif
#endif

#ifndef returnstwice
#if (__has_attribute(__returns_twice__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402)
#define returnstwice __attribute__((__returns_twice__))
#else
#define returnstwice
#endif
#endif

#ifndef nodebuginfo
#if __has_attribute(__nodebug__) || defined(__llvm__)
#define nodebuginfo __attribute__((__nodebug__))
#else
#define nodebuginfo
#endif
#endif

#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
    __has_attribute(__force_align_arg_pointer__)
#define forcealignargpointer __attribute__((__force_align_arg_pointer__))
#else
#define forcealignargpointer "need modern compiler"
#endif

#ifndef returnsnonnull
#if (__has_attribute(__returns_nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsnonnull __attribute__((__returns_nonnull__))
#else
#define returnsnonnull
#endif
#endif

#if (__has_attribute(__assume_aligned__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsaligned(x) __attribute__((__assume_aligned__ x))
#else
#define returnsaligned(x)
#endif

#ifndef returnspointerwithnoaliases
#if (__has_attribute(__malloc__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnspointerwithnoaliases __attribute__((__malloc__))
#elif defined(_MSC_VER)
#define returnspointerwithnoaliases __declspec(allocator)
#else
#define returnspointerwithnoaliases
#endif
#endif

#ifndef attributeallocsize
#if (__has_attribute(__alloc_size__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocsize(x) __attribute__((__alloc_size__ x))
#else
#define attributeallocsize(x)
#endif
#endif

#ifndef attributeallocalign
#if (__has_attribute(__alloc_align__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocalign(x) __attribute__((__alloc_align__ x))
#else
#define attributeallocalign(x)
#endif
#endif

#if __cplusplus + 0 >= 201103L
#define autotype(x) auto
#elif ((__has_builtin(__auto_type) || defined(__llvm__) ||     \
        (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) && \
       !defined(__chibicc__))
#define autotype(x) __auto_type
#else
#define autotype(x) typeof(x)
#endif

#define offsetof(type, member) __builtin_offsetof(type, member)

#ifdef _COSMO_SOURCE

#ifndef dontinstrument
#if (__has_attribute(__no_instrument_function__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
#if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \
    __has_attribute(__patchable_function_entry__)
#define dontinstrument                       \
  __attribute__((__no_instrument_function__, \
                 __patchable_function_entry__(0, 0)))
#else
#define dontinstrument __attribute__((__no_instrument_function__))
#endif
#else
#define dontinstrument
#endif
#endif

#ifndef mayalias
#if (__has_attribute(__may_alias__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define mayalias __attribute__((__may_alias__))
#else
#define mayalias
#endif
#endif

#ifndef dontoptimize
#if defined(__llvm__) || __has_attribute(__optnone__)
#define dontoptimize __attribute__((__optnone__))
#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define dontoptimize __attribute__((__optimize__(0)))
#endif
#endif

#ifndef optimizesize
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define optimizesize __attribute__((__optimize__("s")))
#elif defined(__llvm__) || __has_attribute(__optnone__)
#define optimizesize __attribute__((__optnone__))
#endif
#endif

#ifndef optimizespeed
/* warning: corrupts frame pointer; only use on leaf functions */
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define optimizespeed __attribute__((__optimize__(3)))
#else
#define optimizespeed
#endif
#endif

#ifndef unrollloops
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define unrollloops __attribute__((__optimize__("unroll-loops")))
#else
#define unrollloops
#endif
#endif

#ifndef _Microarchitecture
#if (__has_attribute(__target__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
#define _Microarchitecture(march) __attribute__((__target__(march)))
#else
#define _Microarchitecture(march)
#endif
#endif

#ifdef __x86_64__
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
#else
#define nocallersavedregisters "need modern compiler"
#endif
#else
#define nocallersavedregisters
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_address__))
#define dontasan __attribute__((__no_sanitize_address__))
#else
#define dontasan
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_undefined__))
#define dontubsan __attribute__((__no_sanitize_undefined__))
#else
#define dontubsan
#endif

#ifdef __x86_64__
#define notpossible          \
  do {                       \
    __asm__("nop\n\t"        \
            "ud2\n\t"        \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#elif defined(__aarch64__)
#define notpossible          \
  do {                       \
    __asm__("udf\t#0\n\t"    \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#else
#define notpossible __builtin_trap()
#endif

#define donothing \
  do {            \
  } while (0)

#define textstartup _Section(".text.startup")
#define textexit    _Section(".text.exit")
#define textreal    _Section(".text.real")
#define texthead    _Section(".text.head")
#define textwindows _Section(".text.windows")
#define antiquity   _Section(".text.antiquity")

#ifdef __llvm__
#define __builtin_ia32_movntdq(x, y) (*(x) = (y))
#endif

#ifndef _Section
#define _Section(s) __attribute__((__section__(s)))
#endif

#ifndef __llvm__
#pragma GCC diagnostic ignored "-Wformat=0" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
#pragma GCC diagnostic warning "-Wunknown-pragmas"
#else
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wconstant-logical-operand" /* what */
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wstring-plus-int"       /* features 4 losers */
#pragma GCC diagnostic ignored "-Wkeyword-compat"        /* c++ upgrade */
#pragma GCC diagnostic ignored "-Wuser-defined-literals" /* reserved for me */
#endif

#pragma GCC diagnostic ignored "-Wformat-extra-args"     /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wunused-function"       /* contradicts dce */
#pragma GCC diagnostic ignored "-Wunused-const-variable" /* sooo ridiculous */
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */
#endif

#ifdef __x86_64__
#define DebugBreak() __asm__("int3")
#elif defined(__aarch64__)
#define DebugBreak() __asm__("brk\t#0x666")
#else
#define DebugBreak() __builtin_trap()
#endif

#ifdef __aarch64__
/* raise sigill (not sigtrap) like x86 does */
#define __builtin_trap()     \
  do {                       \
    __asm__("udf\t#0x666");  \
    __builtin_unreachable(); \
  } while (0)
#endif

#endif /* _COSMO_SOURCE */

#define __veil(CONSTRAINT, EXPRESSION)                               \
  __extension__({                                                    \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                 \
    __asm__("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                     \
  })

#define __conceal(CONSTRAINT, EXPRESSION)                                     \
  __extension__({                                                             \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                          \
    __asm__ volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                              \
  })

#define __expropriate(EXPRESSION)                      \
  __extension__({                                      \
    __asm__ volatile("" ::"g"(EXPRESSION) : "memory"); \
    0;                                                 \
  })

#if !defined(__APPLE__) && defined(__x86_64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
#elif defined(__aarch64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
#else
#define __yoink(SYMBOL) (void)0
#endif

#if !defined(__APPLE__) && defined(__x86_64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#elif defined(__aarch64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
#else
#define __static_yoink(SYMBOLSTR)
#endif

#if !defined(IM_FEELING_NAUGHTY)
#define __static_yoink_source(PATH) __static_yoink(PATH)
#else
#define __static_yoink_source(PATH)
#endif

#define __weak_reference(sym, alias) __weak_reference_impl(sym, alias)
#define __weak_reference_impl(sym, alias)  \
  __asm__(".weak\t" #alias "\n\t"          \
          ".equ\t" #alias ", " #sym "\n\t" \
          ".type\t" #alias ",@notype")

#ifndef __chibicc__
#define __strong_reference(sym, alias) \
  extern __typeof(sym) alias __attribute__((__alias__(#sym)))
#else
#define __strong_reference(sym, alias) __weak_reference(sym, alias)
#endif

#if defined(__GNUC__) || defined(__llvm__)
#define __funline \
  extern __inline \
      __attribute__((__gnu_inline__, __always_inline__, __artificial__))
#else
#define __funline static inline
#endif

#if defined(__x86_64__) && (defined(__GNUC__) || defined(__llvm__)) && \
    !defined(__chibicc__) && defined(__OPTIMIZE__)
#define __target_clones(x) __attribute__((__target_clones__(x ",default")))
#else
#define __target_clones(x)
#endif

#if !defined(TINY) && !defined(__AVX__)
#define __vex __target_clones("avx")
#else
#define __vex
#endif

#define __notice(sym, str)                                                   \
  __attribute__((__section__(".notice"), __aligned__(1))) const char sym[] = \
      "\n\n" str

#define MACHINE_CODE_ANALYSIS_BEGIN_
#define MACHINE_CODE_ANALYSIS_END_
#else
#define const
#define volatile
#endif
#ifdef __cplusplus


/*!BEGIN libc/integral/cxx.inc */

#define COSMOPOLITAN_CXX_START_ namespace cosmo {
#define COSMOPOLITAN_CXX_END_   }
#define COSMOPOLITAN_CXX_USING_ using namespace cosmo;
#define COSMOPOLITAN_C_START_   extern "C" {
#define COSMOPOLITAN_C_END_     }

#if !defined(__builtin_types_compatible_p) && !__has_builtin(types_compatible_p)
#if 0 /* todo jart whyyyy */


/*!BEGIN libc/integral/cxxtypescompat.inc */

#define NAME __cxx_types_compatible
#define QUALIFIED(Q1, Q2)       \
  template <class _T, class _U> \
  struct NAME<_T Q1, _U Q2> : NAME<_T, _U> {}

template <class, class>
struct NAME {
  enum { _value = 0 };
};

template <class _T>
struct NAME<_T, _T> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[], _T[N]> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[N], _T[]> {
  enum { _value = 1 };
};

QUALIFIED(const volatile, );
QUALIFIED(const volatile, const);
QUALIFIED(const, const volatile);
QUALIFIED(volatile, const volatile);
QUALIFIED(const volatile, volatile);
QUALIFIED(const, volatile);
QUALIFIED(volatile, const);
QUALIFIED(, const);
QUALIFIED(const, );
QUALIFIED(, volatile);
QUALIFIED(volatile, );

#undef QUALIFIED
#undef NAME
#define __builtin_types_compatible_p(A, B) \
  (__cxx_types_compatible<A, B>::_value)
#else
#define __builtin_types_compatible_p(A, B) 0
#endif
#endif

#if !defined(__builtin_choose_expr) && !__has_builtin(choose_expr)
#if 1
template <bool _P, typename _T, typename _U>
struct __cxx_choose_expr {
  __cxx_choose_expr(_T _a, _U _b) : _value(_a) {
  }
  const _T _value;
};
template <typename _T, typename _U>
struct __cxx_choose_expr<false, _T, _U> {
  __cxx_choose_expr(_T _a, _U _b) : _value(_b) {
  }
  const _U _value;
};
#define __builtin_choose_expr(X, A, B) \
  (__cxx_choose_expr<X, typeof(A), typeof(B)>(A, B)._value)
#else
#define __builtin_choose_expr(X, A, B) ((X) ? (A) : (B))
#endif
#endif

#ifdef __aarch64__
/* todo jart whyyyy */
#define _Float16 __fp16
#endif
#endif
#endif


/*!BEGIN ape/ape.h */

#define COSMOPOLITAN_APE_APE_H_

#define APE_VERSION_MAJOR 1
#define APE_VERSION_MINOR 10
#define APE_VERSION_STR   APE_VERSION_STR_(APE_VERSION_MAJOR, APE_VERSION_MINOR)
#define APE_VERSION_NOTE  APE_VERSION_NOTE_(APE_VERSION_MAJOR, APE_VERSION_MINOR)

#define APE_VERSION_STR__(x, y) #x "." #y
#define APE_VERSION_STR_(x, y)  APE_VERSION_STR__(x, y)
#define APE_VERSION_NOTE_(x, y) (100000000 * (x) + 1000000 * (y))



/*!BEGIN ape/relocations.h */

#define COSMOPOLITAN_APE_RELOCATIONS_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ αcτµαlly pδrταblε εxεcµταblε § relocations                                   │
╚──────────────────────────────────────────────────────────────────────────────╝
  One of the things αcτµαlly pδrταblε εxεcµταblε does a good job
  abstracting, is how a program needs to exist at three addresses
  simultaneously during the early stages of the loading process.

  By default, the linker calculates all symbols using virtual addresses.
  In some cases it's necessary to use addend macros that change virtual
  addresses into the other two types: physical and real. */

#define IMAGE_BASE_REAL 0x2000

#ifndef IMAGE_BASE_VIRTUAL
#define IMAGE_BASE_VIRTUAL 0x400000
#endif

#ifndef IMAGE_BASE_PHYSICAL
#define IMAGE_BASE_PHYSICAL 0x100000
#endif

/**
 * Returns Relative Virtual Address.
 */
#define RVA(x) ((x) - (IMAGE_BASE_VIRTUAL))

/**
 * Adjusts virtual address so it's relative to load address.
 */
#define PHYSICAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_PHYSICAL))

/**
 * Makes high-entropy read-only addresses relocatable in real mode.
 */
#define REAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_REAL))

#if IMAGE_BASE_VIRTUAL % 0x1000 != 0
#error "IMAGE_BASE_VIRTUAL must be 4kb aligned"
#endif
#if IMAGE_BASE_PHYSICAL % 0x1000 != 0
#error "IMAGE_BASE_PHYSICAL must be 4kb aligned"
#endif
#if IMAGE_BASE_REAL % 0x1000 != 0
#error "IMAGE_BASE_REAL must be 4kb aligned"
#endif



/*!BEGIN libc/ar.h */

#define COSMOPOLITAN_LIBC_AR_H_
COSMOPOLITAN_C_START_

#define ARMAG  "!<arch>\n"
#define SARMAG 8
#define ARFMAG "`\n"

struct ar_hdr {
  char ar_name[16];
  char ar_date[12];
  char ar_uid[6];
  char ar_gid[6];
  char ar_mode[8];
  char ar_size[10];
  char ar_fmag[2];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/assert.h */

#undef _ASSERT_H
#undef assert
#ifdef _COSMO_SOURCE
#undef unassert
#undef npassert
#ifndef NDEBUG
#undef __assert_macro
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

#define _ASSERT_H
COSMOPOLITAN_C_START_

void __assert_fail(const char *, const char *, int) libcesque;
void unassert(const char *, const char *, int) libcesque;

#ifdef NDEBUG
#define assert(x) ((void)0)
#else
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0)))
#endif

#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
#undef static_assert
#define static_assert _Static_assert
#endif

#ifdef _COSMO_SOURCE
#ifndef NDEBUG
#define unassert(x) __assert_macro(x, #x)
#define npassert(x) __assert_macro(x, #x)
#define __assert_macro(x, s)             \
  ({                                     \
    if (__builtin_expect(!(x), 0)) {     \
      (unassert)(s, __FILE__, __LINE__); \
      __asm__("nop");                    \
      __builtin_unreachable();           \
    }                                    \
    (void)0;                             \
  })
#else
#define npassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_trap();              \
    }                                \
    (void)0;                         \
  })
#define unassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_unreachable();       \
    }                                \
    (void)0;                         \
  })
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/atomic.h */

#define COSMOPOLITAN_LIBC_ATOMIC_H_

#define atomic_bool           _Atomic(_Bool)
#define atomic_bool32         _Atomic(__INT32_TYPE__)
#define atomic_char           _Atomic(char)
#define atomic_schar          _Atomic(signed char)
#define atomic_uchar          _Atomic(unsigned char)
#define atomic_short          _Atomic(short)
#define atomic_ushort         _Atomic(unsigned short)
#define atomic_int            _Atomic(int)
#define atomic_uint           _Atomic(unsigned int)
#define atomic_long           _Atomic(long)
#define atomic_ulong          _Atomic(unsigned long)
#define atomic_llong          _Atomic(long long)
#define atomic_ullong         _Atomic(unsigned long long)
#define atomic_char16_t       _Atomic(__CHAR16_TYPE__)
#define atomic_char32_t       _Atomic(__CHAR32_TYPE__)
#define atomic_wchar_t        _Atomic(__WCHAR_TYPE__)
#define atomic_intptr_t       _Atomic(__INTPTR_TYPE__)
#define atomic_uintptr_t      _Atomic(__UINTPTR_TYPE__)
#define atomic_size_t         _Atomic(__SIZE_TYPE__)
#define atomic_ptrdiff_t      _Atomic(__PTRDIFF_TYPE__)
#define atomic_int_fast8_t    _Atomic(__INT_FAST8_TYPE__)
#define atomic_uint_fast8_t   _Atomic(__UINT_FAST8_TYPE__)
#define atomic_int_fast16_t   _Atomic(__INT_FAST16_TYPE__)
#define atomic_uint_fast16_t  _Atomic(__UINT_FAST16_TYPE__)
#define atomic_int_fast32_t   _Atomic(__INT_FAST32_TYPE__)
#define atomic_uint_fast32_t  _Atomic(__UINT_FAST32_TYPE__)
#define atomic_int_fast64_t   _Atomic(__INT_FAST64_TYPE__)
#define atomic_uint_fast64_t  _Atomic(__UINT_FAST64_TYPE__)
#define atomic_int_least8_t   _Atomic(__INT_LEAST8_TYPE__)
#define atomic_uint_least8_t  _Atomic(__UINT_LEAST8_TYPE__)
#define atomic_int_least16_t  _Atomic(__INT_LEAST16_TYPE__)
#define atomic_uint_least16_t _Atomic(__UINT_LEAST16_TYPE__)
#define atomic_int_least32_t  _Atomic(__INT_LEAST32_TYPE__)
#define atomic_uint_least32_t _Atomic(__UINT_LEAST32_TYPE__)
#define atomic_int_least64_t  _Atomic(__INT_LEAST64_TYPE__)
#define atomic_uint_least64_t _Atomic(__UINT_LEAST64_TYPE__)

#ifdef __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_BOOL_LOCK_FREE     __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __CLANG_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __CLANG_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __CLANG_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __CLANG_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __CLANG_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __CLANG_ATOMIC_POINTER_LOCK_FREE
#else
#define ATOMIC_BOOL_LOCK_FREE     __GCC_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __GCC_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __GCC_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __GCC_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __GCC_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __GCC_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __GCC_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __GCC_ATOMIC_POINTER_LOCK_FREE
#endif



/*!BEGIN libc/complex.h */

#define COSMOPOLITAN_LIBC_COMPLEX_H_
COSMOPOLITAN_C_START_
#if __STDC_VERSION__ + 0 >= 201112 && !defined(__STDC_NO_COMPLEX__)

#define complex   _Complex
#define imaginary _Imaginary

double cabs(complex double) libcesque;
double carg(complex double) libcesque;
double cimag(complex double) libcesque;
double creal(complex double) libcesque;

float cabsf(complex float) libcesque;
float cargf(complex float) libcesque;
float cimagf(complex float) libcesque;
float crealf(complex float) libcesque;

long double cabsl(complex long double) libcesque;
long double cargl(complex long double) libcesque;
long double cimagl(complex long double) libcesque;
long double creall(complex long double) libcesque;

complex double cacos(complex double) libcesque;
complex double cacosh(complex double) libcesque;
complex double casin(complex double) libcesque;
complex double casinh(complex double) libcesque;
complex double catan(complex double) libcesque;
complex double catanh(complex double) libcesque;
complex double ccos(complex double) libcesque;
complex double ccosh(complex double) libcesque;
complex double cexp(complex double) libcesque;
complex double cexp2(complex double) libcesque;
complex double clog(complex double) libcesque;
complex double conj(complex double) libcesque;
complex double cpow(complex double, complex double) libcesque;
complex double cproj(complex double) libcesque;
complex double csin(complex double) libcesque;
complex double csinh(complex double) libcesque;
complex double csqrt(complex double) libcesque;
complex double ctan(complex double) libcesque;
complex double ctanh(complex double) libcesque;

complex float cacosf(complex float) libcesque;
complex float cacoshf(complex float) libcesque;
complex float casinf(complex float) libcesque;
complex float casinhf(complex float) libcesque;
complex float catanf(complex float) libcesque;
complex float catanhf(complex float) libcesque;
complex float ccosf(complex float) libcesque;
complex float ccoshf(complex float) libcesque;
complex float cexpf(complex float) libcesque;
complex float cexp2f(complex float) libcesque;
complex float clogf(complex float) libcesque;
complex float conjf(complex float) libcesque;
complex float cpowf(complex float, complex float) libcesque;
complex float cprojf(complex float) libcesque;
complex float csinf(complex float) libcesque;
complex float csinhf(complex float) libcesque;
complex float csqrtf(complex float) libcesque;
complex float ctanf(complex float) libcesque;
complex float ctanhf(complex float) libcesque;

complex long double cprojl(complex long double) libcesque;
complex long double csinhl(complex long double) libcesque;
complex long double csinl(complex long double) libcesque;
complex long double csqrtl(complex long double) libcesque;
complex long double ctanhl(complex long double) libcesque;
complex long double ctanl(complex long double) libcesque;
complex long double cacoshl(complex long double) libcesque;
complex long double cacosl(complex long double) libcesque;
complex long double casinhl(complex long double) libcesque;
complex long double casinl(complex long double) libcesque;
complex long double catanhl(complex long double) libcesque;
complex long double catanl(complex long double) libcesque;
complex long double ccoshl(complex long double) libcesque;
complex long double ccosl(complex long double) libcesque;
complex long double cexpl(complex long double) libcesque;
complex long double cexp2l(complex long double) libcesque;
complex long double clogl(complex long double) libcesque;
complex long double conjl(complex long double) libcesque;
complex long double cpowl(complex long double, complex long double) libcesque;

#ifndef __cplusplus
#define __CIMAG(x, t)   \
  (+(union {            \
      _Complex t __z;   \
      t __xy[2];        \
    }){(_Complex t)(x)} \
        .__xy[1])
#define creal(x)  ((double)(x))
#define crealf(x) ((float)(x))
#define creall(x) ((long double)(x))
#define cimag(x)  __CIMAG(x, double)
#define cimagf(x) __CIMAG(x, float)
#define cimagl(x) __CIMAG(x, long double)
#endif

#ifdef __GNUC__
#define _Complex_I (__extension__(0.0f + 1.0fi))
#else
#define _Complex_I (0.0f + 1.0fi)
#endif

#ifdef _Imaginary_I
#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I * (t)(y))
#elif defined(__clang__)
#define __CMPLX(x, y, t) (+(_Complex t){(t)(x), (t)(y)})
#else
#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y)))
#endif

#define CMPLX(x, y)  __CMPLX(x, y, double)
#define CMPLXF(x, y) __CMPLX(x, y, float)
#define CMPLXL(x, y) __CMPLX(x, y, long double)

#endif /* C11 */
COSMOPOLITAN_C_END_


/*!BEGIN libc/cosmo.h */

#define COSMOPOLITAN_LIBC_COSMO_H_
COSMOPOLITAN_C_START_

errno_t cosmo_once(_Atomic(uint32_t) *, void (*)(void));
int systemvpe(const char *, char *const[], char *const[]) libcesque;
char *GetProgramExecutableName(void);
void unleaf(void);
int __demangle(char *, const char *, size_t);
int __is_mangled(const char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/cxxabi.h */

#define _CXXABI_H
COSMOPOLITAN_C_START_

#ifdef __cplusplus
namespace __cxxabiv1 {
#endif /* __cplusplus */

char *__cxa_demangle(const char *, char *, size_t *, int *);
int __cxa_atexit(void (*)(void *), void *, void *) paramsnonnull((1)) dontthrow;
int __cxa_thread_atexit(void (*)(void *), void *, void *) dontthrow;
void __cxa_finalize(void *);

#ifdef __cplusplus
} /* namespace __cxxabiv1 */
#endif /* __cplusplus */

COSMOPOLITAN_C_END_


/*!BEGIN libc/dce.h */

#ifndef COSMOPOLITAN_LIBC_DCE_H_
#define COSMOPOLITAN_LIBC_DCE_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § autotune » dead code elimination                              │
╚─────────────────────────────────────────────────────────────────────────────*/

#ifndef SUPPORT_VECTOR
#ifdef __x86_64__
/**
 * Supported Platforms Tuning Knob (Runtime & Compile-Time)
 * Tuning this bitmask will remove platform polyfills at compile-time.
 */
#define SUPPORT_VECTOR 255
#else
#define SUPPORT_VECTOR (_HOSTLINUX | _HOSTXNU | _HOSTFREEBSD)
#endif
#endif

#define _HOSTLINUX   1
#define _HOSTMETAL   2
#define _HOSTWINDOWS 4
#define _HOSTXNU     8
#define _HOSTOPENBSD 16
#define _HOSTFREEBSD 32
#define _HOSTNETBSD  64

#ifdef NDEBUG
#define NoDebug() 1
#else
#define NoDebug() 0
#endif

#ifdef MODE_DBG
#define IsModeDbg() 1
#else
#define IsModeDbg() 0
#endif

#ifdef TRUSTWORTHY
#define IsTrustworthy() 1
#else
#define IsTrustworthy() 0
#endif

#ifdef TINY
#define IsTiny() 1
#else
#define IsTiny() 0
#endif

#ifdef __OPTIMIZE__
#define IsOptimized() 1
#else
#define IsOptimized() 0
#endif

#ifdef __SANITIZE_ADDRESS__
#define IsAsan() 1
#else
#define IsAsan() 0
#endif

#ifdef __aarch64__
#define IsAarch64()    1
#define IsXnuSilicon() IsXnu()
#else
#define IsAarch64()    0
#define IsXnuSilicon() 0
#endif

#if defined(__x86_64__)
#define _ARCH_NAME "amd64"
#elif defined(__aarch64__)
#define _ARCH_NAME "arm64"
#elif defined(__powerpc64__)
#define _ARCH_NAME "ppc64"
#elif defined(__s390x__)
#define _ARCH_NAME "s390x"
#elif defined(__riscv)
#define _ARCH_NAME "riscv"
#endif

#define SupportsLinux()   ((SUPPORT_VECTOR & _HOSTLINUX) == _HOSTLINUX)
#define SupportsMetal()   ((SUPPORT_VECTOR & _HOSTMETAL) == _HOSTMETAL)
#define SupportsWindows() ((SUPPORT_VECTOR & _HOSTWINDOWS) == _HOSTWINDOWS)
#define SupportsXnu()     ((SUPPORT_VECTOR & _HOSTXNU) == _HOSTXNU)
#define SupportsFreebsd() ((SUPPORT_VECTOR & _HOSTFREEBSD) == _HOSTFREEBSD)
#define SupportsOpenbsd() ((SUPPORT_VECTOR & _HOSTOPENBSD) == _HOSTOPENBSD)
#define SupportsNetbsd()  ((SUPPORT_VECTOR & _HOSTNETBSD) == _HOSTNETBSD)
#define SupportsBsd() \
  (!!(SUPPORT_VECTOR & (_HOSTXNU | _HOSTFREEBSD | _HOSTOPENBSD | _HOSTNETBSD)))
#define SupportsSystemv() \
  (!!(SUPPORT_VECTOR &    \
      (_HOSTLINUX | _HOSTXNU | _HOSTOPENBSD | _HOSTFREEBSD | _HOSTNETBSD)))

#ifndef __ASSEMBLER__
#define IsLinux()   (SupportsLinux() && (__hostos & _HOSTLINUX))
#define IsMetal()   (SupportsMetal() && (__hostos & _HOSTMETAL))
#define IsWindows() (SupportsWindows() && (__hostos & _HOSTWINDOWS))
#define IsXnu()     (SupportsXnu() && (__hostos & _HOSTXNU))
#define IsFreebsd() (SupportsFreebsd() && (__hostos & _HOSTFREEBSD))
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & _HOSTOPENBSD))
#define IsNetbsd()  (SupportsNetbsd() && (__hostos & _HOSTNETBSD))
#define IsBsd()     (IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd())
#else
/* clang-format off */
#define IsLinux() $_HOSTLINUX,__hostos(%rip)
#define IsMetal() $_HOSTMETAL,__hostos(%rip)
#define IsWindows() $_HOSTWINDOWS,__hostos(%rip)
#define IsBsd() $_HOSTXNU|_HOSTFREEBSD|_HOSTOPENBSD|_HOSTNETBSD,__hostos(%rip)
#define IsXnu() $_HOSTXNU,__hostos(%rip)
#define IsFreebsd() $_HOSTFREEBSD,__hostos(%rip)
#define IsOpenbsd() $_HOSTOPENBSD,__hostos(%rip)
#define IsNetbsd() $_HOSTNETBSD,__hostos(%rip)
/* clang-format on */
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __hostos;

int IsQemuUser(void);

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_DCE_H_ */


/*!BEGIN libc/errno.h */

#define COSMOPOLITAN_LIBC_ERRNO_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview System Five error codes.
 *
 * This file defines the `errno` global variable. When system calls
 * (e.g. read(), write(), etc.) fail they return -1 to indicate the
 * failure, and that is *the only* error return value. System calls
 * also update `errno` too whenever -1 is returned (otherwise errno
 * isn't changed) to be a non-zero value holding one of the numbers
 * below, in order to indicate why the system call failed.
 *
 * There is only one exception to the above rule; some system calls
 * are documented with the `@returnserrno` tag, which means they'll
 * return the error number rather than stuffing it in a global. You
 * can usually spot these system calls easily since most of them'll
 * have names like `posix_foo()` or `pthread_bar()`.
 *
 * @see libc/sysv/consts.sh for assigned numbers
 * @see libc/sysv/dos2errno.sh for multimapped numbers
 */

#if defined(__GNUC__) && defined(__aarch64__) && !defined(__cplusplus)
/* this header is included by 700+ files; therefore we */
/* hand-roll &__get_tls()->tib_errno to avoid #include */
/* cosmopolitan uses x28 as the tls register b/c apple */
#define errno                                      \
  (*__extension__({                                \
    errno_t *__ep;                                 \
    __asm__("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
    __ep;                                          \
  }))
#else
#define errno (*__errno_location())
#endif

/**
 * System call unavailable.
 * @note kNtErrorInvalidFunction on NT
 */
extern const errno_t ENOSYS;

/**
 * Operation not permitted.
 * @note kNtErrorInvalidAccess on NT
 */
extern const errno_t EPERM;

/**
 * No such file or directory.
 */
extern const errno_t ENOENT;

/**
 * No such process.
 */
extern const errno_t ESRCH;

/**
 * The greatest of all errnos.
 */
extern const errno_t EINTR;

/**
 * Unix consensus.
 */
extern const errno_t EIO;

/**
 * No such device or address.
 */
extern const errno_t ENXIO;

/**
 * Argument list too long.
 */
extern const errno_t E2BIG;

/**
 * Exec format error.
 */
extern const errno_t ENOEXEC;

/**
 * Bad file descriptor.
 */
extern const errno_t EBADF;

/**
 * No child process.
 */
extern const errno_t ECHILD;

/**
 * Resource temporarily unavailable (e.g. SO_RCVTIMEO expired, too many
 * processes, too much memory locked, read or write with O_NONBLOCK needs
 * polling, etc.).
 */
extern const errno_t EAGAIN;

/**
 * We require more vespene gas.
 */
extern const errno_t ENOMEM;

/**
 * Permission denied.
 */
extern const errno_t EACCES;

/**
 * Pointer passed to system call that would otherwise segfault.
 */
extern const errno_t EFAULT;

/**
 * Block device required.
 */
extern const errno_t ENOTBLK;

/**
 * Device or resource busy.
 */
extern const errno_t EBUSY;

/**
 * File exists.
 */
extern const errno_t EEXIST;

/**
 * Improper link.
 */
extern const errno_t EXDEV;

/**
 * No such device.
 */
extern const errno_t ENODEV;

/**
 * Not a directory.
 */
extern const errno_t ENOTDIR;

/**
 * Is a a directory.
 */
extern const errno_t EISDIR;

/**
 * Invalid argument.
 */
extern const errno_t EINVAL;

/**
 * Too many open files in system.
 */
extern const errno_t ENFILE;

/**
 * Too many open files.
 */
extern const errno_t EMFILE;

/**
 * Inappropriate i/o control operation.
 */
extern const errno_t ENOTTY;

/**
 * Won't open executable that's executing in write mode.
 */
extern const errno_t ETXTBSY;

/**
 * File too large.
 */
extern const errno_t EFBIG;

/**
 * No space left on device.
 */
extern const errno_t ENOSPC;

/**
 * Disk quota exceeded.
 */
extern const errno_t EDQUOT;

/**
 * Invalid seek.
 */
extern const errno_t ESPIPE;

/**
 * Read-only filesystem.
 */
extern const errno_t EROFS;

/**
 * Too many links.
 */
extern const errno_t EMLINK;

/**
 * Broken pipe.
 */
extern const errno_t EPIPE;

/**
 * Mathematics argument out of domain of function.
 */
extern const errno_t EDOM;

/**
 * Result too large.
 */
extern const errno_t ERANGE;

/**
 * Resource deadlock avoided.
 */
extern const errno_t EDEADLK;

/**
 * Filename too long.
 */
extern const errno_t ENAMETOOLONG;

/**
 * No locks available.
 */
extern const errno_t ENOLCK;

/**
 * Directory not empty.
 */
extern const errno_t ENOTEMPTY;

/**
 * Too many levels of symbolic links.
 */
extern const errno_t ELOOP;

/**
 * No message error.
 */
extern const errno_t ENOMSG;

/**
 * Identifier removed.
 */
extern const errno_t EIDRM;

/**
 * Timer expired.
 */
extern const errno_t ETIME;

/**
 * Protocol error.
 */
extern const errno_t EPROTO;

/**
 * Overflow error.
 */
extern const errno_t EOVERFLOW;

/**
 * Unicode decoding error.
 */
extern const errno_t EILSEQ;

/**
 * Too many users.
 */
extern const errno_t EUSERS;

/**
 * Not a socket.
 */
extern const errno_t ENOTSOCK;

/**
 * Destination address required.
 */
extern const errno_t EDESTADDRREQ;

/**
 * Message too long.
 */
extern const errno_t EMSGSIZE;

/**
 * Protocol wrong type for socket.
 */
extern const errno_t EPROTOTYPE;

/**
 * Protocol not available.
 */
extern const errno_t ENOPROTOOPT;

/**
 * Protocol not supported.
 */
extern const errno_t EPROTONOSUPPORT;

/**
 * Socket type not supported.
 */
extern const errno_t ESOCKTNOSUPPORT;

/**
 * Operation not supported.
 */
extern const errno_t ENOTSUP;

/**
 * Socket operation not supported.
 */
extern const errno_t EOPNOTSUPP;

/**
 * Protocol family not supported.
 */
extern const errno_t EPFNOSUPPORT;

/**
 * Address family not supported.
 */
extern const errno_t EAFNOSUPPORT;

/**
 * Address already in use.
 */
extern const errno_t EADDRINUSE;

/**
 * Address not available.
 */
extern const errno_t EADDRNOTAVAIL;

/**
 * Network is down.
 */
extern const errno_t ENETDOWN;

/**
 * Host is unreachable.
 */
extern const errno_t ENETUNREACH;

/**
 * Connection reset by network.
 */
extern const errno_t ENETRESET;

/**
 * Connection reset before accept.
 */
extern const errno_t ECONNABORTED;

/**
 * Connection reset by client.
 */
extern const errno_t ECONNRESET;

/**
 * No buffer space available.
 */
extern const errno_t ENOBUFS;

/**
 * Socket is connected.
 */
extern const errno_t EISCONN;

/**
 * Socket is not connected.
 */
extern const errno_t ENOTCONN;

/**
 * Cannot send after transport endpoint shutdown.
 */
extern const errno_t ESHUTDOWN;

/**
 * Too many references: cannot splice.
 */
extern const errno_t ETOOMANYREFS;

/**
 * Connection timed out.
 */
extern const errno_t ETIMEDOUT;

/**
 * Connection refused error.
 */
extern const errno_t ECONNREFUSED;

/**
 * Host down error.
 */
extern const errno_t EHOSTDOWN;

/**
 * Host unreachable error.
 */
extern const errno_t EHOSTUNREACH;

/**
 * Connection already in progress.
 */
extern const errno_t EALREADY;

/**
 * Operation already in progress.
 */
extern const errno_t EINPROGRESS;

/**
 * Stale error.
 */
extern const errno_t ESTALE;

/**
 * Remote error.
 */
extern const errno_t EREMOTE;

/**
 * Bad message.
 */
extern const errno_t EBADMSG;

/**
 * Operation canceled.
 */
extern const errno_t ECANCELED;

/**
 * Owner died.
 */
extern const errno_t EOWNERDEAD;

/**
 * State not recoverable.
 */
extern const errno_t ENOTRECOVERABLE;

/**
 * No network.
 */
extern const errno_t ENONET;

/**
 * Please restart syscall.
 */
extern const errno_t ERESTART;

/**
 * Out of streams resources.
 */
extern const errno_t ENOSR;

/**
 * No string.
 */
extern const errno_t ENOSTR;

/**
 * No data.
 */
extern const errno_t ENODATA;

/**
 * Multihop attempted.
 */
extern const errno_t EMULTIHOP;

/**
 * Link severed.
 */
extern const errno_t ENOLINK;

/**
 * No medium found.
 */
extern const errno_t ENOMEDIUM;

/**
 * Wrong medium type.
 */
extern const errno_t EMEDIUMTYPE;

/**
 * Inappropriate file type or format.
 */
extern const errno_t EFTYPE;

extern const errno_t EAUTH;
extern const errno_t EBADARCH;
extern const errno_t EBADEXEC;
extern const errno_t EBADMACHO;
extern const errno_t EBADRPC;
extern const errno_t EDEVERR;
extern const errno_t ENEEDAUTH;
extern const errno_t ENOATTR;
extern const errno_t ENOPOLICY;
extern const errno_t EPROCLIM;
extern const errno_t EPROCUNAVAIL;
extern const errno_t EPROGMISMATCH;
extern const errno_t EPROGUNAVAIL;
extern const errno_t EPWROFF;
extern const errno_t ERPCMISMATCH;
extern const errno_t ESHLIBVERS;
extern const errno_t EADV;
extern const errno_t EBADE;
extern const errno_t EBADFD;
extern const errno_t EBADR;
extern const errno_t EBADRQC;
extern const errno_t EBADSLT;
extern const errno_t ECHRNG;
extern const errno_t ECOMM;
extern const errno_t EDOTDOT;
extern const errno_t EHWPOISON;
extern const errno_t EISNAM;
extern const errno_t EKEYEXPIRED;
extern const errno_t EKEYREJECTED;
extern const errno_t EKEYREVOKED;
extern const errno_t EL2HLT;
extern const errno_t EL2NSYNC;
extern const errno_t EL3HLT;
extern const errno_t EL3RST;
extern const errno_t ELIBACC;
extern const errno_t ELIBBAD;
extern const errno_t ELIBEXEC;
extern const errno_t ELIBMAX;
extern const errno_t ELIBSCN;
extern const errno_t ELNRNG;
extern const errno_t ENAVAIL;
extern const errno_t ENOANO;
extern const errno_t ENOCSI;
extern const errno_t ENOKEY;
extern const errno_t ENOPKG;
extern const errno_t ENOTNAM;
extern const errno_t ENOTUNIQ;
extern const errno_t EREMCHG;
extern const errno_t EREMOTEIO;
extern const errno_t ERFKILL;
extern const errno_t ESRMNT;
extern const errno_t ESTRPIPE;
extern const errno_t EUCLEAN;
extern const errno_t EUNATCH;
extern const errno_t EXFULL;

#define E2BIG           E2BIG
#define EACCES          EACCES
#define EADDRINUSE      EADDRINUSE
#define EADDRNOTAVAIL   EADDRNOTAVAIL
#define EAFNOSUPPORT    EAFNOSUPPORT
#define EAGAIN          EAGAIN
#define EALREADY        EALREADY
#define EBADF           EBADF
#define EBADMSG         EBADMSG
#define EBUSY           EBUSY
#define ECANCELED       ECANCELED
#define ECHILD          ECHILD
#define ECONNABORTED    ECONNABORTED
#define ECONNREFUSED    ECONNREFUSED
#define ECONNRESET      ECONNRESET
#define EDEADLK         EDEADLK
#define EDESTADDRREQ    EDESTADDRREQ
#define EDOM            EDOM
#define EDQUOT          EDQUOT
#define EEXIST          EEXIST
#define EFAULT          EFAULT
#define EFBIG           EFBIG
#define EFTYPE          EFTYPE
#define EHOSTDOWN       EHOSTDOWN
#define EHOSTUNREACH    EHOSTUNREACH
#define EIDRM           EIDRM
#define EILSEQ          EILSEQ
#define EINPROGRESS     EINPROGRESS
#define EINTR           EINTR
#define EINVAL          EINVAL
#define EIO             EIO
#define EISCONN         EISCONN
#define EISDIR          EISDIR
#define ELOOP           ELOOP
#define EMEDIUMTYPE     EMEDIUMTYPE
#define EMFILE          EMFILE
#define EMLINK          EMLINK
#define EMSGSIZE        EMSGSIZE
#define EMULTIHOP       EMULTIHOP
#define ENAMETOOLONG    ENAMETOOLONG
#define ENETDOWN        ENETDOWN
#define ENETRESET       ENETRESET
#define ENETUNREACH     ENETUNREACH
#define ENFILE          ENFILE
#define ENOBUFS         ENOBUFS
#define ENODATA         ENODATA
#define ENODEV          ENODEV
#define ENOENT          ENOENT
#define ENOEXEC         ENOEXEC
#define ENOLCK          ENOLCK
#define ENOLINK         ENOLINK
#define ENOMEDIUM       ENOMEDIUM
#define ENOMEM          ENOMEM
#define ENOMSG          ENOMSG
#define ENONET          ENONET
#define ENOPROTOOPT     ENOPROTOOPT
#define ENOSPC          ENOSPC
#define ENOSR           ENOSR
#define ENOSTR          ENOSTR
#define ENOSYS          ENOSYS
#define ENOTBLK         ENOTBLK
#define ENOTCONN        ENOTCONN
#define ENOTDIR         ENOTDIR
#define ENOTEMPTY       ENOTEMPTY
#define ENOTRECOVERABLE ENOTRECOVERABLE
#define ENOTSOCK        ENOTSOCK
#define ENOTSUP         ENOTSUP
#define ENOTTY          ENOTTY
#define ENXIO           ENXIO
#define EOPNOTSUPP      EOPNOTSUPP
#define EOVERFLOW       EOVERFLOW
#define EOWNERDEAD      EOWNERDEAD
#define EPERM           EPERM
#define EPFNOSUPPORT    EPFNOSUPPORT
#define EPIPE           EPIPE
#define EPROTO          EPROTO
#define EPROTONOSUPPORT EPROTONOSUPPORT
#define EPROTOTYPE      EPROTOTYPE
#define ERANGE          ERANGE
#define EREMOTE         EREMOTE
#define ERESTART        ERESTART
#define EROFS           EROFS
#define ESHUTDOWN       ESHUTDOWN
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT
#define ESPIPE          ESPIPE
#define ESRCH           ESRCH
#define ESTALE          ESTALE
#define ETIME           ETIME
#define ETIMEDOUT       ETIMEDOUT
#define ETOOMANYREFS    ETOOMANYREFS
#define ETXTBSY         ETXTBSY
#define EUSERS          EUSERS
#define EWOULDBLOCK     EAGAIN
#define EXDEV           EXDEV

extern errno_t __errno;
errno_t *__errno_location(void) dontthrow pureconst;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
extern char *program_invocation_short_name;
extern char *program_invocation_name;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/inttypes.h */

#define COSMOPOLITAN_LIBC_INTTYPES_H_

typedef __INT_LEAST8_TYPE__ int_least8_t;
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
typedef __INT_LEAST16_TYPE__ int_least16_t;
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
typedef __INT_LEAST32_TYPE__ int_least32_t;
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
typedef __INT_LEAST64_TYPE__ int_least64_t;
typedef __UINT_LEAST64_TYPE__ uint_least64_t;

typedef __INT_FAST8_TYPE__ int_fast8_t;
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
typedef __INT_FAST16_TYPE__ int_fast16_t;
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
typedef __INT_FAST32_TYPE__ int_fast32_t;
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
typedef __INT_FAST64_TYPE__ int_fast64_t;
typedef __UINT_FAST64_TYPE__ uint_fast64_t;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define __PRI8 "hh"

#if __SIZEOF_INT__ == 2
#define __PRI16 ""
#elif __SIZEOF_SHORT__ == 2
#define __PRI16 "h"
#elif __SIZEOF_LONG__ == 2
#define __PRI16 "l"
#endif

#if __SIZEOF_INT__ == 4
#define __PRI32 ""
#elif __SIZEOF_LONG__ == 4
#define __PRI32 "l"
#elif __SIZEOF_LONG_LONG__ == 4
#define __PRI32 "ll"
#endif

#if __SIZEOF_INT__ == 8
#define __PRI64 ""
#elif __SIZEOF_LONG__ == 8
#define __PRI64 "l"
#elif __SIZEOF_LONG_LONG__ == 8
#define __PRI64 "ll"
#endif

#if __SIZEOF_INT__ == 16
#define __PRI128 ""
#elif __SIZEOF_LONG__ == 16
#define __PRI128 "l"
#elif __SIZEOF_LONG_LONG__ == 16
#define __PRI128 "ll"
#elif __SIZEOF_INTMAX__ == 16
#define __PRI128 "j"
#else
#define __PRI128 "jj"
#endif

#if __SIZEOF_POINTER__ == __SIZEOF_INT__
#define __PRIPTR ""
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG__
#define __PRIPTR "l"
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__
#define __PRIPTR "ll"
#endif

#if __INT_FAST16_WIDTH__ == 16
#define __PRIFAST16 "h"
#elif __INT_FAST16_WIDTH__ == 32
#define __PRIFAST16 ""
#else
#define __PRIFAST16 "l"
#endif

#if __INT_FAST32_WIDTH__ == 32
#define __PRIFAST32 ""
#else
#define __PRIFAST32 "l"
#endif

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » decimal                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRId8   __PRI8 "d"
#define PRId16  __PRI16 "d"
#define PRId32  __PRI32 "d"
#define PRId64  __PRI64 "d"
#define PRId128 __PRI128 "d"

#define PRIdLEAST8   __PRI8 "d"
#define PRIdLEAST16  __PRI16 "d"
#define PRIdLEAST32  __PRI32 "d"
#define PRIdLEAST64  __PRI64 "d"
#define PRIdLEAST128 __PRI128 "d"

#define PRIdFAST8   __PRI8 "d"
#define PRIdFAST16  __PRIFAST16 "d"
#define PRIdFAST32  __PRIFAST32 "d"
#define PRIdFAST64  __PRI64 "d"
#define PRIdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » unsigned decimal        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIu8   __PRI8 "u"
#define PRIu16  __PRI16 "u"
#define PRIu32  __PRI32 "u"
#define PRIu64  __PRI64 "u"
#define PRIu128 __PRI128 "u"

#define PRIuLEAST8   __PRI8 "u"
#define PRIuLEAST16  __PRI16 "u"
#define PRIuLEAST32  __PRI32 "u"
#define PRIuLEAST64  __PRI64 "u"
#define PRIuLEAST128 __PRI128 "u"

#define PRIuFAST8   __PRI8 "u"
#define PRIuFAST16  __PRIFAST16 "u"
#define PRIuFAST32  __PRIFAST32 "u"
#define PRIuFAST64  __PRI64 "u"
#define PRIuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » wut                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIi8   __PRI8 "i"
#define PRIi16  __PRI16 "i"
#define PRIi32  __PRI32 "i"
#define PRIi64  __PRI64 "i"
#define PRIi128 __PRI128 "i"

#define PRIiLEAST8   __PRI8 "i"
#define PRIiLEAST16  __PRI16 "i"
#define PRIiLEAST32  __PRI32 "i"
#define PRIiLEAST64  __PRI64 "i"
#define PRIiLEAST128 __PRI128 "i"

#define PRIiFAST8   __PRI8 "i"
#define PRIiFAST16  __PRIFAST16 "i"
#define PRIiFAST32  __PRIFAST32 "i"
#define PRIiFAST64  __PRI64 "i"
#define PRIiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » octal                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIo8   __PRI8 "o"
#define PRIo16  __PRI16 "o"
#define PRIo32  __PRI32 "o"
#define PRIo64  __PRI64 "o"
#define PRIo128 __PRI128 "o"

#define PRIoLEAST8   __PRI8 "o"
#define PRIoLEAST16  __PRI16 "o"
#define PRIoLEAST32  __PRI32 "o"
#define PRIoLEAST64  __PRI64 "o"
#define PRIoLEAST128 __PRI128 "o"

#define PRIoFAST8   __PRI8 "o"
#define PRIoFAST16  __PRIFAST16 "o"
#define PRIoFAST32  __PRIFAST32 "o"
#define PRIoFAST64  __PRI64 "o"
#define PRIoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » hexadecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIx8   __PRI8 "x"
#define PRIx16  __PRI16 "x"
#define PRIx32  __PRI32 "x"
#define PRIx64  __PRI64 "x"
#define PRIx128 __PRI128 "x"

#define PRIxLEAST8   __PRI8 "x"
#define PRIxLEAST16  __PRI16 "x"
#define PRIxLEAST32  __PRI32 "x"
#define PRIxLEAST64  __PRI64 "x"
#define PRIxLEAST128 __PRI128 "x"

#define PRIxFAST8   __PRI8 "x"
#define PRIxFAST16  __PRIFAST16 "x"
#define PRIxFAST32  __PRIFAST32 "x"
#define PRIxFAST64  __PRI64 "x"
#define PRIxFAST128 __PRI128 "x"

#define PRIX8   __PRI8 "X"
#define PRIX16  __PRI16 "X"
#define PRIX32  __PRI32 "X"
#define PRIX64  __PRI64 "X"
#define PRIX128 __PRI128 "X"

#define PRIXLEAST8   __PRI8 "X"
#define PRIXLEAST16  __PRI16 "X"
#define PRIXLEAST32  __PRI32 "X"
#define PRIXLEAST64  __PRI64 "X"
#define PRIXLEAST128 __PRI128 "X"

#define PRIXFAST8   __PRI8 "X"
#define PRIXFAST16  __PRIFAST16 "X"
#define PRIXFAST32  __PRIFAST32 "X"
#define PRIXFAST64  __PRI64 "X"
#define PRIXFAST128 __PRI128 "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » binary                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIb8   __PRI8 "b"
#define PRIb16  __PRI16 "b"
#define PRIb32  __PRI32 "b"
#define PRIb64  __PRI64 "b"
#define PRIb128 __PRI128 "b"

#define PRIbLEAST8   __PRI8 "b"
#define PRIbLEAST16  __PRI16 "b"
#define PRIbLEAST32  __PRI32 "b"
#define PRIbLEAST64  __PRI64 "b"
#define PRIbLEAST128 __PRI128 "b"

#define PRIbFAST8   __PRI8 "b"
#define PRIbFAST16  __PRIFAST16 "b"
#define PRIbFAST32  __PRIFAST32 "b"
#define PRIbFAST64  __PRI64 "b"
#define PRIbFAST128 __PRI128 "b"

#define PRIB8   __PRI8 "B"
#define PRIB16  __PRI16 "B"
#define PRIB32  __PRI32 "B"
#define PRIB64  __PRI64 "B"
#define PRIB128 __PRI128 "B"

#define PRIBLEAST8   __PRI8 "B"
#define PRIBLEAST16  __PRI16 "B"
#define PRIBLEAST32  __PRI32 "B"
#define PRIBLEAST64  __PRI64 "B"
#define PRIBLEAST128 __PRI128 "B"

#define PRIBFAST8   __PRI8 "B"
#define PRIBFAST16  __PRIFAST16 "B"
#define PRIBFAST32  __PRIFAST32 "B"
#define PRIBFAST64  __PRI64 "B"
#define PRIBFAST128 __PRI128 "B"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » miscellaneous           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIdMAX "jd"
#define PRIiMAX "ji"
#define PRIoMAX "jo"
#define PRIuMAX "ju"
#define PRIxMAX "jx"
#define PRIXMAX "jX"

#define PRIdPTR __PRIPTR "d"
#define PRIiPTR __PRIPTR "i"
#define PRIoPTR __PRIPTR "o"
#define PRIuPTR __PRIPTR "u"
#define PRIxPTR __PRIPTR "x"
#define PRIXPTR __PRIPTR "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » decimal                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNd8   __PRI8 "d"
#define SCNd16  __PRI16 "d"
#define SCNd32  __PRI32 "d"
#define SCNd64  __PRI64 "d"
#define SCNd128 __PRI128 "d"

#define SCNdLEAST8   __PRI8 "d"
#define SCNdLEAST16  __PRI16 "d"
#define SCNdLEAST32  __PRI32 "d"
#define SCNdLEAST64  __PRI64 "d"
#define SCNdLEAST128 __PRI128 "d"

#define SCNdFAST8   __PRI8 "d"
#define SCNdFAST16  __PRIFAST16 "d"
#define SCNdFAST32  __PRIFAST32 "d"
#define SCNdFAST64  __PRI64 "d"
#define SCNdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » flexidecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNi8   __PRI8 "i"
#define SCNi16  __PRI16 "i"
#define SCNi32  __PRI32 "i"
#define SCNi64  __PRI64 "i"
#define SCNi128 __PRI128 "i"

#define SCNiLEAST8   __PRI8 "i"
#define SCNiLEAST16  __PRI16 "i"
#define SCNiLEAST32  __PRI32 "i"
#define SCNiLEAST64  __PRI64 "i"
#define SCNiLEAST128 __PRI128 "i"

#define SCNiFAST8   __PRI8 "i"
#define SCNiFAST16  __PRIFAST16 "i"
#define SCNiFAST32  __PRIFAST32 "i"
#define SCNiFAST64  __PRI64 "i"
#define SCNiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » unsigned decimal         ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNu8   __PRI8 "u"
#define SCNu16  __PRI16 "u"
#define SCNu32  __PRI32 "u"
#define SCNu64  __PRI64 "u"
#define SCNu128 __PRI128 "u"

#define SCNuLEAST8   __PRI8 "u"
#define SCNuLEAST16  __PRI16 "u"
#define SCNuLEAST32  __PRI32 "u"
#define SCNuLEAST64  __PRI64 "u"
#define SCNuLEAST128 __PRI128 "u"

#define SCNuFAST8   __PRI8 "u"
#define SCNuFAST16  __PRIFAST16 "u"
#define SCNuFAST32  __PRIFAST32 "u"
#define SCNuFAST64  __PRI64 "u"
#define SCNuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » octal                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNo8   __PRI8 "o"
#define SCNo16  __PRI16 "o"
#define SCNo32  __PRI32 "o"
#define SCNo64  __PRI64 "o"
#define SCNo128 __PRI128 "o"

#define SCNoLEAST8   __PRI8 "o"
#define SCNoLEAST16  __PRI16 "o"
#define SCNoLEAST32  __PRI32 "o"
#define SCNoLEAST64  __PRI64 "o"
#define SCNoLEAST128 __PRI128 "o"

#define SCNoFAST8   __PRI8 "o"
#define SCNoFAST16  __PRIFAST16 "o"
#define SCNoFAST32  __PRIFAST32 "o"
#define SCNoFAST64  __PRI64 "o"
#define SCNoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » hexadecimal              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNx8   __PRI8 "x"
#define SCNx16  __PRI16 "x"
#define SCNx32  __PRI32 "x"
#define SCNx64  __PRI64 "x"
#define SCNx128 __PRI128 "x"

#define SCNxLEAST8   __PRI8 "x"
#define SCNxLEAST16  __PRI16 "x"
#define SCNxLEAST32  __PRI32 "x"
#define SCNxLEAST64  __PRI64 "x"
#define SCNxLEAST128 __PRI128 "x"

#define SCNxFAST8   __PRI8 "x"
#define SCNxFAST16  __PRIFAST16 "x"
#define SCNxFAST32  __PRIFAST32 "x"
#define SCNxFAST64  __PRI64 "x"
#define SCNxFAST128 __PRI128 "x"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » binary                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNb8   __PRI8 "b"
#define SCNb16  __PRI16 "b"
#define SCNb32  __PRI32 "b"
#define SCNb64  __PRI64 "b"
#define SCNb128 __PRI128 "b"

#define SCNbLEAST8   __PRI8 "b"
#define SCNbLEAST16  __PRI16 "b"
#define SCNbLEAST32  __PRI32 "b"
#define SCNbLEAST64  __PRI64 "b"
#define SCNbLEAST128 __PRI128 "b"

#define SCNbFAST8   __PRI8 "b"
#define SCNbFAST16  __PRIFAST16 "b"
#define SCNbFAST32  __PRIFAST32 "b"
#define SCNbFAST64  __PRI64 "b"
#define SCNbFAST128 __PRI128 "b"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » miscellaneous            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNdMAX "jd"
#define SCNiMAX "ji"
#define SCNoMAX "jo"
#define SCNuMAX "ju"
#define SCNxMAX "jx"

#define SCNdPTR __PRIPTR "d"
#define SCNiPTR __PRIPTR "i"
#define SCNoPTR __PRIPTR "o"
#define SCNuPTR __PRIPTR "u"
#define SCNxPTR __PRIPTR "x"



/*!BEGIN libc/limits.h */

#define COSMOPOLITAN_LIBC_LIMITS_H_
#define __STDC_LIMIT_MACROS

#define CHAR_BIT 8
#define PATH_MAX 1024
#define NAME_MAX 255
#define ARG_MAX  131074

#define UCHAR_MIN 0
#define UCHAR_MAX 255

#if '\200' < 0
#define CHAR_MIN '\200'
#define CHAR_MAX '\177'
#else
#define CHAR_MIN '\0'
#define CHAR_MAX '\377'
#endif

#define SCHAR_MAX     __SCHAR_MAX__
#define SHRT_MAX      __SHRT_MAX__
#define INT_MAX       __INT_MAX__
#define LONG_MAX      __LONG_MAX__
#define LLONG_MAX     LONG_LONG_MAX
#define LONG_LONG_MAX __LONG_LONG_MAX__
#define SIZE_MAX      __SIZE_MAX__
#define INT8_MAX      __INT8_MAX__
#define INT16_MAX     __INT16_MAX__
#define INT32_MAX     __INT32_MAX__
#define INT64_MAX     __INT64_MAX__
#define WINT_MAX      __WINT_MAX__
#define WCHAR_MAX     __WCHAR_MAX__
#define INTPTR_MAX    __INTPTR_MAX__
#define PTRDIFF_MAX   __PTRDIFF_MAX__
#define UINTPTR_MAX   __UINTPTR_MAX__
#define UINT8_MAX     __UINT8_MAX__
#define UINT16_MAX    __UINT16_MAX__
#define UINT32_MAX    __UINT32_MAX__
#define UINT64_MAX    __UINT64_MAX__
#define INTMAX_MAX    __INTMAX_MAX__
#define UINTMAX_MAX   __UINTMAX_MAX__
#define SSIZE_MAX     __INT64_MAX__

#define SCHAR_MIN     (-SCHAR_MAX - 1)
#define SHRT_MIN      (-SHRT_MAX - 1)
#define INT_MIN       (-INT_MAX - 1)
#define LONG_MIN      (-LONG_MAX - 1)
#define LLONG_MIN     (-LLONG_MAX - 1)
#define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
#define SIZE_MIN      (-SIZE_MAX - 1)
#define INT8_MIN      (-INT8_MAX - 1)
#define INT16_MIN     (-INT16_MAX - 1)
#define INT32_MIN     (-INT32_MAX - 1)
#define INT64_MIN     (-INT64_MAX - 1)
#define INTMAX_MIN    (-INTMAX_MAX - 1)
#define INTPTR_MIN    (-INTPTR_MAX - 1)
#define WINT_MIN      __WINT_MIN__
#define WCHAR_MIN     (-WCHAR_MAX - 1)
#define PTRDIFF_MIN   (-PTRDIFF_MAX - 1)

#define USHRT_MAX 65535
#define UINT_MAX  0xffffffffu
#if __SIZEOF_LONG__ == 8
#define ULONG_MAX 0xfffffffffffffffful
#else
#define ULONG_MAX 0xfffffffful
#endif
#define ULLONG_MAX     0xffffffffffffffffull
#define ULONG_LONG_MAX 0xffffffffffffffffull

#define USHRT_MIN      0
#define UINT_MIN       0u
#define ULONG_MIN      0ul
#define ULLONG_MIN     0ull
#define ULONG_LONG_MIN 0ull
#define UINT8_MIN      0
#define UINT16_MIN     0
#define UINT32_MIN     0u
#define UINT64_MIN     0ull
#define UINTPTR_MIN    0ull
#define UINTMAX_MIN    ((uintmax_t)0)

#define MB_CUR_MAX 4
#define MB_LEN_MAX 4

#ifdef _COSMO_SOURCE
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 406 || defined(__llvm__)
#define INT128_MIN  (-INT128_MAX - 1)
#define UINT128_MIN ((uint128_t)0)
#define INT128_MAX \
  ((int128_t)0x7fffffffffffffff << 64 | (int128_t)0xffffffffffffffff)
#define UINT128_MAX \
  ((uint128_t)0xffffffffffffffff << 64 | (uint128_t)0xffffffffffffffff)
#endif /* GCC 4.6+ */
#endif /* _COSMO_SOURCE */

#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX

#define FILESIZEBITS   64
#define SYMLOOP_MAX    40
#define TTY_NAME_MAX   32
#define HOST_NAME_MAX  255
#define TZNAME_MAX     6
#define WORD_BIT       32
#define SEM_VALUE_MAX  0x7fffffff
#define SEM_NSEMS_MAX  256
#define DELAYTIMER_MAX 0x7fffffff
#define MQ_PRIO_MAX    32768
#define LOGIN_NAME_MAX 256

#define NL_ARGMAX  9
#define NL_MSGMAX  32767
#define NL_SETMAX  255
#define NL_TEXTMAX 2048

#define INT_FAST8_MIN    (-__INT_FAST8_MAX__ - 1)
#define INT_FAST16_MIN   (-__INT_FAST16_MAX__ - 1)
#define INT_FAST32_MIN   (-__INT_FAST32_MAX__ - 1)
#define INT_FAST64_MIN   (-__INT_FAST64_MAX__ - 1)
#define INT_LEAST8_MIN   (-__INT_LEAST8_MAX__ - 1)
#define INT_LEAST16_MIN  (-__INT_LEAST16_MAX__ - 1)
#define INT_LEAST32_MIN  (-__INT_LEAST32_MAX__ - 1)
#define INT_LEAST64_MIN  (-__INT_LEAST64_MAX__ - 1)
#define INT_FAST8_MAX    __INT_FAST8_MAX__
#define INT_FAST16_MAX   __INT_FAST16_MAX__
#define INT_FAST32_MAX   __INT_FAST32_MAX__
#define INT_FAST64_MAX   __INT_FAST64_MAX__
#define INT_LEAST8_MAX   __INT_LEAST8_MAX__
#define INT_LEAST16_MAX  __INT_LEAST16_MAX__
#define INT_LEAST32_MAX  __INT_LEAST32_MAX__
#define INT_LEAST64_MAX  __INT_LEAST64_MAX__
#define UINT_FAST8_MAX   __UINT_FAST8_MAX__
#define UINT_FAST16_MAX  __UINT_FAST16_MAX__
#define UINT_FAST32_MAX  __UINT_FAST32_MAX__
#define UINT_FAST64_MAX  __UINT_FAST64_MAX__
#define UINT_LEAST8_MAX  __UINT_LEAST8_MAX__
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__

#define BC_BASE_MAX        99
#define BC_DIM_MAX         2048
#define BC_SCALE_MAX       99
#define BC_STRING_MAX      1000
#define CHARCLASS_NAME_MAX 14
#define COLL_WEIGHTS_MAX   2
#define EXPR_NEST_MAX      32
#define LINE_MAX           4096
#define RE_DUP_MAX         255
#define LONG_BIT           64
#define NZERO              20
#define NL_LANGMAX         32



/*!BEGIN libc/literal.h */

#define COSMOPOLITAN_LIBC_LITERAL_H_
#define __STDC_CONSTANT_MACROS

#ifdef __INT8_C
#define INT8_C(c)   __INT8_C(c)
#define UINT8_C(c)  __UINT8_C(c)
#define INT16_C(c)  __INT16_C(c)
#define UINT16_C(c) __UINT16_C(c)
#define INT32_C(c)  __INT32_C(c)
#define UINT32_C(c) __UINT32_C(c)
#define INT64_C(c)  __INT64_C(c)
#define UINT64_C(c) __UINT64_C(c)
#else
#define INT8_C(c)   c
#define UINT8_C(c)  c
#define INT16_C(c)  c
#define UINT16_C(c) c
#define INT32_C(c)  c
#define UINT32_C(c) c##U
#define INT64_C(c)  c##L
#define UINT64_C(c) c##UL
#endif

#if UINTPTR_MAX == UINT64_MAX
#define INTMAX_C(c)  c##L
#define UINTMAX_C(c) c##UL
#else
#define INTMAX_C(c)  c##LL
#define UINTMAX_C(c) c##ULL
#endif



/*!BEGIN libc/math.h */

#define COSMOPOLITAN_LIBC_MATH_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § mathematics                                                   │
╚─────────────────────────────────────────────────────────────────────────────*/

#define M_E        2.7182818284590452354  /* 𝑒 */
#define M_LOG2E    1.4426950408889634074  /* log₂𝑒 */
#define M_LOG10E   0.43429448190325182765 /* log₁₀𝑒 */
#define M_LN2      0.69314718055994530942 /* logₑ2 */
#define M_LN10     2.30258509299404568402 /* logₑ10 */
#define M_PI       3.14159265358979323846 /* 𝜋 */
#define M_PI_2     1.57079632679489661923 /* 𝜋/2 */
#define M_PI_4     0.78539816339744830962 /* 𝜋/4 */
#define M_1_PI     0.31830988618379067154 /* 1/𝜋 */
#define M_2_PI     0.63661977236758134308 /* 2/𝜋 */
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(𝜋) */
#define M_SQRT2    1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2  0.70710678118654752440 /* 1/sqrt(2) */

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_Ef        2.7182818284590452354f  /* 𝑒 */
#define M_LOG2Ef    1.4426950408889634074f  /* log₂𝑒 */
#define M_LOG10Ef   0.43429448190325182765f /* log₁₀𝑒 */
#define M_LN2f      0.69314718055994530942f /* logₑ2 */
#define M_LN10f     2.30258509299404568402f /* logₑ10 */
#define M_PIf       3.14159265358979323846f /* 𝜋 */
#define M_PI_2f     1.57079632679489661923f /* 𝜋/2 */
#define M_PI_4f     0.78539816339744830962f /* 𝜋/4 */
#define M_1_PIf     0.31830988618379067154f /* 1/𝜋 */
#define M_2_PIf     0.63661977236758134308f /* 2/𝜋 */
#define M_2_SQRTPIf 1.12837916709551257390f /* 2/sqrt(𝜋) */
#define M_SQRT2f    1.41421356237309504880f /* sqrt(2) */
#define M_SQRT1_2f  0.70710678118654752440f /* 1/sqrt(2) */
#endif

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_El        2.718281828459045235360287471352662498L /* 𝑒 */
#define M_LOG2El    1.442695040888963407359924681001892137L /* log₂𝑒 */
#define M_LOG10El   0.434294481903251827651128918916605082L /* log₁₀𝑒 */
#define M_LN2l      0.693147180559945309417232121458176568L /* logₑ2 */
#define M_LN10l     2.302585092994045684017991454684364208L /* logₑ10 */
#define M_PIl       3.141592653589793238462643383279502884L /* 𝜋 */
#define M_PI_2l     1.570796326794896619231321691639751442L /* 𝜋/2 */
#define M_PI_4l     0.785398163397448309615660845819875721L /* 𝜋/4 */
#define M_1_PIl     0.318309886183790671537767526745028724L /* 1/𝜋 */
#define M_2_PIl     0.636619772367581343075535053490057448L /* 2/𝜋 */
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(𝜋) */
#define M_SQRT2l    1.414213562373095048801688724209698079L /* sqrt(2) */
#define M_SQRT1_2l  0.707106781186547524400844362104849039L /* 1/sqrt(2) */
#endif

#define DBL_DECIMAL_DIG   __DBL_DECIMAL_DIG__
#define DBL_DIG           __DBL_DIG__
#define DBL_EPSILON       __DBL_EPSILON__
#define DBL_HAS_SUBNORM   __DBL_HAS_DENORM__
#define DBL_IS_IEC_60559  __DBL_IS_IEC_60559__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MAX           __DBL_MAX__
#define DBL_MAX_10_EXP    __DBL_MAX_10_EXP__
#define DBL_MAX_EXP       __DBL_MAX_EXP__
#define DBL_MIN           __DBL_MIN__ /* 2.23e–308 ↔ 1.79e308 */
#define DBL_MIN_10_EXP    __DBL_MIN_10_EXP__
#define DBL_MIN_EXP       __DBL_MIN_EXP__
#define DBL_NORM_MAX      __DBL_NORM_MAX__
#define DBL_TRUE_MIN      __DBL_DENORM_MIN__
#define DECIMAL_DIG       __LDBL_DECIMAL_DIG__
#define FLT_DECIMAL_DIG   __FLT_DECIMAL_DIG__
#define FLT_DIG           __FLT_DIG__
#define FLT_EPSILON       __FLT_EPSILON__
#define FLT_HAS_SUBNORM   __FLT_HAS_DENORM__
#define FLT_IS_IEC_60559  __FLT_IS_IEC_60559__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MAX           __FLT_MAX__
#define FLT_MAX_10_EXP    __FLT_MAX_10_EXP__
#define FLT_MAX_EXP       __FLT_MAX_EXP__
#define FLT_MIN           __FLT_MIN__ /* 1.18e–38 ↔ 3.40e38 */
#define FLT_MIN_10_EXP    __FLT_MIN_10_EXP__
#define FLT_MIN_EXP       __FLT_MIN_EXP__
#define FLT_NORM_MAX      __FLT_NORM_MAX__
#define FLT_RADIX         __FLT_RADIX__
#define FLT_TRUE_MIN      __FLT_DENORM_MIN__
#define HLF_MAX           6.50e4f
#define HLF_MIN           3.10e-5f
#define LDBL_DECIMAL_DIG  __LDBL_DECIMAL_DIG__
#define LDBL_DIG          __LDBL_DIG__
#define LDBL_EPSILON      __LDBL_EPSILON__
#define LDBL_HAS_SUBNORM  __LDBL_HAS_DENORM__
#define LDBL_IS_IEC_60559 __LDBL_IS_IEC_60559__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MAX          __LDBL_MAX__
#define LDBL_MAX_10_EXP   __LDBL_MAX_10_EXP__
#define LDBL_MAX_EXP      __LDBL_MAX_EXP__
#define LDBL_MIN          __LDBL_MIN__ /* 3.37e–4932 ↔ 1.18e4932 */
#define LDBL_MIN_10_EXP   __LDBL_MIN_10_EXP__
#define LDBL_MIN_EXP      __LDBL_MIN_EXP__
#define LDBL_NORM_MAX     __LDBL_NORM_MAX__
#define LDBL_TRUE_MIN     __LDBL_DENORM_MIN__

#define FP_NAN       0
#define FP_INFINITE  1
#define FP_ZERO      2
#define FP_SUBNORMAL 3
#define FP_NORMAL    4
#define FP_ILOGB0    (-2147483647 - 1)
#define FP_ILOGBNAN  (-2147483647 - 1)

#define MATH_ERRNO     1
#define MATH_ERREXCEPT 2

#ifdef __FAST_MATH__
#define math_errhandling 0
#elif defined(__NO_MATH_ERRNO__)
#define math_errhandling (MATH_ERREXCEPT)
#else
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
#endif

#ifdef __FP_FAST_FMA
#define FP_FAST_FMA 1
#endif
#ifdef __FP_FAST_FMAF
#define FP_FAST_FMAF 1
#endif
#ifdef __FP_FAST_FMAL
#define FP_FAST_FMAL 1
#endif

COSMOPOLITAN_C_START_

#define NAN       __builtin_nanf("")
#define INFINITY  __builtin_inff()
#define HUGE_VAL  __builtin_inf()
#define HUGE_VALF __builtin_inff()
#define HUGE_VALL __builtin_infl()

#if __FLT_EVAL_METHOD__ + 0 == 2
typedef long double float_t;
typedef long double double_t;
#else
typedef float float_t;
typedef double double_t;
#endif

#define isinf(x)             __builtin_isinf(x)
#define isnan(x)             __builtin_isnan(x)
#define isfinite(x)          __builtin_isfinite(x)
#define isnormal(x)          __builtin_isnormal(x)
#define isgreater(x, y)      __builtin_isgreater(x, y)
#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
#define isless(x, y)         __builtin_isless(x, y)
#define islessequal(x, y)    __builtin_islessequal(x, y)
#define islessgreater(x, y)  __builtin_islessgreater(x, y)
#define isunordered(x, y)    __builtin_isunordered(x, y)

#define fpclassify(x) \
  __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)

#define signbit(x)                                          \
  (sizeof(x) == sizeof(long double) ? __builtin_signbitl(x) \
   : sizeof(x) == sizeof(float)     ? __builtin_signbitf(x) \
                                    : __builtin_signbit(x))

extern int signgam;

double acos(double) libcesque;
double acosh(double) libcesque;
double asin(double) libcesque;
double asinh(double) libcesque;
double atan(double) libcesque;
double atan2(double, double) libcesque;
double atanh(double) libcesque;
double cbrt(double) libcesque;
double ceil(double) libcesque;
double copysign(double, double) libcesque;
double cos(double) libcesque;
double cosh(double) libcesque;
double drem(double, double) libcesque;
double erf(double) libcesque;
double erfc(double) libcesque;
double exp(double) libcesque;
double exp10(double) libcesque;
double exp2(double) libcesque;
double expm1(double) libcesque;
double fabs(double) libcesque;
double fdim(double, double) libcesque;
double floor(double) libcesque;
double fma(double, double, double) libcesque;
double fmax(double, double) libcesque;
double fmin(double, double) libcesque;
double fmod(double, double) libcesque;
double hypot(double, double) libcesque;
double ldexp(double, int) libcesque;
double log(double) libcesque;
double log10(double) libcesque;
double log1p(double) libcesque;
double log2(double) libcesque;
double logb(double) libcesque;
double nearbyint(double) libcesque;
double nextafter(double, double) libcesque;
double nexttoward(double, long double) libcesque;
double pow(double, double) libcesque;
double pow10(double) libcesque;
double powi(double, int) libcesque;
double remainder(double, double) libcesque;
double rint(double) libcesque;
double round(double) libcesque;
double scalb(double, double) libcesque;
double scalbln(double, long int) libcesque;
double scalbn(double, int) libcesque;
double significand(double) libcesque;
double sin(double) libcesque;
double sinh(double) libcesque;
double sqrt(double) libcesque;
double tan(double) libcesque;
double tanh(double) libcesque;
double trunc(double) libcesque;
double tgamma(double) libcesque;
double lgamma(double) libcesque;
double lgamma_r(double, int *) libcesque;
int finite(double) libcesque;

float acosf(float) libcesque;
float acoshf(float) libcesque;
float asinf(float) libcesque;
float asinhf(float) libcesque;
float atan2f(float, float) libcesque;
float atanf(float) libcesque;
float atanhf(float) libcesque;
float cbrtf(float) libcesque;
float ceilf(float) libcesque;
float copysignf(float, float) libcesque;
float cosf(float) libcesque;
float coshf(float) libcesque;
float dremf(float, float) libcesque;
float erfcf(float) libcesque;
float erff(float) libcesque;
float exp10f(float) libcesque;
float exp2f(float) libcesque;
float expf(float) libcesque;
float expm1f(float) libcesque;
float fabsf(float) libcesque;
float fdimf(float, float) libcesque;
float floorf(float) libcesque;
float fmaf(float, float, float) libcesque;
float fmaxf(float, float) libcesque;
float fminf(float, float) libcesque;
float fmodf(float, float) libcesque;
float hypotf(float, float) libcesque;
float ldexpf(float, int) libcesque;
float lgammaf(float) libcesque;
float lgammaf_r(float, int *) libcesque;
float log10f(float) libcesque;
float log1pf(float) libcesque;
float log2f(float) libcesque;
float logbf(float) libcesque;
float logf(float) libcesque;
float nearbyintf(float) libcesque;
float nextafterf(float, float) libcesque;
float nexttowardf(float, long double) libcesque;
float pow10f(float) libcesque;
float powf(float, float) libcesque;
float powif(float, int) libcesque;
float remainderf(float, float) libcesque;
float rintf(float) libcesque;
float roundf(float) libcesque;
float scalbf(float, float) libcesque;
float scalblnf(float, long int) libcesque;
float scalbnf(float, int) libcesque;
float significandf(float) libcesque;
float sinf(float) libcesque;
float sinhf(float) libcesque;
float sqrtf(float) libcesque;
float tanf(float) libcesque;
float tanhf(float) libcesque;
float tgammaf(float) libcesque;
float truncf(float) libcesque;
int finitef(float) libcesque;

int finitel(long double) libcesque;
long double acoshl(long double) libcesque;
long double acosl(long double) libcesque;
long double asinhl(long double) libcesque;
long double asinl(long double) libcesque;
long double atan2l(long double, long double) libcesque;
long double atanhl(long double) libcesque;
long double atanl(long double) libcesque;
long double cbrtl(long double) libcesque;
long double ceill(long double) libcesque;
long double copysignl(long double, long double) libcesque;
long double coshl(long double) libcesque;
long double cosl(long double) libcesque;
long double dreml(long double, long double) libcesque;
long double erfcl(long double) libcesque;
long double erfl(long double) libcesque;
long double exp10l(long double) libcesque;
long double exp2l(long double) libcesque;
long double expl(long double) libcesque;
long double expm1l(long double) libcesque;
long double fabsl(long double) libcesque;
long double fdiml(long double, long double) libcesque;
long double floorl(long double) libcesque;
long double fmal(long double, long double, long double) libcesque;
long double fmaxl(long double, long double) libcesque;
long double fminl(long double, long double) libcesque;
long double fmodl(long double, long double) libcesque;
long double hypotl(long double, long double) libcesque;
long double ldexpl(long double, int) libcesque;
long double lgammal(long double) libcesque;
long double lgammal_r(long double, int *) libcesque;
long double log10l(long double) libcesque;
long double log1pl(long double) libcesque;
long double log2l(long double) libcesque;
long double logbl(long double) libcesque;
long double logl(long double) libcesque;
long double nearbyintl(long double) libcesque;
long double nextafterl(long double, long double) libcesque;
long double nexttowardl(long double, long double) libcesque;
long double pow10l(long double) libcesque;
long double powl(long double, long double) libcesque;
long double remainderl(long double, long double) libcesque;
long double rintl(long double) libcesque;
long double roundl(long double) libcesque;
long double scalbl(long double, long double) libcesque;
long double scalblnl(long double, long int) libcesque;
long double scalbnl(long double, int) libcesque;
long double significandl(long double) libcesque;
long double sinhl(long double) libcesque;
long double sinl(long double) libcesque;
long double sqrtl(long double) libcesque;
long double tanhl(long double) libcesque;
long double tanl(long double) libcesque;
long double tgammal(long double) libcesque;
long double truncl(long double) libcesque;

long lrint(double) libcesque;
long lrintf(float) libcesque;
long lrintl(long double) libcesque;
long lround(double) libcesque;
long lroundf(float) libcesque;
long lroundl(long double) libcesque;

int ilogbf(float) libcesque;
int ilogb(double) libcesque;
int ilogbl(long double) libcesque;

long long llrint(double) libcesque;
long long llrintf(float) libcesque;
long long llrintl(long double) libcesque;
long long llround(double) libcesque;
long long llroundf(float) libcesque;
long long llroundl(long double) libcesque;

double frexp(double, int *) libcesque;
double modf(double, double *) libcesque;
double nan(const char *) libcesque;
double remquo(double, double, int *) libcesque;
float frexpf(float, int *) libcesque;
float modff(float, float *) libcesque;
float nanf(const char *) libcesque;
float remquof(float, float, int *) libcesque;
long double frexpl(long double, int *) libcesque;
long double modfl(long double, long double *) libcesque;
long double nanl(const char *) libcesque;
long double remquol(long double, long double, int *) libcesque;
void sincos(double, double *, double *) libcesque;
void sincosf(float, float *, float *) libcesque;
void sincosl(long double, long double *, long double *) libcesque;

double fsumf(const float *, size_t) libcesque;
double fsum(const double *, size_t) libcesque;

double j0(double) libcesque;
double j1(double) libcesque;
double jn(int, double) libcesque;
float j0f(float) libcesque;
float j1f(float) libcesque;
float jnf(int, float) libcesque;

double y0(double) libcesque;
double y1(double) libcesque;
double yn(int, double) libcesque;
float y0f(float) libcesque;
float y1f(float) libcesque;
float ynf(int, float) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/paths.h */

#define COSMOPOLITAN_LIBC_PATHS_H_

#define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin"
#define _PATH_STDPATH "/bin:/usr/bin:/sbin:/usr/sbin"

#define _PATH_BSHELL   "/bin/sh"
#define _PATH_CONSOLE  "/dev/console"
#define _PATH_DEVNULL  "/dev/null"
#define _PATH_KLOG     "/proc/kmsg"
#define _PATH_LASTLOG  "/var/log/lastlog"
#define _PATH_MAILDIR  "/var/mail"
#define _PATH_MAN      "/usr/share/man"
#define _PATH_MNTTAB   "/etc/fstab"
#define _PATH_MOUNTED  "/etc/mtab"
#define _PATH_NOLOGIN  "/etc/nologin"
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
#define _PATH_SHADOW   "/etc/shadow"
#define _PATH_SHELLS   "/etc/shells"
#define _PATH_TTY      "/dev/tty"
#define _PATH_UTMP     "/dev/null/utmp"
#define _PATH_VI       "/usr/bin/vi"
#define _PATH_WTMP     "/dev/null/wtmp"

#define _PATH_DEV    "/dev/"
#define _PATH_TMP    "/tmp/"
#define _PATH_VARDB  "/var/lib/misc/"
#define _PATH_VARRUN "/var/run/"
#define _PATH_VARTMP "/var/tmp/"



/*!BEGIN libc/serialize.h */

#define COSMOPOLITAN_SERIALIZE_H_
#ifdef _COSMO_SOURCE

#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define __SWAPBE16(x) (x)
#define __SWAPBE32(x) (x)
#define __SWAPBE64(x) (x)
#else
#define __SWAPBE16(x) __builtin_bswap16(x)
#define __SWAPBE32(x) __builtin_bswap32(x)
#define __SWAPBE64(x) __builtin_bswap64(x)
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __SWAPLE16(x) (x)
#define __SWAPLE32(x) (x)
#define __SWAPLE64(x) (x)
#else
#define __SWAPLE16(x) __builtin_bswap16(x)
#define __SWAPLE32(x) __builtin_bswap32(x)
#define __SWAPLE64(x) __builtin_bswap64(x)
#endif

#define READ16LE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPLE16(__x);                   \
  }))

#define READ16BE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPBE16(__x);                   \
  }))

#define READ32LE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ32BE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPBE32(__x);                   \
  }))

#define READ64LE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ64BE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPBE64(__x);                   \
  }))

#define WRITE16LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPLE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE16BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPBE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE32LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPLE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE32BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPBE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE64LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPLE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#define WRITE64BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPBE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/stdckdint.h */

#define COSMOPOLITAN_LIBC_STDCKDINT_H_
/* clang-format off */

/**
 * @fileoverview C23 Checked Arithmetic
 *
 * This header defines three type generic functions:
 *
 *   - `bool ckd_add(res, a, b)`
 *   - `bool ckd_sub(res, a, b)`
 *   - `bool ckd_mul(res, a, b)`
 *
 * Which allow integer arithmetic errors to be detected. There are many
 * kinds of integer errors, e.g. overflow, truncation, etc. These funcs
 * catch them all. Here's an example of how it works:
 *
 *     uint32_t c;
 *     int32_t a = 0x7fffffff;
 *     int32_t b = 2;
 *     assert(!ckd_add(&c, a, b));
 *     assert(c == 0x80000001u);
 *
 * Experienced C / C++ users should find this example counter-intuitive
 * because the expression `0x7fffffff + 2` not only overflows it's also
 * undefined behavior. However here we see it's specified, and does not
 * result in an error. That's because C23 checked arithmetic is not the
 * arithmetic you're used to. The new standard changes the mathematics.
 *
 * C23 checked arithmetic is defined as performing the arithmetic using
 * infinite precision and then checking if the resulting value will fit
 * in the output type. Our example above did not result in an error due
 * to `0x80000001` being a legal value for `uint32_t`.
 *
 * This implementation will use the GNU compiler builtins, when they're
 * available, only if you don't use build flags like `-std=c11` because
 * they define `__STRICT_ANSI__` and GCC extensions aren't really ANSI.
 * Instead, you'll get a pretty good pure C11 and C++11 implementation.
 *
 * @see https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
 * @version 0.1 (2023-07-22)
 */

#define __STDC_VERSION_STDCKDINT_H__ 202311L

#if ((defined(__llvm__) ||                                              \
      (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406)) && \
     !defined(__STRICT_ANSI__))
#define __ckd_have_int128
#define __ckd_intmax __int128
#elif ((defined(__cplusplus) && __cplusplus >= 201103L) ||              \
       (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L))
#define __ckd_intmax long long
#else
#define __ckd_intmax long
#endif

typedef signed __ckd_intmax __ckd_intmax_t;
typedef unsigned __ckd_intmax __ckd_uintmax_t;

#if (!defined(__STRICT_ANSI__) &&                       \
     ((defined(__GNUC__) && __GNUC__ >= 5 &&            \
       !defined(__chibicc__) && !defined(__ICC)) ||     \
      (__has_builtin(__builtin_add_overflow) &&         \
       __has_builtin(__builtin_sub_overflow) &&         \
       __has_builtin(__builtin_mul_overflow))))
#define ckd_add(res, x, y) __builtin_add_overflow((x), (y), (res))
#define ckd_sub(res, x, y) __builtin_sub_overflow((x), (y), (res))
#define ckd_mul(res, x, y) __builtin_mul_overflow((x), (y), (res))

#elif defined(__cplusplus) && __cplusplus >= 201103L

template <typename __T, typename __U, typename __V>
inline bool ckd_add(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x + __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u + u
      return __truncated | (__z < __x);
    case 1:  // u = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 2:  // u = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 3:  // u = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z | __x) &  __y) |
                                       ((__z & __x) & ~__y)) < 0);
    case 4:  // s = u + u
      return __truncated | (__z < __x) | (static_cast<__ckd_intmax_t>(__z) < 0);
    case 5:  // s = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __y);
    case 6:  // s = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __x);
    case 7:  // s = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_sub(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x - __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u - u
      return __truncated | (__x < __y);
    case 1:  // u = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    case 2:  // u = s - u
      return __truncated | (__y > __x) | (static_cast<__ckd_intmax_t>(__x) < 0);
    case 3:  // u = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z & __x) &  __y) |
                                       ((__z | __x) & ~__y)) < 0);
    case 4:  // s = u - u
      return __truncated |
          ((__x < __y) ^ (static_cast<__ckd_intmax_t>(__z) < 0));
    case 5:  // s = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x >= __y);
    case 6:  // s = s - u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x < __y);
    case 7:  // s = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_mul(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  if ((sizeof(__U) * 8 - std::is_signed<__U>::value) +
      (sizeof(__V) * 8 - std::is_signed<__V>::value) <=
      (sizeof(__T) * 8 - std::is_signed<__T>::value)) {
    if (sizeof(__ckd_uintmax_t) > sizeof(__T) || std::is_signed<__T>::value) {
      __ckd_intmax_t __z = __x * __y;
      return __z != (*__res = __z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0: {  // u = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 1: {  // u = u * s
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__y) < 0) & !!__x) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 2: {  // u = s * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__x) < 0) & !!__y) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 3: { // u = s * s
      int __o = false;
      if (static_cast<__ckd_intmax_t>(__x & __y) < 0) {
        __x = -__x;
        __y = -__y;
      } else if (static_cast<__ckd_intmax_t>(__x ^ __y) < 0) {
        __o = __x && __y;
      }
      __ckd_uintmax_t __z = __x * __y;
      __o |= __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 4: {  // s = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | (static_cast<__ckd_intmax_t>(__z) < 0) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 5: {  // s = u * s
      __ckd_uintmax_t __t = -__y;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __y : __t;
      __ckd_uintmax_t __p = __t * __x;
      int __o = __t && __p / __t != __x;
      int __n = static_cast<__ckd_intmax_t>(__y) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 6: {  // s = s * u
      __ckd_uintmax_t __t = -__x;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __x : __t;
      __ckd_uintmax_t __p = __t * __y;
      int __o = __t && __p / __t != __y;
      int __n = static_cast<__ckd_intmax_t>(__x) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 7: {  // s = s * s
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return ((((static_cast<__ckd_intmax_t>(__y) < 0) &&
                (static_cast<__ckd_intmax_t>(__x) ==
                 std::numeric_limits<__ckd_intmax_t>::min())) ||
               (__y && ((static_cast<__ckd_intmax_t>(__z) /
                         static_cast<__ckd_intmax_t>(__y)) !=
                        static_cast<__ckd_intmax_t>(__x)))) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    default:
      for (;;) (void)0;
  }
}

#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L

#define ckd_add(res, a, b) __ckd_expr(add, (res), (a), (b))
#define ckd_sub(res, a, b) __ckd_expr(sub, (res), (a), (b))
#define ckd_mul(res, a, b) __ckd_expr(mul, (res), (a), (b))

#if defined(__GNUC__) || defined(__llvm__)
#define __ckd_inline                                    \
  extern __inline __attribute__((__gnu_inline__,        \
                                 __always_inline__,     \
                                 __artificial__))
#else
#define __ckd_inline static inline
#endif

#ifdef __ckd_have_int128
#define __ckd_generic_int128(x, y) , signed __int128: x, unsigned __int128: y
#else
#define __ckd_generic_int128(x, y)
#endif

#define __ckd_sign(T)                           \
  ((T)1 << (sizeof(T) * 8 - 1))

#define __ckd_is_signed(x)                      \
  _Generic(x,                                   \
           signed char: 1,                      \
           unsigned char: 0,                    \
           signed short: 1,                     \
           unsigned short: 0,                   \
           signed int: 1,                       \
           unsigned int: 0,                     \
           signed long: 1,                      \
           unsigned long: 0,                    \
           signed long long: 1,                 \
           unsigned long long: 0                \
           __ckd_generic_int128(1, 0))

#define __ckd_expr(op, res, a, b)                       \
  (_Generic(*res,                                       \
            signed char: __ckd_##op##_schar,            \
            unsigned char: __ckd_##op##_uchar,          \
            signed short: __ckd_##op##_sshort,          \
            unsigned short: __ckd_##op##_ushort,        \
            signed int: __ckd_##op##_sint,              \
            unsigned int: __ckd_##op##_uint,            \
            signed long: __ckd_##op##_slong,            \
            unsigned long: __ckd_##op##_ulong,          \
            signed long long: __ckd_##op##_slonger,     \
            unsigned long long: __ckd_##op##_ulonger    \
            __ckd_generic_int128(                       \
                __ckd_##op##_sint128,                   \
                __ckd_##op##_uint128))(                 \
                    res, a, b,                          \
                    __ckd_is_signed(a),                 \
                    __ckd_is_signed(b)))

#define __ckd_declare_add(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x + __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u + u */                                          \
        return __truncated | (__z < __x);                               \
      case 1:  /* u = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 2:  /* u = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 3:  /* u = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z | __x) &  __y) |                    \
                              ((__z & __x) & ~__y)) < 0);               \
      case 4:  /* s = u + u */                                          \
        return __truncated | (__z < __x) | ((__ckd_intmax_t)__z < 0);   \
      case 5:  /* s = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __y);                         \
      case 6:  /* s = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __x);                         \
      case 7:  /* s = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_add(__ckd_add_schar, signed char)
__ckd_declare_add(__ckd_add_uchar, unsigned char)
__ckd_declare_add(__ckd_add_sshort, signed short)
__ckd_declare_add(__ckd_add_ushort, unsigned short)
__ckd_declare_add(__ckd_add_sint, signed int)
__ckd_declare_add(__ckd_add_uint, unsigned int)
__ckd_declare_add(__ckd_add_slong, signed long)
__ckd_declare_add(__ckd_add_ulong, unsigned long)
__ckd_declare_add(__ckd_add_slonger, signed long long)
__ckd_declare_add(__ckd_add_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_add(__ckd_add_sint128, signed __int128)
__ckd_declare_add(__ckd_add_uint128, unsigned __int128)
#endif

#define __ckd_declare_sub(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x - __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u - u */                                          \
        return __truncated | (__x < __y);                               \
      case 1:  /* u = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      case 2:  /* u = s - u */                                          \
        return __truncated | (__y > __x) | ((__ckd_intmax_t)__x < 0);   \
      case 3:  /* u = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z & __x) &  __y) |                    \
                              ((__z | __x) & ~__y)) < 0);               \
      case 4:  /* s = u - u */                                          \
        return __truncated | ((__x < __y) ^ ((__ckd_intmax_t)__z < 0)); \
      case 5:  /* s = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x >= __y);                              \
      case 6:  /* s = s - u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x < __y);                               \
      case 7:  /* s = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_sub(__ckd_sub_schar, signed char)
__ckd_declare_sub(__ckd_sub_uchar, unsigned char)
__ckd_declare_sub(__ckd_sub_sshort, signed short)
__ckd_declare_sub(__ckd_sub_ushort, unsigned short)
__ckd_declare_sub(__ckd_sub_sint, signed int)
__ckd_declare_sub(__ckd_sub_uint, unsigned int)
__ckd_declare_sub(__ckd_sub_slong, signed long)
__ckd_declare_sub(__ckd_sub_ulong, unsigned long)
__ckd_declare_sub(__ckd_sub_slonger, signed long long)
__ckd_declare_sub(__ckd_sub_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_sub(__ckd_sub_sint128, signed __int128)
__ckd_declare_sub(__ckd_sub_uint128, unsigned __int128)
#endif

#define __ckd_declare_mul(S, T)                                 \
  __ckd_inline char S(void *__res,                              \
                      __ckd_uintmax_t __x,                      \
                      __ckd_uintmax_t __y,                      \
                      char __a_signed,                          \
                      char __b_signed) {                        \
    switch (__ckd_is_signed((T)0) << 2 |                        \
            __a_signed << 1 | __b_signed) {                     \
      case 0: {  /* u = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 1: {  /* u = u * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__y < 0) & !!__x) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 2: {  /* u = s * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__x < 0) & !!__y) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 3: {  /* u = s * s */                                \
        int __o = 0;                                            \
        if ((__ckd_intmax_t)(__x & __y) < 0) {                  \
          __x = -__x;                                           \
          __y = -__y;                                           \
        } else if ((__ckd_intmax_t)(__x ^ __y) < 0) {           \
          __o = __x && __y;                                     \
        }                                                       \
        __ckd_uintmax_t __z = __x * __y;                        \
        __o |= __x && __z / __x != __y;                         \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 4: {  /* s = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | ((__ckd_intmax_t)(__z) < 0) |             \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 5: {  /* s = u * s */                                \
        __ckd_uintmax_t __t = -__y;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __y : __t;            \
        __ckd_uintmax_t __p = __t * __x;                        \
        int __o = __t && __p / __t != __x;                      \
        int __n = (__ckd_intmax_t)__y < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 6: {  /* s = s * u */                                \
        __ckd_uintmax_t __t = -__x;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __x : __t;            \
        __ckd_uintmax_t __p = __t * __y;                        \
        int __o = __t && __p / __t != __y;                      \
        int __n = (__ckd_intmax_t)__x < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 7: {  /* s = s * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        *(T *)__res = __z;                                      \
        return (((((__ckd_intmax_t)__y < 0) &&                  \
                  (__x == __ckd_sign(__ckd_uintmax_t))) ||      \
                 (__y && (((__ckd_intmax_t)__z /                \
                           (__ckd_intmax_t)__y) !=              \
                          (__ckd_intmax_t)__x))) |              \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      default:                                                  \
        for (;;) (void)0;                                       \
    }                                                           \
  }

__ckd_declare_mul(__ckd_mul_schar, signed char)
__ckd_declare_mul(__ckd_mul_uchar, unsigned char)
__ckd_declare_mul(__ckd_mul_sshort, signed short)
__ckd_declare_mul(__ckd_mul_ushort, unsigned short)
__ckd_declare_mul(__ckd_mul_sint, signed int)
__ckd_declare_mul(__ckd_mul_uint, unsigned int)
__ckd_declare_mul(__ckd_mul_slong, signed long)
__ckd_declare_mul(__ckd_mul_ulong, unsigned long)
__ckd_declare_mul(__ckd_mul_slonger, signed long long)
__ckd_declare_mul(__ckd_mul_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_mul(__ckd_mul_sint128, signed __int128)
__ckd_declare_mul(__ckd_mul_uint128, unsigned __int128)
#endif

#else
#pragma message "checked integer arithmetic unsupported in this environment"

#define ckd_add(res, x, y) (*(res) = (x) + (y), 0)
#define ckd_sub(res, x, y) (*(res) = (x) - (y), 0)
#define ckd_mul(res, x, y) (*(res) = (x) * (y), 0)

#endif /* GNU */
/* clang-format on */


/*!BEGIN libc/stdlib.h */

#define COSMOPOLITAN_LIBC_STDLIB_H_
COSMOPOLITAN_C_START_

char *fcvt(double, int, int *, int *) libcesque;
char *ecvt(double, int, int *, int *) libcesque;
char *gcvt(double, int, char *) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void setkey(const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/temp.h */

#define COSMOPOLITAN_LIBC_TEMP_H_
COSMOPOLITAN_C_START_

char *mktemp(char *) libcesque returnsnonnull paramsnonnull();
char *mkdtemp(char *) libcesque paramsnonnull() __wur;
int mkstemp(char *) libcesque paramsnonnull() __wur;
int mkstemps(char *, int) libcesque paramsnonnull() __wur;

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
int mkostemp(char *, unsigned) libcesque paramsnonnull() __wur;
int mkostemps(char *, int, unsigned) libcesque paramsnonnull() __wur;
#endif

#ifdef _COSMO_SOURCE
int openatemp(int, char *, int, int, int) libcesque paramsnonnull() __wur;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/time.h */

#define COSMOPOLITAN_LIBC_TIME_H_

#define TIME_UTC 1

COSMOPOLITAN_C_START_

struct tm {
  int32_t tm_sec;
  int32_t tm_min;
  int32_t tm_hour;
  int32_t tm_mday; /* 1-indexed */
  int32_t tm_mon;  /* 0-indexed */
  int32_t tm_year; /* minus 1900 */
  int32_t tm_wday;
  int32_t tm_yday;
  int32_t tm_isdst;
  int64_t tm_gmtoff;
  const char *tm_zone;
};

struct timezone {
  int32_t tz_minuteswest;
  int32_t tz_dsttime;
};

extern char *tzname[2];
extern long timezone;
extern int daylight;

void tzset(void) libcesque;
char *asctime(const struct tm *) libcesque;
char *asctime_r(const struct tm *, char *) libcesque;
char *strptime(const char *, const char *, struct tm *) libcesque;
int64_t mktime(struct tm *) libcesque;
int64_t timegm(struct tm *) libcesque;
int64_t timelocal(struct tm *) libcesque;
int64_t timeoff(struct tm *, long) libcesque;
size_t strftime(char *, size_t, const char *, const struct tm *) libcesque
    strftimeesque(3) libcesque;
size_t wcsftime(wchar_t *, size_t, const wchar_t *,
                const struct tm *) libcesque;
struct tm *gmtime(const int64_t *) libcesque;
struct tm *gmtime_r(const int64_t *, struct tm *) libcesque;
struct tm *localtime(const int64_t *) libcesque;
struct tm *localtime_r(const int64_t *, struct tm *) libcesque;

char *ctime(const int64_t *) libcesque;
char *ctime_r(const int64_t *, char *) libcesque;
double difftime(int64_t, int64_t)
pureconst libcesque;
int stime(const int64_t *) libcesque;
void tzset(void) libcesque;

#ifdef _COSMO_SOURCE
extern const char kWeekdayNameShort[7][4];
extern const char kWeekdayName[7][10];
extern const char kMonthNameShort[12][4];
extern const char kMonthName[12][10];
extern const unsigned short kMonthYearDay[2][12];
#define iso8601 __iso8601
char *iso8601(char[hasatleast 20], struct tm *) libcesque;
#define iso8601us __iso8601us
char *iso8601us(char[hasatleast 27], struct tm *, long) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/type2str.h */

#define COSMOPOLITAN_LIBC_TYPE2STR_H_
#if __STDC_VERSION__ + 0 >= 201112
/* clang-format off */

#define _TYPE2STR(X)                          \
  _Generic(X,                                 \
    _Bool:              "_Bool",              \
    signed char:        "signed char",        \
    unsigned char:      "unsigned char",      \
    char:               "char",               \
    short:              "short",              \
    unsigned short:     "unsigned short",     \
    int:                "int",                \
    unsigned:           "unsigned",           \
    long:               "long",               \
    unsigned long:      "unsigned long",      \
    long long:          "long long",          \
    unsigned long long: "unsigned long long", \
    __int128:           "__int128",           \
    unsigned __int128:  "unsigned __int128",  \
    float:              "float",              \
    double:             "double",             \
    long double:        "long double")

#define _PRINTF_GENERIC(X, D, U) \
  _Generic(X,                    \
    _Bool:              "hhh" U, \
    signed char:        "hh" D,  \
    unsigned char:      "hh" U,  \
    char:               "hh" D,  \
    short:              "h" D,   \
    unsigned short:     "h" U,   \
    int:                D,       \
    unsigned:           U,       \
    long:               "l" D,   \
    unsigned long:      "l" U,   \
    long long:          "ll" D,  \
    unsigned long long: "ll" U,  \
    float:              "f",     \
    double:             "f",     \
    long double:        "Lf")

/* clang-format on */
#endif /* C11 */


/*!BEGIN libc/unistd.h */

#define COSMOPOLITAN_LIBC_UNISTD_H_
COSMOPOLITAN_C_START_

#define _CS_PATH 0

size_t confstr(int, char *, size_t) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void encrypt(char *, int) libcesque;
char *crypt(const char *, const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/utime.h */

#define COSMOPOLITAN_LIBC_UTIME_H_
COSMOPOLITAN_C_START_

struct utimbuf {
  int64_t actime;  /* access time */
  int64_t modtime; /* modified time */
};

int utime(const char *, const struct utimbuf *) libcesque;

#ifdef _COSMO_SOURCE
int sys_utime(const char *, const struct utimbuf *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/typedef/u.h */

#define COSMOPOLITAN_LIBC_CALLS_TYPEDEF_U_H_
COSMOPOLITAN_C_START_

typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
typedef unsigned u_int32_t;
typedef char *caddr_t;
typedef unsigned char u_char;
typedef unsigned short u_short, ushort;
typedef unsigned u_int, uint;
typedef unsigned long u_long, ulong;
typedef long long quad_t;
typedef unsigned long long u_quad_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/cpuset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_

#define CPU_SETSIZE 1024

COSMOPOLITAN_C_START_

typedef struct cpu_set_t {
  uint64_t __bits[16];
} cpu_set_t;

int sched_getcpu(void) libcesque;
int sched_getaffinity(int, size_t, cpu_set_t *) libcesque;
int sched_setaffinity(int, size_t, const cpu_set_t *) libcesque;

#define CPU_SET(i, s)   ((s)->__bits[(i) / 64] |= 1ull << ((i) % 64))
#define CPU_CLR(i, s)   ((s)->__bits[(i) / 64] &= ~(1ull << ((i) % 64)))
#define CPU_ISSET(i, s) (!!((s)->__bits[(i) / 64] & (1ull << ((i) % 64))))

void CPU_ZERO(cpu_set_t *) libcesque;
#define CPU_ZERO(x) CPU_ZERO(x)

int CPU_COUNT(cpu_set_t *) libcesque;
#define CPU_COUNT(x) CPU_COUNT(x)

int CPU_EQUAL(cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_EQUAL(x, y) CPU_EQUAL(x, y)

void CPU_AND(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_AND(x, y, z) CPU_AND(x, y, z)

void CPU_OR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_OR(x, y, z) CPU_OR(x, y, z)

void CPU_XOR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_XOR(x, y, z) CPU_XOR(x, y, z)

int CPU_COUNT_S(size_t, const cpu_set_t *) libcesque;
#define CPU_COUNT_S(x, y) CPU_COUNT_S(x, y)

#define CPU_ALLOC_SIZE(n) \
  ((((n) + (8 * sizeof(long) - 1)) & -(8 * sizeof(long))) / sizeof(long))

#define CPU_ALLOC(n)                  ((cpu_set_t *)calloc(1, CPU_ALLOC_SIZE(n)))
#define CPU_FREE(set)                 free(set)
#define CPU_ZERO_S(size, set)         memset(set, 0, size)
#define CPU_EQUAL_S(size, set1, set2) (!memcmp(set1, set2, size))
#define _CPU_S(i, size, set, op)                                              \
  ((i) / 8U >= (size) ? 0                                                     \
                      : (((unsigned long *)(set))[(i) / 8 / sizeof(long)] op( \
                            1UL << ((i) % (8 * sizeof(long))))))
#define CPU_SET_S(i, size, set)   _CPU_S(i, size, set, |=)
#define CPU_CLR_S(i, size, set)   _CPU_S(i, size, set, &= ~)
#define CPU_ISSET_S(i, size, set) _CPU_S(i, size, set, &)

typedef cpu_set_t cpuset_t; /* for freebsd compatibility */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/dirent.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_
COSMOPOLITAN_C_START_

struct dirent {      /* linux getdents64 abi */
  uint64_t d_ino;    /* inode number */
  int64_t d_off;     /* implementation-dependent location number */
  uint16_t d_reclen; /* byte length of this whole struct and string */
  uint8_t d_type;    /* DT_REG, DT_DIR, DT_UNKNOWN, DT_BLK, etc. */
  char d_name[256];  /* NUL-terminated basename */
};

struct dirstream;
typedef struct dirstream DIR;

DIR *fdopendir(int) libcesque __wur;
DIR *opendir(const char *) libcesque __wur;
int closedir(DIR *) libcesque;
int dirfd(DIR *) libcesque;
long telldir(DIR *) libcesque;
struct dirent *readdir(DIR *) libcesque;
int readdir_r(DIR *, struct dirent *, struct dirent **) libcesque;
void rewinddir(DIR *) libcesque;
void seekdir(DIR *, long) libcesque;
int alphasort(const struct dirent **, const struct dirent **) libcesque;
int versionsort(const struct dirent **, const struct dirent **) libcesque;
int scandir(const char *, struct dirent ***, int (*)(const struct dirent *),
            int (*)(const struct dirent **, const struct dirent **)) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/flock.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FLOCK_H_
COSMOPOLITAN_C_START_

struct flock {      /* cosmopolitan abi */
  int16_t l_type;   /* F_RDLCK, F_WRLCK, F_UNLCK */
  int16_t l_whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
  int64_t l_start;  /* starting offset */
  int64_t l_len;    /* no. bytes (0 means to end of file) */
  int32_t l_pid;    /* lock owner */
  int32_t l_sysid;  /* remote system id or zero for local (freebsd) */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/framebuffercolormap.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERCOLORMAP_H_

struct FrameBufferColorMap {
  uint32_t start;
  uint32_t len;
  uint16_t *red;
  uint16_t *green;
  uint16_t *blue;
  uint16_t *transp;
};



/*!BEGIN libc/calls/struct/framebufferfixedscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERFIXEDSCREENINFO_H_

struct FrameBufferFixedScreenInfo {
  char id[16];
  uint64_t smem_start;
  uint32_t smem_len;
  uint32_t type;
  uint32_t type_aux;
  uint32_t visual;
  uint16_t xpanstep;
  uint16_t ypanstep;
  uint16_t ywrapstep;
  uint32_t line_length;
  uint64_t mmio_start;
  uint32_t mmio_len;
  uint32_t accel;
  uint16_t capabilities;
  uint16_t reserved[2];
};



/*!BEGIN libc/calls/struct/framebuffervirtualscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERVIRTUALSCREENINFO_H_

struct FrameBufferBitField {
  uint32_t offset;
  uint32_t length;
  uint32_t msb_right;
};

struct FrameBufferVirtualScreenInfo {
  uint32_t xres;
  uint32_t yres;
  uint32_t xres_virtual;
  uint32_t yres_virtual;
  uint32_t xoffset;
  uint32_t yoffset;
  uint32_t bits_per_pixel;
  uint32_t grayscale;
  struct FrameBufferBitField red;
  struct FrameBufferBitField green;
  struct FrameBufferBitField blue;
  struct FrameBufferBitField transp;
  uint32_t nonstd;
  uint32_t activate;
  uint32_t height;
  uint32_t width;
  uint32_t accel_flags;
  uint32_t pixclock;
  uint32_t left_margin;
  uint32_t right_margin;
  uint32_t upper_margin;
  uint32_t lower_margin;
  uint32_t hsync_len;
  uint32_t vsync_len;
  uint32_t sync;
  uint32_t vmode;
  uint32_t rotate;
  uint32_t colorspace;
  uint32_t reserved[4];
};



/*!BEGIN libc/calls/struct/fsid.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FSID_H_
COSMOPOLITAN_C_START_

typedef struct fsid_t {
  uint32_t __val[2];
} fsid_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/iovec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct iovec {
  void *iov_base;
  size_t iov_len;
};

ssize_t preadv(int, struct iovec *, int, int64_t) libcesque;
ssize_t pwritev(int, const struct iovec *, int, int64_t) libcesque;
ssize_t readv(int, const struct iovec *, int) libcesque;
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t) libcesque;
ssize_t writev(int, const struct iovec *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/itimerval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_H_


/*!BEGIN libc/calls/struct/timeval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_


/*!BEGIN libc/calls/struct/timespec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct timespec {
  int64_t tv_sec;
  int64_t tv_nsec; /* nanoseconds */
};

int clock_getres(int, struct timespec *) libcesque;
int clock_gettime(int, struct timespec *) libcesque;
int clock_settime(int, const struct timespec *) libcesque;
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int futimens(int, const struct timespec[2]) libcesque;
int nanosleep(const struct timespec *, struct timespec *) libcesque;
int utimensat(int, const char *, const struct timespec[2], int) libcesque;
int timespec_getres(struct timespec *, int) libcesque;
int timespec_get(struct timespec *, int) libcesque;

#ifdef _COSMO_SOURCE
int sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int cosmo_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
#define timespec_zero ((struct timespec){0})
#define timespec_max  ((struct timespec){0x7fffffffffffffff, 999999999})
libcesque int timespec_cmp(struct timespec, struct timespec) pureconst;
libcesque int64_t timespec_tomicros(struct timespec) pureconst;
libcesque int64_t timespec_tomillis(struct timespec) pureconst;
libcesque int64_t timespec_tonanos(struct timespec) pureconst;
libcesque struct timespec timespec_add(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_fromnanos(int64_t) pureconst;
libcesque struct timespec timespec_frommicros(int64_t) pureconst;
libcesque struct timespec timespec_frommillis(int64_t) pureconst;
libcesque struct timespec timespec_real(void) libcesque;
libcesque struct timespec timespec_mono(void) libcesque;
libcesque struct timespec timespec_sleep(struct timespec) libcesque;
libcesque int timespec_sleep_until(struct timespec) libcesque;
libcesque struct timespec timespec_sub(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_subz(struct timespec,
                                        struct timespec) pureconst;
int sys_futex(int *, int, int, const struct timespec *, int *);
static inline struct timespec timespec_fromseconds(int64_t __x) {
  return (struct timespec){__x};
}
static inline int timespec_iszero(struct timespec __ts) {
  return !(__ts.tv_sec | __ts.tv_nsec);
}
static inline int timespec_isvalid(struct timespec __ts) {
  return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
}
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

struct timeval {
  int64_t tv_sec;
  int64_t tv_usec; /* microseconds */
};

int futimes(int, const struct timeval[2]);
int futimesat(int, const char *, const struct timeval[2]);
int gettimeofday(struct timeval *, struct timezone *);
int settimeofday(const struct timeval *, const struct timezone *);
int lutimes(const char *, const struct timeval[2]);
int utimes(const char *, const struct timeval[2]);

#ifdef _COSMO_SOURCE
/* cosmopolitan libc's non-posix timevals library
   removed by default due to emacs codebase clash */
#define timeval_zero ((struct timeval){0})
#define timeval_max  ((struct timeval){0x7fffffffffffffff, 999999})
int timeval_cmp(struct timeval, struct timeval) pureconst;
struct timeval timeval_real(void);
struct timeval timeval_frommicros(int64_t) pureconst;
struct timeval timeval_frommillis(int64_t) pureconst;
struct timeval timeval_add(struct timeval, struct timeval) pureconst;
struct timeval timeval_sub(struct timeval, struct timeval) pureconst;
struct timeval timeval_subz(struct timeval, struct timeval) pureconst;
int64_t timeval_toseconds(struct timeval);
int64_t timeval_tomicros(struct timeval);
int64_t timeval_tomillis(struct timeval);
struct timeval timespec_totimeval(struct timespec) pureconst;
static inline struct timeval timeval_fromseconds(int64_t __x) {
  return (struct timeval){__x};
}
static inline struct timespec timeval_totimespec(struct timeval __tv) {
  return (struct timespec){__tv.tv_sec, __tv.tv_usec * 1000};
}
static inline int timeval_iszero(struct timeval __tv) {
  return !(__tv.tv_sec | __tv.tv_usec);
}
static inline int timeval_isvalid(struct timeval __tv) {
  return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull;
}
#endif /* _COSMO_SOURCE */

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
#define timercmp(s, t, op)                                  \
  ((s)->tv_sec == (t)->tv_sec ? (s)->tv_usec op(t)->tv_usec \
                              : (s)->tv_sec op(t)->tv_sec)
#define timeradd(s, t, a)                                           \
  (void)((a)->tv_sec = (s)->tv_sec + (t)->tv_sec,                   \
         ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
             ((a)->tv_usec -= 1000000, (a)->tv_sec++))
#define timersub(s, t, a)                                    \
  (void)((a)->tv_sec = (s)->tv_sec - (t)->tv_sec,            \
         ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
             ((a)->tv_usec += 1000000, (a)->tv_sec--))
#endif

#ifdef _GNU_SOURCE
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
  ((ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0)
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
  ((tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0)
#endif

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct itimerval {
  struct timeval it_interval; /* {0,0} means singleshot */
  struct timeval it_value;    /* {0,0} means disarm */
};

int getitimer(int, struct itimerval *);
int setitimer(int, const struct itimerval *, struct itimerval *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/metasigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METASIGALTSTACK_H_


/*!BEGIN libc/calls/struct/sigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGALTSTACK_H_
COSMOPOLITAN_C_START_

struct sigaltstack {
  void *ss_sp;
  int ss_flags;
  size_t ss_size;
};

typedef struct sigaltstack stack_t;

int sigaltstack(const struct sigaltstack *, struct sigaltstack *) libcesque;

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct sigaltstack_bsd {
  void *ss_sp;
  uint64_t ss_size;
  int32_t ss_flags;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rlimit.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_
COSMOPOLITAN_C_START_

struct rlimit {
  uint64_t rlim_cur; /* current (soft) limit in bytes */
  uint64_t rlim_max; /* maximum limit in bytes */
};

int getrlimit(int, struct rlimit *) libcesque;
int setrlimit(int, const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rusage.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_
COSMOPOLITAN_C_START_

struct rusage {
  struct timeval ru_utime; /* user CPU time used */
  struct timeval ru_stime; /* system CPU time used */
  int64_t ru_maxrss;       /* maximum resident set size in (kb) */
  int64_t ru_ixrss;        /* shared memory size (integral kb CLK_TCK) */
  int64_t ru_idrss;        /* unshared data size (integral kb CLK_TCK) */
  int64_t ru_isrss;        /* unshared stack size (integral kb CLK_TCK) */
  int64_t ru_minflt;       /* page reclaims */
  int64_t ru_majflt;       /* page faults */
  int64_t ru_nswap;        /* swaps */
  int64_t ru_inblock;      /* block input operations */
  int64_t ru_oublock;      /* block output operations */
  int64_t ru_msgsnd;       /* IPC messages sent */
  int64_t ru_msgrcv;       /* IPC messages received */
  int64_t ru_nsignals;     /* signals received */
  int64_t ru_nvcsw;        /* voluntary context switches */
  int64_t ru_nivcsw;       /* involuntary context switches */
};

int getrusage(int, struct rusage *) libcesque;
int wait3(int *, int, struct rusage *) libcesque;
int wait4(int, int *, int, struct rusage *) libcesque;
void rusage_add(struct rusage *, const struct rusage *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sched_param.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SCHED_PARAM_H_
COSMOPOLITAN_C_START_

struct sched_param {
  int32_t sched_priority;
};

int sched_get_priority_max(int) libcesque;
int sched_get_priority_min(int) libcesque;
int sched_getparam(int, struct sched_param *) libcesque;
int sched_getscheduler(int) libcesque;
int sched_rr_get_interval(int, struct timespec *) libcesque;
int sched_setparam(int, const struct sched_param *) libcesque;
int sched_setscheduler(int, int, const struct sched_param *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigaction.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_


/*!BEGIN libc/calls/struct/siginfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_H_


/*!BEGIN libc/calls/struct/sigval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_
COSMOPOLITAN_C_START_

union sigval {
  int32_t sival_int;
  void *sival_ptr;
};

int sigqueue(int, int, const union sigval);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct siginfo {
  int32_t si_signo;
  int32_t si_errno;
  int32_t si_code; /* {SICODE,SEGV,ILL,FPE,POLL}_xxx */
  union {
    struct {
      union {
        struct {
          /* signals sent by kill() and sigqueue() set these */
          int32_t si_pid;
          uint32_t si_uid;
        };
        struct {
          /* SIGALRM sets these */
          int32_t si_timerid;
          int32_t si_overrun;
        };
      };
      union {
        union sigval si_value; /* provided by third arg of sigqueue(2) */
        struct {
          int32_t si_status;
          int64_t si_utime;
          int64_t si_stime;
        };
      };
    };
    struct {
      void *si_addr;
      int16_t si_addr_lsb;
      union {
        struct {
          void *si_lower;
          void *si_upper;
        };
        uint32_t si_pkey;
      };
    };
    struct {
      int64_t si_band; /* SIGPOLL */
      int32_t si_fd;
    };
    struct {
      void *si_call_addr;
      int32_t si_syscall;
      uint32_t si_arch;
    };
    char __ignoreme[128 - 2 * sizeof(int32_t) - sizeof(int64_t)];
  };
};

typedef struct siginfo siginfo_t;

#ifdef _COSMO_SOURCE
void __minicrash(int, siginfo_t *, void *) libcesque;
char __is_stack_overflow(siginfo_t *, void *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_
COSMOPOLITAN_C_START_

typedef uint64_t sigset_t;

int sigaddset(sigset_t *, int) paramsnonnull();
int sigdelset(sigset_t *, int) paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull();
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect;
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect;
int sigprocmask(int, const sigset_t *, sigset_t *);
int sigsuspend(const sigset_t *);
int sigpending(sigset_t *);
int pthread_sigmask(int, const sigset_t *, sigset_t *);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef void (*sighandler_t)(int);
typedef void (*sigaction_f)(int, struct siginfo *, void *);

struct sigaction {
  union {
    sighandler_t sa_handler;
    sigaction_f sa_sigaction;
  };
  uint64_t sa_flags;
  void (*sa_restorer)(void);
  sigset_t sa_mask;
};

sighandler_t signal(int, sighandler_t) libcesque;
int sigaction(int, const struct sigaction *, struct sigaction *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_H_
COSMOPOLITAN_C_START_

struct stat {              /* cosmo abi */
  uint64_t st_dev;         /* 0: id of device with file */
  uint64_t st_ino;         /* 8: inode number in disk b-tree */
  uint64_t st_nlink;       /* 16: hard link count */
  uint32_t st_mode;        /* 24: octal file mask thing */
  uint32_t st_uid;         /* 28: user id of owner */
  uint32_t st_gid;         /* group id of owning group */
  uint32_t st_flags;       /* nt/xnu/bsd-only */
  uint64_t st_rdev;        /* id of device if a special file */
  int64_t st_size;         /* bytes in file */
  int64_t st_blksize;      /* preferred chunking for underlying filesystem */
  int64_t st_blocks;       /* number of 512-byte pages allocated to file */
  struct timespec st_atim; /* access time */
  struct timespec st_mtim; /* modified time */
  struct timespec st_ctim; /* complicated time */
  struct timespec st_birthtim;
  uint64_t st_gen; /* xnu/bsd only */
};

int stat(const char *, struct stat *);
int lstat(const char *, struct stat *);
int fstat(int, struct stat *);
int fstatat(int, const char *, struct stat *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.macros.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_MACROS_H_

#define STAT_HAVE_NSEC 1

#define st_atime st_atim.tv_sec
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec

#define st_atime_nsec st_atim.tv_nsec
#define st_mtime_nsec st_mtim.tv_nsec
#define st_ctime_nsec st_ctim.tv_nsec

#define st_atimensec st_atim.tv_nsec
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
#define st_birthtime st_birthtim.tv_sec

#define st_file_attributes st_flags

#define INIT_STRUCT_STAT_PADDING(st) (void)st



/*!BEGIN libc/calls/struct/statfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
COSMOPOLITAN_C_START_

struct statfs {       /* cosmo abi */
  int64_t f_type;     /* type of filesystem */
  int64_t f_bsize;    /* optimal transfer block size */
  int64_t f_blocks;   /* total data blocks in filesystem */
  int64_t f_bfree;    /* free blocks in filesystem */
  int64_t f_bavail;   /* free blocks available to unprivileged users */
  int64_t f_files;    /* total file nodes in filesystem */
  int64_t f_ffree;    /* free file nodes in filesystem */
  fsid_t f_fsid;      /* filesystem id */
  int64_t f_namelen;  /* maximum length of filenames */
  int64_t f_frsize;   /* fragment size */
  int64_t f_flags;    /* mount flags of filesystem 2.6.36 */
  int64_t f_spare[4]; /* end of linux abi */
  uint32_t f_owner;
  char f_fstypename[16];
};

int statfs(const char *, struct statfs *) libcesque;
int fstatfs(int, struct statfs *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/statvfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
COSMOPOLITAN_C_START_

struct statvfs {
  unsigned long f_bsize;   /* Filesystem block size */
  unsigned long f_frsize;  /* Fragment size */
  uint64_t f_blocks;       /* Size of fs in f_frsize units */
  uint64_t f_bfree;        /* Number of free blocks */
  uint64_t f_bavail;       /* Number of free blocks for unprivileged users */
  uint64_t f_files;        /* Number of inodes */
  uint64_t f_ffree;        /* Number of free inodes */
  uint64_t f_favail;       /* Number of free inodes for unprivileged users */
  unsigned long f_fsid;    /* Filesystem ID */
  unsigned long f_flag;    /* Mount flags */
  unsigned long f_namemax; /* Maximum filename length */
};

int statvfs(const char *, struct statvfs *);
int fstatvfs(int, struct statvfs *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sysinfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_
COSMOPOLITAN_C_START_

struct sysinfo {
  int64_t uptime;     /* seconds since boot */
  uint64_t loads[3];  /* 1-5-15 min active process averages */
  uint64_t totalram;  /* system physical memory */
  uint64_t freeram;   /* amount of ram currently going to waste */
  uint64_t sharedram; /* bytes w/ pages mapped into multiple progs */
  uint64_t bufferram; /* lingering disk pages; see fadvise */
  uint64_t totalswap; /* size of emergency memory */
  uint64_t freeswap;  /* hopefully equal to totalswap */
  uint16_t procs;     /* number of processes */
  int16_t __ignore1;  /* padding */
  int32_t __ignore2;  /* padding */
  uint64_t totalhigh; /* wut */
  uint64_t freehigh;  /* wut */
  uint32_t mem_unit;  /* ram stuff above is multiples of this */
};

int sysinfo(struct sysinfo *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TERMIOS_H_

#define NCCS 20

COSMOPOLITAN_C_START_

struct termios {      /* cosmo abi */
  uint32_t c_iflag;   /* input modes */
  uint32_t c_oflag;   /* output modes */
  uint32_t c_cflag;   /* control modes */
  uint32_t c_lflag;   /* local modes */
  uint8_t c_cc[NCCS]; /* code mappings */
  uint32_t _c_ispeed; /* use cfgetispeed() and cfsetispeed() */
  uint32_t _c_ospeed; /* use cfgetospeed() and cfsetospeed() */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/tms.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_
COSMOPOLITAN_C_START_

struct tms {
  int64_t tms_utime;  /* userspace time */
  int64_t tms_stime;  /* kernelspace time */
  int64_t tms_cutime; /* children userspace time */
  int64_t tms_cstime; /* children kernelspace time */
};

long times(struct tms *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/user_regs_struct.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_USER_REGS_STRUCT_H_
COSMOPOLITAN_C_START_

/**
 * Linux Kernel user registers.
 *
 * @note superset of struct pt_regs
 * @see ptrace() w/ PTRACE_SYSCALL
 */
struct user_regs_struct {
  uint64_t r15;
  uint64_t r14;
  uint64_t r13;
  uint64_t r12;
  uint64_t rbp;
  uint64_t rbx;
  uint64_t r11;
  uint64_t r10;
  uint64_t r9;
  uint64_t r8;
  uint64_t rax;
  uint64_t rcx;
  uint64_t rdx;
  uint64_t rsi;
  uint64_t rdi;
  uint64_t orig_rax;
  uint64_t rip;
  uint64_t cs;
  uint64_t eflags;
  uint64_t rsp;
  uint64_t ss;
  uint64_t fs_base;
  uint64_t gs_base;
  uint64_t ds;
  uint64_t es;
  uint64_t fs;
  uint64_t gs;
};

struct useregs_struct_freebsd {
  int64_t r15;
  int64_t r14;
  int64_t r13;
  int64_t r12;
  int64_t r11;
  int64_t r10;
  int64_t r9;
  int64_t r8;
  int64_t rdi;
  int64_t rsi;
  int64_t rbp;
  int64_t rbx;
  int64_t rdx;
  int64_t rcx;
  int64_t rax;
  uint32_t trapno;
  uint16_t fs;
  uint16_t gs;
  uint32_t err;
  uint16_t es;
  uint16_t ds;
  int64_t rip;
  int64_t cs;
  int64_t rflags;
  int64_t rsp;
  int64_t ss;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/utsname.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UTSNAME_H_

#define SYS_NMLN 150

COSMOPOLITAN_C_START_

struct utsname {             /* cosmo abi */
  char sysname[SYS_NMLN];    /* name of os */
  char nodename[SYS_NMLN];   /* name of network node */
  char release[SYS_NMLN];    /* release level */
  char version[SYS_NMLN];    /* version level */
  char machine[SYS_NMLN];    /* hardware type */
  char domainname[SYS_NMLN]; /* domain name */
};

int uname(struct utsname *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/winsize.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_
COSMOPOLITAN_C_START_

struct winsize {
  uint16_t ws_row;
  uint16_t ws_col;
  uint16_t ws_xpixel;
  uint16_t ws_ypixel;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/cachestat.h */

#define COSMOPOLITAN_LIBC_CALLS_CACHESTAT_H_

COSMOPOLITAN_C_START_

struct cachestat_range {
  uint64_t off;
  uint64_t len;
};

struct cachestat {
  /** Number of cached pages. */
  uint64_t nr_cache;
  /** Number of dirty pages */
  uint64_t nr_dirty;
  /** Number of pages marked for writeback. */
  uint64_t nr_writeback;
  /** Number of pages evicted from the cache. */
  uint64_t nr_evicted;
  /**
   * Number of recently evicted pages.
   * A page is recently evicted if its last eviction was recent enough that its
   * reentry to the cache would indicate that it is actively being used by the
   * system, and that there is memory pressure on the system.
   */
  uint64_t nr_recently_evicted;
};

int cachestat(int, struct cachestat_range *, struct cachestat *, uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/calls.h */

#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_

#define _POSIX_VERSION  200809L
#define _POSIX2_VERSION _POSIX_VERSION
#define _XOPEN_VERSION  700

#define _POSIX_MAPPED_FILES               _POSIX_VERSION
#define _POSIX_FSYNC                      _POSIX_VERSION
#define _POSIX_IPV6                       _POSIX_VERSION
#define _POSIX_THREADS                    _POSIX_VERSION
#define _POSIX_THREAD_PROCESS_SHARED      _POSIX_VERSION
#define _POSIX_THREAD_SAFE_FUNCTIONS      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKADDR      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKSIZE      _POSIX_VERSION
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
#define _POSIX_THREAD_CPUTIME             _POSIX_VERSION
#define _POSIX_TIMEOUTS                   _POSIX_VERSION
#define _POSIX_MONOTONIC_CLOCK            _POSIX_VERSION
#define _POSIX_CPUTIME                    _POSIX_VERSION
#define _POSIX_BARRIERS                   _POSIX_VERSION
#define _POSIX_SPIN_LOCKS                 _POSIX_VERSION
#define _POSIX_READER_WRITER_LOCKS        _POSIX_VERSION
#define _POSIX_SEMAPHORES                 _POSIX_VERSION
#define _POSIX_SHARED_MEMORY_OBJECTS      _POSIX_VERSION
#define _POSIX_MEMLOCK_RANGE              _POSIX_VERSION
#define _POSIX_SPAWN                      _POSIX_VERSION

#define NSIG 64

#define SEEK_SET 0          /* relative to beginning */
#define SEEK_CUR 1          /* relative to current position */
#define SEEK_END 2          /* relative to end */
#define __WALL   0x40000000 /* Wait on all children, regardless of type */
#define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */

#define SIG_ERR ((void (*)(int))(-1))
#define SIG_DFL ((void (*)(int))0)
#define SIG_IGN ((void (*)(int))1)

#define CLOCKS_PER_SEC 1000000L

#define MAP_FAILED ((void *)-1)

#define WTERMSIG(x)     (127 & (x))
#define WCOREDUMP(x)    (128 & (x))
#define WIFEXITED(x)    (!WTERMSIG(x))
#define WEXITSTATUS(x)  ((x) >> 8)
#define WSTOPSIG(x)     ((0xff00 & (x)) >> 8)
#define WIFSTOPPED(x)   __wifstopped(x)
#define WIFSIGNALED(x)  __wifsignaled(x)
#define WIFCONTINUED(x) __wifcontinued(x)
#define W_STOPCODE(x)   ((x) << 8 | 0177)

#ifdef _COSMO_SOURCE
#define clone         __clone
#define commandv      __commandv
#define fileexists    __fileexists
#define ischardev     __ischardev
#define isdirectory   __isdirectory
#define isexecutable  __isexecutable
#define isregularfile __isregularfile
#define issymlink     __issymlink
#define makedirs      __makedirs
#define tmpfd         __tmpfd
#endif

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § system calls                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

typedef int sig_atomic_t;

bool32 isatty(int) libcesque;
char *getcwd(char *, size_t) dontthrow;
char *realpath(const char *, char *) libcesque __wur;
char *ttyname(int) libcesque;
int access(const char *, int) libcesque;
int chdir(const char *) libcesque;
int chmod(const char *, unsigned) libcesque;
int chown(const char *, unsigned, unsigned) libcesque;
int chroot(const char *) libcesque;
int close(int) libcesque;
int close_range(unsigned, unsigned, unsigned) libcesque;
int closefrom(int) libcesque;
int creat(const char *, unsigned) libcesque;
int dup(int) libcesque;
int dup2(int, int) libcesque;
int dup3(int, int, int) libcesque;
int execl(const char *, const char *, ...) nullterminated() libcesque;
int execle(const char *, const char *, ...) nullterminated((1)) libcesque;
int execlp(const char *, const char *, ...) nullterminated() libcesque;
int execv(const char *, char *const[]) libcesque;
int execve(const char *, char *const[], char *const[]) libcesque;
int execvp(const char *, char *const[]) libcesque;
int faccessat(int, const char *, int, int) libcesque;
int fchdir(int) libcesque;
int fchmod(int, unsigned) libcesque;
int fchmodat(int, const char *, unsigned, int) libcesque;
int fchown(int, unsigned, unsigned) libcesque;
int fchownat(int, const char *, unsigned, unsigned, int) libcesque;
int fcntl(int, int, ...) libcesque;
int fdatasync(int) libcesque;
int fexecve(int, char *const[], char *const[]) libcesque;
int flock(int, int) libcesque;
int fork(void) libcesque;
int fsync(int) libcesque;
int ftruncate(int, int64_t) libcesque;
int getdomainname(char *, size_t) libcesque;
int getgroups(int, unsigned[]) libcesque;
int gethostname(char *, size_t) libcesque;
int getloadavg(double *, int) libcesque;
int getpgid(int) libcesque;
int getpgrp(void) libcesque nosideeffect;
int getpid(void) libcesque nosideeffect;
int getppid(void) libcesque;
int getpriority(int, unsigned) libcesque;
int getsid(int) nosideeffect libcesque;
int ioctl(int, unsigned long, ...) libcesque;
int issetugid(void) libcesque;
int kill(int, int) libcesque;
int killpg(int, int) libcesque;
int lchmod(const char *, unsigned) libcesque;
int lchown(const char *, unsigned, unsigned) libcesque;
int link(const char *, const char *) libcesque;
int linkat(int, const char *, int, const char *, int) libcesque;
int mincore(void *, size_t, unsigned char *) libcesque;
int mkdir(const char *, unsigned) libcesque;
int mkdirat(int, const char *, unsigned) libcesque;
int mknod(const char *, unsigned, uint64_t) libcesque;
int nice(int) libcesque;
int open(const char *, int, ...) libcesque;
int openat(int, const char *, int, ...) libcesque;
int pause(void) libcesque;
int pipe(int[hasatleast 2]) libcesque;
int pipe2(int[hasatleast 2], int) libcesque;
int posix_fadvise(int, int64_t, int64_t, int) libcesque;
int posix_madvise(void *, uint64_t, int) libcesque;
int raise(int) libcesque;
int reboot(int) libcesque;
int remove(const char *) libcesque;
int rename(const char *, const char *) libcesque;
int renameat(int, const char *, int, const char *) libcesque;
int rmdir(const char *) libcesque;
int sched_yield(void) libcesque;
int setegid(unsigned) libcesque;
int seteuid(unsigned) libcesque;
int setfsgid(unsigned) libcesque;
int setfsuid(unsigned) libcesque;
int setgid(unsigned) libcesque;
int setgroups(size_t, const unsigned[]) libcesque;
int setpgid(int, int) libcesque;
int setpgrp(void) libcesque;
int setpriority(int, unsigned, int) libcesque;
int setregid(unsigned, unsigned) libcesque;
int setreuid(unsigned, unsigned) libcesque;
int setsid(void) libcesque;
int setuid(unsigned) libcesque;
int shm_open(const char *, int, unsigned) libcesque;
int shm_unlink(const char *) libcesque;
int sigignore(int) libcesque;
int siginterrupt(int, int) libcesque;
int symlink(const char *, const char *) libcesque;
int symlinkat(const char *, int, const char *) libcesque;
int tcgetpgrp(int) libcesque;
int tcsetpgrp(int, int) libcesque;
int truncate(const char *, int64_t) libcesque;
int ttyname_r(int, char *, size_t) libcesque;
int unlink(const char *) libcesque;
int unlinkat(int, const char *, int) libcesque;
int usleep(uint64_t) libcesque;
int vfork(void) libcesque returnstwice;
int wait(int *) libcesque;
int waitpid(int, int *, int) libcesque;
int64_t clock(void) libcesque;
int64_t time(int64_t *) libcesque;
ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned) libcesque;
ssize_t lseek(int, int64_t, int) libcesque;
ssize_t pread(int, void *, size_t, int64_t) libcesque;
ssize_t pwrite(int, const void *, size_t, int64_t) libcesque;
ssize_t read(int, void *, size_t) libcesque;
ssize_t readlink(const char *, char *, size_t) libcesque;
ssize_t readlinkat(int, const char *, char *, size_t) libcesque;
ssize_t write(int, const void *, size_t) libcesque;
unsigned alarm(unsigned) libcesque;
unsigned getegid(void) libcesque nosideeffect;
unsigned geteuid(void) libcesque nosideeffect;
unsigned getgid(void) libcesque nosideeffect;
unsigned getuid(void) libcesque;
unsigned sleep(unsigned) libcesque;
unsigned ualarm(unsigned, unsigned) libcesque;
unsigned umask(unsigned) libcesque;
void sync(void) libcesque;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
int syncfs(int) libcesque;
int prctl(int, ...) libcesque;
int gettid(void) libcesque;
int setresgid(unsigned, unsigned, unsigned) libcesque;
int setresuid(unsigned, unsigned, unsigned) libcesque;
int getresgid(unsigned *, unsigned *, unsigned *) libcesque;
int getresuid(unsigned *, unsigned *, unsigned *) libcesque;
char *get_current_dir_name(void) libcesque __wur;
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned) libcesque;
int memfd_create(const char *, unsigned int) libcesque;
int execvpe(const char *, char *const[], char *const[]) libcesque;
int euidaccess(const char *, int) libcesque;
int eaccess(const char *, int) libcesque;
int madvise(void *, uint64_t, int) libcesque;
int getcpu(unsigned *, unsigned *) libcesque;
#endif

#ifdef _COSMO_SOURCE
bool32 fdexists(int) libcesque;
bool32 fileexists(const char *) libcesque;
bool32 ischardev(int) libcesque;
bool32 isdirectory(const char *) libcesque;
bool32 isexecutable(const char *) libcesque;
bool32 isregularfile(const char *) libcesque;
bool32 issymlink(const char *) libcesque;
char *commandv(const char *, char *, size_t) libcesque;
int __getcwd(char *, size_t) libcesque;
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
int fadvise(int, uint64_t, uint64_t, int) libcesque;
int makedirs(const char *, unsigned) libcesque;
int pivot_root(const char *, const char *) libcesque;
int pledge(const char *, const char *) libcesque;
int seccomp(unsigned, unsigned, void *) libcesque;
int sys_iopl(int) libcesque;
int sys_ioprio_get(int, int) libcesque;
int sys_ioprio_set(int, int, int) libcesque;
int sys_mlock(const void *, size_t) libcesque;
int sys_mlock2(const void *, size_t, int) libcesque;
int sys_mlockall(int) libcesque;
int sys_munlock(const void *, size_t) libcesque;
int sys_munlockall(void) libcesque;
int sys_personality(uint64_t) libcesque;
int sys_ptrace(int, ...) libcesque;
int sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque;
int sysctlbyname(const char *, void *, size_t *, void *, size_t) libcesque;
int sysctlnametomib(const char *, int *, size_t *) libcesque;
int tmpfd(void) libcesque;
int touch(const char *, unsigned) libcesque;
int unveil(const char *, const char *) libcesque;
long ptrace(int, ...) libcesque;
ssize_t copyfd(int, int, size_t) libcesque;
ssize_t readansi(int, char *, size_t) libcesque;
ssize_t tinyprint(int, const char *, ...) libcesque nullterminated();
void shm_path_np(const char *, char[hasatleast 78]) libcesque;
#endif /* _COSMO_SOURCE */

int system(const char *) libcesque;

int __wifstopped(int) libcesque pureconst;
int __wifcontinued(int) libcesque pureconst;
int __wifsignaled(int) libcesque pureconst;

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define lseek64     lseek
#define pread64     pread
#define pwrite64    pwrite
#define truncate64  truncate
#define ftruncate64 ftruncate
#define lockf64     lockf
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ipc.h */

#define COSMOPOLITAN_LIBC_CALLS_IPC_H_

#define IPC_PRIVATE 0
#define IPC_RMID    0
#define IPC_SET     1
#define IPC_STAT    2
#define IPC_INFO    3
#define IPC_CREAT   01000
#define IPC_EXCL    02000
#define IPC_NOWAIT  04000

COSMOPOLITAN_C_START_

int ftok(const char *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/landlock.h */

#define COSMOPOLITAN_LIBC_CALLS_LANDLOCK_H_

#define LANDLOCK_CREATE_RULESET_VERSION 0x0001ul

#define LANDLOCK_ACCESS_FS_EXECUTE     0x0001ul
#define LANDLOCK_ACCESS_FS_WRITE_FILE  0x0002ul
#define LANDLOCK_ACCESS_FS_READ_FILE   0x0004ul
#define LANDLOCK_ACCESS_FS_READ_DIR    0x0008ul
#define LANDLOCK_ACCESS_FS_REMOVE_DIR  0x0010ul
#define LANDLOCK_ACCESS_FS_REMOVE_FILE 0x0020ul
#define LANDLOCK_ACCESS_FS_MAKE_CHAR   0x0040ul
#define LANDLOCK_ACCESS_FS_MAKE_DIR    0x0080ul
#define LANDLOCK_ACCESS_FS_MAKE_REG    0x0100ul
#define LANDLOCK_ACCESS_FS_MAKE_SOCK   0x0200ul
#define LANDLOCK_ACCESS_FS_MAKE_FIFO   0x0400ul
#define LANDLOCK_ACCESS_FS_MAKE_BLOCK  0x0800ul
#define LANDLOCK_ACCESS_FS_MAKE_SYM    0x1000ul

/**
 * Allow renaming or linking file to a different directory.
 *
 * @see https://lore.kernel.org/r/20220329125117.1393824-8-mic@digikod.net
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 2+
 */
#define LANDLOCK_ACCESS_FS_REFER 0x2000ul

/**
 * Control file truncation.
 *
 * @see
 * https://lore.kernel.org/all/20221018182216.301684-1-gnoack3000@gmail.com/
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 3+
 */
#define LANDLOCK_ACCESS_FS_TRUNCATE 0x4000ul

COSMOPOLITAN_C_START_

enum landlock_rule_type {
  LANDLOCK_RULE_PATH_BENEATH = 1,
};

struct landlock_ruleset_attr {
  uint64_t handled_access_fs;
};

struct thatispacked landlock_path_beneath_attr {
  uint64_t allowed_access;
  int32_t parent_fd;
};

int landlock_restrict_self(int, uint32_t);
int landlock_add_rule(int, enum landlock_rule_type, const void *, uint32_t);
int landlock_create_ruleset(const struct landlock_ruleset_attr *, size_t,
                            uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/makedev.h */

#define COSMOPOLITAN_LIBC_CALLS_MAKEDEV_H_

uint64_t makedev(uint32_t, uint32_t) libcesque;
uint32_t major(uint64_t) libcesque;
uint32_t minor(uint64_t) libcesque;

#define major(x)      major(x)
#define minor(x)      minor(x)
#define makedev(x, y) makedev(x, y)



/*!BEGIN libc/calls/mount.h */

#define COSMOPOLITAN_LIBC_CALLS_MOUNT_H_
COSMOPOLITAN_C_START_

int mount(const char *, const char *, const char *, unsigned long,
          const void *);
int unmount(const char *, int);

#ifdef _GNU_SOURCE
int umount(const char *);
int umount2(const char *, int);
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/pledge.h */

#define COSMOPOLITAN_LIBC_CALLS_PLEDGE_H_

#define PLEDGE_PENALTY_KILL_THREAD  0x0000
#define PLEDGE_PENALTY_KILL_PROCESS 0x0001
#define PLEDGE_PENALTY_RETURN_EPERM 0x0002
#define PLEDGE_PENALTY_MASK         0x000f
#define PLEDGE_STDERR_LOGGING       0x0010

COSMOPOLITAN_C_START_

extern int __pledge_mode;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/sigtimedwait.h */

#define COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_H_
COSMOPOLITAN_C_START_

int sigwait(const sigset_t *, int *);
int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *);
int sigwaitinfo(const sigset_t *, siginfo_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_H_
COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § teletypewriter control                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int tcgetattr(int, struct termios *) libcesque;
int tcsetattr(int, int, const struct termios *) libcesque;

int openpty(int *, int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2));
int forkpty(int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2)) __wur;
char *ptsname(int) libcesque;
errno_t ptsname_r(int, char *, size_t) libcesque;

int grantpt(int) libcesque;
int unlockpt(int) libcesque;
int posix_openpt(int) libcesque __wur;

int tcdrain(int) libcesque;
int tcgetsid(int) libcesque;
int tcflow(int, int) libcesque;
int tcflush(int, int) libcesque;
int tcsetsid(int, int) libcesque;
int tcsendbreak(int, int) libcesque;
void cfmakeraw(struct termios *) libcesque;
int cfsetspeed(struct termios *, uint32_t) libcesque;
int cfsetospeed(struct termios *, uint32_t) libcesque;
int cfsetispeed(struct termios *, uint32_t) libcesque;
uint32_t cfgetospeed(const struct termios *) libcesque;
uint32_t cfgetispeed(const struct termios *) libcesque;
int tcsetwinsize(int, const struct winsize *) libcesque;
int tcgetwinsize(int, struct winsize *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ttydefaults.h */

#define COSMOPOLITAN_LIBC_CALLS_TTYDEFAULTS_H_


/*!BEGIN libc/sysv/consts/termios.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TERMIOS_H_
COSMOPOLITAN_C_START_

#define EXTA B19200
#define EXTB B38400

extern const int _POSIX_VDISABLE;
extern const uint32_t BRKINT;
extern const uint32_t BS1;
extern const uint32_t BS2;
extern const uint32_t BSDLY;
extern const uint32_t CLOCAL;
extern const uint32_t CMSPAR;
extern const uint32_t CR1;
extern const uint32_t CR2;
extern const uint32_t CR3;
extern const uint32_t CRDLY;
extern const uint32_t CREAD;
extern const uint32_t CS5;
extern const uint32_t CS6;
extern const uint32_t CS7;
extern const uint32_t CS8;
extern const uint32_t CSIZE;
extern const uint32_t CSTOPB;
extern const uint32_t ECHOCTL;
extern const uint32_t ECHOE;
extern const uint32_t ECHOK;
extern const uint32_t ECHOKE;
extern const uint32_t ECHONL;
extern const uint32_t ECHOPRT;
extern const long EXTPROC;
extern const uint32_t FF1;
extern const uint32_t FF2;
extern const uint32_t FFDLY;
extern const uint32_t FLUSHO;
extern const uint32_t HUPCL;
extern const uint32_t ICANON;
extern const uint32_t ICRNL;
extern const uint32_t IEXTEN;
extern const uint32_t IGNBRK;
extern const uint32_t IGNCR;
extern const uint32_t IGNPAR;
extern const uint32_t IMAXBEL;
extern const uint32_t INLCR;
extern const uint32_t INPCK;
extern const uint32_t ISIG;
extern const uint32_t ISTRIP;
extern const uint32_t IUCLC;
extern const uint32_t IUTF8;
extern const uint32_t IXANY;
extern const uint32_t IXOFF;
extern const uint32_t IXON;
extern const uint32_t NL1;
extern const uint32_t NL2;
extern const uint32_t NL3;
extern const uint32_t NLDLY;
extern const uint32_t NOFLSH;
extern const uint32_t OCRNL;
extern const uint32_t OFDEL;
extern const uint32_t OFILL;
extern const uint32_t OLCUC;
extern const uint32_t ONLCR;
extern const uint32_t ONLRET;
extern const uint32_t ONOCR;
extern const uint32_t OPOST;
extern const uint32_t PARENB;
extern const uint32_t PARMRK;
extern const uint32_t PARODD;
extern const uint32_t PENDIN;
extern const uint32_t TAB1;
extern const uint32_t TAB2;
extern const uint32_t TAB3;
extern const uint32_t TABDLY;
extern const uint64_t TIOCCONS;
extern const uint64_t TIOCGETD;
extern const uint64_t TIOCGWINSZ;
extern const uint64_t TIOCNOTTY;
extern const uint64_t TIOCNXCL;
extern const uint64_t TIOCOUTQ;
extern const uint64_t TIOCSCTTY;
extern const uint64_t TIOCSETD;
extern const uint64_t TIOCSIG;
extern const uint64_t TIOCSPGRP;
extern const uint64_t TIOCSTI;
extern const uint64_t TIOCSWINSZ;
extern const long TOSTOP;
extern const uint8_t VDISCARD;
extern const uint8_t VEOF;
extern const uint8_t VEOL2;
extern const uint8_t VEOL;
extern const uint8_t VERASE;
extern const uint8_t VINTR;
extern const uint8_t VKILL;
extern const uint8_t VLNEXT;
extern const uint8_t VMIN;
extern const uint8_t VQUIT;
extern const uint8_t VREPRINT;
extern const uint8_t VSTART;
extern const uint8_t VSTOP;
extern const uint8_t VSUSP;
extern const uint8_t VSWTC;
extern const uint32_t VT1;
extern const uint32_t VT2;
extern const uint32_t VTDLY;
extern const uint8_t VTIME;
extern const uint8_t VWERASE;
extern const uint32_t XCASE;
extern const uint32_t XTABS;
extern const uint32_t CRTSCTS;

#define BRKINT  0x02
#define ICRNL   0x0100
#define IGNBRK  0x01
#define IGNCR   0x80
#define IGNPAR  0x04
#define IMAXBEL 0x2000
#define INLCR   0x40
#define INPCK   0x10
#define ISTRIP  0x20
#define IXANY   0x0800
#define OPOST   0x01
#define PARMRK  0x08

#define _POSIX_VDISABLE _POSIX_VDISABLE

#define NLDLY   NLDLY
#define NL0     0
#define NL1     NL1
#define NL2     NL2
#define NL3     NL3
#define CRDLY   CRDLY
#define CR0     0
#define CR1     CR1
#define CR2     CR2
#define CR3     CR3
#define TABDLY  TABDLY
#define TAB0    0
#define TAB1    TAB1
#define TAB2    TAB2
#define TAB3    TAB3
#define XTABS   XTABS
#define CRTSCTS CRTSCTS
#define BSDLY   BSDLY
#define BS0     0
#define BS1     BS1
#define BS2     BS2
#define VTDLY   VTDLY
#define VT0     0
#define VT1     VT1
#define VT2     VT2
#define FFDLY   FFDLY
#define FF0     0
#define FF1     FF1
#define FF2     FF2

#define CLOCAL   CLOCAL
#define CREAD    CREAD
#define CS5      CS5
#define CS6      CS6
#define CS7      CS7
#define CS8      CS8
#define CSIZE    CSIZE
#define CSTOPB   CSTOPB
#define ECHO     8
#define ECHOCTL  ECHOCTL
#define ECHOE    ECHOE
#define ECHOK    ECHOK
#define ECHOKE   ECHOKE
#define ECHONL   ECHONL
#define ECHOPRT  ECHOPRT
#define EXTPROC  EXTPROC
#define FLUSHO   FLUSHO
#define HUPCL    HUPCL
#define ICANON   ICANON
#define IEXTEN   IEXTEN
#define ISIG     ISIG
#define IUCLC    IUCLC
#define IUTF8    IUTF8
#define IXOFF    IXOFF
#define IXON     IXON
#define NOFLSH   NOFLSH
#define OCRNL    OCRNL
#define OFDEL    OFDEL
#define OFILL    OFILL
#define OLCUC    OLCUC
#define ONLCR    ONLCR
#define ONLRET   ONLRET
#define ONOCR    ONOCR
#define PARENB   PARENB
#define PARODD   PARODD
#define PENDIN   PENDIN
#define TOSTOP   TOSTOP
#define VDISCARD VDISCARD
#define VEOF     VEOF
#define VEOL     VEOL
#define VEOL2    VEOL2
#define VERASE   VERASE
#define VINTR    VINTR
#define VKILL    VKILL
#define VLNEXT   VLNEXT
#define VMIN     VMIN
#define VQUIT    VQUIT
#define VREPRINT VREPRINT
#define VSTART   VSTART
#define VSTOP    VSTOP
#define VSUSP    VSUSP
#define VSWTC    VSWTC
#define VTIME    VTIME
#define VWERASE  VWERASE
#define XCASE    XCASE

/* terminal ioctls */
#define TIOCGWINSZ TIOCGWINSZ /* get tty dimensions */
#define TIOCSWINSZ TIOCSWINSZ /* set tty dimensions */
#define TIOCCONS   TIOCCONS   /* redirect terminal */
#define TIOCGETD   TIOCGETD   /* get line discipline */
#define TIOCSETD   TIOCSETD   /* set line discipline */
#define TIOCNOTTY  TIOCNOTTY  /* give up terminal */
#define TIOCNXCL   TIOCNXCL   /* disable exclusive mode */
#define TIOCOUTQ   TIOCOUTQ   /* bytes in output buffer */
#define TIOCSCTTY  TIOCSCTTY  /* make controlling terminal */
#define TIOCSIG    TIOCSIG    /* generate pty signal */
#define TIOCSTI    TIOCSTI    /* insert fake tty input */

/* tcsetattr() */
#define TCSANOW   0
#define TCSAFLUSH 2
#define TCSADRAIN 1
extern const unsigned long TCGETS; /* use tcgetattr() */
extern const unsigned long TCSETS; /* use tcsetattr() */

/* tcflush() */
extern const int TCIFLUSH;
extern const int TCOFLUSH;
extern const int TCIOFLUSH;
#define TCIFLUSH  TCIFLUSH
#define TCOFLUSH  TCOFLUSH
#define TCIOFLUSH TCIOFLUSH

/* tcflow() */
#define TCOOFF 0
#define TCOON  1
#define TCIOFF 2
#define TCION  3

COSMOPOLITAN_C_END_

#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS)
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE | ECHOKE | ECHOCTL)
#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
#define TTYDEF_SPEED (B9600)

#define CTRL(x)  ((x) ^ 0100)
#define CEOF     CTRL('D')
#define CERASE   CTRL('?')
#define CINTR    CTRL('C')
#define CKILL    CTRL('U')
#define CQUIT    CTRL('\\')
#define CSUSP    CTRL('Z')
#define CDSUSP   CTRL('Y')
#define CSTART   CTRL('Q')
#define CSTOP    CTRL('S')
#define CLNEXT   CTRL('V')
#define CDISCARD CTRL('O')
#define CWERASE  CTRL('W')
#define CREPRINT CTRL('R')
#define CEOT     CEOF
#define CBRK     CEOL
#define CRPRNT   CREPRINT
#define CFLUSH   CDISCARD
#define CEOL     255
#define CMIN     1
#define CTIME    0



/*!BEGIN libc/calls/ucontext.h */

#define COSMOPOLITAN_LIBC_CALLS_UCONTEXT_H_
COSMOPOLITAN_C_START_

#ifdef __x86_64__

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define REG_R8      0
#define REG_R9      1
#define REG_R10     2
#define REG_R11     3
#define REG_R12     4
#define REG_R13     5
#define REG_R14     6
#define REG_R15     7
#define REG_RDI     8
#define REG_RSI     9
#define REG_RBP     10
#define REG_RBX     11
#define REG_RDX     12
#define REG_RAX     13
#define REG_RCX     14
#define REG_RSP     15
#define REG_RIP     16
#define REG_EFL     17
#define REG_CSGSFS  18
#define REG_ERR     19
#define REG_TRAPNO  20
#define REG_OLDMASK 21
#define REG_CR2     22
#endif

struct XmmRegister {
  uint64_t u64[2];
};

struct FpuStackEntry {
  uint16_t significand[4];
  uint16_t exponent;
  uint16_t padding[3];
};

struct thatispacked FpuState {

  /* 8087 FPU Control Word
      IM: Invalid Operation ───────────────┐
      DM: Denormal Operand ───────────────┐│
      ZM: Zero Divide ───────────────────┐││
      OM: Overflow ─────────────────────┐│││
      UM: Underflow ───────────────────┐││││
      PM: Precision ──────────────────┐│││││
      PC: Precision Control ───────┐  ││││││
       {float,∅,double,long double}│  ││││││
      RC: Rounding Control ──────┐ │  ││││││
       {even, →-∞, →+∞, →0}      │┌┤  ││││││
                                ┌┤││  ││││││
                               d││││rr││││││
                          0b0000001001111111 */
  uint16_t cwd;

  /* 8087 FPU Status Word */
  uint16_t swd;

  uint16_t ftw;
  uint16_t fop;
  uint64_t rip;
  uint64_t rdp;

  /* SSE CONTROL AND STATUS REGISTER
     IE: Invalid Operation Flag ──────────────┐
     DE: Denormal Flag ──────────────────────┐│
     ZE: Divide-by-Zero Flag ───────────────┐││
     OE: Overflow Flag ────────────────────┐│││
     UE: Underflow Flag ──────────────────┐││││
     PE: Precision Flag ─────────────────┐│││││
     DAZ: Denormals Are Zeros ──────────┐││││││
     IM: Invalid Operation Mask ───────┐│││││││
     DM: Denormal Operation Mask ─────┐││││││││
     ZM: Divide-by-Zero Mask ────────┐│││││││││
     OM: Overflow Mask ─────────────┐││││││││││
     UM: Underflow Mask ───────────┐│││││││││││
     PM: Precision Mask ──────────┐││││││││││││
     RC: Rounding Control ───────┐│││││││││││││
       {even, →-∞, →+∞, →0}      ││││││││││││││
     FTZ: Flush To Zero ───────┐ ││││││││││││││
                               │┌┤│││││││││││││
               ┌──────────────┐││││││││││││││││
               │   reserved   │││││││││││││││││
             0b00000000000000000001111110000000 */
  uint32_t mxcsr;
  uint32_t mxcr_mask;

  struct FpuStackEntry st[8];
  struct XmmRegister xmm[16];
  uint32_t __padding[24];
};

typedef long long greg_t;
typedef greg_t gregset_t[23];
typedef struct FpuState *fpregset_t;

#endif /* __x86_64__ */

struct sigcontext {
#ifdef __x86_64__
  union {
    struct {
      uint64_t r8;     /* 40 */
      uint64_t r9;     /* 48 */
      uint64_t r10;    /* 56 */
      uint64_t r11;    /* 64 */
      uint64_t r12;    /* 72 */
      uint64_t r13;    /* 80 */
      uint64_t r14;    /* 88 */
      uint64_t r15;    /* 96 */
      uint64_t rdi;    /* 104 */
      uint64_t rsi;    /* 112 */
      uint64_t rbp;    /* 120 */
      uint64_t rbx;    /* 128 */
      uint64_t rdx;    /* 136 */
      uint64_t rax;    /* 144 */
      uint64_t rcx;    /* 152 */
      uint64_t rsp;    /* 160 */
      uint64_t rip;    /* 168 */
      uint64_t eflags; /* 176 */
      uint16_t cs;
      uint16_t gs;
      uint16_t fs;
      uint16_t __pad0;
      uint64_t err;
      uint64_t trapno;
      uint64_t oldmask;
      uint64_t cr2;
    };
    gregset_t gregs;
  };
  struct FpuState *fpregs; /* zero when no fpu context */
  uint64_t __pad1[8];
#elif defined(__aarch64__)
  uint64_t fault_address;
  uint64_t regs[31];
  uint64_t sp;
  uint64_t pc;
  uint64_t pstate;
  uint8_t __reserved[4096] __attribute__((__aligned__(16)));
#endif /* __x86_64__ */
};

typedef struct sigcontext mcontext_t;

struct ucontext {
  uint64_t uc_flags; /* don't use this */
  struct ucontext *uc_link;
  stack_t uc_stack;
#ifdef __x86_64__
  struct sigcontext uc_mcontext;
  sigset_t uc_sigmask;
  uint64_t __pad[2];
  struct FpuState __fpustate; /* for cosmo on non-linux */
#elif defined(__aarch64__)
  sigset_t uc_sigmask;
  uint8_t __unused[1024 / 8];
  struct sigcontext uc_mcontext;
#endif
} forcealign(16);

typedef struct ucontext ucontext_t;

int getcontext(ucontext_t *) dontthrow;
int setcontext(const ucontext_t *) dontthrow;
int swapcontext(ucontext_t *, const ucontext_t *) dontthrow returnstwice;
void makecontext(ucontext_t *, void *, int, ...) dontthrow dontcallback;
void __sig_restore(const ucontext_t *) wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/weirdtypes.h */

#define COSMOPOLITAN_LIBC_CALLS_WEIRDTYPES_H_

/**
 * @fileoverview Types we'd prefer hadn't been invented.
 */

typedef int64_t blkcnt_t;
typedef uint8_t cc_t;
typedef int64_t clock_t; /* uint64_t on xnu */
typedef uint64_t dev_t;  /* int32_t on xnu */
typedef uint64_t fsblkcnt_t;
typedef int64_t fsfilcnt_t; /* uint32_t on xnu */
typedef uint32_t gid_t;
typedef int32_t id_t; /* int32_t on linux/freebsd/etc. */
typedef uint32_t in_addr_t;
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
typedef uint64_t ino_t;
typedef int32_t key_t;
typedef int64_t loff_t;
typedef uint32_t mode_t; /* uint16_t on xnu */
typedef uint64_t nfds_t;
typedef int64_t off_t;
typedef int32_t pid_t;
typedef int64_t register_t;
typedef uint16_t sa_family_t; /* bsd:uint8_t */
typedef uint32_t socklen_t;
typedef uint32_t speed_t;
typedef uint32_t suseconds_t;
typedef uint64_t useconds_t;   /* uint32_t on xnu */
typedef int64_t syscall_arg_t; /* uint64_t on xnu */
typedef uint32_t tcflag_t;
typedef int64_t time_t;
typedef void *timer_t;
typedef uint32_t uid_t;
typedef uint64_t rlim_t; /* int64_t on bsd */
typedef int32_t clockid_t;

#ifdef __x86_64__
typedef int64_t blksize_t; /* int32_t on xnu */
typedef uint64_t nlink_t;
#elif defined(__aarch64__)
typedef int32_t blksize_t;
typedef uint32_t nlink_t; /* uint16_t on xnu */
#endif

#define TIME_T_MAX __INT64_MAX__
#define TIME_T_MIN (-TIME_T_MAX - 1)

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define F_GETLK64         F_GETLK
#define F_SETLK64         F_SETLK
#define F_SETLKW64        F_SETLKW
#define RLIM64_INFINITY   RLIM_INFINITY
#define RLIM64_SAVED_CUR  RLIM_SAVED_CUR
#define RLIM64_SAVED_MAX  RLIM_SAVED_MAX
#define alphasort64       alphasort
#define blkcnt64_t        blkcnt_t
#define dirent64          dirent
#define flock64           flock
#define fsfilcnt64_t      fsfilcnt_t
#define fstat64           fstat
#define fstatat64         fstatat
#define fstatfs64         fstatfs
#define fstatvfs64        fstatvfs
#define getrlimit64       getrlimit
#define ino64_t           ino_t
#define lockf64           lockf
#define lstat64           lstat
#define mmap64            mmap
#define off64_t           off_t
#define open64            open
#define openat64          openat
#define posix_fadvise64   posix_fadvise
#define posix_fallocate64 posix_fallocate
#define readdir64         readdir
#define readdir64_r       readdir_r
#define rlim64_t          rlim_t
#define rlimit64          rlimit
#define scandir64         scandir
#define sendfile64        sendfile
#define setrlimit64       setrlimit
#define stat64            stat
#define statfs64          statfs
#define statvfs64         statvfs
#define versionsort64     versionsort
#endif



/*!BEGIN libc/elf/def.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DEF_H_

/**
 * @fileoverview Executable and Linkable Format Definitions.
 */

#define EI_NIDENT 16

#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3

#define ELFMAG  "\177ELF"
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define SELFMAG 4

#define EI_CLASS     4
#define ELFCLASSNONE 0
#define ELFCLASS32   1
#define ELFCLASS64   2
#define ELFCLASSNUM  3

#define EI_DATA     5
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define ELFDATANUM  3

#define EI_VERSION 6

#define EI_OSABI            7
#define ELFOSABI_NONE       0
#define ELFOSABI_SYSV       0
#define ELFOSABI_HPUX       1
#define ELFOSABI_NETBSD     2
#define ELFOSABI_LINUX      3
#define ELFOSABI_GNU        3
#define ELFOSABI_SOLARIS    6
#define ELFOSABI_AIX        7
#define ELFOSABI_IRIX       8
#define ELFOSABI_FREEBSD    9
#define ELFOSABI_TRU64      10
#define ELFOSABI_MODESTO    11
#define ELFOSABI_OPENBSD    12
#define ELFOSABI_ARM        97
#define ELFOSABI_STANDALONE 255

#define EI_ABIVERSION 8

#define EI_PAD 9

#define ET_NONE   0
#define ET_REL    1
#define ET_EXEC   2
#define ET_DYN    3
#define ET_CORE   4
#define ET_NUM    5
#define ET_LOOS   0xfe00
#define ET_HIOS   0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff

#define EM_NONE      0
#define EM_M32       1
#define EM_386       3
#define EM_PPC64     21
#define EM_S390      22
#define EM_ARM       40
#define EM_NEXGEN32E 62
#define EM_X86_64    EM_NEXGEN32E
#define EM_IA32E     EM_NEXGEN32E
#define EM_AMD64     EM_NEXGEN32E
#define EM_PDP11     65
#define EM_CRAYNV2   172
#define EM_L10M      180
#define EM_K10M      181
#define EM_AARCH64   183
#define EM_CUDA      190
#define EM_Z80       220
#define EM_RISCV     243
#define EM_BPF       247

/* the ape flag, "lol cat 5" */
#define EF_APE_MODERN      0x101ca75
#define EF_APE_MODERN_MASK 0x1ffffff

#define GRP_COMDAT 1
#define STN_UNDEF  0

#define EV_NONE    0
#define EV_CURRENT 1
#define EV_NUM     2

#define SYMINFO_NONE          0
#define SYMINFO_CURRENT       1
#define SYMINFO_NUM           2
#define SYMINFO_BT_SELF       0xffff
#define SYMINFO_BT_PARENT     0xfffe
#define SYMINFO_BT_LOWRESERVE 0xff00
#define SYMINFO_FLG_DIRECT    0x0001
#define SYMINFO_FLG_PASSTHRU  0x0002
#define SYMINFO_FLG_COPY      0x0004
#define SYMINFO_FLG_LAZYLOAD  0x0008

#define PT_NULL         0
#define PT_LOAD         1
#define PT_DYNAMIC      2
#define PT_INTERP       3
#define PT_NOTE         4
#define PT_SHLIB        5
#define PT_PHDR         6
#define PT_TLS          7
#define PT_NUM          8
#define PT_LOOS         0x60000000
#define PT_GNU_EH_FRAME 0x6474e550
#define PT_GNU_STACK    0x6474e551
#define PT_GNU_RELRO    0x6474e552
#define PT_LOSUNW       0x6ffffffa
#define PT_SUNWBSS      0x6ffffffa
#define PT_SUNWSTACK    0x6ffffffb
#define PT_HISUNW       0x6fffffff
#define PT_HIOS         0x6fffffff
#define PT_LOPROC       0x70000000
#define PT_HIPROC       0x7fffffff

#define PN_XNUM 0xffff

#define PF_X        1
#define PF_W        2
#define PF_R        4
#define PF_MASKOS   0x0ff00000
#define PF_MASKPROC 0xf0000000

#define R_X86_64_NONE            0
#define R_X86_64_64              1
#define R_X86_64_PC32            2
#define R_X86_64_GOT32           3
#define R_X86_64_PLT32           4
#define R_X86_64_COPY            5
#define R_X86_64_GLOB_DAT        6
#define R_X86_64_JUMP_SLOT       7
#define R_X86_64_RELATIVE        8
#define R_X86_64_GOTPCREL        9
#define R_X86_64_32              10
#define R_X86_64_32S             11
#define R_X86_64_16              12
#define R_X86_64_PC16            13
#define R_X86_64_8               14
#define R_X86_64_PC8             15
#define R_X86_64_DTPMOD64        16
#define R_X86_64_DTPOFF64        17
#define R_X86_64_TPOFF64         18
#define R_X86_64_TLSGD           19
#define R_X86_64_TLSLD           20
#define R_X86_64_DTPOFF32        21
#define R_X86_64_GOTTPOFF        22
#define R_X86_64_TPOFF32         23
#define R_X86_64_PC64            24
#define R_X86_64_GOTOFF64        25
#define R_X86_64_GOTPC32         26
#define R_X86_64_GOT64           27
#define R_X86_64_GOTPCREL64      28
#define R_X86_64_GOTPC64         29
#define R_X86_64_GOTPLT64        30
#define R_X86_64_PLTOFF64        31
#define R_X86_64_SIZE32          32
#define R_X86_64_SIZE64          33
#define R_X86_64_GOTPC32_TLSDESC 34
#define R_X86_64_TLSDESC_CALL    35
#define R_X86_64_TLSDESC         36
#define R_X86_64_IRELATIVE       37
#define R_X86_64_RELATIVE64      38
#define R_X86_64_GOTPCRELX       41 /* 6 bytes */
#define R_X86_64_REX_GOTPCRELX   42 /* 7 bytes */
#define R_X86_64_NUM             43

#define R_AARCH64_NONE   0
#define R_AARCH64_ABS64  257
#define R_AARCH64_ABS32  258
#define R_AARCH64_ABS16  259
#define R_AARCH64_PREL64 260
#define R_AARCH64_PREL32 261
#define R_AARCH64_PREL16 262

#define R_PPC_NONE   0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR24 2
#define R_PPC_ADDR16 3
#define R_PPC_REL32  26

#define R_PPC64_NONE   R_PPC_NONE
#define R_PPC64_ADDR32 R_PPC_ADDR32
#define R_PPC64_ADDR24 R_PPC_ADDR24
#define R_PPC64_ADDR16 R_PPC_ADDR16
#define R_PPC64_REL32  R_PPC_REL32

#define R_RISCV_NONE     0
#define R_RISCV_32       1
#define R_RISCV_64       2
#define R_RISCV_RELATIVE 3

#define R_390_NONE 0
#define R_390_8    1
#define R_390_12   2
#define R_390_16   3
#define R_390_32   4
#define R_390_PC32 5

#define STB_LOCAL      0
#define STB_GLOBAL     1
#define STB_WEAK       2
#define STB_NUM        3
#define STB_LOOS       10
#define STB_GNU_UNIQUE 10
#define STB_HIOS       12
#define STB_LOPROC     13
#define STB_HIPROC     15

#define STT_NOTYPE    0
#define STT_OBJECT    1
#define STT_FUNC      2
#define STT_SECTION   3
#define STT_FILE      4
#define STT_COMMON    5
#define STT_TLS       6
#define STT_NUM       7
#define STT_LOOS      10
#define STT_GNU_IFUNC 10
#define STT_HIOS      12
#define STT_LOPROC    13
#define STT_HIPROC    15

#define STV_DEFAULT   0
#define STV_INTERNAL  1
#define STV_HIDDEN    2
#define STV_PROTECTED 3

#define SHN_UNDEF     0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC    0xff00
#define SHN_BEFORE    0xff00
#define SHN_AFTER     0xff01
#define SHN_HIPROC    0xff1f
#define SHN_LOOS      0xff20
#define SHN_HIOS      0xff3f
#define SHN_ABS       0xfff1
#define SHN_COMMON    0xfff2
#define SHN_XINDEX    0xffff
#define SHN_HIRESERVE 0xffff

#define SHF_WRITE            (1 << 0)
#define SHF_ALLOC            (1 << 1)
#define SHF_EXECINSTR        (1 << 2)
#define SHF_MERGE            (1 << 4)
#define SHF_STRINGS          (1 << 5)
#define SHF_INFO_LINK        (1 << 6)
#define SHF_LINK_ORDER       (1 << 7)
#define SHF_OS_NONCONFORMING (1 << 8)
#define SHF_GROUP            (1 << 9)
#define SHF_TLS              (1 << 10)
#define SHF_COMPRESSED       (1 << 11)
#define SHF_MASKOS           0x0ff00000
#define SHF_MASKPROC         0xf0000000
#define SHF_ORDERED          (1 << 30)
#define SHF_EXCLUDE          (1U << 31)

#define ELFCOMPRESS_ZLIB   1
#define ELFCOMPRESS_LOOS   0x60000000
#define ELFCOMPRESS_HIOS   0x6fffffff
#define ELFCOMPRESS_LOPROC 0x70000000
#define ELFCOMPRESS_HIPROC 0x7fffffff

#define SHT_NULL           0
#define SHT_PROGBITS       1
#define SHT_SYMTAB         2
#define SHT_STRTAB         3
#define SHT_RELA           4
#define SHT_HASH           5
#define SHT_DYNAMIC        6
#define SHT_NOTE           7
#define SHT_NOBITS         8
#define SHT_REL            9
#define SHT_SHLIB          10
#define SHT_DYNSYM         11
#define SHT_INIT_ARRAY     14
#define SHT_FINI_ARRAY     15
#define SHT_PREINIT_ARRAY  16
#define SHT_GROUP          17
#define SHT_SYMTAB_SHNDX   18
#define SHT_NUM            19
#define SHT_LOOS           0x60000000
#define SHT_GNU_ATTRIBUTES 0x6ffffff5
#define SHT_GNU_HASH       0x6ffffff6
#define SHT_GNU_LIBLIST    0x6ffffff7
#define SHT_CHECKSUM       0x6ffffff8
#define SHT_LOSUNW         0x6ffffffa
#define SHT_SUNW_move      0x6ffffffa
#define SHT_SUNW_COMDAT    0x6ffffffb
#define SHT_SUNW_syminfo   0x6ffffffc
#define SHT_GNU_verdef     0x6ffffffd
#define SHT_GNU_verneed    0x6ffffffe
#define SHT_GNU_versym     0x6fffffff
#define SHT_HISUNW         0x6fffffff
#define SHT_HIOS           0x6fffffff
#define SHT_LOPROC         0x70000000
#define SHT_HIPROC         0x7fffffff
#define SHT_LOUSER         0x80000000
#define SHT_HIUSER         0x8fffffff

#define DT_NULL               0
#define DT_NEEDED             1
#define DT_PLTRELSZ           2
#define DT_PLTGOT             3
#define DT_HASH               4
#define DT_STRTAB             5
#define DT_SYMTAB             6
#define DT_RELA               7
#define DT_RELASZ             8
#define DT_RELAENT            9
#define DT_STRSZ              10
#define DT_SYMENT             11
#define DT_INIT               12
#define DT_FINI               13
#define DT_SONAME             14
#define DT_RPATH              15
#define DT_SYMBOLIC           16
#define DT_REL                17
#define DT_RELSZ              18
#define DT_RELENT             19
#define DT_PLTREL             20
#define DT_DEBUG              21
#define DT_TEXTREL            22
#define DT_JMPREL             23
#define DT_BIND_NOW           24
#define DT_INIT_ARRAY         25
#define DT_FINI_ARRAY         26
#define DT_INIT_ARRAYSZ       27
#define DT_FINI_ARRAYSZ       28
#define DT_RUNPATH            29
#define DT_FLAGS              30
#define DT_ENCODING           32
#define DT_PREINIT_ARRAY      32
#define DT_PREINIT_ARRAYSZ    33
#define DT_SYMTAB_SHNDX       34
#define DT_NUM                35
#define DT_LOOS               0x6000000d
#define DT_HIOS               0x6ffff000
#define DT_LOPROC             0x70000000
#define DT_HIPROC             0x7fffffff
#define DT_VALRNGLO           0x6ffffd00
#define DT_GNU_PRELINKED      0x6ffffdf5
#define DT_GNU_CONFLICTSZ     0x6ffffdf6
#define DT_GNU_LIBLISTSZ      0x6ffffdf7
#define DT_CHECKSUM           0x6ffffdf8
#define DT_PLTPADSZ           0x6ffffdf9
#define DT_MOVEENT            0x6ffffdfa
#define DT_MOVESZ             0x6ffffdfb
#define DT_FEATURE_1          0x6ffffdfc
#define DT_POSFLAG_1          0x6ffffdfd
#define DT_SYMINSZ            0x6ffffdfe
#define DT_SYMINENT           0x6ffffdff
#define DT_VALRNGHI           0x6ffffdff
#define DT_VALTAGIDX(tag)     (DT_VALRNGHI - (tag))
#define DT_VALNUM             12
#define DT_ADDRRNGLO          0x6ffffe00
#define DT_GNU_HASH           0x6ffffef5
#define DT_TLSDESC_PLT        0x6ffffef6
#define DT_TLSDESC_GOT        0x6ffffef7
#define DT_GNU_CONFLICT       0x6ffffef8
#define DT_GNU_LIBLIST        0x6ffffef9
#define DT_CONFIG             0x6ffffefa
#define DT_DEPAUDIT           0x6ffffefb
#define DT_AUDIT              0x6ffffefc
#define DT_PLTPAD             0x6ffffefd
#define DT_MOVETAB            0x6ffffefe
#define DT_SYMINFO            0x6ffffeff
#define DT_ADDRRNGHI          0x6ffffeff
#define DT_ADDRTAGIDX(tag)    (DT_ADDRRNGHI - (tag))
#define DT_ADDRNUM            11
#define DT_VERSYM             0x6ffffff0
#define DT_RELACOUNT          0x6ffffff9
#define DT_RELCOUNT           0x6ffffffa
#define DT_FLAGS_1            0x6ffffffb
#define DT_VERDEF             0x6ffffffc
#define DT_VERDEFNUM          0x6ffffffd
#define DT_VERNEED            0x6ffffffe
#define DT_VERNEEDNUM         0x6fffffff
#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag))
#define DT_VERSIONTAGNUM      16
#define DT_AUXILIARY          0x7ffffffd
#define DT_FILTER             0x7fffffff
#define DT_EXTRATAGIDX(tag)   ((Elf32_Word) - ((Elf32_Sword)(tag) << 1 >> 1) - 1)
#define DT_EXTRANUM           3

#define VER_NEED_NONE    0
#define VER_NEED_CURRENT 1
#define VER_NEED_NUM     2
#define VER_FLG_WEAK     0x2

#define ELF_NOTE_SOLARIS       "SUNW Solaris"
#define ELF_NOTE_GNU           "GNU"
#define ELF_NOTE_PAGESIZE_HINT 1
#define ELF_NOTE_ABI           NT_GNU_ABI_TAG
#define ELF_NOTE_OS_LINUX      0
#define ELF_NOTE_OS_GNU        1
#define ELF_NOTE_OS_SOLARIS2   2
#define ELF_NOTE_OS_FREEBSD    3

#define NT_GNU_ABI_TAG      1
#define NT_GNU_BUILD_ID     3
#define NT_GNU_GOLD_VERSION 4

#define EF_CPU32 0x00810000

#define DF_ORIGIN       0x00000001
#define DF_SYMBOLIC     0x00000002
#define DF_TEXTREL      0x00000004
#define DF_BIND_NOW     0x00000008
#define DF_STATIC_TLS   0x00000010
#define DF_1_NOW        0x00000001
#define DF_1_GLOBAL     0x00000002
#define DF_1_GROUP      0x00000004
#define DF_1_NODELETE   0x00000008
#define DF_1_LOADFLTR   0x00000010
#define DF_1_INITFIRST  0x00000020
#define DF_1_NOOPEN     0x00000040
#define DF_1_ORIGIN     0x00000080
#define DF_1_DIRECT     0x00000100
#define DF_1_TRANS      0x00000200
#define DF_1_INTERPOSE  0x00000400
#define DF_1_NODEFLIB   0x00000800
#define DF_1_NODUMP     0x00001000
#define DF_1_CONFALT    0x00002000
#define DF_1_ENDFILTEE  0x00004000
#define DF_1_DISPRELDNE 0x00008000
#define DF_1_DISPRELPND 0x00010000
#define DF_1_NODIRECT   0x00020000
#define DF_1_IGNMULDEF  0x00040000
#define DF_1_NOKSYMS    0x00080000
#define DF_1_NOHDR      0x00100000
#define DF_1_EDITED     0x00200000
#define DF_1_NORELOC    0x00400000
#define DF_1_SYMINTPOSE 0x00800000
#define DF_1_GLOBAUDIT  0x01000000
#define DF_1_SINGLETON  0x02000000
#define DF_1_STUB       0x04000000
#define DF_1_PIE        0x08000000
#define DTF_1_PARINIT   0x00000001
#define DTF_1_CONFEXP   0x00000002
#define DF_P1_LAZYLOAD  0x00000001
#define DF_P1_GROUPPERM 0x00000002

#define ELF64_ST_BIND(val)        (((unsigned char)(val)) >> 4)
#define ELF64_ST_TYPE(val)        ((val)&0xf)
#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf))
#define ELF64_ST_VISIBILITY(o)    ((o)&0x03)

#define ELF64_R_SYM(i)          ((i) >> 32)
#define ELF64_R_TYPE(i)         ((i)&0xffffffff)
#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type))

#define ELF64_M_SYM(info)       ((info) >> 8)
#define ELF64_M_SIZE(info)      ((unsigned char)(info))
#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))

#define NT_PRSTATUS         1
#define NT_PRFPREG          2
#define NT_FPREGSET         2
#define NT_PRPSINFO         3
#define NT_PRXREG           4
#define NT_TASKSTRUCT       4
#define NT_PLATFORM         5
#define NT_AUXV             6
#define NT_GWINDOWS         7
#define NT_ASRS             8
#define NT_PSTATUS          10
#define NT_PSINFO           13
#define NT_PRCRED           14
#define NT_UTSNAME          15
#define NT_LWPSTATUS        16
#define NT_LWPSINFO         17
#define NT_PRFPXREG         20
#define NT_SIGINFO          0x53494749
#define NT_FILE             0x46494c45
#define NT_PRXFPREG         0x46e62b7f
#define NT_PPC_VMX          0x100
#define NT_PPC_SPE          0x101
#define NT_PPC_VSX          0x102
#define NT_PPC_TAR          0x103
#define NT_PPC_PPR          0x104
#define NT_PPC_DSCR         0x105
#define NT_PPC_EBB          0x106
#define NT_PPC_PMU          0x107
#define NT_PPC_TM_CGPR      0x108
#define NT_PPC_TM_CFPR      0x109
#define NT_PPC_TM_CVMX      0x10a
#define NT_PPC_TM_CVSX      0x10b
#define NT_PPC_TM_SPR       0x10c
#define NT_PPC_TM_CTAR      0x10d
#define NT_PPC_TM_CPPR      0x10e
#define NT_PPC_TM_CDSCR     0x10f
#define NT_X86_XSTATE       0x202
#define NT_S390_HIGH_GPRS   0x300
#define NT_S390_TIMER       0x301
#define NT_S390_TODCMP      0x302
#define NT_S390_TODPREG     0x303
#define NT_S390_CTRS        0x304
#define NT_S390_PREFIX      0x305
#define NT_S390_LAST_BREAK  0x306
#define NT_S390_SYSTEM_CALL 0x307
#define NT_S390_TDB         0x308
#define NT_S390_VXRS_LOW    0x309
#define NT_S390_VXRS_HIGH   0x30a
#define NT_S390_GS_CB       0x30b
#define NT_S390_GS_BC       0x30c
#define NT_S390_RI_CB       0x30d
#define NT_ARM_VFP          0x400
#define NT_ARM_TLS          0x401
#define NT_ARM_HW_BREAK     0x402
#define NT_ARM_HW_WATCH     0x403
#define NT_ARM_SYSTEM_CALL  0x404
#define NT_ARM_SVE          0x405
#define NT_ARM_PAC_MASK     0x406
#define NT_METAG_CBUF       0x500
#define NT_METAG_RPIPE      0x501
#define NT_METAG_TLS        0x502
#define NT_ARC_V2           0x600
#define NT_VMCOREDD         0x700
#define NT_VERSION          1

#define VER_DEF_NONE      0
#define VER_DEF_CURRENT   1
#define VER_DEF_NUM       2
#define VER_FLG_BASE      0x1
#define VER_FLG_WEAK      0x2
#define VER_NDX_LOCAL     0
#define VER_NDX_GLOBAL    1
#define VER_NDX_LORESERVE 0xff00
#define VER_NDX_ELIMINATE 0xff01

#define LL_NONE           0
#define LL_EXACT_MATCH    (1 << 0)
#define LL_IGNORE_INT_VER (1 << 1)
#define LL_REQUIRE_MINOR  (1 << 2)
#define LL_EXPORTS        (1 << 3)
#define LL_DELAY_LOAD     (1 << 4)
#define LL_DELTA          (1 << 5)

#define R_BPF_NONE   0
#define R_BPF_MAP_FD 1



/*!BEGIN libc/elf/elf.h */

#define COSMOPOLITAN_LIBC_ELF_H_


/*!BEGIN libc/elf/struct/ehdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_EHDR_H_


/*!BEGIN libc/elf/scalar.h */

#define COSMOPOLITAN_LIBC_ELF_SCALAR_H_

#define Elf64_Addr    uint64_t
#define Elf64_Half    uint16_t
#define Elf64_Off     uint64_t
#define Elf64_Section uint16_t
#define Elf64_Sword   int32_t
#define Elf64_Sxword  int64_t
#define Elf64_Versym  Elf64_Half
#define Elf64_Word    uint32_t
#define Elf64_Xword   uint64_t
#define Elf_Symndx    uint32_t


/*
 * ELF header.
 */
typedef struct Elf64_Ehdr {

  /*
   * Leading bytes of ELF header.
   *
   * - `e_ident[0]` is always `127`
   * - `e_ident[1]` is always `'E'`
   * - `e_ident[2]` is always `'L'`
   * - `e_ident[3]` is always `'F'`
   *
   * - `e_ident[EI_CLASS]` is mandatory and should be:
   *
   *   - `ELFCLASSNONE64` if it's an Elf64 image
   *   - `ELFCLASSNONE32` if it's an Elf32 image
   *   - Otherwise we assume it's an Elf64 image
   *
   * - `e_ident[EI_DATA]` is advisory and could be:
   *
   *   - `ELFDATANONE` isn't strictly valid
   *   - `ELFDATA2LSB` for little-endian
   *   - `ELFDATA2MSB` for big-endian
   *
   * - `e_ident[EI_VERSION]` is advisory and should be:
   *
   *   - `EV_NONE` if it's zero or unspecified
   *   - `EV_CURRENT` for current ELF version (which is 1)
   *
   * - `e_ident[EI_OSABI]` is mandatory and could be:
   *
   *   - `ELFOSABI_NONE` is zero
   *   - `ELFOSABI_GNU` is for GNU
   *   - `ELFOSABI_SYSV` used by GNU
   *   - `ELFOSABI_LINUX` doesn't care
   *   - `ELFOSABI_FREEBSD` does care (recommended)
   *   - `ELFOSABI_NETBSD` doesn't care (see `PT_NOTE`)
   *   - `ELFOSABI_OPENBSD` doesn't care (see `PT_NOTE`)
   *
   * - `e_ident[EI_ABIVERSION]` is advisory
   *
   */
  unsigned char e_ident[16];

  /*
   * ELF image type.
   *
   * This field is mandatory and should be one of:
   *
   * - `ET_REL` for `.o` object files
   * - `ET_DYN` for `.so` files and `-pie` executables
   * - `ET_EXEC` for statically-linked executables
   *
   */
  Elf64_Half e_type;

  /*
   * ELF machine type.
   *
   * This field is mandatory and could be one of:
   *
   * - `EM_M32` for Bellmac
   * - `EM_X86_64` for Amd64
   * - `EM_AARCH64` for Arm64
   * - `EM_PPC64` for Raptors
   * - `EM_RISCV` for Berkeley
   * - `EM_S390` for System/360
   *
   */
  Elf64_Half e_machine;

  /*
   * ELF version.
   *
   * This field is advisory and could be:
   *
   * - `EV_NONE` if it's zero or unspecified
   * - `EV_CURRENT` for current ELF version (which is 1)
   *
   * @see `e_ident[EI_VERSION]`
   */
  Elf64_Word e_version;

  /*
   * ELF executable entrypoint.
   *
   * Static executables should use this field to store the virtual
   * address of the _start() function. This field may be zero, for
   * unspecified.
   */
  Elf64_Addr e_entry;

  /*
   * `Elf64_Phdr` file offset.
   *
   * This field is mandatory. Object files should set it to zero.
   */
  Elf64_Off e_phoff;

  /*
   * `Elf64_Shdr` file offset.
   *
   * This field is advisory.
   */
  Elf64_Off e_shoff;

  /*
   * ELF flags.
   *
   * This field is advisory.
   */
  Elf64_Word e_flags;

  /*
   * `Elf64_Ehdr` size.
   *
   * This field is advisory and should be 64.
   */
  Elf64_Half e_ehsize;

  /*
   * `Elf64_Phdr` element size.
   *
   * This field *is* cared about and should be set to 56. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_phentsize;

  /*
   * `Elf64_Phdr` array count.
   */
  Elf64_Half e_phnum;

  /*
   * `Elf64_Shdr` element size.
   *
   * This field is advisory and should be set to 64. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_shentsize;

  /*
   * `Elf64_Shdr` count.
   *
   * This field is advisory.
   */
  Elf64_Half e_shnum;

  /*
   * Section header index of section name string table.
   */
  Elf64_Half e_shstrndx;

} Elf64_Ehdr;



/*!BEGIN libc/elf/struct/phdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_PHDR_H_

typedef struct Elf64_Phdr {
  Elf64_Word p_type;
  Elf64_Word p_flags;
  Elf64_Off p_offset;
  Elf64_Addr p_vaddr;
  Elf64_Addr p_paddr;
  Elf64_Xword p_filesz;
  Elf64_Xword p_memsz;
  Elf64_Xword p_align;
} Elf64_Phdr;



/*!BEGIN libc/elf/struct/shdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SHDR_H_

/**
 * Section header.
 * @see https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html
 */
typedef struct Elf64_Shdr {

  Elf64_Word sh_name;

  Elf64_Word sh_type; /* SHT_{PROGBITS,NOBITS,STRTAB,SYMTAB,RELA,...} */

  Elf64_Xword sh_flags; /* SHF_{WRITE,ALLOC,EXECINSTR,TLS,MERGE,STRINGS,,...} */

  Elf64_Addr sh_addr;

  Elf64_Off sh_offset;

  Elf64_Xword sh_size;

  /*
   * Index of linked section header.
   *
   * If `sh_type` is `SHT_RELA` then `sh_link` holds the section header
   * index of the associated symbol table.
   *
   * If `sh_type` is `SHT_SYMTAB` then `sh_link` holds the section
   * header index of the associated string table.
   */
  Elf64_Word sh_link;

  /*
   * If `sh_type` is `SHT_RELA` then `sh_info` contains the index of the
   * section to which relocations apply.
   *
   * If `sh_type` is `SHT_SYMTAB` or `SHT_DYNSYM` then `sh_info`
   * contains an index that's one greater than symbol table index of
   * last `STB_LOCAL` symbol.
   */
  Elf64_Word sh_info;

  Elf64_Xword sh_addralign;

  Elf64_Xword sh_entsize;

} Elf64_Shdr;



/*!BEGIN libc/elf/struct/sym.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYM_H_

typedef struct Elf64_Sym {

  /*
   * Symbol name.
   *
   * This value is a byte offset into the `.strtab` section. If this
   * value is zero, then the symbol has no name.
   */
  Elf64_Word st_name;

  /*
   * Symbol type and binding.
   *
   * This value may be created using:
   *
   *     sym.st_info = ELF64_ST_INFO(bind, type);
   *
   * This value may be read using:
   *
   *     int bind = ELF64_ST_BIND(sym.st_info);
   *     int type = ELF64_ST_TYPE(sym.st_info);
   *
   * Where `bind` is typically:
   *
   * - `STB_LOCAL`
   * - `STB_GLOBAL`
   * - `STB_WEAK`
   *
   * Where `type` is typically:
   *
   * - `STT_NOTYPE`
   * - `STT_OBJECT`
   * - `STT_FUNC`
   * - `STT_SECTION`
   * - `STT_FILE`
   * - `STT_COMMON`
   * - `STT_TLS`
   */
  uint8_t st_info;

  /*
   * Symbol visibility.
   *
   * This value should be accessed using:
   *
   *     int visibility = ELF64_ST_VISIBILITY(sym.st_other);
   *
   * Where `visibility` is typically:
   *
   * - `STV_DEFAULT`
   * - `STV_INTERNAL`
   * - `STV_HIDDEN`
   * - `STV_PROTECTED`
   */
  uint8_t st_other;

  /*
   * Symbol section.
   *
   * If `st_shndx` is within `(SHN_UNDEF,SHN_LORESERVE)` then it holds
   * an index into the section header table.
   *
   * Otherwise `st_shndx` is usually one of the following magic numbers:
   *
   * - `SHN_UNDEF` means symbol is undefined
   * - `SHN_ABS` means symbol is a linker integer
   * - `SHN_COMMON` means symbol is defined traditionally
   */
  Elf64_Section st_shndx;

  /*
   * Symbol value.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is `SHN_COMMON`, then
   * `st_value` holds the required symbol alignment, or ≤ 1 if no
   * alignment is required.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is a section index, then
   * `st_value` holds a byte offset into the section memory.
   *
   * If `e_type` isn't `ET_REL` then `st_value` holds a virtual address.
   */
  Elf64_Addr st_value;

  /* byte length optionally set by .size directive */
  Elf64_Xword st_size;

} Elf64_Sym;

#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § executable linkable format                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
/* clang-format off */

bool32 IsElfSymbolContent(const Elf64_Sym *);
bool32 IsElf64Binary(const Elf64_Ehdr *, size_t);
char *GetElfStringTable(const Elf64_Ehdr *, size_t, const char *);
Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
/* clang-format on */


/*!BEGIN libc/elf/link.h */

#define COSMOPOLITAN_ELF_LINK_H_


/*!BEGIN libc/elf/struct/dyn.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DYN_H_

typedef struct Elf64_Dyn {
  Elf64_Sxword d_tag;
  union {
    Elf64_Xword d_val;
    Elf64_Addr d_ptr;
  } d_un;
} Elf64_Dyn;

COSMOPOLITAN_C_START_

#define ElfW(type) Elf64_##type

struct dl_phdr_info {
  Elf64_Addr dlpi_addr;
  const char *dlpi_name;
  const Elf64_Phdr *dlpi_phdr;
  Elf64_Half dlpi_phnum;
  unsigned long long int dlpi_adds;
  unsigned long long int dlpi_subs;
  size_t dlpi_tls_modid;
  void *dlpi_tls_data;
};

struct link_map {
  Elf64_Addr l_addr;
  char *l_name;
  Elf64_Dyn *l_ld;
  struct link_map *l_next;
  struct link_map *l_prev;
};

struct r_debug {
  int r_version;
  struct link_map *r_map;
  Elf64_Addr r_brk;
  enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state;
  Elf64_Addr r_ldbase;
};

int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/elf/struct/auxv.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_AUXV_H_

typedef struct Elf64_auxv_t {
  uint64_t a_type;
  union {
    uint64_t a_val;
  } a_un;
} Elf64_auxv_t;



/*!BEGIN libc/elf/struct/chdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_CHDR_H_

typedef struct Elf64_Chdr {
  Elf64_Word ch_type;
  Elf64_Word ch_reserved;
  Elf64_Xword ch_size;
  Elf64_Xword ch_addralign;
} Elf64_Chdr;



/*!BEGIN libc/elf/struct/lib.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_LIB_H_

typedef struct Elf64_Lib {
  Elf64_Word l_name;
  Elf64_Word l_time_stamp;
  Elf64_Word l_checksum;
  Elf64_Word l_version;
  Elf64_Word l_flags;
} Elf64_Lib;



/*!BEGIN libc/elf/struct/move.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_MOVE_H_

typedef struct Elf64_Move {
  Elf64_Xword m_value;
  Elf64_Xword m_info;
  Elf64_Xword m_poffset;
  Elf64_Half m_repeat;
  Elf64_Half m_stride;
} Elf64_Move;



/*!BEGIN libc/elf/struct/nhdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_NHDR_H_

typedef struct Elf64_Nhdr {
  Elf64_Word n_namesz;
  Elf64_Word n_descsz;
  Elf64_Word n_type;
} Elf64_Nhdr;



/*!BEGIN libc/elf/struct/rel.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_REL_H_

/*
 * ELF relocation.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_REL`.
 *
 * @see Elf64_Rela
 */
typedef struct Elf64_Rel {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` might be:
   *
   * - `R_X86_64_64`
   * - `R_X86_64_PC32`
   * - `R_X86_64_GOTPCRELX`
   * - `R_AARCH64_ABS64`
   *
   * Each relocation type specifies a mathematical formula that's used
   * to compute the appropriate value for the fixed-up object code. If
   * it needs an addend, then this struct doesn't have one, but it can
   * still be embedded by the compiler in the location to be modified.
   */
  Elf64_Xword r_info;

} Elf64_Rel;



/*!BEGIN libc/elf/struct/rela.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_RELA_H_

/*
 * ELF relocation w/ explicit addend.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_RELA`
 *
 * @see Elf64_Rel
 */
typedef struct Elf64_Rela {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` will likely be:
   *
   * - `R_X86_64_PC32`
   * - `R_X86_64_PLT32`
   * - `R_X86_64_32`
   * - `R_X86_64_64`
   * - `R_X86_64_32S`
   * - `R_X86_64_8`
   * - `R_X86_64_16`
   * - `R_X86_64_DTPOFF32`
   * - `R_X86_64_GOTPCREL`
   * - `R_X86_64_PC16`
   * - `R_X86_64_REX_GOTPCRELX`
   * - `R_X86_64_TPOFF32`
   *
   */
  Elf64_Xword r_info;

  /*
   * Relocation parameter.
   *
   * Each relocation type has its own mathematical formula, which should
   * incorporate this value in its own unique way.
   */
  Elf64_Sxword r_addend;

} Elf64_Rela;



/*!BEGIN libc/elf/struct/syminfo.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYMINFO_H_

typedef struct Elf64_Syminfo {
  Elf64_Half si_boundto;
  Elf64_Half si_flags;
} Elf64_Syminfo;



/*!BEGIN libc/elf/struct/verdaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDAUX_H_

typedef struct Elf64_Verdaux {
  Elf64_Word vda_name;
  Elf64_Word vda_next;
} Elf64_Verdaux;



/*!BEGIN libc/elf/struct/verdef.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDEF_H_

typedef struct Elf64_Verdef {
  Elf64_Half vd_version;
  Elf64_Half vd_flags;
  Elf64_Half vd_ndx;
  Elf64_Half vd_cnt;
  Elf64_Word vd_hash;
  Elf64_Word vd_aux;
  Elf64_Word vd_next;
} Elf64_Verdef;



/*!BEGIN libc/elf/struct/vernaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNAUX_H_

typedef struct Elf64_Vernaux {
  Elf64_Word vna_hash;
  Elf64_Half vna_flags;
  Elf64_Half vna_other;
  Elf64_Word vna_name;
  Elf64_Word vna_next;
} Elf64_Vernaux;



/*!BEGIN libc/elf/struct/verneed.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNEED_H_

typedef struct Elf64_Verneed {
  Elf64_Half vn_version;
  Elf64_Half vn_cnt;
  Elf64_Word vn_file;
  Elf64_Word vn_aux;
  Elf64_Word vn_next;
} Elf64_Verneed;



/*!BEGIN libc/fmt/conv.h */

#define COSMOPOLITAN_LIBC_FMT_CONV_H_
COSMOPOLITAN_C_START_

int abs(int) libcesque pureconst;
long labs(long) libcesque pureconst;
long long llabs(long long) libcesque pureconst;
libcesque intmax_t imaxabs(intmax_t) pureconst;
int atoi(const char *) paramsnonnull() libcesque;
long atol(const char *) paramsnonnull() libcesque;
long long atoll(const char *) paramsnonnull() libcesque;
unsigned long strtoul(const char *, char **, int) libcesque paramsnonnull((1));
long long strtoll(const char *, char **, int) libcesque paramsnonnull((1));
unsigned long long strtoull(const char *, char **, int) paramsnonnull((1));
intmax_t strtoimax(const char *, char **, int) libcesque paramsnonnull((1));
uintmax_t strtoumax(const char *, char **, int) libcesque paramsnonnull((1));
intmax_t wcstoimax(const wchar_t *, wchar_t **, int) libcesque;
uintmax_t wcstoumax(const wchar_t *, wchar_t **, int) libcesque;
long wcstol(const wchar_t *, wchar_t **, int) libcesque;
unsigned long wcstoul(const wchar_t *, wchar_t **, int) libcesque;
long strtol(const char *, char **, int) paramsnonnull((1)) libcesque;
long sizetol(const char *, long) paramsnonnull() libcesque;
char *sizefmt(char *, uint64_t, uint64_t) libcesque;
long long wcstoll(const wchar_t *, wchar_t **, int) libcesque;
unsigned long long wcstoull(const wchar_t *, wchar_t **, int) libcesque;
int wcscoll(const wchar_t *, const wchar_t *) libcesque;
size_t wcsxfrm(wchar_t *, const wchar_t *, size_t) libcesque;

double atof(const char *) libcesque;
float strtof(const char *, char **) libcesque;
double strtod(const char *, char **) libcesque;
long double strtold(const char *, char **) libcesque;
float wcstof(const wchar_t *, wchar_t **) libcesque;
double wcstod(const wchar_t *, wchar_t **) libcesque;
long double wcstold(const wchar_t *, wchar_t **) libcesque;

#ifdef _COSMO_SOURCE
char *stripext(char *) libcesque;
char *stripexts(char *) libcesque;
#endif /* _COSMO_SOURCE */

typedef struct {
  int quot;
  int rem;
} div_t;

typedef struct {
  long int quot;
  long int rem;
} ldiv_t;

typedef struct {
  long long int quot;
  long long int rem;
} lldiv_t;

typedef struct {
  intmax_t quot;
  intmax_t rem;
} imaxdiv_t;

libcesque div_t div(int, int) pureconst;
libcesque ldiv_t ldiv(long, long) pureconst;
libcesque lldiv_t lldiv(long long, long long) pureconst;
libcesque imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;

#if __STDC_VERSION__ + 0 >= 199901L
#define div(num, den)   ((div_t){(num) / (den), (num) % (den)})
#define ldiv(num, den)  ((ldiv_t){(num) / (den), (num) % (den)})
#define lldiv(num, den) ((lldiv_t){(num) / (den), (num) % (den)})
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/fmt/itoa.h */

#ifndef COSMOPOLITAN_LIBC_FMT_ITOA_H_
#define COSMOPOLITAN_LIBC_FMT_ITOA_H_
COSMOPOLITAN_C_START_

#define LengthInt64           __LengthInt64
#define LengthUint64          __LengthUint64
#define LengthInt64Thousands  __LengthInt64Thousands
#define LengthUint64Thousands __LengthUint64Thousands
#define FormatInt32           __FormatInt32
#define FormatUint32          __FormatUint32
#define FormatInt64           __FormatInt64
#define FormatUint64          __FormatUint64
#define FormatInt64Thousands  __FormatInt64Thousands
#define FormatUint64Thousands __FormatUint64Thousands
#define FormatOctal32         __FormatOctal32
#define FormatOctal64         __FormatOctal64
#define FormatBinary64        __FormatBinary64
#define FormatHex64           __FormatHex64
#define FormatFlex64          __FormatFlex64
#define uint64toarray_radix16 __uint64toarray_radix16
#define uint64toarray_fixed16 __uint64toarray_fixed16
#define uint64toarray_radix8  __uint64toarray_radix8

libcesque unsigned LengthInt64(int64_t) pureconst;
libcesque unsigned LengthUint64(uint64_t) pureconst;
libcesque unsigned LengthInt64Thousands(int64_t) pureconst;
libcesque unsigned LengthUint64Thousands(uint64_t) pureconst;
libcesque char *FormatInt32(char[hasatleast 12], int32_t);
libcesque char *FormatUint32(char[hasatleast 12], uint32_t);
libcesque char *FormatInt64(char[hasatleast 21], int64_t);
libcesque char *FormatUint64(char[hasatleast 21], uint64_t);
libcesque char *FormatInt64Thousands(char[hasatleast 27], int64_t);
libcesque char *FormatUint64Thousands(char[hasatleast 27], uint64_t);
libcesque char *FormatOctal32(char[hasatleast 13], uint32_t, bool32);
libcesque char *FormatOctal64(char[hasatleast 24], uint64_t, bool32);
libcesque char *FormatBinary64(char[hasatleast 67], uint64_t, char);
libcesque char *FormatHex64(char[hasatleast 19], uint64_t, char);
libcesque char *FormatFlex64(char[hasatleast 24], int64_t, char);
libcesque size_t uint64toarray_radix16(uint64_t, char[hasatleast 17]);
libcesque size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
libcesque size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_ITOA_H_ */


/*!BEGIN libc/fmt/leb128.h */

#ifndef COSMOPOLITAN_LIBC_FMT_LEB128_H_
#define COSMOPOLITAN_LIBC_FMT_LEB128_H_
COSMOPOLITAN_C_START_

#define sleb64   __sleb64
#define zleb64   __zleb64
#define uleb64   __uleb64
#define unzleb64 __unzleb64
#define unuleb64 __unuleb64

char *sleb64(char *, int64_t) libcesque;
char *zleb64(char[hasatleast 10], int64_t) libcesque;
char *uleb64(char[hasatleast 10], uint64_t) libcesque;
int unzleb64(const char *, size_t, int64_t *) libcesque;
int unuleb64(const char *, size_t, uint64_t *) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_LEB128_H_ */


/*!BEGIN libc/fmt/libgen.h */

#define COSMOPOLITAN_LIBC_FMT_LIBGEN_H_
COSMOPOLITAN_C_START_

char *dirname(char *) libcesque;
char *basename(char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/dlopen/dlfcn.h */

#define COSMOPOLITAN_LIBC_DLFCN_H_

#define RTLD_LOCAL  0
#define RTLD_LAZY   1
#define RTLD_NOW    2
#define RTLD_GLOBAL 256

COSMOPOLITAN_C_START_

#define RTLD_NEXT    ((void *)-1)
#define RTLD_DEFAULT ((void *)0)

char *dlerror(void) libcesque;
void *dlopen(const char *, int) libcesque;
void *dlsym(void *, const char *) libcesque;
int dlclose(void *) libcesque;

char *cosmo_dlerror(void) libcesque;
void *cosmo_dlopen(const char *, int) libcesque;
void *cosmo_dlsym(void *, const char *) libcesque;
void *cosmo_dltramp(void *) libcesque;
int cosmo_dlclose(void *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/asancodes.h */

#define COSMOPOLITAN_LIBC_INTRIN_ASANCODES_H_

#define kAsanScale           3
#define kAsanMagic           0x7fff8000
#define kAsanNullPage        -1  /* ∅ 0xff */
#define kAsanProtected       -2  /* P 0xfe */
#define kAsanHeapFree        -3  /* F 0xfd */
#define kAsanHeapRelocated   -4  /* R 0xfc */
#define kAsanAllocaOverrun   -5  /* 𝑂 0xfb */
#define kAsanHeapUnderrun    -6  /* U 0xfa */
#define kAsanHeapOverrun     -7  /* O 0xf9 */
#define kAsanStackUnscoped   -8  /* s 0xf8 */
#define kAsanStackOverflow   -9  /* ! 0xf7 */
#define kAsanGlobalOrder     -10 /* I 0xf6 */
#define kAsanStackFree       -11 /* r 0xf5 */
#define kAsanStackPartial    -12 /* p 0xf4 */
#define kAsanStackOverrun    -13 /* o 0xf3 */
#define kAsanStackMiddle     -14 /* m 0xf2 */
#define kAsanStackUnderrun   -15 /* u 0xf1 */
#define kAsanAllocaUnderrun  -16 /* 𝑈 0xf0 */
#define kAsanUnmapped        -17 /* M 0xef */
#define kAsanGlobalRedzone   -18 /* G 0xee */
#define kAsanGlobalGone      -19 /* 𝐺 0xed */
#define kAsanGlobalUnderrun  -20 /* μ 0xec */
#define kAsanGlobalOverrun   -21 /* Ω 0xeb */
#define kAsanMmapSizeOverrun -22 /* Z 0xea */



/*!BEGIN libc/intrin/asmflag.h */

#define COSMOPOLITAN_LIBC_BITS_ASMFLAG_H_

/*
 * Constraints for virtual machine flags.
 * @note we beseech clang devs for flag constraints
 */
#ifdef __GCC_ASM_FLAG_OUTPUTS__ /* GCC6+ CLANG10+ */
#define CFLAG_CONSTRAINT  "=@ccc"
#define CFLAG_ASM(OP)     OP
#define ZFLAG_CONSTRAINT  "=@ccz"
#define ZFLAG_ASM(OP)     OP
#define OFLAG_CONSTRAINT  "=@cco"
#define OFLAG_ASM(OP)     OP
#define SFLAG_CONSTRAINT  "=@ccs"
#define SFLAG_ASM(SP)     SP
#define ABOVE_CONSTRAINT  "=@cca" /* i.e. !ZF && !CF */
#define ABOVEFLAG_ASM(OP) OP
#else
#define CFLAG_CONSTRAINT  "=q"
#define CFLAG_ASM(OP)     OP "\n\tsetc\t%b0"
#define ZFLAG_CONSTRAINT  "=q"
#define ZFLAG_ASM(OP)     OP "\n\tsetz\t%b0"
#define OFLAG_CONSTRAINT  "=q"
#define OFLAG_ASM(OP)     OP "\n\tseto\t%b0"
#define SFLAG_CONSTRAINT  "=q"
#define SFLAG_ASM(SP)     OP "\n\tsets\t%b0"
#define ABOVE_CONSTRAINT  "=@cca"
#define ABOVEFLAG_ASM(OP) OP "\n\tseta\t%b0"
#endif



/*!BEGIN libc/intrin/atomic.h */

#define COSMOPOLITAN_LIBC_BITS_ATOMIC_H_

/**
 * @fileoverview Cosmopolitan C11 Atomics Library
 *
 * - Forty-two different ways to say MOV.
 * - Fourteen different ways to say XCHG.
 * - Twenty different ways to say LOCK CMPXCHG.
 *
 * @see libc/atomic.h
 */

typedef int memory_order;

enum {
  memory_order_relaxed,
  memory_order_consume,
  memory_order_acquire,
  memory_order_release,
  memory_order_acq_rel,
  memory_order_seq_cst,
};

#define ATOMIC_VAR_INIT(...)     __VA_ARGS__
#define atomic_is_lock_free(obj) ((void)(obj), sizeof(obj) <= sizeof(void *))

#define atomic_flag      atomic_bool
#define ATOMIC_FLAG_INIT ATOMIC_VAR_INIT(0)
#define atomic_flag_test_and_set_explicit(x, order) \
  atomic_exchange_explicit(x, 1, order)
#define atomic_flag_clear_explicit(x, order) atomic_store_explicit(x, 0, order)

#define atomic_compare_exchange_strong(pObject, pExpected, desired) \
  atomic_compare_exchange_strong_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_compare_exchange_weak(pObject, pExpected, desired) \
  atomic_compare_exchange_weak_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_exchange(pObject, desired) \
  atomic_exchange_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_fetch_add(pObject, operand) \
  atomic_fetch_add_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_and(pObject, operand) \
  atomic_fetch_and_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_or(pObject, operand) \
  atomic_fetch_or_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_sub(pObject, operand) \
  atomic_fetch_sub_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_xor(pObject, operand) \
  atomic_fetch_xor_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_load(pObject) atomic_load_explicit(pObject, memory_order_seq_cst)
#define atomic_store(pObject, desired) \
  atomic_store_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_flag_test_and_set(x) \
  atomic_flag_test_and_set_explicit(x, memory_order_seq_cst)
#define atomic_flag_clear(x) atomic_flag_clear_explicit(x, memory_order_seq_cst)

#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)

#define atomic_init(obj, value)    __c11_atomic_init(obj, value)
#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
#define atomic_signal_fence(order) __c11_atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(object, expected, desired, \
                                                success, failure)          \
  __c11_atomic_compare_exchange_strong(object, expected, desired, success, \
                                       failure)
#define atomic_compare_exchange_weak_explicit(object, expected, desired, \
                                              success, failure)          \
  __c11_atomic_compare_exchange_weak(object, expected, desired, success, \
                                     failure)
#define atomic_exchange_explicit(object, desired, order) \
  __c11_atomic_exchange(object, desired, order)
#define atomic_fetch_add_explicit(object, operand, order) \
  __c11_atomic_fetch_add(object, operand, order)
#define atomic_fetch_and_explicit(object, operand, order) \
  __c11_atomic_fetch_and(object, operand, order)
#define atomic_fetch_or_explicit(object, operand, order) \
  __c11_atomic_fetch_or(object, operand, order)
#define atomic_fetch_sub_explicit(object, operand, order) \
  __c11_atomic_fetch_sub(object, operand, order)
#define atomic_fetch_xor_explicit(object, operand, order) \
  __c11_atomic_fetch_xor(object, operand, order)
#define atomic_load_explicit(object, order) __c11_atomic_load(object, order)
#define atomic_store_explicit(object, desired, order) \
  __c11_atomic_store(object, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __atomic_thread_fence(order)
#define atomic_signal_fence(order) __atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(pObject, pExpected, desired, \
                                                success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 0, success, failure)
#define atomic_compare_exchange_weak_explicit(pObject, pExpected, desired, \
                                              success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 1, success, failure)
#define atomic_exchange_explicit(pObject, desired, order) \
  __atomic_exchange_n(pObject, desired, order)
#define atomic_fetch_add_explicit(pObject, operand, order) \
  __atomic_fetch_add(pObject, operand, order)
#define atomic_fetch_and_explicit(pObject, operand, order) \
  __atomic_fetch_and(pObject, operand, order)
#define atomic_fetch_or_explicit(pObject, operand, order) \
  __atomic_fetch_or(pObject, operand, order)
#define atomic_fetch_sub_explicit(pObject, operand, order) \
  __atomic_fetch_sub(pObject, operand, order)
#define atomic_fetch_xor_explicit(pObject, operand, order) \
  __atomic_fetch_xor(pObject, operand, order)
#define atomic_load_explicit(pObject, order) __atomic_load_n(pObject, order)
#define atomic_store_explicit(pObject, desired, order) \
  __atomic_store_n(pObject, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __sync_synchronize()
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define __atomic_apply_stride(object, operand) \
  (((__typeof__(*(object)))0) + (operand))
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    __typeof__(expected) __ep = (expected);                                   \
    __typeof__(*__ep) __e = *__ep;                                            \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    (*__ep = __sync_val_compare_and_swap(object, __e, desired)) == __e;       \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#if __has_builtin(__sync_swap)
#define atomic_exchange_explicit(object, desired, order) \
  ((void)(order), __sync_swap(object, desired))
#else
#define atomic_exchange_explicit(object, desired, order) \
  __extension__({                                        \
    __typeof__(object) __o = (object);                   \
    __typeof__(desired) __d = (desired);                 \
    (void)(order);                                       \
    __sync_synchronize();                                \
    __sync_lock_test_and_set(__o, __d);                  \
  })
#endif
#define atomic_fetch_add_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_add(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_and_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_and(object, operand))
#define atomic_fetch_or_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_or(object, operand))
#define atomic_fetch_sub_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_sub(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_xor_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_xor(object, operand))
#define atomic_load_explicit(object, order) \
  ((void)(order), __sync_fetch_and_add(object, 0))
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#elif defined(__GNUC__) && defined(__x86__) /* x86 with gcc 4.0 and earlier */

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __asm__ volatile("mfence" ::: "memory")
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    char DidIt;                                                               \
    __typeof__(object) IfThing = (object);                                    \
    __typeof__(IfThing) IsEqualToMe = (expected);                             \
    __typeof__(*IfThing) ReplaceItWithMe = (desired), ax;                     \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    __asm__ volatile("lock cmpxchg\t%3,(%1)\n\t"                              \
                     "setz\t%b0"                                              \
                     : "=q"(DidIt), "=r"(IfThing), "+a"(ax)                   \
                     : "r"(ReplaceItWithMe), "2"(*IsEqualToMe)                \
                     : "memory", "cc");                                       \
    *IsEqualToMe = ax;                                                        \
    DidIt;                                                                    \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#define atomic_exchange_explicit(object, desired, order)                \
  __extension__({                                                       \
    __typeof__(object) __o = (object);                                  \
    __typeof__(*__o) __d = (desired);                                   \
    (void)(order);                                                      \
    __asm__ volatile("xchg\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                \
  })
#define atomic_fetch_add_explicit(object, operand, order)                    \
  __extension__({                                                            \
    __typeof__(object) __o = (object);                                       \
    __typeof__(*__o) __d = (desired);                                        \
    (void)(order);                                                           \
    __asm__ volatile("lock xadd\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                     \
  })
#define atomic_fetch_sub_explicit(object, operand, order) \
  atomic_fetch_add_explicit(object, -(operand), order)
#define atomic_load_explicit(object, order) \
  atomic_fetch_add_explicit(object, 0, order)
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#else /* non-gcc or old gcc w/o x86 */
#error "atomic operations not supported with this compiler and/or architecture"
#endif



/*!BEGIN libc/intrin/bsf.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
COSMOPOLITAN_C_START_

libcesque int bsf(int) pureconst;
libcesque int bsfl(long) pureconst;
libcesque int bsfll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsf(x)   __builtin_ctz(x)
#define bsfl(x)  __builtin_ctzl(x)
#define bsfll(x) __builtin_ctzll(x)
#endif

/* deprecated */
#define _bsf(x)   bsf(x)
#define _bsfl(x)  bsfl(x)
#define _bsfll(x) bsfll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */


/*!BEGIN libc/intrin/bsr.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
COSMOPOLITAN_C_START_

libcesque int bsr(int) pureconst;
libcesque int bsrl(long) pureconst;
libcesque int bsrll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsr(x)   (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
#define bsrl(x)  (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
#define bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
#endif

/* deprecated */
#define _bsr(x)   bsr(x)
#define _bsrl(x)  bsrl(x)
#define _bsrll(x) bsrll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */


/*!BEGIN libc/intrin/bswap.h */

#define COSMOPOLITAN_LIBC_BITS_BSWAP_H_
COSMOPOLITAN_C_START_

libcesque uint16_t bswap_16(uint16_t) pureconst;
libcesque uint32_t bswap_32(uint32_t) pureconst;
libcesque uint64_t bswap_64(uint64_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bswap_16(x) __builtin_bswap16(x)
#define bswap_32(x) __builtin_bswap32(x)
#define bswap_64(x) __builtin_bswap64(x)
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/cmpxchg.h */

#define COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
COSMOPOLITAN_C_START_

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME)                       \
  ({                                                                          \
    bool32 DidIt;                                                             \
    autotype(IFTHING) IfThing = (IFTHING);                                    \
    typeof(*IfThing) IsEqualToMe = (ISEQUALTOME);                             \
    typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME);                     \
    asm volatile(ZFLAG_ASM("cmpxchg\t%3,%1")                                  \
                 : ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
                 : "r"(ReplaceItWithMe)                                       \
                 : "cc");                                                     \
    DidIt;                                                                    \
  })
#else
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
  (*(IFTHING) == (ISEQUALTOME) ? (*(IFTHING) = (REPLACEITWITHME), 1) : 0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/dll.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define dll_make_first   __dll_make_first
#define dll_make_last    __dll_make_last
#define dll_remove       __dll_remove
#define dll_splice_after __dll_splice_after
COSMOPOLITAN_C_START_

#define DLL_CONTAINER(t, f, p) ((t *)(((char *)(p)) - offsetof(t, f)))

struct Dll {
  struct Dll *next;
  struct Dll *prev;
};

static inline void dll_init(struct Dll *e) {
  e->next = e;
  e->prev = e;
}

static inline int dll_is_alone(struct Dll *e) {
  return e->next == e && e->prev == e;
}

static inline int dll_is_empty(struct Dll *list) {
  return !list;
}

static inline struct Dll *dll_last(struct Dll *list) {
  return list;
}

static inline struct Dll *dll_first(struct Dll *list) {
  struct Dll *first = 0;
  if (list) first = list->next;
  return first;
}

static inline struct Dll *dll_next(struct Dll *list, struct Dll *e) {
  struct Dll *next = 0;
  if (e != list) next = e->next;
  return next;
}

static inline struct Dll *dll_prev(struct Dll *list, struct Dll *e) {
  struct Dll *prev = 0;
  if (e != list->next) prev = e->prev;
  return prev;
}

void dll_remove(struct Dll **, struct Dll *) paramsnonnull() libcesque;
void dll_make_last(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_make_first(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */


/*!BEGIN libc/intrin/hilbert.h */

#define COSMOPOLITAN_LIBC_BITS_HILBERT_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#define hilbert   __hilbert
#define unhilbert __unhilbert

libcesque long hilbert(long, long, long) pureconst;
libcesque axdx_t unhilbert(long, long) pureconst;

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/kprintf.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
#define COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_

#define klog         __klog
#define kprintf      __kprintf
#define ksnprintf    __ksnprintf
#define kvprintf     __kvprintf
#define kvsnprintf   __kvsnprintf
#define kloghandle   __kloghandle
#define kisdangerous __kisdangerous
#define uprintf      __uprintf
#define uvprintf     __uvprintf

#if !(__ASSEMBLER__ + __LINKER__ + 0)

COSMOPOLITAN_C_START_

void kprintf(const char *, ...) libcesque;
size_t ksnprintf(char *, size_t, const char *, ...) libcesque;
void kvprintf(const char *, va_list) libcesque;
size_t kvsnprintf(char *, size_t, const char *, va_list) libcesque;

bool32 kisdangerous(const void *) libcesque;

void klog(const char *, size_t) libcesque;
void _klog_serial(const char *, size_t) libcesque;
long kloghandle(void) libcesque;

void uprintf(const char *, ...) libcesque;
void uvprintf(const char *, va_list) libcesque;

#ifndef TINY
#define KINFOF(FMT, ...)                                         \
  do {                                                           \
    uprintf("\r\e[35m%s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                      \
  } while (0)
#define KWARNF(FMT, ...)                                                  \
  do {                                                                    \
    uprintf("\r\e[94;49mwarn: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                               \
  } while (0)
#else
#define KINFOF(FMT, ...) ((void)0)
#define KWARNF(FMT, ...) ((void)0)
#endif
#define KDIEF(FMT, ...)                                                     \
  do {                                                                      \
    kprintf("\r\e[30;101mfatal: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                                 \
    for (;;) asm volatile("cli\n\thlt");                                    \
  } while (0)

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_ */


/*!BEGIN libc/intrin/likely.h */

#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
#ifdef _COSMO_SOURCE

#define LIKELY(x)   __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_LIKELY(x) __builtin_expect_with_probability(!!(x), 1, 0.999)
#else
#define VERY_LIKELY(x) LIKELY(x)
#endif

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_UNLIKELY(x) __builtin_expect_with_probability(!!(x), 0, 0.999)
#else
#define VERY_UNLIKELY(x) UNLIKELY(x)
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/macros.h */

#define COSMOPOLITAN_LIBC_INTRIN_MACROS_H_


/*!BEGIN libc/nexgen32e/x86feature.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86FEATURE_H_
#ifdef __x86_64__


/*!BEGIN libc/nexgen32e/kcpuids.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_KCPUIDS_H_

#define KCPUIDS_0H        0
#define KCPUIDS_1H        1
#define KCPUIDS_2H        2
#define KCPUIDS_7H        3
#define KCPUIDS_80000001H 4
#define KCPUIDS_80000007H 5
#define KCPUIDS_16H       6
#define KCPUIDS_7H_1H     7
#define KCPUIDS_LEN       8
#define KCPUIDS_6H        -1 /* TBD: Thermal and Power Management */
#define KCPUIDS_DH        -1 /* TBD: Extended state features */
#define KCPUIDS_80000008H -1 /* TBD: AMD Miscellaneous */
#define KCPUIDS_8000000AH -1 /* TBD: AMD SVM */

#define KCPUIDS_EAX 0
#define KCPUIDS_EBX 1
#define KCPUIDS_ECX 2
#define KCPUIDS_EDX 3

#define KCPUIDS(LEAF, REG) _KCPUIDS(LEAF, REG)
#ifdef __ASSEMBLER__
#define _KCPUIDS(LEAF, REG) KCPUIDS_##LEAF * 16 + KCPUIDS_##REG * 4
#else
#define _KCPUIDS(LEAF, REG) kCpuids[KCPUIDS_##LEAF][KCPUIDS_##REG]
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const unsigned kCpuids[KCPUIDS_LEN][4];

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nexgen32e/x86compiler.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86COMPILER_H_
#ifdef __x86_64__

/**
 * @fileoverview x86 cpu feature compile-time requirement detection.
 * @see -march=native, -mavx2, etc.
 */

#ifdef __AES__
#define _X86_CC_AES 1
#else
#define _X86_CC_AES 0
#endif

#ifdef __AVX__
#define _X86_CC_AVX 1
#else
#define _X86_CC_AVX 0
#endif

#ifdef __AVX2__
#define _X86_CC_AVX2 1
#else
#define _X86_CC_AVX2 0
#endif

#ifdef __F16C__
#define _X86_CC_F16C 1
#else
#define _X86_CC_F16C 0
#endif

#ifdef __AVXVNNI__
#define _X86_CC_AVXVNNI 1
#else
#define _X86_CC_AVXVNNI 0
#endif

#ifdef __AVXVNNIINT8__
#define _X86_CC_AVXVNNIINT8 1
#else
#define _X86_CC_AVXVNNIINT8 0
#endif

#ifdef __AVXVNNIINT16__
#define _X86_CC_AVXVNNIINT16 1
#else
#define _X86_CC_AVXVNNIINT16 0
#endif

#ifdef __AVX512F__
#define _X86_CC_AVX512F 1
#else
#define _X86_CC_AVX512F 0
#endif

#ifdef __AVX512BF16__
#define _X86_CC_AVX512BF16 1
#else
#define _X86_CC_AVX512BF16 0
#endif

#ifdef __AVX512FP16__
#define _X86_CC_AVX512FP16 1
#else
#define _X86_CC_AVX512FP16 0
#endif

#ifdef __AVX512VBMI__
#define _X86_CC_AVX512VBMI 1
#else
#define _X86_CC_AVX512VBMI 0
#endif

#ifdef __AVX512VNNI__
#define _X86_CC_AVX512VNNI 1
#else
#define _X86_CC_AVX512VNNI 0
#endif

#ifdef __AVX5124VNNIW__
#define _X86_CC_AVX5124VNNIW 1
#else
#define _X86_CC_AVX5124VNNIW 0
#endif

#ifdef __ABM__
#define _X86_CC_ABM 1
#else
#define _X86_CC_ABM 0
#endif

#ifdef __BMI__
#define _X86_CC_BMI 1
#else
#define _X86_CC_BMI 0
#endif

#ifdef __BMI2__
#define _X86_CC_BMI2 1
#else
#define _X86_CC_BMI2 0
#endif

#ifdef __FMA__
#define _X86_CC_FMA 1
#else
#define _X86_CC_FMA 0
#endif

#ifdef __ADX__
#define _X86_CC_ADX 1
#else
#define _X86_CC_ADX 0
#endif

#ifdef __PCLMUL__
#define _X86_CC_PCLMUL 1
#else
#define _X86_CC_PCLMUL 0
#endif

#ifdef __POPCNT__
#define _X86_CC_POPCNT 1
#else
#define _X86_CC_POPCNT 0
#endif

#ifdef __RDRND__
#define _X86_CC_RDRND 1
#else
#define _X86_CC_RDRND 0
#endif

#ifdef __RDSEED__
#define _X86_CC_RDSEED 1
#else
#define _X86_CC_RDSEED 0
#endif

#ifdef __SHA__
#define _X86_CC_SHA 1
#else
#define _X86_CC_SHA 0
#endif

#ifdef __SSSE3__
#define _X86_CC_SSSE3 1
#else
#define _X86_CC_SSSE3 0
#endif

#ifdef __SSE__
#define _X86_CC_SSE 1
#else
#define _X86_CC_SSE 0
#endif

#ifdef __SSE2__
#define _X86_CC_SSE2 1
#else
#define _X86_CC_SSE2 0
#endif

#ifdef __SSE3__
#define _X86_CC_SSE3 1
#else
#define _X86_CC_SSE3 0
#endif

#ifdef __SSE4_1__
#define _X86_CC_SSE4_1 1
#else
#define _X86_CC_SSE4_1 0
#endif

#ifdef __SSE4_2__
#define _X86_CC_SSE4_2 1
#else
#define _X86_CC_SSE4_2 0
#endif

#ifdef __XSAVE__
#define _X86_CC_XSAVE 1
#else
#define _X86_CC_XSAVE 0
#endif

#ifdef __CLFLUSHOPT__
#define _X86_CC_CLFLUSHOPT 1
#else
#define _X86_CC_CLFLUSHOPT 0
#endif

#ifdef __RDPID__
#define _X86_CC_RDPID 1
#else
#define _X86_CC_RDPID 0
#endif

#endif /* __x86_64__ */

/* Returns true if x86 FEATURE is present.
   This performs a runtime check in normal portable builds.
   It's usually dead code eliminated for -march=native builds. */
#define X86_HAVE(FEATURE) _X86_HAVE(X86_##FEATURE)

/* Returns true if x86 FEATURE is present.
   This will *always* perform a runtime check.
   It's useful for checking compile-time cpu features are present. */
#define X86_CHECK(FEATURE) _X86_CHECK(X86_##FEATURE)

/* Returns true if x86 FEATURE is mandatory at build time.
   This will never perform runtime checks; it's always constant. */
#define X86_NEED(FEATURE) _X86_NEED(X86_##FEATURE)

/* clang-format off */
/*      --- FEATURE              LEAF       REG BIT  COMPILE-TIME-DEFINE */
#define X86_ACC                  1H,        EDX, 29, 0
#define X86_ACPI                 1H,        EDX, 22, 0
#define X86_ADX                  7H,        EBX, 19, _X86_CC_ADX              /* broadwell c. 2014 */
#define X86_AES                  1H,        ECX, 25, _X86_CC_AES              /* westmere c. 2010 */
#define X86_APIC                 1H,        EDX,  9, 0
#define X86_ARCH_CAPABILITIES    7H,        EDX, 29, 0
#define X86_AVX                  1H,        ECX, 28, _X86_CC_AVX              /* sandybridge c. 2012 */
#define X86_AVX2                 7H,        EBX,  5, _X86_CC_AVX2             /* haswell c. 2013 */
#define X86_AVXVNNI              7H_1H,     EAX,  4, _X86_CC_AVXVNNI
#define X86_AVXVNNIINT8          7H_1H,     EDX,  4, _X86_CC_AVXVNNIINT8
#define X86_AVXVNNIINT16         7H_1H,     EDX, 10, _X86_CC_AVXVNNIINT16
#define X86_AVX512BW             7H,        EBX, 30, 0
#define X86_AVX512CD             7H,        EBX, 28, 0
#define X86_AVX512DQ             7H,        EBX, 17, 0
#define X86_AVX512ER             7H,        EBX, 27, 0
#define X86_AVX512F              7H,        EBX, 16, _X86_CC_AVX512F
#define X86_AVX512IFMA           7H,        EBX, 21, 0
#define X86_AVX512PF             7H,        EBX, 26, 0
#define X86_AVX512VBMI           7H,        ECX,  1, _X86_CC_AVX512VBMI
#define X86_AVX512VL             7H,        EBX, 31, 0
#define X86_AVX512_4FMAPS        7H,        EDX,  3, 0
#define X86_AVX512_4VNNIW        7H,        EDX,  2, _X86_CC_AVX5124VNNIW
#define X86_AVX512_FP16          7H,        EDX, 23, _X86_CC_AVX512FP16
#define X86_AVX512_BF16          7H_1H,     EAX,  5, _X86_CC_AVX512BF16
#define X86_AVX512_BITALG        7H,        ECX, 12, 0
#define X86_AVX512_VBMI2         7H,        ECX,  6, 0
#define X86_AVX512_VNNI          7H,        ECX, 11, _X86_CC_AVX512VNNI
#define X86_AVX512_VP2INTERSECT  7H,        EDX,  8, 0
#define X86_AVX512_VPOPCNTDQ     7H,        ECX, 14, 0
#define X86_BMI                  7H,        EBX,  3, _X86_CC_BMI              /* haswell c. 2013 */
#define X86_BMI2                 7H,        EBX,  8, _X86_CC_BMI2             /* haswell c. 2013 */
#define X86_CID                  1H,        ECX, 10, 0
#define X86_CLDEMOTE             7H,        ECX, 25, 0
#define X86_CLFLUSH              1H,        EDX, 19, _X86_CC_SSE2
#define X86_CLFLUSHOPT           7H,        EBX, 23, _X86_CC_CLFLUSHOPT       /* skylake/zen  */
#define X86_CLWB                 7H,        EBX, 24, 0                        /* skylake/zen2 */
#define X86_CMOV                 1H,        EDX, 15, 0
#define X86_CQM                  7H,        EBX, 12, 0
#define X86_CX16                 1H,        ECX, 13, 0
#define X86_CX8                  1H,        EDX,  8, 0
#define X86_DCA                  1H,        ECX, 18, 0
#define X86_DE                   1H,        EDX,  2, 0
#define X86_DS                   1H,        EDX, 21, 0
#define X86_DSCPL                1H,        ECX,  4, 0
#define X86_DTES64               1H,        ECX,  2, 0
#define X86_ERMS                 7H,        EBX,  9, 0                        /* broaadwell c. 2014 */
#define X86_EST                  1H,        ECX,  7, 0
#define X86_F16C                 1H,        ECX, 29, _X86_CC_F16C
#define X86_FDP_EXCPTN_ONLY      7H,        EBX,  6, 0
#define X86_FLUSH_L1D            7H,        EDX, 28, 0
#define X86_FMA                  1H,        ECX, 12, _X86_CC_FMA              /* haswell c. 2013 */
#define X86_FPU                  1H,        EDX,  0, 0
#define X86_FSGSBASE             7H,        EBX,  0, 0
#define X86_FXSR                 1H,        EDX, 24, 0
#define X86_GBPAGES              80000001H, EDX, 26, 0
#define X86_GFNI                 7H,        ECX,  8, 0
#define X86_HLE                  7H,        EBX,  4, 0
#define X86_HT                   1H,        EDX, 28, 0
#define X86_HYPERVISOR           1H,        ECX, 31, 0
#define X86_IA64                 1H,        EDX, 30, 0
#define X86_INTEL_PT             7H,        EBX, 25, 0
#define X86_INTEL_STIBP          7H,        EDX, 27, 0
#define X86_INVPCID              1H,        EBX, 10, 0
#define X86_INVTSC               80000007H, EDX,  8, _X86_CC_POPCNT           /* i.e. not a K8 */
#define X86_LA57                 7H,        ECX, 16, 0
#define X86_LAHF_LM              80000001H, ECX,  0, 0
#define X86_LM                   80000001H, EDX, 29, 0
#define X86_MCA                  1H,        EDX, 14, 0
#define X86_MCE                  1H,        EDX,  7, 0
#define X86_MD_CLEAR             7H,        EDX, 10, 0
#define X86_MMX                  1H,        EDX, 23, 0
#define X86_MOVBE                1H,        ECX, 22, 0
#define X86_MOVDIR64B            7H,        ECX, 28, 0
#define X86_MOVDIRI              7H,        ECX, 27, 0
#define X86_MP                   80000001H, EDX, 19, 0
#define X86_MPX                  7H,        EBX, 14, 0
#define X86_MSR                  1H,        EDX,  5, 0
#define X86_MTRR                 1H,        EDX, 12, 0
#define X86_MWAIT                1H,        ECX,  3, 0
#define X86_NX                   80000001H, EDX, 20, 0
#define X86_OSPKE                7H,        ECX,  4, 0
#define X86_OSXSAVE              1H,        ECX, 27, 0
#define X86_PAE                  1H,        EDX,  6, 0
#define X86_PAT                  1H,        EDX, 16, 0
#define X86_PBE                  1H,        EDX, 31, 0
#define X86_PCID                 1H,        ECX, 17, 0
#define X86_PCLMUL               1H,        ECX,  1, _X86_CC_PCLMUL           /* westmere c. 2010 */
#define X86_PCONFIG              7H,        EDX, 18, 0
#define X86_PDCM                 1H,        ECX, 15, 0
#define X86_PGE                  1H,        EDX, 13, 0
#define X86_PKU                  7H,        ECX,  3, 0
#define X86_PN                   1H,        EDX, 18, 0
#define X86_POPCNT               1H,        ECX, 23, _X86_CC_POPCNT           /* nehalem c. 2008 */
#define X86_PSE                  1H,        EDX,  3, 0
#define X86_PSE36                1H,        EDX, 17, 0
#define X86_RDPID                7H,        ECX, 22, _X86_CC_RDPID            /* cannonlake c. 2018 */
#define X86_RDRND                1H,        ECX, 30, _X86_CC_RDRND            /* ivybridge c. 2012 */
#define X86_RDSEED               7H,        EBX, 18, _X86_CC_RDSEED           /* broadwell c. 2014 */
#define X86_RDTSCP               80000001H, EDX, 27, 0
#define X86_RDT_A                7H,        EBX, 15, 0
#define X86_RTM                  7H,        EBX, 11, 0
#define X86_SDBG                 1H,        ECX, 11, 0
#define X86_SELFSNOOP            1H,        EDX, 27, 0
#define X86_SEP                  1H,        EDX, 11, 0
#define X86_SHA                  7H,        EBX, 29, _X86_CC_SHA              /* goldmont (2016) */
#define X86_SMAP                 7H,        EBX, 20, 0
#define X86_SMEP                 7H,        EBX,  7, 0
#define X86_SMX                  1H,        ECX,  6, 0
#define X86_SPEC_CTRL            7H,        EDX, 26, 0
#define X86_SPEC_CTRL_SSBD       7H,        EDX, 31, 0
#define X86_SSE                  1H,        EDX, 25, _X86_CC_SSE              /* pentium c. 1999 */
#define X86_SSE2                 1H,        EDX, 26, _X86_CC_SSE2             /* pentium c. 2001 */
#define X86_SSE3                 1H,        ECX,  0, _X86_CC_SSE3             /* k8 c. 2005 */
#define X86_SSE4_1               1H,        ECX, 19, _X86_CC_SSE4_1           /* core c. 2006 */
#define X86_SSE4_2               1H,        ECX, 20, _X86_CC_SSE4_2           /* nehalem c. 2008 */
#define X86_SSSE3                1H,        ECX,  9, _X86_CC_SSSE3            /* westmere c. 2010 */
#define X86_SYSCALL              80000001H, EDX, 11, 0
#define X86_TM2                  1H,        ECX,  8, 0
#define X86_TME                  7H,        ECX, 13, 0
#define X86_TSC                  1H,        EDX,  4, 0
#define X86_TSC_ADJUST           7H,        EBX,  1, 0
#define X86_TSC_DEADLINE_TIMER   1H,        ECX, 24, 0
#define X86_TSX_FORCE_ABORT      7H,        EDX, 13, 0
#define X86_UMIP                 7H,        ECX,  2, 0
#define X86_VAES                 7H,        ECX,  9, 0
#define X86_VME                  1H,        EDX,  1, 0
#define X86_VMX                  1H,        ECX,  5, 0
#define X86_VPCLMULQDQ           7H,        ECX, 10, 0
#define X86_WAITPKG              7H,        ECX,  5, 0
#define X86_X2APIC               1H,        ECX, 21, 0
#define X86_XSAVE                1H,        ECX, 26, _X86_CC_XSAVE            /* sandybridge c. 2012 */
#define X86_XTPR                 1H,        ECX, 14, 0
#define X86_ZERO_FCS_FDS         7H,        EBX, 13, 0
#define X86_JIT                  80000001H, ECX, 31, 0                        /* IsGenuineBlink() */
#define X86_HYBRID_CPU           7H,        EDX, 15, 0                        /* Has performance and efficiency cores */
/* clang-format on */

/* AMD specific features */
#define X86_ABM            80000001H, ECX, 5, _X86_CC_ABM
#define X86_3DNOW          80000001H, EDX, 31, 0
#define X86_3DNOWEXT       80000001H, EDX, 30, 0
#define X86_3DNOWPREFETCH  80000001H, ECX, 8, 0
#define X86_BPEXT          80000001H, ECX, 26, 0
#define X86_CMP_LEGACY     80000001H, ECX, 1, 0
#define X86_CR8_LEGACY     80000001H, ECX, 4, 0
#define X86_EXTAPIC        80000001H, ECX, 3, 0
#define X86_FMA4           80000001H, ECX, 16, 0
#define X86_FXSR_OPT       80000001H, EDX, 25, 0
#define X86_IBS            80000001H, ECX, 10, 0
#define X86_LWP            80000001H, ECX, 15, 0
#define X86_MISALIGNSSE    80000001H, ECX, 7, 0
#define X86_MMXEXT         80000001H, EDX, 22, 0
#define X86_MWAITX         80000001H, ECX, 29, 0
#define X86_NODEID_MSR     80000001H, ECX, 19, 0
#define X86_OSVW           80000001H, ECX, 9, 0
#define X86_OVERFLOW_RECOV 80000007H, EBX, 0, 0
#define X86_PERFCTR_CORE   80000001H, ECX, 23, 0
#define X86_PERFCTR_LLC    80000001H, ECX, 28, 0
#define X86_PERFCTR_NB     80000001H, ECX, 24, 0
#define X86_PTSC           80000001H, ECX, 27, 0
#define X86_SKINIT         80000001H, ECX, 12, 0
#define X86_SMCA           80000007H, EBX, 3, 0
#define X86_SSE4A          80000001H, ECX, 6, 0
#define X86_SUCCOR         80000007H, EBX, 1, 0
#define X86_SVM            80000001H, ECX, 2, 0
#define X86_TBM            80000001H, ECX, 21, 0
#define X86_TCE            80000001H, ECX, 17, 0
#define X86_TOPOEXT        80000001H, ECX, 22, 0
#define X86_WDT            80000001H, ECX, 13, 0
#define X86_XOP            80000001H, ECX, 11, 0

/* Defined but not loaded by kCpuids.S */
#define X86_ARAT            6H, EAX, 2, 0
#define X86_AVIC            8000000AH, EDX, 13, 0
#define X86_CLZERO          80000008H, EBX, 0, 0
#define X86_DECODEASSISTS   8000000AH, EDX, 7, 0
#define X86_DTHERM          6H, EAX, 0, 0
#define X86_FLUSHBYASID     8000000AH, EDX, 6, 0
#define X86_HWP             6H, EAX, 7, 0
#define X86_HWP_ACT_WINDOW  6H, EAX, 9, 0
#define X86_HWP_EPP         6H, EAX, 10, 0
#define X86_HWP_NOTIFY      6H, EAX, 8, 0
#define X86_HWP_PKG_REQ     6H, EAX, 11, 0
#define X86_IBPB            80000008H, EBX, 12, 0
#define X86_IBRS            80000008H, EBX, 14, 0
#define X86_IDA             6H, EAX, 1, 0
#define X86_IRPERF          80000008H, EBX, 1, 0
#define X86_LBRV            8000000AH, EDX, 1, 0
#define X86_NPT             8000000AH, EDX, 0, 0
#define X86_NRIPS           8000000AH, EDX, 3, 0
#define X86_PAUSEFILTER     8000000AH, EDX, 10, 0
#define X86_PFTHRESHOLD     8000000AH, EDX, 12, 0
#define X86_PLN             6H, EAX, 4, 0
#define X86_PTS             6H, EAX, 6, 0
#define X86_SSBD            80000008H, EBX, 24, 0
#define X86_SSB_NO          80000008H, EBX, 26, 0
#define X86_STIBP           80000008H, EBX, 15, 0
#define X86_STIBP_ALWAYS_ON 80000008H, EBX, 17, 0
#define X86_SVML            8000000AH, EDX, 2, 0
#define X86_TSCRATEMSR      8000000AH, EDX, 4, 0
#define X86_VGIF            8000000AH, EDX, 16, 0
#define X86_VIRT_SSBD       80000008H, EBX, 25, 0
#define X86_VMCBCLEAN       8000000AH, EDX, 5, 0
#define X86_V_VMSAVE_VMLOAD 8000000AH, EDX, 15, 0
#define X86_WBNOINVD        80000008H, EBX, 9, 0
#define X86_XGETBV1         DH, EAX, 2, 0
#define X86_XSAVEC          DH, EAX, 1, 0
#define X86_XSAVEERPTR      80000008H, EBX, 2, 0
#define X86_XSAVEOPT        DH, EAX, 0, 0
#define X86_XSAVES          DH, EAX, 3, 0

#define X86_WORD(FEATURE) _X86_WORD(X86_##FEATURE)
#define X86_LEAF(FEATURE) _X86_LEAF(X86_##FEATURE)
#define X86_REG(FEATURE)  _X86_REG(X86_##FEATURE)
#define X86_BIT(FEATURE)  _X86_BIT(X86_##FEATURE)

#define _X86_CHECK(FEATURE) __X86_CHECK(FEATURE)
#define _X86_HAVE(FEATURE)  __X86_HAVE(FEATURE)
#define _X86_NEED(FEATURE)  __X86_NEED(FEATURE)
#define _X86_WORD(FEATURE)  __X86_WORD(FEATURE)
#define _X86_LEAF(FEATURE)  __X86_LEAF(FEATURE)
#define _X86_REG(FEATURE)   __X86_REG(FEATURE)
#define _X86_BIT(FEATURE)   __X86_BIT(FEATURE)

#define __X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  ___X86_CHECK(LEAF, REG, BIT, MANDATORY)
#define __X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  ___X86_HAVE(LEAF, REG, BIT, MANDATORY)
#define __X86_NEED(LEAF, REG, BIT, MANDATORY) MANDATORY
#define __X86_WORD(LEAF, REG, BIT, MANDATORY) KCPUIDS(LEAF, REG)
#define __X86_LEAF(LEAF, REG, BIT, MANDATORY) LEAF
#define __X86_REG(LEAF, REG, BIT, MANDATORY)  REG
#define __X86_BIT(LEAF, REG, BIT, MANDATORY)  BIT

#define ___X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  !!(KCPUIDS(LEAF, REG) & (1u << BIT))

#ifndef __ASSEMBLER__
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  !!(MANDATORY || KCPUIDS(LEAF, REG) & (1u << BIT))
#else
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  $1 << (BIT % 8), BIT / 8 + KCPUIDS(LEAF, REG)
#endif

#else
#define X86_HAVE(FEATURE)  0
#define X86_NEED(FEATURE)  0
#define X86_CHECK(FEATURE) 0
#endif /* __x86_64__ */

#define INTRIN_COMMUTATIVE "%"
#define INTRIN_NONCOMMUTATIVE

#if defined(__x86_64__) && !defined(__STRICT_ANSI__)

typedef char __intrin_xmm_t
    __attribute__((__vector_size__(16), __aligned__(16), __may_alias__));

#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C)                    \
  do {                                                                         \
    if (X86_HAVE(ISA)) {                                                       \
      __intrin_xmm_t *Xmm0 = (void *)(A);                                      \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);                \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(C);                \
      if (!X86_NEED(AVX)) {                                                    \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm2), "0"(*Xmm1));        \
      } else {                                                                 \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm1), "x"(*Xmm2)); \
      }                                                                        \
    } else {                                                                   \
      PURE(A, B, C);                                                           \
    }                                                                          \
  } while (0)

#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)                 \
  do {                                                               \
    if (X86_HAVE(ISA)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I));     \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)                 \
  do {                                                          \
    if (X86_HAVE(ISA)) {                                        \
      __intrin_xmm_t *Xmm0 = (void *)(A);                       \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B); \
      if (!X86_NEED(AVX)) {                                     \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "0"(*Xmm1));           \
      } else {                                                  \
        asm("v" OP "\t%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1));       \
      }                                                         \
    } else {                                                    \
      PURE(A, B);                                               \
    }                                                           \
  } while (0)

#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)                   \
  do {                                                               \
    if (!IsModeDbg() && X86_HAVE(ISA)) {                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "i"(I), "0"(*Xmm1));        \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#else
#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C) PURE(A, B, C)
#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)        PURE(A, B, I)
#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)          PURE(A, B, I)
#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)             PURE(A, B)
#endif /* X86 && !ANSI */



/*!BEGIN libc/intrin/newbie.h */

#define COSMOPOLITAN_LIBC_BITS_NEWBIE_H_

#define BYTE_ORDER    __BYTE_ORDER__
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define PDP_ENDIAN    __ORDER_PDP_ENDIAN__

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define htobe16(x) bswap_16(x)
#define be16toh(x) bswap_16(x)
#define betoh16(x) bswap_16(x)
#define htobe32(x) bswap_32(x)
#define be32toh(x) bswap_32(x)
#define betoh32(x) bswap_32(x)
#define htobe64(x) bswap_64(x)
#define be64toh(x) bswap_64(x)
#define betoh64(x) bswap_64(x)
#define htole16(x) (uint16_t)(x)
#define le16toh(x) (uint16_t)(x)
#define letoh16(x) (uint16_t)(x)
#define htole32(x) (uint32_t)(x)
#define le32toh(x) (uint32_t)(x)
#define letoh32(x) (uint32_t)(x)
#define htole64(x) (uint64_t)(x)
#define le64toh(x) (uint64_t)(x)
#define letoh64(x) (uint64_t)(x)
#else
#define htobe16(x) (uint16_t)(x)
#define be16toh(x) (uint16_t)(x)
#define betoh16(x) (uint16_t)(x)
#define htobe32(x) (uint32_t)(x)
#define be32toh(x) (uint32_t)(x)
#define betoh32(x) (uint32_t)(x)
#define htobe64(x) (uint64_t)(x)
#define be64toh(x) (uint64_t)(x)
#define betoh64(x) (uint64_t)(x)
#define htole16(x) bswap_16(x)
#define le16toh(x) bswap_16(x)
#define letoh16(x) bswap_16(x)
#define htole32(x) bswap_32(x)
#define le32toh(x) bswap_32(x)
#define letoh32(x) bswap_32(x)
#define htole64(x) bswap_64(x)
#define le64toh(x) bswap_64(x)
#define letoh64(x) bswap_64(x)
#endif



/*!BEGIN libc/intrin/packsswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKSSWB_H_
COSMOPOLITAN_C_START_

void packsswb(int8_t[16], const int16_t[8], const int16_t[8]);

#define packsswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packsswb, SSE2, "packsswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/packuswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKUSWB_H_
COSMOPOLITAN_C_START_

void packuswb(uint8_t[16], const int16_t[8], const int16_t[8]);

#define packuswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packuswb, SSE2, "packuswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/paddw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PADDW_H_
COSMOPOLITAN_C_START_

void paddw(int16_t[8], const int16_t[8], const int16_t[8]);

#define paddw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(paddw, SSE2, "paddw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/palignr.h */

#define COSMOPOLITAN_LIBC_INTRIN_PALIGNR_H_


/*!BEGIN libc/str/str.h */

#define COSMOPOLITAN_LIBC_STR_STR_H_

#define INVALID_CODEPOINT 0xfffd

#define _tolower(u) (0040 | (u))
#define _toupper(u) (0137 & (u))

#ifdef _COSMO_SOURCE
#define chomp         _chomp
#define chomp16       _chomp16
#define wchomp        _wchomp
#define tpenc         _tpenc
#define isutf8        _isutf8
#define istext        _istext
#define startswith    _startswith
#define startswithi   _startswithi
#define endswith      _endswith
#define wcsendswith   _wcsendswith
#define wcsstartswith _wcsstartswith
#endif /* _COSMO_SOURCE */

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

int isascii(int) libcesque;
int isspace(int) libcesque;
int isalpha(int) libcesque;
int isdigit(int) libcesque;
int isalnum(int) libcesque;
int isxdigit(int) libcesque;
int isprint(int) libcesque;
int islower(int) libcesque;
int isupper(int) libcesque;
int isblank(int) libcesque;
int iscntrl(int) libcesque;
int isgraph(int) libcesque;
int tolower(int) libcesque;
int ispunct(int) libcesque;
int toupper(int) libcesque;
int toascii(int) libcesque;

int iswalnum(wint_t) libcesque;
int iswalpha(wint_t) libcesque;
int iswblank(wint_t) libcesque;
int iswcntrl(wint_t) libcesque;
int iswdigit(wint_t) libcesque;
int iswgraph(wint_t) libcesque;
int iswlower(wint_t) libcesque;
int iswspace(wint_t) libcesque;
int iswupper(wint_t) libcesque;
int iswxdigit(wint_t) libcesque;
int iswpunct(wint_t) libcesque;
int iswprint(wint_t) libcesque;
int iswseparator(wint_t) libcesque;
wint_t towlower(wint_t) libcesque;
wint_t towupper(wint_t) libcesque;

void *memset(void *, int, size_t) memcpyesque;
void *memmove(void *, const void *, size_t) memcpyesque;
void *memcpy(void *restrict, const void *restrict, size_t) memcpyesque;
void *mempcpy(void *restrict, const void *restrict, size_t) memcpyesque;
char *hexpcpy(char *restrict, const void *restrict, size_t) memcpyesque;
void *memccpy(void *restrict, const void *restrict, int, size_t) memcpyesque;
void explicit_bzero(void *, size_t);

int memcmp(const void *, const void *, size_t) strlenesque;
int timingsafe_bcmp(const void *, const void *, size_t) libcesque;
int timingsafe_memcmp(const void *, const void *, size_t) libcesque;

size_t strlen(const char *) strlenesque;
size_t strnlen(const char *, size_t) strlenesque;
size_t strnlen_s(const char *, size_t) libcesque;
char *strchr(const char *, int) strlenesque;
void *memchr(const void *, int, size_t) strlenesque;
char *strchrnul(const char *, int) strlenesque returnsnonnull;
void *rawmemchr(const void *, int) strlenesque returnsnonnull;
size_t wcslen(const wchar_t *) strlenesque;
size_t wcsnlen(const wchar_t *, size_t) strlenesque;
size_t wcsnlen_s(const wchar_t *, size_t) libcesque;
wchar_t *wcschr(const wchar_t *, wchar_t) strlenesque;
wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) strlenesque;
wchar_t *wcschrnul(const wchar_t *, wchar_t)
strlenesque returnsnonnull;
char *strstr(const char *, const char *) strlenesque;
char *strcasestr(const char *, const char *) strlenesque;
wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque;
int strcmp(const char *, const char *) strlenesque;
int strncmp(const char *, const char *, size_t) strlenesque;
int wcscmp(const wchar_t *, const wchar_t *) strlenesque;
int wcsncmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int wmemcmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int strcasecmp(const char *, const char *) strlenesque;
int memcasecmp(const void *, const void *, size_t) strlenesque;
int wcscasecmp(const wchar_t *, const wchar_t *) strlenesque;
int strncasecmp(const char *, const char *, size_t) strlenesque;
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
char *strrchr(const char *, int) strlenesque;
void *memrchr(const void *, int, size_t) strlenesque;
wchar_t *wcsrchr(const wchar_t *, wchar_t) strlenesque;
void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque;
char *strpbrk(const char *, const char *) strlenesque;
wchar_t *wcspbrk(const wchar_t *, const wchar_t *) strlenesque;
size_t strspn(const char *, const char *) strlenesque;
size_t wcsspn(const wchar_t *, const wchar_t *) strlenesque;
size_t strcspn(const char *, const char *) strlenesque;
size_t wcscspn(const wchar_t *, const wchar_t *) strlenesque;
void *memfrob(void *, size_t) memcpyesque;
int strcoll(const char *, const char *) strlenesque;
char *strsep(char **, const char *) libcesque paramsnonnull();
char *stpcpy(char *, const char *) memcpyesque;
char *stpncpy(char *, const char *, size_t) memcpyesque;
char *strcat(char *, const char *) memcpyesque;
wchar_t *wcscat(wchar_t *, const wchar_t *) memcpyesque;
size_t strlcpy(char *, const char *, size_t) libcesque;
size_t strlcat(char *, const char *, size_t) libcesque;
size_t strxfrm(char *, const char *, size_t) libcesque;
char *strcpy(char *, const char *) memcpyesque;
wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque;
char *strncat(char *, const char *, size_t) memcpyesque;
wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t) memcpyesque;
char *strncpy(char *, const char *, size_t) memcpyesque;
char *strtok(char *, const char *) paramsnonnull((2)) libcesque;
char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
int strverscmp(const char *, const char *) libcesque;
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
void *memmem(const void *, size_t, const void *, size_t)
libcesque nosideeffect;
ssize_t strfmon(char *, size_t, const char *, ...) libcesque;
long a64l(const char *) libcesque;
char *l64a(long) libcesque;

typedef unsigned mbstate_t;

wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t) libcesque;
int mbtowc(wchar_t *, const char *, size_t) libcesque;
size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *) libcesque;
size_t mbstowcs(wchar_t *, const char *, size_t) libcesque;
size_t wcrtomb(char *, wchar_t, mbstate_t *) libcesque;
size_t c32rtomb(char *, char32_t, mbstate_t *) libcesque;
size_t mbrtoc32(char32_t *, const char *, size_t, mbstate_t *) libcesque;
size_t c16rtomb(char *, char16_t, mbstate_t *) libcesque;
size_t mbrtoc16(char16_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbrlen(const char *, size_t, mbstate_t *) libcesque;
size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *);
size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *);
size_t wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *) libcesque;
size_t wcstombs(char *, const wchar_t *, size_t) libcesque;
int mbsinit(const mbstate_t *) libcesque;
int mblen(const char *, size_t) libcesque;
int wctomb(char *, wchar_t) libcesque;
int wctob(wint_t) libcesque;
wint_t btowc(int) libcesque;

typedef unsigned wctype_t;
wctype_t wctype(const char *) strlenesque;
pureconst int iswctype(wint_t, wctype_t) libcesque;

typedef const int *wctrans_t;
wctrans_t wctrans(const char *) libcesque;
wint_t towctrans(wint_t, wctrans_t) libcesque;

int getsubopt(char **, char *const *, char **) libcesque paramsnonnull();
char *strsignal(int) returnsnonnull libcesque;
char *strerror(int) returnsnonnull dontthrow dontcallback;
errno_t strerror_r(int, char *, size_t) libcesque;
char *__xpg_strerror_r(int, char *, size_t) libcesque;

#ifdef _COSMO_SOURCE
pureconst uint64_t tpenc(uint32_t) libcesque;
char *chomp(char *) libcesque;
wchar_t *wchomp(wchar_t *) libcesque;
uint64_t __fnv(const void *, size_t) strlenesque;
bool32 startswith(const char *, const char *) strlenesque;
bool32 startswithi(const char *, const char *) strlenesque;
bool32 endswith(const char *, const char *) strlenesque;
bool32 istext(const void *, size_t) libcesque;
bool32 isutf8(const void *, size_t) libcesque;
const char *strsignal_r(int, char[21]) returnsnonnull libcesque __wur;
char16_t *chomp16(char16_t *) libcesque;
size_t strlen16(const char16_t *) strlenesque;
size_t strnlen16(const char16_t *, size_t) strlenesque;
char16_t *strchr16(const char16_t *, int) strlenesque;
void *memchr16(const void *, int, size_t) strlenesque;
char16_t *strchrnul16(const char16_t *, int) strlenesque returnsnonnull;
void *rawmemchr16(const void *, int) strlenesque returnsnonnull;
char16_t *strstr16(const char16_t *, const char16_t *) strlenesque;
int strcmp16(const char16_t *, const char16_t *) strlenesque;
int strncmp16(const char16_t *, const char16_t *, size_t) strlenesque;
int strcasecmp16(const char16_t *, const char16_t *) strlenesque;
int strncasecmp16(const char16_t *, const char16_t *, size_t) strlenesque;
char16_t *strrchr16(const char16_t *, int) strlenesque;
void *memrchr16(const void *, int, size_t) strlenesque;
char16_t *strpbrk16(const char16_t *, const char16_t *) strlenesque;
size_t strspn16(const char16_t *, const char16_t *) strlenesque;
size_t strcspn16(const char16_t *, const char16_t *) strlenesque;
char16_t *strcat16(char16_t *, const char16_t *) memcpyesque;
char16_t *strcpy16(char16_t *, const char16_t *) memcpyesque;
char16_t *strncat16(char16_t *, const char16_t *, size_t) memcpyesque;
char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque;
bool32 startswith16(const char16_t *, const char16_t *) strlenesque;
bool32 endswith16(const char16_t *, const char16_t *) strlenesque;
axdx_t tprecode8to16(char16_t *, size_t, const char *) libcesque;
axdx_t tprecode16to8(char *, size_t, const char16_t *) libcesque;
bool32 wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
bool32 wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
char *__join_paths(char *, size_t, const char *, const char *) libcesque __wur;
int __mkntpathat(int, const char *, int, char16_t[hasatleast 1024]);
#endif /* _COSMO_SOURCE */

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_POSIX_SOURCE) ||                                                 \
    (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE + 0 < 200809L) ||            \
    (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE + 0 < 700)
int bcmp(const void *, const void *, size_t) strlenesque;
void bcopy(const void *, void *, size_t) memcpyesque;
void bzero(void *, size_t) memcpyesque;
char *index(const char *, int) strlenesque;
char *rindex(const char *, int) strlenesque;
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

void palignr(void *, const void *, const void *, unsigned long);

#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__)
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
#define palignr(C, B, A, I)                                                \
  do {                                                                     \
    if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSSE3), \
                         1)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(C);                                  \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);            \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(A);            \
      if (__builtin_constant_p(I)) {                                       \
        if (!X86_NEED(AVX)) {                                              \
          asm("palignr\t%2,%1,%0"                                          \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm2), "i"(I), "0"(*Xmm1));                           \
        } else {                                                           \
          asm("vpalignr\t%3,%2,%1,%0"                                      \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm1), "x"(*Xmm2), "i"(I));                           \
        }                                                                  \
      } else {                                                             \
        unsigned long Vimm = (I);                                          \
        typeof(__palignrs) *Fn;                                            \
        if (__builtin_expect(Vimm < 32, 1)) {                              \
          Fn = (typeof(__palignrs) *)((uintptr_t)&__palignrs + Vimm * 8);  \
          *Xmm0 = Fn(*Xmm1, *Xmm2);                                        \
        } else {                                                           \
          memset(Xmm0, 0, 16);                                             \
        }                                                                  \
      }                                                                    \
    } else {                                                               \
      palignr(C, B, A, I);                                                 \
    }                                                                      \
  } while (0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pandn.h */

#define COSMOPOLITAN_LIBC_INTRIN_PANDN_H_
COSMOPOLITAN_C_START_

void pandn(uint64_t[2], const uint64_t[2], const uint64_t[2]);

#define pandn(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pandn, SSE2, "pandn", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTB_H_
COSMOPOLITAN_C_START_

void pcmpgtb(int8_t[16], const int8_t[16], const int8_t[16]);

#define pcmpgtb(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtb, SSE2, "pcmpgtb", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTW_H_
COSMOPOLITAN_C_START_

void pcmpgtw(int16_t[8], const int16_t[8], const int16_t[8]);

#define pcmpgtw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtw, SSE2, "pcmpgtw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmaddubsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMADDUBSW_H_
COSMOPOLITAN_C_START_

void pmaddubsw(int16_t[8], const uint8_t[16], const int8_t[16]);

#define pmaddubsw(W, B, C)                                                   \
  INTRIN_SSEVEX_X_X_X_(pmaddubsw, SSSE3, "pmaddubsw", INTRIN_NONCOMMUTATIVE, \
                       W, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmovmskb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMOVMSKB_H_
COSMOPOLITAN_C_START_

uint32_t pmovmskb(const uint8_t[16]);

#if defined(__x86_64__) && defined(__GNUC__)
#define pmovmskb(A)                                            \
  ({                                                           \
    uint32_t Mask;                                             \
    if (!IsModeDbg() && X86_HAVE(SSE2)) {                      \
      const __intrin_xmm_t *Xmm = (const __intrin_xmm_t *)(A); \
      if (!X86_NEED(AVX)) {                                    \
        asm("pmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));       \
      } else {                                                 \
        asm("vpmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));      \
      }                                                        \
    } else {                                                   \
      Mask = pmovmskb(A);                                      \
    }                                                          \
    Mask;                                                      \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmulhrsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMULHRSW_H_
COSMOPOLITAN_C_START_

void pmulhrsw(int16_t a[8], const int16_t b[8], const int16_t c[8]);

#define pmulhrsw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pmulhrsw, SSSE3, "pmulhrsw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/popcnt.h */

#define COSMOPOLITAN_LIBC_BITS_POPCNT_H_
COSMOPOLITAN_C_START_

libcesque size_t _countbits(const void *, size_t);
libcesque unsigned long popcnt(unsigned long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define popcnt(X)                                                \
  (__builtin_constant_p(X) ? __builtin_popcountll(X) : ({        \
    unsigned long PoP = (X);                                     \
    if (X86_HAVE(POPCNT)) {                                      \
      asm("popcnt\t%0,%0" : "+r"(PoP) : /* no inputs */ : "cc"); \
    } else {                                                     \
      PoP = (popcnt)(PoP);                                       \
    }                                                            \
    PoP;                                                         \
  }))
#else
#define popcnt(x) __builtin_popcountll(x)
#endif /* GNUC && !ANSI */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/psraw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PSRAW_H_
COSMOPOLITAN_C_START_

void psraw(int16_t[8], const int16_t[8], unsigned char) libcesque;
void psrawv(int16_t[8], const int16_t[8], const uint64_t[2]) libcesque;

#define psraw(A, B, I) INTRIN_SSEVEX_X_I_(psraw, SSE2, "psraw", A, B, I)
#define psrawv(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(psrawv, SSE2, "psraw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHBW_H_
COSMOPOLITAN_C_START_

void punpckhbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpckhbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhbw, SSE2, "punpckhbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHWD_H_
COSMOPOLITAN_C_START_

void punpckhwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpckhwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhwd, SSE2, "punpckhwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLBW_H_
COSMOPOLITAN_C_START_

void punpcklbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpcklbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklbw, SSE2, "punpcklbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLWD_H_
COSMOPOLITAN_C_START_

void punpcklwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpcklwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklwd, SSE2, "punpcklwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/repmovsb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
#ifdef _COSMO_SOURCE

forceinline void repmovsb(void **dest, const void **src, size_t cx) {
  char *di = (char *)*dest;
  const char *si = (const char *)*src;
  while (cx) *di++ = *si++, cx--;
  *dest = di, *src = si;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repmovsb(DI, SI, CX)                                       \
  ({                                                               \
    void *Di = *(DI);                                              \
    const void *Si = *(SI);                                        \
    size_t Cx = (CX);                                              \
    asm("rep movsb"                                                \
        : "=D"(Di), "=S"(Si), "=c"(Cx), "=m"(*(char(*)[Cx])Di)     \
        : "0"(Di), "1"(Si), "2"(Cx), "m"(*(const char(*)[Cx])Si)); \
    *(DI) = Di, *(SI) = Si;                                        \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/repstosb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
#ifdef _COSMO_SOURCE

forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
  unsigned char *di = (unsigned char *)dest;
  while (cx) *di++ = al, cx--;
  return di;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repstosb(DI, AL, CX)                         \
  ({                                                 \
    void *Di = (DI);                                 \
    size_t Cx = (CX);                                \
    unsigned char Al = (AL);                         \
    asm("rep stosb %b5,(%0)"                         \
        : "=D"(Di), "=c"(Cx), "=m"(*(char(*)[Cx])Di) \
        : "0"(Di), "1"(Cx), "a"(Al));                \
    Di;                                              \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/ubsan.h */

#define COSMOPOLITAN_LIBC_INTRIN_UBSAN_H_
COSMOPOLITAN_C_START_

extern bool32 __ubsan_strict;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/ulock.h */

#define COSMOPOLITAN_ULOCK_H_
COSMOPOLITAN_C_START_

/* both wake and wait take one of these */
#define UL_COMPARE_AND_WAIT          1 /* multi-thread */
#define UL_UNFAIR_LOCK               2
#define UL_COMPARE_AND_WAIT_SHARED   3 /* multi-thread/process */
#define UL_UNFAIR_LOCK64_SHARED      4
#define UL_COMPARE_AND_WAIT64        5
#define UL_COMPARE_AND_WAIT64_SHARED 6

#define ULF_WAKE_ALL             0x00000100
#define ULF_WAKE_THREAD          0x00000200 /* takes wake_value */
#define ULF_WAKE_ALLOW_NON_OWNER 0x00000400

#define ULF_WAIT_WORKQ_DATA_CONTENTION 0x00010000
#define ULF_WAIT_CANCEL_POINT          0x00020000 /* raises eintr */
#define ULF_WAIT_ADAPTIVE_SPIN         0x00040000

int ulock_wake(uint32_t, void *, uint64_t) libcesque;
int ulock_wait(uint32_t, void *, uint64_t, uint32_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/weaken.h */

#define COSMOPOLITAN_LIBC_BITS_WEAKEN_H_

#ifndef __chibicc__
#define _weaken(symbol)                                         \
  __extension__({                                               \
    extern __typeof__(symbol) symbol __attribute__((__weak__)); \
    &symbol;                                                    \
  })
#else
#define _weaken(symbol) (&(symbol))
#endif



/*!BEGIN libc/intrin/x86.h */

#define COSMOPOLITAN_LIBC_INTRIN_X86_H_
COSMOPOLITAN_C_START_

enum VendorSignatures {
  SIG_INTEL = 0x756e6547, /* Genu */
  SIG_AMD = 0x68747541,   /* Auth */
};

enum ProcessorVendors {
  VENDOR_INTEL = 1,
  VENDOR_AMD,
  VENDOR_OTHER,
  VENDOR_MAX
};

enum ProcessorTypes {
  INTEL_BONNELL = 1,
  INTEL_CORE2,
  INTEL_COREI7,
  AMDFAM10H,
  AMDFAM15H,
  INTEL_SILVERMONT,
  INTEL_KNL,
  AMD_BTVER1,
  AMD_BTVER2,
  AMDFAM17H,
  INTEL_KNM,
  INTEL_GOLDMONT,
  INTEL_GOLDMONT_PLUS,
  INTEL_TREMONT,
  AMDFAM19H,
  ZHAOXIN_FAM7H,
  INTEL_SIERRAFOREST,
  INTEL_GRANDRIDGE,
  INTEL_CLEARWATERFOREST,
  CPU_TYPE_MAX
};

enum ProcessorSubtypes {
  INTEL_COREI7_NEHALEM = 1,
  INTEL_COREI7_WESTMERE,
  INTEL_COREI7_SANDYBRIDGE,
  AMDFAM10H_BARCELONA,
  AMDFAM10H_SHANGHAI,
  AMDFAM10H_ISTANBUL,
  AMDFAM15H_BDVER1,
  AMDFAM15H_BDVER2,
  AMDFAM15H_BDVER3,
  AMDFAM15H_BDVER4,
  AMDFAM17H_ZNVER1,
  INTEL_COREI7_IVYBRIDGE,
  INTEL_COREI7_HASWELL,
  INTEL_COREI7_BROADWELL,
  INTEL_COREI7_SKYLAKE,
  INTEL_COREI7_SKYLAKE_AVX512,
  INTEL_COREI7_CANNONLAKE,
  INTEL_COREI7_ICELAKE_CLIENT,
  INTEL_COREI7_ICELAKE_SERVER,
  AMDFAM17H_ZNVER2,
  INTEL_COREI7_CASCADELAKE,
  INTEL_COREI7_TIGERLAKE,
  INTEL_COREI7_COOPERLAKE,
  INTEL_COREI7_SAPPHIRERAPIDS,
  INTEL_COREI7_ALDERLAKE,
  AMDFAM19H_ZNVER3,
  INTEL_COREI7_ROCKETLAKE,
  ZHAOXIN_FAM7H_LUJIAZUI,
  AMDFAM19H_ZNVER4,
  INTEL_COREI7_GRANITERAPIDS,
  INTEL_COREI7_GRANITERAPIDS_D,
  INTEL_COREI7_ARROWLAKE,
  INTEL_COREI7_ARROWLAKE_S,
  INTEL_COREI7_PANTHERLAKE,
  CPU_SUBTYPE_MAX
};

enum ProcessorFeatures {
  FEATURE_CMOV = 0,
  FEATURE_MMX,
  FEATURE_POPCNT,
  FEATURE_SSE,
  FEATURE_SSE2,
  FEATURE_SSE3,
  FEATURE_SSSE3,
  FEATURE_SSE4_1,
  FEATURE_SSE4_2,
  FEATURE_AVX,
  FEATURE_AVX2,
  FEATURE_SSE4_A,
  FEATURE_FMA4,
  FEATURE_XOP,
  FEATURE_FMA,
  FEATURE_AVX512F,
  FEATURE_BMI,
  FEATURE_BMI2,
  FEATURE_AES,
  FEATURE_PCLMUL,
  FEATURE_AVX512VL,
  FEATURE_AVX512BW,
  FEATURE_AVX512DQ,
  FEATURE_AVX512CD,
  FEATURE_AVX512ER,
  FEATURE_AVX512PF,
  FEATURE_AVX512VBMI,
  FEATURE_AVX512IFMA,
  FEATURE_AVX5124VNNIW,
  FEATURE_AVX5124FMAPS,
  FEATURE_AVX512VPOPCNTDQ,
  FEATURE_AVX512VBMI2,
  FEATURE_GFNI,
  FEATURE_VPCLMULQDQ,
  FEATURE_AVX512VNNI,
  FEATURE_AVX512BITALG,
  FEATURE_AVX512BF16,
  FEATURE_AVX512VP2INTERSECT,

  FEATURE_CMPXCHG16B = 46,
  FEATURE_F16C = 49,
  FEATURE_LAHF_LM = 54,
  FEATURE_LM,
  FEATURE_WP,
  FEATURE_LZCNT,
  FEATURE_MOVBE,

  FEATURE_AVX512FP16 = 94,
  FEATURE_X86_64_BASELINE,
  FEATURE_X86_64_V2,
  FEATURE_X86_64_V3,
  FEATURE_X86_64_V4,
  CPU_FEATURE_MAX
};

struct __processor_model {
  unsigned __cpu_vendor;
  unsigned __cpu_type;
  unsigned __cpu_subtype;
  unsigned __cpu_features[1];
  const char *__cpu_march;
};

extern struct __processor_model __cpu_model;

const char *__cpu_march(unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/bsd.h */

#define COSMOPOLITAN_LIBC_LOG_BSD_H_
COSMOPOLITAN_C_START_

void err(int, const char *, ...) wontreturn;
void verr(int, const char *, va_list) wontreturn;
void errc(int, int, const char *, ...) wontreturn;
void verrc(int, int, const char *, va_list) wontreturn;
void errx(int, const char *, ...) wontreturn;
void verrx(int, const char *, va_list) wontreturn;
void warn(const char *, ...);
void vwarn(const char *, va_list);
void warnc(int, const char *, ...);
void vwarnc(int, const char *, va_list);
void warnx(const char *, ...);
void vwarnx(const char *, va_list);
void err_set_exit(void (*)(int));

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/check.h */

#define COSMOPOLITAN_LIBC_LOG_CHECK_H_
COSMOPOLITAN_C_START_

#define CHECK(X, ...)         __CHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define CHECK_EQ(Y, X, ...)   __CHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NE(Y, X, ...)   __CHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LE(Y, X, ...)   __CHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LT(Y, X, ...)   __CHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GE(Y, X, ...)   __CHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GT(Y, X, ...)   __CHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NOTNULL(X, ...) __CHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define DCHECK(X, ...)       __DCHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define DCHECK_EQ(Y, X, ...) __DCHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NE(Y, X, ...) __DCHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LE(Y, X, ...) __DCHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LT(Y, X, ...) __DCHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GE(Y, X, ...) __DCHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GT(Y, X, ...) __DCHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NOTNULL(X, ...) \
  __DCHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define CHECK_ALIGNED(BYTES, VAR, ...)                                \
  do {                                                                \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                            \
      __check_fail_aligned(BYTES, (uintptr_t)VAR, __FILE__, __LINE__, \
                           "" __VA_ARGS__);                           \
      __builtin_unreachable();                                        \
    }                                                                 \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES);          \
  } while (0)

#define DCHECK_ALIGNED(BYTES, VAR, ...)                      \
  do {                                                       \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                   \
      __DCHK_ALIGNED(BYTES, (uintptr_t)VAR, "" __VA_ARGS__); \
      __builtin_unreachable();                               \
    }                                                        \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES); \
  } while (0)

#define __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...)                   \
  do {                                                                       \
    autotype(GOT) Got = (GOT);                                               \
    autotype(WANT) Want = (WANT);                                            \
    if (!(Want OP Got)) {                                                    \
      if (!NoDebug()) {                                                      \
        __check_fail(#SUFFIX, #OP, (uint64_t)Want, (WANTSTR), (uint64_t)Got, \
                     (GOTSTR), __FILE__, __LINE__, __VA_ARGS__);             \
      } else {                                                               \
        __check_fail_##SUFFIX((uint64_t)Want, (uint64_t)Got, __FILE__,       \
                              __LINE__, 0, __VA_ARGS__);                     \
      }                                                                      \
      __builtin_unreachable();                                               \
    }                                                                        \
  } while (0)

#ifdef NDEBUG
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, ...) \
  do {                                              \
    autotype(GOT) Got = (GOT);                      \
    autotype(WANT) Want = (WANT);                   \
    if (!(Want OP Got)) {                           \
      __builtin_unreachable();                      \
    }                                               \
  } while (0)
#else
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \
  __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, __VA_ARGS__)
#endif /* NDEBUG */

#ifdef NDEBUG
#define __DCHK_ALIGNED(BYTES, VAR, ...)
#else
#define __DCHK_ALIGNED(BYTES, VAR, ...) \
  __check_fail_aligned(BYTES, VAR, __FILE__, __LINE__, __VA_ARGS__)
#endif

void __check_fail(const char *, const char *, uint64_t, const char *, uint64_t,
                  const char *, const char *, int, const char *,
                  ...) relegated wontreturn;

void __check_fail_eq(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ne(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_le(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_lt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ge(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_gt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_aligned(unsigned, uint64_t, const char *, int, const char *,
                          ...) relegated wontreturn;

#ifdef __VSCODE_INTELLISENSE__
#undef __CHK
#define __CHK(...)
#undef __DCHK
#define __DCHK(...)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countbranch.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTBRANCH_H_
COSMOPOLITAN_C_START_

#define COUNTBRANCH(x) COUNTBRANCH_(x, #x, STRINGIFY(__FILE__), __LINE__)
#define COUNTBRANCH_(x, xs, file, line) \
  COUNTBRANCH__(x, STRINGIFY(xs), STRINGIFY(xs), file, line)
#define COUNTBRANCH__(x, xs, xss, file, line)                   \
  ({                                                            \
    bool Cond;                                                  \
    struct countbranch *Info;                                   \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31338:\t"                                              \
        ".asciz\t" xs "\n"                                      \
        "31339:\t"                                              \
        ".asciz\t" xss "\n"                                     \
        "31340:\t"                                              \
        ".asciz\t" file "\n\t"                                  \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountbranch_data(%%rip)\n\t"                     \
        ".previous\n\t"                                         \
        ".section .sort.data.countbranch.2,\"a\",@progbits\n\t" \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t0\n\t"                                          \
        ".quad\t0\n\t"                                          \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31339b\n\t"                                     \
        ".quad\t31340b\n\t"                                     \
        ".quad\t" #line "\n\t"                                  \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(Info));                                          \
    Cond = (x);                                                 \
    ++Info->total;                                              \
    if (Cond) ++Info->taken;                                    \
    Cond;                                                       \
  })

struct countbranch {
  long total;
  long taken;
  const char *code;
  const char *xcode;
  const char *file;
  long line;
};

extern struct countbranch countbranch_data[];

void countbranch_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countexpr.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_


/*!BEGIN libc/nexgen32e/bench.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_BENCH_H_


/*!BEGIN libc/nexgen32e/rdtsc.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSC_H_
COSMOPOLITAN_C_START_

/**
 * Reads CPU timestamp counter.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(INVTSC)
 */
#define rdtsc() __RDTSC("rdtsc")

/**
 * Reads CPU timestamp counter w/ full serialization.
 *
 * This macro inhibits CPU magic.
 * This macro inhibits compiler magic.
 *
 * The clock isn't read until:
 *
 *   1. previous instructions finish executing; and
 *   2. previous loads are globally visible; and
 *   3. previous stores are globally visible.
 *
 * Later instructions won't dispatch until RDTSC completes.
 *
 * @see X86_HAVE(INVTSC)
 */
#define mfence_lfence_rdtsc_lfence() \
  __RDTSC("mfence\n\tlfence\n\trdtsc\n\tlfence")

#ifdef __x86__
#define __RDTSC(ASM)                                                       \
  ({                                                                       \
    uint64_t Rax, Rdx;                                                     \
    asm volatile(ASM : "=a"(Rax), "=d"(Rdx) : /* no inputs */ : "memory"); \
    Rdx << 32 | Rax;                                                       \
  })
#elif defined(__aarch64__)
#define __RDTSC(ASM)                                \
  ({                                                \
    uint64_t _Ts;                                   \
    asm volatile("mrs\t%0,cntvct_el0" : "=r"(_Ts)); \
    _Ts * 48; /* the fudge factor */                \
  })
#elif defined(__powerpc64__)
#define __RDTSC(ASM)                           \
  ({                                           \
    uint64_t _Ts;                              \
    asm volatile("mfspr\t%0,268" : "=r"(_Ts)); \
    _Ts;                                       \
  })
#elif defined(__riscv)
#define __RDTSC(ASM)                         \
  ({                                         \
    uint64_t _Ts;                            \
    asm volatile("rdcycle\t%0" : "=r"(_Ts)); \
    _Ts;                                     \
  })
#endif

COSMOPOLITAN_C_END_

/**
 * @fileoverview NexGen32e Microbenchmarking.
 *
 * @see X86_HAVE(INVTSC)
 * @see libc/testlib/bench.h
 */

#ifdef __x86__
#define __startbench()                            \
  ({                                              \
    uint64_t Ticks;                               \
    asm volatile("lfence\n\t"                     \
                 "push\t%%rbx\n\t"                \
                 "cpuid\n\t"                      \
                 "pop\t%%rbx\n\t"                 \
                 "rdtsc\n\t"                      \
                 "shl\t%2,%%rdx\n\t"              \
                 "or\t%%rdx,%0"                   \
                 : "=a"(Ticks)                    \
                 : "0"(0), "J"(32)                \
                 : "rcx", "rdx", "memory", "cc"); \
    Ticks;                                        \
  })
#define __endbench()                                     \
  ({                                                     \
    uint64_t Ticks;                                      \
    asm volatile("rdtscp\n\t"                            \
                 "shl\t%1,%%rdx\n\t"                     \
                 "or\t%%rdx,%%rax\n\t"                   \
                 "mov\t%%rax,%0\n\t"                     \
                 "xor\t%%eax,%%eax\n\t"                  \
                 "push\t%%rbx\n\t"                       \
                 "cpuid\n\t"                             \
                 "pop\t%%rbx"                            \
                 : "=r"(Ticks)                           \
                 : "J"(32)                               \
                 : "rax", "rcx", "rdx", "memory", "cc"); \
    Ticks;                                               \
  })
#else
#define __startbench()                \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#define __endbench()                  \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#endif

#define __startbench_m() mfence_lfence_rdtsc_lfence()
#define __endbench_m()   __startbench_m()
#define __marker()       asm("nop")
#define __ordered()      asm volatile("" ::: "memory")
#define __fakeread(X)    asm volatile("" : /* no outputs */ : "g"(X))
#define __fakereadwrite(X)                 \
  ({                                       \
    autotype(X) Res = (X);                 \
    asm volatile("" : "=g"(Res) : "0"(X)); \
    Res;                                   \
  })

COSMOPOLITAN_C_START_

/**
 * Shows nanosecond timings histogram for expr at exit().
 */
#define COUNTEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, rdtsc, rdtsc, \
             "COUNTEXPR")

/**
 * Like COUNTEXPR() but can be used on function calls that return void.
 */
#define COUNTSTMT(stmt)                                                    \
  (void)COUNTEXPR_((stmt, 0), #stmt, STRINGIFY(__FILE__), __LINE__, rdtsc, \
                   rdtsc, "COUNTSTMT")

/**
 * Same as COUNTEXPR() but uses Intel's expensive measurement technique.
 */
#define BENCHEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, __startbench, \
             __endbench, "BENCHEXPR")

#define COUNTEXPR_(expr, code, file, line, start, stop, macro) \
  COUNTEXPR__(expr, STRINGIFY(code), file, line, start, stop, STRINGIFY(macro))

#define COUNTEXPR__(expr, code, file, line, start, stop, macro) \
  ({                                                            \
    struct countexpr *InfO;                                     \
    uint64_t t1_, t2_, TiCkS, NaNoS;                            \
    t1_ = start();                                              \
    asm volatile("" ::: "memory");                              \
    autotype(expr) ReS = (expr);                                \
    asm volatile("" ::: "memory");                              \
    t2_ = stop();                                               \
    TiCkS = t2_ >= t1_ ? t2_ - t1_ : ~t1_ + t2_ + 1;            \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31340:\t.asciz\t" file "\n\t"                          \
        "31338:\t.asciz\t" code "\n"                            \
        "31332:\t.asciz\t" macro "\n"                           \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountexpr_data(%%rip)\n\t"                       \
        ".previous\n\t"                                         \
        ".section .sort.data.countexpr.2,\"a\",@progbits\n\t"   \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t" #line "\n\t"                                  \
        ".quad\t31340b\n\t"                                     \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31332b\n\t"                                     \
        ".rept\t65\n\t"                                         \
        ".quad\t0\n\t"                                          \
        ".endr\n\t"                                             \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(InfO));                                          \
    /* approximation of round(x*.323018) which is usually */    \
    /* the ratio, between x86 rdtsc ticks and nanoseconds */    \
    NaNoS = (TiCkS * 338709) >> 20;                             \
    ++InfO->logos[NaNoS ? bsrl(NaNoS) + 1 : 0];                 \
    ReS;                                                        \
  })

struct countexpr {
  long line; /* zero for last entry */
  const char *file;
  const char *code;
  const char *macro;
  long logos[65];
};

extern struct countexpr countexpr_data[];

void countexpr_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/gdb.h */

#define COSMOPOLITAN_LIBC_LOG_GDB_H_


/*!BEGIN libc/sysv/consts/nr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NR_H_
#ifdef _COSMO_SOURCE
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __NR_exit;
extern const int __NR_exit_group;
extern const int __NR_read;
extern const int __NR_write;
extern const int __NR_open;
extern const int __NR_close;
extern const int __NR_stat;
extern const int __NR_fstat;
extern const int __NR_lstat;
extern const int __NR_poll;
extern const int __NR_ppoll;
extern const int __NR_lseek;
extern const int __NR_mmap;
extern const int __NR_msync;
extern const int __NR_mprotect;
extern const int __NR_munmap;
extern const int __NR_sigaction;
extern const int __NR_sigprocmask;
extern const int __NR_ioctl;
extern const int __NR_pread;
extern const int __NR_pwrite;
extern const int __NR_readv;
extern const int __NR_writev;
extern const int __NR_access;
extern const int __NR_pipe;
extern const int __NR_select;
extern const int __NR_pselect;
extern const int __NR_pselect6;
extern const int __NR_sched_yield;
extern const int __NR_mremap;
extern const int __NR_mincore;
extern const int __NR_madvise;
extern const int __NR_shmget;
extern const int __NR_shmat;
extern const int __NR_shmctl;
extern const int __NR_dup;
extern const int __NR_dup2;
extern const int __NR_pause;
extern const int __NR_nanosleep;
extern const int __NR_getitimer;
extern const int __NR_setitimer;
extern const int __NR_alarm;
extern const int __NR_getpid;
extern const int __NR_sendfile;
extern const int __NR_socket;
extern const int __NR_connect;
extern const int __NR_accept;
extern const int __NR_sendto;
extern const int __NR_recvfrom;
extern const int __NR_sendmsg;
extern const int __NR_recvmsg;
extern const int __NR_shutdown;
extern const int __NR_bind;
extern const int __NR_listen;
extern const int __NR_getsockname;
extern const int __NR_getpeername;
extern const int __NR_socketpair;
extern const int __NR_setsockopt;
extern const int __NR_getsockopt;
extern const int __NR_fork;
extern const int __NR_vfork;
extern const int __NR_posix_spawn;
extern const int __NR_execve;
extern const int __NR_wait4;
extern const int __NR_kill;
extern const int __NR_killpg;
extern const int __NR_clone;
extern const int __NR_tkill;
extern const int __NR_futex;
extern const int __NR_set_robust_list;
extern const int __NR_get_robust_list;
extern const int __NR_uname;
extern const int __NR_semget;
extern const int __NR_semop;
extern const int __NR_semctl;
extern const int __NR_shmdt;
extern const int __NR_msgget;
extern const int __NR_msgsnd;
extern const int __NR_msgrcv;
extern const int __NR_msgctl;
extern const int __NR_fcntl;
extern const int __NR_flock;
extern const int __NR_fsync;
extern const int __NR_fdatasync;
extern const int __NR_truncate;
extern const int __NR_ftruncate;
extern const int __NR_getcwd;
extern const int __NR_chdir;
extern const int __NR_fchdir;
extern const int __NR_rename;
extern const int __NR_mkdir;
extern const int __NR_rmdir;
extern const int __NR_creat;
extern const int __NR_link;
extern const int __NR_unlink;
extern const int __NR_symlink;
extern const int __NR_readlink;
extern const int __NR_chmod;
extern const int __NR_fchmod;
extern const int __NR_chown;
extern const int __NR_fchown;
extern const int __NR_lchown;
extern const int __NR_umask;
extern const int __NR_gettimeofday;
extern const int __NR_getrlimit;
extern const int __NR_getrusage;
extern const int __NR_sysinfo;
extern const int __NR_times;
extern const int __NR_ptrace;
extern const int __NR_syslog;
extern const int __NR_getuid;
extern const int __NR_getgid;
extern const int __NR_getppid;
extern const int __NR_getpgrp;
extern const int __NR_setsid;
extern const int __NR_getsid;
extern const int __NR_getpgid;
extern const int __NR_setpgid;
extern const int __NR_geteuid;
extern const int __NR_getegid;
extern const int __NR_getgroups;
extern const int __NR_setgroups;
extern const int __NR_setreuid;
extern const int __NR_setregid;
extern const int __NR_setuid;
extern const int __NR_setgid;
extern const int __NR_setresuid;
extern const int __NR_setresgid;
extern const int __NR_getresuid;
extern const int __NR_getresgid;
extern const int __NR_sigpending;
extern const int __NR_sigsuspend;
extern const int __NR_sigaltstack;
extern const int __NR_mknod;
extern const int __NR_mknodat;
extern const int __NR_mkfifo;
extern const int __NR_mkfifoat;
extern const int __NR_statfs;
extern const int __NR_fstatfs;
extern const int __NR_getpriority;
extern const int __NR_setpriority;
extern const int __NR_mlock;
extern const int __NR_munlock;
extern const int __NR_mlockall;
extern const int __NR_munlockall;
extern const int __NR_setrlimit;
extern const int __NR_chroot;
extern const int __NR_sync;
extern const int __NR_acct;
extern const int __NR_settimeofday;
extern const int __NR_mount;
extern const int __NR_reboot;
extern const int __NR_quotactl;
extern const int __NR_setfsuid;
extern const int __NR_setfsgid;
extern const int __NR_capget;
extern const int __NR_capset;
extern const int __NR_sigtimedwait;
extern const int __NR_sigqueueinfo;
extern const int __NR_personality;
extern const int __NR_ustat;
extern const int __NR_sysfs;
extern const int __NR_sched_setparam;
extern const int __NR_sched_getparam;
extern const int __NR_sched_setscheduler;
extern const int __NR_sched_getscheduler;
extern const int __NR_sched_get_priority_max;
extern const int __NR_sched_get_priority_min;
extern const int __NR_sched_rr_get_interval;
extern const int __NR_vhangup;
extern const int __NR_modify_ldt;
extern const int __NR_pivot_root;
extern const int __NR__sysctl;
extern const int __NR_prctl;
extern const int __NR_arch_prctl;
extern const int __NR_adjtimex;
extern const int __NR_umount2;
extern const int __NR_swapon;
extern const int __NR_swapoff;
extern const int __NR_sethostname;
extern const int __NR_setdomainname;
extern const int __NR_iopl;
extern const int __NR_ioperm;
extern const int __NR_init_module;
extern const int __NR_delete_module;
extern const int __NR_gettid;
extern const int __NR_readahead;
extern const int __NR_setxattr;
extern const int __NR_fsetxattr;
extern const int __NR_getxattr;
extern const int __NR_fgetxattr;
extern const int __NR_listxattr;
extern const int __NR_flistxattr;
extern const int __NR_removexattr;
extern const int __NR_fremovexattr;
extern const int __NR_lsetxattr;
extern const int __NR_lgetxattr;
extern const int __NR_llistxattr;
extern const int __NR_lremovexattr;
extern const int __NR_sched_setaffinity;
extern const int __NR_sched_getaffinity;
extern const int __NR_cpuset_getaffinity;
extern const int __NR_cpuset_setaffinity;
extern const int __NR_io_setup;
extern const int __NR_io_destroy;
extern const int __NR_io_getevents;
extern const int __NR_io_submit;
extern const int __NR_io_cancel;
extern const int __NR_lookup_dcookie;
extern const int __NR_epoll_create;
extern const int __NR_epoll_wait;
extern const int __NR_epoll_ctl;
extern const int __NR_getdents;
extern const int __NR_set_tid_address;
extern const int __NR_restart_syscall;
extern const int __NR_semtimedop;
extern const int __NR_fadvise;
extern const int __NR_timer_create;
extern const int __NR_timer_settime;
extern const int __NR_timer_gettime;
extern const int __NR_timer_getoverrun;
extern const int __NR_timer_delete;
extern const int __NR_clock_settime;
extern const int __NR_clock_gettime;
extern const int __NR_clock_getres;
extern const int __NR_clock_nanosleep;
extern const int __NR_tgkill;
extern const int __NR_mbind;
extern const int __NR_set_mempolicy;
extern const int __NR_get_mempolicy;
extern const int __NR_mq_open;
extern const int __NR_mq_unlink;
extern const int __NR_mq_timedsend;
extern const int __NR_mq_timedreceive;
extern const int __NR_mq_notify;
extern const int __NR_mq_getsetattr;
extern const int __NR_kexec_load;
extern const int __NR_waitid;
extern const int __NR_add_key;
extern const int __NR_request_key;
extern const int __NR_keyctl;
extern const int __NR_ioprio_set;
extern const int __NR_ioprio_get;
extern const int __NR_inotify_init;
extern const int __NR_inotify_add_watch;
extern const int __NR_inotify_rm_watch;
extern const int __NR_openat;
extern const int __NR_mkdirat;
extern const int __NR_fchownat;
extern const int __NR_utime;
extern const int __NR_utimes;
extern const int __NR_futimesat;
extern const int __NR_futimes;
extern const int __NR_futimens;
extern const int __NR_fstatat;
extern const int __NR_unlinkat;
extern const int __NR_renameat;
extern const int __NR_linkat;
extern const int __NR_symlinkat;
extern const int __NR_readlinkat;
extern const int __NR_fchmodat;
extern const int __NR_faccessat;
extern const int __NR_unshare;
extern const int __NR_splice;
extern const int __NR_tee;
extern const int __NR_vmsplice;
extern const int __NR_migrate_pages;
extern const int __NR_move_pages;
extern const int __NR_preadv;
extern const int __NR_pwritev;
extern const int __NR_utimensat;
extern const int __NR_fallocate;
extern const int __NR_posix_fallocate;
extern const int __NR_accept4;
extern const int __NR_dup3;
extern const int __NR_pipe2;
extern const int __NR_epoll_pwait;
extern const int __NR_epoll_create1;
extern const int __NR_perf_event_open;
extern const int __NR_inotify_init1;
extern const int __NR_tgsigqueueinfo;
extern const int __NR_signalfd;
extern const int __NR_signalfd4;
extern const int __NR_eventfd;
extern const int __NR_eventfd2;
extern const int __NR_timerfd_create;
extern const int __NR_timerfd_settime;
extern const int __NR_timerfd_gettime;
extern const int __NR_recvmmsg;
extern const int __NR_fanotify_init;
extern const int __NR_fanotify_mark;
extern const int __NR_prlimit;
extern const int __NR_name_to_handle_at;
extern const int __NR_open_by_handle_at;
extern const int __NR_clock_adjtime;
extern const int __NR_syncfs;
extern const int __NR_sendmmsg;
extern const int __NR_setns;
extern const int __NR_getcpu;
extern const int __NR_process_vm_readv;
extern const int __NR_process_vm_writev;
extern const int __NR_kcmp;
extern const int __NR_finit_module;
extern const int __NR_sched_setattr;
extern const int __NR_sched_getattr;
extern const int __NR_renameat2;
extern const int __NR_seccomp;
extern const int __NR_getrandom;
extern const int __NR_memfd_create;
extern const int __NR_kexec_file_load;
extern const int __NR_bpf;
extern const int __NR_execveat;
extern const int __NR_userfaultfd;
extern const int __NR_membarrier;
extern const int __NR_mlock2;
extern const int __NR_copy_file_range;
extern const int __NR_preadv2;
extern const int __NR_pwritev2;
extern const int __NR_pkey_mprotect;
extern const int __NR_pkey_alloc;
extern const int __NR_pkey_free;
extern const int __NR_statx;
extern const int __NR_io_pgetevents;
extern const int __NR_rseq;
extern const int __NR_pidfd_send_signal;
extern const int __NR_io_uring_setup;
extern const int __NR_io_uring_enter;
extern const int __NR_io_uring_register;
extern const int __NR_pledge;
extern const int __NR_msyscall;
extern const int __NR_ktrace;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/w.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_W_H_
COSMOPOLITAN_C_START_

extern const int WNOHANG;
extern const int WUNTRACED;
extern const int WCONTINUED;

#define WNOHANG    1
#define WUNTRACED  WUNTRACED
#define WCONTINUED WCONTINUED


COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/**
 * @fileoverview GDB Attach Support Code.
 *
 * The goal of these macros is to make the backtrace into the failing
 * code as short as possible. It also helps avoid GDB getting confused
 * about how we don't use its readability destroying unwind directives.
 */

extern volatile int g_gdbsync;

int gdbexec(const char *);
int AttachDebugger(intptr_t);

#define AttachDebugger(CONTINUE_TO_ADDR) /* shorten backtraces */ \
  SYNCHRONIZE_DEBUGGER((AttachDebugger)(CONTINUE_TO_ADDR))

#define SYNCHRONIZE_DEBUGGER(PID)                                    \
  ({                                                                 \
    int Rc, Pid = (PID);                                             \
    if (Pid != -1) {                                                 \
      while ((Rc = __inline_wait4(Pid, NULL, WNOHANG, NULL)) == 0) { \
        if (g_gdbsync) {                                             \
          g_gdbsync = 0;                                             \
          if (Rc > 0) Pid = 0;                                       \
          break;                                                     \
        } else {                                                     \
          sched_yield();                                             \
        }                                                            \
      }                                                              \
    }                                                                \
    Pid;                                                             \
  })

#ifdef __x86_64__
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE)     \
  ({                                                                      \
    int64_t WaAx;                                                         \
    if (!IsWindows()) {                                                   \
      asm volatile("mov\t%5,%%r10\n\t"                                    \
                   "syscall"                                              \
                   : "=a"(WaAx)                                           \
                   : "0"(__NR_wait4), "D"(PID), "S"(OPT_OUT_WSTATUS),     \
                     "d"(OPTIONS), "g"(OPT_OUT_RUSAGE)                    \
                   : "rcx", "r8", "r9", "r10", "r11", "memory", "cc");    \
    } else {                                                              \
      WaAx = sys_wait4_nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \
    }                                                                     \
    WaAx;                                                                 \
  })
#else
#define __inline_wait4 wait4
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/log.h */

#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
#define COSMOPOLITAN_LIBC_LOG_LOG_H_


/*!BEGIN libc/stdio/stdio.h */

#define COSMOPOLITAN_LIBC_STDIO_H_

#define EOF    -1  /* end of file */
#define WEOF   -1u /* end of file (multibyte) */
#define _IOFBF 0   /* fully buffered */
#define _IOLBF 1   /* line buffered */
#define _IONBF 2   /* no buffering */

#define L_tmpnam     20
#define L_ctermid    20
#define P_tmpdir     "/tmp"
#define FILENAME_MAX 1024
#define FOPEN_MAX    1000
#define TMP_MAX      10000
#define BUFSIZ       4096

COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct FILE;
typedef struct FILE FILE;

extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;

errno_t ferror(FILE *) libcesque paramsnonnull();
void clearerr(FILE *) libcesque paramsnonnull();
int feof(FILE *) libcesque paramsnonnull();
int getc(FILE *) libcesque paramsnonnull();
int putc(int, FILE *) libcesque paramsnonnull();
int fflush(FILE *) libcesque;
int fpurge(FILE *) libcesque;
int fgetc(FILE *) libcesque paramsnonnull();
char *fgetln(FILE *, size_t *) libcesque paramsnonnull((1));
int ungetc(int, FILE *) libcesque paramsnonnull();
int fileno(FILE *) libcesque paramsnonnull() nosideeffect;
int fputc(int, FILE *) libcesque paramsnonnull();
int fputs(const char *, FILE *) libcesque paramsnonnull();
int fputws(const wchar_t *, FILE *) libcesque paramsnonnull();
void flockfile(FILE *) libcesque paramsnonnull();
void funlockfile(FILE *) libcesque paramsnonnull();
int ftrylockfile(FILE *) libcesque paramsnonnull();
char *fgets(char *, int, FILE *) libcesque paramsnonnull();
wchar_t *fgetws(wchar_t *, int, FILE *) libcesque paramsnonnull();
wint_t putwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t fputwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t putwchar(wchar_t) libcesque;
wint_t getwchar(void) libcesque;
wint_t getwc(FILE *) libcesque paramsnonnull();
wint_t fgetwc(FILE *) libcesque paramsnonnull();
wint_t ungetwc(wint_t, FILE *) libcesque paramsnonnull();
int getchar(void) libcesque;
int putchar(int) libcesque;
int puts(const char *) libcesque;
ssize_t getline(char **, size_t *, FILE *) libcesque paramsnonnull();
ssize_t getdelim(char **, size_t *, int, FILE *) libcesque paramsnonnull();
FILE *fopen(const char *, const char *) libcesque paramsnonnull((2)) __wur;
FILE *fdopen(int, const char *) libcesque paramsnonnull() __wur;
FILE *fmemopen(void *, size_t, const char *) libcesque paramsnonnull((3)) __wur;
FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3));
size_t fread(void *, size_t, size_t, FILE *) libcesque paramsnonnull((4));
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4));
int fclose(FILE *) libcesque;
int fseek(FILE *, long, int) libcesque paramsnonnull();
long ftell(FILE *) libcesque paramsnonnull();
int fseeko(FILE *, int64_t, int) libcesque paramsnonnull();
int64_t ftello(FILE *) libcesque paramsnonnull();
void rewind(FILE *) libcesque paramsnonnull();
int fopenflags(const char *) libcesque paramsnonnull();
void setlinebuf(FILE *) libcesque;
void setbuf(FILE *, char *) libcesque;
void setbuffer(FILE *, char *, size_t) libcesque;
int setvbuf(FILE *, char *, int, size_t) libcesque;
int pclose(FILE *) libcesque;
char *ctermid(char *) libcesque;
void perror(const char *) libcesque relegated;

typedef uint64_t fpos_t;
char *gets(char *) libcesque paramsnonnull();
int fgetpos(FILE *, fpos_t *) libcesque paramsnonnull();
int fsetpos(FILE *, const fpos_t *) libcesque paramsnonnull();

FILE *tmpfile(void) libcesque __wur;
char *tmpnam(char *) libcesque __wur;
char *tmpnam_r(char *) libcesque __wur;

FILE *popen(const char *, const char *) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » formatting                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int printf(const char *, ...) printfesque(1) paramsnonnull((1)) libcesque;
int vprintf(const char *, va_list) paramsnonnull() libcesque;
int fprintf(FILE *, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vfprintf(FILE *, const char *, va_list) paramsnonnull() libcesque;
int scanf(const char *, ...) libcesque scanfesque(1);
int vscanf(const char *, va_list) libcesque;
int fscanf(FILE *, const char *, ...) libcesque scanfesque(2);
int vfscanf(FILE *, const char *, va_list) libcesque;

int snprintf(char *, size_t, const char *, ...) printfesque(3) libcesque;
int vsnprintf(char *, size_t, const char *, va_list) libcesque;
int sprintf(char *, const char *, ...) libcesque;
int vsprintf(char *, const char *, va_list) libcesque;

int fwprintf(FILE *, const wchar_t *, ...) libcesque;
int fwscanf(FILE *, const wchar_t *, ...) libcesque;
int swprintf(wchar_t *, size_t, const wchar_t *, ...) libcesque;
int swscanf(const wchar_t *, const wchar_t *, ...) libcesque;
int vfwprintf(FILE *, const wchar_t *, va_list) libcesque;
int vfwscanf(FILE *, const wchar_t *, va_list) libcesque;
int vswprintf(wchar_t *, size_t, const wchar_t *, va_list) libcesque;
int vswscanf(const wchar_t *, const wchar_t *, va_list) libcesque;
int vwprintf(const wchar_t *, va_list) libcesque;
int vwscanf(const wchar_t *, va_list) libcesque;
int wprintf(const wchar_t *, ...) libcesque;
int wscanf(const wchar_t *, ...) libcesque;
int fwide(FILE *, int) libcesque;

int sscanf(const char *, const char *, ...) libcesque scanfesque(2);
int vsscanf(const char *, const char *, va_list) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » allocating                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int asprintf(char **, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » without mutexes                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int getc_unlocked(FILE *) libcesque paramsnonnull();
int puts_unlocked(const char *) libcesque;
int getchar_unlocked(void) libcesque;
int putc_unlocked(int, FILE *) libcesque paramsnonnull();
int putchar_unlocked(int) libcesque;
void clearerr_unlocked(FILE *) libcesque;
int feof_unlocked(FILE *) libcesque;
int ferror_unlocked(FILE *) libcesque;
int fileno_unlocked(FILE *) libcesque;
int fflush_unlocked(FILE *) libcesque;
int fgetc_unlocked(FILE *) libcesque;
int fputc_unlocked(int, FILE *) libcesque;
size_t fread_unlocked(void *, size_t, size_t, FILE *) libcesque;
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *) libcesque;
char *fgets_unlocked(char *, int, FILE *) libcesque;
int fputs_unlocked(const char *, FILE *) libcesque;
wint_t getwc_unlocked(FILE *) libcesque;
wint_t getwchar_unlocked(void) libcesque;
wint_t fgetwc_unlocked(FILE *) libcesque;
wint_t fputwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwchar_unlocked(wchar_t) libcesque;
wchar_t *fgetws_unlocked(wchar_t *, int, FILE *) libcesque;
int fputws_unlocked(const wchar_t *, FILE *) libcesque;
wint_t ungetwc_unlocked(wint_t, FILE *) libcesque paramsnonnull();
int ungetc_unlocked(int, FILE *) libcesque paramsnonnull();
int fseek_unlocked(FILE *, int64_t, int) libcesque paramsnonnull();
ssize_t getdelim_unlocked(char **, size_t *, int, FILE *) paramsnonnull();
int fprintf_unlocked(FILE *, const char *, ...) printfesque(2) libcesque;
int vfprintf_unlocked(FILE *, const char *, va_list) paramsnonnull() libcesque;

COSMOPOLITAN_C_END_

#define kLogFatal   0
#define kLogError   1
#define kLogWarn    2
#define kLogInfo    3
#define kLogVerbose 4
#define kLogDebug   5
#define kLogNoise   6

/**
 * Log level for compile-time DCE.
 */
#ifndef LOGGABLELEVEL
#ifndef TINY
#define LOGGABLELEVEL kLogNoise
/* #elif IsTiny() */
/* #define LOGGABLELEVEL kLogInfo */
#else
#define LOGGABLELEVEL kLogVerbose
#endif
#endif

#ifdef TINY
#define _LOG_TINY 1
#else
#define _LOG_TINY 0
#endif

COSMOPOLITAN_C_START_

extern FILE *__log_file;

int __watch(void *, size_t);
void __die(void) relegated wontreturn; /* print backtrace and abort() */
void _meminfo(int);                    /* shows malloc statistics &c. */
void _memsummary(int);                 /* light version of same thing */
const char *commandvenv(const char *, const char *);
const char *GetAddr2linePath(void);
const char *GetGdbPath(void);
bool32 IsDebuggerPresent(bool32);
bool32 IsRunningUnderMake(void);
char *GetSymbolByAddr(int64_t);
void PrintGarbage(void);
void PrintGarbageNumeric(FILE *);
void PrintWindowsMemory(const char *, size_t);

#ifndef __STRICT_ANSI__

#define _LOG_UNLIKELY(x) __builtin_expect(!!(x), 0)

extern unsigned __log_level; /* log level for runtime check */

#define LOGGABLE(LEVEL)                                          \
  ((!__builtin_constant_p(LEVEL) || (LEVEL) <= LOGGABLELEVEL) && \
   (LEVEL) <= __log_level)

// log a message with the specified log level (not checking if LOGGABLE)
#define LOGF(LEVEL, FMT, ...)                                   \
  do {                                                          \
    if (!_LOG_TINY) _log_untrace();                             \
    flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    if (!_LOG_TINY) _log_retrace();                             \
  } while (0)

// report an error without backtrace and debugger invocation
#define FATALF(FMT, ...)                                            \
  do {                                                              \
    if (!_LOG_TINY) _log_untrace();                                 \
    flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                   \
  } while (0)

#define DIEF(FMT, ...)                                                \
  do {                                                                \
    if (!_LOG_TINY) _log_untrace();                                   \
    ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    __builtin_unreachable();                                          \
  } while (0)

#define ERRORF(FMT, ...)                   \
  do {                                     \
    if (LOGGABLE(kLogError)) {             \
      LOGF(kLogError, FMT, ##__VA_ARGS__); \
    }                                      \
  } while (0)

#define WARNF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogWarn)) {             \
      LOGF(kLogWarn, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define INFOF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogInfo)) {             \
      LOGF(kLogInfo, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define VERBOSEF(FMT, ...)                                                  \
  do {                                                                      \
    if (LOGGABLE(kLogVerbose)) {                                            \
      if (!_LOG_TINY) _log_untrace();                                       \
      fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                       \
    }                                                                       \
  } while (0)

#define DEBUGF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define NOISEF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define FLOGF(F, FMT, ...)                                        \
  do {                                                            \
    if (LOGGABLE(kLogInfo)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FWARNF(F, FMT, ...)                                       \
  do {                                                            \
    if (LOGGABLE(kLogWarn)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FFATALF(F, FMT, ...)                                     \
  do {                                                           \
    if (!_LOG_TINY) _log_untrace();                              \
    flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                \
  } while (0)

#define FDEBUGF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define FNOISEF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define LOGIFNEG1(FORM)                                                \
  ({                                                                   \
    int e = _log_get_errno();                                          \
    autotype(FORM) Ax = (FORM);                                        \
    if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
      if (!_LOG_TINY) _log_untrace();                                  \
      _log_errno(__FILE__, __LINE__, #FORM);                           \
      if (!_LOG_TINY) _log_retrace();                                  \
      _log_set_errno(e);                                               \
    }                                                                  \
    Ax;                                                                \
  })

#define LOGIFNULL(FORM)                      \
  ({                                         \
    int e = _log_get_errno();                \
    autotype(FORM) Ax = (FORM);              \
    if (Ax == NULL && LOGGABLE(kLogWarn)) {  \
      if (!_LOG_TINY) _log_untrace();        \
      _log_errno(__FILE__, __LINE__, #FORM); \
      if (!_LOG_TINY) _log_retrace();        \
      _log_set_errno(e);                     \
    }                                        \
    Ax;                                      \
  })

void _log_errno(const char *, int, const char *) relegated;
int _log_get_errno(void);
void _log_set_errno(int);
void _log_untrace(void);
void _log_retrace(void);
void _log_exit(int) wontreturn;

#define ARGS  unsigned, const char *, int, FILE *, const char *
#define ATTR  paramsnonnull((5)) printfesque(5)
#define ATTRV paramsnonnull((5))
void flogf(ARGS, ...) ATTR libcesque;
void vflogf(ARGS, va_list) ATTRV libcesque;
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfverbosef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fdebugf(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfdebugf(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fnoisef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfnoisef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void ffatalf(ARGS, ...) asm("flogf") ATTR relegated wontreturn libcesque;
void vffatalf(ARGS, va_list) asm("vflogf") ATTRV relegated wontreturn libcesque;
#undef ARGS
#undef ATTR
#undef ATTRV

#endif /* __STRICT_ANSI__ */
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_LOG_LOG_H_ */


/*!BEGIN libc/log/traceme.h */

#define COSMOPOLITAN_LIBC_LOG_TRACEME_H_
COSMOPOLITAN_C_START_

extern int traceme;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alg.h */

#define COSMOPOLITAN_LIBC_ALG_ALG_H_
COSMOPOLITAN_C_START_

void *bsearch(const void *, const void *, size_t, size_t,
              int (*)(const void *, const void *)) paramsnonnull() nosideeffect;
void *bsearch_r(const void *, const void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 2, 5)) nosideeffect;
void djbsort(int32_t *, size_t) libcesque;
void qsort3(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort_r(void *, size_t, size_t,
             int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 4));
void smoothsort(void *, size_t, size_t, int (*)(const void *, const void *));
void smoothsort_r(void *, size_t, size_t,
                  int (*)(const void *, const void *, void *), void *);
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
int heapsort_r(void *, size_t, size_t,
               int (*)(const void *, const void *, void *), void *);
int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
int mergesort_r(void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *);

int radix_sort_int32(int32_t *, size_t) libcesque;
int radix_sort_int64(int64_t *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alloca.h */

#define COSMOPOLITAN_LIBC_MEM_ALLOCA_H_

#define alloca(size) __builtin_alloca(size)



/*!BEGIN libc/mem/critbit0.h */

#define COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § data structures » critical bit tree (for c strings)       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct critbit0 {
  void *root;
  size_t count;
};

bool critbit0_contains(struct critbit0 *, const char *) libcesque nosideeffect
    paramsnonnull();
int critbit0_insert(struct critbit0 *, const char *) paramsnonnull();
bool critbit0_delete(struct critbit0 *, const char *) libcesque paramsnonnull();
void critbit0_clear(struct critbit0 *) libcesque paramsnonnull();
char *critbit0_get(struct critbit0 *, const char *);
intptr_t critbit0_allprefixed(struct critbit0 *, const char *,
                              intptr_t (*)(const char *, void *), void *)
    paramsnonnull((1, 2, 3)) libcesque;
int critbit0_emplace(struct critbit0 *, const void *, size_t) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/gc.h */

#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_
#define COSMOPOLITAN_LIBC_MEM_GC_H_
COSMOPOLITAN_C_START_

libcesque void _gc_free(void *);
libcesque void __defer(void *, void *, void *);
libcesque void gclongjmp(void *, int) wontreturn;
#define gc(THING)  defer((void *)_gc_free, (void *)(THING))
#define _gc(THING) defer((void *)_gc_free, (void *)(THING))
#define defer(FN, ARG)                             \
  ({                                               \
    autotype(ARG) Arg = (ARG);                     \
    /* prevent weird opts like tail call */        \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    __defer(__builtin_frame_address(0), FN, Arg);  \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    Arg;                                           \
  })

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */


/*!BEGIN libc/mem/mem.h */

#define COSMOPOLITAN_LIBC_MEM_MEM_H_

#define M_TRIM_THRESHOLD (-1)
#define M_GRANULARITY    (-2)
#define M_MMAP_THRESHOLD (-3)

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dynamic memory                                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

void free(void *) libcesque;
void *malloc(size_t) attributeallocsize((1)) mallocesque;
void *calloc(size_t, size_t) attributeallocsize((1, 2)) mallocesque;
void *memalign(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
void *realloc(void *, size_t) reallocesque;
void *realloc_in_place(void *, size_t) reallocesque;
void *reallocarray(void *, size_t, size_t) __wur;
void *valloc(size_t) attributeallocsize((1)) vallocesque;
void *pvalloc(size_t) vallocesque;
char *strdup(const char *) paramsnonnull() mallocesque;
char *strndup(const char *, size_t) paramsnonnull() mallocesque;
void *aligned_alloc(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
int posix_memalign(void **, size_t, size_t) libcesque;

int mallopt(int, int) libcesque;
int malloc_trim(size_t) libcesque;
size_t bulk_free(void **, size_t) libcesque;
size_t malloc_usable_size(void *) libcesque;
void **independent_calloc(size_t, size_t, void **) libcesque;
void **independent_comalloc(size_t, size_t *, void **) libcesque;

wchar_t *wcsdup(const wchar_t *) strlenesque __wur;

struct mallinfo {
  size_t arena;    /* non-mmapped space allocated from system */
  size_t ordblks;  /* number of free chunks */
  size_t smblks;   /* always 0 */
  size_t hblks;    /* always 0 */
  size_t hblkhd;   /* space in mmapped regions */
  size_t usmblks;  /* maximum total allocated space */
  size_t fsmblks;  /* always 0 */
  size_t uordblks; /* total allocated space */
  size_t fordblks; /* total free space */
  size_t keepcost; /* releasable (via malloc_trim) space */
};

struct mallinfo mallinfo(void) libcesque;

size_t malloc_footprint(void) libcesque;
size_t malloc_max_footprint(void) libcesque;
size_t malloc_footprint_limit(void) libcesque;
size_t malloc_set_footprint_limit(size_t) libcesque;
void malloc_inspect_all(void (*)(void *, void *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/cachesize.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CACHESIZE_H_

#define kCpuCacheTypeData        1
#define kCpuCacheTypeInstruction 2
#define kCpuCacheTypeUnified     3

COSMOPOLITAN_C_START_

unsigned _getcachesize(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/crc32.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CRC32_H_
COSMOPOLITAN_C_START_

extern const uint32_t kCrc32cTab[256];

void crc32init(uint32_t[hasatleast 256], uint32_t);
uint32_t crc32c(uint32_t, const void *, size_t) nosideeffect;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/ffs.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_
COSMOPOLITAN_C_START_

int ffs(int) pureconst;
int ffsl(long) pureconst;
int ffsll(long long) pureconst;

#ifdef __GNUC__
#define ffs(u)   __builtin_ffs(u)
#define ffsl(u)  __builtin_ffsl(u)
#define ffsll(u) __builtin_ffsll(u)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/kompressor.h */

#define COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
#ifdef _COSMO_SOURCE

#define rldecode  __rldecode
#define rldecode2 __rldecode2
#define lz4check  __lz4check
#define lz4cpy    __lz4cpy
#define lz4len    __lz4len
#define lz4decode __lz4decode

COSMOPOLITAN_C_START_

struct RlDecode {
  uint8_t repititions;
  uint8_t byte;
};

void rldecode(void *dest, const struct RlDecode *);
void rldecode2(void *dest, const struct RlDecode *);
const uint8_t *lz4check(const void *data);
void *lz4cpy(void *dest, const void *blockdata, size_t blocksize);
size_t lz4len(const void *blockdata, size_t blocksize);
void *lz4decode(void *dest, const void *src);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/nexgen32e/lz4.h */

#define COSMOPOLITAN_LIBC_LZ4_H_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4                                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  LZ4 is a brilliant framing format for REP MOVSB designed by Yann Collet.

  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md
  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Block_format.md
  @see http://ticki.github.io/blog/how-lz4-works/ */

#define LZ4_EOF                0
#define LZ4_VERSION            1
#define LZ4_MAGICNUMBER        0x184D2204
#define LZ4_SKIPPABLE0         0x184D2A50
#define LZ4_SKIPPABLEMASK      0xFFFFFFF0
#define LZ4_MAXHEADERSIZE      (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1)
#define LZ4_BLOCKMAXSIZE_64KB  4
#define LZ4_BLOCKMAXSIZE_256KB 5
#define LZ4_BLOCKMAXSIZE_1MB   6
#define LZ4_BLOCKMAXSIZE_4MB   7

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » frames                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_MAGIC(FRAME)                      READ32LE(FRAME)
#define LZ4_FRAME_VERSION(FRAME)              ((_LZ4_FRAME_FLG(FRAME) >> 6) & 3)
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
#define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1)
#define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \
  ((_LZ4_FRAME_FLG(FRAME) >> 2) & 1)
#define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1)
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME)     ((_LZ4_FRAME_BD(FRAME) >> 4) & 7)
#define LZ4_FRAME_RESERVED1(FRAME)        ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
#define LZ4_FRAME_RESERVED2(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
#define LZ4_FRAME_RESERVED3(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 0) & 15)
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
  (LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? READ64LE((FRAME) + 4 + 1 + 1) : 0)
#define LZ4_FRAME_DICTIONARYID(FRAME)                          \
  (LZ4_FRAME_DICTIONARYIDFLAG(FRAME)                           \
       ? READ32LE(((FRAME) + 4 + 1 + 1 +                       \
                   8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME))) \
       : 0)
#define LZ4_FRAME_HEADERCHECKSUM(FRAME)                                \
  (*((FRAME) + 4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
     4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME)))
#define LZ4_FRAME_HEADERSIZE(FRAME)                        \
  (4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
   4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME) + 1)
#define _LZ4_FRAME_FLG(FRAME) (*((FRAME) + 4))
#define _LZ4_FRAME_BD(FRAME)  (*((FRAME) + 5))

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » blocks                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_BLOCK_DATA(block)         (block + sizeof(uint32_t))
#define LZ4_BLOCK_DATASIZE(block)     (READ32LE(block) & 0x7fffffff)
#define LZ4_BLOCK_ISEOF(block)        (READ32LE(block) == LZ4_EOF)
#define LZ4_BLOCK_ISCOMPRESSED(block) ((READ32LE(block) & 0x80000000) == 0)
#define LZ4_BLOCK_SIZE(frame, block)              \
  (sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \
   (LZ4_FRAME_BLOCKCHECKSUMFLAG(frame) ? sizeof(uint8_t) : 0))

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nexgen32e.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NEXGEN32E_H_
COSMOPOLITAN_C_START_

extern long kHalfCache3;
extern const uint64_t kTens[20];
extern const uint32_t kSha256[64];
extern const uint64_t kSha512[80];
extern const unsigned char kTensIndex[64];

void CheckStackIsAligned(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nt2sysv.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_


/*!BEGIN libc/nexgen32e/trampoline.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_

#define TRAMPOLINE(FUNCTION, THUNK)   \
  ({                                  \
    typeof(FUNCTION) *Tramp;          \
    asm(".section .text.trampoline\n" \
        "183:\n\t"                    \
        "mov\t%1,%%eax\n\t"           \
        "jmp\t" #THUNK "\n\t"         \
        ".previous\n\t"               \
        "mov\t$183b,%k0"              \
        : "=r"(Tramp)                 \
        : "i"(FUNCTION));             \
    Tramp;                            \
  })


/**
 * Creates function to thunk FUNCTION from MSX64 to System V ABI.
 *
 * This macro should be used when specifying callbacks in the WIN32 API.
 */
#define NT2SYSV(FUNCTION) TRAMPOLINE(FUNCTION, __nt2sysv)



/*!BEGIN libc/nexgen32e/rdtscp.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_
COSMOPOLITAN_C_START_

#define TSC_AUX_CORE(MSR) ((MSR) & 0xfff)
#define TSC_AUX_NODE(MSR) (((MSR) >> 12) & 0xfff)

/**
 * Reads CPU timestamp counter and IA32_TSC_AUX.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(RDTSCP)
 */
#define rdtscp(OPT_OUT_IA32_TSC_AUX)               \
  ({                                               \
    uint64_t Rax, Rdx;                             \
    uint32_t Ecx, *EcxOut;                         \
    asm volatile("rdtscp"                          \
                 : "=a"(Rax), "=c"(Ecx), "=d"(Rdx) \
                 : /* no inputs */                 \
                 : "memory");                      \
    EcxOut = (OPT_OUT_IA32_TSC_AUX);               \
    if (EcxOut) *EcxOut = Ecx;                     \
    Rdx << 32 | Rax;                               \
  })

/**
 * Reads timestamp counter auxiliary model specific register value.
 */
#define rdpid()                                                           \
  ({                                                                      \
    long Msr;                                                             \
    bool32 Ok;                                                            \
    Ok = false;                                                           \
    if (X86_HAVE(RDPID)) {                                                \
      asm volatile("rdpid\t%0" : "=r"(Msr) : /* no inputs */ : "memory"); \
      Ok = true;                                                          \
    } else if (IsLinux()) {                                               \
      char *p = (char *)0x7b;                                             \
      asm volatile(ZFLAG_ASM("lsl\t%2,%1")                                \
                   : ZFLAG_CONSTRAINT(Ok), "=r"(Msr)                      \
                   : "r"(p)                                               \
                   : "memory");                                           \
    }                                                                     \
    if (!Ok && X86_HAVE(RDTSCP)) {                                        \
      asm volatile("rdtscp"                                               \
                   : "=c"(Msr)                                            \
                   : /* no inputs */                                      \
                   : "eax", "edx", "memory");                             \
      Ok = true;                                                          \
    }                                                                     \
    if (!Ok) {                                                            \
      Msr = -1;                                                           \
    }                                                                     \
    Msr;                                                                  \
  })

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/sha.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_SHA_H_
COSMOPOLITAN_C_START_

void sha1_transform_avx2(uint32_t[hasatleast 5], const void *, unsigned);
void sha1_transform_ni(uint32_t[hasatleast 5], const void *, unsigned);
void sha256_transform_rorx(uint32_t[hasatleast 8], const void *, unsigned);
void sha256_transform_ni(uint32_t[hasatleast 8], const void *, unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/stackframe.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
COSMOPOLITAN_C_START_

struct StackFrame {
  struct StackFrame *next;
  intptr_t addr;
};

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_ */


/*!BEGIN libc/nexgen32e/x86info.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86INFO_H_

#define kX86CpuStepping    ((KCPUIDS(1H, EAX) >> 0) & 15)
#define kX86CpuModelid     ((KCPUIDS(1H, EAX) >> 4) & 15)
#define kX86CpuFamilyid    ((KCPUIDS(1H, EAX) >> 8) & 15)
#define kX86CpuType        ((KCPUIDS(1H, EAX) >> 12) & 3)
#define kX86CpuExtmodelid  ((KCPUIDS(1H, EAX) >> 16) & 15)
#define kX86CpuExtfamilyid ((KCPUIDS(1H, EAX) >> 20) & 255)

#define kX86CpuFamily \
  (kX86CpuFamilyid + (kX86CpuFamilyid == 15 ? kX86CpuExtfamilyid : 0))

#define kX86CpuModel                                                       \
  (kX86CpuModelid |                                                        \
   (kX86CpuFamilyid == 6 || kX86CpuFamilyid == 15 ? kX86CpuExtmodelid : 0) \
       << 4)

#define kX86ProcessorModelKey                                                 \
  (kX86CpuExtfamilyid << 12 | kX86CpuFamilyid << 8 | kX86CpuExtmodelid << 4 | \
   kX86CpuModelid)

#define X86_MARCH_UNKNOWN        0
#define X86_MARCH_CORE2          1
#define X86_MARCH_NEHALEM        2
#define X86_MARCH_WESTMERE       3
#define X86_MARCH_SANDYBRIDGE    4
#define X86_MARCH_IVYBRIDGE      5
#define X86_MARCH_HASWELL        6
#define X86_MARCH_BROADWELL      7
#define X86_MARCH_SKYLAKE        8
#define X86_MARCH_KABYLAKE       9
#define X86_MARCH_CANNONLAKE     10
#define X86_MARCH_ICELAKE        11
#define X86_MARCH_TIGERLAKE      12
#define X86_MARCH_BONNELL        13
#define X86_MARCH_SALTWELL       14
#define X86_MARCH_SILVERMONT     15
#define X86_MARCH_AIRMONT        16
#define X86_MARCH_GOLDMONT       17
#define X86_MARCH_GOLDMONTPLUS   18
#define X86_MARCH_TREMONT        19
#define X86_MARCH_KNIGHTSLANDING 20
#define X86_MARCH_KNIGHTSMILL    21
#define X86_MARCH_SAPPHIRERAPIDS 22
#define X86_MARCH_ALDERLAKE      23
#define X86_MARCH_COMETLAKE      24
#define X86_MARCH_RAPTORLAKE     25
#define X86_MARCH_ROCKETLAKE     26

#define X86_GRADE_UNKNOWN   0
#define X86_GRADE_APPLIANCE 1
#define X86_GRADE_MOBILE    2
#define X86_GRADE_TABLET    3
#define X86_GRADE_DESKTOP   4
#define X86_GRADE_CLIENT    5
#define X86_GRADE_DENSITY   6
#define X86_GRADE_SERVER    7
#define X86_GRADE_SCIENCE   8

struct X86ProcessorModel {
  short key;
  unsigned char march;
  unsigned char grade;
};

extern const size_t kX86ProcessorModelCount;
extern const struct X86ProcessorModel kX86ProcessorModels[];

const struct X86ProcessorModel *getx86processormodel(short) nosideeffect;



/*!BEGIN libc/nt/enum/accessmask.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ACCESSMASK_H_

#define kNtGenericRead            0x80000000u
#define kNtGenericWrite           0x40000000u
#define kNtGenericExecute         0x20000000u
#define kNtGenericAll             0x10000000u
#define kNtDelete                 0x00010000u
#define kNtReadControl            0x00020000u
#define kNtWriteDac               0x00040000u
#define kNtWriteOwner             0x00080000u
#define kNtSynchronize            0x00100000u
#define kNtStandardRightsRequired 0x000F0000u
#define kNtStandardRightsRead     kNtReadControl
#define kNtStandardRightsWrite    kNtReadControl
#define kNtStandardRightsExecute  kNtReadControl
#define kNtStandardRightsAll      0x001F0000u
#define kNtSpecificRightsAll      0x0000FFFFu
#define kNtAccessSystemSecurity   0x01000000u
#define kNtMaximumAllowed         0x02000000u
#define kNtFileReadData           0x0001u
#define kNtFileListDirectory      0x0001u
#define kNtFileWriteData          0x0002u
#define kNtFileAddFile            0x0002u
#define kNtFileAppendData         0x0004u
#define kNtFileAddSubdirectory    0x0004u
#define kNtFileCreatePipeInstance 0x0004u
#define kNtFileReadEa             0x0008u
#define kNtFileWriteEa            0x0010u
#define kNtFileExecute            0x0020u
#define kNtFileTraverse           0x0020u
#define kNtFileDeleteChild        0x0040u
#define kNtFileReadAttributes     0x0080u
#define kNtFileWriteAttributes    0x0100u
#define kNtFileAllAccess          (kNtStandardRightsRequired | kNtSynchronize | 0x1FFu)
#define kNtFileGenericRead                                           \
  (kNtStandardRightsRead | kNtFileReadData | kNtFileReadAttributes | \
   kNtFileReadEa | kNtSynchronize)
#define kNtFileGenericWrite                                             \
  (kNtStandardRightsWrite | kNtFileWriteData | kNtFileWriteAttributes | \
   kNtFileWriteEa | kNtFileAppendData | kNtSynchronize)
#define kNtFileGenericExecute                                          \
  (kNtStandardRightsExecute | kNtFileReadAttributes | kNtFileExecute | \
   kNtSynchronize)
#define kNtTokenAssignPrimary    0x0001u
#define kNtTokenDuplicate        0x0002u
#define kNtTokenImpersonate      0x0004u
#define kNtTokenQuery            0x0008u
#define kNtTokenQuerySource      0x0010u
#define kNtTokenAdjustPrivileges 0x0020u
#define kNtTokenAdjustGroups     0x0040u
#define kNtTokenAdjustDefault    0x0080u
#define kNtTokenAdjustSessionid  0x0100u
#define kNtTokenAllAccessP                                                 \
  (kNtStandardRightsRequired | kNtTokenAssignPrimary | kNtTokenDuplicate | \
   kNtTokenImpersonate | kNtTokenQuery | kNtTokenQuerySource |             \
   kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | kNtTokenAdjustDefault)
#define kNtTokenAllAccess kNtTokenAllAccessP | kNtTokenAdjustSessionid
#define kNtTokenRead      kNtStandardRightsRead | kNtTokenQuery
#define kNtTokenWrite                                                         \
  (kNtStandardRightsWrite | kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | \
   kNtTokenAdjustDefault)
#define kNtTokenExecute kNtStandardRightsExecute
#define kNtTokenTrustConstraintMask \
  (kNtStandardRightsRead | kNtTokenQuery | kNtTokenQuerySource)
#define kNtTokenAccessPseudoHandleWin8 kNtTokenQuery | kNtTokenQuerySource
#define kNtTokenAccessPseudoHandle     kNtTokenAccessPseudoHandleWin8



/*!BEGIN libc/nt/enum/afd.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_AFD_H_

#define kNtAfdPollReceive          0x0001
#define kNtAfdPollReceiveExpedited 0x0002
#define kNtAfdPollSend             0x0004
#define kNtAfdPollDisconnect       0x0008
#define kNtAfdPollAbort            0x0010
#define kNtAfdPollLocalClose       0x0020
#define kNtAfdPollAccept           0x0080
#define kNtAfdPollConnectFail      0x0100



/*!BEGIN libc/nt/enum/bitblt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_BITBLT_H_

#define kNtSrccopy     0x00CC0020u /* src */
#define kNtSrcpaint    0x00EE0086u /* src | dst */
#define kNtSrcand      0x008800C6u /* src & dst */
#define kNtSrcinvert   0x00660046u /* src ^ dst */
#define kNtSrcerase    0x00440328u /* src & ~dst */
#define kNtNotsrccopy  0x00330008u /* ~src */
#define kNtNotsrcerase 0x001100A6u /* ~src & ~dst */
#define kNtMergecopy   0x00C000CAu /* (src & pattern) */
#define kNtMergepaint  0x00BB0226u /* ~src | dst */
#define kNtPatcopy     0x00F00021u /* pat */
#define kNtPatpaint    0x00FB0A09u /* wut */
#define kNtPatinvert   0x005A0049u /* pat ^ dst */
#define kNtDstinvert   0x00550009u /* ~dst */
#define kNtBlackness   0x00000042u /* black */
#define kNtWhiteness   0x00FF0062u /* white */



/*!BEGIN libc/nt/enum/callback.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CALLBACK_H_

#define kNtCallbackChunkFinished 0
#define kNtCallbackStreamSwitch  1



/*!BEGIN libc/nt/enum/color.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COLOR_H_

#define kNtColorScrollbar               0
#define kNtColorBackground              1
#define kNtColorActivecaption           2
#define kNtColorInactivecaption         3
#define kNtColorMenu                    4
#define kNtColorWindow                  5
#define kNtColorWindowframe             6
#define kNtColorMenutext                7
#define kNtColorWindowtext              8
#define kNtColorCaptiontext             9
#define kNtColorActiveborder            10
#define kNtColorInactiveborder          11
#define kNtColorAppworkspace            12
#define kNtColorHighlight               13
#define kNtColorHighlighttext           14
#define kNtColorBtnface                 15
#define kNtColorBtnshadow               16
#define kNtColorGraytext                17
#define kNtColorBtntext                 18
#define kNtColorInactivecaptiontext     19
#define kNtColorBtnhighlight            20
#define kNtColor3ddkshadow              21
#define kNtColor3dlight                 22
#define kNtColorInfotext                23
#define kNtColorInfobk                  24
#define kNtColorHotlight                26
#define kNtColorGradientactivecaption   27
#define kNtColorGradientinactivecaption 28
#define kNtColorMenuhilight             29
#define kNtColorMenubar                 30



/*!BEGIN libc/nt/enum/computernameformat.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COMPUTERNAMEFORMAT_H_

#define kNtComputerNameNetBios                   0
#define kNtComputerNameDnsHostname               1
#define kNtComputerNameDnsDomain                 2
#define kNtComputerNameDnsFullyQualified         3
#define kNtComputerNamePhysicalNetBios           4
#define kNtComputerNamePhysicalDnsHostname       5
#define kNtComputerNamePhysicalDnsDomain         6
#define kNtComputerNamePhysicalDnsFullyQualified 7
#define kNtComputerName_MAX                      8



/*!BEGIN libc/nt/enum/consolemodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLEMODEFLAGS_H_

/* input mode */
#define kNtEnableProcessedInput 0x0001u
#define kNtEnableLineInput 0x0002u
#define kNtEnableEchoInput 0x0004u
#define kNtEnableWindowInput 0x0008u
#define kNtEnableMouseInput 0x0010u
#define kNtEnableInsertMode 0x0020u
#define kNtEnableQuickEditMode 0x0040u
#define kNtEnableExtendedFlags 0x0080u
#define kNtEnableAutoPosition 0x0100u
#define kNtEnableVirtualTerminalInput 0x0200u

/* output mode */
#define kNtEnableProcessedOutput 0x0001u
#define kNtEnableWrapAtEolOutput 0x0002u
#define kNtEnableVirtualTerminalProcessing 0x0004u
#define kNtDisableNewlineAutoReturn 0x0008u
#define kNtEnableLvbGridWorldwide 0x0010u



/*!BEGIN libc/nt/enum/consoleselectionflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLESELECTIONFLAGS_H_

#define kNtConsoleNoSelection 0x0000u
#define kNtConsoleSelectionInProgress 0x0001u
#define kNtConsoleSelectionNotEmpty 0x0002u
#define kNtConsoleMouseSelection 0x0004u
#define kNtConsoleMouseDown 0x0008u



/*!BEGIN libc/nt/enum/context.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONTEXT_H_

#define kNtContextAmd64 0x00100000

#define kNtContextControl        (kNtContextAmd64 | 0x00000001)
#define kNtContextInteger        (kNtContextAmd64 | 0x00000002)
#define kNtContextSegments       (kNtContextAmd64 | 0x00000004)
#define kNtContextFloatingPoint  (kNtContextAmd64 | 0x00000008)
#define kNtContextDebugRegisters (kNtContextAmd64 | 0x00000010)

#define kNtContextFull \
  (kNtContextControl | kNtContextInteger | kNtContextFloatingPoint)

#define kNtContextAll                                           \
  (kNtContextControl | kNtContextInteger | kNtContextSegments | \
   kNtContextFloatingPoint | kNtContextDebugRegisters)

#define kNtContextXstate (kNtContextAmd64 | 0x00000040)



/*!BEGIN libc/nt/enum/copyfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COPYFILE_H_

#define kNtCopyFileFailIfExists              0x00000001
#define kNtCopyFileRestartable               0x00000002
#define kNtCopyFileOpenSourceForWrite        0x00000004
#define kNtCopyFileAllowDecryptedDestination 0x00000008
#define kNtCopyFileCopySymlink               0x00000800
#define kNtCopyFileNoBuffering               0x00001000
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileResumeFromPause           0x00004000 /* Win8+ */
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileNoOffload                 0x00040000 /* Win8+ */
#define kNtCopyFileIgnoreEdpBlock            0x00400000 /* Win10+ */
#define kNtCopyFileIgnoreSourceEncryption    0x00800000 /* Win10+ */



/*!BEGIN libc/nt/enum/creationdisposition.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CREATIONDISPOSITION_H_

#define kNtCreateNew 1
#define kNtCreateAlways 2
#define kNtOpenExisting 3
#define kNtOpenAlways 4
#define kNtTruncateExisting 5



/*!BEGIN libc/nt/enum/cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CS_H_

#define kNtCsVredraw         0x00000001
#define kNtCsHredraw         0x00000002
#define kNtCsDblclks         0x00000008
#define kNtCsOwndc           0x00000020
#define kNtCsClassdc         0x00000040
#define kNtCsParentdc        0x00000080
#define kNtCsNoclose         0x00000200
#define kNtCsSavebits        0x00000800
#define kNtCsBytealignclient 0x00001000
#define kNtCsBytealignwindow 0x00002000
#define kNtCsGlobalclass     0x00004000
#define kNtCsIme             0x00010000
#define kNtCsDropshadow      0x00020000



/*!BEGIN libc/nt/enum/ctrlevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CTRLEVENT_H_

#define kNtCtrlCEvent 0      /* SIGINT */
#define kNtCtrlBreakEvent 1  /* SIGQUIT */
#define kNtCtrlCloseEvent 2  /* SIGHUP */
#define kNtCtrlLogoffEvent 5 /* SIGTERM */
#define kNtCtrlShutdownEvent 6



/*!BEGIN libc/nt/enum/cw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CW_H_

#define kNtCwUsedefault ((int)0x80000000)



/*!BEGIN libc/nt/enum/dialogresult.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_DIALOGRESULT_H_

#define kNtIdok       1
#define kNtIdcancel   2
#define kNtIdabort    3
#define kNtIdretry    4
#define kNtIdignore   5
#define kNtIdyes      6
#define kNtIdno       7
#define kNtIdclose    8
#define kNtIdhelp     9
#define kNtIdtryagain 10
#define kNtIdcontinue 11



/*!BEGIN libc/nt/enum/errormodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ERRORMODEFLAGS_H_

#define kNtErrorModeDefault      0x0
#define kNtSemFailcriticalerrors 0x1
#define kNtSemNogpfaulterrorbox  0x2
#define kNtSemNoopenfileerrorbox 0x8000



/*!BEGIN libc/nt/enum/event.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENT_H_

#define kNtEventSystemSound            0x0001
#define kNtEventSystemAlert            0x0002
#define kNtEventSystemForeground       0x0003
#define kNtEventSystemMenustart        0x0004
#define kNtEventSystemMenuend          0x0005
#define kNtEventSystemMenupopupstart   0x0006
#define kNtEventSystemMenupopupend     0x0007
#define kNtEventSystemCapturestart     0x0008
#define kNtEventSystemCaptureend       0x0009
#define kNtEventSystemMovesizestart    0x000A
#define kNtEventSystemMovesizeend      0x000B
#define kNtEventSystemContexthelpstart 0x000C
#define kNtEventSystemContexthelpend   0x000D
#define kNtEventSystemDragdropstart    0x000E
#define kNtEventSystemDragdropend      0x000F
#define kNtEventSystemDialogstart      0x0010
#define kNtEventSystemDialogend        0x0011
#define kNtEventSystemScrollingstart   0x0012
#define kNtEventSystemScrollingend     0x0013
#define kNtEventSystemSwitchstart      0x0014
#define kNtEventSystemSwitchend        0x0015
#define kNtEventSystemMinimizestart    0x0016
#define kNtEventSystemMinimizeend      0x0017

#define kNtEventConsoleCaret            0x4001
#define kNtEventConsoleUpdateRegion     0x4002
#define kNtEventConsoleUpdateSimple     0x4003
#define kNtEventConsoleUpdateScroll     0x4004
#define kNtEventConsoleLayout           0x4005
#define kNtEventConsoleStartApplication 0x4006
#define kNtEventConsoleEndApplication   0x4007

#define kNtEventObjectCreate            0x8000
#define kNtEventObjectDestroy           0x8001
#define kNtEventObjectShow              0x8002
#define kNtEventObjectHide              0x8003
#define kNtEventObjectReorder           0x8004
#define kNtEventObjectFocus             0x8005
#define kNtEventObjectSelection         0x8006
#define kNtEventObjectSelectionadd      0x8007
#define kNtEventObjectSelectionremove   0x8008
#define kNtEventObjectSelectionwithin   0x8009
#define kNtEventObjectStatechange       0x800A
#define kNtEventObjectLocationchange    0x800B
#define kNtEventObjectNamechange        0x800C
#define kNtEventObjectDescriptionchange 0x800D
#define kNtEventObjectValuechange       0x800E
#define kNtEventObjectParentchange      0x800F
#define kNtEventObjectHelpchange        0x8010
#define kNtEventObjectDefactionchange   0x8011
#define kNtEventObjectAcceleratorchange 0x8012



/*!BEGIN libc/nt/enum/eventtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENTTYPE_H_

#define kNtNotificationEvent    0
#define kNtSynchronizationEvent 1



/*!BEGIN libc/nt/enum/exceptionhandleractions.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EXCEPTIONHANDLERACTIONS_H_

#define kNtExceptionExecuteHandler 0x1u
#define kNtExceptionContinueExecution 0xffffffffu
#define kNtExceptionContinueSearch 0x0u



/*!BEGIN libc/nt/enum/fileflagandattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEFLAGANDATTRIBUTES_H_

/**
 * MS-DOS File Attributes.
 *
 * @see GetFileInformationByHandle()
 * @see libc/sysv/consts.sh
 */
#define kNtFileAttributeReadonly    0x00000001u
#define kNtFileAttributeHidden      0x00000002u
#define kNtFileAttributeSystem      0x00000004u
#define kNtFileAttributeVolumelabel 0x00000008u
#define kNtFileAttributeDirectory   0x00000010u
#define kNtFileAttributeArchive     0x00000020u

/**
 * NT File Attributes.
 */
#define kNtFileAttributeDevice            0x00000040u
#define kNtFileAttributeNormal            0x00000080u
#define kNtFileAttributeTemporary         0x00000100u
#define kNtFileAttributeSparseFile        0x00000200u
#define kNtFileAttributeReparsePoint      0x00000400u
#define kNtFileAttributeCompressed        0x00000800u
#define kNtFileAttributeOffline           0x00001000u
#define kNtFileAttributeNotContentIndexed 0x00002000u
#define kNtFileAttributeEncrypted         0x00004000u

/**
 * NT File Flags.
 */
#define kNtFileFlagWriteThrough      0x80000000u
#define kNtFileFlagOverlapped        0x40000000u
#define kNtFileFlagNoBuffering       0x20000000u
#define kNtFileFlagRandomAccess      0x10000000u
#define kNtFileFlagSequentialScan    0x08000000u
#define kNtFileFlagDeleteOnClose     0x04000000u
#define kNtFileFlagBackupSemantics   0x02000000u
#define kNtFileFlagPosixSemantics    0x01000000u
#define kNtFileFlagOpenReparsePoint  0x00200000u
#define kNtFileFlagOpenNoRecall      0x00100000u
#define kNtFileFlagFirstPipeInstance 0x00080000u



/*!BEGIN libc/nt/enum/fileinfobyhandleclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFOBYHANDLECLASS_H_

#define kNtFileBasicInfo                  0 /* struct NtFileBasicInformation */
#define kNtFileStandardInfo               1 /* struct NtFileStandardInformation */
#define kNtFileNameInfo                   2 /* struct NtFileNameInformation */
#define kNtFileStreamInfo                 7 /* struct NtFileStreamInformation */
#define kNtFileCompressionInfo            8 /* struct NtFileCompressionInfo */
#define kNtFileAttributeTagInfo           9 /* struct NtFileAttributeTagInformation */
#define kNtFileIdBothDirectoryInfo        10
#define kNtFileIdBothDirectoryRestartInfo 11
#define kNtFileRemoteProtocolInfo         13
#define kNtFileFullDirectoryInfo          14 /* NtFileFullDirectoryInformation */
#define kNtFileFullDirectoryRestartInfo   15
#define kNtFileStorageInfo                16 /* win8+ */
#define kNtFileAlignmentInfo              17 /* win8+ */
#define kNtFileIdInfo                     18 /* win8+ */
#define kNtFileIdExtdDirectoryInfo        19 /* win8+ */
#define kNtFileIdExtdDirectoryRestartInfo 20 /* win8+ */

#define kNtFileRenameInfo         4
#define kNtFileDispositionInfo    5
#define kNtFileAllocationInfo     6
#define kNtFileEndOfFileInfo      7
#define kNtFileIoPriorityHintInfo 13
#define kNtFileDispositionInfoEx  22 /* win10+ */
#define kNtFileRenameInfoEx       23 /* win10+ */



/*!BEGIN libc/nt/enum/fileinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFORMATIONCLASS_H_

#define kNtFileDirectoryInformation 1 /*→ struct NtFileDirectoryInformation */
#define kNtFileFullDirectoryInformation 2 /*→ etc. */
#define kNtFileBothDirectoryInformation 3
#define kNtFileBasicInformation 4
#define kNtFileStandardInformation 5
#define kNtFileInternalInformation 6
#define kNtFileEaInformation 7
#define kNtFileAccessInformation 8
#define kNtFileNameInformation 9
#define kNtFileRenameInformation 10
#define kNtFileLinkInformation 11
#define kNtFileNamesInformation 12
#define kNtFileDispositionInformation 13
#define kNtFilePositionInformation 14
#define kNtFileFullEaInformation 15
#define kNtFileModeInformation 16
#define kNtFileAlignmentInformation 17
#define kNtFileAllInformation 18
#define kNtFileAllocationInformation 19
#define kNtFileEndOfFileInformation 20
#define kNtFileAlternateNameInformation 21
#define kNtFileStreamInformation 22
#define kNtFilePipeInformation 23
#define kNtFilePipeLocalInformation 24
#define kNtFilePipeRemoteInformation 25
#define kNtFileMailslotQueryInformation 26
#define kNtFileMailslotSetInformation 27
#define kNtFileCompressionInformation 28
#define kNtFileObjectIdInformation 29
#define kNtFileCompletionInformation 30
#define kNtFileMoveClusterInformation 31
#define kNtFileQuotaInformation 32
#define kNtFileReparsePointInformation 33
#define kNtFileNetworkOpenInformation 34
#define kNtFileAttributeTagInformation 35
#define kNtFileTrackingInformation 36
#define kNtFileIdBothDirectoryInformation 37
#define kNtFileIdFullDirectoryInformation 38
#define kNtFileValidDataLengthInformation 39
#define kNtFileShortNameInformation 40
#define kNtFileInformation_MAX 40



/*!BEGIN libc/nt/enum/filelockflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILELOCKFLAGS_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/filemapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMAPFLAGS_H_

#define kNtFileMapCopy           0x00000001u
#define kNtFileMapWrite          0x00000002u
#define kNtFileMapRead           0x00000004u
#define kNtFileMapExecute        0x00000020u
#define kNtFileMapReserve        0x80000000u
#define kNtFileMapTargetsInvalid 0x40000000u
#define kNtFileMapLargePages     0x20000000u



/*!BEGIN libc/nt/enum/filemovemethod.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMOVEMETHOD_H_

#define kNtFileBegin   0
#define kNtFileCurrent 1
#define kNtFileEnd     2



/*!BEGIN libc/nt/enum/filesharemode.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILESHAREFLAGS_H_

#define kNtFileShareExclusive 0x00000000u
#define kNtFileShareRead 0x00000001u
#define kNtFileShareWrite 0x00000002u
#define kNtFileShareDelete 0x00000004u



/*!BEGIN libc/nt/enum/filetype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILETYPE_H_

#define kNtFileTypeUnknown 0x0000
#define kNtFileTypeDisk    0x0001 /* @see S_ISBLK() */
#define kNtFileTypeChar    0x0002 /* @see S_ISCHR() */
#define kNtFileTypePipe    0x0003 /* @see S_ISFIFO() */
#define kNtFileTypeRemote  0x8000 /* unused -MSDN */



/*!BEGIN libc/nt/enum/fillattribute.h */

#define COSMOPOLITAN_LIBC_NT_NTFILLATTRIBUTE_H_

#define kNtForegroundBlue 0x0001
#define kNtForegroundGreen 0x0002
#define kNtForegroundRed 0x0004
#define kNtForegroundIntensity 0x0008
#define kNtBackgroundBlue 0x0010
#define kNtBackgroundGreen 0x0020
#define kNtBackgroundRed 0x0040
#define kNtBackgroundIntensity 0x0080



/*!BEGIN libc/nt/enum/findexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXINFOLEVELS_H_

#define kNtFindExInfoStandard     0
#define kNtFindExInfoBasic        1
#define kNtFindExInfoMaxInfoLevel 2



/*!BEGIN libc/nt/enum/findexsearchops.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXSEARCHOPS_H_

#define kNtFindExSearchNameMatch          0
#define kNtFindExSearchLimitToDirectories 1
#define kNtFindExSearchLimitToDevices     2
#define kNtFindExSearchMaxSearchOp        3



/*!BEGIN libc/nt/enum/formatmessageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FORMATMESSAGEFLAGS_H_

#define kNtFormatMessageAllocateBuffer 0x100
#define kNtFormatMessageIgnoreInserts  0x200
#define kNtFormatMessageFromString     0x400
#define kNtFormatMessageFromHmodule    0x800
#define kNtFormatMessageFromSystem     0x1000
#define kNtFormatMessageArgumentArray  0x2000
#define kNtFormatMessageMaxWidthMask   0xff



/*!BEGIN libc/nt/enum/fsctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSCTL_H_

#define kNtFsctlDisableLocalBuffering   0x000902B8u
#define kNtFsctlFilePrefetch            0x00090120u
#define kNtFsctlFilesystemGetStatistics 0x00090060u
#define kNtFsctlGetCompression          0x0009003Cu
#define kNtFsctlGetNtfsFileRecord       0x00090068u
#define kNtFsctlGetNtfsVolumeData       0x00090064u
#define kNtFsctlQueryAllocatedRanges    0x000940CFu
#define kNtFsctlScrubData               0x000902B0u
#define kNtFsctlSetCompression          0x0009C040u
#define kNtFsctlSetSparse               0x000900C4u
#define kNtFsctlSetZeroData             0x000980C8u
#define kNtFsctlGetReparsePoint         0x000900a8u
#define kNtFsctlSetReparsePoint         0x000900a4u



/*!BEGIN libc/nt/enum/fsinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSINFORMATIONCLASS_H_

#define kNtFileFsVolumeInformation 1
#define kNtFileFsLabelInformation 2
#define kNtFileFsSizeInformation 3
#define kNtFileFsDeviceInformation 4
#define kNtFileFsAttributeInformation 5
#define kNtFileFsControlInformation 6
#define kNtFileFsFullSizeInformation 7
#define kNtFileFsObjectIdInformation 8
#define kNtFileFsDriverPathInformation 9
#define kNtFileFsInformation_MAX 10



/*!BEGIN libc/nt/enum/getfileexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_GETFILEEXINFOLEVELS_H_

#define kNtGetFileExInfoStandard 0



/*!BEGIN libc/nt/enum/heap.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HEAP_H_

#define kNtHeapNoSerialize        1
#define kNtHeapGenerateExceptions 4
#define kNtHeapZeroMemory         8
#define kNtHeapReallocInPlaceOnly 16



/*!BEGIN libc/nt/enum/ht.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HT_H_

#define kNtHterror       -2
#define kNtHttransparent -1
#define kNtHtnowhere     0
#define kNtHtclient      1
#define kNtHtcaption     2
#define kNtHtsysmenu     3
#define kNtHtgrowbox     4
#define kNtHtsize        kNtHtgrowbox
#define kNtHtmenu        5
#define kNtHthscroll     6
#define kNtHtvscroll     7
#define kNtHtminbutton   8
#define kNtHtmaxbutton   9
#define kNtHtleft        10
#define kNtHtright       11
#define kNtHttop         12
#define kNtHttopleft     13
#define kNtHttopright    14
#define kNtHtbottom      15
#define kNtHtbottomleft  16
#define kNtHtbottomright 17
#define kNtHtborder      18
#define kNtHtreduce      kNtHtminbutton
#define kNtHtzoom        kNtHtmaxbutton
#define kNtHtsizefirst   kNtHtleft
#define kNtHtsizelast    kNtHtbottomright
#define kNtHtobject      19
#define kNtHtclose       20
#define kNtHthelp        21



/*!BEGIN libc/nt/enum/idc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IDC_H_
COSMOPOLITAN_C_START_

#define kNtIdcArrow    ((const char16_t *)32512)
#define kNtIdcIbeam    ((const char16_t *)32513)
#define kNtIdcWait     ((const char16_t *)32514)
#define kNtIdcCross    ((const char16_t *)32515)
#define kNtIdcUparrow  ((const char16_t *)32516)
#define kNtIdcSizenwse ((const char16_t *)32642)
#define kNtIdcSizenesw ((const char16_t *)32643)
#define kNtIdcSizewe   ((const char16_t *)32644)
#define kNtIdcSizens   ((const char16_t *)32645)
#define kNtIdcSizeall  ((const char16_t *)32646)
#define kNtIdcNo       ((const char16_t *)32648)
#define kNtIdcHand     ((const char16_t *)32649)
#define kNtIdcHelp     ((const char16_t *)32651)
#define kNtIdcPin      ((const char16_t *)32671)
#define kNtIdcPerson   ((const char16_t *)32672)

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/imageauxsymboltype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMAGEAUXSYMBOLTYPE_H_

#define kNtImageAuxSymbolTypeTokenDef 1



/*!BEGIN libc/nt/enum/importobjectnametype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTNAMETYPE_H_

enum NtImportObjectNameType {
  IMPORT_OBJECT_ORDINAL,
  IMPORT_OBJECT_NAME,
  IMPORT_OBJECT_NAME_NO_PREFIX,
  IMPORT_OBJECT_NAME_UNDECORATE,
  IMPORT_OBJECT_NAME_EXPORTAS
};



/*!BEGIN libc/nt/enum/importobjecttype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTTYPE_H_

enum NtImportObjectType {
  IMPORT_OBJECT_CODE,
  IMPORT_OBJECT_DATA,
  IMPORT_OBJECT_CONST
};



/*!BEGIN libc/nt/enum/io.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IO_H_

#define kNtIoReparseTagSymlink    0xa000000c
#define kNtIoReparseTagMountPoint 0xa0000003



/*!BEGIN libc/nt/enum/ioctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IOCTL_H_

#define kNtIoctlDiskGetDriveGeometry 0x00070000u
#define kNtIoctlAfdPoll              0x00012024u



/*!BEGIN libc/nt/enum/jobobjectinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_JOBOBJECTINFOCLASS_H_

#define kNtJobObjectBasicAccountingInformation         1
#define kNtJobObjectBasicLimitInformation              2
#define kNtJobObjectBasicProcessIdList                 3
#define kNtJobObjectBasicUIRestrictions                4
#define kNtJobObjectSecurityLimitInformation           5
#define kNtJobObjectEndOfJobTimeInformation            6
#define kNtJobObjectAssociateCompletionPortInformation 7
#define kNtJobObjectBasicAndIoAccountingInformation    8
#define kNtJobObjectExtendedLimitInformation           9
#define kNtJobObjectJobSetInformation                  10



/*!BEGIN libc/nt/enum/keyaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_

#define kNtKeyRead      0x00020019
#define kNtKeyWrite     0x00020006
#define kNtKeyExecute   0x00020019
#define kNtKeyAllAccess 0x000f003f



/*!BEGIN libc/nt/enum/keyedevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYEDEVENT_H_

#define kNtKeyedeventWait 0x00000001u
#define kNtKeyedeventWake 0x00000002u
#define kNtKeyedeventAllAccess \
  (kNtStandardRightsRequired | kNtKeyedeventWait | kNtKeyedeventWake)



/*!BEGIN libc/nt/enum/keyinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYINFORMATIONCLASS_H_

#define kNtKeyBasicInformation 0
#define kNtKeyNodeInformation  1
#define kNtKeyFullInformation  2
#define kNtKeyNameInformation  3



/*!BEGIN libc/nt/enum/kwaitreason.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KWAITREASON_H_

#define kNtExecutive 0
#define kNtFreePage 1
#define kNtPageIn 2
#define kNtPoolAllocation 3
#define kNtDelayExecution 4
#define kNtSuspended 5
#define kNtUserRequest 6
#define kNtWrExecutive 7
#define kNtWrFreePage 8
#define kNtWrPageIn 9
#define kNtWrPoolAllocation 10
#define kNtWrDelayExecution 11
#define kNtWrSuspended 12
#define kNtWrUserRequest 13
#define kNtWrEventPair 14
#define kNtWrQueue 15
#define kNtWrLpcReceive 16
#define kNtWrLpcReply 17
#define kNtWrVirtualMemory 18
#define kNtWrPageOut 19
#define kNtWrRendezvous 20
#define kNtSpare2 21
#define kNtSpare3 22
#define kNtSpare4 23
#define kNtSpare5 24
#define kNtSpare6 25
#define kNtWrKernel 26
#define kNtMaximumWaitReason 27



/*!BEGIN libc/nt/enum/lang.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LANG_H_

#define MAKELANGID(p, s) ((((uint16_t)(s)) << 10) | (uint16_t)(p))

#define kNtLangNeutral            0x00
#define kNtLangInvariant          0x7f
#define kNtLangAfrikaans          0x36
#define kNtLangAlbanian           0x1c
#define kNtLangAlsatian           0x84
#define kNtLangAmharic            0x5e
#define kNtLangArabic             0x01
#define kNtLangArmenian           0x2b
#define kNtLangAssamese           0x4d
#define kNtLangAzeri              0x2c
#define kNtLangAzerbaijani        0x2c
#define kNtLangBangla             0x45
#define kNtLangBashkir            0x6d
#define kNtLangBasque             0x2d
#define kNtLangBelarusian         0x23
#define kNtLangBengali            0x45
#define kNtLangBreton             0x7e
#define kNtLangBosnian            0x1a
#define kNtLangBosnianNeutral     0x781a
#define kNtLangBulgarian          0x02
#define kNtLangCatalan            0x03
#define kNtLangCentralKurdish     0x92
#define kNtLangCherokee           0x5c
#define kNtLangChinese            0x04
#define kNtLangChineseSimplified  0x04
#define kNtLangChineseTraditional 0x7c04
#define kNtLangCorsican           0x83
#define kNtLangCroatian           0x1a
#define kNtLangCzech              0x05
#define kNtLangDanish             0x06
#define kNtLangDari               0x8c
#define kNtLangDivehi             0x65
#define kNtLangDutch              0x13
#define kNtLangEnglish            0x09
#define kNtLangEstonian           0x25
#define kNtLangFaeroese           0x38
#define kNtLangFarsi              0x29
#define kNtLangFilipino           0x64
#define kNtLangFinnish            0x0b
#define kNtLangFrench             0x0c
#define kNtLangFrisian            0x62
#define kNtLangFulah              0x67
#define kNtLangGalician           0x56
#define kNtLangGeorgian           0x37
#define kNtLangGerman             0x07
#define kNtLangGreek              0x08
#define kNtLangGreenlandic        0x6f
#define kNtLangGujarati           0x47
#define kNtLangHausa              0x68
#define kNtLangHawaiian           0x75
#define kNtLangHebrew             0x0d
#define kNtLangHindi              0x39
#define kNtLangHungarian          0x0e
#define kNtLangIcelandic          0x0f
#define kNtLangIgbo               0x70
#define kNtLangIndonesian         0x21
#define kNtLangInuktitut          0x5d
#define kNtLangIrish              0x3c
#define kNtLangItalian            0x10
#define kNtLangJapanese           0x11
#define kNtLangKannada            0x4b
#define kNtLangKashmiri           0x60
#define kNtLangKazak              0x3f
#define kNtLangKhmer              0x53
#define kNtLangKiche              0x86
#define kNtLangKinyarwanda        0x87
#define kNtLangKonkani            0x57
#define kNtLangKorean             0x12
#define kNtLangKyrgyz             0x40
#define kNtLangLao                0x54
#define kNtLangLatvian            0x26
#define kNtLangLithuanian         0x27
#define kNtLangLowerSorbian       0x2e
#define kNtLangLuxembourgish      0x6e
#define kNtLangMacedonian         0x2f
#define kNtLangMalay              0x3e
#define kNtLangMalayalam          0x4c
#define kNtLangMaltese            0x3a
#define kNtLangManipuri           0x58
#define kNtLangMaori              0x81
#define kNtLangMapudungun         0x7a
#define kNtLangMarathi            0x4e
#define kNtLangMohawk             0x7c
#define kNtLangMongolian          0x50
#define kNtLangNepali             0x61
#define kNtLangNorwegian          0x14
#define kNtLangOccitan            0x82
#define kNtLangOdia               0x48
#define kNtLangOriya              0x48
#define kNtLangPashto             0x63
#define kNtLangPersian            0x29
#define kNtLangPolish             0x15
#define kNtLangPortuguese         0x16
#define kNtLangPular              0x67
#define kNtLangPunjabi            0x46
#define kNtLangQuechua            0x6b
#define kNtLangRomanian           0x18
#define kNtLangRomansh            0x17
#define kNtLangRussian            0x19
#define kNtLangSakha              0x85
#define kNtLangSami               0x3b
#define kNtLangSanskrit           0x4f
#define kNtLangScottishGaelic     0x91
#define kNtLangSerbian            0x1a
#define kNtLangSerbianNeutral     0x7c1a
#define kNtLangSindhi             0x59
#define kNtLangSinhalese          0x5b
#define kNtLangSlovak             0x1b
#define kNtLangSlovenian          0x24
#define kNtLangSotho              0x6c
#define kNtLangSpanish            0x0a
#define kNtLangSwahili            0x41
#define kNtLangSwedish            0x1d
#define kNtLangSyriac             0x5a
#define kNtLangTajik              0x28
#define kNtLangTamazight          0x5f
#define kNtLangTamil              0x49
#define kNtLangTatar              0x44
#define kNtLangTelugu             0x4a
#define kNtLangThai               0x1e
#define kNtLangTibetan            0x51
#define kNtLangTigrigna           0x73
#define kNtLangTigrinya           0x73
#define kNtLangTswana             0x32
#define kNtLangTurkish            0x1f
#define kNtLangTurkmen            0x42
#define kNtLangUighur             0x80
#define kNtLangUkrainian          0x22
#define kNtLangUpperSorbian       0x2e
#define kNtLangUrdu               0x20
#define kNtLangUzbek              0x43
#define kNtLangValencian          0x03
#define kNtLangVietnamese         0x2a
#define kNtLangWelsh              0x52
#define kNtLangWolof              0x88
#define kNtLangXhosa              0x34
#define kNtLangYakut              0x85
#define kNtLangYi                 0x78
#define kNtLangYoruba             0x6a
#define kNtLangZulu               0x35

#define kNtSublangNeutral                          0x00
#define kNtSublangDefault                          0x01
#define kNtSublangSysDefault                       0x02
#define kNtSublangCustomDefault                    0x03
#define kNtSublangCustomUnspecified                0x04
#define kNtSublangUiCustomDefault                  0x05
#define kNtSublangAfrikaansSouthAfrica             0x01
#define kNtSublangAlbanianAlbania                  0x01
#define kNtSublangAlsatianFrance                   0x01
#define kNtSublangAmharicEthiopia                  0x01
#define kNtSublangArabicSaudiArabia                0x01
#define kNtSublangArabicIraq                       0x02
#define kNtSublangArabicEgypt                      0x03
#define kNtSublangArabicLibya                      0x04
#define kNtSublangArabicAlgeria                    0x05
#define kNtSublangArabicMorocco                    0x06
#define kNtSublangArabicTunisia                    0x07
#define kNtSublangArabicOman                       0x08
#define kNtSublangArabicYemen                      0x09
#define kNtSublangArabicSyria                      0x0a
#define kNtSublangArabicJordan                     0x0b
#define kNtSublangArabicLebanon                    0x0c
#define kNtSublangArabicKuwait                     0x0d
#define kNtSublangArabicUae                        0x0e
#define kNtSublangArabicBahrain                    0x0f
#define kNtSublangArabicQatar                      0x10
#define kNtSublangArmenianArmenia                  0x01
#define kNtSublangAssameseIndia                    0x01
#define kNtSublangAzeriLatin                       0x01
#define kNtSublangAzeriCyrillic                    0x02
#define kNtSublangAzerbaijaniAzerbaijanLatin       0x01
#define kNtSublangAzerbaijaniAzerbaijanCyrillic    0x02
#define kNtSublangBanglaIndia                      0x01
#define kNtSublangBanglaBangladesh                 0x02
#define kNtSublangBashkirRussia                    0x01
#define kNtSublangBasqueBasque                     0x01
#define kNtSublangBelarusianBelarus                0x01
#define kNtSublangBengaliIndia                     0x01
#define kNtSublangBengaliBangladesh                0x02
#define kNtSublangBosnianBosniaHerzegovinaLatin    0x05
#define kNtSublangBosnianBosniaHerzegovinaCyrillic 0x08
#define kNtSublangBretonFrance                     0x01
#define kNtSublangBulgarianBulgaria                0x01
#define kNtSublangCatalanCatalan                   0x01
#define kNtSublangCentralKurdishIraq               0x01
#define kNtSublangCherokeeCherokee                 0x01
#define kNtSublangChineseTraditional               0x01
#define kNtSublangChineseSimplified                0x02
#define kNtSublangChineseHongkong                  0x03
#define kNtSublangChineseSingapore                 0x04
#define kNtSublangChineseMacau                     0x05
#define kNtSublangCorsicanFrance                   0x01
#define kNtSublangCzechCzechRepublic               0x01
#define kNtSublangCroatianCroatia                  0x01
#define kNtSublangCroatianBosniaHerzegovinaLatin   0x04
#define kNtSublangDanishDenmark                    0x01
#define kNtSublangDariAfghanistan                  0x01
#define kNtSublangDivehiMaldives                   0x01
#define kNtSublangDutch                            0x01
#define kNtSublangDutchBelgian                     0x02
#define kNtSublangEnglishUs                        0x01
#define kNtSublangEnglishUk                        0x02
#define kNtSublangEnglishAus                       0x03
#define kNtSublangEnglishCan                       0x04
#define kNtSublangEnglishNz                        0x05
#define kNtSublangEnglishEire                      0x06
#define kNtSublangEnglishSouthAfrica               0x07
#define kNtSublangEnglishJamaica                   0x08
#define kNtSublangEnglishCaribbean                 0x09
#define kNtSublangEnglishBelize                    0x0a
#define kNtSublangEnglishTrinidad                  0x0b
#define kNtSublangEnglishZimbabwe                  0x0c
#define kNtSublangEnglishPhilippines               0x0d
#define kNtSublangEnglishIndia                     0x10
#define kNtSublangEnglishMalaysia                  0x11
#define kNtSublangEnglishSingapore                 0x12
#define kNtSublangEstonianEstonia                  0x01
#define kNtSublangFaeroeseFaroeIslands             0x01
#define kNtSublangFilipinoPhilippines              0x01
#define kNtSublangFinnishFinland                   0x01
#define kNtSublangFrench                           0x01
#define kNtSublangFrenchBelgian                    0x02
#define kNtSublangFrenchCanadian                   0x03
#define kNtSublangFrenchSwiss                      0x04
#define kNtSublangFrenchLuxembourg                 0x05
#define kNtSublangFrenchMonaco                     0x06
#define kNtSublangFrisianNetherlands               0x01
#define kNtSublangFulahSenegal                     0x02
#define kNtSublangGalicianGalician                 0x01
#define kNtSublangGeorgianGeorgia                  0x01
#define kNtSublangGerman                           0x01
#define kNtSublangGermanSwiss                      0x02
#define kNtSublangGermanAustrian                   0x03
#define kNtSublangGermanLuxembourg                 0x04
#define kNtSublangGermanLiechtenstein              0x05
#define kNtSublangGreekGreece                      0x01
#define kNtSublangGreenlandicGreenland             0x01
#define kNtSublangGujaratiIndia                    0x01
#define kNtSublangHausaNigeriaLatin                0x01
#define kNtSublangHawaiianUs                       0x01
#define kNtSublangHebrewIsrael                     0x01
#define kNtSublangHindiIndia                       0x01
#define kNtSublangHungarianHungary                 0x01
#define kNtSublangIcelandicIceland                 0x01
#define kNtSublangIgboNigeria                      0x01
#define kNtSublangIndonesianIndonesia              0x01
#define kNtSublangInuktitutCanada                  0x01
#define kNtSublangInuktitutCanadaLatin             0x02
#define kNtSublangIrishIreland                     0x02
#define kNtSublangItalian                          0x01
#define kNtSublangItalianSwiss                     0x02
#define kNtSublangJapaneseJapan                    0x01
#define kNtSublangKannadaIndia                     0x01
#define kNtSublangKashmiriSasia                    0x02
#define kNtSublangKashmiriIndia                    0x02
#define kNtSublangKazakKazakhstan                  0x01
#define kNtSublangKhmerCambodia                    0x01
#define kNtSublangKicheGuatemala                   0x01
#define kNtSublangKinyarwandaRwanda                0x01
#define kNtSublangKonkaniIndia                     0x01
#define kNtSublangKorean                           0x01
#define kNtSublangKyrgyzKyrgyzstan                 0x01
#define kNtSublangLaoLao                           0x01
#define kNtSublangLatvianLatvia                    0x01
#define kNtSublangLithuanian                       0x01
#define kNtSublangLowerSorbianGermany              0x02
#define kNtSublangLuxembourgishLuxembourg          0x01
#define kNtSublangMacedonianMacedonia              0x01
#define kNtSublangMalayMalaysia                    0x01
#define kNtSublangMalayBruneiDarussalam            0x02
#define kNtSublangMalayalamIndia                   0x01
#define kNtSublangMalteseMalta                     0x01
#define kNtSublangMaoriNewZealand                  0x01
#define kNtSublangMapudungunChile                  0x01
#define kNtSublangMarathiIndia                     0x01
#define kNtSublangMohawkMohawk                     0x01
#define kNtSublangMongolianCyrillicMongolia        0x01
#define kNtSublangMongolianPrc                     0x02
#define kNtSublangNepaliIndia                      0x02
#define kNtSublangNepaliNepal                      0x01
#define kNtSublangNorwegianBokmal                  0x01
#define kNtSublangNorwegianNynorsk                 0x02
#define kNtSublangOccitanFrance                    0x01
#define kNtSublangOdiaIndia                        0x01
#define kNtSublangOriyaIndia                       0x01
#define kNtSublangPashtoAfghanistan                0x01
#define kNtSublangPersianIran                      0x01
#define kNtSublangPolishPoland                     0x01
#define kNtSublangPortuguese                       0x02
#define kNtSublangPortugueseBrazilian              0x01
#define kNtSublangPularSenegal                     0x02
#define kNtSublangPunjabiIndia                     0x01
#define kNtSublangPunjabiPakistan                  0x02
#define kNtSublangQuechuaBolivia                   0x01
#define kNtSublangQuechuaEcuador                   0x02
#define kNtSublangQuechuaPeru                      0x03
#define kNtSublangRomanianRomania                  0x01
#define kNtSublangRomanshSwitzerland               0x01
#define kNtSublangRussianRussia                    0x01
#define kNtSublangSakhaRussia                      0x01
#define kNtSublangSamiNorthernNorway               0x01
#define kNtSublangSamiNorthernSweden               0x02
#define kNtSublangSamiNorthernFinland              0x03
#define kNtSublangSamiLuleNorway                   0x04
#define kNtSublangSamiLuleSweden                   0x05
#define kNtSublangSamiSouthernNorway               0x06
#define kNtSublangSamiSouthernSweden               0x07
#define kNtSublangSamiSkoltFinland                 0x08
#define kNtSublangSamiInariFinland                 0x09
#define kNtSublangSanskritIndia                    0x01
#define kNtSublangScottishGaelic                   0x01
#define kNtSublangSerbianBosniaHerzegovinaLatin    0x06
#define kNtSublangSerbianBosniaHerzegovinaCyrillic 0x07
#define kNtSublangSerbianMontenegroLatin           0x0b
#define kNtSublangSerbianMontenegroCyrillic        0x0c
#define kNtSublangSerbianSerbiaLatin               0x09
#define kNtSublangSerbianSerbiaCyrillic            0x0a
#define kNtSublangSerbianCroatia                   0x01
#define kNtSublangSerbianLatin                     0x02
#define kNtSublangSerbianCyrillic                  0x03
#define kNtSublangSindhiIndia                      0x01
#define kNtSublangSindhiPakistan                   0x02
#define kNtSublangSindhiAfghanistan                0x02
#define kNtSublangSinhaleseSriLanka                0x01
#define kNtSublangSothoNorthernSouthAfrica         0x01
#define kNtSublangSlovakSlovakia                   0x01
#define kNtSublangSlovenianSlovenia                0x01
#define kNtSublangSpanish                          0x01
#define kNtSublangSpanishMexican                   0x02
#define kNtSublangSpanishModern                    0x03
#define kNtSublangSpanishGuatemala                 0x04
#define kNtSublangSpanishCostaRica                 0x05
#define kNtSublangSpanishPanama                    0x06
#define kNtSublangSpanishDominicanRepublic         0x07
#define kNtSublangSpanishVenezuela                 0x08
#define kNtSublangSpanishColombia                  0x09
#define kNtSublangSpanishPeru                      0x0a
#define kNtSublangSpanishArgentina                 0x0b
#define kNtSublangSpanishEcuador                   0x0c
#define kNtSublangSpanishChile                     0x0d
#define kNtSublangSpanishUruguay                   0x0e
#define kNtSublangSpanishParaguay                  0x0f
#define kNtSublangSpanishBolivia                   0x10
#define kNtSublangSpanishElSalvador                0x11
#define kNtSublangSpanishHonduras                  0x12
#define kNtSublangSpanishNicaragua                 0x13
#define kNtSublangSpanishPuertoRico                0x14
#define kNtSublangSpanishUs                        0x15
#define kNtSublangSwahiliKenya                     0x01
#define kNtSublangSwedish                          0x01
#define kNtSublangSwedishFinland                   0x02
#define kNtSublangSyriacSyria                      0x01
#define kNtSublangTajikTajikistan                  0x01
#define kNtSublangTamazightAlgeriaLatin            0x02
#define kNtSublangTamazightMoroccoTifinagh         0x04
#define kNtSublangTamilIndia                       0x01
#define kNtSublangTamilSriLanka                    0x02
#define kNtSublangTatarRussia                      0x01
#define kNtSublangTeluguIndia                      0x01
#define kNtSublangThaiThailand                     0x01
#define kNtSublangTibetanPrc                       0x01
#define kNtSublangTigrignaEritrea                  0x02
#define kNtSublangTigrinyaEritrea                  0x02
#define kNtSublangTigrinyaEthiopia                 0x01
#define kNtSublangTswanaBotswana                   0x02
#define kNtSublangTswanaSouthAfrica                0x01
#define kNtSublangTurkishTurkey                    0x01
#define kNtSublangTurkmenTurkmenistan              0x01
#define kNtSublangUighurPrc                        0x01
#define kNtSublangUkrainianUkraine                 0x01
#define kNtSublangUpperSorbianGermany              0x01
#define kNtSublangUrduPakistan                     0x01
#define kNtSublangUrduIndia                        0x02
#define kNtSublangUzbekLatin                       0x01
#define kNtSublangUzbekCyrillic                    0x02
#define kNtSublangValencianValencia                0x02
#define kNtSublangVietnameseVietnam                0x01
#define kNtSublangWelshUnitedKingdom               0x01
#define kNtSublangWolofSenegal                     0x01
#define kNtSublangXhosaSouthAfrica                 0x01
#define kNtSublangYakutRussia                      0x01
#define kNtSublangYiPrc                            0x01
#define kNtSublangYorubaNigeria                    0x01
#define kNtSublangZuluSouthAfrica                  0x01



/*!BEGIN libc/nt/enum/loadlibrarysearch.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOADLIBRARYSEARCH_H_

#define kNtLoadLibrarySearchApplicationDir 0x00000200u
#define kNtLoadLibrarySearchSearchSystem32 0x00000800u
#define kNtLoadLibrarySearchUserDirs       0x00000400u
#define kNtLoadLibrarySearchDefaultDirs    0x00001000u



/*!BEGIN libc/nt/enum/lockfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOCKFILE_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/mb.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MB_H_

#define kNtMbOk                      0x00000000
#define kNtMbOkcancel                0x00000001
#define kNtMbAbortretryignore        0x00000002
#define kNtMbYesnocancel             0x00000003
#define kNtMbYesno                   0x00000004
#define kNtMbRetrycancel             0x00000005
#define kNtMbCanceltrycontinue       0x00000006
#define kNtMbIconhand                0x00000010
#define kNtMbIconquestion            0x00000020
#define kNtMbIconexclamation         0x00000030
#define kNtMbIconasterisk            0x00000040
#define kNtMbUsericon                0x00000080
#define kNtMbIconwarning             kNtMbIconexclamation
#define kNtMbIconerror               kNtMbIconhand
#define kNtMbIconinformation         kNtMbIconasterisk
#define kNtMbIconstop                kNtMbIconhand
#define kNtMbDefbutton1              0x00000000
#define kNtMbDefbutton2              0x00000100
#define kNtMbDefbutton3              0x00000200
#define kNtMbDefbutton4              0x00000300
#define kNtMbApplmodal               0x00000000
#define kNtMbSystemmodal             0x00001000
#define kNtMbTaskmodal               0x00002000
#define kNtMbHelp                    0x00004000
#define kNtMbNofocus                 0x00008000
#define kNtMbSetforeground           0x00010000
#define kNtMbDefaultDesktopOnly      0x00020000
#define kNtMbTopmost                 0x00040000
#define kNtMbRight                   0x00080000
#define kNtMbRtlreading              0x00100000
#define kNtMbServiceNotification     0x00200000
#define kNtMbServiceNotificationNt3x 0x00040000
#define kNtMbTypemask                0x0000000F
#define kNtMbIconmask                0x000000F0
#define kNtMbDefmask                 0x00000F00
#define kNtMbModemask                0x00003000
#define kNtMbMiscmask                0x0000C000



/*!BEGIN libc/nt/enum/memflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMFLAGS_H_

#define kNtMemCommit     0x1000 /* perform physical memory reservation step */
#define kNtMemReserve    0x2000 /* perform virtual memory reservation step */
#define kNtMemDecommit   0x4000
#define kNtMemRelease    0x8000
#define kNtMemFree       0x10000
#define kNtMemPrivate    0x20000
#define kNtMemMapped     0x40000
#define kNtMemReset      0x80000
#define kNtMemTopDown    0x100000
#define kNtMemWriteWatch 0x200000
#define kNtMemPhysical   0x400000
#define kNtMemImage      0x1000000
#define kNtMemLargePages 0x20000000
#define kNtMem4mbPages   0x80000000

#define kNtMemReplacePlaceholder 0x00004000



/*!BEGIN libc/nt/enum/memoryinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMORYINFORMATIONCLASS_H_

#define kNtMemoryBasicInformation    0
#define kNtMemoryWorkingSetList      1
#define kNtMemorySectionName         2
#define kNtMemoryBasicVlmInformation 3



/*!BEGIN libc/nt/enum/mf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MF_H_

#define kNtMfInsert          0x00000000
#define kNtMfChange          0x00000080
#define kNtMfAppend          0x00000100
#define kNtMfDelete          0x00000200
#define kNtMfRemove          0x00001000
#define kNtMfBycommand       0x00000000
#define kNtMfByposition      0x00000400
#define kNtMfSeparator       0x00000800
#define kNtMfEnabled         0x00000000
#define kNtMfGrayed          0x00000001
#define kNtMfDisabled        0x00000002
#define kNtMfUnchecked       0x00000000
#define kNtMfChecked         0x00000008
#define kNtMfUsecheckbitmaps 0x00000200
#define kNtMfString          0x00000000
#define kNtMfBitmap          0x00000004
#define kNtMfOwnerdraw       0x00000100
#define kNtMfPopup           0x00000010
#define kNtMfMenubarbreak    0x00000020
#define kNtMfMenubreak       0x00000040
#define kNtMfUnhilite        0x00000000
#define kNtMfHilite          0x00000080
#define kNtMfDefault         0x00001000
#define kNtMfSysmenu         0x00002000
#define kNtMfHelp            0x00004000
#define kNtMfRightjustify    0x00004000
#define kNtMfMouseselect     0x00008000



/*!BEGIN libc/nt/enum/mk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MK_H_

#define kNtMkLbutton  0x0001
#define kNtMkRbutton  0x0002
#define kNtMkShift    0x0004
#define kNtMkControl  0x0008
#define kNtMkMbutton  0x0010
#define kNtMkXbutton1 0x0020
#define kNtMkXbutton2 0x0040



/*!BEGIN libc/nt/enum/movefileexflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MOVEFILEEXFLAGS_H_

#define kNtMovefileReplaceExisting    1
#define kNtMovefileCopyAllowed        2
#define kNtMovefileDelayUntilReboot   4
#define kNtMovefileWriteThrough       8
#define kNtMovefileCreateHardlink     16
#define kNtMovefileFailIfNotTrackable 32



/*!BEGIN libc/nt/enum/objectinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OBJECTINFORMATIONCLASS_H_

#define kNtObjectBasicInformation 0 /*→ struct NtObjectBasicInformation */
#define kNtObjectNameInformation  1 /*→ etc. */
#define kNtObjectTypeInformation  2
#define kNtObjectAllInformation   3
#define kNtObjectDataInformation  4



/*!BEGIN libc/nt/enum/offerpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFFERPRIORITY_H_

/* TODO(jart): Are these values correct? */
#define kNtVmOfferPriorityVeryLow     1 /* 0x00001000? */
#define kNtVmOfferPriorityLow         2 /* 0x00002000? */
#define kNtVmOfferPriorityBelowNormal 3 /* 0x00002000? */
#define kNtVmOfferPriorityNormal      4 /* 0x00002000? */



/*!BEGIN libc/nt/enum/ofn.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFN_H_

#define kNtOfnReadonly             0x00000001
#define kNtOfnOverwriteprompt      0x00000002
#define kNtOfnHidereadonly         0x00000004
#define kNtOfnNochangedir          0x00000008
#define kNtOfnShowhelp             0x00000010
#define kNtOfnEnablehook           0x00000020
#define kNtOfnEnabletemplate       0x00000040
#define kNtOfnEnabletemplatehandle 0x00000080
#define kNtOfnNovalidate           0x00000100
#define kNtOfnAllowmultiselect     0x00000200
#define kNtOfnExtensiondifferent   0x00000400
#define kNtOfnPathmustexist        0x00000800
#define kNtOfnFilemustexist        0x00001000
#define kNtOfnCreateprompt         0x00002000
#define kNtOfnShareaware           0x00004000
#define kNtOfnNoreadonlyreturn     0x00008000
#define kNtOfnNotestfilecreate     0x00010000
#define kNtOfnNonetworkbutton      0x00020000
#define kNtOfnNolongnames          0x00040000
#define kNtOfnExplorer             0x00080000
#define kNtOfnNodereferencelinks   0x00100000
#define kNtOfnLongnames            0x00200000
#define kNtOfnEnableincludenotify  0x00400000
#define kNtOfnEnablesizing         0x00800000
#define kNtOfnDontaddtorecent      0x02000000
#define kNtOfnForceshowhidden      0x10000000



/*!BEGIN libc/nt/enum/pageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PAGEFLAGS_H_

/* Pick One */
#define kNtPageNoaccess         0x001
#define kNtPageReadonly         0x002
#define kNtPageReadwrite        0x004
#define kNtPageWritecopy        0x008
#define kNtPageExecute          0x010
#define kNtPageExecuteRead      0x020
#define kNtPageExecuteReadwrite 0x040
#define kNtPageExecuteWritecopy 0x080
#define kNtPageGuard            0x100
#define kNtPageNocache          0x200
#define kNtPageWritecombine     0x400

/* These may be OR'd */
#define kNtSecReserve        0x04000000
#define kNtSecCommit         0x08000000 /* default */
#define kNtSecImageNoExecute 0x11000000
#define kNtSecImage          0x01000000
#define kNtSecNocache        0x10000000
#define kNtSecLargePages     0x80000000
#define kNtSecWritecombine   0x40000000



/*!BEGIN libc/nt/enum/pdh.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PDH_H_

#define kNtPdhFmtRaw          0x00000010u
#define kNtPdhFmtAnsi         0x00000020u
#define kNtPdhFmtUnicode      0x00000040u
#define kNtPdhFmtLong         0x00000100u
#define kNtPdhFmtDouble       0x00000200u
#define kNtPdhFmtLarge        0x00000400u
#define kNtPdhFmtNoscale      0x00001000u
#define kNtPdhFmt1000         0x00002000u
#define kNtPdhFmtNodata       0x00004000u
#define kNtPdhFmtNocap100     0x00008000u
#define kNtPerfDetailCostly   0x00010000u
#define kNtPerfDetailStandard 0x0000FFFFu



/*!BEGIN libc/nt/enum/processaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSACCESS_H_

#define kNtProcessCreateProcess 0x0080u
#define kNtProcessCreateThread 0x0002u
#define kNtProcessDupHandle 0x0040u
#define kNtProcessQueryInformation 0x0400u
#define kNtProcessQueryLimitedInformation 0x1000u
#define kNtProcessSetInformation 0x0200u
#define kNtProcessSetQuota 0x0100u
#define kNtProcessSuspendResume 0x0800u
#define kNtProcessTerminate 0x0001u
#define kNtProcessVmOperation 0x0008u
#define kNtProcessVmRead 0x0010u
#define kNtProcessVmWrite 0x0020u
#define kNtProcessSynchronize kNtSynchronize
#define kNtProcessAllAccess \
  (kNtStandardRightsRequired | kNtSynchronize | 0xffffu)



/*!BEGIN libc/nt/enum/processcreationflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSCREATIONFLAGS_H_

#define kNtIdlePriorityClass        0x00000040u
#define kNtBelowNormalPriorityClass 0x00004000u
#define kNtNormalPriorityClass      0x00000020u
#define kNtAboveNormalPriorityClass 0x00008000u
#define kNtHighPriorityClass        0x00000080u
#define kNtRealtimePriorityClass    0x00000100u

#define kNtDebugProcess                 0x00000001u
#define kNtDebugOnlyThisProcess         0x00000002u
#define kNtCreateSuspended              0x00000004u
#define kNtDetachedProcess              0x00000008u
#define kNtCreateNewConsole             0x00000010u
#define kNtCreateNewProcessGroup        0x00000200u
#define kNtCreateUnicodeEnvironment     0x00000400u
#define kNtCreateSeparateWowVdm         0x00000800u
#define kNtCreateSharedWowVdm           0x00001000u
#define kNtCreateForcedos               0x00002000u
#define kNtInheritParentAffinity        0x00010000u
#define kNtCreateProtectedProcess       0x00040000u
#define kNtExtendedStartupinfoPresent   0x00080000u
#define kNtProcessModeBackgroundBegin   0x00100000u
#define kNtProcessModeBackgroundEnd     0x00200000u
#define kNtCreateSecureProcess          0x00400000u
#define kNtCreateBreakawayFromJob       0x01000000u
#define kNtCreatePreserveCodeAuthzLevel 0x02000000u
#define kNtCreateDefaultErrorMode       0x04000000u
#define kNtCreateNoWindow               0x08000000u
#define kNtProfileUser                  0x10000000u
#define kNtProfileKernel                0x20000000u
#define kNtProfileServer                0x40000000u
#define kNtCreateIgnoreSystemDefault    0x80000000u

#define kNtStackSizeParamIsAReservation 0x00010000



/*!BEGIN libc/nt/enum/processinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSINFOCLASS_H_

#define kNtProcessBasicInformation 0
#define kNtProcessQuotaLimits      1
#define kNtProcessIoCounters       2
#define kNtProcessVmCounters       3
#define kNtProcessTimes            4
#define kNtProcessBasePriority     5
#define kNtProcessRaisePriority    6
#define kNtProcessDebugPort        7
#define kNtProcessExceptionPort    8
#define kNtProcessAccessToken      9
#define kNtProcessWow64Information 26
#define kNtProcessImageFileName    27



/*!BEGIN libc/nt/enum/procthreadattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCTHREADATTRIBUTES_H_

#define kNtProcThreadAttributeReplaceValue 1
#define kNtProcThreadAttributeHandleList 0x00020002



/*!BEGIN libc/nt/enum/progress.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROGRESS_H_

#define kNtProgressContinue 0
#define kNtProgressCancel   1
#define kNtProgressStop     2
#define kNtProgressQuiet    3



/*!BEGIN libc/nt/enum/pseudoconsole.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PSEUDOCONSOLE_H_

#define kNtPseudoconsoleInheritCursor 1



/*!BEGIN libc/nt/enum/pwr.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PWR_H_

#define kNtPwrOk             1
#define kNtPwrFail           (-1)
#define kNtPwrSuspendrequest 1
#define kNtPwrSuspendresume  2
#define kNtPwrCriticalresume 3



/*!BEGIN libc/nt/enum/rdw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_RDW_H_

#define kNtRdwInvalidate      0x0001
#define kNtRdwInternalpaint   0x0002
#define kNtRdwErase           0x0004
#define kNtRdwValidate        0x0008
#define kNtRdwNointernalpaint 0x0010
#define kNtRdwNoerase         0x0020
#define kNtRdwNochildren      0x0040
#define kNtRdwAllchildren     0x0080
#define kNtRdwUpdatenow       0x0100
#define kNtRdwErasenow        0x0200
#define kNtRdwFrame           0x0400
#define kNtRdwNoframe         0x0800



/*!BEGIN libc/nt/enum/reggetvalueflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGGETVALUEFLAGS_H_

#define kNtRrfRtRegNone        0x00000001
#define kNtRrfRtRegSz          0x00000002
#define kNtRrfRtRegExpandSz    0x00000004
#define kNtRrfRtRegBinary      0x00000008
#define kNtRrfRtRegDword       0x00000010
#define kNtRrfRtRegMultiSz     0x00000020
#define kNtRrfRtRegQword       0x00000040
#define kNtRrfRtDword          (kNtRrfRtRegBinary | kNtRrfRtRegDword)
#define kNtRrfRtQword          (kNtRrfRtRegBinary | kNtRrfRtRegQword)
#define kNtRrfRtAny            0x0000ffff
#define kNtRrfSubkeyWow6464key 0x00010000
#define kNtRrfSubkeyWow6432key 0x00020000
#define kNtRrfWow64Mask        0x00030000
#define kNtRrfNoexpand         0x10000000
#define kNtRrfZeroonfailure    0x20000000



/*!BEGIN libc/nt/enum/regtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGTYPE_H_

#define kNtRegNone                     0
#define kNtRegSz                       1 /* UTF-16 string */
#define kNtRegExpandSz                 2 /* UTF-16 string w/ env vars refs */
#define kNtRegBinary                   3
#define kNtRegDword                    4
#define kNtRegDwordBigEndian           5
#define kNtRegLink                     6
#define kNtRegMultiSz                  7 /* UTF-16 double-nul-terminated */
#define kNtRegResourceList             8
#define kNtRegFullResourceDescriptor   9
#define kNtRegResourceRequirementsList 10
#define kNtRegQword                    11



/*!BEGIN libc/nt/enum/replacefile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REPLACEFILE_H_

#define kNtReplacefileWriteThrough      1
#define kNtReplacefileIgnoreMergeErrors 2
#define kNtReplacefileIgnoreAclErrors   4



/*!BEGIN libc/nt/enum/sc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SC_H_

#define kNtScSize         0xF000
#define kNtScMove         0xF010
#define kNtScMinimize     0xF020
#define kNtScMaximize     0xF030
#define kNtScNextwindow   0xF040
#define kNtScPrevwindow   0xF050
#define kNtScClose        0xF060
#define kNtScVscroll      0xF070
#define kNtScHscroll      0xF080
#define kNtScMousemenu    0xF090
#define kNtScKeymenu      0xF100
#define kNtScArrange      0xF110
#define kNtScRestore      0xF120
#define kNtScTasklist     0xF130
#define kNtScScreensave   0xF140
#define kNtScHotkey       0xF150
#define kNtScDefault      0xF160
#define kNtScMonitorpower 0xF170
#define kNtScContexthelp  0xF180
#define kNtScSeparator    0xF00F



/*!BEGIN libc/nt/enum/sectioninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINFORMATIONCLASS_H_

#define kNtSectionBasicInformation 0
#define kNtSectionImageInformation 1



/*!BEGIN libc/nt/enum/sectioninherit.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINHERIT_H_

enum NtSectionInherit { kNtViewShare = 1, kNtViewUnmap = 2 };



/*!BEGIN libc/nt/enum/sectionmapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONMAPFLAGS_H_

#define kNtSectionQuery              0x0001
#define kNtSectionMapWrite           0x0002
#define kNtSectionMapRead            0x0004
#define kNtSectionMapExecute         0x0008
#define kNtSectionExtendSize         0x0010
#define kNtSectionMapExecuteExplicit 0x0020



/*!BEGIN libc/nt/enum/securityimpersonationlevel.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYIMPERSONATIONLEVEL_H_

#define kNtSecurityAnonymous      0
#define kNtSecurityIdentification 1
#define kNtSecurityImpersonation  2
#define kNtSecurityDelegation     3



/*!BEGIN libc/nt/enum/securityinformation.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYINFORMATION_H_

#define kNtOwnerSecurityInformation 0x00000001
#define kNtGroupSecurityInformation 0x00000002
#define kNtDaclSecurityInformation 0x00000004
#define kNtSaclSecurityInformation 0x00000008
#define kNtLabelSecurityInformation 0x00000010
#define kNtAttributeSecurityInformation 0x00000020
#define kNtScopeSecurityInformation 0x00000040
#define kNtProcessTrustLabelSecurityInformation 0x00000080
#define kNtAccessFilterSecurityInformation 0x00000100
#define kNtBackupSecurityInformation 0x00010000
#define kNtProtectedDaclSecurityInformation 0x80000000
#define kNtProtectedSaclSecurityInformation 0x40000000
#define kNtUnprotectedDaclSecurityInformation 0x20000000
#define kNtUnprotectedSaclSecurityInformation 0x10000000



/*!BEGIN libc/nt/enum/signal.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIGNAL_H_

#define kNtSignalBreakpoint          0x80000003u
#define kNtSignalIllegalInstruction  0xC000001Du
#define kNtSignalPrivInstruction     0xC0000096u
#define kNtSignalGuardPage           0x80000001u
#define kNtSignalAccessViolation     0xC0000005u
#define kNtSignalInPageError         0xC0000006u
#define kNtSignalInvalidHandle       0xC0000008u
#define kNtSignalInvalidParameter    0xC000000du
#define kNtSignalFltDenormalOperand  0xC000008Du
#define kNtSignalFltDivideByZero     0xC000008Eu
#define kNtSignalFltInexactResult    0xC000008Fu
#define kNtSignalFltInvalidOperation 0xC0000090u
#define kNtSignalFltOverflow         0xC0000091u
#define kNtSignalFltStackCheck       0xC0000092u
#define kNtSignalFltUnderflow        0xC0000093u
#define kNtSignalIntegerDivideByZero 0xC0000094u
#define kNtSignalDllNotFound         0xC0000135u
#define kNtSignalOrdinalNotFound     0xC0000138u
#define kNtSignalEntrypointNotFound  0xC0000139u
#define kNtSignalControlCExit        0xC000013Au
#define kNtSignalDllInitFailed       0xC0000142u
#define kNtSignalFloatMultipleFaults 0xC00002B4u
#define kNtSignalFloatMultipleTraps  0xC00002B5u
#define kNtSignalAssertionFailure    0xC0000420u



/*!BEGIN libc/nt/enum/sio.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIO_H_

#define kNtSioAbsorbRtralert                      0x98000005u
#define kNtSioAcquirePortReservation              0x98000064u
#define kNtSioAddressListChange                   0x28000017u
#define kNtSioAddressListQuery                    0x48000016u
#define kNtSioAddressListSort                     0xc8000019u
#define kNtSioApplyTransportSetting               0x98000013u
#define kNtSioAssociateHandle                     0x88000001u
#define kNtSioAssociatePortReservation            0x98000066u
#define kNtSioBaseHandle                          0x48000022u
#define kNtSioBspHandlePoll                       0x4800001Du
#define kNtSioDeletePeerTargetName                0x980000cbu
#define kNtSioEnableCircularQueueing              0x28000002u
#define kNtSioFindRoute                           0x48000003u
#define kNtSioFlush                               0x28000004u
#define kNtSioGetBroadcastAddress                 0x48000005u
#define kNtSioGetExtensionFunctionPointer         0xc8000006u
#define kNtSioGetGroupQos                         0xc8000008u
#define kNtSioGetInterfaceList                    0x4008747fu
#define kNtSioGetMultipleExtensionFunctionPointer 0xc8000024u
#define kNtSioGetQos                              0xc8000007u
#define kNtSioIndexAddMcast                       0x9800000au
#define kNtSioIndexBind                           0x98000008u
#define kNtSioIndexDelMcast                       0x9800000bu
#define kNtSioIndexMcastif                        0x98000009u
#define kNtSioKeepaliveVals                       0x98000004u
#define kNtSioLimitBroadcasts                     0x98000007u
#define kNtSioLoopbackFastPath                    0x98000010u
#define kNtSioMulticastScope                      0x8800000au
#define kNtSioMultipointLoopback                  0x88000009u
#define kNtSioQueryRssProcessorInfo               0x48000025u
#define kNtSioQueryRssScalabilityInfo             0x580000d2u
#define kNtSioQuerySecurity                       0xd80000c9u
#define kNtSioQueryTargetPnpHandle                0x48000018u
#define kNtSioQueryTransportSetting               0x98000014u
#define kNtSioQueryWfpAleEndpointHandle           0x580000cdu
#define kNtSioQueryWfpConnectionRedirectContext   0x980000ddu
#define kNtSioQueryWfpConnectionRedirectRecords   0x980000dcu
#define kNtSioRcvall                              0x98000001u
#define kNtSioRcvallIf                            0x9800000eu
#define kNtSioRcvallIgmpmcast                     0x98000003u
#define kNtSioRcvallMcast                         0x98000002u
#define kNtSioRcvallMcastIf                       0x9800000du
#define kNtSioReleasePortReservation              0x98000065u
#define kNtSioReserved1                           0x8800001au
#define kNtSioReserved2                           0x88000021u
#define kNtSioRoutingInterfaceChange              0x88000015u
#define kNtSioRoutingInterfaceQuery               0xc8000014u
#define kNtSioSetGroupQos                         0x8800000cu
#define kNtSioSetPeerTargetName                   0x980000cau
#define kNtSioSetPriorityHint                     0x98000018u
#define kNtSioSetQos                              0x8800000bu
#define kNtSioSetSecurity                         0x980000c8u
#define kNtSioSetWfpConnectionRedirectRecords     0x980000deu
#define kNtSioSocketCloseNotify                   0x9800000du
#define kNtSioSocketUsageNotification             0x980000ccu
#define kNtSioTcpInfo                             0xd8000027u
#define kNtSioTcpInitialRto                       0x98000011u
#define kNtSioTcpSetAckFrequency                  0x98000017u
#define kNtSioTcpSetIcw                           0x98000016u
#define kNtSioTranslateHandle                     0xc800000du
#define kNtSioUcastIf                             0x98000006u
#define kNtSioUdpConnreset                        0x9800000cu
#define kNtSioUdpNetreset                         0x9800000fu



/*!BEGIN libc/nt/enum/size.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIZE_H_

#define kNtSizeRestored  0
#define kNtSizeMinimized 1
#define kNtSizeMaximized 2
#define kNtSizeMaxshow   3
#define kNtSizeMaxhide   4



/*!BEGIN libc/nt/enum/startf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STARTF_H_

#define kNtStartfUseshowwindow 0x00000001 /* otherwise wShowWindow ignored */
#define kNtStartfUsesize 0x00000002       /* otherwise dwX / dwY ignored */
#define kNtStartfUseposition 0x00000004   /* otherwise dwX/YSize ignored */
#define kNtStartfUsecountchars 0x00000008 /* otherwise dwX/YCountChars ign. */
#define kNtStartfUsefillattribute 0x00000010 /* etc. */
#define kNtStartfRunfullscreen 0x00000020
#define kNtStartfForceonfeedback 0x00000040
#define kNtStartfForceofffeedback 0x00000080
#define kNtStartfUsestdhandles 0x00000100 /* otherwise hStd... ignored */
#define kNtStartfUsehotkey 0x00000200
#define kNtStartfTitleislinkname 0x00000800
#define kNtStartfTitleisappid 0x00001000
#define kNtStartfPreventpinning 0x00002000
#define kNtStartfUntrustedsource 0x00008000



/*!BEGIN libc/nt/enum/statfs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STATFS_H_
COSMOPOLITAN_C_START_

#define kNtFileCasePreservedNames         0x00000002
#define kNtFileCaseSensitiveSearch        0x00000001
#define kNtFileFileCompression            0x00000010
#define kNtFileNamedStreams               0x00040000
#define kNtFilePersistentAcls             0x00000008
#define kNtFileReadOnlyVolume             0x00080000 /* ST_RDONLY */
#define kNtFileSequentialWriteOnce        0x00100000
#define kNtFileSupportsEncryption         0x00020000
#define kNtFileSupportsExtendedAttributes 0x00800000
#define kNtFileSupportsHardLinks          0x00400000
#define kNtFileSupportsObjectIds          0x00010000
#define kNtFileSupportsOpenByFileId       0x01000000
#define kNtFileSupportsReparsePoints      0x00000080
#define kNtFileSupportsSparseFiles        0x00000040
#define kNtFileSupportsTransactions       0x00200000
#define kNtFileSupportsUsnJournal         0x02000000
#define kNtFileUnicodeOnDisk              0x00000004
#define kNtFileVolumeIsCompressed         0x00008000
#define kNtFileVolumeQuotas               0x00000020
#define kNtFileSupportsBlockRefcounting   0x08000000

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/status.h */

#define COSMOPOLITAN_LIBC_NT_STATUS_H_

/* high two bits = {success,informational,warning,error} */
#define kNtStatusSuccess                  0x00000000 /* success statuses */
#define kNtStatusWait0                    0x00000000
#define kNtStatusAbandonedWait0           0x00000080
#define kNtStatusUserApc                  0x000000C0
#define kNtStatusTimeout                  0x00000102
#define kNtStatusPending                  0x00000103
#define kNtStatusGuardPageViolation       0x80000001 /* warning statuses */
#define kNtStatusDatatypeMisalignment     0x80000002
#define kNtStatusBreakpoint               0x80000003
#define kNtStatusSingleStep               0x80000004
#define kNtStatusLongjump                 0x80000026
#define kNtStatusUnwindConsolidate        0x80000029
#define kNtStatusAccessViolation          0xC0000005 /* error statuses */
#define kNtStatusInPageError              0xC0000006
#define kNtStatusInvalidHandle            0xC0000008
#define kNtStatusInvalidParameter         0xC000000D
#define kNtStatusNoMemory                 0xC0000017
#define kNtStatusIllegalInstruction       0xC000001D
#define kNtStatusNoncontinuableException  0xC0000025
#define kNtStatusInvalidDisposition       0xC0000026
#define kNtStatusArrayBoundsExceeded      0xC000008C
#define kNtStatusFloatDenormalOperand     0xC000008D
#define kNtStatusFloatDivideByZero        0xC000008E
#define kNtStatusFloatInexactResult       0xC000008F
#define kNtStatusFloatInvalidOperation    0xC0000090
#define kNtStatusFloatOverflow            0xC0000091
#define kNtStatusFloatStackCheck          0xC0000092
#define kNtStatusFloatUnderflow           0xC0000093
#define kNtStatusIntegerDivideBYZero      0xC0000094
#define kNtStatusIntegerOverflow          0xC0000095
#define kNtStatusPrivilegedInstruction    0xC0000096
#define kNtStatusStackOverflow            0xC00000FD
#define kNtStatusDllNotFound              0xC0000135
#define kNtStatusOrdinalNotFound          0xC0000138
#define kNtStatusEntrypointNotFound       0xC0000139
#define kNtStatusControlCExit             0xC000013A
#define kNtStatusDllInitFailed            0xC0000142
#define kNtStatusFloatMultipleFaults      0xC00002B4
#define kNtStatusFloatMultipleTraps       0xC00002B5
#define kNtStatusRegNatConsumption        0xC00002C9
#define kNtStatusHeapCorruption           0xC0000374
#define kNtStatusStackBufferOverrun       0xC0000409
#define kNtStatusInvalidCruntimeParameter 0xC0000417
#define kNtStatusAssertionFailure         0xC0000420
#define kNtStatusEnclaveViolation         0xC00004A2
#define kNtStatusSegmentNotification      0x40000005
#define kNtStatusFatalAppExit             0x40000015
#define kNtStatusNotFound                 0xC0000225
#define kNtStatusCancelled                0xC0000120

#define kNtDbgExceptionHandled    0x00010001
#define kNtDbgContinue            0x00010002
#define kNtDbgReplyLater          0x40010001
#define kNtDbgTerminateThread     0x40010003
#define kNtDbgTerminateProcess    0x40010004
#define kNtDbgControlC            0x40010005
#define kNtDbgPrintexceptionC     0x40010006
#define kNtDbgRipexception        0x40010007
#define kNtDbgControlBreak        0x40010008
#define kNtDbgCommandException    0x40010009
#define kNtDbgPrintexceptionWideC 0x4001000A
#define kNtDbgExceptionNotHandled 0x80010001
#define kNtStillActive            kNtStatusPending

#if !(__ASSEMBLER__ + __LINKER__ + 0)

typedef uint32_t NtStatus;

#define NtSuccess(s)      ((NtStatus)(s) >= 0)
#define NtInformation(s)  (NtSeverity(s) == 1)
#define NtWarning(s)      (NtSeverity(s) == 2)
#define NtError(s)        (NtSeverity(s) == 3)
#define NtCode(s)         ((NtStatus)(s)&0xffff)
#define NtSeverity(s)     ((NtStatus)(s) >> 30)
#define NtFacility(s)     (((NtStatus)(s) >> 16) & 0xfff)
#define NtFacilityCode(s) ((NtStatus)(s)&0x0FFFFFFF)

#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nt/enum/sw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SW_H_

#define kNtSwHide            0
#define kNtSwShownormal      1
#define kNtSwNormal          1
#define kNtSwShowminimized   2
#define kNtSwShowmaximized   3
#define kNtSwMaximize        3
#define kNtSwShownoactivate  4
#define kNtSwShow            5
#define kNtSwMinimize        6
#define kNtSwShowminnoactive 7
#define kNtSwShowna          8
#define kNtSwRestore         9
#define kNtSwShowdefault     10
#define kNtSwForceminimize   11



/*!BEGIN libc/nt/enum/symboliclink.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYMBOLICLINK_H_

#define kNtSymbolicLinkFlagDirectory               1
#define kNtSymbolicLinkFlagAllowUnprivilegedCreate 2



/*!BEGIN libc/nt/enum/systeminformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYSTEMINFORMATIONCLASS_H_

#define kNtSystemBasicInformation 0
#define kNtSystemProcessorInformation 1
#define kNtSystemPerformanceInformation 2
#define kNtSystemTimeOfDayInformation 3
#define kNtSystemProcessInformation 5
#define kNtSystemProcessorTimes 8
#define kNtSystemGlobalFlag 9
#define kNtSystemModuleInformation 11
#define kNtSystemLockInformation 12
#define kNtSystemHandleInformation 16
#define kNtSystemObjectInformation 17
#define kNtSystemInterruptInformation 23
#define kNtSystemExceptionInformation 33
#define kNtSystemRegistryQuotaInformation 37
#define kNtSystemLookasideInformation 45



/*!BEGIN libc/nt/enum/th32cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TH32CS_H_

#define kNtTh32csInherit      0x80000000
#define kNtTh32csSnapheaplist 0x00000001
#define kNtTh32csSnapmodule   0x00000008
#define kNtTh32csSnapmodule32 0x00000010
#define kNtTh32csSnapprocess  0x00000002
#define kNtTh32csSnapthread   0x00000004



/*!BEGIN libc/nt/enum/threadaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADACCESS_H_

#define kNtThreadTerminate 0x0001
#define kNtThreadSuspendResume 0x0002
#define kNtThreadGetContext 0x0008
#define kNtThreadSetContext 0x0010
#define kNtThreadQueryInformation 0x0040
#define kNtThreadSetInformation 0x0020
#define kNtThreadSetThreadToken 0x0080
#define kNtThreadImpersonate 0x0100
#define kNtThreadDirectImpersonation 0x0200
#define kNtThreadSetLimitedInformation 0x0400
#define kNtThreadQueryLimitedInformation 0x0800
#define kNtThreadResume 0x1000
#define kNtThreadAllAccess (kNtStandardRightsRequired | kNtSynchronize | 0xFFFF)



/*!BEGIN libc/nt/enum/threadinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADINFOCLASS_H_

enum NtThreadInfoClass {
  kNtThreadBasicInformation,
  kNtThreadTimes,
  kNtThreadPriority,
  kNtThreadBasePriority,
  kNtThreadAffinityMask,
  kNtThreadImpersonationToken,
  kNtThreadDescriptorTableEntry,
  kNtThreadEnableAlignmentFaultFixup,
  kNtThreadEventPair_Reusable,
  kNtThreadQuerySetWin32StartAddress,
  kNtThreadZeroTlsCell,
  kNtThreadPerformanceCount,
  kNtThreadAmILastThread,
  kNtThreadIdealProcessor,
  kNtThreadPriorityBoost,
  kNtThreadSetTlsArrayAddress,
  kNtThreadIsIoPending,
  kNtThreadHideFromDebugger,
  kNtThreadInfoClass_MAX
};



/*!BEGIN libc/nt/enum/threadpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADPRIORITY_H_

#define kNtThreadBasePriorityIdle  (-15)
#define kNtThreadBasePriorityMin   (-2)
#define kNtThreadBasePriorityMax   2
#define kNtThreadBasePriorityLowrt 15

#define kNtThreadPriorityIdle         kNtThreadBasePriorityIdle
#define kNtThreadPriorityLowest       kNtThreadBasePriorityMin
#define kNtThreadPriorityBelowNormal  (kNtThreadPriorityLowest + 1)
#define kNtThreadPriorityNormal       0
#define kNtThreadPriorityAboveNormal  (kNtThreadPriorityHighest - 1)
#define kNtThreadPriorityHighest      kNtThreadBasePriorityMax
#define kNtThreadPriorityTimeCritical kNtThreadBasePriorityLowrt



/*!BEGIN libc/nt/enum/threadstate.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADSTATE_H_

#define kNtStateInitialized 0
#define kNtStateReady       1
#define kNtStateRunning     2
#define kNtStateStandby     3
#define kNtStateTerminated  4
#define kNtStateWait        5
#define kNtStateTransition  6
#define kNtStateUnknown     7



/*!BEGIN libc/nt/enum/timezoneid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TIMEZONEID_H_

#define kNtTimeZoneIdUnknown  0
#define kNtTimeZoneIdStandard 1
#define kNtTimeZoneIdDaylight 2



/*!BEGIN libc/nt/enum/tokeninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENINFORMATIONCLASS_H_

#define kNtTokenUser 1
#define kNtTokenGroups 2
#define kNtTokenPrivileges 3
#define kNtTokenOwner 4
#define kNtTokenPrimaryGroup 5
#define kNtTokenDefaultDacl 6
#define kNtTokenSource 7
#define kNtTokenType 8
#define kNtTokenImpersonationLevel 9
#define kNtTokenStatistics 10
#define kNtTokenRestrictedSids 11
#define kNtTokenSessionId 12
#define kNtTokenGroupsAndPrivileges 13
#define kNtTokenSessionReference 14
#define kNtTokenSandBoxInert 15
#define kNtTokenAuditPolicy 16
#define kNtTokenOrigin 17
#define kNtTokenInfoClass_MAX 18



/*!BEGIN libc/nt/enum/tokentype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENTYPE_H_

#define kNtTokenPrimary       1
#define kNtTokenImpersonation 2



/*!BEGIN libc/nt/enum/tpm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TPM_H_

#define kNtTpmLeftbutton      0x00000
#define kNtTpmRightbutton     0x00002
#define kNtTpmLeftalign       0x00000
#define kNtTpmCenteralign     0x00004
#define kNtTpmRightalign      0x00008
#define kNtTpmTopalign        0x00000
#define kNtTpmVcenteralign    0x00010
#define kNtTpmBottomalign     0x00020
#define kNtTpmHorizontal      0x00000
#define kNtTpmVertical        0x00040
#define kNtTpmNonotify        0x00080
#define kNtTpmReturncmd       0x00100
#define kNtTpmRecurse         0x00001
#define kNtTpmHorposanimation 0x00400
#define kNtTpmHorneganimation 0x00800
#define kNtTpmVerposanimation 0x01000
#define kNtTpmVerneganimation 0x02000
#define kNtTpmNoanimation     0x04000
#define kNtTpmLayoutrtl       0x08000
#define kNtTpmWorkarea        0x10000



/*!BEGIN libc/nt/enum/valueinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VALUEINFORMATIONCLASS_H_

#define kNtKeyValueBasicInformation          0
#define kNtKeyValueFullInformation           1
#define kNtKeyValuePartialInformation        2
#define kNtKeyValueFullInformationAlign64    3
#define kNtKeyValuePartialInformationAlign64 4



/*!BEGIN libc/nt/enum/version.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VERSION_H_

/**
 * Known versions of the New Technology executive.
 * @see IsAtLeastWindows10()
 * @see NtGetVersion()
 */
#define kNtVersionWindows10    0x0a00
#define kNtVersionWindows81    0x0603
#define kNtVersionWindows8     0x0602
#define kNtVersionWindows7     0x0601
#define kNtVersionWindowsVista 0x0600 /* intended baseline */
#define kNtVersionWindowsXp64  0x0502 /* end of the road */
#define kNtVersionWindowsXp    0x0501 /* snowball's chance */
#define kNtVersionWindows2000  0x0500 /* the golden age */
#define kNtVersionFuture       0x0b00



/*!BEGIN libc/nt/enum/vk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VK_H_

#define kNtVkLbutton                      0x01
#define kNtVkRbutton                      0x02
#define kNtVkCancel                       0x03
#define kNtVkMbutton                      0x04
#define kNtVkXbutton1                     0x05
#define kNtVkXbutton2                     0x06
#define kNtVkBack                         0x08
#define kNtVkTab                          0x09
#define kNtVkClear                        0x0C
#define kNtVkReturn                       0x0D
#define kNtVkShift                        0x10
#define kNtVkControl                      0x11
#define kNtVkMenu                         0x12 /* alt? */
#define kNtVkPause                        0x13
#define kNtVkCapital                      0x14
#define kNtVkKana                         0x15
#define kNtVkHangul                       0x15
#define kNtVkJunja                        0x17
#define kNtVkFinal                        0x18
#define kNtVkHanja                        0x19
#define kNtVkKanji                        0x19
#define kNtVkEscape                       0x1B
#define kNtVkConvert                      0x1C
#define kNtVkNonconvert                   0x1D
#define kNtVkAccept                       0x1E
#define kNtVkModechange                   0x1F
#define kNtVkSpace                        0x20
#define kNtVkPrior                        0x21 /* page up */
#define kNtVkNext                         0x22 /* page down */
#define kNtVkEnd                          0x23
#define kNtVkHome                         0x24
#define kNtVkLeft                         0x25
#define kNtVkUp                           0x26
#define kNtVkRight                        0x27
#define kNtVkDown                         0x28
#define kNtVkSelect                       0x29
#define kNtVkPrint                        0x2A
#define kNtVkExecute                      0x2B
#define kNtVkSnapshot                     0x2C
#define kNtVkInsert                       0x2D
#define kNtVkDelete                       0x2E
#define kNtVkHelp                         0x2F
#define kNtVkLwin                         0x5B
#define kNtVkRwin                         0x5C
#define kNtVkApps                         0x5D
#define kNtVkSleep                        0x5F
#define kNtVkNumpad0                      0x60
#define kNtVkNumpad1                      0x61
#define kNtVkNumpad2                      0x62
#define kNtVkNumpad3                      0x63
#define kNtVkNumpad4                      0x64
#define kNtVkNumpad5                      0x65
#define kNtVkNumpad6                      0x66
#define kNtVkNumpad7                      0x67
#define kNtVkNumpad8                      0x68
#define kNtVkNumpad9                      0x69
#define kNtVkMultiply                     0x6A
#define kNtVkAdd                          0x6B
#define kNtVkSeparator                    0x6C
#define kNtVkSubtract                     0x6D
#define kNtVkDecimal                      0x6E
#define kNtVkDivide                       0x6F
#define kNtVkF1                           0x70
#define kNtVkF2                           0x71
#define kNtVkF3                           0x72
#define kNtVkF4                           0x73
#define kNtVkF5                           0x74
#define kNtVkF6                           0x75
#define kNtVkF7                           0x76
#define kNtVkF8                           0x77
#define kNtVkF9                           0x78
#define kNtVkF10                          0x79
#define kNtVkF11                          0x7A
#define kNtVkF12                          0x7B
#define kNtVkF13                          0x7C
#define kNtVkF14                          0x7D
#define kNtVkF15                          0x7E
#define kNtVkF16                          0x7F
#define kNtVkF17                          0x80
#define kNtVkF18                          0x81
#define kNtVkF19                          0x82
#define kNtVkF20                          0x83
#define kNtVkF21                          0x84
#define kNtVkF22                          0x85
#define kNtVkF23                          0x86
#define kNtVkF24                          0x87
#define kNtVkNumlock                      0x90
#define kNtVkScroll                       0x91
#define kNtVkLshift                       0xA0
#define kNtVkRshift                       0xA1
#define kNtVkLcontrol                     0xA2
#define kNtVkRcontrol                     0xA3
#define kNtVkLmenu                        0xA4
#define kNtVkRmenu                        0xA5
#define kNtVkBrowserBack                  0xA6
#define kNtVkBrowserForward               0xA7
#define kNtVkBrowserRefresh               0xA8
#define kNtVkBrowserStop                  0xA9
#define kNtVkBrowserSearch                0xAA
#define kNtVkBrowserFavorites             0xAB
#define kNtVkBrowserHome                  0xAC
#define kNtVkVolumeMute                   0xAD
#define kNtVkVolumeDown                   0xAE
#define kNtVkVolumeUp                     0xAF
#define kNtVkMediaNextTrack               0xB0
#define kNtVkMediaPrevTrack               0xB1
#define kNtVkMediaStop                    0xB2
#define kNtVkMediaPlayPause               0xB3
#define kNtVkLaunchMail                   0xB4
#define kNtVkLaunchMediaSelect            0xB5
#define kNtVkLaunchApp1                   0xB6
#define kNtVkLaunchApp2                   0xB7
#define kNtVkOem_1                        0xBA
#define kNtVkOemPlus                      0xBB
#define kNtVkOemComma                     0xBC
#define kNtVkOemMinus                     0xBD
#define kNtVkOemPeriod                    0xBE
#define kNtVkOem_2                        0xBF
#define kNtVkOem_3                        0xC0
#define kNtVkGamepadA                     0xC3
#define kNtVkGamepadB                     0xC4
#define kNtVkGamepadX                     0xC5
#define kNtVkGamepadY                     0xC6
#define kNtVkGamepadRightShoulder         0xC7
#define kNtVkGamepadLeftShoulder          0xC8
#define kNtVkGamepadLeftTrigger           0xC9
#define kNtVkGamepadRightTrigger          0xCA
#define kNtVkGamepadDpadUp                0xCB
#define kNtVkGamepadDpadDown              0xCC
#define kNtVkGamepadDpadLeft              0xCD
#define kNtVkGamepadDpadRight             0xCE
#define kNtVkGamepadMenu                  0xCF
#define kNtVkGamepadView                  0xD0
#define kNtVkGamepadLeftThumbstickButton  0xD1
#define kNtVkGamepadRightThumbstickButton 0xD2
#define kNtVkGamepadLeftThumbstickUp      0xD3
#define kNtVkGamepadLeftThumbstickDown    0xD4
#define kNtVkGamepadLeftThumbstickRight   0xD5
#define kNtVkGamepadLeftThumbstickLeft    0xD6
#define kNtVkGamepadRightThumbstickUp     0xD7
#define kNtVkGamepadRightThumbstickDown   0xD8
#define kNtVkGamepadRightThumbstickRight  0xD9
#define kNtVkGamepadRightThumbstickLeft   0xDA
#define kNtVkOem_4                        0xDB
#define kNtVkOem_5                        0xDC
#define kNtVkOem_6                        0xDD
#define kNtVkOem_7                        0xDE
#define kNtVkOem_8                        0xDF
#define kNtVkOemAx                        0xE1
#define kNtVkOem_102                      0xE2
#define kNtVkIcoHelp                      0xE3
#define kNtVkIco_00                       0xE4
#define kNtVkProcesskey                   0xE5
#define kNtVkIcoClear                     0xE6
#define kNtVkPacket                       0xE7
#define kNtVkOemReset                     0xE9
#define kNtVkOemJump                      0xEA
#define kNtVkOemPa1                       0xEB
#define kNtVkOemPa2                       0xEC
#define kNtVkOemPa3                       0xED
#define kNtVkOemWsctrl                    0xEE
#define kNtVkOemCusel                     0xEF
#define kNtVkOemAttn                      0xF0
#define kNtVkOemFinish                    0xF1
#define kNtVkOemCopy                      0xF2
#define kNtVkOemAuto                      0xF3
#define kNtVkOemEnlw                      0xF4
#define kNtVkOemBacktab                   0xF5
#define kNtVkAttn                         0xF6
#define kNtVkCrsel                        0xF7
#define kNtVkExsel                        0xF8
#define kNtVkEreof                        0xF9
#define kNtVkPlay                         0xFA
#define kNtVkZoom                         0xFB
#define kNtVkNoname                       0xFC
#define kNtVkPa1                          0xFD
#define kNtVkOemClear                     0xFE



/*!BEGIN libc/nt/enum/wa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WA_H_

#define kNtWaInactive    0
#define kNtWaActive      1
#define kNtWaClickactive 2



/*!BEGIN libc/nt/enum/wait.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WAIT_H_

#define kNtWaitFailed    0xffffffffu
#define kNtWaitTimeout   0x00000102u
#define kNtWaitAbandoned 0x00000080u



/*!BEGIN libc/nt/enum/wm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WM_H_

#define kNtWmNull                   0x0000
#define kNtWmCreate                 0x0001
#define kNtWmDestroy                0x0002
#define kNtWmMove                   0x0003
#define kNtWmSize                   0x0005
#define kNtWmActivate               0x0006
#define kNtWmSetfocus               0x0007
#define kNtWmKillfocus              0x0008
#define kNtWmEnable                 0x000A
#define kNtWmSetredraw              0x000B
#define kNtWmSettext                0x000C
#define kNtWmGettext                0x000D
#define kNtWmGettextlength          0x000E
#define kNtWmPaint                  0x000F
#define kNtWmClose                  0x0010
#define kNtWmQueryendsession        0x0011
#define kNtWmQueryopen              0x0013
#define kNtWmEndsession             0x0016
#define kNtWmQuit                   0x0012
#define kNtWmErasebkgnd             0x0014
#define kNtWmSyscolorchange         0x0015
#define kNtWmShowwindow             0x0018
#define kNtWmWininichange           0x001A
#define kNtWmSettingchange          kNtWmWininichange
#define kNtWmDevmodechange          0x001B
#define kNtWmActivateapp            0x001C
#define kNtWmFontchange             0x001D
#define kNtWmTimechange             0x001E
#define kNtWmCancelmode             0x001F
#define kNtWmSetcursor              0x0020
#define kNtWmMouseactivate          0x0021
#define kNtWmChildactivate          0x0022
#define kNtWmQueuesync              0x0023
#define kNtWmGetminmaxinfo          0x0024
#define kNtWmPainticon              0x0026
#define kNtWmIconerasebkgnd         0x0027
#define kNtWmNextdlgctl             0x0028
#define kNtWmSpoolerstatus          0x002A
#define kNtWmDrawitem               0x002B
#define kNtWmMeasureitem            0x002C
#define kNtWmDeleteitem             0x002D
#define kNtWmVkeytoitem             0x002E
#define kNtWmChartoitem             0x002F
#define kNtWmSetfont                0x0030
#define kNtWmGetfont                0x0031
#define kNtWmSethotkey              0x0032
#define kNtWmGethotkey              0x0033
#define kNtWmQuerydragicon          0x0037
#define kNtWmCompareitem            0x0039
#define kNtWmGetobject              0x003D
#define kNtWmCompacting             0x0041
#define kNtWmWindowposchanging      0x0046
#define kNtWmWindowposchanged       0x0047
#define kNtWmPower                  0x0048
#define kNtWmCopydata               0x004A
#define kNtWmCanceljournal          0x004B
#define kNtWmNotify                 0x004E
#define kNtWmInputlangchangerequest 0x0050
#define kNtWmInputlangchange        0x0051
#define kNtWmTcard                  0x0052
#define kNtWmHelp                   0x0053
#define kNtWmUserchanged            0x0054
#define kNtWmNotifyformat           0x0055
#define kNtWmContextmenu            0x007B
#define kNtWmStylechanging          0x007C
#define kNtWmStylechanged           0x007D
#define kNtWmDisplaychange          0x007E
#define kNtWmGeticon                0x007F
#define kNtWmSeticon                0x0080
#define kNtWmNccreate               0x0081
#define kNtWmNcdestroy              0x0082
#define kNtWmNccalcsize             0x0083
#define kNtWmNchittest              0x0084
#define kNtWmNcpaint                0x0085
#define kNtWmNcactivate             0x0086
#define kNtWmGetdlgcode             0x0087
#define kNtWmNcmousemove            0x00A0
#define kNtWmNclbuttondown          0x00A1
#define kNtWmNclbuttonup            0x00A2
#define kNtWmNclbuttondblclk        0x00A3
#define kNtWmNcrbuttondown          0x00A4
#define kNtWmNcrbuttonup            0x00A5
#define kNtWmNcrbuttondblclk        0x00A6
#define kNtWmNcmbuttondown          0x00A7
#define kNtWmNcmbuttonup            0x00A8
#define kNtWmNcmbuttondblclk        0x00A9
#define kNtWmNcxbuttondown          0x00AB
#define kNtWmNcxbuttonup            0x00AC
#define kNtWmNcxbuttondblclk        0x00AD
#define kNtWmKeyfirst               0x0100
#define kNtWmKeydown                0x0100
#define kNtWmKeyup                  0x0101
#define kNtWmChar                   0x0102
#define kNtWmDeadchar               0x0103
#define kNtWmSyskeydown             0x0104
#define kNtWmSyskeyup               0x0105
#define kNtWmSyschar                0x0106
#define kNtWmSysdeadchar            0x0107
#define kNtWmUnichar                0x0109
#define kNtWmKeylast                0x0109
#define kNtWmInitdialog             0x0110
#define kNtWmCommand                0x0111
#define kNtWmSyscommand             0x0112
#define kNtWmTimer                  0x0113
#define kNtWmHscroll                0x0114
#define kNtWmVscroll                0x0115
#define kNtWmInitmenu               0x0116
#define kNtWmInitmenupopup          0x0117
#define kNtWmGesture                0x0119
#define kNtWmGesturenotify          0x011A
#define kNtWmMenuselect             0x011F
#define kNtWmMenuchar               0x0120
#define kNtWmEnteridle              0x0121
#define kNtWmMenurbuttonup          0x0122
#define kNtWmMenudrag               0x0123
#define kNtWmMenugetobject          0x0124
#define kNtWmUninitmenupopup        0x0125
#define kNtWmMenucommand            0x0126
#define kNtWmChangeuistate          0x0127
#define kNtWmUpdateuistate          0x0128
#define kNtWmQueryuistate           0x0129
#define kNtWmMousefirst             0x0200
#define kNtWmMousemove              0x0200
#define kNtWmLbuttondown            0x0201
#define kNtWmLbuttonup              0x0202
#define kNtWmLbuttondblclk          0x0203
#define kNtWmRbuttondown            0x0204
#define kNtWmRbuttonup              0x0205
#define kNtWmRbuttondblclk          0x0206
#define kNtWmMbuttondown            0x0207
#define kNtWmMbuttonup              0x0208
#define kNtWmMbuttondblclk          0x0209
#define kNtWmMousewheel             0x020A
#define kNtWmXbuttondown            0x020B
#define kNtWmXbuttonup              0x020C
#define kNtWmXbuttondblclk          0x020D
#define kNtWmMousehwheel            0x020E
#define kNtWmMouselast              0x020E
#define kNtWmParentnotify           0x0210
#define kNtWmEntermenuloop          0x0211
#define kNtWmExitmenuloop           0x0212
#define kNtWmNextmenu               0x0213
#define kNtWmSizing                 0x0214
#define kNtWmCapturechanged         0x0215
#define kNtWmMoving                 0x0216
#define kNtWmPowerbroadcast         0x0218
#define kNtWmMdicreate              0x0220
#define kNtWmMdidestroy             0x0221
#define kNtWmMdiactivate            0x0222
#define kNtWmMdirestore             0x0223
#define kNtWmMdinext                0x0224
#define kNtWmMdimaximize            0x0225
#define kNtWmMditile                0x0226
#define kNtWmMdicascade             0x0227
#define kNtWmMdiiconarrange         0x0228
#define kNtWmMdigetactive           0x0229
#define kNtWmMdisetmenu             0x0230
#define kNtWmEntersizemove          0x0231
#define kNtWmExitsizemove           0x0232
#define kNtWmDropfiles              0x0233
#define kNtWmMdirefreshmenu         0x0234
#define kNtWmCut                    0x0300
#define kNtWmCopy                   0x0301
#define kNtWmPaste                  0x0302
#define kNtWmClear                  0x0303
#define kNtWmUndo                   0x0304
#define kNtWmRenderformat           0x0305
#define kNtWmRenderallformats       0x0306
#define kNtWmDestroyclipboard       0x0307
#define kNtWmDrawclipboard          0x0308
#define kNtWmPaintclipboard         0x0309
#define kNtWmVscrollclipboard       0x030A
#define kNtWmSizeclipboard          0x030B
#define kNtWmAskcbformatname        0x030C
#define kNtWmChangecbchain          0x030D
#define kNtWmHscrollclipboard       0x030E
#define kNtWmQuerynewpalette        0x030F
#define kNtWmPaletteischanging      0x0310
#define kNtWmPalettechanged         0x0311
#define kNtWmHotkey                 0x0312



/*!BEGIN libc/nt/enum/ws.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WS_H_

#define kNtWsOverlapped   0x00000000
#define kNtWsPopup        0x80000000
#define kNtWsChild        0x40000000
#define kNtWsMinimize     0x20000000
#define kNtWsVisible      0x10000000
#define kNtWsDisabled     0x08000000
#define kNtWsClipsiblings 0x04000000
#define kNtWsClipchildren 0x02000000
#define kNtWsMaximize     0x01000000
#define kNtWsCaption      0x00C00000
#define kNtWsBorder       0x00800000
#define kNtWsDlgframe     0x00400000
#define kNtWsVscroll      0x00200000
#define kNtWsHscroll      0x00100000
#define kNtWsSysmenu      0x00080000
#define kNtWsThickframe   0x00040000
#define kNtWsGroup        0x00020000
#define kNtWsTabstop      0x00010000
#define kNtWsMinimizebox  0x00020000
#define kNtWsMaximizebox  0x00010000
#define kNtWsTiled        kNtWsOverlapped
#define kNtWsIconic       kNtWsMinimize
#define kNtWsSizebox      kNtWsThickframe
#define kNtWsTiledwindow  kNtWsOverlappedwindow
#define kNtWsOverlappedwindow                                        \
  (kNtWsOverlapped | kNtWsCaption | kNtWsSysmenu | kNtWsThickframe | \
   kNtWsMinimizebox | kNtWsMaximizebox)
#define kNtWsPopupwindow (kNtWsPopup | kNtWsBorder | kNtWsSysmenu)

#define kNtWsExDlgmodalframe       0x00000001
#define kNtWsExNoparentnotify      0x00000004
#define kNtWsExTopmost             0x00000008
#define kNtWsExAcceptfiles         0x00000010
#define kNtWsExTransparent         0x00000020
#define kNtWsExMdichild            0x00000040
#define kNtWsExToolwindow          0x00000080
#define kNtWsExWindowedge          0x00000100
#define kNtWsExClientedge          0x00000200
#define kNtWsExContexthelp         0x00000400
#define kNtWsExRight               0x00001000
#define kNtWsExLeft                0x00000000
#define kNtWsExRtlreading          0x00002000
#define kNtWsExLtrreading          0x00000000
#define kNtWsExLeftscrollbar       0x00004000
#define kNtWsExRightscrollbar      0x00000000
#define kNtWsExControlparent       0x00010000
#define kNtWsExStaticedge          0x00020000
#define kNtWsExAppwindow           0x00040000
#define kNtWsExNoinheritlayout     0x00100000
#define kNtWsExNoredirectionbitmap 0x00200000
#define kNtWsExLayoutrtl           0x00400000
#define kNtWsExComposited          0x02000000
#define kNtWsExNoactivate          0x08000000

#define kNtWsExOverlappedwindow (kNtWsExWindowedge | kNtWsExClientedge)
#define kNtWsExPalettewindow \
  (kNtWsExWindowedge | kNtWsExToolwindow | kNtWsExTopmost)



/*!BEGIN libc/nt/enum/wsa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSA_H_


/*!BEGIN libc/nt/errors.h */

#define COSMOPOLITAN_NT_ERRORS_H_

#define kNtNoError 0

#define kNtErrorInsufficientBuffer 122

#define kNtErrorSuccess                                             0
#define kNtErrorInvalidFunction                                     1 /* ENOSYS */
#define kNtErrorFileNotFound                                        2 /* ENOENT */
#define kNtErrorPathNotFound                                        3 /* ENOTDIR */
#define kNtErrorTooManyOpenFiles                                    4 /* EMFILE */
#define kNtErrorAccessDenied                                        5 /* EACCES */
#define kNtErrorInvalidHandle                                       6 /* EBADF */
#define kNtErrorArenaTrashed                                        7
#define kNtErrorNotEnoughMemory                                     8
#define kNtErrorInvalidBlock                                        9
#define kNtErrorBadEnvironment                                      10
#define kNtErrorBadFormat                                           11
#define kNtErrorInvalidAccess                                       12 /* EPERM */
#define kNtErrorInvalidData                                         13
#define kNtErrorOutofmemory                                         14 /* ENOMEM */
#define kNtErrorInvalidDrive                                        15
#define kNtErrorCurrentDirectory                                    16
#define kNtErrorNotSameDevice                                       17
#define kNtErrorNoMoreFiles                                         18
#define kNtErrorWriteProtect                                        19
#define kNtErrorBadUnit                                             20
#define kNtErrorNotReady                                            21
#define kNtErrorBadCommand                                          22
#define kNtErrorCrc                                                 23
#define kNtErrorBadLength                                           24
#define kNtErrorSeek                                                25 /* ESPIPE */
#define kNtErrorNotDosDisk                                          26 /* ENOTBLK */
#define kNtErrorSectorNotFound                                      27
#define kNtErrorOutOfPaper                                          28
#define kNtErrorWriteFault                                          29
#define kNtErrorReadFault                                           30
#define kNtErrorGenFailure                                          31
#define kNtErrorSharingViolation                                    32
#define kNtErrorLockViolation                                       33
#define kNtErrorWrongDisk                                           34
#define kNtErrorSharingBufferExceeded                               36
#define kNtErrorHandleEof                                           38 /* w/ GetOverlappedResult() */
#define kNtErrorHandleDiskFull                                      39
#define kNtErrorNotSupported                                        50
#define kNtErrorRemNotList                                          51
#define kNtErrorDupName                                             52
#define kNtErrorBadNetpath                                          53
#define kNtErrorNetworkBusy                                         54
#define kNtErrorDevNotExist                                         55
#define kNtErrorTooManyCmds                                         56
#define kNtErrorAdapHdwErr                                          57
#define kNtErrorBadNetResp                                          58
#define kNtErrorUnexpNetErr                                         59
#define kNtErrorBadRemAdap                                          60
#define kNtErrorPrintqFull                                          61
#define kNtErrorNoSpoolSpace                                        62
#define kNtErrorPrintCancelled                                      63
#define kNtErrorNetnameDeleted                                      64
#define kNtErrorNetworkAccessDenied                                 65
#define kNtErrorBadDevType                                          66
#define kNtErrorBadNetName                                          67
#define kNtErrorTooManyNames                                        68
#define kNtErrorTooManySess                                         69
#define kNtErrorSharingPaused                                       70
#define kNtErrorReqNotAccep                                         71
#define kNtErrorRedirPaused                                         72
#define kNtErrorFileExists                                          80 /* EEXIST */
#define kNtErrorCannotMake                                          82
#define kNtErrorFailI24                                             83
#define kNtErrorOutOfStructures                                     84
#define kNtErrorAlreadyAssigned                                     85
#define kNtErrorInvalidPassword                                     86
#define kNtErrorInvalidParameter                                    87 /* EINVAL */
#define kNtErrorNetWriteFault                                       88
#define kNtErrorNoProcSlots                                         89
#define kNtErrorTooManySemaphores                                   100
#define kNtErrorExclSemAlreadyOwned                                 101
#define kNtErrorSemIsSet                                            102
#define kNtErrorTooManySemRequests                                  103
#define kNtErrorInvalidAtInterruptTime                              104
#define kNtErrorSemOwnerDied                                        105 /* EOWNERDEAD */
#define kNtErrorSemUserLimit                                        106
#define kNtErrorDiskChange                                          107
#define kNtErrorDriveLocked                                         108
#define kNtErrorBrokenPipe                                          109 /* EPIPE; happens on ReadFile() too */
#define kNtErrorOpenFailed                                          110
#define kNtErrorBufferOverflow                                      111
#define kNtErrorDiskFull                                            112 /* ENOSPC */
#define kNtErrorNoMoreSearchHandles                                 113
#define kNtErrorInvalidTargetHandle                                 114 /* EBADF */
#define kNtErrorInvalidCategory                                     117 /* ENOATTR */
#define kNtErrorInvalidVerifySwitch                                 118
#define kNtErrorBadDriverLevel                                      119
#define kNtErrorCallNotImplemented                                  120
#define kNtErrorSemTimeout                                          121
#define kNtErrorInsufficientBuffer                                  122
#define kNtErrorInvalidName                                         123
#define kNtErrorInvalidLevel                                        124
#define kNtErrorNoVolumeLabel                                       125
#define kNtErrorModNotFound                                         126
#define kNtErrorProcNotFound                                        127
#define kNtErrorWaitNoChildren                                      128 /* ECHILD */
#define kNtErrorChildNotComplete                                    129
#define kNtErrorDirectAccessHandle                                  130 /* EBADF */
#define kNtErrorNegativeSeek                                        131
#define kNtErrorSeekOnDevice                                        132
#define kNtErrorIsJoinTarget                                        133
#define kNtErrorIsJoined                                            134
#define kNtErrorIsSubsted                                           135
#define kNtErrorNotJoined                                           136
#define kNtErrorNotSubsted                                          137
#define kNtErrorJoinToJoin                                          138
#define kNtErrorSubstToSubst                                        139
#define kNtErrorJoinToSubst                                         140
#define kNtErrorSubstToJoin                                         141
#define kNtErrorBusyDrive                                           142
#define kNtErrorSameDrive                                           143
#define kNtErrorDirNotRoot                                          144
#define kNtErrorDirNotEmpty                                         145
#define kNtErrorIsSubstPath                                         146
#define kNtErrorIsJoinPath                                          147
#define kNtErrorPathBusy                                            148 /* ETXTBSY */
#define kNtErrorIsSubstTarget                                       149
#define kNtErrorSystemTrace                                         150
#define kNtErrorInvalidEventCount                                   151
#define kNtErrorTooManyMuxwaiters                                   152
#define kNtErrorInvalidListFormat                                   153
#define kNtErrorLabelTooLong                                        154
#define kNtErrorTooManyTcbs                                         155
#define kNtErrorSignalRefused                                       156
#define kNtErrorDiscarded                                           157
#define kNtErrorNotLocked                                           158 /* ENOLCK */
#define kNtErrorBadThreadidAddr                                     159
#define kNtErrorBadArguments                                        160
#define kNtErrorBadPathname                                         161
#define kNtErrorSignalPending                                       162
#define kNtErrorMaxThrdsReached                                     164
#define kNtErrorLockFailed                                          167
#define kNtErrorBusy                                                170 /* EBUSY */
#define kNtErrorDeviceSupportInProgress                             171
#define kNtErrorCancelViolation                                     173
#define kNtErrorAtomicLocksNotSupported                             174
#define kNtErrorInvalidSegmentNumber                                180
#define kNtErrorInvalidOrdinal                                      182
#define kNtErrorAlreadyExists                                       183 /* EEXIST */
#define kNtErrorInvalidFlagNumber                                   186
#define kNtErrorSemNotFound                                         187
#define kNtErrorInvalidStartingCodeseg                              188
#define kNtErrorInvalidStackseg                                     189
#define kNtErrorInvalidModuletype                                   190
#define kNtErrorInvalidExeSignature                                 191
#define kNtErrorExeMarkedInvalid                                    192 /* EBADEXEC */
#define kNtErrorBadExeFormat                                        193 /* ENOEXEC */
#define kNtErrorIteratedDataExceeds_64k                             194
#define kNtErrorInvalidMinallocsize                                 195
#define kNtErrorDynlinkFromInvalidRing                              196
#define kNtErrorIoplNotEnabled                                      197
#define kNtErrorInvalidSegdpl                                       198
#define kNtErrorAutodatasegExceeds_64k                              199
#define kNtErrorRing2segMustBeMovable                               200
#define kNtErrorRelocChainXeedsSeglim                               201
#define kNtErrorInfloopInRelocChain                                 202
#define kNtErrorEnvvarNotFound                                      203
#define kNtErrorNoSignalSent                                        205
#define kNtErrorFilenameExcedRange                                  206 /* ENAMETOOLONG */
#define kNtErrorRing2StackInUse                                     207
#define kNtErrorMetaExpansionTooLong                                208
#define kNtErrorInvalidSignalNumber                                 209
#define kNtErrorThread_1Inactive                                    210
#define kNtErrorLocked                                              212
#define kNtErrorTooManyModules                                      214
#define kNtErrorNestingNotAllowed                                   215
#define kNtErrorExeMachineTypeMismatch                              216 /* EBADARCH */
#define kNtErrorExeCannotModifySignedBinary                         217
#define kNtErrorExeCannotModifyStrongSignedBinary                   218
#define kNtErrorFileCheckedOut                                      220
#define kNtErrorCheckoutRequired                                    221
#define kNtErrorBadFileType                                         222 /* EFTYPE */
#define kNtErrorFileTooLarge                                        223 /* EFBIG */
#define kNtErrorFormsAuthRequired                                   224 /* ENEEDAUTH */
#define kNtErrorVirusInfected                                       225
#define kNtErrorVirusDeleted                                        226
#define kNtErrorPipeLocal                                           229
#define kNtErrorBadPipe                                             230
#define kNtErrorPipeBusy                                            231
#define kNtErrorNoData                                              232
#define kNtErrorPipeNotConnected                                    233
#define kNtErrorMoreData                                            234
#define kNtErrorNoWorkDone                                          235
#define kNtErrorVcDisconnected                                      240
#define kNtErrorInvalidEaName                                       254
#define kNtErrorEaListInconsistent                                  255
#define kNtErrorNoMoreItems                                         259
#define kNtErrorCannotCopy                                          266
#define kNtErrorDirectory                                           267 /* EISDIR */
#define kNtErrorEasDidntFit                                         275
#define kNtErrorEaFileCorrupt                                       276
#define kNtErrorEaTableFull                                         277
#define kNtErrorInvalidEaHandle                                     278
#define kNtErrorEasNotSupported                                     282
#define kNtErrorNotOwner                                            288
#define kNtErrorTooManyPosts                                        298
#define kNtErrorPartialCopy                                         299
#define kNtErrorOplockNotGranted                                    300
#define kNtErrorInvalidOplockProtocol                               301
#define kNtErrorDiskTooFragmented                                   302
#define kNtErrorDeletePending                                       303
#define kNtErrorIncompatibleWithGlobalShortNameRegistrySetting      304
#define kNtErrorShortNamesNotEnabledOnVolume                        305
#define kNtErrorSecurityStreamIsInconsistent                        306
#define kNtErrorInvalidLockRange                                    307
#define kNtErrorImageSubsystemNotPresent                            308
#define kNtErrorNotificationGuidAlreadyDefined                      309
#define kNtErrorInvalidExceptionHandler                             310
#define kNtErrorDuplicatePrivileges                                 311
#define kNtErrorNoRangesProcessed                                   312
#define kNtErrorNotAllowedOnSystemFile                              313
#define kNtErrorDiskResourcesExhausted                              314
#define kNtErrorInvalidToken                                        315
#define kNtErrorDeviceFeatureNotSupported                           316
#define kNtErrorMrMidNotFound                                       317
#define kNtErrorScopeNotFound                                       318
#define kNtErrorUndefinedScope                                      319
#define kNtErrorInvalidCap                                          320
#define kNtErrorDeviceUnreachable                                   321
#define kNtErrorDeviceNoResources                                   322
#define kNtErrorDataChecksumError                                   323
#define kNtErrorIntermixedKernelEaOperation                         324
#define kNtErrorFileLevelTrimNotSupported                           326
#define kNtErrorOffsetAlignmentViolation                            327
#define kNtErrorInvalidFieldInParameterList                         328
#define kNtErrorOperationInProgress                                 329 /* EPROGUNAVAIL */
#define kNtErrorBadDevicePath                                       330
#define kNtErrorTooManyDescriptors                                  331 /* ENFILE */
#define kNtErrorScrubDataDisabled                                   332
#define kNtErrorNotRedundantStorage                                 333
#define kNtErrorResidentFileNotSupported                            334
#define kNtErrorCompressedFileNotSupported                          335
#define kNtErrorDirectoryNotSupported                               336
#define kNtErrorNotReadFromCopy                                     337
#define kNtErrorFtWriteFailure                                      338
#define kNtErrorFtDiScanRequired                                    339
#define kNtErrorInvalidKernelInfoVersion                            340
#define kNtErrorInvalidPepInfoVersion                               341
#define kNtErrorObjectNotExternallyBacked                           342
#define kNtErrorExternalBackingProviderUnknown                      343
#define kNtErrorCompressionNotBeneficial                            344
#define kNtErrorStorageTopologyIdMismatch                           345
#define kNtErrorBlockedByParentalControls                           346
#define kNtErrorBlockTooManyReferences                              347
#define kNtErrorMarkedToDisallowWrites                              348
#define kNtErrorEnclaveFailure                                      349
#define kNtErrorFailNoactionReboot                                  350
#define kNtErrorFailShutdown                                        351
#define kNtErrorFailRestart                                         352
#define kNtErrorMaxSessionsReached                                  353
#define kNtErrorNetworkAccessDeniedEdp                              354
#define kNtErrorDeviceHintNameBufferTooSmall                        355
#define kNtErrorEdpPolicyDeniesOperation                            356
#define kNtErrorEdpDplPolicyCantBeSatisfied                         357
#define kNtErrorCloudFileSyncRootMetadataCorrupt                    358
#define kNtErrorDeviceInMaintenance                                 359
#define kNtErrorNotSupportedOnDax                                   360
#define kNtErrorDaxMappingExists                                    361
#define kNtErrorCloudFileProviderNotRunning                         362
#define kNtErrorCloudFileMetadataCorrupt                            363
#define kNtErrorCloudFileMetadataTooLarge                           364
#define kNtErrorCloudFilePropertyBlobTooLarge                       365
#define kNtErrorCloudFilePropertyBlobChecksumMismatch               366
#define kNtErrorChildProcessBlocked                                 367
#define kNtErrorStorageLostDataPersistence                          368
#define kNtErrorFileSystemVirtualizationUnavailable                 369
#define kNtErrorFileSystemVirtualizationMetadataCorrupt             370
#define kNtErrorFileSystemVirtualizationBusy                        371
#define kNtErrorFileSystemVirtualizationProviderUnknown             372
#define kNtErrorGdiHandleLeak                                       373
#define kNtErrorCloudFileTooManyPropertyBlobs                       374
#define kNtErrorCloudFilePropertyVersionNotSupported                375
#define kNtErrorNotACloudFile                                       376
#define kNtErrorCloudFileNotInSync                                  377
#define kNtErrorCloudFileAlreadyConnected                           378
#define kNtErrorCloudFileNotSupported                               379
#define kNtErrorCloudFileInvalidRequest                             380
#define kNtErrorCloudFileReadOnlyVolume                             381
#define kNtErrorCloudFileConnectedProviderOnly                      382
#define kNtErrorCloudFileValidationFailed                           383
#define kNtErrorSmb1NotAvailable                                    384
#define kNtErrorFileSystemVirtualizationInvalidOperation            385
#define kNtErrorCloudFileAuthenticationFailed                       386
#define kNtErrorCloudFileInsufficientResources                      387
#define kNtErrorCloudFileNetworkUnavailable                         388
#define kNtErrorCloudFileUnsuccessful                               389
#define kNtErrorCloudFileNotUnderSyncRoot                           390
#define kNtErrorCloudFileInUse                                      391
#define kNtErrorCloudFilePinned                                     392
#define kNtErrorCloudFileRequestAborted                             393
#define kNtErrorCloudFilePropertyCorrupt                            394
#define kNtErrorCloudFileAccessDenied                               395
#define kNtErrorCloudFileIncompatibleHardlinks                      396
#define kNtErrorCloudFilePropertyLockConflict                       397
#define kNtErrorCloudFileRequestCanceled                            398
#define kNtErrorExternalSyskeyNotSupported                          399
#define kNtErrorThreadModeAlreadyBackground                         400
#define kNtErrorThreadModeNotBackground                             401
#define kNtErrorProcessModeAlreadyBackground                        402
#define kNtErrorProcessModeNotBackground                            403
#define kNtErrorCloudFileProviderTerminated                         404
#define kNtErrorNotACloudSyncRoot                                   405
#define kNtErrorFileProtectedUnderDpl                               406
#define kNtErrorVolumeNotClusterAligned                             407
#define kNtErrorNoPhysicallyAlignedFreeSpaceFound                   408
#define kNtErrorAppxFileNotEncrypted                                409
#define kNtErrorRwrawEncryptedFileNotEncrypted                      410
#define kNtErrorRwrawEncryptedInvalidEdatainfoFileoffset            411
#define kNtErrorRwrawEncryptedInvalidEdatainfoFilerange             412
#define kNtErrorRwrawEncryptedInvalidEdatainfoParameter             413
#define kNtErrorLinuxSubsystemNotPresent                            414
#define kNtErrorCapauthzNotDevunlocked                              450
#define kNtErrorCapauthzChangeType                                  451
#define kNtErrorCapauthzNotProvisioned                              452
#define kNtErrorCapauthzNotAuthorized                               453
#define kNtErrorCapauthzNoPolicy                                    454
#define kNtErrorCapauthzDbCorrupted                                 455
#define kNtErrorCapauthzSccdInvalidCatalog                          456
#define kNtErrorCapauthzSccdNoAuthEntity                            457
#define kNtErrorCapauthzSccdParseError                              458
#define kNtErrorCapauthzSccdDevModeRequired                         459
#define kNtErrorCapauthzSccdNoCapabilityMatch                       460
#define kNtErrorPnpQueryRemoveDeviceTimeout                         480
#define kNtErrorPnpQueryRemoveRelatedDeviceTimeout                  481
#define kNtErrorPnpQueryRemoveUnrelatedDeviceTimeout                482
#define kNtErrorDeviceHardwareError                                 483 /* EDEVERR */
#define kNtErrorInvalidAddress                                      487 /* EFAULT */
#define kNtErrorVrfCfgEnabled                                       1183
#define kNtErrorPartitionTerminating                                1184
#define kNtErrorUserProfileLoad                                     500
#define kNtErrorArithmeticOverflow                                  534 /* EOVERFLOW */
#define kNtErrorPipeConnected                                       535
#define kNtErrorPipeListening                                       536
#define kNtErrorVerifierStop                                        537
#define kNtErrorAbiosError                                          538
#define kNtErrorWx86Warning                                         539
#define kNtErrorWx86Error                                           540
#define kNtErrorTimerNotCanceled                                    541
#define kNtErrorUnwind                                              542
#define kNtErrorBadStack                                            543
#define kNtErrorInvalidUnwindTarget                                 544
#define kNtErrorInvalidPortAttributes                               545
#define kNtErrorPortMessageTooLong                                  546
#define kNtErrorInvalidQuotaLower                                   547
#define kNtErrorDeviceAlreadyAttached                               548
#define kNtErrorInstructionMisalignment                             549
#define kNtErrorProfilingNotStarted                                 550
#define kNtErrorProfilingNotStopped                                 551
#define kNtErrorCouldNotInterpret                                   552
#define kNtErrorProfilingAtLimit                                    553
#define kNtErrorCantWait                                            554
#define kNtErrorCantTerminateSelf                                   555
#define kNtErrorUnexpectedMmCreateErr                               556
#define kNtErrorUnexpectedMmMapError                                557
#define kNtErrorUnexpectedMmExtendErr                               558
#define kNtErrorBadFunctionTable                                    559
#define kNtErrorNoGuidTranslation                                   560
#define kNtErrorInvalidLdtSize                                      561
#define kNtErrorInvalidLdtOffset                                    563
#define kNtErrorInvalidLdtDescriptor                                564
#define kNtErrorTooManyThreads                                      565
#define kNtErrorThreadNotInProcess                                  566 /* ESRCH */
#define kNtErrorPagefileQuotaExceeded                               567
#define kNtErrorLogonServerConflict                                 568
#define kNtErrorSynchronizationRequired                             569
#define kNtErrorNetOpenFailed                                       570
#define kNtErrorIoPrivilegeFailed                                   571
#define kNtErrorControlCExit                                        572
#define kNtErrorMissingSystemfile                                   573
#define kNtErrorUnhandledException                                  574
#define kNtErrorAppInitFailure                                      575
#define kNtErrorPagefileCreateFailed                                576
#define kNtErrorInvalidImageHash                                    577
#define kNtErrorNoPagefile                                          578
#define kNtErrorIllegalFloatContext                                 579
#define kNtErrorNoEventPair                                         580
#define kNtErrorDomainCtrlrConfigError                              581
#define kNtErrorIllegalCharacter                                    582 /* EILSEQ */
#define kNtErrorUndefinedCharacter                                  583
#define kNtErrorFloppyVolume                                        584
#define kNtErrorBiosFailedToConnectInterrupt                        585
#define kNtErrorBackupController                                    586
#define kNtErrorMutantLimitExceeded                                 587
#define kNtErrorFsDriverRequired                                    588
#define kNtErrorCannotLoadRegistryFile                              589
#define kNtErrorDebugAttachFailed                                   590
#define kNtErrorSystemProcessTerminated                             591
#define kNtErrorDataNotAccepted                                     592
#define kNtErrorVdmHardError                                        593
#define kNtErrorDriverCancelTimeout                                 594
#define kNtErrorReplyMessageMismatch                                595 /* EPROGMISMATCH */
#define kNtErrorLostWritebehindData                                 596
#define kNtErrorClientServerParametersInvalid                       597
#define kNtErrorNotTinyStream                                       598
#define kNtErrorStackOverflowRead                                   599
#define kNtErrorConvertToLarge                                      600
#define kNtErrorFoundOutOfScope                                     601
#define kNtErrorAllocateBucket                                      602
#define kNtErrorMarshallOverflow                                    603
#define kNtErrorInvalidVariant                                      604
#define kNtErrorBadCompressionBuffer                                605
#define kNtErrorAuditFailed                                         606
#define kNtErrorTimerResolutionNotSet                               607
#define kNtErrorInsufficientLogonInfo                               608
#define kNtErrorBadDllEntrypoint                                    609
#define kNtErrorBadServiceEntrypoint                                610
#define kNtErrorIpAddressConflict1                                  611
#define kNtErrorIpAddressConflict2                                  612
#define kNtErrorRegistryQuotaLimit                                  613
#define kNtErrorNoCallbackActive                                    614
#define kNtErrorPwdTooShort                                         615
#define kNtErrorPwdTooRecent                                        616
#define kNtErrorPwdHistoryConflict                                  617
#define kNtErrorUnsupportedCompression                              618
#define kNtErrorInvalidHwProfile                                    619
#define kNtErrorInvalidPlugplayDevicePath                           620
#define kNtErrorQuotaListInconsistent                               621
#define kNtErrorEvaluationExpiration                                622
#define kNtErrorIllegalDllRelocation                                623
#define kNtErrorDllInitFailedLogoff                                 624
#define kNtErrorValidateContinue                                    625
#define kNtErrorNoMoreMatches                                       626
#define kNtErrorRangeListConflict                                   627
#define kNtErrorServerSidMismatch                                   628
#define kNtErrorCantEnableDenyOnly                                  629
#define kNtErrorFloatMultipleFaults                                 630
#define kNtErrorFloatMultipleTraps                                  631
#define kNtErrorNointerface                                         632
#define kNtErrorDriverFailedSleep                                   633
#define kNtErrorCorruptSystemFile                                   634
#define kNtErrorCommitmentMinimum                                   635
#define kNtErrorPnpRestartEnumeration                               636
#define kNtErrorSystemImageBadSignature                             637
#define kNtErrorPnpRebootRequired                                   638
#define kNtErrorInsufficientPower                                   639 /* EPWROFF */
#define kNtErrorMultipleFaultViolation                              640
#define kNtErrorSystemShutdown                                      641
#define kNtErrorPortNotSet                                          642
#define kNtErrorDsVersionCheckFailure                               643
#define kNtErrorRangeNotFound                                       644
#define kNtErrorNotSafeModeDriver                                   646
#define kNtErrorFailedDriverEntry                                   647
#define kNtErrorDeviceEnumerationError                              648
#define kNtErrorMountPointNotResolved                               649
#define kNtErrorInvalidDeviceObjectParameter                        650
#define kNtErrorMcaOccured                                          651
#define kNtErrorDriverDatabaseError                                 652
#define kNtErrorSystemHiveTooLarge                                  653
#define kNtErrorDriverFailedPriorUnload                             654
#define kNtErrorVolsnapPrepareHibernate                             655
#define kNtErrorHibernationFailure                                  656
#define kNtErrorPwdTooLong                                          657
#define kNtErrorFileSystemLimitation                                665
#define kNtErrorAssertionFailure                                    668
#define kNtErrorAcpiError                                           669
#define kNtErrorWowAssertion                                        670
#define kNtErrorPnpBadMpsTable                                      671
#define kNtErrorPnpTranslationFailed                                672
#define kNtErrorPnpIrqTranslationFailed                             673
#define kNtErrorPnpInvalidId                                        674
#define kNtErrorWakeSystemDebugger                                  675
#define kNtErrorHandlesClosed                                       676
#define kNtErrorExtraneousInformation                               677
#define kNtErrorRxactCommitNecessary                                678
#define kNtErrorMediaCheck                                          679
#define kNtErrorGuidSubstitutionMade                                680
#define kNtErrorStoppedOnSymlink                                    681
#define kNtErrorLongjump                                            682
#define kNtErrorPlugplayQueryVetoed                                 683
#define kNtErrorUnwindConsolidate                                   684
#define kNtErrorRegistryHiveRecovered                               685
#define kNtErrorDllMightBeInsecure                                  686
#define kNtErrorDllMightBeIncompatible                              687
#define kNtErrorDbgExceptionNotHandled                              688
#define kNtErrorDbgReplyLater                                       689
#define kNtErrorDbgUnableToProvideHandle                            690
#define kNtErrorDbgTerminateThread                                  691
#define kNtErrorDbgTerminateProcess                                 692
#define kNtErrorDbgControlC                                         693
#define kNtErrorDbgPrintexceptionC                                  694
#define kNtErrorDbgRipexception                                     695
#define kNtErrorDbgControlBreak                                     696
#define kNtErrorDbgCommandException                                 697
#define kNtErrorObjectNameExists                                    698
#define kNtErrorThreadWasSuspended                                  699
#define kNtErrorImageNotAtBase                                      700
#define kNtErrorRxactStateCreated                                   701
#define kNtErrorSegmentNotification                                 702
#define kNtErrorBadCurrentDirectory                                 703
#define kNtErrorFtReadRecoveryFromBackup                            704
#define kNtErrorFtWriteRecovery                                     705
#define kNtErrorImageMachineTypeMismatch                            706
#define kNtErrorReceivePartial                                      707
#define kNtErrorReceiveExpedited                                    708
#define kNtErrorReceivePartialExpedited                             709
#define kNtErrorEventDone                                           710
#define kNtErrorEventPending                                        711
#define kNtErrorCheckingFileSystem                                  712
#define kNtErrorFatalAppExit                                        713
#define kNtErrorPredefinedHandle                                    714
#define kNtErrorWasUnlocked                                         715
#define kNtErrorServiceNotification                                 716
#define kNtErrorWasLocked                                           717
#define kNtErrorLogHardError                                        718
#define kNtErrorAlreadyWin32                                        719
#define kNtErrorImageMachineTypeMismatchExe                         720
#define kNtErrorNoYieldPerformed                                    721
#define kNtErrorTimerResumeIgnored                                  722
#define kNtErrorArbitrationUnhandled                                723
#define kNtErrorCardbusNotSupported                                 724
#define kNtErrorMpProcessorMismatch                                 725
#define kNtErrorHibernated                                          726
#define kNtErrorResumeHibernation                                   727
#define kNtErrorFirmwareUpdated                                     728
#define kNtErrorDriversLeakingLockedPages                           729
#define kNtErrorWakeSystem                                          730
#define kNtErrorWait_1                                              731
#define kNtErrorWait_2                                              732
#define kNtErrorWait_3                                              733
#define kNtErrorWait_63                                             734
#define kNtErrorAbandonedWait_0                                     735
#define kNtErrorAbandonedWait_63                                    736
#define kNtErrorUserApc                                             737
#define kNtErrorKernelApc                                           738
#define kNtErrorAlerted                                             739
#define kNtErrorElevationRequired                                   740
#define kNtErrorReparse                                             741
#define kNtErrorOplockBreakInProgress                               742
#define kNtErrorVolumeMounted                                       743
#define kNtErrorRxactCommitted                                      744
#define kNtErrorNotifyCleanup                                       745
#define kNtErrorPrimaryTransportConnectFailed                       746
#define kNtErrorPageFaultTransition                                 747
#define kNtErrorPageFaultDemandZero                                 748
#define kNtErrorPageFaultCopyOnWrite                                749
#define kNtErrorPageFaultGuardPage                                  750
#define kNtErrorPageFaultPagingFile                                 751
#define kNtErrorCachePageLocked                                     752
#define kNtErrorCrashDump                                           753
#define kNtErrorBufferAllZeros                                      754
#define kNtErrorReparseObject                                       755
#define kNtErrorResourceRequirementsChanged                         756
#define kNtErrorTranslationComplete                                 757
#define kNtErrorNothingToTerminate                                  758
#define kNtErrorProcessNotInJob                                     759
#define kNtErrorProcessInJob                                        760
#define kNtErrorVolsnapHibernateReady                               761
#define kNtErrorFsfilterOpCompletedSuccessfully                     762
#define kNtErrorInterruptVectorAlreadyConnected                     763
#define kNtErrorInterruptStillConnected                             764
#define kNtErrorWaitForOplock                                       765
#define kNtErrorDbgExceptionHandled                                 766
#define kNtErrorDbgContinue                                         767
#define kNtErrorCallbackPopStack                                    768
#define kNtErrorCompressionDisabled                                 769
#define kNtErrorCantfetchbackwards                                  770
#define kNtErrorCantscrollbackwards                                 771
#define kNtErrorRowsnotreleased                                     772
#define kNtErrorBadAccessorFlags                                    773
#define kNtErrorErrorsEncountered                                   774
#define kNtErrorNotCapable                                          775
#define kNtErrorRequestOutOfSequence                                776
#define kNtErrorVersionParseError                                   777
#define kNtErrorBadstartposition                                    778
#define kNtErrorMemoryHardware                                      779
#define kNtErrorDiskRepairDisabled                                  780
#define kNtErrorInsufficientResourceForSpecifiedSharedSectionSize   781
#define kNtErrorSystemPowerstateTransition                          782
#define kNtErrorSystemPowerstateComplexTransition                   783
#define kNtErrorMcaException                                        784
#define kNtErrorAccessAuditByPolicy                                 785
#define kNtErrorAccessDisabledNoSaferUiByPolicy                     786
#define kNtErrorAbandonHiberfile                                    787
#define kNtErrorLostWritebehindDataNetworkDisconnected              788
#define kNtErrorLostWritebehindDataNetworkServerError               789
#define kNtErrorLostWritebehindDataLocalDiskError                   790
#define kNtErrorBadMcfgTable                                        791
#define kNtErrorDiskRepairRedirected                                792
#define kNtErrorDiskRepairUnsuccessful                              793
#define kNtErrorCorruptLogOverfull                                  794
#define kNtErrorCorruptLogCorrupted                                 795
#define kNtErrorCorruptLogUnavailable                               796
#define kNtErrorCorruptLogDeletedFull                               797
#define kNtErrorCorruptLogCleared                                   798
#define kNtErrorOrphanNameExhausted                                 799
#define kNtErrorOplockSwitchedToNewHandle                           800
#define kNtErrorCannotGrantRequestedOplock                          801
#define kNtErrorCannotBreakOplock                                   802
#define kNtErrorOplockHandleClosed                                  803
#define kNtErrorNoAceCondition                                      804
#define kNtErrorInvalidAceCondition                                 805
#define kNtErrorFileHandleRevoked                                   806
#define kNtErrorImageAtDifferentBase                                807
#define kNtErrorEncryptedIoNotPossible                              808
#define kNtErrorFileMetadataOptimizationInProgress                  809
#define kNtErrorQuotaActivity                                       810
#define kNtErrorHandleRevoked                                       811
#define kNtErrorCallbackInvokeInline                                812
#define kNtErrorCpuSetInvalid                                       813
#define kNtErrorEnclaveNotTerminated                                814
#define kNtErrorEnclaveViolation                                    815
#define kNtErrorEaAccessDenied                                      994
#define kNtErrorOperationAborted                                    995
#define kNtErrorIoIncomplete                                        996
#define kNtErrorIoPending                                           997
#define kNtErrorNoaccess                                            998
#define kNtErrorSwaperror                                           999
#define kNtErrorStackOverflow                                       1001
#define kNtErrorInvalidMessage                                      1002
#define kNtErrorCanNotComplete                                      1003
#define kNtErrorInvalidFlags                                        1004
#define kNtErrorUnrecognizedVolume                                  1005
#define kNtErrorFileInvalid                                         1006
#define kNtErrorFullscreenMode                                      1007
#define kNtErrorNoToken                                             1008
#define kNtErrorBaddb                                               1009
#define kNtErrorBadkey                                              1010
#define kNtErrorCantopen                                            1011
#define kNtErrorCantread                                            1012
#define kNtErrorCantwrite                                           1013
#define kNtErrorRegistryRecovered                                   1014
#define kNtErrorRegistryCorrupt                                     1015
#define kNtErrorRegistryIoFailed                                    1016
#define kNtErrorNotRegistryFile                                     1017
#define kNtErrorKeyDeleted                                          1018
#define kNtErrorNoLogSpace                                          1019
#define kNtErrorKeyHasChildren                                      1020
#define kNtErrorChildMustBeVolatile                                 1021
#define kNtErrorNotifyEnumDir                                       1022
#define kNtErrorDependentServicesRunning                            1051
#define kNtErrorInvalidServiceControl                               1052
#define kNtErrorServiceRequestTimeout                               1053
#define kNtErrorServiceNoThread                                     1054
#define kNtErrorServiceDatabaseLocked                               1055
#define kNtErrorServiceAlreadyRunning                               1056
#define kNtErrorInvalidServiceAccount                               1057
#define kNtErrorServiceDisabled                                     1058
#define kNtErrorCircularDependency                                  1059
#define kNtErrorServiceDoesNotExist                                 1060
#define kNtErrorServiceCannotAcceptCtrl                             1061
#define kNtErrorServiceNotActive                                    1062
#define kNtErrorFailedServiceControllerConnect                      1063
#define kNtErrorExceptionInService                                  1064
#define kNtErrorDatabaseDoesNotExist                                1065
#define kNtErrorServiceSpecificError                                1066
#define kNtErrorProcessAborted                                      1067
#define kNtErrorServiceDependencyFail                               1068
#define kNtErrorServiceLogonFailed                                  1069
#define kNtErrorServiceStartHang                                    1070
#define kNtErrorInvalidServiceLock                                  1071
#define kNtErrorServiceMarkedForDelete                              1072
#define kNtErrorServiceExists                                       1073
#define kNtErrorAlreadyRunningLkg                                   1074
#define kNtErrorServiceDependencyDeleted                            1075
#define kNtErrorBootAlreadyAccepted                                 1076
#define kNtErrorServiceNeverStarted                                 1077
#define kNtErrorDuplicateServiceName                                1078
#define kNtErrorDifferentServiceAccount                             1079
#define kNtErrorCannotDetectDriverFailure                           1080
#define kNtErrorCannotDetectProcessAbort                            1081
#define kNtErrorNoRecoveryProgram                                   1082
#define kNtErrorServiceNotInExe                                     1083
#define kNtErrorNotSafebootService                                  1084
#define kNtErrorEndOfMedia                                          1100
#define kNtErrorFilemarkDetected                                    1101
#define kNtErrorBeginningOfMedia                                    1102
#define kNtErrorSetmarkDetected                                     1103
#define kNtErrorNoDataDetected                                      1104
#define kNtErrorPartitionFailure                                    1105
#define kNtErrorInvalidBlockLength                                  1106
#define kNtErrorDeviceNotPartitioned                                1107
#define kNtErrorUnableToLockMedia                                   1108
#define kNtErrorUnableToUnloadMedia                                 1109
#define kNtErrorMediaChanged                                        1110
#define kNtErrorBusReset                                            1111
#define kNtErrorNoMediaInDrive                                      1112 /* ENXIO */
#define kNtErrorNoUnicodeTranslation                                1113
#define kNtErrorDllInitFailed                                       1114
#define kNtErrorShutdownInProgress                                  1115
#define kNtErrorNoShutdownInProgress                                1116
#define kNtErrorIoDevice                                            1117 /* EIO */
#define kNtErrorSerialNoDevice                                      1118 /* ENOTTY */
#define kNtErrorIrqBusy                                             1119
#define kNtErrorMoreWrites                                          1120
#define kNtErrorCounterTimeout                                      1121
#define kNtErrorFloppyIdMarkNotFound                                1122
#define kNtErrorFloppyWrongCylinder                                 1123
#define kNtErrorFloppyUnknownError                                  1124
#define kNtErrorFloppyBadRegisters                                  1125
#define kNtErrorDiskRecalibrateFailed                               1126
#define kNtErrorDiskOperationFailed                                 1127
#define kNtErrorDiskResetFailed                                     1128
#define kNtErrorEomOverflow                                         1129
#define kNtErrorNotEnoughServerMemory                               1130
#define kNtErrorPossibleDeadlock                                    1131 /* EDEADLK */
#define kNtErrorMappedAlignment                                     1132
#define kNtErrorSetPowerStateVetoed                                 1140
#define kNtErrorSetPowerStateFailed                                 1141
#define kNtErrorTooManyLinks                                        1142
#define kNtErrorOldWinVersion                                       1150
#define kNtErrorAppWrongOs                                          1151
#define kNtErrorSingleInstanceApp                                   1152
#define kNtErrorRmodeApp                                            1153
#define kNtErrorInvalidDll                                          1154
#define kNtErrorNoAssociation                                       1155
#define kNtErrorDdeFail                                             1156
#define kNtErrorDllNotFound                                         1157
#define kNtErrorNoMoreUserHandles                                   1158
#define kNtErrorMessageSyncOnly                                     1159
#define kNtErrorSourceElementEmpty                                  1160
#define kNtErrorDestinationElementFull                              1161
#define kNtErrorIllegalElementAddress                               1162
#define kNtErrorMagazineNotPresent                                  1163
#define kNtErrorDeviceReinitializationNeeded                        1164
#define kNtErrorDeviceRequiresCleaning                              1165
#define kNtErrorDeviceDoorOpen                                      1166
#define kNtErrorDeviceNotConnected                                  1167
#define kNtErrorNotFound                                            1168
#define kNtErrorNoMatch                                             1169
#define kNtErrorSetNotFound                                         1170
#define kNtErrorPointNotFound                                       1171
#define kNtErrorNoTrackingService                                   1172
#define kNtErrorNoVolumeId                                          1173
#define kNtErrorUnableToRemoveReplaced                              1175
#define kNtErrorUnableToMoveReplacement                             1176
#define kNtErrorUnableToMoveReplacement_2                           1177
#define kNtErrorJournalDeleteInProgress                             1178
#define kNtErrorJournalNotActive                                    1179
#define kNtErrorPotentialFileFound                                  1180
#define kNtErrorJournalEntryDeleted                                 1181
#define kNtErrorShutdownIsScheduled                                 1190
#define kNtErrorShutdownUsersLoggedOn                               1191
#define kNtErrorBadDevice                                           1200 /* ENODEV */
#define kNtErrorConnectionUnavail                                   1201
#define kNtErrorDeviceAlreadyRemembered                             1202
#define kNtErrorNoNetOrBadPath                                      1203
#define kNtErrorBadProvider                                         1204
#define kNtErrorCannotOpenProfile                                   1205
#define kNtErrorBadProfile                                          1206
#define kNtErrorNotContainer                                        1207
#define kNtErrorExtendedError                                       1208
#define kNtErrorInvalidGroupname                                    1209
#define kNtErrorInvalidComputername                                 1210
#define kNtErrorInvalidEventname                                    1211
#define kNtErrorInvalidDomainname                                   1212
#define kNtErrorInvalidServicename                                  1213
#define kNtErrorInvalidNetname                                      1214
#define kNtErrorInvalidSharename                                    1215
#define kNtErrorInvalidPasswordname                                 1216
#define kNtErrorInvalidMessagename                                  1217
#define kNtErrorInvalidMessagedest                                  1218
#define kNtErrorSessionCredentialConflict                           1219
#define kNtErrorRemoteSessionLimitExceeded                          1220
#define kNtErrorDupDomainname                                       1221
#define kNtErrorNoNetwork                                           1222
#define kNtErrorCancelled                                           1223 /* ECANCELED */
#define kNtErrorUserMappedFile                                      1224
#define kNtErrorConnectionRefused                                   1225
#define kNtErrorGracefulDisconnect                                  1226
#define kNtErrorAddressAlreadyAssociated                            1227
#define kNtErrorAddressNotAssociated                                1228
#define kNtErrorConnectionInvalid                                   1229
#define kNtErrorConnectionActive                                    1230
#define kNtErrorNetworkUnreachable                                  1231
#define kNtErrorHostUnreachable                                     1232
#define kNtErrorProtocolUnreachable                                 1233 /* multimapped to ENETUNREACH */
#define kNtErrorPortUnreachable                                     1234
#define kNtErrorRequestAborted                                      1235
#define kNtErrorConnectionAborted                                   1236
#define kNtErrorRetry                                               1237
#define kNtErrorConnectionCountLimit                                1238
#define kNtErrorLoginTimeRestriction                                1239
#define kNtErrorLoginWkstaRestriction                               1240
#define kNtErrorIncorrectAddress                                    1241
#define kNtErrorAlreadyRegistered                                   1242
#define kNtErrorServiceNotFound                                     1243
#define kNtErrorNotAuthenticated                                    1244 /* EAUTH */
#define kNtErrorNotLoggedOn                                         1245
#define kNtErrorContinue                                            1246
#define kNtErrorAlreadyInitialized                                  1247
#define kNtErrorNoMoreDevices                                       1248
#define kNtErrorNoSuchSite                                          1249
#define kNtErrorDomainControllerExists                              1250
#define kNtErrorOnlyIfConnected                                     1251
#define kNtErrorOverrideNochanges                                   1252
#define kNtErrorBadUserProfile                                      1253
#define kNtErrorNotSupportedOnSbs                                   1254
#define kNtErrorServerShutdownInProgress                            1255
#define kNtErrorHostDown                                            1256
#define kNtErrorNonAccountSid                                       1257
#define kNtErrorNonDomainSid                                        1258
#define kNtErrorApphelpBlock                                        1259
#define kNtErrorAccessDisabledByPolicy                              1260
#define kNtErrorRegNatConsumption                                   1261
#define kNtErrorCscshareOffline                                     1262
#define kNtErrorPkinitFailure                                       1263
#define kNtErrorSmartcardSubsystemFailure                           1264
#define kNtErrorDowngradeDetected                                   1265
#define kNtErrorMachineLocked                                       1271
#define kNtErrorSmbGuestLogonBlocked                                1272
#define kNtErrorCallbackSuppliedInvalidData                         1273
#define kNtErrorSyncForegroundRefreshRequired                       1274
#define kNtErrorDriverBlocked                                       1275
#define kNtErrorInvalidImportOfNonDll                               1276
#define kNtErrorAccessDisabledWebblade                              1277
#define kNtErrorAccessDisabledWebbladeTamper                        1278
#define kNtErrorRecoveryFailure                                     1279
#define kNtErrorAlreadyFiber                                        1280
#define kNtErrorAlreadyThread                                       1281
#define kNtErrorStackBufferOverrun                                  1282
#define kNtErrorParameterQuotaExceeded                              1283
#define kNtErrorDebuggerInactive                                    1284
#define kNtErrorDelayLoadFailed                                     1285
#define kNtErrorVdmDisallowed                                       1286
#define kNtErrorUnidentifiedError                                   1287 /* EIDRM */
#define kNtErrorInvalidCruntimeParameter                            1288
#define kNtErrorBeyondVdl                                           1289
#define kNtErrorIncompatibleServiceSidType                          1290
#define kNtErrorDriverProcessTerminated                             1291
#define kNtErrorImplementationLimit                                 1292
#define kNtErrorProcessIsProtected                                  1293
#define kNtErrorServiceNotifyClientLagging                          1294
#define kNtErrorDiskQuotaExceeded                                   1295
#define kNtErrorContentBlocked                                      1296
#define kNtErrorIncompatibleServicePrivilege                        1297
#define kNtErrorAppHang                                             1298
#define kNtErrorInvalidLabel                                        1299
#define kNtErrorNotAllAssigned                                      1300
#define kNtErrorSomeNotMapped                                       1301
#define kNtErrorNoQuotasForAccount                                  1302
#define kNtErrorLocalUserSessionKey                                 1303
#define kNtErrorNullLmPassword                                      1304
#define kNtErrorUnknownRevision                                     1305
#define kNtErrorRevisionMismatch                                    1306
#define kNtErrorInvalidOwner                                        1307
#define kNtErrorInvalidPrimaryGroup                                 1308
#define kNtErrorNoImpersonationToken                                1309
#define kNtErrorCantDisableMandatory                                1310
#define kNtErrorNoLogonServers                                      1311
#define kNtErrorNoSuchLogonSession                                  1312
#define kNtErrorNoSuchPrivilege                                     1313
#define kNtErrorPrivilegeNotHeld                                    1314
#define kNtErrorInvalidAccountName                                  1315
#define kNtErrorUserExists                                          1316
#define kNtErrorNoSuchUser                                          1317
#define kNtErrorGroupExists                                         1318
#define kNtErrorNoSuchGroup                                         1319
#define kNtErrorMemberInGroup                                       1320
#define kNtErrorMemberNotInGroup                                    1321
#define kNtErrorLastAdmin                                           1322
#define kNtErrorWrongPassword                                       1323
#define kNtErrorIllFormedPassword                                   1324
#define kNtErrorPasswordRestriction                                 1325
#define kNtErrorLogonFailure                                        1326
#define kNtErrorAccountRestriction                                  1327
#define kNtErrorInvalidLogonHours                                   1328
#define kNtErrorInvalidWorkstation                                  1329
#define kNtErrorPasswordExpired                                     1330
#define kNtErrorAccountDisabled                                     1331
#define kNtErrorNoneMapped                                          1332
#define kNtErrorTooManyLuidsRequested                               1333
#define kNtErrorLuidsExhausted                                      1334
#define kNtErrorInvalidSubAuthority                                 1335
#define kNtErrorInvalidAcl                                          1336
#define kNtErrorInvalidSid                                          1337
#define kNtErrorInvalidSecurityDescr                                1338
#define kNtErrorBadInheritanceAcl                                   1340
#define kNtErrorServerDisabled                                      1341
#define kNtErrorServerNotDisabled                                   1342
#define kNtErrorInvalidIdAuthority                                  1343
#define kNtErrorAllottedSpaceExceeded                               1344
#define kNtErrorInvalidGroupAttributes                              1345
#define kNtErrorBadImpersonationLevel                               1346
#define kNtErrorCantOpenAnonymous                                   1347
#define kNtErrorBadValidationClass                                  1348
#define kNtErrorBadTokenType                                        1349
#define kNtErrorNoSecurityOnObject                                  1350
#define kNtErrorCantAccessDomainInfo                                1351
#define kNtErrorInvalidServerState                                  1352
#define kNtErrorInvalidDomainState                                  1353
#define kNtErrorInvalidDomainRole                                   1354
#define kNtErrorNoSuchDomain                                        1355
#define kNtErrorDomainExists                                        1356
#define kNtErrorDomainLimitExceeded                                 1357
#define kNtErrorInternalDbCorruption                                1358
#define kNtErrorInternalError                                       1359
#define kNtErrorGenericNotMapped                                    1360
#define kNtErrorBadDescriptorFormat                                 1361
#define kNtErrorNotLogonProcess                                     1362
#define kNtErrorLogonSessionExists                                  1363
#define kNtErrorNoSuchPackage                                       1364
#define kNtErrorBadLogonSessionState                                1365
#define kNtErrorLogonSessionCollision                               1366
#define kNtErrorInvalidLogonType                                    1367
#define kNtErrorCannotImpersonate                                   1368
#define kNtErrorRxactInvalidState                                   1369
#define kNtErrorRxactCommitFailure                                  1370
#define kNtErrorSpecialAccount                                      1371
#define kNtErrorSpecialGroup                                        1372
#define kNtErrorSpecialUser                                         1373
#define kNtErrorMembersPrimaryGroup                                 1374
#define kNtErrorTokenAlreadyInUse                                   1375
#define kNtErrorNoSuchAlias                                         1376
#define kNtErrorMemberNotInAlias                                    1377
#define kNtErrorMemberInAlias                                       1378
#define kNtErrorAliasExists                                         1379
#define kNtErrorLogonNotGranted                                     1380
#define kNtErrorTooManySecrets                                      1381
#define kNtErrorSecretTooLong                                       1382
#define kNtErrorInternalDbError                                     1383
#define kNtErrorTooManyContextIds                                   1384
#define kNtErrorLogonTypeNotGranted                                 1385
#define kNtErrorNtCrossEncryptionRequired                           1386
#define kNtErrorNoSuchMember                                        1387
#define kNtErrorInvalidMember                                       1388
#define kNtErrorTooManySids                                         1389
#define kNtErrorLmCrossEncryptionRequired                           1390
#define kNtErrorNoInheritance                                       1391
#define kNtErrorFileCorrupt                                         1392
#define kNtErrorDiskCorrupt                                         1393
#define kNtErrorNoUserSessionKey                                    1394
#define kNtErrorLicenseQuotaExceeded                                1395
#define kNtErrorWrongTargetName                                     1396
#define kNtErrorMutualAuthFailed                                    1397
#define kNtErrorTimeSkew                                            1398
#define kNtErrorCurrentDomainNotAllowed                             1399
#define kNtErrorInvalidWindowHandle                                 1400
#define kNtErrorInvalidMenuHandle                                   1401
#define kNtErrorInvalidCursorHandle                                 1402
#define kNtErrorInvalidAccelHandle                                  1403
#define kNtErrorInvalidHookHandle                                   1404
#define kNtErrorInvalidDwpHandle                                    1405
#define kNtErrorTlwWithWschild                                      1406
#define kNtErrorCannotFindWndClass                                  1407
#define kNtErrorWindowOfOtherThread                                 1408
#define kNtErrorHotkeyAlreadyRegistered                             1409
#define kNtErrorClassAlreadyExists                                  1410
#define kNtErrorClassDoesNotExist                                   1411
#define kNtErrorClassHasWindows                                     1412
#define kNtErrorInvalidIndex                                        1413
#define kNtErrorInvalidIconHandle                                   1414
#define kNtErrorPrivateDialogIndex                                  1415
#define kNtErrorListboxIdNotFound                                   1416
#define kNtErrorNoWildcardCharacters                                1417
#define kNtErrorClipboardNotOpen                                    1418
#define kNtErrorHotkeyNotRegistered                                 1419
#define kNtErrorWindowNotDialog                                     1420
#define kNtErrorControlIdNotFound                                   1421
#define kNtErrorInvalidComboboxMessage                              1422
#define kNtErrorWindowNotCombobox                                   1423
#define kNtErrorInvalidEditHeight                                   1424
#define kNtErrorDcNotFound                                          1425
#define kNtErrorInvalidHookFilter                                   1426
#define kNtErrorInvalidFilterProc                                   1427
#define kNtErrorHookNeedsHmod                                       1428
#define kNtErrorGlobalOnlyHook                                      1429
#define kNtErrorJournalHookSet                                      1430
#define kNtErrorHookNotInstalled                                    1431
#define kNtErrorInvalidLbMessage                                    1432
#define kNtErrorSetcountOnBadLb                                     1433
#define kNtErrorLbWithoutTabstops                                   1434
#define kNtErrorDestroyObjectOfOtherThread                          1435
#define kNtErrorChildWindowMenu                                     1436
#define kNtErrorNoSystemMenu                                        1437
#define kNtErrorInvalidMsgboxStyle                                  1438
#define kNtErrorInvalidSpiValue                                     1439
#define kNtErrorScreenAlreadyLocked                                 1440
#define kNtErrorHwndsHaveDiffParent                                 1441
#define kNtErrorNotChildWindow                                      1442
#define kNtErrorInvalidGwCommand                                    1443
#define kNtErrorInvalidThreadId                                     1444
#define kNtErrorNonMdichildWindow                                   1445
#define kNtErrorPopupAlreadyActive                                  1446
#define kNtErrorNoScrollbars                                        1447
#define kNtErrorInvalidScrollbarRange                               1448
#define kNtErrorInvalidShowwinCommand                               1449
#define kNtErrorNoSystemResources                                   1450
#define kNtErrorNonpagedSystemResources                             1451
#define kNtErrorPagedSystemResources                                1452
#define kNtErrorWorkingSetQuota                                     1453
#define kNtErrorPagefileQuota                                       1454
#define kNtErrorCommitmentLimit                                     1455
#define kNtErrorMenuItemNotFound                                    1456
#define kNtErrorInvalidKeyboardHandle                               1457
#define kNtErrorHookTypeNotAllowed                                  1458
#define kNtErrorRequiresInteractiveWindowstation                    1459
#define kNtErrorTimeout                                             1460 /* ETIMEDOUT */
#define kNtErrorInvalidMonitorHandle                                1461
#define kNtErrorIncorrectSize                                       1462
#define kNtErrorSymlinkClassDisabled                                1463
#define kNtErrorSymlinkNotSupported                                 1464
#define kNtErrorXmlParseError                                       1465
#define kNtErrorXmldsigError                                        1466
#define kNtErrorRestartApplication                                  1467
#define kNtErrorWrongCompartment                                    1468
#define kNtErrorAuthipFailure                                       1469
#define kNtErrorNoNvramResources                                    1470
#define kNtErrorNotGuiProcess                                       1471
#define kNtErrorEventlogFileCorrupt                                 1500
#define kNtErrorEventlogCantStart                                   1501
#define kNtErrorLogFileFull                                         1502
#define kNtErrorEventlogFileChanged                                 1503
#define kNtErrorContainerAssigned                                   1504
#define kNtErrorJobNoContainer                                      1505
#define kNtErrorInvalidTaskName                                     1550
#define kNtErrorInvalidTaskIndex                                    1551
#define kNtErrorThreadAlreadyInTask                                 1552
#define kNtErrorInstallServiceFailure                               1601
#define kNtErrorInstallUserexit                                     1602
#define kNtErrorInstallFailure                                      1603
#define kNtErrorInstallSuspend                                      1604
#define kNtErrorUnknownProduct                                      1605
#define kNtErrorUnknownFeature                                      1606
#define kNtErrorUnknownComponent                                    1607
#define kNtErrorUnknownProperty                                     1608
#define kNtErrorInvalidHandleState                                  1609
#define kNtErrorBadConfiguration                                    1610
#define kNtErrorIndexAbsent                                         1611
#define kNtErrorInstallSourceAbsent                                 1612
#define kNtErrorInstallPackageVersion                               1613
#define kNtErrorProductUninstalled                                  1614
#define kNtErrorBadQuerySyntax                                      1615
#define kNtErrorInvalidField                                        1616
#define kNtErrorDeviceRemoved                                       1617
#define kNtErrorInstallAlreadyRunning                               1618
#define kNtErrorInstallPackageOpenFailed                            1619
#define kNtErrorInstallPackageInvalid                               1620
#define kNtErrorInstallUiFailure                                    1621
#define kNtErrorInstallLogFailure                                   1622
#define kNtErrorInstallLanguageUnsupported                          1623
#define kNtErrorInstallTransformFailure                             1624
#define kNtErrorInstallPackageRejected                              1625
#define kNtErrorFunctionNotCalled                                   1626 /* EBADRPC */
#define kNtErrorFunctionFailed                                      1627 /* ERPCMISMATCH */
#define kNtErrorInvalidTable                                        1628
#define kNtErrorDatatypeMismatch                                    1629
#define kNtErrorUnsupportedType                                     1630
#define kNtErrorCreateFailed                                        1631
#define kNtErrorInstallTempUnwritable                               1632
#define kNtErrorInstallPlatformUnsupported                          1633
#define kNtErrorInstallNotused                                      1634
#define kNtErrorPatchPackageOpenFailed                              1635
#define kNtErrorPatchPackageInvalid                                 1636
#define kNtErrorPatchPackageUnsupported                             1637
#define kNtErrorProductVersion                                      1638
#define kNtErrorInvalidCommandLine                                  1639 /* E2BIG */
#define kNtErrorInstallRemoteDisallowed                             1640
#define kNtErrorSuccessRebootInitiated                              1641
#define kNtErrorPatchTargetNotFound                                 1642
#define kNtErrorPatchPackageRejected                                1643
#define kNtErrorInstallTransformRejected                            1644
#define kNtErrorInstallRemoteProhibited                             1645
#define kNtErrorPatchRemovalUnsupported                             1646
#define kNtErrorUnknownPatch                                        1647
#define kNtErrorPatchNoSequence                                     1648
#define kNtErrorPatchRemovalDisallowed                              1649
#define kNtErrorInvalidPatchXml                                     1650
#define kNtErrorPatchManagedAdvertisedProduct                       1651
#define kNtErrorInstallServiceSafeboot                              1652
#define kNtErrorFailFastException                                   1653
#define kNtErrorInstallRejected                                     1654
#define kNtErrorDynamicCodeBlocked                                  1655
#define kNtErrorNotSameObject                                       1656
#define kNtErrorStrictCfgViolation                                  1657
#define kNtErrorSetContextDenied                                    1660
#define kNtErrorCrossPartitionViolation                             1661
#define kNtErrorInvalidUserBuffer                                   1784
#define kNtErrorUnrecognizedMedia                                   1785
#define kNtErrorNoTrustLsaSecret                                    1786
#define kNtErrorNoTrustSamAccount                                   1787
#define kNtErrorTrustedDomainFailure                                1788
#define kNtErrorTrustedRelationshipFailure                          1789
#define kNtErrorTrustFailure                                        1790
#define kNtErrorNetlogonNotStarted                                  1792
#define kNtErrorAccountExpired                                      1793
#define kNtErrorRedirectorHasOpenHandles                            1794
#define kNtErrorPrinterDriverAlreadyInstalled                       1795
#define kNtErrorUnknownPort                                         1796
#define kNtErrorUnknownPrinterDriver                                1797
#define kNtErrorUnknownPrintprocessor                               1798
#define kNtErrorInvalidSeparatorFile                                1799
#define kNtErrorInvalidPriority                                     1800
#define kNtErrorInvalidPrinterName                                  1801
#define kNtErrorPrinterAlreadyExists                                1802
#define kNtErrorInvalidPrinterCommand                               1803
#define kNtErrorInvalidDatatype                                     1804
#define kNtErrorInvalidEnvironment                                  1805
#define kNtErrorNologonInterdomainTrustAccount                      1807
#define kNtErrorNologonWorkstationTrustAccount                      1808
#define kNtErrorNologonServerTrustAccount                           1809
#define kNtErrorDomainTrustInconsistent                             1810
#define kNtErrorServerHasOpenHandles                                1811
#define kNtErrorResourceDataNotFound                                1812
#define kNtErrorResourceTypeNotFound                                1813
#define kNtErrorResourceNameNotFound                                1814
#define kNtErrorResourceLangNotFound                                1815
#define kNtErrorNotEnoughQuota                                      1816 /* EDQUOT */
#define kNtErrorInvalidTime                                         1901
#define kNtErrorInvalidFormName                                     1902
#define kNtErrorInvalidFormSize                                     1903
#define kNtErrorAlreadyWaiting                                      1904
#define kNtErrorPrinterDeleted                                      1905
#define kNtErrorInvalidPrinterState                                 1906
#define kNtErrorPasswordMustChange                                  1907
#define kNtErrorDomainControllerNotFound                            1908
#define kNtErrorAccountLockedOut                                    1909
#define kNtErrorNoSitename                                          1919
#define kNtErrorCantAccessFile                                      1920
#define kNtErrorCantResolveFilename                                 1921
#define kNtErrorKmDriverBlocked                                     1930
#define kNtErrorContextExpired                                      1931
#define kNtErrorPerUserTrustQuotaExceeded                           1932
#define kNtErrorAllUserTrustQuotaExceeded                           1933
#define kNtErrorUserDeleteTrustQuotaExceeded                        1934
#define kNtErrorAuthenticationFirewallFailed                        1935
#define kNtErrorRemotePrintConnectionsBlocked                       1936
#define kNtErrorNtlmBlocked                                         1937
#define kNtErrorPasswordChangeRequired                              1938
#define kNtErrorLostModeLogonRestriction                            1939
#define kNtErrorInvalidPixelFormat                                  2000
#define kNtErrorBadDriver                                           2001
#define kNtErrorInvalidWindowStyle                                  2002
#define kNtErrorMetafileNotSupported                                2003
#define kNtErrorTransformNotSupported                               2004
#define kNtErrorClippingNotSupported                                2005
#define kNtErrorInvalidCmm                                          2010
#define kNtErrorInvalidProfile                                      2011
#define kNtErrorTagNotFound                                         2012
#define kNtErrorTagNotPresent                                       2013
#define kNtErrorDuplicateTag                                        2014
#define kNtErrorProfileNotAssociatedWithDevice                      2015
#define kNtErrorProfileNotFound                                     2016
#define kNtErrorInvalidColorspace                                   2017
#define kNtErrorIcmNotEnabled                                       2018
#define kNtErrorDeletingIcmXform                                    2019
#define kNtErrorInvalidTransform                                    2020
#define kNtErrorColorspaceMismatch                                  2021
#define kNtErrorInvalidColorindex                                   2022
#define kNtErrorProfileDoesNotMatchDevice                           2023
#define kNtErrorConnectedOtherPassword                              2108
#define kNtErrorConnectedOtherPasswordDefault                       2109
#define kNtErrorBadUsername                                         2202
#define kNtErrorNotConnected                                        2250
#define kNtErrorOpenFiles                                           2401
#define kNtErrorActiveConnections                                   2402
#define kNtErrorDeviceInUse                                         2404
#define kNtErrorUnknownPrintMonitor                                 3000
#define kNtErrorPrinterDriverInUse                                  3001
#define kNtErrorSpoolFileNotFound                                   3002
#define kNtErrorSplNoStartdoc                                       3003
#define kNtErrorSplNoAddjob                                         3004
#define kNtErrorPrintProcessorAlreadyInstalled                      3005
#define kNtErrorPrintMonitorAlreadyInstalled                        3006
#define kNtErrorInvalidPrintMonitor                                 3007
#define kNtErrorPrintMonitorInUse                                   3008
#define kNtErrorPrinterHasJobsQueued                                3009
#define kNtErrorSuccessRebootRequired                               3010
#define kNtErrorSuccessRestartRequired                              3011
#define kNtErrorPrinterNotFound                                     3012
#define kNtErrorPrinterDriverWarned                                 3013
#define kNtErrorPrinterDriverBlocked                                3014
#define kNtErrorPrinterDriverPackageInUse                           3015
#define kNtErrorCoreDriverPackageNotFound                           3016
#define kNtErrorFailRebootRequired                                  3017
#define kNtErrorFailRebootInitiated                                 3018
#define kNtErrorPrinterDriverDownloadNeeded                         3019
#define kNtErrorPrintJobRestartRequired                             3020
#define kNtErrorInvalidPrinterDriverManifest                        3021
#define kNtErrorPrinterNotShareable                                 3022
#define kNtErrorRequestPaused                                       3050
#define kNtErrorAppexecConditionNotSatisfied                        3060
#define kNtErrorAppexecHandleInvalidated                            3061
#define kNtErrorAppexecInvalidHostGeneration                        3062
#define kNtErrorAppexecUnexpectedProcessRegistration                3063
#define kNtErrorAppexecInvalidHostState                             3064
#define kNtErrorAppexecNoDonor                                      3065
#define kNtErrorAppexecHostIdMismatch                               3066
#define kNtErrorIoReissueAsCached                                   3950
#define kNtErrorWinsInternal                                        4000
#define kNtErrorCanNotDelLocalWins                                  4001
#define kNtErrorStaticInit                                          4002
#define kNtErrorIncBackup                                           4003
#define kNtErrorFullBackup                                          4004
#define kNtErrorRecNonExistent                                      4005
#define kNtErrorRplNotAllowed                                       4006
#define kNtErrorDhcpAddressConflict                                 4100
#define kNtErrorWmiGuidNotFound                                     4200
#define kNtErrorWmiInstanceNotFound                                 4201
#define kNtErrorWmiItemidNotFound                                   4202
#define kNtErrorWmiTryAgain                                         4203
#define kNtErrorWmiDpNotFound                                       4204
#define kNtErrorWmiUnresolvedInstanceRef                            4205
#define kNtErrorWmiAlreadyEnabled                                   4206
#define kNtErrorWmiGuidDisconnected                                 4207
#define kNtErrorWmiServerUnavailable                                4208
#define kNtErrorWmiDpFailed                                         4209
#define kNtErrorWmiInvalidMof                                       4210
#define kNtErrorWmiInvalidReginfo                                   4211
#define kNtErrorWmiAlreadyDisabled                                  4212
#define kNtErrorWmiReadOnly                                         4213
#define kNtErrorWmiSetFailure                                       4214
#define kNtErrorNotAppcontainer                                     4250
#define kNtErrorAppcontainerRequired                                4251
#define kNtErrorNotSupportedInAppcontainer                          4252
#define kNtErrorInvalidPackageSidLength                             4253
#define kNtErrorInvalidMedia                                        4300
#define kNtErrorInvalidLibrary                                      4301
#define kNtErrorInvalidMediaPool                                    4302
#define kNtErrorDriveMediaMismatch                                  4303
#define kNtErrorMediaOffline                                        4304
#define kNtErrorLibraryOffline                                      4305
#define kNtErrorEmpty                                               4306 /* ENOMSG */
#define kNtErrorNotEmpty                                            4307
#define kNtErrorMediaUnavailable                                    4308
#define kNtErrorResourceDisabled                                    4309
#define kNtErrorInvalidCleaner                                      4310
#define kNtErrorUnableToClean                                       4311
#define kNtErrorObjectNotFound                                      4312
#define kNtErrorDatabaseFailure                                     4313
#define kNtErrorDatabaseFull                                        4314
#define kNtErrorMediaIncompatible                                   4315
#define kNtErrorResourceNotPresent                                  4316
#define kNtErrorInvalidOperation                                    4317
#define kNtErrorMediaNotAvailable                                   4318
#define kNtErrorDeviceNotAvailable                                  4319
#define kNtErrorRequestRefused                                      4320
#define kNtErrorInvalidDriveObject                                  4321
#define kNtErrorLibraryFull                                         4322
#define kNtErrorMediumNotAccessible                                 4323
#define kNtErrorUnableToLoadMedium                                  4324
#define kNtErrorUnableToInventoryDrive                              4325
#define kNtErrorUnableToInventorySlot                               4326
#define kNtErrorUnableToInventoryTransport                          4327
#define kNtErrorTransportFull                                       4328
#define kNtErrorControllingIeport                                   4329
#define kNtErrorUnableToEjectMountedMedia                           4330
#define kNtErrorCleanerSlotSet                                      4331
#define kNtErrorCleanerSlotNotSet                                   4332
#define kNtErrorCleanerCartridgeSpent                               4333
#define kNtErrorUnexpectedOmid                                      4334
#define kNtErrorCantDeleteLastItem                                  4335
#define kNtErrorMessageExceedsMaxSize                               4336
#define kNtErrorVolumeContainsSysFiles                              4337
#define kNtErrorIndigenousType                                      4338
#define kNtErrorNoSupportingDrives                                  4339
#define kNtErrorCleanerCartridgeInstalled                           4340
#define kNtErrorIeportFull                                          4341
#define kNtErrorFileOffline                                         4350
#define kNtErrorRemoteStorageNotActive                              4351
#define kNtErrorRemoteStorageMediaError                             4352
#define kNtErrorNotAReparsePoint                                    4390
#define kNtErrorReparseAttributeConflict                            4391
#define kNtErrorInvalidReparseData                                  4392
#define kNtErrorReparseTagInvalid                                   4393
#define kNtErrorReparseTagMismatch                                  4394
#define kNtErrorReparsePointEncountered                             4395
#define kNtErrorAppDataNotFound                                     4400
#define kNtErrorAppDataExpired                                      4401
#define kNtErrorAppDataCorrupt                                      4402
#define kNtErrorAppDataLimitExceeded                                4403
#define kNtErrorAppDataRebootRequired                               4404
#define kNtErrorSecurebootRollbackDetected                          4420
#define kNtErrorSecurebootPolicyViolation                           4421
#define kNtErrorSecurebootInvalidPolicy                             4422
#define kNtErrorSecurebootPolicyPublisherNotFound                   4423
#define kNtErrorSecurebootPolicyNotSigned                           4424
#define kNtErrorSecurebootNotEnabled                                4425
#define kNtErrorSecurebootFileReplaced                              4426
#define kNtErrorSecurebootPolicyNotAuthorized                       4427
#define kNtErrorSecurebootPolicyUnknown                             4428
#define kNtErrorSecurebootPolicyMissingAntirollbackversion          4429
#define kNtErrorSecurebootPlatformIdMismatch                        4430
#define kNtErrorSecurebootPolicyRollbackDetected                    4431
#define kNtErrorSecurebootPolicyUpgradeMismatch                     4432
#define kNtErrorSecurebootRequiredPolicyFileMissing                 4433
#define kNtErrorSecurebootNotBasePolicy                             4434
#define kNtErrorSecurebootNotSupplementalPolicy                     4435
#define kNtErrorOffloadReadFltNotSupported                          4440
#define kNtErrorOffloadWriteFltNotSupported                         4441
#define kNtErrorOffloadReadFileNotSupported                         4442
#define kNtErrorOffloadWriteFileNotSupported                        4443
#define kNtErrorAlreadyHasStreamId                                  4444
#define kNtErrorSmrGarbageCollectionRequired                        4445
#define kNtErrorWofWimHeaderCorrupt                                 4446
#define kNtErrorWofWimResourceTableCorrupt                          4447
#define kNtErrorWofFileResourceTableCorrupt                         4448
#define kNtErrorVolumeNotSisEnabled                                 4500
#define kNtErrorSystemIntegrityRollbackDetected                     4550
#define kNtErrorSystemIntegrityPolicyViolation                      4551
#define kNtErrorSystemIntegrityInvalidPolicy                        4552
#define kNtErrorSystemIntegrityPolicyNotSigned                      4553
#define kNtErrorVsmNotInitialized                                   4560
#define kNtErrorVsmDmaProtectionNotInUse                            4561
#define kNtErrorPlatformManifestNotAuthorized                       4570
#define kNtErrorPlatformManifestInvalid                             4571
#define kNtErrorPlatformManifestFileNotAuthorized                   4572
#define kNtErrorPlatformManifestCatalogNotAuthorized                4573
#define kNtErrorPlatformManifestBinaryIdNotFound                    4574
#define kNtErrorPlatformManifestNotActive                           4575
#define kNtErrorPlatformManifestNotSigned                           4576
#define kNtErrorDependentResourceExists                             5001
#define kNtErrorDependencyNotFound                                  5002
#define kNtErrorDependencyAlreadyExists                             5003
#define kNtErrorResourceNotOnline                                   5004
#define kNtErrorHostNodeNotAvailable                                5005
#define kNtErrorResourceNotAvailable                                5006
#define kNtErrorResourceNotFound                                    5007
#define kNtErrorShutdownCluster                                     5008
#define kNtErrorCantEvictActiveNode                                 5009
#define kNtErrorObjectAlreadyExists                                 5010
#define kNtErrorObjectInList                                        5011
#define kNtErrorGroupNotAvailable                                   5012
#define kNtErrorGroupNotFound                                       5013
#define kNtErrorGroupNotOnline                                      5014
#define kNtErrorHostNodeNotResourceOwner                            5015
#define kNtErrorHostNodeNotGroupOwner                               5016
#define kNtErrorResmonCreateFailed                                  5017
#define kNtErrorResmonOnlineFailed                                  5018
#define kNtErrorResourceOnline                                      5019
#define kNtErrorQuorumResource                                      5020
#define kNtErrorNotQuorumCapable                                    5021
#define kNtErrorClusterShuttingDown                                 5022
#define kNtErrorInvalidState                                        5023
#define kNtErrorResourcePropertiesStored                            5024
#define kNtErrorNotQuorumClass                                      5025
#define kNtErrorCoreResource                                        5026
#define kNtErrorQuorumResourceOnlineFailed                          5027
#define kNtErrorQuorumlogOpenFailed                                 5028
#define kNtErrorClusterlogCorrupt                                   5029
#define kNtErrorClusterlogRecordExceedsMaxsize                      5030
#define kNtErrorClusterlogExceedsMaxsize                            5031
#define kNtErrorClusterlogChkpointNotFound                          5032
#define kNtErrorClusterlogNotEnoughSpace                            5033
#define kNtErrorQuorumOwnerAlive                                    5034
#define kNtErrorNetworkNotAvailable                                 5035
#define kNtErrorNodeNotAvailable                                    5036
#define kNtErrorAllNodesNotAvailable                                5037
#define kNtErrorResourceFailed                                      5038
#define kNtErrorClusterInvalidNode                                  5039
#define kNtErrorClusterNodeExists                                   5040
#define kNtErrorClusterJoinInProgress                               5041
#define kNtErrorClusterNodeNotFound                                 5042
#define kNtErrorClusterLocalNodeNotFound                            5043
#define kNtErrorClusterNetworkExists                                5044
#define kNtErrorClusterNetworkNotFound                              5045
#define kNtErrorClusterNetinterfaceExists                           5046
#define kNtErrorClusterNetinterfaceNotFound                         5047
#define kNtErrorClusterInvalidRequest                               5048
#define kNtErrorClusterInvalidNetworkProvider                       5049
#define kNtErrorClusterNodeDown                                     5050
#define kNtErrorClusterNodeUnreachable                              5051
#define kNtErrorClusterNodeNotMember                                5052
#define kNtErrorClusterJoinNotInProgress                            5053
#define kNtErrorClusterInvalidNetwork                               5054
#define kNtErrorClusterNodeUp                                       5056
#define kNtErrorClusterIpaddrInUse                                  5057
#define kNtErrorClusterNodeNotPaused                                5058
#define kNtErrorClusterNoSecurityContext                            5059
#define kNtErrorClusterNetworkNotInternal                           5060
#define kNtErrorClusterNodeAlreadyUp                                5061
#define kNtErrorClusterNodeAlreadyDown                              5062
#define kNtErrorClusterNetworkAlreadyOnline                         5063
#define kNtErrorClusterNetworkAlreadyOffline                        5064
#define kNtErrorClusterNodeAlreadyMember                            5065
#define kNtErrorClusterLastInternalNetwork                          5066
#define kNtErrorClusterNetworkHasDependents                         5067
#define kNtErrorInvalidOperationOnQuorum                            5068
#define kNtErrorDependencyNotAllowed                                5069
#define kNtErrorClusterNodePaused                                   5070
#define kNtErrorNodeCantHostResource                                5071
#define kNtErrorClusterNodeNotReady                                 5072
#define kNtErrorClusterNodeShuttingDown                             5073
#define kNtErrorClusterJoinAborted                                  5074
#define kNtErrorClusterIncompatibleVersions                         5075
#define kNtErrorClusterMaxnumOfResourcesExceeded                    5076
#define kNtErrorClusterSystemConfigChanged                          5077
#define kNtErrorClusterResourceTypeNotFound                         5078
#define kNtErrorClusterRestypeNotSupported                          5079
#define kNtErrorClusterResnameNotFound                              5080
#define kNtErrorClusterNoRpcPackagesRegistered                      5081
#define kNtErrorClusterOwnerNotInPreflist                           5082
#define kNtErrorClusterDatabaseSeqmismatch                          5083
#define kNtErrorResmonInvalidState                                  5084
#define kNtErrorClusterGumNotLocker                                 5085
#define kNtErrorQuorumDiskNotFound                                  5086
#define kNtErrorDatabaseBackupCorrupt                               5087
#define kNtErrorClusterNodeAlreadyHasDfsRoot                        5088
#define kNtErrorResourcePropertyUnchangeable                        5089
#define kNtErrorNoAdminAccessPoint                                  5090
#define kNtErrorClusterMembershipInvalidState                       5890
#define kNtErrorClusterQuorumlogNotFound                            5891
#define kNtErrorClusterMembershipHalt                               5892
#define kNtErrorClusterInstanceIdMismatch                           5893
#define kNtErrorClusterNetworkNotFoundForIp                         5894
#define kNtErrorClusterPropertyDataTypeMismatch                     5895
#define kNtErrorClusterEvictWithoutCleanup                          5896
#define kNtErrorClusterParameterMismatch                            5897
#define kNtErrorNodeCannotBeClustered                               5898
#define kNtErrorClusterWrongOsVersion                               5899
#define kNtErrorClusterCantCreateDupClusterName                     5900
#define kNtErrorCluscfgAlreadyCommitted                             5901
#define kNtErrorCluscfgRollbackFailed                               5902
#define kNtErrorCluscfgSystemDiskDriveLetterConflict                5903
#define kNtErrorClusterOldVersion                                   5904
#define kNtErrorClusterMismatchedComputerAcctName                   5905
#define kNtErrorClusterNoNetAdapters                                5906
#define kNtErrorClusterPoisoned                                     5907
#define kNtErrorClusterGroupMoving                                  5908
#define kNtErrorClusterResourceTypeBusy                             5909
#define kNtErrorResourceCallTimedOut                                5910
#define kNtErrorInvalidClusterIpv6Address                           5911
#define kNtErrorClusterInternalInvalidFunction                      5912
#define kNtErrorClusterParameterOutOfBounds                         5913
#define kNtErrorClusterPartialSend                                  5914
#define kNtErrorClusterRegistryInvalidFunction                      5915
#define kNtErrorClusterInvalidStringTermination                     5916
#define kNtErrorClusterInvalidStringFormat                          5917
#define kNtErrorClusterDatabaseTransactionInProgress                5918
#define kNtErrorClusterDatabaseTransactionNotInProgress             5919
#define kNtErrorClusterNullData                                     5920
#define kNtErrorClusterPartialRead                                  5921
#define kNtErrorClusterPartialWrite                                 5922
#define kNtErrorClusterCantDeserializeData                          5923
#define kNtErrorDependentResourcePropertyConflict                   5924
#define kNtErrorClusterNoQuorum                                     5925
#define kNtErrorClusterInvalidIpv6Network                           5926
#define kNtErrorClusterInvalidIpv6TunnelNetwork                     5927
#define kNtErrorQuorumNotAllowedInThisGroup                         5928
#define kNtErrorDependencyTreeTooComplex                            5929
#define kNtErrorExceptionInResourceCall                             5930
#define kNtErrorClusterRhsFailedInitialization                      5931
#define kNtErrorClusterNotInstalled                                 5932
#define kNtErrorClusterResourcesMustBeOnlineOnTheSameNode           5933
#define kNtErrorClusterMaxNodesInCluster                            5934
#define kNtErrorClusterTooManyNodes                                 5935
#define kNtErrorClusterObjectAlreadyUsed                            5936
#define kNtErrorNoncoreGroupsFound                                  5937
#define kNtErrorFileShareResourceConflict                           5938
#define kNtErrorClusterEvictInvalidRequest                          5939
#define kNtErrorClusterSingletonResource                            5940
#define kNtErrorClusterGroupSingletonResource                       5941
#define kNtErrorClusterResourceProviderFailed                       5942
#define kNtErrorClusterResourceConfigurationError                   5943
#define kNtErrorClusterGroupBusy                                    5944
#define kNtErrorClusterNotSharedVolume                              5945
#define kNtErrorClusterInvalidSecurityDescriptor                    5946
#define kNtErrorClusterSharedVolumesInUse                           5947
#define kNtErrorClusterUseSharedVolumesApi                          5948
#define kNtErrorClusterBackupInProgress                             5949
#define kNtErrorNonCsvPath                                          5950
#define kNtErrorCsvVolumeNotLocal                                   5951
#define kNtErrorClusterWatchdogTerminating                          5952
#define kNtErrorClusterResourceVetoedMoveIncompatibleNodes          5953
#define kNtErrorClusterInvalidNodeWeight                            5954
#define kNtErrorClusterResourceVetoedCall                           5955
#define kNtErrorResmonSystemResourcesLacking                        5956
#define kNtErrorClusterResourceVetoedMoveNotEnoughResourcesOnSource 5958
#define kNtErrorClusterGroupQueued                                  5959
#define kNtErrorClusterResourceLockedStatus                         5960
#define kNtErrorClusterSharedVolumeFailoverNotAllowed               5961
#define kNtErrorClusterNodeDrainInProgress                          5962
#define kNtErrorClusterDiskNotConnected                             5963
#define kNtErrorDiskNotCsvCapable                                   5964
#define kNtErrorResourceNotInAvailableStorage                       5965
#define kNtErrorClusterSharedVolumeRedirected                       5966
#define kNtErrorClusterSharedVolumeNotRedirected                    5967
#define kNtErrorClusterCannotReturnProperties                       5968
#define kNtErrorClusterResourceIsInMaintenanceMode                  5970
#define kNtErrorClusterAffinityConflict                             5971
#define kNtErrorClusterResourceIsReplicaVirtualMachine              5972
#define kNtErrorClusterUpgradeIncompatibleVersions                  5973
#define kNtErrorClusterUpgradeFixQuorumNotSupported                 5974
#define kNtErrorClusterUpgradeRestartRequired                       5975
#define kNtErrorClusterUpgradeInProgress                            5976
#define kNtErrorClusterUpgradeIncomplete                            5977
#define kNtErrorClusterNodeInGracePeriod                            5978
#define kNtErrorClusterCsvIoPauseTimeout                            5979
#define kNtErrorNodeNotActiveClusterMember                          5980
#define kNtErrorClusterResourceNotMonitored                         5981
#define kNtErrorClusterResourceDoesNotSupportUnmonitored            5982
#define kNtErrorClusterResourceIsReplicated                         5983
#define kNtErrorClusterNodeIsolated                                 5984
#define kNtErrorClusterNodeQuarantined                              5985
#define kNtErrorClusterDatabaseUpdateConditionFailed                5986
#define kNtErrorClusterSpaceDegraded                                5987
#define kNtErrorClusterTokenDelegationNotSupported                  5988
#define kNtErrorClusterCsvInvalidHandle                             5989
#define kNtErrorClusterCsvSupportedOnlyOnCoordinator                5990
#define kNtErrorGroupsetNotAvailable                                5991
#define kNtErrorGroupsetNotFound                                    5992
#define kNtErrorGroupsetCantProvide                                 5993
#define kNtErrorClusterFaultDomainParentNotFound                    5994
#define kNtErrorClusterFaultDomainInvalidHierarchy                  5995
#define kNtErrorClusterFaultDomainFailedS2dValidation               5996
#define kNtErrorClusterFaultDomainS2dConnectivityLoss               5997
#define kNtErrorClusterInvalidInfrastructureFileserverName          5998
#define kNtErrorClustersetManagementClusterUnreachable              5999
#define kNtErrorEncryptionFailed                                    6000
#define kNtErrorDecryptionFailed                                    6001
#define kNtErrorFileEncrypted                                       6002
#define kNtErrorNoRecoveryPolicy                                    6003
#define kNtErrorNoEfs                                               6004
#define kNtErrorWrongEfs                                            6005
#define kNtErrorNoUserKeys                                          6006
#define kNtErrorFileNotEncrypted                                    6007
#define kNtErrorNotExportFormat                                     6008
#define kNtErrorFileReadOnly                                        6009 /* EROFS */
#define kNtErrorDirEfsDisallowed                                    6010
#define kNtErrorEfsServerNotTrusted                                 6011
#define kNtErrorBadRecoveryPolicy                                   6012
#define kNtErrorEfsAlgBlobTooBig                                    6013
#define kNtErrorVolumeNotSupportEfs                                 6014
#define kNtErrorEfsDisabled                                         6015
#define kNtErrorEfsVersionNotSupport                                6016
#define kNtErrorCsEncryptionInvalidServerResponse                   6017
#define kNtErrorCsEncryptionUnsupportedServer                       6018
#define kNtErrorCsEncryptionExistingEncryptedFile                   6019
#define kNtErrorCsEncryptionNewEncryptedFile                        6020
#define kNtErrorCsEncryptionFileNotCse                              6021
#define kNtErrorEncryptionPolicyDeniesOperation                     6022
#define kNtErrorNoBrowserServersFound                               6118
#define kNtErrorLogSectorInvalid                                    6600
#define kNtErrorLogSectorParityInvalid                              6601
#define kNtErrorLogSectorRemapped                                   6602
#define kNtErrorLogBlockIncomplete                                  6603
#define kNtErrorLogInvalidRange                                     6604 /* ERANGE */
#define kNtErrorLogBlocksExhausted                                  6605
#define kNtErrorLogReadContextInvalid                               6606
#define kNtErrorLogRestartInvalid                                   6607
#define kNtErrorLogBlockVersion                                     6608
#define kNtErrorLogBlockInvalid                                     6609
#define kNtErrorLogReadModeInvalid                                  6610
#define kNtErrorLogNoRestart                                        6611
#define kNtErrorLogMetadataCorrupt                                  6612
#define kNtErrorLogMetadataInvalid                                  6613
#define kNtErrorLogMetadataInconsistent                             6614
#define kNtErrorLogReservationInvalid                               6615
#define kNtErrorLogCantDelete                                       6616
#define kNtErrorLogContainerLimitExceeded                           6617
#define kNtErrorLogStartOfLog                                       6618
#define kNtErrorLogPolicyAlreadyInstalled                           6619
#define kNtErrorLogPolicyNotInstalled                               6620
#define kNtErrorLogPolicyInvalid                                    6621
#define kNtErrorLogPolicyConflict                                   6622
#define kNtErrorLogPinnedArchiveTail                                6623
#define kNtErrorLogRecordNonexistent                                6624
#define kNtErrorLogRecordsReservedInvalid                           6625
#define kNtErrorLogSpaceReservedInvalid                             6626
#define kNtErrorLogTailInvalid                                      6627
#define kNtErrorLogFull                                             6628
#define kNtErrorCouldNotResizeLog                                   6629
#define kNtErrorLogMultiplexed                                      6630
#define kNtErrorLogDedicated                                        6631
#define kNtErrorLogArchiveNotInProgress                             6632
#define kNtErrorLogArchiveInProgress                                6633
#define kNtErrorLogEphemeral                                        6634
#define kNtErrorLogNotEnoughContainers                              6635
#define kNtErrorLogClientAlreadyRegistered                          6636
#define kNtErrorLogClientNotRegistered                              6637
#define kNtErrorLogFullHandlerInProgress                            6638
#define kNtErrorLogContainerReadFailed                              6639
#define kNtErrorLogContainerWriteFailed                             6640
#define kNtErrorLogContainerOpenFailed                              6641
#define kNtErrorLogContainerStateInvalid                            6642
#define kNtErrorLogStateInvalid                                     6643
#define kNtErrorLogPinned                                           6644
#define kNtErrorLogMetadataFlushFailed                              6645
#define kNtErrorLogInconsistentSecurity                             6646
#define kNtErrorLogAppendedFlushFailed                              6647
#define kNtErrorLogPinnedReservation                                6648
#define kNtErrorInvalidTransaction                                  6700
#define kNtErrorTransactionNotActive                                6701
#define kNtErrorTransactionRequestNotValid                          6702
#define kNtErrorTransactionNotRequested                             6703
#define kNtErrorTransactionAlreadyAborted                           6704
#define kNtErrorTransactionAlreadyCommitted                         6705
#define kNtErrorTmInitializationFailed                              6706
#define kNtErrorResourcemanagerReadOnly                             6707
#define kNtErrorTransactionNotJoined                                6708
#define kNtErrorTransactionSuperiorExists                           6709
#define kNtErrorCrmProtocolAlreadyExists                            6710
#define kNtErrorTransactionPropagationFailed                        6711
#define kNtErrorCrmProtocolNotFound                                 6712
#define kNtErrorTransactionInvalidMarshallBuffer                    6713
#define kNtErrorCurrentTransactionNotValid                          6714
#define kNtErrorTransactionNotFound                                 6715
#define kNtErrorResourcemanagerNotFound                             6716
#define kNtErrorEnlistmentNotFound                                  6717
#define kNtErrorTransactionmanagerNotFound                          6718
#define kNtErrorTransactionmanagerNotOnline                         6719
#define kNtErrorTransactionmanagerRecoveryNameCollision             6720
#define kNtErrorTransactionNotRoot                                  6721
#define kNtErrorTransactionObjectExpired                            6722
#define kNtErrorTransactionResponseNotEnlisted                      6723
#define kNtErrorTransactionRecordTooLong                            6724
#define kNtErrorImplicitTransactionNotSupported                     6725
#define kNtErrorTransactionIntegrityViolated                        6726
#define kNtErrorTransactionmanagerIdentityMismatch                  6727
#define kNtErrorRmCannotBeFrozenForSnapshot                         6728
#define kNtErrorTransactionMustWritethrough                         6729
#define kNtErrorTransactionNoSuperior                               6730
#define kNtErrorHeuristicDamagePossible                             6731
#define kNtErrorTransactionalConflict                               6800
#define kNtErrorRmNotActive                                         6801
#define kNtErrorRmMetadataCorrupt                                   6802
#define kNtErrorDirectoryNotRm                                      6803
#define kNtErrorTransactionsUnsupportedRemote                       6805
#define kNtErrorLogResizeInvalidSize                                6806
#define kNtErrorObjectNoLongerExists                                6807
#define kNtErrorStreamMiniversionNotFound                           6808
#define kNtErrorStreamMiniversionNotValid                           6809
#define kNtErrorMiniversionInaccessibleFromSpecifiedTransaction     6810
#define kNtErrorCantOpenMiniversionWithModifyIntent                 6811
#define kNtErrorCantCreateMoreStreamMiniversions                    6812
#define kNtErrorRemoteFileVersionMismatch                           6814
#define kNtErrorHandleNoLongerValid                                 6815
#define kNtErrorNoTxfMetadata                                       6816
#define kNtErrorLogCorruptionDetected                               6817
#define kNtErrorCantRecoverWithHandleOpen                           6818
#define kNtErrorRmDisconnected                                      6819
#define kNtErrorEnlistmentNotSuperior                               6820
#define kNtErrorRecoveryNotNeeded                                   6821
#define kNtErrorRmAlreadyStarted                                    6822
#define kNtErrorFileIdentityNotPersistent                           6823
#define kNtErrorCantBreakTransactionalDependency                    6824
#define kNtErrorCantCrossRmBoundary                                 6825
#define kNtErrorTxfDirNotEmpty                                      6826
#define kNtErrorIndoubtTransactionsExist                            6827
#define kNtErrorTmVolatile                                          6828
#define kNtErrorRollbackTimerExpired                                6829
#define kNtErrorTxfAttributeCorrupt                                 6830
#define kNtErrorEfsNotAllowedInTransaction                          6831
#define kNtErrorTransactionalOpenNotAllowed                         6832
#define kNtErrorLogGrowthFailed                                     6833
#define kNtErrorTransactedMappingUnsupportedRemote                  6834
#define kNtErrorTxfMetadataAlreadyPresent                           6835
#define kNtErrorTransactionScopeCallbacksNotSet                     6836
#define kNtErrorTransactionRequiredPromotion                        6837
#define kNtErrorCannotExecuteFileInTransaction                      6838
#define kNtErrorTransactionsNotFrozen                               6839
#define kNtErrorTransactionFreezeInProgress                         6840
#define kNtErrorNotSnapshotVolume                                   6841
#define kNtErrorNoSavepointWithOpenFiles                            6842
#define kNtErrorDataLostRepair                                      6843
#define kNtErrorSparseNotAllowedInTransaction                       6844
#define kNtErrorTmIdentityMismatch                                  6845
#define kNtErrorFloatedSection                                      6846
#define kNtErrorCannotAcceptTransactedWork                          6847
#define kNtErrorCannotAbortTransactions                             6848
#define kNtErrorBadClusters                                         6849
#define kNtErrorCompressionNotAllowedInTransaction                  6850
#define kNtErrorVolumeDirty                                         6851
#define kNtErrorNoLinkTrackingInTransaction                         6852
#define kNtErrorOperationNotSupportedInTransaction                  6853
#define kNtErrorExpiredHandle                                       6854
#define kNtErrorTransactionNotEnlisted                              6855
#define kNtErrorCtxWinstationNameInvalid                            7001
#define kNtErrorCtxInvalidPd                                        7002
#define kNtErrorCtxPdNotFound                                       7003
#define kNtErrorCtxWdNotFound                                       7004
#define kNtErrorCtxCannotMakeEventlogEntry                          7005
#define kNtErrorCtxServiceNameCollision                             7006
#define kNtErrorCtxClosePending                                     7007
#define kNtErrorCtxNoOutbuf                                         7008
#define kNtErrorCtxModemInfNotFound                                 7009
#define kNtErrorCtxInvalidModemname                                 7010
#define kNtErrorCtxModemResponseError                               7011
#define kNtErrorCtxModemResponseTimeout                             7012
#define kNtErrorCtxModemResponseNoCarrier                           7013
#define kNtErrorCtxModemResponseNoDialtone                          7014
#define kNtErrorCtxModemResponseBusy                                7015
#define kNtErrorCtxModemResponseVoice                               7016
#define kNtErrorCtxTdError                                          7017
#define kNtErrorCtxWinstationNotFound                               7022
#define kNtErrorCtxWinstationAlreadyExists                          7023
#define kNtErrorCtxWinstationBusy                                   7024
#define kNtErrorCtxBadVideoMode                                     7025
#define kNtErrorCtxGraphicsInvalid                                  7035
#define kNtErrorCtxLogonDisabled                                    7037
#define kNtErrorCtxNotConsole                                       7038
#define kNtErrorCtxClientQueryTimeout                               7040
#define kNtErrorCtxConsoleDisconnect                                7041
#define kNtErrorCtxConsoleConnect                                   7042
#define kNtErrorCtxShadowDenied                                     7044
#define kNtErrorCtxWinstationAccessDenied                           7045
#define kNtErrorCtxInvalidWd                                        7049
#define kNtErrorCtxShadowInvalid                                    7050
#define kNtErrorCtxShadowDisabled                                   7051
#define kNtErrorCtxClientLicenseInUse                               7052
#define kNtErrorCtxClientLicenseNotSet                              7053
#define kNtErrorCtxLicenseNotAvailable                              7054
#define kNtErrorCtxLicenseClientInvalid                             7055
#define kNtErrorCtxLicenseExpired                                   7056
#define kNtErrorCtxShadowNotRunning                                 7057
#define kNtErrorCtxShadowEndedByModeChange                          7058
#define kNtErrorActivationCountExceeded                             7059
#define kNtErrorCtxWinstationsDisabled                              7060
#define kNtErrorCtxEncryptionLevelRequired                          7061
#define kNtErrorCtxSessionInUse                                     7062
#define kNtErrorCtxNoForceLogoff                                    7063
#define kNtErrorCtxAccountRestriction                               7064
#define kNtErrorRdpProtocolError                                    7065 /* EPROTO */
#define kNtErrorCtxCdmConnect                                       7066
#define kNtErrorCtxCdmDisconnect                                    7067
#define kNtErrorCtxSecurityLayerError                               7068
#define kNtErrorTsIncompatibleSessions                              7069
#define kNtErrorTsVideoSubsystemError                               7070
#define kNtErrorDsNotInstalled                                      8200
#define kNtErrorDsMembershipEvaluatedLocally                        8201
#define kNtErrorDsNoAttributeOrValue                                8202
#define kNtErrorDsInvalidAttributeSyntax                            8203
#define kNtErrorDsAttributeTypeUndefined                            8204
#define kNtErrorDsAttributeOrValueExists                            8205
#define kNtErrorDsBusy                                              8206
#define kNtErrorDsUnavailable                                       8207
#define kNtErrorDsNoRidsAllocated                                   8208
#define kNtErrorDsNoMoreRids                                        8209
#define kNtErrorDsIncorrectRoleOwner                                8210
#define kNtErrorDsRidmgrInitError                                   8211
#define kNtErrorDsObjClassViolation                                 8212
#define kNtErrorDsCantOnNonLeaf                                     8213
#define kNtErrorDsCantOnRdn                                         8214
#define kNtErrorDsCantModObjClass                                   8215
#define kNtErrorDsCrossDomMoveError                                 8216
#define kNtErrorDsGcNotAvailable                                    8217
#define kNtErrorSharedPolicy                                        8218
#define kNtErrorPolicyObjectNotFound                                8219
#define kNtErrorPolicyOnlyInDs                                      8220
#define kNtErrorPromotionActive                                     8221
#define kNtErrorNoPromotionActive                                   8222
#define kNtErrorDsOperationsError                                   8224
#define kNtErrorDsProtocolError                                     8225
#define kNtErrorDsTimelimitExceeded                                 8226
#define kNtErrorDsSizelimitExceeded                                 8227
#define kNtErrorDsAdminLimitExceeded                                8228
#define kNtErrorDsCompareFalse                                      8229
#define kNtErrorDsCompareTrue                                       8230
#define kNtErrorDsAuthMethodNotSupported                            8231
#define kNtErrorDsStrongAuthRequired                                8232
#define kNtErrorDsInappropriateAuth                                 8233
#define kNtErrorDsAuthUnknown                                       8234
#define kNtErrorDsReferral                                          8235
#define kNtErrorDsUnavailableCritExtension                          8236
#define kNtErrorDsConfidentialityRequired                           8237
#define kNtErrorDsInappropriateMatching                             8238
#define kNtErrorDsConstraintViolation                               8239
#define kNtErrorDsNoSuchObject                                      8240
#define kNtErrorDsAliasProblem                                      8241
#define kNtErrorDsInvalidDnSyntax                                   8242
#define kNtErrorDsIsLeaf                                            8243
#define kNtErrorDsAliasDerefProblem                                 8244
#define kNtErrorDsUnwillingToPerform                                8245
#define kNtErrorDsLoopDetect                                        8246
#define kNtErrorDsNamingViolation                                   8247
#define kNtErrorDsObjectResultsTooLarge                             8248
#define kNtErrorDsAffectsMultipleDsas                               8249
#define kNtErrorDsServerDown                                        8250
#define kNtErrorDsLocalError                                        8251
#define kNtErrorDsEncodingError                                     8252
#define kNtErrorDsDecodingError                                     8253
#define kNtErrorDsFilterUnknown                                     8254
#define kNtErrorDsParamError                                        8255
#define kNtErrorDsNotSupported                                      8256
#define kNtErrorDsNoResultsReturned                                 8257
#define kNtErrorDsControlNotFound                                   8258
#define kNtErrorDsClientLoop                                        8259
#define kNtErrorDsReferralLimitExceeded                             8260
#define kNtErrorDsSortControlMissing                                8261
#define kNtErrorDsOffsetRangeError                                  8262
#define kNtErrorDsRidmgrDisabled                                    8263
#define kNtErrorDsRootMustBeNc                                      8301
#define kNtErrorDsAddReplicaInhibited                               8302
#define kNtErrorDsAttNotDefInSchema                                 8303
#define kNtErrorDsMaxObjSizeExceeded                                8304
#define kNtErrorDsObjStringNameExists                               8305
#define kNtErrorDsNoRdnDefinedInSchema                              8306
#define kNtErrorDsRdnDoesntMatchSchema                              8307
#define kNtErrorDsNoRequestedAttsFound                              8308
#define kNtErrorDsUserBufferToSmall                                 8309
#define kNtErrorDsAttIsNotOnObj                                     8310
#define kNtErrorDsIllegalModOperation                               8311
#define kNtErrorDsObjTooLarge                                       8312
#define kNtErrorDsBadInstanceType                                   8313
#define kNtErrorDsMasterdsaRequired                                 8314
#define kNtErrorDsObjectClassRequired                               8315
#define kNtErrorDsMissingRequiredAtt                                8316
#define kNtErrorDsAttNotDefForClass                                 8317
#define kNtErrorDsAttAlreadyExists                                  8318
#define kNtErrorDsCantAddAttValues                                  8320
#define kNtErrorDsSingleValueConstraint                             8321
#define kNtErrorDsRangeConstraint                                   8322
#define kNtErrorDsAttValAlreadyExists                               8323
#define kNtErrorDsCantRemMissingAtt                                 8324
#define kNtErrorDsCantRemMissingAttVal                              8325
#define kNtErrorDsRootCantBeSubref                                  8326
#define kNtErrorDsNoChaining                                        8327
#define kNtErrorDsNoChainedEval                                     8328
#define kNtErrorDsNoParentObject                                    8329
#define kNtErrorDsParentIsAnAlias                                   8330
#define kNtErrorDsCantMixMasterAndReps                              8331
#define kNtErrorDsChildrenExist                                     8332
#define kNtErrorDsObjNotFound                                       8333
#define kNtErrorDsAliasedObjMissing                                 8334
#define kNtErrorDsBadNameSyntax                                     8335
#define kNtErrorDsAliasPointsToAlias                                8336
#define kNtErrorDsCantDerefAlias                                    8337
#define kNtErrorDsOutOfScope                                        8338
#define kNtErrorDsObjectBeingRemoved                                8339
#define kNtErrorDsCantDeleteDsaObj                                  8340
#define kNtErrorDsGenericError                                      8341
#define kNtErrorDsDsaMustBeIntMaster                                8342
#define kNtErrorDsClassNotDsa                                       8343
#define kNtErrorDsInsuffAccessRights                                8344
#define kNtErrorDsIllegalSuperior                                   8345
#define kNtErrorDsAttributeOwnedBySam                               8346
#define kNtErrorDsNameTooManyParts                                  8347
#define kNtErrorDsNameTooLong                                       8348
#define kNtErrorDsNameValueTooLong                                  8349
#define kNtErrorDsNameUnparseable                                   8350
#define kNtErrorDsNameTypeUnknown                                   8351
#define kNtErrorDsNotAnObject                                       8352
#define kNtErrorDsSecDescTooShort                                   8353
#define kNtErrorDsSecDescInvalid                                    8354
#define kNtErrorDsNoDeletedName                                     8355
#define kNtErrorDsSubrefMustHaveParent                              8356
#define kNtErrorDsNcnameMustBeNc                                    8357
#define kNtErrorDsCantAddSystemOnly                                 8358
#define kNtErrorDsClassMustBeConcrete                               8359
#define kNtErrorDsInvalidDmd                                        8360
#define kNtErrorDsObjGuidExists                                     8361
#define kNtErrorDsNotOnBacklink                                     8362
#define kNtErrorDsNoCrossrefForNc                                   8363
#define kNtErrorDsShuttingDown                                      8364
#define kNtErrorDsUnknownOperation                                  8365
#define kNtErrorDsInvalidRoleOwner                                  8366
#define kNtErrorDsCouldntContactFsmo                                8367
#define kNtErrorDsCrossNcDnRename                                   8368
#define kNtErrorDsCantModSystemOnly                                 8369
#define kNtErrorDsReplicatorOnly                                    8370
#define kNtErrorDsObjClassNotDefined                                8371
#define kNtErrorDsObjClassNotSubclass                               8372
#define kNtErrorDsNameReferenceInvalid                              8373
#define kNtErrorDsCrossRefExists                                    8374
#define kNtErrorDsCantDelMasterCrossref                             8375
#define kNtErrorDsSubtreeNotifyNotNcHead                            8376
#define kNtErrorDsNotifyFilterTooComplex                            8377
#define kNtErrorDsDupRdn                                            8378
#define kNtErrorDsDupOid                                            8379
#define kNtErrorDsDupMapiId                                         8380
#define kNtErrorDsDupSchemaIdGuid                                   8381
#define kNtErrorDsDupLdapDisplayName                                8382
#define kNtErrorDsSemanticAttTest                                   8383
#define kNtErrorDsSyntaxMismatch                                    8384
#define kNtErrorDsExistsInMustHave                                  8385
#define kNtErrorDsExistsInMayHave                                   8386
#define kNtErrorDsNonexistentMayHave                                8387
#define kNtErrorDsNonexistentMustHave                               8388
#define kNtErrorDsAuxClsTestFail                                    8389
#define kNtErrorDsNonexistentPossSup                                8390
#define kNtErrorDsSubClsTestFail                                    8391
#define kNtErrorDsBadRdnAttIdSyntax                                 8392
#define kNtErrorDsExistsInAuxCls                                    8393
#define kNtErrorDsExistsInSubCls                                    8394
#define kNtErrorDsExistsInPossSup                                   8395
#define kNtErrorDsRecalcschemaFailed                                8396
#define kNtErrorDsTreeDeleteNotFinished                             8397
#define kNtErrorDsCantDelete                                        8398
#define kNtErrorDsAttSchemaReqId                                    8399
#define kNtErrorDsBadAttSchemaSyntax                                8400
#define kNtErrorDsCantCacheAtt                                      8401
#define kNtErrorDsCantCacheClass                                    8402
#define kNtErrorDsCantRemoveAttCache                                8403
#define kNtErrorDsCantRemoveClassCache                              8404
#define kNtErrorDsCantRetrieveDn                                    8405
#define kNtErrorDsMissingSupref                                     8406
#define kNtErrorDsCantRetrieveInstance                              8407
#define kNtErrorDsCodeInconsistency                                 8408
#define kNtErrorDsDatabaseError                                     8409
#define kNtErrorDsGovernsidMissing                                  8410
#define kNtErrorDsMissingExpectedAtt                                8411
#define kNtErrorDsNcnameMissingCrRef                                8412
#define kNtErrorDsSecurityCheckingError                             8413
#define kNtErrorDsSchemaNotLoaded                                   8414
#define kNtErrorDsSchemaAllocFailed                                 8415
#define kNtErrorDsAttSchemaReqSyntax                                8416
#define kNtErrorDsGcverifyError                                     8417
#define kNtErrorDsDraSchemaMismatch                                 8418
#define kNtErrorDsCantFindDsaObj                                    8419
#define kNtErrorDsCantFindExpectedNc                                8420
#define kNtErrorDsCantFindNcInCache                                 8421
#define kNtErrorDsCantRetrieveChild                                 8422
#define kNtErrorDsSecurityIllegalModify                             8423
#define kNtErrorDsCantReplaceHiddenRec                              8424
#define kNtErrorDsBadHierarchyFile                                  8425
#define kNtErrorDsBuildHierarchyTableFailed                         8426
#define kNtErrorDsConfigParamMissing                                8427
#define kNtErrorDsCountingAbIndicesFailed                           8428
#define kNtErrorDsHierarchyTableMallocFailed                        8429
#define kNtErrorDsInternalFailure                                   8430
#define kNtErrorDsUnknownError                                      8431
#define kNtErrorDsRootRequiresClassTop                              8432
#define kNtErrorDsRefusingFsmoRoles                                 8433
#define kNtErrorDsMissingFsmoSettings                               8434
#define kNtErrorDsUnableToSurrenderRoles                            8435
#define kNtErrorDsDraGeneric                                        8436
#define kNtErrorDsDraInvalidParameter                               8437
#define kNtErrorDsDraBusy                                           8438
#define kNtErrorDsDraBadDn                                          8439
#define kNtErrorDsDraBadNc                                          8440
#define kNtErrorDsDraDnExists                                       8441
#define kNtErrorDsDraInternalError                                  8442
#define kNtErrorDsDraInconsistentDit                                8443
#define kNtErrorDsDraConnectionFailed                               8444
#define kNtErrorDsDraBadInstanceType                                8445
#define kNtErrorDsDraOutOfMem                                       8446
#define kNtErrorDsDraMailProblem                                    8447
#define kNtErrorDsDraRefAlreadyExists                               8448
#define kNtErrorDsDraRefNotFound                                    8449
#define kNtErrorDsDraObjIsRepSource                                 8450
#define kNtErrorDsDraDbError                                        8451
#define kNtErrorDsDraNoReplica                                      8452
#define kNtErrorDsDraAccessDenied                                   8453
#define kNtErrorDsDraNotSupported                                   8454
#define kNtErrorDsDraRpcCancelled                                   8455
#define kNtErrorDsDraSourceDisabled                                 8456
#define kNtErrorDsDraSinkDisabled                                   8457
#define kNtErrorDsDraNameCollision                                  8458
#define kNtErrorDsDraSourceReinstalled                              8459
#define kNtErrorDsDraMissingParent                                  8460
#define kNtErrorDsDraPreempted                                      8461
#define kNtErrorDsDraAbandonSync                                    8462
#define kNtErrorDsDraShutdown                                       8463
#define kNtErrorDsDraIncompatiblePartialSet                         8464
#define kNtErrorDsDraSourceIsPartialReplica                         8465
#define kNtErrorDsDraExtnConnectionFailed                           8466
#define kNtErrorDsInstallSchemaMismatch                             8467
#define kNtErrorDsDupLinkId                                         8468
#define kNtErrorDsNameErrorResolving                                8469
#define kNtErrorDsNameErrorNotFound                                 8470
#define kNtErrorDsNameErrorNotUnique                                8471
#define kNtErrorDsNameErrorNoMapping                                8472
#define kNtErrorDsNameErrorDomainOnly                               8473
#define kNtErrorDsNameErrorNoSyntacticalMapping                     8474
#define kNtErrorDsConstructedAttMod                                 8475
#define kNtErrorDsWrongOmObjClass                                   8476
#define kNtErrorDsDraReplPending                                    8477
#define kNtErrorDsDsRequired                                        8478
#define kNtErrorDsInvalidLdapDisplayName                            8479
#define kNtErrorDsNonBaseSearch                                     8480
#define kNtErrorDsCantRetrieveAtts                                  8481
#define kNtErrorDsBacklinkWithoutLink                               8482
#define kNtErrorDsEpochMismatch                                     8483
#define kNtErrorDsSrcNameMismatch                                   8484
#define kNtErrorDsSrcAndDstNcIdentical                              8485
#define kNtErrorDsDstNcMismatch                                     8486
#define kNtErrorDsNotAuthoritiveForDstNc                            8487
#define kNtErrorDsSrcGuidMismatch                                   8488
#define kNtErrorDsCantMoveDeletedObject                             8489
#define kNtErrorDsPdcOperationInProgress                            8490
#define kNtErrorDsCrossDomainCleanupReqd                            8491
#define kNtErrorDsIllegalXdomMoveOperation                          8492
#define kNtErrorDsCantWithAcctGroupMembershps                       8493
#define kNtErrorDsNcMustHaveNcParent                                8494
#define kNtErrorDsCrImpossibleToValidate                            8495
#define kNtErrorDsDstDomainNotNative                                8496
#define kNtErrorDsMissingInfrastructureContainer                    8497
#define kNtErrorDsCantMoveAccountGroup                              8498
#define kNtErrorDsCantMoveResourceGroup                             8499
#define kNtErrorDsInvalidSearchFlag                                 8500
#define kNtErrorDsNoTreeDeleteAboveNc                               8501
#define kNtErrorDsCouldntLockTreeForDelete                          8502
#define kNtErrorDsCouldntIdentifyObjectsForTreeDelete               8503
#define kNtErrorDsSamInitFailure                                    8504
#define kNtErrorDsSensitiveGroupViolation                           8505
#define kNtErrorDsCantModPrimarygroupid                             8506
#define kNtErrorDsIllegalBaseSchemaMod                              8507
#define kNtErrorDsNonsafeSchemaChange                               8508
#define kNtErrorDsSchemaUpdateDisallowed                            8509
#define kNtErrorDsCantCreateUnderSchema                             8510
#define kNtErrorDsInstallNoSrcSchVersion                            8511
#define kNtErrorDsInstallNoSchVersionInInifile                      8512
#define kNtErrorDsInvalidGroupType                                  8513
#define kNtErrorDsNoNestGlobalgroupInMixeddomain                    8514
#define kNtErrorDsNoNestLocalgroupInMixeddomain                     8515
#define kNtErrorDsGlobalCantHaveLocalMember                         8516
#define kNtErrorDsGlobalCantHaveUniversalMember                     8517
#define kNtErrorDsUniversalCantHaveLocalMember                      8518
#define kNtErrorDsGlobalCantHaveCrossdomainMember                   8519
#define kNtErrorDsLocalCantHaveCrossdomainLocalMember               8520
#define kNtErrorDsHavePrimaryMembers                                8521
#define kNtErrorDsStringSdConversionFailed                          8522
#define kNtErrorDsNamingMasterGc                                    8523
#define kNtErrorDsDnsLookupFailure                                  8524
#define kNtErrorDsCouldntUpdateSpns                                 8525
#define kNtErrorDsCantRetrieveSd                                    8526
#define kNtErrorDsKeyNotUnique                                      8527
#define kNtErrorDsWrongLinkedAttSyntax                              8528
#define kNtErrorDsSamNeedBootkeyPassword                            8529
#define kNtErrorDsSamNeedBootkeyFloppy                              8530
#define kNtErrorDsCantStart                                         8531
#define kNtErrorDsInitFailure                                       8532
#define kNtErrorDsNoPktPrivacyOnConnection                          8533
#define kNtErrorDsSourceDomainInForest                              8534
#define kNtErrorDsDestinationDomainNotInForest                      8535
#define kNtErrorDsDestinationAuditingNotEnabled                     8536
#define kNtErrorDsCantFindDcForSrcDomain                            8537
#define kNtErrorDsSrcObjNotGroupOrUser                              8538
#define kNtErrorDsSrcSidExistsInForest                              8539
#define kNtErrorDsSrcAndDstObjectClassMismatch                      8540
#define kNtErrorSamInitFailure                                      8541
#define kNtErrorDsDraSchemaInfoShip                                 8542
#define kNtErrorDsDraSchemaConflict                                 8543
#define kNtErrorDsDraEarlierSchemaConflict                          8544
#define kNtErrorDsDraObjNcMismatch                                  8545
#define kNtErrorDsNcStillHasDsas                                    8546
#define kNtErrorDsGcRequired                                        8547
#define kNtErrorDsLocalMemberOfLocalOnly                            8548
#define kNtErrorDsNoFpoInUniversalGroups                            8549
#define kNtErrorDsCantAddToGc                                       8550
#define kNtErrorDsNoCheckpointWithPdc                               8551
#define kNtErrorDsSourceAuditingNotEnabled                          8552
#define kNtErrorDsCantCreateInNondomainNc                           8553
#define kNtErrorDsInvalidNameForSpn                                 8554
#define kNtErrorDsFilterUsesContructedAttrs                         8555
#define kNtErrorDsUnicodepwdNotInQuotes                             8556
#define kNtErrorDsMachineAccountQuotaExceeded                       8557
#define kNtErrorDsMustBeRunOnDstDc                                  8558
#define kNtErrorDsSrcDcMustBeSp4OrGreater                           8559
#define kNtErrorDsCantTreeDeleteCriticalObj                         8560
#define kNtErrorDsInitFailureConsole                                8561
#define kNtErrorDsSamInitFailureConsole                             8562
#define kNtErrorDsForestVersionTooHigh                              8563
#define kNtErrorDsDomainVersionTooHigh                              8564
#define kNtErrorDsForestVersionTooLow                               8565
#define kNtErrorDsDomainVersionTooLow                               8566
#define kNtErrorDsIncompatibleVersion                               8567
#define kNtErrorDsLowDsaVersion                                     8568
#define kNtErrorDsNoBehaviorVersionInMixeddomain                    8569
#define kNtErrorDsNotSupportedSortOrder                             8570
#define kNtErrorDsNameNotUnique                                     8571
#define kNtErrorDsMachineAccountCreatedPrent4                       8572
#define kNtErrorDsOutOfVersionStore                                 8573
#define kNtErrorDsIncompatibleControlsUsed                          8574
#define kNtErrorDsNoRefDomain                                       8575
#define kNtErrorDsReservedLinkId                                    8576
#define kNtErrorDsLinkIdNotAvailable                                8577
#define kNtErrorDsAgCantHaveUniversalMember                         8578
#define kNtErrorDsModifydnDisallowedByInstanceType                  8579
#define kNtErrorDsNoObjectMoveInSchemaNc                            8580
#define kNtErrorDsModifydnDisallowedByFlag                          8581
#define kNtErrorDsModifydnWrongGrandparent                          8582
#define kNtErrorDsNameErrorTrustReferral                            8583
#define kNtErrorNotSupportedOnStandardServer                        8584
#define kNtErrorDsCantAccessRemotePartOfAd                          8585
#define kNtErrorDsCrImpossibleToValidateV2                          8586
#define kNtErrorDsThreadLimitExceeded                               8587
#define kNtErrorDsNotClosest                                        8588
#define kNtErrorDsCantDeriveSpnWithoutServerRef                     8589
#define kNtErrorDsSingleUserModeFailed                              8590
#define kNtErrorDsNtdscriptSyntaxError                              8591
#define kNtErrorDsNtdscriptProcessError                             8592
#define kNtErrorDsDifferentReplEpochs                               8593
#define kNtErrorDsDrsExtensionsChanged                              8594
#define kNtErrorDsReplicaSetChangeNotAllowedOnDisabledCr            8595
#define kNtErrorDsNoMsdsIntid                                       8596
#define kNtErrorDsDupMsdsIntid                                      8597
#define kNtErrorDsExistsInRdnattid                                  8598
#define kNtErrorDsAuthorizationFailed                               8599
#define kNtErrorDsInvalidScript                                     8600
#define kNtErrorDsRemoteCrossrefOpFailed                            8601
#define kNtErrorDsCrossRefBusy                                      8602
#define kNtErrorDsCantDeriveSpnForDeletedDomain                     8603
#define kNtErrorDsCantDemoteWithWriteableNc                         8604
#define kNtErrorDsDuplicateIdFound                                  8605
#define kNtErrorDsInsufficientAttrToCreateObject                    8606
#define kNtErrorDsGroupConversionError                              8607
#define kNtErrorDsCantMoveAppBasicGroup                             8608
#define kNtErrorDsCantMoveAppQueryGroup                             8609
#define kNtErrorDsRoleNotVerified                                   8610
#define kNtErrorDsWkoContainerCannotBeSpecial                       8611
#define kNtErrorDsDomainRenameInProgress                            8612
#define kNtErrorDsExistingAdChildNc                                 8613
#define kNtErrorDsReplLifetimeExceeded                              8614
#define kNtErrorDsDisallowedInSystemContainer                       8615
#define kNtErrorDsLdapSendQueueFull                                 8616
#define kNtErrorDsDraOutScheduleWindow                              8617
#define kNtErrorDsPolicyNotKnown                                    8618
#define kNtErrorNoSiteSettingsObject                                8619
#define kNtErrorNoSecrets                                           8620
#define kNtErrorNoWritableDcFound                                   8621
#define kNtErrorDsNoServerObject                                    8622
#define kNtErrorDsNoNtdsaObject                                     8623
#define kNtErrorDsNonAsqSearch                                      8624
#define kNtErrorDsAuditFailure                                      8625
#define kNtErrorDsInvalidSearchFlagSubtree                          8626
#define kNtErrorDsInvalidSearchFlagTuple                            8627
#define kNtErrorDsHierarchyTableTooDeep                             8628
#define kNtErrorDsDraCorruptUtdVector                               8629
#define kNtErrorDsDraSecretsDenied                                  8630
#define kNtErrorDsReservedMapiId                                    8631
#define kNtErrorDsMapiIdNotAvailable                                8632
#define kNtErrorDsDraMissingKrbtgtSecret                            8633
#define kNtErrorDsDomainNameExistsInForest                          8634
#define kNtErrorDsFlatNameExistsInForest                            8635
#define kNtErrorInvalidUserPrincipalName                            8636
#define kNtErrorDsOidMappedGroupCantHaveMembers                     8637
#define kNtErrorDsOidNotFound                                       8638
#define kNtErrorDsDraRecycledTarget                                 8639
#define kNtErrorDsDisallowedNcRedirect                              8640
#define kNtErrorDsHighAdldsFfl                                      8641
#define kNtErrorDsHighDsaVersion                                    8642
#define kNtErrorDsLowAdldsFfl                                       8643
#define kNtErrorDomainSidSameAsLocalWorkstation                     8644
#define kNtErrorDsUndeleteSamValidationFailed                       8645
#define kNtErrorIncorrectAccountType                                8646
#define kNtErrorDsSpnValueNotUniqueInForest                         8647
#define kNtErrorDsUpnValueNotUniqueInForest                         8648
#define kNtErrorDsMissingForestTrust                                8649
#define kNtErrorDsValueKeyNotUnique                                 8650
#define kNtErrorIpsecQmPolicyExists                                 13000
#define kNtErrorIpsecQmPolicyNotFound                               13001
#define kNtErrorIpsecQmPolicyInUse                                  13002
#define kNtErrorIpsecMmPolicyExists                                 13003
#define kNtErrorIpsecMmPolicyNotFound                               13004
#define kNtErrorIpsecMmPolicyInUse                                  13005
#define kNtErrorIpsecMmFilterExists                                 13006
#define kNtErrorIpsecMmFilterNotFound                               13007
#define kNtErrorIpsecTransportFilterExists                          13008
#define kNtErrorIpsecTransportFilterNotFound                        13009
#define kNtErrorIpsecMmAuthExists                                   13010
#define kNtErrorIpsecMmAuthNotFound                                 13011
#define kNtErrorIpsecMmAuthInUse                                    13012
#define kNtErrorIpsecDefaultMmPolicyNotFound                        13013
#define kNtErrorIpsecDefaultMmAuthNotFound                          13014
#define kNtErrorIpsecDefaultQmPolicyNotFound                        13015
#define kNtErrorIpsecTunnelFilterExists                             13016
#define kNtErrorIpsecTunnelFilterNotFound                           13017
#define kNtErrorIpsecMmFilterPendingDeletion                        13018
#define kNtErrorIpsecTransportFilterPendingDeletion                 13019
#define kNtErrorIpsecTunnelFilterPendingDeletion                    13020
#define kNtErrorIpsecMmPolicyPendingDeletion                        13021
#define kNtErrorIpsecMmAuthPendingDeletion                          13022
#define kNtErrorIpsecQmPolicyPendingDeletion                        13023
#define kNtErrorIpsecIkeNegStatusBegin                              13800
#define kNtErrorIpsecIkeAuthFail                                    13801
#define kNtErrorIpsecIkeAttribFail                                  13802
#define kNtErrorIpsecIkeNegotiationPending                          13803
#define kNtErrorIpsecIkeGeneralProcessingError                      13804
#define kNtErrorIpsecIkeTimedOut                                    13805
#define kNtErrorIpsecIkeNoCert                                      13806
#define kNtErrorIpsecIkeSaDeleted                                   13807
#define kNtErrorIpsecIkeSaReaped                                    13808
#define kNtErrorIpsecIkeMmAcquireDrop                               13809
#define kNtErrorIpsecIkeQmAcquireDrop                               13810
#define kNtErrorIpsecIkeQueueDropMm                                 13811
#define kNtErrorIpsecIkeQueueDropNoMm                               13812
#define kNtErrorIpsecIkeDropNoResponse                              13813
#define kNtErrorIpsecIkeMmDelayDrop                                 13814
#define kNtErrorIpsecIkeQmDelayDrop                                 13815
#define kNtErrorIpsecIkeError                                       13816
#define kNtErrorIpsecIkeCrlFailed                                   13817
#define kNtErrorIpsecIkeInvalidKeyUsage                             13818
#define kNtErrorIpsecIkeInvalidCertType                             13819
#define kNtErrorIpsecIkeNoPrivateKey                                13820
#define kNtErrorIpsecIkeSimultaneousRekey                           13821
#define kNtErrorIpsecIkeDhFail                                      13822
#define kNtErrorIpsecIkeCriticalPayloadNotRecognized                13823
#define kNtErrorIpsecIkeInvalidHeader                               13824
#define kNtErrorIpsecIkeNoPolicy                                    13825
#define kNtErrorIpsecIkeInvalidSignature                            13826
#define kNtErrorIpsecIkeKerberosError                               13827
#define kNtErrorIpsecIkeNoPublicKey                                 13828
#define kNtErrorIpsecIkeProcessErr                                  13829
#define kNtErrorIpsecIkeProcessErrSa                                13830
#define kNtErrorIpsecIkeProcessErrProp                              13831
#define kNtErrorIpsecIkeProcessErrTrans                             13832
#define kNtErrorIpsecIkeProcessErrKe                                13833
#define kNtErrorIpsecIkeProcessErrId                                13834
#define kNtErrorIpsecIkeProcessErrCert                              13835
#define kNtErrorIpsecIkeProcessErrCertReq                           13836
#define kNtErrorIpsecIkeProcessErrHash                              13837
#define kNtErrorIpsecIkeProcessErrSig                               13838
#define kNtErrorIpsecIkeProcessErrNonce                             13839
#define kNtErrorIpsecIkeProcessErrNotify                            13840
#define kNtErrorIpsecIkeProcessErrDelete                            13841
#define kNtErrorIpsecIkeProcessErrVendor                            13842
#define kNtErrorIpsecIkeInvalidPayload                              13843
#define kNtErrorIpsecIkeLoadSoftSa                                  13844
#define kNtErrorIpsecIkeSoftSaTornDown                              13845
#define kNtErrorIpsecIkeInvalidCookie                               13846
#define kNtErrorIpsecIkeNoPeerCert                                  13847
#define kNtErrorIpsecIkePeerCrlFailed                               13848
#define kNtErrorIpsecIkePolicyChange                                13849
#define kNtErrorIpsecIkeNoMmPolicy                                  13850
#define kNtErrorIpsecIkeNotcbpriv                                   13851
#define kNtErrorIpsecIkeSecloadfail                                 13852
#define kNtErrorIpsecIkeFailsspinit                                 13853
#define kNtErrorIpsecIkeFailqueryssp                                13854
#define kNtErrorIpsecIkeSrvacqfail                                  13855
#define kNtErrorIpsecIkeSrvquerycred                                13856
#define kNtErrorIpsecIkeGetspifail                                  13857
#define kNtErrorIpsecIkeInvalidFilter                               13858
#define kNtErrorIpsecIkeOutOfMemory                                 13859
#define kNtErrorIpsecIkeAddUpdateKeyFailed                          13860
#define kNtErrorIpsecIkeInvalidPolicy                               13861
#define kNtErrorIpsecIkeUnknownDoi                                  13862
#define kNtErrorIpsecIkeInvalidSituation                            13863
#define kNtErrorIpsecIkeDhFailure                                   13864
#define kNtErrorIpsecIkeInvalidGroup                                13865
#define kNtErrorIpsecIkeEncrypt                                     13866
#define kNtErrorIpsecIkeDecrypt                                     13867
#define kNtErrorIpsecIkePolicyMatch                                 13868
#define kNtErrorIpsecIkeUnsupportedId                               13869
#define kNtErrorIpsecIkeInvalidHash                                 13870
#define kNtErrorIpsecIkeInvalidHashAlg                              13871
#define kNtErrorIpsecIkeInvalidHashSize                             13872
#define kNtErrorIpsecIkeInvalidEncryptAlg                           13873
#define kNtErrorIpsecIkeInvalidAuthAlg                              13874
#define kNtErrorIpsecIkeInvalidSig                                  13875
#define kNtErrorIpsecIkeLoadFailed                                  13876
#define kNtErrorIpsecIkeRpcDelete                                   13877
#define kNtErrorIpsecIkeBenignReinit                                13878
#define kNtErrorIpsecIkeInvalidResponderLifetimeNotify              13879
#define kNtErrorIpsecIkeInvalidMajorVersion                         13880
#define kNtErrorIpsecIkeInvalidCertKeylen                           13881
#define kNtErrorIpsecIkeMmLimit                                     13882
#define kNtErrorIpsecIkeNegotiationDisabled                         13883
#define kNtErrorIpsecIkeQmLimit                                     13884
#define kNtErrorIpsecIkeMmExpired                                   13885
#define kNtErrorIpsecIkePeerMmAssumedInvalid                        13886
#define kNtErrorIpsecIkeCertChainPolicyMismatch                     13887
#define kNtErrorIpsecIkeUnexpectedMessageId                         13888
#define kNtErrorIpsecIkeInvalidAuthPayload                          13889
#define kNtErrorIpsecIkeDosCookieSent                               13890
#define kNtErrorIpsecIkeShuttingDown                                13891
#define kNtErrorIpsecIkeCgaAuthFailed                               13892
#define kNtErrorIpsecIkeProcessErrNatoa                             13893
#define kNtErrorIpsecIkeInvalidMmForQm                              13894
#define kNtErrorIpsecIkeQmExpired                                   13895
#define kNtErrorIpsecIkeTooManyFilters                              13896
#define kNtErrorIpsecIkeNegStatusEnd                                13897
#define kNtErrorIpsecIkeKillDummyNapTunnel                          13898
#define kNtErrorIpsecIkeInnerIpAssignmentFailure                    13899
#define kNtErrorIpsecIkeRequireCpPayloadMissing                     13900
#define kNtErrorIpsecKeyModuleImpersonationNegotiationPending       13901
#define kNtErrorIpsecIkeCoexistenceSuppress                         13902
#define kNtErrorIpsecIkeRatelimitDrop                               13903
#define kNtErrorIpsecIkePeerDoesntSupportMobike                     13904
#define kNtErrorIpsecIkeAuthorizationFailure                        13905
#define kNtErrorIpsecIkeStrongCredAuthorizationFailure              13906
#define kNtErrorIpsecIkeAuthorizationFailureWithOptionalRetry       13907
#define kNtErrorIpsecIkeStrongCredAuthorizationAndCertmapFailure    13908
#define kNtErrorIpsecIkeNegStatusExtendedEnd                        13909
#define kNtErrorIpsecBadSpi                                         13910
#define kNtErrorIpsecSaLifetimeExpired                              13911
#define kNtErrorIpsecWrongSa                                        13912
#define kNtErrorIpsecReplayCheckFailed                              13913
#define kNtErrorIpsecInvalidPacket                                  13914
#define kNtErrorIpsecIntegrityCheckFailed                           13915
#define kNtErrorIpsecClearTextDrop                                  13916
#define kNtErrorIpsecAuthFirewallDrop                               13917
#define kNtErrorIpsecThrottleDrop                                   13918
#define kNtErrorIpsecDospBlock                                      13925
#define kNtErrorIpsecDospReceivedMulticast                          13926
#define kNtErrorIpsecDospInvalidPacket                              13927
#define kNtErrorIpsecDospStateLookupFailed                          13928
#define kNtErrorIpsecDospMaxEntries                                 13929
#define kNtErrorIpsecDospKeymodNotAllowed                           13930
#define kNtErrorIpsecDospNotInstalled                               13931
#define kNtErrorIpsecDospMaxPerIpRatelimitQueues                    13932
#define kNtErrorSxsSectionNotFound                                  14000
#define kNtErrorSxsCantGenActctx                                    14001
#define kNtErrorSxsInvalidActctxdataFormat                          14002
#define kNtErrorSxsAssemblyNotFound                                 14003
#define kNtErrorSxsManifestFormatError                              14004
#define kNtErrorSxsManifestParseError                               14005
#define kNtErrorSxsActivationContextDisabled                        14006
#define kNtErrorSxsKeyNotFound                                      14007
#define kNtErrorSxsVersionConflict                                  14008
#define kNtErrorSxsWrongSectionType                                 14009
#define kNtErrorSxsThreadQueriesDisabled                            14010
#define kNtErrorSxsProcessDefaultAlreadySet                         14011
#define kNtErrorSxsUnknownEncodingGroup                             14012
#define kNtErrorSxsUnknownEncoding                                  14013
#define kNtErrorSxsInvalidXmlNamespaceUri                           14014
#define kNtErrorSxsRootManifestDependencyNotInstalled               14015
#define kNtErrorSxsLeafManifestDependencyNotInstalled               14016
#define kNtErrorSxsInvalidAssemblyIdentityAttribute                 14017
#define kNtErrorSxsManifestMissingRequiredDefaultNamespace          14018
#define kNtErrorSxsManifestInvalidRequiredDefaultNamespace          14019
#define kNtErrorSxsPrivateManifestCrossPathWithReparsePoint         14020
#define kNtErrorSxsDuplicateDllName                                 14021
#define kNtErrorSxsDuplicateWindowclassName                         14022
#define kNtErrorSxsDuplicateClsid                                   14023
#define kNtErrorSxsDuplicateIid                                     14024
#define kNtErrorSxsDuplicateTlbid                                   14025
#define kNtErrorSxsDuplicateProgid                                  14026
#define kNtErrorSxsDuplicateAssemblyName                            14027
#define kNtErrorSxsFileHashMismatch                                 14028
#define kNtErrorSxsPolicyParseError                                 14029
#define kNtErrorSxsXmlEMissingquote                                 14030
#define kNtErrorSxsXmlECommentsyntax                                14031
#define kNtErrorSxsXmlEBadstartnamechar                             14032
#define kNtErrorSxsXmlEBadnamechar                                  14033
#define kNtErrorSxsXmlEBadcharinstring                              14034
#define kNtErrorSxsXmlEXmldeclsyntax                                14035
#define kNtErrorSxsXmlEBadchardata                                  14036
#define kNtErrorSxsXmlEMissingwhitespace                            14037
#define kNtErrorSxsXmlEExpectingtagend                              14038
#define kNtErrorSxsXmlEMissingsemicolon                             14039
#define kNtErrorSxsXmlEUnbalancedparen                              14040
#define kNtErrorSxsXmlEInternalerror                                14041
#define kNtErrorSxsXmlEUnexpectedWhitespace                         14042
#define kNtErrorSxsXmlEIncompleteEncoding                           14043
#define kNtErrorSxsXmlEMissingParen                                 14044
#define kNtErrorSxsXmlEExpectingclosequote                          14045
#define kNtErrorSxsXmlEMultipleColons                               14046
#define kNtErrorSxsXmlEInvalidDecimal                               14047
#define kNtErrorSxsXmlEInvalidHexidecimal                           14048
#define kNtErrorSxsXmlEInvalidUnicode                               14049
#define kNtErrorSxsXmlEWhitespaceorquestionmark                     14050
#define kNtErrorSxsXmlEUnexpectedendtag                             14051
#define kNtErrorSxsXmlEUnclosedtag                                  14052
#define kNtErrorSxsXmlEDuplicateattribute                           14053
#define kNtErrorSxsXmlEMultipleroots                                14054
#define kNtErrorSxsXmlEInvalidatrootlevel                           14055
#define kNtErrorSxsXmlEBadxmldecl                                   14056
#define kNtErrorSxsXmlEMissingroot                                  14057
#define kNtErrorSxsXmlEUnexpectedeof                                14058
#define kNtErrorSxsXmlEBadperefinsubset                             14059
#define kNtErrorSxsXmlEUnclosedstarttag                             14060
#define kNtErrorSxsXmlEUnclosedendtag                               14061
#define kNtErrorSxsXmlEUnclosedstring                               14062
#define kNtErrorSxsXmlEUnclosedcomment                              14063
#define kNtErrorSxsXmlEUncloseddecl                                 14064
#define kNtErrorSxsXmlEUnclosedcdata                                14065
#define kNtErrorSxsXmlEReservednamespace                            14066
#define kNtErrorSxsXmlEInvalidencoding                              14067
#define kNtErrorSxsXmlEInvalidswitch                                14068
#define kNtErrorSxsXmlEBadxmlcase                                   14069
#define kNtErrorSxsXmlEInvalidStandalone                            14070
#define kNtErrorSxsXmlEUnexpectedStandalone                         14071
#define kNtErrorSxsXmlEInvalidVersion                               14072
#define kNtErrorSxsXmlEMissingequals                                14073
#define kNtErrorSxsProtectionRecoveryFailed                         14074
#define kNtErrorSxsProtectionPublicKeyTooShort                      14075
#define kNtErrorSxsProtectionCatalogNotValid                        14076
#define kNtErrorSxsUntranslatableHresult                            14077
#define kNtErrorSxsProtectionCatalogFileMissing                     14078
#define kNtErrorSxsMissingAssemblyIdentityAttribute                 14079
#define kNtErrorSxsInvalidAssemblyIdentityAttributeName             14080
#define kNtErrorSxsAssemblyMissing                                  14081
#define kNtErrorSxsCorruptActivationStack                           14082
#define kNtErrorSxsCorruption                                       14083
#define kNtErrorSxsEarlyDeactivation                                14084
#define kNtErrorSxsInvalidDeactivation                              14085
#define kNtErrorSxsMultipleDeactivation                             14086
#define kNtErrorSxsProcessTerminationRequested                      14087
#define kNtErrorSxsReleaseActivationContext                         14088
#define kNtErrorSxsSystemDefaultActivationContextEmpty              14089
#define kNtErrorSxsInvalidIdentityAttributeValue                    14090
#define kNtErrorSxsInvalidIdentityAttributeName                     14091
#define kNtErrorSxsIdentityDuplicateAttribute                       14092
#define kNtErrorSxsIdentityParseError                               14093
#define kNtErrorMalformedSubstitutionString                         14094
#define kNtErrorSxsIncorrectPublicKeyToken                          14095
#define kNtErrorUnmappedSubstitutionString                          14096
#define kNtErrorSxsAssemblyNotLocked                                14097
#define kNtErrorSxsComponentStoreCorrupt                            14098
#define kNtErrorAdvancedInstallerFailed                             14099
#define kNtErrorXmlEncodingMismatch                                 14100
#define kNtErrorSxsManifestIdentitySameButContentsDifferent         14101
#define kNtErrorSxsIdentitiesDifferent                              14102
#define kNtErrorSxsAssemblyIsNotADeployment                         14103
#define kNtErrorSxsFileNotPartOfAssembly                            14104
#define kNtErrorSxsManifestTooBig                                   14105
#define kNtErrorSxsSettingNotRegistered                             14106
#define kNtErrorSxsTransactionClosureIncomplete                     14107
#define kNtErrorSmiPrimitiveInstallerFailed                         14108
#define kNtErrorGenericCommandFailed                                14109
#define kNtErrorSxsFileHashMissing                                  14110
#define kNtErrorEvtInvalidChannelPath                               15000
#define kNtErrorEvtInvalidQuery                                     15001
#define kNtErrorEvtPublisherMetadataNotFound                        15002
#define kNtErrorEvtEventTemplateNotFound                            15003
#define kNtErrorEvtInvalidPublisherName                             15004
#define kNtErrorEvtInvalidEventData                                 15005
#define kNtErrorEvtChannelNotFound                                  15007
#define kNtErrorEvtMalformedXmlText                                 15008
#define kNtErrorEvtSubscriptionToDirectChannel                      15009
#define kNtErrorEvtConfigurationError                               15010
#define kNtErrorEvtQueryResultStale                                 15011
#define kNtErrorEvtQueryResultInvalidPosition                       15012
#define kNtErrorEvtNonValidatingMsxml                               15013
#define kNtErrorEvtFilterAlreadyscoped                              15014
#define kNtErrorEvtFilterNoteltset                                  15015
#define kNtErrorEvtFilterInvarg                                     15016
#define kNtErrorEvtFilterInvtest                                    15017
#define kNtErrorEvtFilterInvtype                                    15018
#define kNtErrorEvtFilterParseerr                                   15019
#define kNtErrorEvtFilterUnsupportedop                              15020
#define kNtErrorEvtFilterUnexpectedtoken                            15021
#define kNtErrorEvtInvalidOperationOverEnabledDirectChannel         15022
#define kNtErrorEvtInvalidChannelPropertyValue                      15023
#define kNtErrorEvtInvalidPublisherPropertyValue                    15024
#define kNtErrorEvtChannelCannotActivate                            15025
#define kNtErrorEvtFilterTooComplex                                 15026
#define kNtErrorEvtMessageNotFound                                  15027
#define kNtErrorEvtMessageIdNotFound                                15028
#define kNtErrorEvtUnresolvedValueInsert                            15029
#define kNtErrorEvtUnresolvedParameterInsert                        15030
#define kNtErrorEvtMaxInsertsReached                                15031
#define kNtErrorEvtEventDefinitionNotFound                          15032
#define kNtErrorEvtMessageLocaleNotFound                            15033
#define kNtErrorEvtVersionTooOld                                    15034
#define kNtErrorEvtVersionTooNew                                    15035
#define kNtErrorEvtCannotOpenChannelOfQuery                         15036
#define kNtErrorEvtPublisherDisabled                                15037
#define kNtErrorEvtFilterOutOfRange                                 15038
#define kNtErrorEcSubscriptionCannotActivate                        15080
#define kNtErrorEcLogDisabled                                       15081
#define kNtErrorEcCircularForwarding                                15082
#define kNtErrorEcCredstoreFull                                     15083
#define kNtErrorEcCredNotFound                                      15084
#define kNtErrorEcNoActiveChannel                                   15085
#define kNtErrorMuiFileNotFound                                     15100
#define kNtErrorMuiInvalidFile                                      15101
#define kNtErrorMuiInvalidRcConfig                                  15102
#define kNtErrorMuiInvalidLocaleName                                15103
#define kNtErrorMuiInvalidUltimatefallbackName                      15104
#define kNtErrorMuiFileNotLoaded                                    15105
#define kNtErrorResourceEnumUserStop                                15106
#define kNtErrorMuiIntlsettingsUilangNotInstalled                   15107
#define kNtErrorMuiIntlsettingsInvalidLocaleName                    15108
#define kNtErrorMrmRuntimeNoDefaultOrNeutralResource                15110
#define kNtErrorMrmInvalidPriconfig                                 15111
#define kNtErrorMrmInvalidFileType                                  15112
#define kNtErrorMrmUnknownQualifier                                 15113
#define kNtErrorMrmInvalidQualifierValue                            15114
#define kNtErrorMrmNoCandidate                                      15115
#define kNtErrorMrmNoMatchOrDefaultCandidate                        15116
#define kNtErrorMrmResourceTypeMismatch                             15117
#define kNtErrorMrmDuplicateMapName                                 15118
#define kNtErrorMrmDuplicateEntry                                   15119
#define kNtErrorMrmInvalidResourceIdentifier                        15120
#define kNtErrorMrmFilepathTooLong                                  15121
#define kNtErrorMrmUnsupportedDirectoryType                         15122
#define kNtErrorMrmInvalidPriFile                                   15126
#define kNtErrorMrmNamedResourceNotFound                            15127
#define kNtErrorMrmMapNotFound                                      15135
#define kNtErrorMrmUnsupportedProfileType                           15136
#define kNtErrorMrmInvalidQualifierOperator                         15137
#define kNtErrorMrmIndeterminateQualifierValue                      15138
#define kNtErrorMrmAutomergeEnabled                                 15139
#define kNtErrorMrmTooManyResources                                 15140
#define kNtErrorMrmUnsupportedFileTypeForMerge                      15141
#define kNtErrorMrmUnsupportedFileTypeForLoadUnloadPriFile          15142
#define kNtErrorMrmNoCurrentViewOnThread                            15143
#define kNtErrorDifferentProfileResourceManagerExist                15144
#define kNtErrorOperationNotAllowedFromSystemComponent              15145
#define kNtErrorMrmDirectRefToNonDefaultResource                    15146
#define kNtErrorMrmGenerationCountMismatch                          15147
#define kNtErrorPriMergeVersionMismatch                             15148
#define kNtErrorPriMergeMissingSchema                               15149
#define kNtErrorPriMergeLoadFileFailed                              15150
#define kNtErrorPriMergeAddFileFailed                               15151
#define kNtErrorPriMergeWriteFileFailed                             15152
#define kNtErrorPriMergeMultiplePackageFamiliesNotAllowed           15153
#define kNtErrorPriMergeMultipleMainPackagesNotAllowed              15154
#define kNtErrorPriMergeBundlePackagesNotAllowed                    15155
#define kNtErrorPriMergeMainPackageRequired                         15156
#define kNtErrorPriMergeResourcePackageRequired                     15157
#define kNtErrorPriMergeInvalidFileName                             15158
#define kNtErrorMcaInvalidCapabilitiesString                        15200
#define kNtErrorMcaInvalidVcpVersion                                15201
#define kNtErrorMcaMonitorViolatesMccsSpecification                 15202
#define kNtErrorMcaMccsVersionMismatch                              15203
#define kNtErrorMcaUnsupportedMccsVersion                           15204
#define kNtErrorMcaInternalError                                    15205
#define kNtErrorMcaInvalidTechnologyTypeReturned                    15206
#define kNtErrorMcaUnsupportedColorTemperature                      15207
#define kNtErrorAmbiguousSystemDevice                               15250
#define kNtErrorSystemDeviceNotFound                                15299
#define kNtErrorHashNotSupported                                    15300
#define kNtErrorHashNotPresent                                      15301
#define kNtErrorSecondaryIcProviderNotRegistered                    15321
#define kNtErrorGpioClientInformationInvalid                        15322
#define kNtErrorGpioVersionNotSupported                             15323
#define kNtErrorGpioInvalidRegistrationPacket                       15324
#define kNtErrorGpioOperationDenied                                 15325
#define kNtErrorGpioIncompatibleConnectMode                         15326
#define kNtErrorGpioInterruptAlreadyUnmasked                        15327
#define kNtErrorCannotSwitchRunlevel                                15400
#define kNtErrorInvalidRunlevelSetting                              15401
#define kNtErrorRunlevelSwitchTimeout                               15402
#define kNtErrorRunlevelSwitchAgentTimeout                          15403
#define kNtErrorRunlevelSwitchInProgress                            15404
#define kNtErrorServicesFailedAutostart                             15405
#define kNtErrorComTaskStopPending                                  15501
#define kNtErrorInstallOpenPackageFailed                            15600
#define kNtErrorInstallPackageNotFound                              15601
#define kNtErrorInstallInvalidPackage                               15602
#define kNtErrorInstallResolveDependencyFailed                      15603
#define kNtErrorInstallOutOfDiskSpace                               15604
#define kNtErrorInstallNetworkFailure                               15605
#define kNtErrorInstallRegistrationFailure                          15606
#define kNtErrorInstallDeregistrationFailure                        15607
#define kNtErrorInstallCancel                                       15608
#define kNtErrorInstallFailed                                       15609
#define kNtErrorRemoveFailed                                        15610
#define kNtErrorPackageAlreadyExists                                15611
#define kNtErrorNeedsRemediation                                    15612
#define kNtErrorInstallPrerequisiteFailed                           15613
#define kNtErrorPackageRepositoryCorrupted                          15614
#define kNtErrorInstallPolicyFailure                                15615
#define kNtErrorPackageUpdating                                     15616
#define kNtErrorDeploymentBlockedByPolicy                           15617
#define kNtErrorPackagesInUse                                       15618
#define kNtErrorRecoveryFileCorrupt                                 15619
#define kNtErrorInvalidStagedSignature                              15620
#define kNtErrorDeletingExistingApplicationdataStoreFailed          15621
#define kNtErrorInstallPackageDowngrade                             15622
#define kNtErrorSystemNeedsRemediation                              15623
#define kNtErrorAppxIntegrityFailureClrNgen                         15624
#define kNtErrorResiliencyFileCorrupt                               15625
#define kNtErrorInstallFirewallServiceNotRunning                    15626
#define kNtErrorPackageMoveFailed                                   15627
#define kNtErrorInstallVolumeNotEmpty                               15628
#define kNtErrorInstallVolumeOffline                                15629
#define kNtErrorInstallVolumeCorrupt                                15630
#define kNtErrorNeedsRegistration                                   15631
#define kNtErrorInstallWrongProcessorArchitecture                   15632
#define kNtErrorDevSideloadLimitExceeded                            15633
#define kNtErrorInstallOptionalPackageRequiresMainPackage           15634
#define kNtErrorPackageNotSupportedOnFilesystem                     15635
#define kNtErrorPackageMoveBlockedByStreaming                       15636
#define kNtErrorInstallOptionalPackageApplicationidNotUnique        15637
#define kNtErrorPackageStagingOnhold                                15638
#define kNtErrorInstallInvalidRelatedSetUpdate                      15639
#define kNtErrorPackagesReputationCheckFailed                       15643
#define kNtErrorPackagesReputationCheckTimedout                     15644
#define kNtErrorStateLoadStoreFailed                                15800
#define kNtErrorStateGetVersionFailed                               15801
#define kNtErrorStateSetVersionFailed                               15802
#define kNtErrorStateStructuredResetFailed                          15803
#define kNtErrorStateOpenContainerFailed                            15804
#define kNtErrorStateCreateContainerFailed                          15805
#define kNtErrorStateDeleteContainerFailed                          15806
#define kNtErrorStateReadSettingFailed                              15807
#define kNtErrorStateWriteSettingFailed                             15808
#define kNtErrorStateDeleteSettingFailed                            15809
#define kNtErrorStateQuerySettingFailed                             15810
#define kNtErrorStateReadCompositeSettingFailed                     15811
#define kNtErrorStateWriteCompositeSettingFailed                    15812
#define kNtErrorStateEnumerateContainerFailed                       15813
#define kNtErrorStateEnumerateSettingsFailed                        15814
#define kNtErrorStateCompositeSettingValueSizeLimitExceeded         15815
#define kNtErrorStateSettingValueSizeLimitExceeded                  15816
#define kNtErrorStateSettingNameSizeLimitExceeded                   15817
#define kNtErrorStateContainerNameSizeLimitExceeded                 15818
#define kNtErrorApiUnavailable                                      15841 /* EPROCUNAVAIL */

#define kNtWaitIoCompletion 0xc0

/* WinSock Error Codes: 10000-11999 */
#define WSABASEERR                  10000
#define WSAEINTR                    10004
#define WSAEBADF                    10009
#define WSAEACCES                   10013
#define WSAEFAULT                   10014
#define WSAEINVAL                   10022
#define WSAEMFILE                   10024
#define WSAEWOULDBLOCK              10035
#define WSAEINPROGRESS              10036
#define WSAEALREADY                 10037
#define WSAENOTSOCK                 10038
#define WSAEDESTADDRREQ             10039
#define WSAEMSGSIZE                 10040
#define WSAEPROTOTYPE               10041
#define WSAENOPROTOOPT              10042
#define WSAEPROTONOSUPPORT          10043
#define WSAESOCKTNOSUPPORT          10044
#define WSAEOPNOTSUPP               10045
#define WSAEPFNOSUPPORT             10046
#define WSAEAFNOSUPPORT             10047
#define WSAEADDRINUSE               10048
#define WSAEADDRNOTAVAIL            10049
#define WSAENETDOWN                 10050
#define WSAENETUNREACH              10051
#define WSAENETRESET                10052
#define WSAECONNABORTED             10053
#define WSAECONNRESET               10054
#define WSAENOBUFS                  10055
#define WSAEISCONN                  10056
#define WSAENOTCONN                 10057
#define WSAESHUTDOWN                10058
#define WSAETOOMANYREFS             10059
#define WSAETIMEDOUT                10060
#define WSAECONNREFUSED             10061
#define WSAELOOP                    10062
#define WSAENAMETOOLONG             10063
#define WSAEHOSTDOWN                10064
#define WSAEHOSTUNREACH             10065
#define WSAENOTEMPTY                10066
#define WSAEPROCLIM                 10067
#define WSAEUSERS                   10068
#define WSAEDQUOT                   10069
#define WSAESTALE                   10070
#define WSAEREMOTE                  10071
#define WSASYSNOTREADY              10091
#define WSAVERNOTSUPPORTED          10092
#define WSANOTINITIALISED           10093
#define WSAEDISCON                  10101
#define WSAENOMORE                  10102
#define WSAECANCELLED               10103
#define WSAEINVALIDPROCTABLE        10104
#define WSAEINVALIDPROVIDER         10105
#define WSAEPROVIDERFAILEDINIT      10106
#define WSASYSCALLFAILURE           10107
#define WSASERVICE_NOT_FOUND        10108
#define WSATYPE_NOT_FOUND           10109
#define WSA_E_NO_MORE               10110
#define WSA_E_CANCELLED             10111
#define WSAEREFUSED                 10112
#define WSAHOST_NOT_FOUND           11001
#define WSATRY_AGAIN                11002
#define WSANO_RECOVERY              11003
#define WSANO_DATA                  11004
#define WSA_QOS_RECEIVERS           11005
#define WSA_QOS_SENDERS             11006
#define WSA_QOS_NO_SENDERS          11007
#define WSA_QOS_NO_RECEIVERS        11008
#define WSA_QOS_REQUEST_CONFIRMED   11009
#define WSA_QOS_ADMISSION_FAILURE   11010
#define WSA_QOS_POLICY_FAILURE      11011
#define WSA_QOS_BAD_STYLE           11012
#define WSA_QOS_BAD_OBJECT          11013
#define WSA_QOS_TRAFFIC_CTRL_ERROR  11014
#define WSA_QOS_GENERIC_ERROR       11015
#define WSA_QOS_ESERVICETYPE        11016
#define WSA_QOS_EFLOWSPEC           11017
#define WSA_QOS_EPROVSPECBUF        11018
#define WSA_QOS_EFILTERSTYLE        11019
#define WSA_QOS_EFILTERTYPE         11020
#define WSA_QOS_EFILTERCOUNT        11021
#define WSA_QOS_EOBJLENGTH          11022
#define WSA_QOS_EFLOWCOUNT          11023
#define WSA_QOS_EUNKOWNPSOBJ        11024
#define WSA_QOS_EPOLICYOBJ          11025
#define WSA_QOS_EFLOWDESC           11026
#define WSA_QOS_EPSFLOWSPEC         11027
#define WSA_QOS_EPSFILTERSPEC       11028
#define WSA_QOS_ESDMODEOBJ          11029
#define WSA_QOS_ESHAPERATEOBJ       11030
#define WSA_QOS_RESERVED_PETYPE     11031
#define WSA_SECURE_HOST_NOT_FOUND   11032
#define WSA_IPSEC_NAME_POLICY_ERROR 11033

#define WSA_WAIT_FAILED         -1u
#define WSA_WAIT_EVENT_0        0
#define WSA_WAIT_IO_COMPLETION  0xc0
#define WSA_WAIT_TIMEOUT        258
#define WSA_MAXIMUM_WAIT_EVENTS 64
#define WSA_IO_PENDING          997


#define kNtWsaInvalidHandle    kNtErrorInvalidHandle
#define kNtWsaNotEnoughMemory  kNtErrorNotEnoughMemory
#define kNtWsaInvalidParameter kNtErrorInvalidParameter
#define kNtWsaIoPending        kNtErrorIoPending
#define kNtWsaIoIncomplete     kNtErrorIoIncomplete
#define kNtWsaOperationAborted kNtErrorOperationAborted



/*!BEGIN libc/nt/enum/wsaid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSAID_H_
COSMOPOLITAN_C_START_

#define WSAID_WSAPOLL                                \
  {                                                  \
    0x18C76F85, 0xDC66, 0x4964, {                    \
      0x97, 0x2E, 0x23, 0xC2, 0x72, 0x38, 0x31, 0x2B \
    }                                                \
  }

#define WSAID_WSARECVMSG                             \
  {                                                  \
    0xf689d7c8, 0x6f1f, 0x436b, {                    \
      0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22 \
    }                                                \
  }

#define WSAID_WSASENDMSG                             \
  {                                                  \
    0xa441e712, 0x754f, 0x43ca, {                    \
      0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d \
    }                                                \
  }

#define WSAID_CONNECTEX                              \
  {                                                  \
    0x25a207b9, 0xddf3, 0x4660, {                    \
      0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e \
    }                                                \
  }

#define WSAID_ACCEPTEX                               \
  {                                                  \
    0xb5367df1, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_GETACCEPTEXSOCKADDRS                   \
  {                                                  \
    0xb5367df2, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITFILE                           \
  {                                                  \
    0xb5367df0, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITPACKETS                        \
  {                                                  \
    0xd9689da0, 0x1f90, 0x11d3, {                    \
      0x99, 0x71, 0x00, 0xc0, 0x4f, 0x68, 0xc8, 0x76 \
    }                                                \
  }

#define WSAID_DISCONNECTEX                           \
  {                                                  \
    0x7fda2e11, 0x8630, 0x436f, {                    \
      0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57 \
    }                                                \
  }

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/wt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WT_H_

#define kNtWtExecutedefault            0x00000000u
#define kNtWtExecuteonlyonce           0x00000008u
#define kNtWtExecuteintimerthread      0x00000020u
#define kNtWtExecuteinpersistentthread 0x00000080u
#define kNtWtExecutelongfunction       0x00000010u
#define kNtWtTransferImpersonation     0𝔵00000100𝔲



/*!BEGIN libc/nt/struct/acl.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ACL_H_

struct NtAcl {
  uint8_t AclRevision;
  uint8_t Sbz1;
  uint16_t AclSize;
  uint16_t AceCount;
  uint16_t Sbz2;
};



/*!BEGIN libc/nt/struct/afd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_AFD_H_
COSMOPOLITAN_C_START_

struct NtAfdPollHandleInfo {
  int64_t Handle;
  uint32_t Events;
  NtStatus Status;
};

struct NtAfdPollInfo {
  int64_t Timeout;
  uint32_t NumberOfHandles;
  uint32_t Exclusive;
  struct NtAfdPollHandleInfo Handles[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ansistring.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ANSISTRING_H_

struct NtAnsiString {
  unsigned short Length;
  unsigned short MaximumLength;
  char *Buffer;
};



/*!BEGIN libc/nt/struct/byhandlefileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_BYHANDLEFILEINFORMATION_H_


/*!BEGIN libc/nt/struct/filetime.h */

#define COSMOPOLITAN_LIBC_NT_FILETIME_H_

struct NtFileTime {
  uint32_t dwLowDateTime;
  uint32_t dwHighDateTime;
};


struct NtByHandleFileInformation {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationFileTime;
  struct NtFileTime ftLastAccessFileTime;
  struct NtFileTime ftLastWriteFileTime;
  uint32_t dwVolumeSerialNumber;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t nNumberOfLinks;
  uint32_t nFileIndexHigh;
  uint32_t nFileIndexLow;
};



/*!BEGIN libc/nt/struct/charinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CHARINFO_H_

struct NtCharInfo {
  union {
    char16_t UnicodeChar;
    char AsciiChar;
  } Char;
  uint16_t Attributes;
};



/*!BEGIN libc/nt/struct/clientid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CLIENTID_H_

struct NtClientId {
  void *UniqueProcess;
  void *UniqueThread;
};



/*!BEGIN libc/nt/struct/consolecursorinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLECURSORINFO_H_

struct NtConsoleCursorInfo {
  uint32_t dwSize;
  bool32 bVisible;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFO_H_


/*!BEGIN libc/nt/struct/coord.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COORD_H_

struct NtCoord {
  int16_t X;
  int16_t Y;
};



/*!BEGIN libc/nt/struct/smallrect.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SMALLRECT_H_

struct NtSmallRect {
  int16_t Left;
  int16_t Top;
  int16_t Right;
  int16_t Bottom;
};


struct NtConsoleScreenBufferInfo {
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes;
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFOEX_H_

struct NtConsoleScreenBufferInfoEx {
  uint32_t cbSize; /* sizeof(struct NtConsoleScreenBufferInfoEx) */
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes; /* kNt{Foreground,Background}... */
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
  uint16_t wPopupAttributes;
  bool32 bFullscreenSupported;
  uint32_t ColorTable[16]; /* 0x00BBGGRR */
};



/*!BEGIN libc/nt/struct/consoleselectioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESELECTIONINFO_H_

struct NtConsoleSelectionInfo {
  uint32_t dwFlags;
  struct NtCoord dwSelectionAnchor;
  struct NtSmallRect srSelection;
};



/*!BEGIN libc/nt/struct/context.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONTEXT_H_

struct NtM128A {
  uint64_t Low;
  int64_t High;
};

struct NtXmmSaveArea32 { /* basically same as struct FpuState */
  uint16_t ControlWord;
  uint16_t StatusWord;
  uint8_t TagWord;
  uint8_t Reserved1;
  uint16_t ErrorOpcode;
  uint32_t ErrorOffset;
  uint16_t ErrorSelector;
  uint16_t Reserved2;
  uint32_t DataOffset;
  uint16_t DataSelector;
  uint16_t Reserved3;
  uint32_t MxCsr;
  uint32_t MxCsr_Mask;
  struct NtM128A FloatRegisters[8];
  struct NtM128A XmmRegisters[16];
  uint8_t Reserved4[96];
};

struct NtContext {
  uint64_t P1Home, P2Home, P3Home, P4Home, P5Home, P6Home;
  uint32_t ContextFlags;
  uint32_t MxCsr;
  uint16_t SegCs, SegDs, SegEs, SegFs, SegGs, SegSs;
  uint32_t EFlags;
  uint64_t Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
  uint64_t Rax, Rcx, Rdx, Rbx, Rsp, Rbp, Rsi, Rdi;
  uint64_t R8, R9, R10, R11, R12, R13, R14, R15;
  uint64_t Rip;
  union {
    struct NtXmmSaveArea32 FltSave;
    struct NtXmmSaveArea32 FloatSave;
    struct {
      struct NtM128A Header[2];
      struct NtM128A Legacy[8];
      struct NtM128A Xmm0, Xmm1, Xmm2, Xmm3, Xmm4, Xmm5, Xmm6, Xmm7;
      struct NtM128A Xmm8, Xmm9, Xmm10, Xmm11, Xmm12, Xmm13, Xmm14, Xmm15;
    };
  };
  struct NtM128A VectorRegister[26];
  uint64_t VectorControl;
  uint64_t DebugControl;
  uint64_t LastBranchToRip;
  uint64_t LastBranchFromRip;
  uint64_t LastExceptionToRip;
  uint64_t LastExceptionFromRip;
} forcealign(16);



/*!BEGIN libc/nt/struct/criticalsection.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTION_H_


/*!BEGIN libc/nt/struct/criticalsectiondebug.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTIONDEBUG_H_


/*!BEGIN libc/nt/struct/linkedlist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINKEDLIST_H_

/**
 * Dynamic linked list overlay.
 */
struct NtLinkedList {
  struct NtLinkedList *Next;
  struct NtLinkedList *Prev;
};


struct NtCriticalSectionDebug {
  uint16_t Type;
  uint16_t CreatorBackTraceIndex;
  struct NtCriticalSection *CriticalSection;
  struct NtLinkedList ProcessLocksList;
  uint32_t EntryCount;
  uint32_t ContentionCount;
  uint32_t Spare[2];
};


struct NtCriticalSection {
  struct NtCriticalSectionDebug *DebugInfo;
  int32_t LockCount;
  int32_t RecursionCount;
  void *OwningThread;
  void *LockSemaphore;
  uintptr_t SpinCount;
};



/*!BEGIN libc/nt/struct/drawtextparams.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DRAWTEXTPARAMS_H_
COSMOPOLITAN_C_START_

struct NtDrawTextParams {
  uint32_t cbSize;
  int32_t iTabLength;
  int32_t iLeftMargin;
  int32_t iRightMargin;
  uint32_t uiLengthDrawn;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/dynamictimezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DYNAMICTIMEZONEINFORMATION_H_


/*!BEGIN libc/nt/struct/systemtime.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIME_H_

struct NtSystemTime {
  uint16_t wYear;
  uint16_t wMonth;
  uint16_t wDayOfWeek;
  uint16_t wDay;
  uint16_t wHour;
  uint16_t wMinute;
  uint16_t wSecond;
  uint16_t wMilliseconds;
};


struct NtDynamicTimeZoneInformation {
  int32_t Bias;
  char16_t StandardName[32];
  struct NtSystemTime StandardDate;
  int32_t StandardBias;
  char16_t DaylightName[32];
  struct NtSystemTime DaylightDate;
  int32_t DaylightBias;
  char16_t TimeZoneKeyName[128];
  bool32 DynamicDaylightTimeDisabled;
};



/*!BEGIN libc/nt/struct/editmenu.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EDITMENU_H_

struct NtEditMenu {
  int64_t hmenu;
  uint16_t idEdit;
  uint16_t idCut;
  uint16_t idCopy;
  uint16_t idPaste;
  uint16_t idClear;
  uint16_t idUndo;
};



/*!BEGIN libc/nt/struct/exceptionframe.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EXCEPTIONFRAME_H_

struct NtExceptionFrame {
  struct NtExceptionFrame *Prev;
};



/*!BEGIN libc/nt/struct/fdset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FDSET_H_
COSMOPOLITAN_C_START_

struct NtFdSet {
  uint32_t fd_count;
  int64_t fd_array[64];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/fileaccessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEACCESSINFORMATION_H_

struct NtFileAccessInformation {
  uint32_t AccessFlags;
};



/*!BEGIN libc/nt/struct/filealignmentinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALIGNMENTINFORMATION_H_

struct NtFileAlignmentInformation {
  uint32_t AlignmentRequirement;
};



/*!BEGIN libc/nt/struct/fileallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLINFORMATION_H_


/*!BEGIN libc/nt/struct/filebasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFORMATION_H_

struct NtFileBasicInformation {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/fileeainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEEAINFORMATION_H_

struct NtFileEaInformation {
  uint32_t EaSize;
};



/*!BEGIN libc/nt/struct/fileinternalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEINTERNALINFORMATION_H_

struct NtFileInternalInformation {
  int64_t IndexNumber;
};



/*!BEGIN libc/nt/struct/filemodeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMODEINFORMATION_H_

struct NtFileModeInformation {
  uint32_t Mode;
};



/*!BEGIN libc/nt/struct/filenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMEINFORMATION_H_

struct NtFileNameInformation {
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filepositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPOSITIONINFORMATION_H_

struct NtFilePositionInformation {
  int64_t CurrentByteOffset;
};



/*!BEGIN libc/nt/struct/filestandardinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTANDARDINFORMATION_H_

struct NtFileStandardInformation {
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t NumberOfLinks;
  bool32 DeletePending;
  bool32 Directory;
};


struct NtFileAllInformation {
  struct NtFileBasicInformation BasicInformation;
  struct NtFileStandardInformation StandardInformation;
  struct NtFileInternalInformation InternalInformation;
  struct NtFileEaInformation EaInformation;
  struct NtFileAccessInformation AccessInformation;
  struct NtFilePositionInformation PositionInformation;
  struct NtFileModeInformation ModeInformation;
  struct NtFileAlignmentInformation AlignmentInformation;
  struct NtFileNameInformation NameInformation;
};



/*!BEGIN libc/nt/struct/fileallocationinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLOCATIONINFORMATION_H_

struct NtFileAllocationInformation {
  int64_t AllocationSize;
};



/*!BEGIN libc/nt/struct/fileattributetaginformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEATTRIBUTETAGINFORMATION_H_

struct NtFileAttributeTagInformation {
  uint32_t FileAttributes;
  uint32_t ReparseTag;
};



/*!BEGIN libc/nt/struct/filebasicinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFO_H_

struct NtFileBasicInfo {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/filebothdirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBOTHDIRECTORYINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileBothDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  unsigned char ShortNameLength;
  char16_t ShortName[12];
  char16_t FileName[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filecompressioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILECOMPRESSIONINFO_H_

struct NtFileCompressionInfo {
  int64_t CompressedFileSize;
  uint16_t CompressionFormat;
  uint8_t CompressionUnitShift;
  uint8_t ChunkShift;
  uint8_t ClusterShift;
  uint8_t Reserved[3];
};



/*!BEGIN libc/nt/struct/filedirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDIRECTORYINFORMATION_H_

struct NtFileDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filedispositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDISPOSITIONINFORMATION_H_

struct NtFileDispositionInformation {
  bool32 DoDeleteFile;
};



/*!BEGIN libc/nt/struct/fileendoffileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEENDOFFILEINFORMATION_H_

struct FileEndOfFileInformation {
  int64_t EndOfFile;
};



/*!BEGIN libc/nt/struct/filefsfullsizeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFSFULLSIZEINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileFsFullSizeInformation {
  int64_t TotalAllocationUnits;
  int64_t CallerAvailableAllocationUnits;
  int64_t ActualAvailableAllocationUnits;
  uint32_t SectorsPerAllocationUnit;
  uint32_t BytesPerSector;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filefulldirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLDIRECTORYINFORMATION_H_

struct NtFileFullDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filefulleainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLEAINFORMATION_H_

struct NtFileFullEaInformation {
  uint32_t NextEntryOffset;
  uint8_t Flags;
  uint8_t EaNameLength;
  uint16_t EaValueLength;
  char EaName[1];
};



/*!BEGIN libc/nt/struct/filemailslotqueryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTQUERYINFORMATION_H_

struct NtFileMailslotQueryInformation {
  uint32_t MaximumMessageSize;
  uint32_t MailslotQuota;
  uint32_t NextMessageSize;
  uint32_t MessagesAvailable;
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filemailslotsetinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTSETINFORMATION_H_

struct NtFileMailslotSetInformation {
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filenamesinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMESINFORMATION_H_

struct NtFileNamesInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filenetworkopeninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENETWORKOPENINFORMATION_H_

struct NtFileNetworkOpenInformation {
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t FileAttributes;
};



/*!BEGIN libc/nt/struct/filepipelocalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPIPELOCALINFORMATION_H_

struct NtFilePipeLocalInformation {
  uint32_t NamedPipeType;
  uint32_t NamedPipeConfiguration;
  uint32_t MaximumInstances;
  uint32_t CurrentInstances;
  uint32_t InboundQuota;
  uint32_t ReadDataAvailable;
  uint32_t OutboundQuota;
  uint32_t WriteQuotaAvailable;
  uint32_t NamedPipeState;
  uint32_t NamedPipeEnd;
};



/*!BEGIN libc/nt/struct/filerenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILERENAMEINFORMATION_H_

struct NtFileRenameInformation {
  bool32 Replace;
  void *RootDir;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filesegmentelement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESEGMENTELEMENT_H_

union NtFileSegmentElement {
  void *Buffer;
  uint64_t Alignment;
};



/*!BEGIN libc/nt/struct/filestreaminformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTREAMINFORMATION_H_

struct NtFileStreamInformation {
  uint32_t NextEntryOffset;
  uint32_t StreamNameLength;
  int64_t StreamSize;
  int64_t StreamAllocationSize;
  char16_t StreamName[1];
};



/*!BEGIN libc/nt/struct/filezerodatainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEZERODATAINFORMATION_H_

struct NtFileZeroDataInformation {
  uint64_t FileOffset;
  uint64_t BeyondFinalZero;
};



/*!BEGIN libc/nt/struct/fpodata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FPODATA_H_

struct NtFpoData {
  /* TODO(jart): No bitfields. */
  uint32_t ulOffStart;
  uint32_t cbProcSize;
  uint32_t cdwLocals;
  uint16_t cdwParams;
  uint16_t cbProlog : 8;
  uint16_t cbRegs : 3;
  uint16_t fHasSEH : 1;
  uint16_t fUseBP : 1;
  uint16_t reserved : 1;
  uint16_t cbFrame : 2;
};



/*!BEGIN libc/nt/struct/genericmapping.h */

#define COSMOPOLITAN_LIBC_NT_GENERICMAPPING_H_

struct NtGenericMapping {
  unsigned int GenericRead;
  unsigned int GenericWrite;
  unsigned int GenericExecute;
  unsigned int GenericAll;
};



/*!BEGIN libc/nt/struct/guid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_GUID_H_
COSMOPOLITAN_C_START_

struct NtGuid {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/inputrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_INPUTRECORD_H_

struct NtKeyEventRecord {
  bool32 bKeyDown;
  uint16_t wRepeatCount;
  uint16_t wVirtualKeyCode;
  uint16_t wVirtualScanCode;
  union {
    uint16_t UnicodeChar;
    char AsciiChar;
  } uChar;
  unsigned int dwControlKeyState;
#define kNtRightAltPressed  0x0001
#define kNtLeftAltPressed   0x0002
#define kNtRightCtrlPressed 0x0004
#define kNtLeftCtrlPressed  0x0008
#define kNtShiftPressed     0x0010
#define kNtNumlockOn        0x0020
#define kNtScrolllockOn     0x0040
#define kNtCapslockOn       0x0080
#define kNtEnhancedKey      0x0100
};

struct NtMouseEventRecord {
  struct NtCoord dwMousePosition;
  uint32_t dwButtonState;
#define kNtFromLeft1stButtonPressed 0x0001
#define kNtRightmostButtonPressed   0x0002
#define kNtFromLeft2ndButtonPressed 0x0004
#define kNtFromLeft3rdButtonPressed 0x0008
#define kNtFromLeft4thButtonPressed 0x0010
  uint32_t dwControlKeyState;
  uint32_t dwEventFlags;
#define kNtMouseMoved    0x0001
#define kNtDoubleClick   0x0002
#define kNtMouseWheeled  0x0004
#define kNtMouseHwheeled 0x0008
};

struct NtWindowBufferSizeRecord {
  struct NtCoord dwSize;
};

struct NtMenuEventRecord {
  uint32_t dwCommandId;
};

struct NtFocusEventRecord {
  bool32 bSetFocus;
};

struct NtInputRecord {
  uint16_t EventType;
#define kNtKeyEvent              0x0001
#define kNtMouseEvent            0x0002
#define kNtWindowBufferSizeEvent 0x0004
#define kNtMenuEvent             0x0008
#define kNtFocusEvent            0x0010
  union {
    struct NtKeyEventRecord KeyEvent;
    struct NtMouseEventRecord MouseEvent;
    struct NtWindowBufferSizeRecord WindowBufferSizeEvent;
    struct NtMenuEventRecord MenuEvent;
    struct NtFocusEventRecord FocusEvent;
  } Event;
};



/*!BEGIN libc/nt/struct/iocounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOCOUNTERS_H_

struct NtIoCounters {
  uint64_t ReadOperationCount;
  uint64_t WriteOperationCount;
  uint64_t OtherOperationCount;
  uint64_t ReadTransferCount;
  uint64_t WriteTransferCount;
  uint64_t OtherTransferCount;
};



/*!BEGIN libc/nt/struct/iostatusblock.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOSTATUSBLOCK_H_

struct NtIoStatusBlock {
  union {
    NtStatus Status;
    void *Pointer; /* reserved for internal use */
  };
  uint32_t *Information; /* request dependent */
};



/*!BEGIN libc/nt/struct/iovec.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct NtIovec {
  uint32_t len;
  char *buf;
};

void DescribeIovNt(const struct NtIovec *, uint32_t, ssize_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ipadapteraddresses.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IP_ADAPTER_ADDRESSES_H_


/*!BEGIN libc/nt/winsock.h */

#define COSMOPOLITAN_LIBC_NT_WINSOCK_H_


/*!BEGIN libc/nt/struct/overlapped.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPED_H_

struct NtOverlapped {
  uintptr_t Internal;
  uintptr_t InternalHigh;
  union {
    struct {
      uint32_t Offset;
      uint32_t OffsetHigh;
    };
    int64_t Pointer;
  };
  int64_t hEvent;
};



/*!BEGIN libc/nt/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POLLFD_H_

struct sys_pollfd_nt {
  int64_t handle;
  int16_t events;
  int16_t revents;
};



/*!BEGIN libc/nt/struct/timeval.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEVAL_H_
COSMOPOLITAN_C_START_

struct NtTimeval {
  int32_t tv_sec; /* [sic] */
  int32_t tv_usec;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thunk/msabi.h */

#define COSMOPOLITAN_LIBC_NT_THUNK_MSABI_H_
#ifdef __x86_64__

#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
     (__has_attribute(__ms_abi__) || defined(__llvm__)))
/**
 * Defines function as using Microsoft x64 calling convention.
 *
 * This can be used to define prototypes that allow modern compilers to
 * generate code that calls MS ABI functions directly, without needing
 * to jump through the assembly thunks.
 */
#define __msabi __attribute__((__ms_abi__))
#endif

/*
 * Returns true if header should provide MS-ABI overrides.
 */
#ifndef ShouldUseMsabiAttribute
#if defined(__msabi) && defined(NDEBUG) && !defined(__PG__) && !defined(FTRACE)
#define ShouldUseMsabiAttribute() 1
#else
#define ShouldUseMsabiAttribute() 0
#endif
#endif

#else
#define __msabi
#ifndef ShouldUseMsabiAttribute
#define ShouldUseMsabiAttribute() 0
#endif
#endif /* __x86_64__ */


/*!BEGIN libc/sock/sock.h */

#define COSMOPOLITAN_LIBC_SOCK_SOCK_H_
COSMOPOLITAN_C_START_

#define INET_ADDRSTRLEN 22
#define IFHWADDRLEN     6

libcesque uint16_t htons(uint16_t) pureconst;
libcesque uint16_t ntohs(uint16_t) pureconst;
libcesque uint32_t htonl(uint32_t) pureconst;
libcesque uint32_t ntohl(uint32_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define htons(x) __builtin_bswap16(x)
#define ntohs(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define ntohl(x) __builtin_bswap32(x)
#endif

const char *inet_ntop(int, const void *, char *, uint32_t) libcesque;
int inet_pton(int, const char *, void *) libcesque;
uint32_t inet_addr(const char *) libcesque;
libcesque uint32_t *GetHostIps(void) __wur;

int socket(int, int, int) libcesque;
int listen(int, int) libcesque;
int shutdown(int, int) libcesque;
ssize_t send(int, const void *, size_t, int) libcesque;
ssize_t recv(int, void *, size_t, int) libcesque;
ssize_t sendfile(int, int, int64_t *, size_t) libcesque;
int getsockopt(int, int, int, void *, uint32_t *) libcesque;
int setsockopt(int, int, int, const void *, uint32_t) libcesque;
int socketpair(int, int, int, int[2]) libcesque;
int sockatmark(int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/sockaddr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_H_
COSMOPOLITAN_C_START_

struct sockaddr {     /* Linux+NT ABI */
  uint16_t sa_family; /* AF_XXX */
  char sa_data[14];
};

struct in_addr { /* ARPA ABI */
  /* e.g. 127|0<<8|0<<16|1<<24 or inet_pton(AF_INET, "127.0.0.1", &s_addr) */
  uint32_t s_addr;
};

struct sockaddr_in {   /* Linux+NT ABI */
  uint16_t sin_family; /* AF_XXX */
  uint16_t sin_port;   /* htons(XXX) i.e. big endian */
  struct in_addr sin_addr;
  uint8_t sin_zero[8];
};

struct sockaddr_un {
  uint16_t sun_family; /* AF_UNIX */
  char sun_path[108];  /* path */
};

struct sockaddr_storage {
  union {
    uint16_t ss_family;
    intptr_t __ss_align;
    char __ss_storage[128];
  };
};

int inet_aton(const char *, struct in_addr *);
char *inet_ntoa(struct in_addr);
int accept(int, struct sockaddr *, uint32_t *);
int accept4(int, struct sockaddr *, uint32_t *, int);
int bind(int, const struct sockaddr *, uint32_t);
int connect(int, const struct sockaddr *, uint32_t);
int getsockname(int, struct sockaddr *, uint32_t *);
int getpeername(int, struct sockaddr *, uint32_t *);
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, uint32_t *);
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
               uint32_t);

COSMOPOLITAN_C_END_
/* ░▓█████████████████████████████████████████████▓▒
   ░█▓░░░░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒░
   ░█▓░ ░▒▒▒▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░ ░▓▓▓▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░       ░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒▒
   ░███████████████████████████████████████████████▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░          ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░             ▒█▓▒▒
   ░█▓░        ░▒░                 ▒█▓░          ▒█▓▒▒
   ░█▓░      ░░░░    ░░░░░░░░      ▒▓▓▓▒░        ▒█▓▒▒
   ░█▓░    ░░░░  ░░░░░▒▒▓███▓░░░░░░░░▒▓▓▓▓▒      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒████▓░░░░░░░░░░▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒▓▓▓▓▓░░░░░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▒▒▒░░░░░ ░▒▒▒▒░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓   ░▓█▓▒▒▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░░▒██▓   ░████▓▒░
   ░█▓░     ░░░░░░░░▒▒░░░░░░░░░▒▒░░░▒▒▓▓▒░░    ░░▓███▓▒░
   ░█▓░      ░░░░░░░░░░░░░░░░░░░░░░▒▓▓▓▒░        ▒████▓▒░░░░░░
   ░█▓░        ░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░        ░▓▓▓▓██▒░░░░░░░░
   ░█▓░          ▒█████████████████▒  ▓█▓▒░      ▒█▓ ░█▓      ░▓▓░
   ░█▓░                              ░▓████▒░    ▒█▓▒░  ░░░░░░░  ▓█▓░
   ░█▓░                                ░▓████▒░  ░▒░  ░░░░░░░░░░░  ░█▓
   ░█▓                                    ▒███▓▒▒░  ░░░░░░░░░░░░░░░  ▒▓▓
   ░██████████████████████████████████████▓▒▓█▓░  ░░░░░░░░░░░░░░░░░░ ▒█▓
    ▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░ ░░░░░░░░░░░░░░░░░░░░▒█▓
         ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒██▒▒▒░░░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░██▒▒▒▒▒░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░▒▓█▓
                                            ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░▒▒▒▒▓▓▒
                                              ░██▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  ░█▓
                                                 ▒█▓▒▒▒▒▒▒▒▒▒▒▒██▓▒░ ░█▓
                                                   ▒█████████████▓▒▒░  ░██▒
╔────────────────────────────────────────────────────────────────▀▀▀▀───▀▀▀▀─│─╗
│ cosmopolitan § new technology » winsock                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtWsaFlagOverlapped      0x01
#define kNtWsaFlagNoHandleInherit 0x80

#define kNtCompEqual   0
#define kNtCompNotless 1

#define kNtTfDisconnect       0x01
#define kNtTfReuseSocket      0x02
#define kNtTfWriteBehind      0x04
#define kNtTfUseDefaultWorker 0x00
#define kNtTfUseSystemThread  0x10
#define kNtTfUseKernelApc     0x20

#define kNtSoConnectTime          0x700C
#define kNtSoUpdateAcceptContext  0x700B
#define kNtSoUpdateConnectContext 0x7010

#define kNtNspNotifyImmediately 0
#define kNtNspNotifyHwnd        1
#define kNtNspNotifyEvent       2
#define kNtNspNotifyPort        3
#define kNtNspNotifyApc         4

COSMOPOLITAN_C_START_

struct NtMsgHdr {
  struct sockaddr *name;
  int32_t namelen;
  struct NtIovec *lpBuffers;
  uint32_t dwBufferCount;
  struct NtIovec Control;
  uint32_t dwFlags;
};

struct NtWsaData {
  uint16_t wVersion;
  uint16_t wHighVersion;
  uint16_t iMaxSockets;
  uint16_t iMaxUdpDg;
  char *lpVendorInfo;
  char szDescription[257];
  char szSystemStatus[129];
};

struct NtSocketAddress {
  struct sockaddr *lpSockaddr;
  int32_t iSockaddrLength;
};

struct NtSocketAddressList {
  int32_t iAddressCount;
  struct NtSocketAddress Address[1];
};

struct NtAddrInfoEx {  /* win8+ */
  int32_t ai_flags;    /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
  int32_t ai_family;   /* PF_XXX */
  int32_t ai_socktype; /* SOCK_XXX */
  int32_t ai_protocol;
  uint64_t ai_addrlen;
  char16_t *ai_canonname;
  struct sockaddr *ai_addr;
  void *ai_blob;
  uint64_t ai_bloblen;
  struct NtGuid *ai_provider;
  struct NtAddrInfoEx *ai_next;
  int32_t ai_version;          /* v2 */
  char16_t *ai_fqdn;           /* v2 */
  int32_t ai_interfaceindex;   /* v3 */
  int64_t ai_resolutionhandle; /* v4 */
};

struct NtWsaProtocolChain {
  int32_t ChainLen;
  uint32_t ChainEntries[7];
};

struct NtWsaProtocolInfo {
  uint32_t dwServiceFlags1;
  uint32_t dwServiceFlags2;
  uint32_t dwServiceFlags3;
  uint32_t dwServiceFlags4;
  uint32_t dwProviderFlags;
  struct NtGuid ProviderId;
  uint32_t dwCatalogEntryId;
  struct NtWsaProtocolChain ProtocolChain;
  int32_t iVersion;
  int32_t iAddressFamily;
  int32_t iMaxSockAddr;
  int32_t iMinSockAddr;
  int32_t iSocketType;
  int32_t iProtocol;
  int32_t iProtocolMaxOffset;
  int32_t iNetworkByteOrder;
  int32_t iSecurityScheme;
  uint32_t dwMessageSize;
  uint32_t dwProviderReserved;
  char16_t szProtocol[256];
};

struct NtFlowSpec {
  uint32_t TokenRate;          /* bytes/sec */
  uint32_t TokenBucketSize;    /* bytes */
  uint32_t PeakBandwidth;      /* bytes/sec */
  uint32_t Latency;            /* µs */
  uint32_t DelayVariation;     /* µs */
  uint32_t ServiceType;        /* kNtServicetypeXxx */
  uint32_t MaxSduSize;         /* bytes */
  uint32_t MinimumPolicedSize; /* bytes */
};

struct NtQos {
  struct NtFlowSpec SendingFlowspec;
  struct NtFlowSpec ReceivingFlowspec;
  struct NtIovec ProviderSpecific;
};

struct NtWsaVersion {
  uint32_t dwVersion;
  int ecHow;
};

struct NtAfProtocols {
  int32_t iAddressFamily;
  int32_t iProtocol;
};

struct NtBlob {
  uint32_t cbSize;
  uint8_t pBlobData;
};

struct NtCsAddrInfo {
  struct NtSocketAddress LocalAddr;
  struct NtSocketAddress RemoteAddr;
  int32_t iSocketType;
  int32_t iProtocol;
};

struct NtWsaQuerySet {
  uint32_t dwSize; /* of this */
  char16_t *lpszServiceInstanceName;
  struct NtGuid *lpServiceClassId;
  struct NtWsaVersion *lpVersion;
  char16_t *lpszComment;
  uint32_t dwNameSpace;
  struct NtGuid *lpNSProviderId;
  char16_t *lpszContext;
  uint32_t dwNumberOfProtocols;
  struct NtAfProtocols *lpafpProtocols /*[dwNumberOfProtocols]*/;
  char16_t *lpszQueryString;
  uint32_t dwNumberOfCsAddrs;
  struct NtCsAddrInfo *lpcsaBuffer /*[dwNumberOfCsAddrs]*/;
  uint32_t dwOutputFlags;
  struct NtBlob *lpBlob;
};

struct NtWsaNamespaceInfoEx {
  struct NtGuid NSProviderId;
  uint32_t dwNameSpace;
  bool32 fActive;
  uint32_t dwVersion;
  char16_t *lpszIdentifier;
  struct NtBlob *ProviderSpecific;
};

struct NtWsansClassInfo {
  char16_t *lpszName;
  uint32_t dwNameSpace;
  uint32_t dwValueType;
  uint32_t dwValueSize;
  void *lpValue;
};

struct NtWsaServiceClassInfo {
  struct NtGuid *lpServiceClassId;
  char16_t *lpszServiceClassName;
  uint32_t dwCount;
  struct NtWsansClassInfo *lpClassInfos;
};

struct NtWsaNetworkEvents {
  int32_t lNetworkEvents;
  int32_t iErrorCode[10];
};

struct NtTransmitFileBuffers {
  void *Head;
  uint32_t HeadLength;
  void *Tail;
  uint32_t TailLength;
};

typedef int (*NtConditionProc)(
    const struct NtIovec *lpCallerId, const struct NtIovec *lpCallerData,
    struct NtQos *inout_lpSQOS, struct NtQos *inout_lpGQOS,
    const struct NtIovec *lpCalleeId, const struct NtIovec *lpCalleeData,
    uint32_t *out_group, const uint32_t *dwCallbackData);

typedef void (*NtWsaOverlappedCompletionRoutine)(
    uint32_t dwError, uint32_t cbTransferred,
    const struct NtOverlapped *lpOverlapped, uint32_t dwFlags);

struct NtWsaCompletion {
  int Type;
  union {
    struct {
      int64_t hWnd;
      uint32_t uMsg;
      uintptr_t context;
    } WindowMessage;
    struct {
      struct NtOverlapped *lpOverlapped;
    } Event;
    struct {
      struct NtOverlapped *lpOverlapped;
      NtWsaOverlappedCompletionRoutine lpfnCompletionProc;
    } Apc;
    struct {
      struct NtOverlapped *lpOverlapped;
      int64_t hPort;
      uint32_t Key;
    } Port;
  } Parameters;
};

struct NtInterfaceInfo {
  uint64_t iiFlags;
  struct sockaddr_in iiAddress;
  struct sockaddr_in iiBroadcastAddress;
  struct sockaddr_in iiNetmask;
};

/**
 * Winsock2 prototypes.
 *
 * @note Some of the functions exported by WS2_32.DLL, e.g. bind(),
 *       overlap with the names used by System V. Prototypes for these
 *       functions are declared within their respective wrappers.
 */

int32_t WSAStartup(uint16_t wVersionRequested, struct NtWsaData *lpWSAData)
    paramsnonnull();

int WSACleanup(void);
int WSAGetLastError(void) nosideeffect;
void WSASetLastError(int);

int64_t __sys_socket_nt(int, int, int);
int __sys_bind_nt(uint64_t, const void *, int);
int __sys_closesocket_nt(uint64_t);
int __sys_getpeername_nt(uint64_t, void *, uint32_t *);
int __sys_getsockname_nt(uint64_t, void *, uint32_t *);
int __sys_getsockopt_nt(uint64_t, int, int, void *, uint32_t *);
int __sys_ioctlsocket_nt(uint64_t, int32_t, uint32_t *);
int __sys_listen_nt(uint64_t, int);
int __sys_setsockopt_nt(uint64_t, int, int, const void *, int);
int __sys_shutdown_nt(uint64_t, int);
int __sys_select_nt(int, struct NtFdSet *, struct NtFdSet *, struct NtFdSet *,
                    struct NtTimeval *);

uint64_t WSASocket(int af, int type, int protocol,
                   const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                   const uint32_t opt_group, uint32_t dwFlags) __wur;

int WSAConnect(uint64_t s, const struct sockaddr *name, const int namelen,
               const struct NtIovec *opt_lpCallerData,
               struct NtIovec *opt_out_lpCalleeData,
               const struct NtQos *opt_lpSQOS, const struct NtQos *opt_lpGQOS)
    paramsnonnull((2));

bool32 WSAConnectByName(uint64_t s, const char16_t *nodename,
                        const char16_t *servicename,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2, 3));

bool32 WSAConnectByList(uint64_t s,
                        const struct NtSocketAddressList *SocketAddress,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2));

int64_t WSAAccept(uint64_t s, struct sockaddr *out_addr,
                  int32_t *opt_inout_addrlen,
                  const NtConditionProc opt_lpfnCondition,
                  const uint32_t *opt_dwCallbackData) paramsnonnull((2)) __wur;

int WSASend(uint64_t s, const struct NtIovec *lpBuffers, uint32_t dwBufferCount,
            uint32_t *opt_out_lpNumberOfBytesSent, uint32_t dwFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendMsg(int64_t Handle, const struct NtMsgHdr *lpMsg, uint32_t dwFlags,
               uint32_t *opt_out_lpNumberOfBytesSent,
               struct NtOverlapped *opt_inout_lpOverlapped,
               const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendTo(uint64_t s, const struct NtIovec *lpBuffers,
              uint32_t dwBufferCount,
              uint32_t *opt_out_lpNumberOfBytesSent /* opt if !overlapped */,
              uint32_t dwFlags, const void *opt_tosockaddr,
              int32_t tosockaddrlen,
              struct NtOverlapped *opt_inout_lpOverlapped,
              const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSAPoll(struct sys_pollfd_nt *inout_fdArray, uint32_t nfds,
            signed timeout_ms) paramsnonnull();

int WSARecv(uint64_t s, const struct NtIovec *inout_lpBuffers,
            uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
            uint32_t *inout_lpFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvFrom(uint64_t s, const struct NtIovec *inout_lpBuffers,
                uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
                uint32_t *inout_lpFlags, void *out_fromsockaddr,
                uint32_t *opt_inout_fromsockaddrlen,
                struct NtOverlapped *opt_inout_lpOverlapped,
                const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvDisconnect(uint64_t s, struct NtIovec *out_InboundDisconnectData);
int WSASendDisconnect(int64_t s, struct NtIovec *opt_OutboundDisconnectData);

int WSADuplicateSocket(uint64_t s, uint32_t dwProcessId,
                       struct NtWsaProtocolInfo *out_lpProtocolInfo)
    paramsnonnull((3));

int WSAIoctl(uint64_t s, uint32_t dwIoControlCode, const void *lpvInBuffer,
             uint32_t cbInBuffer, void *out_lpvOutBuffer, uint32_t cbOutBuffer,
             uint32_t *out_lpcbBytesReturned,
             struct NtOverlapped *opt_inout_lpOverlapped,
             const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((5, 7));

int WSANSPIoctl(int64_t hLookup, uint32_t dwControlCode,
                const void *lpvInBuffer, uint32_t cbInBuffer,
                void *out_lpvOutBuffer, uint32_t cbOutBuffer,
                uint32_t *out_lpcbBytesReturned,
                const struct NtWsaCompletion *opt_lpCompletion)
    paramsnonnull((3, 5, 7));

int64_t WSACreateEvent(void) __wur;
bool32 WSACloseEvent(const int64_t hEvent);
bool32 WSAResetEvent(const int64_t hEvent);
bool32 WSASetEvent(const int64_t hEvent);

int WSAEventSelect(uint64_t s, const int64_t opt_hEventObject,
                   long lNetworkEvents);

uint32_t WSAWaitForMultipleEvents(uint32_t cEvents, const int64_t *lphEvents,
                                  bool32 fWaitAll, uint32_t dwTimeout_ms,
                                  bool32 fAlertable) paramsnonnull();

int WSAEnumNetworkEvents(uint64_t s, const int64_t hEventObject,
                         struct NtWsaNetworkEvents *out_lpNetworkEvents)
    paramsnonnull();

bool32 WSAGetOverlappedResult(uint64_t s,
                              const struct NtOverlapped *lpOverlapped,
                              uint32_t *out_lpcbTransfer, bool32 fWait,
                              uint32_t *out_lpdwFlags) paramsnonnull();

int WSAEnumProtocols(const int32_t *opt_lpiProtocols,
                     struct NtWsaProtocolInfo *out_lpProtocolBuffer,
                     uint32_t *inout_lpdwBufferLength) paramsnonnull();

bool32 WSAGetQOSByName(uint64_t s, const struct NtIovec *lpQOSName,
                       struct NtQos *out_lpQOS) paramsnonnull();

uint64_t WSAJoinLeaf(uint64_t s, const struct sockaddr *name, const int namelen,
                     const struct NtIovec *opt_lpCallerData,
                     struct NtIovec *opt_out_lpCalleeData,
                     const struct NtQos *opt_lpSQOS,
                     const struct NtQos *opt_lpGQOS, uint32_t dwFlags)
    paramsnonnull((2, 4));

int WSALookupServiceBegin(const struct NtWsaQuerySet *lpqsRestrictions,
                          uint32_t dwControlFlags, int64_t *out_lphLookup)
    paramsnonnull();

int WSALookupServiceNext(const int64_t hLookup, uint32_t dwControlFlags,
                         uint32_t *inout_lpdwBufferLength,
                         struct NtWsaQuerySet *out_lpqsResults) paramsnonnull();

int WSALookupServiceEnd(int64_t hLookup);

int WSAAddressToString(const struct sockaddr *lpsaAddress,
                       uint32_t dwAddressLength,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       char16_t *out_lpszAddressString,
                       uint32_t *inout_lpdwAddressStringLength)
    paramsnonnull((1, 4, 5));

int WSAStringToAddress(const char16_t *AddressString, int AddressFamily,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       struct sockaddr *out_lpAddress,
                       int *inout_lpAddressLength) paramsnonnull((1, 3, 4));

int WSAEnumNameSpaceProvidersEx(uint32_t *inout_lpdwBufferLength,
                                struct NtWsaNamespaceInfoEx *out_lpnspBuffer)
    paramsnonnull();

int WSAProviderConfigChange(
    int64_t *inout_lpNotificationHandle,
    struct NtOverlapped *opt_inout_lpOverlapped,
    NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((1));

int WSAInstallServiceClass(
    const struct NtWsaServiceClassInfo *lpServiceClassInfo) paramsnonnull();

int WSARemoveServiceClass(const struct NtGuid *lpServiceClassId)
    paramsnonnull();

int WSAGetServiceClassInfo(const struct NtGuid *lpProviderId,
                           const struct NtGuid *lpServiceClassId,
                           uint32_t *inout_lpdwBufSize,
                           struct NtWsaServiceClassInfo *out_lpServiceClassInfo)
    paramsnonnull((1, 2, 3));

int WSASetService(const struct NtWsaQuerySet *lpqsRegInfo, int essoperation,
                  uint32_t dwControlFlags) paramsnonnull();

int /* success==0 */ WSAGetServiceClassNameByClassId(
    const struct NtGuid *lpServiceClassId, char16_t *out_lpszServiceClassName,
    uint32_t *inout_lpdwBufferLength) paramsnonnull();

void GetAcceptExSockaddrs(
    const void *lpOutputBuffer /*[recvsize+addrsize+addrlen]*/,
    uint32_t dwReceiveDataLength, uint32_t dwLocalAddressLength,
    uint32_t dwRemoteAddressLength,
    struct sockaddr **out_LocalSockaddr /*[*LocalSockaddrLength]*/,
    int *out_LocalSockaddrLength,
    struct sockaddr **out_RemoteSockaddr /*[*RemoteSockaddrLength]*/,
    int *out_RemoteSockaddrLength);

bool32 DisconnectEx(int64_t s, struct NtOverlapped *inout_opt_lpOverlapped,
                    uint32_t dwFlags, uint32_t dwReserved);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/winsock.inc */

extern typeof(WSAGetLastError) *const __imp_WSAGetLastError __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_

/* Constants ----------------------------------------------------------- */

#define kNtMaxAdapterAddressLength  8
#define kNtMaxDnsSuffixStringLength 256
#define kNtMaxDhcpv6DuidLength      130

/* Values for the 'Flags' parameter of GetAdaptersAddresses */
#define kNtGaaFlagSkipUnicast               0x0001
#define kNtGaaFlagSkipAnycast               0x0002
#define kNtGaaFlagSkipMulticast             0x0004
#define kNtGaaFlagSkipDnsServer             0x0008
#define kNtGaaFlagIncludePrefix             0x0010
#define kNtGaaFlagSkipFriendlyName          0x0020
#define kNtGaaFlagIncludeWinsInfo           0x0040
#define kNtGaaFlagIncludeGateways           0x0080
#define kNtGaaFlagIncludeAllInterfaces      0x0100
#define kNtGaaFlagIncludeAllCompartments    0x0200
#define kNtGaaFlagIncludeTunnelBindingorder 0x0400
#define kNtGaaFlagSkipDnsInfo               0x0800

/* Values for the IfType parameter
 * See:
 * https://docs.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_addresses_lh
 */
#define kNtIfTypeOther             1
#define kNtIfTypeEthernetCsmacd    6
#define kNtIfTypeIso88025Tokenring 9
#define kNtIfTypePpp               23
#define kNtIfTypeSoftwareLoopback  24
#define kNtIfTypeAtm               37
#define kNtIfTypeIeee80211         71 /* wifi */
#define kNtIfTypeTunnel            131
#define kNtIfTypeIeee1394          144 /* firewire */

#define kNtIpAdapterDdnsEnabled             0x0001
#define kNtIpAdapterRegisterAdapterSuffix   0x0002
#define kNtIpAdapterDhcpv4Enabled           0x0004
#define kNtIpAdapterReceiveOnly             0x0008
#define kNtIpAdapterNoMulticast             0x0010
#define kNtIpAdapterIpv6OtherStatefulConfig 0x0020
#define kNtIpAdapterNetbiosOverTcpipEnabled 0x0040
#define kNtIpAdapterIpv4Enabled             0x0080
#define kNtIpAdapterIpv6Enabled             0x0100
#define kNtIpAdapterIpv6Managed             0x0200

#define kNtIpPrefixOriginOther               0
#define kNtIpPrefixOriginManual              1
#define kNtIpPrefixOriginWellKnown           2
#define kNtIpPrefixOriginDhcp                3
#define kNtIpPrefixOriginRouterAdvertisement 4
#define kNtIpPrefixOriginUnchanged           16

#define kNtIpSuffixOriginOther            0
#define kNtIpSuffixOriginManual           1
#define kNtIpSuffixOriginWellKnown        2
#define kNtIpSuffixOriginDhcp             3
#define kNtIpSuffixOriginLinkLayerAddress 4
#define kNtIpSuffixOriginRandom           5
#define kNtIpSuffixOriginUnchanged        16

#define kNtIpDadStateInvalid    0
#define kNtIpDadStateTentative  1
#define kNtIpDadStateDuplicate  2
#define kNtIpDadStateDeprecated 3
#define kNtIpDadStatePreferred  4

#define kNtIfOperStatusUp             1
#define kNtIfOperStatusDown           2
#define kNtIfOperStatusTesting        3
#define kNtIfOperStatusUnknown        4
#define kNtIfOperStatusDormant        5
#define kNtIfOperStatusNotPresent     6
#define kNtIfOperStatusLowerLayerDown 7

#define kNtNetIfConnectionDedicated 1
#define kNtNetIfConnectionPassive   2
#define kNtNetIfConnectionDemand    3
#define kNtNetIfConnectionMaximum   4

#define kNtTunnelTypeNone    0
#define kNtTunnelTypeOther   1
#define kNtTunnelTypeDirect  2
#define kNtTunnelType6to4    11
#define kNtTunnelTypeIsatap  13
#define kNtTunnelTypeTeredo  14
#define kNtTunnelTypeIphttps 15

COSMOPOLITAN_C_START_

/* Inner Types --------------------------------------------------------- */

struct NtIpAdapterUnicastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterUnicastAddress *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixOrigin; /* kNtIpPrefixOrigin... */
  uint32_t SuffixOrigin; /* kNtIpSuffixOrigin... */
  uint32_t DadState;     /* kNtIpDadState... */
  uint32_t ValidLifetime;
  uint32_t PreferredLifetime;
  uint32_t LeaseLifetime;
  uint8_t OnLinkPrefixLength;
};

struct NtIpAdapterAnycastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterAnycastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterMulticastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterMulticastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterDnsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterPrefix {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterPrefix *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixLength;
};

struct NtIpAdapterWinsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterWinsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterGatewayAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterGatewayAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsSuffix {
  struct NtIpAdapterDnsSuffix *Next;
  uint16_t String[kNtMaxDnsSuffixStringLength];
};

/* Top level ----------------------------------------------------------- */

struct NtIpAdapterAddresses {
  uint32_t Length;
  uint32_t IfIndex;
  struct NtIpAdapterAddresses *Next;
  char *AdapterName;
  struct NtIpAdapterUnicastAddress *FirstUnicastAddress;
  struct NtIpAdapterAnycastAddress *FirstAnycastAddress;
  struct NtIpAdapterMulticastAddress *FirstMulticastAddress;
  struct NtIpAdapterDnsServerAddress *FirstDnsServerAddress;
  uint16_t *DnsSuffix;
  uint16_t *Description;
  uint16_t *FriendlyName;
  uint8_t PhysicalAddress[kNtMaxAdapterAddressLength];
  uint32_t PhysicalAddressLength;
  uint32_t Flags; /* kNtIpAdapter... */
  uint32_t Mtu;
  uint32_t IfType;     /* kNtIfType... */
  uint32_t OperStatus; /* kNtIfOperStatus... */
  uint32_t Ipv6IfIndex;
  uint32_t ZoneIndices[16];
  struct NtIpAdapterPrefix *FirstPrefix;
  uint64_t TransmitLinkSpeed;
  uint64_t ReceiveLinkSpeed;
  struct NtIpAdapterWinsServerAddress *FirstWinsServerAddress;
  struct NtIpAdapterGatewayAddress *FirstGatewayAddress;
  uint32_t Ipv4Metric;
  uint32_t Ipv6Metric;
  uint64_t Luid; /* reserved(24bits),NetLuidIndex(24b),IfType(16b) */
  struct NtSocketAddress Dhcpv4Server;
  uint32_t CompartmentId;
  struct NtGuid NetworkGuid;
  uint32_t ConnectionType; /* kNtNetIfConnection... */
  uint32_t TunnelType;     /* kNtTunnelType... */
  struct NtSocketAddress Dhcpv6Server;
  uint8_t Dhcpv6ClientDuid[kNtMaxDhcpv6DuidLength];
  uint32_t Dhcpv6ClientDuidLength;
  uint32_t Dhcpv6Iaid;
  struct NtIpAdapterDnsSuffix *FirstDnsSuffix;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/kernelusertimes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_KERNELUSERTIMES_H_

struct NtKernelUserTimes {
  uint64_t CreateFileTime;
  uint64_t ExitFileTime;
  int64_t KernelTime;
  int64_t UserTime;
};



/*!BEGIN libc/nt/struct/ldr.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDR_H_

struct NtLdr {
  uint32_t SizeOfThis;                       /* msdn:reserved */
  uint32_t IsInitialized;                    /* msdn:reserved */
  void *SsHandle;                            /* msdn:reserved */
  struct NtLinkedList InLoadOrderModuleList; /* msdn:reserved */
  struct NtLinkedList /*∩NtLdrDataTableEntry*/ InMemoryOrderModuleList;
  struct NtLinkedList InInitOrderModuleList; /* msdn:reserved */
};



/*!BEGIN libc/nt/struct/ldrdatatableentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDRDATATABLEENTRY_H_


/*!BEGIN libc/nt/struct/unicodestring.h */

#define COSMOPOLITAN_LIBC_NT_UNICODE_H_

struct NtUnicodeString {
  uint16_t Length;
  uint16_t MaxLength;
  char16_t *Data;
};


struct NtLdrDataTableEntry {
  struct NtLinkedList InLoadOrderLinks; /* msdn:reserved */
  struct NtLinkedList InMemoryOrderLinks;
  struct NtLinkedList InInitOrderLinks; /* msdn:reserved */
  void *DllBase;
  void *EntryPoint;
  union {
    uint32_t SizeOfImage;
    unsigned char SizeOfImagePadding[__SIZEOF_POINTER__];
  };
  struct NtUnicodeString FullDllName;
  struct NtUnicodeString BaseDllName;
  uint32_t Flags;
  uint16_t Load_Count;
  uint16_t TlsIndex;
  union {
    struct NtLinkedList HashLinks;
    struct {
      void *SectionPointer;
      uint32_t CheckSum;
    };
  };
  union {
    void *LoadedImports;
    uint32_t TimeDateStamp;
  };
  void *EntryPointActivationContext;
  void *PatchInformation;
  struct NtLinkedList ForwarderLinks;
  struct NtLinkedList ServiceTagLinks;
  struct NtLinkedList StaticLinks;
  void *ContextInformation;
  uintptr_t OriginalBase;
  int64_t LoadTime;
};



/*!BEGIN libc/nt/struct/linger.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger_nt {
  uint16_t l_onoff;  /* on/off */
  uint16_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/luid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUID_H_

struct NtLuid {
  uint32_t LowPart;
  int32_t HighPart;
};



/*!BEGIN libc/nt/struct/luidandattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUIDANDATTRIBUTES_H_

struct NtLuidAndAttributes {
  struct NtLuid Luid;
  uint32_t Attributes;
};



/*!BEGIN libc/nt/struct/memextendedparameter.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMEXTENDEDPARAMETER_H_

#define kNtMemExtendedParameterTypeBits 8

#define kNtMemExtendedParameterInvalidType         0
#define kNtMemExtendedParameterAddressRequirements 1
#define kNtMemExtendedParameterNumaNode            2
#define kNtMemExtendedParameterPartitionHandle     3
#define kNtMemExtendedParameterUserPhysicalHandle  4
#define kNtMemExtendedParameterAttributeFlags      5
#define kNtMemExtendedParameterMax                 6

#define kNtMemExtendedParameterGraphics          0x00000001
#define kNtMemExtendedParameterNonpaged          0x00000002
#define kNtMemExtendedParameterZeroPagesOptional 0x00000004
#define kNtMemExtendedParameterNonpagedLarge     0x00000008
#define kNtMemExtendedParameterNonpagedHuge      0x00000010

struct NtMemExtendedParameter {
  struct {
    uint64_t Type : kNtMemExtendedParameterTypeBits;
    uint64_t Reserved : 64 - kNtMemExtendedParameterTypeBits;
  } DUMMYSTRUCTNAME;
  union {
    uint64_t ULong64;
    void *Pointer;
    size_t Size;
    intptr_t Handle;
    unsigned ULong;
  } DUMMYUNIONNAME;
};



/*!BEGIN libc/nt/struct/memorybasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYBASICINFORMATION_H_

struct NtMemoryBasicInformation {
  void *BaseAddress;
  void *AllocationBase;
  uint32_t AllocationProtect;
  uint64_t RegionSize;
  uint32_t State;
  uint32_t Protect;
  uint32_t Type;
};



/*!BEGIN libc/nt/struct/memoryrangeentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYRANGEENTRY_H_

struct NtMemoryRangeEntry {
  void *VirtualAddress;
  size_t NumberOfBytes;
};



/*!BEGIN libc/nt/struct/memorystatusex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYSTATUSEX_H_

struct NtMemoryStatusEx {
  uint32_t dwLength;
  uint32_t dwMemoryLoad;
  uint64_t ullTotalPhys;
  uint64_t ullAvailPhys;
  uint64_t ullTotalPageFile;
  uint64_t ullAvailPageFile;
  uint64_t ullTotalVirtual;
  uint64_t ullAvailVirtual;
  uint64_t ullAvailExtendedVirtual;
};



/*!BEGIN libc/nt/struct/msg.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MSG_H_


/*!BEGIN libc/nt/struct/point.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POINT_H_

struct NtPoint {
  int32_t x;
  int32_t y;
};


struct NtMsg {
  int64_t hwnd;
  uint32_t dwMessage;
  uint64_t wParam;
  int64_t lParam;
  uint32_t dwTime;
  struct NtPoint pt;
};



/*!BEGIN libc/nt/struct/nonpageddebuginfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NONPAGEDDEBUGINFO_H_

struct NtNonPagedDebugInfo {
  uint16_t Signature;
  uint16_t Flags;
  uint32_t Size;
  uint16_t Machine;
  uint16_t Characteristics;
  uint32_t TimeDateStamp;
  uint32_t CheckSum;
  uint32_t SizeOfImage;
  uint64_t ImageBase;
};



/*!BEGIN libc/nt/struct/ntexceptionpointers.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONPOINTERS_H_


/*!BEGIN libc/nt/struct/ntexceptionrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONRECORD_H_

#define kNtExceptionMaximumParameters 15
#define kNtExceptionNoncontinuable    1


struct NtExceptionRecord {
  uint32_t ExceptionCode;                    /* kNtException... */
  uint32_t ExceptionFlags;                   /* kNtExceptionNoncontinuable */
  struct NtExceptionRecord *ExceptionRecord; /* nested exceptions */
  void *ExceptionAddress;                    /* %rip */
  uint32_t NumberParameters;                 /* #ExceptionInformation */
  uint64_t ExceptionInformation[kNtExceptionMaximumParameters];
};


struct NtExceptionPointers {
  struct NtExceptionRecord *ExceptionRecord;
  struct NtContext *ContextRecord;
};



/*!BEGIN libc/nt/struct/objectallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTALLINFORMATION_H_


/*!BEGIN libc/nt/struct/objecttypeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTTYPEINFORMATION_H_

struct NtObjectTypeInformation {
  struct NtUnicodeString TypeName;
  uint32_t TotalNumberOfObjects;
  uint32_t TotalNumberOfHandles;
  uint32_t TotalPagedPoolUsage;
  uint32_t TotalNonPagedPoolUsage;
  uint32_t TotalNamePoolUsage;
  uint32_t TotalHandleTableUsage;
  uint32_t HighWaterNumberOfObjects;
  uint32_t HighWaterNumberOfHandles;
  uint32_t HighWaterPagedPoolUsage;
  uint32_t HighWaterNonPagedPoolUsage;
  uint32_t HighWaterNamePoolUsage;
  uint32_t HighWaterHandleTableUsage;
  uint32_t InvalidAttributes;
  struct NtGenericMapping GenericMapping;
  uint32_t ValidAccessMask;
  bool32 SecurityRequired;
  bool32 MaintainHandleCount;
  uint32_t PoolType;
  uint32_t DefaultPagedPoolCharge;
  uint32_t DefaultNonPagedPoolCharge;
};


struct NtObjectAllInformation {
  uint32_t NumberOfObjects;
  struct NtObjectTypeInformation ObjectTypeInformation[1];
};



/*!BEGIN libc/nt/struct/objectattributes.h */

#define COSMOPOLITAN_LIBC_NT_I_OBJECTATTRIBUTES_H_


/*!BEGIN libc/nt/struct/rtluserprocessparameters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSPARAMETERS_H_

struct NtRtlUserProcessParameters {
  uint32_t MaximumLength;
  uint32_t Length;
  uint32_t Flags;
  uint32_t DebugFlags;
  int64_t ConsoleHandle;
  uint32_t ConsoleFlags;
  int64_t StdInputHandle;
  int64_t StdOutputHandle;
  int64_t StdErrorHandle;
  struct NtUnicodeString *CurrentDirectoryPath;
  int64_t CurrentDirectoryHandle;
  struct NtUnicodeString *DllPath;
  struct NtUnicodeString *ImagePathName;
  struct NtUnicodeString *CommandLine;
  void *Environment;
  uint32_t StartingPositionLeft;
  uint32_t StartingPositionTop;
  uint32_t Width;
  uint32_t Height;
  uint32_t CharWidth;
  uint32_t CharHeight;
  uint32_t ConsoleTextAttributes;
  uint32_t WindowFlags;
  uint32_t ShowWindowFlags;
  struct NtUnicodeString *WindowTitle;
  struct NtUnicodeString *DesktopName;
  struct NtUnicodeString *ShellInfo;
  struct NtUnicodeString *RuntimeData;
};



/*!BEGIN libc/nt/struct/securityattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYATTRIBUTES_H_


/*!BEGIN libc/nt/struct/securitydescriptor.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYDESCRIPTOR_H_

struct NtSecurityDescriptor {
  uint8_t Revision;
  uint8_t Sbz1;
  uint16_t Control;
  void *Owner;
  void *Group;
  struct NtAcl *Sacl;
  struct NtAcl *Dacl;
};


struct NtSecurityAttributes {
  uint32_t nLength;
  struct NtSecurityDescriptor *lpSecurityDescriptor;
  bool32 bInheritHandle;
};

const char *DescribeNtSecurityAttributes(char[32],
                                         const struct NtSecurityAttributes *);
#define DescribeNtSecurityAttributes(x) \
  DescribeNtSecurityAttributes(alloca(32), x)


struct NtObjectAttributes {
  uint32_t Length;
  int64_t RootDirectory;
  const struct NtUnicodeString *ObjectName;
  uint32_t Attributes; /* OBJ_INHERIT, etc. */
  struct NtSecurityDescriptor *SecurityDescriptor;
  void *SecurityQualityOfService;
};



/*!BEGIN libc/nt/struct/objectbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTBASICINFORMATION_H_

struct NtObjectBasicInformation {
  uint32_t Attributes;
  uint32_t GrantedAccess;
  uint32_t HandleCount;
  uint32_t PointerCount;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t Reserved[3];
  uint32_t NameInformationLength;
  uint32_t TypeInformationLength;
  uint32_t SecurityDescriptorLength;
  int64_t CreateTime;
};



/*!BEGIN libc/nt/struct/objectnameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTNAMEINFORMATION_H_

struct NtObjectNameInformation {
  struct NtUnicodeString Name;
};



/*!BEGIN libc/nt/struct/openfilename.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OPENFILENAME_H_

struct NtOpenFilename {
  uint32_t lStructSize;
  int64_t hwndOwner;
  int64_t hInstance;
  const char16_t *lpstrFilter;
  char16_t *lpstrCustomFilter;
  uint32_t nMaxCustFilter;
  uint32_t nFilterIndex;
  char16_t *lpstrFile;
  uint32_t nMaxFile;
  char16_t *lpstrFileTitle;
  uint32_t nMaxFileTitle;
  const char16_t *lpstrInitialDir;
  const char16_t *lpstrTitle;
  uint32_t Flags;
  uint16_t nFileOffset;
  uint16_t nFileExtension;
  const char16_t *lpstrDefExt;
  intptr_t lCustData;
  uint64_t (*lpfnHook)(int64_t, uint32_t, uint64_t, int64_t);
  const char16_t *lpTemplateName;
  void *pvReserved;
  uint32_t dwReserved;
  uint32_t FlagsEx;
};



/*!BEGIN libc/nt/struct/osversioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OSVERSIONINFO_H_
COSMOPOLITAN_C_START_

struct NtOsVersionInfo {
  uint32_t dwOSVersionInfoSize;
  uint32_t dwMajorVersion;
  uint32_t dwMinorVersion;
  uint32_t dwBuildNumber;
  uint32_t dwPlatformId;
  char16_t szCSDVersion[128];
  uint16_t wServicePackMajor;
  uint16_t wServicePackMinor;
  uint16_t wSuiteMask;
  uint8_t wProductType;
  uint8_t wReserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/overlappedentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPEDENTRY_H_
COSMOPOLITAN_C_START_

struct NtOverlappedEntry {
  uint64_t lpCompletionKey;
  struct NtOverlapped *lpOverlapped;
  uint32_t *Internal;
  uint32_t dwNumberOfBytesTransferred;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/paintstruct.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PAINTSTRUCT_H_


/*!BEGIN libc/nt/struct/rect.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RECT_H_

struct NtRect {
  int32_t left;
  int32_t top;
  int32_t right;
  int32_t bottom;
};


struct NtPaintStruct {
  int64_t hdc;
  bool32 fErase;
  struct NtRect rcPaint;
  bool32 fRestore;
  bool32 fIncUpdate;
  uint8_t rgbReserved[32];
};



/*!BEGIN libc/nt/struct/pdhfmtcountervalue.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PDHFMTCOUNTERVALUE_H_
COSMOPOLITAN_C_START_

struct NtPdhFmtCountervalue {
  uint32_t CStatus;
  union {
    int32_t longValue;
    double doubleValue;
    int64_t largeValue;
    const char *AnsiStringValue;
    const char16_t *WideStringValue;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/peb.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PEB_H_

struct NtPeb {
  union {
    struct {
      unsigned char InheritedAddressSpace;
      unsigned char ReadImageFileExecOptions;
      unsigned char BeingDebugged;
      unsigned char __wut1;
    };
    uint64_t __wut2;
  };
  uint64_t Mutant;
  uint64_t ImageBaseAddress;
  struct NtLdr *Ldr;
  uint64_t ProcessParameters;
  uint64_t SubSystemData;
  uint64_t ProcessHeap;
  uint64_t FastPebLock;
  uint64_t __wut3;
  uint64_t __wut4;
  uint64_t __wut5;
  union {
    uint64_t KernelCallbackTable;
    uint64_t UserSharedInfoPtr;
  };
  uint32_t SystemReserved;
  uint32_t __wut6;
  uint64_t __wut7;
  uint64_t TlsExpansionCounter;
  uint64_t TlsBitmap;
  uint32_t TlsBitmapBits[2];
  uint64_t ReadOnlySharedMemoryBase;
  uint64_t __wut8;
  uint64_t ReadOnlyStaticServerData;
  uint64_t AnsiCodePageData;
  uint64_t OemCodePageData;
  uint64_t UnicodeCaseTableData;
  uint32_t NumberOfProcessors;
#ifdef __x86_64__
  uint32_t NtGlobalFlag;
#else
  uint64_t NtGlobalFlag;
#endif
  int64_t CriticalSectionTimeout;
  uint64_t HeapSegmentReserve;
  uint64_t HeapSegmentCommit;
  uint64_t HeapDeCommitTotalFreeThreshold;
  uint64_t HeapDeCommitFreeBlockThreshold;
  uint32_t NumberOfHeaps;
  uint32_t MaximumNumberOfHeaps;
  uint64_t ProcessHeaps;
  uint64_t GdiSharedHandleTable;
  uint64_t ProcessStarterHelper;
  uint64_t GdiDCAttributeList;
  uint64_t LoaderLock;
  union {
    struct {
      uint32_t OSMajorVersion;
      uint32_t OSMinorVersion;
    };
    uint64_t OSVersion;
  };
  uint16_t OSBuildNumber;
  uint16_t OSCSDVersion;
  uint32_t OSPlatformId;
  uint32_t ImageSubsystem;
  uint32_t ImageSubsystemMajorVersion;
  uint64_t ImageSubsystemMinorVersion;
  union {
    uint64_t ImageProcessAffinityMask;
    uint64_t ActiveProcessAffinityMask;
  };
  uint64_t GdiHandleBuffer[38 - __SIZEOF_POINTER__];
  uint64_t PostProcessInitRoutine;
  uint64_t TlsExpansionBitmap;
  uint32_t TlsExpansionBitmapBits[32];
  uint64_t SessionId;
  uint64_t AppCompatFlags;
  uint64_t AppCompatFlagsUser;
  uint64_t pShimData;
  uint64_t AppCompatInfo;
  struct NtUnicodeString CSDVersion;
  uint64_t ActivationContextData;
  uint64_t ProcessAssemblyStorageMap;
  uint64_t SystemDefaultActivationContextData;
  uint64_t SystemAssemblyStorageMap;
  uint64_t MinimumStackCommit;
};



/*!BEGIN libc/nt/struct/privilegeset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PRIVILEGESET_H_

struct NtPrivilegeSet {
  uint32_t PrivilegeCount;
  uint32_t Control;
  struct NtLuidAndAttributes Privilege[1];
};



/*!BEGIN libc/nt/struct/processbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSBASICINFORMATION_H_

struct NtProcessBasicInformation {
  int32_t ExitStatus;
  struct NtPeb *PebBaseAddress;
  uint32_t *AffinityMask;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
};



/*!BEGIN libc/nt/struct/processentry32.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSENTRY32_H_

struct NtProcessEntry32 {
  uint32_t dwSize;
  uint32_t cntUsage; /* unused */
  uint32_t th32ProcessID;
  uint64_t th32DefaultHeapID; /* unused */
  uint32_t th32ModuleID;      /* unused */
  uint32_t cntThreads;
  uint32_t th32ParentProcessID;
  int32_t cPriClassBase;
  uint32_t dwFlags; /* unused */
  char16_t szExeFile[260];
};



/*!BEGIN libc/nt/struct/processinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSINFORMATION_H_

struct NtProcessInformation {
  int64_t hProcess;
  int64_t hThread;
  uint32_t dwProcessId;
  uint32_t dwThreadId;
};



/*!BEGIN libc/nt/struct/processmemorycounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSMEMORYCOUNTERS_H_
COSMOPOLITAN_C_START_

struct NtProcessMemoryCountersEx {
  uint32_t cb; /* count bytes */
  uint32_t PageFaultCount;
  uint64_t PeakWorkingSetSize;
  uint64_t WorkingSetSize;
  uint64_t QuotaPeakPagedPoolUsage;
  uint64_t QuotaPagedPoolUsage;
  uint64_t QuotaPeakNonPagedPoolUsage;
  uint64_t QuotaNonPagedPoolUsage;
  uint64_t PagefileUsage;
  uint64_t PeakPagefileUsage;
  uint64_t PrivateUsage;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/processornumber.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSORNUMBER_H_
COSMOPOLITAN_C_START_

struct NtProcessorNumber {
  uint16_t Group;
  uint8_t Number;
  uint8_t Reserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/procthreadattributelist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCTHREADATTRIBUTELIST_H_

struct NtProcThreadAttributeList;



/*!BEGIN libc/nt/struct/reparsedatabuffer.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_REPARSEDATABUFFER_H_
COSMOPOLITAN_C_START_

struct NtReparseDataBuffer {
  uint32_t ReparseTag;
  uint16_t ReparseDataLength;
  uint16_t Reserved;
  union {
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      uint32_t Flags;
      char16_t PathBuffer[1];
    } SymbolicLinkReparseBuffer;
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      char16_t PathBuffer[1];
    } MountPointReparseBuffer;
    struct {
      uint8_t DataBuffer[1];
    } GenericReparseBuffer;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/rtluserprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/sectionimageinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECTIONIMAGEINFORMATION_H_

struct NtSectionImageInformation {
  void *EntryPoint;
  uint32_t Unknown1;
  uint32_t StackReserve;
  uint32_t StackCommit;
  uint32_t Subsystem;
  uint16_t MinorSubsystemVersion;
  uint16_t MajorSubsystemVersion;
  uint32_t Unknown2;
  uint32_t Characteristics;
  uint16_t ImageNumber;
  uint32_t IsExecutable;
  uint8_t __wut1;
  uint32_t __wut2[3];
};


struct NtRtlUserProcessInformation {
  uint32_t SizeOfThis;
  int64_t ProcessHandle;
  int64_t ThreadHandle;
  struct NtClientId ClientId;
  struct NtSectionImageInformation ImageInformation;
};



/*!BEGIN libc/nt/struct/size.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SIZE_H_
COSMOPOLITAN_C_START_

struct NtSize {
  int32_t cx;
  int32_t cy;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFO_H_

struct NtStartupInfo {
  uint32_t cb /* = sizeof(struct NtStartupInfo) */;
  uint16_t *lpReserved;
  char16_t *lpDesktop;
  char16_t *lpTitle; /* title of *new* console window only */
  uint32_t dwX;      /* position of window on screen */
  uint32_t dwY;
  uint32_t dwXSize;
  uint32_t dwYSize;
  uint32_t dwXCountChars; /* used to dimension the dos terminal */
  uint32_t dwYCountChars;
  uint32_t dwFillAttribute;
  uint32_t dwFlags;
  uint16_t wShowWindow;
  uint16_t cbReserved2;
  uint8_t *lpReserved2;
  union {
    struct {
      int64_t hStdInput;
      int64_t hStdOutput;
      int64_t hStdError;
    };
    int64_t stdiofds[3];
  };
};



/*!BEGIN libc/nt/struct/startupinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFOEX_H_

struct NtStartupInfoEx {
  struct NtStartupInfo StartupInfo;
  struct NtProcThreadAttributeList *lpAttributeList;
};



/*!BEGIN libc/nt/struct/systembasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMBASICINFORMATION_H_

struct NtSystemBasicInformation {
  unsigned char Reserved1[4];
  uint32_t MaximumIncrement;
  uint32_t PhysicalPageSize;
  uint32_t NumberOfPhysicalPages;
  uint32_t LowestPhysicalPage;
  uint32_t HighestPhysicalPage;
  uint32_t AllocationGranularity;
  uint32_t LowestUserAddress;
  uint32_t HighestUserAddress;
  uint32_t ActiveProcessors;
  char NumberOfProcessors;
};



/*!BEGIN libc/nt/struct/systemexceptioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMEXCEPTIONINFORMATION_H_

struct NtSystemExceptionInformation {
  unsigned char Reserved1[16];
};



/*!BEGIN libc/nt/struct/systemhandleentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEENTRY_H_

struct NtSystemHandleEntry {
  uint32_t OwnerPid;
  unsigned char ObjectType;
  unsigned char HandleFlags;
  unsigned short HandleValue;
  void *ObjectPointer;
  uint32_t AccessMask;
};



/*!BEGIN libc/nt/struct/systemhandleinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEINFORMATION_H_

struct NtSystemHandleInformation {
  uint32_t Count;
  struct NtSystemHandleEntry Handle[1];
};



/*!BEGIN libc/nt/struct/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINFO_H_

struct NtSystemInfo {
  union {
    uint32_t dwOemId;
    struct {
      uint16_t wProcessorArchitecture;
      uint16_t wReserved;
    };
  };
  uint32_t dwPageSize;
  void *lpMinimumApplicationAddress;
  void *lpMaximumApplicationAddress;
  uintptr_t dwActiveProcessorMask;
  uint32_t dwNumberOfProcessors;
  uint32_t dwProcessorType;
  uint32_t dwAllocationGranularity;
  uint16_t wProcessorLevel;
  uint16_t wProcessorRevision;
};



/*!BEGIN libc/nt/struct/systeminterruptinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINTERRUPTINFORMATION_H_

struct NtSystemInterruptInformation {
  unsigned char Reserved1[24];
};



/*!BEGIN libc/nt/struct/systemlookasideinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMLOOKASIDEINFORMATION_H_

struct NtSystemLookasideInformation {
  unsigned char Reserved1[32];
};



/*!BEGIN libc/nt/struct/systemperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPERFORMANCEINFORMATION_H_

struct NtSystemPerformanceInformation {
  int64_t IdleTime;
  int64_t ReadTransferCount;
  int64_t WriteTransferCount;
  int64_t OtherTransferCount;
  uint32_t ReadOperationCount;
  uint32_t WriteOperationCount;
  uint32_t OtherOperationCount;
  uint32_t AvailablePages;
  uint32_t TotalCommittedPages;
  uint32_t TotalCommitLimit;
  uint32_t PeakCommitment;
  uint32_t PageFaults;
  uint32_t WriteCopyFaults;
  uint32_t TransitionFaults;
  uint32_t CacheTransitionFaults;
  uint32_t DemandZeroFaults;
  uint32_t PagesRead;
  uint32_t PageReadIos;
  uint32_t CacheReads;
  uint32_t CacheIos;
  uint32_t PagefilePagesWritten;
  uint32_t PagefilePageWriteIos;
  uint32_t MappedFilePagesWritten;
  uint32_t MappedFilePageWriteIos;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t PagedPoolAllocs;
  uint32_t PagedPoolFrees;
  uint32_t NonPagedPoolAllocs;
  uint32_t NonPagedPoolFrees;
  uint32_t TotalFreeSystemPtes;
  uint32_t SystemCodePage;
  uint32_t TotalSystemDriverPages;
  uint32_t TotalSystemCodePages;
  uint32_t SmallNonPagedLookasideListAllocateHits;
  uint32_t SmallPagedLookasideListAllocateHits;
  uint32_t Reserved3;
  uint32_t MmSystemCachePage;
  uint32_t PagedPoolPage;
  uint32_t SystemDriverPage;
  uint32_t FastReadNoWait;
  uint32_t FastReadWait;
  uint32_t FastReadResourceMiss;
  uint32_t FastReadNotPossible;
  uint32_t FastMdlReadNoWait;
  uint32_t FastMdlReadWait;
  uint32_t FastMdlReadResourceMiss;
  uint32_t FastMdlReadNotPossible;
  uint32_t MapDataNoWait;
  uint32_t MapDataWait;
  uint32_t MapDataNoWaitMiss;
  uint32_t MapDataWaitMiss;
  uint32_t PinMappedDataCount;
  uint32_t PinReadNoWait;
  uint32_t PinReadWait;
  uint32_t PinReadNoWaitMiss;
  uint32_t PinReadWaitMiss;
  uint32_t CopyReadNoWait;
  uint32_t CopyReadWait;
  uint32_t CopyReadNoWaitMiss;
  uint32_t CopyReadWaitMiss;
  uint32_t MdlReadNoWait;
  uint32_t MdlReadWait;
  uint32_t MdlReadNoWaitMiss;
  uint32_t MdlReadWaitMiss;
  uint32_t ReadAheadIos;
  uint32_t LazyWriteIos;
  uint32_t LazyWritePages;
  uint32_t DataFlushes;
  uint32_t DataPages;
  uint32_t ContextSwitches;
  uint32_t FirstLevelTbFills;
  uint32_t SecondLevelTbFills;
  uint32_t SystemCalls;
};



/*!BEGIN libc/nt/struct/systemprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/vmcounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VMCOUNTERS_H_

struct NtVmCounters {
  size_t PeakVirtualSize;
  size_t VirtualSize;
  uint32_t PageFaultCount;
  size_t PeakWorkingSetSize;
  size_t WorkingSetSize;
  size_t QuotaPeakPagedPoolUsage;
  size_t QuotaPagedPoolUsage;
  size_t QuotaPeakNonPagedPoolUsage;
  size_t QuotaNonPagedPoolUsage;
  size_t PagefileUsage;
  size_t PeakPagefileUsage;
};


struct NtSystemProcessInformation {
  uint32_t NextEntryOffset;
  uint32_t NumberOfThreads;
  int64_t Reserved[3];
  int64_t CreateTime;
  int64_t UserTime;
  int64_t KernelTime;
  struct NtUnicodeString ImageName;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
  uint32_t HandleCount;
  uint32_t SessionId;
  uint32_t PageDirectoryBase;
  struct NtVmCounters VirtualMemoryCounters;
  size_t PrivatePageCount;
  struct NtIoCounters IoCounters;
};



/*!BEGIN libc/nt/struct/systemprocessorinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORINFORMATION_H_

struct NtSystemProcessorInformation {
  unsigned short ProcessorArchitecture;
  unsigned short ProcessorLevel;
  unsigned short ProcessorRevision;
  unsigned short Unknown;
  uint32_t FeatureBits;
};



/*!BEGIN libc/nt/struct/systemprocessorperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORPERFORMANCEINFORMATION_H_

struct NtSystemProcessorPerformanceInformation {
  int64_t IdleTime;
  int64_t KernelTime;
  int64_t UserTime;
  int64_t Reserved1[2];
  uint32_t Reserved2;
};



/*!BEGIN libc/nt/struct/systemregistryquotainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMREGISTRYQUOTAINFORMATION_H_

struct NtSystemRegistryQuotaInformation {
  uint32_t RegistryQuotaAllowed;
  uint32_t RegistryQuotaUsed;
  void *Reserved1;
};



/*!BEGIN libc/nt/struct/systemthreads.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTHREADS_H_

struct NtSystemThreads {
  int64_t KernelTime;
  int64_t UserTime;
  int64_t CreateTime;
  uint32_t WaitTime;
  void *StartAddress;
  struct NtClientId ClientId;
  int32_t Priority;
  int32_t BasePriority;
  uint32_t ContextSwitchCount;
  int State;
  uint32_t WaitReason;
};



/*!BEGIN libc/nt/struct/systemtimeofdayinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIMEOFDAYINFORMATION_H_

struct NtSystemTimeofdayInformation {
  int64_t BootTime;
  int64_t CurrentTime;
  int64_t TimeZoneBias;
  uint32_t CurrentTimeZoneId;
  unsigned char Reserved1[20];
};



/*!BEGIN libc/nt/struct/teb.h */

#define COSMOPOLITAN_LIBC_NT_TEB_H_
#ifdef __GNUC__

/*
 * These macros address directly into NT's TEB a.k.a. TIB
 * Any function that does this needs the `dontasan` keyword
 */
#define NtGetPeb()           ((__seg_gs struct NtPeb *)0x60)
#define NtGetTeb()           ((void *)*(__seg_gs uintptr_t *)0x30)
#define NtGetPid()           (*(__seg_gs uint32_t *)0x40)
#define NtGetTid()           (*(__seg_gs uint32_t *)0x48)
#define NtGetErr()           (*(__seg_gs int *)0x68)
#define _NtGetSeh()          ((void *)*(__seg_gs uintptr_t *)0x00)
#define _NtGetStackHigh()    ((void *)*(__seg_gs uintptr_t *)0x08)
#define _NtGetStackLow()     ((void *)*(__seg_gs uintptr_t *)0x10)
#define _NtGetSubsystemTib() ((void *)*(__seg_gs uintptr_t *)0x18)
#define _NtGetFib()          ((void *)*(__seg_gs uintptr_t *)0x20)
#define _NtGetEnv()          ((char16_t *)*(__seg_gs intptr_t *)0x38)
#define _NtGetRpc()          ((void *)*(__seg_gs uintptr_t *)0x50)
#define _NtGetTls()          ((void *)*(__seg_gs uintptr_t *)0x58)

#endif /* __GNUC__ */


/*!BEGIN libc/nt/struct/timezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEZONEINFORMATION_H_

struct NtTimeZoneInformation {
  int Bias;                  /* in minutes e.g. +480 for -8:00 */
  char16_t StandardName[32]; /* e.g. "Pacific Standard Time" */
  struct NtSystemTime StandardDate;
  int StandardBias;
  char16_t DaylightName[32]; /* e.g. "Pacific Daylight Time" */
  struct NtSystemTime DaylightDate;
  int DaylightBias; /* e.g. -60 */
};



/*!BEGIN libc/nt/struct/tokenprivileges.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TOKENPRIVILEGES_H_

struct NtTokenPrivileges {
  uint32_t PrivilegeCount;
  struct NtLuidAndAttributes Privileges[1];
};



/*!BEGIN libc/nt/struct/userstack.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTUSERSTACK_H_

struct NtUserStack {
  void *FixedStackBase;
  void *FixedStackLimit;
  void *ExpandableStackBase;
  void *ExpandableStackLimit;
  void *ExpandableStackBottom;
};



/*!BEGIN libc/nt/struct/valent.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VALENT_H_

struct NtValent {
  char16_t *ve_valuename;
  uint32_t ve_valuelen;
  uintptr_t ve_valueptr;
  uint32_t ve_type;
};



/*!BEGIN libc/nt/struct/win32fileattributedata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FILEATTRIBUTEDATA_H_

struct NtWin32FileAttributeData {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
};



/*!BEGIN libc/nt/struct/win32finddata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FINDDATA_H_

struct NtWin32FindData {
  uint32_t dwFileAttributes;
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t dwReserved0;
  uint32_t dwReserved1;
  char16_t cFileName[260];
  char16_t cAlternateFileName[14];
  uint32_t dwFileType;    /* obsolete */
  uint32_t dwCreatorType; /* obsolete */
  uint16_t wFinderFlags;  /* obsolete */
};



/*!BEGIN libc/nt/struct/windowplacement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WINDOWPLACEMENT_H_

struct NtWindowPlacement {
  uint32_t length;
  uint32_t flags;
  uint32_t showCmd;
  struct NtPoint ptMinPosition;
  struct NtPoint ptMaxPosition;
  struct NtRect rcNormalPosition;
  struct NtRect rcDevice;
};



/*!BEGIN libc/nt/struct/wndclass.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASS_H_


/*!BEGIN libc/nt/typedef/wndproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDPROC_H_
COSMOPOLITAN_C_START_

typedef int64_t (*NtWndProc)(int64_t, uint32_t, uint64_t, int64_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct NtWndClass {
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/wndclassex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASSEX_H_
COSMOPOLITAN_C_START_

struct NtWndClassEx {
  uint32_t cbSize;
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
  int64_t hIconSm;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/exceptionhandler.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_EXCEPTIONHANDLER_H_
COSMOPOLITAN_C_START_

typedef unsigned (*NtExceptionHandler)(struct NtExceptionRecord *,
                                       struct NtExceptionFrame *,
                                       struct NtContext *, void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/handlerroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HANDLERROUTINE_H_

typedef bool32 (*NtHandlerRoutine)(uint32_t);



/*!BEGIN libc/nt/typedef/hookproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HOOKPROC_H_

typedef intptr_t (*NtHookProc)(int code, uintptr_t wParam, intptr_t lParam);



/*!BEGIN libc/nt/typedef/imagetlscallback.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IMAGETLSCALLBACK_H_

typedef void (*NtImageTlsCallback)(void *DllHandle, uint32_t Reason,
                                   void *Reserved);



/*!BEGIN libc/nt/typedef/ioapcroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IOAPCROUTINE_H_

typedef void (*NtIoApcRoutine)(void *ApcContext,
                               struct NtIoStatusBlock *IoStatusBlock,
                               uint32_t Reserved);



/*!BEGIN libc/nt/typedef/pknormalroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_PKNORMALROUTINE_H_

typedef void (*NtPkNormalRoutine)(void *NormalContext, void *SystemArgument1,
                                  void *SystemArgument2);



/*!BEGIN libc/nt/typedef/timerproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_TIMERPROC_H_

typedef void (*NtTimerProc)(int64_t, uint32_t, uintptr_t, uint32_t);



/*!BEGIN libc/nt/typedef/wambda.h */

#define COSMOPOLITAN_LIBC_NT_WAMBDA_H_
COSMOPOLITAN_C_START_

typedef intptr_t (*wambda)();

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/wndenumproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDENUMPROC_H_

typedef int (*NtWndEnumProc)(int64_t foo, intptr_t bar);



/*!BEGIN libc/nt/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » debugging              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtContinue(struct NtContext *Context, int32_t TestAlert);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/file.h */

#define COSMOPOLITAN_LIBC_NT_NT_FILE_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtClose(int64_t handle);

NtStatus NtCreateFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                      const struct NtObjectAttributes *ObjectAttributes,
                      struct NtIoStatusBlock *out_IoStatusBlock,
                      int64_t *opt_AllocationSize, uint32_t FileAttributes,
                      uint32_t ShareAccess, uint32_t CreateDisposition,
                      uint32_t CreateOptions, void *opt_EaBuffer,
                      uint32_t EaLength);

NtStatus NtReadFile(int64_t FileHandle, void *opt_Event,
                    NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                    struct NtIoStatusBlock *out_IoStatusBlock, void *out_Buffer,
                    uint32_t Length, int64_t *opt_ByteOffset,
                    uint32_t *opt_Key);

NtStatus NtWriteFile(int64_t FileHandle, void *opt_Event,
                     NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                     struct NtIoStatusBlock *out_IoStatusBlock,
                     const void *Buffer, uint32_t Length,
                     int64_t *opt_ByteOffset, uint32_t *opt_Key);

NtStatus NtDuplicateObject(int64_t SourceProcessHandle, void *SourceHandle,
                           void *TargetProcessHandle,
                           void **opt_out_TargetHandle, uint32_t DesiredAcess,
                           uint32_t Attributes, uint32_t options_t);

NtStatus NtQueryInformationFile(int64_t FileHandle,
                                struct NtIoStatusBlock *out_IoStatusBlock,
                                void *out_FileInformation,
                                uint32_t FileInformationLength,
                                uint32_t FileInformationClass);

NtStatus NtSetInformationFile(int64_t FileHandle,
                              struct NtIoStatusBlock *out_IoStatusBlock,
                              void *FileInformation,
                              uint32_t FileInformationLength,
                              uint32_t FileInformationClass);

NtStatus NtDeviceIoControlFile(
    int64_t FileHandle, int64_t opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    uint32_t IoControlCode, void *opt_InputBuffer, uint32_t InputBufferLength,
    void *opt_out_OutputBuffer, uint32_t OutputBufferLength);

NtStatus NtCancelIoFileEx(int64_t FileHandle,
                          struct NtIoStatusBlock *IoRequestToCancel,
                          struct NtIoStatusBlock *IoStatusBlock);

NtStatus RtlNtStatusToDosError(NtStatus Status);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntfile.inc */

#define NtQueryInformationFile(...) __imp_NtQueryInformationFile(__VA_ARGS__)

extern typeof(NtQueryInformationFile) *const
    __imp_NtQueryInformationFile __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_NT_IPC_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » ipc                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtCreateNamedPipeFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes,
                               struct NtIoStatusBlock *out_IoStatusBlock,
                               uint32_t ShareAccess, uint32_t CreateDisposition,
                               uint32_t CreateOptions, int32_t TypeMessage,
                               int32_t ReadmodeMessage, int32_t Nonblocking,
                               uint32_t MaxInstances, uint32_t InBufferSize,
                               uint32_t OutBufferSize,
                               int64_t *opt_DefaultTimeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/key.h */

#define COSMOPOLITAN_LIBC_NT_NT_EVENT_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtCreateKeyedEvent(int64_t *KeyedEventHandle, uint32_t DesiredAccess,
                            struct NtObjectAttributes *ObjectAttributes,
                            uint32_t Flags);

NtStatus NtReleaseKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

NtStatus NtWaitForKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/loader.h */

#define COSMOPOLITAN_LIBC_NT_NT_LOADER_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » loader                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtAnsiString;
struct NtLdrDataTableEntry;
struct NtUnicodeString;

NtStatus LdrLoadDll(const char16_t *opt_PathToFile, uint32_t *opt_Flags,
                    struct NtUnicodeString *ModuleFileName,
                    void **out_ModuleHandle);
NtStatus LdrUnloadDll(void *ModuleHandle);
NtStatus LdrGetProcedureAddress(void *ModuleHandle,
                                struct NtAnsiString *opt_ProcedureName,
                                uint32_t opt_Ordinal,
                                wambda *out_ProcedureAddress);
NtStatus LdrGetDllHandle(const char16_t *opt_PathToFile, uint32_t opt_Unused,
                         struct NtUnicodeString *ModuleFileName,
                         void **out_ModuleHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_NT_MEMORY_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » memory                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtAllocateVirtualMemory(int64_t ProcessHandle,
                                 void **inout_BaseAddress, uint32_t dwZeroBits,
                                 uint32_t *inout_AllocationSize,
                                 uint32_t dwMemAllocationType,
                                 uint32_t dwPageProtect);
NtStatus NtFreeVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                             size_t *inout_FreeSize, uint32_t FreeType);
NtStatus NtQueryVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                              int MemoryInformationClass,
                              void *out_MemoryInformation,
                              size_t MemoryInformationLength,
                              size_t *opt_out_ReturnLength);
NtStatus NtProtectVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                                uint32_t *inout_ProtectSize,
                                uint32_t NewProtect, uint32_t *out_OldProtect);
NtStatus NtWriteVirtualMemory(int64_t ProcessHandle, void *BaseAddress,
                              const void *Buffer, size_t BufferLength,
                              size_t *opt_out_ReturnLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_NT_PROCESS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » processes              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtObjectAttributes;
struct NtRtlUserProcessInformation;
struct NtRtlUserProcessParameters;
struct NtSecurityDescriptor;
struct NtUnicodeString;

NtStatus NtCreateProcess(int64_t *out_ProcessHandle, uint32_t dwDesiredAccess,
                         struct NtObjectAttributes *opt_ObjectAttributes,
                         void *InheritFromProcessHandle, int32_t InheritHandles,
                         void *opt_SectionHandle, void *opt_DebugPort,
                         void *opt_ExceptionPort);
NtStatus NtTerminateProcess(int64_t opt_ProcessHandle, int32_t ExitStatus);

NtStatus NtQueryInformationProcess(int64_t ProcessHandle,
                                   int ProcessInformationClass,
                                   void *out_ProcessInformation,
                                   uint32_t ProcessInformationLength,
                                   uint32_t *opt_out_ReturnLength);
NtStatus NtOpenProcessToken(int64_t ProcessToken, uint32_t DesiredAccess,
                            int64_t *out_TokenHandle);
NtStatus NtOpenProcess(int64_t *out_ProcessHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       struct NtClientId *ClientId);

NtStatus RtlCreateProcessParameters(
    struct NtRtlUserProcessParameters **out_ProcessParameters,
    struct NtUnicodeString *ImageFile, struct NtUnicodeString *opt_DllPath,
    struct NtUnicodeString *opt_CurrentDirectory,
    struct NtUnicodeString *opt_CommandLine, uint32_t CreationFlags,
    struct NtUnicodeString *opt_WindowTitle,
    struct NtUnicodeString *opt_Desktop, struct NtUnicodeString *opt_Reserved,
    struct NtUnicodeString *opt_Reserved2);

NtStatus RtlDestroyProcessParameters(
    struct NtRtlUserProcessParameters *ProcessParameters);

NtStatus RtlCloneUserProcess(
    uint32_t ProcessFlags,
    struct NtSecurityDescriptor *opt_ProcessSecurityDescriptor,
    struct NtSecurityDescriptor *opt_ThreadSecurityDescriptor,
    void *opt_DebugPort,
    struct NtRtlUserProcessInformation *ProcessInformation);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/process.inc */

#define NtQueryInformationProcess(...) \
  __imp_NtQueryInformationProcess(__VA_ARGS__)

extern typeof(NtQueryInformationProcess) *const
    __imp_NtQueryInformationProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/sections.h */

#define COSMOPOLITAN_LIBC_NT_NT_SECTIONS_H_
COSMOPOLITAN_C_START_

NtStatus NtCreateSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                         struct NtObjectAttributes *ObjectAttributes,
                         int64_t *opt_SectionSize, uint32_t Protect,
                         uint32_t Attributes, int64_t FileHandle);
NtStatus NtOpenSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes);
NtStatus NtMapViewOfSection(int64_t SectionHandle, int64_t ProcessHandle,
                            void **inout_BaseAddress, uint32_t *ZeroBits,
                            size_t CommitSize, int64_t *opt_inout_SectionOffset,
                            size_t *inout_ViewSize, int InheritDisposition,
                            uint32_t AllocationType, uint32_t Protect);
NtStatus NtUnmapViewOfSection(int64_t ProcessHandle, void *BaseAddress);
NtStatus NtQuerySection(int64_t SectionHandle, int SectionInformationClass,
                        void *out_SectionInformation,
                        uint32_t SectionInformationLength,
                        uint32_t *opt_out_ResultLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/signing.h */

#define COSMOPOLITAN_LIBC_NT_NT_SIGNING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » code signing           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus CsrClientCallServer(void *inout_Message, void *unknown,
                             uint32_t Opcode, uint32_t Size);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » threads                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtContext;
struct NtObjectAttributes;
struct NtUserStack;

NtStatus NtCreateThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                        struct NtObjectAttributes *ObjectAttributes,
                        int64_t ProcessHandle, struct NtClientId *out_ClientId,
                        struct NtContext *ThreadContext,
                        struct NtUserStack *UserStack, int32_t CreateSuspended);

NtStatus NtTerminateThread(void *opt_ThreadHandle, int32_t ExitStatus);

NtStatus NtOpenThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                      struct NtObjectAttributes *ObjectAttributes,
                      struct NtClientId *ClientId);

NtStatus NtQueryInformationThread(int64_t ThreadHandle,
                                  enum NtThreadInfoClass ThreadInformationClass,
                                  void *out_ThreadInformation,
                                  uint32_t ThreadInformationLength,
                                  uint32_t *opt_out_ReturnLength);

NtStatus NtGetContextThread(int64_t ThreadHandle,
                            struct NtContext *out_Context);
NtStatus NtSetContextThread(int64_t ThreadHandle, struct NtContext *Context);
NtStatus NtSuspendThread(int64_t ThreadHandle,
                         uint32_t *opt_out_PreviousSuspendCount);
NtStatus NtResumeThread(int64_t ThreadHandle,
                        uint32_t *opt_out_PreviousSuspendCount);

NtStatus NtOpenThreadToken(int64_t ThreadHandle, uint32_t DesiredAccess,
                           int32_t OpenAsSelf, int64_t *out_TokenHandle);

NtStatus NtSetInformationThread(int64_t ThreadHandle,
                                enum NtThreadInfoClass ThreadInformationClass,
                                void *ThreadInformation,
                                uint32_t ThreadInformationLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » time                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtDelayExecution(bool32 alertable, int64_t *AbsCobolOrNegRelHectoNano);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/time.inc */

#define NtDelayExecution(...) __imp_NtDelayExecution(__VA_ARGS__)

extern typeof(NtDelayExecution) *const __imp_NtDelayExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/accounting.h */

#define COSMOPOLITAN_LIBC_NT_ACCOUNTING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » accounting                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetMaximumProcessorCount(uint16_t GroupNumber);
int GetUserName(char16_t (*buf)[257], uint32_t *in_out_size);
bool32 GlobalMemoryStatusEx(struct NtMemoryStatusEx *lpBuffer);
int32_t GetExitCodeProcess(int64_t hProcess, uint32_t *lpExitCode);
int32_t GetProcessHandleCount(int64_t hProcess, uint32_t *pdwHandleCount);
bool32 GetSystemTimes(struct NtFileTime *opt_out_lpIdleTime,
                      struct NtFileTime *opt_out_lpKernelTime,
                      struct NtFileTime *opt_out_lpUserTime);
bool32 GetProcessTimes(int64_t hProcess,
                       struct NtFileTime *out_lpCreationFileTime,
                       struct NtFileTime *out_lpExitFileTime,
                       struct NtFileTime *out_lpKernelFileTime,
                       struct NtFileTime *out_lpUserFileTime);
bool32 GetThreadTimes(int64_t hThread,
                      struct NtFileTime *out_lpCreationFileTime,
                      struct NtFileTime *out_lpExitFileTime,
                      struct NtFileTime *out_lpKernelFileTime,
                      struct NtFileTime *out_lpUserFileTime);
int32_t GetProcessIoCounters(int64_t hProcess,
                             struct NtIoCounters *lpIoCounters);
int32_t GetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t *lpMinimumWorkingSetSize,
                                 uint64_t *lpMaximumWorkingSetSize);
int32_t GetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t *lpMinimumWorkingSetSize,
                                   uint64_t *lpMaximumWorkingSetSize,
                                   uint32_t *Flags);
int32_t SetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t dwMinimumWorkingSetSize,
                                 uint64_t dwMaximumWorkingSetSize);
int32_t SetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t dwMinimumWorkingSetSize,
                                   uint64_t dwMaximumWorkingSetSize,
                                   uint32_t Flags);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/accounting.inc */

#define GetProcessTimes(...) __imp_GetProcessTimes(__VA_ARGS__)
extern typeof(GetProcessTimes) *const __imp_GetProcessTimes __msabi;

#define GetThreadTimes(...) __imp_GetThreadTimes(__VA_ARGS__)
extern typeof(GetThreadTimes) *const __imp_GetThreadTimes __msabi;

#define GetUserName(...) __imp_GetUserNameW(__VA_ARGS__)
extern typeof(GetUserName) *const __imp_GetUserNameW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/automation.h */

#define COSMOPOLITAN_LIBC_NT_AUTOMATION_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » aol hacking                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int64_t GetShellWindow(void);
int64_t GetDesktopWindow(void);
int64_t GetParent(int64_t hWnd);
int64_t SetParent(int64_t hWndChild, int64_t hWndNewParent);
int32_t EnumChildWindows(int64_t hWndParent, NtWndEnumProc lpEnumFunc,
                         intptr_t lParam);
int64_t FindWindow(const char16_t *lpClassName, const char16_t *lpWindowName);
int64_t FindWindowEx(int64_t hWndParent, int64_t hWndChildAfter,
                     const char16_t *lpszClass, const char16_t *lpszWindow);
int64_t GetWindow(int64_t hWnd, uint32_t uCmd);
int64_t SetWindowsHook(int nFilterType, NtHookProc pfnFilterProc);
int32_t UnhookWindowsHook(int nCode, NtHookProc pfnFilterProc);
int64_t SetWindowsHookEx(int idHook, NtHookProc lpfn, int64_t hmod,
                         uint32_t dwThreadId);
int32_t UnhookWindowsHookEx(int64_t hhk);
intptr_t CallNextHookEx(int64_t hhk, int nCode, uintptr_t wParam,
                        intptr_t lParam);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/codegen.h */

#define COSMOPOLITAN_LIBC_NT_CODEGEN_H_


/*!BEGIN libc/nt/comdlg.h */

#define COSMOPOLITAN_LIBC_NT_COMDLG_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » common dialogs                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 GetOpenFileName(struct NtOpenFilename *arg);
bool32 GetSaveFileName(struct NtOpenFilename *arg);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/comms.h */

#define COSMOPOLITAN_LIBC_NT_COMMS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » communications                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

bool32 PurgeComm(int64_t hFile, uint32_t dwFlags);
bool32 TransmitCommChar(int64_t hFile, char cChar);
bool32 ClearCommBreak(int64_t hFile);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/console.h */

#define COSMOPOLITAN_LIBC_NT_CONSOLE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » console                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtAttachParentProcess -1u

COSMOPOLITAN_C_START_

bool32 WriteConsoleOutput(int64_t hConsoleOutput,
                          const struct NtCharInfo *lpBuffer,
                          struct NtCoord dwBufferSize,
                          struct NtCoord dwBufferCoord,
                          struct NtSmallRect *lpWriteRegion);
bool32 ReadConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 PeekConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 GetNumberOfConsoleInputEvents(int64_t hConsoleInput,
                                     uint32_t *lpNumberOfEvents);
bool32 ReadConsoleOutput(int64_t hConsoleOutput, struct NtCharInfo *lpBuffer,
                         struct NtCoord dwBufferSize,
                         struct NtCoord dwBufferCoord,
                         struct NtSmallRect *lpReadRegion);
bool32 WriteConsoleInput(int64_t hConsoleInput,
                         const struct NtInputRecord *lpBuffer, uint32_t nLength,
                         uint32_t *lpNumberOfEventsWritten);
bool32 FlushConsoleInputBuffer(int64_t hConsoleInput);

int64_t GetConsoleWindow(void);
bool32 GetConsoleMode(int64_t hConsoleHandle, uint32_t *lpMode);
bool32 SetConsoleMode(int64_t hConsoleHandle, uint32_t dwMode);
int32_t AllocConsole(void);
int32_t FreeConsole(void);
int32_t AttachConsole(uint32_t dwProcessId);
uint32_t GetConsoleTitle(char16_t *lpConsoleTitle, uint32_t nSize);
int32_t SetConsoleTitle(const char16_t *lpConsoleTitle);
bool32 GetConsoleScreenBufferInfo(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfo *out_lpConsoleScreenBufferInfo);
bool32 GetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfoEx *in_out_lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    const struct NtConsoleScreenBufferInfoEx *lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferSize(int64_t lpConsoleOutput,
                                  struct NtCoord dwSize);
struct NtCoord GetLargestConsoleWindowSize(int64_t hConsoleHandle);
int32_t ReadConsole(int64_t hConsoleInput, void *lpBuffer,
                    uint32_t nNumberOfCharsToRead,
                    uint32_t *lpNumberOfCharsRead, void *lpReserved);
int32_t WriteConsole(int64_t hConsoleOutput, const void *lpBuffer,
                     uint32_t nNumberOfCharsToWrite,
                     uint32_t *lpNumberOfCharsWritten, void *lpReserved)
    paramsnonnull((2, 4));
bool32 GetNumberOfConsoleMouseButtons(uint32_t *out_lpNumberOfMouseButtons)
    paramsnonnull();
bool32 GetConsoleSelectionInfo(
    struct NtConsoleSelectionInfo *out_lpConsoleSelectionInfo);
uint32_t WaitForInputIdle(int64_t hProcess, uint32_t dwMilliseconds);
uint32_t GetConsoleCP(void);
bool32 SetConsoleCP(uint32_t wCodePageID);
bool32 SetConsoleOutputCP(uint32_t wCodePageID);
uint32_t GetConsoleOutputCP(void);
bool32 SetConsoleCtrlHandler(NtHandlerRoutine opt_HandlerRoutine, bool32 Add);
bool32 GenerateConsoleCtrlEvent(uint32_t dwCtrlEvent,
                                uint32_t dwProcessGroupId);

bool32 GetConsoleCursorInfo(
    int64_t hConsoleOutput,
    struct NtConsoleCursorInfo *out_lpConsoleCursorInfo);
bool32 SetConsoleCursorInfo(
    int64_t hConsoleOutput,
    const struct NtConsoleCursorInfo *lpConsoleCursorInfo);

long CreatePseudoConsole(struct NtCoord size, int64_t hInput, int64_t hOutput,
                         uint32_t dwFlags, int64_t *out_phPC);
long ResizePseudoConsole(int64_t hPC, struct NtCoord size);
void ClosePseudoConsole(int64_t hPC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/console.inc */

#define GetConsoleMode(...) __imp_GetConsoleMode(__VA_ARGS__)
extern typeof(GetConsoleMode) *const __imp_GetConsoleMode __msabi;

#define SetConsoleCP(...) __imp_SetConsoleCP(__VA_ARGS__)
extern typeof(SetConsoleCP) *const __imp_SetConsoleCP __msabi;

#define GetConsoleCP(...) __imp_GetConsoleCP(__VA_ARGS__)
extern typeof(GetConsoleCP) *const __imp_GetConsoleCP __msabi;

#define SetConsoleCtrlHandler(...) __imp_SetConsoleCtrlHandler(__VA_ARGS__)
extern typeof(SetConsoleCtrlHandler) *const __imp_SetConsoleCtrlHandler __msabi;

#define SetConsoleMode(...) __imp_SetConsoleMode(__VA_ARGS__)
extern typeof(SetConsoleMode) *const __imp_SetConsoleMode __msabi;

#define SetConsoleOutputCP(...) __imp_SetConsoleOutputCP(__VA_ARGS__)
extern typeof(SetConsoleOutputCP) *const __imp_SetConsoleOutputCP __msabi;

#define GetConsoleOutputCP(...) __imp_GetConsoleOutputCP(__VA_ARGS__)
extern typeof(GetConsoleOutputCP) *const __imp_GetConsoleOutputCP __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/createfile.h */

#define COSMOPOLITAN_LIBC_NT_CREATEFILE_H_
COSMOPOLITAN_C_START_

int64_t CreateFile(
    const char16_t *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int64_t CreateFileA(
    const char *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int GetNtOpenFlags(int, int, uint32_t *, uint32_t *, uint32_t *, uint32_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » debugging                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* Some of these APIs were moved to system.h and libc.h */
int32_t DebugBreakProcess(void *Process);
int32_t DebugActiveProcess(uint32_t dwProcessId);
int32_t DebugActiveProcessStop(uint32_t dwProcessId);
int32_t CheckRemoteDebuggerPresent(int64_t hProcess, int *pbDebuggerPresent);
int32_t ContinueDebugEvent(uint32_t dwProcessId, uint32_t dwThreadId,
                           uint32_t dwContinueStatus);
void FatalExit(int uExitCode);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/dll.h */

#define COSMOPOLITAN_LIBC_NT_DLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » dynamic link libraries                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t LoadLibrary(const char16_t *lpLibFileName);
int64_t LoadLibraryA(const char *lpLibFileName);
int64_t LoadLibraryEx(const char16_t *lpLibFileName, int64_t hFile,
                      uint32_t dwFlags);
uint32_t GetModuleFileNameA(int64_t hModule, char *lpFilename, uint32_t nSize);
intptr_t GetModuleHandle(const char *opt_lpModuleName);
intptr_t GetModuleHandleW(const char16_t *opt_lpModuleName);
void *GetProcAddress(int64_t hModule, const char *lpProcName);
int32_t FreeResource(int64_t hResData);
intptr_t LockResource(int64_t hResData);
int32_t FreeLibrary(int64_t hLibModule);
void *AddDllDirectory(const char16_t *NewDirectory);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/efi.h */

#define COSMOPOLITAN_LIBC_NT_EFI_H_
/*
    ▐██ ░█████████▓   ▐██▌     ██▓░   ▐█▌  ▐██  ░██░    ▓█▌  ▓██▒     ▓██
    ▐██     ░██░     ▒█▓██░    ████░  ▐█▌  ▐██  ░██░    ▓█▌  ▓███░   ▓███
    ▐██     ░██░     ██░▐█▓    ██▒▓█░ ▐█▌  ▐██  ░██░    ▓█▌  ▓█▌▓█░ ▓█▒██
    ▐██     ░██░    ▐█▌  ▓█▌   ██░░▓█░▐█▌  ▐██  ░██░    ▓█▌  ▓█▌░█▓▓█▒░██
    ▐██     ░██░   ▒██▓█████░  ██░ ░▓▓▓█▌  ▐██  ░██░    ██░  ▓█▌ ░██▌ ░██
    ▐██     ░██░   ▓█▌    ▓█▓  ██░  ░███▌  ▐██   ▐██▄▄▄▓█▓   ▓█▌      ░██
╔────────────────────────────────────────────────────────────────────────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § the unified extensible firmware interface ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define EFI_SUCCESS           0x8000000000000000
#define EFI_LOAD_ERROR        0x8000000000000001
#define EFI_INVALID_PARAMETER 0x8000000000000002
#define EFI_UNSUPPORTED       0x8000000000000003
#define EFI_BAD_BUFFER_SIZE   0x8000000000000004
#define EFI_BUFFER_TOO_SMALL  0x8000000000000005
#define EFI_NOT_READY         0x8000000000000006
#define EFI_DEVICE_ERROR      0x8000000000000007
#define EFI_WRITE_PROTECTED   0x8000000000000008
#define EFI_OUT_OF_RESOURCES  0x8000000000000009
#define EFI_VOLUME_CORRUPTED  0x800000000000000a
#define EFI_VOLUME_FULL       0x800000000000000b
#define EFI_NO_MEDIA          0x800000000000000c
#define EFI_MEDIA_CHANGED     0x800000000000000d
#define EFI_NOT_FOUND         0x800000000000000e
#define EFI_ACCESS_DENIED     0x800000000000000f
#define EFI_NO_RESPONSE       0x8000000000000010
#define EFI_NO_MAPPING        0x8000000000000011
#define EFI_TIMEOUT           0x8000000000000012
#define EFI_NOT_STARTED       0x8000000000000013
#define EFI_ALREADY_STARTED   0x8000000000000014
#define EFI_ABORTED           0x8000000000000015
#define EFI_ICMP_ERROR        0x8000000000000016
#define EFI_TFTP_ERROR        0x8000000000000017
#define EFI_PROTOCOL_ERROR    0x8000000000000018

#define EFI_VARIABLE_NON_VOLATILE                          0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS                    0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS                        0x00000004
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD                 0x00000008
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS            0x00000010
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
#define EFI_VARIABLE_APPEND_WRITE                          0x00000040

#define EFI_MEMORY_UC            0x0000000000000001U
#define EFI_MEMORY_WC            0x0000000000000002U
#define EFI_MEMORY_WT            0x0000000000000004U
#define EFI_MEMORY_WB            0x0000000000000008U
#define EFI_MEMORY_UCE           0x0000000000000010U
#define EFI_MEMORY_WP            0x0000000000001000U
#define EFI_MEMORY_RP            0x0000000000002000U
#define EFI_MEMORY_XP            0x0000000000004000U
#define EFI_MEMORY_RO            0x0000000000020000U
#define EFI_MEMORY_NV            0x0000000000008000U
#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000U
#define EFI_MEMORY_RUNTIME       0x8000000000000000U

#define EFI_OPTIONAL_PTR 0x00000001

#define EFI_SCAN_NULL      0x0000
#define EFI_SCAN_UP        0x0001
#define EFI_SCAN_DOWN      0x0002
#define EFI_SCAN_RIGHT     0x0003
#define EFI_SCAN_LEFT      0x0004
#define EFI_SCAN_HOME      0x0005
#define EFI_SCAN_END       0x0006
#define EFI_SCAN_INSERT    0x0007
#define EFI_SCAN_DELETE    0x0008
#define EFI_SCAN_PAGE_UP   0x0009
#define EFI_SCAN_PAGE_DOWN 0x000A
#define EFI_SCAN_F1        0x000B
#define EFI_SCAN_F2        0x000C
#define EFI_SCAN_F3        0x000D
#define EFI_SCAN_F4        0x000E
#define EFI_SCAN_F5        0x000F
#define EFI_SCAN_F6        0x0010
#define EFI_SCAN_F7        0x0011
#define EFI_SCAN_F8        0x0012
#define EFI_SCAN_F9        0x0013
#define EFI_SCAN_F10       0x0014
#define EFI_SCAN_ESC       0x0017

#define EFI_EVT_TIMER                         0x80000000
#define EFI_EVT_RUNTIME                       0x40000000
#define EFI_EVT_NOTIFY_WAIT                   0x00000100
#define EFI_EVT_NOTIFY_SIGNAL                 0x00000200
#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES     0x00000201
#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
#define EFI_EVT_RUNTIME_CONTEXT               0x20000000

#define LOADED_IMAGE_PROTOCOL                        \
  {                                                  \
    0x5B1B31A1, 0x9562, 0x11d2, {                    \
      0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \
    }                                                \
  }
#define GRAPHICS_OUTPUT_PROTOCOL                     \
  {                                                  \
    0x9042A9DE, 0x23DC, 0x4A38, {                    \
      0x96, 0xFB, 0x7A, 0xDE, 0xD0, 0x80, 0x51, 0x6A \
    }                                                \
  }
#define ACPI_20_TABLE_GUID                           \
  {                                                  \
    0x8868E871, 0xE4F1, 0x11D3, {                    \
      0xBC, 0x22, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 \
    }                                                \
  }
#define ACPI_10_TABLE_GUID                           \
  {                                                  \
    0xEB9D2D30, 0x2D88, 0x11D3, {                    \
      0x9A, 0x16, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D \
    }                                                \
  }

COSMOPOLITAN_C_START_

#if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__chibicc__) && \
    defined(__x86_64__)
#define EFIAPI __attribute__((__ms_abi__))
#else
#define EFIAPI /* TODO(jart): fix me */
#endif

#define EFI_STATUS uint64_t
#define EFI_EVENT  uintptr_t
#define EFI_HANDLE uintptr_t

typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
typedef struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL;

typedef enum {
  EfiReservedMemoryType,
  EfiLoaderCode,
  EfiLoaderData,
  EfiBootServicesCode,
  EfiBootServicesData,
  EfiRuntimeServicesCode,
  EfiRuntimeServicesData,
  EfiConventionalMemory,
  EfiUnusableMemory,
  EfiACPIReclaimMemory,
  EfiACPIMemoryNVS,
  EfiMemoryMappedIO,
  EfiMemoryMappedIOPortSpace,
  EfiPalCode,
  EfiPersistentMemory,
  EfiMaxMemoryType
} EFI_MEMORY_TYPE;

typedef enum {
  EfiResetCold,
  EfiResetWarm,
  EfiResetShutdown,
  EfiResetPlatformSpecific
} EFI_RESET_TYPE;

typedef enum {
  AllocateAnyPages,
  AllocateMaxAddress,
  AllocateAddress,
  MaxAllocateType
} EFI_ALLOCATE_TYPE;

typedef enum {
  TimerCancel,
  TimerPeriodic,
  TimerRelative,
} EFI_TIMER_DELAY;

typedef struct {
  uint32_t Resolution;
  uint32_t Accuracy;
  bool32 SetsToZero;
} EFI_TIME_CAPABILITIES;

typedef struct {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
} EFI_GUID;

typedef struct {
  uint16_t Year;
  uint8_t Month;
  uint8_t Day;
  uint8_t Hour;
  uint8_t Minute;
  uint8_t Second;
  uint8_t Pad1;
  uint32_t Nanosecond;
  int16_t TimeZone;
  uint8_t Daylight;
  uint8_t Pad2;
} EFI_TIME;

typedef struct {
  uint32_t Type;
  uint64_t PhysicalStart;
  uint64_t VirtualStart;
  uint64_t NumberOfPages;
  uint64_t Attribute;
} EFI_MEMORY_DESCRIPTOR;

typedef struct {
  EFI_GUID VendorGuid;
  void *VendorTable;
} EFI_CONFIGURATION_TABLE;

typedef struct {
  EFI_GUID CapsuleGuid;
  uint32_t HeaderSize;
  uint32_t Flags;
  uint32_t CapsuleImageSize;
} EFI_CAPSULE_HEADER;

typedef struct {
  uint16_t ScanCode;
  char16_t UnicodeChar;
} EFI_INPUT_KEY;

typedef struct {
  int32_t MaxMode;
  int32_t Mode;
  int32_t Attribute;
  int32_t CursorColumn;
  int32_t CursorRow;
  bool32 CursorVisible;
} EFI_SIMPLE_TEXT_OUTPUT_MODE;

typedef enum {
  PixelRedGreenBlueReserved8BitPerColor,
  PixelBlueGreenRedReserved8BitPerColor,
  PixelBitMask,
  PixelBltOnly,
  PixelFormatMax
} EFI_GRAPHICS_PIXEL_FORMAT;

typedef struct {
  uint32_t RedMask;
  uint32_t GreenMask;
  uint32_t BlueMask;
  uint32_t ReservedMask;
} EFI_PIXEL_BITMASK;

typedef struct {
  uint32_t Version;
  uint32_t HorizontalResolution;
  uint32_t VerticalResolution;
  EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
  EFI_PIXEL_BITMASK PixelInformation;
  uint32_t PixelsPerScanLine;
} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;

typedef struct {
  uint8_t Blue;
  uint8_t Green;
  uint8_t Red;
  uint8_t Reserved;
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;

typedef enum {
  EfiBltVideoFill,
  EfiBltVideoToBltBuffer,
  EfiBltBufferToVideo,
  EfiBltVideoToVideo,
  EfiGraphicsOutputBltOperationMax
} EFI_GRAPHICS_OUTPUT_BLT_OPERATION;

typedef struct {
  uint32_t MaxMode;
  uint32_t Mode;
  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
  uint32_t SizeOfInfo;
  uint64_t FrameBufferBase;
  uint32_t FrameBufferSize;
} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;

typedef struct {
  uint64_t Signature;
  uint32_t Revision;
  uint32_t HeaderSize;
  uint32_t CRC32;
  uint32_t Reserved;
} EFI_TABLE_HEADER;

typedef struct {
  uint8_t Type;
  uint8_t SubType;
  uint8_t Length[2];
} EFI_DEVICE_PATH_PROTOCOL;

typedef EFI_STATUS(EFIAPI *EFI_EXIT)(EFI_HANDLE ImageHandle,
                                     EFI_STATUS ExitStatus,
                                     uintptr_t ExitDataSize,
                                     char16_t *opt_ExitData);

typedef EFI_STATUS(EFIAPI *EFI_GET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t *outopt_Attributes,
                                             uintptr_t *inout_DataSize,
                                             void *outopt_Data);
typedef EFI_STATUS(EFIAPI *EFI_SET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t Attributes,
                                             uintptr_t DataSize, void *Data);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME)(
    uintptr_t *inout_VariableNameSize, char16_t *inout_VariableName,
    EFI_GUID *inout_VendorGuid);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_VARIABLE_INFO)(
    uint32_t Attributes, uint64_t *out_MaximumVariableStorageSize,
    uint64_t *out_RemainingVariableStorageSize,
    uint64_t *out_MaximumVariableSize);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_PAGES)(EFI_ALLOCATE_TYPE Type,
                                               EFI_MEMORY_TYPE MemoryType,
                                               uintptr_t Pages,
                                               uint64_t *inout_Memory);
typedef EFI_STATUS(EFIAPI *EFI_FREE_PAGES)(uint64_t Memory, uintptr_t Pages);
typedef EFI_STATUS(EFIAPI *EFI_GET_MEMORY_MAP)(
    uintptr_t *inout_MemoryMapSize, EFI_MEMORY_DESCRIPTOR *inout_MemoryMap,
    uintptr_t *out_MapKey, uintptr_t *out_DescriptorSize,
    uint32_t *out_DescriptorVersion);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_POOL)(EFI_MEMORY_TYPE PoolType,
                                              uintptr_t Size, void *out_Buffer);
typedef EFI_STATUS(EFIAPI *EFI_FREE_POOL)(void *Buffer);
typedef void(EFIAPI *EFI_SET_MEM)(void *Buffer, uintptr_t Size, uint8_t Value);
typedef void(EFIAPI *EFI_COPY_MEM)(void *Destination, void *Source,
                                   uintptr_t Length);

typedef EFI_STATUS(EFIAPI *EFI_CHECK_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_CLOSE_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_SIGNAL_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_WAIT_FOR_EVENT)(uintptr_t NumberOfEvents,
                                               EFI_EVENT *Events,
                                               uintptr_t *out_Index);
typedef EFI_STATUS(EFIAPI *EFI_SET_TIMER)(EFI_EVENT Event, EFI_TIMER_DELAY Type,
                                          uint64_t TriggerTime);
typedef void(EFIAPI *EFI_EVENT_NOTIFY)(EFI_EVENT Event, void *Context);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT)(uint32_t Type, uintptr_t NotifyTpl,
                                             EFI_EVENT_NOTIFY NotifyFunction,
                                             void *NotifyContext,
                                             EFI_EVENT *out_Event);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT_EX)(
    uint32_t Type, uintptr_t NotifyTpl, EFI_EVENT_NOTIFY opt_NotifyFunction,
    const void *opt_NotifyContext, const EFI_GUID *opt_EventGroup,
    EFI_EVENT *out_Event);

typedef EFI_STATUS(EFIAPI *EFI_UPDATE_CAPSULE)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t opt_ScatterGatherList);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t *out_MaximumCapsuleSize, EFI_RESET_TYPE *out_ResetType);
typedef EFI_STATUS(EFIAPI *EFI_GET_WAKEUP_TIME)(bool32 *out_Enabled,
                                                bool32 *out_Pending,
                                                EFI_TIME *out_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WAKEUP_TIME)(bool32 Enable,
                                                EFI_TIME *opt_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WATCHDOG_TIMER)(uintptr_t Timeout,
                                                   uint64_t WatchdogCode,
                                                   uintptr_t DataSize,
                                                   char16_t *opt_WatchdogData);
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)(EFI_GUID *Protocol,
                                                void *Registration,
                                                void *Interface);

typedef EFI_STATUS(EFIAPI *EFI_SET_TIME)(EFI_TIME *Time);
typedef EFI_STATUS(EFIAPI *EFI_GET_TIME)(
    EFI_TIME *out_Time, EFI_TIME_CAPABILITIES *outopt_Capabilities);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT)(
    uint32_t *out_HighCount);
typedef EFI_STATUS(EFIAPI *EFI_STALL)(uintptr_t Microseconds);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT)(uint64_t *out_Count);

typedef EFI_STATUS(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP)(
    uintptr_t MemoryMapSize, uintptr_t DescriptorSize,
    uint32_t DescriptorVersion, EFI_MEMORY_DESCRIPTOR *VirtualMap);
typedef void(EFIAPI *EFI_RESET_SYSTEM)(EFI_RESET_TYPE ResetType,
                                       EFI_STATUS ResetStatus,
                                       uintptr_t DataSize, void *opt_ResetData);
typedef EFI_STATUS(EFIAPI *EFI_CONVERT_POINTER)(uintptr_t DebugDisposition,
                                                void **inout_Address);

typedef EFI_STATUS(EFIAPI *EFI_INPUT_RESET)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_INPUT_READ_KEY)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, EFI_INPUT_KEY *out_Key);

typedef EFI_STATUS(EFIAPI *EFI_TEXT_RESET)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_TEST_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_QUERY_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber,
    uint64_t *out_Columns, uint64_t *out_Rows);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_ATTRIBUTE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Attribute);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_CLEAR_SCREEN)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_CURSOR_POSITION)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Column, uint64_t Row);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_ENABLE_CURSOR)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 Visible);

typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber,
    uint32_t *SizeOfInfo, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
    EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
    EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, uint32_t SourceX,
    uint32_t SourceY, uint32_t DestinationX, uint32_t DestinationY,
    uint32_t Width, uint32_t Height, uint32_t Delta);

typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(EFI_HANDLE Handle,
                                                EFI_GUID *Protocol,
                                                void *out_Interface);

typedef EFI_STATUS(EFIAPI *EFI_IMAGE_LOAD)(bool32 BootPolicy,
                                           EFI_HANDLE ParentImageHandle,
                                           EFI_DEVICE_PATH_PROTOCOL *DevicePath,
                                           void *opt_SourceBuffer,
                                           uintptr_t SourceSize,
                                           EFI_HANDLE *out_ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_UNLOAD)(EFI_HANDLE ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_EXIT_BOOT_SERVICES)(EFI_HANDLE ImageHandle,
                                                   uintptr_t MapKey);

typedef struct {
  EFI_TABLE_HEADER Hdr;
  EFI_GET_TIME GetTime;
  EFI_SET_TIME SetTime;
  EFI_GET_WAKEUP_TIME GetWakeupTime;
  EFI_SET_WAKEUP_TIME SetWakeupTime;
  EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap;
  EFI_CONVERT_POINTER ConvertPointer;
  EFI_GET_VARIABLE GetVariable;
  EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName;
  EFI_SET_VARIABLE SetVariable;
  EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount;
  EFI_RESET_SYSTEM ResetSystem;
  EFI_UPDATE_CAPSULE UpdateCapsule;
  EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;
  EFI_QUERY_VARIABLE_INFO QueryVariableInfo;
} EFI_RUNTIME_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  void *RaiseTPL;
  void *RestoreTPL;
  EFI_ALLOCATE_PAGES AllocatePages;
  EFI_FREE_PAGES FreePages;
  EFI_GET_MEMORY_MAP GetMemoryMap;
  EFI_ALLOCATE_POOL AllocatePool;
  EFI_FREE_POOL FreePool;
  EFI_CREATE_EVENT CreateEvent;
  EFI_SET_TIMER SetTimer;
  EFI_WAIT_FOR_EVENT WaitForEvent;
  EFI_SIGNAL_EVENT SignalEvent;
  EFI_CLOSE_EVENT CloseEvent;
  EFI_CHECK_EVENT CheckEvent;
  void *InstallProtocolInterface;
  void *ReinstallProtocolInterface;
  void *UninstallProtocolInterface;
  EFI_HANDLE_PROTOCOL HandleProtocol;
  void *Reserved;
  void *RegisterProtocolNotify;
  void *LocateHandle;
  void *LocateDevicePath;
  void *InstallConfigurationTable;
  EFI_IMAGE_LOAD LoadImage;
  void *StartImage;
  EFI_EXIT Exit;
  EFI_IMAGE_UNLOAD UnloadImage;
  EFI_EXIT_BOOT_SERVICES ExitBootServices;
  EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount;
  EFI_STALL Stall;
  EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;
  void *ConnectController;
  void *DisconnectController;
  void *OpenProtocol;
  void *CloseProtocol;
  void *OpenProtocolInformation;
  void *ProtocolsPerHandle;
  void *LocateHandleBuffer;
  EFI_LOCATE_PROTOCOL LocateProtocol;
  void *InstallMultipleProtocolInterfaces;
  void *UninstallMultipleProtocolInterfaces;
  void *CalculateCrc32;
  EFI_COPY_MEM CopyMem;
  EFI_SET_MEM SetMem;
  EFI_CREATE_EVENT_EX CreateEventEx;
} EFI_BOOT_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  char16_t *FirmwareVendor;
  uint32_t FirmwareRevision;
  EFI_HANDLE ConsoleInHandle;
  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
  EFI_HANDLE ConsoleOutHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
  EFI_HANDLE StandardErrorHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
  EFI_RUNTIME_SERVICES *RuntimeServices;
  EFI_BOOT_SERVICES *BootServices;
  uintptr_t NumberOfTableEntries;
  EFI_CONFIGURATION_TABLE *ConfigurationTable;
} EFI_SYSTEM_TABLE;

struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
  EFI_INPUT_RESET Reset;
  EFI_INPUT_READ_KEY ReadKeyStroke;
  EFI_EVENT WaitForKey;
};

struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
  EFI_TEXT_RESET Reset;
  EFI_TEXT_STRING OutputString;
  EFI_TEXT_TEST_STRING TestString;
  EFI_TEXT_QUERY_MODE QueryMode;
  EFI_TEXT_SET_MODE SetMode;
  EFI_TEXT_SET_ATTRIBUTE SetAttribute;
  EFI_TEXT_CLEAR_SCREEN ClearScreen;
  EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition;
  EFI_TEXT_ENABLE_CURSOR EnableCursor;
  EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;
};

struct _EFI_GRAPHICS_OUTPUT_PROTOCOL {
  EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
};

typedef struct {
  uint32_t Revision;
  EFI_HANDLE ParentHandle;
  EFI_SYSTEM_TABLE *SystemTable;
  EFI_HANDLE DeviceHandle;
  EFI_DEVICE_PATH_PROTOCOL *FilePath;
  void *Reserved;
  uint32_t LoadOptionsSize;
  void *LoadOptions;
  void *ImageBase;
  uint64_t ImageSize;
  EFI_MEMORY_TYPE ImageCodeType;
  EFI_MEMORY_TYPE ImageDataType;
  EFI_IMAGE_UNLOAD Unload;
} EFI_LOADED_IMAGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/events.h */

#define COSMOPOLITAN_LIBC_NT_EVENTS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » events                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int32_t GetMessage(struct NtMsg *lpMsg, int64_t hWnd, uint32_t wMsgFilterMin,
                   uint32_t wMsgFilterMax);
int32_t TranslateMessage(const struct NtMsg *lpMsg);
intptr_t DispatchMessage(const struct NtMsg *lpMsg);
void PostQuitMessage(int nExitCode);
bool32 GetCursorPos(struct NtPoint *lpPoint);
int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                    int64_t lParam);

#define EVENTLOG_SUCCESS          0x00000000
#define EVENTLOG_ERROR_TYPE       0x00000001
#define EVENTLOG_WARNING_TYPE     0x00000002
#define EVENTLOG_INFORMATION_TYPE 0x00000004
#define EVENTLOG_AUDIT_SUCCESS    0x00000008
#define EVENTLOG_AUDIT_FAILURE    0x00000010

int32_t ReportEventA(int64_t handle, uint16_t wType, uint16_t wCategory,
                     uint32_t dwEventID, const char *lpUserId,
                     uint16_t wNumStrings, uint32_t dwDataSize,
                     const char **lpStrings, void **lpRawData);
int64_t RegisterEventSource(const char16_t *lpUNCServerName,
                            const char16_t *lpSourceName);
int32_t DeregisterEventSource(uint64_t handle);

int64_t CreateEvent(const struct NtSecurityAttributes *opt_lpEventAttributes,
                    bool32 bManualReset, bool32 bInitialState,
                    const char16_t *opt_lpName);
int64_t CreateEventA(const struct NtSecurityAttributes *opt_lpEventAttributes,
                     bool32 bManualReset, bool32 bInitialState,
                     const char *opt_lpName);
int64_t CreateEventEx(const struct NtSecurityAttributes *lpEventAttributes,
                      const char16_t *lpName, uint32_t dwFlags,
                      uint32_t dwDesiredAccess);

int32_t SetEvent(int64_t hEvent);
int32_t ResetEvent(int64_t hEvent);
int32_t PulseEvent(int64_t hEvent);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/files.h */

#define COSMOPOLITAN_LIBC_NT_FILES_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » files                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtHandleFlagInherit          1 /* SetHandleInformation */
#define kNtHandleFlagProtectFromClose 2

#define kNtFindFirstExCaseSensitive 1
#define kNtFindFirstExLargeFetch    2

#define kNtDuplicateCloseSource 1
#define kNtDuplicateSameAccess  2

COSMOPOLITAN_C_START_

intptr_t LoadResource(int64_t hModule, int64_t hResInfo);
uint32_t SetHandleCount(uint32_t uNumber);
uint32_t GetLogicalDrives(void);
bool32 FlushFileBuffers(int64_t hFile);

int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess,
                   uint32_t dwShareMode, uint32_t dwFlagsAndAttributes);

bool32 DeleteFile(const char16_t *lpFileName) paramsnonnull();

bool32 CopyFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName, bool32 bFailIfExists)
    paramsnonnull();

bool32 MoveFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName) paramsnonnull();
bool32 MoveFileEx(const char16_t *lpExistingFileName,
                  const char16_t *opt_lpNewFileName, int dwFlags)
    paramsnonnull((1));

bool32 SetCurrentDirectory(const char16_t *lpPathName);
uint32_t GetCurrentDirectory(uint32_t nBufferLength, char16_t *out_lpBuffer);

bool32 CreateDirectory(const char16_t *lpPathName,
                       const struct NtSecurityAttributes *lpSecurityAttributes);
bool32 RemoveDirectory(const char16_t *lpPathName);

bool32 DuplicateHandle(int64_t hSourceProcessHandle, int64_t hSourceHandle,
                       int64_t hTargetProcessHandle, int64_t *lpTargetHandle,
                       uint32_t dwDesiredAccess, bool32 bInheritHandle,
                       uint32_t dwOptions);

bool32 GetHandleInformation(int64_t hObject, uint32_t *out_lpdwFlags);
bool32 SetHandleInformation(int64_t hObject, uint32_t dwMask, uint32_t dwFlags);
int GetFileType(int64_t hFile);

bool32 GetFileInformationByHandleEx(int64_t hFile,
                                    uint32_t FileInformationClass,
                                    void *out_lpFileInformation,
                                    uint32_t dwBufferSize);

bool32 GetFileInformationByHandle(
    int64_t hFile, struct NtByHandleFileInformation *lpFileInformation);
bool32 SetFileInformationByHandle(int64_t hFile, int FileInformationClass,
                                  const void *lpFileInformation,
                                  uint32_t dwBufferSize);

uint32_t GetFileAttributes(const char16_t *lpFileName);
bool32 GetFileAttributesEx(
    const char16_t *lpFileName, int fInfoLevelId /* kNtGetFileExInfoStandard */,
    void *out_lpFileInformation /* → struct NtWin32FileAttributeData * */)
    paramsnonnull();

uint32_t GetCompressedFileSize(const char16_t *lpFileName,
                               uint32_t *lpFileSizeHigh);
bool32 SetFileAttributes(const char16_t *lpFileName, uint32_t dwFileAttributes);
bool32 GetFileTime(int64_t hFile, struct NtFileTime *opt_lpCreationFileTime,
                   struct NtFileTime *opt_lpLastAccessFileTime,
                   struct NtFileTime *opt_lpLastWriteFileTime);
bool32 SetFileTime(int64_t hFile,
                   const struct NtFileTime *opt_lpCreationFileTime,
                   const struct NtFileTime *opt_lpLastAccessFileTime,
                   const struct NtFileTime *opt_lpLastWriteFileTime);

bool32 DeviceIoControl(int64_t hDevice, uint32_t dwIoControlCode,
                       void *lpInBuffer, uint32_t nInBufferSize,
                       void *lpOutBuffer, uint32_t nOutBufferSize,
                       uint32_t *lpBytesReturned,
                       struct NtOverlapped *lpOverlapped);

bool32 LockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToLockLow,
                uint32_t nNumberOfBytesToLockHigh);
bool32 UnlockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                  uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToUnlockLow,
                  uint32_t nNumberOfBytesToUnlockHigh);
bool32 LockFileEx(int64_t hFile, uint32_t dwFlags, uint32_t dwReserved,
                  uint32_t nNumberOfBytesToLockLow,
                  uint32_t nNumberOfBytesToLockHigh,
                  struct NtOverlapped *lpOverlapped) paramsnonnull();
bool32 UnlockFileEx(int64_t hFile, uint32_t dwReserved,
                    uint32_t nNumberOfBytesToUnlockLow,
                    uint32_t nNumberOfBytesToUnlockHigh,
                    struct NtOverlapped *lpOverlapped) paramsnonnull();

bool32 CreateHardLink(const char16_t *lpFileName,
                      const char16_t *lpExistingFileName,
                      const struct NtSecurityAttributes *reserved)
    paramsnonnull((1, 2));
bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName,
                          const char16_t *lpTargetPathName, uint32_t dwFlags)
    paramsnonnull();

bool32 SetEndOfFile(int64_t hFile);
bool32 SetFileValidData(int64_t hFile, int64_t ValidDataLength);

bool32 GetFileSecurity(const char16_t *lpFileName,
                       uint32_t RequestedInformation,
                       struct NtSecurityDescriptor *pSecurityDescriptor,
                       uint32_t nLength, uint32_t *lpnLengthNeeded);

bool32 OpenProcessToken(int64_t hProcessHandle, uint32_t dwDesiredAccess,
                        int64_t *out_hTokenHandle);
bool32 DuplicateToken(int64_t hExistingTokenHandle, int dwImpersonationLevel,
                      int64_t *out_hDuplicateTokenHandle);
bool32 DuplicateTokenEx(int64_t hExistingToken, unsigned int dwDesiredAccess,
                        const struct NtSecurityAttributes *lpTokenAttributes,
                        int ImpersonationLevel, int TokenType,
                        int64_t *out_phNewToken);

bool32 AccessCheck(struct NtSecurityDescriptor *pSecurityDescriptor,
                   int64_t ClientToken, unsigned int DesiredAccess,
                   struct NtGenericMapping *lpGenericMapping,
                   struct NtPrivilegeSet *lpPrivilegeSet,
                   unsigned int *PrivilegeSetLength,
                   unsigned int *GrantedAccess, bool32 *AccessStatus);

void MapGenericMask(uint32_t *AccessMask,
                    struct NtGenericMapping *GenericMapping);

int64_t FindFirstFile(const char16_t *lpFileName,
                      struct NtWin32FindData *out_lpFindFileData);
int64_t FindFirstFileEx(const char16_t *lpFileName, int fInfoLevelId,
                        void *out_lpFindFileData, int fSearchOp,
                        void *reserved_lpSearchFilter,
                        uint32_t dwAdditionalFlags);
bool32 FindNextFile(int64_t hFindFile,
                    struct NtWin32FindData *out_lpFindFileData);
bool32 FindClose(int64_t hFindFile);

int64_t FindFirstVolume(char16_t *out_lpszVolumeName, uint32_t cchBufferLength);
bool32 FindNextVolume(int64_t inout_hFindVolume, char16_t *out_lpszVolumeName,
                      uint32_t cchBufferLength);
bool32 FindVolumeClose(int64_t hFindVolume);

bool32 ReadFileScatter(
    int64_t hFileOpenedWithOverlappedAndNoBuffering,
    const union NtFileSegmentElement
        aNullTerminatedPageAlignedSizedSegmentArray[],
    uint32_t nNumberOfBytesToReadThatsMultipleOfFileVolumeSectorSize,
    uint32_t *lpReserved, struct NtOverlapped *inout_lpOverlapped)
    paramsnonnull();

bool32 WriteFileGather(int64_t hFileOpenedWithOverlappedAndNoBuffering,
                       const union NtFileSegmentElement aSegmentArray[],
                       uint32_t nNumberOfBytesToWrite, uint32_t *lpReserved,
                       struct NtOverlapped inout_lpOverlapped) paramsnonnull();

#define kNtFileNameNormalized 0x0
#define kNtFileNameOpened     0x8
#define kNtVolumeNameDos      0x0 /* e.g. \\?\C:\Users\jart */
#define kNtVolumeNameGuid     0x1 /* e.g. \\?\Volume{ea38-etc.}\Users\jart */
#define kNtVolumeNameNt       0x2 /* e.g. \Device\HarddiskVolume4\Users\jart */
#define kNtVolumeNameNone     0x4 /* e.g. \Users\jart */
uint32_t GetFinalPathNameByHandle(int64_t hFile, char16_t *out_path,
                                  uint32_t arraylen, uint32_t flags);

uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength,
                         char16_t *lpBuffer, char16_t **lpFilePart);

bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped,
                           uint32_t *lpNumberOfBytesTransferred, bool32 bWait);
bool32 GetOverlappedResultEx(int64_t hFile, struct NtOverlapped *lpOverlapped,
                             uint32_t *lpNumberOfBytesTransferred,
                             uint32_t dwMilliseconds, bool32 bAlertable);

bool32 GetVolumePathName(const char16_t *lpszFileName,
                         char16_t *lpszVolumePathName,
                         uint32_t cchBufferLength);

bool32 GetVolumeInformationByHandle(int64_t hFile,
                                    char16_t *opt_out_lpVolumeNameBuffer,
                                    uint32_t nVolumeNameSize,
                                    uint32_t *opt_out_lpVolumeSerialNumber,
                                    uint32_t *opt_out_lpMaximumComponentLength,
                                    uint32_t *opt_out_lpFileSystemFlags,
                                    char16_t *opt_out_lpFileSystemNameBuffer,
                                    uint32_t nFileSystemNameSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/files.inc */

#define CopyFile(...) __imp_CopyFileW(__VA_ARGS__)
extern typeof(CopyFile) *const __imp_CopyFileW __msabi;

#define GetFileType(...) __imp_GetFileType(__VA_ARGS__)
extern typeof(GetFileType) *const __imp_GetFileType __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iocp.h */

#define COSMOPOLITAN_LIBC_NT_IOCP_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » i/o completion ports                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtFileSkipCompletionPortOnSuccess 1
#define kNtFileSkipSetEventOnHandle        2

COSMOPOLITAN_C_START_

typedef void (*NtOverlappedCompletionRoutine)(
    uint32_t dwErrorCode, uint32_t dwNumberOfBytesTransfered,
    struct NtOverlapped *inout_lpOverlapped);

int64_t CreateIoCompletionPort(int64_t FileHandleOrNeg1,
                               int64_t opt_ExistingCompletionPortOrZero,
                               uint64_t CompletionKey,
                               uint32_t NumberOfConcurrentThreads);

bool32 GetQueuedCompletionStatus(int64_t CompletionPort,
                                 uint32_t *lpNumberOfBytesTransferred,
                                 uint64_t *out_lpCompletionKey,
                                 struct NtOverlapped **out_lpOverlapped,
                                 uint32_t dwMilliseconds);

bool32 GetQueuedCompletionStatusEx(
    int64_t CompletionPort,
    struct NtOverlappedEntry *out_lpCompletionPortEntries, uint32_t ulCount,
    uint32_t *out_ulNumEntriesRemoved, uint32_t dwMilliseconds,
    bool32 fAlertable);

bool32 PostQueuedCompletionStatus(int64_t CompletionPort,
                                  uint32_t dwNumberOfBytesTransferred,
                                  uint64_t dwCompletionKey,
                                  struct NtOverlapped *opt_lpOverlapped);

bool32 SetFileCompletionNotificationModes(int64_t FileHandle,
                                          unsigned char Flags);

bool32 ReadFileEx(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                  uint32_t *lpNumberOfBytesRead,
                  struct NtOverlapped *opt_lpOverlapped,
                  NtOverlappedCompletionRoutine lpCompletionRoutine);

bool32 WriteFileEx(int64_t hFile, const void *lpBuffer,
                   uint32_t nNumberOfBytesToWrite,
                   struct NtOverlapped *lpOverlapped,
                   NtOverlappedCompletionRoutine lpCompletionRoutine);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_IPC_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ipc                                      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* CreateNamedPipe:dwOpenMode */
#define kNtPipeAccessInbound  0x00000001
#define kNtPipeAccessOutbound 0x00000002
#define kNtPipeAccessDuplex   0x00000003

/* CreateNamedPipe::dwPipeMode */
#define kNtPipeWait                0x00000000
#define kNtPipeNowait              0x00000001
#define kNtPipeReadmodeByte        0x00000000
#define kNtPipeReadmodeMessage     0x00000002
#define kNtPipeTypeByte            0x00000000
#define kNtPipeTypeMessage         0x00000004
#define kNtPipeAcceptRemoteClients 0x00000000
#define kNtPipeRejectRemoteClients 0x00000008

/* CreateNamedPipe::nMaxInstances */
#define kNtPipeUnlimitedInstances 255

/* GetNamedPipeInfo */
#define kNtPipeClientEnd 0x00000000
#define kNtPipeServerEnd 0x00000001

COSMOPOLITAN_C_START_

bool32 CreatePipe(int64_t *out_hReadPipe, int64_t *out_hWritePipe,
                  const struct NtSecurityAttributes *opt_lpPipeAttributes,
                  uint32_t nSize) paramsnonnull((1, 2));

int64_t CreateNamedPipe(
    const char16_t *lpName, uint32_t dwOpenMode, uint32_t dwPipeMode,
    uint32_t nMaxInstances, uint32_t nOutBufferSize, uint32_t nInBufferSize,
    uint32_t nDefaultTimeOut,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes)
    paramsnonnull((1));

bool32 CallNamedPipe(const char16_t *lpNamedPipeName, void *lpInBuffer,
                     uint32_t nInBufferSize, void *lpOutBuffer,
                     uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                     uint32_t nTimeOut);

bool32 ConnectNamedPipe(int64_t hNamedPipe, struct NtOverlapped *lpOverlapped);
bool32 WaitNamedPipe(const char16_t *lpNamedPipeName, uint32_t nTimeOut);
bool32 DisconnectNamedPipe(int64_t hNamedPipe);

bool32 SetNamedPipeHandleState(int64_t hNamedPipe, uint32_t *lpMode,
                               uint32_t *lpMaxCollectionCount,
                               uint32_t *lpCollectDataTimeout);

bool32 PeekNamedPipe(int64_t hNamedPipe, void *lpBuffer, uint32_t nBufferSize,
                     uint32_t *opt_lpBytesRead, uint32_t *opt_lpTotalBytesAvail,
                     uint32_t *opt_lpBytesLeftThisMessage);

bool32 TransactNamedPipe(int64_t hNamedPipe, void *lpInBuffer,
                         uint32_t nInBufferSize, void *lpOutBuffer,
                         uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                         struct NtOverlapped *lpOverlapped);

bool32 GetNamedPipeInfo(int64_t hNamedPipe, uint32_t *opt_out_lpFlags,
                        uint32_t *opt_out_lpOutBufferSize,
                        uint32_t *opt_out_lpInBufferSize,
                        uint32_t *opt_out_lpMaxInstances);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iphlpapi.h */

#define COSMOPOLITAN_LIBC_NT_IPHLPAPI_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ip helper api                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetAdaptersAddresses(uint32_t Family, uint32_t Flags, void *Reserved,
                              struct NtIpAdapterAddresses *AdapterAddresses,
                              uint32_t *SizePointer);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_MEMORY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » memory                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtNumaNoPreferredNode 0xffffffffu

COSMOPOLITAN_C_START_

void *LocalFree(void *hMem);

int64_t CreateFileMapping(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName);
int64_t CreateFileMappingNuma(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName, uint32_t nndDesiredNumaNode);

void *MapViewOfFileEx(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                      uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                      size_t dwNumberOfBytesToMap,
                      void *opt_lpDesiredBaseAddress);
void *MapViewOfFileExNuma(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                          uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                          size_t dwNumberOfBytesToMap,
                          void *opt_lpDesiredBaseAddress,
                          uint32_t nndDesiredNumaNode);

bool32 UnmapViewOfFile(const void *lpBaseAddress);
bool32 FlushViewOfFile(const void *lpBaseAddress,
                       size_t dwNumberOfBytesToFlush);

void *VirtualAlloc(void *opt_lpAddress, uint64_t dwSize,
                   uint32_t flAllocationType, uint32_t flProtect);
bool32 VirtualFree(void *lpAddress, uint64_t dwSize, uint32_t dwFreeType);
bool32 VirtualProtect(void *lpAddress, uint64_t dwSize, uint32_t flNewProtect,
                      uint32_t *lpflOldProtect) paramsnonnull();
bool32 VirtualLock(const void *lpAddress, size_t dwSize);
bool32 VirtualUnlock(const void *lpAddress, size_t dwSize);
uint64_t VirtualQuery(const void *lpAddress,
                      struct NtMemoryBasicInformation *lpBuffer,
                      uint64_t dwLength);
void *VirtualAllocEx(int64_t hProcess, void *lpAddress, uint64_t dwSize,
                     uint32_t flAllocationType, uint32_t flProtect);

int64_t GetProcessHeap(void);
void *HeapAlloc(int64_t hHeap, uint32_t dwFlags, size_t dwBytes) __wur;
bool32 HeapFree(int64_t hHeap, uint32_t dwFlags, void *opt_lpMem);
void *HeapReAlloc(int64_t hHeap, uint32_t dwFlags, void *lpMem,
                  size_t dwBytes) __wur;

void *GlobalAlloc(uint32_t uFlags, uint64_t dwBytes) __wur;
void *GlobalFree(void *hMem);

/**
 * @param AllocationType
 *     - kNtMemReserve
 *     - kNtMemReplacePlaceholder
 *     - kNtMemLargePages
 */
void *MapViewOfFile3(
    intptr_t FileMapping, intptr_t Process, void *opt_BaseAddress,
    uint64_t Offset, size_t ViewSize, unsigned AllocationType,
    unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

void *VirtualAlloc2(
    intptr_t opt_Process, void *opt_BaseAddress, size_t Size,
    unsigned AllocationType, unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/memory.inc */

extern typeof(LocalFree) *const __imp_LocalFree __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/messagebox.h */

#define COSMOPOLITAN_LIBC_NT_MESSAGEBOX_H_
COSMOPOLITAN_C_START_

int MessageBox(int64_t hWnd, const char16_t *lpText, const char16_t *lpCaption,
               uint32_t mbType);
int MessageBoxEx(int64_t hWnd, const char16_t *lpText,
                 const char16_t *lpCaption, uint32_t mbType,
                 uint16_t wLanguageId);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdll.h */

#define COSMOPOLITAN_LIBC_NT_NTDLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

#define __nt_system_call_dispatcher (wambda *)0x7ffe0308

extern const struct NtUnicodeString *const RtlNtdllName;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » eponymous runtime      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define NT_PROCESS_FLAGS_CREATE_SUSPENDED 0x00000001
#define NT_PROCESS_FLAGS_INHERIT_HANDLES  0x00000002
#define NT_PROCESS_FLAGS_NO_SYNCHRONIZE   0x00000004
#define NT_RTL_CLONE_PARENT               0
#define NT_RTL_CLONE_CHILD                297

NtStatus NtCallbackReturn(void *opt_Result, uint32_t ResultLength,
                          int32_t Status);
NtStatus NtTestAlert(void);

NtStatus NtOpenFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                    struct NtObjectAttributes *ObjectAttributes,
                    struct NtIoStatusBlock *out_IoStatusBlock,
                    uint32_t ShareAccess, uint32_t OpenOptions);

NtStatus NtQueryInformationToken(int64_t TokenHandle,
                                 uint32_t TokenInformationClass,
                                 void *out_TokenInformation,
                                 uint32_t TokenInformationLength,
                                 uint32_t *out_ReturnLength);
NtStatus NtYieldExecution(void);
NtStatus NtQuerySystemInformation(uint32_t info_class, void *out_info,
                                  uint32_t info_size,
                                  uint32_t *out_bytes_received);
NtStatus NtReadVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                             void *out_Buffer, size_t BufferLength,
                             size_t *opt_out_ReturnLength);
NtStatus NtCreateTimer(void **out_TimerHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       uint32_t TimerType);
NtStatus NtSetTimer(void *TimerHandle, int64_t *DueTime, void *TimerApcRoutine,
                    void *TimerContext, int32_t Resume, int32_t Period,
                    int32_t *out_PreviousState);
NtStatus NtQueryObject(void *ObjectHandle, int ObjectInformationClass,
                       void *out_ObjectInformation,
                       uint32_t ObjectInformationLength,
                       uint32_t *opt_out_ReturnLength);
NtStatus NtQueryFullAttributesFile(
    struct NtObjectAttributes *attributes,
    struct NtFileNetworkOpenInformation *out_info);
NtStatus NtCreateKey(void **out_KeyHandle, uint32_t DesiredAccess,
                     struct NtObjectAttributes *ObjectAttributes,
                     uint32_t TitleIndex, struct NtUnicodeString *opt_Class,
                     uint32_t CreateOptions, uint32_t *opt_out_Disposition);
NtStatus NtOpenKey(void **out_KeyHandle, uint32_t DesiredAccess,
                   struct NtObjectAttributes *ObjectAttributes);
NtStatus NtSetValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                       uint32_t opt_TitleIndex, uint32_t Type, void *Data,
                       uint32_t DataSize);
NtStatus NtDeleteKey(void *KeyHandle);
NtStatus NtQueryValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                         int KeyValueInformationClass,
                         void *out_KeyValueInformation, uint32_t Length,
                         uint32_t *out_ResultLength);
NtStatus NtFlushKey(void *KeyHandle);
NtStatus NtEnumerateKey(int64_t hkey, uint32_t index, int info_class,
                        void *out_key_info, uint32_t key_info_size,
                        uint32_t *out_bytes_received);
NtStatus NtEnumerateValueKey(int64_t hKey, uint32_t index, int info_class,
                             void *out_key_info, uint32_t key_info_size,
                             uint32_t *out_bytes_received);
NtStatus NtQuerySystemTime(int64_t *SystemTime);
NtStatus NtDeleteFile(struct NtObjectAttributes *ObjectAttributes);
NtStatus NtFlushBuffersFile(int64_t FileHandle,
                            struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateIoCompletion(void **out_IoCompletionHandle,
                              uint32_t DesiredAccess,
                              struct NtObjectAttributes *ObjectAttributes,
                              uint32_t NumberOfConcurrentThreads);
NtStatus NtRaiseHardError(int32_t ErrorStatus, uint32_t NumberOfArguments,
                          uint32_t UnicodeStringArgumentsMask, void *Arguments,
                          uint32_t MessageBoxType,
                          uint32_t *out_MessageBoxResult);
NtStatus NtRaiseException(struct NtExceptionRecord *ExceptionRecord,
                          struct NtContext *Context, int32_t SearchFrames);
NtStatus NtCreateEvent(void **out_EventHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       int EventType, int32_t InitialState);
NtStatus NtWaitForSingleObject(void *ObjectHandle, int32_t Alertable,
                               int64_t *TimeOut);
NtStatus NtSetEvent(void *EventHandle, int32_t *opt_out_PreviousState);
NtStatus NtClearEvent(void *EventHandle);
NtStatus NtSignalAndWaitForSingleObject(void *ObjectToSignal,
                                        void *WaitableObject, int32_t Alertable,
                                        int64_t *opt_Time);
NtStatus NtQueryPerformanceCounter(int64_t *out_PerformanceCount,
                                   int64_t *opt_out_PerformanceFrequency);
NtStatus NtFsControlFile(int64_t FileHandle, void *opt_Event,
                         NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                         struct NtIoStatusBlock *out_IoStatusBlock,
                         uint32_t FsControlCode, void *opt_InputBuffer,
                         uint32_t InputBufferLength, void *opt_out_OutputBuffer,
                         uint32_t OutputBufferLength);
NtStatus NtCancelIoFile(int64_t FileHandle,
                        struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateProfile(void **out_ProfileHandle, int64_t ProcessHandle,
                         void *Base, uint32_t Size, uint32_t BucketShift,
                         uint32_t *Buffer, uint32_t BufferLength, int Source,
                         uint32_t ProcessorMask);
NtStatus NtSetIntervalProfile(uint32_t Interval, int Source);
NtStatus NtQueryIntervalProfile(int Source, uint32_t *out_Interval);
NtStatus NtStartProfile(void *ProfileHandle);
NtStatus NtStopProfile(void *ProfileHandle);
NtStatus NtCreateDirectoryObject(int64_t *out_DirectoryHandle,
                                 uint32_t DesiredAccess,
                                 struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenDirectoryObject(int64_t *out_DirectoryHandle,
                               uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenSymbolicLinkObject(int64_t *out_DirectoryHandle,
                                  uint32_t DesiredAccess,
                                  struct NtObjectAttributes *ObjectAttributes);
NtStatus NtQuerySymbolicLinkObject(int64_t DirectoryHandle,
                                   struct NtUnicodeString *inout_TargetName,
                                   uint32_t *opt_out_ReturnLength);
NtStatus ZwAreMappedFilesTheSame(void *Address1, void *Address2);
NtStatus NtQueryVolumeInformationFile(int64_t FileHandle,
                                      struct NtIoStatusBlock *out_IoStatusBlock,
                                      void *out_FsInformation, uint32_t Length,
                                      uint32_t FsInformationClass);
NtStatus NtQuerySecurityObject(
    int64_t handle, int RequestedInformation,
    struct NtSecurityDescriptor *out_SecurityDescriptor,
    uint32_t SecurityDescriptorLength, uint32_t *out_ReturnLength);
NtStatus NtQueueApcThread(int64_t ThreadHandle, NtPkNormalRoutine ApcRoutine,
                          void *opt_ApcContext, void *opt_Argument1,
                          void *opt_Argument2);
NtStatus NtFlushInstructionCache(int64_t ProcessHandle, void *opt_BaseAddress,
                                 size_t FlushSize);
NtStatus NtQueryAttributesFile(const struct NtObjectAttributes *object,
                               struct NtFileBasicInformation *file_information);
NtStatus NtQueryDirectoryFile(
    int64_t FileHandle, void *opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    void *out_FileInformation, uint32_t FileInformationLength,
    uint32_t FileInformationClass, int32_t ReturnSingleEntry,
    struct NtUnicodeString *opt_FileName, int32_t RestartScan);
NtStatus NtFlushVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                              uint32_t **inout_FlushSize,
                              struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtQueryInformationJobObject(void *JobHandle, int JobInformationClass,
                                     void *out_JobInformation,
                                     uint32_t JobInformationLength,
                                     uint32_t *opt_out_ReturnLength);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » runtime library        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

NtStatus RtlInitializeCriticalSection(struct NtCriticalSection *out_crit);
NtStatus RtlDeleteCriticalSection(struct NtCriticalSection *crit);
NtStatus RtlEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlLeaveCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlTryEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlInitUnicodeString(struct NtUnicodeString *inout_DestinationString,
                              const char16_t *SourceString);
void RtlFreeUnicodeString(struct NtUnicodeString **string);
NtStatus RtlQueryEnvironmentVariable_U(char16_t *Environment,
                                       struct NtUnicodeString *Name,
                                       struct NtUnicodeString *Value);
NtStatus RtlConvertSidToUnicodeString(struct NtUnicodeString *out_UnicodeString,
                                      void *Sid,
                                      int32_t AllocateDestinationString);
void *RtlCreateHeap(uint32_t flags, void *base, size_t reserve_sz,
                    size_t commit_sz, void *lock, void *params);
NtStatus RtlDestroyHeap(void *base);
void *RtlAllocateHeap(int64_t heap, uint32_t flags, size_t size);
void *RtlReAllocateHeap(int64_t heap, uint32_t flags, void *ptr, size_t size);
NtStatus RtlFreeHeap(int64_t heap, uint32_t flags, void *ptr);
size_t RtlSizeHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlValidateHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlLockHeap(int64_t heap);
NtStatus RtlUnlockHeap(int64_t heap);
NtStatus RtlGetProcessHeaps(uint32_t count, void **out_Heaps);
NtStatus RtlWalkHeap(int64_t heap, void *out_Info);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntdll.inc */

#define NtYieldExecution(...) __imp_NtYieldExecution(__VA_ARGS__)

extern typeof(NtYieldExecution) *const __imp_NtYieldExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdllimport.h */

/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8     -*-│
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8                                 :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney                              │
│                                                                              │
│ Permission to use, copy, modify, and/or distribute this software for         │
│ any purpose with or without fee is hereby granted, provided that the         │
│ above copyright notice and this permission notice appear in all copies.      │
│                                                                              │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             │
│ PERFORMANCE OF THIS SOFTWARE.                                                │
╚─────────────────────────────────────────────────────────────────────────────*/
#define COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_
#ifdef __ASSEMBLER__
/* clang-format off */

.macro	.ntimp	fn:req name:req
#ifdef __x86_64__
	.yoink	_init_ntdll
	.initbss 202,_init_ntdll.\fn
__imp_\fn:
	.quad	0
	.endobj	__imp_\fn,globl,hidden
	.previous
	.initro 202,_init_ntdll.2.\fn
	.quad	RVA(.L\fn)
	.previous
	.section .rodata.str1.1,"aSM",@progbits,1
.L\fn:
	.asciz	"\fn"
	.previous
#elif defined(__aarch64__)
	.section .data.nt.\fn,"aw",@progbits
	.globl	__imp_\fn
	.balign	8
__imp_\fn:
	.quad	\name
	.weak	\name
#endif
.endm

/* clang-format on */
#endif /* __ASSEMBLER__ */


/*!BEGIN libc/nt/paint.h */

#define COSMOPOLITAN_LIBC_NT_PAINT_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » cpu graphics                             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t BeginPaint(int64_t hWnd, struct NtPaintStruct *lpPaint);
int32_t EndPaint(int64_t hWnd, const struct NtPaintStruct *lpPaint);
int32_t BitBlt(int64_t hdc, int x, int y, int cx, int cy, int64_t hdcSrc,
               int x1, int y1, uint32_t rop);
int32_t GetClientRect(int64_t hWnd, struct NtRect *lpRect);
int32_t GetWindowRect(int64_t hWnd, struct NtRect *lpRect);
int32_t SetBkMode(int64_t hdc, int mode);
uint32_t SetTextColor(int64_t hdc, uint32_t color);
uint32_t SetTextAlign(int64_t hdc, uint32_t align);
int32_t SetTextJustification(int64_t hdc, int extra, int count);
int32_t DrawText(int64_t hdc, const char16_t *lpchText, int cchText,
                 struct NtRect *lprc, uint32_t format);
int32_t DrawTextEx(int64_t hdc, char16_t *lpchText, int cchText,
                   struct NtRect *lprc, uint32_t format,
                   struct NtDrawTextParams *lpdtp);
int32_t FillRect(int64_t hDC, const struct NtRect *lpRC, int64_t hBrush);
uint32_t GetPixel(int64_t hdc, int x, int y);
uint32_t SetPixel(int64_t hdc, int x, int y, uint32_t color);
bool32 RedrawWindow(int64_t hWnd, const struct NtRect *opt_lprcUpdate,
                    int64_t opt_hrgnUpdate, uint32_t rdwFlags);
int64_t CreateCompatibleDC(int64_t hdc);
int64_t CreateCompatibleBitmap(int64_t hdc, int cx, int cy);
int64_t SelectObject(int64_t hdc, int64_t h);
bool32 DeleteObject(int64_t ho);
bool32 DeleteDC(int64_t hdc);
int SaveDC(int64_t hdc);
bool32 RestoreDC(int64_t hdc, int nSavedDC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/paint.inc */

#define SetPixel(...) __imp_SetPixel(__VA_ARGS__)
#define GetPixel(...) __imp_GetPixel(__VA_ARGS__)

extern typeof(SetPixel) *const __imp_SetPixel __msabi;
extern typeof(GetPixel) *const __imp_GetPixel __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/pdh.h */

#define COSMOPOLITAN_LIBC_NT_PDH_H_

/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » performance counters                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int PdhOpenQuery(const char16_t *opt_szDataSource, uint32_t *dwUserData,
                 int64_t *out_phQuery);

int PdhAddEnglishCounter(int64_t hQuery, const char16_t *szFullCounterPath,
                         uint32_t *dwUserData, int64_t *out_phCounter);

int PdhCollectQueryDataEx(int64_t hQuery, uint32_t dwIntervalTime,
                          int64_t hNewDataEvent);

int PdhGetFormattedCounterValue(int64_t hCounter, uint32_t dwFormat,
                                uint32_t *out_opt_lpdwType,
                                struct NtPdhFmtCountervalue *out_pValue);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/privilege.h */

#define COSMOPOLITAN_LIBC_NT_PRIVILEGE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » check your privilege                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtSePrivilegeEnabledByDefault 0x00000001u
#define kNtSePrivilegeEnabled          0x00000002u
#define kNtSePrivilegeRemoved          0x00000004u
#define kNtSePrivilegeUsedForAccess    0x80000000u

COSMOPOLITAN_C_START_

bool32 LookupPrivilegeValue(const char16_t *opt_lpSystemName,
                            const char16_t *lpName, struct NtLuid *out_lpLuid);

bool32 AdjustTokenPrivileges(int64_t TokenHandle, bool32 DisableAllPrivileges,
                             const struct NtTokenPrivileges *opt_NewState,
                             uint32_t BufferLength,
                             struct NtTokenPrivileges *opt_out_PreviousState,
                             uint32_t *opt_out_ReturnLength);

bool32 ImpersonateSelf(int kNtSecurityImpersonationLevel);
bool32 RevertToSelf(void);

bool32 OpenThreadToken(intptr_t ThreadHandle, uint32_t DesiredAccess,
                       bool32 OpenAsSelf, intptr_t *TokenHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_PROCESS_H_


/*!BEGIN libc/nt/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_NTSTARTUPINFO_H_
COSMOPOLITAN_C_START_

#define kNtProcThreadAttributeParentProcess 0x00020000
#define kNtProcThreadAttributeHandleList    0x00020002

void GetStartupInfo(struct NtStartupInfo *lpStartupInfo);

bool32 InitializeProcThreadAttributeList(
    struct NtProcThreadAttributeList *opt_inout_lpAttributeList,
    uint32_t dwAttributeCount, uint32_t reserved_dwFlags, size_t *inout_lpSize);
bool32 UpdateProcThreadAttribute(
    struct NtProcThreadAttributeList *inout_lpAttributeList, uint32_t dwFlags,
    uint64_t Attribute, const void *lpValue, size_t cbSize,
    void *reserved_lpPreviousValue, size_t *reserved_lpReturnSize);
void DeleteProcThreadAttributeList(
    struct NtProcThreadAttributeList *inout_lpAttributeList);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/startupinfo.inc */

#define GetStartupInfo(...) __imp_GetStartupInfoW(__VA_ARGS__)

extern typeof(GetStartupInfo) *const __imp_GetStartupInfoW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » processes                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 CreateProcess(const char16_t *opt_lpApplicationName,
                     char16_t *lpCommandLine,
                     const struct NtSecurityAttributes *opt_lpProcessAttributes,
                     const struct NtSecurityAttributes *opt_lpThreadAttributes,
                     bool32 bInheritHandles, uint32_t dwCreationFlags,
                     void *opt_lpEnvironment,
                     const char16_t *opt_lpCurrentDirectory,
                     const struct NtStartupInfo *lpStartupInfo,
                     struct NtProcessInformation *opt_out_lpProcessInformation)
    paramsnonnull((9));

uint32_t GetThreadId(int64_t hThread);   /* cf. NT_TID */
uint32_t GetProcessId(int64_t hProcess); /* cf. NT_PID */
void SetLastError(uint32_t dwErrCode);
uint32_t FormatMessage(uint32_t dwFlags, const void *lpSource,
                       uint32_t dwMessageId, uint32_t dwLanguageId,
                       char16_t *lpBuffer, uint32_t nSize, va_list *Arguments);
uint32_t FormatMessageA(uint32_t dwFlags, const void *lpSource,
                        uint32_t dwMessageId, uint32_t dwLanguageId,
                        char *lpBuffer, uint32_t nSize, va_list *Arguments);
int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                    uint32_t dwProcessId);
uint32_t GetCurrentProcessId(void); /* %gs:0x40 */
uint32_t GetEnvironmentVariable(const char16_t *lpName, char16_t *lpBuffer,
                                uint32_t nSize);
uint32_t SetEnvironmentVariable(const char16_t *lpName,
                                const char16_t *lpValue);
int32_t SetEnvironmentStrings(char16_t *NewEnvironment);
bool32 GetProcessAffinityMask(int64_t hProcess, uint64_t *lpProcessAffinityMask,
                              uint64_t *lpSystemAffinityMask);
uint64_t /*bool32*/ SetProcessAffinityMask(int64_t hProcess,
                                           uint64_t dwProcessAffinityMask);

/* e.g. kNtAboveNormalPriorityClass, kNtHighPriorityClass */
uint32_t GetPriorityClass(int64_t hProcess);
bool32 SetPriorityClass(int64_t hProcess, uint32_t dwPriorityClass);
bool32 SetProcessPriorityBoost(int64_t hProcess, bool32 bDisablePriorityBoost);
bool32 GetProcessPriorityBoost(int64_t hProcess, bool32 *pDisablePriorityBoost);

bool32 GetProcessMemoryInfo(
    int64_t hProcess, struct NtProcessMemoryCountersEx *out_ppsmemCounters,
    uint32_t cb);

int64_t CreateToolhelp32Snapshot(uint32_t dwFlags, uint32_t th32ProcessID);
bool32 Process32First(int64_t hSnapshot, struct NtProcessEntry32 *in_out_lppe);
bool32 Process32Next(int64_t hSnapshot, struct NtProcessEntry32 *out_lppe);

bool32 EnumProcesses(uint32_t *out_lpidProcess, uint32_t cb,
                     uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModules(int64_t hProcess, int64_t *out_lphModule, uint32_t cb,
                          uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModulesEx(int64_t hProcess, int64_t *out_lphModule,
                            uint32_t cb, uint32_t *out_lpcbNeeded,
                            uint32_t dwFilterFlag) paramsnonnull();
uint32_t GetModuleBaseName(int64_t hProcess, int64_t opt_hModule,
                           char16_t *out_lpBaseName, uint32_t nSize)
    paramsnonnull();

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/process.inc */

#define GetEnvironmentVariable(...) __imp_GetEnvironmentVariableW(__VA_ARGS__)
extern typeof(GetEnvironmentVariable) *const __imp_GetEnvironmentVariableW
    __msabi;

#define SetEnvironmentVariable(...) __imp_SetEnvironmentVariableW(__VA_ARGS__)
extern typeof(SetEnvironmentVariable) *const __imp_SetEnvironmentVariableW
    __msabi;

#define GetPriorityClass(...) __imp_GetPriorityClass(__VA_ARGS__)
extern typeof(GetPriorityClass) *const __imp_GetPriorityClass __msabi;

#define SetPriorityClass(...) __imp_SetPriorityClass(__VA_ARGS__)
extern typeof(SetPriorityClass) *const __imp_SetPriorityClass __msabi;

#define GetCurrentProcessId(...) __imp_GetCurrentProcessId(__VA_ARGS__)
extern typeof(GetCurrentProcessId) *const __imp_GetCurrentProcessId __msabi;

extern typeof(FormatMessage) *const __imp_FormatMessageW __msabi;
extern typeof(SetLastError) *const __imp_SetLastError __msabi;
extern typeof(FormatMessage) *const __imp_FormatMessage __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/registry.h */

#define COSMOPOLITAN_LIBC_NT_REGISTRY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » registry                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtMaxKeyNameChars   255
#define kNtMaxValueNameChars 16383
#define kNtMaxValueBytes     0x100000

#define kNtHkeyClassesRoot              0x80000000l
#define kNtHkeyCurrentUser              0x80000001l
#define kNtHkeyLocalMachine             0x80000002l
#define kNtHkeyUsers                    0x80000003l
#define kNtHkeyPerformanceData          0x80000004l
#define kNtHkeyPerformanceText          0x80000050l
#define kNtHkeyPerformanceNlstext       0x80000060l
#define kNtHkeyCurrentConfig            0x80000005l
#define kNtHkeyDynData                  0x80000006l
#define kNtHkeyCurrentUserLocalSettings 0x80000007l

COSMOPOLITAN_C_START_

int RegOpenKey(int64_t hKey, const char16_t *opt_lpSubKey,
               int64_t *out_phkResult) paramsnonnull((3));
int RegOpenKeyEx(int64_t hKey, const char16_t *opt_lpSubKey,
                 uint32_t opt_ulOptions, int samDesired, int64_t *out_phkResult)
    paramsnonnull((5));
int RegCloseKey(int64_t hKey);

int RegGetValue(int64_t hkey, const char16_t *opt_lpSubKey,
                const char16_t *opt_lpValue, unsigned dwFlags, int *opt_pdwType,
                void *opt_out_pvData, uint32_t *opt_inout_pcbDataBytes);
int RegSetValue(int64_t hKey, const char16_t *lpSubKey, int dwType,
                const char16_t *lpData, uint32_t cbData);
int RegSetValueEx(int64_t hKey, const char16_t *lpValueName, uint32_t Reserved,
                  int dwType, const unsigned char *lpData, uint32_t cbData);

int RegQueryInfoKey(int64_t hKey, char16_t *opt_out_lpClass,
                    uint32_t *opt_inout_lpClassLen, uint32_t *lpReserved,
                    uint32_t *opt_out_lpcSubKeys,
                    uint32_t *opt_out_lpcbMaxSubKeyBytes,
                    uint32_t *opt_out_lpcbMaxClassBytes,
                    uint32_t *opt_out_lpcValues,
                    uint32_t *opt_out_lpcbMaxValueNameBytes,
                    uint32_t *opt_out_lpcbMaxValueBytes,
                    uint32_t *opt_out_lpcbSecurityDescriptorBytes,
                    struct NtFileTime *opt_out_lpftLastWriteTime);
int RegEnumKey(int64_t hKey, uint32_t dwIndex, char16_t *opt_lpName,
               uint32_t NameLen);
int RegEnumKeyEx(int64_t hKey, uint32_t dwIndex, char16_t *out_lpName,
                 uint32_t *inout_lpcchName, uint32_t *lpReserved,
                 char16_t *opt_out_lpClass, uint32_t *opt_inout_lpcchClassLen,
                 struct NtFileTime *opt_out_lpftLastWriteTime);

int RegEnumValue(int64_t hKey, uint32_t dwIndex, char16_t *lpValueName,
                 uint32_t *lpValueNameLen, uint32_t *lpReserved,
                 int *opt_out_lpType, unsigned char *opt_out_lpData,
                 uint32_t *opt_inout_lpcbDataBytes);
int RegQueryValue(int64_t hKey, const char16_t *opt_lpSubKey,
                  char16_t *opt_out_lpData, int32_t *opt_inout_lpcbDataBytes);
int RegQueryValueEx(int64_t hKey, const char16_t *opt_lpValueName,
                    uint32_t *lpReserved, int *opt_out_lpType,
                    unsigned char *opt_out_lpData,
                    uint32_t *opt_inout_lpcbDataBytes);

int RegOverridePredefKey(int64_t hKey, int64_t hNewHKey);
int RegOpenUserClassesRoot(void *hToken, uint32_t dwOptions, int samDesired,
                           int64_t *phkResult);
int RegOpenCurrentUser(int samDesired, int64_t *phkResult);
int RegDisablePredefinedCache();
int RegConnectRegistry(const char16_t *lpMachineName, int64_t hKey,
                       int64_t *phkResult);
int RegConnectRegistryEx(const char16_t *lpMachineName, int64_t hKey,
                         uint32_t Flags, int64_t *phkResult);
int RegCreateKey(int64_t hKey, const char16_t *lpSubKey, int64_t *phkResult);
int RegCreateKeyEx(int64_t hKey, const char16_t *lpSubKey, uint32_t Reserved,
                   int16_t *lpClass, uint32_t dwOptions, int samDesired,
                   const struct NtSecurityAttributes *lpSecurityAttributes,
                   int64_t *phkResult, uint32_t *lpdwDisposition);
int RegDeleteKey(int64_t hKey, const char16_t *lpSubKey);
int RegDeleteKeyEx(int64_t hKey, const char16_t *lpSubKey, int samDesired,
                   uint32_t Reserved);
int RegDeleteTree(int64_t hKey, const char16_t *opt_lpSubKey);
int RegDisableReflectionKey(int64_t hBase);
int RegEnableReflectionKey(int64_t hBase);
int RegQueryReflectionKey(int64_t hBase, bool32 *bIsReflectionDisabled);
int RegDeleteValue(int64_t hKey, const char16_t *lpValueName);
int RegFlushKey(int64_t hKey);
int RegGetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor,
                      uint32_t *lpcbSecurityDescriptorBytes);
int RegLoadKey(int64_t hKey, const char16_t *lpSubKey, const char16_t *lpFile);
int RegNotifyChangeKeyValue(int64_t hKey, bool32 bWatchSubtree,
                            uint32_t dwNotifyFilter, void *hEvent,
                            int fAsynchronous);
int RegQueryMultipleValues(int64_t hKey, struct NtValent *inout_val_list,
                           uint32_t num_vals, int16_t *out_lpValueBuf,
                           uint32_t *inout_ldwTotsize) paramsnonnull();
int RegReplaceKey(int64_t hKey, const char16_t *lpSubKey,
                  const char16_t *lpNewFile, const char16_t *lpOldFile);
int RegRestoreKey(int64_t hKey, const char16_t *lpFile, uint32_t dwFlags);
int RegSaveKey(int64_t hKey, const char16_t *lpFile,
               const struct NtSecurityAttributes *lpSecurityAttributes);
int RegSetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor);
int RegUnLoadKey(int64_t hKey, const char16_t *lpSubKey);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/runtime.h */

#define COSMOPOLITAN_LIBC_NT_RUNTIME_H_

/**
 * @fileoverview NT Obligatory Runtime Functions.
 *
 * These functions are placed in their own file because they're (a)
 * abstracted by the Cosmopolitan runtime; and (b) it helps GCC avoid
 * bloating binaries with debug information the user doesn't need.
 */

#define kNtCpUtf8             65001
#define kNtInvalidHandleValue -1L
#define kNtStdInputHandle     -10u
#define kNtStdOutputHandle    -11u
#define kNtStdErrorHandle     -12u

#define GetCurrentProcess() -1

COSMOPOLITAN_C_START_

char16_t *GetCommandLine(void) nosideeffect;
char16_t *GetEnvironmentStrings(void) __wur;
bool32 FreeEnvironmentStrings(char16_t *) paramsnonnull();
bool32 ReadFile(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                uint32_t *lpNumberOfBytesRead,
                struct NtOverlapped *opt_lpOverlapped);
bool32 WriteFile(int64_t hFile, const void *lpBuffer,
                 uint32_t nNumberOfBytesToWrite,
                 uint32_t *lpNumberOfBytesWritten,
                 struct NtOverlapped *opt_lpOverlapped);
bool32 TerminateProcess(int64_t hProcess, uint32_t uExitCode);
void TerminateThisProcess(uint32_t dwWaitStatus) wontreturn;
void ExitProcess(uint32_t uExitCode) wontreturn;
uint32_t GetLastError(void) nosideeffect;
bool32 CloseHandle(int64_t hObject) dontthrow dontcallback;
intptr_t GetStdHandle(uint32_t nStdHandle) nosideeffect;
bool32 SetStdHandle(uint32_t nStdHandle, int64_t hHandle);
bool32 SetDefaultDllDirectories(unsigned dirflags);
bool32 ProcessPrng(void *RandomBuffer, uint32_t RandomBufferLength);
uint32_t GetModuleFileName(int64_t hModule, char16_t *lpFilename,
                           uint32_t nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/runtime.inc */

#define FreeEnvironmentStrings(...) __imp_FreeEnvironmentStringsW(__VA_ARGS__)
extern typeof(FreeEnvironmentStrings) *const __imp_FreeEnvironmentStringsW
    __msabi;

#define GetCommandLine(...) __imp_GetCommandLineW(__VA_ARGS__)
extern typeof(GetCommandLine) *const __imp_GetCommandLineW __msabi;

#define GetEnvironmentStrings(...) __imp_GetEnvironmentStringsW(__VA_ARGS__)
extern typeof(GetEnvironmentStrings) *const __imp_GetEnvironmentStringsW
    __msabi;

#define GetStdHandle(...) __imp_GetStdHandle(__VA_ARGS__)
extern typeof(GetStdHandle) *const __imp_GetStdHandle __msabi;

#define SetStdHandle(...) __imp_SetStdHandle(__VA_ARGS__)
extern typeof(SetStdHandle) *const __imp_SetStdHandle __msabi;

#define ReadFile(...) __imp_ReadFile(__VA_ARGS__)
extern typeof(ReadFile) *const __imp_ReadFile __msabi;

#define WriteFile(...) __imp_WriteFile(__VA_ARGS__)
extern typeof(WriteFile) *const __imp_WriteFile __msabi;

#define SetDefaultDllDirectories(...) \
  __imp_SetDefaultDllDirectories(__VA_ARGS__)
extern typeof(SetDefaultDllDirectories) *const __imp_SetDefaultDllDirectories
    __msabi;

#define GetModuleFileName(...) __imp_GetModuleFileNameW(__VA_ARGS__)
extern typeof(GetModuleFileName) *const __imp_GetModuleFileNameW __msabi;

extern typeof(GetLastError) *const __imp_GetLastError __msabi;
extern typeof(ExitProcess) *const __imp_ExitProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/signals.h */

#define COSMOPOLITAN_LIBC_NT_EXCEPTIONS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » signals                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

typedef int (*NtTopLevelExceptionFilter)(const struct NtExceptionPointers *);
typedef int32_t (*NtVectoredExceptionHandler)(struct NtExceptionPointers *);

int SetErrorMode(int uMode);

int64_t AddVectoredExceptionHandler(uint32_t First,
                                    NtVectoredExceptionHandler pHandler);
int64_t AddVectoredContinueHandler(uint32_t First,
                                   NtVectoredExceptionHandler pHandler);

uint32_t RemoveVectoredExceptionHandler(int64_t hHandle);
uint32_t RemoveVectoredContinueHandler(int64_t hHandle);

NtTopLevelExceptionFilter SetUnhandledExceptionFilter(
    NtTopLevelExceptionFilter opt_lpTopLevelExceptionFilter);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/signals.inc */

#define SetErrorMode(...) __imp_SetErrorMode(__VA_ARGS__)
#define AddVectoredExceptionHandler(...) \
  __imp_AddVectoredExceptionHandler(__VA_ARGS__)
#define AddVectoredContinueHandler(...) \
  __imp_AddVectoredContinueHandler(__VA_ARGS__)
#define RemoveVectoredExceptionHandler(...) \
  __imp_RemoveVectoredExceptionHandler(__VA_ARGS__)
#define RemoveVectoredContinueHandler(...) \
  __imp_RemoveVectoredContinueHandler(__VA_ARGS__)
#define SetUnhandledExceptionFilter(...) \
  __imp_SetUnhandledExceptionFilter(__VA_ARGS__)

extern typeof(SetErrorMode) *const __imp_SetErrorMode __msabi;
extern typeof(AddVectoredExceptionHandler) *const
    __imp_AddVectoredExceptionHandler __msabi;
extern typeof(AddVectoredContinueHandler) *const
    __imp_AddVectoredContinueHandler __msabi;
extern typeof(RemoveVectoredExceptionHandler) *const
    __imp_RemoveVectoredExceptionHandler __msabi;
extern typeof(RemoveVectoredContinueHandler) *const
    __imp_RemoveVectoredContinueHandler __msabi;
extern typeof(SetUnhandledExceptionFilter) *const
    __imp_SetUnhandledExceptionFilter __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/synchronization.h */

#define COSMOPOLITAN_LIBC_NT_SYNCHRONIZATION_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » synchronization                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

static inline int32_t InterlockedAdd(int32_t volatile *p, int32_t x) {
  return atomic_fetch_add((_Atomic(int32_t) *)p, x) + x;
}

static inline int32_t InterlockedExchange(int32_t volatile *p, int32_t x) {
  return atomic_exchange((_Atomic(int32_t) *)p, x);
}

typedef void (*NtTimerapcroutine)(void *lpArgToCompletionRoutine,
                                  uint32_t dwTimerLowValue,
                                  uint32_t dwTimerHighValue);
typedef void (*NtWaitOrTimerCallback)(void *lpParameter,
                                      bool32 TimerOrWaitFired);

void WakeByAddressAll(void *Address);
void WakeByAddressSingle(void *Address);
bool32 WaitOnAddress(const volatile void *Address, void *CompareAddress,
                     size_t AddressSize, uint32_t opt_dwMilliseconds);

void Sleep(uint32_t dwMilliseconds);
uint32_t SleepEx(uint32_t dwMilliseconds, bool32 bAlertable);

void GetSystemTime(struct NtSystemTime *lpSystemTime);
bool32 SystemTimeToFileTime(const struct NtSystemTime *lpSystemTime,
                            struct NtFileTime *lpFileTime);
void GetSystemTimeAsFileTime(struct NtFileTime *);
void GetSystemTimePreciseAsFileTime(struct NtFileTime *); /* win8+ */

uint32_t WaitForSingleObject(int64_t hHandle, uint32_t dwMilliseconds);
uint32_t WaitForMultipleObjects(uint32_t nCount, const int64_t *lpHandles,
                                bool32 bWaitAll, uint32_t dwMilliseconds);
uint32_t WaitForSingleObjectEx(int64_t hHandle, uint32_t dwMilliseconds,
                               bool32 bAlertable);
uint32_t WaitForMultipleObjectsEx(unsigned int nCount, const int64_t *lpHandles,
                                  bool32 bWaitAll, uint32_t dwMilliseconds,
                                  bool32 bAlertable);
bool32 RegisterWaitForSingleObject(int64_t *phNewWaitObject, int64_t hObject,
                                   NtWaitOrTimerCallback Callback,
                                   void *Context, uint32_t dwMilliseconds,
                                   uint32_t dwFlags);

int64_t CreateWaitableTimer(
    const struct NtSecurityAttributes *lpTimerAttributes, bool32 bManualReset,
    const char16_t *lpTimerName);
bool32 SetWaitableTimer(int64_t hTimer, const int64_t *lpDueTimeAsFtOrNegRela,
                        int32_t opt_lPeriodMs, NtTimerapcroutine opt_callback,
                        void *lpArgToCallback, bool32 fUnsleepSystem);

int64_t CreateSemaphore(
    const struct NtSecurityAttributes *opt_lpSemaphoreAttributes,
    uint32_t lInitialCount, uint32_t lMaximumCount, const char16_t *opt_lpName);

int32_t ReleaseMutex(int64_t hMutex);
int32_t ReleaseSemaphore(int64_t hSemaphore, int32_t lReleaseCount,
                         int *lpPreviousCount);

void InitializeCriticalSection(struct NtCriticalSection *lpCriticalSection);
void EnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void LeaveCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t TryEnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void DeleteCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t InitializeCriticalSectionAndSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);
uint32_t SetCriticalSectionSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);

void InitializeSRWLock(intptr_t *);
void AcquireSRWLockExclusive(intptr_t *);
void AcquireSRWLockShared(intptr_t *);
void ReleaseSRWLockExclusive(intptr_t *);
void ReleaseSRWLockShared(intptr_t *);
void TryAcquireSRWLockExclusive(intptr_t *);
void TryAcquireSRWLockShared(intptr_t *);

uint64_t GetTickCount64(void);

bool32 QueryPerformanceFrequency(uint64_t *lpFrequency);
bool32 QueryPerformanceCounter(uint64_t *lpPerformanceCount);
bool32 GetSystemTimeAdjustment(uint32_t *lpTimeAdjustment,
                               uint32_t *lpTimeIncrement,
                               bool32 *lpTimeAdjustmentDisabled);

void GetCurrentProcessorNumberEx(struct NtProcessorNumber *out_ProcNumber);

bool32 GetNumaProcessorNodeEx(const struct NtProcessorNumber *Processor,
                              unsigned short *out_NodeNumber);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/synchronization.inc */

extern typeof(SleepEx) *const __imp_SleepEx __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/system.h */

#define COSMOPOLITAN_LIBC_NT_SYSTEM_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » system control                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

bool32 SetSuspendState(bool32 bHibernate, bool32 bForce,
                       bool32 bWakeupEventsDisabled);

uint32_t InitiateShutdown(const char16_t *lpMachineName,
                          const char16_t *lpMessage, uint32_t dwGracePeriod,
                          uint32_t dwShutdownFlags, uint32_t dwReason);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_INFO_H_
COSMOPOLITAN_C_START_

void GetSystemInfo(struct NtSystemInfo *lpSystemInfo);
uint32_t GetSystemDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetSystemDirectoryA(char *lpBuffer, uint32_t uSize);
uint32_t GetWindowsDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetTempPath(uint32_t uSize, char16_t *lpBuffer);

bool32 GetComputerNameEx(/* enum/computernameformat.h */ int NameType,
                         char16_t *opt_lpBuffer, uint32_t *nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/systeminfo.inc */

#define GetSystemInfo(...) __imp_GetSystemInfo(__VA_ARGS__)
#define GetTempPath(...) __imp_GetTempPathW(__VA_ARGS__)

extern typeof(GetSystemInfo) *const __imp_GetSystemInfo __msabi;
extern typeof(GetTempPath) *const __imp_GetTempPathW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_THREADS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » threads                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t CreateThread(const struct NtSecurityAttributes *lpThreadAttributes,
                     size_t dwStackSize, void *lpStartAddress,
                     void *lpParameter, uint32_t dwCreationFlags,
                     uint32_t *opt_lpThreadId) paramsnonnull((3));

void ExitThread(uint32_t dwExitCode) wontreturn;
int64_t GetCurrentThread(void);
uint32_t GetCurrentThreadId(void);
uint64_t SetThreadAffinityMask(int64_t hThread, uintptr_t dwThreadAffinityMask);
int64_t OpenThread(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                   uint32_t dwThreadId);
bool32 TerminateThread(int64_t hThread, uint32_t dwExitCode);
bool32 GetExitCodeThread(int64_t hThread, uint32_t *lpExitCode);

/* e.g. kNtThreadPriorityAboveNormal, -1u on error */
uint32_t GetThreadPriority(int64_t hThread);
bool32 SetThreadPriority(int64_t hThread, int32_t nPriority);
bool32 SetThreadPriorityBoost(int64_t hThread, bool32 bDisablePriorityBoost);
bool32 GetThreadPriorityBoost(int64_t hThread, bool32 *pDisablePriorityBoost);
bool32 GetThreadIOPendingFlag(int64_t hThread, bool32 *lpIOIsPending);

bool32 CancelSynchronousIo(int64_t hThread);
bool32 CancelIo(int64_t hFile);
bool32 CancelIoEx(int64_t hFile, struct NtOverlapped *opt_lpOverlapped);

uint32_t TlsAlloc(void);
bool32 TlsFree(uint32_t);
bool32 TlsSetValue(uint32_t, void *);
void *TlsGetValue(uint32_t);

uint32_t SuspendThread(int64_t hThread);
uint32_t ResumeThread(int64_t hThread);
bool32 GetThreadContext(int64_t hThread, struct NtContext *in_out_lpContext);
bool32 SetThreadContext(int64_t hThread, const struct NtContext *lpContext);

void *SetThreadDescription(int64_t hThread,
                           const char16_t *lpThreadDescription);
void *GetThreadDescription(int64_t hThread,
                           char16_t *out_ppszThreadDescription);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/thread.inc */

#define GetCurrentThread(...)  __imp_GetCurrentThread(__VA_ARGS__)
#define GetThreadPriority(...) __imp_GetThreadPriority(__VA_ARGS__)
#define SetThreadPriority(...) __imp_SetThreadPriority(__VA_ARGS__)

extern typeof(GetCurrentThread) *const __imp_GetCurrentThread __msabi;
extern typeof(GetThreadPriority) *const __imp_GetThreadPriority __msabi;
extern typeof(SetThreadPriority) *const __imp_SetThreadPriority __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_TIME_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » time                                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetTimeZoneInformation(
    struct NtTimeZoneInformation *out_lpTimeZoneInformation);
uint32_t GetDynamicTimeZoneInformation(
    struct NtDynamicTimeZoneInformation *out_lpTimeZoneInformation);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/version.h */

#define COSMOPOLITAN_LIBC_NT_VERSION_H_
COSMOPOLITAN_C_START_

bool32 IsAtLeastWindows10(void) pureconst;
bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
#define GetNtMajorVersion()        \
  __extension__({                  \
    uintptr_t __x;                 \
    __asm__("mov\t%%gs:96,%q0\r\n" \
            "mov\t280(%q0),%b0"    \
            : "=q"(__x));          \
    (unsigned char)__x;            \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/windows.h */

#define COSMOPOLITAN_LIBC_NT_WINDOWS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » windows                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

int64_t CreateWindowEx(uint32_t dwExStyle, const char16_t *lpClassName,
                       const char16_t *lpWindowName, uint32_t dwStyle, int X,
                       int Y, int nWidth, int nHeight, int64_t hWndParent,
                       int64_t hMenu, int64_t hInstance, int64_t lpParam);

uint16_t RegisterClass(const struct NtWndClass *lpWndClass);

int64_t DefWindowProc(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                      int64_t lParam);

int32_t CloseWindow(int64_t hWnd);
int32_t DestroyWindow(int64_t hWnd);
int32_t ShowWindow(int64_t hWnd, int sw);
int32_t ShowCaret(bool32 bShow);
int32_t AnimateWindow(int64_t hWnd, uint32_t dwTime, uint32_t dwFlags);
int64_t LoadIcon(int64_t hInstance, const char16_t *lpIconName);
int32_t MoveWindow(int64_t hWnd, int X, int Y, int nWidth, int nHeight,
                   bool32 bRepaint);
int32_t BringWindowToTop(int64_t hWnd);
int32_t IsWindowVisible(int64_t hWnd);
int32_t SetWindowText(int64_t hWnd, const char16_t *lpString);
int32_t GetWindowText(int64_t hWnd, char16_t *lpString, int nMaxCount);
int32_t SetWindowPos(int64_t hWnd, int64_t hWndInsertAfter, int X, int Y,
                     int cx, int cy, uint32_t uFlags);
bool32 GetWindowPlacement(int64_t hWnd, struct NtWindowPlacement *lpwndpl);
bool32 SetWindowPlacement(int64_t hWnd,
                          const struct NtWindowPlacement *lpwndpl);

int64_t GetCursor(void);
int64_t SetCursor(int64_t hCursor);
int32_t ShowCursor(bool32 bShow);
int64_t LoadCursor(int64_t opt_hInstance, const char16_t *lpCursorNameOrIdc);

bool32 IsWindow(int64_t hWnd);
bool32 IsMenu(int64_t hMenu);
bool32 IsChild(int64_t hWndParent, int64_t hWnd);
bool32 IsZoomed(int64_t hWnd);
bool32 IsIconic(int64_t hWnd);

uintptr_t SetTimer(int64_t opt_hWnd, uintptr_t nIDEvent, uint32_t uElapseMs,
                   NtTimerProc lpTimerFunc);
int32_t KillTimer(int64_t hWnd, uintptr_t uIDEvent);

int64_t SetCapture(int64_t hWnd);
bool32 ReleaseCapture(void);
int16_t GetKeyState(int32_t nVirtKey);

int64_t CreateMenu(void);
int64_t CreatePopupMenu(void);
int64_t GetMenu(int64_t hWnd);
bool32 DestroyMenu(int64_t hMenu);
int64_t GetSystemMenu(int64_t hWnd, bool32 bRevert);
bool32 AppendMenu(int64_t hMenu, uint32_t mfFlags, uintptr_t uIDNewItem,
                  const char16_t *lpNewItem);
bool32 InsertMenu(int64_t hMenu, uint32_t uPosition, uint32_t uFlags,
                  uintptr_t uIDNewItem, const char16_t *lpNewItem);
bool32 TrackPopupMenu(int64_t hMenu, uint32_t uFlags, int32_t x, int32_t y,
                      int32_t nReserved, int64_t hWnd,
                      const struct NtRect *prcRect);

int WideCharToMultiByte(unsigned int CodePage, uint32_t dwFlags,
                        uint16_t *lpWideCharStr, int cchWideChar,
                        char *lpMultiByteStr, int cbMultiByte,
                        uint16_t *lpDefaultChar, int *lpUsedDefaultChar);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/clktck.h */

#define COSMOPOLITAN_LIBC_RUNTIME_CLKTCK_H_
COSMOPOLITAN_C_START_

#define CLK_TCK (__clk_tck())

int __clk_tck(void) pureconst;

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/fenv.h */

#define COSMOPOLITAN_LIBC_RUNTIME_FENV_H_

#ifdef __x86_64__
#define FE_INVALID    1
#define __FE_DENORM   2
#define FE_DIVBYZERO  4
#define FE_OVERFLOW   8
#define FE_UNDERFLOW  16
#define FE_INEXACT    32
#define FE_ALL_EXCEPT 63
#define FE_TONEAREST  0x0000
#define FE_DOWNWARD   0x0400
#define FE_UPWARD     0x0800
#define FE_TOWARDZERO 0x0c00
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint16_t fexcept_t;

#elif defined(__aarch64__)
#define FE_INVALID    1
#define FE_DIVBYZERO  2
#define FE_OVERFLOW   4
#define FE_UNDERFLOW  8
#define FE_INEXACT    16
#define FE_ALL_EXCEPT 31
#define FE_TONEAREST  0
#define FE_DOWNWARD   0x800000
#define FE_UPWARD     0x400000
#define FE_TOWARDZERO 0xc00000
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint32_t fexcept_t;

#elif defined(__powerpc64__)
#define FE_TONEAREST                  0
#define FE_TOWARDZERO                 1
#define FE_UPWARD                     2
#define FE_DOWNWARD                   3
#define FE_INEXACT                    0x02000000
#define FE_DIVBYZERO                  0x04000000
#define FE_UNDERFLOW                  0x08000000
#define FE_OVERFLOW                   0x10000000
#define FE_INVALID                    0x20000000
#define FE_ALL_EXCEPT                 0x3e000000
#define FE_INVALID_SNAN               0x01000000
#define FE_INVALID_ISI                0x00800000
#define FE_INVALID_IDI                0x00400000
#define FE_INVALID_ZDZ                0x00200000
#define FE_INVALID_IMZ                0x00100000
#define FE_INVALID_COMPARE            0x00080000
#define FE_INVALID_SOFTWARE           0x00000400
#define FE_INVALID_SQRT               0x00000200
#define FE_INVALID_INTEGER_CONVERSION 0x00000100
#define FE_ALL_INVALID                0x01f80700
#define FE_DFL_ENV                    ((const fenv_t *)-1)
typedef unsigned fexcept_t;
typedef double fenv_t;

#endif /* __x86_64__ */

#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD_TS_18661_3__
#elif defined(__FLT_EVAL_METHOD__)
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#else
#define FLT_EVAL_METHOD 0
#endif

COSMOPOLITAN_C_START_

#define FLT_ROUNDS (__flt_rounds())

int feclearexcept(int);
int fegetenv(fenv_t *);
int fegetexceptflag(fexcept_t *, int);
int fegetround(void);
int feholdexcept(fenv_t *);
int feraiseexcept(int);
int fesetenv(const fenv_t *);
int fesetexceptflag(const fexcept_t *, int);
int fesetround(int);
int fetestexcept(int);
int feenableexcept(int);
int fedisableexcept(int);
int feupdateenv(const fenv_t *);
int __flt_rounds(void);
int __fesetround(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/pathconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_PATHCONF_H_

#define _PC_LINK_MAX           0
#define _PC_MAX_CANON          1
#define _PC_MAX_INPUT          2
#define _PC_NAME_MAX           3
#define _PC_PATH_MAX           4
#define _PC_PIPE_BUF           5
#define _PC_CHOWN_RESTRICTED   6
#define _PC_NO_TRUNC           7
#define _PC_VDISABLE           8
#define _PC_SYNC_IO            9
#define _PC_ASYNC_IO           10
#define _PC_PRIO_IO            11
#define _PC_SOCK_MAXBUF        12
#define _PC_FILESIZEBITS       13
#define _PC_REC_INCR_XFER_SIZE 14
#define _PC_REC_MAX_XFER_SIZE  15
#define _PC_REC_MIN_XFER_SIZE  16
#define _PC_REC_XFER_ALIGN     17
#define _PC_ALLOC_SIZE_MIN     18
#define _PC_SYMLINK_MAX        19
#define _PC_2_SYMLINKS         20

COSMOPOLITAN_C_START_

long fpathconf(int, int);
long pathconf(const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/runtime.h */

#define COSMOPOLITAN_LIBC_RUNTIME_RUNTIME_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § runtime                                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#ifdef __x86_64__
typedef long jmp_buf[8];
typedef long sigjmp_buf[11];
#elif defined(__aarch64__)
typedef long jmp_buf[22];
typedef long sigjmp_buf[25];
#elif defined(__powerpc64__)
typedef unsigned __int128 jmp_buf[32];
#elif defined(__s390x__)
typedef unsigned long jmp_buf[18];
#elif defined(__riscv)
typedef unsigned long jmp_buf[26];
#endif

void mcount(void);
int daemon(int, int);
unsigned long getauxval(unsigned long);
int setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
int _setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
void siglongjmp(sigjmp_buf, int) libcesque wontreturn paramsnonnull();
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
void exit(int) wontreturn;
void _exit(int) libcesque wontreturn;
void _Exit(int) libcesque wontreturn;
void quick_exit(int) wontreturn;
void abort(void) wontreturn;
int atexit(void (*)(void)) paramsnonnull() libcesque;
char *getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
int putenv(char *);
int setenv(const char *, const char *, int);
int unsetenv(const char *);
int clearenv(void);
void fpreset(void);
void *mmap(void *, uint64_t, int32_t, int32_t, int32_t, int64_t);
int munmap(void *, uint64_t);
int mprotect(void *, uint64_t, int);
int msync(void *, size_t, int);
int mlock(const void *, size_t);
int munlock(const void *, size_t);
long gethostid(void);
int sethostid(long);
char *getlogin(void);
int getlogin_r(char *, size_t);
int login_tty(int);
int getpagesize(void);
int syncfs(int) dontthrow;
int vhangup(void);
int getdtablesize(void);
int sethostname(const char *, size_t);
int acct(const char *);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
extern char **environ;
char *secure_getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
#endif

#ifdef _COSMO_SOURCE
extern int __argc;
extern char **__argv;
extern char **__envp;
extern unsigned long *__auxv;
extern intptr_t __oldstack;
extern char *__program_executable_name;
extern uint64_t __nosync;
extern int __strace;
extern int __ftrace;
extern uint64_t __syscount;
extern uint64_t kStartTsc;
extern const char kNtSystemDirectory[];
extern const char kNtWindowsDirectory[];
extern size_t __virtualmax;
extern size_t __stackmax;
extern bool32 __isworker;
/* utilities */
void _intsort(int *, size_t);
void _longsort(long *, size_t);
/* diagnostics */
void ShowCrashReports(void);
int ftrace_install(void);
int ftrace_enabled(int);
int strace_enabled(int);
void __print_maps(void);
void __printargs(const char *);
/* builtin sh-like system/popen dsl */
int _cocmd(int, char **, char **);
/* executable program */
char *GetProgramExecutableName(void);
char *GetInterpreterExecutableName(char *, size_t);
int __open_executable(void);
/* execution control */
int verynice(void);
void __warn_if_powersave(void);
void _Exit1(int) libcesque wontreturn;
void __paginate(int, const char *);
void __paginate_file(int, const char *);
/* memory management */
void _weakfree(void *);
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
void CheckForMemoryLeaks(void);
void CheckForFileLeaks(void);
bool32 _isheap(const void *);
void __enable_threads(void);
void __oom_hook(size_t);
/* code morphing */
void __morph_begin(void);
void __morph_end(void);
void __jit_begin(void);
void __jit_end(void);
void __clear_cache(void *, void *);
/* portability */
int NtGetVersion(void) pureconst;
bool32 IsGenuineBlink(void);
bool32 IsCygwin(void);
const char *GetCpuidOs(void);
const char *GetCpuidEmulator(void);
void GetCpuidBrand(char[13], uint32_t);
long __get_rlimit(int);
const char *__describe_os(void);
long __get_sysctl(int, int);
int __get_arg_max(void) pureconst;
int __get_cpu_count(void) pureconst;
long __get_avphys_pages(void) pureconst;
long __get_phys_pages(void) pureconst;
long __get_minsigstksz(void) pureconst;
void __get_main_stack(void **, size_t *, int *);
long __get_safe_size(long, long);
char *__get_tmpdir(void);
forceinline int __trace_disabled(int x) {
  return 0;
}
#ifndef FTRACE
#define ftrace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#ifndef SYSDEBUG
#define strace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/stack.h */

#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_

/**
 * Returns preferred size and alignment of thread stack.
 */
#define GetStackSize() 262144

/**
 * Returns preferred stack guard size.
 *
 * This is the max cpu page size of supported architectures.
 */
#define GetGuardSize() 16384

/**
 * Align APE main thread stack at startup.
 *
 * You need this in your main program module:
 *
 *     STATIC_STACK_ALIGN(GetStackSize());
 *
 * If you want to use GetStackAddr() and HaveStackMemory() safely on
 * your main thread in your process. It causes crt.S to waste a tiny
 * amount of memory to ensure those macros go extremely fast.
 */
#define STATIC_STACK_ALIGN(BYTES) \
  _STACK_SYMBOL("ape_stack_align", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Makes program stack executable if declared, e.g.
 *
 *     STATIC_EXEC_STACK();
 *     int main() {
 *       char code[16] = {
 *           0x55,                          // push %rbp
 *           0xb8, 0007, 0x00, 0x00, 0x00,  // mov  $7,%eax
 *           0x5d,                          // push %rbp
 *           0xc3,                          // ret
 *       };
 *       int (*func)(void) = (void *)code;
 *       printf("result %d should be 7\n", func());
 *     }
 */
#define STATIC_EXEC_STACK() _STACK_SYMBOL("ape_stack_pf", "7")

#define _STACK_STRINGIFY(ADDR) #ADDR
#define _STACK_SYMBOL(NAME, VALUE)       \
  __asm__(".equ\t" NAME "," VALUE "\n\t" \
          ".globl\t" NAME)

#ifdef __SANITIZE_ADDRESS__
#define _STACK_EXTRA "*2"
#else
#define _STACK_EXTRA ""
#endif

#if defined(__GNUC__) && defined(__ELF__)
COSMOPOLITAN_C_START_

extern char ape_stack_prot[] __attribute__((__weak__));
extern char ape_stack_memsz[] __attribute__((__weak__));
extern char ape_stack_align[] __attribute__((__weak__));

/**
 * Returns address of bottom of current stack.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants.
 */
#define GetStackAddr() ((GetStackPointer() - 1) & -GetStackSize())

#define GetStaticStackSize() ((uintptr_t)ape_stack_memsz)

/**
 * Returns true if at least `n` bytes of stack are available.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants,
 * which make this check exceedingly fast.
 */
#define HaveStackMemory(n) \
  (GetStackPointer() >= GetStackAddr() + GetGuardSize() + (n))

/**
 * Extends stack memory by poking large allocations.
 *
 * This can be particularly useful depending on how your system
 * implements guard pages. For example, Windows can make stacks
 * that aren't fully committed, in which case there's only 4096
 * bytes of grows-down guard pages made by portable executable.
 * If you alloca() more memory than that, you should call this,
 * since it'll not only ensure stack overflows are detected, it
 * will also trigger the stack to grow down safely.
 */
forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
  for (; n > 0; n -= 4096) {
    ((char *)p)[n - 1] = 0;
  }
}

void *NewCosmoStack(void) vallocesque;
int FreeCosmoStack(void *) libcesque;

/**
 * Tunes stack size of main thread on Windows.
 *
 * On UNIX systems use `RLIMIT_STACK` to tune the main thread size.
 */
#define STATIC_STACK_SIZE(BYTES) \
  _STACK_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Tunes main thread stack address on Windows.
 */
#define STATIC_STACK_ADDR(ADDR) \
  _STACK_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))

#ifdef __x86_64__
/**
 * Returns preferred bottom address of main thread stack.
 *
 * On UNIX systems we favor the system provided stack, so this only
 * really applies to Windows. It's configurable at link time. It is
 * needed because polyfilling fork requires that we know, precicely
 * where the stack memory begins and ends.
 */
#define GetStaticStackAddr(ADDEND)          \
  ({                                        \
    intptr_t vAddr;                         \
    __asm__(".weak\tape_stack_vaddr\n\t"    \
            "movabs\t%1+ape_stack_vaddr,%0" \
            : "=r"(vAddr)                   \
            : "i"(ADDEND));                 \
    vAddr;                                  \
  })
#else
#define GetStaticStackAddr(ADDEND) (GetStackAddr() + ADDEND)
#endif

#define GetStackPointer()           \
  ({                                \
    uintptr_t __sp;                 \
    __asm__(__mov_sp : "=r"(__sp)); \
    __sp;                           \
  })

#ifdef __x86_64__
#define __mov_sp "mov\t%%rsp,%0"
#elif defined(__aarch64__)
#define __mov_sp "mov\t%0,sp"
#endif

COSMOPOLITAN_C_END_
#endif /* GNU ELF */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_STACK_H_ */


/*!BEGIN libc/runtime/sysconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_SYSCONF_H_

#define _SC_ARG_MAX                      0
#define _SC_CHILD_MAX                    1
#define _SC_CLK_TCK                      2
#define _SC_NGROUPS_MAX                  3
#define _SC_OPEN_MAX                     4
#define _SC_STREAM_MAX                   5
#define _SC_TZNAME_MAX                   6
#define _SC_JOB_CONTROL                  7
#define _SC_SAVED_IDS                    8
#define _SC_REALTIME_SIGNALS             9
#define _SC_PRIORITY_SCHEDULING          10
#define _SC_TIMERS                       11
#define _SC_ASYNCHRONOUS_IO              12
#define _SC_PRIORITIZED_IO               13
#define _SC_SYNCHRONIZED_IO              14
#define _SC_FSYNC                        15
#define _SC_MAPPED_FILES                 16
#define _SC_MEMLOCK                      17
#define _SC_MEMLOCK_RANGE                18
#define _SC_MEMORY_PROTECTION            19
#define _SC_MESSAGE_PASSING              20
#define _SC_SEMAPHORES                   21
#define _SC_SHARED_MEMORY_OBJECTS        22
#define _SC_AIO_LISTIO_MAX               23
#define _SC_AIO_MAX                      24
#define _SC_AIO_PRIO_DELTA_MAX           25
#define _SC_DELAYTIMER_MAX               26
#define _SC_MQ_OPEN_MAX                  27
#define _SC_MQ_PRIO_MAX                  28
#define _SC_VERSION                      29
#define _SC_PAGE_SIZE                    30
#define _SC_PAGESIZE                     30 /* !! */
#define _SC_RTSIG_MAX                    31
#define _SC_SEM_NSEMS_MAX                32
#define _SC_SEM_VALUE_MAX                33
#define _SC_SIGQUEUE_MAX                 34
#define _SC_TIMER_MAX                    35
#define _SC_BC_BASE_MAX                  36
#define _SC_BC_DIM_MAX                   37
#define _SC_BC_SCALE_MAX                 38
#define _SC_BC_STRING_MAX                39
#define _SC_COLL_WEIGHTS_MAX             40
#define _SC_EXPR_NEST_MAX                42
#define _SC_LINE_MAX                     43
#define _SC_RE_DUP_MAX                   44
#define _SC_2_VERSION                    46
#define _SC_2_C_BIND                     47
#define _SC_2_C_DEV                      48
#define _SC_2_FORT_DEV                   49
#define _SC_2_FORT_RUN                   50
#define _SC_2_SW_DEV                     51
#define _SC_2_LOCALEDEF                  52
#define _SC_UIO_MAXIOV                   60 /* !! */
#define _SC_IOV_MAX                      60
#define _SC_THREADS                      67
#define _SC_THREAD_SAFE_FUNCTIONS        68
#define _SC_GETGR_R_SIZE_MAX             69
#define _SC_GETPW_R_SIZE_MAX             70
#define _SC_LOGIN_NAME_MAX               71
#define _SC_TTY_NAME_MAX                 72
#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73
#define _SC_THREAD_KEYS_MAX              74
#define _SC_THREAD_STACK_MIN             75
#define _SC_THREAD_THREADS_MAX           76
#define _SC_THREAD_ATTR_STACKADDR        77
#define _SC_THREAD_ATTR_STACKSIZE        78
#define _SC_THREAD_PRIORITY_SCHEDULING   79
#define _SC_THREAD_PRIO_INHERIT          80
#define _SC_THREAD_PRIO_PROTECT          81
#define _SC_THREAD_PROCESS_SHARED        82
#define _SC_NPROCESSORS_CONF             83
#define _SC_NPROCESSORS_ONLN             84
#define _SC_PHYS_PAGES                   85
#define _SC_AVPHYS_PAGES                 86
#define _SC_ATEXIT_MAX                   87
#define _SC_PASS_MAX                     88
#define _SC_XOPEN_VERSION                89
#define _SC_XOPEN_XCU_VERSION            90
#define _SC_XOPEN_UNIX                   91
#define _SC_XOPEN_CRYPT                  92
#define _SC_XOPEN_ENH_I18N               93
#define _SC_XOPEN_SHM                    94
#define _SC_2_CHAR_TERM                  95
#define _SC_2_UPE                        97
#define _SC_XOPEN_XPG2                   98
#define _SC_XOPEN_XPG3                   99
#define _SC_XOPEN_XPG4                   100
#define _SC_NZERO                        109
#define _SC_XBS5_ILP32_OFF32             125
#define _SC_XBS5_ILP32_OFFBIG            126
#define _SC_XBS5_LP64_OFF64              127
#define _SC_XBS5_LPBIG_OFFBIG            128
#define _SC_XOPEN_LEGACY                 129
#define _SC_XOPEN_REALTIME               130
#define _SC_XOPEN_REALTIME_THREADS       131
#define _SC_ADVISORY_INFO                132
#define _SC_BARRIERS                     133
#define _SC_CLOCK_SELECTION              137
#define _SC_CPUTIME                      138
#define _SC_THREAD_CPUTIME               139
#define _SC_MONOTONIC_CLOCK              149
#define _SC_READER_WRITER_LOCKS          153
#define _SC_SPIN_LOCKS                   154
#define _SC_REGEXP                       155
#define _SC_SHELL                        157
#define _SC_SPAWN                        159
#define _SC_SPORADIC_SERVER              160
#define _SC_THREAD_SPORADIC_SERVER       161
#define _SC_TIMEOUTS                     164
#define _SC_TYPED_MEMORY_OBJECTS         165
#define _SC_2_PBS                        168
#define _SC_2_PBS_ACCOUNTING             169
#define _SC_2_PBS_LOCATE                 170
#define _SC_2_PBS_MESSAGE                171
#define _SC_2_PBS_TRACK                  172
#define _SC_SYMLOOP_MAX                  173
#define _SC_STREAMS                      174
#define _SC_2_PBS_CHECKPOINT             175
#define _SC_V6_ILP32_OFF32               176
#define _SC_V6_ILP32_OFFBIG              177
#define _SC_V6_LP64_OFF64                178
#define _SC_V6_LPBIG_OFFBIG              179
#define _SC_HOST_NAME_MAX                180
#define _SC_TRACE                        181
#define _SC_TRACE_EVENT_FILTER           182
#define _SC_TRACE_INHERIT                183
#define _SC_TRACE_LOG                    184
#define _SC_IPV6                         235
#define _SC_RAW_SOCKETS                  236
#define _SC_V7_ILP32_OFF32               237
#define _SC_V7_ILP32_OFFBIG              238
#define _SC_V7_LP64_OFF64                239
#define _SC_V7_LPBIG_OFFBIG              240
#define _SC_SS_REPL_MAX                  241
#define _SC_TRACE_EVENT_NAME_MAX         242
#define _SC_TRACE_NAME_MAX               243
#define _SC_TRACE_SYS_MAX                244
#define _SC_TRACE_USER_EVENT_MAX         245
#define _SC_XOPEN_STREAMS                246
#define _SC_THREAD_ROBUST_PRIO_INHERIT   247
#define _SC_THREAD_ROBUST_PRIO_PROTECT   248
#define _SC_SIGSTKSZ                     249
#define _SC_MINSIGSTKSZ                  250

COSMOPOLITAN_C_START_

long sysconf(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/utmp.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMP_H_


/*!BEGIN libc/runtime/utmpx.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMPX_H_
COSMOPOLITAN_C_START_

struct utmpx {
  short ut_type;
  pid_t ut_pid;
  char ut_line[32];
  char ut_id[4];
  char ut_user[32];
  char ut_host[256];
  struct {
    short __e_termination;
    short __e_exit;
  } ut_exit;
  long ut_session;
  struct timeval ut_tv;
  unsigned ut_addr_v6[4];
  char __unused[20];
};

void endutxent(void);
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *);
struct utmpx *getutxline(const struct utmpx *);
struct utmpx *pututxline(const struct utmpx *);
void setutxent(void);

#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define e_exit        __e_exit
#define e_termination __e_termination
void updwtmpx(const char *, const struct utmpx *);
int utmpxname(const char *);
#endif

#define EMPTY         0
#define RUN_LVL       1
#define BOOT_TIME     2
#define NEW_TIME      3
#define OLD_TIME      4
#define INIT_PROCESS  5
#define LOGIN_PROCESS 6
#define USER_PROCESS  7
#define DEAD_PROCESS  8

COSMOPOLITAN_C_END_

#define ACCOUNTING  9
#define UT_NAMESIZE 32
#define UT_HOSTSIZE 256
#define UT_LINESIZE 32

COSMOPOLITAN_C_START_

struct lastlog {
  time_t ll_time;
  char ll_line[UT_LINESIZE];
  char ll_host[UT_HOSTSIZE];
};

#define ut_time       ut_tv.tv_sec
#define ut_name       ut_user
#define ut_addr       ut_addr_v6[0]
#define utmp          utmpx
#define e_exit        __e_exit
#define e_termination __e_termination

int login_tty(int);
int utmpname(const char *);
struct utmp *getutent(void);
struct utmp *getutid(const struct utmp *);
struct utmp *getutline(const struct utmp *);
struct utmp *pututline(const struct utmp *);
void endutent(void);
void setutent(void);
void updwtmp(const char *, const struct utmp *);

#define _PATH_UTMP "/dev/null/utmp"
#define _PATH_WTMP "/dev/null/wtmp"

#define UTMP_FILE     _PATH_UTMP
#define WTMP_FILE     _PATH_WTMP
#define UTMP_FILENAME _PATH_UTMP
#define WTMP_FILENAME _PATH_WTMP

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/alg.h */

#define COSMOPOLITAN_LIBC_SOCK_ALG_H_
COSMOPOLITAN_C_START_

struct sockaddr_alg {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[64];
};

struct sockaddr_alg_new {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[]; /* Linux v4.12+ */
};

struct af_alg_iv {
  uint32_t ivlen;
  uint8_t iv[0];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/epoll.h */

#define COSMOPOLITAN_LIBC_SOCK_WEPOLL_H_
COSMOPOLITAN_C_START_

typedef union epoll_data {
  void *ptr;
  int fd;
  uint32_t u32;
  uint64_t u64;
} epoll_data_t;

struct thatispacked epoll_event {
  uint32_t events;
  epoll_data_t data;
};

int epoll_create(int) libcesque;
int epoll_create1(int) libcesque;
int epoll_ctl(int, int, int, struct epoll_event *) libcesque;
int epoll_wait(int, struct epoll_event *, int, int) libcesque;
int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/ifaddrs.h */

#define COSMOPOLITAN_LIBC_SOCK_IFADDRS_H_
COSMOPOLITAN_C_START_

struct ifaddrs {
  struct ifaddrs *ifa_next;
  char *ifa_name;
  unsigned ifa_flags;
  struct sockaddr *ifa_addr;
  struct sockaddr *ifa_netmask;
  union {
    struct sockaddr *ifa_broadaddr;
    struct sockaddr *ifa_dstaddr;
  };
  void *ifa_data;
};

void freeifaddrs(struct ifaddrs *) libcesque;
int getifaddrs(struct ifaddrs **) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/in.h */

#define COSMOPOLITAN_LIBC_SOCK_IN_H_

#define IN_CLASSA(a)       ((((in_addr_t)(a)) & 0x80000000) == 0)
#define IN_CLASSA_NET      0xff000000
#define IN_CLASSA_NSHIFT   24
#define IN_CLASSA_HOST     (0xffffffff & ~IN_CLASSA_NET)
#define IN_CLASSA_MAX      128
#define IN_CLASSB(a)       ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET      0xffff0000
#define IN_CLASSB_NSHIFT   16
#define IN_CLASSB_HOST     (0xffffffff & ~IN_CLASSB_NET)
#define IN_CLASSB_MAX      65536
#define IN_CLASSC(a)       ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET      0xffffff00
#define IN_CLASSC_NSHIFT   8
#define IN_CLASSC_HOST     (0xffffffff & ~IN_CLASSC_NET)
#define IN_CLASSD(a)       ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
#define IN_MULTICAST(a)    IN_CLASSD(a)
#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
#define IN_BADCLASS(a)     ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)

#define IN6_IS_ADDR_UNSPECIFIED(a)                           \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint32_t *)(a))[3] == 0)

#define IN6_IS_ADDR_LOOPBACK(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[12] == 0 && \
   ((uint8_t *)(a))[13] == 0 && ((uint8_t *)(a))[14] == 0 && \
   ((uint8_t *)(a))[15] == 1)

#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *)(a))[0] == 0xff)

#define IN6_IS_ADDR_LINKLOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0x80)

#define IN6_IS_ADDR_SITELOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0xc0)

#define IN6_IS_ADDR_V4MAPPED(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint8_t *)(a))[8] == 0 && ((uint8_t *)(a))[9] == 0 &&   \
   ((uint8_t *)(a))[10] == 0xff && ((uint8_t *)(a))[11] == 0xff)

#define IN6_IS_ADDR_V4COMPAT(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[15] > 1)

#define IN6_IS_ADDR_MC_NODELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x1))

#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x2))

#define IN6_IS_ADDR_MC_SITELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x5))

#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x8))

#define IN6_IS_ADDR_MC_GLOBAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0xe))

#define __ARE_4_EQUAL(a, b) \
  (!((0 [a] - 0 [b]) | (1 [a] - 1 [b]) | (2 [a] - 2 [b]) | (3 [a] - 3 [b])))
#define IN6_ARE_ADDR_EQUAL(a, b) \
  __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))



/*!BEGIN libc/sock/select.h */

#define COSMOPOLITAN_LIBC_SOCK_SELECT_H_

#define FD_SETSIZE 1024 /* it's 64 on windows */

COSMOPOLITAN_C_START_

typedef struct fd_set {
  unsigned long fds_bits[FD_SETSIZE / (sizeof(long) * 8)];
} fd_set;

#define FD_ISSET(FD, SET) (((SET)->fds_bits[(FD) >> 6] >> ((FD)&63)) & 1)
#define FD_SET(FD, SET)   ((SET)->fds_bits[(FD) >> 6] |= 1ull << ((FD)&63))
#define FD_CLR(FD, SET)   ((SET)->fds_bits[(FD) >> 6] &= ~(1ull << ((FD)&63)))
#define FD_ZERO(SET)      bzero((SET)->fds_bits, sizeof((SET)->fds_bits))
#define FD_SIZE(bits)     (((bits) + (sizeof(long) * 8) - 1) / sizeof(long))

int select(int, fd_set *, fd_set *, fd_set *, struct timeval *) libcesque;
int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
            const sigset_t *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/syslog.h */

#define COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_
COSMOPOLITAN_C_START_

int setlogmask(int) libcesque;
void openlog(const char *, int, int) libcesque;
void syslog(int, const char *, ...) libcesque;
void closelog(void) libcesque;
void vsyslog(int, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arphdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPHDR_H_
COSMOPOLITAN_C_START_

struct arphdr {
  uint16_t ar_hrd;
  uint16_t ar_pro;
  uint8_t ar_hln;
  uint8_t ar_pln;
  uint16_t ar_op;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arpreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPREQ_H_
COSMOPOLITAN_C_START_

struct arpreq {
  struct sockaddr arp_pa;
  struct sockaddr arp_ha;
  int arp_flags;
  struct sockaddr arp_netmask;
  char arp_dev[16];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/cmsghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_H_
COSMOPOLITAN_C_START_

#define CMSG_DATA(cmsg) ((unsigned char *)(((struct cmsghdr *)(cmsg)) + 1))

#define CMSG_FIRSTHDR(mhdr)                                 \
  ((size_t)(mhdr)->msg_controllen >= sizeof(struct cmsghdr) \
       ? (struct cmsghdr *)(mhdr)->msg_control              \
       : (struct cmsghdr *)0)

#define CMSG_NXTHDR(mhdr, cmsg)                           \
  ((cmsg)->cmsg_len < sizeof(struct cmsghdr) ||           \
           __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >=   \
               __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
       ? 0                                                \
       : (struct cmsghdr *)__CMSG_NEXT(cmsg))

#define CMSG_ALIGN(len) \
  (((len) + sizeof(size_t) - 1) & (size_t) ~(sizeof(size_t) - 1))

#define CMSG_SPACE(len) (CMSG_ALIGN(len) + CMSG_ALIGN(sizeof(struct cmsghdr)))

#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))

#define __CMSG_LEN(cmsg) \
  (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
#define __MHDR_END(mhdr) \
  ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)

struct cmsghdr { /* linux abi */
  uint32_t cmsg_len;
  uint32_t __pad1;
  int32_t cmsg_level;
  int32_t cmsg_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ether_header.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ETHER_HEADER_H_

#define ETH_ALEN 6

COSMOPOLITAN_C_START_

struct ether_addr {
  uint8_t ether_addr_octet[ETH_ALEN];
};

struct ether_header {
  uint8_t ether_dhost[ETH_ALEN];
  uint8_t ether_shost[ETH_ALEN];
  uint16_t ether_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ifconf.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFCONF_H_


/*!BEGIN libc/sock/struct/ifreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFREQ_H_
COSMOPOLITAN_C_START_

#define IF_NAMESIZE 16
#define IFNAMSIZ    IF_NAMESIZE

struct ifreq {
  union {
    char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0".  */
  } ifr_ifrn;
  union {
    struct sockaddr ifru_addr;      /* SIOCGIFADDR */
    struct sockaddr ifru_dstaddr;   /* SIOCGIFDSTADDR */
    struct sockaddr ifru_netmask;   /* SIOCGIFNETMASK */
    struct sockaddr ifru_broadaddr; /* SIOCGIFBRDADDR */
    short ifru_flags;               /* SIOCGIFFLAGS */
    int ifru_ivalue;                /* todo(jart) */
    char ifru_pad[24];              /* ifru_map is the largest, just pad */
  } ifr_ifru;
};

#define ifr_name      ifr_ifrn.ifrn_name      /* interface name */
#define ifr_addr      ifr_ifru.ifru_addr      /* address */
#define ifr_netmask   ifr_ifru.ifru_netmask   /* netmask */
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
#define ifr_dstaddr   ifr_ifru.ifru_dstaddr   /* destination address */
#define ifr_flags     ifr_ifru.ifru_flags     /* flags */
#define ifr_ifindex   ifr_ifru.ifru_ivalue

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/*
 * Structure used in SIOCGIFCONF request.
 * Used to retrieve interface configuration
 * for machine (useful for programs which
 * must know all networks accessible).
 */
struct ifconf {
  int32_t ifc_len; /* size of buffer */
  int32_t padding;
  union {
    char *ifcu_buf;
    struct ifreq *ifcu_req;
  } ifc_ifcu;
};

/* Shortcuts to the ifconf buffer or ifreq array */
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address   */
#define ifc_req ifc_ifcu.ifcu_req /* array of structures  */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in6_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN6_PKTINFO_H_


/*!BEGIN libc/sock/struct/sockaddr6.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SOCKADDR6_H_

struct in6_addr {
  union {
    uint8_t s6_addr[16];
    uint16_t s6_addr16[8];
    uint32_t s6_addr32[4];
  };
};

struct sockaddr_in6 { /* Linux+NT ABI */
  uint16_t sin6_family;
  uint16_t sin6_port;
  uint32_t sin6_flowinfo;
  struct in6_addr sin6_addr;
  uint32_t sin6_scope_id; /* rfc2553 */
};

extern const struct in6_addr in6addr_any;
extern const struct in6_addr in6addr_loopback;

COSMOPOLITAN_C_START_

struct in6_pktinfo {
  struct in6_addr ipi6_addr;
  unsigned ipi6_ifindex;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN_PKTINFO_H_
COSMOPOLITAN_C_START_

struct in_pktinfo {
  int ipi_ifindex;
  struct in_addr ipi_spec_dst;
  struct in_addr ipi_addr;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ip_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IP_MREQ_H_
COSMOPOLITAN_C_START_

struct ip_mreq {
  struct in_addr imr_multiaddr; /* IP multicast address of group */
  struct in_addr imr_interface; /* local IP address of interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ipv6_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IPV6_MREQ_H_
COSMOPOLITAN_C_START_

struct ipv6_mreq {
  struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address of group */
  unsigned ipv6mr_interface;        /* local interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/linger.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger {     /* Linux+XNU+BSD ABI */
  int32_t l_onoff;  /* on/off */
  int32_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/msghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_H_
COSMOPOLITAN_C_START_

struct msghdr {            /* Linux+NT ABI */
  void *msg_name;          /* optional address */
  uint32_t msg_namelen;    /* size of msg_name */
  struct iovec *msg_iov;   /* scatter/gather array */
  uint64_t msg_iovlen;     /* # elements in msg_iov */
  void *msg_control;       /* ancillary data c. cmsghdr */
  uint64_t msg_controllen; /* ancillary data buffer len */
  uint32_t msg_flags;      /* MSG_XXX */
};

ssize_t recvmsg(int, struct msghdr *, int);
ssize_t sendmsg(int, const struct msghdr *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_
COSMOPOLITAN_C_START_

struct pollfd {
  int32_t fd;
  int16_t events;
  int16_t revents;
};

int poll(struct pollfd *, uint64_t, int32_t);
int ppoll(struct pollfd *, uint64_t, const struct timespec *, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/append.h */

#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_

#define APPEND_COOKIE 21578

#define appendz   __appendz
#define appendr   __appendr
#define appendd   __appendd
#define appendw   __appendw
#define appends   __appends
#define appendf   __appendf
#define vappendf  __vappendf
#define kappendf  __kappendf
#define kvappendf __kvappendf

COSMOPOLITAN_C_START_

struct appendz {
  size_t i;
  size_t n;
};

struct appendz appendz(char *) libcesque;
ssize_t appendr(char **, size_t) libcesque;
ssize_t appendd(char **, const void *, size_t) libcesque;
ssize_t appendw(char **, uint64_t) libcesque;
ssize_t appends(char **, const char *) libcesque;
ssize_t appendf(char **, const char *, ...) libcesque;
ssize_t vappendf(char **, const char *, va_list) libcesque;
ssize_t kappendf(char **, const char *, ...) libcesque;
ssize_t kvappendf(char **, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_STDIO_APPEND_H_ */


/*!BEGIN libc/stdio/dprintf.h */

#define COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_
COSMOPOLITAN_C_START_

libcesque int dprintf(int, const char *, ...) paramsnonnull((2));
libcesque int vdprintf(int, const char *, va_list) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/ftw.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_FTW_H_
COSMOPOLITAN_C_START_

/**
 * Type for file.
 */
#define FTW_F 1

/**
 * Type for directory.
 */
#define FTW_D 2

/**
 * Type for directory that cannot be read.
 */
#define FTW_DNR 3

/**
 * Type for stat() failed and not a symbolic link.
 */
#define FTW_NS 4

/**
 * Type for symbolic link when `FTW_PHYS` is in flags.
 */
#define FTW_SL 5

/**
 * Directory and `FTW_DEPTH` in flags.
 */
#define FTW_DP 6

/**
 * Type for broken symbolic link when `FTW_PHYS` is not in flags.
 */
#define FTW_SLN 7

/**
 * Flag to prevent following symbolic links (recommended).
 * @see nftw() flags
 */
#define FTW_PHYS 1

/**
 * Flag to prevent crossing mount points.
 * @see nftw() flags
 */
#define FTW_MOUNT 2

/**
 * Unsupported.
 * @see nftw() flags
 */
#define FTW_CHDIR 4

/**
 * Flag for post-order traversal.
 *
 * 1. Will use `FTW_DP` instead of `FTW_D` as type.
 * 2. Directory callback happens *after* rather than before.
 *
 * @see nftw() flags
 */
#define FTW_DEPTH 8

struct FTW {

  /**
   * Byte offset of basename component in `fpath` passed to callback.
   */
  int base;

  /**
   * Depth relative to `dirpath` whose level is zero.
   */
  int level;
};

int ftw(const char *, int (*)(const char *, const struct stat *, int),
        int) dontthrow;

int nftw(const char *,
         int (*)(const char *, const struct stat *, int, struct FTW *), int,
         int) dontthrow;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/iconv.h */

#define COSMOPOLITAN_LIBC_STDIO_ICONV_H_
COSMOPOLITAN_C_START_

typedef void *iconv_t;

iconv_t iconv_open(const char *, const char *);
size_t iconv(iconv_t, char **, size_t *, char **, size_t *);
int iconv_close(iconv_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/rand.h */

#define COSMOPOLITAN_LIBC_RAND_RAND_H_
#define RAND_MAX __INT_MAX__
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § random                                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int rand(void) libcesque;
void srand(unsigned) libcesque;
char *strfry(char *) libcesque;
int getentropy(void *, size_t) libcesque;
ssize_t getrandom(void *, size_t, unsigned) libcesque;
char *initstate(unsigned, char *, size_t) libcesque;
char *setstate(char *) libcesque;
long random(void) libcesque;
void srandom(unsigned) libcesque;

#ifdef _COSMO_SOURCE
#define vigna   __vigna
#define vigna_r __vigna_r
#define rngset  __rngset
#define rdrand  __rdrand
#define rdseed  __rdseed
double poz(double) libcesque;
double pochisq(double, int) libcesque;
uint64_t lemur64(void) libcesque;
uint64_t _rand64(void) libcesque;
uint64_t vigna(void) libcesque;
uint64_t vigna_r(uint64_t[hasatleast 1]) libcesque;
void svigna(uint64_t) libcesque;
uint64_t rdrand(void) libcesque;
uint64_t rdseed(void) libcesque;
void _smt19937(uint64_t) libcesque;
void _Smt19937(uint64_t[], size_t) libcesque;
uint64_t _mt19937(void) libcesque;
double _real1(uint64_t) libcesque;
double _real2(uint64_t) libcesque;
double _real3(uint64_t) libcesque;
double MeasureEntropy(const char *, size_t) libcesque;
void *rngset(void *, size_t, uint64_t (*)(void), size_t) libcesque;
void rt_init(int) libcesque;
void rt_add(void *, int) libcesque;
void rt_end(double *, double *, double *, double *, double *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/readpassphrase.h */

#define COSMOPOLITAN_LIBC_STDIO_READPASSPHRASE_H_

#define RPP_ECHO_OFF    0x00
#define RPP_ECHO_ON     0x01
#define RPP_REQUIRE_TTY 0x02
#define RPP_FORCELOWER  0x04
#define RPP_FORCEUPPER  0x08
#define RPP_SEVENBIT    0x10
#define RPP_STDIN       0x20

COSMOPOLITAN_C_START_

char *readpassphrase(const char *, char *, size_t, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/stdio_ext.h */

#define COSMOPOLITAN_LIBC_STDIO_STDIO_EXT_H_

#define FSETLOCKING_QUERY    0
#define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_BYCALLER 2

COSMOPOLITAN_C_START_

size_t __fbufsize(FILE *) libcesque;
size_t __fpending(FILE *) libcesque;
int __flbf(FILE *) libcesque;
int __freadable(FILE *) libcesque;
int __fwritable(FILE *) libcesque;
int __freading(FILE *) libcesque;
int __fwriting(FILE *) libcesque;
int __fsetlocking(FILE *, int) libcesque;
void _flushlbf(void) libcesque;
void __fpurge(FILE *) libcesque;
void __fseterr(FILE *) libcesque;
const char *__freadptr(FILE *, size_t *) libcesque;
size_t __freadahead(FILE *) libcesque;
void __freadptrinc(FILE *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/syscall.h */

#define COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_
COSMOPOLITAN_C_START_

#define SYS_gettid    1
#define SYS_getrandom 2
#define SYS_getcpu    3

long syscall(long, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/sysparam.h */

#define COSMOPOLITAN_LIBC_SYSPARAM_H_

#define MAXSYMLINKS    20
#define MAXHOSTNAMELEN 64
#define MAXNAMLEN      255
#define MAXPATHLEN     PATH_MAX
#define NBBY           8
#define NGROUPS        32
#define CANBSIZ        255
#define NOFILE         256
#define NCARGS         131072
#define DEV_BSIZE      512
#define NOGROUP        (-1)

COSMOPOLITAN_C_START_

#define __bitop(x, i, o) ((x)[(i) / 8] o(1 << (i) % 8))
#define setbit(x, i)     __bitop(x, i, |=)
#define clrbit(x, i)     __bitop(x, i, &= ~)
#define isset(x, i)      __bitop(x, i, &)
#define isclr(x, i)      !isset(x, i)

#undef roundup
#define roundup(n, d) (howmany(n, d) * (d))
#define powerof2(n)   !(((n)-1) & (n))
#define howmany(n, d) (((n) + ((d)-1)) / (d))

#ifdef MIN
#undef MIN
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

#ifdef MAX
#undef MAX
#endif
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/ntspawn.h */

#define COSMOPOLITAN_NTSPAWN_H_
COSMOPOLITAN_C_START_

struct NtSpawnArgs {
  int64_t dirhand;
  const char *prog;
  char *const *argv;
  char *const *envp;
  char *const *extravars;
  uint32_t dwCreationFlags;
  const char16_t *opt_lpCurrentDirectory;
  int64_t opt_hParentProcess;
  int64_t *opt_lpExplicitHandleList;
  uint32_t dwExplicitHandleCount;
  const struct NtStartupInfo *lpStartupInfo;
  struct NtProcessInformation *opt_out_lpProcessInformation;
};

int mkntenvblock(char16_t[32767], char *const[], char *const[], char[32767]);
int ntspawn(struct NtSpawnArgs *);
size_t mkntcmdline(char16_t *, char *const[], size_t);
void mungentpath(char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/posix_spawn.h */

#define COSMOPOLITAN_LIBC_STDIO_SPAWN_H_

#define POSIX_SPAWN_USEVFORK      0
#define POSIX_SPAWN_RESETIDS      1
#define POSIX_SPAWN_SETPGROUP     2
#define POSIX_SPAWN_SETSIGDEF     4
#define POSIX_SPAWN_SETSIGMASK    8
#define POSIX_SPAWN_SETSCHEDPARAM 16
#define POSIX_SPAWN_SETSCHEDULER  32
#define POSIX_SPAWN_SETSID        128
#define POSIX_SPAWN_SETRLIMIT     256

COSMOPOLITAN_C_START_

typedef struct _posix_spawna *posix_spawnattr_t;
typedef struct _posix_faction *posix_spawn_file_actions_t;

int posix_spawn(int *, const char *, const posix_spawn_file_actions_t *,
                const posix_spawnattr_t *, char *const[], char *const[]);
int posix_spawnp(int *, const char *, const posix_spawn_file_actions_t *,
                 const posix_spawnattr_t *, char *const[], char *const[]);

int posix_spawn_file_actions_init(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *,
                                      int) libcesque;
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int,
                                     int) libcesque;
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *, int,
                                     const char *, int, unsigned) libcesque;
int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *,
                                         const char *) libcesque;
int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
                                          int) libcesque;

int posix_spawnattr_init(posix_spawnattr_t *) libcesque;
int posix_spawnattr_destroy(posix_spawnattr_t *) libcesque;
int posix_spawnattr_getflags(const posix_spawnattr_t *, short *) libcesque;
int posix_spawnattr_setflags(posix_spawnattr_t *, short) libcesque;
int posix_spawnattr_getpgroup(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setpgroup(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedparam(const posix_spawnattr_t *,
                                  struct sched_param *) libcesque;
int posix_spawnattr_setschedparam(posix_spawnattr_t *,
                                  const struct sched_param *) libcesque;
int posix_spawnattr_getsigmask(const posix_spawnattr_t *, sigset_t *) libcesque;
int posix_spawnattr_setsigmask(posix_spawnattr_t *, const sigset_t *) libcesque;
int posix_spawnattr_getsigdefault(const posix_spawnattr_t *,
                                  sigset_t *) libcesque;
int posix_spawnattr_setsigdefault(posix_spawnattr_t *,
                                  const sigset_t *) libcesque;
int posix_spawnattr_getrlimit(const posix_spawnattr_t *, int,
                              struct rlimit *) libcesque;
int posix_spawnattr_setrlimit(posix_spawnattr_t *, int,
                              const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/atomic.h */

#define NSYNC_ATOMIC_H_
COSMOPOLITAN_C_START_

#define nsync_atomic_uint32_ atomic_uint

#define NSYNC_ATOMIC_UINT32_INIT_        0
#define NSYNC_ATOMIC_UINT32_LOAD_(p)     (*(p))
#define NSYNC_ATOMIC_UINT32_STORE_(p, v) (*(p) = (v))
#define NSYNC_ATOMIC_UINT32_PTR_(p)      (p)

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/counter.h */

#define NSYNC_COUNTER_H_


/*!BEGIN third_party/nsync/time.h */

#define NSYNC_TIME_H_
COSMOPOLITAN_C_START_

#define NSYNC_TIME_SEC(t)  ((t).tv_sec)
#define NSYNC_TIME_NSEC(t) ((t).tv_nsec)
#define NSYNC_TIME_STATIC_INIT(t, ns) \
  { (t), (ns) }

/* The type nsync_time represents the interval elapsed between two
   moments in time. Often the first such moment is an address-space-wide
   epoch, such as the Unix epoch, but clients should not rely on the
   epoch in one address space being the same as that in another.
   Intervals relative to the epoch are known as absolute times. */
typedef struct timespec nsync_time;

/* A deadline infinitely far in the future. */
#define nsync_time_no_deadline timespec_max

/* The zero delay, or an expired deadline. */
#define nsync_time_zero timespec_zero

/* Return the current time since the epoch.  */
#define nsync_time_now() timespec_real()

/* Sleep for the specified delay. Returns the unslept time which may be
   non-zero if the call was interrupted. */
#define nsync_time_sleep(a) timespec_sleep(a)

/* Sleep until the specified time.  Returns 0 on success, and EINTR
   if the call was interrupted. */
#define nsync_time_sleep_until(a) timespec_sleep_until(a)

/* Return a+b */
#define nsync_time_add(a, b) timespec_add(a, b)

/* Return a-b */
#define nsync_time_sub(a, b) timespec_sub(a, b)

/* Return +ve, 0, or -ve according to whether a>b, a==b, or a<b. */
#define nsync_time_cmp(a, b) timespec_cmp(a, b)

/* Return the specified number of milliseconds as a time. */
#define nsync_time_ms(a) timespec_frommillis(a)

/* Return the specified number of microseconds as a time. */
#define nsync_time_us(a) timespec_frommicros(a)

/* Return the specified number of nanoseconds as a time. */
#define nsync_time_ns(a) timespec_fromnanos(a)

/* Return an nsync_time constructed from second and nanosecond
   components */
#define nsync_time_s_ns(s, ns) ((nsync_time){(int64_t)(s), (unsigned)(ns)})

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/* An nsync_counter represents an unsigned integer that can count up and down,
   and wake waiters when zero.  */
typedef struct nsync_counter_s_ *nsync_counter;

/* Return a freshly allocated nsync_counter with the specified value,
   of NULL if an nsync_counter cannot be created.

   Any non-NULL returned value should be passed to nsync_counter_free() when no
   longer needed.  */
nsync_counter nsync_counter_new(uint32_t value);

/* Free resources associated with c.  Requires that c was allocated by
   nsync_counter_new(), and no concurrent or future operations are applied to
   c.  */
void nsync_counter_free(nsync_counter c);

/* Add delta to c, and return its new value.  It is a checkable runtime error
   to decrement c below 0, or to increment c (i.e., apply a delta > 0) after a
   waiter has waited.  */
uint32_t nsync_counter_add(nsync_counter c, int32_t delta);

/* Return the current value of c.  */
uint32_t nsync_counter_value(nsync_counter c);

/* Wait until c has value 0, or until abs_deadline, then return
   the value of c.  It is a checkable runtime error to increment c after
   a waiter may have been woken due to the counter reaching zero.
   If abs_deadline==nsync_time_no_deadline, the deadline
   is far in the future. */
uint32_t nsync_counter_wait(nsync_counter c, nsync_time abs_deadline);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/cv.h */

#define NSYNC_CV_H_


/*!BEGIN third_party/nsync/mu.h */

#define NSYNC_MU_H_
COSMOPOLITAN_C_START_

/* An nsync_mu is a lock. If initialized to zero, it's valid and unlocked.

   An nsync_mu can be "free", held by a single thread (aka fiber,
   goroutine) in "write" (exclusive) mode, or by many threads in "read"
   (shared) mode. A thread that acquires it should eventually release
   it. It is illegal to acquire an nsync_mu in one thread and release it
   in another. It is illegal for a thread to reacquire an nsync_mu while
   holding it (even a second share of a "read" lock).

   Example usage:

       static struct foo {
         nsync_mu mu; // protects invariant a+b==0 on fields below.
         int a;
         int b;
       } p = { NSYNC_MU_INIT, 0, 0 };
       // ....
       nsync_mu_lock (&p.mu);
       // The current thread now has exclusive access to p.a and p.b;
       // invariant assumed true.
       p.a++;
       p.b--; // restore invariant p.a+p.b==0 before releasing p.mu
       nsync_mu_unlock (&p.mu)

   Mutexes can be used with condition variables; see nsync_cv.h.

   nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. See nsync_mu_wait.h for more details. Example
   use of nsync_mu_wait() to wait for p.a==0, using definition above:

        int a_is_zero (const void *condition_arg) {
                return (((const struct foo *)condition_arg)->a == 0);
        }
        ...
        nsync_mu_lock (&p.mu);
        nsync_mu_wait (&p.mu, &a_is_zero, &p, NULL);
        // The current thread now has exclusive access to
        // p.a and p.b, and p.a==0.
        ...
        nsync_mu_unlock (&p.mu);

*/
typedef struct nsync_mu_s_ {
  nsync_atomic_uint32_ word; /* internal use only */
  int _zero;                 /* c pthread_mutex_t */
  struct Dll *waiters;       /* internal use only */
} nsync_mu;

/* An nsync_mu should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_MU_INIT, or by setting
   the entire structure to all zeroes, or using nsync_mu_init(). */
#define NSYNC_MU_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }
void nsync_mu_init(nsync_mu *mu);

/* Block until *mu is free and then acquire it in writer mode. Requires
   that the calling thread not already hold *mu in any mode. */
void nsync_mu_lock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in write mode by the
   calling thread, and wake waiters, if appropriate. */
void nsync_mu_unlock(nsync_mu *mu);

/* Attempt to acquire *mu in writer mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. */
int nsync_mu_trylock(nsync_mu *mu);

/* Block until *mu can be acquired in reader mode and then acquire it.
   Requires that the calling thread not already hold *mu in any mode. */
void nsync_mu_rlock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in read mode by the calling
   thread, and wake waiters, if appropriate. */
void nsync_mu_runlock(nsync_mu *mu);

/* Attempt to acquire *mu in reader mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. Perhaps fail to acquire if a writer is waiting, to
   avoid starvation. */
int nsync_mu_rtrylock(nsync_mu *mu);

/* May abort if *mu is not held in write mode by the calling thread. */
void nsync_mu_assert_held(const nsync_mu *mu);

/* May abort if *mu is not held in read or write mode
   by the calling thread.  */
void nsync_mu_rassert_held(const nsync_mu *mu);

/* Return whether *mu is held in read mode.
   Requires that the calling thread holds *mu in some mode. */
int nsync_mu_is_reader(const nsync_mu *mu);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

#define NSYNC_CV_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }

struct nsync_note_s_;

/* An nsync_cv is a condition variable in the style of Mesa, Java,
   POSIX, and Go's sync.Cond. It allows a thread to wait for a condition
   on state protected by a mutex, and to proceed with the mutex held and
   the condition true.

   See also nsync_mu_wait() and nsync_mu_wait_with_deadline(), which
   implement conditional critical sections. In many cases, they are
   easier to use than condition variables.

   Usage

   After making the desired predicate true, call:

       nsync_cv_signal (&cv);    // If at most one thread can make use
                                 // of the predicate becoming true.

   or

       nsync_cv_broadcast (&cv); // If multiple threads can make use
                                 // of the predicate becoming true.

   To wait for a predicate with no deadline (assuming
   nsync_cv_broadcast() or nsync_cv_signal() is called whenever the
   predicate becomes true):

       nsync_mu_lock (&mu;)
       while (!some_predicate_protected_by_mu) { // while-loop required
         nsync_cv_wait (&cv, &mu);
       }
       // predicate is now true
       nsync_mu_unlock (&mu);

   To wait for a predicate with a deadline (assuming nsync_cv_broadcast() or
   nsync_cv_signal() is called whenever the predicate becomes true):

       nsync_mu_lock (&mu);
       while (!some_predicate_protected_by_mu &&
         nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                      cancel_note) == 0) {
       }
       if (some_predicate_protected_by_mu) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   or, if the predicate is complex and you wish to write it just once
   and inline, you could use the following instead of the for-loop
   above:

       nsync_mu_lock (&mu);
       int pred_is_true = 0;
       int outcome = 0;
       while (!(pred_is_true = some_predicate_protected_by_mu) &&
              outcome == 0) {
         outcome = nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                                cancel_note);
       }
       if (pred_is_true) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   As the examples show, Mesa-style condition variables require that
   waits use a loop that tests the predicate anew after each wait. It
   may be surprising that these are preferred over the precise wakeups
   offered by the condition variables in Hoare monitors. Imprecise
   wakeups make more efficient use of the critical section, because
   threads can enter it while a woken thread is still emerging from the
   scheduler, which may take thousands of cycles. Further, they make the
   programme easier to read and debug by making the predicate explicit
   locally at the wait, where the predicate is about to be assumed; the
   reader does not have to infer the predicate by examining all the
   places where wakeups may occur. */
typedef struct nsync_cv_s_ {
  /* see bits below */
  nsync_atomic_uint32_ word;
  /* points to tail of list of waiters; under mu. */
  struct Dll *waiters;
} nsync_cv;

/* An nsync_cv should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_CV_INIT, or by setting
   the entire struct to 0, or using nsync_cv_init(). */
void nsync_cv_init(nsync_cv *cv);

/* Wake at least one thread if any are currently blocked on *cv. If the
   chosen thread is a reader on an nsync_mu, wake all readers and, if
   possible, a writer. */
void nsync_cv_signal(nsync_cv *cv);

/* Wake all threads currently blocked on *cv. */
void nsync_cv_broadcast(nsync_cv *cv);

/* Atomically release "mu" (which must be held on entry) and block the
   caller on *cv. Wait until awakened by a call to nsync_cv_signal() or
   nsync_cv_broadcast(), or a spurious wakeup; then reacquire "mu", and
   return. Equivalent to a call to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL. Callers
   should use nsync_cv_wait() in a loop, as with all standard Mesa-style
   condition variables. See examples above. Returns 0 normally, otherwise
   ECANCELED may be returned if calling POSIX thread is cancelled only when
   the PTHREAD_CANCEL_MASKED mode is in play. */
int nsync_cv_wait(nsync_cv *cv, nsync_mu *mu);

/* Atomically release "mu" (which must be held on entry) and block the
   calling thread on *cv. It then waits until awakened by a call to
   nsync_cv_signal() or nsync_cv_broadcast() (or a spurious wakeup), or
   by the time reaching abs_deadline, or by cancel_note being notified.
   In all cases, it reacquires "mu", and returns the reason for the call
   returned (0, ETIMEDOUT, or ECANCELED). Use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no nsync cancellations (however POSIX thread
   cancellations may still happen, and ECANCELED could still be returned
   when the calling thread is cancelled only if PTHREAD_CANCEL_MASKED is
   in play). wait_with_deadline() should be used in a loop, as with all
   Mesa-style condition variables. See examples above.

   There are two reasons for using an absolute deadline, rather than a
   relative timeout---these are why pthread_cond_timedwait() also uses
   an absolute deadline. First, condition variable waits have to be used
   in a loop; with an absolute times, the deadline does not have to be
   recomputed on each iteration. Second, in most real programmes, some
   activity (such as an RPC to a server, or when guaranteeing response
   time in a UI), there is a deadline imposed by the specification or
   the caller/user; relative delays can shift arbitrarily with
   scheduling delays, and so after multiple waits might extend beyond
   the expected deadline. Relative delays tend to be more convenient
   mostly in tests and trivial examples than they are in real
   programmes. */
int nsync_cv_wait_with_deadline(nsync_cv *cv, nsync_mu *mu,
                                nsync_time abs_deadline,
                                struct nsync_note_s_ *cancel_note);

/* Like nsync_cv_wait_with_deadline(), but allow an arbitrary lock *v to be
   used, given its (*lock)(mu) and (*unlock)(mu) routines.  */
int nsync_cv_wait_with_deadline_generic(nsync_cv *cv, void *mu,
                                        void (*lock)(void *),
                                        void (*unlock)(void *),
                                        nsync_time abs_deadline,
                                        struct nsync_note_s_ *cancel_note);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/debug.h */

#define NSYNC_DEBUG_H_
COSMOPOLITAN_C_START_

/* Debugging operations for mutexes and condition variables.

   These operations should not be relied upon for normal functionality.
   The implementation may be slow, output formats may change, and the
   implementation is free to yield the empty string. */

/* Place in buf[0,..,n-1] a nul-terminated, human readable string
   indicative of some of the internal state of the mutex or condition
   variable, and return buf. If n>=4, buffer overflow is indicated by
   placing the characters "..." at the end of the string.

   The *_and_waiters() variants attempt to output the waiter lists in
   addition to the basic state. These variants may acquire internal
   locks and follow internal pointers. Thus, they are riskier if invoked
   in an address space whose overall health is uncertain. */
char *nsync_mu_debug_state(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state(nsync_cv *cv, char *buf, int n);
char *nsync_mu_debug_state_and_waiters(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state_and_waiters(nsync_cv *cv, char *buf, int n);

/* Like nsync_*_debug_state_and_waiters(), but ignoring all locking and
   safety considerations, and using an internal, possibly static buffer
   that may be overwritten by subsequent or concurrent calls to these
   routines. These variants should be used only from an interactive
   debugger, when all other threads are stopped; the debugger is
   expected to recover from errors. */
char *nsync_mu_debugger(nsync_mu *mu);
char *nsync_cv_debugger(nsync_cv *cv);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_semaphore.h */

#define NSYNC_SEM_H_
COSMOPOLITAN_C_START_

typedef struct nsync_semaphore_s_ {
  void *sem_space[3];
} nsync_semaphore;

/* Initialize *s; the initial value is 0. */
void nsync_mu_semaphore_init(nsync_semaphore *s);

/* Wait until the count of *s exceeds 0, and decrement it. */
errno_t nsync_mu_semaphore_p(nsync_semaphore *s);

/* Wait until one of: the count of *s is non-zero, in which case
   decrement *s and return 0; or abs_deadline expires, in which case
   return ETIMEDOUT. */
errno_t nsync_mu_semaphore_p_with_deadline(nsync_semaphore *s,
                                           nsync_time abs_deadline);

/* Ensure that the count of *s is at least 1. */
void nsync_mu_semaphore_v(nsync_semaphore *s);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_wait.h */

#define NSYNC_MU_WAIT_H_
COSMOPOLITAN_C_START_

/* nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. In many straightforward situations they are
   of equivalent performance and are somewhat easier to use, because
   unlike condition variables, they do not require that the waits be
   placed in a loop, and they do not require explicit wakeup calls.
   Example:

   Definitions:

       static nsync_mu mu = NSYNC_MU_INIT;
       static int i = 0;  // protected by mu
       // Condition for use with nsync_mu_wait().
       static int int_is_zero (const void *v) {
         return (*(const int *)v == 0);
       }

   Waiter:

       nsync_mu_lock (&mu);
       // Wait until i is zero.
       nsync_mu_wait (&mu, &int_is_zero, &i, NULL);
       // i is known to be zero here.
       // ...
       nsync_mu_unlock (&mu);

   Thread potentially making i zero:

       nsync_mu_lock (&mu);
       i--;
       // No need to signal that i may have become zero.  The unlock call
       // below will evaluate waiters' conditions to decide which to wake.
       nsync_mu_unlock (&mu);

   It is legal to use conditional critical sections and condition
   variables on the same mutex.

                              --------------

   The implementation benefits from determining whether waiters are
   waiting for the same condition; it may then evaluate a condition once
   on behalf of several waiters. Two waiters have equal condition if
   their "condition" pointers are equal, and either:

     - their "condition_arg" pointers are equal, or

     - "condition_arg_eq" is non-null and (*condition_arg_eq)
       (condition_arg0, condition_arg1) returns non-zero.

   *condition_arg_eq will not be invoked unless the "condition" pointers
   are equal, and the "condition_arg" pointers are unequal.

   If many waiters wait for distinct conditions simultaneously,
   condition variables may be faster.
 */

struct nsync_note_s_; /* forward declaration for an nsync_note */

/* Return when (*condition) (condition_arg) is true. Perhaps unlock and
   relock *mu while blocked waiting for the condition to become true.
   nsync_mu_wait() is equivalent to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL.

   Requires that *mu be held on entry. See nsync_mu_wait_with_deadline()
   for more details on *condition and *condition_arg_eq. */
void nsync_mu_wait(nsync_mu *mu, int (*condition)(const void *condition_arg),
                   const void *condition_arg,
                   int (*condition_arg_eq)(const void *a, const void *b));

/* Return when at least one of: (*condition) (condition_arg) is true,
   the deadline expires, or *cancel_note is notified. Perhaps unlock and
   relock *mu while blocked waiting for one of these events, but always
   return with *mu held. Return 0 iff the (*condition) (condition_arg)
   is true on return, and otherwise either ETIMEDOUT or ECANCELED,
   depending on why the call returned early. Callers should use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no cancellation.

   Requires that *mu be held on entry.

   The implementation may call *condition from any thread using the
   mutex, and while holding *mu in either read or write mode; it
   guarantees that any thread calling *condition will hold *mu in some
   mode. Requires that (*condition) (condition_arg) neither modify state
   protected by *mu, nor return a value dependent on state not protected
   by *mu. To depend on time, use the abs_deadline parameter.
   (Conventional use of condition variables have the same restrictions
   on the conditions tested by the while-loop.) If non-null,
   condition_arg_eq should return whether two condition_arg calls with
   the same "condition" pointer are considered equivalent; it should
   have no side-effects. */
int nsync_mu_wait_with_deadline(
    nsync_mu *mu, int (*condition)(const void *condition_arg),
    const void *condition_arg,
    int (*condition_arg_eq)(const void *a, const void *b),
    nsync_time abs_deadline, struct nsync_note_s_ *cancel_note);

/* Unlock *mu, which must be held in write mode, and wake waiters, if
   appropriate. Unlike nsync_mu_unlock(), this call is not required to
   wake nsync_mu_wait/nsync_mu_wait_with_deadline calls on conditions
   that were false before this thread acquired the lock. This call
   should be used only at the end of critical sections for which:
   - nsync_mu_wait and/or nsync_mu_wait_with_deadline are in use on the same
     mutex,
   - this critical section cannot make the condition true for any of those
     nsync_mu_wait/nsync_mu_wait_with_deadline waits, and
   - when performance is significantly improved by using this call. */
void nsync_mu_unlock_without_wakeup(nsync_mu *mu);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/note.h */

#define NSYNC_NOTE_H_
COSMOPOLITAN_C_START_

/* An nsync_note represents a single bit that can transition from 0 to 1
   at most once. When 1, the note is said to be notified. There are
   operations to wait for the transition, which can be triggered either
   by an explicit call, or timer expiry. Notes can have parent notes; a
   note becomes notified if its parent becomes notified. */
typedef struct nsync_note_s_ *nsync_note;

/* Return a freshly allocated nsync_note, or NULL if an nsync_note
   cannot be created.

   If parent!=NULL, the allocated nsync_note's parent will be parent.
   The newaly allocated note will be automatically notified at
   abs_deadline, and is notified at initialization if
   abs_deadline==nsync_zero_time.

   nsync_notes should be passed to nsync_note_free() when no longer needed. */
nsync_note nsync_note_new(nsync_note parent, nsync_time abs_deadline);

/* Free resources associated with n. Requires that n was allocated by
   nsync_note_new(), and no concurrent or future operations are applied
   to n directly.

   It is legal to call nsync_note_free() on a node even if it has a
   parent or children that are in use; if n has both a parent and
   children, n's parent adopts its children. */
void nsync_note_free(nsync_note n);

/* Notify n and all its descendants. */
void nsync_note_notify(nsync_note n);

/* Return whether n has been notified.  */
int nsync_note_is_notified(nsync_note n);

/* Wait until n has been notified or abs_deadline is reached, and return
   whether n has been notified. If abs_deadline==nsync_time_no_deadline,
   the deadline is far in the future. */
int nsync_note_wait(nsync_note n, nsync_time abs_deadline);

/* Return the expiry time associated with n. This is the minimum of the
   abs_deadline passed on creation and that of any of its ancestors. */
nsync_time nsync_note_expiry(nsync_note n);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/once.h */

#define NSYNC_ONCE_H_
COSMOPOLITAN_C_START_

/* An nsync_once allows a function to be called exactly once, when first
   referenced. */
typedef nsync_atomic_uint32_ nsync_once;

/* An initializer for nsync_once; it is guaranteed to be all zeroes. */
#define NSYNC_ONCE_INIT NSYNC_ATOMIC_UINT32_INIT_

/* The first time nsync_run_once() or nsync_run_once_arg() is applied to
   *once, the supplied function is run (with argument, in the case of
   nsync_run_once_arg()). Other callers will wait until the run of the
   function is complete, and then return without running the function
   again. */
void nsync_run_once(nsync_once *once, void (*f)(void));
void nsync_run_once_arg(nsync_once *once, void (*farg)(void *arg), void *arg);

/* Same as nsync_run_once()/nsync_run_once_arg() but uses a spinloop.
   Can be used on the same nsync_once as
   nsync_run_once/nsync_run_once_arg().

   These *_spin variants should be used only in contexts where normal
   blocking is disallowed, such as within user-space schedulers, when
   the runtime is not fully initialized, etc. They provide no
   significant performance benefit, and they should be avoided in normal
   code. */
void nsync_run_once_spin(nsync_once *once, void (*f)(void));
void nsync_run_once_arg_spin(nsync_once *once, void (*farg)(void *arg),
                             void *arg);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/waiter.h */

#define NSYNC_WAITER_H_
COSMOPOLITAN_C_START_

/* nsync_wait_n() allows the client to wait on multiple objects
   (condition variables, nsync_notes, nsync_counters, etc.) until at
   least one of them becomes ready, or a deadline expires.

   It can be thought of as rather like Unix's select() or poll(), except
   the the objects being waited for are synchronization data structures,
   rather than file descriptors.

   The client can construct new objects that can be waited for by
   implementing three routines.

   Examples:

   To wait on two nsync_notes n0, n1, and a nsync_counter c0, with a
   deadline of abs_deadline:

       // Form an array of struct nsync_waitable_s, identifying the
       // objects and the corresponding descriptors. (Static
       // initialization syntax is used for brevity.)
       static struct nsync_waitable_s w[] = {
         { &n0, &nsync_note_waitable_funcs },
         { &n1, &nsync_note_waitable_funcs },
         { &c0, &nsync_counter_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1], &w[2] };
       int n = sizeof (w) / sizeof (w[0]);

       // Wait. The mu, lock, and unlock arguments are NULL because no
       // condition variables are invovled.
       int i = nsync_wait_n (NULL, NULL, NULL, abs_deadline, n, pw);
       if (i == n) {
         // timeout
       } else {
         // w[i].v became ready.
       }

    To wait on multiple condition variables, the mu/lock/unlock
    parameters are used. Imagine cv0 and cv1 are signalled when
    predicates pred0() (under lock mu0) and pred1() (under lock mu1)
    become true respectively. Assume that mu0 is acquired before mu1.

       static void lock2 (void *v) {  // lock two mutexes in order
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_lock (mu[0]);
         nsync_mu_lock (mu[1]);
       }
       static void unlock2 (void *v) { // unlock two mutexes.
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_unlock (mu[1]);
         nsync_mu_unlock (mu[0]);
       }

       // Describe the condition variables and the locks.
       static struct nsync_waitable_s w[] = {
         { &cv0, &nsync_cv_waitable_funcs },
         { &cv1, &nsync_cv_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1] };
       nsync_mu *lock_list[] = { &mu0, &mu1 };
       int n = sizeof (w) / sizeof (w[0]);

       lock2 (list_list);
       while (!pred0 () && !pred1 ()) {
         // Wait for one of the condition variables to be signalled,
         // with no timeout.
         nsync_wait_n (lock_list, &lock2, &unlock2,
                       nsync_time_no_deadline, n, pw);
       }
       if (pred0 ()) { ... }
       if (pred1 ()) { ... }
       unlock2 (list_list);

   */

/* forward declaration of struct that contains type dependent wait
   operations */
struct nsync_waitable_funcs_s;

/* Clients wait on objects by forming an array of struct
   nsync_waitable_s. Each each element points to one object and its
   type-dependent functions. */
struct nsync_waitable_s {
  /* pointer to object */
  void *v;
  /* pointer to type-dependent functions. Use
     &nsync_note_waitable_funcs for an nsync_note,
     &nsync_counternote_waitable_funcs for an nsync_counter,
     &nsync_cv_waitable_funcs for an nsync_cv. */
  const struct nsync_waitable_funcs_s *funcs;
};

/* Wait until at least one of *waitable[0,..,count-1] is has been
   notified, or abs_deadline is reached. Return the index of the
   notified element of waitable[], or count if no such element exists.
   If mu!=NULL, (*unlock)(mu) is called after the thread is queued on
   the various waiters, and (*lock)(mu) is called before return;
   mu/lock/unlock are used to acquire and release the relevant locks
   whan waiting on condition variables. */
int nsync_wait_n(void *mu, void (*lock)(void *), void (*unlock)(void *),
                 nsync_time abs_deadline, int count,
                 struct nsync_waitable_s *waitable[]);

/* A "struct nsync_waitable_s" implementation must implement these
   functions. Clients should ignore the internals. */
struct nsync_waiter_s;
struct nsync_waitable_funcs_s {

  /* Return the time when *v will be ready (max time if unknown), or 0
     if it is already ready. The parameter nw may be passed as NULL, in
     which case the result should indicate whether the thread would
     block if it were to wait on *v. All calls with the same *v must
     report the same result until the object becomes ready, from which
     point calls must report 0. */
  nsync_time (*ready_time)(void *v, struct nsync_waiter_s *nw);

  /* If *v is ready, return zero; otherwise enqueue *nw on *v and return
     non-zero. */
  int (*enqueue)(void *v, struct nsync_waiter_s *nw);

  /* If nw has been previously dequeued, return zero; otherwise dequeue
   *nw from *v and return non-zero.  */
  int (*dequeue)(void *v, struct nsync_waiter_s *nw);
};

/* The "struct nsync_waitable_s" for nsync_note, nsync_counter, and nsync_cv. */
extern const struct nsync_waitable_funcs_s nsync_note_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_counter_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_cv_waitable_funcs;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/avx512.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
COSMOPOLITAN_C_START_

union XedAvx512Payload1 {
  struct {
    unsigned map : 4;
    unsigned rr_inv : 1;
    unsigned b_inv : 1;
    unsigned x_inv : 1;
    unsigned r_inv : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload2 {
  struct {
    unsigned pp : 2;
    unsigned ubit : 1;
    unsigned vexdest210 : 3;
    unsigned vexdest3 : 1;
    unsigned rexw : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload3 {
  struct {
    unsigned mask : 3;
    unsigned vexdest4p : 1;
    unsigned bcrc : 1;
    unsigned llrc : 2;
    unsigned z : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/private.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_PRIVATE_H_


/*!BEGIN third_party/xed/x86.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86_H_
/*           ▓▓▓▓▓▓▓▓▓▓▓▓▓                      ▄▄▄▄
             ▓▓▓▓▓▓▓▓▓▓▓▓▓     ▄▓▓▓▓▓▓▄      ▄▓▓▓▓▓▓▓▓            ▄▓▓▓▀
             ▓▓▓▓    ▓▓▓▓▓    ▓     ▓▓▓▓    ▓▓       ▓▓▓      ▄▓▓▓▓
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▬▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▬▬▬▬▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓     ▓▓▓▄     ▓▓▓   ▓▓▓▓             │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▀▓▓▓▓▄▄▄▓▓▓▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓▓▓▄   ▄▄▓▓▓▓▓▓▓▓▓  ▓▓▓▓      ▓▓▓▄    │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▄▄▓▓▀  ▀▀▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬║▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▓▓▓ ▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬║▬▬▬
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▓▓▓▓▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
■■■■■■■■║■■■■▓▓▓▓    ▓▓▓▓▓■■■▓▓▓▄▄▄▓▓▓▓■■■■▬▓▓▓▓▄▄▄▄▓▓▓■■■■▬▓▓▓▓▄▄▄▓▓▓▓▀■■■■║■■■
■■■■■■■■■■■■■▓▓▓▓▓▓▓▓▓▓▓▓▓■■■■■▀▓▓▓■■■■■■■■■■■■■■▀▀■■■■■■■■■■■■▀▓▓▀■■■■■■■■■■■■■
        ║▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓║
╔───────╨───────────────────────────────────────────────────────────────────╨──╗
│ cosmopolitan § virtual machine » byte code language                          │
╚─────────────────────────────────────────────────────────────────────────────*/

#define XED_MAX_INSTRUCTION_BYTES 15

#define XED_MODE_REAL   0
#define XED_MODE_LEGACY 1
#define XED_MODE_LONG   2

#define XED_HINT_NTAKEN 2
#define XED_HINT_TAKEN  4
#define XED_HINT_ALTER  6

#define XED_SEG_ES 1
#define XED_SEG_CS 2
#define XED_SEG_SS 3
#define XED_SEG_DS 4
#define XED_SEG_FS 5
#define XED_SEG_GS 6

#define xed_modrm_mod(M)           (((M)&0xff) >> 6)
#define xed_modrm_reg(M)           (((M)&0b00111000) >> 3)
#define xed_modrm_rm(M)            ((M)&7)
#define xed_sib_base(M)            ((M)&7)
#define xed_sib_index(M)           (((M)&0b00111000) >> 3)
#define xed_sib_scale(M)           (((M)&0xff) >> 6)
#define xed_get_modrm_reg_field(M) (((M)&0x38) >> 3)

COSMOPOLITAN_C_START_

#define XED_MACHINE_MODE_REAL           XED_MODE_REAL
#define XED_MACHINE_MODE_LEGACY_32      XED_MODE_LEGACY
#define XED_MACHINE_MODE_LONG_64        XED_MODE_LONG
#define XED_MACHINE_MODE_UNREAL         (1 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LEGACY_16      (2 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_16 (3 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_32 (4 << 2 | XED_MODE_LEGACY)
#define XED_MACHINE_MODE_LAST           (XED_MACHINE_MODE_LONG_COMPAT_32 + 1)

#define XED_ERROR_NONE                         0
#define XED_ERROR_BUFFER_TOO_SHORT             1
#define XED_ERROR_GENERAL_ERROR                2
#define XED_ERROR_INVALID_FOR_CHIP             3
#define XED_ERROR_BAD_REGISTER                 4
#define XED_ERROR_BAD_LOCK_PREFIX              5
#define XED_ERROR_BAD_REP_PREFIX               6
#define XED_ERROR_BAD_LEGACY_PREFIX            7
#define XED_ERROR_BAD_REX_PREFIX               8
#define XED_ERROR_BAD_EVEX_UBIT                9
#define XED_ERROR_BAD_MAP                      10
#define XED_ERROR_BAD_EVEX_V_PRIME             11
#define XED_ERROR_BAD_EVEX_Z_NO_MASKING        12
#define XED_ERROR_NO_OUTPUT_POINTER            13
#define XED_ERROR_NO_AGEN_CALL_BACK_REGISTERED 14
#define XED_ERROR_BAD_MEMOP_INDEX              15
#define XED_ERROR_CALLBACK_PROBLEM             16
#define XED_ERROR_GATHER_REGS                  17
#define XED_ERROR_INSTR_TOO_LONG               18
#define XED_ERROR_INVALID_MODE                 19
#define XED_ERROR_BAD_EVEX_LL                  20
#define XED_ERROR_UNIMPLEMENTED                21
#define XED_ERROR_LAST                         22

#define XED_ADDRESS_WIDTH_INVALID 0
#define XED_ADDRESS_WIDTH_16b     2
#define XED_ADDRESS_WIDTH_32b     4
#define XED_ADDRESS_WIDTH_64b     8
#define XED_ADDRESS_WIDTH_LAST    9

#define XED_ILD_MAP0        0 /* 8086+  ... */
#define XED_ILD_MAP1        1 /* 286+   0x0F,... */
#define XED_ILD_MAP2        2 /* Core2+ 0x0F,0x38,... */
#define XED_ILD_MAP3        3 /* Core2+ 0x0F,0x3A,... */
#define XED_ILD_MAP4        4
#define XED_ILD_MAP5        5
#define XED_ILD_MAP6        6
#define XED_ILD_MAPAMD      7
#define XED_ILD_MAP_XOP8    8
#define XED_ILD_MAP_XOP9    9
#define XED_ILD_MAP_XOPA    10
#define XED_ILD_MAP_LAST    11
#define XED_ILD_MAP_INVALID 12

struct XedOperands { /*
  ┌rep
  │ ┌log₂𝑏
  │ │ ┌mode
  │ │ │ ┌eamode
  │ │ │ │ ┌mod
  │ │ │ │ │
  │ │ │ │ │  ┌sego
  │ │ │ │ │  │
  │ │ │ │ │  │   ┌rex         REGISTER
  │ │ │ │ │  │   │┌rexb       DISPATCH
  │ │ │ │ │  │   ││┌srm       ENCODING
  │ │ │ │ │  │   │││  ┌rex
  │ │ │ │ │  │   │││  │┌rexb
  │ │ │ │ │  │   │││  ││┌rm
  │ │ │ │ │  │   │││  │││  ┌rexw
  │ │ │ │ │  │   │││  │││  │┌osz
  │ │ │ │ │  │   │││  │││  ││┌rex
  │ │ │ │ │  │   │││  │││  │││┌rexr
  │ │ │ │ │  │   │││  │││  ││││┌reg
  │3│2│2│2│2 │   │││  │││  │││││
  │0│8│6│4│2 │18 │││12│││ 7│││││ 0
  ├┐├┐├┐├┐├┐ ├─┐ ││├─┐││├─┐││││├─┐
  00000000000000000000000000000000*/
  uint32_t rde;
  union {
    struct {
      union {
        uint8_t opcode;
        uint8_t srm : 3;
      };
      uint8_t map : 4;
    };
    uint16_t dispatch;
  };
  union {
    uint8_t sib;
    struct {
      uint8_t base : 3;
      uint8_t index : 3;
      uint8_t scale : 2;
    };
  };
  bool osz : 1;   /* operand size override prefix */
  bool rexw : 1;  /* rex.w or rex.wb or etc. 64-bit override */
  bool rexb : 1;  /* rex.b or rex.wb or etc. see modrm table */
  bool rexr : 1;  /* rex.r or rex.wr or etc. see modrm table */
  bool rex : 1;   /* any rex prefix including rex */
  bool rexx : 1;  /* rex.x or rex.wx or etc. see sib table */
  bool rexrr : 1; /* evex */
  bool asz : 1;   /* address size override */
  int64_t disp;   /* displacement(%xxx) mostly sign-extended */
  uint64_t uimm0; /* $immediate mostly sign-extended */
  bool out_of_bytes : 1;
  bool is_intel_specific : 1;
  bool ild_f2 : 1;
  bool ild_f3 : 1;
  bool has_sib : 1;
  bool realmode : 1;
  bool amd3dnow : 1;
  bool lock : 1;
  union {
    uint8_t modrm; /* selects address register */
    struct {
      uint8_t rm : 3;
      uint8_t reg : 3;
      uint8_t mod : 2;
    };
  };
  uint8_t max_bytes;
  uint8_t rep : 2; /* 0, 2 (0xf2 repnz), 3 (0xf3 rep/repe) */
  uint8_t has_modrm : 2;
  bool imm_signed : 1;       /* internal */
  bool disp_unsigned : 1;    /* internal */
  uint8_t seg_ovd : 3;       /* XED_SEG_xx */
  uint8_t error : 5;         /* enum XedError */
  uint8_t mode : 2;          /* real,legacy,long */
  uint8_t hint : 3;          /* static branch prediction */
  uint8_t uimm1;             /* enter $x,$y */
  uint8_t disp_width;        /* in bits */
  uint8_t imm_width;         /* in bits */
  uint8_t mode_first_prefix; /* see xed_set_chip_modes() */
  uint8_t nrexes;
  uint8_t nprefixes;
  uint8_t nseg_prefixes;
  uint8_t ubit;       /* vex */
  uint8_t vexvalid;   /* vex */
  uint8_t vexdest3;   /* vex */
  uint8_t vexdest4;   /* vex */
  uint8_t vexdest210; /* vex */
  uint8_t vex_prefix; /* vex */
  uint8_t zeroing;    /* evex */
  uint8_t bcrc;       /* evex */
  uint8_t llrc;       /* evex */
  uint8_t vl;         /* evex */
  uint8_t mask;       /* evex */
  uint8_t imm1_bytes; /* evex */
  uint8_t pos_disp;
  uint8_t pos_imm;
  uint8_t pos_imm1;
  uint8_t pos_modrm;
  uint8_t pos_opcode;
  uint8_t pos_sib;
};

struct XedDecodedInst {
  unsigned char length;
  uint8_t bytes[15];
  struct XedOperands op;
};

#define xed_operands_set_mode(p, machine_mode) \
  do {                                         \
    struct XedOperands *__p = p;               \
    __p->realmode = false;                     \
    switch (machine_mode) {                    \
      default:                                 \
      case XED_MACHINE_MODE_LONG_64:           \
        __p->mode = XED_MODE_LONG;             \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_32:         \
      case XED_MACHINE_MODE_LONG_COMPAT_32:    \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_REAL:              \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
      case XED_MACHINE_MODE_UNREAL:            \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_16:         \
      case XED_MACHINE_MODE_LONG_COMPAT_16:    \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
    }                                          \
  } while (0)

extern const char kXedErrorNames[];
extern const uint8_t kXedEamode[2][3];

struct XedDecodedInst *xed_decoded_inst_zero_set_mode(struct XedDecodedInst *,
                                                      int);
int xed_instruction_length_decode(struct XedDecodedInst *, const void *,
                                  size_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef int xed_int_t;
typedef unsigned int xed_uint_t;
typedef unsigned int xed_uint_t;
typedef unsigned char xed_bits_t;
typedef intptr_t xed_addr_t;
typedef bool xed_bool_t;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/x86isa.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_
COSMOPOLITAN_C_START_

#define XED_CHIP_INVALID           1
#define XED_CHIP_I86               2
#define XED_CHIP_I86FP             3
#define XED_CHIP_I186              4
#define XED_CHIP_I186FP            5
#define XED_CHIP_I286REAL          6
#define XED_CHIP_I286              7
#define XED_CHIP_I2186FP           8
#define XED_CHIP_I386REAL          9
#define XED_CHIP_I386              10
#define XED_CHIP_I386FP            11
#define XED_CHIP_I486REAL          12
#define XED_CHIP_I486              13
#define XED_CHIP_PENTIUMREAL       14
#define XED_CHIP_PENTIUM           15
#define XED_CHIP_QUARK             16
#define XED_CHIP_PENTIUMMMXREAL    17
#define XED_CHIP_PENTIUMMMX        18
#define XED_CHIP_ALLREAL           19
#define XED_CHIP_PENTIUMPRO        20
#define XED_CHIP_PENTIUM2          21
#define XED_CHIP_PENTIUM3          22
#define XED_CHIP_PENTIUM4          23
#define XED_CHIP_P4PRESCOTT        24
#define XED_CHIP_P4PRESCOTT_NOLAHF 25
#define XED_CHIP_P4PRESCOTT_VTX    26
#define XED_CHIP_CORE2             27
#define XED_CHIP_PENRYN            28
#define XED_CHIP_PENRYN_E          29
#define XED_CHIP_NEHALEM           30
#define XED_CHIP_WESTMERE          31
#define XED_CHIP_BONNELL           32
#define XED_CHIP_SALTWELL          33
#define XED_CHIP_SILVERMONT        34
#define XED_CHIP_AMD               35
#define XED_CHIP_GOLDMONT          36
#define XED_CHIP_GOLDMONT_PLUS     37
#define XED_CHIP_TREMONT           38
#define XED_CHIP_SANDYBRIDGE       39
#define XED_CHIP_IVYBRIDGE         40
#define XED_CHIP_HASWELL           41
#define XED_CHIP_BROADWELL         42
#define XED_CHIP_SKYLAKE           43
#define XED_CHIP_SKYLAKE_SERVER    44
#define XED_CHIP_CASCADE_LAKE      45
#define XED_CHIP_KNL               46
#define XED_CHIP_KNM               47
#define XED_CHIP_CANNONLAKE        48
#define XED_CHIP_ICELAKE           49
#define XED_CHIP_ICELAKE_SERVER    50
#define XED_CHIP_FUTURE            51
#define XED_CHIP_ALL               52
#define XED_CHIP_LAST              53

#define XED_ISA_SET_INVALID               0
#define XED_ISA_SET_3DNOW                 1
#define XED_ISA_SET_ADOX_ADCX             2
#define XED_ISA_SET_AES                   3
#define XED_ISA_SET_AMD                   4
#define XED_ISA_SET_AVX                   5
#define XED_ISA_SET_AVX2                  6
#define XED_ISA_SET_AVX2GATHER            7
#define XED_ISA_SET_AVX512BW_128          8
#define XED_ISA_SET_AVX512BW_128N         9
#define XED_ISA_SET_AVX512BW_256          10
#define XED_ISA_SET_AVX512BW_512          11
#define XED_ISA_SET_AVX512BW_KOP          12
#define XED_ISA_SET_AVX512CD_128          13
#define XED_ISA_SET_AVX512CD_256          14
#define XED_ISA_SET_AVX512CD_512          15
#define XED_ISA_SET_AVX512DQ_128          16
#define XED_ISA_SET_AVX512DQ_128N         17
#define XED_ISA_SET_AVX512DQ_256          18
#define XED_ISA_SET_AVX512DQ_512          19
#define XED_ISA_SET_AVX512DQ_KOP          20
#define XED_ISA_SET_AVX512DQ_SCALAR       21
#define XED_ISA_SET_AVX512ER_512          22
#define XED_ISA_SET_AVX512ER_SCALAR       23
#define XED_ISA_SET_AVX512F_128           24
#define XED_ISA_SET_AVX512F_128N          25
#define XED_ISA_SET_AVX512F_256           26
#define XED_ISA_SET_AVX512F_512           27
#define XED_ISA_SET_AVX512F_KOP           28
#define XED_ISA_SET_AVX512F_SCALAR        29
#define XED_ISA_SET_AVX512PF_512          30
#define XED_ISA_SET_AVX512_4FMAPS_512     31
#define XED_ISA_SET_AVX512_4FMAPS_SCALAR  32
#define XED_ISA_SET_AVX512_4VNNIW_512     33
#define XED_ISA_SET_AVX512_BITALG_128     34
#define XED_ISA_SET_AVX512_BITALG_256     35
#define XED_ISA_SET_AVX512_BITALG_512     36
#define XED_ISA_SET_AVX512_GFNI_128       37
#define XED_ISA_SET_AVX512_GFNI_256       38
#define XED_ISA_SET_AVX512_GFNI_512       39
#define XED_ISA_SET_AVX512_IFMA_128       40
#define XED_ISA_SET_AVX512_IFMA_256       41
#define XED_ISA_SET_AVX512_IFMA_512       42
#define XED_ISA_SET_AVX512_VAES_128       43
#define XED_ISA_SET_AVX512_VAES_256       44
#define XED_ISA_SET_AVX512_VAES_512       45
#define XED_ISA_SET_AVX512_VBMI2_128      46
#define XED_ISA_SET_AVX512_VBMI2_256      47
#define XED_ISA_SET_AVX512_VBMI2_512      48
#define XED_ISA_SET_AVX512_VBMI_128       49
#define XED_ISA_SET_AVX512_VBMI_256       50
#define XED_ISA_SET_AVX512_VBMI_512       51
#define XED_ISA_SET_AVX512_VNNI_128       52
#define XED_ISA_SET_AVX512_VNNI_256       53
#define XED_ISA_SET_AVX512_VNNI_512       54
#define XED_ISA_SET_AVX512_VPCLMULQDQ_128 55
#define XED_ISA_SET_AVX512_VPCLMULQDQ_256 56
#define XED_ISA_SET_AVX512_VPCLMULQDQ_512 57
#define XED_ISA_SET_AVX512_VPOPCNTDQ_128  58
#define XED_ISA_SET_AVX512_VPOPCNTDQ_256  59
#define XED_ISA_SET_AVX512_VPOPCNTDQ_512  60
#define XED_ISA_SET_AVXAES                61
#define XED_ISA_SET_AVX_GFNI              62
#define XED_ISA_SET_BMI1                  63
#define XED_ISA_SET_BMI2                  64
#define XED_ISA_SET_CET                   65
#define XED_ISA_SET_CLDEMOTE              66
#define XED_ISA_SET_CLFLUSHOPT            67
#define XED_ISA_SET_CLFSH                 68
#define XED_ISA_SET_CLWB                  69
#define XED_ISA_SET_CLZERO                70
#define XED_ISA_SET_CMOV                  71
#define XED_ISA_SET_CMPXCHG16B            72
#define XED_ISA_SET_F16C                  73
#define XED_ISA_SET_FAT_NOP               74
#define XED_ISA_SET_FCMOV                 75
#define XED_ISA_SET_FMA                   76
#define XED_ISA_SET_FMA4                  77
#define XED_ISA_SET_FXSAVE                78
#define XED_ISA_SET_FXSAVE64              79
#define XED_ISA_SET_GFNI                  80
#define XED_ISA_SET_I186                  81
#define XED_ISA_SET_I286PROTECTED         82
#define XED_ISA_SET_I286REAL              83
#define XED_ISA_SET_I386                  84
#define XED_ISA_SET_I486                  85
#define XED_ISA_SET_I486REAL              86
#define XED_ISA_SET_I86                   87
#define XED_ISA_SET_INVPCID               88
#define XED_ISA_SET_LAHF                  89
#define XED_ISA_SET_LONGMODE              90
#define XED_ISA_SET_LZCNT                 91
#define XED_ISA_SET_MONITOR               92
#define XED_ISA_SET_MONITORX              93
#define XED_ISA_SET_MOVBE                 94
#define XED_ISA_SET_MOVDIR                95
#define XED_ISA_SET_MPX                   96
#define XED_ISA_SET_PAUSE                 97
#define XED_ISA_SET_PCLMULQDQ             98
#define XED_ISA_SET_PCONFIG               99
#define XED_ISA_SET_PENTIUMMMX            100
#define XED_ISA_SET_PENTIUMREAL           101
#define XED_ISA_SET_PKU                   102
#define XED_ISA_SET_POPCNT                103
#define XED_ISA_SET_PPRO                  104
#define XED_ISA_SET_PREFETCHW             105
#define XED_ISA_SET_PREFETCHWT1           106
#define XED_ISA_SET_PREFETCH_NOP          107
#define XED_ISA_SET_PT                    108
#define XED_ISA_SET_RDPID                 109
#define XED_ISA_SET_RDPMC                 110
#define XED_ISA_SET_RDRAND                111
#define XED_ISA_SET_RDSEED                112
#define XED_ISA_SET_RDTSCP                113
#define XED_ISA_SET_RDWRFSGS              114
#define XED_ISA_SET_RTM                   115
#define XED_ISA_SET_SGX                   116
#define XED_ISA_SET_SGX_ENCLV             117
#define XED_ISA_SET_SHA                   118
#define XED_ISA_SET_SMAP                  119
#define XED_ISA_SET_SMX                   120
#define XED_ISA_SET_SSE                   121
#define XED_ISA_SET_SSE2                  122
#define XED_ISA_SET_SSE2MMX               123
#define XED_ISA_SET_SSE3                  124
#define XED_ISA_SET_SSE3X87               125
#define XED_ISA_SET_SSE4                  126
#define XED_ISA_SET_SSE42                 127
#define XED_ISA_SET_SSE4A                 128
#define XED_ISA_SET_SSEMXCSR              129
#define XED_ISA_SET_SSE_PREFETCH          130
#define XED_ISA_SET_SSSE3                 131
#define XED_ISA_SET_SSSE3MMX              132
#define XED_ISA_SET_SVM                   133
#define XED_ISA_SET_TBM                   134
#define XED_ISA_SET_VAES                  135
#define XED_ISA_SET_VMFUNC                136
#define XED_ISA_SET_VPCLMULQDQ            137
#define XED_ISA_SET_VTX                   138
#define XED_ISA_SET_WAITPKG               139
#define XED_ISA_SET_WBNOINVD              140
#define XED_ISA_SET_X87                   141
#define XED_ISA_SET_XOP                   142
#define XED_ISA_SET_XSAVE                 143
#define XED_ISA_SET_XSAVEC                144
#define XED_ISA_SET_XSAVEOPT              145
#define XED_ISA_SET_XSAVES                146
#define XED_ISA_SET_LAST                  147

struct XedChipFeatures {
  uint64_t f[3];
};

#define xed_set_chip_modes(d, chip)    \
  do {                                 \
    struct XedDecodedInst *__d = d;    \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
        break;                         \
      case XED_CHIP_I86:               \
      case XED_CHIP_I86FP:             \
      case XED_CHIP_I186:              \
      case XED_CHIP_I186FP:            \
      case XED_CHIP_I286REAL:          \
      case XED_CHIP_I286:              \
      case XED_CHIP_I2186FP:           \
      case XED_CHIP_I386REAL:          \
      case XED_CHIP_I386:              \
      case XED_CHIP_I386FP:            \
      case XED_CHIP_I486REAL:          \
      case XED_CHIP_I486:              \
      case XED_CHIP_QUARK:             \
      case XED_CHIP_PENTIUM:           \
      case XED_CHIP_PENTIUMREAL:       \
      case XED_CHIP_PENTIUMMMX:        \
      case XED_CHIP_PENTIUMMMXREAL:    \
        __d->op.mode_first_prefix = 1; \
        break;                         \
      default:                         \
        break;                         \
    }                                  \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
      case XED_CHIP_ALL:               \
      case XED_CHIP_AMD:               \
        break;                         \
      default:                         \
        __d->op.is_intel_specific = 1; \
        break;                         \
    }                                  \
  } while (0)

extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];

bool xed_test_chip_features(struct XedChipFeatures *, int);
void xed_get_chip_features(struct XedChipFeatures *, int);
bool xed_isa_set_is_valid_for_chip(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/blake2.h */

#define COSMOPOLITAN_LIBC_STR_BLAKE2_H_

#define BLAKE2B256_DIGEST_LENGTH 32
#define BLAKE2B_CBLOCK           128

#define BLAKE2B256_Init    __BLAKE2B256_Init
#define BLAKE2B256_Update  __BLAKE2B256_Update
#define BLAKE2B256_Process __BLAKE2B256_Process
#define BLAKE2B256_Final   __BLAKE2B256_Final
#define BLAKE2B256         __BLAKE2B256

COSMOPOLITAN_C_START_

struct Blake2b {
  uint64_t h[8];
  uint64_t t_low;
  uint64_t t_high;
  union {
    uint8_t bytes[BLAKE2B_CBLOCK];
    uint64_t words[16];
  } block;
  size_t block_used;
};

int BLAKE2B256_Init(struct Blake2b *);
int BLAKE2B256_Update(struct Blake2b *, const void *, size_t);
int BLAKE2B256_Process(struct Blake2b *, const uint64_t[BLAKE2B_CBLOCK / 8]);
int BLAKE2B256_Final(struct Blake2b *, uint8_t[BLAKE2B256_DIGEST_LENGTH]);
int BLAKE2B256(const void *, size_t, uint8_t[BLAKE2B256_DIGEST_LENGTH]);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/highwayhash64.h */

#define COSMOPOLITAN_LIBC_STR_HIGHWAYHASH64_H_
COSMOPOLITAN_C_START_

uint64_t HighwayHash64(const void *, size_t, const uint64_t[4]) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/langinfo.h */

#define COSMOPOLITAN_LIBC_STR_LANGINFO_H_
COSMOPOLITAN_C_START_

#define ABDAY_1 0x20000
#define ABDAY_2 0x20001
#define ABDAY_3 0x20002
#define ABDAY_4 0x20003
#define ABDAY_5 0x20004
#define ABDAY_6 0x20005
#define ABDAY_7 0x20006

#define DAY_1 0x20007
#define DAY_2 0x20008
#define DAY_3 0x20009
#define DAY_4 0x2000A
#define DAY_5 0x2000B
#define DAY_6 0x2000C
#define DAY_7 0x2000D

#define ABMON_1  0x2000E
#define ABMON_2  0x2000F
#define ABMON_3  0x20010
#define ABMON_4  0x20011
#define ABMON_5  0x20012
#define ABMON_6  0x20013
#define ABMON_7  0x20014
#define ABMON_8  0x20015
#define ABMON_9  0x20016
#define ABMON_10 0x20017
#define ABMON_11 0x20018
#define ABMON_12 0x20019

#define MON_1  0x2001A
#define MON_2  0x2001B
#define MON_3  0x2001C
#define MON_4  0x2001D
#define MON_5  0x2001E
#define MON_6  0x2001F
#define MON_7  0x20020
#define MON_8  0x20021
#define MON_9  0x20022
#define MON_10 0x20023
#define MON_11 0x20024
#define MON_12 0x20025

#define AM_STR 0x20026
#define PM_STR 0x20027

#define D_T_FMT    0x20028
#define D_FMT      0x20029
#define T_FMT      0x2002A
#define T_FMT_AMPM 0x2002B

#define ERA         0x2002C
#define ERA_D_FMT   0x2002E
#define ALT_DIGITS  0x2002F
#define ERA_D_T_FMT 0x20030
#define ERA_T_FMT   0x20031

#define CODESET 14

#define CRNCYSTR 0x4000F

#define RADIXCHAR 0x10000
#define THOUSEP   0x10001
#define YESEXPR   0x50000
#define NOEXPR    0x50001

#define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff)

#if defined(_GNU_SOURCE)
#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat)
#endif

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define YESSTR 0x50002
#define NOSTR  0x50003
#endif

char *nl_langinfo(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/locale.h */

#define COSMOPOLITAN_LIBC_STR_LOCALE_H_

#define LC_CTYPE         0
#define LC_NUMERIC       1
#define LC_CTYPE_MASK    1
#define LC_TIME          2
#define LC_NUMERIC_MASK  2
#define LC_COLLATE       3
#define LC_MONETARY      4
#define LC_TIME_MASK     4
#define LC_MESSAGES      5
#define LC_ALL           6
#define LC_COLLATE_MASK  8
#define LC_MONETARY_MASK 16
#define LC_MESSAGES_MASK 32
#define LC_ALL_MASK      0x1fbf
#define LOCALE_NAME_MAX  23

COSMOPOLITAN_C_START_

#define LC_GLOBAL_LOCALE ((locale_t) - 1)

struct __locale_map {
  const void *map;
  size_t map_size;
  char name[LOCALE_NAME_MAX + 1];
  const struct __locale_map *next;
};

struct __locale_struct {
  const struct __locale_map *cat[6];
};

typedef struct __locale_struct *locale_t;

extern const struct __locale_map __c_dot_utf8;
extern const struct __locale_struct __c_locale;
extern const struct __locale_struct __c_dot_utf8_locale;

char *nl_langinfo_l(int, locale_t) libcesque;
char *setlocale(int, const char *) libcesque;
double strtod_l(const char *, char **, locale_t) libcesque;
double wcstod_l(const wchar_t *, wchar_t **, locale_t) libcesque;
float strtof_l(const char *, char **, locale_t) libcesque;
float wcstof_l(const wchar_t *, wchar_t **, locale_t) libcesque;
int isdigit_l(int, locale_t) libcesque;
int islower_l(int, locale_t) libcesque;
int isupper_l(int, locale_t) libcesque;
int iswalpha_l(wint_t, locale_t) libcesque;
int iswblank_l(wint_t, locale_t) libcesque;
int iswcntrl_l(wint_t, locale_t) libcesque;
int iswdigit_l(wint_t, locale_t) libcesque;
int iswlower_l(wint_t, locale_t) libcesque;
int iswprint_l(wint_t, locale_t) libcesque;
int iswpunct_l(wint_t, locale_t) libcesque;
int iswspace_l(wint_t, locale_t) libcesque;
int iswupper_l(wint_t, locale_t) libcesque;
int iswxdigit_l(wint_t, locale_t) libcesque;
int isxdigit_l(int, locale_t) libcesque;
int strcoll_l(const char *, const char *, locale_t) libcesque;
int tolower_l(int, locale_t) libcesque;
int toupper_l(int, locale_t) libcesque;
int wcscoll_l(const wchar_t *, const wchar_t *, locale_t) libcesque;
locale_t duplocale(locale_t) libcesque;
locale_t newlocale(int, const char *, locale_t) libcesque;
locale_t uselocale(locale_t) libcesque;
long double strtold_l(const char *, char **, locale_t) libcesque;
long double wcstold_l(const wchar_t *, wchar_t **, locale_t) libcesque;
long long strtoll_l(const char *, char **, int, locale_t) libcesque;
long long wcstoll_l(const wchar_t *, wchar_t **, int, locale_t) libcesque;
size_t strftime_l(char *, size_t, char const *, struct tm const *, locale_t);
size_t strxfrm_l(char *, const char *, size_t, locale_t) libcesque;
size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t) libcesque;
unsigned long long strtoull_l(const char *, char **, int, locale_t) libcesque;
unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t);
void freelocale(locale_t) libcesque;
wint_t towlower_l(wint_t, locale_t) libcesque;
wint_t towupper_l(wint_t, locale_t) libcesque;
int strcasecmp_l(const char *, const char *, locale_t) libcesque;
int strncasecmp_l(const char *, const char *, size_t, locale_t) libcesque;
ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/nltypes.h */

#define COSMOPOLITAN_LIBC_STR_NLTYPES_H_

#define NL_SETD       1
#define NL_CAT_LOCALE 1

COSMOPOLITAN_C_START_

typedef int nl_item;
typedef void *nl_catd;

nl_catd catopen(const char *, int);
char *catgets(nl_catd, int, int, const char *);
int catclose(nl_catd);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/slice.h */

#define COSMOPOLITAN_LIBC_STR_SLICE_H_
COSMOPOLITAN_C_START_

#define SlicesEqual(a, n, b, m)       \
  ({                                  \
    size_t __n = (n);                 \
    __n == (m) && !memcmp(a, b, __n); \
  })

#define SlicesEqualCase(a, n, b, m)       \
  ({                                      \
    size_t __n = (n);                     \
    __n == (m) && !memcasecmp(a, b, __n); \
  })

int CompareSlices(const char *, size_t, const char *, size_t) libcesque;
int CompareSlicesCase(const char *, size_t, const char *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/strwidth.h */

#define COSMOPOLITAN_LIBC_STR_STRWIDTH_H_
COSMOPOLITAN_C_START_

int strwidth(const char *, size_t) strlenesque;
int strnwidth(const char *, size_t, size_t) strlenesque;
int strwidth16(const char16_t *, size_t) strlenesque;
int strnwidth16(const char16_t *, size_t, size_t) strlenesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/thompike.h */

#define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_

#define ThomPikeCont(x)     (0200 == (0300 & (x)))
#define ThomPikeByte(x)     ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
#define ThomPikeLen(x)      (7 - ThomPikeMsb(x))
#define ThomPikeMsb(x)      ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1)
#define ThomPikeMerge(x, y) ((x) << 6 | (077 & (y)))



/*!BEGIN libc/str/unicode.h */

#define COSMOPOLITAN_LIBC_STR_UNICODE_H_
COSMOPOLITAN_C_START_

struct lconv {
  char *decimal_point;
  char *thousands_sep;
  char *grouping;
  char *int_curr_symbol;
  char *currency_symbol;
  char *mon_decimal_point;
  char *mon_thousands_sep;
  char *mon_grouping;
  char *positive_sign;
  char *negative_sign;
  char int_frac_digits;
  char frac_digits;
  char p_cs_precedes;
  char p_sep_by_space;
  char n_cs_precedes;
  char n_sep_by_space;
  char p_sign_posn;
  char n_sign_posn;
  char int_p_cs_precedes;
  char int_n_cs_precedes;
  char int_p_sep_by_space;
  char int_n_sep_by_space;
  char int_p_sign_posn;
  char int_n_sign_posn;
};

pureconst int wcwidth(wchar_t) libcesque;
int wcswidth(const wchar_t *, size_t) strlenesque;
struct lconv *localeconv(void) libcesque;

#ifdef _COSMO_SOURCE
int wcsnwidth(const wchar_t *, size_t, size_t) strlenesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/utf16.h */

#define COSMOPOLITAN_LIBC_STR_UTF16_H_

#define UTF16_MASK 0xfc00
#define UTF16_MOAR 0xd800 /* 0xD800..0xDBFF */
#define UTF16_CONT 0xdc00 /* 0xDC00..0xDFFF */

COSMOPOLITAN_C_START_

#define IsSurrogate(wc)     ((0xf800 & (wc)) == 0xd800)
#define IsHighSurrogate(wc) ((UTF16_MASK & (wc)) == UTF16_MOAR)
#define IsLowSurrogate(wc)  ((UTF16_MASK & (wc)) == UTF16_CONT)
#define IsUcs2(wc)          (((65535 & (wc)) >> 11) != 27)
#define IsUtf16Cont(wc)     IsLowSurrogate(wc) /* TODO: DELETE */
#define MergeUtf16(hi, lo)  ((((hi)-0xD800) << 10) + ((lo)-0xDC00) + 0x10000)
#define EncodeUtf16(wc)                                       \
  (LIKELY((0x0000 <= (wc) && (wc) <= 0xFFFF) ||               \
          (0xE000 <= (wc) && (wc) <= 0xFFFF))                 \
       ? (wc)                                                 \
   : 0x10000 <= (wc) && (wc) <= 0x10FFFF                      \
       ? (((((wc)-0x10000) >> 10) + 0xD800) |                 \
          (unsigned)((((wc)-0x10000) & 1023) + 0xDC00) << 16) \
       : 0xFFFD)

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/errfuns.h */

#define COSMOPOLITAN_LIBC_SYSV_ERRFUNS_H_

/**
 * @fileoverview Optimized error return paths.
 *
 * Saying this:
 *
 *     return einval();
 *
 * Instead of this:
 *
 *     errno = EINVAL;
 *     return -1;
 *
 * Allows the compiler to generate 11 fewer bytes of code each time.
 *
 * @return always -1
 * @see libc/sysv/errfuns.inc (for implementation)
 */

libcesque intptr_t einval(void) relegated;
libcesque intptr_t eperm(void) relegated;
libcesque intptr_t enoent(void) relegated;
libcesque intptr_t esrch(void) relegated;
libcesque intptr_t eintr(void) relegated;
libcesque intptr_t eio(void) relegated;
libcesque intptr_t enxio(void) relegated;
libcesque intptr_t e2big(void) relegated;
libcesque intptr_t enoexec(void) relegated;
libcesque intptr_t ebadf(void) relegated;
libcesque intptr_t echild(void) relegated;
libcesque intptr_t eagain(void) relegated;
libcesque intptr_t enomem(void) relegated;
libcesque intptr_t eacces(void) relegated;
libcesque intptr_t efault(void) relegated;
libcesque intptr_t enotblk(void) relegated;
libcesque intptr_t ebusy(void) relegated;
libcesque intptr_t eexist(void) relegated;
libcesque intptr_t exdev(void) relegated;
libcesque intptr_t enodev(void) relegated;
libcesque intptr_t enotdir(void) relegated;
libcesque intptr_t eisdir(void) relegated;
libcesque intptr_t enfile(void) relegated;
libcesque intptr_t emfile(void) relegated;
libcesque intptr_t enotty(void) relegated;
libcesque intptr_t enotsup(void) relegated;
libcesque intptr_t etxtbsy(void) relegated;
libcesque intptr_t efbig(void) relegated;
libcesque intptr_t enospc(void) relegated;
libcesque intptr_t espipe(void) relegated;
libcesque intptr_t erofs(void) relegated;
libcesque intptr_t emlink(void) relegated;
libcesque intptr_t epipe(void) relegated;
libcesque intptr_t edom(void) relegated;
libcesque intptr_t erange(void) relegated;
libcesque intptr_t edeadlk(void) relegated;
libcesque intptr_t enametoolong(void) relegated;
libcesque intptr_t enolck(void) relegated;
libcesque intptr_t enosys(void) relegated;
libcesque intptr_t enotempty(void) relegated;
libcesque intptr_t eloop(void) relegated;
libcesque intptr_t enomsg(void) relegated;
libcesque intptr_t eidrm(void) relegated;
libcesque intptr_t echrng(void) relegated;
libcesque intptr_t el2nsync(void) relegated;
libcesque intptr_t el3hlt(void) relegated;
libcesque intptr_t el3rst(void) relegated;
libcesque intptr_t elnrng(void) relegated;
libcesque intptr_t eunatch(void) relegated;
libcesque intptr_t enocsi(void) relegated;
libcesque intptr_t el2hlt(void) relegated;
libcesque intptr_t ebade(void) relegated;
libcesque intptr_t ebadr(void) relegated;
libcesque intptr_t exfull(void) relegated;
libcesque intptr_t enoano(void) relegated;
libcesque intptr_t ebadrqc(void) relegated;
libcesque intptr_t ebadslt(void) relegated;
libcesque intptr_t enostr(void) relegated;
libcesque intptr_t enodata(void) relegated;
libcesque intptr_t etime(void) relegated;
libcesque intptr_t enosr(void) relegated;
libcesque intptr_t enonet(void) relegated;
libcesque intptr_t enopkg(void) relegated;
libcesque intptr_t eremote(void) relegated;
libcesque intptr_t enolink(void) relegated;
libcesque intptr_t eadv(void) relegated;
libcesque intptr_t esrmnt(void) relegated;
libcesque intptr_t ecomm(void) relegated;
libcesque intptr_t eproto(void) relegated;
libcesque intptr_t emultihop(void) relegated;
libcesque intptr_t edotdot(void) relegated;
libcesque intptr_t ebadmsg(void) relegated;
libcesque intptr_t eoverflow(void) relegated;
libcesque intptr_t enotuniq(void) relegated;
libcesque intptr_t ebadfd(void) relegated;
libcesque intptr_t eremchg(void) relegated;
libcesque intptr_t elibacc(void) relegated;
libcesque intptr_t elibbad(void) relegated;
libcesque intptr_t elibscn(void) relegated;
libcesque intptr_t elibmax(void) relegated;
libcesque intptr_t elibexec(void) relegated;
libcesque intptr_t eilseq(void) relegated;
libcesque intptr_t erestart(void) relegated;
libcesque intptr_t estrpipe(void) relegated;
libcesque intptr_t eusers(void) relegated;
libcesque intptr_t enotsock(void) relegated;
libcesque intptr_t edestaddrreq(void) relegated;
libcesque intptr_t emsgsize(void) relegated;
libcesque intptr_t eprototype(void) relegated;
libcesque intptr_t enoprotoopt(void) relegated;
libcesque intptr_t eprotonosupport(void) relegated;
libcesque intptr_t esocktnosupport(void) relegated;
libcesque intptr_t eopnotsupp(void) relegated;
libcesque intptr_t epfnosupport(void) relegated;
libcesque intptr_t eafnosupport(void) relegated;
libcesque intptr_t eaddrinuse(void) relegated;
libcesque intptr_t eaddrnotavail(void) relegated;
libcesque intptr_t enetdown(void) relegated;
libcesque intptr_t enetunreach(void) relegated;
libcesque intptr_t enetreset(void) relegated;
libcesque intptr_t econnaborted(void) relegated;
libcesque intptr_t econnreset(void) relegated;
libcesque intptr_t enobufs(void) relegated;
libcesque intptr_t eisconn(void) relegated;
libcesque intptr_t enotconn(void) relegated;
libcesque intptr_t eshutdown(void) relegated;
libcesque intptr_t etoomanyrefs(void) relegated;
libcesque intptr_t etimedout(void) relegated;
libcesque intptr_t econnrefused(void) relegated;
libcesque intptr_t ehostdown(void) relegated;
libcesque intptr_t ehostunreach(void) relegated;
libcesque intptr_t ealready(void) relegated;
libcesque intptr_t einprogress(void) relegated;
libcesque intptr_t estale(void) relegated;
libcesque intptr_t euclean(void) relegated;
libcesque intptr_t enotnam(void) relegated;
libcesque intptr_t enavail(void) relegated;
libcesque intptr_t eisnam(void) relegated;
libcesque intptr_t eremoteio(void) relegated;
libcesque intptr_t edquot(void) relegated;
libcesque intptr_t enomedium(void) relegated;
libcesque intptr_t emediumtype(void) relegated;
libcesque intptr_t ecanceled(void) relegated;
libcesque intptr_t enokey(void) relegated;
libcesque intptr_t ekeyexpired(void) relegated;
libcesque intptr_t ekeyrevoked(void) relegated;
libcesque intptr_t ekeyrejected(void) relegated;
libcesque intptr_t eownerdead(void) relegated;
libcesque intptr_t enotrecoverable(void) relegated;
libcesque intptr_t erfkill(void) relegated;
libcesque intptr_t ehwpoison(void) relegated;

#if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __ERRFUN(FUNC)               \
  ({                                 \
    intptr_t NegOne;                 \
    asm volatile("call\t" FUNC       \
                 : "=a"(NegOne)      \
                 : /* no outputs */  \
                 : "rcx", "memory"); \
    NegOne;                          \
  })
#define einval()          __ERRFUN("einval")
#define eperm()           __ERRFUN("eperm")
#define enoent()          __ERRFUN("enoent")
#define esrch()           __ERRFUN("esrch")
#define eintr()           __ERRFUN("eintr")
#define eio()             __ERRFUN("eio")
#define enxio()           __ERRFUN("enxio")
#define e2big()           __ERRFUN("e2big")
#define enoexec()         __ERRFUN("enoexec")
#define ebadf()           __ERRFUN("ebadf")
#define echild()          __ERRFUN("echild")
#define eagain()          __ERRFUN("eagain")
#define enomem()          __ERRFUN("enomem")
#define eacces()          __ERRFUN("eacces")
#define efault()          __ERRFUN("efault")
#define enotblk()         __ERRFUN("enotblk")
#define ebusy()           __ERRFUN("ebusy")
#define eexist()          __ERRFUN("eexist")
#define exdev()           __ERRFUN("exdev")
#define enodev()          __ERRFUN("enodev")
#define enotdir()         __ERRFUN("enotdir")
#define eisdir()          __ERRFUN("eisdir")
#define enfile()          __ERRFUN("enfile")
#define emfile()          __ERRFUN("emfile")
#define enotty()          __ERRFUN("enotty")
#define enotsup()         __ERRFUN("enotsup")
#define etxtbsy()         __ERRFUN("etxtbsy")
#define efbig()           __ERRFUN("efbig")
#define enospc()          __ERRFUN("enospc")
#define espipe()          __ERRFUN("espipe")
#define erofs()           __ERRFUN("erofs")
#define emlink()          __ERRFUN("emlink")
#define epipe()           __ERRFUN("epipe")
#define edom()            __ERRFUN("edom")
#define erange()          __ERRFUN("erange")
#define edeadlk()         __ERRFUN("edeadlk")
#define enametoolong()    __ERRFUN("enametoolong")
#define enolck()          __ERRFUN("enolck")
#define enosys()          __ERRFUN("enosys")
#define enotempty()       __ERRFUN("enotempty")
#define eloop()           __ERRFUN("eloop")
#define enomsg()          __ERRFUN("enomsg")
#define eidrm()           __ERRFUN("eidrm")
#define echrng()          __ERRFUN("echrng")
#define el2nsync()        __ERRFUN("el2nsync")
#define el3hlt()          __ERRFUN("el3hlt")
#define el3rst()          __ERRFUN("el3rst")
#define elnrng()          __ERRFUN("elnrng")
#define eunatch()         __ERRFUN("eunatch")
#define enocsi()          __ERRFUN("enocsi")
#define el2hlt()          __ERRFUN("el2hlt")
#define ebade()           __ERRFUN("ebade")
#define ebadr()           __ERRFUN("ebadr")
#define exfull()          __ERRFUN("exfull")
#define enoano()          __ERRFUN("enoano")
#define ebadrqc()         __ERRFUN("ebadrqc")
#define ebadslt()         __ERRFUN("ebadslt")
#define enostr()          __ERRFUN("enostr")
#define enodata()         __ERRFUN("enodata")
#define etime()           __ERRFUN("etime")
#define enosr()           __ERRFUN("enosr")
#define enonet()          __ERRFUN("enonet")
#define enopkg()          __ERRFUN("enopkg")
#define eremote()         __ERRFUN("eremote")
#define enolink()         __ERRFUN("enolink")
#define eadv()            __ERRFUN("eadv")
#define esrmnt()          __ERRFUN("esrmnt")
#define ecomm()           __ERRFUN("ecomm")
#define eproto()          __ERRFUN("eproto")
#define emultihop()       __ERRFUN("emultihop")
#define edotdot()         __ERRFUN("edotdot")
#define ebadmsg()         __ERRFUN("ebadmsg")
#define eoverflow()       __ERRFUN("eoverflow")
#define enotuniq()        __ERRFUN("enotuniq")
#define ebadfd()          __ERRFUN("ebadfd")
#define eremchg()         __ERRFUN("eremchg")
#define elibacc()         __ERRFUN("elibacc")
#define elibbad()         __ERRFUN("elibbad")
#define elibscn()         __ERRFUN("elibscn")
#define elibmax()         __ERRFUN("elibmax")
#define elibexec()        __ERRFUN("elibexec")
#define eilseq()          __ERRFUN("eilseq")
#define erestart()        __ERRFUN("erestart")
#define estrpipe()        __ERRFUN("estrpipe")
#define eusers()          __ERRFUN("eusers")
#define enotsock()        __ERRFUN("enotsock")
#define edestaddrreq()    __ERRFUN("edestaddrreq")
#define emsgsize()        __ERRFUN("emsgsize")
#define eprototype()      __ERRFUN("eprototype")
#define enoprotoopt()     __ERRFUN("enoprotoopt")
#define eprotonosupport() __ERRFUN("eprotonosupport")
#define esocktnosupport() __ERRFUN("esocktnosupport")
#define eopnotsupp()      __ERRFUN("eopnotsupp")
#define epfnosupport()    __ERRFUN("epfnosupport")
#define eafnosupport()    __ERRFUN("eafnosupport")
#define eaddrinuse()      __ERRFUN("eaddrinuse")
#define eaddrnotavail()   __ERRFUN("eaddrnotavail")
#define enetdown()        __ERRFUN("enetdown")
#define enetunreach()     __ERRFUN("enetunreach")
#define enetreset()       __ERRFUN("enetreset")
#define econnaborted()    __ERRFUN("econnaborted")
#define econnreset()      __ERRFUN("econnreset")
#define enobufs()         __ERRFUN("enobufs")
#define eisconn()         __ERRFUN("eisconn")
#define enotconn()        __ERRFUN("enotconn")
#define eshutdown()       __ERRFUN("eshutdown")
#define etoomanyrefs()    __ERRFUN("etoomanyrefs")
#define etimedout()       __ERRFUN("etimedout")
#define econnrefused()    __ERRFUN("econnrefused")
#define ehostdown()       __ERRFUN("ehostdown")
#define ehostunreach()    __ERRFUN("ehostunreach")
#define ealready()        __ERRFUN("ealready")
#define einprogress()     __ERRFUN("einprogress")
#define estale()          __ERRFUN("estale")
#define euclean()         __ERRFUN("euclean")
#define enotnam()         __ERRFUN("enotnam")
#define enavail()         __ERRFUN("enavail")
#define eisnam()          __ERRFUN("eisnam")
#define eremoteio()       __ERRFUN("eremoteio")
#define edquot()          __ERRFUN("edquot")
#define enomedium()       __ERRFUN("enomedium")
#define emediumtype()     __ERRFUN("emediumtype")
#define ecanceled()       __ERRFUN("ecanceled")
#define enokey()          __ERRFUN("enokey")
#define ekeyexpired()     __ERRFUN("ekeyexpired")
#define ekeyrevoked()     __ERRFUN("ekeyrevoked")
#define ekeyrejected()    __ERRFUN("ekeyrejected")
#define eownerdead()      __ERRFUN("eownerdead")
#define enotrecoverable() __ERRFUN("enotrecoverable")
#define erfkill()         __ERRFUN("erfkill")
#define ehwpoison()       __ERRFUN("ehwpoison")
#endif



/*!BEGIN libc/sysv/consts/_posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS__POSIX_H_

/* The Open Group Base Specifications Issue 7, 2018 edition */
/* IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)  */

#define _POSIX_AIO_LISTIO_MAX               2
#define _POSIX_CLOCKRES_MIN                 20000000
#define _POSIX_AIO_MAX                      1
#define _POSIX_ARG_MAX                      4096
#define _POSIX_CHILD_MAX                    25
#define _POSIX_DELAYTIMER_MAX               32
#define _POSIX_HOST_NAME_MAX                255
#define _POSIX_LINK_MAX                     8
#define _POSIX_LOGIN_NAME_MAX               9
#define _POSIX_MAX_CANON                    255
#define _POSIX_MAX_INPUT                    255
#define _POSIX_MQ_OPEN_MAX                  8
#define _POSIX_MQ_PRIO_MAX                  32
#define _POSIX_NAME_MAX                     14
#define _POSIX_NGROUPS_MAX                  8
#define _POSIX_OPEN_MAX                     20
#define _POSIX_PATH_MAX                     256
#define _POSIX_PIPE_BUF                     512
#define _POSIX_RE_DUP_MAX                   255
#define _POSIX_RTSIG_MAX                    8
#define _POSIX_SEM_NSEMS_MAX                256
#define _POSIX_SEM_VALUE_MAX                32767
#define _POSIX_SIGQUEUE_MAX                 32
#define _POSIX_SSIZE_MAX                    32767
#define _POSIX_SS_REPL_MAX                  4
#define _POSIX_STREAM_MAX                   8
#define _POSIX_SYMLINK_MAX                  255
#define _POSIX_SYMLOOP_MAX                  8
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
#define _POSIX_THREAD_KEYS_MAX              128
#define _POSIX_THREAD_THREADS_MAX           64
#define _POSIX_TIMER_MAX                    32
#define _POSIX_TRACE_EVENT_NAME_MAX         30
#define _POSIX_TRACE_NAME_MAX               8
#define _POSIX_TRACE_SYS_MAX                8
#define _POSIX_TRACE_USER_EVENT_MAX         32
#define _POSIX_TTY_NAME_MAX                 9
#define _POSIX_TZNAME_MAX                   6

#define _POSIX2_BC_BASE_MAX        99
#define _POSIX2_BC_DIM_MAX         2048
#define _POSIX2_BC_SCALE_MAX       99
#define _POSIX2_BC_STRING_MAX      1000
#define _POSIX2_CHARCLASS_NAME_MAX 14
#define _POSIX2_COLL_WEIGHTS_MAX   2
#define _POSIX2_EXPR_NEST_MAX      32
#define _POSIX2_LINE_MAX           2048
#define _POSIX2_RE_DUP_MAX         255



/*!BEGIN libc/sysv/consts/af.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AF_H_
COSMOPOLITAN_C_START_

extern const int AF_ALG;
extern const int AF_APPLETALK;
extern const int AF_ASH;
extern const int AF_ATMPVC;
extern const int AF_ATMSVC;
extern const int AF_AX25;
extern const int AF_BLUETOOTH;
extern const int AF_BRIDGE;
extern const int AF_CAIF;
extern const int AF_CAN;
extern const int AF_ECONET;
extern const int AF_FILE;
extern const int AF_IB;
extern const int AF_IEEE802154;
extern const int AF_INET6;
extern const int AF_INET;
extern const int AF_IPX;
extern const int AF_IRDA;
extern const int AF_ISDN;
extern const int AF_IUCV;
extern const int AF_KCM;
extern const int AF_KEY;
extern const int AF_LINK;
extern const int AF_LLC;
extern const int AF_LOCAL;
extern const int AF_MAX;
extern const int AF_MPLS;
extern const int AF_NETBEUI;
extern const int AF_NETLINK;
extern const int AF_NETROM;
extern const int AF_NFC;
extern const int AF_PACKET;
extern const int AF_PHONET;
extern const int AF_PPPOX;
extern const int AF_ROSE;
extern const int AF_ROUTE;
extern const int AF_RXRPC;
extern const int AF_SECURITY;
extern const int AF_SNA;
extern const int AF_TIPC;
extern const int AF_UNIX;
extern const int AF_UNSPEC;
extern const int AF_VSOCK;
extern const int AF_WANPIPE;
extern const int AF_X25;

#define AF_ALG        AF_ALG
#define AF_LINK       AF_LINK
#define AF_APPLETALK  AF_APPLETALK
#define AF_ASH        AF_ASH
#define AF_ATMPVC     AF_ATMPVC
#define AF_ATMSVC     AF_ATMSVC
#define AF_AX25       AF_AX25
#define AF_BLUETOOTH  AF_BLUETOOTH
#define AF_BRIDGE     AF_BRIDGE
#define AF_CAIF       AF_CAIF
#define AF_CAN        AF_CAN
#define AF_ECONET     AF_ECONET
#define AF_FILE       AF_FILE
#define AF_IB         AF_IB
#define AF_IEEE802154 AF_IEEE802154
#define AF_INET       2
#define AF_INET6      AF_INET6
#define AF_IPX        AF_IPX
#define AF_IRDA       AF_IRDA
#define AF_ISDN       AF_ISDN
#define AF_IUCV       AF_IUCV
#define AF_KCM        AF_KCM
#define AF_KEY        AF_KEY
#define AF_LLC        AF_LLC
#define AF_LOCAL      AF_LOCAL
#define AF_MAX        AF_MAX
#define AF_MPLS       AF_MPLS
#define AF_NETBEUI    AF_NETBEUI
#define AF_NETLINK    AF_NETLINK
#define AF_NETROM     AF_NETROM
#define AF_NFC        AF_NFC
#define AF_PACKET     AF_PACKET
#define AF_PHONET     AF_PHONET
#define AF_PPPOX      AF_PPPOX
#define AF_ROSE       AF_ROSE
#define AF_ROUTE      AF_ROUTE
#define AF_RXRPC      AF_RXRPC
#define AF_SECURITY   AF_SECURITY
#define AF_SNA        AF_SNA
#define AF_TIPC       AF_TIPC
#define AF_UNIX       1
#define AF_UNSPEC     0
#define AF_VSOCK      AF_VSOCK
#define AF_WANPIPE    AF_WANPIPE
#define AF_X25        AF_X25

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/arch.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARCH_H_

#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004



/*!BEGIN libc/sysv/consts/arp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARP_H_

#define ARPHRD_ETHER 1



/*!BEGIN libc/sysv/consts/at.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AT_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview AT_xxx constants for fcntl(), fopenat(), etc..
 * @see libc/sysv/consts/auxv.h for getauxval() constants
 */

extern const int AT_FDCWD;
extern const int AT_SYMLINK_FOLLOW;
extern const int AT_SYMLINK_NOFOLLOW;
extern const int AT_REMOVEDIR;
extern const int AT_EACCESS;
extern const int AT_EMPTY_PATH;

COSMOPOLITAN_C_END_

#define AT_FDCWD            AT_FDCWD
#define AT_SYMLINK_FOLLOW   AT_SYMLINK_FOLLOW
#define AT_SYMLINK_NOFOLLOW AT_SYMLINK_NOFOLLOW
#define AT_REMOVEDIR        AT_REMOVEDIR
#define AT_EACCESS          AT_EACCESS



/*!BEGIN libc/sysv/consts/audit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AUDIT_H_

#define __AUDIT_ARCH_64BIT                 0x80000000
#define __AUDIT_ARCH_LE                    0x40000000
#define __AUDIT_ARCH_CONVENTION_MASK       0x30000000
#define __AUDIT_ARCH_CONVENTION_MIPS64_N32 0x20000000

#define AUDIT_ARCH_X86_64  (EM_X86_64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_I386    (EM_386 | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_AARCH64 (EM_AARCH64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_PPC64LE (EM_PPC64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_RISCV64 (EM_RISCV | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_S390X   (EM_S390 | __AUDIT_ARCH_64BIT)



/*!BEGIN libc/sysv/consts/auxv.h */

#define COSMOPOLITAN_LIBC_CALLS_AUXV_H_

/*
 * integral getauxval() keys
 */
#define AT_PHDR                     3
#define AT_PHENT                    4
#define AT_PHNUM                    5
#define AT_PAGESZ                   6
#define AT_BASE                     7
#define AT_FLAGS                    8
#define AT_FLAGS_PRESERVE_ARGV0_BIT 0
#define AT_FLAGS_PRESERVE_ARGV0     (1 << AT_FLAGS_PRESERVE_ARGV0_BIT)
#define AT_ENTRY                    9

COSMOPOLITAN_C_START_

/*
 * portable getauxval() keys
 */
extern const unsigned long AT_EXECFN;
extern const unsigned long AT_SECURE;
extern const unsigned long AT_RANDOM;
extern const unsigned long AT_HWCAP;
extern const unsigned long AT_HWCAP2;
extern const unsigned long AT_UID;
extern const unsigned long AT_EUID;
extern const unsigned long AT_GID;
extern const unsigned long AT_EGID;
#define AT_EXECFN AT_EXECFN
#define AT_SECURE AT_SECURE
#define AT_RANDOM AT_RANDOM
#define AT_HWCAP  AT_HWCAP
#define AT_HWCAP2 AT_HWCAP2
#define AT_UID    AT_UID
#define AT_EUID   AT_EUID
#define AT_GID    AT_GID
#define AT_EGID   AT_EGID

/*
 * platform-specific getauxval() keys
 */
extern const unsigned long AT_BASE_PLATFORM;
extern const unsigned long AT_CANARY;
extern const unsigned long AT_CANARYLEN;
extern const unsigned long AT_CLKTCK;
extern const unsigned long AT_DCACHEBSIZE;
extern const unsigned long AT_EHDRFLAGS;
extern const unsigned long AT_EXECFD;
extern const unsigned long AT_EXECPATH;
extern const unsigned long AT_ICACHEBSIZE;
extern const unsigned long AT_MINSIGSTKSZ;
extern const unsigned long AT_NCPUS;
extern const unsigned long AT_NOTELF;
extern const unsigned long AT_NO_AUTOMOUNT;
extern const unsigned long AT_OSRELDATE;
extern const unsigned long AT_PAGESIZES;
extern const unsigned long AT_PAGESIZESLEN;
extern const unsigned long AT_PLATFORM;
extern const unsigned long AT_STACKBASE;
extern const unsigned long AT_STACKPROT;
extern const unsigned long AT_SYSINFO_EHDR;
extern const unsigned long AT_TIMEKEEP;
extern const unsigned long AT_UCACHEBSIZE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/c.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CPIO_H_

#define MAGIC "070707"

#define C_IRUSR 000400
#define C_IWUSR 000200
#define C_IXUSR 000100
#define C_IRGRP 000040
#define C_IWGRP 000020
#define C_IXGRP 000010
#define C_IROTH 000004
#define C_IWOTH 000002
#define C_IXOTH 000001

#define C_ISUID 004000
#define C_ISGID 002000
#define C_ISVTX 001000

#define C_ISBLK  060000
#define C_ISCHR  020000
#define C_ISDIR  040000
#define C_ISFIFO 010000
#define C_ISSOCK 0140000
#define C_ISLNK  0120000
#define C_ISCTG  0110000
#define C_ISREG  0100000



/*!BEGIN libc/sysv/consts/cap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CAP_H_

#define CAP_CHOWN              0
#define CAP_DAC_OVERRIDE       1
#define CAP_DAC_READ_SEARCH    2
#define CAP_FOWNER             3
#define CAP_FSETID             4
#define CAP_KILL               5
#define CAP_SETGID             6
#define CAP_SETUID             7
#define CAP_SETPCAP            8
#define CAP_LINUX_IMMUTABLE    9
#define CAP_NET_BIND_SERVICE   10
#define CAP_NET_BROADCAST      11
#define CAP_NET_ADMIN          12
#define CAP_NET_RAW            13
#define CAP_IPC_LOCK           14
#define CAP_IPC_OWNER          15
#define CAP_SYS_MODULE         16
#define CAP_SYS_RAWIO          17
#define CAP_SYS_CHROOT         18
#define CAP_SYS_PTRACE         19
#define CAP_SYS_PACCT          20
#define CAP_SYS_ADMIN          21
#define CAP_SYS_BOOT           22
#define CAP_SYS_NICE           23
#define CAP_SYS_RESOURCE       24
#define CAP_SYS_TIME           25
#define CAP_SYS_TTY_CONFIG     26
#define CAP_MKNOD              27
#define CAP_LEASE              28
#define CAP_AUDIT_WRITE        29
#define CAP_AUDIT_CONTROL      30
#define CAP_SETFCAP            31
#define CAP_MAC_OVERRIDE       32
#define CAP_MAC_ADMIN          33
#define CAP_SYSLOG             34
#define CAP_WAKE_ALARM         35
#define CAP_BLOCK_SUSPEND      36
#define CAP_AUDIT_READ         37
#define CAP_PERFMON            38
#define CAP_BPF                39
#define CAP_CHECKPOINT_RESTORE 40
#define CAP_LAST_CAP           CAP_CHECKPOINT_RESTORE



/*!BEGIN libc/sysv/consts/clock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOCK_H_
COSMOPOLITAN_C_START_

extern const int CLOCK_BOOTTIME;
extern const int CLOCK_BOOTTIME_ALARM;
extern const int CLOCK_MONOTONIC;
extern const int CLOCK_MONOTONIC_COARSE;
extern const int CLOCK_MONOTONIC_FAST;
extern const int CLOCK_MONOTONIC_PRECISE;
extern const int CLOCK_MONOTONIC_RAW;
extern const int CLOCK_PROCESS_CPUTIME_ID;
extern const int CLOCK_PROF;
extern const int CLOCK_REALTIME_ALARM;
extern const int CLOCK_REALTIME_COARSE;
extern const int CLOCK_REALTIME_FAST;
extern const int CLOCK_REALTIME_PRECISE;
extern const int CLOCK_SECOND;
extern const int CLOCK_TAI;
extern const int CLOCK_THREAD_CPUTIME_ID;
extern const int CLOCK_UPTIME;
extern const int CLOCK_UPTIME_FAST;
extern const int CLOCK_UPTIME_PRECISE;

COSMOPOLITAN_C_END_

#define CLOCK_REALTIME  0
#define CLOCK_MONOTONIC CLOCK_MONOTONIC



/*!BEGIN libc/sysv/consts/clone.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLONE_H_
#ifdef _COSMO_SOURCE

#define CSIGNAL              0x000000ff
#define CLONE_VM             0x00000100
#define CLONE_FS             0x00000200
#define CLONE_FILES          0x00000400
#define CLONE_SIGHAND        0x00000800
#define CLONE_PIDFD          0x00001000
#define CLONE_PTRACE         0x00002000
#define CLONE_VFORK          0x00004000
#define CLONE_PARENT         0x00008000
#define CLONE_THREAD         0x00010000
#define CLONE_NEWNS          0x00020000
#define CLONE_SYSVSEM        0x00040000
#define CLONE_SETTLS         0x00080000
#define CLONE_PARENT_SETTID  0x00100000
#define CLONE_CHILD_CLEARTID 0x00200000
#define CLONE_DETACHED       0x00400000
#define CLONE_UNTRACED       0x00800000
#define CLONE_CHILD_SETTID   0x01000000
#define CLONE_NEWCGROUP      0x02000000
#define CLONE_NEWUTS         0x04000000
#define CLONE_NEWIPC         0x08000000
#define CLONE_NEWUSER        0x10000000
#define CLONE_NEWPID         0x20000000
#define CLONE_NEWNET         0x40000000
#define CLONE_IO             0x80000000

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/close.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOSE_H_
COSMOPOLITAN_C_START_

extern const unsigned int CLOSE_RANGE_UNSHARE;
extern const unsigned int CLOSE_RANGE_CLOEXEC;

COSMOPOLITAN_C_END_

#define CLOSE_RANGE_UNSHARE CLOSE_RANGE_UNSHARE
#define CLOSE_RANGE_CLOEXEC CLOSE_RANGE_CLOEXEC



/*!BEGIN libc/sysv/consts/dn.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DN_H_

#define DN_ACCESS    0x00000001 /* file accessed */
#define DN_MODIFY    0x00000002 /* file modified */
#define DN_CREATE    0x00000004 /* file created */
#define DN_DELETE    0x00000008 /* file removed */
#define DN_RENAME    0x00000010 /* file renamed */
#define DN_ATTRIB    0x00000020 /* file changed attibutes */
#define DN_MULTISHOT 0x80000000 /* don't remove notifier */



/*!BEGIN libc/sysv/consts/dt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DT_H_

#define DT_UNKNOWN 0
#define DT_FIFO    1
#define DT_CHR     2
#define DT_DIR     4
#define DT_BLK     6
#define DT_REG     8
#define DT_LNK     10
#define DT_SOCK    12



/*!BEGIN libc/sysv/consts/endian.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ENDIAN_H_

#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define __BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define __PDP_ENDIAN    __ORDER_PDP_ENDIAN__
#define __BYTE_ORDER    __BYTE_ORDER__



/*!BEGIN libc/sysv/consts/epoll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EPOLL_H_


/*!BEGIN libc/sysv/consts/o.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_

#define O_RDONLY  0
#define O_WRONLY  1
#define O_RDWR    2
#define O_ACCMODE 3

COSMOPOLITAN_C_START_

extern const unsigned O_APPEND;
extern const unsigned O_ASYNC;
extern const unsigned O_CLOEXEC;
extern const unsigned O_COMPRESSED;
extern const unsigned O_CREAT;
extern const unsigned O_DIRECT;
extern const unsigned O_DIRECTORY;
extern const unsigned O_DSYNC;
extern const unsigned O_EXCL;
extern const unsigned O_EXEC;
extern const unsigned O_EXLOCK;
extern const unsigned O_INDEXED;
extern const unsigned O_LARGEFILE;
extern const unsigned O_NOATIME;
extern const unsigned O_NOCTTY;
extern const unsigned O_NOFOLLOW;
extern const unsigned O_NOFOLLOW_ANY;
extern const unsigned O_NONBLOCK;
extern const unsigned O_PATH;
extern const unsigned O_RANDOM;
extern const unsigned O_RSYNC;
extern const unsigned O_SEARCH;
extern const unsigned O_SEQUENTIAL;
extern const unsigned O_SHLOCK;
extern const unsigned O_SYNC;
extern const unsigned O_TMPFILE; /* use tmpfd() or tmpfile() */
extern const unsigned O_TRUNC;
extern const unsigned O_TTY_INIT;
extern const unsigned O_UNLINK;
extern const unsigned O_VERIFY;

#define O_APPEND     O_APPEND
#define O_ASYNC      O_ASYNC
#define O_CLOEXEC    O_CLOEXEC
#define O_COMPRESSED O_COMPRESSED
#define O_CREAT      O_CREAT
#define O_DIRECTORY  O_DIRECTORY
#define O_EXCL       O_EXCL
#define O_EXEC       O_EXEC
#define O_INDEXED    O_INDEXED
#define O_LARGEFILE  O_LARGEFILE
#define O_NDELAY     O_NONBLOCK
#define O_NOATIME    O_NOATIME
#define O_NOCTTY     O_NOCTTY
#define O_NOFOLLOW   O_NOFOLLOW
#define O_NONBLOCK   O_NONBLOCK
#define O_RANDOM     O_RANDOM
#define O_SEQUENTIAL O_SEQUENTIAL
#define O_SYNC       O_SYNC
#define O_TRUNC      O_TRUNC
#define O_UNLINK     O_UNLINK

COSMOPOLITAN_C_END_

#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_DEL 2
#define EPOLL_CTL_MOD 3

#define EPOLLIN        1
#define EPOLLPRI       2
#define EPOLLOUT       4
#define EPOLLERR       8
#define EPOLLHUP       0x10
#define EPOLLRDNORM    0x40
#define EPOLLRDBAND    0x80
#define EPOLLWRNORM    0x0100
#define EPOLLWRBAND    0x0200
#define EPOLLMSG       0x0400
#define EPOLLRDHUP     0x2000
#define EPOLLEXCLUSIVE 0x10000000
#define EPOLLWAKEUP    0x20000000
#define EPOLLONESHOT   0x40000000
#define EPOLLET        0x80000000

COSMOPOLITAN_C_START_

extern const int EPOLL_CLOEXEC;
#define EPOLL_CLOEXEC O_CLOEXEC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ethernet.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ETHERNET_H_

#define ETHERTYPE_PUP      0x0200
#define ETHERTYPE_SPRITE   0x0500
#define ETHERTYPE_IP       0x0800
#define ETHERTYPE_ARP      0x0806
#define ETHERTYPE_REVARP   0x8035
#define ETHERTYPE_AT       0x809B
#define ETHERTYPE_AARP     0x80F3
#define ETHERTYPE_VLAN     0x8100
#define ETHERTYPE_IPX      0x8137
#define ETHERTYPE_IPV6     0x86dd
#define ETHERTYPE_LOOPBACK 0x9000

#define ETHER_ADDR_LEN ETH_ALEN
#define ETHER_TYPE_LEN 2
#define ETHER_CRC_LEN  4
#define ETHER_HDR_LEN  ETH_HLEN
#define ETHER_MIN_LEN  (ETH_ZLEN + ETHER_CRC_LEN)
#define ETHER_MAX_LEN  (ETH_FRAME_LEN + ETHER_CRC_LEN)

#define ETHER_IS_VALID_LEN(foo) \
  ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)

#define ETHERTYPE_TRAIL    0x1000
#define ETHERTYPE_NTRAILER 16

#define ETHERMTU ETH_DATA_LEN
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)



/*!BEGIN libc/sysv/consts/ex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EX_H_

/**
 * @fileoverview Eric Allman's exit() codes
 *
 * - Broadly supported style guideline;
 * - Dating back to 1980 in 4.0BSD;
 * - That won't be standardized.
 *
 */

#define EX_CANTCREAT   73
#define EX_CONFIG      78
#define EX_DATAERR     65
#define EX_IOERR       74
#define EX_NOHOST      68
#define EX_NOINPUT     66
#define EX_NOPERM      77
#define EX_NOUSER      67
#define EX_OK          0
#define EX_OSERR       71
#define EX_OSFILE      72
#define EX_PROTOCOL    76
#define EX_SOFTWARE    70
#define EX_TEMPFAIL    75
#define EX_UNAVAILABLE 69
#define EX_USAGE       64
#define EX__BASE       64
#define EX__MAX        78



/*!BEGIN libc/sysv/consts/exit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EXIT_H_

#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0



/*!BEGIN libc/sysv/consts/f.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_F_H_
COSMOPOLITAN_C_START_

/*
 * full set of fcntl() commands
 * many are only provided by a single platform
 * will be equal to -1 when not available on host
 */
extern const int F_BARRIERFSYNC;
extern const int F_DUPFD;
extern const int F_DUPFD_CLOEXEC;
extern const int F_FULLFSYNC;
extern const int F_GETFD;
extern const int F_GETFL;
extern const int F_GETLEASE;
extern const int F_GETLK;
extern const int F_GETNOSIGPIPE;
extern const int F_GETOWN;
extern const int F_GETPATH;
extern const int F_GETPIPE_SZ;
extern const int F_GETSIG;
extern const int F_MAXFD;
extern const int F_NOCACHE;
extern const int F_NOTIFY;
extern const int F_OFD_GETLK;
extern const int F_OFD_SETLK;
extern const int F_OFD_SETLKW;
extern const int F_RDLCK;
extern const int F_SETFD;
extern const int F_SETFL;
extern const int F_SETLEASE;
extern const int F_SETLK;
extern const int F_SETLKW;
extern const int F_SETNOSIGPIPE;
extern const int F_SETOWN;
extern const int F_SETPIPE_SZ;
extern const int F_SETSIG;
extern const int F_UNLCK;
extern const int F_WRLCK;

COSMOPOLITAN_C_END_

/*
 * portable fcntl() commands
 */
#define F_DUPFD         0
#define F_GETFD         1
#define F_SETFD         2
#define F_GETFL         3
#define F_SETFL         4
#define F_DUPFD_CLOEXEC F_DUPFD_CLOEXEC

/*
 * posix advisory locks
 * polyfilled poorly on windows
 */
#define F_SETLK  F_SETLK
#define F_SETLKW F_SETLKW
#define F_GETLK  F_GETLK
#define F_RDLCK  F_RDLCK
#define F_UNLCK  F_UNLCK
#define F_WRLCK  F_WRLCK



/*!BEGIN libc/sysv/consts/falloc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FALLOC_H_
COSMOPOLITAN_C_START_

extern const int FALLOC_FL_KEEP_SIZE;
extern const int FALLOC_FL_PUNCH_HOLE;
extern const int FALLOC_FL_NO_HIDE_STALE;
extern const int FALLOC_FL_COLLAPSE_RANGE;
extern const int FALLOC_FL_ZERO_RANGE;
extern const int FALLOC_FL_INSERT_RANGE;
extern const int FALLOC_FL_UNSHARE_RANGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fan.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FAN_H_

#define FAN_CLASS_NOTIF              0
#define FAN_ACCESS                   1
#define FAN_ACCESS_PERM              0x020000
#define FAN_ALLOW                    1
#define FAN_ALL_CLASS_BITS           12
#define FAN_ALL_EVENTS               59
#define FAN_ALL_INIT_FLAGS           63
#define FAN_ALL_MARK_FLAGS           255
#define FAN_ALL_OUTGOING_EVENTS      0x03403b
#define FAN_ALL_PERM_EVENTS          0x030000
#define FAN_CLASS_CONTENT            4
#define FAN_CLASS_PRE_CONTENT        8
#define FAN_CLOEXEC                  1
#define FAN_CLOSE                    24
#define FAN_CLOSE_NOWRITE            0x10
#define FAN_CLOSE_WRITE              8
#define FAN_DENY                     2
#define FAN_EVENT_METADATA_LEN       24
#define FAN_EVENT_ON_CHILD           0x08000000
#define FAN_MARK_ADD                 1
#define FAN_MARK_DONT_FOLLOW         4
#define FAN_MARK_FLUSH               0x80
#define FAN_MARK_IGNORED_MASK        0x20
#define FAN_MARK_IGNORED_SURV_MODIFY 0x40
#define FAN_MARK_MOUNT               0x10
#define FAN_MARK_ONLYDIR             8
#define FAN_MARK_REMOVE              2
#define FAN_MODIFY                   2
#define FAN_NOFD                     -1
#define FAN_NONBLOCK                 2
#define FAN_ONDIR                    0x40000000
#define FAN_OPEN                     0x20
#define FAN_OPEN_PERM                0x010000
#define FAN_Q_OVERFLOW               0x4000
#define FAN_UNLIMITED_MARKS          0x20
#define FAN_UNLIMITED_QUEUE          0x10



/*!BEGIN libc/sysv/consts/fbio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FB_H_
COSMOPOLITAN_C_START_

extern const uint64_t FBIOGET_VSCREENINFO;
extern const uint64_t FBIOPUT_VSCREENINFO;
extern const uint64_t FBIOGET_FSCREENINFO;
extern const uint64_t FBIOGETCMAP;
extern const uint64_t FBIOPUTCMAP;
extern const uint64_t FBIOPAN_DISPLAY;
extern const uint64_t FBIO_WAITFORVSYNC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FD_H_
COSMOPOLITAN_C_START_

extern const int FD_CLOEXEC;

#define FD_CLOEXEC 1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fileno.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FILENO_H_

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2



/*!BEGIN libc/sysv/consts/fio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FIO_H_
COSMOPOLITAN_C_START_

extern const uint32_t FIONREAD; /* one of the few encouraged ioctls */
extern const uint32_t FIONBIO;  /* use fcntl(fd, F_SETFL, O_NONBLOCK) */
extern const uint32_t FIOCLEX;  /* use fcntl(fd, F_SETFD, FD_CLOEXEC) */
extern const uint32_t FIONCLEX; /* use fcntl(fd, F_SETFD, 0) */
extern const uint32_t FIOASYNC; /* todo: fcntl(fd, F_SETOWN, pid) */

#define FIONREAD FIONREAD

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fs.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FS_H_

#define FS_IOC_GETFLAGS   0x80086601
#define FS_IOC_SETFLAGS   0x40086602
#define FS_IOC_GETVERSION 0x80087601
#define FS_IOC_SETVERSION 0x40087602
#define FS_IOC_FIEMAP     0xc020660b
#define FS_IOC_FSGETXATTR 0x801c581f
#define FS_IOC_FSSETXATTR 0x401c5820
#define FS_IOC_GETFSLABEL 0x81009431
#define FS_IOC_SETFSLABEL 0x41009432

#define FS_FL_USER_VISIBLE    0x0003DFFF /* user visible flags */
#define FS_FL_USER_MODIFIABLE 0x000380FF /* user modifiable flags */
#define FS_SECRM_FL           0x00000001 /* secure deletion */
#define FS_UNRM_FL            0x00000002 /* undelete */
#define FS_COMPR_FL           0x00000004 /* compress */
#define FS_SYNC_FL            0x00000008 /* synchronous */
#define FS_IMMUTABLE_FL       0x00000010
#define FS_APPEND_FL          0x00000020 /* append-only */
#define FS_NODUMP_FL          0x00000040
#define FS_NOATIME_FL         0x00000080
#define FS_DIRTY_FL           0x00000100
#define FS_COMPRBLK_FL        0x00000200
#define FS_NOCOMP_FL          0x00000400
#define FS_ENCRYPT_FL         0x00000800 /* encrypted file */
#define FS_BTREE_FL           0x00001000
#define FS_INDEX_FL           0x00001000 /* hash-indexed directory */
#define FS_IMAGIC_FL          0x00002000
#define FS_JOURNAL_DATA_FL    0x00004000
#define FS_NOTAIL_FL          0x00008000
#define FS_DIRSYNC_FL         0x00010000
#define FS_TOPDIR_FL          0x00020000
#define FS_HUGE_FILE_FL       0x00040000
#define FS_EXTENT_FL          0x00080000



/*!BEGIN libc/sysv/consts/futex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FUTEX_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_

extern const int FUTEX_WAIT;
extern const int FUTEX_WAKE;
extern const int FUTEX_REQUEUE;

#define FUTEX_WAIT         FUTEX_WAIT
#define FUTEX_WAKE         FUTEX_WAKE
#define FUTEX_REQUEUE      FUTEX_REQUEUE
#define FUTEX_PRIVATE_FLAG 128

#define FUTEX_WAIT_PRIVATE    (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAKE_PRIVATE    (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)

#define FUTEX_WAIT_BITSET      9
#define FUTEX_CLOCK_REALTIME   256
#define FUTEX_BITSET_MATCH_ANY 0xffffffff

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/grnd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_GRND_H_

#define GRND_NONBLOCK 1
#define GRND_RANDOM   2



/*!BEGIN libc/sysv/consts/hwcap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_HWCAP_H_
#ifdef __aarch64__

// Feature bits for getauxval(AT_HWCAP) on AARCH64 GNU/SystemD.

#define HWCAP_FP       (1 << 0)
#define HWCAP_ASIMD    (1 << 1)
#define HWCAP_EVTSTRM  (1 << 2)
#define HWCAP_AES      (1 << 3)
#define HWCAP_PMULL    (1 << 4)
#define HWCAP_SHA1     (1 << 5)
#define HWCAP_SHA2     (1 << 6)
#define HWCAP_CRC32    (1 << 7)
#define HWCAP_ATOMICS  (1 << 8)
#define HWCAP_FPHP     (1 << 9)
#define HWCAP_ASIMDHP  (1 << 10)
#define HWCAP_CPUID    (1 << 11)
#define HWCAP_ASIMDRDM (1 << 12)
#define HWCAP_JSCVT    (1 << 13)
#define HWCAP_FCMA     (1 << 14)
#define HWCAP_LRCPC    (1 << 15)
#define HWCAP_DCPOP    (1 << 16)
#define HWCAP_SHA3     (1 << 17)
#define HWCAP_SM3      (1 << 18)
#define HWCAP_SM4      (1 << 19)
#define HWCAP_ASIMDDP  (1 << 20)
#define HWCAP_SHA512   (1 << 21)
#define HWCAP_SVE      (1 << 22)
#define HWCAP_ASIMDFHM (1 << 23)
#define HWCAP_DIT      (1 << 24)
#define HWCAP_USCAT    (1 << 25)
#define HWCAP_ILRCPC   (1 << 26)
#define HWCAP_FLAGM    (1 << 27)
#define HWCAP_SSBS     (1 << 28)
#define HWCAP_SB       (1 << 29)
#define HWCAP_PACA     (1 << 30)
#define HWCAP_PACG     (1UL << 31)

#define HWCAP2_DCPODP     (1 << 0)
#define HWCAP2_SVE2       (1 << 1)
#define HWCAP2_SVEAES     (1 << 2)
#define HWCAP2_SVEPMULL   (1 << 3)
#define HWCAP2_SVEBITPERM (1 << 4)
#define HWCAP2_SVESHA3    (1 << 5)
#define HWCAP2_SVESM4     (1 << 6)
#define HWCAP2_FLAGM2     (1 << 7)
#define HWCAP2_FRINT      (1 << 8)
#define HWCAP2_SVEI8MM    (1 << 9)
#define HWCAP2_SVEF32MM   (1 << 10)
#define HWCAP2_SVEF64MM   (1 << 11)
#define HWCAP2_SVEBF16    (1 << 12)
#define HWCAP2_I8MM       (1 << 13)
#define HWCAP2_BF16       (1 << 14)
#define HWCAP2_DGH        (1 << 15)
#define HWCAP2_RNG        (1 << 16)
#define HWCAP2_BTI        (1 << 17)
#define HWCAP2_MTE        (1 << 18)

#endif /* __aarch64__ */


/*!BEGIN libc/sysv/consts/icmp6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ICMP6_H_

#define ICMP6_DST_UNREACH ICMP6_DST_UNREACH
#define ICMP6_DST_UNREACH_ADDR ICMP6_DST_UNREACH_ADDR
#define ICMP6_DST_UNREACH_ADMIN ICMP6_DST_UNREACH_ADMIN
#define ICMP6_DST_UNREACH_BEYONDSCOPE ICMP6_DST_UNREACH_BEYONDSCOPE
#define ICMP6_DST_UNREACH_NOPORT ICMP6_DST_UNREACH_NOPORT
#define ICMP6_DST_UNREACH_NOROUTE ICMP6_DST_UNREACH_NOROUTE
#define ICMP6_ECHO_REPLY ICMP6_ECHO_REPLY
#define ICMP6_ECHO_REQUEST ICMP6_ECHO_REQUEST
#define ICMP6_FILTER ICMP6_FILTER
#define ICMP6_INFOMSG_MASK ICMP6_INFOMSG_MASK
#define ICMP6_PACKET_TOO_BIG ICMP6_PACKET_TOO_BIG
#define ICMP6_PARAMPROB_HEADER ICMP6_PARAMPROB_HEADER
#define ICMP6_PARAMPROB_NEXTHEADER ICMP6_PARAMPROB_NEXTHEADER
#define ICMP6_PARAMPROB_OPTION ICMP6_PARAMPROB_OPTION
#define ICMP6_PARAM_PROB ICMP6_PARAM_PROB
#define ICMP6_ROUTER_RENUMBERING ICMP6_ROUTER_RENUMBERING
#define ICMP6_RR_FLAGS_FORCEAPPLY ICMP6_RR_FLAGS_FORCEAPPLY
#define ICMP6_RR_FLAGS_PREVDONE ICMP6_RR_FLAGS_PREVDONE
#define ICMP6_RR_FLAGS_REQRESULT ICMP6_RR_FLAGS_REQRESULT
#define ICMP6_RR_FLAGS_SPECSITE ICMP6_RR_FLAGS_SPECSITE
#define ICMP6_RR_FLAGS_TEST ICMP6_RR_FLAGS_TEST
#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO ICMP6_RR_PCOUSE_RAFLAGS_AUTO
#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN \
  ICMP6_RR_RESULT_FLAGS_FORBIDDEN
#define ICMP6_RR_RESULT_FLAGS_OOB ICMP6_RR_RESULT_FLAGS_OOB
#define ICMP6_TIME_EXCEEDED ICMP6_TIME_EXCEEDED
#define ICMP6_TIME_EXCEED_REASSEMBLY ICMP6_TIME_EXCEED_REASSEMBLY
#define ICMP6_TIME_EXCEED_TRANSIT ICMP6_TIME_EXCEED_TRANSIT

COSMOPOLITAN_C_START_

extern const uint8_t ICMP6_DST_UNREACH;
extern const uint8_t ICMP6_DST_UNREACH_ADDR;
extern const uint8_t ICMP6_DST_UNREACH_ADMIN;
extern const uint8_t ICMP6_DST_UNREACH_BEYONDSCOPE;
extern const uint8_t ICMP6_DST_UNREACH_NOPORT;
extern const uint8_t ICMP6_DST_UNREACH_NOROUTE;
extern const uint8_t ICMP6_ECHO_REPLY;
extern const uint8_t ICMP6_ECHO_REQUEST;
extern const uint8_t ICMP6_FILTER;
extern const uint8_t ICMP6_INFOMSG_MASK;
extern const uint8_t ICMP6_PACKET_TOO_BIG;
extern const uint8_t ICMP6_PARAMPROB_HEADER;
extern const uint8_t ICMP6_PARAMPROB_NEXTHEADER;
extern const uint8_t ICMP6_PARAMPROB_OPTION;
extern const uint8_t ICMP6_PARAM_PROB;
extern const uint8_t ICMP6_ROUTER_RENUMBERING;
extern const uint8_t ICMP6_RR_FLAGS_FORCEAPPLY;
extern const uint8_t ICMP6_RR_FLAGS_PREVDONE;
extern const uint8_t ICMP6_RR_FLAGS_REQRESULT;
extern const uint8_t ICMP6_RR_FLAGS_SPECSITE;
extern const uint8_t ICMP6_RR_FLAGS_TEST;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_AUTO;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_ONLINK;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_FORBIDDEN;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_OOB;
extern const uint8_t ICMP6_TIME_EXCEEDED;
extern const uint8_t ICMP6_TIME_EXCEED_REASSEMBLY;
extern const uint8_t ICMP6_TIME_EXCEED_TRANSIT;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/iff.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IFF_H_
COSMOPOLITAN_C_START_

extern const int IFF_UP;
extern const int IFF_ALLMULTI;
extern const int IFF_AUTOMEDIA;
extern const int IFF_BROADCAST;
extern const int IFF_DEBUG;
extern const int IFF_DYNAMIC;
extern const int IFF_LOOPBACK;
extern const int IFF_MASTER;
extern const int IFF_MULTICAST;
extern const int IFF_NOARP;
extern const int IFF_NOTRAILERS;
extern const int IFF_POINTOPOINT;
extern const int IFF_PORTSEL;
extern const int IFF_PROMISC;
extern const int IFF_RUNNING;
extern const int IFF_SLAVE;

COSMOPOLITAN_C_END_

#define IFF_UP          1
#define IFF_BROADCAST   2
#define IFF_DEBUG       4
#define IFF_LOOPBACK    8
#define IFF_ALLMULTI    IFF_ALLMULTI
#define IFF_AUTOMEDIA   IFF_AUTOMEDIA
#define IFF_DYNAMIC     IFF_DYNAMIC
#define IFF_MASTER      IFF_MASTER
#define IFF_MULTICAST   IFF_MULTICAST
#define IFF_NOARP       IFF_NOARP
#define IFF_NOTRAILERS  IFF_NOTRAILERS
#define IFF_POINTOPOINT IFF_POINTOPOINT
#define IFF_PORTSEL     IFF_PORTSEL
#define IFF_PROMISC     IFF_PROMISC
#define IFF_RUNNING     IFF_RUNNING
#define IFF_SLAVE       IFF_SLAVE




/*!BEGIN libc/sysv/consts/in.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IN_H_

#define IN_ACCESS        1
#define IN_ALL_EVENTS    0x0fff
#define IN_ATTRIB        4
#define IN_CLOEXEC       0x080000
#define IN_CLOSE         24
#define IN_CLOSE_NOWRITE 0x10
#define IN_CLOSE_WRITE   8
#define IN_CREATE        0x0100
#define IN_DELETE        0x0200
#define IN_DELETE_SELF   0x0400
#define IN_DONT_FOLLOW   0x02000000
#define IN_EXCL_UNLINK   0x04000000
#define IN_IGNORED       0x8000
#define IN_ISDIR         0x40000000
#define IN_MASK_ADD      0x20000000
#define IN_MODIFY        2
#define IN_MOVE          192
#define IN_MOVED_FROM    0x40
#define IN_MOVED_TO      0x80
#define IN_MOVE_SELF     0x0800
#define IN_NONBLOCK      0x0800
#define IN_ONESHOT       0x80000000
#define IN_ONLYDIR       0x01000000
#define IN_OPEN          0x20
#define IN_Q_OVERFLOW    0x4000
#define IN_UNMOUNT       0x2000
#define IN_CLASSA_NSHIFT 24



/*!BEGIN libc/sysv/consts/inaddr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INADDR_H_

/**
 * @fileoverview Well-known Internet addresses.
 * These need to be hard-coded as little-endian, so htonl() is needed.
 */

#define INADDR_ANY       0x00000000u /* 0.0.0.0 */
#define INADDR_BROADCAST 0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_NONE      0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_LOOPBACK  0x7F000001u /* 127.0.0.1 */
#define INADDR_TESTNET1  0xC0000200u /* 192.0.2.0/24 (RFC5737§3) */
#define INADDR_TESTNET2  0xC6336400u /* 198.51.100.0/24 */
#define INADDR_TESTNET3  0xCB007100u /* 203.0.113.0/24 */

#define INADDR_ALLHOSTS_GROUP  0xE0000001u
#define INADDR_ALLRTRS_GROUP   0xE0000002u
#define INADDR_MAX_LOCAL_GROUP 0xE00000FFu
#define INADDR_UNSPEC_GROUP    0xE0000000u

#define IN_LOOPBACKNET 127

/* clang-format off */
#define IN6ADDR_ANY_INIT      { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
/* clang-format on */



/*!BEGIN libc/sysv/consts/inet6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INET6_H_

#define INET6_ADDRSTRLEN 48



/*!BEGIN libc/sysv/consts/io.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IO_H_
COSMOPOLITAN_C_START_

#define _IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16))
#define _IOC_NONE        0U
#define _IOC_WRITE       1U
#define _IOC_READ        2U

#define _IO(a, b)      _IOC(_IOC_NONE, (a), (b), 0)
#define _IOW(a, b, c)  _IOC(_IOC_WRITE, (a), (b), sizeof(c))
#define _IOR(a, b, c)  _IOC(_IOC_READ, (a), (b), sizeof(c))
#define _IOWR(a, b, c) _IOC(_IOC_READ | _IOC_WRITE, (a), (b), sizeof(c))

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ioprio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOPRIO_H_
#ifdef _COSMO_SOURCE

#define IOPRIO_WHO_PROCESS 1
#define IOPRIO_WHO_PGRP    2
#define IOPRIO_WHO_USER    3

#define IOPRIO_CLASS_SHIFT 13
#define IOPRIO_CLASS_MASK  0x07
#define IOPRIO_PRIO_MASK   ((1UL << IOPRIO_CLASS_SHIFT) - 1)

#define IOPRIO_PRIO_CLASS(ioprio) \
  (((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)
#define IOPRIO_PRIO_DATA(ioprio) ((ioprio)&IOPRIO_PRIO_MASK)
#define IOPRIO_PRIO_VALUE(class, data)                     \
  ((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \
   ((data)&IOPRIO_PRIO_MASK))

#define IOPRIO_CLASS_NONE 0
#define IOPRIO_CLASS_RT   1
#define IOPRIO_CLASS_BE   2
#define IOPRIO_CLASS_IDLE 3

#define IOPRIO_NR_LEVELS 8
#define IOPRIO_BE_NR     IOPRIO_NR_LEVELS

#define IOPRIO_NORM    4
#define IOPRIO_BE_NORM IOPRIO_NORM

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/iov.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOV_H_
COSMOPOLITAN_C_START_

extern const int IOV_MAX;

COSMOPOLITAN_C_END_

#define IOV_MAX IOV_MAX



/*!BEGIN libc/sysv/consts/ip.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IP_H_
COSMOPOLITAN_C_START_

extern const int IP_ADD_MEMBERSHIP;
extern const int IP_ADD_SOURCE_MEMBERSHIP;
extern const int IP_BIND_ADDRESS_NO_PORT;
extern const int IP_BLOCK_SOURCE;
extern const int IP_CHECKSUM;
extern const int IP_DEFAULT_MULTICAST_LOOP;
extern const int IP_DEFAULT_MULTICAST_TTL;
extern const int IP_DROP_MEMBERSHIP;
extern const int IP_DROP_SOURCE_MEMBERSHIP;
extern const int IP_FREEBIND;
extern const int IP_HDRINCL;
extern const int IP_IPSEC_POLICY;
extern const int IP_MAX_MEMBERSHIPS;
extern const int IP_MINTTL;
extern const int IP_MSFILTER;
extern const int IP_MTU;
extern const int IP_MTU_DISCOVER;
extern const int IP_MULTICAST_ALL;
extern const int IP_MULTICAST_IF;
extern const int IP_MULTICAST_LOOP;
extern const int IP_MULTICAST_TTL;
extern const int IP_NODEFRAG;
extern const int IP_OPTIONS;
extern const int IP_ORIGDSTADDR;
extern const int IP_PASSSEC;
extern const int IP_PKTINFO;
extern const int IP_PKTOPTIONS;
extern const int IP_PMTUDISC;
extern const int IP_PMTUDISC_DO;
extern const int IP_PMTUDISC_DONT;
extern const int IP_PMTUDISC_INTERFACE;
extern const int IP_PMTUDISC_OMIT;
extern const int IP_PMTUDISC_PROBE;
extern const int IP_PMTUDISC_WANT;
extern const int IP_RECVDSTADDR;
extern const int IP_RECVERR;
extern const int IP_RECVOPTS;
extern const int IP_RECVORIGDSTADDR;
extern const int IP_RECVRETOPTS;
extern const int IP_RECVTOS;
extern const int IP_RECVTTL;
extern const int IP_RETOPTS;
extern const int IP_ROUTER_ALERT;
extern const int IP_TOS;
extern const int IP_TRANSPARENT;
extern const int IP_TTL;
extern const int IP_UNBLOCK_SOURCE;
extern const int IP_UNICAST_IF;
extern const int IP_XFRM_POLICY;

#define IP_ADD_MEMBERSHIP         IP_ADD_MEMBERSHIP
#define IP_ADD_SOURCE_MEMBERSHIP  IP_ADD_SOURCE_MEMBERSHIP
#define IP_BIND_ADDRESS_NO_PORT   IP_BIND_ADDRESS_NO_PORT
#define IP_BLOCK_SOURCE           IP_BLOCK_SOURCE
#define IP_CHECKSUM               IP_CHECKSUM
#define IP_DEFAULT_MULTICAST_LOOP IP_DEFAULT_MULTICAST_LOOP
#define IP_DEFAULT_MULTICAST_TTL  IP_DEFAULT_MULTICAST_TTL
#define IP_DROP_MEMBERSHIP        IP_DROP_MEMBERSHIP
#define IP_DROP_SOURCE_MEMBERSHIP IP_DROP_SOURCE_MEMBERSHIP
#define IP_FREEBIND               IP_FREEBIND
#define IP_HDRINCL                IP_HDRINCL
#define IP_IPSEC_POLICY           IP_IPSEC_POLICY
#define IP_MAX_MEMBERSHIPS        IP_MAX_MEMBERSHIPS
#define IP_MINTTL                 IP_MINTTL
#define IP_MSFILTER               IP_MSFILTER
#define IP_MTU                    IP_MTU
#define IP_MTU_DISCOVER           IP_MTU_DISCOVER
#define IP_MULTICAST_ALL          IP_MULTICAST_ALL
#define IP_MULTICAST_IF           IP_MULTICAST_IF
#define IP_MULTICAST_LOOP         IP_MULTICAST_LOOP
#define IP_MULTICAST_TTL          IP_MULTICAST_TTL
#define IP_NODEFRAG               IP_NODEFRAG
#define IP_OPTIONS                IP_OPTIONS
#define IP_ORIGDSTADDR            IP_ORIGDSTADDR
#define IP_PASSSEC                IP_PASSSEC
#define IP_PKTINFO                IP_PKTINFO
#define IP_PKTOPTIONS             IP_PKTOPTIONS
#define IP_PMTUDISC               IP_PMTUDISC
#define IP_PMTUDISC_DO            IP_PMTUDISC_DO
#define IP_PMTUDISC_DONT          IP_PMTUDISC_DONT
#define IP_PMTUDISC_INTERFACE     IP_PMTUDISC_INTERFACE
#define IP_PMTUDISC_OMIT          IP_PMTUDISC_OMIT
#define IP_PMTUDISC_PROBE         IP_PMTUDISC_PROBE
#define IP_PMTUDISC_WANT          IP_PMTUDISC_WANT
#define IP_RECVDSTADDR            IP_RECVDSTADDR
#define IP_RECVERR                IP_RECVERR
#define IP_RECVOPTS               IP_RECVOPTS
#define IP_RECVORIGDSTADDR        IP_RECVORIGDSTADDR
#define IP_RECVRETOPTS            IP_RECVRETOPTS
#define IP_RECVTOS                IP_RECVTOS
#define IP_RECVTTL                IP_RECVTTL
#define IP_RETOPTS                IP_RETOPTS
#define IP_ROUTER_ALERT           IP_ROUTER_ALERT
#define IP_TOS                    IP_TOS
#define IP_TRANSPARENT            IP_TRANSPARENT
#define IP_TTL                    IP_TTL
#define IP_UNBLOCK_SOURCE         IP_UNBLOCK_SOURCE
#define IP_UNICAST_IF             IP_UNICAST_IF
#define IP_XFRM_POLICY            IP_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipport.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPORT_H_

/**
 * ARPA network ports.
 */
#define IPPORT_ECHO         7
#define IPPORT_DISCARD      9
#define IPPORT_SYSTAT       11
#define IPPORT_DAYTIME      13
#define IPPORT_NETSTAT      15
#define IPPORT_FTP          21
#define IPPORT_TELNET       23
#define IPPORT_SMTP         25
#define IPPORT_TIMESERVER   37
#define IPPORT_NAMESERVER   42
#define IPPORT_WHOIS        43
#define IPPORT_MTP          57
#define IPPORT_TFTP         69
#define IPPORT_RJE          77
#define IPPORT_FINGER       79
#define IPPORT_TTYLINK      87
#define IPPORT_SUPDUP       95
#define IPPORT_EXECSERVER   512
#define IPPORT_LOGINSERVER  513
#define IPPORT_CMDSERVER    514
#define IPPORT_EFSSERVER    520
#define IPPORT_BIFFUDP      512
#define IPPORT_WHOSERVER    513
#define IPPORT_ROUTESERVER  520
#define IPPORT_RESERVED     1024
#define IPPORT_USERRESERVED IPPORT_USERRESERVED

/**
 * Modern network ports.
 */
#define IPPORT_SSH         22
#define IPPORT_DOMAIN      53
#define IPPORT_HTTP        80
#define IPPORT_POP3        110
#define IPPORT_SFTP        115
#define IPPORT_NTP         123
#define IPPORT_IMAP2       143
#define IPPORT_NETBIOS_NS  137
#define IPPORT_NETBIOS_DGM 138
#define IPPORT_NETBIOS_SSN 139
#define IPPORT_BGP         179
#define IPPORT_IRC         194
#define IPPORT_HTTPS       443
#define IPPORT_PRINTER     515
#define IPPORT_NFS         2049
#define IPPORT_DISTCC      3632
#define IPPORT_SIP         5060
#define IPPORT_POSTGRESQL  5432
#define IPPORT_X11         6000
#define IPPORT_GIT         9418
#define IPPORT_IRCD        6667
#define IPPORT_IMAPS       993
#define IPPORT_POP3S       995

COSMOPOLITAN_C_START_

extern const int IPPORT_USERRESERVED;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipproto.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPROTO_H_

#define IPPROTO_IP     0
#define IPPROTO_ICMP   1
#define IPPROTO_TCP    6
#define IPPROTO_UDP    17
#define IPPROTO_IPV6   41
#define IPPROTO_ICMPV6 58
#define IPPROTO_RAW    255
#define IPPROTO_MAX    263 /* xxx */



/*!BEGIN libc/sysv/consts/ipv6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPV6_H_
COSMOPOLITAN_C_START_

extern const int IPV6_2292DSTOPTS;
extern const int IPV6_2292HOPLIMIT;
extern const int IPV6_2292HOPOPTS;
extern const int IPV6_2292PKTINFO;
extern const int IPV6_2292PKTOPTIONS;
extern const int IPV6_2292RTHDR;
extern const int IPV6_ADDRFORM;
extern const int IPV6_ADD_MEMBERSHIP;
extern const int IPV6_AUTHHDR;
extern const int IPV6_AUTOFLOWLABEL;
extern const int IPV6_CHECKSUM;
extern const int IPV6_DONTFRAG;
extern const int IPV6_DROP_MEMBERSHIP;
extern const int IPV6_DSTOPTS;
extern const int IPV6_HDRINCL;
extern const int IPV6_HOPLIMIT;
extern const int IPV6_HOPOPTS;
extern const int IPV6_IPSEC_POLICY;
extern const int IPV6_JOIN_ANYCAST;
extern const int IPV6_JOIN_GROUP;
extern const int IPV6_LEAVE_ANYCAST;
extern const int IPV6_LEAVE_GROUP;
extern const int IPV6_MINHOPCOUNT;
extern const int IPV6_MTU;
extern const int IPV6_MTU_DISCOVER;
extern const int IPV6_MULTICAST_HOPS;
extern const int IPV6_MULTICAST_IF;
extern const int IPV6_MULTICAST_LOOP;
extern const int IPV6_NEXTHOP;
extern const int IPV6_ORIGDSTADDR;
extern const int IPV6_PATHMTU;
extern const int IPV6_PKTINFO;
extern const int IPV6_PMTUDISC_DO;
extern const int IPV6_PMTUDISC_DONT;
extern const int IPV6_PMTUDISC_INTERFACE;
extern const int IPV6_PMTUDISC_OMIT;
extern const int IPV6_PMTUDISC_PROBE;
extern const int IPV6_PMTUDISC_WANT;
extern const int IPV6_RECVDSTOPTS;
extern const int IPV6_RECVERR;
extern const int IPV6_RECVHOPLIMIT;
extern const int IPV6_RECVHOPOPTS;
extern const int IPV6_RECVORIGDSTADDR;
extern const int IPV6_RECVPATHMTU;
extern const int IPV6_RECVPKTINFO;
extern const int IPV6_RECVRTHDR;
extern const int IPV6_RECVTCLASS;
extern const int IPV6_ROUTER_ALERT;
extern const int IPV6_RTHDR;
extern const int IPV6_RTHDRDSTOPTS;
extern const int IPV6_RTHDR_LOOSE;
extern const int IPV6_RTHDR_STRICT;
extern const int IPV6_RTHDR_TYPE_0;
extern const int IPV6_RXDSTOPTS;
extern const int IPV6_RXHOPOPTS;
extern const int IPV6_TCLASS;
extern const int IPV6_UNICAST_HOPS;
extern const int IPV6_V6ONLY;
extern const int IPV6_XFRM_POLICY;

#define IPV6_2292DSTOPTS        IPV6_2292DSTOPTS
#define IPV6_2292HOPLIMIT       IPV6_2292HOPLIMIT
#define IPV6_2292HOPOPTS        IPV6_2292HOPOPTS
#define IPV6_2292PKTINFO        IPV6_2292PKTINFO
#define IPV6_2292PKTOPTIONS     IPV6_2292PKTOPTIONS
#define IPV6_2292RTHDR          IPV6_2292RTHDR
#define IPV6_ADDRFORM           IPV6_ADDRFORM
#define IPV6_ADD_MEMBERSHIP     IPV6_ADD_MEMBERSHIP
#define IPV6_AUTHHDR            IPV6_AUTHHDR
#define IPV6_AUTOFLOWLABEL      IPV6_AUTOFLOWLABEL
#define IPV6_CHECKSUM           IPV6_CHECKSUM
#define IPV6_DONTFRAG           IPV6_DONTFRAG
#define IPV6_DROP_MEMBERSHIP    IPV6_DROP_MEMBERSHIP
#define IPV6_DSTOPTS            IPV6_DSTOPTS
#define IPV6_HDRINCL            IPV6_HDRINCL
#define IPV6_HOPLIMIT           IPV6_HOPLIMIT
#define IPV6_HOPOPTS            IPV6_HOPOPTS
#define IPV6_IPSEC_POLICY       IPV6_IPSEC_POLICY
#define IPV6_JOIN_ANYCAST       IPV6_JOIN_ANYCAST
#define IPV6_JOIN_GROUP         IPV6_JOIN_GROUP
#define IPV6_LEAVE_ANYCAST      IPV6_LEAVE_ANYCAST
#define IPV6_LEAVE_GROUP        IPV6_LEAVE_GROUP
#define IPV6_MINHOPCOUNT        IPV6_MINHOPCOUNT
#define IPV6_MTU                IPV6_MTU
#define IPV6_MTU_DISCOVER       IPV6_MTU_DISCOVER
#define IPV6_MULTICAST_HOPS     IPV6_MULTICAST_HOPS
#define IPV6_MULTICAST_IF       IPV6_MULTICAST_IF
#define IPV6_MULTICAST_LOOP     IPV6_MULTICAST_LOOP
#define IPV6_NEXTHOP            IPV6_NEXTHOP
#define IPV6_ORIGDSTADDR        IPV6_ORIGDSTADDR
#define IPV6_PATHMTU            IPV6_PATHMTU
#define IPV6_PKTINFO            IPV6_PKTINFO
#define IPV6_PMTUDISC_DO        IPV6_PMTUDISC_DO
#define IPV6_PMTUDISC_DONT      IPV6_PMTUDISC_DONT
#define IPV6_PMTUDISC_INTERFACE IPV6_PMTUDISC_INTERFACE
#define IPV6_PMTUDISC_OMIT      IPV6_PMTUDISC_OMIT
#define IPV6_PMTUDISC_PROBE     IPV6_PMTUDISC_PROBE
#define IPV6_PMTUDISC_WANT      IPV6_PMTUDISC_WANT
#define IPV6_RECVDSTOPTS        IPV6_RECVDSTOPTS
#define IPV6_RECVERR            IPV6_RECVERR
#define IPV6_RECVHOPLIMIT       IPV6_RECVHOPLIMIT
#define IPV6_RECVHOPOPTS        IPV6_RECVHOPOPTS
#define IPV6_RECVORIGDSTADDR    IPV6_RECVORIGDSTADDR
#define IPV6_RECVPATHMTU        IPV6_RECVPATHMTU
#define IPV6_RECVPKTINFO        IPV6_RECVPKTINFO
#define IPV6_RECVRTHDR          IPV6_RECVRTHDR
#define IPV6_RECVTCLASS         IPV6_RECVTCLASS
#define IPV6_ROUTER_ALERT       IPV6_ROUTER_ALERT
#define IPV6_RTHDR              IPV6_RTHDR
#define IPV6_RTHDRDSTOPTS       IPV6_RTHDRDSTOPTS
#define IPV6_RTHDR_LOOSE        IPV6_RTHDR_LOOSE
#define IPV6_RTHDR_STRICT       IPV6_RTHDR_STRICT
#define IPV6_RTHDR_TYPE_0       IPV6_RTHDR_TYPE_0
#define IPV6_RXDSTOPTS          IPV6_RXDSTOPTS
#define IPV6_RXHOPOPTS          IPV6_RXHOPOPTS
#define IPV6_TCLASS             IPV6_TCLASS
#define IPV6_UNICAST_HOPS       IPV6_UNICAST_HOPS
#define IPV6_V6ONLY             IPV6_V6ONLY
#define IPV6_XFRM_POLICY        IPV6_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/itimer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ITIMER_H_

#define ITIMER_REAL    0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF    2



/*!BEGIN libc/sysv/consts/kd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KD_H_
COSMOPOLITAN_C_START_

extern const uint64_t GIO_FONT;
extern const uint64_t PIO_FONT;
extern const uint64_t GIO_FONTX;
extern const uint64_t PIO_FONTX;
extern const uint64_t PIO_FONT8x8;
extern const uint64_t PIO_FONT8x14;
extern const uint64_t PIO_FONT8x16;
extern const uint64_t PIO_VFONT;
extern const uint64_t PIO_FONTRESET;
extern const uint64_t KDFONTOP;

COSMOPOLITAN_C_END_

#define GIO_FONT      GIO_FONT
#define PIO_FONT      PIO_FONT
#define GIO_FONTX     GIO_FONTX
#define PIO_FONTX     PIO_FONTX
#define PIO_FONT8x8   PIO_FONT8x8
#define PIO_FONT8x14  PIO_FONT8x14
#define PIO_FONT8x16  PIO_FONT8x14
#define PIO_VFONT     PIO_VFONT
#define PIO_FONTRESET PIO_FONTRESET
#define KDFONTOP      KDFONTOP

#ifdef _BSD_SOURCE
#define PIO_VFONT_DEFAULT PIO_FONTRESET
#endif



/*!BEGIN libc/sysv/consts/kern.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KERN_H_
COSMOPOLITAN_C_START_

#define KERN_SOH       "\001"
#define KERN_SOH_ASCII '\001'
#define KERN_EMERG     KERN_SOH "0"
#define KERN_ALERT     KERN_SOH "1"
#define KERN_CRIT      KERN_SOH "2"
#define KERN_ERR       KERN_SOH "3"
#define KERN_WARNING   KERN_SOH "4"
#define KERN_NOTICE    KERN_SOH "5"
#define KERN_INFO      KERN_SOH "6"
#define KERN_DEBUG     KERN_SOH "7"
#define KERN_DEFAULT   ""
#define KERN_CONT      KERN_SOH "c"

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/l.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_L_H_

#define L_SET  SEEK_SET
#define L_INCR SEEK_CUR
#define L_XTND SEEK_END



/*!BEGIN libc/sysv/consts/limits.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIMITS_H_
COSMOPOLITAN_C_START_

extern const int NGROUPS_MAX;
extern const int PIPE_BUF;
extern const int SOMAXCONN;
extern const int _ARG_MAX;
extern const int _NAME_MAX;
extern const int _NSIG;
extern const int _PATH_MAX;
extern const int LINK_MAX;
extern const int MAX_CANON;
extern const int MAX_INPUT;

#define NGROUPS_MAX NGROUPS_MAX
#define PIPE_BUF    PIPE_BUF
#define SOMAXCONN   SOMAXCONN
#define _ARG_MAX    _ARG_MAX
#define _NAME_MAX   _NAME_MAX
#define _NSIG       _NSIG
#define _PATH_MAX   _PATH_MAX
#define LINK_MAX    LINK_MAX
#define MAX_CANON   MAX_CANON
#define MAX_INPUT   MAX_INPUT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIO_H_

#define LIO_NOP LIO_NOP
#define LIO_NOWAIT LIO_NOWAIT
#define LIO_READ LIO_READ
#define LIO_WAIT LIO_WAIT
#define LIO_WRITE LIO_WRITE

COSMOPOLITAN_C_START_

extern const int LIO_NOP;
extern const int LIO_NOWAIT;
extern const int LIO_READ;
extern const int LIO_WAIT;
extern const int LIO_WRITE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOCK_H_
COSMOPOLITAN_C_START_

extern const int LOCK_EX;
extern const int LOCK_NB;
extern const int LOCK_SH;
extern const int LOCK_UN;
extern const int LOCK_UNLOCK_CACHE;

COSMOPOLITAN_C_END_

#define LOCK_EX 2
#define LOCK_NB LOCK_NB
#define LOCK_SH LOCK_SH
#define LOCK_UN LOCK_UN




/*!BEGIN libc/sysv/consts/log.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOG_H_

#define LOG_MASK(pri) (1 << (pri))
#define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)

#define LOG_EMERG   0
#define LOG_ALERT   1
#define LOG_CRIT    2
#define LOG_ERR     3
#define LOG_WARNING 4
#define LOG_NOTICE  5
#define LOG_INFO    6
#define LOG_DEBUG   7

#define LOG_KERN     0000
#define LOG_USER     0010
#define LOG_MAIL     0020
#define LOG_DAEMON   0030
#define LOG_AUTH     0040
#define LOG_SYSLOG   0050
#define LOG_LPR      0060
#define LOG_NEWS     0070
#define LOG_UUCP     0100
#define LOG_CRON     0110
#define LOG_AUTHPRIV 0120
#define LOG_FTP      0130

#define LOG_PID    1
#define LOG_CONS   2
#define LOG_ODELAY 4
#define LOG_NDELAY 8
#define LOG_NOWAIT 16
#define LOG_PERROR 32

#define LOG_LOCAL0 128
#define LOG_LOCAL1 136
#define LOG_LOCAL2 144
#define LOG_LOCAL3 152
#define LOG_LOCAL4 160
#define LOG_LOCAL5 168
#define LOG_LOCAL6 176
#define LOG_LOCAL7 184

#define LOG_NFACILITIES 24
#define LOG_FACMASK     0x03f8
#define LOG_FAC(p)      ((LOG_FACMASK & (p)) >> 3)

#define LOG_PRIMASK       7
#define LOG_PRI(p)        (LOG_PRIMASK & (p))
#define LOG_MAKEPRI(f, p) (((f) << 3) | (p))



/*!BEGIN libc/sysv/consts/loglevel.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOGLEVEL_H_
COSMOPOLITAN_C_START_

#define LOGLEVEL_SCHED   -2
#define LOGLEVEL_DEFAULT -1
#define LOGLEVEL_EMERG   0
#define LOGLEVEL_ALERT   1
#define LOGLEVEL_CRIT    2
#define LOGLEVEL_ERR     3
#define LOGLEVEL_WARNING 4
#define LOGLEVEL_NOTICE  5
#define LOGLEVEL_INFO    6
#define LOGLEVEL_DEBUG   7

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/madv.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MADV_H_
COSMOPOLITAN_C_START_

extern const unsigned MADV_DODUMP;
extern const unsigned MADV_DOFORK;
extern const unsigned MADV_DONTDUMP;
extern const unsigned MADV_DONTFORK;
extern const unsigned MADV_DONTNEED;
extern const unsigned MADV_FREE;
extern const unsigned MADV_HUGEPAGE;
extern const unsigned MADV_HWPOISON;
extern const unsigned MADV_MERGEABLE;
extern const unsigned MADV_NOHUGEPAGE;
extern const unsigned MADV_NORMAL;
extern const unsigned MADV_RANDOM;
extern const unsigned MADV_REMOVE;
extern const unsigned MADV_SEQUENTIAL;
extern const unsigned MADV_UNMERGEABLE;
extern const unsigned MADV_WILLNEED;
extern const unsigned MADV_SOFT_OFFLINE;
extern const unsigned MADV_WIPEONFORK;
extern const unsigned MADV_KEEPONFORK;
extern const unsigned MADV_COLD;
extern const unsigned MADV_PAGEOUT;
extern const unsigned MADV_POPULATE_READ;
extern const unsigned MADV_POPULATE_WRITE;
extern const unsigned MADV_DONTNEED_LOCKED;
extern const unsigned MADV_COLLAPSE;

#define MADV_NORMAL     0
#define MADV_RANDOM     1
#define MADV_SEQUENTIAL 2
#define MADV_WILLNEED   3

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/map.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MAP_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int MAP_32BIT;
extern const int MAP_ANON;
extern const int MAP_ANONYMOUS;
extern const int MAP_CONCEAL;
extern const int MAP_DENYWRITE;
extern const int MAP_EXECUTABLE;
extern const int MAP_FILE;
extern const int MAP_FIXED;
extern const int MAP_FIXED_NOREPLACE;
extern const int MAP_HASSEMAPHORE;
extern const int MAP_HUGETLB;
extern const int MAP_INHERIT;
extern const int MAP_JIT;
extern const int MAP_LOCKED;
extern const int MAP_NOCACHE;
extern const int MAP_NOEXTEND;
extern const int MAP_NONBLOCK;
extern const int MAP_NORESERVE;
extern const int MAP_NOSYNC;
extern const int MAP_POPULATE;
extern const int MAP_PRIVATE;
extern const int MAP_SHARED;
extern const int MAP_SHARED_VALIDATE;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define MAP_FILE    0
#define MAP_SHARED  1
#define MAP_PRIVATE 2
#define MAP_STACK   6
#define MAP_TYPE    15
#define MAP_FIXED   16

#define MAP_ANONYMOUS       MAP_ANONYMOUS
#define MAP_CONCEAL         MAP_CONCEAL
#define MAP_EXECUTABLE      MAP_EXECUTABLE
#define MAP_FIXED_NOREPLACE MAP_FIXED_NOREPLACE
#define MAP_HASSEMAPHORE    MAP_HASSEMAPHORE
#define MAP_POPULATE        MAP_POPULATE
#define MAP_NORESERVE       MAP_NORESERVE

#define MAP_ANON   MAP_ANONYMOUS
#define MAP_NOCORE MAP_CONCEAL



/*!BEGIN libc/sysv/consts/mcast.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MCAST_H_

#define MCAST_BLOCK_SOURCE MCAST_BLOCK_SOURCE
#define MCAST_EXCLUDE MCAST_EXCLUDE
#define MCAST_INCLUDE MCAST_INCLUDE
#define MCAST_JOIN_GROUP MCAST_JOIN_GROUP
#define MCAST_JOIN_SOURCE_GROUP MCAST_JOIN_SOURCE_GROUP
#define MCAST_LEAVE_GROUP MCAST_LEAVE_GROUP
#define MCAST_LEAVE_SOURCE_GROUP MCAST_LEAVE_SOURCE_GROUP
#define MCAST_MSFILTER MCAST_MSFILTER
#define MCAST_UNBLOCK_SOURCE MCAST_UNBLOCK_SOURCE

COSMOPOLITAN_C_START_

extern const int MCAST_BLOCK_SOURCE;
extern const int MCAST_EXCLUDE;
extern const int MCAST_INCLUDE;
extern const int MCAST_JOIN_GROUP;
extern const int MCAST_JOIN_SOURCE_GROUP;
extern const int MCAST_LEAVE_GROUP;
extern const int MCAST_LEAVE_SOURCE_GROUP;
extern const int MCAST_MSFILTER;
extern const int MCAST_UNBLOCK_SOURCE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mfd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MFD_H_

#define MFD_CLOEXEC       1
#define MFD_ALLOW_SEALING 2



/*!BEGIN libc/sysv/consts/mlock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MLOCK_H_
COSMOPOLITAN_C_START_

extern const int MCL_CURRENT;
extern const int MCL_FUTURE;
extern const int MCL_ONFAULT;

COSMOPOLITAN_C_END_

#define MCL_CURRENT 1
#define MCL_FUTURE  2
#define MCL_ONFAULT MCL_ONFAULT



/*!BEGIN libc/sysv/consts/modem.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MODEM_H_
COSMOPOLITAN_C_START_

extern const uint64_t TIOCMGET;
extern const uint64_t TIOCMSET;
extern const uint64_t TIOCMBIC;
extern const uint64_t TIOCMBIS;

extern const int TIOCM_CAR;
extern const int TIOCM_CD;
extern const int TIOCM_CTS;
extern const int TIOCM_DSR;
extern const int TIOCM_DTR;
extern const int TIOCM_LE;
extern const int TIOCM_RI;
extern const int TIOCM_RNG;
extern const int TIOCM_RTS;
extern const int TIOCM_SR;
extern const int TIOCM_ST;

#define TIOCM_LE  0x01
#define TIOCM_DTR 0x02
#define TIOCM_RTS 0x04
#define TIOCM_ST  0x08
#define TIOCM_SR  0x10
#define TIOCM_CTS 0x20
#define TIOCM_CAR 0x40
#define TIOCM_CD  0x40
#define TIOCM_RI  0x80
#define TIOCM_RNG 0x80
#define TIOCM_DSR 0x0100

#define TIOCMGET TIOCMGET
#define TIOCMSET TIOCMSET
#define TIOCMBIC TIOCMBIC
#define TIOCMBIS TIOCMBIS


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const unsigned long MS_RDONLY;
extern const int MNT_RDONLY;
extern const unsigned long MS_NOSUID;
extern const int MNT_NOSUID;
extern const unsigned long MS_NODEV;
extern const int MNT_NODEV;
extern const unsigned long MS_NOEXEC;
extern const int MNT_NOEXEC;
extern const unsigned long MS_SYNCHRONOUS;
extern const int MNT_SYNCHRONOUS;
extern const unsigned long MS_REMOUNT;
extern const int MNT_UPDATE;
extern const unsigned long MS_MANDLOCK;
extern const unsigned long MS_DIRSYNC;
extern const unsigned long MS_NOATIME;
extern const int MNT_NOATIME;
extern const unsigned long MS_NODIRATIME;
extern const unsigned long MS_BIND;
extern const unsigned long MS_MOVE;
extern const unsigned long MS_REC;
extern const unsigned long MS_SILENT;
extern const unsigned long MS_POSIXACL;
extern const unsigned long MS_UNBINDABLE;
extern const unsigned long MS_PRIVATE;
extern const unsigned long MS_SLAVE;
extern const unsigned long MS_SHARED;
extern const unsigned long MS_RELATIME;
extern const int MNT_RELATIME;
extern const unsigned long MS_KERNMOUNT;
extern const unsigned long MS_I_VERSION;
extern const unsigned long MS_STRICTATIME;
extern const int MNT_STRICTATIME;
extern const unsigned long MS_LAZYTIME;
extern const unsigned long MS_ACTIVE;
extern const unsigned long MS_NOUSER;
extern const unsigned long MS_RMT_MASK;
extern const unsigned long MS_MGC_VAL;
extern const unsigned long MS_MGC_MSK;
extern const int MNT_ASYNC;
extern const int MNT_RELOAD;
extern const int MNT_SUIDDIR;
extern const int MNT_NOCLUSTERR;
extern const int MNT_NOCLUSTERW;
extern const int MNT_SNAPSHOT;

#define MS_RDONLY       0x00000001
#define MNT_RDONLY      0x00000001
#define MS_NOSUID       MS_NOSUID
#define MNT_NOSUID      MNT_NOSUID
#define MS_NODEV        MS_NODEV
#define MNT_NODEV       MNT_NODEV
#define MS_NOEXEC       MS_NOEXEC
#define MNT_NOEXEC      MNT_NOEXEC
#define MS_SYNCHRONOUS  MS_SYNCHRONOUS
#define MNT_SYNCHRONOUS MNT_SYNCHRONOUS
#define MS_REMOUNT      MS_REMOUNT
#define MNT_UPDATE      MNT_UPDATE
#define MS_MANDLOCK     MS_MANDLOCK
#define MS_DIRSYNC      MS_DIRSYNC
#define MS_NOATIME      MS_NOATIME
#define MNT_NOATIME     MNT_NOATIME
#define MS_NODIRATIME   MS_NODIRATIME
#define MS_BIND         MS_BIND
#define MS_MOVE         MS_MOVE
#define MS_REC          MS_REC
#define MS_SILENT       MS_SILENT
#define MS_POSIXACL     MS_POSIXACL
#define MS_UNBINDABLE   MS_UNBINDABLE
#define MS_PRIVATE      MS_PRIVATE
#define MS_SLAVE        MS_SLAVE
#define MS_SHARED       MS_SHARED
#define MS_RELATIME     MS_RELATIME
#define MNT_RELATIME    MNT_RELATIME
#define MS_KERNMOUNT    MS_KERNMOUNT
#define MS_I_VERSION    MS_I_VERSION
#define MS_STRICTATIME  MS_STRICTATIME
#define MNT_STRICTATIME MNT_STRICTATIME
#define MS_LAZYTIME     MS_LAZYTIME
#define MS_ACTIVE       MS_ACTIVE
#define MS_NOUSER       MS_NOUSER
#define MS_RMT_MASK     MS_RMT_MASK
#define MS_MGC_VAL      MS_MGC_VAL
#define MS_MGC_MSK      MS_MGC_MSK
#define MNT_ASYNC       MNT_ASYNC
#define MNT_RELOAD      MNT_RELOAD
#define MNT_SUIDDIR     MNT_SUIDDIR
#define MNT_NOCLUSTERR  MNT_NOCLUSTERR
#define MNT_NOCLUSTERW  MNT_NOCLUSTERW
#define MNT_SNAPSHOT    MNT_SNAPSHOT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mremap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MREMAP_H_

#define MREMAP_MAYMOVE 1
#define MREMAP_FIXED   2



/*!BEGIN libc/sysv/consts/msg.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSG_H_
COSMOPOLITAN_C_START_

extern const int MSG_BATCH;
extern const int MSG_BCAST;
extern const int MSG_CMSG_CLOEXEC;
extern const int MSG_CONFIRM;
extern const int MSG_CTRUNC;
extern const int MSG_DONTROUTE;
extern const int MSG_DONTWAIT;
extern const int MSG_EOF;
extern const int MSG_EOR;
extern const int MSG_ERRQUEUE;
extern const int MSG_EXCEPT;
extern const int MSG_FASTOPEN;
extern const int MSG_FIN;
extern const int MSG_INFO;
extern const int MSG_MCAST;
extern const int MSG_MORE;
extern const int MSG_NOERROR;
extern const int MSG_NOSIGNAL;
extern const int MSG_NOTIFICATION;
extern const int MSG_OOB;
extern const int MSG_PARITY_ERROR;
extern const int MSG_PEEK;
extern const int MSG_PROXY;
extern const int MSG_RST;
extern const int MSG_STAT;
extern const int MSG_SYN;
extern const int MSG_TRUNC;
extern const int MSG_WAITALL;
extern const int MSG_WAITFORONE;

#define MSG_OOB       1
#define MSG_PEEK      2
#define MSG_DONTROUTE 4
#define MSG_DONTWAIT  MSG_DONTWAIT
#define MSG_FASTOPEN  MSG_FASTOPEN
#define MSG_WAITALL   MSG_WAITALL
#define MSG_TRUNC     MSG_TRUNC
#define MSG_CTRUNC    MSG_CTRUNC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/msync.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSYNC_H_
COSMOPOLITAN_C_START_

extern const int MS_SYNC;
extern const int MS_ASYNC;
extern const int MS_INVALIDATE;

#define MS_SYNC       MS_SYNC
#define MS_ASYNC      MS_ASYNC
#define MS_INVALIDATE MS_INVALIDATE

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/nrlinux.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NRLINUX_H_
#ifdef _COSMO_SOURCE

#ifdef __x86_64__

#define __NR_linux_exit                    0x003c
#define __NR_linux_exit_group              0x00e7
#define __NR_linux_read                    0x0000
#define __NR_linux_write                   0x0001
#define __NR_linux_open                    0x0002
#define __NR_linux_close                   0x0003
#define __NR_linux_stat                    0x0004
#define __NR_linux_fstat                   0x0005
#define __NR_linux_lstat                   0x0006
#define __NR_linux_poll                    0x0007
#define __NR_linux_ppoll                   0x010f
#define __NR_linux_brk                     0x000c
#define __NR_linux_sigreturn               0x000f
#define __NR_linux_lseek                   0x0008
#define __NR_linux_mmap                    0x0009
#define __NR_linux_msync                   0x001a
#define __NR_linux_mprotect                0x000a
#define __NR_linux_munmap                  0x000b
#define __NR_linux_sigaction               0x000d
#define __NR_linux_sigprocmask             0x000e
#define __NR_linux_ioctl                   0x0010
#define __NR_linux_pread                   0x0011
#define __NR_linux_pwrite                  0x0012
#define __NR_linux_readv                   0x0013
#define __NR_linux_writev                  0x0014
#define __NR_linux_access                  0x0015
#define __NR_linux_pipe                    0x0016
#define __NR_linux_select                  0x0017
#define __NR_linux_pselect6                0x010e
#define __NR_linux_sched_yield             0x0018
#define __NR_linux_mremap                  0x0019
#define __NR_linux_mincore                 0x001b
#define __NR_linux_madvise                 0x001c
#define __NR_linux_shmget                  0x001d
#define __NR_linux_shmat                   0x001e
#define __NR_linux_shmctl                  0x001f
#define __NR_linux_dup                     0x0020
#define __NR_linux_dup2                    0x0021
#define __NR_linux_pause                   0x0022
#define __NR_linux_nanosleep               0x0023
#define __NR_linux_getitimer               0x0024
#define __NR_linux_setitimer               0x0026
#define __NR_linux_alarm                   0x0025
#define __NR_linux_getpid                  0x0027
#define __NR_linux_sendfile                0x0028
#define __NR_linux_socket                  0x0029
#define __NR_linux_connect                 0x002a
#define __NR_linux_accept                  0x002b
#define __NR_linux_sendto                  0x002c
#define __NR_linux_recvfrom                0x002d
#define __NR_linux_sendmsg                 0x002e
#define __NR_linux_recvmsg                 0x002f
#define __NR_linux_shutdown                0x0030
#define __NR_linux_bind                    0x0031
#define __NR_linux_listen                  0x0032
#define __NR_linux_getsockname             0x0033
#define __NR_linux_getpeername             0x0034
#define __NR_linux_socketpair              0x0035
#define __NR_linux_setsockopt              0x0036
#define __NR_linux_getsockopt              0x0037
#define __NR_linux_fork                    0x0039
#define __NR_linux_vfork                   0x003a
#define __NR_linux_execve                  0x003b
#define __NR_linux_wait4                   0x003d
#define __NR_linux_kill                    0x003e
#define __NR_linux_clone                   0x0038
#define __NR_linux_tkill                   0x00c8
#define __NR_linux_futex                   0x00ca
#define __NR_linux_set_robust_list         0x0111
#define __NR_linux_get_robust_list         0x0112
#define __NR_linux_uname                   0x003f
#define __NR_linux_semget                  0x0040
#define __NR_linux_semop                   0x0041
#define __NR_linux_semctl                  0x0042
#define __NR_linux_shmdt                   0x0043
#define __NR_linux_msgget                  0x0044
#define __NR_linux_msgsnd                  0x0045
#define __NR_linux_msgrcv                  0x0046
#define __NR_linux_msgctl                  0x0047
#define __NR_linux_fcntl                   0x0048
#define __NR_linux_flock                   0x0049
#define __NR_linux_fsync                   0x004a
#define __NR_linux_fdatasync               0x004b
#define __NR_linux_truncate                0x004c
#define __NR_linux_ftruncate               0x004d
#define __NR_linux_getcwd                  0x004f
#define __NR_linux_chdir                   0x0050
#define __NR_linux_fchdir                  0x0051
#define __NR_linux_rename                  0x0052
#define __NR_linux_mkdir                   0x0053
#define __NR_linux_rmdir                   0x0054
#define __NR_linux_creat                   0x0055
#define __NR_linux_link                    0x0056
#define __NR_linux_unlink                  0x0057
#define __NR_linux_symlink                 0x0058
#define __NR_linux_readlink                0x0059
#define __NR_linux_chmod                   0x005a
#define __NR_linux_fchmod                  0x005b
#define __NR_linux_chown                   0x005c
#define __NR_linux_fchown                  0x005d
#define __NR_linux_lchown                  0x005e
#define __NR_linux_umask                   0x005f
#define __NR_linux_gettimeofday            0x0060
#define __NR_linux_getrlimit               0x0061
#define __NR_linux_getrusage               0x0062
#define __NR_linux_sysinfo                 0x0063
#define __NR_linux_times                   0x0064
#define __NR_linux_ptrace                  0x0065
#define __NR_linux_syslog                  0x0067
#define __NR_linux_getuid                  0x0066
#define __NR_linux_getgid                  0x0068
#define __NR_linux_getppid                 0x006e
#define __NR_linux_getpgrp                 0x006f
#define __NR_linux_setsid                  0x0070
#define __NR_linux_getsid                  0x007c
#define __NR_linux_getpgid                 0x0079
#define __NR_linux_setpgid                 0x006d
#define __NR_linux_geteuid                 0x006b
#define __NR_linux_getegid                 0x006c
#define __NR_linux_getgroups               0x0073
#define __NR_linux_setgroups               0x0074
#define __NR_linux_setreuid                0x0071
#define __NR_linux_setregid                0x0072
#define __NR_linux_setuid                  0x0069
#define __NR_linux_setgid                  0x006a
#define __NR_linux_setresuid               0x0075
#define __NR_linux_setresgid               0x0077
#define __NR_linux_getresuid               0x0076
#define __NR_linux_getresgid               0x0078
#define __NR_linux_sigpending              0x007f
#define __NR_linux_sigsuspend              0x0082
#define __NR_linux_sigaltstack             0x0083
#define __NR_linux_mknod                   0x0085
#define __NR_linux_mknodat                 0x0103
#define __NR_linux_statfs                  0x0089
#define __NR_linux_fstatfs                 0x008a
#define __NR_linux_getpriority             0x008c
#define __NR_linux_setpriority             0x008d
#define __NR_linux_mlock                   0x0095
#define __NR_linux_munlock                 0x0096
#define __NR_linux_mlockall                0x0097
#define __NR_linux_munlockall              0x0098
#define __NR_linux_setrlimit               0x00a0
#define __NR_linux_chroot                  0x00a1
#define __NR_linux_sync                    0x00a2
#define __NR_linux_acct                    0x00a3
#define __NR_linux_settimeofday            0x00a4
#define __NR_linux_mount                   0x00a5
#define __NR_linux_reboot                  0x00a9
#define __NR_linux_quotactl                0x00b3
#define __NR_linux_setfsuid                0x007a
#define __NR_linux_setfsgid                0x007b
#define __NR_linux_capget                  0x007d
#define __NR_linux_capset                  0x007e
#define __NR_linux_sigtimedwait            0x0080
#define __NR_linux_sigqueueinfo            0x0081
#define __NR_linux_personality             0x0087
#define __NR_linux_ustat                   0x0088
#define __NR_linux_sysfs                   0x008b
#define __NR_linux_sched_setparam          0x008e
#define __NR_linux_sched_getparam          0x008f
#define __NR_linux_sched_setscheduler      0x0090
#define __NR_linux_sched_getscheduler      0x0091
#define __NR_linux_sched_get_priority_max  0x0092
#define __NR_linux_sched_get_priority_min  0x0093
#define __NR_linux_sched_rr_get_interval   0x0094
#define __NR_linux_vhangup                 0x0099
#define __NR_linux_modify_ldt              0x009a
#define __NR_linux_pivot_root              0x009b
#define __NR_linux__sysctl                 0x009c
#define __NR_linux_prctl                   0x009d
#define __NR_linux_arch_prctl              0x009e
#define __NR_linux_adjtimex                0x009f
#define __NR_linux_umount2                 0x00a6
#define __NR_linux_swapon                  0x00a7
#define __NR_linux_swapoff                 0x00a8
#define __NR_linux_sethostname             0x00aa
#define __NR_linux_setdomainname           0x00ab
#define __NR_linux_iopl                    0x00ac
#define __NR_linux_ioperm                  0x00ad
#define __NR_linux_init_module             0x00af
#define __NR_linux_delete_module           0x00b0
#define __NR_linux_gettid                  0x00ba
#define __NR_linux_readahead               0x00bb
#define __NR_linux_setxattr                0x00bc
#define __NR_linux_fsetxattr               0x00be
#define __NR_linux_getxattr                0x00bf
#define __NR_linux_fgetxattr               0x00c1
#define __NR_linux_listxattr               0x00c2
#define __NR_linux_flistxattr              0x00c4
#define __NR_linux_removexattr             0x00c5
#define __NR_linux_fremovexattr            0x00c7
#define __NR_linux_lsetxattr               0x00bd
#define __NR_linux_lgetxattr               0x00c0
#define __NR_linux_llistxattr              0x00c3
#define __NR_linux_lremovexattr            0x00c6
#define __NR_linux_sched_setaffinity       0x00cb
#define __NR_linux_sched_getaffinity       0x00cc
#define __NR_linux_io_setup                0x00ce
#define __NR_linux_io_destroy              0x00cf
#define __NR_linux_io_getevents            0x00d0
#define __NR_linux_io_submit               0x00d1
#define __NR_linux_io_cancel               0x00d2
#define __NR_linux_lookup_dcookie          0x00d4
#define __NR_linux_epoll_create            0x00d5
#define __NR_linux_epoll_wait              0x00e8
#define __NR_linux_epoll_ctl               0x00e9
#define __NR_linux_getdents                0x00d9
#define __NR_linux_oldgetdents             0x004e
#define __NR_linux_set_tid_address         0x00da
#define __NR_linux_restart_syscall         0x00db
#define __NR_linux_semtimedop              0x00dc
#define __NR_linux_fadvise                 0x00dd
#define __NR_linux_timer_create            0x00de
#define __NR_linux_timer_settime           0x00df
#define __NR_linux_timer_gettime           0x00e0
#define __NR_linux_timer_getoverrun        0x00e1
#define __NR_linux_timer_delete            0x00e2
#define __NR_linux_clock_settime           0x00e3
#define __NR_linux_clock_gettime           0x00e4
#define __NR_linux_clock_getres            0x00e5
#define __NR_linux_clock_nanosleep         0x00e6
#define __NR_linux_tgkill                  0x00ea
#define __NR_linux_mbind                   0x00ed
#define __NR_linux_set_mempolicy           0x00ee
#define __NR_linux_get_mempolicy           0x00ef
#define __NR_linux_mq_open                 0x00f0
#define __NR_linux_mq_unlink               0x00f1
#define __NR_linux_mq_timedsend            0x00f2
#define __NR_linux_mq_timedreceive         0x00f3
#define __NR_linux_mq_notify               0x00f4
#define __NR_linux_mq_getsetattr           0x00f5
#define __NR_linux_kexec_load              0x00f6
#define __NR_linux_waitid                  0x00f7
#define __NR_linux_add_key                 0x00f8
#define __NR_linux_request_key             0x00f9
#define __NR_linux_keyctl                  0x00fa
#define __NR_linux_ioprio_set              0x00fb
#define __NR_linux_ioprio_get              0x00fc
#define __NR_linux_inotify_init            0x00fd
#define __NR_linux_inotify_add_watch       0x00fe
#define __NR_linux_inotify_rm_watch        0x00ff
#define __NR_linux_openat                  0x0101
#define __NR_linux_mkdirat                 0x0102
#define __NR_linux_fchownat                0x0104
#define __NR_linux_utime                   0x0084
#define __NR_linux_utimes                  0x00eb
#define __NR_linux_futimesat               0x0105
#define __NR_linux_fstatat                 0x0106
#define __NR_linux_unlinkat                0x0107
#define __NR_linux_renameat                0x0108
#define __NR_linux_linkat                  0x0109
#define __NR_linux_symlinkat               0x010a
#define __NR_linux_readlinkat              0x010b
#define __NR_linux_fchmodat                0x010c
#define __NR_linux_faccessat               0x010d
#define __NR_linux_unshare                 0x0110
#define __NR_linux_splice                  0x0113
#define __NR_linux_tee                     0x0114
#define __NR_linux_sync_file_range         0x0115
#define __NR_linux_vmsplice                0x0116
#define __NR_linux_migrate_pages           0x0100
#define __NR_linux_move_pages              0x0117
#define __NR_linux_preadv                  0x0127
#define __NR_linux_pwritev                 0x0128
#define __NR_linux_utimensat               0x0118
#define __NR_linux_fallocate               0x011d
#define __NR_linux_accept4                 0x0120
#define __NR_linux_dup3                    0x0124
#define __NR_linux_pipe2                   0x0125
#define __NR_linux_epoll_pwait             0x0119
#define __NR_linux_epoll_create1           0x0123
#define __NR_linux_perf_event_open         0x012a
#define __NR_linux_inotify_init1           0x0126
#define __NR_linux_tgsigqueueinfo          0x0129
#define __NR_linux_signalfd                0x011a
#define __NR_linux_signalfd4               0x0121
#define __NR_linux_eventfd                 0x011c
#define __NR_linux_eventfd2                0x0122
#define __NR_linux_timerfd_create          0x011b
#define __NR_linux_timerfd_settime         0x011e
#define __NR_linux_timerfd_gettime         0x011f
#define __NR_linux_recvmmsg                0x012b
#define __NR_linux_fanotify_init           0x012c
#define __NR_linux_fanotify_mark           0x012d
#define __NR_linux_prlimit                 0x012e
#define __NR_linux_name_to_handle_at       0x012f
#define __NR_linux_open_by_handle_at       0x0130
#define __NR_linux_clock_adjtime           0x0131
#define __NR_linux_syncfs                  0x0132
#define __NR_linux_sendmmsg                0x0133
#define __NR_linux_setns                   0x0134
#define __NR_linux_getcpu                  0x0135
#define __NR_linux_process_vm_readv        0x0136
#define __NR_linux_process_vm_writev       0x0137
#define __NR_linux_kcmp                    0x0138
#define __NR_linux_finit_module            0x0139
#define __NR_linux_sched_setattr           0x013a
#define __NR_linux_sched_getattr           0x013b
#define __NR_linux_renameat2               0x013c
#define __NR_linux_seccomp                 0x013d
#define __NR_linux_getrandom               0x013e
#define __NR_linux_memfd_create            0x013f
#define __NR_linux_kexec_file_load         0x0140
#define __NR_linux_bpf                     0x0141
#define __NR_linux_execveat                0x0142
#define __NR_linux_userfaultfd             0x0143
#define __NR_linux_membarrier              0x0144
#define __NR_linux_mlock2                  0x0145
#define __NR_linux_copy_file_range         0x0146
#define __NR_linux_preadv2                 0x0147
#define __NR_linux_pwritev2                0x0148
#define __NR_linux_pkey_mprotect           0x0149
#define __NR_linux_pkey_alloc              0x014a
#define __NR_linux_pkey_free               0x014b
#define __NR_linux_statx                   0x014c
#define __NR_linux_io_pgetevents           0x014d
#define __NR_linux_rseq                    0x014e
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_quotactl_fd             0x01bb
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be
#define __NR_linux_memfd_secret            0x01bf
#define __NR_linux_process_mrelease        0x01c0
#define __NR_linux_futex_waitv             0x01c1
#define __NR_linux_set_mempolicy_home_node 0x01c2

#elif defined(__aarch64__)

#define __NR_linux_exit                    0x005d
#define __NR_linux_exit_group              0x005e
#define __NR_linux_read                    0x003f
#define __NR_linux_write                   0x0040
#define __NR_linux_open                    0x00b4
#define __NR_linux_close                   0x0039
#define __NR_linux_stat                    0x004f
#define __NR_linux_fstat                   0x0050
#define __NR_linux_ppoll                   0x0049
#define __NR_linux_brk                     0x00d6
#define __NR_linux_sigreturn               0x008b
#define __NR_linux_lseek                   0x003e
#define __NR_linux_mmap                    0x00de
#define __NR_linux_msync                   0x00e3
#define __NR_linux_mprotect                0x00e2
#define __NR_linux_munmap                  0x00d7
#define __NR_linux_sigaction               0x0086
#define __NR_linux_sigprocmask             0x0087
#define __NR_linux_ioctl                   0x001d
#define __NR_linux_pread                   0x0043
#define __NR_linux_pwrite                  0x0044
#define __NR_linux_readv                   0x0041
#define __NR_linux_writev                  0x0042
#define __NR_linux_pselect6                0x0048
#define __NR_linux_sched_yield             0x007c
#define __NR_linux_mremap                  0x00d8
#define __NR_linux_mincore                 0x00e8
#define __NR_linux_madvise                 0x00e9
#define __NR_linux_shmget                  0x00c2
#define __NR_linux_shmat                   0x00c4
#define __NR_linux_shmctl                  0x00c3
#define __NR_linux_dup                     0x0017
#define __NR_linux_nanosleep               0x0065
#define __NR_linux_getitimer               0x0066
#define __NR_linux_setitimer               0x0067
#define __NR_linux_getpid                  0x00ac
#define __NR_linux_sendfile                0x0047
#define __NR_linux_socket                  0x00c6
#define __NR_linux_connect                 0x00cb
#define __NR_linux_accept                  0x00ca
#define __NR_linux_sendto                  0x00ce
#define __NR_linux_recvfrom                0x00cf
#define __NR_linux_sendmsg                 0x00d3
#define __NR_linux_recvmsg                 0x00d4
#define __NR_linux_shutdown                0x00d2
#define __NR_linux_bind                    0x00c8
#define __NR_linux_listen                  0x00c9
#define __NR_linux_getsockname             0x00cc
#define __NR_linux_getpeername             0x00cd
#define __NR_linux_socketpair              0x00c7
#define __NR_linux_setsockopt              0x00d0
#define __NR_linux_getsockopt              0x00d1
#define __NR_linux_execve                  0x00dd
#define __NR_linux_wait4                   0x0104
#define __NR_linux_kill                    0x0081
#define __NR_linux_clone                   0x00dc
#define __NR_linux_tkill                   0x0082
#define __NR_linux_futex                   0x0062
#define __NR_linux_set_robust_list         0x0063
#define __NR_linux_get_robust_list         0x0064
#define __NR_linux_uname                   0x00a0
#define __NR_linux_semget                  0x00be
#define __NR_linux_semop                   0x00c1
#define __NR_linux_semctl                  0x00bf
#define __NR_linux_shmdt                   0x00c5
#define __NR_linux_msgget                  0x00ba
#define __NR_linux_msgsnd                  0x00bd
#define __NR_linux_msgrcv                  0x00bc
#define __NR_linux_msgctl                  0x00bb
#define __NR_linux_fcntl                   0x0019
#define __NR_linux_flock                   0x0020
#define __NR_linux_fsync                   0x0052
#define __NR_linux_fdatasync               0x0053
#define __NR_linux_truncate                0x002d
#define __NR_linux_ftruncate               0x002e
#define __NR_linux_getcwd                  0x0011
#define __NR_linux_chdir                   0x0031
#define __NR_linux_fchdir                  0x0032
#define __NR_linux_unlink                  0x00b5
#define __NR_linux_fchmod                  0x0034
#define __NR_linux_fchown                  0x0037
#define __NR_linux_umask                   0x00a6
#define __NR_linux_gettimeofday            0x00a9
#define __NR_linux_getrlimit               0x00a3
#define __NR_linux_getrusage               0x00a5
#define __NR_linux_sysinfo                 0x00b3
#define __NR_linux_times                   0x0099
#define __NR_linux_ptrace                  0x0075
#define __NR_linux_syslog                  0x0074
#define __NR_linux_getuid                  0x00ae
#define __NR_linux_getgid                  0x00b0
#define __NR_linux_getppid                 0x00ad
#define __NR_linux_setsid                  0x009d
#define __NR_linux_getsid                  0x009c
#define __NR_linux_getpgid                 0x009b
#define __NR_linux_setpgid                 0x009a
#define __NR_linux_geteuid                 0x00af
#define __NR_linux_getegid                 0x00b1
#define __NR_linux_getgroups               0x009e
#define __NR_linux_setgroups               0x009f
#define __NR_linux_setreuid                0x0091
#define __NR_linux_setregid                0x008f
#define __NR_linux_setuid                  0x0092
#define __NR_linux_setgid                  0x0090
#define __NR_linux_setresuid               0x0093
#define __NR_linux_setresgid               0x0095
#define __NR_linux_getresuid               0x0094
#define __NR_linux_getresgid               0x0096
#define __NR_linux_sigpending              0x0088
#define __NR_linux_sigsuspend              0x0085
#define __NR_linux_sigaltstack             0x0084
#define __NR_linux_mknodat                 0x0021
#define __NR_linux_statfs                  0x002b
#define __NR_linux_fstatfs                 0x002c
#define __NR_linux_getpriority             0x008d
#define __NR_linux_setpriority             0x008c
#define __NR_linux_mlock                   0x00e4
#define __NR_linux_munlock                 0x00e5
#define __NR_linux_mlockall                0x00e6
#define __NR_linux_munlockall              0x00e7
#define __NR_linux_setrlimit               0x00a4
#define __NR_linux_chroot                  0x0033
#define __NR_linux_sync                    0x0051
#define __NR_linux_acct                    0x0059
#define __NR_linux_settimeofday            0x00aa
#define __NR_linux_mount                   0x0028
#define __NR_linux_reboot                  0x008e
#define __NR_linux_quotactl                0x003c
#define __NR_linux_setfsuid                0x0097
#define __NR_linux_setfsgid                0x0098
#define __NR_linux_capget                  0x005a
#define __NR_linux_capset                  0x005b
#define __NR_linux_sigtimedwait            0x0089
#define __NR_linux_sigqueueinfo            0x008a
#define __NR_linux_personality             0x005c
#define __NR_linux_sched_setparam          0x0076
#define __NR_linux_sched_getparam          0x0079
#define __NR_linux_sched_setscheduler      0x0077
#define __NR_linux_sched_getscheduler      0x0078
#define __NR_linux_sched_get_priority_max  0x007d
#define __NR_linux_sched_get_priority_min  0x007e
#define __NR_linux_sched_rr_get_interval   0x007f
#define __NR_linux_vhangup                 0x003a
#define __NR_linux_pivot_root              0x0029
#define __NR_linux_prctl                   0x00a7
#define __NR_linux_adjtimex                0x00ab
#define __NR_linux_umount2                 0x0027
#define __NR_linux_swapon                  0x00e0
#define __NR_linux_swapoff                 0x00e1
#define __NR_linux_sethostname             0x00a1
#define __NR_linux_setdomainname           0x00a2
#define __NR_linux_init_module             0x0069
#define __NR_linux_delete_module           0x006a
#define __NR_linux_gettid                  0x00b2
#define __NR_linux_readahead               0x00d5
#define __NR_linux_setxattr                0x0005
#define __NR_linux_fsetxattr               0x0007
#define __NR_linux_getxattr                0x0008
#define __NR_linux_fgetxattr               0x000a
#define __NR_linux_listxattr               0x000b
#define __NR_linux_flistxattr              0x000d
#define __NR_linux_removexattr             0x000e
#define __NR_linux_fremovexattr            0x0010
#define __NR_linux_lsetxattr               0x0006
#define __NR_linux_lgetxattr               0x0009
#define __NR_linux_llistxattr              0x000c
#define __NR_linux_lremovexattr            0x000f
#define __NR_linux_sched_setaffinity       0x007a
#define __NR_linux_sched_getaffinity       0x007b
#define __NR_linux_io_setup                0x0000
#define __NR_linux_io_destroy              0x0001
#define __NR_linux_io_getevents            0x0004
#define __NR_linux_io_submit               0x0002
#define __NR_linux_io_cancel               0x0003
#define __NR_linux_lookup_dcookie          0x0012
#define __NR_linux_epoll_ctl               0x0015
#define __NR_linux_getdents                0x003d
#define __NR_linux_set_tid_address         0x0060
#define __NR_linux_restart_syscall         0x0080
#define __NR_linux_semtimedop              0x00c0
#define __NR_linux_fadvise                 0x00df
#define __NR_linux_timer_create            0x006b
#define __NR_linux_timer_settime           0x006e
#define __NR_linux_timer_gettime           0x006c
#define __NR_linux_timer_getoverrun        0x006d
#define __NR_linux_timer_delete            0x006f
#define __NR_linux_clock_settime           0x0070
#define __NR_linux_clock_gettime           0x0071
#define __NR_linux_clock_getres            0x0072
#define __NR_linux_clock_nanosleep         0x0073
#define __NR_linux_tgkill                  0x0083
#define __NR_linux_mbind                   0x00eb
#define __NR_linux_set_mempolicy           0x00ed
#define __NR_linux_get_mempolicy           0x00ec
#define __NR_linux_mq_open                 0x00b4
#define __NR_linux_mq_unlink               0x00b5
#define __NR_linux_mq_timedsend            0x00b6
#define __NR_linux_mq_timedreceive         0x00b7
#define __NR_linux_mq_notify               0x00b8
#define __NR_linux_mq_getsetattr           0x00b9
#define __NR_linux_kexec_load              0x0068
#define __NR_linux_waitid                  0x005f
#define __NR_linux_add_key                 0x00d9
#define __NR_linux_request_key             0x00da
#define __NR_linux_keyctl                  0x00db
#define __NR_linux_ioprio_set              0x001e
#define __NR_linux_ioprio_get              0x001f
#define __NR_linux_openat                  0x0038
#define __NR_linux_mkdirat                 0x0022
#define __NR_linux_fchownat                0x0036
#define __NR_linux_utime                   0x0062
#define __NR_linux_utimes                  0x0058
#define __NR_linux_fstatat                 0x004f
#define __NR_linux_unlinkat                0x0023
#define __NR_linux_renameat                0x0026
#define __NR_linux_linkat                  0x0025
#define __NR_linux_symlinkat               0x0024
#define __NR_linux_readlinkat              0x004e
#define __NR_linux_fchmodat                0x0035
#define __NR_linux_faccessat               0x0030
#define __NR_linux_unshare                 0x0061
#define __NR_linux_splice                  0x004c
#define __NR_linux_tee                     0x004d
#define __NR_linux_sync_file_range         0x0054
#define __NR_linux_vmsplice                0x004b
#define __NR_linux_migrate_pages           0x00ee
#define __NR_linux_move_pages              0x00ef
#define __NR_linux_preadv                  0x0045
#define __NR_linux_pwritev                 0x0046
#define __NR_linux_utimensat               0x0058
#define __NR_linux_fallocate               0x002f
#define __NR_linux_accept4                 0x00f2
#define __NR_linux_dup3                    0x0018
#define __NR_linux_pipe2                   0x003b
#define __NR_linux_epoll_pwait             0x0016
#define __NR_linux_epoll_create1           0x0014
#define __NR_linux_perf_event_open         0x00f1
#define __NR_linux_inotify_init1           0x001a
#define __NR_linux_tgsigqueueinfo          0x00f0
#define __NR_linux_signalfd4               0x004a
#define __NR_linux_eventfd2                0x0013
#define __NR_linux_timerfd_create          0x0055
#define __NR_linux_timerfd_settime         0x0056
#define __NR_linux_timerfd_gettime         0x0057
#define __NR_linux_recvmmsg                0x00f3
#define __NR_linux_fanotify_init           0x0106
#define __NR_linux_fanotify_mark           0x0107
#define __NR_linux_prlimit                 0x0105
#define __NR_linux_name_to_handle_at       0x0108
#define __NR_linux_open_by_handle_at       0x0109
#define __NR_linux_clock_adjtime           0x010a
#define __NR_linux_syncfs                  0x010b
#define __NR_linux_sendmmsg                0x010d
#define __NR_linux_setns                   0x010c
#define __NR_linux_getcpu                  0x00a8
#define __NR_linux_process_vm_readv        0x010e
#define __NR_linux_process_vm_writev       0x010f
#define __NR_linux_kcmp                    0x0110
#define __NR_linux_finit_module            0x0111
#define __NR_linux_sched_setattr           0x0112
#define __NR_linux_sched_getattr           0x0113
#define __NR_linux_renameat2               0x0114
#define __NR_linux_seccomp                 0x0115
#define __NR_linux_getrandom               0x0116
#define __NR_linux_memfd_create            0x0117
#define __NR_linux_bpf                     0x0118
#define __NR_linux_execveat                0x0119
#define __NR_linux_userfaultfd             0x011a
#define __NR_linux_membarrier              0x011b
#define __NR_linux_mlock2                  0x011c
#define __NR_linux_copy_file_range         0x011d
#define __NR_linux_preadv2                 0x011e
#define __NR_linux_pwritev2                0x011f
#define __NR_linux_pkey_mprotect           0x0120
#define __NR_linux_pkey_alloc              0x0121
#define __NR_linux_pkey_free               0x0122
#define __NR_linux_statx                   0x0123
#define __NR_linux_io_pgetevents           0x0124
#define __NR_linux_rseq                    0x0125
#define __NR_linux_kexec_file_load         0x0126
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be

#endif /* __x86_64__ */

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/ok.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_OK_H_

#define F_OK 0
#define X_OK X_OK
#define W_OK W_OK
#define R_OK R_OK

COSMOPOLITAN_C_START_

extern const int X_OK;
extern const int W_OK;
extern const unsigned R_OK; /* warning: is sign bit on windows */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/personality.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PERSONALITY_H_

#define ADDR_COMPAT_LAYOUT 0x0200000
#define READ_IMPLIES_EXEC  0x0400000
#define ADDR_LIMIT_3GB     0x8000000
#define FDPIC_FUNCPTRS     0x0080000
#define STICKY_TIMEOUTS    0x4000000
#define MMAP_PAGE_ZERO     0x0100000
#define ADDR_LIMIT_32BIT   0x0800000
#define WHOLE_SECONDS      0x2000000
#define ADDR_NO_RANDOMIZE  0x0040000
#define SHORT_INODE        0x1000000
#define UNAME26            0x0020000



/*!BEGIN libc/sysv/consts/pf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PF_H_
COSMOPOLITAN_C_START_

extern const int PF_ALG;
extern const int PF_APPLETALK;
extern const int PF_ASH;
extern const int PF_ATMPVC;
extern const int PF_ATMSVC;
extern const int PF_AX25;
extern const int PF_BLUETOOTH;
extern const int PF_BRIDGE;
extern const int PF_CAIF;
extern const int PF_CAN;
extern const int PF_ECONET;
extern const int PF_FILE;
extern const int PF_IB;
extern const int PF_IEEE802154;
extern const int PF_INET6;
extern const int PF_INET;
extern const int PF_IPX;
extern const int PF_IRDA;
extern const int PF_ISDN;
extern const int PF_IUCV;
extern const int PF_KCM;
extern const int PF_KEY;
extern const int PF_LLC;
extern const int PF_LOCAL;
extern const int PF_MAX;
extern const int PF_MPLS;
extern const int PF_NETBEUI;
extern const int PF_NETLINK;
extern const int PF_NETROM;
extern const int PF_NFC;
extern const int PF_PACKET;
extern const int PF_PHONET;
extern const int PF_PPPOX;
extern const int PF_RDS;
extern const int PF_ROSE;
extern const int PF_ROUTE;
extern const int PF_RXRPC;
extern const int PF_SECURITY;
extern const int PF_SNA;
extern const int PF_TIPC;
extern const int PF_UNIX;
extern const int PF_UNSPEC;
extern const int PF_VSOCK;
extern const int PF_WANPIPE;
extern const int PF_X25;

#define PF_ALG        PF_ALG
#define PF_APPLETALK  PF_APPLETALK
#define PF_ASH        PF_ASH
#define PF_ATMPVC     PF_ATMPVC
#define PF_ATMSVC     PF_ATMSVC
#define PF_AX25       PF_AX25
#define PF_BLUETOOTH  PF_BLUETOOTH
#define PF_BRIDGE     PF_BRIDGE
#define PF_CAIF       PF_CAIF
#define PF_CAN        PF_CAN
#define PF_ECONET     PF_ECONET
#define PF_FILE       PF_FILE
#define PF_IB         PF_IB
#define PF_IEEE802154 PF_IEEE802154
#define PF_INET       PF_INET
#define PF_INET6      PF_INET6
#define PF_IPX        PF_IPX
#define PF_IRDA       PF_IRDA
#define PF_ISDN       PF_ISDN
#define PF_IUCV       PF_IUCV
#define PF_KCM        PF_KCM
#define PF_KEY        PF_KEY
#define PF_LLC        PF_LLC
#define PF_LOCAL      PF_LOCAL
#define PF_MAX        PF_MAX
#define PF_MPLS       PF_MPLS
#define PF_NETBEUI    PF_NETBEUI
#define PF_NETLINK    PF_NETLINK
#define PF_NETROM     PF_NETROM
#define PF_NFC        PF_NFC
#define PF_PACKET     PF_PACKET
#define PF_PHONET     PF_PHONET
#define PF_PPPOX      PF_PPPOX
#define PF_RDS        PF_RDS
#define PF_ROSE       PF_ROSE
#define PF_ROUTE      PF_ROUTE
#define PF_RXRPC      PF_RXRPC
#define PF_SECURITY   PF_SECURITY
#define PF_SNA        PF_SNA
#define PF_TIPC       PF_TIPC
#define PF_UNIX       PF_UNIX
#define PF_UNSPEC     PF_UNSPEC
#define PF_VSOCK      PF_VSOCK
#define PF_WANPIPE    PF_WANPIPE
#define PF_X25        PF_X25


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/poll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POLL_H_
COSMOPOLITAN_C_START_

extern const int16_t POLLERR;
extern const int16_t POLLHUP;
extern const int16_t POLLIN;
extern const int16_t POLLNVAL;
extern const int16_t POLLOUT;
extern const int16_t POLLPRI;
extern const int16_t POLLRDBAND;
extern const int16_t POLLRDHUP;
extern const int16_t POLLRDNORM;
extern const int16_t POLLWRBAND;
extern const int16_t POLLWRNORM;

#define INFTIM     (-1)
#define POLLERR    POLLERR
#define POLLHUP    POLLHUP
#define POLLIN     POLLIN
#define POLLNVAL   POLLNVAL
#define POLLOUT    POLLOUT
#define POLLPRI    POLLPRI
#define POLLRDBAND POLLRDBAND
#define POLLRDHUP  POLLRDHUP
#define POLLRDNORM POLLRDNORM
#define POLLWRBAND POLLWRBAND
#define POLLWRNORM POLLWRNORM


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_
COSMOPOLITAN_C_START_

extern const int POSIX_FADV_DONTNEED;
extern const int POSIX_FADV_NOREUSE;
extern const int POSIX_MADV_DONTNEED;
extern const int POSIX_MADV_DONTNEED;

#define POSIX_FADV_NORMAL     0
#define POSIX_FADV_RANDOM     1
#define POSIX_FADV_SEQUENTIAL 2
#define POSIX_FADV_WILLNEED   3

#define POSIX_FADV_DONTNEED POSIX_FADV_DONTNEED
#define POSIX_FADV_NOREUSE  POSIX_FADV_NOREUSE

#define POSIX_MADV_NORMAL     0
#define POSIX_MADV_RANDOM     1
#define POSIX_MADV_SEQUENTIAL 2
#define POSIX_MADV_WILLNEED   3

#define POSIX_MADV_DONTNEED POSIX_MADV_DONTNEED


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/pr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PR_H_

#define PR_GET_SECCOMP        21
#define PR_SET_SECCOMP        22
#define SECCOMP_MODE_DISABLED 0
#define SECCOMP_MODE_STRICT   1
#define SECCOMP_MODE_FILTER   2

#define PR_CAPBSET_READ 23
#define PR_CAPBSET_DROP 24

#define PR_SET_NO_NEW_PRIVS 38
#define PR_GET_NO_NEW_PRIVS 39

#define PR_SET_NAME 15
#define PR_GET_NAME 16

#define PR_GET_TSC     25
#define PR_SET_TSC     26
#define PR_TSC_ENABLE  1
#define PR_TSC_SIGSEGV 2

#define PR_GET_FPEXC        11
#define PR_SET_FPEXC        12
#define PR_FP_EXC_SW_ENABLE 0x80
#define PR_FP_EXC_DIV       0x010000
#define PR_FP_EXC_OVF       0x020000
#define PR_FP_EXC_UND       0x040000
#define PR_FP_EXC_RES       0x080000
#define PR_FP_EXC_INV       0x100000
#define PR_FP_EXC_DISABLED  0
#define PR_FP_EXC_NONRECOV  1
#define PR_FP_EXC_ASYNC     2
#define PR_FP_EXC_PRECISE   3

#define PR_MCE_KILL_CLEAR           0
#define PR_MCE_KILL_LATE            0
#define PR_SPEC_NOT_AFFECTED        0
#define PR_SPEC_STORE_BYPASS        0
#define PR_CAP_AMBIENT_IS_SET       1
#define PR_FPEMU_NOPRINT            1
#define PR_MCE_KILL_EARLY           1
#define PR_MCE_KILL_SET             1
#define PR_SET_MM_START_CODE        1
#define PR_SET_PDEATHSIG            1
#define PR_SPEC_PRCTL               1
#define PR_CAP_AMBIENT_RAISE        2
#define PR_FPEMU_SIGFPE             2
#define PR_GET_PDEATHSIG            2
#define PR_MCE_KILL_DEFAULT         2
#define PR_SET_MM_END_CODE          2
#define PR_SPEC_ENABLE              2
#define PR_CAP_AMBIENT_LOWER        3
#define PR_GET_DUMPABLE             3
#define PR_SET_MM_START_DATA        3
#define PR_CAP_AMBIENT_CLEAR_ALL    4
#define PR_SET_DUMPABLE             4
#define PR_SET_MM_END_DATA          4
#define PR_SPEC_DISABLE             4
#define PR_SET_MM_START_STACK       5
#define PR_SET_MM_START_BRK         6
#define PR_GET_KEEPCAPS             7
#define PR_SET_MM_BRK               7
#define PR_SET_KEEPCAPS             8
#define PR_SET_MM_ARG_START         8
#define PR_SPEC_FORCE_DISABLE       8
#define PR_GET_FPEMU                9
#define PR_SET_MM_ARG_END           9
#define PR_SET_FPEMU                10
#define PR_SET_MM_ENV_START         10
#define PR_GET_FPEXC                11
#define PR_SET_MM_ENV_END           11
#define PR_SET_FPEXC                12
#define PR_SET_MM_AUXV              12
#define PR_SET_MM_EXE_FILE          13
#define PR_SET_MM_MAP               14
#define PR_SET_MM_MAP_SIZE          15
#define PR_GET_TSC                  25
#define PR_SET_TSC                  26
#define PR_GET_SECUREBITS           27
#define PR_SET_SECUREBITS           28
#define PR_SET_TIMERSLACK           29
#define PR_GET_TIMERSLACK           30
#define PR_TASK_PERF_EVENTS_DISABLE 31
#define PR_TASK_PERF_EVENTS_ENABLE  0x20
#define PR_MCE_KILL                 33
#define PR_MCE_KILL_GET             34
#define PR_SET_MM                   35
#define PR_SET_CHILD_SUBREAPER      36
#define PR_GET_CHILD_SUBREAPER      37
#define PR_GET_TID_ADDRESS          40
#define PR_SET_THP_DISABLE          41
#define PR_GET_THP_DISABLE          42
#define PR_MPX_ENABLE_MANAGEMENT    43
#define PR_MPX_DISABLE_MANAGEMENT   44
#define PR_CAP_AMBIENT              47
#define PR_GET_SPECULATION_CTRL     52
#define PR_SET_SPECULATION_CTRL     53
#define PR_SET_TAGGED_ADDR_CTRL     55
#define PR_GET_TAGGED_ADDR_CTRL     56
#define PR_SET_IO_FLUSHER           57
#define PR_GET_IO_FLUSHER           58
#define PR_SET_PTRACER              0x59616d61
#define PR_SET_PTRACER_ANY          -1
#define PR_SET_VMA                  0x53564d41
#define PR_SET_VMA_ANON_NAME        0



/*!BEGIN libc/sysv/consts/prio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PRIO_H_
COSMOPOLITAN_C_START_

extern const int PRIO_MAX;
extern const int PRIO_MIN;
extern const int PRIO_PGRP;
extern const int PRIO_PROCESS;
extern const int PRIO_USER;

#define PRIO_PROCESS 0
#define PRIO_PGRP    1
#define PRIO_USER    2
#define PRIO_MIN     -20
#define PRIO_MAX     20

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/prot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PROT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int PROT_NONE;
extern const int PROT_READ;
extern const int PROT_WRITE;
extern const int PROT_EXEC;
extern const int PROT_GROWSDOWN;
extern const int PROT_GROWSUP;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define PROT_NONE  0
#define PROT_READ  1
#define PROT_WRITE 2
#define PROT_EXEC  4



/*!BEGIN libc/sysv/consts/pt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PT_H_


/*!BEGIN libc/sysv/consts/ptrace.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTRACE_H_
COSMOPOLITAN_C_START_

extern const int PTRACE_TRACEME;
extern const int PTRACE_PEEKTEXT;
extern const int PTRACE_PEEKDATA;
extern const int PTRACE_PEEKUSER;
extern const int PTRACE_POKETEXT;
extern const int PTRACE_POKEDATA;
extern const int PTRACE_POKEUSER;
extern const int PTRACE_CONT;
extern const int PTRACE_KILL;
extern const int PTRACE_SINGLESTEP;
extern const int PTRACE_GETREGS;
extern const int PTRACE_SETREGS;
extern const int PTRACE_GETFPREGS;
extern const int PTRACE_SETFPREGS;
extern const int PTRACE_ATTACH;
extern const int PTRACE_DETACH;
extern const int PTRACE_GETFPXREGS;
extern const int PTRACE_SETFPXREGS;
extern const int PTRACE_SYSCALL;
extern const int PTRACE_GETEVENTMSG;
extern const int PTRACE_GETSIGINFO;
extern const int PTRACE_SETOPTIONS;
extern const int PTRACE_SETSIGINFO;
extern const int PTRACE_GETREGSET;
extern const int PTRACE_GETSIGMASK;
extern const int PTRACE_INTERRUPT;
extern const int PTRACE_LISTEN;
extern const int PTRACE_PEEKSIGINFO;
extern const int PTRACE_SECCOMP_GET_FILTER;
extern const int PTRACE_SECCOMP_GET_METADATA;
extern const int PTRACE_SEIZE;
extern const int PTRACE_SETREGSET;
extern const int PTRACE_SETSIGMASK;
extern const int PTRACE_O_TRACESYSGOOD;
extern const int PTRACE_O_TRACEFORK;
extern const int PTRACE_O_TRACEVFORK;
extern const int PTRACE_O_TRACECLONE;
extern const int PTRACE_O_TRACEEXEC;
extern const int PTRACE_O_TRACEVFORKDONE;
extern const int PTRACE_O_TRACEEXIT;
extern const int PTRACE_O_TRACESECCOMP;
extern const int PTRACE_O_MASK;
extern const int PTRACE_EVENT_FORK;
extern const int PTRACE_EVENT_VFORK;
extern const int PTRACE_EVENT_CLONE;
extern const int PTRACE_EVENT_EXEC;
extern const int PTRACE_EVENT_VFORK_DONE;
extern const int PTRACE_EVENT_EXIT;
extern const int PTRACE_EVENT_STOP;
extern const int PTRACE_EVENT_SECCOMP;

COSMOPOLITAN_C_END_

#define PTRACE_TRACEME              PTRACE_TRACEME
#define PTRACE_PEEKTEXT             PTRACE_PEEKTEXT
#define PTRACE_PEEKDATA             PTRACE_PEEKDATA
#define PTRACE_PEEKUSER             PTRACE_PEEKUSER
#define PTRACE_POKETEXT             PTRACE_POKETEXT
#define PTRACE_POKEDATA             PTRACE_POKEDATA
#define PTRACE_POKEUSER             PTRACE_POKEUSER
#define PTRACE_CONT                 PTRACE_CONT
#define PTRACE_KILL                 PTRACE_KILL
#define PTRACE_SINGLESTEP           PTRACE_SINGLESTEP
#define PTRACE_GETREGS              PTRACE_GETREGS
#define PTRACE_SETREGS              PTRACE_SETREGS
#define PTRACE_GETFPREGS            PTRACE_GETFPREGS
#define PTRACE_SETFPREGS            PTRACE_SETFPREGS
#define PTRACE_ATTACH               PTRACE_ATTACH
#define PTRACE_DETACH               PTRACE_DETACH
#define PTRACE_GETFPXREGS           PTRACE_GETFPXREGS
#define PTRACE_SETFPXREGS           PTRACE_SETFPXREGS
#define PTRACE_SYSCALL              PTRACE_SYSCALL
#define PTRACE_GETEVENTMSG          PTRACE_GETEVENTMSG
#define PTRACE_GETSIGINFO           PTRACE_GETSIGINFO
#define PTRACE_SETOPTIONS           PTRACE_SETOPTIONS
#define PTRACE_SETSIGINFO           PTRACE_SETSIGINFO
#define PTRACE_GETREGSET            PTRACE_GETREGSET
#define PTRACE_GETSIGMASK           PTRACE_GETSIGMASK
#define PTRACE_INTERRUPT            PTRACE_INTERRUPT
#define PTRACE_LISTEN               PTRACE_LISTEN
#define PTRACE_PEEKSIGINFO          PTRACE_PEEKSIGINFO
#define PTRACE_SECCOMP_GET_FILTER   PTRACE_SECCOMP_GET_FILTER
#define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
#define PTRACE_SEIZE                PTRACE_SEIZE
#define PTRACE_SETREGSET            PTRACE_SETREGSET
#define PTRACE_SETSIGMASK           PTRACE_SETSIGMASK
#define PTRACE_O_TRACESYSGOOD       PTRACE_O_TRACESYSGOOD
#define PTRACE_O_TRACEFORK          PTRACE_O_TRACEFORK
#define PTRACE_O_TRACEVFORK         PTRACE_O_TRACEVFORK
#define PTRACE_O_TRACECLONE         PTRACE_O_TRACECLONE
#define PTRACE_O_TRACEEXEC          PTRACE_O_TRACEEXEC
#define PTRACE_O_TRACEVFORKDONE     PTRACE_O_TRACEVFORKDONE
#define PTRACE_O_TRACEEXIT          PTRACE_O_TRACEEXIT
#define PTRACE_O_TRACESECCOMP       PTRACE_O_TRACESECCOMP
#define PTRACE_O_MASK               PTRACE_O_MASK
#define PTRACE_EVENT_FORK           PTRACE_EVENT_FORK
#define PTRACE_EVENT_VFORK          PTRACE_EVENT_VFORK
#define PTRACE_EVENT_CLONE          PTRACE_EVENT_CLONE
#define PTRACE_EVENT_EXEC           PTRACE_EVENT_EXEC
#define PTRACE_EVENT_VFORK_DONE     PTRACE_EVENT_VFORK_DONE
#define PTRACE_EVENT_EXIT           PTRACE_EVENT_EXIT
#define PTRACE_EVENT_STOP           PTRACE_EVENT_STOP
#define PTRACE_EVENT_SECCOMP        PTRACE_EVENT_SECCOMP


#define PT_ATTACH      PTRACE_ATTACH
#define PT_CONTINUE    PTRACE_CONT
#define PT_DETACH      PTRACE_DETACH
#define PT_GETEVENTMSG PTRACE_GETEVENTMSG
#define PT_GETFPREGS   PTRACE_GETFPREGS
#define PT_GETFPXREGS  PTRACE_GETFPXREGS
#define PT_GETREGS     PTRACE_GETREGS
#define PT_GETSIGINFO  PTRACE_GETSIGINFO
#define PT_KILL        PTRACE_KILL
#define PT_READ_D      PTRACE_PEEKDATA
#define PT_READ_I      PTRACE_PEEKTEXT
#define PT_READ_U      PTRACE_PEEKUSER
#define PT_SETFPREGS   PTRACE_SETFPREGS
#define PT_SETFPXREGS  PTRACE_SETFPXREGS
#define PT_SETOPTIONS  PTRACE_SETOPTIONS
#define PT_SETREGS     PTRACE_SETREGS
#define PT_SETSIGINFO  PTRACE_SETSIGINFO
#define PT_STEP        PTRACE_SINGLESTEP
#define PT_SYSCALL     PTRACE_SYSCALL
#define PT_WRITE_D     PTRACE_POKEDATA
#define PT_WRITE_I     PTRACE_POKETEXT
#define PT_WRITE_U     PTRACE_POKEUSER



/*!BEGIN libc/sysv/consts/pty.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTY_H_
COSMOPOLITAN_C_START_

extern const int TIOCPKT;
extern const int TIOCPKT_DATA;
extern const int TIOCPKT_DOSTOP;
extern const int TIOCPKT_FLUSHREAD;
extern const int TIOCPKT_FLUSHWRITE;
extern const int TIOCPKT_IOCTL;
extern const int TIOCPKT_NOSTOP;
extern const int TIOCPKT_START;
extern const int TIOCPKT_STOP;

#define TIOCPKT_DATA       0x00
#define TIOCPKT_DOSTOP     0x01
#define TIOCPKT_FLUSHREAD  0x02
#define TIOCPKT_FLUSHWRITE 0x04
#define TIOCPKT_IOCTL      0x08
#define TIOCPKT_NOSTOP     0x10
#define TIOCPKT_START      0x20
#define TIOCPKT_STOP       0x40

#define TIOCPKT TIOCPKT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/read.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_READ_H_

#define READ_10 READ_10
#define READ_12 READ_12
#define READ_6 READ_6
#define READ_BLOCK_LIMITS READ_BLOCK_LIMITS
#define READ_BUFFER READ_BUFFER
#define READ_CAPACITY READ_CAPACITY
#define READ_DEFECT_DATA READ_DEFECT_DATA
#define READ_ELEMENT_STATUS READ_ELEMENT_STATUS
#define READ_LONG READ_LONG
#define READ_POSITION READ_POSITION
#define READ_REVERSE READ_REVERSE
#define READ_TOC READ_TOC

COSMOPOLITAN_C_START_

extern const long READ_10;
extern const long READ_12;
extern const long READ_6;
extern const long READ_BLOCK_LIMITS;
extern const long READ_BUFFER;
extern const long READ_CAPACITY;
extern const long READ_DEFECT_DATA;
extern const long READ_ELEMENT_STATUS;
extern const long READ_LONG;
extern const long READ_POSITION;
extern const long READ_REVERSE;
extern const long READ_TOC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/reboot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_REBOOT_H_
COSMOPOLITAN_C_START_

extern const unsigned RB_AUTOBOOT;
extern const unsigned RB_POWER_OFF;
extern const unsigned RB_POWERDOWN;
extern const unsigned RB_POWEROFF;
extern const unsigned RB_HALT_SYSTEM;
extern const unsigned RB_HALT;
extern const unsigned RB_SW_SUSPEND;
extern const unsigned RB_KEXEC;
extern const unsigned RB_ENABLE_CAD;
extern const unsigned RB_DISABLE_CAD;
extern const unsigned RB_NOSYNC;

#define RB_AUTOBOOT    RB_AUTOBOOT
#define RB_POWER_OFF   RB_POWER_OFF
#define RB_POWERDOWN   RB_POWERDOWN
#define RB_POWEROFF    RB_POWEROFF
#define RB_HALT_SYSTEM RB_HALT_SYSTEM
#define RB_HALT        RB_HALT
#define RB_SW_SUSPEND  RB_SW_SUSPEND
#define RB_KEXEC       RB_KEXEC
#define RB_ENABLE_CAD  RB_ENABLE_CAD
#define RB_DISABLE_CAD RB_DISABLE_CAD
#define RB_NOSYNC      RB_NOSYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlim.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIM_H_
COSMOPOLITAN_C_START_

extern const uint64_t RLIM_INFINITY;
extern const uint64_t RLIM_NLIMITS;
extern const uint64_t RLIM_SAVED_CUR;
extern const uint64_t RLIM_SAVED_MAX;

#define RLIM_INFINITY  RLIM_INFINITY
#define RLIM_NLIMITS   RLIM_NLIMITS
#define RLIM_SAVED_CUR RLIM_SAVED_CUR
#define RLIM_SAVED_MAX RLIM_SAVED_MAX


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlimit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIMIT_H_
COSMOPOLITAN_C_START_

extern const unsigned RLIMIT_AS;
extern const unsigned RLIMIT_CORE;
extern const unsigned RLIMIT_CPU;
extern const unsigned RLIMIT_DATA;
extern const unsigned RLIMIT_FSIZE;
extern const unsigned RLIMIT_LOCKS;
extern const unsigned RLIMIT_MEMLOCK;
extern const unsigned RLIMIT_MSGQUEUE;
extern const unsigned RLIMIT_NICE;
extern const unsigned RLIMIT_NOFILE;
extern const unsigned RLIMIT_NPROC;
extern const unsigned RLIMIT_NPTS;
extern const unsigned RLIMIT_RSS;
extern const unsigned RLIMIT_RTPRIO;
extern const unsigned RLIMIT_RTTIME;
extern const unsigned RLIMIT_SBSIZE;
extern const unsigned RLIMIT_SIGPENDING;
extern const unsigned RLIMIT_STACK;
extern const unsigned RLIMIT_SWAP;
extern const unsigned RLIMIT_VMEM;

#define RLIMIT_AS         RLIMIT_AS
#define RLIMIT_CORE       RLIMIT_CORE
#define RLIMIT_CPU        RLIMIT_CPU
#define RLIMIT_DATA       RLIMIT_DATA
#define RLIMIT_FSIZE      RLIMIT_FSIZE
#define RLIMIT_LOCKS      RLIMIT_LOCKS
#define RLIMIT_MEMLOCK    RLIMIT_MEMLOCK
#define RLIMIT_MSGQUEUE   RLIMIT_MSGQUEUE
#define RLIMIT_NICE       RLIMIT_NICE
#define RLIMIT_NOFILE     RLIMIT_NOFILE
#define RLIMIT_NPROC      RLIMIT_NPROC
#define RLIMIT_NPTS       RLIMIT_NPTS
#define RLIMIT_RSS        RLIMIT_RSS
#define RLIMIT_RTPRIO     RLIMIT_RTPRIO
#define RLIMIT_RTTIME     RLIMIT_RTTIME
#define RLIMIT_SBSIZE     RLIMIT_SBSIZE
#define RLIMIT_SIGPENDING RLIMIT_SIGPENDING
#define RLIMIT_STACK      RLIMIT_STACK
#define RLIMIT_SWAP       RLIMIT_SWAP
#define RLIMIT_VMEM       RLIMIT_VMEM

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rusage.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RUSAGE_H_
COSMOPOLITAN_C_START_

extern const int RUSAGE_THREAD;
extern const int RUSAGE_CHILDREN;
extern const int RUSAGE_BOTH;

#define RUSAGE_SELF     0
#define RUSAGE_CHILDREN RUSAGE_CHILDREN

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/s.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_S_H_

#define S_IFIFO  0010000 /* pipe */
#define S_IFCHR  0020000 /* character device */
#define S_IFDIR  0040000 /* directory */
#define S_IFBLK  0060000 /* block device */
#define S_IFREG  0100000 /* regular file */
#define S_IFLNK  0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
#define S_IFMT   0170000 /* mask of file types above */

#define S_ISVTX  0001000 /* THE STICKY BIT */
#define S_ISGID  0002000 /* the setgid bit */
#define S_ISUID  0004000 /* the setuid bit */
#define S_IXUSR  0000100 /* user  --x; just use octal */
#define S_IWUSR  0000200 /* user  -w-; just use octal */
#define S_IRUSR  0000400 /* user  r--; just use octal */
#define S_IRWXU  0000700 /* user  rwx; just use octal */
#define S_IXGRP  0000010 /* group --x; just use octal */
#define S_IWGRP  0000020 /* group -w-; just use octal */
#define S_IRGRP  0000040 /* group r--; just use octal */
#define S_IRWXG  0000070 /* group rwx; just use octal */
#define S_IXOTH  0000001 /* other --x; just use octal */
#define S_IWOTH  0000002 /* other -w-; just use octal */
#define S_IROTH  0000004 /* other r--; just use octal */
#define S_IRWXO  0000007 /* other rwx; just use octal */
#define S_IREAD  0000400 /* just use octal */
#define S_IEXEC  0000100 /* just use octal */
#define S_IWRITE 0000200 /* just use octal */
#define S_ISTXT  0001000 /* just use octal */

#define S_ISDIR(mode)  (((mode)&S_IFMT) == S_IFDIR)
#define S_ISCHR(mode)  (((mode)&S_IFMT) == S_IFCHR)
#define S_ISBLK(mode)  (((mode)&S_IFMT) == S_IFBLK)
#define S_ISREG(mode)  (((mode)&S_IFMT) == S_IFREG)
#define S_ISFIFO(mode) (((mode)&S_IFMT) == S_IFIFO)
#define S_ISLNK(mode)  (((mode)&S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)

#define S_BLKSIZE   512
#define ALLPERMS    (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO)
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)



/*!BEGIN libc/sysv/consts/sa.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SA_H_
COSMOPOLITAN_C_START_

extern const uint64_t SA_NOCLDSTOP;
extern const uint64_t SA_NOCLDWAIT;
extern const uint64_t SA_NODEFER;
extern const uint64_t SA_NOMASK;
extern const uint64_t SA_ONESHOT;
extern const uint64_t SA_ONSTACK;
extern const uint64_t SA_RESETHAND;
extern const uint64_t SA_RESTART;
extern const uint64_t SA_SIGINFO;

#define SA_NOCLDSTOP SA_NOCLDSTOP
#define SA_NOCLDWAIT SA_NOCLDWAIT
#define SA_NODEFER   SA_NODEFER
#define SA_NOMASK    SA_NOMASK
#define SA_ONESHOT   SA_ONESHOT
#define SA_ONSTACK   SA_ONSTACK
#define SA_RESETHAND SA_RESETHAND
#define SA_RESTART   SA_RESTART
#define SA_SIGINFO   SA_SIGINFO


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sched.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCHED_H_
COSMOPOLITAN_C_START_

extern const int SCHED_BATCH;
extern const int SCHED_DEADLINE;
extern const int SCHED_FIFO;
extern const int SCHED_IDLE;
extern const int SCHED_OTHER;
extern const int SCHED_RESET_ON_FORK;
extern const int SCHED_RR;

#define SCHED_BATCH         SCHED_BATCH
#define SCHED_DEADLINE      SCHED_DEADLINE
#define SCHED_FIFO          SCHED_FIFO
#define SCHED_IDLE          SCHED_IDLE
#define SCHED_NORMAL        SCHED_OTHER
#define SCHED_OTHER         SCHED_OTHER
#define SCHED_RESET_ON_FORK SCHED_RESET_ON_FORK
#define SCHED_RR            SCHED_RR


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/scm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCM_H_
COSMOPOLITAN_C_START_

extern const int SCM_TIMESTAMP;
extern const int SCM_CREDENTIALS;
extern const int SCM_TIMESTAMPING;
extern const int SCM_TIMESTAMPNS;
extern const int SCM_WIFI_STATUS;

COSMOPOLITAN_C_END_

#define SCM_RIGHTS       1
#define SCM_TIMESTAMP    SCM_TIMESTAMP
#define SCM_CREDENTIALS  SCM_CREDENTIALS
#define SCM_TIMESTAMPING SCM_TIMESTAMPING
#define SCM_TIMESTAMPNS  SCM_TIMESTAMPNS
#define SCM_WIFI_STATUS  SCM_WIFI_STATUS




/*!BEGIN libc/sysv/consts/seek.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SEEK_H_
COSMOPOLITAN_C_START_

extern const int SEEK_DATA;
extern const int SEEK_HOLE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SF_H_
COSMOPOLITAN_C_START_

struct sf_hdtr {
  struct iovec *headers;
  int hdr_cnt;
  struct iovec *trailers;
  int trl_cnt;
};

extern const int SF_MNOWAIT;
extern const int SF_NODISKIO;
extern const int SF_SYNC;

#define SF_MNOWAIT  SF_MNOWAIT
#define SF_NODISKIO SF_NODISKIO
#define SF_SYNC     SF_SYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHM_H_

#define SHM_ANON      SHM_ANON
#define SHM_DEST      SHM_DEST
#define SHM_EXEC      SHM_EXEC
#define SHM_HUGETLB   SHM_HUGETLB
#define SHM_INFO      SHM_INFO
#define SHM_LOCK      SHM_LOCK
#define SHM_LOCKED    SHM_LOCKED
#define SHM_NORESERVE SHM_NORESERVE
#define SHM_R         SHM_R
#define SHM_RDONLY    SHM_RDONLY
#define SHM_REMAP     SHM_REMAP
#define SHM_RND       SHM_RND
#define SHM_STAT      SHM_STAT
#define SHM_UNLOCK    SHM_UNLOCK
#define SHM_W         SHM_W

COSMOPOLITAN_C_START_

extern const char *SHM_ANON;
extern const int SHM_DEST;
extern const int SHM_EXEC;
extern const int SHM_HUGETLB;
extern const int SHM_INFO;
extern const int SHM_LOCK;
extern const int SHM_LOCKED;
extern const int SHM_NORESERVE;
extern const int SHM_R;
extern const int SHM_RDONLY;
extern const int SHM_REMAP;
extern const int SHM_RND;
extern const int SHM_STAT;
extern const int SHM_UNLOCK;
extern const int SHM_W;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shut.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHUT_H_
COSMOPOLITAN_C_START_

extern const int SHUT_RD;
extern const int SHUT_RDWR;
extern const int SHUT_WR;

#define SHUT_RD   0
#define SHUT_RDWR 2
#define SHUT_WR   1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sicode.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SICODE_H_
COSMOPOLITAN_C_START_

extern const int32_t SI_USER;
extern const int32_t SI_QUEUE;
extern const int32_t SI_TIMER;
extern const int32_t SI_MESGQ;
extern const int32_t SI_ASYNCIO;
extern const int32_t SI_TKILL;
extern const int32_t SI_ASYNCNL;
extern const int32_t SI_KERNEL;
extern const int32_t SI_NOINFO;
extern const int32_t CLD_EXITED;
extern const int32_t CLD_KILLED;
extern const int32_t CLD_DUMPED;
extern const int32_t CLD_TRAPPED;
extern const int32_t CLD_STOPPED;
extern const int32_t CLD_CONTINUED;
extern const int32_t TRAP_BRKPT;
extern const int32_t TRAP_TRACE;
extern const int32_t SEGV_MAPERR;
extern const int32_t SEGV_ACCERR;
extern const int32_t SEGV_PKUERR;
extern const int32_t FPE_INTDIV;
extern const int32_t FPE_INTOVF;
extern const int32_t FPE_FLTDIV;
extern const int32_t FPE_FLTOVF;
extern const int32_t FPE_FLTUND;
extern const int32_t FPE_FLTRES;
extern const int32_t FPE_FLTINV;
extern const int32_t FPE_FLTSUB;
extern const int32_t ILL_ILLOPC;
extern const int32_t ILL_ILLOPN;
extern const int32_t ILL_ILLADR;
extern const int32_t ILL_ILLTRP;
extern const int32_t ILL_PRVOPC;
extern const int32_t ILL_PRVREG;
extern const int32_t ILL_COPROC;
extern const int32_t ILL_BADSTK;
extern const int32_t BUS_ADRALN;
extern const int32_t BUS_ADRERR;
extern const int32_t BUS_OBJERR;
extern const int32_t BUS_MCEERR_AR;
extern const int32_t BUS_MCEERR_AO;
extern const int32_t BUS_OOMERR;
extern const int32_t POLL_IN;
extern const int32_t POLL_OUT;
extern const int32_t POLL_MSG;
extern const int32_t POLL_ERR;
extern const int32_t POLL_PRI;
extern const int32_t POLL_HUP;
extern const int32_t SYS_SECCOMP;
extern const int32_t SYS_USER_DISPATCH;

#define CLD_EXITED    1
#define CLD_KILLED    2
#define CLD_DUMPED    3
#define CLD_TRAPPED   4
#define CLD_STOPPED   5
#define CLD_CONTINUED 6
#define TRAP_BRKPT    1
#define TRAP_TRACE    2
#define SEGV_MAPERR   1
#define SEGV_ACCERR   2
#define ILL_ILLOPC    1
#define ILL_PRVREG    6
#define ILL_COPROC    7
#define ILL_BADSTK    8
#define BUS_ADRALN    1
#define BUS_ADRERR    2
#define BUS_OBJERR    3
#define POLL_IN       1
#define POLL_OUT      2
#define POLL_MSG      3
#define POLL_ERR      4
#define POLL_PRI      5
#define POLL_HUP      6

#define SI_USER           SI_USER
#define SI_QUEUE          SI_QUEUE
#define SI_TIMER          SI_TIMER
#define SI_MESGQ          SI_MESGQ
#define SI_ASYNCIO        SI_ASYNCIO
#define SI_TKILL          SI_TKILL
#define SI_ASYNCNL        SI_ASYNCNL
#define SI_KERNEL         SI_KERNEL
#define SI_NOINFO         SI_NOINFO
#define SEGV_PKUERR       SEGV_PKUERR
#define FPE_INTDIV        FPE_INTDIV
#define FPE_INTOVF        FPE_INTOVF
#define FPE_FLTDIV        FPE_FLTDIV
#define FPE_FLTOVF        FPE_FLTOVF
#define FPE_FLTUND        FPE_FLTUND
#define FPE_FLTRES        FPE_FLTRES
#define FPE_FLTINV        FPE_FLTINV
#define FPE_FLTSUB        FPE_FLTSUB
#define ILL_ILLOPN        ILL_ILLOPN
#define ILL_ILLADR        ILL_ILLADR
#define ILL_ILLTRP        ILL_ILLTRP
#define ILL_PRVOPC        ILL_PRVOPC
#define BUS_OOMERR        BUS_OOMERR
#define BUS_MCEERR_AR     BUS_MCEERR_AR
#define BUS_MCEERR_AO     BUS_MCEERR_AO
#define SYS_SECCOMP       SYS_SECCOMP
#define SYS_USER_DISPATCH SYS_USER_DISPATCH


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sig.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIG_H_
COSMOPOLITAN_C_START_

extern const int SIGABRT;
extern const int SIGALRM;
extern const int SIGBUS;
extern const int SIGTHR;
extern const int SIGCHLD;
extern const int SIGCONT;
extern const int SIGEMT;
extern const int SIGFPE;
extern const int SIGHUP;
extern const int SIGILL;
extern const int SIGINFO;
extern const int SIGINT;
extern const int SIGIO;
extern const int SIGIOT;
extern const int SIGKILL;
extern const int SIGPIPE;
extern const int SIGPOLL;
extern const int SIGPROF;
extern const int SIGPWR;
extern const int SIGQUIT;
extern const int SIGRTMAX;
extern const int SIGRTMIN;
extern const int SIGSEGV;
extern const int SIGSTKFLT;
extern const int SIGSTOP;
extern const int SIGSYS;
extern const int SIGTERM;
extern const int SIGTRAP;
extern const int SIGTSTP;
extern const int SIGTTIN;
extern const int SIGTTOU;
extern const int SIGUNUSED;
extern const int SIGURG;
extern const int SIGUSR1;
extern const int SIGUSR2;
extern const int SIGVTALRM;
extern const int SIGWINCH;
extern const int SIGXCPU;
extern const int SIGXFSZ;

extern const int SIG_BLOCK;
extern const int SIG_SETMASK;
extern const int SIG_UNBLOCK;

COSMOPOLITAN_C_END_

#define SIGABRT   6
#define SIGALRM   14
#define SIGFPE    8
#define SIGHUP    1
#define SIGILL    4
#define SIGINT    2
#define SIGIOT    6
#define SIGKILL   9
#define SIGPIPE   13
#define SIGPROF   27
#define SIGQUIT   3
#define SIGSEGV   11
#define SIGTERM   15
#define SIGTRAP   5
#define SIGTTIN   21
#define SIGTTOU   22
#define SIGVTALRM 26
#define SIGWINCH  28
#define SIGXCPU   24
#define SIGXFSZ   25

/*
 * - No macro is define for SIGIO and SIGPOLL in order to persuade
 *   ./configure scripts to favor using poll() or select() instead of
 *   interrupt-based i/o.
 *
 * - No macros are defined for SIGRTMIN and SIGRTMAX because the project
 *   hasn't fleshed them out yet.
 *
 * - SIGTHR doesn't have a macro since it's internal to posix threads.
 *
 * - SIGSTKFLT is Linux-only so no macro is defined.
 */

#define SIGBUS  SIGBUS
#define SIGCHLD SIGCHLD
#define SIGCONT SIGCONT
#define SIGEMT  SIGEMT
#define SIGINFO SIGINFO
#define SIGPWR  SIGPWR
#define SIGSTOP SIGSTOP
#define SIGSYS  SIGSYS
#define SIGTSTP SIGTSTP
#define SIGURG  SIGURG
#define SIGUSR1 SIGUSR1
#define SIGUSR2 SIGUSR2

#define SIG_BLOCK   SIG_BLOCK
#define SIG_SETMASK SIG_SETMASK
#define SIG_UNBLOCK SIG_UNBLOCK



/*!BEGIN libc/sysv/consts/sio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIO_H_
COSMOPOLITAN_C_START_

extern const unsigned long SIOCADDDLCI;
extern const unsigned long SIOCADDMULTI;
extern const unsigned long SIOCADDRT;
extern const unsigned long SIOCDARP;
extern const unsigned long SIOCDELDLCI;
extern const unsigned long SIOCDELMULTI;
extern const unsigned long SIOCDELRT;
extern const unsigned long SIOCDEVPRIVATE;
extern const unsigned long SIOCDIFADDR;
extern const unsigned long SIOCDRARP;
extern const unsigned long SIOCGARP;
extern const unsigned long SIOCGIFADDR;
extern const unsigned long SIOCGIFBR;
extern const unsigned long SIOCGIFBRDADDR;
extern const unsigned long SIOCGIFCONF;
extern const unsigned long SIOCGIFCOUNT;
extern const unsigned long SIOCGIFDSTADDR;
extern const unsigned long SIOCGIFENCAP;
extern const unsigned long SIOCGIFFLAGS;
extern const unsigned long SIOCGIFHWADDR;
extern const unsigned long SIOCGIFINDEX;
extern const unsigned long SIOCGIFMAP;
extern const unsigned long SIOCGIFMEM;
extern const unsigned long SIOCGIFMETRIC;
extern const unsigned long SIOCGIFMTU;
extern const unsigned long SIOCGIFNAME;
extern const unsigned long SIOCGIFNETMASK;
extern const unsigned long SIOCGIFPFLAGS;
extern const unsigned long SIOCGIFSLAVE;
extern const unsigned long SIOCGIFTXQLEN;
extern const unsigned long SIOCGPGRP;
extern const unsigned long SIOCGRARP;
extern const unsigned long SIOCGSTAMP;
extern const unsigned long SIOCGSTAMPNS;
extern const unsigned long SIOCPROTOPRIVATE;
extern const unsigned long SIOCRTMSG;
extern const unsigned long SIOCSARP;
extern const unsigned long SIOCSIFADDR;
extern const unsigned long SIOCSIFBR;
extern const unsigned long SIOCSIFBRDADDR;
extern const unsigned long SIOCSIFDSTADDR;
extern const unsigned long SIOCSIFENCAP;
extern const unsigned long SIOCSIFFLAGS;
extern const unsigned long SIOCSIFHWADDR;
extern const unsigned long SIOCSIFHWBROADCAST;
extern const unsigned long SIOCSIFLINK;
extern const unsigned long SIOCSIFMAP;
extern const unsigned long SIOCSIFMEM;
extern const unsigned long SIOCSIFMETRIC;
extern const unsigned long SIOCSIFMTU;
extern const unsigned long SIOCSIFNAME;
extern const unsigned long SIOCSIFNETMASK;
extern const unsigned long SIOCSIFPFLAGS;
extern const unsigned long SIOCSIFSLAVE;
extern const unsigned long SIOCSIFTXQLEN;
extern const unsigned long SIOCSPGRP;
extern const unsigned long SIOCSRARP;
extern const unsigned long SIOGIFINDEX;

#define SIOCGIFCONF    SIOCGIFCONF
#define SIOCGIFADDR    SIOCGIFADDR
#define SIOCSIFADDR    SIOCSIFADDR
#define SIOCDIFADDR    SIOCDIFADDR
#define SIOCGIFBRDADDR SIOCGIFBRDADDR
#define SIOCGIFNETMASK SIOCGIFNETMASK
#define SIOCGIFFLAGS   SIOCGIFFLAGS
#define SIOCSIFFLAGS   SIOCSIFFLAGS
#define SIOCGIFMETRIC  SIOCGIFMETRIC
#define SIOCSIFMETRIC  SIOCSIFMETRIC
#define SIOCSIFBRDADDR SIOCSIFBRDADDR
#define SIOCSIFNETMASK SIOCSIFNETMASK
#define SIOCGIFDSTADDR SIOCGIFDSTADDR
#define SIOCSIFDSTADDR SIOCSIFDSTADDR
#define SIOCGIFMTU     SIOCGIFMTU
#define SIOCSIFMTU     SIOCSIFMTU

#define SIOCGPGRP SIOCGPGRP
#define SIOCSPGRP SIOCSPGRP

#define SIOCADDMULTI SIOCADDMULTI
#define SIOCDELMULTI SIOCDELMULTI

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/so.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SO_H_

#define SO_DEBUG 1

COSMOPOLITAN_C_START_

extern const int SO_TYPE;
extern const int SO_ERROR;
extern const int SO_ACCEPTCONN;
extern const int SO_REUSEADDR;
extern const int SO_KEEPALIVE;
extern const int SO_DONTROUTE;
extern const int SO_BROADCAST;
extern const int SO_USELOOPBACK;
extern const int SO_LINGER;
extern const int SO_OOBINLINE;
extern const int SO_SNDBUF;
extern const int SO_RCVBUF;
extern const int SO_RCVTIMEO;
extern const int SO_SNDTIMEO;
extern const int SO_RCVLOWAT;
extern const int SO_SNDLOWAT;

#define SO_TYPE        SO_TYPE
#define SO_ERROR       SO_ERROR
#define SO_ACCEPTCONN  SO_ACCEPTCONN
#define SO_REUSEADDR   SO_REUSEADDR
#define SO_KEEPALIVE   SO_KEEPALIVE
#define SO_DONTROUTE   SO_DONTROUTE
#define SO_BROADCAST   SO_BROADCAST
#define SO_USELOOPBACK SO_USELOOPBACK
#define SO_LINGER      SO_LINGER
#define SO_OOBINLINE   SO_OOBINLINE
#define SO_SNDBUF      SO_SNDBUF
#define SO_RCVBUF      SO_RCVBUF
#define SO_RCVTIMEO    SO_RCVTIMEO
#define SO_SNDTIMEO    SO_SNDTIMEO
#define SO_RCVLOWAT    SO_RCVLOWAT
#define SO_SNDLOWAT    SO_SNDLOWAT

/*
 * this isn't available on windows, but it should be fine to use anyway,
 * setsockopt will return ENOPROTOOPT which is perfectly fine to ignore.
 */
extern const int SO_REUSEPORT;
#define SO_REUSEPORT SO_REUSEPORT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOCK_H_
COSMOPOLITAN_C_START_

extern const int SOCK_CLOEXEC;
extern const int SOCK_DCCP;
extern const int SOCK_DGRAM;
extern const int SOCK_NONBLOCK;
extern const int SOCK_PACKET;
extern const int SOCK_RAW;
extern const int SOCK_RDM;
extern const int SOCK_SEQPACKET;
extern const int SOCK_STREAM;

#define SOCK_STREAM    1
#define SOCK_DGRAM     2
#define SOCK_RAW       3
#define SOCK_RDM       4
#define SOCK_SEQPACKET 5
#define SOCK_CLOEXEC   SOCK_CLOEXEC
#define SOCK_NONBLOCK  SOCK_NONBLOCK

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sol.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOL_H_

#define SOL_IP     0
#define SOL_ICMP   1
#define SOL_TCP    6
#define SOL_UDP    17
#define SOL_IPV6   41
#define SOL_ICMPV6 58
#define SOL_RAW    255

COSMOPOLITAN_C_START_

extern const int SOL_SOCKET;
#define SOL_SOCKET SOL_SOCKET

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/splice.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SPLICE_H_
COSMOPOLITAN_C_START_

extern const unsigned int SPLICE_F_GIFT;
extern const unsigned int SPLICE_F_MORE;
extern const unsigned int SPLICE_F_MOVE;
extern const unsigned int SPLICE_F_NONBLOCK;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ss.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SS_H_
COSMOPOLITAN_C_START_

extern const int SS_DISABLE;
extern const int _SIGSTKSZ;
extern const int _MINSIGSTKSZ;

COSMOPOLITAN_C_END_

#define SIGSTKSZ    32768
#define MINSIGSTKSZ 32768 /* xnu defines the highest minimum */
#define SS_ONSTACK  1
#define SS_DISABLE  SS_DISABLE



/*!BEGIN libc/sysv/consts/st.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ST_H_
COSMOPOLITAN_C_START_

extern const int ST_APPEND;
extern const int ST_IMMUTABLE;
extern const int ST_MANDLOCK;
extern const int ST_NOATIME;
extern const int ST_NODEV;
extern const int ST_NODIRATIME;
extern const int ST_NOEXEC;
extern const int ST_NOSUID;
extern const int ST_RDONLY;
extern const int ST_RELATIME;
extern const int ST_SYNCHRONOUS;
extern const int ST_WRITE;

#define ST_APPEND      ST_APPEND
#define ST_IMMUTABLE   ST_IMMUTABLE
#define ST_MANDLOCK    ST_MANDLOCK
#define ST_NOATIME     ST_NOATIME
#define ST_NODEV       ST_NODEV
#define ST_NODIRATIME  ST_NODIRATIME
#define ST_NOEXEC      ST_NOEXEC
#define ST_NOSUID      ST_NOSUID
#define ST_RDONLY      ST_RDONLY
#define ST_RELATIME    ST_RELATIME
#define ST_SYNCHRONOUS ST_SYNCHRONOUS
#define ST_WRITE       ST_WRITE


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCP_H_
COSMOPOLITAN_C_START_

extern const int TCP_CC_INFO;
extern const int TCP_CONGESTION;
extern const int TCP_COOKIE_TRANSACTIONS;
extern const int TCP_CORK;
extern const int TCP_DEFER_ACCEPT;
extern const int TCP_FASTOPEN;
extern const int TCP_FASTOPEN_CONNECT;
extern const int TCP_INFO;
extern const int TCP_KEEPCNT;
extern const int TCP_KEEPIDLE;
extern const int TCP_KEEPINTVL;
extern const int TCP_LINGER2;
extern const int TCP_MAXSEG;
extern const int TCP_MD5SIG;
extern const int TCP_MD5SIG_MAXKEYLEN;
extern const int TCP_NODELAY;
extern const int TCP_NOTSENT_LOWAT;
extern const int TCP_QUEUE_SEQ;
extern const int TCP_QUICKACK;
extern const int TCP_REPAIR;
extern const int TCP_REPAIR_OPTIONS;
extern const int TCP_REPAIR_QUEUE;
extern const int TCP_SAVED_SYN;
extern const int TCP_SAVE_SYN;
extern const int TCP_SYNCNT;
extern const int TCP_THIN_DUPACK;
extern const int TCP_THIN_LINEAR_TIMEOUTS;
extern const int TCP_TIMESTAMP;
extern const int TCP_ULP;
extern const int TCP_USER_TIMEOUT;
extern const int TCP_WINDOW_CLAMP;

#define TCP_NODELAY              1
#define TCP_CC_INFO              TCP_CC_INFO
#define TCP_CONGESTION           TCP_CONGESTION
#define TCP_COOKIE_TRANSACTIONS  TCP_COOKIE_TRANSACTIONS
#define TCP_CORK                 TCP_CORK
#define TCP_DEFER_ACCEPT         TCP_DEFER_ACCEPT
#define TCP_FASTOPEN             TCP_FASTOPEN
#define TCP_FASTOPEN_CONNECT     TCP_FASTOPEN_CONNECT
#define TCP_INFO                 TCP_INFO
#define TCP_KEEPCNT              TCP_KEEPCNT
#define TCP_KEEPIDLE             TCP_KEEPIDLE
#define TCP_KEEPINTVL            TCP_KEEPINTVL
#define TCP_LINGER2              TCP_LINGER2
#define TCP_MAXSEG               TCP_MAXSEG
#define TCP_MD5SIG               TCP_MD5SIG
#define TCP_MD5SIG_MAXKEYLEN     TCP_MD5SIG_MAXKEYLEN
#define TCP_NOTSENT_LOWAT        TCP_NOTSENT_LOWAT
#define TCP_QUEUE_SEQ            TCP_QUEUE_SEQ
#define TCP_QUICKACK             TCP_QUICKACK
#define TCP_REPAIR               TCP_REPAIR
#define TCP_REPAIR_OPTIONS       TCP_REPAIR_OPTIONS
#define TCP_REPAIR_QUEUE         TCP_REPAIR_QUEUE
#define TCP_SAVED_SYN            TCP_SAVED_SYN
#define TCP_SAVE_SYN             TCP_SAVE_SYN
#define TCP_SYNCNT               TCP_SYNCNT
#define TCP_THIN_DUPACK          TCP_THIN_DUPACK
#define TCP_THIN_LINEAR_TIMEOUTS TCP_THIN_LINEAR_TIMEOUTS
#define TCP_TIMESTAMP            TCP_TIMESTAMP
#define TCP_ULP                  TCP_ULP
#define TCP_USER_TIMEOUT         TCP_USER_TIMEOUT
#define TCP_WINDOW_CLAMP         TCP_WINDOW_CLAMP


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcpopt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCPOPT_H_

#define TCPOPT_EOL            0
#define TCPOPT_NOP            1
#define TCPOPT_MAXSEG         2
#define TCPOPT_WINDOW         3
#define TCPOPT_SACK_PERMITTED 4
#define TCPOPT_SACK           5
#define TCPOPT_TIMESTAMP      8

#define TCPOLEN_SACK_PERMITTED 2
#define TCPOLEN_WINDOW         3
#define TCPOLEN_MAXSEG         4
#define TCPOLEN_TIMESTAMP      10



/*!BEGIN libc/sysv/consts/th.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TH_H_

#define TH_FIN  1
#define TH_SYN  2
#define TH_RST  4
#define TH_PUSH 8
#define TH_URG  32
#define TH_ACK  16



/*!BEGIN libc/sysv/consts/timer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TIMER_H_

#define TIMER_ABSTIME 1



/*!BEGIN libc/sysv/consts/uc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UC_H_
COSMOPOLITAN_C_START_

#define UC_FP_XSTATE         1
#define UC_SIGCONTEXT_SS     2
#define UC_STRICT_RESTORE_SS 4

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/unmount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const int MNT_FORCE;
extern const int MNT_DETACH;
extern const int MNT_EXPIRE;
extern const int UMOUNT_NOFOLLOW;
extern const int MNT_BYFSID;

COSMOPOLITAN_C_END_

#define MNT_FORCE       MNT_FORCE
#define MNT_DETACH      MNT_DETACH
#define MNT_EXPIRE      MNT_EXPIRE
#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW
#define MNT_BYFSID      MNT_BYFSID



/*!BEGIN libc/sysv/consts/utime.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UTIME_H_
COSMOPOLITAN_C_START_

extern const int UTIME_NOW;
extern const int UTIME_OMIT;

COSMOPOLITAN_C_END_

#define UTIME_NOW  UTIME_NOW
#define UTIME_OMIT UTIME_OMIT




/*!BEGIN libc/sysv/consts/waitid.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_WAITID_H_
COSMOPOLITAN_C_START_

extern const int WEXITED;
extern const int WSTOPPED;
extern const int WNOWAIT;

#define WEXITED  WEXITED
#define WSTOPPED WSTOPPED
#define WNOWAIT  WNOWAIT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/xopen.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_XOPEN_H_

#define _XOPEN_IOV_MAX  16
#define _XOPEN_ENH_I18N 1
#define _XOPEN_UNIX     1
#define _XOPEN_NAME_MAX 63
#define _XOPEN_PATH_MAX 1024
#define _XOPEN_SOURCE   700



/*!BEGIN libc/thread/semaphore.h */

#define COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
COSMOPOLITAN_C_START_

#define SEM_FAILED        ((sem_t *)0)
#define SEM_MAGIC_NAMED   0xDEADBEEFu
#define SEM_MAGIC_UNNAMED 0xFEEDABEEu
#define SEM_MAGIC_KERNEL  0xCAFEBABEu

typedef struct {
  union {
    struct {
      _Atomic(int) sem_value;
      _Atomic(int) sem_waiters;
      _Atomic(int) sem_prefs; /* named only */
      unsigned sem_magic;
      int64_t sem_dev;     /* named only */
      int64_t sem_ino;     /* named only */
      int sem_pid;         /* unnamed only */
      char sem_lazydelete; /* named only */
      char sem_pshared;
      int *sem_kernel;
    };
    void *sem_space[32];
  };
} sem_t;

int sem_init(sem_t *, int, unsigned) libcesque;
int sem_destroy(sem_t *) libcesque;
int sem_post(sem_t *) libcesque;
int sem_wait(sem_t *) libcesque;
int sem_trywait(sem_t *) libcesque;
int sem_timedwait(sem_t *, const struct timespec *) libcesque;
int sem_getvalue(sem_t *, int *) libcesque;
sem_t *sem_open(const char *, int, ...) libcesque;
int sem_close(sem_t *) libcesque;
int sem_unlink(const char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/thread.h */

#define COSMOPOLITAN_LIBC_THREAD_THREAD_H_

#define PTHREAD_KEYS_MAX              128
#define PTHREAD_STACK_MIN             65536
#define PTHREAD_DESTRUCTOR_ITERATIONS 4

#define PTHREAD_BARRIER_SERIAL_THREAD 31337

#define PTHREAD_MUTEX_DEFAULT    0
#define PTHREAD_MUTEX_NORMAL     0
#define PTHREAD_MUTEX_RECURSIVE  1
#define PTHREAD_MUTEX_ERRORCHECK 2
#define PTHREAD_MUTEX_STALLED    0
#define PTHREAD_MUTEX_ROBUST     1

#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED  1

#define PTHREAD_CREATE_JOINABLE 0
#define PTHREAD_CREATE_DETACHED 1

#define PTHREAD_INHERIT_SCHED  0
#define PTHREAD_EXPLICIT_SCHED 1

#define PTHREAD_CANCELED ((void *)-1)

#define PTHREAD_CANCEL_ENABLE  0
#define PTHREAD_CANCEL_DISABLE 1
#define PTHREAD_CANCEL_MASKED  2

#define PTHREAD_CANCEL_DEFERRED     0
#define PTHREAD_CANCEL_ASYNCHRONOUS 1

#define PTHREAD_SCOPE_SYSTEM  0
#define PTHREAD_SCOPE_PROCESS 1

#define PTHREAD_ATTR_NO_SIGMASK_NP -1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

#define PTHREAD_ONCE_INIT          _PTHREAD_INIT
#define PTHREAD_COND_INITIALIZER   _PTHREAD_INIT
#define PTHREAD_RWLOCK_INITIALIZER _PTHREAD_INIT
#define PTHREAD_MUTEX_INITIALIZER  _PTHREAD_INIT
#define _PTHREAD_INIT \
  { 0 }

typedef uintptr_t pthread_t;
typedef int pthread_id_np_t;
typedef char pthread_condattr_t;
typedef char pthread_rwlockattr_t;
typedef char pthread_barrierattr_t;
typedef unsigned pthread_key_t;
typedef void (*pthread_key_dtor)(void *);

typedef struct pthread_once_s {
  _Atomic(uint32_t) _lock;
} pthread_once_t;

typedef struct pthread_spinlock_s {
  _Atomic(int) _lock;
} pthread_spinlock_t;

typedef struct pthread_mutex_s {
  _Atomic(int32_t) _lock;
  unsigned _type : 2;
  unsigned _pshared : 1;
  unsigned _depth : 6;
  unsigned _owner : 23;
  long _pid;
} pthread_mutex_t;

typedef struct pthread_mutexattr_s {
  char _type;
  char _pshared;
} pthread_mutexattr_t;

typedef struct pthread_cond_s {
  void *_nsync[2];
} pthread_cond_t;

typedef struct pthread_rwlock_s {
  void *_nsync[2];
  char _iswrite;
} pthread_rwlock_t;

typedef struct pthread_barrier_s {
  void *_nsync;
} pthread_barrier_t;

typedef struct pthread_attr_s {
  char __detachstate;
  char __inheritsched;
  char __havesigmask;
  int __schedparam;
  int __schedpolicy;
  int __contentionscope;
  int __guardsize;
  size_t __stacksize;
  uint64_t __sigmask;
  void *__stackaddr;
} pthread_attr_t;

struct _pthread_cleanup_buffer {
  void (*__routine)(void *);
  void *__arg;
  int __canceltype;
  struct _pthread_cleanup_buffer *__prev;
};

/* clang-format off */

int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) dontthrow;
int pthread_attr_destroy(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_getdetachstate(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getguardsize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_getinheritsched(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getschedpolicy(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getscope(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getstack(const pthread_attr_t *, void **, size_t *) libcesque paramsnonnull();
int pthread_attr_getstacksize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_init(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_setdetachstate(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setguardsize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_attr_setinheritsched(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setschedpolicy(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setscope(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setstack(pthread_attr_t *, void *, size_t) libcesque paramsnonnull((1));
int pthread_attr_setstacksize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_barrier_destroy(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned) libcesque paramsnonnull((1));
int pthread_barrier_wait(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrierattr_destroy(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *) libcesque paramsnonnull();
int pthread_barrierattr_init(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int) libcesque paramsnonnull();
int pthread_cancel(pthread_t) libcesque;
int pthread_cond_broadcast(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_destroy(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *) libcesque paramsnonnull((1));
int pthread_cond_signal(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *) libcesque paramsnonnull();
int pthread_condattr_destroy(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_getpshared(const pthread_condattr_t *, int *) libcesque paramsnonnull();
int pthread_condattr_init(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_setpshared(pthread_condattr_t *, int) libcesque paramsnonnull();
int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *) dontthrow paramsnonnull((1));
int pthread_detach(pthread_t) libcesque;
int pthread_equal(pthread_t, pthread_t) libcesque;
int pthread_getattr_np(pthread_t, pthread_attr_t *) libcesque paramsnonnull();
int pthread_getname_np(pthread_t, char *, size_t) libcesque paramsnonnull();
int pthread_getunique_np(pthread_t, pthread_id_np_t *) libcesque paramsnonnull();
int pthread_join(pthread_t, void **) libcesque;
int pthread_key_create(pthread_key_t *, pthread_key_dtor) libcesque paramsnonnull((1));
int pthread_key_delete(pthread_key_t) libcesque;
int pthread_kill(pthread_t, int) libcesque;
int pthread_mutex_consistent(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_destroy(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *) libcesque paramsnonnull((1));
int pthread_mutex_lock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_trylock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_unlock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutexattr_destroy(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_init(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_mutexattr_settype(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_once(pthread_once_t *, void (*)(void)) paramsnonnull();
int pthread_orphan_np(void) libcesque;
int pthread_rwlock_destroy(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *) libcesque paramsnonnull((1));
int pthread_rwlock_rdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_tryrdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_trywrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_unlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_wrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, int *) libcesque paramsnonnull();
int pthread_rwlockattr_init(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int) libcesque paramsnonnull();
int pthread_setcancelstate(int, int *) libcesque;
int pthread_setcanceltype(int, int *) libcesque;
int pthread_setname_np(pthread_t, const char *) libcesque paramsnonnull();
int pthread_setschedprio(pthread_t, int) libcesque;
int pthread_setspecific(pthread_key_t, const void *) libcesque;
int pthread_spin_destroy(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_init(pthread_spinlock_t *, int) libcesque paramsnonnull();
int pthread_spin_lock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_trylock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_unlock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_testcancel_np(void) libcesque;
int pthread_tryjoin_np(pthread_t, void **) libcesque;
int pthread_yield_np(void) libcesque;
int pthread_yield(void) libcesque;
pthread_id_np_t pthread_getthreadid_np(void) libcesque;
pthread_t pthread_self(void) libcesque pureconst;
void *pthread_getspecific(pthread_key_t) libcesque;
void pthread_cleanup_pop(struct _pthread_cleanup_buffer *, int) libcesque paramsnonnull();
void pthread_cleanup_push(struct _pthread_cleanup_buffer *, void (*)(void *), void *) libcesque paramsnonnull((1));
void pthread_exit(void *) libcesque wontreturn;
void pthread_testcancel(void) libcesque;
void pthread_pause_np(void) libcesque;

/* clang-format on */

#define pthread_cleanup_push(routine, arg)  \
  {                                         \
    struct _pthread_cleanup_buffer _buffer; \
    pthread_cleanup_push(&_buffer, (routine), (arg));

#define pthread_cleanup_pop(execute)        \
  pthread_cleanup_pop(&_buffer, (execute)); \
  }

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/thread/thread2.h */

#define COSMOPOLITAN_LIBC_INTRIN_PTHREAD2_H_
COSMOPOLITAN_C_START_
/* clang-format off */

int pthread_attr_getschedparam(const pthread_attr_t *, struct sched_param *) libcesque paramsnonnull();
int pthread_attr_getsigmask_np(const pthread_attr_t *, sigset_t *) libcesque paramsnonnull((1));
int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *) libcesque paramsnonnull();
int pthread_attr_setsigmask_np(pthread_attr_t *, const sigset_t *) libcesque paramsnonnull((1));
int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *) libcesque paramsnonnull((1, 2));
int pthread_getaffinity_np(pthread_t, size_t, cpu_set_t *) libcesque paramsnonnull();
int pthread_getschedparam(pthread_t, int *, struct sched_param *) libcesque paramsnonnull();
int pthread_setaffinity_np(pthread_t, size_t, const cpu_set_t *) libcesque paramsnonnull();
int pthread_setschedparam(pthread_t, int, const struct sched_param *) libcesque paramsnonnull();
int pthread_timedjoin_np(pthread_t, void **, struct timespec *) libcesque;

/* clang-format off */
COSMOPOLITAN_C_END_
/* clang-format on */


/*!BEGIN libc/thread/threads.h */

#define COSMOPOLITAN_LIBC_THREAD_THREADS_H_
COSMOPOLITAN_C_START_

#if !defined(__cplusplus) &&                   \
    (!(defined(__GNUC__) && __GNUC__ >= 13) || \
     !(defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L))
#define thread_local _Thread_local
#endif

#define TSS_DTOR_ITERATIONS 4

enum {
  thrd_success = 0,
  thrd_busy = 1,
  thrd_error = 2,
  thrd_nomem = 3,
  thrd_timedout = 4,
};

enum {
  mtx_plain = 0,
  mtx_recursive = 1,
  mtx_timed = 2,
};

typedef uintptr_t thrd_t;
typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *);
typedef _Atomic(uint32_t) once_flag;

void call_once(once_flag *, void (*)(void));
int thrd_create(thrd_t *, thrd_start_t, void *);
void thrd_exit(int) wontreturn;
int thrd_join(thrd_t, int *);
int thrd_detach(thrd_t);
int thrd_equal(thrd_t, thrd_t);
thrd_t thrd_current(void);
void thrd_yield(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/tls.h */

#define COSMOPOLITAN_LIBC_THREAD_TLS_H_

#define TLS_ALIGNMENT 64

#define TIB_FLAG_VFORKED 1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct CosmoFtrace {   /* 16 */
  char ft_once;        /*  0 */
  char ft_noreentry;   /*  1 */
  int ft_skew;         /*  4 */
  int64_t ft_lastaddr; /*  8 */
};

/* NOTE: update aarch64 libc/errno.h if sizeof changes */
/* NOTE: update aarch64 libc/proc/vfork.S if sizeof changes */
/* NOTE: update aarch64 libc/nexgen32e/gc.S if sizeof changes */
struct CosmoTib {
  struct CosmoTib *tib_self;      /* 0x00 */
  struct CosmoFtrace tib_ftracer; /* 0x08 */
  void *tib_garbages;             /* 0x18 */
  intptr_t tib_locale;            /* 0x20 */
  intptr_t tib_pthread;           /* 0x28 */
  struct CosmoTib *tib_self2;     /* 0x30 */
  _Atomic(int32_t) tib_tid;       /* 0x38 transitions -1 → tid → 0 */
  int32_t tib_errno;              /* 0x3c */
  uint64_t tib_flags;             /* 0x40 */
  int tib_ftrace;                 /* inherited */
  int tib_strace;                 /* inherited */
  _Atomic(uint64_t) tib_sigmask;  /* inherited */
  _Atomic(uint64_t) tib_sigpending;
  _Atomic(uint64_t) tib_syshand; /* win32=kThread, xnusilicon=pthread_t */
  char *tib_sigstack_addr;
  uint32_t tib_sigstack_size;
  uint32_t tib_sigstack_flags;
  void **tib_keys;
  void *tib_nsync;
  void *tib_todo[7];
} __attribute__((__aligned__(64)));

extern int __threaded;
extern char __tls_morphed;
extern unsigned __tls_index;

char *_mktls(struct CosmoTib **) libcesque;
void __bootstrap_tls(struct CosmoTib *, char *) libcesque;

#ifdef __x86_64__
extern char __tls_enabled;
#define __tls_enabled_set(x) __tls_enabled = x
#elif defined(__aarch64__)
#define __tls_enabled        true
#define __tls_enabled_set(x) (void)0
#else
#error "unsupported architecture"
#endif

void __set_tls(struct CosmoTib *) libcesque;

/**
 * Returns location of thread information block.
 *
 * This can't be used in privileged functions.
 */
forceinline pureconst struct CosmoTib *__get_tls(void) {
#ifdef __chibicc__
  return 0;
#elif __x86_64__
  struct CosmoTib *__tib;
  __asm__("mov\t%%gs:0x30,%0" : "=r"(__tib));
  return __tib;
#elif defined(__aarch64__)
  register struct CosmoTib *__tls __asm__("x28");
  return __tls - 1;
#endif
}

#ifdef __x86_64__
#define __adj_tls(tib) (tib)
#elif defined(__aarch64__)
#define __adj_tls(tib) ((struct CosmoTib *)(tib) + 1)
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/tinymath/emod.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMOD_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmod()
 */
#define emod(x, y)                            \
  ({                                          \
    double __x = x;                           \
    double __y = y;                           \
    __x - fabs(__y) * floor(__x / fabs(__y)); \
  })



/*!BEGIN libc/tinymath/emodl.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmodl()
 */
#define emodl(x, y)                              \
  ({                                             \
    long double __x = x;                         \
    long double __y = y;                         \
    __x - fabsl(__y) * floorl(__x / fabsl(__y)); \
  })



/*!BEGIN libc/tinymath/magicu.h */

#define COSMOPOLITAN_LIBC_TINYMATH_MAGICU_H_
COSMOPOLITAN_C_START_

struct magicu {
  uint32_t M;
  uint32_t s;
};

struct magicu __magicu_get(uint32_t);

/**
 * Performs fast division using precomputed magic for constant divisor.
 *
 * @param x is unsigned integer that shall be divided
 * @param d should be `__magicu_get(y)` if computing `x / y`
 * @return result of unsigned integer division
 */
forceinline uint32_t __magicu_div(uint32_t x, struct magicu d) {
  return ((((uint64_t)x * d.M) >> 32) + ((d.s & 64) ? x : 0)) >> (d.s & 63);
}

/**
 * Checks if 𝑑 contains a valid initialized divisor.
 */
static inline bool32 __magicu_valid(struct magicu d) {
  if (!d.M && !d.s) return false;     /* uninitialized */
  if (d.s & ~(64 | 63)) return false; /* corrupted */
  return true;
}

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/x.h */

#ifndef COSMOPOLITAN_LIBC_X_H_
#define COSMOPOLITAN_LIBC_X_H_

#define xwrite        __xwrite
#define xdie          __xdie
#define xmalloc       __xmalloc
#define xrealloc      __xrealloc
#define xcalloc       __xcalloc
#define xvalloc       __xvalloc
#define xmemalign     __xmemalign
#define xmemalignzero __xmemalignzero
#define xstrdup       __xstrdup
#define xstrndup      __xstrndup
#define xstrmul       __xstrmul
#define xinet_ntop    __xinet_ntop
#define xunbinga      __xunbinga
#define xunbing       __xunbing
#define utf8to16      __utf8to16
#define utf16to8      __utf16to8
#define utf8to32      __utf8to32
#define utf16to32     __utf16to32
#define utf32to8      __utf32to8
#define xhomedir      __xhomedir
#define xstripext     __xstripext
#define xstripexts    __xstripexts
#define xload         __xload
#define rmrf          __rmrf
#define xbasename     __xbasename
#define xdirname      __xdirname
#define xjoinpaths    __xjoinpaths
#define xfixpath      __xfixpath
#define xslurp        __xslurp
#define xbarf         __xbarf

COSMOPOLITAN_C_START_

int xwrite(int, const void *, uint64_t);
void xdie(void) wontreturn;
char *xdtoa(double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoaf(float)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoal(long double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmalloc(size_t) attributeallocsize((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xrealloc(void *, size_t)
    attributeallocsize((2)) dontthrow dontcallback __wur;
void *xcalloc(size_t, size_t) attributeallocsize((1, 2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xvalloc(size_t) attributeallocsize((1)) returnsaligned((65536))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalign(size_t, size_t) attributeallocalign((1)) attributeallocsize((2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalignzero(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2))
        returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrdup(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrndup(const char *, size_t) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrcat(const char *, ...) paramsnonnull((1)) nullterminated()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
#define xstrcat(...) (xstrcat)(__VA_ARGS__, NULL)
char *xstrmul(const char *, size_t) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xinet_ntop(int, const void *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xunbinga(size_t, const char16_t *)
    attributeallocalign((1)) returnspointerwithnoaliases dontthrow dontcallback
    __wur returnsnonnull dontthrow dontcallback __wur returnsnonnull;
void *xunbing(const char16_t *)
    returnspointerwithnoaliases dontthrow dontcallback __wur
    returnsnonnull dontthrow dontcallback __wur returnsnonnull;
char16_t *utf8to16(const char *, size_t, size_t *) __wur;
char *utf16to8(const char16_t *, size_t, size_t *) __wur;
wchar_t *utf8to32(const char *, size_t, size_t *) __wur;
wchar_t *utf16to32(const char16_t *, size_t, size_t *) __wur;
char *utf32to8(const wchar_t *, size_t, size_t *) __wur;
char *xhomedir(void) __wur;
char *xstripext(const char *) __wur;
char *xstripexts(const char *) __wur;
void *xload(_Atomic(void *) *, const void *, size_t, size_t);
int rmrf(const char *);
char *xbasename(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdirname(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xjoinpaths(const char *, const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void xfixpath(void);
void *xslurp(const char *, size_t *)
    paramsnonnull((1)) returnspointerwithnoaliases returnsaligned((4096)) __wur;
int xbarf(const char *, const void *, size_t);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_X_H_ */


/*!BEGIN libc/x/xasprintf.h */

#define COSMOPOLITAN_LIBC_X_XASPRINTF_H_
COSMOPOLITAN_C_START_

char *xasprintf(const char *, ...) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xvasprintf(const char *, va_list) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xgetline.h */

#define COSMOPOLITAN_LIBC_X_XGETLINE_H_
COSMOPOLITAN_C_START_

char *xgetline(FILE *) paramsnonnull() mallocesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xsigaction.h */

#define COSMOPOLITAN_LIBC_X_XSIGACTION_H_
COSMOPOLITAN_C_START_

int xsigaction(int, void *, uint64_t, uint64_t, struct sigaction *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xspawn.h */

#define COSMOPOLITAN_LIBC_X_XSPAWN_H_
COSMOPOLITAN_C_START_

int xspawn(struct rusage *);
int xvspawn(void (*)(void *), void *, struct rusage *) returnstwice;

COSMOPOLITAN_C_END_


/*!BEGIN net/http/csscolor.h */

#define COSMOPOLITAN_NET_HTTP_CSSCOLOR_H_

#define ALICEBLUE            0xFFFFF8F0u
#define ANTIQUEWHITE         0xFFD7EBFAu
#define ANTIQUEWHITE1        0xFFDBEFFFu
#define ANTIQUEWHITE2        0xFFCCDFEEu
#define ANTIQUEWHITE3        0xFFB0C0CDu
#define ANTIQUEWHITE4        0xFF78838Bu
#define AQUAMARINE           0xFFD4FF7Fu
#define AQUAMARINE1          0xFFD4FF7Fu
#define AQUAMARINE2          0xFFC6EE76u
#define AQUAMARINE3          0xFFAACD66u
#define AQUAMARINE4          0xFF748B45u
#define AZURE                0xFFFFFFF0u
#define AZURE1               0xFFFFFFF0u
#define AZURE2               0xFFEEEEE0u
#define AZURE3               0xFFCDCDC1u
#define AZURE4               0xFF8B8B83u
#define BEIGE                0xFFDCF5F5u
#define BISQUE               0xFFC4E4FFu
#define BISQUE1              0xFFC4E4FFu
#define BISQUE2              0xFFB7D5EEu
#define BISQUE3              0xFF9EB7CDu
#define BISQUE4              0xFF6B7D8Bu
#define BLACK                0xFF000000u
#define BLANCHEDALMOND       0xFFCDEBFFu
#define BLUE                 0xFFFF0000u
#define BLUE1                0xFFFF0000u
#define BLUE2                0xFFEE0000u
#define BLUE3                0xFFCD0000u
#define BLUE4                0xFF8B0000u
#define BLUEVIOLET           0xFFE22B8Au
#define BROWN                0xFF2A2AA5u
#define BROWN1               0xFF4040FFu
#define BROWN2               0xFF3B3BEEu
#define BROWN3               0xFF3333CDu
#define BROWN4               0xFF23238Bu
#define BURLYWOOD            0xFF87B8DEu
#define BURLYWOOD1           0xFF9BD3FFu
#define BURLYWOOD2           0xFF91C5EEu
#define BURLYWOOD3           0xFF7DAACDu
#define BURLYWOOD4           0xFF55738Bu
#define CADETBLUE            0xFFA09E5Fu
#define CADETBLUE1           0xFFFFF598u
#define CADETBLUE2           0xFFEEE58Eu
#define CADETBLUE3           0xFFCDC57Au
#define CADETBLUE4           0xFF8B8653u
#define CHARTREUSE           0xFF00FF7Fu
#define CHARTREUSE1          0xFF00FF7Fu
#define CHARTREUSE2          0xFF00EE76u
#define CHARTREUSE3          0xFF00CD66u
#define CHARTREUSE4          0xFF008B45u
#define CHOCOLATE            0xFF1E69D2u
#define CHOCOLATE1           0xFF247FFFu
#define CHOCOLATE2           0xFF2176EEu
#define CHOCOLATE3           0xFF1D66CDu
#define CHOCOLATE4           0xFF13458Bu
#define CORAL                0xFF507FFFu
#define CORAL1               0xFF5672FFu
#define CORAL2               0xFF506AEEu
#define CORAL3               0xFF455BCDu
#define CORAL4               0xFF2F3E8Bu
#define CORNFLOWERBLUE       0xFFED9564u
#define CORNSILK             0xFFDCF8FFu
#define CORNSILK1            0xFFDCF8FFu
#define CORNSILK2            0xFFCDE8EEu
#define CORNSILK3            0xFFB1C8CDu
#define CORNSILK4            0xFF78888Bu
#define CYAN                 0xFFFFFF00u
#define CYAN1                0xFFFFFF00u
#define CYAN2                0xFFEEEE00u
#define CYAN3                0xFFCDCD00u
#define CYAN4                0xFF8B8B00u
#define DARKBLUE             0xFF8B0000u
#define DARKCYAN             0xFF8B8B00u
#define DARKGOLDENROD        0xFF0B86B8u
#define DARKGOLDENROD1       0xFF0FB9FFu
#define DARKGOLDENROD2       0xFF0EADEEu
#define DARKGOLDENROD3       0xFF0C95CDu
#define DARKGOLDENROD4       0xFF08658Bu
#define DARKGRAY             0xFFA9A9A9u
#define DARKGREEN            0xFF006400u
#define DARKGREY             0xFFA9A9A9u
#define DARKKHAKI            0xFF6BB7BDu
#define DARKMAGENTA          0xFF8B008Bu
#define DARKOLIVEGREEN       0xFF2F6B55u
#define DARKOLIVEGREEN1      0xFF70FFCAu
#define DARKOLIVEGREEN2      0xFF68EEBCu
#define DARKOLIVEGREEN3      0xFF5ACDA2u
#define DARKOLIVEGREEN4      0xFF3D8B6Eu
#define DARKORANGE           0xFF008CFFu
#define DARKORANGE1          0xFF007FFFu
#define DARKORANGE2          0xFF0076EEu
#define DARKORANGE3          0xFF0066CDu
#define DARKORANGE4          0xFF00458Bu
#define DARKORCHID           0xFFCC3299u
#define DARKORCHID1          0xFFFF3EBFu
#define DARKORCHID2          0xFFEE3AB2u
#define DARKORCHID3          0xFFCD329Au
#define DARKORCHID4          0xFF8B2268u
#define DARKRED              0xFF00008Bu
#define DARKSALMON           0xFF7A96E9u
#define DARKSEAGREEN         0xFF8FBC8Fu
#define DARKSEAGREEN1        0xFFC1FFC1u
#define DARKSEAGREEN2        0xFFB4EEB4u
#define DARKSEAGREEN3        0xFF9BCD9Bu
#define DARKSEAGREEN4        0xFF698B69u
#define DARKSLATEBLUE        0xFF8B3D48u
#define DARKSLATEGRAY        0xFF4F4F2Fu
#define DARKSLATEGRAY1       0xFFFFFF97u
#define DARKSLATEGRAY2       0xFFEEEE8Du
#define DARKSLATEGRAY3       0xFFCDCD79u
#define DARKSLATEGRAY4       0xFF8B8B52u
#define DARKSLATEGREY        0xFF4F4F2Fu
#define DARKTURQUOISE        0xFFD1CE00u
#define DARKVIOLET           0xFFD30094u
#define DEEPPINK             0xFF9314FFu
#define DEEPPINK1            0xFF9314FFu
#define DEEPPINK2            0xFF8912EEu
#define DEEPPINK3            0xFF7610CDu
#define DEEPPINK4            0xFF500A8Bu
#define DEEPSKYBLUE          0xFFFFBF00u
#define DEEPSKYBLUE1         0xFFFFBF00u
#define DEEPSKYBLUE2         0xFFEEB200u
#define DEEPSKYBLUE3         0xFFCD9A00u
#define DEEPSKYBLUE4         0xFF8B6800u
#define DIMGRAY              0xFF696969u
#define DIMGREY              0xFF696969u
#define DODGERBLUE           0xFFFF901Eu
#define DODGERBLUE1          0xFFFF901Eu
#define DODGERBLUE2          0xFFEE861Cu
#define DODGERBLUE3          0xFFCD7418u
#define DODGERBLUE4          0xFF8B4E10u
#define FIREBRICK            0xFF2222B2u
#define FIREBRICK1           0xFF3030FFu
#define FIREBRICK2           0xFF2C2CEEu
#define FIREBRICK3           0xFF2626CDu
#define FIREBRICK4           0xFF1A1A8Bu
#define FLORALWHITE          0xFFF0FAFFu
#define FORESTGREEN          0xFF228B22u
#define GAINSBORO            0xFFDCDCDCu
#define GHOSTWHITE           0xFFFFF8F8u
#define GOLD                 0xFF00D7FFu
#define GOLD1                0xFF00D7FFu
#define GOLD2                0xFF00C9EEu
#define GOLD3                0xFF00ADCDu
#define GOLD4                0xFF00758Bu
#define GOLDENROD            0xFF20A5DAu
#define GOLDENROD1           0xFF25C1FFu
#define GOLDENROD2           0xFF22B4EEu
#define GOLDENROD3           0xFF1D9BCDu
#define GOLDENROD4           0xFF14698Bu
#define GRAY                 0xFFBEBEBEu
#define GRAY0                0xFF000000u
#define GRAY1                0xFF030303u
#define GRAY10               0xFF1A1A1Au
#define GRAY100              0xFFFFFFFFu
#define GRAY11               0xFF1C1C1Cu
#define GRAY12               0xFF1F1F1Fu
#define GRAY13               0xFF212121u
#define GRAY14               0xFF242424u
#define GRAY15               0xFF262626u
#define GRAY16               0xFF292929u
#define GRAY17               0xFF2B2B2Bu
#define GRAY18               0xFF2E2E2Eu
#define GRAY19               0xFF303030u
#define GRAY2                0xFF050505u
#define GRAY20               0xFF333333u
#define GRAY21               0xFF363636u
#define GRAY22               0xFF383838u
#define GRAY23               0xFF3B3B3Bu
#define GRAY24               0xFF3D3D3Du
#define GRAY25               0xFF404040u
#define GRAY26               0xFF424242u
#define GRAY27               0xFF454545u
#define GRAY28               0xFF474747u
#define GRAY29               0xFF4A4A4Au
#define GRAY3                0xFF080808u
#define GRAY30               0xFF4D4D4Du
#define GRAY31               0xFF4F4F4Fu
#define GRAY32               0xFF525252u
#define GRAY33               0xFF545454u
#define GRAY34               0xFF575757u
#define GRAY35               0xFF595959u
#define GRAY36               0xFF5C5C5Cu
#define GRAY37               0xFF5E5E5Eu
#define GRAY38               0xFF616161u
#define GRAY39               0xFF636363u
#define GRAY4                0xFF0A0A0Au
#define GRAY40               0xFF666666u
#define GRAY41               0xFF696969u
#define GRAY42               0xFF6B6B6Bu
#define GRAY43               0xFF6E6E6Eu
#define GRAY44               0xFF707070u
#define GRAY45               0xFF737373u
#define GRAY46               0xFF757575u
#define GRAY47               0xFF787878u
#define GRAY48               0xFF7A7A7Au
#define GRAY49               0xFF7D7D7Du
#define GRAY5                0xFF0D0D0Du
#define GRAY50               0xFF7F7F7Fu
#define GRAY51               0xFF828282u
#define GRAY52               0xFF858585u
#define GRAY53               0xFF878787u
#define GRAY54               0xFF8A8A8Au
#define GRAY55               0xFF8C8C8Cu
#define GRAY56               0xFF8F8F8Fu
#define GRAY57               0xFF919191u
#define GRAY58               0xFF949494u
#define GRAY59               0xFF969696u
#define GRAY6                0xFF0F0F0Fu
#define GRAY60               0xFF999999u
#define GRAY61               0xFF9C9C9Cu
#define GRAY62               0xFF9E9E9Eu
#define GRAY63               0xFFA1A1A1u
#define GRAY64               0xFFA3A3A3u
#define GRAY65               0xFFA6A6A6u
#define GRAY66               0xFFA8A8A8u
#define GRAY67               0xFFABABABu
#define GRAY68               0xFFADADADu
#define GRAY69               0xFFB0B0B0u
#define GRAY7                0xFF121212u
#define GRAY70               0xFFB3B3B3u
#define GRAY71               0xFFB5B5B5u
#define GRAY72               0xFFB8B8B8u
#define GRAY73               0xFFBABABAu
#define GRAY74               0xFFBDBDBDu
#define GRAY75               0xFFBFBFBFu
#define GRAY76               0xFFC2C2C2u
#define GRAY77               0xFFC4C4C4u
#define GRAY78               0xFFC7C7C7u
#define GRAY79               0xFFC9C9C9u
#define GRAY8                0xFF141414u
#define GRAY80               0xFFCCCCCCu
#define GRAY81               0xFFCFCFCFu
#define GRAY82               0xFFD1D1D1u
#define GRAY83               0xFFD4D4D4u
#define GRAY84               0xFFD6D6D6u
#define GRAY85               0xFFD9D9D9u
#define GRAY86               0xFFDBDBDBu
#define GRAY87               0xFFDEDEDEu
#define GRAY88               0xFFE0E0E0u
#define GRAY89               0xFFE3E3E3u
#define GRAY9                0xFF171717u
#define GRAY90               0xFFE5E5E5u
#define GRAY91               0xFFE8E8E8u
#define GRAY92               0xFFEBEBEBu
#define GRAY93               0xFFEDEDEDu
#define GRAY94               0xFFF0F0F0u
#define GRAY95               0xFFF2F2F2u
#define GRAY96               0xFFF5F5F5u
#define GRAY97               0xFFF7F7F7u
#define GRAY98               0xFFFAFAFAu
#define GRAY99               0xFFFCFCFCu
#define GREEN                0xFF00FF00u
#define GREEN1               0xFF00FF00u
#define GREEN2               0xFF00EE00u
#define GREEN3               0xFF00CD00u
#define GREEN4               0xFF008B00u
#define GREENYELLOW          0xFF2FFFADu
#define GREY                 0xFFBEBEBEu
#define GREY0                0xFF000000u
#define GREY1                0xFF030303u
#define GREY10               0xFF1A1A1Au
#define GREY100              0xFFFFFFFFu
#define GREY11               0xFF1C1C1Cu
#define GREY12               0xFF1F1F1Fu
#define GREY13               0xFF212121u
#define GREY14               0xFF242424u
#define GREY15               0xFF262626u
#define GREY16               0xFF292929u
#define GREY17               0xFF2B2B2Bu
#define GREY18               0xFF2E2E2Eu
#define GREY19               0xFF303030u
#define GREY2                0xFF050505u
#define GREY20               0xFF333333u
#define GREY21               0xFF363636u
#define GREY22               0xFF383838u
#define GREY23               0xFF3B3B3Bu
#define GREY24               0xFF3D3D3Du
#define GREY25               0xFF404040u
#define GREY26               0xFF424242u
#define GREY27               0xFF454545u
#define GREY28               0xFF474747u
#define GREY29               0xFF4A4A4Au
#define GREY3                0xFF080808u
#define GREY30               0xFF4D4D4Du
#define GREY31               0xFF4F4F4Fu
#define GREY32               0xFF525252u
#define GREY33               0xFF545454u
#define GREY34               0xFF575757u
#define GREY35               0xFF595959u
#define GREY36               0xFF5C5C5Cu
#define GREY37               0xFF5E5E5Eu
#define GREY38               0xFF616161u
#define GREY39               0xFF636363u
#define GREY4                0xFF0A0A0Au
#define GREY40               0xFF666666u
#define GREY41               0xFF696969u
#define GREY42               0xFF6B6B6Bu
#define GREY43               0xFF6E6E6Eu
#define GREY44               0xFF707070u
#define GREY45               0xFF737373u
#define GREY46               0xFF757575u
#define GREY47               0xFF787878u
#define GREY48               0xFF7A7A7Au
#define GREY49               0xFF7D7D7Du
#define GREY5                0xFF0D0D0Du
#define GREY50               0xFF7F7F7Fu
#define GREY51               0xFF828282u
#define GREY52               0xFF858585u
#define GREY53               0xFF878787u
#define GREY54               0xFF8A8A8Au
#define GREY55               0xFF8C8C8Cu
#define GREY56               0xFF8F8F8Fu
#define GREY57               0xFF919191u
#define GREY58               0xFF949494u
#define GREY59               0xFF969696u
#define GREY6                0xFF0F0F0Fu
#define GREY60               0xFF999999u
#define GREY61               0xFF9C9C9Cu
#define GREY62               0xFF9E9E9Eu
#define GREY63               0xFFA1A1A1u
#define GREY64               0xFFA3A3A3u
#define GREY65               0xFFA6A6A6u
#define GREY66               0xFFA8A8A8u
#define GREY67               0xFFABABABu
#define GREY68               0xFFADADADu
#define GREY69               0xFFB0B0B0u
#define GREY7                0xFF121212u
#define GREY70               0xFFB3B3B3u
#define GREY71               0xFFB5B5B5u
#define GREY72               0xFFB8B8B8u
#define GREY73               0xFFBABABAu
#define GREY74               0xFFBDBDBDu
#define GREY75               0xFFBFBFBFu
#define GREY76               0xFFC2C2C2u
#define GREY77               0xFFC4C4C4u
#define GREY78               0xFFC7C7C7u
#define GREY79               0xFFC9C9C9u
#define GREY8                0xFF141414u
#define GREY80               0xFFCCCCCCu
#define GREY81               0xFFCFCFCFu
#define GREY82               0xFFD1D1D1u
#define GREY83               0xFFD4D4D4u
#define GREY84               0xFFD6D6D6u
#define GREY85               0xFFD9D9D9u
#define GREY86               0xFFDBDBDBu
#define GREY87               0xFFDEDEDEu
#define GREY88               0xFFE0E0E0u
#define GREY89               0xFFE3E3E3u
#define GREY9                0xFF171717u
#define GREY90               0xFFE5E5E5u
#define GREY91               0xFFE8E8E8u
#define GREY92               0xFFEBEBEBu
#define GREY93               0xFFEDEDEDu
#define GREY94               0xFFF0F0F0u
#define GREY95               0xFFF2F2F2u
#define GREY96               0xFFF5F5F5u
#define GREY97               0xFFF7F7F7u
#define GREY98               0xFFFAFAFAu
#define GREY99               0xFFFCFCFCu
#define HONEYDEW             0xFFF0FFF0u
#define HONEYDEW1            0xFFF0FFF0u
#define HONEYDEW2            0xFFE0EEE0u
#define HONEYDEW3            0xFFC1CDC1u
#define HONEYDEW4            0xFF838B83u
#define HOTPINK              0xFFB469FFu
#define HOTPINK1             0xFFB46EFFu
#define HOTPINK2             0xFFA76AEEu
#define HOTPINK3             0xFF9060CDu
#define HOTPINK4             0xFF623A8Bu
#define INDIANRED            0xFF5C5CCDu
#define INDIANRED1           0xFF6A6AFFu
#define INDIANRED2           0xFF6363EEu
#define INDIANRED3           0xFF5555CDu
#define INDIANRED4           0xFF3A3A8Bu
#define IVORY                0xFFF0FFFFu
#define IVORY1               0xFFF0FFFFu
#define IVORY2               0xFFE0EEEEu
#define IVORY3               0xFFC1CDCDu
#define IVORY4               0xFF838B8Bu
#define KHAKI                0xFF8CE6F0u
#define KHAKI1               0xFF8FF6FFu
#define KHAKI2               0xFF85E6EEu
#define KHAKI3               0xFF73C6CDu
#define KHAKI4               0xFF4E868Bu
#define LAVENDER             0xFFFAE6E6u
#define LAVENDERBLUSH        0xFFF5F0FFu
#define LAVENDERBLUSH1       0xFFF5F0FFu
#define LAVENDERBLUSH2       0xFFE5E0EEu
#define LAVENDERBLUSH3       0xFFC5C1CDu
#define LAVENDERBLUSH4       0xFF86838Bu
#define LAWNGREEN            0xFF00FC7Cu
#define LEMONCHIFFON         0xFFCDFAFFu
#define LEMONCHIFFON1        0xFFCDFAFFu
#define LEMONCHIFFON2        0xFFBFE9EEu
#define LEMONCHIFFON3        0xFFA5C9CDu
#define LEMONCHIFFON4        0xFF70898Bu
#define LIGHTBLUE            0xFFE6D8ADu
#define LIGHTBLUE1           0xFFFFEFBFu
#define LIGHTBLUE2           0xFFEEDFB2u
#define LIGHTBLUE3           0xFFCDC09Au
#define LIGHTBLUE4           0xFF8B8368u
#define LIGHTCORAL           0xFF8080F0u
#define LIGHTCYAN            0xFFFFFFE0u
#define LIGHTCYAN1           0xFFFFFFE0u
#define LIGHTCYAN2           0xFFEEEED1u
#define LIGHTCYAN3           0xFFCDCDB4u
#define LIGHTCYAN4           0xFF8B8B7Au
#define LIGHTGOLDENROD       0xFF82DDEEu
#define LIGHTGOLDENROD1      0xFF8BECFFu
#define LIGHTGOLDENROD2      0xFF82DCEEu
#define LIGHTGOLDENROD3      0xFF70BECDu
#define LIGHTGOLDENROD4      0xFF4C818Bu
#define LIGHTGOLDENRODYELLOW 0xFFD2FAFAu
#define LIGHTGRAY            0xFFD3D3D3u
#define LIGHTGREEN           0xFF90EE90u
#define LIGHTGREY            0xFFD3D3D3u
#define LIGHTPINK            0xFFC1B6FFu
#define LIGHTPINK1           0xFFB9AEFFu
#define LIGHTPINK2           0xFFADA2EEu
#define LIGHTPINK3           0xFF958CCDu
#define LIGHTPINK4           0xFF655F8Bu
#define LIGHTSALMON          0xFF7AA0FFu
#define LIGHTSALMON1         0xFF7AA0FFu
#define LIGHTSALMON2         0xFF7295EEu
#define LIGHTSALMON3         0xFF6281CDu
#define LIGHTSALMON4         0xFF42578Bu
#define LIGHTSEAGREEN        0xFFAAB220u
#define LIGHTSKYBLUE         0xFFFACE87u
#define LIGHTSKYBLUE1        0xFFFFE2B0u
#define LIGHTSKYBLUE2        0xFFEED3A4u
#define LIGHTSKYBLUE3        0xFFCDB68Du
#define LIGHTSKYBLUE4        0xFF8B7B60u
#define LIGHTSLATEBLUE       0xFFFF7084u
#define LIGHTSLATEGRAY       0xFF998877u
#define LIGHTSLATEGREY       0xFF998877u
#define LIGHTSTEELBLUE       0xFFDEC4B0u
#define LIGHTSTEELBLUE1      0xFFFFE1CAu
#define LIGHTSTEELBLUE2      0xFFEED2BCu
#define LIGHTSTEELBLUE3      0xFFCDB5A2u
#define LIGHTSTEELBLUE4      0xFF8B7B6Eu
#define LIGHTYELLOW          0xFFE0FFFFu
#define LIGHTYELLOW1         0xFFE0FFFFu
#define LIGHTYELLOW2         0xFFD1EEEEu
#define LIGHTYELLOW3         0xFFB4CDCDu
#define LIGHTYELLOW4         0xFF7A8B8Bu
#define LIMEGREEN            0xFF32CD32u
#define LINEN                0xFFE6F0FAu
#define MAGENTA              0xFFFF00FFu
#define MAGENTA1             0xFFFF00FFu
#define MAGENTA2             0xFFEE00EEu
#define MAGENTA3             0xFFCD00CDu
#define MAGENTA4             0xFF8B008Bu
#define MAROON               0xFF6030B0u
#define MAROON1              0xFFB334FFu
#define MAROON2              0xFFA730EEu
#define MAROON3              0xFF9029CDu
#define MAROON4              0xFF621C8Bu
#define MEDIUMAQUAMARINE     0xFFAACD66u
#define MEDIUMBLUE           0xFFCD0000u
#define MEDIUMORCHID         0xFFD355BAu
#define MEDIUMORCHID1        0xFFFF66E0u
#define MEDIUMORCHID2        0xFFEE5FD1u
#define MEDIUMORCHID3        0xFFCD52B4u
#define MEDIUMORCHID4        0xFF8B377Au
#define MEDIUMPURPLE         0xFFDB7093u
#define MEDIUMPURPLE1        0xFFFF82ABu
#define MEDIUMPURPLE2        0xFFEE799Fu
#define MEDIUMPURPLE3        0xFFCD6889u
#define MEDIUMPURPLE4        0xFF8B475Du
#define MEDIUMSEAGREEN       0xFF71B33Cu
#define MEDIUMSLATEBLUE      0xFFEE687Bu
#define MEDIUMSPRINGGREEN    0xFF9AFA00u
#define MEDIUMTURQUOISE      0xFFCCD148u
#define MEDIUMVIOLETRED      0xFF8515C7u
#define MIDNIGHTBLUE         0xFF701919u
#define MINTCREAM            0xFFFAFFF5u
#define MISTYROSE            0xFFE1E4FFu
#define MISTYROSE1           0xFFE1E4FFu
#define MISTYROSE2           0xFFD2D5EEu
#define MISTYROSE3           0xFFB5B7CDu
#define MISTYROSE4           0xFF7B7D8Bu
#define MOCCASIN             0xFFB5E4FFu
#define NAVAJOWHITE          0xFFADDEFFu
#define NAVAJOWHITE1         0xFFADDEFFu
#define NAVAJOWHITE2         0xFFA1CFEEu
#define NAVAJOWHITE3         0xFF8BB3CDu
#define NAVAJOWHITE4         0xFF5E798Bu
#define NAVY                 0xFF800000u
#define NAVYBLUE             0xFF800000u
#define OLDLACE              0xFFE6F5FDu
#define OLIVEDRAB            0xFF238E6Bu
#define OLIVEDRAB1           0xFF3EFFC0u
#define OLIVEDRAB2           0xFF3AEEB3u
#define OLIVEDRAB3           0xFF32CD9Au
#define OLIVEDRAB4           0xFF228B69u
#define ORANGE               0xFF00A5FFu
#define ORANGE1              0xFF00A5FFu
#define ORANGE2              0xFF009AEEu
#define ORANGE3              0xFF0085CDu
#define ORANGE4              0xFF005A8Bu
#define ORANGERED            0xFF0045FFu
#define ORANGERED1           0xFF0045FFu
#define ORANGERED2           0xFF0040EEu
#define ORANGERED3           0xFF0037CDu
#define ORANGERED4           0xFF00258Bu
#define ORCHID               0xFFD670DAu
#define ORCHID1              0xFFFA83FFu
#define ORCHID2              0xFFE97AEEu
#define ORCHID3              0xFFC969CDu
#define ORCHID4              0xFF89478Bu
#define PALEGOLDENROD        0xFFAAE8EEu
#define PALEGREEN            0xFF98FB98u
#define PALEGREEN1           0xFF9AFF9Au
#define PALEGREEN2           0xFF90EE90u
#define PALEGREEN3           0xFF7CCD7Cu
#define PALEGREEN4           0xFF548B54u
#define PALETURQUOISE        0xFFEEEEAFu
#define PALETURQUOISE1       0xFFFFFFBBu
#define PALETURQUOISE2       0xFFEEEEAEu
#define PALETURQUOISE3       0xFFCDCD96u
#define PALETURQUOISE4       0xFF8B8B66u
#define PALEVIOLETRED        0xFF9370DBu
#define PALEVIOLETRED1       0xFFAB82FFu
#define PALEVIOLETRED2       0xFF9F79EEu
#define PALEVIOLETRED3       0xFF8968CDu
#define PALEVIOLETRED4       0xFF5D478Bu
#define PAPAYAWHIP           0xFFD5EFFFu
#define PEACHPUFF            0xFFB9DAFFu
#define PEACHPUFF1           0xFFB9DAFFu
#define PEACHPUFF2           0xFFADCBEEu
#define PEACHPUFF3           0xFF95AFCDu
#define PEACHPUFF4           0xFF65778Bu
#define PERU                 0xFF3F85CDu
#define PINK                 0xFFCBC0FFu
#define PINK1                0xFFC5B5FFu
#define PINK2                0xFFB8A9EEu
#define PINK3                0xFF9E91CDu
#define PINK4                0xFF6C638Bu
#define PLUM                 0xFFDDA0DDu
#define PLUM1                0xFFFFBBFFu
#define PLUM2                0xFFEEAEEEu
#define PLUM3                0xFFCD96CDu
#define PLUM4                0xFF8B668Bu
#define POWDERBLUE           0xFFE6E0B0u
#define PURPLE               0xFFF020A0u
#define PURPLE1              0xFFFF309Bu
#define PURPLE2              0xFFEE2C91u
#define PURPLE3              0xFFCD267Du
#define PURPLE4              0xFF8B1A55u
#define RED                  0xFF0000FFu
#define RED1                 0xFF0000FFu
#define RED2                 0xFF0000EEu
#define RED3                 0xFF0000CDu
#define RED4                 0xFF00008Bu
#define ROSYBROWN            0xFF8F8FBCu
#define ROSYBROWN1           0xFFC1C1FFu
#define ROSYBROWN2           0xFFB4B4EEu
#define ROSYBROWN3           0xFF9B9BCDu
#define ROSYBROWN4           0xFF69698Bu
#define ROYALBLUE            0xFFE16941u
#define ROYALBLUE1           0xFFFF7648u
#define ROYALBLUE2           0xFFEE6E43u
#define ROYALBLUE3           0xFFCD5F3Au
#define ROYALBLUE4           0xFF8B4027u
#define SADDLEBROWN          0xFF13458Bu
#define SALMON               0xFF7280FAu
#define SALMON1              0xFF698CFFu
#define SALMON2              0xFF6282EEu
#define SALMON3              0xFF5470CDu
#define SALMON4              0xFF394C8Bu
#define SANDYBROWN           0xFF60A4F4u
#define SEAGREEN             0xFF578B2Eu
#define SEAGREEN1            0xFF9FFF54u
#define SEAGREEN2            0xFF94EE4Eu
#define SEAGREEN3            0xFF80CD43u
#define SEAGREEN4            0xFF578B2Eu
#define SEASHELL             0xFFEEF5FFu
#define SEASHELL1            0xFFEEF5FFu
#define SEASHELL2            0xFFDEE5EEu
#define SEASHELL3            0xFFBFC5CDu
#define SEASHELL4            0xFF82868Bu
#define SIENNA               0xFF2D52A0u
#define SIENNA1              0xFF4782FFu
#define SIENNA2              0xFF4279EEu
#define SIENNA3              0xFF3968CDu
#define SIENNA4              0xFF26478Bu
#define SKYBLUE              0xFFEBCE87u
#define SKYBLUE1             0xFFFFCE87u
#define SKYBLUE2             0xFFEEC07Eu
#define SKYBLUE3             0xFFCDA66Cu
#define SKYBLUE4             0xFF8B704Au
#define SLATEBLUE            0xFFCD5A6Au
#define SLATEBLUE1           0xFFFF6F83u
#define SLATEBLUE2           0xFFEE677Au
#define SLATEBLUE3           0xFFCD5969u
#define SLATEBLUE4           0xFF8B3C47u
#define SLATEGRAY            0xFF908070u
#define SLATEGRAY1           0xFFFFE2C6u
#define SLATEGRAY2           0xFFEED3B9u
#define SLATEGRAY3           0xFFCDB69Fu
#define SLATEGRAY4           0xFF8B7B6Cu
#define SLATEGREY            0xFF908070u
#define SNOW                 0xFFFAFAFFu
#define SNOW1                0xFFFAFAFFu
#define SNOW2                0xFFE9E9EEu
#define SNOW3                0xFFC9C9CDu
#define SNOW4                0xFF89898Bu
#define SPRINGGREEN          0xFF7FFF00u
#define SPRINGGREEN1         0xFF7FFF00u
#define SPRINGGREEN2         0xFF76EE00u
#define SPRINGGREEN3         0xFF66CD00u
#define SPRINGGREEN4         0xFF458B00u
#define STEELBLUE            0xFFB48246u
#define STEELBLUE1           0xFFFFB863u
#define STEELBLUE2           0xFFEEAC5Cu
#define STEELBLUE3           0xFFCD944Fu
#define STEELBLUE4           0xFF8B6436u
#define TAN                  0xFF8CB4D2u
#define TAN1                 0xFF4FA5FFu
#define TAN2                 0xFF499AEEu
#define TAN3                 0xFF3F85CDu
#define TAN4                 0xFF2B5A8Bu
#define THISTLE              0xFFD8BFD8u
#define THISTLE1             0xFFFFE1FFu
#define THISTLE2             0xFFEED2EEu
#define THISTLE3             0xFFCDB5CDu
#define THISTLE4             0xFF8B7B8Bu
#define TOMATO               0xFF4763FFu
#define TOMATO1              0xFF4763FFu
#define TOMATO2              0xFF425CEEu
#define TOMATO3              0xFF394FCDu
#define TOMATO4              0xFF26368Bu
#define TURQUOISE            0xFFD0E040u
#define TURQUOISE1           0xFFFFF500u
#define TURQUOISE2           0xFFEEE500u
#define TURQUOISE3           0xFFCDC500u
#define TURQUOISE4           0xFF8B8600u
#define VIOLET               0xFFEE82EEu
#define VIOLETRED            0xFF9020D0u
#define VIOLETRED1           0xFF963EFFu
#define VIOLETRED2           0xFF8C3AEEu
#define VIOLETRED3           0xFF7832CDu
#define VIOLETRED4           0xFF52228Bu
#define WHEAT                0xFFB3DEF5u
#define WHEAT1               0xFFBAE7FFu
#define WHEAT2               0xFFAED8EEu
#define WHEAT3               0xFF96BACDu
#define WHEAT4               0xFF667E8Bu
#define WHITE                0xFFFFFFFFu
#define WHITESMOKE           0xFFF5F5F5u
#define YELLOW               0xFF00FFFFu
#define YELLOW1              0xFF00FFFFu
#define YELLOW2              0xFF00EEEEu
#define YELLOW3              0xFF00CDCDu
#define YELLOW4              0xFF008B8Bu
#define YELLOWGREEN          0xFF32CD9Au



/*!BEGIN net/http/escape.h */

#define COSMOPOLITAN_NET_HTTP_ESCAPE_H_

#define kControlWs 1
#define kControlC0 2
#define kControlC1 4

COSMOPOLITAN_C_START_

extern const char kEscapeAuthority[256];
extern const char kEscapeIp[256];
extern const char kEscapePath[256];
extern const char kEscapeSegment[256];
extern const char kEscapeParam[256];
extern const char kEscapeFragment[256];

char *EscapeHtml(const char *, size_t, size_t *);
char *EscapeUrl(const char *, size_t, size_t *, const char[256]);
char *EscapeUser(const char *, size_t, size_t *);
char *EscapePass(const char *, size_t, size_t *);
char *EscapeIp(const char *, size_t, size_t *);
char *EscapeHost(const char *, size_t, size_t *);
char *EscapePath(const char *, size_t, size_t *);
char *EscapeParam(const char *, size_t, size_t *);
char *EscapeFragment(const char *, size_t, size_t *);
char *EscapeSegment(const char *, size_t, size_t *);
char *EscapeJsStringLiteral(char **, size_t *, const char *, size_t, size_t *);

ssize_t HasControlCodes(const char *, size_t, int);
char *Underlong(const char *, size_t, size_t *);
char *DecodeLatin1(const char *, size_t, size_t *);
char *EncodeLatin1(const char *, size_t, size_t *, int);
char *EncodeHttpHeaderValue(const char *, size_t, size_t *);
char *VisualizeControlCodes(const char *, size_t, size_t *);
char *IndentLines(const char *, size_t, size_t *, size_t);
char *EncodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *DecodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *EncodeBase64(const char *, size_t, size_t *);
char *DecodeBase64(const char *, size_t, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/http.h */

#define COSMOPOLITAN_LIBC_HTTP_HTTP_H_

#define kHttpRequest  0
#define kHttpResponse 1

#define kHttpGet     READ32LE("GET")
#define kHttpHead    READ32LE("HEAD")
#define kHttpPost    READ32LE("POST")
#define kHttpPut     READ32LE("PUT")
#define kHttpDelete  READ64LE("DELETE\0")
#define kHttpOptions READ64LE("OPTIONS")
#define kHttpConnect READ64LE("CONNECT")
#define kHttpTrace   READ64LE("TRACE\0\0")

#define kHttpStateStart   0
#define kHttpStateMethod  1
#define kHttpStateUri     2
#define kHttpStateVersion 3
#define kHttpStateStatus  4
#define kHttpStateMessage 5
#define kHttpStateName    6
#define kHttpStateColon   7
#define kHttpStateValue   8
#define kHttpStateCr      9
#define kHttpStateLf1     10
#define kHttpStateLf2     11

#define kHttpClientStateHeaders      0
#define kHttpClientStateBody         1
#define kHttpClientStateBodyChunked  2
#define kHttpClientStateBodyLengthed 3

#define kHttpStateChunkStart   0
#define kHttpStateChunkSize    1
#define kHttpStateChunkExt     2
#define kHttpStateChunkLf1     3
#define kHttpStateChunk        4
#define kHttpStateChunkCr2     5
#define kHttpStateChunkLf2     6
#define kHttpStateTrailerStart 7
#define kHttpStateTrailer      8
#define kHttpStateTrailerLf1   9
#define kHttpStateTrailerLf2   10

#define kHttpHost                          0
#define kHttpCacheControl                  1
#define kHttpConnection                    2
#define kHttpAccept                        3
#define kHttpAcceptLanguage                4
#define kHttpAcceptEncoding                5
#define kHttpUserAgent                     6
#define kHttpReferer                       7
#define kHttpXForwardedFor                 8
#define kHttpOrigin                        9
#define kHttpUpgradeInsecureRequests       10
#define kHttpPragma                        11
#define kHttpCookie                        12
#define kHttpDnt                           13
#define kHttpSecGpc                        14
#define kHttpFrom                          15
#define kHttpIfModifiedSince               16
#define kHttpXRequestedWith                17
#define kHttpXForwardedHost                18
#define kHttpXForwardedProto               19
#define kHttpXCsrfToken                    20
#define kHttpSaveData                      21
#define kHttpRange                         22
#define kHttpContentLength                 23
#define kHttpContentType                   24
#define kHttpVary                          25
#define kHttpDate                          26
#define kHttpServer                        27
#define kHttpExpires                       28
#define kHttpContentEncoding               29
#define kHttpLastModified                  30
#define kHttpEtag                          31
#define kHttpAllow                         32
#define kHttpContentRange                  33
#define kHttpAcceptCharset                 34
#define kHttpAccessControlAllowCredentials 35
#define kHttpAccessControlAllowHeaders     36
#define kHttpAccessControlAllowMethods     37
#define kHttpAccessControlAllowOrigin      38
#define kHttpAccessControlMaxAge           39
#define kHttpAccessControlMethod           40
#define kHttpAccessControlRequestHeaders   41
#define kHttpAccessControlRequestMethod    42
#define kHttpAccessControlRequestMethods   43
#define kHttpAge                           44
#define kHttpAuthorization                 45
#define kHttpContentBase                   46
#define kHttpContentDescription            47
#define kHttpContentDisposition            48
#define kHttpContentLanguage               49
#define kHttpContentLocation               50
#define kHttpContentMd5                    51
#define kHttpExpect                        52
#define kHttpIfMatch                       53
#define kHttpIfNoneMatch                   54
#define kHttpIfRange                       55
#define kHttpIfUnmodifiedSince             56
#define kHttpKeepAlive                     57
#define kHttpLink                          58
#define kHttpLocation                      59
#define kHttpMaxForwards                   60
#define kHttpProxyAuthenticate             61
#define kHttpProxyAuthorization            62
#define kHttpProxyConnection               63
#define kHttpPublic                        64
#define kHttpRetryAfter                    65
#define kHttpTe                            66
#define kHttpTrailer                       67
#define kHttpTransferEncoding              68
#define kHttpUpgrade                       69
#define kHttpWarning                       70
#define kHttpWwwAuthenticate               71
#define kHttpVia                           72
#define kHttpStrictTransportSecurity       73
#define kHttpXFrameOptions                 74
#define kHttpXContentTypeOptions           75
#define kHttpAltSvc                        76
#define kHttpReferrerPolicy                77
#define kHttpXXssProtection                78
#define kHttpAcceptRanges                  79
#define kHttpSetCookie                     80
#define kHttpSecChUa                       81
#define kHttpSecChUaMobile                 82
#define kHttpSecFetchSite                  83
#define kHttpSecFetchMode                  84
#define kHttpSecFetchUser                  85
#define kHttpSecFetchDest                  86
#define kHttpCfRay                         87
#define kHttpCfVisitor                     88
#define kHttpCfConnectingIp                89
#define kHttpCfIpcountry                   90
#define kHttpSecChUaPlatform               91
#define kHttpCdnLoop                       92
#define kHttpHeadersMax                    93

COSMOPOLITAN_C_START_

struct HttpSlice {
  short a, b;
};

struct HttpHeader {
  struct HttpSlice k;
  struct HttpSlice v;
};

struct HttpHeaders {
  unsigned n, c;
  struct HttpHeader *p;
};

struct HttpMessage {
  int i, a, status;
  unsigned char t;
  unsigned char type;
  unsigned char version;
  uint64_t method;
  struct HttpSlice k;
  struct HttpSlice uri;
  struct HttpSlice scratch;
  struct HttpSlice message;
  struct HttpSlice headers[kHttpHeadersMax];
  struct HttpHeaders xheaders;
};

struct HttpUnchunker {
  int t;
  size_t i;
  size_t j;
  ssize_t m;
};

extern const char kHttpToken[256];
extern const bool kHttpRepeatable[kHttpHeadersMax];

const char *GetHttpReason(int);
const char *GetHttpHeaderName(int);
int GetHttpHeader(const char *, size_t);
void InitHttpMessage(struct HttpMessage *, int);
void DestroyHttpMessage(struct HttpMessage *);
int ParseHttpMessage(struct HttpMessage *, const char *, size_t);
bool HeaderHas(struct HttpMessage *, const char *, int, const char *, size_t);
int64_t ParseContentLength(const char *, size_t);
char *FormatHttpDateTime(char[hasatleast 30], struct tm *);
bool ParseHttpRange(const char *, size_t, long, long *, long *);
int64_t ParseHttpDateTime(const char *, size_t);
uint64_t ParseHttpMethod(const char *, size_t);
bool IsValidHttpToken(const char *, size_t);
bool IsValidCookieValue(const char *, size_t);
bool IsAcceptablePath(const char *, size_t);
bool IsAcceptableHost(const char *, size_t);
bool IsAcceptablePort(const char *, size_t);
bool IsReasonablePath(const char *, size_t);
int ParseForwarded(const char *, size_t, uint32_t *, uint16_t *);
bool IsMimeType(const char *, size_t, const char *);
ssize_t Unchunk(struct HttpUnchunker *, char *, size_t, size_t *);
const char *FindContentType(const char *, size_t);
bool IsNoCompressExt(const char *, size_t);
char *FoldHeader(struct HttpMessage *, const char *, int, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/ip.h */

#define COSMOPOLITAN_NET_HTTP_IP_H_

#define kIpUnknown    0
#define kIpMulticast  1
#define kIpLoopback   2
#define kIpPrivate    3
#define kIpTestnet    4
#define kIpAfrinic    5
#define kIpLacnic     6
#define kIpApnic      7
#define kIpArin       8
#define kIpRipe       9
#define kIpDod        10
#define kIpAtt        11
#define kIpApple      12
#define kIpFord       13
#define kIpCogent     14
#define kIpPrudential 15
#define kIpUsps       16
#define kIpComcast    17
#define kIpFuture     18
#define kIpAnonymous  19

COSMOPOLITAN_C_START_

struct Cidr {
  int64_t addr;
  int cidr;
};

int64_t ParseIp(const char *, size_t);
struct Cidr ParseCidr(const char *, size_t);
bool IsDodIp(uint32_t);
bool IsArinIp(uint32_t);
bool IsRipeIp(uint32_t);
bool IsApnicIp(uint32_t);
bool IsLacnicIp(uint32_t);
bool IsPublicIp(uint32_t);
bool IsPrivateIp(uint32_t);
bool IsAfrinicIp(uint32_t);
bool IsTestnetIp(uint32_t);
bool IsLoopbackIp(uint32_t);
bool IsMulticastIp(uint32_t);
bool IsAnonymousIp(uint32_t);
int CategorizeIp(uint32_t);
const char *GetIpCategoryName(int);
bool IsCloudflareIp(uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/tokenbucket.h */

#define COSMOPOLITAN_NET_HTTP_TOKENBUCKET_H_
COSMOPOLITAN_C_START_

void ReplenishTokens(atomic_uint_fast64_t *, size_t);
int AcquireToken(atomic_schar *, uint32_t, int);
int CountTokens(atomic_schar *, uint32_t, int);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/url.h */

#define COSMOPOLITAN_NET_HTTP_URL_H_

#define kUrlPlus   1
#define kUrlLatin1 2
#define kUrlOpaque 4

COSMOPOLITAN_C_START_

struct UrlView {
  size_t n;
  char *p;
};

struct UrlParams {
  size_t n;
  struct UrlParam {
    struct UrlView key;
    struct UrlView val;
  } * p;
};

struct Url {
  struct UrlView scheme; /* must be [A-Za-z][-+.0-9A-Za-z]* or empty */
  struct UrlView user;   /* depends on host non-absence */
  struct UrlView pass;   /* depends on user non-absence */
  struct UrlView host;   /* or reg_name */
  struct UrlView port;   /* depends on host non-absence */
  struct UrlView path;   /* or opaque_part */
  struct UrlParams params;
  struct UrlView fragment;
};

char *EncodeUrl(struct Url *, size_t *);
char *ParseUrl(const char *, size_t, struct Url *, int);
char *ParseParams(const char *, size_t, struct UrlParams *);
char *ParseHost(const char *, size_t, struct Url *);
char *EscapeUrlView(char *, struct UrlView *, const char[256]);

COSMOPOLITAN_C_END_


/*!BEGIN tool/args/args.h */

#define COSMOPOLITAN_TOOL_ARGS_ARGS_H_
COSMOPOLITAN_C_START_

int LoadZipArgs(int *, char ***);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/dlmalloc/dlmalloc.h */

#define COSMOPOLITAN_THIRD_PARTY_DLMALLOC_DLMALLOC_H_

#define dlbulk_free                  __dlbulk_free
#define dlcalloc                     __dlcalloc
#define dlfree                       __dlfree
#define dlindependent_calloc         __dlindependent_calloc
#define dlindependent_comalloc       __dlindependent_comalloc
#define dlmallinfo                   __dlmallinfo
#define dlmalloc                     __dlmalloc
#define dlmalloc_abort               __dlmalloc_abort
#define dlmalloc_atfork              __dlmalloc_atfork
#define dlmalloc_footprint           __dlmalloc_footprint
#define dlmalloc_footprint_limit     __dlmalloc_footprint_limit
#define dlmalloc_inspect_all         __dlmalloc_inspect_all
#define dlmalloc_max_footprint       __dlmalloc_max_footprint
#define dlmalloc_set_footprint_limit __dlmalloc_set_footprint_limit
#define dlmalloc_stats               __dlmalloc_stats
#define dlmalloc_trim                __dlmalloc_trim
#define dlmalloc_usable_size         __dlmalloc_usable_size
#define dlmallopt                    __dlmallopt
#define dlmallopt                    __dlmallopt
#define dlmemalign                   __dlmemalign
#define dlrealloc                    __dlrealloc
#define dlrealloc_in_place           __dlrealloc_in_place
#define dlrealloc_in_place           __dlrealloc_in_place

COSMOPOLITAN_C_START_

/*
  malloc(size_t n)
  Returns a pointer to a newly allocated chunk of at least n bytes, or
  null if no space is available, in which case errno is set to ENOMEM
  on ANSI C systems.

  If n is zero, malloc returns a minimum-sized chunk. (The minimum
  size is 16 bytes on most 32bit systems, and 32 bytes on 64bit
  systems.)  Note that size_t is an unsigned type, so calls with
  arguments that would be negative if signed are interpreted as
  requests for huge amounts of space, which will often fail. The
  maximum supported value of n differs across systems, but is in all
  cases less than the maximum representable value of a size_t.
*/
void* dlmalloc(size_t);

/*
  free(void* p)
  Releases the chunk of memory pointed to by p, that had been previously
  allocated using malloc or a related routine such as realloc.
  It has no effect if p is null. If p was not malloced or already
  freed, free(p) will by default cuase the current program to abort.
*/
void dlfree(void*);

/*
  calloc(size_t n_elements, size_t element_size);
  Returns a pointer to n_elements * element_size bytes, with all locations
  set to zero.
*/
void* dlcalloc(size_t, size_t);

/*
  realloc(void* p, size_t n)
  Returns a pointer to a chunk of size n that contains the same data
  as does chunk p up to the minimum of (n, p's size) bytes, or null
  if no space is available.

  The returned pointer may or may not be the same as p. The algorithm
  prefers extending p in most cases when possible, otherwise it
  employs the equivalent of a malloc-copy-free sequence.

  If p is null, realloc is equivalent to malloc.

  If space is not available, realloc returns null, errno is set (if on
  ANSI) and p is NOT freed.

  if n is for fewer bytes than already held by p, the newly unused
  space is lopped off and freed if possible.  realloc with a size
  argument of zero (re)allocates a minimum-sized chunk.

  The old unix realloc convention of allowing the last-free'd chunk
  to be used as an argument to realloc is not supported.
*/
void* dlrealloc(void*, size_t);

/*
  realloc_in_place(void* p, size_t n)
  Resizes the space allocated for p to size n, only if this can be
  done without moving p (i.e., only if there is adjacent space
  available if n is greater than p's current allocated size, or n is
  less than or equal to p's size). This may be used instead of plain
  realloc if an alternative allocation strategy is needed upon failure
  to expand space; for example, reallocation of a buffer that must be
  memory-aligned or cleared. You can use realloc_in_place to trigger
  these alternatives only when needed.

  Returns p if successful; otherwise null.
*/
void* dlrealloc_in_place(void*, size_t);

/*
  memalign(size_t alignment, size_t n);
  Returns a pointer to a newly allocated chunk of n bytes, aligned
  in accord with the alignment argument.

  The alignment argument should be a power of two. If the argument is
  not a power of two, the nearest greater power is used.
  8-byte alignment is guaranteed by normal malloc calls, so don't
  bother calling memalign with an argument of 8 or less.

  Overreliance on memalign is a sure way to fragment space.
*/
void* dlmemalign(size_t, size_t);

/*
  mallopt(int parameter_number, int parameter_value)
  Sets tunable parameters The format is to provide a
  (parameter-number, parameter-value) pair.  mallopt then sets the
  corresponding parameter to the argument value if it can (i.e., so
  long as the value is meaningful), and returns 1 if successful else
  0.  SVID/XPG/ANSI defines four standard param numbers for mallopt,
  normally defined in malloc.h.  None of these are use in this malloc,
  so setting them has no effect. But this malloc also supports other
  options in mallopt:

  Symbol            param #  default    allowed param values
  M_TRIM_THRESHOLD     -1   2*1024*1024   any   (-1U disables trimming)
  M_GRANULARITY        -2     page size   any power of 2 >= page size
  M_MMAP_THRESHOLD     -3      256*1024   any   (or 0 if no MMAP support)
*/
int dlmallopt(int, int);

/*
  malloc_footprint();
  Returns the number of bytes obtained from the system.  The total
  number of bytes allocated by malloc, realloc etc., is less than this
  value. Unlike mallinfo, this function returns only a precomputed
  result, so can be called frequently to monitor memory consumption.
  Even if locks are otherwise defined, this function does not use them,
  so results might not be up to date.
*/
size_t dlmalloc_footprint(void);

/*
  malloc_max_footprint();
  Returns the maximum number of bytes obtained from the system. This
  value will be greater than current footprint if deallocated space
  has been reclaimed by the system. The peak number of bytes allocated
  by malloc, realloc etc., is less than this value. Unlike mallinfo,
  this function returns only a precomputed result, so can be called
  frequently to monitor memory consumption.  Even if locks are
  otherwise defined, this function does not use them, so results might
  not be up to date.
*/
size_t dlmalloc_max_footprint(void);

/*
  malloc_footprint_limit();
  Returns the number of bytes that the heap is allowed to obtain from
  the system, returning the last value returned by
  malloc_set_footprint_limit, or the maximum size_t value if
  never set. The returned value reflects a permission. There is no
  guarantee that this number of bytes can actually be obtained from
  the system.
*/
size_t dlmalloc_footprint_limit(void);

/*
  malloc_set_footprint_limit();
  Sets the maximum number of bytes to obtain from the system, causing
  failure returns from malloc and related functions upon attempts to
  exceed this value. The argument value may be subject to page
  rounding to an enforceable limit; this actual value is returned.
  Using an argument of the maximum possible size_t effectively
  disables checks. If the argument is less than or equal to the
  current malloc_footprint, then all future allocations that require
  additional system memory will fail. However, invocation cannot
  retroactively deallocate existing used memory.
*/
size_t dlmalloc_set_footprint_limit(size_t bytes);

/*
  malloc_inspect_all(void(*handler)(void *start,
                                    void *end,
                                    size_t used_bytes,
                                    void* callback_arg),
                      void* arg);
  Traverses the heap and calls the given handler for each managed
  region, skipping all bytes that are (or may be) used for bookkeeping
  purposes.  Traversal does not include include chunks that have been
  directly memory mapped. Each reported region begins at the start
  address, and continues up to but not including the end address.  The
  first used_bytes of the region contain allocated data. If
  used_bytes is zero, the region is unallocated. The handler is
  invoked with the given callback argument. If locks are defined, they
  are held during the entire traversal. It is a bad idea to invoke
  other malloc functions from within the handler.

  For example, to count the number of in-use chunks with size greater
  than 1000, you could write:
  static int count = 0;
  void count_chunks(void* start, void* end, size_t used, void* arg) {
    if (used >= 1000) ++count;
  }
  then:
    malloc_inspect_all(count_chunks, NULL);

  malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined.
*/
void dlmalloc_inspect_all(void (*handler)(void*, void*, size_t, void*),
                          void* arg);

/*
  mallinfo()
  Returns (by copy) a struct containing various summary statistics:

  arena:     current total non-mmapped bytes allocated from system
  ordblks:   the number of free chunks
  smblks:    always zero.
  hblks:     current number of mmapped regions
  hblkhd:    total bytes held in mmapped regions
  usmblks:   the maximum total allocated space. This will be greater
                than current total if trimming has occurred.
  fsmblks:   always zero
  uordblks:  current total allocated space (normal or mmapped)
  fordblks:  total free space
  keepcost:  the maximum number of bytes that could ideally be released
               back to system via malloc_trim. ("ideally" means that
               it ignores page restrictions etc.)

  Because these fields are ints, but internal bookkeeping may
  be kept as longs, the reported values may wrap around zero and
  thus be inaccurate.
*/

struct mallinfo dlmallinfo(void);

/*
  independent_calloc(size_t n_elements, size_t element_size, void* chunks[]);

  independent_calloc is similar to calloc, but instead of returning a
  single cleared space, it returns an array of pointers to n_elements
  independent elements that can hold contents of size elem_size, each
  of which starts out cleared, and can be independently freed,
  realloc'ed etc. The elements are guaranteed to be adjacently
  allocated (this is not guaranteed to occur with multiple callocs or
  mallocs), which may also improve cache locality in some
  applications.

  The "chunks" argument is optional (i.e., may be null, which is
  probably the most typical usage). If it is null, the returned array
  is itself dynamically allocated and should also be freed when it is
  no longer needed. Otherwise, the chunks array must be of at least
  n_elements in length. It is filled in with the pointers to the
  chunks.

  In either case, independent_calloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and "chunks"
  is null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_calloc simplifies and speeds up implementations of many
  kinds of pools.  It may also be useful when constructing large data
  structures that initially have a fixed number of fixed-sized nodes,
  but the number is not known at compile time, and some of the nodes
  may later need to be freed. For example:

  struct Node { int item; struct Node* next; };

  struct Node* build_list() {
    struct Node** pool;
    int n = read_number_of_nodes_needed();
    if (n <= 0) return 0;
    pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
    if (pool == 0) die();
    // organize into a linked list...
    struct Node* first = pool[0];
    for (i = 0; i < n-1; ++i)
      pool[i]->next = pool[i+1];
    free(pool);     // Can now free the array (or not, if it is needed later)
    return first;
  }
*/
void** dlindependent_calloc(size_t, size_t, void**);

/*
  independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);

  independent_comalloc allocates, all at once, a set of n_elements
  chunks with sizes indicated in the "sizes" array.    It returns
  an array of pointers to these elements, each of which can be
  independently freed, realloc'ed etc. The elements are guaranteed to
  be adjacently allocated (this is not guaranteed to occur with
  multiple callocs or mallocs), which may also improve cache locality
  in some applications.

  The "chunks" argument is optional (i.e., may be null). If it is null
  the returned array is itself dynamically allocated and should also
  be freed when it is no longer needed. Otherwise, the chunks array
  must be of at least n_elements in length. It is filled in with the
  pointers to the chunks.

  In either case, independent_comalloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and chunks is
  null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_comallac differs from independent_calloc in that each
  element may have a different size, and also that it does not
  automatically clear elements.

  independent_comalloc can be used to speed up allocation in cases
  where several structs or objects must always be allocated at the
  same time.  For example:

  struct Head { ... }
  struct Foot { ... }

  void send_message(char* msg) {
    int msglen = strlen(msg);
    size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
    void* chunks[3];
    if (independent_comalloc(3, sizes, chunks) == 0)
      die();
    struct Head* head = (struct Head*)(chunks[0]);
    char*        body = (char*)(chunks[1]);
    struct Foot* foot = (struct Foot*)(chunks[2]);
    // ...
  }

  In general though, independent_comalloc is worth using only for
  larger values of n_elements. For small values, you probably won't
  detect enough difference from series of malloc calls to bother.

  Overuse of independent_comalloc can increase overall memory usage,
  since it cannot reuse existing noncontiguous small chunks that
  might be available for some of the elements.
*/
void** dlindependent_comalloc(size_t, size_t*, void**);

/*
  bulk_free(void* array[], size_t n_elements)
  Frees and clears (sets to null) each non-null pointer in the given
  array.  This is likely to be faster than freeing them one-by-one.
  If footers are used, pointers that have been allocated in different
  mspaces are not freed or cleared, and the count of all such pointers
  is returned.  For large arrays of pointers with poor locality, it
  may be worthwhile to sort this array before calling bulk_free.
*/
size_t dlbulk_free(void**, size_t n_elements);

/*
  malloc_trim(size_t pad);

  If possible, gives memory back to the system (via negative arguments
  to sbrk) if there is unused memory at the `high' end of the malloc
  pool or in unused MMAP segments. You can call this after freeing
  large blocks of memory to potentially reduce the system-level memory
  requirements of a program. However, it cannot guarantee to reduce
  memory. Under some allocation patterns, some large free blocks of
  memory will be locked between two used chunks, so they cannot be
  given back to the system.

  The `pad' argument to malloc_trim represents the amount of free
  trailing space to leave untrimmed. If this argument is zero, only
  the minimum amount of memory to maintain internal data structures
  will be left. Non-zero arguments can be supplied to maintain enough
  trailing space to service future expected allocations without having
  to re-obtain memory from the system.

  Malloc_trim returns 1 if it actually released any memory, else 0.
*/
int dlmalloc_trim(size_t);

/*
  malloc_stats();
  Prints on stderr the amount of space obtained from the system (both
  via sbrk and mmap), the maximum amount (which may be more than
  current if malloc_trim and/or munmap got called), and the current
  number of bytes allocated via malloc (or realloc, etc) but not yet
  freed. Note that this is the number of bytes allocated, not the
  number requested. It will be larger than the number requested
  because of alignment and bookkeeping overhead. Because it includes
  alignment wastage as being in use, this figure may be greater than
  zero even when no user-level chunks are allocated.

  The reported current and maximum system memory can be inaccurate if
  a program makes other calls to system memory allocation functions
  (normally sbrk) outside of malloc.

  malloc_stats prints only the most commonly interesting statistics.
  More information can be obtained by calling mallinfo.

  malloc_stats is not compiled if NO_MALLOC_STATS is defined.
*/
void dlmalloc_stats(void);

/*
  malloc_usable_size(void* p);

  Returns the number of bytes you can actually use in
  an allocated chunk, which may be more than you requested (although
  often not) due to alignment and minimum size constraints.
  You can use this many bytes without worrying about
  overwriting other allocated objects. This is not a particularly great
  programming practice. malloc_usable_size can be more useful in
  debugging and assertions, for example:

  p = malloc(n);
  assert(malloc_usable_size(p) >= 256);
*/
size_t dlmalloc_usable_size(void*);

/*
  mspace is an opaque type representing an independent
  region of space that supports mspace_malloc, etc.
*/
typedef void* mspace;

/*
  create_mspace creates and returns a new independent space with the
  given initial capacity, or, if 0, the default granularity size.  It
  returns null if there is no system memory available to create the
  space.  If argument locked is non-zero, the space uses a separate
  lock to control access. The capacity of the space will grow
  dynamically as needed to service mspace_malloc requests.  You can
  control the sizes of incremental increases of this space by
  compiling with a different DEFAULT_GRANULARITY or dynamically
  setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
  destroy_mspace destroys the given space, and attempts to return all
  of its memory back to the system, returning the total number of
  bytes freed. After destruction, the results of access to all memory
  used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

/*
  create_mspace_with_base uses the memory supplied as the initial base
  of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this
  space is used for bookkeeping, so the capacity must be at least this
  large. (Otherwise 0 is returned.) When this initial space is
  exhausted, additional memory will be obtained from the system.
  Destroying this space will deallocate all additionally allocated
  space (if possible) but not the initial base.
*/
mspace create_mspace_with_base(void* base, size_t capacity, int locked);

/*
  mspace_track_large_chunks controls whether requests for large chunks
  are allocated in their own untracked mmapped regions, separate from
  others in this mspace. By default large chunks are not tracked,
  which reduces fragmentation. However, such chunks are not
  necessarily released to the system upon destroy_mspace.  Enabling
  tracking by setting to true may increase fragmentation, but avoids
  leakage when relying on destroy_mspace to release all memory
  allocated using this space.  The function returns the previous
  setting.
*/
int mspace_track_large_chunks(mspace msp, int enable);

/*
  mspace_mallinfo behaves as mallinfo, but reports properties of
  the given space.
*/
struct mallinfo mspace_mallinfo(mspace msp);

/*
  An alias for mallopt.
*/
int mspace_mallopt(int, int);

/*
  The following operate identically to their malloc counterparts
  but operate only for the given mspace argument
*/
void* mspace_malloc(mspace msp, size_t bytes);
void mspace_free(mspace msp, void* mem);
void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
void* mspace_realloc(mspace msp, void* mem, size_t newsize);
void* mspace_realloc_in_place(mspace msp, void* mem, size_t newsize);
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
void** mspace_independent_calloc(mspace msp, size_t n_elements,
                                 size_t elem_size, void* chunks[]);
void** mspace_independent_comalloc(mspace msp, size_t n_elements,
                                   size_t sizes[], void* chunks[]);
size_t mspace_bulk_free(mspace msp, void**, size_t n_elements);
size_t mspace_usable_size(const void* mem);
void mspace_malloc_stats(mspace msp);
int mspace_trim(mspace msp, size_t pad);
size_t mspace_footprint(mspace msp);
size_t mspace_max_footprint(mspace msp);
size_t mspace_footprint_limit(mspace msp);
size_t mspace_set_footprint_limit(mspace msp, size_t bytes);
void mspace_inspect_all(mspace msp,
                        void (*handler)(void*, void*, size_t, void*),
                        void* arg);

void dlmalloc_atfork(void);
void dlmalloc_abort(void) relegated wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/gdtoa/gdtoa.h */

#define COSMOPOLITAN_THIRD_PARTY_GDTOA_GDTOA_H_
COSMOPOLITAN_C_START_

#define dtoa      __dtoa
#define gdtoa     __gdtoa
#define strtodg   __strtodg
#define freedtoa  __freedtoa
#define g_ddfmt   __g_ddfmt
#define g_ddfmt_p __g_ddfmt_p
#define g_dfmt    __g_dfmt
#define g_dfmt_p  __g_dfmt_p
#define g_ffmt    __g_ffmt
#define g_ffmt_p  __g_ffmt_p
#define g_Qfmt    __g_Qfmt
#define g_Qfmt_p  __g_Qfmt_p
#define g_xfmt    __g_xfmt
#define g_xfmt_p  __g_xfmt_p
#define g_xLfmt   __g_xLfmt
#define g_xLfmt_p __g_xLfmt_p
#define strtoId   __strtoId
#define strtoIdd  __strtoIdd
#define strtoIf   __strtoIf
#define strtoIQ   __strtoIQ
#define strtoIx   __strtoIx
#define strtoIxL  __strtoIxL
#define strtord   __strtord
#define strtordd  __strtordd
#define strtorf   __strtorf
#define strtorQ   __strtorQ
#define strtorx   __strtorx
#define strtorxL  __strtorxL
#define strtodI   __strtodI
#define strtopd   __strtopd
#define strtopdd  __strtopdd
#define strtopf   __strtopf
#define strtopQ   __strtopQ
#define strtopx   __strtopx
#define strtopxL  __strtopxL

/**
 * Configures g_*fmt()
 *
 * @param ic
 * 	0 ==> Infinity or NaN
 * 	1 ==> infinity or nan
 * 	2 ==> INFINITY or NAN
 * 	3 ==> Inf or NaN
 * 	4 ==> inf or nan
 * 	5 ==> INF or NAN
 * @param ic determines if NaNs are rendered as NaN(...)
 * 	0 ==> no
 * 	1 ==> yes
 * 	2 ==> no for default NaN values; yes otherwise
 * @param ns determines sign of NaN values reported
 * 	0 ==> distinguish NaN and -NaN
 * 	1 ==> report both as NaN
 */
#define NIK(ic, nb, ns) (ic + 6 * (nb + 3 * ns))

enum {
  /* return values from strtodg */
  STRTOG_Zero = 0,
  STRTOG_Normal = 1,
  STRTOG_Denormal = 2,
  STRTOG_Infinite = 3,
  STRTOG_NaN = 4,
  STRTOG_NaNbits = 5,
  STRTOG_NoNumber = 6,
  STRTOG_Retmask = 7,
  /* The following may be or-ed into one of the above values. */
  STRTOG_Neg = 0x08,    /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
  STRTOG_Inexlo = 0x10, /* returned result rounded toward zero */
  STRTOG_Inexhi = 0x20, /* returned result rounded away from zero */
  STRTOG_Inexact = 0x30,
  STRTOG_Underflow = 0x40,
  STRTOG_Overflow = 0x80
};

typedef struct FPI {
  int nbits;
  int emin;
  int emax;
  int rounding;
  int sudden_underflow;
  int int_max;
} FPI;

enum {
  /* FPI.rounding values: same as FLT_ROUNDS */
  FPI_Round_zero = 0,
  FPI_Round_near = 1,
  FPI_Round_up = 2,
  FPI_Round_down = 3
};

char *dtoa(double, int, int, int *, int *, char **);
char *gdtoa(const FPI *, int, unsigned *, int *, int, int, int *, char **);
int strtodg(const char *, char **, const FPI *, int *, unsigned *);
void freedtoa(char *);

char *g_ddfmt(char *, double *, int, size_t);
char *g_ddfmt_p(char *, double *, int, size_t, int);
char *g_dfmt(char *, double *, int, size_t);
char *g_dfmt_p(char *, double *, int, size_t, int);
char *g_ffmt(char *, float *, int, size_t);
char *g_ffmt_p(char *, float *, int, size_t, int);
char *g_Qfmt(char *, void *, int, size_t);
char *g_Qfmt_p(char *, void *, int, size_t, int);
char *g_xfmt(char *, void *, int, size_t);
char *g_xfmt_p(char *, void *, int, size_t, int);
char *g_xLfmt(char *, void *, int, size_t);
char *g_xLfmt_p(char *, void *, int, size_t, int);

int strtoId(const char *, char **, double *, double *);
int strtoIdd(const char *, char **, double *, double *);
int strtoIf(const char *, char **, float *, float *);
int strtoIQ(const char *, char **, void *, void *);
int strtoIx(const char *, char **, void *, void *);
int strtoIxL(const char *, char **, void *, void *);
int strtord(const char *, char **, int, double *);
int strtordd(const char *, char **, int, double *);
int strtorf(const char *, char **, int, float *);
int strtorQ(const char *, char **, int, void *);
int strtorx(const char *, char **, int, void *);
int strtorxL(const char *, char **, int, void *);

int strtodI(const char *, char **, double *);
int strtopd(const char *, char **, double *);
int strtopdd(const char *, char **, double *);
int strtopf(const char *, char **, float *);
int strtopQ(const char *, char **, void *);
int strtopx(const char *, char **, void *);
int strtopxL(const char *, char **, void *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long1.h */

#define _GETOPT_CORE_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif
COSMOPOLITAN_C_START_

extern char *optarg;
extern int optind, opterr, optopt, optreset;

int getopt(int, char *const *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long2.h */

#define _GETOPT_EXT_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif

#define no_argument       0
#define required_argument 1
#define optional_argument 2

COSMOPOLITAN_C_START_

struct option {
  const char *name;
  int has_arg;
  int *flag;
  int val;
};

int getopt_long(int, char *const *, const char *, const struct option *, int *);
int getopt_long_only(int, char *const *, const char *, const struct option *,
                     int *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/crypt.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_CRYPT_H_
COSMOPOLITAN_C_START_

struct crypt_data {
  int initialized;
  char __buf[256];
};

char *crypt(const char *, const char *) libcesque;
char *crypt_r(const char *, const char *, struct crypt_data *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/fnmatch.h */

#define COSMOPOLITAN_THIRD_PARTY_REGEX_FNMATCH_H_
COSMOPOLITAN_C_START_

#define FNM_PATHNAME    0x1
#define FNM_NOESCAPE    0x2
#define FNM_PERIOD      0x4
#define FNM_LEADING_DIR 0x8
#define FNM_CASEFOLD    0x10
#define FNM_FILE_NAME   FNM_PATHNAME

#define FNM_NOMATCH 1
#define FNM_NOSYS   (-1)

int fnmatch(const char *, const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/glob.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_GLOB_H_
COSMOPOLITAN_C_START_

#define GLOB_ERR      0x01
#define GLOB_MARK     0x02
#define GLOB_NOSORT   0x04
#define GLOB_DOOFFS   0x08 /* reserves null slots at start of gl_pathv */
#define GLOB_NOCHECK  0x10 /* just yield pattern if GLOB_NOMATCH happens */
#define GLOB_APPEND   0x20 /* enables us to call glob() multiple times */
#define GLOB_NOESCAPE 0x40 /* don't allow things like \*\?\[\] escaping */
#define GLOB_PERIOD   0x80

#define GLOB_TILDE       0x1000
#define GLOB_TILDE_CHECK 0x4000

#define GLOB_NOSPACE 1
#define GLOB_ABORTED 2
#define GLOB_NOMATCH 3
#define GLOB_NOSYS   4

typedef struct {
  size_t gl_pathc;
  char **gl_pathv;
  size_t gl_offs;
  int __dummy1;
  void *__dummy2[5];
} glob_t;

int glob(const char *, int, int (*)(const char *, int), glob_t *);
void globfree(glob_t *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/lockf.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_LOCKF_H_

#define F_ULOCK 0
#define F_LOCK  1
#define F_TLOCK 2
#define F_TEST  3

COSMOPOLITAN_C_START_

int lockf(int, int, int64_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/mntent.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_MNTENT_H_
COSMOPOLITAN_C_START_

#define MOUNTED "/etc/mtab"

#define MNTTYPE_IGNORE  "ignore"
#define MNTTYPE_NFS     "nfs"
#define MNTTYPE_SWAP    "swap"
#define MNTOPT_DEFAULTS "defaults"
#define MNTOPT_RO       "ro"
#define MNTOPT_RW       "rw"
#define MNTOPT_SUID     "suid"
#define MNTOPT_NOSUID   "nosuid"
#define MNTOPT_NOAUTO   "noauto"

struct mntent {
  char *mnt_fsname;
  char *mnt_dir;
  char *mnt_type;
  char *mnt_opts;
  int mnt_freq;
  int mnt_passno;
};

FILE *setmntent(const char *, const char *);
int endmntent(FILE *);
struct mntent *getmntent(FILE *);
struct mntent *getmntent_r(FILE *, struct mntent *, char *, int);
int addmntent(FILE *, const struct mntent *);
char *hasmntopt(const struct mntent *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/nameser.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NAMESER_H_
COSMOPOLITAN_C_START_

#define __NAMESER	19991006
#define NS_PACKETSZ	512
#define NS_MAXDNAME	1025
#define NS_MAXMSG	65535
#define NS_MAXCDNAME	255
#define NS_MAXLABEL	63
#define NS_HFIXEDSZ	12
#define NS_QFIXEDSZ	4
#define NS_RRFIXEDSZ	10
#define NS_INT32SZ	4
#define NS_INT16SZ	2
#define NS_INT8SZ	1
#define NS_INADDRSZ	4
#define NS_IN6ADDRSZ	16
#define NS_CMPRSFLGS	0xc0
#define NS_DEFAULTPORT	53

typedef enum __ns_sect {
	ns_s_qd = 0,
	ns_s_zn = 0,
	ns_s_an = 1,
	ns_s_pr = 1,
	ns_s_ns = 2,
	ns_s_ud = 2,
	ns_s_ar = 3,
	ns_s_max = 4
} ns_sect;

typedef struct __ns_msg {
	const unsigned char *_msg, *_eom;
	uint16_t _id, _flags, _counts[ns_s_max];
	const unsigned char *_sections[ns_s_max];
	ns_sect _sect;
	int _rrnum;
	const unsigned char *_msg_ptr;
} ns_msg;

struct _ns_flagdata {  int mask, shift;  };
extern const struct _ns_flagdata _ns_flagdata[];

#define ns_msg_id(handle) ((handle)._id + 0)
#define ns_msg_base(handle) ((handle)._msg + 0)
#define ns_msg_end(handle) ((handle)._eom + 0)
#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
#define ns_msg_getflag(handle, flag) \
	(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)

typedef	struct __ns_rr {
	char		name[NS_MAXDNAME];
	uint16_t	type;
	uint16_t	rr_class;
	uint32_t	ttl;
	uint16_t	rdlength;
	const unsigned char *rdata;
} ns_rr;

#define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
#define ns_rr_type(rr)	((ns_type)((rr).type + 0))
#define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0))
#define ns_rr_ttl(rr)	((rr).ttl + 0)
#define ns_rr_rdlen(rr)	((rr).rdlength + 0)
#define ns_rr_rdata(rr)	((rr).rdata + 0)

typedef enum __ns_flag {
	ns_f_qr,
	ns_f_opcode,
	ns_f_aa,
	ns_f_tc,
	ns_f_rd,
	ns_f_ra,
	ns_f_z,
	ns_f_ad,
	ns_f_cd,
	ns_f_rcode,
	ns_f_max
} ns_flag;

typedef enum __ns_opcode {
	ns_o_query = 0,
	ns_o_iquery = 1,
	ns_o_status = 2,
	ns_o_notify = 4,
	ns_o_update = 5,
	ns_o_max = 6
} ns_opcode;

typedef	enum __ns_rcode {
	ns_r_noerror = 0,
	ns_r_formerr = 1,
	ns_r_servfail = 2,
	ns_r_nxdomain = 3,
	ns_r_notimpl = 4,
	ns_r_refused = 5,
	ns_r_yxdomain = 6,
	ns_r_yxrrset = 7,
	ns_r_nxrrset = 8,
	ns_r_notauth = 9,
	ns_r_notzone = 10,
	ns_r_max = 11,
	ns_r_badvers = 16,
	ns_r_badsig = 16,
	ns_r_badkey = 17,
	ns_r_badtime = 18
} ns_rcode;

typedef enum __ns_update_operation {
	ns_uop_delete = 0,
	ns_uop_add = 1,
	ns_uop_max = 2
} ns_update_operation;

struct ns_tsig_key {
        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
        unsigned char *data;
        int len;
};
typedef struct ns_tsig_key ns_tsig_key;

struct ns_tcp_tsig_state {
	int counter;
	struct dst_key *key;
	void *ctx;
	unsigned char sig[NS_PACKETSZ];
	int siglen;
};
typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;

#define NS_TSIG_FUDGE 300
#define NS_TSIG_TCP_COUNT 100
#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"

#define NS_TSIG_ERROR_NO_TSIG -10
#define NS_TSIG_ERROR_NO_SPACE -11
#define NS_TSIG_ERROR_FORMERR -12

typedef enum __ns_type {
	ns_t_invalid = 0,
	ns_t_a = 1,
	ns_t_ns = 2,
	ns_t_md = 3,
	ns_t_mf = 4,
	ns_t_cname = 5,
	ns_t_soa = 6,
	ns_t_mb = 7,
	ns_t_mg = 8,
	ns_t_mr = 9,
	ns_t_null = 10,
	ns_t_wks = 11,
	ns_t_ptr = 12,
	ns_t_hinfo = 13,
	ns_t_minfo = 14,
	ns_t_mx = 15,
	ns_t_txt = 16,
	ns_t_rp = 17,
	ns_t_afsdb = 18,
	ns_t_x25 = 19,
	ns_t_isdn = 20,
	ns_t_rt = 21,
	ns_t_nsap = 22,
	ns_t_nsap_ptr = 23,
	ns_t_sig = 24,
	ns_t_key = 25,
	ns_t_px = 26,
	ns_t_gpos = 27,
	ns_t_aaaa = 28,
	ns_t_loc = 29,
	ns_t_nxt = 30,
	ns_t_eid = 31,
	ns_t_nimloc = 32,
	ns_t_srv = 33,
	ns_t_atma = 34,
	ns_t_naptr = 35,
	ns_t_kx = 36,
	ns_t_cert = 37,
	ns_t_a6 = 38,
	ns_t_dname = 39,
	ns_t_sink = 40,
	ns_t_opt = 41,
	ns_t_apl = 42,
	ns_t_tkey = 249,
	ns_t_tsig = 250,
	ns_t_ixfr = 251,
	ns_t_axfr = 252,
	ns_t_mailb = 253,
	ns_t_maila = 254,
	ns_t_any = 255,
	ns_t_zxfr = 256,
	ns_t_max = 65536
} ns_type;

#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
		      (t) == ns_t_mailb || (t) == ns_t_maila)
#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
		       (t) == ns_t_zxfr)

typedef enum __ns_class {
	ns_c_invalid = 0,
	ns_c_in = 1,
	ns_c_2 = 2,
	ns_c_chaos = 3,
	ns_c_hs = 4,
	ns_c_none = 254,
	ns_c_any = 255,
	ns_c_max = 65536
} ns_class;

typedef enum __ns_key_types {
	ns_kt_rsa = 1,
	ns_kt_dh  = 2,
	ns_kt_dsa = 3,
	ns_kt_private = 254
} ns_key_types;

typedef enum __ns_cert_types {
	cert_t_pkix = 1,
	cert_t_spki = 2,
	cert_t_pgp  = 3,
	cert_t_url  = 253,
	cert_t_oid  = 254
} ns_cert_types;

#define	NS_KEY_TYPEMASK		0xC000
#define	NS_KEY_TYPE_AUTH_CONF	0x0000
#define	NS_KEY_TYPE_CONF_ONLY	0x8000
#define	NS_KEY_TYPE_AUTH_ONLY	0x4000
#define	NS_KEY_TYPE_NO_KEY	0xC000
#define	NS_KEY_NO_AUTH		0x8000
#define	NS_KEY_NO_CONF		0x4000
#define	NS_KEY_RESERVED2	0x2000
#define	NS_KEY_EXTENDED_FLAGS	0x1000
#define	NS_KEY_RESERVED4	0x0800
#define	NS_KEY_RESERVED5	0x0400
#define	NS_KEY_NAME_TYPE	0x0300
#define	NS_KEY_NAME_USER	0x0000
#define	NS_KEY_NAME_ENTITY	0x0200
#define	NS_KEY_NAME_ZONE	0x0100
#define	NS_KEY_NAME_RESERVED	0x0300
#define	NS_KEY_RESERVED8	0x0080
#define	NS_KEY_RESERVED9	0x0040
#define	NS_KEY_RESERVED10	0x0020
#define	NS_KEY_RESERVED11	0x0010
#define	NS_KEY_SIGNATORYMASK	0x000F
#define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
				  NS_KEY_RESERVED4 | \
				  NS_KEY_RESERVED5 | \
				  NS_KEY_RESERVED8 | \
				  NS_KEY_RESERVED9 | \
				  NS_KEY_RESERVED10 | \
				  NS_KEY_RESERVED11 )
#define NS_KEY_RESERVED_BITMASK2 0xFFFF
#define	NS_ALG_MD5RSA		1
#define	NS_ALG_DH               2
#define	NS_ALG_DSA              3
#define	NS_ALG_DSS              NS_ALG_DSA
#define	NS_ALG_EXPIRE_ONLY	253
#define	NS_ALG_PRIVATE_OID	254

#define NS_KEY_PROT_TLS         1
#define NS_KEY_PROT_EMAIL       2
#define NS_KEY_PROT_DNSSEC      3
#define NS_KEY_PROT_IPSEC       4
#define NS_KEY_PROT_ANY		255

#define	NS_MD5RSA_MIN_BITS	 512
#define	NS_MD5RSA_MAX_BITS	4096
#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
#define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
#define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
#define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)

#define NS_DSA_SIG_SIZE         41
#define NS_DSA_MIN_SIZE         213
#define NS_DSA_MAX_BYTES        405

#define	NS_SIG_TYPE	0
#define	NS_SIG_ALG	2
#define	NS_SIG_LABELS	3
#define	NS_SIG_OTTL	4
#define	NS_SIG_EXPIR	8
#define	NS_SIG_SIGNED	12
#define	NS_SIG_FOOT	16
#define	NS_SIG_SIGNER	18
#define	NS_NXT_BITS 8
#define	NS_NXT_BIT_SET(  n,p) (p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
#define NS_NXT_MAX 127

#define NS_OPT_DNSSEC_OK        0x8000U
#define NS_OPT_NSID		3

#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2))
#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4))
#define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2)
#define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4)

unsigned ns_get16(const unsigned char *);
unsigned long ns_get32(const unsigned char *);
void ns_put16(unsigned, unsigned char *);
void ns_put32(unsigned long, unsigned char *);

int ns_initparse(const unsigned char *, int, ns_msg *);
int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int);
int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t);


#define	__BIND		19950621

typedef struct {
	unsigned	id :16;
#if __BYTE_ORDER == __BIG_ENDIAN
	unsigned	qr: 1;
	unsigned	opcode: 4;
	unsigned	aa: 1;
	unsigned	tc: 1;
	unsigned	rd: 1;
	unsigned	ra: 1;
	unsigned	unused :1;
	unsigned	ad: 1;
	unsigned	cd: 1;
	unsigned	rcode :4;
#else
	unsigned	rd :1;
	unsigned	tc :1;
	unsigned	aa :1;
	unsigned	opcode :4;
	unsigned	qr :1;
	unsigned	rcode :4;
	unsigned	cd: 1;
	unsigned	ad: 1;
	unsigned	unused :1;
	unsigned	ra :1;
#endif
	unsigned	qdcount :16;
	unsigned	ancount :16;
	unsigned	nscount :16;
	unsigned	arcount :16;
} HEADER;

#define PACKETSZ	NS_PACKETSZ
#define MAXDNAME	NS_MAXDNAME
#define MAXCDNAME	NS_MAXCDNAME
#define MAXLABEL	NS_MAXLABEL
#define	HFIXEDSZ	NS_HFIXEDSZ
#define QFIXEDSZ	NS_QFIXEDSZ
#define RRFIXEDSZ	NS_RRFIXEDSZ
#define	INT32SZ		NS_INT32SZ
#define	INT16SZ		NS_INT16SZ
#define INT8SZ		NS_INT8SZ
#define	INADDRSZ	NS_INADDRSZ
#define	IN6ADDRSZ	NS_IN6ADDRSZ
#define	INDIR_MASK	NS_CMPRSFLGS
#define NAMESERVER_PORT	NS_DEFAULTPORT

#define S_ZONE		ns_s_zn
#define S_PREREQ	ns_s_pr
#define S_UPDATE	ns_s_ud
#define S_ADDT		ns_s_ar

#define QUERY		ns_o_query
#define IQUERY		ns_o_iquery
#define STATUS		ns_o_status
#define	NS_NOTIFY_OP	ns_o_notify
#define	NS_UPDATE_OP	ns_o_update

#define NOERROR		ns_r_noerror
#define FORMERR		ns_r_formerr
#define SERVFAIL	ns_r_servfail
#define NXDOMAIN	ns_r_nxdomain
#define NOTIMP		ns_r_notimpl
#define REFUSED		ns_r_refused
#define YXDOMAIN	ns_r_yxdomain
#define YXRRSET		ns_r_yxrrset
#define NXRRSET		ns_r_nxrrset
#define NOTAUTH		ns_r_notauth
#define NOTZONE		ns_r_notzone

#define DELETE		ns_uop_delete
#define ADD		ns_uop_add

#define T_A		ns_t_a
#define T_NS		ns_t_ns
#define T_MD		ns_t_md
#define T_MF		ns_t_mf
#define T_CNAME		ns_t_cname
#define T_SOA		ns_t_soa
#define T_MB		ns_t_mb
#define T_MG		ns_t_mg
#define T_MR		ns_t_mr
#define T_NULL		ns_t_null
#define T_WKS		ns_t_wks
#define T_PTR		ns_t_ptr
#define T_HINFO		ns_t_hinfo
#define T_MINFO		ns_t_minfo
#define T_MX		ns_t_mx
#define T_TXT		ns_t_txt
#define	T_RP		ns_t_rp
#define T_AFSDB		ns_t_afsdb
#define T_X25		ns_t_x25
#define T_ISDN		ns_t_isdn
#define T_RT		ns_t_rt
#define T_NSAP		ns_t_nsap
#define T_NSAP_PTR	ns_t_nsap_ptr
#define	T_SIG		ns_t_sig
#define	T_KEY		ns_t_key
#define	T_PX		ns_t_px
#define	T_GPOS		ns_t_gpos
#define	T_AAAA		ns_t_aaaa
#define	T_LOC		ns_t_loc
#define	T_NXT		ns_t_nxt
#define	T_EID		ns_t_eid
#define	T_NIMLOC	ns_t_nimloc
#define	T_SRV		ns_t_srv
#define T_ATMA		ns_t_atma
#define T_NAPTR		ns_t_naptr
#define T_A6		ns_t_a6
#define T_DNAME		ns_t_dname
#define	T_TSIG		ns_t_tsig
#define	T_IXFR		ns_t_ixfr
#define T_AXFR		ns_t_axfr
#define T_MAILB		ns_t_mailb
#define T_MAILA		ns_t_maila
#define T_ANY		ns_t_any

#define C_IN		ns_c_in
#define C_CHAOS		ns_c_chaos
#define C_HS		ns_c_hs
#define C_NONE		ns_c_none
#define C_ANY		ns_c_any

#define	GETSHORT		NS_GET16
#define	GETLONG			NS_GET32
#define	PUTSHORT		NS_PUT16
#define	PUTLONG			NS_PUT32

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/netdb.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NETDB_H_
COSMOPOLITAN_C_START_

struct addrinfo {
	int ai_flags;
	int ai_family;
	int ai_socktype;
	int ai_protocol;
	uint32_t ai_addrlen;
	struct sockaddr *ai_addr;
	char *ai_canonname;
	struct addrinfo *ai_next;
};

#define AI_PASSIVE      0x01
#define AI_CANONNAME    0x02
#define AI_NUMERICHOST  0x04
#define AI_V4MAPPED     0x08
#define AI_ALL          0x10
#define AI_ADDRCONFIG   0x20
#define AI_NUMERICSERV  0x400

#define NI_NUMERICHOST  0x01
#define NI_NUMERICSERV  0x02
#define NI_NOFQDN       0x04
#define NI_NAMEREQD     0x08
#define NI_DGRAM        0x10
#define NI_NUMERICSCOPE 0x100

#define EAI_BADFLAGS   -1
#define EAI_NONAME     -2
#define EAI_AGAIN      -3
#define EAI_FAIL       -4
#define EAI_FAMILY     -6
#define EAI_SOCKTYPE   -7
#define EAI_SERVICE    -8
#define EAI_MEMORY     -10
#define EAI_SYSTEM     -11
#define EAI_OVERFLOW   -12

int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
void freeaddrinfo (struct addrinfo *);
int getnameinfo (const struct sockaddr *, uint32_t, char *, uint32_t, char *, uint32_t, int);
const char *gai_strerror(int);


/* Legacy functions follow (marked OBsolete in SUS) */

struct netent {
	char *n_name;
	char **n_aliases;
	int n_addrtype;
	uint32_t n_net;
};

struct hostent {
	char *h_name;
	char **h_aliases;
	int h_addrtype;
	int h_length;
	char **h_addr_list;
};
#define h_addr h_addr_list[0]

struct servent {
	char *s_name;
	char **s_aliases;
	int s_port;
	char *s_proto;
};

struct protoent {
	char *p_name;
	char **p_aliases;
	int p_proto;
};

void sethostent (int);
void endhostent (void);
struct hostent *gethostent (void);

void setnetent (int);
void endnetent (void);
struct netent *getnetent (void);
struct netent *getnetbyaddr (uint32_t, int);
struct netent *getnetbyname (const char *);

void setservent (int);
void endservent (void);
struct servent *getservent (void);
struct servent *getservbyname (const char *, const char *);
struct servent *getservbyport (int, const char *);

void setprotoent (int);
void endprotoent (void);
struct protoent *getprotoent (void);
struct protoent *getprotobyname (const char *);
struct protoent *getprotobynumber (int);

#define NI_MAXHOST 255
#define NI_MAXSERV 32

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
struct hostent *gethostbyname (const char *);
struct hostent *gethostbyaddr (const void *, uint32_t, int);
errno_t *__h_errno_location(void) dontthrow pureconst;
#define h_errno (*__h_errno_location())
#define HOST_NOT_FOUND 1
#define TRY_AGAIN      2
#define NO_RECOVERY    3
#define NO_DATA        4
#define NO_ADDRESS     NO_DATA
#endif

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
void herror(const char *);
const char *hstrerror(int);
int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
struct hostent *gethostbyname2(const char *, int);
int gethostbyaddr_r(const void *, uint32_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
#define EAI_NODATA     -5
#define EAI_ADDRFAMILY -9
#define EAI_INPROGRESS -100
#define EAI_CANCELED   -101
#define EAI_NOTCANCELED -102
#define EAI_ALLDONE    -103
#define EAI_INTR       -104
#define EAI_IDN_ENCODE -105
#endif

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/passwd.h */

#define COSMOPOLITAN_LIBC_PASSWD_H_
COSMOPOLITAN_C_START_

struct passwd {
  char *pw_name;
  char *pw_passwd;
  uid_t pw_uid;
  gid_t pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};

void setpwent(void);
void endpwent(void);
struct passwd *getpwent(void);
struct passwd *getpwuid(uid_t);
struct passwd *getpwnam(const char *);
int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
struct passwd *fgetpwent(FILE *);
int putpwent(const struct passwd *, FILE *);

struct group {
  char *gr_name;
  char *gr_passwd;
  gid_t gr_gid;
  char **gr_mem;
};

struct group *getgrgid(gid_t);
struct group *getgrnam(const char *);
int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
struct group *getgrent(void);
void endgrent(void);
void setgrent(void);
struct group *fgetgrent(FILE *);
int putgrent(const struct group *, FILE *);
int getgrouplist(const char *, gid_t, gid_t *, int *);
int initgroups(const char *, gid_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/rand48.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RAND48_H_
COSMOPOLITAN_C_START_

double drand48(void);
double erand48(unsigned short[3]);
long int lrand48(void);
long int nrand48(unsigned short[3]);
long mrand48(void);
long jrand48(unsigned short[3]);
void srand48(long);
unsigned short *seed48(unsigned short[3]);
void lcong48(unsigned short[7]);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/resolv.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RESOLV_H_
COSMOPOLITAN_C_START_

#define MAXNS			3
#define MAXDFLSRCH		3
#define MAXDNSRCH		6
#define LOCALDOMAINPARTS	2

#define RES_TIMEOUT		5
#define MAXRESOLVSORT		10
#define RES_MAXNDOTS		15
#define RES_MAXRETRANS		30
#define RES_MAXRETRY		5
#define RES_DFLRETRY		2
#define RES_MAXTIME		65535

/* unused; purely for broken apps */
typedef struct __res_state {
	int retrans;
	int retry;
	unsigned long options;
	int nscount;
	struct sockaddr_in nsaddr_list[MAXNS];
# define nsaddr	nsaddr_list[0]
	unsigned short id;
	char *dnsrch[MAXDNSRCH+1];
	char defdname[256];
	unsigned long pfcode;
	unsigned ndots:4;
	unsigned nsort:4;
	unsigned ipv6_unavail:1;
	unsigned unused:23;
	struct {
		struct in_addr addr;
		uint32_t mask;
	} sort_list[MAXRESOLVSORT];
	void *qhook;
	void *rhook;
	int res_h_errno;
	int _vcsock;
	unsigned _flags;
	union {
		char pad[52];
		struct {
			uint16_t		nscount;
			uint16_t		nsmap[MAXNS];
			int			nssocks[MAXNS];
			uint16_t		nscount6;
			uint16_t		nsinit;
			struct sockaddr_in6	*nsaddrs[MAXNS];
			unsigned int		_initstamp[2];
		} _ext;
	} _u;
} *res_state;

#define	__RES	19960801

#ifndef _PATH_RESCONF
#define _PATH_RESCONF        "/etc/resolv.conf"
#endif

struct res_sym {
	int number;
	char *name;
	char *humanname;
};

#define	RES_F_VC	0x00000001
#define	RES_F_CONN	0x00000002
#define RES_F_EDNS0ERR	0x00000004

#define	RES_EXHAUSTIVE	0x00000001

#define RES_INIT	0x00000001
#define RES_DEBUG	0x00000002
#define RES_AAONLY	0x00000004
#define RES_USEVC	0x00000008
#define RES_PRIMARY	0x00000010
#define RES_IGNTC	0x00000020
#define RES_RECURSE	0x00000040
#define RES_DEFNAMES	0x00000080
#define RES_STAYOPEN	0x00000100
#define RES_DNSRCH	0x00000200
#define	RES_INSECURE1	0x00000400
#define	RES_INSECURE2	0x00000800
#define	RES_NOALIASES	0x00001000
#define	RES_USE_INET6	0x00002000
#define RES_ROTATE	0x00004000
#define	RES_NOCHECKNAME	0x00008000
#define	RES_KEEPTSIG	0x00010000
#define	RES_BLAST	0x00020000
#define RES_USEBSTRING	0x00040000
#define RES_NOIP6DOTINT	0x00080000
#define RES_USE_EDNS0	0x00100000
#define RES_SNGLKUP	0x00200000
#define RES_SNGLKUPREOP	0x00400000
#define RES_USE_DNSSEC	0x00800000

#define RES_DEFAULT	(RES_RECURSE|RES_DEFNAMES|RES_DNSRCH|RES_NOIP6DOTINT)

#define RES_PRF_STATS	0x00000001
#define RES_PRF_UPDATE	0x00000002
#define RES_PRF_CLASS   0x00000004
#define RES_PRF_CMD	0x00000008
#define RES_PRF_QUES	0x00000010
#define RES_PRF_ANS	0x00000020
#define RES_PRF_AUTH	0x00000040
#define RES_PRF_ADD	0x00000080
#define RES_PRF_HEAD1	0x00000100
#define RES_PRF_HEAD2	0x00000200
#define RES_PRF_TTLID	0x00000400
#define RES_PRF_HEADX	0x00000800
#define RES_PRF_QUERY	0x00001000
#define RES_PRF_REPLY	0x00002000
#define RES_PRF_INIT	0x00004000

struct __res_state *__res_state(void);
#define _res (*__res_state())

int res_init(void);
int res_query(const char *, int, int, unsigned char *, int);
int res_querydomain(const char *, const char *, int, int, unsigned char *, int);
int res_search(const char *, int, int, unsigned char *, int);
int res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
int res_send(const unsigned char *, int, unsigned char *, int);
int dn_comp(const char *, unsigned char *, int, unsigned char **, unsigned char **);
int dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
int dn_skipname(const unsigned char *, const unsigned char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/search.h */

#define COSMOPOLITAN_THIRDPARTY_MUSL_SEARCH_H

typedef enum { FIND, ENTER } ACTION;
typedef enum { preorder, postorder, endorder, leaf } VISIT;

typedef struct entry {
	char *key;
	void *data;
} ENTRY;

int hcreate(size_t);
void hdestroy(void);
ENTRY *hsearch(ENTRY, ACTION);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct hsearch_data {
	struct __tab *__tab;
	unsigned int __unused1;
	unsigned int __unused2;
};

int hcreate_r(size_t, struct hsearch_data *);
void hdestroy_r(struct hsearch_data *);
int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *);
#endif

void insque(void *, void *);
void remque(void *);

void *lsearch(const void *, void *, size_t *, size_t,
	int (*)(const void *, const void *));
void *lfind(const void *, const void *, size_t *, size_t,
	int (*)(const void *, const void *));

void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *));
void *tfind(const void *, void *const *, int(*)(const void *, const void *));
void *tsearch(const void *, void **, int (*)(const void *, const void *));
void twalk(const void *, void (*)(const void *, VISIT, int));

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct qelem {
	struct qelem *q_forw, *q_back;
	char q_data[1];
};

void tdestroy(void *, void (*)(void *));
#endif



/*!BEGIN third_party/musl/shadow.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_SHADOW_H_
COSMOPOLITAN_C_START_

#define	SHADOW "/etc/shadow"

struct spwd {
	char *sp_namp;
	char *sp_pwdp;
	long sp_lstchg;
	long sp_min;
	long sp_max;
	long sp_warn;
	long sp_inact;
	long sp_expire;
	unsigned long sp_flag;
};

void setspent(void);
void endspent(void);
struct spwd *getspent(void);
struct spwd *fgetspent(FILE *);
struct spwd *sgetspent(const char *);
int putspent(const struct spwd *, FILE *);

struct spwd *getspnam(const char *);
int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **);

int lckpwdf(void);
int ulckpwdf(void);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/tempnam.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_TEMPNAM_H_
COSMOPOLITAN_C_START_

char *tempnam(const char *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/zlib/zconf.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZCONF_H_

#define STDC
#define STDC99
#define MAX_MEM_LEVEL 9
#define DEF_MEM_LEVEL 8
#define MAX_WBITS     15 /* 32K LZ77 window */

#ifdef MODE_DBG
#define ZLIB_DEBUG
#endif

#define z_const const

#define Z_COSMO_PREFIX_SET

#define Bytef                    _Cz_Bytef
#define _dist_code               _Cz__dist_code
#define _length_code             _Cz__length_code
#define _tr_align                _Cz__tr_align
#define _tr_flush_bits           _Cz__tr_flush_bits
#define _tr_flush_block          _Cz__tr_flush_block
#define _tr_init                 _Cz__tr_init
#define _tr_stored_block         _Cz__tr_stored_block
#define _tr_tally                _Cz__tr_tally
#define adler32                  _Cz_adler32
#define adler32_combine          _Cz_adler32_combine
#define adler32_combine64        _Cz_adler32_combine64
#define adler32_simd_            _Cz_adler32_simd_
#define adler32_z                _Cz_adler32_z
#define alloc_func               _Cz_alloc_func
#define arm_check_features       _Cz_arm_check_features
#define arm_cpu_enable_crc32     _Cz_arm_cpu_enable_crc32
#define arm_cpu_enable_pmull     _Cz_arm_cpu_enable_pmull
#define armv8_crc32_little       _Cz_armv8_crc32_little
#define armv8_crc32_pmull_little _Cz_armv8_crc32_pmull_little
#define charf                    _Cz_charf
#define compress                 _Cz_compress
#define compress2                _Cz_compress2
#define compressBound            _Cz_compressBound
#define copy_with_crc            _Cz_copy_with_crc
#define cpu_check_features       _Cz_cpu_check_features
#define crc32                    _Cz_crc32
#define crc32_combine            _Cz_crc32_combine
#define crc32_combine64          _Cz_crc32_combine64
#define crc32_combine_gen        _Cz_crc32_combine_gen
#define crc32_combine_gen64      _Cz_crc32_combine_gen64
#define crc32_combine_op         _Cz_crc32_combine_op
#define crc32_sse42_simd_        _Cz_crc32_sse42_simd_
#define crc32_z                  _Cz_crc32_z
#define crc_finalize             _Cz_crc_finalize
#define crc_fold_512to32         _Cz_crc_fold_512to32
#define crc_fold_copy            _Cz_crc_fold_copy
#define crc_fold_init            _Cz_crc_fold_init
#define crc_reset                _Cz_crc_reset
#define deflate                  _Cz_deflate
#define deflateBound             _Cz_deflateBound
#define deflateCopy              _Cz_deflateCopy
#define deflateEnd               _Cz_deflateEnd
#define deflateGetDictionary     _Cz_deflateGetDictionary
#define deflateInit              _Cz_deflateInit
#define deflateInit2             _Cz_deflateInit2
#define deflateParams            _Cz_deflateParams
#define deflatePending           _Cz_deflatePending
#define deflatePrime             _Cz_deflatePrime
#define deflateReset             _Cz_deflateReset
#define deflateResetKeep         _Cz_deflateResetKeep
#define deflateSetDictionary     _Cz_deflateSetDictionary
#define deflateSetHeader         _Cz_deflateSetHeader
#define deflateTune              _Cz_deflateTune
#define deflate_copyright        _Cz_deflate_copyright
#define deflate_read_buf         _Cz_deflate_read_buf
#define fill_window_sse          _Cz_fill_window_sse
#define free_func                _Cz_free_func
#define get_crc_table            _Cz_get_crc_table
#define gzFile                   _Cz_gzFile
#define gz_error                 _Cz_gz_error
#define gz_header                _Cz_gz_header
#define gz_header_s              _Cz_gz_header_s
#define gz_headerp               _Cz_gz_headerp
#define gz_intmax                _Cz_gz_intmax
#define gz_strwinerror           _Cz_gz_strwinerror
#define gzbuffer                 _Cz_gzbuffer
#define gzclearerr               _Cz_gzclearerr
#define gzclose                  _Cz_gzclose
#define gzclose_r                _Cz_gzclose_r
#define gzclose_w                _Cz_gzclose_w
#define gzdirect                 _Cz_gzdirect
#define gzdopen                  _Cz_gzdopen
#define gzeof                    _Cz_gzeof
#define gzerror                  _Cz_gzerror
#define gzflush                  _Cz_gzflush
#define gzfread                  _Cz_gzfread
#define gzfwrite                 _Cz_gzfwrite
#define gzgetc                   _Cz_gzgetc
#define gzgetc_                  _Cz_gzgetc_
#define gzgets                   _Cz_gzgets
#define gzoffset                 _Cz_gzoffset
#define gzoffset64               _Cz_gzoffset64
#define gzopen                   _Cz_gzopen
#define gzopen64                 _Cz_gzopen64
#define gzopen_w                 _Cz_gzopen_w
#define gzprintf                 _Cz_gzprintf
#define gzputc                   _Cz_gzputc
#define gzputs                   _Cz_gzputs
#define gzread                   _Cz_gzread
#define gzrewind                 _Cz_gzrewind
#define gzseek                   _Cz_gzseek
#define gzseek64                 _Cz_gzseek64
#define gzsetparams              _Cz_gzsetparams
#define gztell                   _Cz_gztell
#define gztell64                 _Cz_gztell64
#define gzungetc                 _Cz_gzungetc
#define gzvprintf                _Cz_gzvprintf
#define gzwrite                  _Cz_gzwrite
#define in_func                  _Cz_in_func
#define inflate                  _Cz_inflate
#define inflateBack              _Cz_inflateBack
#define inflateBackEnd           _Cz_inflateBackEnd
#define inflateBackInit_         _Cz_inflateBackInit_
#define inflateCodesUsed         _Cz_inflateCodesUsed
#define inflateCopy              _Cz_inflateCopy
#define inflateEnd               _Cz_inflateEnd
#define inflateGetDictionary     _Cz_inflateGetDictionary
#define inflateGetHeader         _Cz_inflateGetHeader
#define inflateInit              _Cz_inflateInit
#define inflateInit2             _Cz_inflateInit2
#define inflateMark              _Cz_inflateMark
#define inflatePrime             _Cz_inflatePrime
#define inflateReset             _Cz_inflateReset
#define inflateReset2            _Cz_inflateReset2
#define inflateResetKeep         _Cz_inflateResetKeep
#define inflateSetDictionary     _Cz_inflateSetDictionary
#define inflateSync              _Cz_inflateSync
#define inflateSyncPoint         _Cz_inflateSyncPoint
#define inflateUndermine         _Cz_inflateUndermine
#define inflateValidate          _Cz_inflateValidate
#define inflate_copyright        _Cz_inflate_copyright
#define inflate_fast             _Cz_inflate_fast
#define inflate_fast_chunk_      _Cz_inflate_fast_chunk_
#define inflate_table            _Cz_inflate_table
#define intf                     _Cz_intf
#define out_func                 _Cz_out_func
#define uInt                     _Cz_uInt
#define uIntf                    _Cz_uIntf
#define uLong                    _Cz_uLong
#define uLongf                   _Cz_uLongf
#define uncompress               _Cz_uncompress
#define uncompress2              _Cz_uncompress2
#define voidp                    _Cz_voidp
#define voidpc                   _Cz_voidpc
#define voidpf                   _Cz_voidpf
#define x86_check_features       _Cz_x86_check_features
#define x86_cpu_enable_simd      _Cz_x86_cpu_enable_simd
#define x86_cpu_enable_sse2      _Cz_x86_cpu_enable_sse2
#define x86_cpu_enable_ssse3     _Cz_x86_cpu_enable_ssse3
#define zError                   _Cz_zError
#define z_errmsg                 _Cz_z_errmsg
#define zcalloc                  _Cz_zcalloc
#define zcfree                   _Cz_zcfree
#define zlibCompileFlags         _Cz_zlibCompileFlags
#define zlibVersion              _Cz_zlibVersion


typedef unsigned char Byte;
typedef unsigned int uInt;   /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef Byte Bytef;
typedef char charf;
typedef int intf;
typedef uInt uIntf;
typedef uLong uLongf;
typedef void const *voidpc;
typedef void *voidpf;
typedef void *voidp;
typedef uint32_t z_crc_t;
typedef int64_t z_off64_t;
typedef size_t z_size_t;



/*!BEGIN third_party/zlib/zlib.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZLIB_H_

/**
 * @fileoverview zlib
 *
 * The 'zlib' compression library provides in-memory
 * compression and decompression functions, including integrity checks
 * of the uncompressed data. This version of the library supports only
 * one compression method (deflation) but other algorithms will be added
 * later and will have the same stream interface.
 *
 * Compression can be done in a single step if the buffers are large enough,
 * or can be done by repeated calls of the compression function.  In the latter
 * case, the application must provide more input and/or consume the output
 * (providing more output space) before each call.
 *
 * The compressed data format used by default by the in-memory functions is
 * the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
 * around a deflate stream, which is itself documented in RFC 1951.
 *
 * The library also supports reading and writing files in gzip (.gz) format
 * with an interface similar to that of stdio using the functions that start
 * with "gz".  The gzip format is different from the zlib format.  gzip is a
 * gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
 *
 * This library can optionally read and write gzip and raw deflate streams in
 * memory as well.
 *
 * The zlib format was designed to be compact and fast for use in memory
 * and on communications channels.  The gzip format was designed for single-
 * file compression on file systems, has a larger header than zlib to maintain
 * directory information, and uses a different, slower check method than zlib.
 *
 * The library does not install any signal handler.  The decoder checks
 * the consistency of the compressed data, so the library should never crash
 * even in the case of corrupted input.
 */

#define ZLIB_VERSION         "1.2.11"
#define ZLIB_VERNUM          0x12b0
#define ZLIB_VER_MAJOR       1
#define ZLIB_VER_MINOR       2
#define ZLIB_VER_REVISION    11
#define ZLIB_VER_SUBREVISION 0

/**
 * The application must update next_in and avail_in when avail_in has
 * dropped to zero. It must update next_out and avail_out when avail_out
 * has dropped to zero. The application must initialize zalloc, zfree
 * and opaque before calling the init function. All other fields are set
 * by the compression library and must not be updated by the
 * application.
 *
 * The opaque value provided by the application will be passed as the
 * first parameter for calls of zalloc and zfree. This can be useful for
 * custom memory management. The compression library attaches no meaning
 * to the opaque value.
 *
 * zalloc must return Z_NULL if there is not enough memory for the
 * object. If zlib is used in a multi-threaded application, zalloc and
 * zfree must be thread safe. In that case, zlib is thread-safe. When
 * zalloc and zfree are Z_NULL on entry to the initialization function,
 * they are set to internal routines that use the standard library
 * functions malloc() and free().
 *
 * On 16-bit systems, the functions zalloc and zfree must be able to
 * allocate exactly 65536 bytes, but will not be required to allocate
 * more than this if the symbol MAXSEG_64K is defined (see zconf.h).
 * WARNING: On MSDOS, pointers returned by zalloc for objects of exactly
 * 65536 bytes *must* have their offset normalized to zero. The default
 * allocation function provided by this library ensures this (see
 * zutil.c). To reduce memory requirements and avoid any allocation of
 * 64K objects, at the expense of compression ratio, compile the library
 * with -DMAX_WBITS=14 (see zconf.h).
 *
 * The fields total_in and total_out can be used for statistics or
 * progress reports. After compression, total_in holds the total size of
 * the uncompressed data and may be saved for use by the decompressor
 * (particularly if the decompressor wants to decompress everything in a
 * single step).
 */
#define Z_NO_FLUSH      0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH    2
#define Z_FULL_FLUSH    3
#define Z_FINISH        4
#define Z_BLOCK         5
#define Z_TREES         6

/**
 * Allowed flush values; see deflate() and inflate() below for details.
 */
#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO         (-1)
#define Z_STREAM_ERROR  (-2)
#define Z_DATA_ERROR    (-3)
#define Z_MEM_ERROR     (-4)
#define Z_BUF_ERROR     (-5)
#define Z_VERSION_ERROR (-6)

/**
 * Return codes for the compression/decompression functions. Negative
 * values are errors, positive values are used for special but normal
 * events.
 */
#define Z_NO_COMPRESSION      0
#define Z_BEST_SPEED          1
#define Z_BEST_COMPRESSION    9
#define Z_DEFAULT_COMPRESSION (-1)

/**
 * Compression levels.
 */
#define Z_FILTERED         1
#define Z_HUFFMAN_ONLY     2
#define Z_RLE              3
#define Z_FIXED            4
#define Z_DEFAULT_STRATEGY 0

/**
 * Compression strategy; see deflateInit2() below for details
 */
#define Z_BINARY  0
#define Z_TEXT    1
#define Z_ASCII   Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN 2

/**
 * Possible values of the data_type field for deflate()
 */
#define Z_DEFLATED 8

/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */

COSMOPOLITAN_C_START_

typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
typedef void (*free_func)(voidpf opaque, voidpf address);

struct internal_state;

typedef struct z_stream_s {
  const Bytef *next_in;         /* next input byte */
  uInt avail_in;                /* number of bytes available at next_in */
  uLong total_in;               /* total number of input bytes read so far */
  Bytef *next_out;              /* next output byte will go here */
  uInt avail_out;               /* remaining free space at next_out */
  uLong total_out;              /* total number of bytes output so far */
  const char *msg;              /* last error message, NULL if no error */
  struct internal_state *state; /* not visible by applications */
  alloc_func zalloc;            /* used to allocate the internal state */
  free_func zfree;              /* used to free the internal state */
  voidpf opaque;  /* private data object passed to zalloc and zfree */
  int data_type;  /* best guess about the data type: binary or text
                     for deflate, or the decoding state for inflate */
  uLong adler;    /* Adler-32 or CRC-32 value of the uncompressed data */
  uLong reserved; /* reserved for future use */
} z_stream;

typedef z_stream *z_streamp;

/**
 * gzip header information passed to and from zlib routines. See RFC
 * 1952 for more details on the meanings of these fields.
 */
typedef struct gz_header_s {
  int text;       /* true if compressed data believed to be text */
  uLong time_;    /* modification time */
  int xflags;     /* extra flags (not used when writing a gzip file) */
  int os;         /* operating system */
  Bytef *extra;   /* pointer to extra field or Z_NULL if none */
  uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  uInt extra_max; /* space at extra (only when reading header) */
  Bytef *name;    /* pointer to zero-terminated file name or Z_NULL */
  uInt name_max;  /* space at name (only when reading header) */
  Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  uInt comm_max;  /* space at comment (only when reading header) */
  int hcrc;       /* true if there was or will be a header crc */
  int done;       /* true when done reading gzip header (not used
                     when writing a gzip file) */
} gz_header;

typedef gz_header *gz_headerp;

#define zlib_version zlibVersion()

/**
 * The application can compare zlibVersion and ZLIB_VERSION for consistency.
 * If the first character differs, the library code actually used is not
 * compatible with the zlib.h header file used by the application.  This check
 * is automatically made by deflateInit and inflateInit.
 */
const char *zlibVersion(void);

/**
 * Initializes the internal stream state for compression.  The fields
 * zalloc, zfree and opaque must be initialized before by the caller.  If
 * zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
 * allocation functions.
 *
 * The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
 * 1 gives best speed, 9 gives best compression, 0 gives no compression at all
 * (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION
 * requests a default compromise between speed and compression (currently
 * equivalent to level 6).
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if level is not a valid compression level. msg
 *     is set to null if there is no error message. deflateInit does not
 *     perform any compression: this will be done by deflate().
 */
int deflateInit(z_streamp strm, int level);

/**
 * deflate compresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full. It may
 * introduce some output latency (reading input without producing any
 * output) except when forced to flush.
 *
 * The detailed semantics are as follows. deflate performs one or both
 * of the following actions:
 *
 * - Compress more input starting at next_in and update next_in and
 *  avail_in accordingly. If not all input can be processed (because
 *  there is not enough room in the output buffer), next_in and avail_in
 *  are updated and processing will resume at this point for the next
 *  call of deflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *  avail_out accordingly. This action is forced if the parameter flush
 *  is non zero. Forcing flush frequently degrades the compression
 *  ratio, so this parameter should be set only when necessary. Some
 *  output may be provided even if flush is zero.
 *
 * Before the call of deflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating avail_in or avail_out
 * accordingly; avail_out should never be zero before the call. The
 * application can consume the compressed output when it wants, for
 * example when the output buffer is full (avail_out == 0), or after
 * each call of deflate(). If deflate returns Z_OK and with zero
 * avail_out, it must be called again after making room in the output
 * buffer because there might be more output pending. See
 * deflatePending(), which can be used if desired to determine whether
 * or not there is more ouput in that case.
 *
 * Normally the parameter flush is set to Z_NO_FLUSH, which allows
 * deflate to decide how much data to accumulate before producing
 * output, in order to maximize compression.
 *
 * If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
 * flushed to the output buffer and the output is aligned on a byte
 * boundary, so that the decompressor can get all input data available
 * so far. (In particular avail_in is zero after the call if enough
 * output space has been provided before the call.) Flushing may degrade
 * compression for some compression algorithms and so it should be used
 * only when necessary. This completes the current deflate block and
 * follows it with an empty stored block that is three bits plus filler
 * bits to the next byte, followed by four bytes (00 00 ff ff).
 *
 * If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to
 * the output buffer, but the output is not aligned to a byte boundary.
 * All of the input data so far will be available to the decompressor,
 * as for Z_SYNC_FLUSH. This completes the current deflate block and
 * follows it with an empty fixed codes block that is 10 bits long. This
 * assures that enough bytes are output in order for the decompressor to
 * finish the block before the empty fixed codes block.
 *
 * If flush is set to Z_BLOCK, a deflate block is completed and emitted,
 * as for Z_SYNC_FLUSH, but the output is not aligned on a byte
 * boundary, and up to seven bits of the current block are held to be
 * written as the next byte after the next deflate block is completed.
 * In this case, the decompressor may not be provided enough bits at
 * this point in order to complete decompression of the data provided so
 * far to the compressor. It may need to wait for the next block to be
 * emitted. This is for advanced applications that need to control the
 * emission of deflate blocks.
 *
 * If flush is set to Z_FULL_FLUSH, all output is flushed as with
 * Z_SYNC_FLUSH, and the compression state is reset so that
 * decompression can restart from this point if previous compressed data
 * has been damaged or if random access is desired. Using Z_FULL_FLUSH
 * too often can seriously degrade compression.
 *
 * If deflate returns with avail_out == 0, this function must be called
 * again with the same value of the flush parameter and more output
 * space (updated avail_out), until the flush is complete (deflate
 * returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or
 * Z_SYNC_FLUSH, make sure that avail_out is greater than six to avoid
 * repeated flush markers due to avail_out == 0 on return.
 *
 * If the parameter flush is set to Z_FINISH, pending input is
 * processed, pending output is flushed and deflate returns with
 * Z_STREAM_END if there was enough output space. If deflate returns
 * with Z_OK or Z_BUF_ERROR, this function must be called again with
 * Z_FINISH and more output space (updated avail_out) but no more input
 * data, until it returns with Z_STREAM_END or an error. After deflate
 * has returned Z_STREAM_END, the only possible operations on the stream
 * are deflateReset or deflateEnd.
 *
 * Z_FINISH can be used in the first deflate call after deflateInit if
 * all the compression is to be done in a single step. In order to
 * complete in one call, avail_out must be at least the value returned
 * by deflateBound (see below). Then deflate is guaranteed to return
 * Z_STREAM_END. If not enough output space is provided, deflate will
 * not return Z_STREAM_END, and it must be called again as described
 * above.
 *
 * deflate() sets strm->adler to the Adler-32 checksum of all input read
 * so far (that is, total_in bytes). If a gzip stream is being
 * generated, then strm->adler will be the CRC-32 checksum of the input
 * read so far. (See deflateInit2 below.)
 *
 * deflate() may update strm->data_type if it can make a good guess about
 * the input data type (Z_BINARY or Z_TEXT).  If in doubt, the data is
 * considered binary.  This field is only for information purposes and does not
 * affect the compression algorithm in any manner.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if all input has been
 *     consumed and all output has been produced (only when flush is set
 *     to Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent
 *     (for example if next_in or next_out was Z_NULL or the state was
 *     inadvertently written over by the application), or Z_BUF_ERROR if
 *     no progress is possible (for example avail_in or avail_out was
 *     zero). Note that Z_BUF_ERROR is not fatal, and deflate() can be
 *     called again with more input and more output space to continue
 *     compressing.
 */
int deflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the stream state was
 *     inconsistent, Z_DATA_ERROR if the stream was freed prematurely
 *     (some input or output was discarded). In the error case, msg may
 *     be set but then points to a static string (which must not be
 *     deallocated).
 */
int deflateEnd(z_streamp strm);

/**
 * Initializes the internal stream state for decompression. The fields
 * next_in, avail_in, zalloc, zfree and opaque must be initialized
 * before by the caller. In the current version of inflate, the provided
 * input is not read or consumed. The allocation of a sliding window
 * will be deferred to the first call of inflate (if the decompression
 * does not complete on the first call). If zalloc and zfree are set to
 * Z_NULL, inflateInit updates them to use default allocation functions.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit does not perform any decompression. Actual
 *     decompression will be done by inflate(). So next_in, and
 *     avail_in, next_out, and avail_out are unused and unchanged. The
 *     current implementation of inflateInit() does not process any
 *     header information -- that is deferred until inflate() is called.
 */
int inflateInit(z_streamp strm);

/**
 * inflate decompresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full.  It may introduce
 * some output latency (reading input without producing any output) except when
 * forced to flush.
 *
 * The detailed semantics are as follows.  inflate performs one or both of the
 * following actions:
 *
 * - Decompress more input starting at next_in and update next_in and
 *   avail_in accordingly. If not all input can be processed (because
 *   there is not enough room in the output buffer), then next_in and
 *   avail_in are updated accordingly, and processing will resume at
 *   this point for the next call of inflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *   avail_out accordingly. inflate() provides as much output as
 *   possible, until there is no more input data or no more space in the
 *   output buffer (see below about the flush parameter).
 *
 * Before the call of inflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating the next_* and avail_* values
 * accordingly. If the caller of inflate() does not provide both
 * available input and available output space, it is possible that there
 * will be no progress made. The application can consume the
 * uncompressed output when it wants, for example when the output buffer
 * is full (avail_out == 0), or after each call of inflate(). If inflate
 * returns Z_OK and with zero avail_out, it must be called again after
 * making room in the output buffer because there might be more output
 * pending.
 *
 * The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
 * Z_FINISH, Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate()
 * flush as much output as possible to the output buffer. Z_BLOCK
 * requests that inflate() stop if and when it gets to the next deflate
 * block boundary. When decoding the zlib or gzip format, this will
 * cause inflate() to return immediately after the header and before the
 * first block. When doing a raw inflate, inflate() will go ahead and
 * process the first block, and will return when it gets to the end of
 * that block, or when it runs out of data.
 *
 * The Z_BLOCK option assists in appending to or combining deflate
 * streams. To assist in this, on return inflate() always sets
 * strm->data_type to the number of unused bits in the last byte taken
 * from strm->next_in, plus 64 if inflate() is currently decoding the
 * last block in the deflate stream, plus 128 if inflate() returned
 * immediately after decoding an end-of-block code or decoding the
 * complete header up to just before the first byte of the deflate
 * stream. The end-of-block will not be indicated until all of the
 * uncompressed data from that block has been written to strm->next_out.
 * The number of unused bits may in general be greater than seven,
 * except when bit 7 of data_type is set, in which case the number of
 * unused bits will be less than eight. data_type is set as noted here
 * every time inflate() returns for all flush options, and so can be
 * used to determine the amount of currently consumed input in bits.
 *
 * The Z_TREES option behaves as Z_BLOCK does, but it also returns when
 * the end of each deflate block header is reached, before any actual
 * data in that block is decoded. This allows the caller to determine
 * the length of the deflate block header for later use in random access
 * within a deflate block. 256 is added to the value of strm->data_type
 * when inflate() returns immediately after reaching the end of the
 * deflate block header.
 *
 * inflate() should normally be called until it returns Z_STREAM_END or
 * an error. However if all decompression is to be performed in a single
 * step (a single call of inflate), the parameter flush should be set to
 * Z_FINISH. In this case all pending input is processed and all pending
 * output is flushed; avail_out must be large enough to hold all of the
 * uncompressed data for the operation to complete. (The size of the
 * uncompressed data may have been saved by the compressor for this
 * purpose.) The use of Z_FINISH is not required to perform an inflation
 * in one step. However it may be used to inform inflate that a faster
 * approach can be used for the single inflate() call. Z_FINISH also
 * informs inflate to not maintain a sliding window if the stream
 * completes, which reduces inflate's memory footprint. If the stream
 * does not complete, either because not all of the stream is provided
 * or not enough output space is provided, then a sliding window will be
 * allocated and inflate() can be called again to continue the operation
 * as if Z_NO_FLUSH had been used.
 *
 * In this implementation, inflate() always flushes as much output as
 * possible to the output buffer, and always uses the faster approach on
 * the first call. So the effects of the flush parameter in this
 * implementation are on the return value of inflate() as noted below,
 * when inflate() returns early when Z_BLOCK or Z_TREES is used, and
 * when inflate() avoids the allocation of memory for a sliding window
 * when Z_FINISH is used.
 *
 * If a preset dictionary is needed after this call (see
 * inflateSetDictionary below), inflate sets strm->adler to the Adler-32
 * checksum of the dictionary chosen by the compressor and returns
 * Z_NEED_DICT; otherwise it sets strm->adler to the Adler-32 checksum
 * of all output produced so far (that is, total_out bytes) and returns
 * Z_OK, Z_STREAM_END or an error code as described below. At the end of
 * the stream, inflate() checks that its computed Adler-32 checksum is
 * equal to that saved by the compressor and returns Z_STREAM_END only
 * if the checksum is correct.
 *
 * inflate() can decompress and check either zlib-wrapped or
 * gzip-wrapped deflate data. The header type is detected automatically,
 * if requested when initializing with inflateInit2(). Any information
 * contained in the gzip header is not retained unless
 * inflateGetHeader() is used. When processing gzip-wrapped deflate
 * data, strm->adler32 is set to the CRC-32 of the output produced so
 * far. The CRC-32 is checked against the gzip trailer, as is the
 * uncompressed length, modulo 2^32.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if the end of the compressed
 *     data has been reached and all uncompressed output has been
 *     produced, Z_NEED_DICT if a preset dictionary is needed at this
 *     point, Z_DATA_ERROR if the input data was corrupted (input stream
 *     not conforming to the zlib format or incorrect check value, in
 *     which case strm->msg points to a string with a more specific
 *     error), Z_STREAM_ERROR if the stream structure was inconsistent
 *     (for example next_in or next_out was Z_NULL, or the state was
 *     inadvertently written over by the application), Z_MEM_ERROR if
 *     there was not enough memory, Z_BUF_ERROR if no progress was
 *     possible or if there was not enough room in the output buffer
 *     when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
 *     inflate() can be called again with more input and more output
 *     space to continue decompressing. If Z_DATA_ERROR is returned, the
 *     application may then call inflateSync() to look for a good
 *     compression block if a partial recovery of the data is to be
 *     attempted.
 */
int inflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK or Z_STREAM_ERROR if stream state inconsistent
 */
int inflateEnd(z_streamp strm);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » special functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  the following functions are needed only in some special applications */

/**
 * This is another version of deflateInit with more compression options.
 * The fields next_in, zalloc, zfree and opaque must be initialized
 * before by the caller.
 *
 * The method parameter is the compression method. It must be Z_DEFLATED
 * in this version of the library.
 *
 * The windowBits parameter is the base two logarithm of the window size
 * (the size of the history buffer). It should be in the range 8..15 for
 * this version of the library. Larger values of this parameter result
 * in better compression at the expense of memory usage. The default
 * value is 15 if deflateInit is used instead.
 *
 * For the current implementation of deflate(), a windowBits value of 8
 * (a window size of 256 bytes) is not supported. As a result, a request
 * for 8 will result in 9 (a 512-byte window). In that case, providing 8
 * to inflateInit2() will result in an error when the zlib header with 9
 * is checked against the initialization of inflate(). The remedy is to
 * not use 8 with deflateInit2() with this initialization, or at least
 * in that case use 9 with inflateInit2().
 *
 * windowBits can also be -8..-15 for raw deflate. In this case,
 * -windowBits determines the window size. deflate() will then generate
 * raw deflate data with no zlib header or trailer, and will not compute
 * a check value.
 *
 * windowBits can also be greater than 15 for optional gzip encoding.
 * Add 16 to windowBits to write a simple gzip header and trailer around
 * the compressed data instead of a zlib wrapper. The gzip header will
 * have no file name, no extra data, no comment, no modification time
 * (set to zero), no header crc, and the operating system will be set to
 * the appropriate value, if the operating system was determined at
 * compile time. If a gzip stream is being written, strm->adler is a
 * CRC-32 instead of an Adler-32.
 *
 * For raw deflate or gzip encoding, a request for a 256-byte window is
 * rejected as invalid, since only the zlib header provides a means of
 * transmitting the window size to the decompressor.
 *
 * The memLevel parameter specifies how much memory should be allocated
 * for the internal compression state. memLevel=1 uses minimum memory
 * but is slow and reduces compression ratio; memLevel=9 uses maximum
 * memory for optimal speed. The default value is 8. See zconf.h for
 * total memory usage as a function of windowBits and memLevel.
 *
 * The strategy parameter is used to tune the compression algorithm. Use
 * the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
 * produced by a filter (or predictor), Z_HUFFMAN_ONLY to force Huffman
 * encoding only (no string match), or Z_RLE to limit match distances to
 * one (run-length encoding). Filtered data consists mostly of small
 * values with a somewhat random distribution. In this case, the
 * compression algorithm is tuned to compress them better. The effect of
 * Z_FILTERED is to force more Huffman coding and less string matching;
 * it is somewhat intermediate between Z_DEFAULT_STRATEGY and
 * Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
 * Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
 * strategy parameter only affects the compression ratio but not the
 * correctness of the compressed output even if it is not set
 * appropriately. Z_FIXED prevents the use of dynamic Huffman codes,
 * allowing for a simpler decoder for special applications.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if any parameter is invalid (such as an invalid
 *     method). msg is set to null if there is no error message.
 *     deflateInit2 does not perform any compression: this will be done
 *     by deflate().
 */
int deflateInit2(z_streamp strm, int level, int method, int windowBits,
                 int memLevel, int strategy);

/**
 * Initializes the compression dictionary from the given byte sequence
 * without producing any compressed output. When using the zlib format,
 * this function must be called immediately after deflateInit,
 * deflateInit2 or deflateReset, and before any call of deflate. When
 * doing raw deflate, this function must be called either before any
 * call of deflate, or immediately after the completion of a deflate
 * block, i.e. after all input has been consumed and all output has been
 * delivered when using any of the flush options Z_BLOCK,
 * Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The compressor and
 * decompressor must use exactly the same dictionary (see
 * inflateSetDictionary).
 *
 * The dictionary should consist of strings (byte sequences) that are
 * likely to be encountered later in the data to be compressed, with the
 * most commonly used strings preferably put towards the end of the
 * dictionary. Using a dictionary is most useful when the data to be
 * compressed is short and can be predicted with good accuracy; the data
 * can then be compressed better than with the default empty dictionary.
 *
 * Depending on the size of the compression data structures selected by
 * deflateInit or deflateInit2, a part of the dictionary may in effect
 * be discarded, for example if the dictionary is larger than the window
 * size provided in deflateInit or deflateInit2. Thus the strings most
 * likely to be useful should be put at the end of the dictionary, not
 * at the front. In addition, the current implementation of deflate will
 * use at most the window size minus 262 bytes of the provided
 * dictionary.
 *
 * Upon return of this function, strm->adler is set to the Adler-32
 * value of the dictionary; the decompressor may later use this value to
 * determine which dictionary has been used by the compressor. (The
 * Adler-32 value applies to the whole dictionary even if only a subset
 * of the dictionary is actually used by the compressor.) If a raw
 * deflate was requested, then the Adler-32 value is not computed and
 * strm->adler is not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent (for example if deflate has already been called for
 *     this stream or if not at a block boundary for raw deflate).
 *     deflateSetDictionary does not perform any compression: this will
 *     be done by deflate().
 */
int deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by deflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If deflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * deflateGetDictionary() may return a length less than the window size, even
 * when more than the window size in input has been provided. It may return up
 * to 258 bytes less in that case, due to how zlib's implementation of deflate
 * manages the sliding window and lookahead for matches, where matches can be
 * up to 258 bytes long. If the application needs the last window-size bytes of
 * input, then that would need to be saved by the application outside of zlib.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int deflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Sets destination stream as a complete copy of the source stream.
 *
 * This function can be useful when several compression strategies will be
 * tried, for example when there are several ways of pre-processing the input
 * data with a filter.  The streams that will be discarded should then be freed
 * by calling deflateEnd.  Note that deflateCopy duplicates the internal
 * compression state which can be quite large, so this strategy is slow and can
 * consume lots of memory.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int deflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to deflateEnd followed by deflateInit, but
 * does not free and reallocate the internal compression state.  The stream
 * will leave the compression level and any other attributes that may have been
 * set unchanged.
 *
 * deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 * stream state was inconsistent (such as zalloc or state being Z_NULL).
 */
int deflateReset(z_streamp strm);

/**
 * Dynamically update the compression level and compression strategy.  The
 * interpretation of level and strategy is as in deflateInit2().  This can be
 * used to switch between compression and straight copy of the input data, or
 * to switch to a different kind of input data requiring a different strategy.
 * If the compression approach (which is a function of the level) or the
 * strategy is changed, and if any input has been consumed in a previous
 * deflate() call, then the input available so far is compressed with the old
 * level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
 * for the compression levels 0, 1..3, and 4..9 respectively.  The new level
 * and strategy will take effect at the next call of deflate().
 *
 * If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
 * not have enough output space to complete, then the parameter change will not
 * take effect.  In this case, deflateParams() can be called again with the
 * same parameters and more output space to try again.
 *
 * In order to assure a change in the parameters on the first try, the
 * deflate stream should be flushed using deflate() with Z_BLOCK or other flush
 * request until strm.avail_out is not zero, before calling deflateParams().
 * Then no more input data should be provided before the deflateParams() call.
 * If this is done, the old level and strategy will be applied to the data
 * compressed before deflateParams(), and the new level and strategy will be
 * applied to the the data compressed after deflateParams().
 *
 * deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
 * state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
 * there was not enough output space to complete the compression of the
 * available input data before a change in the strategy or approach.  Note that
 * in the case of a Z_BUF_ERROR, the parameters are not changed.  A return
 * value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
 * retried with more output space.
 */
int deflateParams(z_streamp strm, int level, int strategy);

/**
 * Fine tune deflate's internal compression parameters. This should only
 * be used by someone who understands the algorithm used by zlib's
 * deflate for searching for the best matching string, and even then
 * only by the most fanatic optimizer trying to squeeze out the last
 * compressed bit for their specific input data. Read the deflate.c
 * source code for the meaning of the max_lazy, good_length,
 * nice_length, and max_chain parameters.
 *
 * deflateTune() can be called after deflateInit() or deflateInit2(), and
 * returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
 */
int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
                int max_chain);

/**
 * deflateBound() returns an upper bound on the compressed size after
 * deflation of sourceLen bytes. It must be called after deflateInit()
 * or deflateInit2(), and after deflateSetHeader(), if used. This would
 * be used to allocate an output buffer for deflation in a single pass,
 * and so would be called before deflate(). If that first deflate() call
 * is provided the sourceLen input bytes, an output buffer allocated to
 * the size returned by deflateBound(), and the flush value Z_FINISH,
 * then deflate() is guaranteed to return Z_STREAM_END. Note that it is
 * possible for the compressed size to be larger than the value returned
 * by deflateBound() if flush options other than Z_FINISH or Z_NO_FLUSH
 * are used.
 */
uLong deflateBound(z_streamp strm, uLong sourceLen);

/**
 * deflatePending() returns the number of bytes and bits of output that
 * have been generated, but not yet provided in the available output.
 * The bytes not provided would be due to the available output space
 * having being consumed. The number of bits of output not provided are
 * between 0 and 7, where they await more bits to join them in order to
 * fill out a full byte. If pending or bits are Z_NULL, then those
 * values are not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int deflatePending(z_streamp strm, unsigned *pending, int *bits);

/**
 * deflatePrime() inserts bits in the deflate output stream.  The intent
 * is that this function is used to start off the deflate output with the bits
 * leftover from a previous deflate stream when appending to it.  As such, this
 * function can only be used for raw deflate, and must be used before the first
 * deflate() call after a deflateInit2() or deflateReset().  bits must be less
 * than or equal to 16, and that many of the least significant bits of value
 * will be inserted in the output.
 *
 * @return Z_OK if success, Z_BUF_ERROR if there was not enough room in
 *     the internal buffer to insert the bits, or Z_STREAM_ERROR if the
 *     source stream state was inconsistent.
 */
int deflatePrime(z_streamp strm, int bits, int value);

/**
 * Provides gzip header information for when a gzip stream is requested
 * by deflateInit2(). deflateSetHeader() may be called after
 * deflateInit2() or deflateReset() and before the first call of
 * deflate(). The text, time, os, extra field, name, and comment
 * information in the provided gz_header structure are written to the
 * gzip header (xflag is ignored -- the extra flags are set according to
 * the compression level). The caller must assure that, if not Z_NULL,
 * name and comment are terminated with a zero byte, and that if extra
 * is not Z_NULL, that extra_len bytes are available there. If hcrc is
 * true, a gzip header crc is included. Note that the current versions
 * of the command-line version of gzip (up through version 1.3.x) do not
 * support header crc's, and will report that it is a "multi-part gzip
 * file" and give up.
 *
 * If deflateSetHeader is not used, the default gzip header has text
 * false, the time set to zero, and os set to 255, with no extra, name,
 * or comment fields. The gzip header is returned to the default state
 * by deflateReset().
 *
 * deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the
 * source stream state was inconsistent.
 */
int deflateSetHeader(z_streamp strm, gz_headerp head);

/**
 * This is another version of inflateInit with an extra parameter. The
 * fields next_in, avail_in, zalloc, zfree and opaque must be
 * initialized before by the caller.
 *
 * The windowBits parameter is the base two logarithm of the maximum
 * window size (the size of the history buffer). It should be in the
 * range 8..15 for this version of the library. The default value is 15
 * if inflateInit is used instead. windowBits must be greater than or
 * equal to the windowBits value provided to deflateInit2() while
 * compressing, or it must be equal to 15 if deflateInit2() was not
 * used. If a compressed stream with a larger window size is given as
 * input, inflate() will return with the error code Z_DATA_ERROR instead
 * of trying to allocate a larger window.
 *
 * windowBits can also be zero to request that inflate use the window
 * size in the zlib header of the compressed stream.
 *
 * windowBits can also be -8..-15 for raw inflate. In this case,
 * -windowBits determines the window size. inflate() will then process
 * raw deflate data, not looking for a zlib or gzip header, not
 * generating a check value, and not looking for any check values for
 * comparison at the end of the stream. This is for use with other
 * formats that use the deflate compressed data format such as zip.
 * Those formats provide their own check values. If a custom format is
 * developed using the raw deflate format for compressed data, it is
 * recommended that a check value such as an Adler-32 or a CRC-32 be
 * applied to the uncompressed data as is done in the zlib, gzip, and
 * zip formats. For most applications, the zlib format should be used as
 * is. Note that comments above on the use in deflateInit2() applies to
 * the magnitude of windowBits.
 *
 * windowBits can also be greater than 15 for optional gzip decoding.
 * Add 32 to windowBits to enable zlib and gzip decoding with automatic
 * header detection, or add 16 to decode only the gzip format (the zlib
 * format will return a Z_DATA_ERROR). If a gzip stream is being
 * decoded, strm->adler is a CRC-32 instead of an Adler-32. Unlike the
 * gunzip utility and gzread() (see below), inflate() will not
 * automatically decode concatenated gzip streams. inflate() will return
 * Z_STREAM_END at the end of the gzip stream. The state would need to
 * be reset to continue decoding a subsequent gzip stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit2 does not perform any decompression apart
 *     from possibly reading the zlib header if present: actual
 *     decompression will be done by inflate(). (So next_in and avail_in
 *     may be modified, but next_out and avail_out are unused and
 *     unchanged.) The current implementation of inflateInit2() does not
 *     process any header information -- that is deferred until
 *     inflate() is called.
 */
int inflateInit2(z_streamp strm, int windowBits);

/**
 * Initializes the decompression dictionary from the given uncompressed
 * byte sequence. This function must be called immediately after a call
 * of inflate, if that call returned Z_NEED_DICT. The dictionary chosen
 * by the compressor can be determined from the Adler-32 value returned
 * by that call of inflate. The compressor and decompressor must use
 * exactly the same dictionary (see deflateSetDictionary). For raw
 * inflate, this function can be called at any time to set the
 * dictionary. If the provided dictionary is smaller than the window and
 * there is already data in the window, then the provided dictionary
 * will amend what's there. The application must insure that the
 * dictionary that was used for compression is provided.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent, Z_DATA_ERROR if the given dictionary doesn't match
 *     the expected one (incorrect Adler-32 value). inflateSetDictionary
 *     does not perform any decompression: this will be done by
 *     subsequent calls of inflate().
 */
int inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by inflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If inflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Skips invalid compressed data until a possible full flush point (see
 * above for the description of deflate with Z_FULL_FLUSH) can be found,
 * or until all available input is skipped. No output is provided.
 *
 * inflateSync searches for a 00 00 FF FF pattern in the compressed
 * data. All full flush points have this pattern, but not all
 * occurrences of this pattern are full flush points.
 *
 * @return Z_OK if a possible full flush point has been found,
 *     Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no
 *     flush point has been found, or Z_STREAM_ERROR if the stream
 *     structure was inconsistent. In the success case, the application
 *     may save the current current value of total_in which indicates
 *     where valid compressed data was found. In the error case, the
 *     application may repeatedly call inflateSync, providing more input
 *     each time, until success or end of the input data.
 */
int inflateSync(z_streamp strm);

/**
 * Sets the destination stream as a complete copy of the source stream.
 *
 * This function can be useful when randomly accessing a large stream.
 * The first pass through the stream can periodically record the inflate
 * state, allowing restarting inflate at those points when randomly
 * accessing the stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int inflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to inflateEnd followed by inflateInit,
 * but does not free and reallocate the internal decompression state.  The
 * stream will keep attributes that may have been set by inflateInit2.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL).
 */
int inflateReset(z_streamp strm);

/**
 * This function is the same as inflateReset, but it also permits changing
 * the wrap and window size requests.  The windowBits parameter is interpreted
 * the same as it is for inflateInit2.  If the window size is changed, then the
 * memory allocated for the window is freed, and the window will be reallocated
 * by inflate() if needed.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL), or if
 *     the windowBits parameter is invalid.
 */
int inflateReset2(z_streamp strm, int windowBits);

/**
 * This function inserts bits in the inflate input stream.  The intent is
 * that this function is used to start inflating at a bit position in the
 * middle of a byte.  The provided bits will be used before any bytes are used
 * from next_in.  This function should only be used with raw inflate, and
 * should be used before the first inflate() call after inflateInit2() or
 * inflateReset().  bits must be less than or equal to 16, and that many of the
 * least significant bits of value will be inserted in the input.
 *
 * If bits is negative, then the input stream bit buffer is emptied.  Then
 * inflatePrime() can be called again to put bits in the buffer.  This is used
 * to clear out bits leftover after feeding inflate a block description prior
 * to feeding inflate codes.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflatePrime(z_streamp strm, int bits, int value);

/**
 * Returns two values, one in the lower 16 bits of the return value, and
 * the other in the remaining upper bits, obtained by shifting the
 * return value down 16 bits. If the upper value is -1 and the lower
 * value is zero, then inflate() is currently decoding information
 * outside of a block. If the upper value is -1 and the lower value is
 * non-zero, then inflate is in the middle of a stored block, with the
 * lower value equaling the number of bytes from the input remaining to
 * copy. If the upper value is not -1, then it is the number of bits
 * back from the current bit position in the input of the code (literal
 * or length/distance pair) currently being processed. In that case the
 * lower value is the number of bytes already emitted for that code.
 *
 * A code is being processed if inflate is waiting for more input to
 * complete decoding of the code, or if it has completed decoding but is
 * waiting for more output space to write the literal or match data.
 *
 * inflateMark() is used to mark locations in the input data for random
 * access, which may be at bit positions, and to note those cases where
 * the output of a code may span boundaries of random access blocks. The
 * current location in the input stream can be determined from avail_in
 * and data_type as noted in the description for the Z_BLOCK flush
 * parameter for inflate.
 *
 * @return the value noted above, or -65536 if the provided source
 *     stream state was inconsistent.
 */
long inflateMark(z_streamp strm);

/**
 * inflateGetHeader() requests that gzip header information be stored in
 * the provided gz_header structure. inflateGetHeader() may be called
 * after inflateInit2() or inflateReset(), and before the first call of
 * inflate(). As inflate() processes the gzip stream, head->done is zero
 * until the header is completed, at which time head->done is set to
 * one. If a zlib stream is being decoded, then head->done is set to -1
 * to indicate that there will be no gzip header information
 * forthcoming. Note that Z_BLOCK or Z_TREES can be used to force
 * inflate() to return immediately after header processing is complete
 * and before any actual data is decompressed.
 *
 * The text, time, xflags, and os fields are filled in with the gzip
 * header contents. hcrc is set to true if there is a header CRC. (The
 * header CRC was valid if done is set to one.) If extra is not Z_NULL,
 * then extra_max contains the maximum number of bytes to write to
 * extra. Once done is true, extra_len contains the actual extra field
 * length, and extra contains the extra field, or that field truncated
 * if extra_max is less than extra_len. If name is not Z_NULL, then up
 * to name_max characters are written there, terminated with a zero
 * unless the length is greater than name_max. If comment is not Z_NULL,
 * then up to comm_max characters are written there, terminated with a
 * zero unless the length is greater than comm_max. When any of extra,
 * name, or comment are not Z_NULL and the respective field is not
 * present in the header, then that field is set to Z_NULL to signal its
 * absence. This allows the use of deflateSetHeader() with the returned
 * structure to duplicate the header. However if those fields are set to
 * allocated memory, then the application will need to save those
 * pointers elsewhere so that they can be eventually freed.
 *
 * If inflateGetHeader is not used, then the header information is
 * simply discarded. The header is always checked for validity,
 * including the header CRC if present. inflateReset() will reset the
 * process to discard the header information. The application would need
 * to call inflateGetHeader() again to retrieve the header from the next
 * gzip stream.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflateGetHeader(z_streamp strm, gz_headerp head);

/**
 * Initialize internal stream state for decompression using
 * inflateBack() calls. The fields zalloc, zfree and opaque in strm must
 * be initialized before the call. If zalloc and zfree are Z_NULL, then
 * the default library- derived memory allocation routines are used.
 * windowBits is the base two logarithm of the window size, in the range
 * 8..15. window is a caller supplied buffer of that size. Except for
 * special applications where it is assured that deflate was used with
 * small window sizes, windowBits must be 15 and a 32K byte window must
 * be supplied to be able to decompress general deflate streams.
 *
 * See inflateBack() for the usage of these routines.
 *
 * @return Z_OK on success, Z_STREAM_ERROR if any of the parameters are
 *     invalid, or Z_MEM_ERROR if the internal state could not be
 *     allocated.
 */
int inflateBackInit(z_streamp strm, int windowBits, unsigned char *window);

typedef unsigned (*in_func)(void *, const unsigned char **);
typedef int (*out_func)(void *, unsigned char *, unsigned);

/**
 * inflateBack() does a raw inflate with a single call using a call-back
 * interface for input and output. This is potentially more efficient
 * than inflate() for file i/o applications, in that it avoids copying
 * between the output and the sliding window by simply making the window
 * itself the output buffer. inflate() can be faster on modern CPUs when
 * used with large buffers. inflateBack() trusts the application to not
 * change the output buffer passed by the output function, at least
 * until inflateBack() returns.
 *
 * inflateBackInit() must be called first to allocate the internal state
 * and to initialize the state with the user-provided window buffer.
 * inflateBack() may then be used multiple times to inflate a complete,
 * raw deflate stream with each call. inflateBackEnd() is then called to
 * free the allocated state.
 *
 * A raw deflate stream is one with no zlib or gzip header or trailer.
 * This routine would normally be used in a utility that reads zip or
 * gzip files and writes out uncompressed files. The utility would
 * decode the header and process the trailer on its own, hence this
 * routine expects only the raw deflate stream to decompress. This is
 * different from the default behavior of inflate(), which expects a
 * zlib header and trailer around the deflate stream.
 *
 * inflateBack() uses two subroutines supplied by the caller that are
 * then called by inflateBack() for input and output. inflateBack()
 * calls those routines until it reads a complete deflate stream and
 * writes out all of the uncompressed data, or until it encounters an
 * error. The function's parameters and return types are defined above
 * in the in_func and out_func typedefs. inflateBack() will call
 * in(in_desc, &buf) which should return the number of bytes of provided
 * input, and a pointer to that input in buf. If there is no input
 * available, in() must return zero -- buf is ignored in that case --
 * and inflateBack() will return a buffer error. inflateBack() will call
 * out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
 * out() should return zero on success, or non-zero on failure. If out()
 * returns non-zero, inflateBack() will return with an error. Neither
 * in() nor out() are permitted to change the contents of the window
 * provided to inflateBackInit(), which is also the buffer that out()
 * uses to write from. The length written by out() will be at most the
 * window size. Any non-zero amount of input may be provided by in().
 *
 * For convenience, inflateBack() can be provided input on the first
 * call by setting strm->next_in and strm->avail_in. If that input is
 * exhausted, then in() will be called. Therefore strm->next_in must be
 * initialized before calling inflateBack(). If strm->next_in is Z_NULL,
 * then in() will be called immediately for input. If strm->next_in is
 * not Z_NULL, then strm->avail_in must also be initialized, and then if
 * strm->avail_in is not zero, input will initially be taken from
 * strm->next_in[0 .. strm->avail_in - 1].
 *
 * The in_desc and out_desc parameters of inflateBack() is passed as the
 * first parameter of in() and out() respectively when they are called.
 * These descriptors can be optionally used to pass any information that
 * the caller- supplied in() and out() functions need to do their job.
 *
 * On return, inflateBack() will set strm->next_in and strm->avail_in to
 * pass back any unused input that was provided by the last in() call.
 * The return values of inflateBack() can be Z_STREAM_END on success,
 * Z_BUF_ERROR if in() or out() returned an error, Z_DATA_ERROR if there
 * was a format error in the deflate stream (in which case strm->msg is
 * set to indicate the nature of the error), or Z_STREAM_ERROR if the
 * stream was not properly initialized. In the case of Z_BUF_ERROR, an
 * input or output error can be distinguished using strm->next_in which
 * will be Z_NULL only if in() returned an error. If strm->next_in is
 * not Z_NULL, then the Z_BUF_ERROR was due to out() returning non-zero.
 * (in() will always be called before out(), so strm->next_in is assured
 * to be defined if out() returns non-zero.) Note that inflateBack()
 * cannot return Z_OK.
 */
int inflateBack(z_streamp strm, in_func in, void *in_desc, out_func out,
                void *out_desc);

/**
 * All memory allocated by inflateBackInit() is freed.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state was
 *     inconsistent.
 */
int inflateBackEnd(z_streamp strm);

/*
 * Return flags indicating compile-time options.
 *
 * Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
 *   1.0: size of uInt
 *   3.2: size of uLong
 *   5.4: size of voidpf (pointer)
 *   7.6: size of off_t
 *
 * Compiler, assembler, and debug options:
 *   8: ZLIB_DEBUG
 *   9: ASMV or ASMINF -- use ASM code
 *   10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
 *   11: 0 (reserved)
 *
 * One-time table building (smaller code, but not thread-safe if true):
 *   12: BUILDFIXED -- build static block decoding tables when needed
 *   13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
 *   14,15: 0 (reserved)
 *
 * Library content (indicates missing functionality):
 *
 *   16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
 *   deflate code when not needed)
 *
 *   17: NO_GZIP -- deflate can't write gzip streams, and inflate can't
 *   detect and decode gzip streams (to avoid linking crc code)
 *
 *   18-19: 0 (reserved)
 *
 * Operation variations (changes in library functionality):
 *   20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
 *   21: FASTEST -- deflate algorithm with only one, lowest compression level
 *   22,23: 0 (reserved)
 *
 * The sprintf variant used by gzprintf (zero is best):
 *   24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
 *   25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
 *   26: 0 = returns value, 1 = void -- 1 means inferred string length returned
 *
 * Remainder is:
 *   27-31: 0 (reserved)
 */
uLong zlibCompileFlags(void);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » utility functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  The following utility functions are implemented on top of the basic
  stream-oriented functions. To simplify the interface, some default
  options are assumed (compression level and memory usage, standard
  memory allocation functions). The source code of these utility
  functions can be modified if you need special options. */

/**
 * Compresses source buffer into the destination buffer. sourceLen is
 * the byte length of the source buffer. Upon entry, destLen is the
 * total size of the destination buffer, which must be at least the
 * value returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data. compress() is equivalent to
 * compress2() with a level parameter of Z_DEFAULT_COMPRESSION.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer.
 */
int compress(Bytef *dest, uLongf *destLen, const Bytef *source,
             uLong sourceLen);

/**
 * Compresses source buffer into the destination buffer. The level
 * parameter has the same meaning as in deflateInit. sourceLen is the
 * byte length of the source buffer. Upon entry, destLen is the total
 * size of the destination buffer, which must be at least the value
 * returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer,
 *     Z_STREAM_ERROR if the level parameter is invalid.
 */
int compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
              uLong sourceLen, int level);

/**
 * Returns an upper bound on the compressed size after compress() or
 * compress2() on sourceLen bytes. It would be used before a compress()
 * or compress2() call to allocate the destination buffer.
 */
uLong compressBound(uLong sourceLen);

/**
 * Decompresses the source buffer into the destination buffer.  sourceLen is
 * the byte length of the source buffer.  Upon entry, destLen is the total size
 * of the destination buffer, which must be large enough to hold the entire
 * uncompressed data.  (The size of the uncompressed data must have been saved
 * previously by the compressor and transmitted to the decompressor by some
 * mechanism outside the scope of this compression library.) Upon exit, destLen
 * is the actual size of the uncompressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer, or
 *     Z_DATA_ERROR if the input data was corrupted or incomplete. In
 *     the case where there is not enough room, uncompress() will fill
 *     the output buffer with the uncompressed data up to that point.
 */
int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
               uLong sourceLen);

/**
 * Same as uncompress, except that sourceLen is a pointer, where the
 * length of the source is *sourceLen.  On return, *sourceLen is the number of
 * source bytes consumed.
 */
int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
                uLong *sourceLen);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » gzip                                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  This library supports reading and writing files in gzip (.gz) format
  with an interface similar to that of stdio, using the functions that
  start with "gz". The gzip format is different from the zlib format.
  gzip is a gzip wrapper, documented in RFC 1952, wrapped around a
  deflate stream. */

typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */

/**
 * Opens a gzip (.gz) file for reading or writing.
 *
 * The mode parameter is as in fopen ("rb" or "wb") but can also include
 * a compression level ("wb9") or a strategy: 'f' for filtered data as
 * in "wb6f", 'h' for Huffman-only compression as in "wb1h", 'R' for
 * run-length encoding as in "wb1R", or 'F' for fixed code compression
 * as in "wb9F". (See the description of deflateInit2 for more
 * information about the strategy parameter.) 'T' will request
 * transparent writing or appending with no compression and not using
 * the gzip format.
 *
 * "a" can be used instead of "w" to request that the gzip stream that
 * will be written be appended to the file. "+" will result in an error,
 * since reading and writing to the same gzip file is not supported. The
 * addition of "x" when writing will create the file exclusively, which
 * fails if the file already exists. On systems that support it, the
 * addition of "e" when reading or writing will set the flag to close
 * the file on an execve() call.
 *
 * These functions, as well as gzip, will read and decode a sequence of
 * gzip streams in a file. The append function of gzopen() can be used
 * to create such a file. (Also see gzflush() for another way to do
 * this.) When appending, gzopen does not test whether the file begins
 * with a gzip stream, nor does it look for the end of the gzip streams
 * to begin appending. gzopen will simply append a gzip stream to the
 * existing file.
 *
 * gzopen can be used to read a file which is not in gzip format; in
 * this case gzread will directly read from the file without
 * decompression. When reading, this will be detected automatically by
 * looking for the magic two- byte gzip header.
 *
 * @return Z_OK if the file could not be opened, if there was insufficient
 *     memory to allocate the gzFile state, or if an invalid mode was
 *     specified (an 'r', 'w', or 'a' was not provided, or '+' was
 *     provided). errno can be checked to determine if the reason gzopen
 *     failed was that the file could not be opened.
 */
gzFile gzopen(const char *path, const char *mode);

/**
 * Associates gzFile with the file descriptor.
 *
 * File descriptors are obtained from calls like open, dup, creat, pipe
 * or fileno (if the file has been previously opened with fopen). The
 * mode parameter is as in gzopen.
 *
 * The next call of gzclose on the returned gzFile will also close the file
 * descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
 * fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
 * mode);.  The duplicated descriptor should be saved to avoid a leak, since
 * gzdopen does not close fd if it fails.  If you are using fileno() to get the
 * file descriptor from a FILE *, then you will have to use dup() to avoid
 * double-close()ing the file descriptor.  Both gzclose() and fclose() will
 * close the associated file descriptor, so they need to have different file
 * descriptors.
 *
 * @return Z_OK if there was insufficient memory to allocate the gzFile
 *     state, if an invalid mode was specified (an 'r', 'w', or 'a' was
 *     not provided, or '+' was provided), or if fd is -1. The file
 *     descriptor is not used until the next gz* read, write, seek, or
 *     close operation, so gzdopen will not detect if fd is invalid
 *     (unless fd is -1).
 */
gzFile gzdopen(int fd, const char *mode);

/**
 * Sets internal buffer size used by this library's functions. The
 * default buffer size is 8192 bytes. This function must be called after
 * gzopen() or gzdopen(), and before any other calls that read or write
 * the file. The buffer memory allocation is always deferred to the
 * first read or write. Three times that size in buffer space is
 * allocated. A larger buffer size of, for example, 64K or 128K bytes
 * will noticeably increase the speed of decompression (reading).
 *
 * The new buffer size also affects the maximum length for gzprintf().
 *
 * @return Z_OK on success, or -1 on failure, such as being called too
 *     late.
 */
int gzbuffer(gzFile file, unsigned size);

/**
 * Dynamically update the compression level or strategy.  See the description
 * of deflateInit2 for the meaning of these parameters.  Previously provided
 * data is flushed before the parameter change.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the file was not opened for
 *     writing, Z_ERRNO if there is an error writing the flushed data,
 *     or Z_MEM_ERROR if there is a memory allocation error.
 */
int gzsetparams(gzFile file, int level, int strategy);

/**
 * Reads given number of uncompressed bytes from the compressed file. If
 * the input file is not in gzip format, gzread copies the given number
 * of bytes into the buffer directly from the file.
 *
 * After reaching the end of a gzip stream in the input, gzread will continue
 * to read, looking for another gzip stream.  Any number of gzip streams may be
 * concatenated in the input file, and will all be decompressed by gzread().
 * If something other than a gzip stream is encountered after a gzip stream,
 * that remaining trailing garbage is ignored (and no error is returned).
 *
 * gzread can be used to read a gzip file that is being concurrently written.
 * Upon reaching the end of the input, gzread will return with the available
 * data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
 * gzclearerr can be used to clear the end of file indicator in order to permit
 * gzread to be tried again.  Z_OK indicates that a gzip stream was completed
 * on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
 * middle of a gzip stream.  Note that gzread does not return -1 in the event
 * of an incomplete gzip stream.  This error is deferred until gzclose(), which
 * will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
 * stream.  Alternatively, gzerror can be used before gzclose to detect this
 * case.
 *
 * @return Z_OK number of uncompressed bytes actually read, less than
 *     len for end of file, or -1 for error. If len is too large to fit
 *     in an int, then nothing is read, -1 is returned, and the error
 *     state is set to Z_STREAM_ERROR.
 */
int gzread(gzFile file, voidp buf, unsigned len);

/**
 * Read up to nitems items of size size from file to buf, otherwise operating
 * as gzread() does.  This duplicates the interface of stdio's fread(), with
 * size_t request and return types.  If the library defines size_t, then
 * size_t is identical to size_t.  If not, then size_t is an unsigned
 * integer type that can contain a pointer.
 *
 * gzfread() returns the number of full items read of size size, or zero if
 * the end of the file was reached and a full item could not be read, or if
 * there was an error.  gzerror() must be consulted if zero is returned in
 * order to determine if there was an error.  If the multiplication of size and
 * nitems overflows, i.e. the product does not fit in a size_t, then nothing
 * is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
 *
 * In the event that the end of file is reached and only a partial item is
 * available at the end, i.e. the remaining uncompressed data length is not a
 * multiple of size, then the final partial item is nevetheless read into buf
 * and the end-of-file flag is set.  The length of the partial item read is not
 * provided, but could be inferred from the result of gztell().  This behavior
 * is the same as the behavior of fread() implementations in common libraries,
 * but it prevents the direct use of gzfread() to read a concurrently written
 * file, reseting and retrying on end-of-file, when size is not 1.
 */
size_t gzfread(voidp buf, size_t size, size_t nitems, gzFile file);

/**
 * Writes given number of uncompressed bytes into the compressed file.
 * gzwrite returns the number of uncompressed bytes written or 0 in case
 * of error.
 */
int gzwrite(gzFile file, voidpc buf, unsigned len);

/**
 * Writes nitems items of size size from buf to file, duplicating the
 * interface of stdio's fwrite(), with size_t request and return types.
 * If the library defines size_t, then size_t is identical to size_t. If
 * not, then size_t is an unsigned integer type that can contain a
 * pointer.
 *
 * gzfwrite() returns the number of full items written of size size, or zero
 * if there was an error.  If the multiplication of size and nitems overflows,
 * i.e. the product does not fit in a size_t, then nothing is written, zero
 * is returned, and the error state is set to Z_STREAM_ERROR.
 */
size_t gzfwrite(voidpc buf, size_t size, size_t nitems, gzFile file);

/**
 * Converts, formats, and writes the arguments to the compressed file
 * under control of the format string, as in fprintf. gzprintf returns
 * the number of uncompressed bytes actually written, or a negative zlib
 * error code in case of error. The number of uncompressed bytes written
 * is limited to 8191, or one less than the buffer size given to
 * gzbuffer(). The caller should assure that this limit is not exceeded.
 * If it is exceeded, then gzprintf() will return an error (0) with
 * nothing written. In this case, there may also be a buffer overflow
 * with unpredictable consequences, which is possible only if zlib was
 * compiled with the insecure functions sprintf() or vsprintf() because
 * the secure snprintf() or vsnprintf() functions were not available.
 * This can be determined using zlibCompileFlags().
 */
int gzprintf(gzFile file, const char *format, ...);

/**
 * Writes the given null-terminated string to the compressed file, excluding
 * the terminating null character.
 *
 * @return Z_OK number of characters written, or -1 in case of error.
 */
int gzputs(gzFile file, const char *s);

/**
 * Reads bytes from the compressed file until len-1 characters are read,
 * or a newline character is read and transferred to buf, or an
 * end-of-file condition is encountered. If any characters are read or
 * if len == 1, the string is terminated with a null character. If no
 * characters are read due to an end-of-file or len < 1, then the buffer
 * is left untouched.
 *
 * @return buf which is a null-terminated string, or it returns NULL for
 *     end-of-file or in case of error. If there was an error, the
 *     contents at buf are indeterminate.
 */
char *gzgets(gzFile file, char *buf, int len);

/**
 * Writes character converted to an unsigned char into compressed file.
 * @return value that was written, or -1 on error
 */
int gzputc(gzFile file, int c);

/**
 * Reads one byte from the compressed file. gzgetc returns this byte or
 * -1 in case of end of file or error. This is implemented as a macro
 * for speed. As such, it does not do all of the checking the other
 * functions do. I.e. it does not check to see if file is NULL, nor
 * whether the structure file points to has been clobbered or not.
 */
int gzgetc(gzFile file);

/**
 * Pushes one character back onto the stream to be read as the first
 * character on the next read. At least one character of push-back is
 * allowed. gzungetc() returns the character pushed, or -1 on failure.
 * gzungetc() will fail if c is -1, and may fail if a character has been
 * pushed but not read yet. If gzungetc is used immediately after gzopen
 * or gzdopen, at least the output buffer size of pushed characters is
 * allowed. (See gzbuffer above.) The pushed character will be discarded
 * if the stream is repositioned with gzseek() or gzrewind().
 */
int gzungetc(int c, gzFile file);

/**
 * Flushes all pending output into the compressed file. The parameter
 * flush is as in the deflate() function. The return value is the zlib
 * error number (see function gzerror below). gzflush is only permitted
 * when writing.
 *
 * If the flush parameter is Z_FINISH, the remaining data is written and
 * the gzip stream is completed in the output. If gzwrite() is called
 * again, a new gzip stream will be started in the output. gzread() is
 * able to read such concatenated gzip streams.
 *
 * gzflush should be called only when strictly necessary because it will
 * degrade compression if called too often.
 */
int gzflush(gzFile file, int flush);

/**
 * Sets starting position for the next gzread or gzwrite on the given
 * compressed file. The offset represents a number of bytes in the
 * uncompressed data stream. The whence parameter is defined as in
 * lseek(2); the value SEEK_END is not supported.
 *
 * If the file is opened for reading, this function is emulated but can be
 * extremely slow.  If the file is opened for writing, only forward seeks are
 * supported; gzseek then compresses a sequence of zeroes up to the new
 * starting position.
 *
 * @return resulting offset location as measured in bytes from the
 *     beginning of the uncompressed stream, or -1 in case of error, in
 *     particular if the file is opened for writing and the new starting
 *     position would be before the current position.
 */
ssize_t gzseek(gzFile file, int64_t offset, int whence);

/**
 * Rewinds file.
 *
 * This function is supported only for reading.
 *
 * @note gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
 */
int gzrewind(gzFile file);

/**
 * Returns starting position for the next gzread or gzwrite on the given
 * compressed file. This position represents a number of bytes in the
 * uncompressed data stream, and is zero when starting, even if
 * appending or reading a gzip stream from the middle of a file using
 * gzdopen().
 *
 * @note gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 */
ssize_t gztell(gzFile file);

/**
 * Returns current offset in the file being read or written. This offset
 * includes the count of bytes that precede the gzip stream, for example
 * when appending or when using gzdopen() for reading. When reading, the
 * offset does not include as yet unused buffered input. This
 * information can be used for a progress indicator. On error,
 * gzoffset() returns -1.
 */
ssize_t gzoffset(gzFile file);

/**
 * Returns true (1) if the end-of-file indicator has been set while
 * reading, false (0) otherwise. Note that the end-of-file indicator is
 * set only if the read tried to go past the end of the input, but came
 * up short. Therefore, just like feof(), gzeof() may return false even
 * if there is no more data to read, in the event that the last read
 * request was for the exact number of bytes remaining in the input
 * file. This will happen if the input file size is an exact multiple of
 * the buffer size.
 *
 * If gzeof() returns true, then the read functions will return no more
 * data, unless the end-of-file indicator is reset by gzclearerr() and
 * the input file has grown since the previous end of file was detected.
 */
int gzeof(gzFile file);

/**
 * Returns true (1) if file is being copied directly while reading, or
 * false (0) if file is a gzip stream being decompressed.
 *
 * If the input file is empty, gzdirect() will return true, since the
 * input does not contain a gzip stream.
 *
 * If gzdirect() is used immediately after gzopen() or gzdopen() it will
 * cause buffers to be allocated to allow reading the file to determine
 * if it is a gzip file. Therefore if gzbuffer() is used, it should be
 * called before gzdirect().
 *
 * When writing, gzdirect() returns true (1) if transparent writing was
 * requested ("wT" for the gzopen() mode), or false (0) otherwise.
 * (Note: gzdirect() is not needed when writing. Transparent writing
 * must be explicitly requested, so the application already knows the
 * answer. When linking statically, using gzdirect() will include all of
 * the zlib code for gzip file reading and decompression, which may not
 * be desired.)
 */
int gzdirect(gzFile file);

/**
 * Flushes all pending output if necessary, closes the compressed file
 * and deallocates the (de)compression state. Note that once file is
 * closed, you cannot call gzerror with file, since its structures have
 * been deallocated. gzclose must not be called more than once on the
 * same file, just as free must not be called more than once on the same
 * allocation.
 *
 * @return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a file
 *     operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
 *     last read ended in the middle of a gzip stream, or Z_OK on
 *     success.
 */
int gzclose(gzFile file);

/**
 * Same as gzclose(), but gzclose_r() is only for use when reading, and
 * gzclose_w() is only for use when writing or appending. The advantage
 * to using these instead of gzclose() is that they avoid linking in
 * zlib compression or decompression code that is not used when only
 * reading or only writing respectively. If gzclose() is used, then both
 * compression and decompression code will be included the application
 * when linking to a static zlib library.
 */
int gzclose_r(gzFile file);
int gzclose_w(gzFile file);

/**
 * Returns the error message for the last error which occurred on the given
 * compressed file.  errnum is set to zlib error number.  If an error occurred
 * in the file system and not in the compression library, errnum is set to
 * Z_ERRNO and the application may consult errno to get the exact error code.
 *
 * The application must not modify the returned string.  Future calls to
 * this function may invalidate the previously returned string.  If file is
 * closed, then the string previously returned by gzerror will no longer be
 * available.
 *
 * gzerror() should be used to distinguish errors from end-of-file for those
 * functions above that do not distinguish those cases in their return values.
 */
const char *gzerror(gzFile file, int *errnum);

/**
 * Clears the error and end-of-file flags for file.  This is analogous to the
 * clearerr() function in stdio.  This is useful for continuing to read a gzip
 * file that is being written concurrently.
 */
void gzclearerr(gzFile file);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » checksums                                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/**
 * Updates running Adler-32 checksum with the bytes buf[0..len-1] and
 * return the updated checksum. If buf is Z_NULL, this function returns
 * the required initial value for the checksum.
 */
uLong adler32(uLong adler, const Bytef *buf, uInt len);

/**
 * Same as adler32(), but with a size_t length.
 */
uLong adler32_z(uLong adler, const Bytef *buf, size_t len);

/**
 * Combine two Adler-32 checksums into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were
 * calculated for each, adler1 and adler2. adler32_combine() returns the
 * Adler-32 checksum of seq1 and seq2 concatenated, requiring only
 * adler1, adler2, and len2. Note that the off_t type (like off_t) is a
 * signed integer. If len2 is negative, the result has no meaning or
 * utility.
 */
uLong adler32_combine(uLong adler1, uLong adler2, int64_t len2);

/**
 * Update a running CRC-32 with the bytes buf[0..len-1] and return the
 * updated CRC-32.  If buf is Z_NULL, this function returns the required
 * initial value for the crc.  Pre- and post-conditioning (one's complement) is
 * performed within this function so it shouldn't be done by the application.
 *
 * Usage example:
 *
 *     uLong crc = crc32(0L, Z_NULL, 0);
 *     while (read_buffer(buffer, length) != EOF) {
 *       crc = crc32(crc, buffer, length);
 *     }
 *     if (crc != original_crc) error();
 */
uLong crc32(uLong crc, const Bytef *buf, uInt len);

/**
 * Same as crc32(), but with a size_t length.
 */
uint32_t crc32_z(uint32_t crc, const void *buf, size_t len);

/**
 * Combine two CRC-32 check values into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
 * calculated for each, crc1 and crc2. crc32_combine() returns the
 * CRC-32 check value of seq1 and seq2 concatenated, requiring only
 * crc1, crc2, and len2.
 */
uLong crc32_combine(uLong crc1, uLong crc2, int64_t len2);

/**
 * gzgetc() macro and its supporting function and exposed data
 * structure. Note that the real internal state is much larger than the
 * exposed structure. This abbreviated structure exposes just enough for
 * the gzgetc() macro. The user should not mess with these exposed
 * elements, since their names or behavior could change in the future,
 * perhaps even capriciously. They can only be used by the gzgetc()
 * macro. You have been warned.
 */
struct gzFile_s {
  unsigned have;
  unsigned char *next;
  int64_t pos;
};

int gzgetc_(gzFile file); /* backward compatibility */
#ifdef Z_PREFIX_SET
#undef z_gzgetc
#define z_gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#elif defined(Z_COSMO_PREFIX_SET)
#undef gzgetc
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (__gzgetc)(g))
#else
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#endif

/* undocumented functions */
const char *zError(int);
int inflateSyncPoint(z_streamp);
int inflateUndermine(z_streamp, int);
int inflateValidate(z_streamp, int);
unsigned long inflateCodesUsed(z_streamp);
int inflateResetKeep(z_streamp);
int deflateResetKeep(z_streamp);
int gzvprintf(gzFile file, const char *format, va_list va);
void inflate_fast_chunk(z_streamp strm, unsigned start);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/regex/regex.h */

#define COSMOPOLITAN_LIBC_REGEX_REGEX_H_
COSMOPOLITAN_C_START_

#if 0
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § regular expressions                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
#endif

#define REG_EXTENDED 1
#define REG_ICASE    2
#define REG_NEWLINE  4
#define REG_NOSUB    8

#define REG_NOTBOL 1 /* ^ should not match beginning of string */
#define REG_NOTEOL 2 /* $ should not match end of string */

#define REG_OK       0
#define REG_NOMATCH  1
#define REG_BADPAT   2
#define REG_ECOLLATE 3
#define REG_ECTYPE   4
#define REG_EESCAPE  5
#define REG_ESUBREG  6
#define REG_EBRACK   7
#define REG_EPAREN   8
#define REG_EBRACE   9
#define REG_BADBR    10
#define REG_ERANGE   11
#define REG_ESPACE   12
#define REG_BADRPT   13

#define REG_ENOSYS -1

typedef long regoff_t;

struct PosixRegex {
  size_t re_nsub;
  void *__opaque, *__padding[4];
  size_t __nsub2;
  char __padding2;
};

struct PosixRegexMatch {
  regoff_t rm_so;
  regoff_t rm_eo;
};

typedef struct PosixRegex regex_t;
typedef struct PosixRegexMatch regmatch_t;

int regcomp(regex_t *, const char *, int);
int regexec(const regex_t *, const char *, size_t, regmatch_t *, int);
size_t regerror(int, const regex_t *, char *, size_t);
void regfree(regex_t *);

COSMOPOLITAN_C_END_

#endif /* COSMOPOLITAN_H_ */
#ifndef COSMOPOLITAN_H_
#define COSMOPOLITAN_H_


/*!BEGIN libc/integral/normalize.inc */

#ifdef __COSMOPOLITAN__
#undef __COSMOPOLITAN__
#endif

#define __COSMOPOLITAN_MAJOR__ 3
#define __COSMOPOLITAN_MINOR__ 3
#define __COSMOPOLITAN_PATCH__ 9
#define __COSMOPOLITAN__                                                   \
  (100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
   __COSMOPOLITAN_PATCH__)

#ifndef __COUNTER__
#define __COUNTER__ __LINE__
#endif

#if __GNUC__ + 0 < 2
#undef __GNUC__
#elif defined(__GNUC__) && defined(SWIG) /* lool */
#undef __GNUC__
#elif defined(__GNUC__) && defined(__NVCC__) /* lool */
#undef __GNUC__
#elif !defined(__GNUC__) && defined(__APPLE__) /* modesty */
#define __GNUC__            4
#define __GNUC_MINOR__      2
#define __GNUC_PATCHLEVEL__ 1
#elif !defined(__GNUC__) && defined(__TINYC__)
#define __GNUC__            2
#define __GNUC_MINOR__      0
#define __GNUC_PATCHLEVEL__ 0
#endif

#if !defined(__x86_64__) && \
    (defined(__amd64__) || (defined(_M_AMD64) && defined(_M_X64)))
#define __x86_64__ 1
#elif !defined(__i386__) && ((defined(__i486__) || defined(__i586__) ||  \
                              defined(__i686__) || defined(__i786__)) || \
                             _M_IX86 + 0 >= 400)
#define __i386__ 1
#elif !defined(__ia16__) && (defined(__MSDOS__) || defined(__BCC__))
#define __ia16__ 1
#endif
#if __ia16__ + __i386__ + __x86_64__ + 0
#define __x86__ 1
#endif

#ifdef _MSC_VER
#define __STRICT_ANSI__
#ifndef __STDC__
#define __STDC__
#endif
#endif

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif
#ifndef __has_extension
#define __has_extension(x) 0
#endif

#ifdef unix
#undef unix
#endif

#ifdef linux
#undef linux
#endif

#ifdef __linux
#undef __linux
#endif

#ifdef __linux__
#undef __linux__
#endif

#ifndef __BIGGEST_ALIGNMENT__
#define __BIGGEST_ALIGNMENT__ 16
#endif

#ifdef _COSMO_SOURCE
#define FRAMESIZE 65536
#define _PAGESIZE 4096
#endif

#if defined(__LP64__) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/lp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xfffffffffffffffful
#define __SIZE_MAX__    0xfffffffffffffffful
#define __INTPTR_MAX__  0x7fffffffffffffffl
#define __UINTPTR_MAX__ 0xfffffffffffffffful
#define __WINT_MAX__    0xffffffffu
#define __UINTMAX_MAX__ 0xffffffffffffffffUL
#define __INTMAX_MAX__  0x7fffffffffffffffL

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        8
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      8
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __INT16_TYPE__   short int
#define __INT32_TYPE__   int
#define __INT64_TYPE__   long int
#define __INT8_TYPE__    signed char
#define __INTMAX_TYPE__  long int
#define __INTPTR_TYPE__  long int
#define __PTRDIFF_TYPE__ long int
#define __SIZE_TYPE__    long unsigned int
#define __UINT16_TYPE__  short unsigned int
#define __UINT32_TYPE__  unsigned int
#define __UINT64_TYPE__  long unsigned int
#define __UINT8_TYPE__   unsigned char
#define __UINTMAX_TYPE__ long unsigned int
#define __UINTPTR_TYPE__ long unsigned int
#define __WCHAR_TYPE__   int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#elif defined(_MSC_VER) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/llp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xffffffffffffffffull
#define __SIZE_MAX__    0xffffffffffffffffull
#define __INTPTR_MAX__  0x7fffffffffffffffll
#define __UINTPTR_MAX__ 0xffffffffffffffffull
#define __WINT_MAX__    0xffffffffu

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        4
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      4
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#define __INT8_C(c)   c
#define __UINT8_C(c)  c
#define __INT16_C(c)  c
#define __UINT16_C(c) c
#define __INT32_C(c)  c
#define __UINT32_C(c) c##U
#define __INT64_C(c)  c##LL
#define __UINT64_C(c) c##ULL

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __INT8_TYPE__    signed char
#define __UINT8_TYPE__   unsigned char
#define __INT16_TYPE__   short int
#define __UINT16_TYPE__  short unsigned int
#define __INT32_TYPE__   int
#define __UINT32_TYPE__  unsigned int
#define __INT64_TYPE__   long long int
#define __UINT64_TYPE__  long long unsigned int
#define __INTPTR_TYPE__  long long int
#define __UINTPTR_TYPE__ long long unsigned int
#define __PTRDIFF_TYPE__ long long int
#define __SIZE_TYPE__    unsigned int
#define __WCHAR_TYPE__   int
#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef __STDC__


/*!BEGIN libc/integral/c.inc */

#if __GNUC__ + 0 < 2
#define __attribute__(x)
#endif

#ifndef __cplusplus
#define COSMOPOLITAN_C_START_
#define COSMOPOLITAN_C_END_
#define COSMOPOLITAN_CXX_START_
#define COSMOPOLITAN_CXX_END_
#define COSMOPOLITAN_CXX_USING_
#endif

#ifndef __ia16__
#define __far
#endif

#if !defined(__GNUC__) && __cplusplus + 0 >= 201103L
#define typeof(x) decltype(x)
#elif !defined(__GNUC__) && __STDC_VERSION__ + 0 < 201112
#define typeof(x) __typeof(x)
#endif

#ifdef __cplusplus
#if __cplusplus >= 201103L
#define _Alignof(x) alignof(x)
#endif /* C++11 */
#else  /* __cplusplus */
#if __STDC_VERSION__ + 0 < 201112
#if __GNUC__ + _MSC_VER + 0
#define _Alignof(x) __alignof(x)
#else
#define _Alignof(x) /* basically all it ever did lool */ sizeof(x)
#endif /* GNU/MSVC/!ANSI */
#endif /* C11 */
#endif /* __cplusplus */

#if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901
#if defined(__GNUC__) || defined(_MSC_VER)
#define inline __inline
#else
#define inline
#define __inline
#endif
#endif

#ifdef __chibicc__
#define __extension__
#endif

#if __STDC_VERSION__ + 0 < 201112
#ifdef __GNUC__
#define _Alignas(x) __attribute__((__aligned__(x)))
#elif defined(_MSC_VER)
#define _Alignas(x) __declspec(align(x))
#endif
#endif

#ifdef _MSC_VER
#define __builtin_unreachable() __assume(false)
#elif !((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
        defined(__clang__) || defined(__INTEL_COMPILER) ||    \
        __has_builtin(__builtin_unreachable))
#define __builtin_unreachable() \
  for (;;) {                    \
  }
#endif

#if (!defined(__llvm__) && !__has_builtin(__builtin_assume))
#define __builtin_assume(x)    \
  do {                         \
    if (!(x))                  \
      __builtin_unreachable(); \
  } while (0)
#endif

#if __STDC_VERSION__ + 0 < 201112
#define _Atomic(TYPE) TYPE volatile
#endif

#ifdef __llvm__
#define __gnu_printf__ __printf__
#define __gnu_scanf__  __scanf__
#endif

#if __cplusplus + 0 >= 201103L
#define NULL nullptr
#elif !defined(__cplusplus)
#define NULL ((void *)0)
#else
#define NULL 0
#endif

#ifndef __cplusplus
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wc++-compat"
#endif
typedef __WCHAR_TYPE__ wchar_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC pop_options
#endif
#endif /* __cplusplus */

#ifndef __COSMOCC__


/*!BEGIN libc/stdbool.h */

#define COSMOPOLITAN_LIBC_STDBOOL_H_

#ifndef __cplusplus

#define bool _Bool
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
#define true  ((_Bool) + 1u)
#define false ((_Bool) + 0u)
#else
#define true  1
#define false 0
#endif

#else /* __cplusplus */

#define _Bool bool

#endif /* __cplusplus */

#define __bool_true_false_are_defined 1

#endif

#define _LIBCPP_STDINT_H

typedef int errno_t;
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __WINT_TYPE__ wint_t; /* uint32_t on linux but int32_t on xnu */
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ bool32;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;

#define __DEFINED_max_align_t
typedef long double max_align_t;

#ifdef _COSMO_SOURCE
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || defined(__llvm__)
typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t;
#endif
#endif /* _COSMO_SOURCE */

#ifndef __AXDX_T
#define __AXDX_T
typedef struct {
  intptr_t ax, dx;
} axdx_t;
#endif

#ifndef __chibicc__
#define va_list            __builtin_va_list
#define va_arg(ap, type)   __builtin_va_arg(ap, type)
#define va_copy(dest, src) __builtin_va_copy(dest, src)
#define va_end(ap)         __builtin_va_end(ap)
#define va_start(ap, last) __builtin_va_start(ap, last)
#else


/*!BEGIN libc/integral/lp64arg.inc */

/* variadic arguments for chibicc */

/* <sync libc/runtime/valist.c> */
struct __va_list {
  uint32_t gp_offset;
  uint32_t fp_offset;
  void *overflow_arg_area;
  void *reg_save_area;
};
/* </sync libc/runtime/valist.c> */

void *__va_arg(struct __va_list *, size_t, unsigned, unsigned);

#define __GNUC_VA_LIST 1
#define __gnuc_va_list va_list

#define va_end(AP)
#define va_copy(DST, SRC) ((DST)[0] = (SRC)[0])
#define va_start(AP, LAST)                    \
  do {                                        \
    *(AP) = *(struct __va_list *)__va_area__; \
  } while (0)

#define va_arg(AP, TYPE)                               \
  (*(TYPE *)__va_arg(AP, sizeof(TYPE), _Alignof(TYPE), \
                     __builtin_reg_class(TYPE)))

typedef struct __va_list va_list[1];
#endif

#define libcesque   dontthrow dontcallback
#define memcpyesque libcesque
#define strlenesque libcesque nosideeffect paramsnonnull()
#define vallocesque \
  libcesque __wur returnsaligned((65536)) returnspointerwithnoaliases
#define reallocesque libcesque returnsaligned((16))
#define mallocesque  reallocesque returnspointerwithnoaliases
#define interruptfn  nocallersavedregisters forcealignargpointer

#ifndef pureconst
#define pureconst __attribute__((__const__))
#endif

#ifndef forcealign
#define forcealign(bytes) __attribute__((__aligned__(bytes)))
#endif
#define thatispacked __attribute__((__packed__))

#define printfesque(n)   __attribute__((__format__(__gnu_printf__, n, n + 1)))
#define scanfesque(n)    __attribute__((__format__(__gnu_scanf__, n, n + 1)))
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))

#ifndef privileged
#define privileged \
  _Section(".privileged") dontinline dontinstrument dontubsan dontasan
#endif

#ifndef wontreturn
#if (__has_attribute(__noreturn__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208)
#define wontreturn __attribute__((__noreturn__))
#else
#define wontreturn
#endif
#endif

#ifndef nosideeffect
#if (__has_attribute(__pure__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296)
#define nosideeffect __attribute__((__pure__))
#else
#define nosideeffect
#endif
#endif

#ifndef dontinline
#ifdef _MSC_VER
#define dontinline __declspec(noinline)
#elif (__has_attribute(__noinline__) || \
       (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
#define dontinline __attribute__((__noinline__))
#else
#define dontinline
#endif
#endif

#ifndef dontclone
#if (__has_attribute(__noclone__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405)
#define dontclone __attribute__((__noclone__))
#else
#define dontclone
#endif
#endif

#ifndef forceinline
#ifdef __cplusplus
#define forceinline inline
#else
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
    !defined(__cplusplus) ||                              \
    (defined(__clang__) &&                                \
     (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define forceinline                                                 \
  static __inline __attribute__((__always_inline__, __gnu_inline__, \
                                 __no_instrument_function__, __unused__))
#else
#define forceinline                                 \
  static __inline __attribute__((__always_inline__, \
                                 __no_instrument_function__, __unused__))
#endif /* __GNUC_STDC_INLINE__ */
#endif /* GCC >= 4.3 */
#elif defined(_MSC_VER)
#define forceinline __forceinline
#else
#define forceinline static inline
#endif /* !ANSI && GCC >= 3.2 */
#endif /* __cplusplus */
#endif /* forceinline */

#ifndef __wur
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
     __has_attribute(__warn_unused_result__))
#define __wur __attribute__((__warn_unused_result__))
#else
#define __wur
#endif
#endif

#ifndef nullterminated
#if __has_attribute(__sentinel__) || __GNUC__ + 0 >= 4
#define nullterminated(x) __attribute__((__sentinel__ x))
#else
#define nullterminated(x)
#endif
#endif

#ifndef flattenout
#if __has_attribute(__flatten__) || \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401 && !defined(__llvm__))
#define flattenout __attribute__((__flatten__))
#else
#define flattenout
#endif
#endif

#ifndef externinline
#if (!defined(__cplusplus) ||                              \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
     (defined(__clang__) &&                                \
      (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__))))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define externinline extern __inline __attribute__((__gnu_inline__))
#else
#define externinline extern __inline __attribute__((__always_inline__))
#endif
#else
#define externinline inline
#endif
#endif

#ifndef relegated
#if (__has_attribute(__cold__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define relegated __attribute__((__cold__))
#else
#define relegated
#endif
#endif

#if (__has_attribute(__warning__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define warnifused(s) __attribute__((__warning__(s)))
#else
#define warnifused(s)
#endif

#ifndef firstclass
#if (__has_attribute(__hot__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define firstclass __attribute__((__hot__))
#else
#define firstclass
#endif
#endif

#ifndef paramsnonnull
#if (__has_attribute(__nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs))
#else
#define paramsnonnull(opt_1idxs)
#endif
#endif

#if __STDC_VERSION__ + 0 >= 199901L
#define hasatleast static
#else
#define hasatleast
#endif

#if __STDC_VERSION__ + 0 < 199901L && !defined(restrict)
#if !defined(__cplusplus) && \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER))
#define restrict __restrict__
#else
#define restrict
#define __restrict
#endif
#endif

#ifndef dontcallback
#if (__has_attribute(__leaf__) || \
     (!defined(__llvm__) &&       \
      (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406))
#define dontcallback __attribute__((__leaf__))
#else
#define dontcallback
#endif
#endif

#ifndef dontthrow
#if defined(__cplusplus) &&        \
    (__has_attribute(dontthrow) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define dontthrow __attribute__((__nothrow__))
#elif defined(_MSC_VER)
#define dontthrow __declspec(nothrow)
#else
#define dontthrow
#endif
#endif

#ifndef returnstwice
#if (__has_attribute(__returns_twice__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402)
#define returnstwice __attribute__((__returns_twice__))
#else
#define returnstwice
#endif
#endif

#ifndef nodebuginfo
#if __has_attribute(__nodebug__) || defined(__llvm__)
#define nodebuginfo __attribute__((__nodebug__))
#else
#define nodebuginfo
#endif
#endif

#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
    __has_attribute(__force_align_arg_pointer__)
#define forcealignargpointer __attribute__((__force_align_arg_pointer__))
#else
#define forcealignargpointer "need modern compiler"
#endif

#ifndef returnsnonnull
#if (__has_attribute(__returns_nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsnonnull __attribute__((__returns_nonnull__))
#else
#define returnsnonnull
#endif
#endif

#if (__has_attribute(__assume_aligned__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsaligned(x) __attribute__((__assume_aligned__ x))
#else
#define returnsaligned(x)
#endif

#ifndef returnspointerwithnoaliases
#if (__has_attribute(__malloc__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnspointerwithnoaliases __attribute__((__malloc__))
#elif defined(_MSC_VER)
#define returnspointerwithnoaliases __declspec(allocator)
#else
#define returnspointerwithnoaliases
#endif
#endif

#ifndef attributeallocsize
#if (__has_attribute(__alloc_size__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocsize(x) __attribute__((__alloc_size__ x))
#else
#define attributeallocsize(x)
#endif
#endif

#ifndef attributeallocalign
#if (__has_attribute(__alloc_align__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocalign(x) __attribute__((__alloc_align__ x))
#else
#define attributeallocalign(x)
#endif
#endif

#if __cplusplus + 0 >= 201103L
#define autotype(x) auto
#elif ((__has_builtin(__auto_type) || defined(__llvm__) ||     \
        (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) && \
       !defined(__chibicc__))
#define autotype(x) __auto_type
#else
#define autotype(x) typeof(x)
#endif

#define offsetof(type, member) __builtin_offsetof(type, member)

#ifdef _COSMO_SOURCE

#ifndef dontinstrument
#if (__has_attribute(__no_instrument_function__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
#if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \
    __has_attribute(__patchable_function_entry__)
#define dontinstrument                       \
  __attribute__((__no_instrument_function__, \
                 __patchable_function_entry__(0, 0)))
#else
#define dontinstrument __attribute__((__no_instrument_function__))
#endif
#else
#define dontinstrument
#endif
#endif

#ifndef mayalias
#if (__has_attribute(__may_alias__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define mayalias __attribute__((__may_alias__))
#else
#define mayalias
#endif
#endif

#ifndef dontoptimize
#if defined(__llvm__) || __has_attribute(__optnone__)
#define dontoptimize __attribute__((__optnone__))
#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define dontoptimize __attribute__((__optimize__(0)))
#endif
#endif

#ifndef optimizesize
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define optimizesize __attribute__((__optimize__("s")))
#elif defined(__llvm__) || __has_attribute(__optnone__)
#define optimizesize __attribute__((__optnone__))
#endif
#endif

#ifndef optimizespeed
/* warning: corrupts frame pointer; only use on leaf functions */
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define optimizespeed __attribute__((__optimize__(3)))
#else
#define optimizespeed
#endif
#endif

#ifndef unrollloops
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define unrollloops __attribute__((__optimize__("unroll-loops")))
#else
#define unrollloops
#endif
#endif

#ifndef _Microarchitecture
#if (__has_attribute(__target__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
#define _Microarchitecture(march) __attribute__((__target__(march)))
#else
#define _Microarchitecture(march)
#endif
#endif

#ifdef __x86_64__
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
#else
#define nocallersavedregisters "need modern compiler"
#endif
#else
#define nocallersavedregisters
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_address__))
#define dontasan __attribute__((__no_sanitize_address__))
#else
#define dontasan
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_undefined__))
#define dontubsan __attribute__((__no_sanitize_undefined__))
#else
#define dontubsan
#endif

#ifdef __x86_64__
#define notpossible          \
  do {                       \
    __asm__("nop\n\t"        \
            "ud2\n\t"        \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#elif defined(__aarch64__)
#define notpossible          \
  do {                       \
    __asm__("udf\t#0\n\t"    \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#else
#define notpossible __builtin_trap()
#endif

#define donothing \
  do {            \
  } while (0)

#define textstartup _Section(".text.startup")
#define textexit    _Section(".text.exit")
#define textreal    _Section(".text.real")
#define texthead    _Section(".text.head")
#define textwindows _Section(".text.windows")
#define antiquity   _Section(".text.antiquity")

#ifdef __llvm__
#define __builtin_ia32_movntdq(x, y) (*(x) = (y))
#endif

#ifndef _Section
#define _Section(s) __attribute__((__section__(s)))
#endif

#ifndef __llvm__
#pragma GCC diagnostic ignored "-Wformat=0" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
#pragma GCC diagnostic warning "-Wunknown-pragmas"
#else
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wconstant-logical-operand" /* what */
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wstring-plus-int"       /* features 4 losers */
#pragma GCC diagnostic ignored "-Wkeyword-compat"        /* c++ upgrade */
#pragma GCC diagnostic ignored "-Wuser-defined-literals" /* reserved for me */
#endif

#pragma GCC diagnostic ignored "-Wformat-extra-args"     /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wunused-function"       /* contradicts dce */
#pragma GCC diagnostic ignored "-Wunused-const-variable" /* sooo ridiculous */
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */
#endif

#ifdef __x86_64__
#define DebugBreak() __asm__("int3")
#elif defined(__aarch64__)
#define DebugBreak() __asm__("brk\t#0x666")
#else
#define DebugBreak() __builtin_trap()
#endif

#ifdef __aarch64__
/* raise sigill (not sigtrap) like x86 does */
#define __builtin_trap()     \
  do {                       \
    __asm__("udf\t#0x666");  \
    __builtin_unreachable(); \
  } while (0)
#endif

#endif /* _COSMO_SOURCE */

#define __veil(CONSTRAINT, EXPRESSION)                               \
  __extension__({                                                    \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                 \
    __asm__("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                     \
  })

#define __conceal(CONSTRAINT, EXPRESSION)                                     \
  __extension__({                                                             \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                          \
    __asm__ volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                              \
  })

#define __expropriate(EXPRESSION)                      \
  __extension__({                                      \
    __asm__ volatile("" ::"g"(EXPRESSION) : "memory"); \
    0;                                                 \
  })

#if !defined(__APPLE__) && defined(__x86_64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
#elif defined(__aarch64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
#else
#define __yoink(SYMBOL) (void)0
#endif

#if !defined(__APPLE__) && defined(__x86_64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#elif defined(__aarch64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
#else
#define __static_yoink(SYMBOLSTR)
#endif

#if !defined(IM_FEELING_NAUGHTY)
#define __static_yoink_source(PATH) __static_yoink(PATH)
#else
#define __static_yoink_source(PATH)
#endif

#define __weak_reference(sym, alias) __weak_reference_impl(sym, alias)
#define __weak_reference_impl(sym, alias)  \
  __asm__(".weak\t" #alias "\n\t"          \
          ".equ\t" #alias ", " #sym "\n\t" \
          ".type\t" #alias ",@notype")

#ifndef __chibicc__
#define __strong_reference(sym, alias) \
  extern __typeof(sym) alias __attribute__((__alias__(#sym)))
#else
#define __strong_reference(sym, alias) __weak_reference(sym, alias)
#endif

#if defined(__GNUC__) || defined(__llvm__)
#define __funline \
  extern __inline \
      __attribute__((__gnu_inline__, __always_inline__, __artificial__))
#else
#define __funline static inline
#endif

#if defined(__x86_64__) && (defined(__GNUC__) || defined(__llvm__)) && \
    !defined(__chibicc__) && defined(__OPTIMIZE__)
#define __target_clones(x) __attribute__((__target_clones__(x ",default")))
#else
#define __target_clones(x)
#endif

#if !defined(TINY) && !defined(__AVX__)
#define __vex __target_clones("avx")
#else
#define __vex
#endif

#define __notice(sym, str)                                                   \
  __attribute__((__section__(".notice"), __aligned__(1))) const char sym[] = \
      "\n\n" str

#define MACHINE_CODE_ANALYSIS_BEGIN_
#define MACHINE_CODE_ANALYSIS_END_
#else
#define const
#define volatile
#endif
#ifdef __cplusplus


/*!BEGIN libc/integral/cxx.inc */

#define COSMOPOLITAN_CXX_START_ namespace cosmo {
#define COSMOPOLITAN_CXX_END_   }
#define COSMOPOLITAN_CXX_USING_ using namespace cosmo;
#define COSMOPOLITAN_C_START_   extern "C" {
#define COSMOPOLITAN_C_END_     }

#if !defined(__builtin_types_compatible_p) && !__has_builtin(types_compatible_p)
#if 0 /* todo jart whyyyy */


/*!BEGIN libc/integral/cxxtypescompat.inc */

#define NAME __cxx_types_compatible
#define QUALIFIED(Q1, Q2)       \
  template <class _T, class _U> \
  struct NAME<_T Q1, _U Q2> : NAME<_T, _U> {}

template <class, class>
struct NAME {
  enum { _value = 0 };
};

template <class _T>
struct NAME<_T, _T> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[], _T[N]> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[N], _T[]> {
  enum { _value = 1 };
};

QUALIFIED(const volatile, );
QUALIFIED(const volatile, const);
QUALIFIED(const, const volatile);
QUALIFIED(volatile, const volatile);
QUALIFIED(const volatile, volatile);
QUALIFIED(const, volatile);
QUALIFIED(volatile, const);
QUALIFIED(, const);
QUALIFIED(const, );
QUALIFIED(, volatile);
QUALIFIED(volatile, );

#undef QUALIFIED
#undef NAME
#define __builtin_types_compatible_p(A, B) \
  (__cxx_types_compatible<A, B>::_value)
#else
#define __builtin_types_compatible_p(A, B) 0
#endif
#endif

#if !defined(__builtin_choose_expr) && !__has_builtin(choose_expr)
#if 1
template <bool _P, typename _T, typename _U>
struct __cxx_choose_expr {
  __cxx_choose_expr(_T _a, _U _b) : _value(_a) {
  }
  const _T _value;
};
template <typename _T, typename _U>
struct __cxx_choose_expr<false, _T, _U> {
  __cxx_choose_expr(_T _a, _U _b) : _value(_b) {
  }
  const _U _value;
};
#define __builtin_choose_expr(X, A, B) \
  (__cxx_choose_expr<X, typeof(A), typeof(B)>(A, B)._value)
#else
#define __builtin_choose_expr(X, A, B) ((X) ? (A) : (B))
#endif
#endif

#ifdef __aarch64__
/* todo jart whyyyy */
#define _Float16 __fp16
#endif
#endif
#endif


/*!BEGIN ape/ape.h */

#define COSMOPOLITAN_APE_APE_H_

#define APE_VERSION_MAJOR 1
#define APE_VERSION_MINOR 10
#define APE_VERSION_STR   APE_VERSION_STR_(APE_VERSION_MAJOR, APE_VERSION_MINOR)
#define APE_VERSION_NOTE  APE_VERSION_NOTE_(APE_VERSION_MAJOR, APE_VERSION_MINOR)

#define APE_VERSION_STR__(x, y) #x "." #y
#define APE_VERSION_STR_(x, y)  APE_VERSION_STR__(x, y)
#define APE_VERSION_NOTE_(x, y) (100000000 * (x) + 1000000 * (y))



/*!BEGIN ape/relocations.h */

#define COSMOPOLITAN_APE_RELOCATIONS_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ αcτµαlly pδrταblε εxεcµταblε § relocations                                   │
╚──────────────────────────────────────────────────────────────────────────────╝
  One of the things αcτµαlly pδrταblε εxεcµταblε does a good job
  abstracting, is how a program needs to exist at three addresses
  simultaneously during the early stages of the loading process.

  By default, the linker calculates all symbols using virtual addresses.
  In some cases it's necessary to use addend macros that change virtual
  addresses into the other two types: physical and real. */

#define IMAGE_BASE_REAL 0x2000

#ifndef IMAGE_BASE_VIRTUAL
#define IMAGE_BASE_VIRTUAL 0x400000
#endif

#ifndef IMAGE_BASE_PHYSICAL
#define IMAGE_BASE_PHYSICAL 0x100000
#endif

/**
 * Returns Relative Virtual Address.
 */
#define RVA(x) ((x) - (IMAGE_BASE_VIRTUAL))

/**
 * Adjusts virtual address so it's relative to load address.
 */
#define PHYSICAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_PHYSICAL))

/**
 * Makes high-entropy read-only addresses relocatable in real mode.
 */
#define REAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_REAL))

#if IMAGE_BASE_VIRTUAL % 0x1000 != 0
#error "IMAGE_BASE_VIRTUAL must be 4kb aligned"
#endif
#if IMAGE_BASE_PHYSICAL % 0x1000 != 0
#error "IMAGE_BASE_PHYSICAL must be 4kb aligned"
#endif
#if IMAGE_BASE_REAL % 0x1000 != 0
#error "IMAGE_BASE_REAL must be 4kb aligned"
#endif



/*!BEGIN libc/ar.h */

#define COSMOPOLITAN_LIBC_AR_H_
COSMOPOLITAN_C_START_

#define ARMAG  "!<arch>\n"
#define SARMAG 8
#define ARFMAG "`\n"

struct ar_hdr {
  char ar_name[16];
  char ar_date[12];
  char ar_uid[6];
  char ar_gid[6];
  char ar_mode[8];
  char ar_size[10];
  char ar_fmag[2];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/assert.h */

#undef _ASSERT_H
#undef assert
#ifdef _COSMO_SOURCE
#undef unassert
#undef npassert
#ifndef NDEBUG
#undef __assert_macro
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

#define _ASSERT_H
COSMOPOLITAN_C_START_

void __assert_fail(const char *, const char *, int) libcesque;
void unassert(const char *, const char *, int) libcesque;

#ifdef NDEBUG
#define assert(x) ((void)0)
#else
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0)))
#endif

#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
#undef static_assert
#define static_assert _Static_assert
#endif

#ifdef _COSMO_SOURCE
#ifndef NDEBUG
#define unassert(x) __assert_macro(x, #x)
#define npassert(x) __assert_macro(x, #x)
#define __assert_macro(x, s)             \
  ({                                     \
    if (__builtin_expect(!(x), 0)) {     \
      (unassert)(s, __FILE__, __LINE__); \
      __asm__("nop");                    \
      __builtin_unreachable();           \
    }                                    \
    (void)0;                             \
  })
#else
#define npassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_trap();              \
    }                                \
    (void)0;                         \
  })
#define unassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_unreachable();       \
    }                                \
    (void)0;                         \
  })
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/atomic.h */

#define COSMOPOLITAN_LIBC_ATOMIC_H_

#define atomic_bool           _Atomic(_Bool)
#define atomic_bool32         _Atomic(__INT32_TYPE__)
#define atomic_char           _Atomic(char)
#define atomic_schar          _Atomic(signed char)
#define atomic_uchar          _Atomic(unsigned char)
#define atomic_short          _Atomic(short)
#define atomic_ushort         _Atomic(unsigned short)
#define atomic_int            _Atomic(int)
#define atomic_uint           _Atomic(unsigned int)
#define atomic_long           _Atomic(long)
#define atomic_ulong          _Atomic(unsigned long)
#define atomic_llong          _Atomic(long long)
#define atomic_ullong         _Atomic(unsigned long long)
#define atomic_char16_t       _Atomic(__CHAR16_TYPE__)
#define atomic_char32_t       _Atomic(__CHAR32_TYPE__)
#define atomic_wchar_t        _Atomic(__WCHAR_TYPE__)
#define atomic_intptr_t       _Atomic(__INTPTR_TYPE__)
#define atomic_uintptr_t      _Atomic(__UINTPTR_TYPE__)
#define atomic_size_t         _Atomic(__SIZE_TYPE__)
#define atomic_ptrdiff_t      _Atomic(__PTRDIFF_TYPE__)
#define atomic_int_fast8_t    _Atomic(__INT_FAST8_TYPE__)
#define atomic_uint_fast8_t   _Atomic(__UINT_FAST8_TYPE__)
#define atomic_int_fast16_t   _Atomic(__INT_FAST16_TYPE__)
#define atomic_uint_fast16_t  _Atomic(__UINT_FAST16_TYPE__)
#define atomic_int_fast32_t   _Atomic(__INT_FAST32_TYPE__)
#define atomic_uint_fast32_t  _Atomic(__UINT_FAST32_TYPE__)
#define atomic_int_fast64_t   _Atomic(__INT_FAST64_TYPE__)
#define atomic_uint_fast64_t  _Atomic(__UINT_FAST64_TYPE__)
#define atomic_int_least8_t   _Atomic(__INT_LEAST8_TYPE__)
#define atomic_uint_least8_t  _Atomic(__UINT_LEAST8_TYPE__)
#define atomic_int_least16_t  _Atomic(__INT_LEAST16_TYPE__)
#define atomic_uint_least16_t _Atomic(__UINT_LEAST16_TYPE__)
#define atomic_int_least32_t  _Atomic(__INT_LEAST32_TYPE__)
#define atomic_uint_least32_t _Atomic(__UINT_LEAST32_TYPE__)
#define atomic_int_least64_t  _Atomic(__INT_LEAST64_TYPE__)
#define atomic_uint_least64_t _Atomic(__UINT_LEAST64_TYPE__)

#ifdef __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_BOOL_LOCK_FREE     __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __CLANG_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __CLANG_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __CLANG_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __CLANG_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __CLANG_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __CLANG_ATOMIC_POINTER_LOCK_FREE
#else
#define ATOMIC_BOOL_LOCK_FREE     __GCC_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __GCC_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __GCC_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __GCC_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __GCC_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __GCC_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __GCC_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __GCC_ATOMIC_POINTER_LOCK_FREE
#endif



/*!BEGIN libc/complex.h */

#define COSMOPOLITAN_LIBC_COMPLEX_H_
COSMOPOLITAN_C_START_
#if __STDC_VERSION__ + 0 >= 201112 && !defined(__STDC_NO_COMPLEX__)

#define complex   _Complex
#define imaginary _Imaginary

double cabs(complex double) libcesque;
double carg(complex double) libcesque;
double cimag(complex double) libcesque;
double creal(complex double) libcesque;

float cabsf(complex float) libcesque;
float cargf(complex float) libcesque;
float cimagf(complex float) libcesque;
float crealf(complex float) libcesque;

long double cabsl(complex long double) libcesque;
long double cargl(complex long double) libcesque;
long double cimagl(complex long double) libcesque;
long double creall(complex long double) libcesque;

complex double cacos(complex double) libcesque;
complex double cacosh(complex double) libcesque;
complex double casin(complex double) libcesque;
complex double casinh(complex double) libcesque;
complex double catan(complex double) libcesque;
complex double catanh(complex double) libcesque;
complex double ccos(complex double) libcesque;
complex double ccosh(complex double) libcesque;
complex double cexp(complex double) libcesque;
complex double cexp2(complex double) libcesque;
complex double clog(complex double) libcesque;
complex double conj(complex double) libcesque;
complex double cpow(complex double, complex double) libcesque;
complex double cproj(complex double) libcesque;
complex double csin(complex double) libcesque;
complex double csinh(complex double) libcesque;
complex double csqrt(complex double) libcesque;
complex double ctan(complex double) libcesque;
complex double ctanh(complex double) libcesque;

complex float cacosf(complex float) libcesque;
complex float cacoshf(complex float) libcesque;
complex float casinf(complex float) libcesque;
complex float casinhf(complex float) libcesque;
complex float catanf(complex float) libcesque;
complex float catanhf(complex float) libcesque;
complex float ccosf(complex float) libcesque;
complex float ccoshf(complex float) libcesque;
complex float cexpf(complex float) libcesque;
complex float cexp2f(complex float) libcesque;
complex float clogf(complex float) libcesque;
complex float conjf(complex float) libcesque;
complex float cpowf(complex float, complex float) libcesque;
complex float cprojf(complex float) libcesque;
complex float csinf(complex float) libcesque;
complex float csinhf(complex float) libcesque;
complex float csqrtf(complex float) libcesque;
complex float ctanf(complex float) libcesque;
complex float ctanhf(complex float) libcesque;

complex long double cprojl(complex long double) libcesque;
complex long double csinhl(complex long double) libcesque;
complex long double csinl(complex long double) libcesque;
complex long double csqrtl(complex long double) libcesque;
complex long double ctanhl(complex long double) libcesque;
complex long double ctanl(complex long double) libcesque;
complex long double cacoshl(complex long double) libcesque;
complex long double cacosl(complex long double) libcesque;
complex long double casinhl(complex long double) libcesque;
complex long double casinl(complex long double) libcesque;
complex long double catanhl(complex long double) libcesque;
complex long double catanl(complex long double) libcesque;
complex long double ccoshl(complex long double) libcesque;
complex long double ccosl(complex long double) libcesque;
complex long double cexpl(complex long double) libcesque;
complex long double cexp2l(complex long double) libcesque;
complex long double clogl(complex long double) libcesque;
complex long double conjl(complex long double) libcesque;
complex long double cpowl(complex long double, complex long double) libcesque;

#ifndef __cplusplus
#define __CIMAG(x, t)   \
  (+(union {            \
      _Complex t __z;   \
      t __xy[2];        \
    }){(_Complex t)(x)} \
        .__xy[1])
#define creal(x)  ((double)(x))
#define crealf(x) ((float)(x))
#define creall(x) ((long double)(x))
#define cimag(x)  __CIMAG(x, double)
#define cimagf(x) __CIMAG(x, float)
#define cimagl(x) __CIMAG(x, long double)
#endif

#ifdef __GNUC__
#define _Complex_I (__extension__(0.0f + 1.0fi))
#else
#define _Complex_I (0.0f + 1.0fi)
#endif

#ifdef _Imaginary_I
#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I * (t)(y))
#elif defined(__clang__)
#define __CMPLX(x, y, t) (+(_Complex t){(t)(x), (t)(y)})
#else
#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y)))
#endif

#define CMPLX(x, y)  __CMPLX(x, y, double)
#define CMPLXF(x, y) __CMPLX(x, y, float)
#define CMPLXL(x, y) __CMPLX(x, y, long double)

#endif /* C11 */
COSMOPOLITAN_C_END_


/*!BEGIN libc/cosmo.h */

#define COSMOPOLITAN_LIBC_COSMO_H_
COSMOPOLITAN_C_START_

errno_t cosmo_once(_Atomic(uint32_t) *, void (*)(void));
int systemvpe(const char *, char *const[], char *const[]) libcesque;
char *GetProgramExecutableName(void);
void unleaf(void);
int __demangle(char *, const char *, size_t);
int __is_mangled(const char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/cxxabi.h */

#define _CXXABI_H
COSMOPOLITAN_C_START_

#ifdef __cplusplus
namespace __cxxabiv1 {
#endif /* __cplusplus */

char *__cxa_demangle(const char *, char *, size_t *, int *);
int __cxa_atexit(void (*)(void *), void *, void *) paramsnonnull((1)) dontthrow;
int __cxa_thread_atexit(void (*)(void *), void *, void *) dontthrow;
void __cxa_finalize(void *);

#ifdef __cplusplus
} /* namespace __cxxabiv1 */
#endif /* __cplusplus */

COSMOPOLITAN_C_END_


/*!BEGIN libc/dce.h */

#ifndef COSMOPOLITAN_LIBC_DCE_H_
#define COSMOPOLITAN_LIBC_DCE_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § autotune » dead code elimination                              │
╚─────────────────────────────────────────────────────────────────────────────*/

#ifndef SUPPORT_VECTOR
#ifdef __x86_64__
/**
 * Supported Platforms Tuning Knob (Runtime & Compile-Time)
 * Tuning this bitmask will remove platform polyfills at compile-time.
 */
#define SUPPORT_VECTOR 255
#else
#define SUPPORT_VECTOR (_HOSTLINUX | _HOSTXNU | _HOSTFREEBSD)
#endif
#endif

#define _HOSTLINUX   1
#define _HOSTMETAL   2
#define _HOSTWINDOWS 4
#define _HOSTXNU     8
#define _HOSTOPENBSD 16
#define _HOSTFREEBSD 32
#define _HOSTNETBSD  64

#ifdef NDEBUG
#define NoDebug() 1
#else
#define NoDebug() 0
#endif

#ifdef MODE_DBG
#define IsModeDbg() 1
#else
#define IsModeDbg() 0
#endif

#ifdef TRUSTWORTHY
#define IsTrustworthy() 1
#else
#define IsTrustworthy() 0
#endif

#ifdef TINY
#define IsTiny() 1
#else
#define IsTiny() 0
#endif

#ifdef __OPTIMIZE__
#define IsOptimized() 1
#else
#define IsOptimized() 0
#endif

#ifdef __SANITIZE_ADDRESS__
#define IsAsan() 1
#else
#define IsAsan() 0
#endif

#ifdef __aarch64__
#define IsAarch64()    1
#define IsXnuSilicon() IsXnu()
#else
#define IsAarch64()    0
#define IsXnuSilicon() 0
#endif

#if defined(__x86_64__)
#define _ARCH_NAME "amd64"
#elif defined(__aarch64__)
#define _ARCH_NAME "arm64"
#elif defined(__powerpc64__)
#define _ARCH_NAME "ppc64"
#elif defined(__s390x__)
#define _ARCH_NAME "s390x"
#elif defined(__riscv)
#define _ARCH_NAME "riscv"
#endif

#define SupportsLinux()   ((SUPPORT_VECTOR & _HOSTLINUX) == _HOSTLINUX)
#define SupportsMetal()   ((SUPPORT_VECTOR & _HOSTMETAL) == _HOSTMETAL)
#define SupportsWindows() ((SUPPORT_VECTOR & _HOSTWINDOWS) == _HOSTWINDOWS)
#define SupportsXnu()     ((SUPPORT_VECTOR & _HOSTXNU) == _HOSTXNU)
#define SupportsFreebsd() ((SUPPORT_VECTOR & _HOSTFREEBSD) == _HOSTFREEBSD)
#define SupportsOpenbsd() ((SUPPORT_VECTOR & _HOSTOPENBSD) == _HOSTOPENBSD)
#define SupportsNetbsd()  ((SUPPORT_VECTOR & _HOSTNETBSD) == _HOSTNETBSD)
#define SupportsBsd() \
  (!!(SUPPORT_VECTOR & (_HOSTXNU | _HOSTFREEBSD | _HOSTOPENBSD | _HOSTNETBSD)))
#define SupportsSystemv() \
  (!!(SUPPORT_VECTOR &    \
      (_HOSTLINUX | _HOSTXNU | _HOSTOPENBSD | _HOSTFREEBSD | _HOSTNETBSD)))

#ifndef __ASSEMBLER__
#define IsLinux()   (SupportsLinux() && (__hostos & _HOSTLINUX))
#define IsMetal()   (SupportsMetal() && (__hostos & _HOSTMETAL))
#define IsWindows() (SupportsWindows() && (__hostos & _HOSTWINDOWS))
#define IsXnu()     (SupportsXnu() && (__hostos & _HOSTXNU))
#define IsFreebsd() (SupportsFreebsd() && (__hostos & _HOSTFREEBSD))
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & _HOSTOPENBSD))
#define IsNetbsd()  (SupportsNetbsd() && (__hostos & _HOSTNETBSD))
#define IsBsd()     (IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd())
#else
/* clang-format off */
#define IsLinux() $_HOSTLINUX,__hostos(%rip)
#define IsMetal() $_HOSTMETAL,__hostos(%rip)
#define IsWindows() $_HOSTWINDOWS,__hostos(%rip)
#define IsBsd() $_HOSTXNU|_HOSTFREEBSD|_HOSTOPENBSD|_HOSTNETBSD,__hostos(%rip)
#define IsXnu() $_HOSTXNU,__hostos(%rip)
#define IsFreebsd() $_HOSTFREEBSD,__hostos(%rip)
#define IsOpenbsd() $_HOSTOPENBSD,__hostos(%rip)
#define IsNetbsd() $_HOSTNETBSD,__hostos(%rip)
/* clang-format on */
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __hostos;

int IsQemuUser(void);

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_DCE_H_ */


/*!BEGIN libc/errno.h */

#define COSMOPOLITAN_LIBC_ERRNO_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview System Five error codes.
 *
 * This file defines the `errno` global variable. When system calls
 * (e.g. read(), write(), etc.) fail they return -1 to indicate the
 * failure, and that is *the only* error return value. System calls
 * also update `errno` too whenever -1 is returned (otherwise errno
 * isn't changed) to be a non-zero value holding one of the numbers
 * below, in order to indicate why the system call failed.
 *
 * There is only one exception to the above rule; some system calls
 * are documented with the `@returnserrno` tag, which means they'll
 * return the error number rather than stuffing it in a global. You
 * can usually spot these system calls easily since most of them'll
 * have names like `posix_foo()` or `pthread_bar()`.
 *
 * @see libc/sysv/consts.sh for assigned numbers
 * @see libc/sysv/dos2errno.sh for multimapped numbers
 */

#if defined(__GNUC__) && defined(__aarch64__) && !defined(__cplusplus)
/* this header is included by 700+ files; therefore we */
/* hand-roll &__get_tls()->tib_errno to avoid #include */
/* cosmopolitan uses x28 as the tls register b/c apple */
#define errno                                      \
  (*__extension__({                                \
    errno_t *__ep;                                 \
    __asm__("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
    __ep;                                          \
  }))
#else
#define errno (*__errno_location())
#endif

/**
 * System call unavailable.
 * @note kNtErrorInvalidFunction on NT
 */
extern const errno_t ENOSYS;

/**
 * Operation not permitted.
 * @note kNtErrorInvalidAccess on NT
 */
extern const errno_t EPERM;

/**
 * No such file or directory.
 */
extern const errno_t ENOENT;

/**
 * No such process.
 */
extern const errno_t ESRCH;

/**
 * The greatest of all errnos.
 */
extern const errno_t EINTR;

/**
 * Unix consensus.
 */
extern const errno_t EIO;

/**
 * No such device or address.
 */
extern const errno_t ENXIO;

/**
 * Argument list too long.
 */
extern const errno_t E2BIG;

/**
 * Exec format error.
 */
extern const errno_t ENOEXEC;

/**
 * Bad file descriptor.
 */
extern const errno_t EBADF;

/**
 * No child process.
 */
extern const errno_t ECHILD;

/**
 * Resource temporarily unavailable (e.g. SO_RCVTIMEO expired, too many
 * processes, too much memory locked, read or write with O_NONBLOCK needs
 * polling, etc.).
 */
extern const errno_t EAGAIN;

/**
 * We require more vespene gas.
 */
extern const errno_t ENOMEM;

/**
 * Permission denied.
 */
extern const errno_t EACCES;

/**
 * Pointer passed to system call that would otherwise segfault.
 */
extern const errno_t EFAULT;

/**
 * Block device required.
 */
extern const errno_t ENOTBLK;

/**
 * Device or resource busy.
 */
extern const errno_t EBUSY;

/**
 * File exists.
 */
extern const errno_t EEXIST;

/**
 * Improper link.
 */
extern const errno_t EXDEV;

/**
 * No such device.
 */
extern const errno_t ENODEV;

/**
 * Not a directory.
 */
extern const errno_t ENOTDIR;

/**
 * Is a a directory.
 */
extern const errno_t EISDIR;

/**
 * Invalid argument.
 */
extern const errno_t EINVAL;

/**
 * Too many open files in system.
 */
extern const errno_t ENFILE;

/**
 * Too many open files.
 */
extern const errno_t EMFILE;

/**
 * Inappropriate i/o control operation.
 */
extern const errno_t ENOTTY;

/**
 * Won't open executable that's executing in write mode.
 */
extern const errno_t ETXTBSY;

/**
 * File too large.
 */
extern const errno_t EFBIG;

/**
 * No space left on device.
 */
extern const errno_t ENOSPC;

/**
 * Disk quota exceeded.
 */
extern const errno_t EDQUOT;

/**
 * Invalid seek.
 */
extern const errno_t ESPIPE;

/**
 * Read-only filesystem.
 */
extern const errno_t EROFS;

/**
 * Too many links.
 */
extern const errno_t EMLINK;

/**
 * Broken pipe.
 */
extern const errno_t EPIPE;

/**
 * Mathematics argument out of domain of function.
 */
extern const errno_t EDOM;

/**
 * Result too large.
 */
extern const errno_t ERANGE;

/**
 * Resource deadlock avoided.
 */
extern const errno_t EDEADLK;

/**
 * Filename too long.
 */
extern const errno_t ENAMETOOLONG;

/**
 * No locks available.
 */
extern const errno_t ENOLCK;

/**
 * Directory not empty.
 */
extern const errno_t ENOTEMPTY;

/**
 * Too many levels of symbolic links.
 */
extern const errno_t ELOOP;

/**
 * No message error.
 */
extern const errno_t ENOMSG;

/**
 * Identifier removed.
 */
extern const errno_t EIDRM;

/**
 * Timer expired.
 */
extern const errno_t ETIME;

/**
 * Protocol error.
 */
extern const errno_t EPROTO;

/**
 * Overflow error.
 */
extern const errno_t EOVERFLOW;

/**
 * Unicode decoding error.
 */
extern const errno_t EILSEQ;

/**
 * Too many users.
 */
extern const errno_t EUSERS;

/**
 * Not a socket.
 */
extern const errno_t ENOTSOCK;

/**
 * Destination address required.
 */
extern const errno_t EDESTADDRREQ;

/**
 * Message too long.
 */
extern const errno_t EMSGSIZE;

/**
 * Protocol wrong type for socket.
 */
extern const errno_t EPROTOTYPE;

/**
 * Protocol not available.
 */
extern const errno_t ENOPROTOOPT;

/**
 * Protocol not supported.
 */
extern const errno_t EPROTONOSUPPORT;

/**
 * Socket type not supported.
 */
extern const errno_t ESOCKTNOSUPPORT;

/**
 * Operation not supported.
 */
extern const errno_t ENOTSUP;

/**
 * Socket operation not supported.
 */
extern const errno_t EOPNOTSUPP;

/**
 * Protocol family not supported.
 */
extern const errno_t EPFNOSUPPORT;

/**
 * Address family not supported.
 */
extern const errno_t EAFNOSUPPORT;

/**
 * Address already in use.
 */
extern const errno_t EADDRINUSE;

/**
 * Address not available.
 */
extern const errno_t EADDRNOTAVAIL;

/**
 * Network is down.
 */
extern const errno_t ENETDOWN;

/**
 * Host is unreachable.
 */
extern const errno_t ENETUNREACH;

/**
 * Connection reset by network.
 */
extern const errno_t ENETRESET;

/**
 * Connection reset before accept.
 */
extern const errno_t ECONNABORTED;

/**
 * Connection reset by client.
 */
extern const errno_t ECONNRESET;

/**
 * No buffer space available.
 */
extern const errno_t ENOBUFS;

/**
 * Socket is connected.
 */
extern const errno_t EISCONN;

/**
 * Socket is not connected.
 */
extern const errno_t ENOTCONN;

/**
 * Cannot send after transport endpoint shutdown.
 */
extern const errno_t ESHUTDOWN;

/**
 * Too many references: cannot splice.
 */
extern const errno_t ETOOMANYREFS;

/**
 * Connection timed out.
 */
extern const errno_t ETIMEDOUT;

/**
 * Connection refused error.
 */
extern const errno_t ECONNREFUSED;

/**
 * Host down error.
 */
extern const errno_t EHOSTDOWN;

/**
 * Host unreachable error.
 */
extern const errno_t EHOSTUNREACH;

/**
 * Connection already in progress.
 */
extern const errno_t EALREADY;

/**
 * Operation already in progress.
 */
extern const errno_t EINPROGRESS;

/**
 * Stale error.
 */
extern const errno_t ESTALE;

/**
 * Remote error.
 */
extern const errno_t EREMOTE;

/**
 * Bad message.
 */
extern const errno_t EBADMSG;

/**
 * Operation canceled.
 */
extern const errno_t ECANCELED;

/**
 * Owner died.
 */
extern const errno_t EOWNERDEAD;

/**
 * State not recoverable.
 */
extern const errno_t ENOTRECOVERABLE;

/**
 * No network.
 */
extern const errno_t ENONET;

/**
 * Please restart syscall.
 */
extern const errno_t ERESTART;

/**
 * Out of streams resources.
 */
extern const errno_t ENOSR;

/**
 * No string.
 */
extern const errno_t ENOSTR;

/**
 * No data.
 */
extern const errno_t ENODATA;

/**
 * Multihop attempted.
 */
extern const errno_t EMULTIHOP;

/**
 * Link severed.
 */
extern const errno_t ENOLINK;

/**
 * No medium found.
 */
extern const errno_t ENOMEDIUM;

/**
 * Wrong medium type.
 */
extern const errno_t EMEDIUMTYPE;

/**
 * Inappropriate file type or format.
 */
extern const errno_t EFTYPE;

extern const errno_t EAUTH;
extern const errno_t EBADARCH;
extern const errno_t EBADEXEC;
extern const errno_t EBADMACHO;
extern const errno_t EBADRPC;
extern const errno_t EDEVERR;
extern const errno_t ENEEDAUTH;
extern const errno_t ENOATTR;
extern const errno_t ENOPOLICY;
extern const errno_t EPROCLIM;
extern const errno_t EPROCUNAVAIL;
extern const errno_t EPROGMISMATCH;
extern const errno_t EPROGUNAVAIL;
extern const errno_t EPWROFF;
extern const errno_t ERPCMISMATCH;
extern const errno_t ESHLIBVERS;
extern const errno_t EADV;
extern const errno_t EBADE;
extern const errno_t EBADFD;
extern const errno_t EBADR;
extern const errno_t EBADRQC;
extern const errno_t EBADSLT;
extern const errno_t ECHRNG;
extern const errno_t ECOMM;
extern const errno_t EDOTDOT;
extern const errno_t EHWPOISON;
extern const errno_t EISNAM;
extern const errno_t EKEYEXPIRED;
extern const errno_t EKEYREJECTED;
extern const errno_t EKEYREVOKED;
extern const errno_t EL2HLT;
extern const errno_t EL2NSYNC;
extern const errno_t EL3HLT;
extern const errno_t EL3RST;
extern const errno_t ELIBACC;
extern const errno_t ELIBBAD;
extern const errno_t ELIBEXEC;
extern const errno_t ELIBMAX;
extern const errno_t ELIBSCN;
extern const errno_t ELNRNG;
extern const errno_t ENAVAIL;
extern const errno_t ENOANO;
extern const errno_t ENOCSI;
extern const errno_t ENOKEY;
extern const errno_t ENOPKG;
extern const errno_t ENOTNAM;
extern const errno_t ENOTUNIQ;
extern const errno_t EREMCHG;
extern const errno_t EREMOTEIO;
extern const errno_t ERFKILL;
extern const errno_t ESRMNT;
extern const errno_t ESTRPIPE;
extern const errno_t EUCLEAN;
extern const errno_t EUNATCH;
extern const errno_t EXFULL;

#define E2BIG           E2BIG
#define EACCES          EACCES
#define EADDRINUSE      EADDRINUSE
#define EADDRNOTAVAIL   EADDRNOTAVAIL
#define EAFNOSUPPORT    EAFNOSUPPORT
#define EAGAIN          EAGAIN
#define EALREADY        EALREADY
#define EBADF           EBADF
#define EBADMSG         EBADMSG
#define EBUSY           EBUSY
#define ECANCELED       ECANCELED
#define ECHILD          ECHILD
#define ECONNABORTED    ECONNABORTED
#define ECONNREFUSED    ECONNREFUSED
#define ECONNRESET      ECONNRESET
#define EDEADLK         EDEADLK
#define EDESTADDRREQ    EDESTADDRREQ
#define EDOM            EDOM
#define EDQUOT          EDQUOT
#define EEXIST          EEXIST
#define EFAULT          EFAULT
#define EFBIG           EFBIG
#define EFTYPE          EFTYPE
#define EHOSTDOWN       EHOSTDOWN
#define EHOSTUNREACH    EHOSTUNREACH
#define EIDRM           EIDRM
#define EILSEQ          EILSEQ
#define EINPROGRESS     EINPROGRESS
#define EINTR           EINTR
#define EINVAL          EINVAL
#define EIO             EIO
#define EISCONN         EISCONN
#define EISDIR          EISDIR
#define ELOOP           ELOOP
#define EMEDIUMTYPE     EMEDIUMTYPE
#define EMFILE          EMFILE
#define EMLINK          EMLINK
#define EMSGSIZE        EMSGSIZE
#define EMULTIHOP       EMULTIHOP
#define ENAMETOOLONG    ENAMETOOLONG
#define ENETDOWN        ENETDOWN
#define ENETRESET       ENETRESET
#define ENETUNREACH     ENETUNREACH
#define ENFILE          ENFILE
#define ENOBUFS         ENOBUFS
#define ENODATA         ENODATA
#define ENODEV          ENODEV
#define ENOENT          ENOENT
#define ENOEXEC         ENOEXEC
#define ENOLCK          ENOLCK
#define ENOLINK         ENOLINK
#define ENOMEDIUM       ENOMEDIUM
#define ENOMEM          ENOMEM
#define ENOMSG          ENOMSG
#define ENONET          ENONET
#define ENOPROTOOPT     ENOPROTOOPT
#define ENOSPC          ENOSPC
#define ENOSR           ENOSR
#define ENOSTR          ENOSTR
#define ENOSYS          ENOSYS
#define ENOTBLK         ENOTBLK
#define ENOTCONN        ENOTCONN
#define ENOTDIR         ENOTDIR
#define ENOTEMPTY       ENOTEMPTY
#define ENOTRECOVERABLE ENOTRECOVERABLE
#define ENOTSOCK        ENOTSOCK
#define ENOTSUP         ENOTSUP
#define ENOTTY          ENOTTY
#define ENXIO           ENXIO
#define EOPNOTSUPP      EOPNOTSUPP
#define EOVERFLOW       EOVERFLOW
#define EOWNERDEAD      EOWNERDEAD
#define EPERM           EPERM
#define EPFNOSUPPORT    EPFNOSUPPORT
#define EPIPE           EPIPE
#define EPROTO          EPROTO
#define EPROTONOSUPPORT EPROTONOSUPPORT
#define EPROTOTYPE      EPROTOTYPE
#define ERANGE          ERANGE
#define EREMOTE         EREMOTE
#define ERESTART        ERESTART
#define EROFS           EROFS
#define ESHUTDOWN       ESHUTDOWN
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT
#define ESPIPE          ESPIPE
#define ESRCH           ESRCH
#define ESTALE          ESTALE
#define ETIME           ETIME
#define ETIMEDOUT       ETIMEDOUT
#define ETOOMANYREFS    ETOOMANYREFS
#define ETXTBSY         ETXTBSY
#define EUSERS          EUSERS
#define EWOULDBLOCK     EAGAIN
#define EXDEV           EXDEV

extern errno_t __errno;
errno_t *__errno_location(void) dontthrow pureconst;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
extern char *program_invocation_short_name;
extern char *program_invocation_name;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/inttypes.h */

#define COSMOPOLITAN_LIBC_INTTYPES_H_

typedef __INT_LEAST8_TYPE__ int_least8_t;
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
typedef __INT_LEAST16_TYPE__ int_least16_t;
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
typedef __INT_LEAST32_TYPE__ int_least32_t;
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
typedef __INT_LEAST64_TYPE__ int_least64_t;
typedef __UINT_LEAST64_TYPE__ uint_least64_t;

typedef __INT_FAST8_TYPE__ int_fast8_t;
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
typedef __INT_FAST16_TYPE__ int_fast16_t;
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
typedef __INT_FAST32_TYPE__ int_fast32_t;
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
typedef __INT_FAST64_TYPE__ int_fast64_t;
typedef __UINT_FAST64_TYPE__ uint_fast64_t;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define __PRI8 "hh"

#if __SIZEOF_INT__ == 2
#define __PRI16 ""
#elif __SIZEOF_SHORT__ == 2
#define __PRI16 "h"
#elif __SIZEOF_LONG__ == 2
#define __PRI16 "l"
#endif

#if __SIZEOF_INT__ == 4
#define __PRI32 ""
#elif __SIZEOF_LONG__ == 4
#define __PRI32 "l"
#elif __SIZEOF_LONG_LONG__ == 4
#define __PRI32 "ll"
#endif

#if __SIZEOF_INT__ == 8
#define __PRI64 ""
#elif __SIZEOF_LONG__ == 8
#define __PRI64 "l"
#elif __SIZEOF_LONG_LONG__ == 8
#define __PRI64 "ll"
#endif

#if __SIZEOF_INT__ == 16
#define __PRI128 ""
#elif __SIZEOF_LONG__ == 16
#define __PRI128 "l"
#elif __SIZEOF_LONG_LONG__ == 16
#define __PRI128 "ll"
#elif __SIZEOF_INTMAX__ == 16
#define __PRI128 "j"
#else
#define __PRI128 "jj"
#endif

#if __SIZEOF_POINTER__ == __SIZEOF_INT__
#define __PRIPTR ""
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG__
#define __PRIPTR "l"
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__
#define __PRIPTR "ll"
#endif

#if __INT_FAST16_WIDTH__ == 16
#define __PRIFAST16 "h"
#elif __INT_FAST16_WIDTH__ == 32
#define __PRIFAST16 ""
#else
#define __PRIFAST16 "l"
#endif

#if __INT_FAST32_WIDTH__ == 32
#define __PRIFAST32 ""
#else
#define __PRIFAST32 "l"
#endif

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » decimal                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRId8   __PRI8 "d"
#define PRId16  __PRI16 "d"
#define PRId32  __PRI32 "d"
#define PRId64  __PRI64 "d"
#define PRId128 __PRI128 "d"

#define PRIdLEAST8   __PRI8 "d"
#define PRIdLEAST16  __PRI16 "d"
#define PRIdLEAST32  __PRI32 "d"
#define PRIdLEAST64  __PRI64 "d"
#define PRIdLEAST128 __PRI128 "d"

#define PRIdFAST8   __PRI8 "d"
#define PRIdFAST16  __PRIFAST16 "d"
#define PRIdFAST32  __PRIFAST32 "d"
#define PRIdFAST64  __PRI64 "d"
#define PRIdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » unsigned decimal        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIu8   __PRI8 "u"
#define PRIu16  __PRI16 "u"
#define PRIu32  __PRI32 "u"
#define PRIu64  __PRI64 "u"
#define PRIu128 __PRI128 "u"

#define PRIuLEAST8   __PRI8 "u"
#define PRIuLEAST16  __PRI16 "u"
#define PRIuLEAST32  __PRI32 "u"
#define PRIuLEAST64  __PRI64 "u"
#define PRIuLEAST128 __PRI128 "u"

#define PRIuFAST8   __PRI8 "u"
#define PRIuFAST16  __PRIFAST16 "u"
#define PRIuFAST32  __PRIFAST32 "u"
#define PRIuFAST64  __PRI64 "u"
#define PRIuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » wut                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIi8   __PRI8 "i"
#define PRIi16  __PRI16 "i"
#define PRIi32  __PRI32 "i"
#define PRIi64  __PRI64 "i"
#define PRIi128 __PRI128 "i"

#define PRIiLEAST8   __PRI8 "i"
#define PRIiLEAST16  __PRI16 "i"
#define PRIiLEAST32  __PRI32 "i"
#define PRIiLEAST64  __PRI64 "i"
#define PRIiLEAST128 __PRI128 "i"

#define PRIiFAST8   __PRI8 "i"
#define PRIiFAST16  __PRIFAST16 "i"
#define PRIiFAST32  __PRIFAST32 "i"
#define PRIiFAST64  __PRI64 "i"
#define PRIiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » octal                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIo8   __PRI8 "o"
#define PRIo16  __PRI16 "o"
#define PRIo32  __PRI32 "o"
#define PRIo64  __PRI64 "o"
#define PRIo128 __PRI128 "o"

#define PRIoLEAST8   __PRI8 "o"
#define PRIoLEAST16  __PRI16 "o"
#define PRIoLEAST32  __PRI32 "o"
#define PRIoLEAST64  __PRI64 "o"
#define PRIoLEAST128 __PRI128 "o"

#define PRIoFAST8   __PRI8 "o"
#define PRIoFAST16  __PRIFAST16 "o"
#define PRIoFAST32  __PRIFAST32 "o"
#define PRIoFAST64  __PRI64 "o"
#define PRIoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » hexadecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIx8   __PRI8 "x"
#define PRIx16  __PRI16 "x"
#define PRIx32  __PRI32 "x"
#define PRIx64  __PRI64 "x"
#define PRIx128 __PRI128 "x"

#define PRIxLEAST8   __PRI8 "x"
#define PRIxLEAST16  __PRI16 "x"
#define PRIxLEAST32  __PRI32 "x"
#define PRIxLEAST64  __PRI64 "x"
#define PRIxLEAST128 __PRI128 "x"

#define PRIxFAST8   __PRI8 "x"
#define PRIxFAST16  __PRIFAST16 "x"
#define PRIxFAST32  __PRIFAST32 "x"
#define PRIxFAST64  __PRI64 "x"
#define PRIxFAST128 __PRI128 "x"

#define PRIX8   __PRI8 "X"
#define PRIX16  __PRI16 "X"
#define PRIX32  __PRI32 "X"
#define PRIX64  __PRI64 "X"
#define PRIX128 __PRI128 "X"

#define PRIXLEAST8   __PRI8 "X"
#define PRIXLEAST16  __PRI16 "X"
#define PRIXLEAST32  __PRI32 "X"
#define PRIXLEAST64  __PRI64 "X"
#define PRIXLEAST128 __PRI128 "X"

#define PRIXFAST8   __PRI8 "X"
#define PRIXFAST16  __PRIFAST16 "X"
#define PRIXFAST32  __PRIFAST32 "X"
#define PRIXFAST64  __PRI64 "X"
#define PRIXFAST128 __PRI128 "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » binary                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIb8   __PRI8 "b"
#define PRIb16  __PRI16 "b"
#define PRIb32  __PRI32 "b"
#define PRIb64  __PRI64 "b"
#define PRIb128 __PRI128 "b"

#define PRIbLEAST8   __PRI8 "b"
#define PRIbLEAST16  __PRI16 "b"
#define PRIbLEAST32  __PRI32 "b"
#define PRIbLEAST64  __PRI64 "b"
#define PRIbLEAST128 __PRI128 "b"

#define PRIbFAST8   __PRI8 "b"
#define PRIbFAST16  __PRIFAST16 "b"
#define PRIbFAST32  __PRIFAST32 "b"
#define PRIbFAST64  __PRI64 "b"
#define PRIbFAST128 __PRI128 "b"

#define PRIB8   __PRI8 "B"
#define PRIB16  __PRI16 "B"
#define PRIB32  __PRI32 "B"
#define PRIB64  __PRI64 "B"
#define PRIB128 __PRI128 "B"

#define PRIBLEAST8   __PRI8 "B"
#define PRIBLEAST16  __PRI16 "B"
#define PRIBLEAST32  __PRI32 "B"
#define PRIBLEAST64  __PRI64 "B"
#define PRIBLEAST128 __PRI128 "B"

#define PRIBFAST8   __PRI8 "B"
#define PRIBFAST16  __PRIFAST16 "B"
#define PRIBFAST32  __PRIFAST32 "B"
#define PRIBFAST64  __PRI64 "B"
#define PRIBFAST128 __PRI128 "B"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » miscellaneous           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIdMAX "jd"
#define PRIiMAX "ji"
#define PRIoMAX "jo"
#define PRIuMAX "ju"
#define PRIxMAX "jx"
#define PRIXMAX "jX"

#define PRIdPTR __PRIPTR "d"
#define PRIiPTR __PRIPTR "i"
#define PRIoPTR __PRIPTR "o"
#define PRIuPTR __PRIPTR "u"
#define PRIxPTR __PRIPTR "x"
#define PRIXPTR __PRIPTR "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » decimal                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNd8   __PRI8 "d"
#define SCNd16  __PRI16 "d"
#define SCNd32  __PRI32 "d"
#define SCNd64  __PRI64 "d"
#define SCNd128 __PRI128 "d"

#define SCNdLEAST8   __PRI8 "d"
#define SCNdLEAST16  __PRI16 "d"
#define SCNdLEAST32  __PRI32 "d"
#define SCNdLEAST64  __PRI64 "d"
#define SCNdLEAST128 __PRI128 "d"

#define SCNdFAST8   __PRI8 "d"
#define SCNdFAST16  __PRIFAST16 "d"
#define SCNdFAST32  __PRIFAST32 "d"
#define SCNdFAST64  __PRI64 "d"
#define SCNdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » flexidecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNi8   __PRI8 "i"
#define SCNi16  __PRI16 "i"
#define SCNi32  __PRI32 "i"
#define SCNi64  __PRI64 "i"
#define SCNi128 __PRI128 "i"

#define SCNiLEAST8   __PRI8 "i"
#define SCNiLEAST16  __PRI16 "i"
#define SCNiLEAST32  __PRI32 "i"
#define SCNiLEAST64  __PRI64 "i"
#define SCNiLEAST128 __PRI128 "i"

#define SCNiFAST8   __PRI8 "i"
#define SCNiFAST16  __PRIFAST16 "i"
#define SCNiFAST32  __PRIFAST32 "i"
#define SCNiFAST64  __PRI64 "i"
#define SCNiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » unsigned decimal         ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNu8   __PRI8 "u"
#define SCNu16  __PRI16 "u"
#define SCNu32  __PRI32 "u"
#define SCNu64  __PRI64 "u"
#define SCNu128 __PRI128 "u"

#define SCNuLEAST8   __PRI8 "u"
#define SCNuLEAST16  __PRI16 "u"
#define SCNuLEAST32  __PRI32 "u"
#define SCNuLEAST64  __PRI64 "u"
#define SCNuLEAST128 __PRI128 "u"

#define SCNuFAST8   __PRI8 "u"
#define SCNuFAST16  __PRIFAST16 "u"
#define SCNuFAST32  __PRIFAST32 "u"
#define SCNuFAST64  __PRI64 "u"
#define SCNuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » octal                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNo8   __PRI8 "o"
#define SCNo16  __PRI16 "o"
#define SCNo32  __PRI32 "o"
#define SCNo64  __PRI64 "o"
#define SCNo128 __PRI128 "o"

#define SCNoLEAST8   __PRI8 "o"
#define SCNoLEAST16  __PRI16 "o"
#define SCNoLEAST32  __PRI32 "o"
#define SCNoLEAST64  __PRI64 "o"
#define SCNoLEAST128 __PRI128 "o"

#define SCNoFAST8   __PRI8 "o"
#define SCNoFAST16  __PRIFAST16 "o"
#define SCNoFAST32  __PRIFAST32 "o"
#define SCNoFAST64  __PRI64 "o"
#define SCNoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » hexadecimal              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNx8   __PRI8 "x"
#define SCNx16  __PRI16 "x"
#define SCNx32  __PRI32 "x"
#define SCNx64  __PRI64 "x"
#define SCNx128 __PRI128 "x"

#define SCNxLEAST8   __PRI8 "x"
#define SCNxLEAST16  __PRI16 "x"
#define SCNxLEAST32  __PRI32 "x"
#define SCNxLEAST64  __PRI64 "x"
#define SCNxLEAST128 __PRI128 "x"

#define SCNxFAST8   __PRI8 "x"
#define SCNxFAST16  __PRIFAST16 "x"
#define SCNxFAST32  __PRIFAST32 "x"
#define SCNxFAST64  __PRI64 "x"
#define SCNxFAST128 __PRI128 "x"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » binary                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNb8   __PRI8 "b"
#define SCNb16  __PRI16 "b"
#define SCNb32  __PRI32 "b"
#define SCNb64  __PRI64 "b"
#define SCNb128 __PRI128 "b"

#define SCNbLEAST8   __PRI8 "b"
#define SCNbLEAST16  __PRI16 "b"
#define SCNbLEAST32  __PRI32 "b"
#define SCNbLEAST64  __PRI64 "b"
#define SCNbLEAST128 __PRI128 "b"

#define SCNbFAST8   __PRI8 "b"
#define SCNbFAST16  __PRIFAST16 "b"
#define SCNbFAST32  __PRIFAST32 "b"
#define SCNbFAST64  __PRI64 "b"
#define SCNbFAST128 __PRI128 "b"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » miscellaneous            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNdMAX "jd"
#define SCNiMAX "ji"
#define SCNoMAX "jo"
#define SCNuMAX "ju"
#define SCNxMAX "jx"

#define SCNdPTR __PRIPTR "d"
#define SCNiPTR __PRIPTR "i"
#define SCNoPTR __PRIPTR "o"
#define SCNuPTR __PRIPTR "u"
#define SCNxPTR __PRIPTR "x"



/*!BEGIN libc/limits.h */

#define COSMOPOLITAN_LIBC_LIMITS_H_
#define __STDC_LIMIT_MACROS

#define CHAR_BIT 8
#define PATH_MAX 1024
#define NAME_MAX 255
#define ARG_MAX  131074

#define UCHAR_MIN 0
#define UCHAR_MAX 255

#if '\200' < 0
#define CHAR_MIN '\200'
#define CHAR_MAX '\177'
#else
#define CHAR_MIN '\0'
#define CHAR_MAX '\377'
#endif

#define SCHAR_MAX     __SCHAR_MAX__
#define SHRT_MAX      __SHRT_MAX__
#define INT_MAX       __INT_MAX__
#define LONG_MAX      __LONG_MAX__
#define LLONG_MAX     LONG_LONG_MAX
#define LONG_LONG_MAX __LONG_LONG_MAX__
#define SIZE_MAX      __SIZE_MAX__
#define INT8_MAX      __INT8_MAX__
#define INT16_MAX     __INT16_MAX__
#define INT32_MAX     __INT32_MAX__
#define INT64_MAX     __INT64_MAX__
#define WINT_MAX      __WINT_MAX__
#define WCHAR_MAX     __WCHAR_MAX__
#define INTPTR_MAX    __INTPTR_MAX__
#define PTRDIFF_MAX   __PTRDIFF_MAX__
#define UINTPTR_MAX   __UINTPTR_MAX__
#define UINT8_MAX     __UINT8_MAX__
#define UINT16_MAX    __UINT16_MAX__
#define UINT32_MAX    __UINT32_MAX__
#define UINT64_MAX    __UINT64_MAX__
#define INTMAX_MAX    __INTMAX_MAX__
#define UINTMAX_MAX   __UINTMAX_MAX__
#define SSIZE_MAX     __INT64_MAX__

#define SCHAR_MIN     (-SCHAR_MAX - 1)
#define SHRT_MIN      (-SHRT_MAX - 1)
#define INT_MIN       (-INT_MAX - 1)
#define LONG_MIN      (-LONG_MAX - 1)
#define LLONG_MIN     (-LLONG_MAX - 1)
#define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
#define SIZE_MIN      (-SIZE_MAX - 1)
#define INT8_MIN      (-INT8_MAX - 1)
#define INT16_MIN     (-INT16_MAX - 1)
#define INT32_MIN     (-INT32_MAX - 1)
#define INT64_MIN     (-INT64_MAX - 1)
#define INTMAX_MIN    (-INTMAX_MAX - 1)
#define INTPTR_MIN    (-INTPTR_MAX - 1)
#define WINT_MIN      __WINT_MIN__
#define WCHAR_MIN     (-WCHAR_MAX - 1)
#define PTRDIFF_MIN   (-PTRDIFF_MAX - 1)

#define USHRT_MAX 65535
#define UINT_MAX  0xffffffffu
#if __SIZEOF_LONG__ == 8
#define ULONG_MAX 0xfffffffffffffffful
#else
#define ULONG_MAX 0xfffffffful
#endif
#define ULLONG_MAX     0xffffffffffffffffull
#define ULONG_LONG_MAX 0xffffffffffffffffull

#define USHRT_MIN      0
#define UINT_MIN       0u
#define ULONG_MIN      0ul
#define ULLONG_MIN     0ull
#define ULONG_LONG_MIN 0ull
#define UINT8_MIN      0
#define UINT16_MIN     0
#define UINT32_MIN     0u
#define UINT64_MIN     0ull
#define UINTPTR_MIN    0ull
#define UINTMAX_MIN    ((uintmax_t)0)

#define MB_CUR_MAX 4
#define MB_LEN_MAX 4

#ifdef _COSMO_SOURCE
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 406 || defined(__llvm__)
#define INT128_MIN  (-INT128_MAX - 1)
#define UINT128_MIN ((uint128_t)0)
#define INT128_MAX \
  ((int128_t)0x7fffffffffffffff << 64 | (int128_t)0xffffffffffffffff)
#define UINT128_MAX \
  ((uint128_t)0xffffffffffffffff << 64 | (uint128_t)0xffffffffffffffff)
#endif /* GCC 4.6+ */
#endif /* _COSMO_SOURCE */

#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX

#define FILESIZEBITS   64
#define SYMLOOP_MAX    40
#define TTY_NAME_MAX   32
#define HOST_NAME_MAX  255
#define TZNAME_MAX     6
#define WORD_BIT       32
#define SEM_VALUE_MAX  0x7fffffff
#define SEM_NSEMS_MAX  256
#define DELAYTIMER_MAX 0x7fffffff
#define MQ_PRIO_MAX    32768
#define LOGIN_NAME_MAX 256

#define NL_ARGMAX  9
#define NL_MSGMAX  32767
#define NL_SETMAX  255
#define NL_TEXTMAX 2048

#define INT_FAST8_MIN    (-__INT_FAST8_MAX__ - 1)
#define INT_FAST16_MIN   (-__INT_FAST16_MAX__ - 1)
#define INT_FAST32_MIN   (-__INT_FAST32_MAX__ - 1)
#define INT_FAST64_MIN   (-__INT_FAST64_MAX__ - 1)
#define INT_LEAST8_MIN   (-__INT_LEAST8_MAX__ - 1)
#define INT_LEAST16_MIN  (-__INT_LEAST16_MAX__ - 1)
#define INT_LEAST32_MIN  (-__INT_LEAST32_MAX__ - 1)
#define INT_LEAST64_MIN  (-__INT_LEAST64_MAX__ - 1)
#define INT_FAST8_MAX    __INT_FAST8_MAX__
#define INT_FAST16_MAX   __INT_FAST16_MAX__
#define INT_FAST32_MAX   __INT_FAST32_MAX__
#define INT_FAST64_MAX   __INT_FAST64_MAX__
#define INT_LEAST8_MAX   __INT_LEAST8_MAX__
#define INT_LEAST16_MAX  __INT_LEAST16_MAX__
#define INT_LEAST32_MAX  __INT_LEAST32_MAX__
#define INT_LEAST64_MAX  __INT_LEAST64_MAX__
#define UINT_FAST8_MAX   __UINT_FAST8_MAX__
#define UINT_FAST16_MAX  __UINT_FAST16_MAX__
#define UINT_FAST32_MAX  __UINT_FAST32_MAX__
#define UINT_FAST64_MAX  __UINT_FAST64_MAX__
#define UINT_LEAST8_MAX  __UINT_LEAST8_MAX__
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__

#define BC_BASE_MAX        99
#define BC_DIM_MAX         2048
#define BC_SCALE_MAX       99
#define BC_STRING_MAX      1000
#define CHARCLASS_NAME_MAX 14
#define COLL_WEIGHTS_MAX   2
#define EXPR_NEST_MAX      32
#define LINE_MAX           4096
#define RE_DUP_MAX         255
#define LONG_BIT           64
#define NZERO              20
#define NL_LANGMAX         32



/*!BEGIN libc/literal.h */

#define COSMOPOLITAN_LIBC_LITERAL_H_
#define __STDC_CONSTANT_MACROS

#ifdef __INT8_C
#define INT8_C(c)   __INT8_C(c)
#define UINT8_C(c)  __UINT8_C(c)
#define INT16_C(c)  __INT16_C(c)
#define UINT16_C(c) __UINT16_C(c)
#define INT32_C(c)  __INT32_C(c)
#define UINT32_C(c) __UINT32_C(c)
#define INT64_C(c)  __INT64_C(c)
#define UINT64_C(c) __UINT64_C(c)
#else
#define INT8_C(c)   c
#define UINT8_C(c)  c
#define INT16_C(c)  c
#define UINT16_C(c) c
#define INT32_C(c)  c
#define UINT32_C(c) c##U
#define INT64_C(c)  c##L
#define UINT64_C(c) c##UL
#endif

#if UINTPTR_MAX == UINT64_MAX
#define INTMAX_C(c)  c##L
#define UINTMAX_C(c) c##UL
#else
#define INTMAX_C(c)  c##LL
#define UINTMAX_C(c) c##ULL
#endif



/*!BEGIN libc/math.h */

#define COSMOPOLITAN_LIBC_MATH_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § mathematics                                                   │
╚─────────────────────────────────────────────────────────────────────────────*/

#define M_E        2.7182818284590452354  /* 𝑒 */
#define M_LOG2E    1.4426950408889634074  /* log₂𝑒 */
#define M_LOG10E   0.43429448190325182765 /* log₁₀𝑒 */
#define M_LN2      0.69314718055994530942 /* logₑ2 */
#define M_LN10     2.30258509299404568402 /* logₑ10 */
#define M_PI       3.14159265358979323846 /* 𝜋 */
#define M_PI_2     1.57079632679489661923 /* 𝜋/2 */
#define M_PI_4     0.78539816339744830962 /* 𝜋/4 */
#define M_1_PI     0.31830988618379067154 /* 1/𝜋 */
#define M_2_PI     0.63661977236758134308 /* 2/𝜋 */
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(𝜋) */
#define M_SQRT2    1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2  0.70710678118654752440 /* 1/sqrt(2) */

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_Ef        2.7182818284590452354f  /* 𝑒 */
#define M_LOG2Ef    1.4426950408889634074f  /* log₂𝑒 */
#define M_LOG10Ef   0.43429448190325182765f /* log₁₀𝑒 */
#define M_LN2f      0.69314718055994530942f /* logₑ2 */
#define M_LN10f     2.30258509299404568402f /* logₑ10 */
#define M_PIf       3.14159265358979323846f /* 𝜋 */
#define M_PI_2f     1.57079632679489661923f /* 𝜋/2 */
#define M_PI_4f     0.78539816339744830962f /* 𝜋/4 */
#define M_1_PIf     0.31830988618379067154f /* 1/𝜋 */
#define M_2_PIf     0.63661977236758134308f /* 2/𝜋 */
#define M_2_SQRTPIf 1.12837916709551257390f /* 2/sqrt(𝜋) */
#define M_SQRT2f    1.41421356237309504880f /* sqrt(2) */
#define M_SQRT1_2f  0.70710678118654752440f /* 1/sqrt(2) */
#endif

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_El        2.718281828459045235360287471352662498L /* 𝑒 */
#define M_LOG2El    1.442695040888963407359924681001892137L /* log₂𝑒 */
#define M_LOG10El   0.434294481903251827651128918916605082L /* log₁₀𝑒 */
#define M_LN2l      0.693147180559945309417232121458176568L /* logₑ2 */
#define M_LN10l     2.302585092994045684017991454684364208L /* logₑ10 */
#define M_PIl       3.141592653589793238462643383279502884L /* 𝜋 */
#define M_PI_2l     1.570796326794896619231321691639751442L /* 𝜋/2 */
#define M_PI_4l     0.785398163397448309615660845819875721L /* 𝜋/4 */
#define M_1_PIl     0.318309886183790671537767526745028724L /* 1/𝜋 */
#define M_2_PIl     0.636619772367581343075535053490057448L /* 2/𝜋 */
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(𝜋) */
#define M_SQRT2l    1.414213562373095048801688724209698079L /* sqrt(2) */
#define M_SQRT1_2l  0.707106781186547524400844362104849039L /* 1/sqrt(2) */
#endif

#define DBL_DECIMAL_DIG   __DBL_DECIMAL_DIG__
#define DBL_DIG           __DBL_DIG__
#define DBL_EPSILON       __DBL_EPSILON__
#define DBL_HAS_SUBNORM   __DBL_HAS_DENORM__
#define DBL_IS_IEC_60559  __DBL_IS_IEC_60559__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MAX           __DBL_MAX__
#define DBL_MAX_10_EXP    __DBL_MAX_10_EXP__
#define DBL_MAX_EXP       __DBL_MAX_EXP__
#define DBL_MIN           __DBL_MIN__ /* 2.23e–308 ↔ 1.79e308 */
#define DBL_MIN_10_EXP    __DBL_MIN_10_EXP__
#define DBL_MIN_EXP       __DBL_MIN_EXP__
#define DBL_NORM_MAX      __DBL_NORM_MAX__
#define DBL_TRUE_MIN      __DBL_DENORM_MIN__
#define DECIMAL_DIG       __LDBL_DECIMAL_DIG__
#define FLT_DECIMAL_DIG   __FLT_DECIMAL_DIG__
#define FLT_DIG           __FLT_DIG__
#define FLT_EPSILON       __FLT_EPSILON__
#define FLT_HAS_SUBNORM   __FLT_HAS_DENORM__
#define FLT_IS_IEC_60559  __FLT_IS_IEC_60559__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MAX           __FLT_MAX__
#define FLT_MAX_10_EXP    __FLT_MAX_10_EXP__
#define FLT_MAX_EXP       __FLT_MAX_EXP__
#define FLT_MIN           __FLT_MIN__ /* 1.18e–38 ↔ 3.40e38 */
#define FLT_MIN_10_EXP    __FLT_MIN_10_EXP__
#define FLT_MIN_EXP       __FLT_MIN_EXP__
#define FLT_NORM_MAX      __FLT_NORM_MAX__
#define FLT_RADIX         __FLT_RADIX__
#define FLT_TRUE_MIN      __FLT_DENORM_MIN__
#define HLF_MAX           6.50e4f
#define HLF_MIN           3.10e-5f
#define LDBL_DECIMAL_DIG  __LDBL_DECIMAL_DIG__
#define LDBL_DIG          __LDBL_DIG__
#define LDBL_EPSILON      __LDBL_EPSILON__
#define LDBL_HAS_SUBNORM  __LDBL_HAS_DENORM__
#define LDBL_IS_IEC_60559 __LDBL_IS_IEC_60559__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MAX          __LDBL_MAX__
#define LDBL_MAX_10_EXP   __LDBL_MAX_10_EXP__
#define LDBL_MAX_EXP      __LDBL_MAX_EXP__
#define LDBL_MIN          __LDBL_MIN__ /* 3.37e–4932 ↔ 1.18e4932 */
#define LDBL_MIN_10_EXP   __LDBL_MIN_10_EXP__
#define LDBL_MIN_EXP      __LDBL_MIN_EXP__
#define LDBL_NORM_MAX     __LDBL_NORM_MAX__
#define LDBL_TRUE_MIN     __LDBL_DENORM_MIN__

#define FP_NAN       0
#define FP_INFINITE  1
#define FP_ZERO      2
#define FP_SUBNORMAL 3
#define FP_NORMAL    4
#define FP_ILOGB0    (-2147483647 - 1)
#define FP_ILOGBNAN  (-2147483647 - 1)

#define MATH_ERRNO     1
#define MATH_ERREXCEPT 2

#ifdef __FAST_MATH__
#define math_errhandling 0
#elif defined(__NO_MATH_ERRNO__)
#define math_errhandling (MATH_ERREXCEPT)
#else
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
#endif

#ifdef __FP_FAST_FMA
#define FP_FAST_FMA 1
#endif
#ifdef __FP_FAST_FMAF
#define FP_FAST_FMAF 1
#endif
#ifdef __FP_FAST_FMAL
#define FP_FAST_FMAL 1
#endif

COSMOPOLITAN_C_START_

#define NAN       __builtin_nanf("")
#define INFINITY  __builtin_inff()
#define HUGE_VAL  __builtin_inf()
#define HUGE_VALF __builtin_inff()
#define HUGE_VALL __builtin_infl()

#if __FLT_EVAL_METHOD__ + 0 == 2
typedef long double float_t;
typedef long double double_t;
#else
typedef float float_t;
typedef double double_t;
#endif

#define isinf(x)             __builtin_isinf(x)
#define isnan(x)             __builtin_isnan(x)
#define isfinite(x)          __builtin_isfinite(x)
#define isnormal(x)          __builtin_isnormal(x)
#define isgreater(x, y)      __builtin_isgreater(x, y)
#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
#define isless(x, y)         __builtin_isless(x, y)
#define islessequal(x, y)    __builtin_islessequal(x, y)
#define islessgreater(x, y)  __builtin_islessgreater(x, y)
#define isunordered(x, y)    __builtin_isunordered(x, y)

#define fpclassify(x) \
  __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)

#define signbit(x)                                          \
  (sizeof(x) == sizeof(long double) ? __builtin_signbitl(x) \
   : sizeof(x) == sizeof(float)     ? __builtin_signbitf(x) \
                                    : __builtin_signbit(x))

extern int signgam;

double acos(double) libcesque;
double acosh(double) libcesque;
double asin(double) libcesque;
double asinh(double) libcesque;
double atan(double) libcesque;
double atan2(double, double) libcesque;
double atanh(double) libcesque;
double cbrt(double) libcesque;
double ceil(double) libcesque;
double copysign(double, double) libcesque;
double cos(double) libcesque;
double cosh(double) libcesque;
double drem(double, double) libcesque;
double erf(double) libcesque;
double erfc(double) libcesque;
double exp(double) libcesque;
double exp10(double) libcesque;
double exp2(double) libcesque;
double expm1(double) libcesque;
double fabs(double) libcesque;
double fdim(double, double) libcesque;
double floor(double) libcesque;
double fma(double, double, double) libcesque;
double fmax(double, double) libcesque;
double fmin(double, double) libcesque;
double fmod(double, double) libcesque;
double hypot(double, double) libcesque;
double ldexp(double, int) libcesque;
double log(double) libcesque;
double log10(double) libcesque;
double log1p(double) libcesque;
double log2(double) libcesque;
double logb(double) libcesque;
double nearbyint(double) libcesque;
double nextafter(double, double) libcesque;
double nexttoward(double, long double) libcesque;
double pow(double, double) libcesque;
double pow10(double) libcesque;
double powi(double, int) libcesque;
double remainder(double, double) libcesque;
double rint(double) libcesque;
double round(double) libcesque;
double scalb(double, double) libcesque;
double scalbln(double, long int) libcesque;
double scalbn(double, int) libcesque;
double significand(double) libcesque;
double sin(double) libcesque;
double sinh(double) libcesque;
double sqrt(double) libcesque;
double tan(double) libcesque;
double tanh(double) libcesque;
double trunc(double) libcesque;
double tgamma(double) libcesque;
double lgamma(double) libcesque;
double lgamma_r(double, int *) libcesque;
int finite(double) libcesque;

float acosf(float) libcesque;
float acoshf(float) libcesque;
float asinf(float) libcesque;
float asinhf(float) libcesque;
float atan2f(float, float) libcesque;
float atanf(float) libcesque;
float atanhf(float) libcesque;
float cbrtf(float) libcesque;
float ceilf(float) libcesque;
float copysignf(float, float) libcesque;
float cosf(float) libcesque;
float coshf(float) libcesque;
float dremf(float, float) libcesque;
float erfcf(float) libcesque;
float erff(float) libcesque;
float exp10f(float) libcesque;
float exp2f(float) libcesque;
float expf(float) libcesque;
float expm1f(float) libcesque;
float fabsf(float) libcesque;
float fdimf(float, float) libcesque;
float floorf(float) libcesque;
float fmaf(float, float, float) libcesque;
float fmaxf(float, float) libcesque;
float fminf(float, float) libcesque;
float fmodf(float, float) libcesque;
float hypotf(float, float) libcesque;
float ldexpf(float, int) libcesque;
float lgammaf(float) libcesque;
float lgammaf_r(float, int *) libcesque;
float log10f(float) libcesque;
float log1pf(float) libcesque;
float log2f(float) libcesque;
float logbf(float) libcesque;
float logf(float) libcesque;
float nearbyintf(float) libcesque;
float nextafterf(float, float) libcesque;
float nexttowardf(float, long double) libcesque;
float pow10f(float) libcesque;
float powf(float, float) libcesque;
float powif(float, int) libcesque;
float remainderf(float, float) libcesque;
float rintf(float) libcesque;
float roundf(float) libcesque;
float scalbf(float, float) libcesque;
float scalblnf(float, long int) libcesque;
float scalbnf(float, int) libcesque;
float significandf(float) libcesque;
float sinf(float) libcesque;
float sinhf(float) libcesque;
float sqrtf(float) libcesque;
float tanf(float) libcesque;
float tanhf(float) libcesque;
float tgammaf(float) libcesque;
float truncf(float) libcesque;
int finitef(float) libcesque;

int finitel(long double) libcesque;
long double acoshl(long double) libcesque;
long double acosl(long double) libcesque;
long double asinhl(long double) libcesque;
long double asinl(long double) libcesque;
long double atan2l(long double, long double) libcesque;
long double atanhl(long double) libcesque;
long double atanl(long double) libcesque;
long double cbrtl(long double) libcesque;
long double ceill(long double) libcesque;
long double copysignl(long double, long double) libcesque;
long double coshl(long double) libcesque;
long double cosl(long double) libcesque;
long double dreml(long double, long double) libcesque;
long double erfcl(long double) libcesque;
long double erfl(long double) libcesque;
long double exp10l(long double) libcesque;
long double exp2l(long double) libcesque;
long double expl(long double) libcesque;
long double expm1l(long double) libcesque;
long double fabsl(long double) libcesque;
long double fdiml(long double, long double) libcesque;
long double floorl(long double) libcesque;
long double fmal(long double, long double, long double) libcesque;
long double fmaxl(long double, long double) libcesque;
long double fminl(long double, long double) libcesque;
long double fmodl(long double, long double) libcesque;
long double hypotl(long double, long double) libcesque;
long double ldexpl(long double, int) libcesque;
long double lgammal(long double) libcesque;
long double lgammal_r(long double, int *) libcesque;
long double log10l(long double) libcesque;
long double log1pl(long double) libcesque;
long double log2l(long double) libcesque;
long double logbl(long double) libcesque;
long double logl(long double) libcesque;
long double nearbyintl(long double) libcesque;
long double nextafterl(long double, long double) libcesque;
long double nexttowardl(long double, long double) libcesque;
long double pow10l(long double) libcesque;
long double powl(long double, long double) libcesque;
long double remainderl(long double, long double) libcesque;
long double rintl(long double) libcesque;
long double roundl(long double) libcesque;
long double scalbl(long double, long double) libcesque;
long double scalblnl(long double, long int) libcesque;
long double scalbnl(long double, int) libcesque;
long double significandl(long double) libcesque;
long double sinhl(long double) libcesque;
long double sinl(long double) libcesque;
long double sqrtl(long double) libcesque;
long double tanhl(long double) libcesque;
long double tanl(long double) libcesque;
long double tgammal(long double) libcesque;
long double truncl(long double) libcesque;

long lrint(double) libcesque;
long lrintf(float) libcesque;
long lrintl(long double) libcesque;
long lround(double) libcesque;
long lroundf(float) libcesque;
long lroundl(long double) libcesque;

int ilogbf(float) libcesque;
int ilogb(double) libcesque;
int ilogbl(long double) libcesque;

long long llrint(double) libcesque;
long long llrintf(float) libcesque;
long long llrintl(long double) libcesque;
long long llround(double) libcesque;
long long llroundf(float) libcesque;
long long llroundl(long double) libcesque;

double frexp(double, int *) libcesque;
double modf(double, double *) libcesque;
double nan(const char *) libcesque;
double remquo(double, double, int *) libcesque;
float frexpf(float, int *) libcesque;
float modff(float, float *) libcesque;
float nanf(const char *) libcesque;
float remquof(float, float, int *) libcesque;
long double frexpl(long double, int *) libcesque;
long double modfl(long double, long double *) libcesque;
long double nanl(const char *) libcesque;
long double remquol(long double, long double, int *) libcesque;
void sincos(double, double *, double *) libcesque;
void sincosf(float, float *, float *) libcesque;
void sincosl(long double, long double *, long double *) libcesque;

double fsumf(const float *, size_t) libcesque;
double fsum(const double *, size_t) libcesque;

double j0(double) libcesque;
double j1(double) libcesque;
double jn(int, double) libcesque;
float j0f(float) libcesque;
float j1f(float) libcesque;
float jnf(int, float) libcesque;

double y0(double) libcesque;
double y1(double) libcesque;
double yn(int, double) libcesque;
float y0f(float) libcesque;
float y1f(float) libcesque;
float ynf(int, float) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/paths.h */

#define COSMOPOLITAN_LIBC_PATHS_H_

#define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin"
#define _PATH_STDPATH "/bin:/usr/bin:/sbin:/usr/sbin"

#define _PATH_BSHELL   "/bin/sh"
#define _PATH_CONSOLE  "/dev/console"
#define _PATH_DEVNULL  "/dev/null"
#define _PATH_KLOG     "/proc/kmsg"
#define _PATH_LASTLOG  "/var/log/lastlog"
#define _PATH_MAILDIR  "/var/mail"
#define _PATH_MAN      "/usr/share/man"
#define _PATH_MNTTAB   "/etc/fstab"
#define _PATH_MOUNTED  "/etc/mtab"
#define _PATH_NOLOGIN  "/etc/nologin"
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
#define _PATH_SHADOW   "/etc/shadow"
#define _PATH_SHELLS   "/etc/shells"
#define _PATH_TTY      "/dev/tty"
#define _PATH_UTMP     "/dev/null/utmp"
#define _PATH_VI       "/usr/bin/vi"
#define _PATH_WTMP     "/dev/null/wtmp"

#define _PATH_DEV    "/dev/"
#define _PATH_TMP    "/tmp/"
#define _PATH_VARDB  "/var/lib/misc/"
#define _PATH_VARRUN "/var/run/"
#define _PATH_VARTMP "/var/tmp/"



/*!BEGIN libc/serialize.h */

#define COSMOPOLITAN_SERIALIZE_H_
#ifdef _COSMO_SOURCE

#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define __SWAPBE16(x) (x)
#define __SWAPBE32(x) (x)
#define __SWAPBE64(x) (x)
#else
#define __SWAPBE16(x) __builtin_bswap16(x)
#define __SWAPBE32(x) __builtin_bswap32(x)
#define __SWAPBE64(x) __builtin_bswap64(x)
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __SWAPLE16(x) (x)
#define __SWAPLE32(x) (x)
#define __SWAPLE64(x) (x)
#else
#define __SWAPLE16(x) __builtin_bswap16(x)
#define __SWAPLE32(x) __builtin_bswap32(x)
#define __SWAPLE64(x) __builtin_bswap64(x)
#endif

#define READ16LE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPLE16(__x);                   \
  }))

#define READ16BE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPBE16(__x);                   \
  }))

#define READ32LE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ32BE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPBE32(__x);                   \
  }))

#define READ64LE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ64BE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPBE64(__x);                   \
  }))

#define WRITE16LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPLE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE16BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPBE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE32LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPLE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE32BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPBE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE64LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPLE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#define WRITE64BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPBE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/stdckdint.h */

#define COSMOPOLITAN_LIBC_STDCKDINT_H_
/* clang-format off */

/**
 * @fileoverview C23 Checked Arithmetic
 *
 * This header defines three type generic functions:
 *
 *   - `bool ckd_add(res, a, b)`
 *   - `bool ckd_sub(res, a, b)`
 *   - `bool ckd_mul(res, a, b)`
 *
 * Which allow integer arithmetic errors to be detected. There are many
 * kinds of integer errors, e.g. overflow, truncation, etc. These funcs
 * catch them all. Here's an example of how it works:
 *
 *     uint32_t c;
 *     int32_t a = 0x7fffffff;
 *     int32_t b = 2;
 *     assert(!ckd_add(&c, a, b));
 *     assert(c == 0x80000001u);
 *
 * Experienced C / C++ users should find this example counter-intuitive
 * because the expression `0x7fffffff + 2` not only overflows it's also
 * undefined behavior. However here we see it's specified, and does not
 * result in an error. That's because C23 checked arithmetic is not the
 * arithmetic you're used to. The new standard changes the mathematics.
 *
 * C23 checked arithmetic is defined as performing the arithmetic using
 * infinite precision and then checking if the resulting value will fit
 * in the output type. Our example above did not result in an error due
 * to `0x80000001` being a legal value for `uint32_t`.
 *
 * This implementation will use the GNU compiler builtins, when they're
 * available, only if you don't use build flags like `-std=c11` because
 * they define `__STRICT_ANSI__` and GCC extensions aren't really ANSI.
 * Instead, you'll get a pretty good pure C11 and C++11 implementation.
 *
 * @see https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
 * @version 0.1 (2023-07-22)
 */

#define __STDC_VERSION_STDCKDINT_H__ 202311L

#if ((defined(__llvm__) ||                                              \
      (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406)) && \
     !defined(__STRICT_ANSI__))
#define __ckd_have_int128
#define __ckd_intmax __int128
#elif ((defined(__cplusplus) && __cplusplus >= 201103L) ||              \
       (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L))
#define __ckd_intmax long long
#else
#define __ckd_intmax long
#endif

typedef signed __ckd_intmax __ckd_intmax_t;
typedef unsigned __ckd_intmax __ckd_uintmax_t;

#if (!defined(__STRICT_ANSI__) &&                       \
     ((defined(__GNUC__) && __GNUC__ >= 5 &&            \
       !defined(__chibicc__) && !defined(__ICC)) ||     \
      (__has_builtin(__builtin_add_overflow) &&         \
       __has_builtin(__builtin_sub_overflow) &&         \
       __has_builtin(__builtin_mul_overflow))))
#define ckd_add(res, x, y) __builtin_add_overflow((x), (y), (res))
#define ckd_sub(res, x, y) __builtin_sub_overflow((x), (y), (res))
#define ckd_mul(res, x, y) __builtin_mul_overflow((x), (y), (res))

#elif defined(__cplusplus) && __cplusplus >= 201103L

template <typename __T, typename __U, typename __V>
inline bool ckd_add(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x + __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u + u
      return __truncated | (__z < __x);
    case 1:  // u = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 2:  // u = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 3:  // u = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z | __x) &  __y) |
                                       ((__z & __x) & ~__y)) < 0);
    case 4:  // s = u + u
      return __truncated | (__z < __x) | (static_cast<__ckd_intmax_t>(__z) < 0);
    case 5:  // s = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __y);
    case 6:  // s = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __x);
    case 7:  // s = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_sub(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x - __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u - u
      return __truncated | (__x < __y);
    case 1:  // u = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    case 2:  // u = s - u
      return __truncated | (__y > __x) | (static_cast<__ckd_intmax_t>(__x) < 0);
    case 3:  // u = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z & __x) &  __y) |
                                       ((__z | __x) & ~__y)) < 0);
    case 4:  // s = u - u
      return __truncated |
          ((__x < __y) ^ (static_cast<__ckd_intmax_t>(__z) < 0));
    case 5:  // s = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x >= __y);
    case 6:  // s = s - u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x < __y);
    case 7:  // s = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_mul(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  if ((sizeof(__U) * 8 - std::is_signed<__U>::value) +
      (sizeof(__V) * 8 - std::is_signed<__V>::value) <=
      (sizeof(__T) * 8 - std::is_signed<__T>::value)) {
    if (sizeof(__ckd_uintmax_t) > sizeof(__T) || std::is_signed<__T>::value) {
      __ckd_intmax_t __z = __x * __y;
      return __z != (*__res = __z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0: {  // u = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 1: {  // u = u * s
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__y) < 0) & !!__x) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 2: {  // u = s * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__x) < 0) & !!__y) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 3: { // u = s * s
      int __o = false;
      if (static_cast<__ckd_intmax_t>(__x & __y) < 0) {
        __x = -__x;
        __y = -__y;
      } else if (static_cast<__ckd_intmax_t>(__x ^ __y) < 0) {
        __o = __x && __y;
      }
      __ckd_uintmax_t __z = __x * __y;
      __o |= __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 4: {  // s = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | (static_cast<__ckd_intmax_t>(__z) < 0) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 5: {  // s = u * s
      __ckd_uintmax_t __t = -__y;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __y : __t;
      __ckd_uintmax_t __p = __t * __x;
      int __o = __t && __p / __t != __x;
      int __n = static_cast<__ckd_intmax_t>(__y) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 6: {  // s = s * u
      __ckd_uintmax_t __t = -__x;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __x : __t;
      __ckd_uintmax_t __p = __t * __y;
      int __o = __t && __p / __t != __y;
      int __n = static_cast<__ckd_intmax_t>(__x) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 7: {  // s = s * s
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return ((((static_cast<__ckd_intmax_t>(__y) < 0) &&
                (static_cast<__ckd_intmax_t>(__x) ==
                 std::numeric_limits<__ckd_intmax_t>::min())) ||
               (__y && ((static_cast<__ckd_intmax_t>(__z) /
                         static_cast<__ckd_intmax_t>(__y)) !=
                        static_cast<__ckd_intmax_t>(__x)))) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    default:
      for (;;) (void)0;
  }
}

#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L

#define ckd_add(res, a, b) __ckd_expr(add, (res), (a), (b))
#define ckd_sub(res, a, b) __ckd_expr(sub, (res), (a), (b))
#define ckd_mul(res, a, b) __ckd_expr(mul, (res), (a), (b))

#if defined(__GNUC__) || defined(__llvm__)
#define __ckd_inline                                    \
  extern __inline __attribute__((__gnu_inline__,        \
                                 __always_inline__,     \
                                 __artificial__))
#else
#define __ckd_inline static inline
#endif

#ifdef __ckd_have_int128
#define __ckd_generic_int128(x, y) , signed __int128: x, unsigned __int128: y
#else
#define __ckd_generic_int128(x, y)
#endif

#define __ckd_sign(T)                           \
  ((T)1 << (sizeof(T) * 8 - 1))

#define __ckd_is_signed(x)                      \
  _Generic(x,                                   \
           signed char: 1,                      \
           unsigned char: 0,                    \
           signed short: 1,                     \
           unsigned short: 0,                   \
           signed int: 1,                       \
           unsigned int: 0,                     \
           signed long: 1,                      \
           unsigned long: 0,                    \
           signed long long: 1,                 \
           unsigned long long: 0                \
           __ckd_generic_int128(1, 0))

#define __ckd_expr(op, res, a, b)                       \
  (_Generic(*res,                                       \
            signed char: __ckd_##op##_schar,            \
            unsigned char: __ckd_##op##_uchar,          \
            signed short: __ckd_##op##_sshort,          \
            unsigned short: __ckd_##op##_ushort,        \
            signed int: __ckd_##op##_sint,              \
            unsigned int: __ckd_##op##_uint,            \
            signed long: __ckd_##op##_slong,            \
            unsigned long: __ckd_##op##_ulong,          \
            signed long long: __ckd_##op##_slonger,     \
            unsigned long long: __ckd_##op##_ulonger    \
            __ckd_generic_int128(                       \
                __ckd_##op##_sint128,                   \
                __ckd_##op##_uint128))(                 \
                    res, a, b,                          \
                    __ckd_is_signed(a),                 \
                    __ckd_is_signed(b)))

#define __ckd_declare_add(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x + __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u + u */                                          \
        return __truncated | (__z < __x);                               \
      case 1:  /* u = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 2:  /* u = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 3:  /* u = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z | __x) &  __y) |                    \
                              ((__z & __x) & ~__y)) < 0);               \
      case 4:  /* s = u + u */                                          \
        return __truncated | (__z < __x) | ((__ckd_intmax_t)__z < 0);   \
      case 5:  /* s = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __y);                         \
      case 6:  /* s = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __x);                         \
      case 7:  /* s = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_add(__ckd_add_schar, signed char)
__ckd_declare_add(__ckd_add_uchar, unsigned char)
__ckd_declare_add(__ckd_add_sshort, signed short)
__ckd_declare_add(__ckd_add_ushort, unsigned short)
__ckd_declare_add(__ckd_add_sint, signed int)
__ckd_declare_add(__ckd_add_uint, unsigned int)
__ckd_declare_add(__ckd_add_slong, signed long)
__ckd_declare_add(__ckd_add_ulong, unsigned long)
__ckd_declare_add(__ckd_add_slonger, signed long long)
__ckd_declare_add(__ckd_add_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_add(__ckd_add_sint128, signed __int128)
__ckd_declare_add(__ckd_add_uint128, unsigned __int128)
#endif

#define __ckd_declare_sub(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x - __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u - u */                                          \
        return __truncated | (__x < __y);                               \
      case 1:  /* u = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      case 2:  /* u = s - u */                                          \
        return __truncated | (__y > __x) | ((__ckd_intmax_t)__x < 0);   \
      case 3:  /* u = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z & __x) &  __y) |                    \
                              ((__z | __x) & ~__y)) < 0);               \
      case 4:  /* s = u - u */                                          \
        return __truncated | ((__x < __y) ^ ((__ckd_intmax_t)__z < 0)); \
      case 5:  /* s = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x >= __y);                              \
      case 6:  /* s = s - u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x < __y);                               \
      case 7:  /* s = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_sub(__ckd_sub_schar, signed char)
__ckd_declare_sub(__ckd_sub_uchar, unsigned char)
__ckd_declare_sub(__ckd_sub_sshort, signed short)
__ckd_declare_sub(__ckd_sub_ushort, unsigned short)
__ckd_declare_sub(__ckd_sub_sint, signed int)
__ckd_declare_sub(__ckd_sub_uint, unsigned int)
__ckd_declare_sub(__ckd_sub_slong, signed long)
__ckd_declare_sub(__ckd_sub_ulong, unsigned long)
__ckd_declare_sub(__ckd_sub_slonger, signed long long)
__ckd_declare_sub(__ckd_sub_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_sub(__ckd_sub_sint128, signed __int128)
__ckd_declare_sub(__ckd_sub_uint128, unsigned __int128)
#endif

#define __ckd_declare_mul(S, T)                                 \
  __ckd_inline char S(void *__res,                              \
                      __ckd_uintmax_t __x,                      \
                      __ckd_uintmax_t __y,                      \
                      char __a_signed,                          \
                      char __b_signed) {                        \
    switch (__ckd_is_signed((T)0) << 2 |                        \
            __a_signed << 1 | __b_signed) {                     \
      case 0: {  /* u = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 1: {  /* u = u * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__y < 0) & !!__x) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 2: {  /* u = s * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__x < 0) & !!__y) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 3: {  /* u = s * s */                                \
        int __o = 0;                                            \
        if ((__ckd_intmax_t)(__x & __y) < 0) {                  \
          __x = -__x;                                           \
          __y = -__y;                                           \
        } else if ((__ckd_intmax_t)(__x ^ __y) < 0) {           \
          __o = __x && __y;                                     \
        }                                                       \
        __ckd_uintmax_t __z = __x * __y;                        \
        __o |= __x && __z / __x != __y;                         \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 4: {  /* s = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | ((__ckd_intmax_t)(__z) < 0) |             \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 5: {  /* s = u * s */                                \
        __ckd_uintmax_t __t = -__y;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __y : __t;            \
        __ckd_uintmax_t __p = __t * __x;                        \
        int __o = __t && __p / __t != __x;                      \
        int __n = (__ckd_intmax_t)__y < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 6: {  /* s = s * u */                                \
        __ckd_uintmax_t __t = -__x;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __x : __t;            \
        __ckd_uintmax_t __p = __t * __y;                        \
        int __o = __t && __p / __t != __y;                      \
        int __n = (__ckd_intmax_t)__x < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 7: {  /* s = s * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        *(T *)__res = __z;                                      \
        return (((((__ckd_intmax_t)__y < 0) &&                  \
                  (__x == __ckd_sign(__ckd_uintmax_t))) ||      \
                 (__y && (((__ckd_intmax_t)__z /                \
                           (__ckd_intmax_t)__y) !=              \
                          (__ckd_intmax_t)__x))) |              \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      default:                                                  \
        for (;;) (void)0;                                       \
    }                                                           \
  }

__ckd_declare_mul(__ckd_mul_schar, signed char)
__ckd_declare_mul(__ckd_mul_uchar, unsigned char)
__ckd_declare_mul(__ckd_mul_sshort, signed short)
__ckd_declare_mul(__ckd_mul_ushort, unsigned short)
__ckd_declare_mul(__ckd_mul_sint, signed int)
__ckd_declare_mul(__ckd_mul_uint, unsigned int)
__ckd_declare_mul(__ckd_mul_slong, signed long)
__ckd_declare_mul(__ckd_mul_ulong, unsigned long)
__ckd_declare_mul(__ckd_mul_slonger, signed long long)
__ckd_declare_mul(__ckd_mul_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_mul(__ckd_mul_sint128, signed __int128)
__ckd_declare_mul(__ckd_mul_uint128, unsigned __int128)
#endif

#else
#pragma message "checked integer arithmetic unsupported in this environment"

#define ckd_add(res, x, y) (*(res) = (x) + (y), 0)
#define ckd_sub(res, x, y) (*(res) = (x) - (y), 0)
#define ckd_mul(res, x, y) (*(res) = (x) * (y), 0)

#endif /* GNU */
/* clang-format on */


/*!BEGIN libc/stdlib.h */

#define COSMOPOLITAN_LIBC_STDLIB_H_
COSMOPOLITAN_C_START_

char *fcvt(double, int, int *, int *) libcesque;
char *ecvt(double, int, int *, int *) libcesque;
char *gcvt(double, int, char *) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void setkey(const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/temp.h */

#define COSMOPOLITAN_LIBC_TEMP_H_
COSMOPOLITAN_C_START_

char *mktemp(char *) libcesque returnsnonnull paramsnonnull();
char *mkdtemp(char *) libcesque paramsnonnull() __wur;
int mkstemp(char *) libcesque paramsnonnull() __wur;
int mkstemps(char *, int) libcesque paramsnonnull() __wur;

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
int mkostemp(char *, unsigned) libcesque paramsnonnull() __wur;
int mkostemps(char *, int, unsigned) libcesque paramsnonnull() __wur;
#endif

#ifdef _COSMO_SOURCE
int openatemp(int, char *, int, int, int) libcesque paramsnonnull() __wur;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/time.h */

#define COSMOPOLITAN_LIBC_TIME_H_

#define TIME_UTC 1

COSMOPOLITAN_C_START_

struct tm {
  int32_t tm_sec;
  int32_t tm_min;
  int32_t tm_hour;
  int32_t tm_mday; /* 1-indexed */
  int32_t tm_mon;  /* 0-indexed */
  int32_t tm_year; /* minus 1900 */
  int32_t tm_wday;
  int32_t tm_yday;
  int32_t tm_isdst;
  int64_t tm_gmtoff;
  const char *tm_zone;
};

struct timezone {
  int32_t tz_minuteswest;
  int32_t tz_dsttime;
};

extern char *tzname[2];
extern long timezone;
extern int daylight;

void tzset(void) libcesque;
char *asctime(const struct tm *) libcesque;
char *asctime_r(const struct tm *, char *) libcesque;
char *strptime(const char *, const char *, struct tm *) libcesque;
int64_t mktime(struct tm *) libcesque;
int64_t timegm(struct tm *) libcesque;
int64_t timelocal(struct tm *) libcesque;
int64_t timeoff(struct tm *, long) libcesque;
size_t strftime(char *, size_t, const char *, const struct tm *) libcesque
    strftimeesque(3) libcesque;
size_t wcsftime(wchar_t *, size_t, const wchar_t *,
                const struct tm *) libcesque;
struct tm *gmtime(const int64_t *) libcesque;
struct tm *gmtime_r(const int64_t *, struct tm *) libcesque;
struct tm *localtime(const int64_t *) libcesque;
struct tm *localtime_r(const int64_t *, struct tm *) libcesque;

char *ctime(const int64_t *) libcesque;
char *ctime_r(const int64_t *, char *) libcesque;
double difftime(int64_t, int64_t)
pureconst libcesque;
int stime(const int64_t *) libcesque;
void tzset(void) libcesque;

#ifdef _COSMO_SOURCE
extern const char kWeekdayNameShort[7][4];
extern const char kWeekdayName[7][10];
extern const char kMonthNameShort[12][4];
extern const char kMonthName[12][10];
extern const unsigned short kMonthYearDay[2][12];
#define iso8601 __iso8601
char *iso8601(char[hasatleast 20], struct tm *) libcesque;
#define iso8601us __iso8601us
char *iso8601us(char[hasatleast 27], struct tm *, long) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/type2str.h */

#define COSMOPOLITAN_LIBC_TYPE2STR_H_
#if __STDC_VERSION__ + 0 >= 201112
/* clang-format off */

#define _TYPE2STR(X)                          \
  _Generic(X,                                 \
    _Bool:              "_Bool",              \
    signed char:        "signed char",        \
    unsigned char:      "unsigned char",      \
    char:               "char",               \
    short:              "short",              \
    unsigned short:     "unsigned short",     \
    int:                "int",                \
    unsigned:           "unsigned",           \
    long:               "long",               \
    unsigned long:      "unsigned long",      \
    long long:          "long long",          \
    unsigned long long: "unsigned long long", \
    __int128:           "__int128",           \
    unsigned __int128:  "unsigned __int128",  \
    float:              "float",              \
    double:             "double",             \
    long double:        "long double")

#define _PRINTF_GENERIC(X, D, U) \
  _Generic(X,                    \
    _Bool:              "hhh" U, \
    signed char:        "hh" D,  \
    unsigned char:      "hh" U,  \
    char:               "hh" D,  \
    short:              "h" D,   \
    unsigned short:     "h" U,   \
    int:                D,       \
    unsigned:           U,       \
    long:               "l" D,   \
    unsigned long:      "l" U,   \
    long long:          "ll" D,  \
    unsigned long long: "ll" U,  \
    float:              "f",     \
    double:             "f",     \
    long double:        "Lf")

/* clang-format on */
#endif /* C11 */


/*!BEGIN libc/unistd.h */

#define COSMOPOLITAN_LIBC_UNISTD_H_
COSMOPOLITAN_C_START_

#define _CS_PATH 0

size_t confstr(int, char *, size_t) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void encrypt(char *, int) libcesque;
char *crypt(const char *, const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/utime.h */

#define COSMOPOLITAN_LIBC_UTIME_H_
COSMOPOLITAN_C_START_

struct utimbuf {
  int64_t actime;  /* access time */
  int64_t modtime; /* modified time */
};

int utime(const char *, const struct utimbuf *) libcesque;

#ifdef _COSMO_SOURCE
int sys_utime(const char *, const struct utimbuf *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/typedef/u.h */

#define COSMOPOLITAN_LIBC_CALLS_TYPEDEF_U_H_
COSMOPOLITAN_C_START_

typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
typedef unsigned u_int32_t;
typedef char *caddr_t;
typedef unsigned char u_char;
typedef unsigned short u_short, ushort;
typedef unsigned u_int, uint;
typedef unsigned long u_long, ulong;
typedef long long quad_t;
typedef unsigned long long u_quad_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/cpuset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_

#define CPU_SETSIZE 1024

COSMOPOLITAN_C_START_

typedef struct cpu_set_t {
  uint64_t __bits[16];
} cpu_set_t;

int sched_getcpu(void) libcesque;
int sched_getaffinity(int, size_t, cpu_set_t *) libcesque;
int sched_setaffinity(int, size_t, const cpu_set_t *) libcesque;

#define CPU_SET(i, s)   ((s)->__bits[(i) / 64] |= 1ull << ((i) % 64))
#define CPU_CLR(i, s)   ((s)->__bits[(i) / 64] &= ~(1ull << ((i) % 64)))
#define CPU_ISSET(i, s) (!!((s)->__bits[(i) / 64] & (1ull << ((i) % 64))))

void CPU_ZERO(cpu_set_t *) libcesque;
#define CPU_ZERO(x) CPU_ZERO(x)

int CPU_COUNT(cpu_set_t *) libcesque;
#define CPU_COUNT(x) CPU_COUNT(x)

int CPU_EQUAL(cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_EQUAL(x, y) CPU_EQUAL(x, y)

void CPU_AND(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_AND(x, y, z) CPU_AND(x, y, z)

void CPU_OR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_OR(x, y, z) CPU_OR(x, y, z)

void CPU_XOR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_XOR(x, y, z) CPU_XOR(x, y, z)

int CPU_COUNT_S(size_t, const cpu_set_t *) libcesque;
#define CPU_COUNT_S(x, y) CPU_COUNT_S(x, y)

#define CPU_ALLOC_SIZE(n) \
  ((((n) + (8 * sizeof(long) - 1)) & -(8 * sizeof(long))) / sizeof(long))

#define CPU_ALLOC(n)                  ((cpu_set_t *)calloc(1, CPU_ALLOC_SIZE(n)))
#define CPU_FREE(set)                 free(set)
#define CPU_ZERO_S(size, set)         memset(set, 0, size)
#define CPU_EQUAL_S(size, set1, set2) (!memcmp(set1, set2, size))
#define _CPU_S(i, size, set, op)                                              \
  ((i) / 8U >= (size) ? 0                                                     \
                      : (((unsigned long *)(set))[(i) / 8 / sizeof(long)] op( \
                            1UL << ((i) % (8 * sizeof(long))))))
#define CPU_SET_S(i, size, set)   _CPU_S(i, size, set, |=)
#define CPU_CLR_S(i, size, set)   _CPU_S(i, size, set, &= ~)
#define CPU_ISSET_S(i, size, set) _CPU_S(i, size, set, &)

typedef cpu_set_t cpuset_t; /* for freebsd compatibility */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/dirent.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_
COSMOPOLITAN_C_START_

struct dirent {      /* linux getdents64 abi */
  uint64_t d_ino;    /* inode number */
  int64_t d_off;     /* implementation-dependent location number */
  uint16_t d_reclen; /* byte length of this whole struct and string */
  uint8_t d_type;    /* DT_REG, DT_DIR, DT_UNKNOWN, DT_BLK, etc. */
  char d_name[256];  /* NUL-terminated basename */
};

struct dirstream;
typedef struct dirstream DIR;

DIR *fdopendir(int) libcesque __wur;
DIR *opendir(const char *) libcesque __wur;
int closedir(DIR *) libcesque;
int dirfd(DIR *) libcesque;
long telldir(DIR *) libcesque;
struct dirent *readdir(DIR *) libcesque;
int readdir_r(DIR *, struct dirent *, struct dirent **) libcesque;
void rewinddir(DIR *) libcesque;
void seekdir(DIR *, long) libcesque;
int alphasort(const struct dirent **, const struct dirent **) libcesque;
int versionsort(const struct dirent **, const struct dirent **) libcesque;
int scandir(const char *, struct dirent ***, int (*)(const struct dirent *),
            int (*)(const struct dirent **, const struct dirent **)) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/flock.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FLOCK_H_
COSMOPOLITAN_C_START_

struct flock {      /* cosmopolitan abi */
  int16_t l_type;   /* F_RDLCK, F_WRLCK, F_UNLCK */
  int16_t l_whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
  int64_t l_start;  /* starting offset */
  int64_t l_len;    /* no. bytes (0 means to end of file) */
  int32_t l_pid;    /* lock owner */
  int32_t l_sysid;  /* remote system id or zero for local (freebsd) */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/framebuffercolormap.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERCOLORMAP_H_

struct FrameBufferColorMap {
  uint32_t start;
  uint32_t len;
  uint16_t *red;
  uint16_t *green;
  uint16_t *blue;
  uint16_t *transp;
};



/*!BEGIN libc/calls/struct/framebufferfixedscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERFIXEDSCREENINFO_H_

struct FrameBufferFixedScreenInfo {
  char id[16];
  uint64_t smem_start;
  uint32_t smem_len;
  uint32_t type;
  uint32_t type_aux;
  uint32_t visual;
  uint16_t xpanstep;
  uint16_t ypanstep;
  uint16_t ywrapstep;
  uint32_t line_length;
  uint64_t mmio_start;
  uint32_t mmio_len;
  uint32_t accel;
  uint16_t capabilities;
  uint16_t reserved[2];
};



/*!BEGIN libc/calls/struct/framebuffervirtualscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERVIRTUALSCREENINFO_H_

struct FrameBufferBitField {
  uint32_t offset;
  uint32_t length;
  uint32_t msb_right;
};

struct FrameBufferVirtualScreenInfo {
  uint32_t xres;
  uint32_t yres;
  uint32_t xres_virtual;
  uint32_t yres_virtual;
  uint32_t xoffset;
  uint32_t yoffset;
  uint32_t bits_per_pixel;
  uint32_t grayscale;
  struct FrameBufferBitField red;
  struct FrameBufferBitField green;
  struct FrameBufferBitField blue;
  struct FrameBufferBitField transp;
  uint32_t nonstd;
  uint32_t activate;
  uint32_t height;
  uint32_t width;
  uint32_t accel_flags;
  uint32_t pixclock;
  uint32_t left_margin;
  uint32_t right_margin;
  uint32_t upper_margin;
  uint32_t lower_margin;
  uint32_t hsync_len;
  uint32_t vsync_len;
  uint32_t sync;
  uint32_t vmode;
  uint32_t rotate;
  uint32_t colorspace;
  uint32_t reserved[4];
};



/*!BEGIN libc/calls/struct/fsid.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FSID_H_
COSMOPOLITAN_C_START_

typedef struct fsid_t {
  uint32_t __val[2];
} fsid_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/iovec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct iovec {
  void *iov_base;
  size_t iov_len;
};

ssize_t preadv(int, struct iovec *, int, int64_t) libcesque;
ssize_t pwritev(int, const struct iovec *, int, int64_t) libcesque;
ssize_t readv(int, const struct iovec *, int) libcesque;
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t) libcesque;
ssize_t writev(int, const struct iovec *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/itimerval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_H_


/*!BEGIN libc/calls/struct/timeval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_


/*!BEGIN libc/calls/struct/timespec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct timespec {
  int64_t tv_sec;
  int64_t tv_nsec; /* nanoseconds */
};

int clock_getres(int, struct timespec *) libcesque;
int clock_gettime(int, struct timespec *) libcesque;
int clock_settime(int, const struct timespec *) libcesque;
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int futimens(int, const struct timespec[2]) libcesque;
int nanosleep(const struct timespec *, struct timespec *) libcesque;
int utimensat(int, const char *, const struct timespec[2], int) libcesque;
int timespec_getres(struct timespec *, int) libcesque;
int timespec_get(struct timespec *, int) libcesque;

#ifdef _COSMO_SOURCE
int sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int cosmo_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
#define timespec_zero ((struct timespec){0})
#define timespec_max  ((struct timespec){0x7fffffffffffffff, 999999999})
libcesque int timespec_cmp(struct timespec, struct timespec) pureconst;
libcesque int64_t timespec_tomicros(struct timespec) pureconst;
libcesque int64_t timespec_tomillis(struct timespec) pureconst;
libcesque int64_t timespec_tonanos(struct timespec) pureconst;
libcesque struct timespec timespec_add(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_fromnanos(int64_t) pureconst;
libcesque struct timespec timespec_frommicros(int64_t) pureconst;
libcesque struct timespec timespec_frommillis(int64_t) pureconst;
libcesque struct timespec timespec_real(void) libcesque;
libcesque struct timespec timespec_mono(void) libcesque;
libcesque struct timespec timespec_sleep(struct timespec) libcesque;
libcesque int timespec_sleep_until(struct timespec) libcesque;
libcesque struct timespec timespec_sub(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_subz(struct timespec,
                                        struct timespec) pureconst;
int sys_futex(int *, int, int, const struct timespec *, int *);
static inline struct timespec timespec_fromseconds(int64_t __x) {
  return (struct timespec){__x};
}
static inline int timespec_iszero(struct timespec __ts) {
  return !(__ts.tv_sec | __ts.tv_nsec);
}
static inline int timespec_isvalid(struct timespec __ts) {
  return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
}
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

struct timeval {
  int64_t tv_sec;
  int64_t tv_usec; /* microseconds */
};

int futimes(int, const struct timeval[2]);
int futimesat(int, const char *, const struct timeval[2]);
int gettimeofday(struct timeval *, struct timezone *);
int settimeofday(const struct timeval *, const struct timezone *);
int lutimes(const char *, const struct timeval[2]);
int utimes(const char *, const struct timeval[2]);

#ifdef _COSMO_SOURCE
/* cosmopolitan libc's non-posix timevals library
   removed by default due to emacs codebase clash */
#define timeval_zero ((struct timeval){0})
#define timeval_max  ((struct timeval){0x7fffffffffffffff, 999999})
int timeval_cmp(struct timeval, struct timeval) pureconst;
struct timeval timeval_real(void);
struct timeval timeval_frommicros(int64_t) pureconst;
struct timeval timeval_frommillis(int64_t) pureconst;
struct timeval timeval_add(struct timeval, struct timeval) pureconst;
struct timeval timeval_sub(struct timeval, struct timeval) pureconst;
struct timeval timeval_subz(struct timeval, struct timeval) pureconst;
int64_t timeval_toseconds(struct timeval);
int64_t timeval_tomicros(struct timeval);
int64_t timeval_tomillis(struct timeval);
struct timeval timespec_totimeval(struct timespec) pureconst;
static inline struct timeval timeval_fromseconds(int64_t __x) {
  return (struct timeval){__x};
}
static inline struct timespec timeval_totimespec(struct timeval __tv) {
  return (struct timespec){__tv.tv_sec, __tv.tv_usec * 1000};
}
static inline int timeval_iszero(struct timeval __tv) {
  return !(__tv.tv_sec | __tv.tv_usec);
}
static inline int timeval_isvalid(struct timeval __tv) {
  return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull;
}
#endif /* _COSMO_SOURCE */

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
#define timercmp(s, t, op)                                  \
  ((s)->tv_sec == (t)->tv_sec ? (s)->tv_usec op(t)->tv_usec \
                              : (s)->tv_sec op(t)->tv_sec)
#define timeradd(s, t, a)                                           \
  (void)((a)->tv_sec = (s)->tv_sec + (t)->tv_sec,                   \
         ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
             ((a)->tv_usec -= 1000000, (a)->tv_sec++))
#define timersub(s, t, a)                                    \
  (void)((a)->tv_sec = (s)->tv_sec - (t)->tv_sec,            \
         ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
             ((a)->tv_usec += 1000000, (a)->tv_sec--))
#endif

#ifdef _GNU_SOURCE
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
  ((ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0)
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
  ((tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0)
#endif

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct itimerval {
  struct timeval it_interval; /* {0,0} means singleshot */
  struct timeval it_value;    /* {0,0} means disarm */
};

int getitimer(int, struct itimerval *);
int setitimer(int, const struct itimerval *, struct itimerval *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/metasigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METASIGALTSTACK_H_


/*!BEGIN libc/calls/struct/sigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGALTSTACK_H_
COSMOPOLITAN_C_START_

struct sigaltstack {
  void *ss_sp;
  int ss_flags;
  size_t ss_size;
};

typedef struct sigaltstack stack_t;

int sigaltstack(const struct sigaltstack *, struct sigaltstack *) libcesque;

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct sigaltstack_bsd {
  void *ss_sp;
  uint64_t ss_size;
  int32_t ss_flags;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rlimit.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_
COSMOPOLITAN_C_START_

struct rlimit {
  uint64_t rlim_cur; /* current (soft) limit in bytes */
  uint64_t rlim_max; /* maximum limit in bytes */
};

int getrlimit(int, struct rlimit *) libcesque;
int setrlimit(int, const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rusage.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_
COSMOPOLITAN_C_START_

struct rusage {
  struct timeval ru_utime; /* user CPU time used */
  struct timeval ru_stime; /* system CPU time used */
  int64_t ru_maxrss;       /* maximum resident set size in (kb) */
  int64_t ru_ixrss;        /* shared memory size (integral kb CLK_TCK) */
  int64_t ru_idrss;        /* unshared data size (integral kb CLK_TCK) */
  int64_t ru_isrss;        /* unshared stack size (integral kb CLK_TCK) */
  int64_t ru_minflt;       /* page reclaims */
  int64_t ru_majflt;       /* page faults */
  int64_t ru_nswap;        /* swaps */
  int64_t ru_inblock;      /* block input operations */
  int64_t ru_oublock;      /* block output operations */
  int64_t ru_msgsnd;       /* IPC messages sent */
  int64_t ru_msgrcv;       /* IPC messages received */
  int64_t ru_nsignals;     /* signals received */
  int64_t ru_nvcsw;        /* voluntary context switches */
  int64_t ru_nivcsw;       /* involuntary context switches */
};

int getrusage(int, struct rusage *) libcesque;
int wait3(int *, int, struct rusage *) libcesque;
int wait4(int, int *, int, struct rusage *) libcesque;
void rusage_add(struct rusage *, const struct rusage *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sched_param.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SCHED_PARAM_H_
COSMOPOLITAN_C_START_

struct sched_param {
  int32_t sched_priority;
};

int sched_get_priority_max(int) libcesque;
int sched_get_priority_min(int) libcesque;
int sched_getparam(int, struct sched_param *) libcesque;
int sched_getscheduler(int) libcesque;
int sched_rr_get_interval(int, struct timespec *) libcesque;
int sched_setparam(int, const struct sched_param *) libcesque;
int sched_setscheduler(int, int, const struct sched_param *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigaction.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_


/*!BEGIN libc/calls/struct/siginfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_H_


/*!BEGIN libc/calls/struct/sigval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_
COSMOPOLITAN_C_START_

union sigval {
  int32_t sival_int;
  void *sival_ptr;
};

int sigqueue(int, int, const union sigval);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct siginfo {
  int32_t si_signo;
  int32_t si_errno;
  int32_t si_code; /* {SICODE,SEGV,ILL,FPE,POLL}_xxx */
  union {
    struct {
      union {
        struct {
          /* signals sent by kill() and sigqueue() set these */
          int32_t si_pid;
          uint32_t si_uid;
        };
        struct {
          /* SIGALRM sets these */
          int32_t si_timerid;
          int32_t si_overrun;
        };
      };
      union {
        union sigval si_value; /* provided by third arg of sigqueue(2) */
        struct {
          int32_t si_status;
          int64_t si_utime;
          int64_t si_stime;
        };
      };
    };
    struct {
      void *si_addr;
      int16_t si_addr_lsb;
      union {
        struct {
          void *si_lower;
          void *si_upper;
        };
        uint32_t si_pkey;
      };
    };
    struct {
      int64_t si_band; /* SIGPOLL */
      int32_t si_fd;
    };
    struct {
      void *si_call_addr;
      int32_t si_syscall;
      uint32_t si_arch;
    };
    char __ignoreme[128 - 2 * sizeof(int32_t) - sizeof(int64_t)];
  };
};

typedef struct siginfo siginfo_t;

#ifdef _COSMO_SOURCE
void __minicrash(int, siginfo_t *, void *) libcesque;
char __is_stack_overflow(siginfo_t *, void *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_
COSMOPOLITAN_C_START_

typedef uint64_t sigset_t;

int sigaddset(sigset_t *, int) paramsnonnull();
int sigdelset(sigset_t *, int) paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull();
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect;
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect;
int sigprocmask(int, const sigset_t *, sigset_t *);
int sigsuspend(const sigset_t *);
int sigpending(sigset_t *);
int pthread_sigmask(int, const sigset_t *, sigset_t *);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef void (*sighandler_t)(int);
typedef void (*sigaction_f)(int, struct siginfo *, void *);

struct sigaction {
  union {
    sighandler_t sa_handler;
    sigaction_f sa_sigaction;
  };
  uint64_t sa_flags;
  void (*sa_restorer)(void);
  sigset_t sa_mask;
};

sighandler_t signal(int, sighandler_t) libcesque;
int sigaction(int, const struct sigaction *, struct sigaction *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_H_
COSMOPOLITAN_C_START_

struct stat {              /* cosmo abi */
  uint64_t st_dev;         /* 0: id of device with file */
  uint64_t st_ino;         /* 8: inode number in disk b-tree */
  uint64_t st_nlink;       /* 16: hard link count */
  uint32_t st_mode;        /* 24: octal file mask thing */
  uint32_t st_uid;         /* 28: user id of owner */
  uint32_t st_gid;         /* group id of owning group */
  uint32_t st_flags;       /* nt/xnu/bsd-only */
  uint64_t st_rdev;        /* id of device if a special file */
  int64_t st_size;         /* bytes in file */
  int64_t st_blksize;      /* preferred chunking for underlying filesystem */
  int64_t st_blocks;       /* number of 512-byte pages allocated to file */
  struct timespec st_atim; /* access time */
  struct timespec st_mtim; /* modified time */
  struct timespec st_ctim; /* complicated time */
  struct timespec st_birthtim;
  uint64_t st_gen; /* xnu/bsd only */
};

int stat(const char *, struct stat *);
int lstat(const char *, struct stat *);
int fstat(int, struct stat *);
int fstatat(int, const char *, struct stat *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.macros.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_MACROS_H_

#define STAT_HAVE_NSEC 1

#define st_atime st_atim.tv_sec
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec

#define st_atime_nsec st_atim.tv_nsec
#define st_mtime_nsec st_mtim.tv_nsec
#define st_ctime_nsec st_ctim.tv_nsec

#define st_atimensec st_atim.tv_nsec
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
#define st_birthtime st_birthtim.tv_sec

#define st_file_attributes st_flags

#define INIT_STRUCT_STAT_PADDING(st) (void)st



/*!BEGIN libc/calls/struct/statfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
COSMOPOLITAN_C_START_

struct statfs {       /* cosmo abi */
  int64_t f_type;     /* type of filesystem */
  int64_t f_bsize;    /* optimal transfer block size */
  int64_t f_blocks;   /* total data blocks in filesystem */
  int64_t f_bfree;    /* free blocks in filesystem */
  int64_t f_bavail;   /* free blocks available to unprivileged users */
  int64_t f_files;    /* total file nodes in filesystem */
  int64_t f_ffree;    /* free file nodes in filesystem */
  fsid_t f_fsid;      /* filesystem id */
  int64_t f_namelen;  /* maximum length of filenames */
  int64_t f_frsize;   /* fragment size */
  int64_t f_flags;    /* mount flags of filesystem 2.6.36 */
  int64_t f_spare[4]; /* end of linux abi */
  uint32_t f_owner;
  char f_fstypename[16];
};

int statfs(const char *, struct statfs *) libcesque;
int fstatfs(int, struct statfs *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/statvfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
COSMOPOLITAN_C_START_

struct statvfs {
  unsigned long f_bsize;   /* Filesystem block size */
  unsigned long f_frsize;  /* Fragment size */
  uint64_t f_blocks;       /* Size of fs in f_frsize units */
  uint64_t f_bfree;        /* Number of free blocks */
  uint64_t f_bavail;       /* Number of free blocks for unprivileged users */
  uint64_t f_files;        /* Number of inodes */
  uint64_t f_ffree;        /* Number of free inodes */
  uint64_t f_favail;       /* Number of free inodes for unprivileged users */
  unsigned long f_fsid;    /* Filesystem ID */
  unsigned long f_flag;    /* Mount flags */
  unsigned long f_namemax; /* Maximum filename length */
};

int statvfs(const char *, struct statvfs *);
int fstatvfs(int, struct statvfs *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sysinfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_
COSMOPOLITAN_C_START_

struct sysinfo {
  int64_t uptime;     /* seconds since boot */
  uint64_t loads[3];  /* 1-5-15 min active process averages */
  uint64_t totalram;  /* system physical memory */
  uint64_t freeram;   /* amount of ram currently going to waste */
  uint64_t sharedram; /* bytes w/ pages mapped into multiple progs */
  uint64_t bufferram; /* lingering disk pages; see fadvise */
  uint64_t totalswap; /* size of emergency memory */
  uint64_t freeswap;  /* hopefully equal to totalswap */
  uint16_t procs;     /* number of processes */
  int16_t __ignore1;  /* padding */
  int32_t __ignore2;  /* padding */
  uint64_t totalhigh; /* wut */
  uint64_t freehigh;  /* wut */
  uint32_t mem_unit;  /* ram stuff above is multiples of this */
};

int sysinfo(struct sysinfo *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TERMIOS_H_

#define NCCS 20

COSMOPOLITAN_C_START_

struct termios {      /* cosmo abi */
  uint32_t c_iflag;   /* input modes */
  uint32_t c_oflag;   /* output modes */
  uint32_t c_cflag;   /* control modes */
  uint32_t c_lflag;   /* local modes */
  uint8_t c_cc[NCCS]; /* code mappings */
  uint32_t _c_ispeed; /* use cfgetispeed() and cfsetispeed() */
  uint32_t _c_ospeed; /* use cfgetospeed() and cfsetospeed() */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/tms.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_
COSMOPOLITAN_C_START_

struct tms {
  int64_t tms_utime;  /* userspace time */
  int64_t tms_stime;  /* kernelspace time */
  int64_t tms_cutime; /* children userspace time */
  int64_t tms_cstime; /* children kernelspace time */
};

long times(struct tms *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/user_regs_struct.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_USER_REGS_STRUCT_H_
COSMOPOLITAN_C_START_

/**
 * Linux Kernel user registers.
 *
 * @note superset of struct pt_regs
 * @see ptrace() w/ PTRACE_SYSCALL
 */
struct user_regs_struct {
  uint64_t r15;
  uint64_t r14;
  uint64_t r13;
  uint64_t r12;
  uint64_t rbp;
  uint64_t rbx;
  uint64_t r11;
  uint64_t r10;
  uint64_t r9;
  uint64_t r8;
  uint64_t rax;
  uint64_t rcx;
  uint64_t rdx;
  uint64_t rsi;
  uint64_t rdi;
  uint64_t orig_rax;
  uint64_t rip;
  uint64_t cs;
  uint64_t eflags;
  uint64_t rsp;
  uint64_t ss;
  uint64_t fs_base;
  uint64_t gs_base;
  uint64_t ds;
  uint64_t es;
  uint64_t fs;
  uint64_t gs;
};

struct useregs_struct_freebsd {
  int64_t r15;
  int64_t r14;
  int64_t r13;
  int64_t r12;
  int64_t r11;
  int64_t r10;
  int64_t r9;
  int64_t r8;
  int64_t rdi;
  int64_t rsi;
  int64_t rbp;
  int64_t rbx;
  int64_t rdx;
  int64_t rcx;
  int64_t rax;
  uint32_t trapno;
  uint16_t fs;
  uint16_t gs;
  uint32_t err;
  uint16_t es;
  uint16_t ds;
  int64_t rip;
  int64_t cs;
  int64_t rflags;
  int64_t rsp;
  int64_t ss;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/utsname.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UTSNAME_H_

#define SYS_NMLN 150

COSMOPOLITAN_C_START_

struct utsname {             /* cosmo abi */
  char sysname[SYS_NMLN];    /* name of os */
  char nodename[SYS_NMLN];   /* name of network node */
  char release[SYS_NMLN];    /* release level */
  char version[SYS_NMLN];    /* version level */
  char machine[SYS_NMLN];    /* hardware type */
  char domainname[SYS_NMLN]; /* domain name */
};

int uname(struct utsname *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/winsize.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_
COSMOPOLITAN_C_START_

struct winsize {
  uint16_t ws_row;
  uint16_t ws_col;
  uint16_t ws_xpixel;
  uint16_t ws_ypixel;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/cachestat.h */

#define COSMOPOLITAN_LIBC_CALLS_CACHESTAT_H_

COSMOPOLITAN_C_START_

struct cachestat_range {
  uint64_t off;
  uint64_t len;
};

struct cachestat {
  /** Number of cached pages. */
  uint64_t nr_cache;
  /** Number of dirty pages */
  uint64_t nr_dirty;
  /** Number of pages marked for writeback. */
  uint64_t nr_writeback;
  /** Number of pages evicted from the cache. */
  uint64_t nr_evicted;
  /**
   * Number of recently evicted pages.
   * A page is recently evicted if its last eviction was recent enough that its
   * reentry to the cache would indicate that it is actively being used by the
   * system, and that there is memory pressure on the system.
   */
  uint64_t nr_recently_evicted;
};

int cachestat(int, struct cachestat_range *, struct cachestat *, uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/calls.h */

#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_

#define _POSIX_VERSION  200809L
#define _POSIX2_VERSION _POSIX_VERSION
#define _XOPEN_VERSION  700

#define _POSIX_MAPPED_FILES               _POSIX_VERSION
#define _POSIX_FSYNC                      _POSIX_VERSION
#define _POSIX_IPV6                       _POSIX_VERSION
#define _POSIX_THREADS                    _POSIX_VERSION
#define _POSIX_THREAD_PROCESS_SHARED      _POSIX_VERSION
#define _POSIX_THREAD_SAFE_FUNCTIONS      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKADDR      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKSIZE      _POSIX_VERSION
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
#define _POSIX_THREAD_CPUTIME             _POSIX_VERSION
#define _POSIX_TIMEOUTS                   _POSIX_VERSION
#define _POSIX_MONOTONIC_CLOCK            _POSIX_VERSION
#define _POSIX_CPUTIME                    _POSIX_VERSION
#define _POSIX_BARRIERS                   _POSIX_VERSION
#define _POSIX_SPIN_LOCKS                 _POSIX_VERSION
#define _POSIX_READER_WRITER_LOCKS        _POSIX_VERSION
#define _POSIX_SEMAPHORES                 _POSIX_VERSION
#define _POSIX_SHARED_MEMORY_OBJECTS      _POSIX_VERSION
#define _POSIX_MEMLOCK_RANGE              _POSIX_VERSION
#define _POSIX_SPAWN                      _POSIX_VERSION

#define NSIG 64

#define SEEK_SET 0          /* relative to beginning */
#define SEEK_CUR 1          /* relative to current position */
#define SEEK_END 2          /* relative to end */
#define __WALL   0x40000000 /* Wait on all children, regardless of type */
#define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */

#define SIG_ERR ((void (*)(int))(-1))
#define SIG_DFL ((void (*)(int))0)
#define SIG_IGN ((void (*)(int))1)

#define CLOCKS_PER_SEC 1000000L

#define MAP_FAILED ((void *)-1)

#define WTERMSIG(x)     (127 & (x))
#define WCOREDUMP(x)    (128 & (x))
#define WIFEXITED(x)    (!WTERMSIG(x))
#define WEXITSTATUS(x)  ((x) >> 8)
#define WSTOPSIG(x)     ((0xff00 & (x)) >> 8)
#define WIFSTOPPED(x)   __wifstopped(x)
#define WIFSIGNALED(x)  __wifsignaled(x)
#define WIFCONTINUED(x) __wifcontinued(x)
#define W_STOPCODE(x)   ((x) << 8 | 0177)

#ifdef _COSMO_SOURCE
#define clone         __clone
#define commandv      __commandv
#define fileexists    __fileexists
#define ischardev     __ischardev
#define isdirectory   __isdirectory
#define isexecutable  __isexecutable
#define isregularfile __isregularfile
#define issymlink     __issymlink
#define makedirs      __makedirs
#define tmpfd         __tmpfd
#endif

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § system calls                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

typedef int sig_atomic_t;

bool32 isatty(int) libcesque;
char *getcwd(char *, size_t) dontthrow;
char *realpath(const char *, char *) libcesque __wur;
char *ttyname(int) libcesque;
int access(const char *, int) libcesque;
int chdir(const char *) libcesque;
int chmod(const char *, unsigned) libcesque;
int chown(const char *, unsigned, unsigned) libcesque;
int chroot(const char *) libcesque;
int close(int) libcesque;
int close_range(unsigned, unsigned, unsigned) libcesque;
int closefrom(int) libcesque;
int creat(const char *, unsigned) libcesque;
int dup(int) libcesque;
int dup2(int, int) libcesque;
int dup3(int, int, int) libcesque;
int execl(const char *, const char *, ...) nullterminated() libcesque;
int execle(const char *, const char *, ...) nullterminated((1)) libcesque;
int execlp(const char *, const char *, ...) nullterminated() libcesque;
int execv(const char *, char *const[]) libcesque;
int execve(const char *, char *const[], char *const[]) libcesque;
int execvp(const char *, char *const[]) libcesque;
int faccessat(int, const char *, int, int) libcesque;
int fchdir(int) libcesque;
int fchmod(int, unsigned) libcesque;
int fchmodat(int, const char *, unsigned, int) libcesque;
int fchown(int, unsigned, unsigned) libcesque;
int fchownat(int, const char *, unsigned, unsigned, int) libcesque;
int fcntl(int, int, ...) libcesque;
int fdatasync(int) libcesque;
int fexecve(int, char *const[], char *const[]) libcesque;
int flock(int, int) libcesque;
int fork(void) libcesque;
int fsync(int) libcesque;
int ftruncate(int, int64_t) libcesque;
int getdomainname(char *, size_t) libcesque;
int getgroups(int, unsigned[]) libcesque;
int gethostname(char *, size_t) libcesque;
int getloadavg(double *, int) libcesque;
int getpgid(int) libcesque;
int getpgrp(void) libcesque nosideeffect;
int getpid(void) libcesque nosideeffect;
int getppid(void) libcesque;
int getpriority(int, unsigned) libcesque;
int getsid(int) nosideeffect libcesque;
int ioctl(int, unsigned long, ...) libcesque;
int issetugid(void) libcesque;
int kill(int, int) libcesque;
int killpg(int, int) libcesque;
int lchmod(const char *, unsigned) libcesque;
int lchown(const char *, unsigned, unsigned) libcesque;
int link(const char *, const char *) libcesque;
int linkat(int, const char *, int, const char *, int) libcesque;
int mincore(void *, size_t, unsigned char *) libcesque;
int mkdir(const char *, unsigned) libcesque;
int mkdirat(int, const char *, unsigned) libcesque;
int mknod(const char *, unsigned, uint64_t) libcesque;
int nice(int) libcesque;
int open(const char *, int, ...) libcesque;
int openat(int, const char *, int, ...) libcesque;
int pause(void) libcesque;
int pipe(int[hasatleast 2]) libcesque;
int pipe2(int[hasatleast 2], int) libcesque;
int posix_fadvise(int, int64_t, int64_t, int) libcesque;
int posix_madvise(void *, uint64_t, int) libcesque;
int raise(int) libcesque;
int reboot(int) libcesque;
int remove(const char *) libcesque;
int rename(const char *, const char *) libcesque;
int renameat(int, const char *, int, const char *) libcesque;
int rmdir(const char *) libcesque;
int sched_yield(void) libcesque;
int setegid(unsigned) libcesque;
int seteuid(unsigned) libcesque;
int setfsgid(unsigned) libcesque;
int setfsuid(unsigned) libcesque;
int setgid(unsigned) libcesque;
int setgroups(size_t, const unsigned[]) libcesque;
int setpgid(int, int) libcesque;
int setpgrp(void) libcesque;
int setpriority(int, unsigned, int) libcesque;
int setregid(unsigned, unsigned) libcesque;
int setreuid(unsigned, unsigned) libcesque;
int setsid(void) libcesque;
int setuid(unsigned) libcesque;
int shm_open(const char *, int, unsigned) libcesque;
int shm_unlink(const char *) libcesque;
int sigignore(int) libcesque;
int siginterrupt(int, int) libcesque;
int symlink(const char *, const char *) libcesque;
int symlinkat(const char *, int, const char *) libcesque;
int tcgetpgrp(int) libcesque;
int tcsetpgrp(int, int) libcesque;
int truncate(const char *, int64_t) libcesque;
int ttyname_r(int, char *, size_t) libcesque;
int unlink(const char *) libcesque;
int unlinkat(int, const char *, int) libcesque;
int usleep(uint64_t) libcesque;
int vfork(void) libcesque returnstwice;
int wait(int *) libcesque;
int waitpid(int, int *, int) libcesque;
int64_t clock(void) libcesque;
int64_t time(int64_t *) libcesque;
ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned) libcesque;
ssize_t lseek(int, int64_t, int) libcesque;
ssize_t pread(int, void *, size_t, int64_t) libcesque;
ssize_t pwrite(int, const void *, size_t, int64_t) libcesque;
ssize_t read(int, void *, size_t) libcesque;
ssize_t readlink(const char *, char *, size_t) libcesque;
ssize_t readlinkat(int, const char *, char *, size_t) libcesque;
ssize_t write(int, const void *, size_t) libcesque;
unsigned alarm(unsigned) libcesque;
unsigned getegid(void) libcesque nosideeffect;
unsigned geteuid(void) libcesque nosideeffect;
unsigned getgid(void) libcesque nosideeffect;
unsigned getuid(void) libcesque;
unsigned sleep(unsigned) libcesque;
unsigned ualarm(unsigned, unsigned) libcesque;
unsigned umask(unsigned) libcesque;
void sync(void) libcesque;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
int syncfs(int) libcesque;
int prctl(int, ...) libcesque;
int gettid(void) libcesque;
int setresgid(unsigned, unsigned, unsigned) libcesque;
int setresuid(unsigned, unsigned, unsigned) libcesque;
int getresgid(unsigned *, unsigned *, unsigned *) libcesque;
int getresuid(unsigned *, unsigned *, unsigned *) libcesque;
char *get_current_dir_name(void) libcesque __wur;
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned) libcesque;
int memfd_create(const char *, unsigned int) libcesque;
int execvpe(const char *, char *const[], char *const[]) libcesque;
int euidaccess(const char *, int) libcesque;
int eaccess(const char *, int) libcesque;
int madvise(void *, uint64_t, int) libcesque;
int getcpu(unsigned *, unsigned *) libcesque;
#endif

#ifdef _COSMO_SOURCE
bool32 fdexists(int) libcesque;
bool32 fileexists(const char *) libcesque;
bool32 ischardev(int) libcesque;
bool32 isdirectory(const char *) libcesque;
bool32 isexecutable(const char *) libcesque;
bool32 isregularfile(const char *) libcesque;
bool32 issymlink(const char *) libcesque;
char *commandv(const char *, char *, size_t) libcesque;
int __getcwd(char *, size_t) libcesque;
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
int fadvise(int, uint64_t, uint64_t, int) libcesque;
int makedirs(const char *, unsigned) libcesque;
int pivot_root(const char *, const char *) libcesque;
int pledge(const char *, const char *) libcesque;
int seccomp(unsigned, unsigned, void *) libcesque;
int sys_iopl(int) libcesque;
int sys_ioprio_get(int, int) libcesque;
int sys_ioprio_set(int, int, int) libcesque;
int sys_mlock(const void *, size_t) libcesque;
int sys_mlock2(const void *, size_t, int) libcesque;
int sys_mlockall(int) libcesque;
int sys_munlock(const void *, size_t) libcesque;
int sys_munlockall(void) libcesque;
int sys_personality(uint64_t) libcesque;
int sys_ptrace(int, ...) libcesque;
int sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque;
int sysctlbyname(const char *, void *, size_t *, void *, size_t) libcesque;
int sysctlnametomib(const char *, int *, size_t *) libcesque;
int tmpfd(void) libcesque;
int touch(const char *, unsigned) libcesque;
int unveil(const char *, const char *) libcesque;
long ptrace(int, ...) libcesque;
ssize_t copyfd(int, int, size_t) libcesque;
ssize_t readansi(int, char *, size_t) libcesque;
ssize_t tinyprint(int, const char *, ...) libcesque nullterminated();
void shm_path_np(const char *, char[hasatleast 78]) libcesque;
#endif /* _COSMO_SOURCE */

int system(const char *) libcesque;

int __wifstopped(int) libcesque pureconst;
int __wifcontinued(int) libcesque pureconst;
int __wifsignaled(int) libcesque pureconst;

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define lseek64     lseek
#define pread64     pread
#define pwrite64    pwrite
#define truncate64  truncate
#define ftruncate64 ftruncate
#define lockf64     lockf
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ipc.h */

#define COSMOPOLITAN_LIBC_CALLS_IPC_H_

#define IPC_PRIVATE 0
#define IPC_RMID    0
#define IPC_SET     1
#define IPC_STAT    2
#define IPC_INFO    3
#define IPC_CREAT   01000
#define IPC_EXCL    02000
#define IPC_NOWAIT  04000

COSMOPOLITAN_C_START_

int ftok(const char *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/landlock.h */

#define COSMOPOLITAN_LIBC_CALLS_LANDLOCK_H_

#define LANDLOCK_CREATE_RULESET_VERSION 0x0001ul

#define LANDLOCK_ACCESS_FS_EXECUTE     0x0001ul
#define LANDLOCK_ACCESS_FS_WRITE_FILE  0x0002ul
#define LANDLOCK_ACCESS_FS_READ_FILE   0x0004ul
#define LANDLOCK_ACCESS_FS_READ_DIR    0x0008ul
#define LANDLOCK_ACCESS_FS_REMOVE_DIR  0x0010ul
#define LANDLOCK_ACCESS_FS_REMOVE_FILE 0x0020ul
#define LANDLOCK_ACCESS_FS_MAKE_CHAR   0x0040ul
#define LANDLOCK_ACCESS_FS_MAKE_DIR    0x0080ul
#define LANDLOCK_ACCESS_FS_MAKE_REG    0x0100ul
#define LANDLOCK_ACCESS_FS_MAKE_SOCK   0x0200ul
#define LANDLOCK_ACCESS_FS_MAKE_FIFO   0x0400ul
#define LANDLOCK_ACCESS_FS_MAKE_BLOCK  0x0800ul
#define LANDLOCK_ACCESS_FS_MAKE_SYM    0x1000ul

/**
 * Allow renaming or linking file to a different directory.
 *
 * @see https://lore.kernel.org/r/20220329125117.1393824-8-mic@digikod.net
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 2+
 */
#define LANDLOCK_ACCESS_FS_REFER 0x2000ul

/**
 * Control file truncation.
 *
 * @see
 * https://lore.kernel.org/all/20221018182216.301684-1-gnoack3000@gmail.com/
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 3+
 */
#define LANDLOCK_ACCESS_FS_TRUNCATE 0x4000ul

COSMOPOLITAN_C_START_

enum landlock_rule_type {
  LANDLOCK_RULE_PATH_BENEATH = 1,
};

struct landlock_ruleset_attr {
  uint64_t handled_access_fs;
};

struct thatispacked landlock_path_beneath_attr {
  uint64_t allowed_access;
  int32_t parent_fd;
};

int landlock_restrict_self(int, uint32_t);
int landlock_add_rule(int, enum landlock_rule_type, const void *, uint32_t);
int landlock_create_ruleset(const struct landlock_ruleset_attr *, size_t,
                            uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/makedev.h */

#define COSMOPOLITAN_LIBC_CALLS_MAKEDEV_H_

uint64_t makedev(uint32_t, uint32_t) libcesque;
uint32_t major(uint64_t) libcesque;
uint32_t minor(uint64_t) libcesque;

#define major(x)      major(x)
#define minor(x)      minor(x)
#define makedev(x, y) makedev(x, y)



/*!BEGIN libc/calls/mount.h */

#define COSMOPOLITAN_LIBC_CALLS_MOUNT_H_
COSMOPOLITAN_C_START_

int mount(const char *, const char *, const char *, unsigned long,
          const void *);
int unmount(const char *, int);

#ifdef _GNU_SOURCE
int umount(const char *);
int umount2(const char *, int);
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/pledge.h */

#define COSMOPOLITAN_LIBC_CALLS_PLEDGE_H_

#define PLEDGE_PENALTY_KILL_THREAD  0x0000
#define PLEDGE_PENALTY_KILL_PROCESS 0x0001
#define PLEDGE_PENALTY_RETURN_EPERM 0x0002
#define PLEDGE_PENALTY_MASK         0x000f
#define PLEDGE_STDERR_LOGGING       0x0010

COSMOPOLITAN_C_START_

extern int __pledge_mode;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/sigtimedwait.h */

#define COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_H_
COSMOPOLITAN_C_START_

int sigwait(const sigset_t *, int *);
int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *);
int sigwaitinfo(const sigset_t *, siginfo_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_H_
COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § teletypewriter control                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int tcgetattr(int, struct termios *) libcesque;
int tcsetattr(int, int, const struct termios *) libcesque;

int openpty(int *, int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2));
int forkpty(int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2)) __wur;
char *ptsname(int) libcesque;
errno_t ptsname_r(int, char *, size_t) libcesque;

int grantpt(int) libcesque;
int unlockpt(int) libcesque;
int posix_openpt(int) libcesque __wur;

int tcdrain(int) libcesque;
int tcgetsid(int) libcesque;
int tcflow(int, int) libcesque;
int tcflush(int, int) libcesque;
int tcsetsid(int, int) libcesque;
int tcsendbreak(int, int) libcesque;
void cfmakeraw(struct termios *) libcesque;
int cfsetspeed(struct termios *, uint32_t) libcesque;
int cfsetospeed(struct termios *, uint32_t) libcesque;
int cfsetispeed(struct termios *, uint32_t) libcesque;
uint32_t cfgetospeed(const struct termios *) libcesque;
uint32_t cfgetispeed(const struct termios *) libcesque;
int tcsetwinsize(int, const struct winsize *) libcesque;
int tcgetwinsize(int, struct winsize *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ttydefaults.h */

#define COSMOPOLITAN_LIBC_CALLS_TTYDEFAULTS_H_


/*!BEGIN libc/sysv/consts/termios.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TERMIOS_H_
COSMOPOLITAN_C_START_

#define EXTA B19200
#define EXTB B38400

extern const int _POSIX_VDISABLE;
extern const uint32_t BRKINT;
extern const uint32_t BS1;
extern const uint32_t BS2;
extern const uint32_t BSDLY;
extern const uint32_t CLOCAL;
extern const uint32_t CMSPAR;
extern const uint32_t CR1;
extern const uint32_t CR2;
extern const uint32_t CR3;
extern const uint32_t CRDLY;
extern const uint32_t CREAD;
extern const uint32_t CS5;
extern const uint32_t CS6;
extern const uint32_t CS7;
extern const uint32_t CS8;
extern const uint32_t CSIZE;
extern const uint32_t CSTOPB;
extern const uint32_t ECHOCTL;
extern const uint32_t ECHOE;
extern const uint32_t ECHOK;
extern const uint32_t ECHOKE;
extern const uint32_t ECHONL;
extern const uint32_t ECHOPRT;
extern const long EXTPROC;
extern const uint32_t FF1;
extern const uint32_t FF2;
extern const uint32_t FFDLY;
extern const uint32_t FLUSHO;
extern const uint32_t HUPCL;
extern const uint32_t ICANON;
extern const uint32_t ICRNL;
extern const uint32_t IEXTEN;
extern const uint32_t IGNBRK;
extern const uint32_t IGNCR;
extern const uint32_t IGNPAR;
extern const uint32_t IMAXBEL;
extern const uint32_t INLCR;
extern const uint32_t INPCK;
extern const uint32_t ISIG;
extern const uint32_t ISTRIP;
extern const uint32_t IUCLC;
extern const uint32_t IUTF8;
extern const uint32_t IXANY;
extern const uint32_t IXOFF;
extern const uint32_t IXON;
extern const uint32_t NL1;
extern const uint32_t NL2;
extern const uint32_t NL3;
extern const uint32_t NLDLY;
extern const uint32_t NOFLSH;
extern const uint32_t OCRNL;
extern const uint32_t OFDEL;
extern const uint32_t OFILL;
extern const uint32_t OLCUC;
extern const uint32_t ONLCR;
extern const uint32_t ONLRET;
extern const uint32_t ONOCR;
extern const uint32_t OPOST;
extern const uint32_t PARENB;
extern const uint32_t PARMRK;
extern const uint32_t PARODD;
extern const uint32_t PENDIN;
extern const uint32_t TAB1;
extern const uint32_t TAB2;
extern const uint32_t TAB3;
extern const uint32_t TABDLY;
extern const uint64_t TIOCCONS;
extern const uint64_t TIOCGETD;
extern const uint64_t TIOCGWINSZ;
extern const uint64_t TIOCNOTTY;
extern const uint64_t TIOCNXCL;
extern const uint64_t TIOCOUTQ;
extern const uint64_t TIOCSCTTY;
extern const uint64_t TIOCSETD;
extern const uint64_t TIOCSIG;
extern const uint64_t TIOCSPGRP;
extern const uint64_t TIOCSTI;
extern const uint64_t TIOCSWINSZ;
extern const long TOSTOP;
extern const uint8_t VDISCARD;
extern const uint8_t VEOF;
extern const uint8_t VEOL2;
extern const uint8_t VEOL;
extern const uint8_t VERASE;
extern const uint8_t VINTR;
extern const uint8_t VKILL;
extern const uint8_t VLNEXT;
extern const uint8_t VMIN;
extern const uint8_t VQUIT;
extern const uint8_t VREPRINT;
extern const uint8_t VSTART;
extern const uint8_t VSTOP;
extern const uint8_t VSUSP;
extern const uint8_t VSWTC;
extern const uint32_t VT1;
extern const uint32_t VT2;
extern const uint32_t VTDLY;
extern const uint8_t VTIME;
extern const uint8_t VWERASE;
extern const uint32_t XCASE;
extern const uint32_t XTABS;
extern const uint32_t CRTSCTS;

#define BRKINT  0x02
#define ICRNL   0x0100
#define IGNBRK  0x01
#define IGNCR   0x80
#define IGNPAR  0x04
#define IMAXBEL 0x2000
#define INLCR   0x40
#define INPCK   0x10
#define ISTRIP  0x20
#define IXANY   0x0800
#define OPOST   0x01
#define PARMRK  0x08

#define _POSIX_VDISABLE _POSIX_VDISABLE

#define NLDLY   NLDLY
#define NL0     0
#define NL1     NL1
#define NL2     NL2
#define NL3     NL3
#define CRDLY   CRDLY
#define CR0     0
#define CR1     CR1
#define CR2     CR2
#define CR3     CR3
#define TABDLY  TABDLY
#define TAB0    0
#define TAB1    TAB1
#define TAB2    TAB2
#define TAB3    TAB3
#define XTABS   XTABS
#define CRTSCTS CRTSCTS
#define BSDLY   BSDLY
#define BS0     0
#define BS1     BS1
#define BS2     BS2
#define VTDLY   VTDLY
#define VT0     0
#define VT1     VT1
#define VT2     VT2
#define FFDLY   FFDLY
#define FF0     0
#define FF1     FF1
#define FF2     FF2

#define CLOCAL   CLOCAL
#define CREAD    CREAD
#define CS5      CS5
#define CS6      CS6
#define CS7      CS7
#define CS8      CS8
#define CSIZE    CSIZE
#define CSTOPB   CSTOPB
#define ECHO     8
#define ECHOCTL  ECHOCTL
#define ECHOE    ECHOE
#define ECHOK    ECHOK
#define ECHOKE   ECHOKE
#define ECHONL   ECHONL
#define ECHOPRT  ECHOPRT
#define EXTPROC  EXTPROC
#define FLUSHO   FLUSHO
#define HUPCL    HUPCL
#define ICANON   ICANON
#define IEXTEN   IEXTEN
#define ISIG     ISIG
#define IUCLC    IUCLC
#define IUTF8    IUTF8
#define IXOFF    IXOFF
#define IXON     IXON
#define NOFLSH   NOFLSH
#define OCRNL    OCRNL
#define OFDEL    OFDEL
#define OFILL    OFILL
#define OLCUC    OLCUC
#define ONLCR    ONLCR
#define ONLRET   ONLRET
#define ONOCR    ONOCR
#define PARENB   PARENB
#define PARODD   PARODD
#define PENDIN   PENDIN
#define TOSTOP   TOSTOP
#define VDISCARD VDISCARD
#define VEOF     VEOF
#define VEOL     VEOL
#define VEOL2    VEOL2
#define VERASE   VERASE
#define VINTR    VINTR
#define VKILL    VKILL
#define VLNEXT   VLNEXT
#define VMIN     VMIN
#define VQUIT    VQUIT
#define VREPRINT VREPRINT
#define VSTART   VSTART
#define VSTOP    VSTOP
#define VSUSP    VSUSP
#define VSWTC    VSWTC
#define VTIME    VTIME
#define VWERASE  VWERASE
#define XCASE    XCASE

/* terminal ioctls */
#define TIOCGWINSZ TIOCGWINSZ /* get tty dimensions */
#define TIOCSWINSZ TIOCSWINSZ /* set tty dimensions */
#define TIOCCONS   TIOCCONS   /* redirect terminal */
#define TIOCGETD   TIOCGETD   /* get line discipline */
#define TIOCSETD   TIOCSETD   /* set line discipline */
#define TIOCNOTTY  TIOCNOTTY  /* give up terminal */
#define TIOCNXCL   TIOCNXCL   /* disable exclusive mode */
#define TIOCOUTQ   TIOCOUTQ   /* bytes in output buffer */
#define TIOCSCTTY  TIOCSCTTY  /* make controlling terminal */
#define TIOCSIG    TIOCSIG    /* generate pty signal */
#define TIOCSTI    TIOCSTI    /* insert fake tty input */

/* tcsetattr() */
#define TCSANOW   0
#define TCSAFLUSH 2
#define TCSADRAIN 1
extern const unsigned long TCGETS; /* use tcgetattr() */
extern const unsigned long TCSETS; /* use tcsetattr() */

/* tcflush() */
extern const int TCIFLUSH;
extern const int TCOFLUSH;
extern const int TCIOFLUSH;
#define TCIFLUSH  TCIFLUSH
#define TCOFLUSH  TCOFLUSH
#define TCIOFLUSH TCIOFLUSH

/* tcflow() */
#define TCOOFF 0
#define TCOON  1
#define TCIOFF 2
#define TCION  3

COSMOPOLITAN_C_END_

#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS)
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE | ECHOKE | ECHOCTL)
#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
#define TTYDEF_SPEED (B9600)

#define CTRL(x)  ((x) ^ 0100)
#define CEOF     CTRL('D')
#define CERASE   CTRL('?')
#define CINTR    CTRL('C')
#define CKILL    CTRL('U')
#define CQUIT    CTRL('\\')
#define CSUSP    CTRL('Z')
#define CDSUSP   CTRL('Y')
#define CSTART   CTRL('Q')
#define CSTOP    CTRL('S')
#define CLNEXT   CTRL('V')
#define CDISCARD CTRL('O')
#define CWERASE  CTRL('W')
#define CREPRINT CTRL('R')
#define CEOT     CEOF
#define CBRK     CEOL
#define CRPRNT   CREPRINT
#define CFLUSH   CDISCARD
#define CEOL     255
#define CMIN     1
#define CTIME    0



/*!BEGIN libc/calls/ucontext.h */

#define COSMOPOLITAN_LIBC_CALLS_UCONTEXT_H_
COSMOPOLITAN_C_START_

#ifdef __x86_64__

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define REG_R8      0
#define REG_R9      1
#define REG_R10     2
#define REG_R11     3
#define REG_R12     4
#define REG_R13     5
#define REG_R14     6
#define REG_R15     7
#define REG_RDI     8
#define REG_RSI     9
#define REG_RBP     10
#define REG_RBX     11
#define REG_RDX     12
#define REG_RAX     13
#define REG_RCX     14
#define REG_RSP     15
#define REG_RIP     16
#define REG_EFL     17
#define REG_CSGSFS  18
#define REG_ERR     19
#define REG_TRAPNO  20
#define REG_OLDMASK 21
#define REG_CR2     22
#endif

struct XmmRegister {
  uint64_t u64[2];
};

struct FpuStackEntry {
  uint16_t significand[4];
  uint16_t exponent;
  uint16_t padding[3];
};

struct thatispacked FpuState {

  /* 8087 FPU Control Word
      IM: Invalid Operation ───────────────┐
      DM: Denormal Operand ───────────────┐│
      ZM: Zero Divide ───────────────────┐││
      OM: Overflow ─────────────────────┐│││
      UM: Underflow ───────────────────┐││││
      PM: Precision ──────────────────┐│││││
      PC: Precision Control ───────┐  ││││││
       {float,∅,double,long double}│  ││││││
      RC: Rounding Control ──────┐ │  ││││││
       {even, →-∞, →+∞, →0}      │┌┤  ││││││
                                ┌┤││  ││││││
                               d││││rr││││││
                          0b0000001001111111 */
  uint16_t cwd;

  /* 8087 FPU Status Word */
  uint16_t swd;

  uint16_t ftw;
  uint16_t fop;
  uint64_t rip;
  uint64_t rdp;

  /* SSE CONTROL AND STATUS REGISTER
     IE: Invalid Operation Flag ──────────────┐
     DE: Denormal Flag ──────────────────────┐│
     ZE: Divide-by-Zero Flag ───────────────┐││
     OE: Overflow Flag ────────────────────┐│││
     UE: Underflow Flag ──────────────────┐││││
     PE: Precision Flag ─────────────────┐│││││
     DAZ: Denormals Are Zeros ──────────┐││││││
     IM: Invalid Operation Mask ───────┐│││││││
     DM: Denormal Operation Mask ─────┐││││││││
     ZM: Divide-by-Zero Mask ────────┐│││││││││
     OM: Overflow Mask ─────────────┐││││││││││
     UM: Underflow Mask ───────────┐│││││││││││
     PM: Precision Mask ──────────┐││││││││││││
     RC: Rounding Control ───────┐│││││││││││││
       {even, →-∞, →+∞, →0}      ││││││││││││││
     FTZ: Flush To Zero ───────┐ ││││││││││││││
                               │┌┤│││││││││││││
               ┌──────────────┐││││││││││││││││
               │   reserved   │││││││││││││││││
             0b00000000000000000001111110000000 */
  uint32_t mxcsr;
  uint32_t mxcr_mask;

  struct FpuStackEntry st[8];
  struct XmmRegister xmm[16];
  uint32_t __padding[24];
};

typedef long long greg_t;
typedef greg_t gregset_t[23];
typedef struct FpuState *fpregset_t;

#endif /* __x86_64__ */

struct sigcontext {
#ifdef __x86_64__
  union {
    struct {
      uint64_t r8;     /* 40 */
      uint64_t r9;     /* 48 */
      uint64_t r10;    /* 56 */
      uint64_t r11;    /* 64 */
      uint64_t r12;    /* 72 */
      uint64_t r13;    /* 80 */
      uint64_t r14;    /* 88 */
      uint64_t r15;    /* 96 */
      uint64_t rdi;    /* 104 */
      uint64_t rsi;    /* 112 */
      uint64_t rbp;    /* 120 */
      uint64_t rbx;    /* 128 */
      uint64_t rdx;    /* 136 */
      uint64_t rax;    /* 144 */
      uint64_t rcx;    /* 152 */
      uint64_t rsp;    /* 160 */
      uint64_t rip;    /* 168 */
      uint64_t eflags; /* 176 */
      uint16_t cs;
      uint16_t gs;
      uint16_t fs;
      uint16_t __pad0;
      uint64_t err;
      uint64_t trapno;
      uint64_t oldmask;
      uint64_t cr2;
    };
    gregset_t gregs;
  };
  struct FpuState *fpregs; /* zero when no fpu context */
  uint64_t __pad1[8];
#elif defined(__aarch64__)
  uint64_t fault_address;
  uint64_t regs[31];
  uint64_t sp;
  uint64_t pc;
  uint64_t pstate;
  uint8_t __reserved[4096] __attribute__((__aligned__(16)));
#endif /* __x86_64__ */
};

typedef struct sigcontext mcontext_t;

struct ucontext {
  uint64_t uc_flags; /* don't use this */
  struct ucontext *uc_link;
  stack_t uc_stack;
#ifdef __x86_64__
  struct sigcontext uc_mcontext;
  sigset_t uc_sigmask;
  uint64_t __pad[2];
  struct FpuState __fpustate; /* for cosmo on non-linux */
#elif defined(__aarch64__)
  sigset_t uc_sigmask;
  uint8_t __unused[1024 / 8];
  struct sigcontext uc_mcontext;
#endif
} forcealign(16);

typedef struct ucontext ucontext_t;

int getcontext(ucontext_t *) dontthrow;
int setcontext(const ucontext_t *) dontthrow;
int swapcontext(ucontext_t *, const ucontext_t *) dontthrow returnstwice;
void makecontext(ucontext_t *, void *, int, ...) dontthrow dontcallback;
void __sig_restore(const ucontext_t *) wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/weirdtypes.h */

#define COSMOPOLITAN_LIBC_CALLS_WEIRDTYPES_H_

/**
 * @fileoverview Types we'd prefer hadn't been invented.
 */

typedef int64_t blkcnt_t;
typedef uint8_t cc_t;
typedef int64_t clock_t; /* uint64_t on xnu */
typedef uint64_t dev_t;  /* int32_t on xnu */
typedef uint64_t fsblkcnt_t;
typedef int64_t fsfilcnt_t; /* uint32_t on xnu */
typedef uint32_t gid_t;
typedef int32_t id_t; /* int32_t on linux/freebsd/etc. */
typedef uint32_t in_addr_t;
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
typedef uint64_t ino_t;
typedef int32_t key_t;
typedef int64_t loff_t;
typedef uint32_t mode_t; /* uint16_t on xnu */
typedef uint64_t nfds_t;
typedef int64_t off_t;
typedef int32_t pid_t;
typedef int64_t register_t;
typedef uint16_t sa_family_t; /* bsd:uint8_t */
typedef uint32_t socklen_t;
typedef uint32_t speed_t;
typedef uint32_t suseconds_t;
typedef uint64_t useconds_t;   /* uint32_t on xnu */
typedef int64_t syscall_arg_t; /* uint64_t on xnu */
typedef uint32_t tcflag_t;
typedef int64_t time_t;
typedef void *timer_t;
typedef uint32_t uid_t;
typedef uint64_t rlim_t; /* int64_t on bsd */
typedef int32_t clockid_t;

#ifdef __x86_64__
typedef int64_t blksize_t; /* int32_t on xnu */
typedef uint64_t nlink_t;
#elif defined(__aarch64__)
typedef int32_t blksize_t;
typedef uint32_t nlink_t; /* uint16_t on xnu */
#endif

#define TIME_T_MAX __INT64_MAX__
#define TIME_T_MIN (-TIME_T_MAX - 1)

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define F_GETLK64         F_GETLK
#define F_SETLK64         F_SETLK
#define F_SETLKW64        F_SETLKW
#define RLIM64_INFINITY   RLIM_INFINITY
#define RLIM64_SAVED_CUR  RLIM_SAVED_CUR
#define RLIM64_SAVED_MAX  RLIM_SAVED_MAX
#define alphasort64       alphasort
#define blkcnt64_t        blkcnt_t
#define dirent64          dirent
#define flock64           flock
#define fsfilcnt64_t      fsfilcnt_t
#define fstat64           fstat
#define fstatat64         fstatat
#define fstatfs64         fstatfs
#define fstatvfs64        fstatvfs
#define getrlimit64       getrlimit
#define ino64_t           ino_t
#define lockf64           lockf
#define lstat64           lstat
#define mmap64            mmap
#define off64_t           off_t
#define open64            open
#define openat64          openat
#define posix_fadvise64   posix_fadvise
#define posix_fallocate64 posix_fallocate
#define readdir64         readdir
#define readdir64_r       readdir_r
#define rlim64_t          rlim_t
#define rlimit64          rlimit
#define scandir64         scandir
#define sendfile64        sendfile
#define setrlimit64       setrlimit
#define stat64            stat
#define statfs64          statfs
#define statvfs64         statvfs
#define versionsort64     versionsort
#endif



/*!BEGIN libc/elf/def.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DEF_H_

/**
 * @fileoverview Executable and Linkable Format Definitions.
 */

#define EI_NIDENT 16

#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3

#define ELFMAG  "\177ELF"
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define SELFMAG 4

#define EI_CLASS     4
#define ELFCLASSNONE 0
#define ELFCLASS32   1
#define ELFCLASS64   2
#define ELFCLASSNUM  3

#define EI_DATA     5
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define ELFDATANUM  3

#define EI_VERSION 6

#define EI_OSABI            7
#define ELFOSABI_NONE       0
#define ELFOSABI_SYSV       0
#define ELFOSABI_HPUX       1
#define ELFOSABI_NETBSD     2
#define ELFOSABI_LINUX      3
#define ELFOSABI_GNU        3
#define ELFOSABI_SOLARIS    6
#define ELFOSABI_AIX        7
#define ELFOSABI_IRIX       8
#define ELFOSABI_FREEBSD    9
#define ELFOSABI_TRU64      10
#define ELFOSABI_MODESTO    11
#define ELFOSABI_OPENBSD    12
#define ELFOSABI_ARM        97
#define ELFOSABI_STANDALONE 255

#define EI_ABIVERSION 8

#define EI_PAD 9

#define ET_NONE   0
#define ET_REL    1
#define ET_EXEC   2
#define ET_DYN    3
#define ET_CORE   4
#define ET_NUM    5
#define ET_LOOS   0xfe00
#define ET_HIOS   0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff

#define EM_NONE      0
#define EM_M32       1
#define EM_386       3
#define EM_PPC64     21
#define EM_S390      22
#define EM_ARM       40
#define EM_NEXGEN32E 62
#define EM_X86_64    EM_NEXGEN32E
#define EM_IA32E     EM_NEXGEN32E
#define EM_AMD64     EM_NEXGEN32E
#define EM_PDP11     65
#define EM_CRAYNV2   172
#define EM_L10M      180
#define EM_K10M      181
#define EM_AARCH64   183
#define EM_CUDA      190
#define EM_Z80       220
#define EM_RISCV     243
#define EM_BPF       247

/* the ape flag, "lol cat 5" */
#define EF_APE_MODERN      0x101ca75
#define EF_APE_MODERN_MASK 0x1ffffff

#define GRP_COMDAT 1
#define STN_UNDEF  0

#define EV_NONE    0
#define EV_CURRENT 1
#define EV_NUM     2

#define SYMINFO_NONE          0
#define SYMINFO_CURRENT       1
#define SYMINFO_NUM           2
#define SYMINFO_BT_SELF       0xffff
#define SYMINFO_BT_PARENT     0xfffe
#define SYMINFO_BT_LOWRESERVE 0xff00
#define SYMINFO_FLG_DIRECT    0x0001
#define SYMINFO_FLG_PASSTHRU  0x0002
#define SYMINFO_FLG_COPY      0x0004
#define SYMINFO_FLG_LAZYLOAD  0x0008

#define PT_NULL         0
#define PT_LOAD         1
#define PT_DYNAMIC      2
#define PT_INTERP       3
#define PT_NOTE         4
#define PT_SHLIB        5
#define PT_PHDR         6
#define PT_TLS          7
#define PT_NUM          8
#define PT_LOOS         0x60000000
#define PT_GNU_EH_FRAME 0x6474e550
#define PT_GNU_STACK    0x6474e551
#define PT_GNU_RELRO    0x6474e552
#define PT_LOSUNW       0x6ffffffa
#define PT_SUNWBSS      0x6ffffffa
#define PT_SUNWSTACK    0x6ffffffb
#define PT_HISUNW       0x6fffffff
#define PT_HIOS         0x6fffffff
#define PT_LOPROC       0x70000000
#define PT_HIPROC       0x7fffffff

#define PN_XNUM 0xffff

#define PF_X        1
#define PF_W        2
#define PF_R        4
#define PF_MASKOS   0x0ff00000
#define PF_MASKPROC 0xf0000000

#define R_X86_64_NONE            0
#define R_X86_64_64              1
#define R_X86_64_PC32            2
#define R_X86_64_GOT32           3
#define R_X86_64_PLT32           4
#define R_X86_64_COPY            5
#define R_X86_64_GLOB_DAT        6
#define R_X86_64_JUMP_SLOT       7
#define R_X86_64_RELATIVE        8
#define R_X86_64_GOTPCREL        9
#define R_X86_64_32              10
#define R_X86_64_32S             11
#define R_X86_64_16              12
#define R_X86_64_PC16            13
#define R_X86_64_8               14
#define R_X86_64_PC8             15
#define R_X86_64_DTPMOD64        16
#define R_X86_64_DTPOFF64        17
#define R_X86_64_TPOFF64         18
#define R_X86_64_TLSGD           19
#define R_X86_64_TLSLD           20
#define R_X86_64_DTPOFF32        21
#define R_X86_64_GOTTPOFF        22
#define R_X86_64_TPOFF32         23
#define R_X86_64_PC64            24
#define R_X86_64_GOTOFF64        25
#define R_X86_64_GOTPC32         26
#define R_X86_64_GOT64           27
#define R_X86_64_GOTPCREL64      28
#define R_X86_64_GOTPC64         29
#define R_X86_64_GOTPLT64        30
#define R_X86_64_PLTOFF64        31
#define R_X86_64_SIZE32          32
#define R_X86_64_SIZE64          33
#define R_X86_64_GOTPC32_TLSDESC 34
#define R_X86_64_TLSDESC_CALL    35
#define R_X86_64_TLSDESC         36
#define R_X86_64_IRELATIVE       37
#define R_X86_64_RELATIVE64      38
#define R_X86_64_GOTPCRELX       41 /* 6 bytes */
#define R_X86_64_REX_GOTPCRELX   42 /* 7 bytes */
#define R_X86_64_NUM             43

#define R_AARCH64_NONE   0
#define R_AARCH64_ABS64  257
#define R_AARCH64_ABS32  258
#define R_AARCH64_ABS16  259
#define R_AARCH64_PREL64 260
#define R_AARCH64_PREL32 261
#define R_AARCH64_PREL16 262

#define R_PPC_NONE   0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR24 2
#define R_PPC_ADDR16 3
#define R_PPC_REL32  26

#define R_PPC64_NONE   R_PPC_NONE
#define R_PPC64_ADDR32 R_PPC_ADDR32
#define R_PPC64_ADDR24 R_PPC_ADDR24
#define R_PPC64_ADDR16 R_PPC_ADDR16
#define R_PPC64_REL32  R_PPC_REL32

#define R_RISCV_NONE     0
#define R_RISCV_32       1
#define R_RISCV_64       2
#define R_RISCV_RELATIVE 3

#define R_390_NONE 0
#define R_390_8    1
#define R_390_12   2
#define R_390_16   3
#define R_390_32   4
#define R_390_PC32 5

#define STB_LOCAL      0
#define STB_GLOBAL     1
#define STB_WEAK       2
#define STB_NUM        3
#define STB_LOOS       10
#define STB_GNU_UNIQUE 10
#define STB_HIOS       12
#define STB_LOPROC     13
#define STB_HIPROC     15

#define STT_NOTYPE    0
#define STT_OBJECT    1
#define STT_FUNC      2
#define STT_SECTION   3
#define STT_FILE      4
#define STT_COMMON    5
#define STT_TLS       6
#define STT_NUM       7
#define STT_LOOS      10
#define STT_GNU_IFUNC 10
#define STT_HIOS      12
#define STT_LOPROC    13
#define STT_HIPROC    15

#define STV_DEFAULT   0
#define STV_INTERNAL  1
#define STV_HIDDEN    2
#define STV_PROTECTED 3

#define SHN_UNDEF     0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC    0xff00
#define SHN_BEFORE    0xff00
#define SHN_AFTER     0xff01
#define SHN_HIPROC    0xff1f
#define SHN_LOOS      0xff20
#define SHN_HIOS      0xff3f
#define SHN_ABS       0xfff1
#define SHN_COMMON    0xfff2
#define SHN_XINDEX    0xffff
#define SHN_HIRESERVE 0xffff

#define SHF_WRITE            (1 << 0)
#define SHF_ALLOC            (1 << 1)
#define SHF_EXECINSTR        (1 << 2)
#define SHF_MERGE            (1 << 4)
#define SHF_STRINGS          (1 << 5)
#define SHF_INFO_LINK        (1 << 6)
#define SHF_LINK_ORDER       (1 << 7)
#define SHF_OS_NONCONFORMING (1 << 8)
#define SHF_GROUP            (1 << 9)
#define SHF_TLS              (1 << 10)
#define SHF_COMPRESSED       (1 << 11)
#define SHF_MASKOS           0x0ff00000
#define SHF_MASKPROC         0xf0000000
#define SHF_ORDERED          (1 << 30)
#define SHF_EXCLUDE          (1U << 31)

#define ELFCOMPRESS_ZLIB   1
#define ELFCOMPRESS_LOOS   0x60000000
#define ELFCOMPRESS_HIOS   0x6fffffff
#define ELFCOMPRESS_LOPROC 0x70000000
#define ELFCOMPRESS_HIPROC 0x7fffffff

#define SHT_NULL           0
#define SHT_PROGBITS       1
#define SHT_SYMTAB         2
#define SHT_STRTAB         3
#define SHT_RELA           4
#define SHT_HASH           5
#define SHT_DYNAMIC        6
#define SHT_NOTE           7
#define SHT_NOBITS         8
#define SHT_REL            9
#define SHT_SHLIB          10
#define SHT_DYNSYM         11
#define SHT_INIT_ARRAY     14
#define SHT_FINI_ARRAY     15
#define SHT_PREINIT_ARRAY  16
#define SHT_GROUP          17
#define SHT_SYMTAB_SHNDX   18
#define SHT_NUM            19
#define SHT_LOOS           0x60000000
#define SHT_GNU_ATTRIBUTES 0x6ffffff5
#define SHT_GNU_HASH       0x6ffffff6
#define SHT_GNU_LIBLIST    0x6ffffff7
#define SHT_CHECKSUM       0x6ffffff8
#define SHT_LOSUNW         0x6ffffffa
#define SHT_SUNW_move      0x6ffffffa
#define SHT_SUNW_COMDAT    0x6ffffffb
#define SHT_SUNW_syminfo   0x6ffffffc
#define SHT_GNU_verdef     0x6ffffffd
#define SHT_GNU_verneed    0x6ffffffe
#define SHT_GNU_versym     0x6fffffff
#define SHT_HISUNW         0x6fffffff
#define SHT_HIOS           0x6fffffff
#define SHT_LOPROC         0x70000000
#define SHT_HIPROC         0x7fffffff
#define SHT_LOUSER         0x80000000
#define SHT_HIUSER         0x8fffffff

#define DT_NULL               0
#define DT_NEEDED             1
#define DT_PLTRELSZ           2
#define DT_PLTGOT             3
#define DT_HASH               4
#define DT_STRTAB             5
#define DT_SYMTAB             6
#define DT_RELA               7
#define DT_RELASZ             8
#define DT_RELAENT            9
#define DT_STRSZ              10
#define DT_SYMENT             11
#define DT_INIT               12
#define DT_FINI               13
#define DT_SONAME             14
#define DT_RPATH              15
#define DT_SYMBOLIC           16
#define DT_REL                17
#define DT_RELSZ              18
#define DT_RELENT             19
#define DT_PLTREL             20
#define DT_DEBUG              21
#define DT_TEXTREL            22
#define DT_JMPREL             23
#define DT_BIND_NOW           24
#define DT_INIT_ARRAY         25
#define DT_FINI_ARRAY         26
#define DT_INIT_ARRAYSZ       27
#define DT_FINI_ARRAYSZ       28
#define DT_RUNPATH            29
#define DT_FLAGS              30
#define DT_ENCODING           32
#define DT_PREINIT_ARRAY      32
#define DT_PREINIT_ARRAYSZ    33
#define DT_SYMTAB_SHNDX       34
#define DT_NUM                35
#define DT_LOOS               0x6000000d
#define DT_HIOS               0x6ffff000
#define DT_LOPROC             0x70000000
#define DT_HIPROC             0x7fffffff
#define DT_VALRNGLO           0x6ffffd00
#define DT_GNU_PRELINKED      0x6ffffdf5
#define DT_GNU_CONFLICTSZ     0x6ffffdf6
#define DT_GNU_LIBLISTSZ      0x6ffffdf7
#define DT_CHECKSUM           0x6ffffdf8
#define DT_PLTPADSZ           0x6ffffdf9
#define DT_MOVEENT            0x6ffffdfa
#define DT_MOVESZ             0x6ffffdfb
#define DT_FEATURE_1          0x6ffffdfc
#define DT_POSFLAG_1          0x6ffffdfd
#define DT_SYMINSZ            0x6ffffdfe
#define DT_SYMINENT           0x6ffffdff
#define DT_VALRNGHI           0x6ffffdff
#define DT_VALTAGIDX(tag)     (DT_VALRNGHI - (tag))
#define DT_VALNUM             12
#define DT_ADDRRNGLO          0x6ffffe00
#define DT_GNU_HASH           0x6ffffef5
#define DT_TLSDESC_PLT        0x6ffffef6
#define DT_TLSDESC_GOT        0x6ffffef7
#define DT_GNU_CONFLICT       0x6ffffef8
#define DT_GNU_LIBLIST        0x6ffffef9
#define DT_CONFIG             0x6ffffefa
#define DT_DEPAUDIT           0x6ffffefb
#define DT_AUDIT              0x6ffffefc
#define DT_PLTPAD             0x6ffffefd
#define DT_MOVETAB            0x6ffffefe
#define DT_SYMINFO            0x6ffffeff
#define DT_ADDRRNGHI          0x6ffffeff
#define DT_ADDRTAGIDX(tag)    (DT_ADDRRNGHI - (tag))
#define DT_ADDRNUM            11
#define DT_VERSYM             0x6ffffff0
#define DT_RELACOUNT          0x6ffffff9
#define DT_RELCOUNT           0x6ffffffa
#define DT_FLAGS_1            0x6ffffffb
#define DT_VERDEF             0x6ffffffc
#define DT_VERDEFNUM          0x6ffffffd
#define DT_VERNEED            0x6ffffffe
#define DT_VERNEEDNUM         0x6fffffff
#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag))
#define DT_VERSIONTAGNUM      16
#define DT_AUXILIARY          0x7ffffffd
#define DT_FILTER             0x7fffffff
#define DT_EXTRATAGIDX(tag)   ((Elf32_Word) - ((Elf32_Sword)(tag) << 1 >> 1) - 1)
#define DT_EXTRANUM           3

#define VER_NEED_NONE    0
#define VER_NEED_CURRENT 1
#define VER_NEED_NUM     2
#define VER_FLG_WEAK     0x2

#define ELF_NOTE_SOLARIS       "SUNW Solaris"
#define ELF_NOTE_GNU           "GNU"
#define ELF_NOTE_PAGESIZE_HINT 1
#define ELF_NOTE_ABI           NT_GNU_ABI_TAG
#define ELF_NOTE_OS_LINUX      0
#define ELF_NOTE_OS_GNU        1
#define ELF_NOTE_OS_SOLARIS2   2
#define ELF_NOTE_OS_FREEBSD    3

#define NT_GNU_ABI_TAG      1
#define NT_GNU_BUILD_ID     3
#define NT_GNU_GOLD_VERSION 4

#define EF_CPU32 0x00810000

#define DF_ORIGIN       0x00000001
#define DF_SYMBOLIC     0x00000002
#define DF_TEXTREL      0x00000004
#define DF_BIND_NOW     0x00000008
#define DF_STATIC_TLS   0x00000010
#define DF_1_NOW        0x00000001
#define DF_1_GLOBAL     0x00000002
#define DF_1_GROUP      0x00000004
#define DF_1_NODELETE   0x00000008
#define DF_1_LOADFLTR   0x00000010
#define DF_1_INITFIRST  0x00000020
#define DF_1_NOOPEN     0x00000040
#define DF_1_ORIGIN     0x00000080
#define DF_1_DIRECT     0x00000100
#define DF_1_TRANS      0x00000200
#define DF_1_INTERPOSE  0x00000400
#define DF_1_NODEFLIB   0x00000800
#define DF_1_NODUMP     0x00001000
#define DF_1_CONFALT    0x00002000
#define DF_1_ENDFILTEE  0x00004000
#define DF_1_DISPRELDNE 0x00008000
#define DF_1_DISPRELPND 0x00010000
#define DF_1_NODIRECT   0x00020000
#define DF_1_IGNMULDEF  0x00040000
#define DF_1_NOKSYMS    0x00080000
#define DF_1_NOHDR      0x00100000
#define DF_1_EDITED     0x00200000
#define DF_1_NORELOC    0x00400000
#define DF_1_SYMINTPOSE 0x00800000
#define DF_1_GLOBAUDIT  0x01000000
#define DF_1_SINGLETON  0x02000000
#define DF_1_STUB       0x04000000
#define DF_1_PIE        0x08000000
#define DTF_1_PARINIT   0x00000001
#define DTF_1_CONFEXP   0x00000002
#define DF_P1_LAZYLOAD  0x00000001
#define DF_P1_GROUPPERM 0x00000002

#define ELF64_ST_BIND(val)        (((unsigned char)(val)) >> 4)
#define ELF64_ST_TYPE(val)        ((val)&0xf)
#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf))
#define ELF64_ST_VISIBILITY(o)    ((o)&0x03)

#define ELF64_R_SYM(i)          ((i) >> 32)
#define ELF64_R_TYPE(i)         ((i)&0xffffffff)
#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type))

#define ELF64_M_SYM(info)       ((info) >> 8)
#define ELF64_M_SIZE(info)      ((unsigned char)(info))
#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))

#define NT_PRSTATUS         1
#define NT_PRFPREG          2
#define NT_FPREGSET         2
#define NT_PRPSINFO         3
#define NT_PRXREG           4
#define NT_TASKSTRUCT       4
#define NT_PLATFORM         5
#define NT_AUXV             6
#define NT_GWINDOWS         7
#define NT_ASRS             8
#define NT_PSTATUS          10
#define NT_PSINFO           13
#define NT_PRCRED           14
#define NT_UTSNAME          15
#define NT_LWPSTATUS        16
#define NT_LWPSINFO         17
#define NT_PRFPXREG         20
#define NT_SIGINFO          0x53494749
#define NT_FILE             0x46494c45
#define NT_PRXFPREG         0x46e62b7f
#define NT_PPC_VMX          0x100
#define NT_PPC_SPE          0x101
#define NT_PPC_VSX          0x102
#define NT_PPC_TAR          0x103
#define NT_PPC_PPR          0x104
#define NT_PPC_DSCR         0x105
#define NT_PPC_EBB          0x106
#define NT_PPC_PMU          0x107
#define NT_PPC_TM_CGPR      0x108
#define NT_PPC_TM_CFPR      0x109
#define NT_PPC_TM_CVMX      0x10a
#define NT_PPC_TM_CVSX      0x10b
#define NT_PPC_TM_SPR       0x10c
#define NT_PPC_TM_CTAR      0x10d
#define NT_PPC_TM_CPPR      0x10e
#define NT_PPC_TM_CDSCR     0x10f
#define NT_X86_XSTATE       0x202
#define NT_S390_HIGH_GPRS   0x300
#define NT_S390_TIMER       0x301
#define NT_S390_TODCMP      0x302
#define NT_S390_TODPREG     0x303
#define NT_S390_CTRS        0x304
#define NT_S390_PREFIX      0x305
#define NT_S390_LAST_BREAK  0x306
#define NT_S390_SYSTEM_CALL 0x307
#define NT_S390_TDB         0x308
#define NT_S390_VXRS_LOW    0x309
#define NT_S390_VXRS_HIGH   0x30a
#define NT_S390_GS_CB       0x30b
#define NT_S390_GS_BC       0x30c
#define NT_S390_RI_CB       0x30d
#define NT_ARM_VFP          0x400
#define NT_ARM_TLS          0x401
#define NT_ARM_HW_BREAK     0x402
#define NT_ARM_HW_WATCH     0x403
#define NT_ARM_SYSTEM_CALL  0x404
#define NT_ARM_SVE          0x405
#define NT_ARM_PAC_MASK     0x406
#define NT_METAG_CBUF       0x500
#define NT_METAG_RPIPE      0x501
#define NT_METAG_TLS        0x502
#define NT_ARC_V2           0x600
#define NT_VMCOREDD         0x700
#define NT_VERSION          1

#define VER_DEF_NONE      0
#define VER_DEF_CURRENT   1
#define VER_DEF_NUM       2
#define VER_FLG_BASE      0x1
#define VER_FLG_WEAK      0x2
#define VER_NDX_LOCAL     0
#define VER_NDX_GLOBAL    1
#define VER_NDX_LORESERVE 0xff00
#define VER_NDX_ELIMINATE 0xff01

#define LL_NONE           0
#define LL_EXACT_MATCH    (1 << 0)
#define LL_IGNORE_INT_VER (1 << 1)
#define LL_REQUIRE_MINOR  (1 << 2)
#define LL_EXPORTS        (1 << 3)
#define LL_DELAY_LOAD     (1 << 4)
#define LL_DELTA          (1 << 5)

#define R_BPF_NONE   0
#define R_BPF_MAP_FD 1



/*!BEGIN libc/elf/elf.h */

#define COSMOPOLITAN_LIBC_ELF_H_


/*!BEGIN libc/elf/struct/ehdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_EHDR_H_


/*!BEGIN libc/elf/scalar.h */

#define COSMOPOLITAN_LIBC_ELF_SCALAR_H_

#define Elf64_Addr    uint64_t
#define Elf64_Half    uint16_t
#define Elf64_Off     uint64_t
#define Elf64_Section uint16_t
#define Elf64_Sword   int32_t
#define Elf64_Sxword  int64_t
#define Elf64_Versym  Elf64_Half
#define Elf64_Word    uint32_t
#define Elf64_Xword   uint64_t
#define Elf_Symndx    uint32_t


/*
 * ELF header.
 */
typedef struct Elf64_Ehdr {

  /*
   * Leading bytes of ELF header.
   *
   * - `e_ident[0]` is always `127`
   * - `e_ident[1]` is always `'E'`
   * - `e_ident[2]` is always `'L'`
   * - `e_ident[3]` is always `'F'`
   *
   * - `e_ident[EI_CLASS]` is mandatory and should be:
   *
   *   - `ELFCLASSNONE64` if it's an Elf64 image
   *   - `ELFCLASSNONE32` if it's an Elf32 image
   *   - Otherwise we assume it's an Elf64 image
   *
   * - `e_ident[EI_DATA]` is advisory and could be:
   *
   *   - `ELFDATANONE` isn't strictly valid
   *   - `ELFDATA2LSB` for little-endian
   *   - `ELFDATA2MSB` for big-endian
   *
   * - `e_ident[EI_VERSION]` is advisory and should be:
   *
   *   - `EV_NONE` if it's zero or unspecified
   *   - `EV_CURRENT` for current ELF version (which is 1)
   *
   * - `e_ident[EI_OSABI]` is mandatory and could be:
   *
   *   - `ELFOSABI_NONE` is zero
   *   - `ELFOSABI_GNU` is for GNU
   *   - `ELFOSABI_SYSV` used by GNU
   *   - `ELFOSABI_LINUX` doesn't care
   *   - `ELFOSABI_FREEBSD` does care (recommended)
   *   - `ELFOSABI_NETBSD` doesn't care (see `PT_NOTE`)
   *   - `ELFOSABI_OPENBSD` doesn't care (see `PT_NOTE`)
   *
   * - `e_ident[EI_ABIVERSION]` is advisory
   *
   */
  unsigned char e_ident[16];

  /*
   * ELF image type.
   *
   * This field is mandatory and should be one of:
   *
   * - `ET_REL` for `.o` object files
   * - `ET_DYN` for `.so` files and `-pie` executables
   * - `ET_EXEC` for statically-linked executables
   *
   */
  Elf64_Half e_type;

  /*
   * ELF machine type.
   *
   * This field is mandatory and could be one of:
   *
   * - `EM_M32` for Bellmac
   * - `EM_X86_64` for Amd64
   * - `EM_AARCH64` for Arm64
   * - `EM_PPC64` for Raptors
   * - `EM_RISCV` for Berkeley
   * - `EM_S390` for System/360
   *
   */
  Elf64_Half e_machine;

  /*
   * ELF version.
   *
   * This field is advisory and could be:
   *
   * - `EV_NONE` if it's zero or unspecified
   * - `EV_CURRENT` for current ELF version (which is 1)
   *
   * @see `e_ident[EI_VERSION]`
   */
  Elf64_Word e_version;

  /*
   * ELF executable entrypoint.
   *
   * Static executables should use this field to store the virtual
   * address of the _start() function. This field may be zero, for
   * unspecified.
   */
  Elf64_Addr e_entry;

  /*
   * `Elf64_Phdr` file offset.
   *
   * This field is mandatory. Object files should set it to zero.
   */
  Elf64_Off e_phoff;

  /*
   * `Elf64_Shdr` file offset.
   *
   * This field is advisory.
   */
  Elf64_Off e_shoff;

  /*
   * ELF flags.
   *
   * This field is advisory.
   */
  Elf64_Word e_flags;

  /*
   * `Elf64_Ehdr` size.
   *
   * This field is advisory and should be 64.
   */
  Elf64_Half e_ehsize;

  /*
   * `Elf64_Phdr` element size.
   *
   * This field *is* cared about and should be set to 56. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_phentsize;

  /*
   * `Elf64_Phdr` array count.
   */
  Elf64_Half e_phnum;

  /*
   * `Elf64_Shdr` element size.
   *
   * This field is advisory and should be set to 64. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_shentsize;

  /*
   * `Elf64_Shdr` count.
   *
   * This field is advisory.
   */
  Elf64_Half e_shnum;

  /*
   * Section header index of section name string table.
   */
  Elf64_Half e_shstrndx;

} Elf64_Ehdr;



/*!BEGIN libc/elf/struct/phdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_PHDR_H_

typedef struct Elf64_Phdr {
  Elf64_Word p_type;
  Elf64_Word p_flags;
  Elf64_Off p_offset;
  Elf64_Addr p_vaddr;
  Elf64_Addr p_paddr;
  Elf64_Xword p_filesz;
  Elf64_Xword p_memsz;
  Elf64_Xword p_align;
} Elf64_Phdr;



/*!BEGIN libc/elf/struct/shdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SHDR_H_

/**
 * Section header.
 * @see https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html
 */
typedef struct Elf64_Shdr {

  Elf64_Word sh_name;

  Elf64_Word sh_type; /* SHT_{PROGBITS,NOBITS,STRTAB,SYMTAB,RELA,...} */

  Elf64_Xword sh_flags; /* SHF_{WRITE,ALLOC,EXECINSTR,TLS,MERGE,STRINGS,,...} */

  Elf64_Addr sh_addr;

  Elf64_Off sh_offset;

  Elf64_Xword sh_size;

  /*
   * Index of linked section header.
   *
   * If `sh_type` is `SHT_RELA` then `sh_link` holds the section header
   * index of the associated symbol table.
   *
   * If `sh_type` is `SHT_SYMTAB` then `sh_link` holds the section
   * header index of the associated string table.
   */
  Elf64_Word sh_link;

  /*
   * If `sh_type` is `SHT_RELA` then `sh_info` contains the index of the
   * section to which relocations apply.
   *
   * If `sh_type` is `SHT_SYMTAB` or `SHT_DYNSYM` then `sh_info`
   * contains an index that's one greater than symbol table index of
   * last `STB_LOCAL` symbol.
   */
  Elf64_Word sh_info;

  Elf64_Xword sh_addralign;

  Elf64_Xword sh_entsize;

} Elf64_Shdr;



/*!BEGIN libc/elf/struct/sym.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYM_H_

typedef struct Elf64_Sym {

  /*
   * Symbol name.
   *
   * This value is a byte offset into the `.strtab` section. If this
   * value is zero, then the symbol has no name.
   */
  Elf64_Word st_name;

  /*
   * Symbol type and binding.
   *
   * This value may be created using:
   *
   *     sym.st_info = ELF64_ST_INFO(bind, type);
   *
   * This value may be read using:
   *
   *     int bind = ELF64_ST_BIND(sym.st_info);
   *     int type = ELF64_ST_TYPE(sym.st_info);
   *
   * Where `bind` is typically:
   *
   * - `STB_LOCAL`
   * - `STB_GLOBAL`
   * - `STB_WEAK`
   *
   * Where `type` is typically:
   *
   * - `STT_NOTYPE`
   * - `STT_OBJECT`
   * - `STT_FUNC`
   * - `STT_SECTION`
   * - `STT_FILE`
   * - `STT_COMMON`
   * - `STT_TLS`
   */
  uint8_t st_info;

  /*
   * Symbol visibility.
   *
   * This value should be accessed using:
   *
   *     int visibility = ELF64_ST_VISIBILITY(sym.st_other);
   *
   * Where `visibility` is typically:
   *
   * - `STV_DEFAULT`
   * - `STV_INTERNAL`
   * - `STV_HIDDEN`
   * - `STV_PROTECTED`
   */
  uint8_t st_other;

  /*
   * Symbol section.
   *
   * If `st_shndx` is within `(SHN_UNDEF,SHN_LORESERVE)` then it holds
   * an index into the section header table.
   *
   * Otherwise `st_shndx` is usually one of the following magic numbers:
   *
   * - `SHN_UNDEF` means symbol is undefined
   * - `SHN_ABS` means symbol is a linker integer
   * - `SHN_COMMON` means symbol is defined traditionally
   */
  Elf64_Section st_shndx;

  /*
   * Symbol value.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is `SHN_COMMON`, then
   * `st_value` holds the required symbol alignment, or ≤ 1 if no
   * alignment is required.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is a section index, then
   * `st_value` holds a byte offset into the section memory.
   *
   * If `e_type` isn't `ET_REL` then `st_value` holds a virtual address.
   */
  Elf64_Addr st_value;

  /* byte length optionally set by .size directive */
  Elf64_Xword st_size;

} Elf64_Sym;

#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § executable linkable format                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
/* clang-format off */

bool32 IsElfSymbolContent(const Elf64_Sym *);
bool32 IsElf64Binary(const Elf64_Ehdr *, size_t);
char *GetElfStringTable(const Elf64_Ehdr *, size_t, const char *);
Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
/* clang-format on */


/*!BEGIN libc/elf/link.h */

#define COSMOPOLITAN_ELF_LINK_H_


/*!BEGIN libc/elf/struct/dyn.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DYN_H_

typedef struct Elf64_Dyn {
  Elf64_Sxword d_tag;
  union {
    Elf64_Xword d_val;
    Elf64_Addr d_ptr;
  } d_un;
} Elf64_Dyn;

COSMOPOLITAN_C_START_

#define ElfW(type) Elf64_##type

struct dl_phdr_info {
  Elf64_Addr dlpi_addr;
  const char *dlpi_name;
  const Elf64_Phdr *dlpi_phdr;
  Elf64_Half dlpi_phnum;
  unsigned long long int dlpi_adds;
  unsigned long long int dlpi_subs;
  size_t dlpi_tls_modid;
  void *dlpi_tls_data;
};

struct link_map {
  Elf64_Addr l_addr;
  char *l_name;
  Elf64_Dyn *l_ld;
  struct link_map *l_next;
  struct link_map *l_prev;
};

struct r_debug {
  int r_version;
  struct link_map *r_map;
  Elf64_Addr r_brk;
  enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state;
  Elf64_Addr r_ldbase;
};

int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/elf/struct/auxv.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_AUXV_H_

typedef struct Elf64_auxv_t {
  uint64_t a_type;
  union {
    uint64_t a_val;
  } a_un;
} Elf64_auxv_t;



/*!BEGIN libc/elf/struct/chdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_CHDR_H_

typedef struct Elf64_Chdr {
  Elf64_Word ch_type;
  Elf64_Word ch_reserved;
  Elf64_Xword ch_size;
  Elf64_Xword ch_addralign;
} Elf64_Chdr;



/*!BEGIN libc/elf/struct/lib.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_LIB_H_

typedef struct Elf64_Lib {
  Elf64_Word l_name;
  Elf64_Word l_time_stamp;
  Elf64_Word l_checksum;
  Elf64_Word l_version;
  Elf64_Word l_flags;
} Elf64_Lib;



/*!BEGIN libc/elf/struct/move.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_MOVE_H_

typedef struct Elf64_Move {
  Elf64_Xword m_value;
  Elf64_Xword m_info;
  Elf64_Xword m_poffset;
  Elf64_Half m_repeat;
  Elf64_Half m_stride;
} Elf64_Move;



/*!BEGIN libc/elf/struct/nhdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_NHDR_H_

typedef struct Elf64_Nhdr {
  Elf64_Word n_namesz;
  Elf64_Word n_descsz;
  Elf64_Word n_type;
} Elf64_Nhdr;



/*!BEGIN libc/elf/struct/rel.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_REL_H_

/*
 * ELF relocation.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_REL`.
 *
 * @see Elf64_Rela
 */
typedef struct Elf64_Rel {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` might be:
   *
   * - `R_X86_64_64`
   * - `R_X86_64_PC32`
   * - `R_X86_64_GOTPCRELX`
   * - `R_AARCH64_ABS64`
   *
   * Each relocation type specifies a mathematical formula that's used
   * to compute the appropriate value for the fixed-up object code. If
   * it needs an addend, then this struct doesn't have one, but it can
   * still be embedded by the compiler in the location to be modified.
   */
  Elf64_Xword r_info;

} Elf64_Rel;



/*!BEGIN libc/elf/struct/rela.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_RELA_H_

/*
 * ELF relocation w/ explicit addend.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_RELA`
 *
 * @see Elf64_Rel
 */
typedef struct Elf64_Rela {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` will likely be:
   *
   * - `R_X86_64_PC32`
   * - `R_X86_64_PLT32`
   * - `R_X86_64_32`
   * - `R_X86_64_64`
   * - `R_X86_64_32S`
   * - `R_X86_64_8`
   * - `R_X86_64_16`
   * - `R_X86_64_DTPOFF32`
   * - `R_X86_64_GOTPCREL`
   * - `R_X86_64_PC16`
   * - `R_X86_64_REX_GOTPCRELX`
   * - `R_X86_64_TPOFF32`
   *
   */
  Elf64_Xword r_info;

  /*
   * Relocation parameter.
   *
   * Each relocation type has its own mathematical formula, which should
   * incorporate this value in its own unique way.
   */
  Elf64_Sxword r_addend;

} Elf64_Rela;



/*!BEGIN libc/elf/struct/syminfo.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYMINFO_H_

typedef struct Elf64_Syminfo {
  Elf64_Half si_boundto;
  Elf64_Half si_flags;
} Elf64_Syminfo;



/*!BEGIN libc/elf/struct/verdaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDAUX_H_

typedef struct Elf64_Verdaux {
  Elf64_Word vda_name;
  Elf64_Word vda_next;
} Elf64_Verdaux;



/*!BEGIN libc/elf/struct/verdef.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDEF_H_

typedef struct Elf64_Verdef {
  Elf64_Half vd_version;
  Elf64_Half vd_flags;
  Elf64_Half vd_ndx;
  Elf64_Half vd_cnt;
  Elf64_Word vd_hash;
  Elf64_Word vd_aux;
  Elf64_Word vd_next;
} Elf64_Verdef;



/*!BEGIN libc/elf/struct/vernaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNAUX_H_

typedef struct Elf64_Vernaux {
  Elf64_Word vna_hash;
  Elf64_Half vna_flags;
  Elf64_Half vna_other;
  Elf64_Word vna_name;
  Elf64_Word vna_next;
} Elf64_Vernaux;



/*!BEGIN libc/elf/struct/verneed.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNEED_H_

typedef struct Elf64_Verneed {
  Elf64_Half vn_version;
  Elf64_Half vn_cnt;
  Elf64_Word vn_file;
  Elf64_Word vn_aux;
  Elf64_Word vn_next;
} Elf64_Verneed;



/*!BEGIN libc/fmt/conv.h */

#define COSMOPOLITAN_LIBC_FMT_CONV_H_
COSMOPOLITAN_C_START_

int abs(int) libcesque pureconst;
long labs(long) libcesque pureconst;
long long llabs(long long) libcesque pureconst;
libcesque intmax_t imaxabs(intmax_t) pureconst;
int atoi(const char *) paramsnonnull() libcesque;
long atol(const char *) paramsnonnull() libcesque;
long long atoll(const char *) paramsnonnull() libcesque;
unsigned long strtoul(const char *, char **, int) libcesque paramsnonnull((1));
long long strtoll(const char *, char **, int) libcesque paramsnonnull((1));
unsigned long long strtoull(const char *, char **, int) paramsnonnull((1));
intmax_t strtoimax(const char *, char **, int) libcesque paramsnonnull((1));
uintmax_t strtoumax(const char *, char **, int) libcesque paramsnonnull((1));
intmax_t wcstoimax(const wchar_t *, wchar_t **, int) libcesque;
uintmax_t wcstoumax(const wchar_t *, wchar_t **, int) libcesque;
long wcstol(const wchar_t *, wchar_t **, int) libcesque;
unsigned long wcstoul(const wchar_t *, wchar_t **, int) libcesque;
long strtol(const char *, char **, int) paramsnonnull((1)) libcesque;
long sizetol(const char *, long) paramsnonnull() libcesque;
char *sizefmt(char *, uint64_t, uint64_t) libcesque;
long long wcstoll(const wchar_t *, wchar_t **, int) libcesque;
unsigned long long wcstoull(const wchar_t *, wchar_t **, int) libcesque;
int wcscoll(const wchar_t *, const wchar_t *) libcesque;
size_t wcsxfrm(wchar_t *, const wchar_t *, size_t) libcesque;

double atof(const char *) libcesque;
float strtof(const char *, char **) libcesque;
double strtod(const char *, char **) libcesque;
long double strtold(const char *, char **) libcesque;
float wcstof(const wchar_t *, wchar_t **) libcesque;
double wcstod(const wchar_t *, wchar_t **) libcesque;
long double wcstold(const wchar_t *, wchar_t **) libcesque;

#ifdef _COSMO_SOURCE
char *stripext(char *) libcesque;
char *stripexts(char *) libcesque;
#endif /* _COSMO_SOURCE */

typedef struct {
  int quot;
  int rem;
} div_t;

typedef struct {
  long int quot;
  long int rem;
} ldiv_t;

typedef struct {
  long long int quot;
  long long int rem;
} lldiv_t;

typedef struct {
  intmax_t quot;
  intmax_t rem;
} imaxdiv_t;

libcesque div_t div(int, int) pureconst;
libcesque ldiv_t ldiv(long, long) pureconst;
libcesque lldiv_t lldiv(long long, long long) pureconst;
libcesque imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;

#if __STDC_VERSION__ + 0 >= 199901L
#define div(num, den)   ((div_t){(num) / (den), (num) % (den)})
#define ldiv(num, den)  ((ldiv_t){(num) / (den), (num) % (den)})
#define lldiv(num, den) ((lldiv_t){(num) / (den), (num) % (den)})
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/fmt/itoa.h */

#ifndef COSMOPOLITAN_LIBC_FMT_ITOA_H_
#define COSMOPOLITAN_LIBC_FMT_ITOA_H_
COSMOPOLITAN_C_START_

#define LengthInt64           __LengthInt64
#define LengthUint64          __LengthUint64
#define LengthInt64Thousands  __LengthInt64Thousands
#define LengthUint64Thousands __LengthUint64Thousands
#define FormatInt32           __FormatInt32
#define FormatUint32          __FormatUint32
#define FormatInt64           __FormatInt64
#define FormatUint64          __FormatUint64
#define FormatInt64Thousands  __FormatInt64Thousands
#define FormatUint64Thousands __FormatUint64Thousands
#define FormatOctal32         __FormatOctal32
#define FormatOctal64         __FormatOctal64
#define FormatBinary64        __FormatBinary64
#define FormatHex64           __FormatHex64
#define FormatFlex64          __FormatFlex64
#define uint64toarray_radix16 __uint64toarray_radix16
#define uint64toarray_fixed16 __uint64toarray_fixed16
#define uint64toarray_radix8  __uint64toarray_radix8

libcesque unsigned LengthInt64(int64_t) pureconst;
libcesque unsigned LengthUint64(uint64_t) pureconst;
libcesque unsigned LengthInt64Thousands(int64_t) pureconst;
libcesque unsigned LengthUint64Thousands(uint64_t) pureconst;
libcesque char *FormatInt32(char[hasatleast 12], int32_t);
libcesque char *FormatUint32(char[hasatleast 12], uint32_t);
libcesque char *FormatInt64(char[hasatleast 21], int64_t);
libcesque char *FormatUint64(char[hasatleast 21], uint64_t);
libcesque char *FormatInt64Thousands(char[hasatleast 27], int64_t);
libcesque char *FormatUint64Thousands(char[hasatleast 27], uint64_t);
libcesque char *FormatOctal32(char[hasatleast 13], uint32_t, bool32);
libcesque char *FormatOctal64(char[hasatleast 24], uint64_t, bool32);
libcesque char *FormatBinary64(char[hasatleast 67], uint64_t, char);
libcesque char *FormatHex64(char[hasatleast 19], uint64_t, char);
libcesque char *FormatFlex64(char[hasatleast 24], int64_t, char);
libcesque size_t uint64toarray_radix16(uint64_t, char[hasatleast 17]);
libcesque size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
libcesque size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_ITOA_H_ */


/*!BEGIN libc/fmt/leb128.h */

#ifndef COSMOPOLITAN_LIBC_FMT_LEB128_H_
#define COSMOPOLITAN_LIBC_FMT_LEB128_H_
COSMOPOLITAN_C_START_

#define sleb64   __sleb64
#define zleb64   __zleb64
#define uleb64   __uleb64
#define unzleb64 __unzleb64
#define unuleb64 __unuleb64

char *sleb64(char *, int64_t) libcesque;
char *zleb64(char[hasatleast 10], int64_t) libcesque;
char *uleb64(char[hasatleast 10], uint64_t) libcesque;
int unzleb64(const char *, size_t, int64_t *) libcesque;
int unuleb64(const char *, size_t, uint64_t *) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_LEB128_H_ */


/*!BEGIN libc/fmt/libgen.h */

#define COSMOPOLITAN_LIBC_FMT_LIBGEN_H_
COSMOPOLITAN_C_START_

char *dirname(char *) libcesque;
char *basename(char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/dlopen/dlfcn.h */

#define COSMOPOLITAN_LIBC_DLFCN_H_

#define RTLD_LOCAL  0
#define RTLD_LAZY   1
#define RTLD_NOW    2
#define RTLD_GLOBAL 256

COSMOPOLITAN_C_START_

#define RTLD_NEXT    ((void *)-1)
#define RTLD_DEFAULT ((void *)0)

char *dlerror(void) libcesque;
void *dlopen(const char *, int) libcesque;
void *dlsym(void *, const char *) libcesque;
int dlclose(void *) libcesque;

char *cosmo_dlerror(void) libcesque;
void *cosmo_dlopen(const char *, int) libcesque;
void *cosmo_dlsym(void *, const char *) libcesque;
void *cosmo_dltramp(void *) libcesque;
int cosmo_dlclose(void *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/asancodes.h */

#define COSMOPOLITAN_LIBC_INTRIN_ASANCODES_H_

#define kAsanScale           3
#define kAsanMagic           0x7fff8000
#define kAsanNullPage        -1  /* ∅ 0xff */
#define kAsanProtected       -2  /* P 0xfe */
#define kAsanHeapFree        -3  /* F 0xfd */
#define kAsanHeapRelocated   -4  /* R 0xfc */
#define kAsanAllocaOverrun   -5  /* 𝑂 0xfb */
#define kAsanHeapUnderrun    -6  /* U 0xfa */
#define kAsanHeapOverrun     -7  /* O 0xf9 */
#define kAsanStackUnscoped   -8  /* s 0xf8 */
#define kAsanStackOverflow   -9  /* ! 0xf7 */
#define kAsanGlobalOrder     -10 /* I 0xf6 */
#define kAsanStackFree       -11 /* r 0xf5 */
#define kAsanStackPartial    -12 /* p 0xf4 */
#define kAsanStackOverrun    -13 /* o 0xf3 */
#define kAsanStackMiddle     -14 /* m 0xf2 */
#define kAsanStackUnderrun   -15 /* u 0xf1 */
#define kAsanAllocaUnderrun  -16 /* 𝑈 0xf0 */
#define kAsanUnmapped        -17 /* M 0xef */
#define kAsanGlobalRedzone   -18 /* G 0xee */
#define kAsanGlobalGone      -19 /* 𝐺 0xed */
#define kAsanGlobalUnderrun  -20 /* μ 0xec */
#define kAsanGlobalOverrun   -21 /* Ω 0xeb */
#define kAsanMmapSizeOverrun -22 /* Z 0xea */



/*!BEGIN libc/intrin/asmflag.h */

#define COSMOPOLITAN_LIBC_BITS_ASMFLAG_H_

/*
 * Constraints for virtual machine flags.
 * @note we beseech clang devs for flag constraints
 */
#ifdef __GCC_ASM_FLAG_OUTPUTS__ /* GCC6+ CLANG10+ */
#define CFLAG_CONSTRAINT  "=@ccc"
#define CFLAG_ASM(OP)     OP
#define ZFLAG_CONSTRAINT  "=@ccz"
#define ZFLAG_ASM(OP)     OP
#define OFLAG_CONSTRAINT  "=@cco"
#define OFLAG_ASM(OP)     OP
#define SFLAG_CONSTRAINT  "=@ccs"
#define SFLAG_ASM(SP)     SP
#define ABOVE_CONSTRAINT  "=@cca" /* i.e. !ZF && !CF */
#define ABOVEFLAG_ASM(OP) OP
#else
#define CFLAG_CONSTRAINT  "=q"
#define CFLAG_ASM(OP)     OP "\n\tsetc\t%b0"
#define ZFLAG_CONSTRAINT  "=q"
#define ZFLAG_ASM(OP)     OP "\n\tsetz\t%b0"
#define OFLAG_CONSTRAINT  "=q"
#define OFLAG_ASM(OP)     OP "\n\tseto\t%b0"
#define SFLAG_CONSTRAINT  "=q"
#define SFLAG_ASM(SP)     OP "\n\tsets\t%b0"
#define ABOVE_CONSTRAINT  "=@cca"
#define ABOVEFLAG_ASM(OP) OP "\n\tseta\t%b0"
#endif



/*!BEGIN libc/intrin/atomic.h */

#define COSMOPOLITAN_LIBC_BITS_ATOMIC_H_

/**
 * @fileoverview Cosmopolitan C11 Atomics Library
 *
 * - Forty-two different ways to say MOV.
 * - Fourteen different ways to say XCHG.
 * - Twenty different ways to say LOCK CMPXCHG.
 *
 * @see libc/atomic.h
 */

typedef int memory_order;

enum {
  memory_order_relaxed,
  memory_order_consume,
  memory_order_acquire,
  memory_order_release,
  memory_order_acq_rel,
  memory_order_seq_cst,
};

#define ATOMIC_VAR_INIT(...)     __VA_ARGS__
#define atomic_is_lock_free(obj) ((void)(obj), sizeof(obj) <= sizeof(void *))

#define atomic_flag      atomic_bool
#define ATOMIC_FLAG_INIT ATOMIC_VAR_INIT(0)
#define atomic_flag_test_and_set_explicit(x, order) \
  atomic_exchange_explicit(x, 1, order)
#define atomic_flag_clear_explicit(x, order) atomic_store_explicit(x, 0, order)

#define atomic_compare_exchange_strong(pObject, pExpected, desired) \
  atomic_compare_exchange_strong_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_compare_exchange_weak(pObject, pExpected, desired) \
  atomic_compare_exchange_weak_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_exchange(pObject, desired) \
  atomic_exchange_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_fetch_add(pObject, operand) \
  atomic_fetch_add_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_and(pObject, operand) \
  atomic_fetch_and_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_or(pObject, operand) \
  atomic_fetch_or_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_sub(pObject, operand) \
  atomic_fetch_sub_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_xor(pObject, operand) \
  atomic_fetch_xor_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_load(pObject) atomic_load_explicit(pObject, memory_order_seq_cst)
#define atomic_store(pObject, desired) \
  atomic_store_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_flag_test_and_set(x) \
  atomic_flag_test_and_set_explicit(x, memory_order_seq_cst)
#define atomic_flag_clear(x) atomic_flag_clear_explicit(x, memory_order_seq_cst)

#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)

#define atomic_init(obj, value)    __c11_atomic_init(obj, value)
#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
#define atomic_signal_fence(order) __c11_atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(object, expected, desired, \
                                                success, failure)          \
  __c11_atomic_compare_exchange_strong(object, expected, desired, success, \
                                       failure)
#define atomic_compare_exchange_weak_explicit(object, expected, desired, \
                                              success, failure)          \
  __c11_atomic_compare_exchange_weak(object, expected, desired, success, \
                                     failure)
#define atomic_exchange_explicit(object, desired, order) \
  __c11_atomic_exchange(object, desired, order)
#define atomic_fetch_add_explicit(object, operand, order) \
  __c11_atomic_fetch_add(object, operand, order)
#define atomic_fetch_and_explicit(object, operand, order) \
  __c11_atomic_fetch_and(object, operand, order)
#define atomic_fetch_or_explicit(object, operand, order) \
  __c11_atomic_fetch_or(object, operand, order)
#define atomic_fetch_sub_explicit(object, operand, order) \
  __c11_atomic_fetch_sub(object, operand, order)
#define atomic_fetch_xor_explicit(object, operand, order) \
  __c11_atomic_fetch_xor(object, operand, order)
#define atomic_load_explicit(object, order) __c11_atomic_load(object, order)
#define atomic_store_explicit(object, desired, order) \
  __c11_atomic_store(object, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __atomic_thread_fence(order)
#define atomic_signal_fence(order) __atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(pObject, pExpected, desired, \
                                                success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 0, success, failure)
#define atomic_compare_exchange_weak_explicit(pObject, pExpected, desired, \
                                              success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 1, success, failure)
#define atomic_exchange_explicit(pObject, desired, order) \
  __atomic_exchange_n(pObject, desired, order)
#define atomic_fetch_add_explicit(pObject, operand, order) \
  __atomic_fetch_add(pObject, operand, order)
#define atomic_fetch_and_explicit(pObject, operand, order) \
  __atomic_fetch_and(pObject, operand, order)
#define atomic_fetch_or_explicit(pObject, operand, order) \
  __atomic_fetch_or(pObject, operand, order)
#define atomic_fetch_sub_explicit(pObject, operand, order) \
  __atomic_fetch_sub(pObject, operand, order)
#define atomic_fetch_xor_explicit(pObject, operand, order) \
  __atomic_fetch_xor(pObject, operand, order)
#define atomic_load_explicit(pObject, order) __atomic_load_n(pObject, order)
#define atomic_store_explicit(pObject, desired, order) \
  __atomic_store_n(pObject, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __sync_synchronize()
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define __atomic_apply_stride(object, operand) \
  (((__typeof__(*(object)))0) + (operand))
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    __typeof__(expected) __ep = (expected);                                   \
    __typeof__(*__ep) __e = *__ep;                                            \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    (*__ep = __sync_val_compare_and_swap(object, __e, desired)) == __e;       \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#if __has_builtin(__sync_swap)
#define atomic_exchange_explicit(object, desired, order) \
  ((void)(order), __sync_swap(object, desired))
#else
#define atomic_exchange_explicit(object, desired, order) \
  __extension__({                                        \
    __typeof__(object) __o = (object);                   \
    __typeof__(desired) __d = (desired);                 \
    (void)(order);                                       \
    __sync_synchronize();                                \
    __sync_lock_test_and_set(__o, __d);                  \
  })
#endif
#define atomic_fetch_add_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_add(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_and_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_and(object, operand))
#define atomic_fetch_or_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_or(object, operand))
#define atomic_fetch_sub_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_sub(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_xor_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_xor(object, operand))
#define atomic_load_explicit(object, order) \
  ((void)(order), __sync_fetch_and_add(object, 0))
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#elif defined(__GNUC__) && defined(__x86__) /* x86 with gcc 4.0 and earlier */

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __asm__ volatile("mfence" ::: "memory")
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    char DidIt;                                                               \
    __typeof__(object) IfThing = (object);                                    \
    __typeof__(IfThing) IsEqualToMe = (expected);                             \
    __typeof__(*IfThing) ReplaceItWithMe = (desired), ax;                     \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    __asm__ volatile("lock cmpxchg\t%3,(%1)\n\t"                              \
                     "setz\t%b0"                                              \
                     : "=q"(DidIt), "=r"(IfThing), "+a"(ax)                   \
                     : "r"(ReplaceItWithMe), "2"(*IsEqualToMe)                \
                     : "memory", "cc");                                       \
    *IsEqualToMe = ax;                                                        \
    DidIt;                                                                    \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#define atomic_exchange_explicit(object, desired, order)                \
  __extension__({                                                       \
    __typeof__(object) __o = (object);                                  \
    __typeof__(*__o) __d = (desired);                                   \
    (void)(order);                                                      \
    __asm__ volatile("xchg\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                \
  })
#define atomic_fetch_add_explicit(object, operand, order)                    \
  __extension__({                                                            \
    __typeof__(object) __o = (object);                                       \
    __typeof__(*__o) __d = (desired);                                        \
    (void)(order);                                                           \
    __asm__ volatile("lock xadd\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                     \
  })
#define atomic_fetch_sub_explicit(object, operand, order) \
  atomic_fetch_add_explicit(object, -(operand), order)
#define atomic_load_explicit(object, order) \
  atomic_fetch_add_explicit(object, 0, order)
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#else /* non-gcc or old gcc w/o x86 */
#error "atomic operations not supported with this compiler and/or architecture"
#endif



/*!BEGIN libc/intrin/bsf.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
COSMOPOLITAN_C_START_

libcesque int bsf(int) pureconst;
libcesque int bsfl(long) pureconst;
libcesque int bsfll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsf(x)   __builtin_ctz(x)
#define bsfl(x)  __builtin_ctzl(x)
#define bsfll(x) __builtin_ctzll(x)
#endif

/* deprecated */
#define _bsf(x)   bsf(x)
#define _bsfl(x)  bsfl(x)
#define _bsfll(x) bsfll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */


/*!BEGIN libc/intrin/bsr.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
COSMOPOLITAN_C_START_

libcesque int bsr(int) pureconst;
libcesque int bsrl(long) pureconst;
libcesque int bsrll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsr(x)   (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
#define bsrl(x)  (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
#define bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
#endif

/* deprecated */
#define _bsr(x)   bsr(x)
#define _bsrl(x)  bsrl(x)
#define _bsrll(x) bsrll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */


/*!BEGIN libc/intrin/bswap.h */

#define COSMOPOLITAN_LIBC_BITS_BSWAP_H_
COSMOPOLITAN_C_START_

libcesque uint16_t bswap_16(uint16_t) pureconst;
libcesque uint32_t bswap_32(uint32_t) pureconst;
libcesque uint64_t bswap_64(uint64_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bswap_16(x) __builtin_bswap16(x)
#define bswap_32(x) __builtin_bswap32(x)
#define bswap_64(x) __builtin_bswap64(x)
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/cmpxchg.h */

#define COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
COSMOPOLITAN_C_START_

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME)                       \
  ({                                                                          \
    bool32 DidIt;                                                             \
    autotype(IFTHING) IfThing = (IFTHING);                                    \
    typeof(*IfThing) IsEqualToMe = (ISEQUALTOME);                             \
    typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME);                     \
    asm volatile(ZFLAG_ASM("cmpxchg\t%3,%1")                                  \
                 : ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
                 : "r"(ReplaceItWithMe)                                       \
                 : "cc");                                                     \
    DidIt;                                                                    \
  })
#else
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
  (*(IFTHING) == (ISEQUALTOME) ? (*(IFTHING) = (REPLACEITWITHME), 1) : 0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/dll.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define dll_make_first   __dll_make_first
#define dll_make_last    __dll_make_last
#define dll_remove       __dll_remove
#define dll_splice_after __dll_splice_after
COSMOPOLITAN_C_START_

#define DLL_CONTAINER(t, f, p) ((t *)(((char *)(p)) - offsetof(t, f)))

struct Dll {
  struct Dll *next;
  struct Dll *prev;
};

static inline void dll_init(struct Dll *e) {
  e->next = e;
  e->prev = e;
}

static inline int dll_is_alone(struct Dll *e) {
  return e->next == e && e->prev == e;
}

static inline int dll_is_empty(struct Dll *list) {
  return !list;
}

static inline struct Dll *dll_last(struct Dll *list) {
  return list;
}

static inline struct Dll *dll_first(struct Dll *list) {
  struct Dll *first = 0;
  if (list) first = list->next;
  return first;
}

static inline struct Dll *dll_next(struct Dll *list, struct Dll *e) {
  struct Dll *next = 0;
  if (e != list) next = e->next;
  return next;
}

static inline struct Dll *dll_prev(struct Dll *list, struct Dll *e) {
  struct Dll *prev = 0;
  if (e != list->next) prev = e->prev;
  return prev;
}

void dll_remove(struct Dll **, struct Dll *) paramsnonnull() libcesque;
void dll_make_last(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_make_first(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */


/*!BEGIN libc/intrin/hilbert.h */

#define COSMOPOLITAN_LIBC_BITS_HILBERT_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#define hilbert   __hilbert
#define unhilbert __unhilbert

libcesque long hilbert(long, long, long) pureconst;
libcesque axdx_t unhilbert(long, long) pureconst;

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/kprintf.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
#define COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_

#define klog         __klog
#define kprintf      __kprintf
#define ksnprintf    __ksnprintf
#define kvprintf     __kvprintf
#define kvsnprintf   __kvsnprintf
#define kloghandle   __kloghandle
#define kisdangerous __kisdangerous
#define uprintf      __uprintf
#define uvprintf     __uvprintf

#if !(__ASSEMBLER__ + __LINKER__ + 0)

COSMOPOLITAN_C_START_

void kprintf(const char *, ...) libcesque;
size_t ksnprintf(char *, size_t, const char *, ...) libcesque;
void kvprintf(const char *, va_list) libcesque;
size_t kvsnprintf(char *, size_t, const char *, va_list) libcesque;

bool32 kisdangerous(const void *) libcesque;

void klog(const char *, size_t) libcesque;
void _klog_serial(const char *, size_t) libcesque;
long kloghandle(void) libcesque;

void uprintf(const char *, ...) libcesque;
void uvprintf(const char *, va_list) libcesque;

#ifndef TINY
#define KINFOF(FMT, ...)                                         \
  do {                                                           \
    uprintf("\r\e[35m%s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                      \
  } while (0)
#define KWARNF(FMT, ...)                                                  \
  do {                                                                    \
    uprintf("\r\e[94;49mwarn: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                               \
  } while (0)
#else
#define KINFOF(FMT, ...) ((void)0)
#define KWARNF(FMT, ...) ((void)0)
#endif
#define KDIEF(FMT, ...)                                                     \
  do {                                                                      \
    kprintf("\r\e[30;101mfatal: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                                 \
    for (;;) asm volatile("cli\n\thlt");                                    \
  } while (0)

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_ */


/*!BEGIN libc/intrin/likely.h */

#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
#ifdef _COSMO_SOURCE

#define LIKELY(x)   __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_LIKELY(x) __builtin_expect_with_probability(!!(x), 1, 0.999)
#else
#define VERY_LIKELY(x) LIKELY(x)
#endif

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_UNLIKELY(x) __builtin_expect_with_probability(!!(x), 0, 0.999)
#else
#define VERY_UNLIKELY(x) UNLIKELY(x)
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/macros.h */

#define COSMOPOLITAN_LIBC_INTRIN_MACROS_H_


/*!BEGIN libc/nexgen32e/x86feature.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86FEATURE_H_
#ifdef __x86_64__


/*!BEGIN libc/nexgen32e/kcpuids.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_KCPUIDS_H_

#define KCPUIDS_0H        0
#define KCPUIDS_1H        1
#define KCPUIDS_2H        2
#define KCPUIDS_7H        3
#define KCPUIDS_80000001H 4
#define KCPUIDS_80000007H 5
#define KCPUIDS_16H       6
#define KCPUIDS_7H_1H     7
#define KCPUIDS_LEN       8
#define KCPUIDS_6H        -1 /* TBD: Thermal and Power Management */
#define KCPUIDS_DH        -1 /* TBD: Extended state features */
#define KCPUIDS_80000008H -1 /* TBD: AMD Miscellaneous */
#define KCPUIDS_8000000AH -1 /* TBD: AMD SVM */

#define KCPUIDS_EAX 0
#define KCPUIDS_EBX 1
#define KCPUIDS_ECX 2
#define KCPUIDS_EDX 3

#define KCPUIDS(LEAF, REG) _KCPUIDS(LEAF, REG)
#ifdef __ASSEMBLER__
#define _KCPUIDS(LEAF, REG) KCPUIDS_##LEAF * 16 + KCPUIDS_##REG * 4
#else
#define _KCPUIDS(LEAF, REG) kCpuids[KCPUIDS_##LEAF][KCPUIDS_##REG]
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const unsigned kCpuids[KCPUIDS_LEN][4];

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nexgen32e/x86compiler.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86COMPILER_H_
#ifdef __x86_64__

/**
 * @fileoverview x86 cpu feature compile-time requirement detection.
 * @see -march=native, -mavx2, etc.
 */

#ifdef __AES__
#define _X86_CC_AES 1
#else
#define _X86_CC_AES 0
#endif

#ifdef __AVX__
#define _X86_CC_AVX 1
#else
#define _X86_CC_AVX 0
#endif

#ifdef __AVX2__
#define _X86_CC_AVX2 1
#else
#define _X86_CC_AVX2 0
#endif

#ifdef __F16C__
#define _X86_CC_F16C 1
#else
#define _X86_CC_F16C 0
#endif

#ifdef __AVXVNNI__
#define _X86_CC_AVXVNNI 1
#else
#define _X86_CC_AVXVNNI 0
#endif

#ifdef __AVXVNNIINT8__
#define _X86_CC_AVXVNNIINT8 1
#else
#define _X86_CC_AVXVNNIINT8 0
#endif

#ifdef __AVXVNNIINT16__
#define _X86_CC_AVXVNNIINT16 1
#else
#define _X86_CC_AVXVNNIINT16 0
#endif

#ifdef __AVX512F__
#define _X86_CC_AVX512F 1
#else
#define _X86_CC_AVX512F 0
#endif

#ifdef __AVX512BF16__
#define _X86_CC_AVX512BF16 1
#else
#define _X86_CC_AVX512BF16 0
#endif

#ifdef __AVX512FP16__
#define _X86_CC_AVX512FP16 1
#else
#define _X86_CC_AVX512FP16 0
#endif

#ifdef __AVX512VBMI__
#define _X86_CC_AVX512VBMI 1
#else
#define _X86_CC_AVX512VBMI 0
#endif

#ifdef __AVX512VNNI__
#define _X86_CC_AVX512VNNI 1
#else
#define _X86_CC_AVX512VNNI 0
#endif

#ifdef __AVX5124VNNIW__
#define _X86_CC_AVX5124VNNIW 1
#else
#define _X86_CC_AVX5124VNNIW 0
#endif

#ifdef __ABM__
#define _X86_CC_ABM 1
#else
#define _X86_CC_ABM 0
#endif

#ifdef __BMI__
#define _X86_CC_BMI 1
#else
#define _X86_CC_BMI 0
#endif

#ifdef __BMI2__
#define _X86_CC_BMI2 1
#else
#define _X86_CC_BMI2 0
#endif

#ifdef __FMA__
#define _X86_CC_FMA 1
#else
#define _X86_CC_FMA 0
#endif

#ifdef __ADX__
#define _X86_CC_ADX 1
#else
#define _X86_CC_ADX 0
#endif

#ifdef __PCLMUL__
#define _X86_CC_PCLMUL 1
#else
#define _X86_CC_PCLMUL 0
#endif

#ifdef __POPCNT__
#define _X86_CC_POPCNT 1
#else
#define _X86_CC_POPCNT 0
#endif

#ifdef __RDRND__
#define _X86_CC_RDRND 1
#else
#define _X86_CC_RDRND 0
#endif

#ifdef __RDSEED__
#define _X86_CC_RDSEED 1
#else
#define _X86_CC_RDSEED 0
#endif

#ifdef __SHA__
#define _X86_CC_SHA 1
#else
#define _X86_CC_SHA 0
#endif

#ifdef __SSSE3__
#define _X86_CC_SSSE3 1
#else
#define _X86_CC_SSSE3 0
#endif

#ifdef __SSE__
#define _X86_CC_SSE 1
#else
#define _X86_CC_SSE 0
#endif

#ifdef __SSE2__
#define _X86_CC_SSE2 1
#else
#define _X86_CC_SSE2 0
#endif

#ifdef __SSE3__
#define _X86_CC_SSE3 1
#else
#define _X86_CC_SSE3 0
#endif

#ifdef __SSE4_1__
#define _X86_CC_SSE4_1 1
#else
#define _X86_CC_SSE4_1 0
#endif

#ifdef __SSE4_2__
#define _X86_CC_SSE4_2 1
#else
#define _X86_CC_SSE4_2 0
#endif

#ifdef __XSAVE__
#define _X86_CC_XSAVE 1
#else
#define _X86_CC_XSAVE 0
#endif

#ifdef __CLFLUSHOPT__
#define _X86_CC_CLFLUSHOPT 1
#else
#define _X86_CC_CLFLUSHOPT 0
#endif

#ifdef __RDPID__
#define _X86_CC_RDPID 1
#else
#define _X86_CC_RDPID 0
#endif

#endif /* __x86_64__ */

/* Returns true if x86 FEATURE is present.
   This performs a runtime check in normal portable builds.
   It's usually dead code eliminated for -march=native builds. */
#define X86_HAVE(FEATURE) _X86_HAVE(X86_##FEATURE)

/* Returns true if x86 FEATURE is present.
   This will *always* perform a runtime check.
   It's useful for checking compile-time cpu features are present. */
#define X86_CHECK(FEATURE) _X86_CHECK(X86_##FEATURE)

/* Returns true if x86 FEATURE is mandatory at build time.
   This will never perform runtime checks; it's always constant. */
#define X86_NEED(FEATURE) _X86_NEED(X86_##FEATURE)

/* clang-format off */
/*      --- FEATURE              LEAF       REG BIT  COMPILE-TIME-DEFINE */
#define X86_ACC                  1H,        EDX, 29, 0
#define X86_ACPI                 1H,        EDX, 22, 0
#define X86_ADX                  7H,        EBX, 19, _X86_CC_ADX              /* broadwell c. 2014 */
#define X86_AES                  1H,        ECX, 25, _X86_CC_AES              /* westmere c. 2010 */
#define X86_APIC                 1H,        EDX,  9, 0
#define X86_ARCH_CAPABILITIES    7H,        EDX, 29, 0
#define X86_AVX                  1H,        ECX, 28, _X86_CC_AVX              /* sandybridge c. 2012 */
#define X86_AVX2                 7H,        EBX,  5, _X86_CC_AVX2             /* haswell c. 2013 */
#define X86_AVXVNNI              7H_1H,     EAX,  4, _X86_CC_AVXVNNI
#define X86_AVXVNNIINT8          7H_1H,     EDX,  4, _X86_CC_AVXVNNIINT8
#define X86_AVXVNNIINT16         7H_1H,     EDX, 10, _X86_CC_AVXVNNIINT16
#define X86_AVX512BW             7H,        EBX, 30, 0
#define X86_AVX512CD             7H,        EBX, 28, 0
#define X86_AVX512DQ             7H,        EBX, 17, 0
#define X86_AVX512ER             7H,        EBX, 27, 0
#define X86_AVX512F              7H,        EBX, 16, _X86_CC_AVX512F
#define X86_AVX512IFMA           7H,        EBX, 21, 0
#define X86_AVX512PF             7H,        EBX, 26, 0
#define X86_AVX512VBMI           7H,        ECX,  1, _X86_CC_AVX512VBMI
#define X86_AVX512VL             7H,        EBX, 31, 0
#define X86_AVX512_4FMAPS        7H,        EDX,  3, 0
#define X86_AVX512_4VNNIW        7H,        EDX,  2, _X86_CC_AVX5124VNNIW
#define X86_AVX512_FP16          7H,        EDX, 23, _X86_CC_AVX512FP16
#define X86_AVX512_BF16          7H_1H,     EAX,  5, _X86_CC_AVX512BF16
#define X86_AVX512_BITALG        7H,        ECX, 12, 0
#define X86_AVX512_VBMI2         7H,        ECX,  6, 0
#define X86_AVX512_VNNI          7H,        ECX, 11, _X86_CC_AVX512VNNI
#define X86_AVX512_VP2INTERSECT  7H,        EDX,  8, 0
#define X86_AVX512_VPOPCNTDQ     7H,        ECX, 14, 0
#define X86_BMI                  7H,        EBX,  3, _X86_CC_BMI              /* haswell c. 2013 */
#define X86_BMI2                 7H,        EBX,  8, _X86_CC_BMI2             /* haswell c. 2013 */
#define X86_CID                  1H,        ECX, 10, 0
#define X86_CLDEMOTE             7H,        ECX, 25, 0
#define X86_CLFLUSH              1H,        EDX, 19, _X86_CC_SSE2
#define X86_CLFLUSHOPT           7H,        EBX, 23, _X86_CC_CLFLUSHOPT       /* skylake/zen  */
#define X86_CLWB                 7H,        EBX, 24, 0                        /* skylake/zen2 */
#define X86_CMOV                 1H,        EDX, 15, 0
#define X86_CQM                  7H,        EBX, 12, 0
#define X86_CX16                 1H,        ECX, 13, 0
#define X86_CX8                  1H,        EDX,  8, 0
#define X86_DCA                  1H,        ECX, 18, 0
#define X86_DE                   1H,        EDX,  2, 0
#define X86_DS                   1H,        EDX, 21, 0
#define X86_DSCPL                1H,        ECX,  4, 0
#define X86_DTES64               1H,        ECX,  2, 0
#define X86_ERMS                 7H,        EBX,  9, 0                        /* broaadwell c. 2014 */
#define X86_EST                  1H,        ECX,  7, 0
#define X86_F16C                 1H,        ECX, 29, _X86_CC_F16C
#define X86_FDP_EXCPTN_ONLY      7H,        EBX,  6, 0
#define X86_FLUSH_L1D            7H,        EDX, 28, 0
#define X86_FMA                  1H,        ECX, 12, _X86_CC_FMA              /* haswell c. 2013 */
#define X86_FPU                  1H,        EDX,  0, 0
#define X86_FSGSBASE             7H,        EBX,  0, 0
#define X86_FXSR                 1H,        EDX, 24, 0
#define X86_GBPAGES              80000001H, EDX, 26, 0
#define X86_GFNI                 7H,        ECX,  8, 0
#define X86_HLE                  7H,        EBX,  4, 0
#define X86_HT                   1H,        EDX, 28, 0
#define X86_HYPERVISOR           1H,        ECX, 31, 0
#define X86_IA64                 1H,        EDX, 30, 0
#define X86_INTEL_PT             7H,        EBX, 25, 0
#define X86_INTEL_STIBP          7H,        EDX, 27, 0
#define X86_INVPCID              1H,        EBX, 10, 0
#define X86_INVTSC               80000007H, EDX,  8, _X86_CC_POPCNT           /* i.e. not a K8 */
#define X86_LA57                 7H,        ECX, 16, 0
#define X86_LAHF_LM              80000001H, ECX,  0, 0
#define X86_LM                   80000001H, EDX, 29, 0
#define X86_MCA                  1H,        EDX, 14, 0
#define X86_MCE                  1H,        EDX,  7, 0
#define X86_MD_CLEAR             7H,        EDX, 10, 0
#define X86_MMX                  1H,        EDX, 23, 0
#define X86_MOVBE                1H,        ECX, 22, 0
#define X86_MOVDIR64B            7H,        ECX, 28, 0
#define X86_MOVDIRI              7H,        ECX, 27, 0
#define X86_MP                   80000001H, EDX, 19, 0
#define X86_MPX                  7H,        EBX, 14, 0
#define X86_MSR                  1H,        EDX,  5, 0
#define X86_MTRR                 1H,        EDX, 12, 0
#define X86_MWAIT                1H,        ECX,  3, 0
#define X86_NX                   80000001H, EDX, 20, 0
#define X86_OSPKE                7H,        ECX,  4, 0
#define X86_OSXSAVE              1H,        ECX, 27, 0
#define X86_PAE                  1H,        EDX,  6, 0
#define X86_PAT                  1H,        EDX, 16, 0
#define X86_PBE                  1H,        EDX, 31, 0
#define X86_PCID                 1H,        ECX, 17, 0
#define X86_PCLMUL               1H,        ECX,  1, _X86_CC_PCLMUL           /* westmere c. 2010 */
#define X86_PCONFIG              7H,        EDX, 18, 0
#define X86_PDCM                 1H,        ECX, 15, 0
#define X86_PGE                  1H,        EDX, 13, 0
#define X86_PKU                  7H,        ECX,  3, 0
#define X86_PN                   1H,        EDX, 18, 0
#define X86_POPCNT               1H,        ECX, 23, _X86_CC_POPCNT           /* nehalem c. 2008 */
#define X86_PSE                  1H,        EDX,  3, 0
#define X86_PSE36                1H,        EDX, 17, 0
#define X86_RDPID                7H,        ECX, 22, _X86_CC_RDPID            /* cannonlake c. 2018 */
#define X86_RDRND                1H,        ECX, 30, _X86_CC_RDRND            /* ivybridge c. 2012 */
#define X86_RDSEED               7H,        EBX, 18, _X86_CC_RDSEED           /* broadwell c. 2014 */
#define X86_RDTSCP               80000001H, EDX, 27, 0
#define X86_RDT_A                7H,        EBX, 15, 0
#define X86_RTM                  7H,        EBX, 11, 0
#define X86_SDBG                 1H,        ECX, 11, 0
#define X86_SELFSNOOP            1H,        EDX, 27, 0
#define X86_SEP                  1H,        EDX, 11, 0
#define X86_SHA                  7H,        EBX, 29, _X86_CC_SHA              /* goldmont (2016) */
#define X86_SMAP                 7H,        EBX, 20, 0
#define X86_SMEP                 7H,        EBX,  7, 0
#define X86_SMX                  1H,        ECX,  6, 0
#define X86_SPEC_CTRL            7H,        EDX, 26, 0
#define X86_SPEC_CTRL_SSBD       7H,        EDX, 31, 0
#define X86_SSE                  1H,        EDX, 25, _X86_CC_SSE              /* pentium c. 1999 */
#define X86_SSE2                 1H,        EDX, 26, _X86_CC_SSE2             /* pentium c. 2001 */
#define X86_SSE3                 1H,        ECX,  0, _X86_CC_SSE3             /* k8 c. 2005 */
#define X86_SSE4_1               1H,        ECX, 19, _X86_CC_SSE4_1           /* core c. 2006 */
#define X86_SSE4_2               1H,        ECX, 20, _X86_CC_SSE4_2           /* nehalem c. 2008 */
#define X86_SSSE3                1H,        ECX,  9, _X86_CC_SSSE3            /* westmere c. 2010 */
#define X86_SYSCALL              80000001H, EDX, 11, 0
#define X86_TM2                  1H,        ECX,  8, 0
#define X86_TME                  7H,        ECX, 13, 0
#define X86_TSC                  1H,        EDX,  4, 0
#define X86_TSC_ADJUST           7H,        EBX,  1, 0
#define X86_TSC_DEADLINE_TIMER   1H,        ECX, 24, 0
#define X86_TSX_FORCE_ABORT      7H,        EDX, 13, 0
#define X86_UMIP                 7H,        ECX,  2, 0
#define X86_VAES                 7H,        ECX,  9, 0
#define X86_VME                  1H,        EDX,  1, 0
#define X86_VMX                  1H,        ECX,  5, 0
#define X86_VPCLMULQDQ           7H,        ECX, 10, 0
#define X86_WAITPKG              7H,        ECX,  5, 0
#define X86_X2APIC               1H,        ECX, 21, 0
#define X86_XSAVE                1H,        ECX, 26, _X86_CC_XSAVE            /* sandybridge c. 2012 */
#define X86_XTPR                 1H,        ECX, 14, 0
#define X86_ZERO_FCS_FDS         7H,        EBX, 13, 0
#define X86_JIT                  80000001H, ECX, 31, 0                        /* IsGenuineBlink() */
#define X86_HYBRID_CPU           7H,        EDX, 15, 0                        /* Has performance and efficiency cores */
/* clang-format on */

/* AMD specific features */
#define X86_ABM            80000001H, ECX, 5, _X86_CC_ABM
#define X86_3DNOW          80000001H, EDX, 31, 0
#define X86_3DNOWEXT       80000001H, EDX, 30, 0
#define X86_3DNOWPREFETCH  80000001H, ECX, 8, 0
#define X86_BPEXT          80000001H, ECX, 26, 0
#define X86_CMP_LEGACY     80000001H, ECX, 1, 0
#define X86_CR8_LEGACY     80000001H, ECX, 4, 0
#define X86_EXTAPIC        80000001H, ECX, 3, 0
#define X86_FMA4           80000001H, ECX, 16, 0
#define X86_FXSR_OPT       80000001H, EDX, 25, 0
#define X86_IBS            80000001H, ECX, 10, 0
#define X86_LWP            80000001H, ECX, 15, 0
#define X86_MISALIGNSSE    80000001H, ECX, 7, 0
#define X86_MMXEXT         80000001H, EDX, 22, 0
#define X86_MWAITX         80000001H, ECX, 29, 0
#define X86_NODEID_MSR     80000001H, ECX, 19, 0
#define X86_OSVW           80000001H, ECX, 9, 0
#define X86_OVERFLOW_RECOV 80000007H, EBX, 0, 0
#define X86_PERFCTR_CORE   80000001H, ECX, 23, 0
#define X86_PERFCTR_LLC    80000001H, ECX, 28, 0
#define X86_PERFCTR_NB     80000001H, ECX, 24, 0
#define X86_PTSC           80000001H, ECX, 27, 0
#define X86_SKINIT         80000001H, ECX, 12, 0
#define X86_SMCA           80000007H, EBX, 3, 0
#define X86_SSE4A          80000001H, ECX, 6, 0
#define X86_SUCCOR         80000007H, EBX, 1, 0
#define X86_SVM            80000001H, ECX, 2, 0
#define X86_TBM            80000001H, ECX, 21, 0
#define X86_TCE            80000001H, ECX, 17, 0
#define X86_TOPOEXT        80000001H, ECX, 22, 0
#define X86_WDT            80000001H, ECX, 13, 0
#define X86_XOP            80000001H, ECX, 11, 0

/* Defined but not loaded by kCpuids.S */
#define X86_ARAT            6H, EAX, 2, 0
#define X86_AVIC            8000000AH, EDX, 13, 0
#define X86_CLZERO          80000008H, EBX, 0, 0
#define X86_DECODEASSISTS   8000000AH, EDX, 7, 0
#define X86_DTHERM          6H, EAX, 0, 0
#define X86_FLUSHBYASID     8000000AH, EDX, 6, 0
#define X86_HWP             6H, EAX, 7, 0
#define X86_HWP_ACT_WINDOW  6H, EAX, 9, 0
#define X86_HWP_EPP         6H, EAX, 10, 0
#define X86_HWP_NOTIFY      6H, EAX, 8, 0
#define X86_HWP_PKG_REQ     6H, EAX, 11, 0
#define X86_IBPB            80000008H, EBX, 12, 0
#define X86_IBRS            80000008H, EBX, 14, 0
#define X86_IDA             6H, EAX, 1, 0
#define X86_IRPERF          80000008H, EBX, 1, 0
#define X86_LBRV            8000000AH, EDX, 1, 0
#define X86_NPT             8000000AH, EDX, 0, 0
#define X86_NRIPS           8000000AH, EDX, 3, 0
#define X86_PAUSEFILTER     8000000AH, EDX, 10, 0
#define X86_PFTHRESHOLD     8000000AH, EDX, 12, 0
#define X86_PLN             6H, EAX, 4, 0
#define X86_PTS             6H, EAX, 6, 0
#define X86_SSBD            80000008H, EBX, 24, 0
#define X86_SSB_NO          80000008H, EBX, 26, 0
#define X86_STIBP           80000008H, EBX, 15, 0
#define X86_STIBP_ALWAYS_ON 80000008H, EBX, 17, 0
#define X86_SVML            8000000AH, EDX, 2, 0
#define X86_TSCRATEMSR      8000000AH, EDX, 4, 0
#define X86_VGIF            8000000AH, EDX, 16, 0
#define X86_VIRT_SSBD       80000008H, EBX, 25, 0
#define X86_VMCBCLEAN       8000000AH, EDX, 5, 0
#define X86_V_VMSAVE_VMLOAD 8000000AH, EDX, 15, 0
#define X86_WBNOINVD        80000008H, EBX, 9, 0
#define X86_XGETBV1         DH, EAX, 2, 0
#define X86_XSAVEC          DH, EAX, 1, 0
#define X86_XSAVEERPTR      80000008H, EBX, 2, 0
#define X86_XSAVEOPT        DH, EAX, 0, 0
#define X86_XSAVES          DH, EAX, 3, 0

#define X86_WORD(FEATURE) _X86_WORD(X86_##FEATURE)
#define X86_LEAF(FEATURE) _X86_LEAF(X86_##FEATURE)
#define X86_REG(FEATURE)  _X86_REG(X86_##FEATURE)
#define X86_BIT(FEATURE)  _X86_BIT(X86_##FEATURE)

#define _X86_CHECK(FEATURE) __X86_CHECK(FEATURE)
#define _X86_HAVE(FEATURE)  __X86_HAVE(FEATURE)
#define _X86_NEED(FEATURE)  __X86_NEED(FEATURE)
#define _X86_WORD(FEATURE)  __X86_WORD(FEATURE)
#define _X86_LEAF(FEATURE)  __X86_LEAF(FEATURE)
#define _X86_REG(FEATURE)   __X86_REG(FEATURE)
#define _X86_BIT(FEATURE)   __X86_BIT(FEATURE)

#define __X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  ___X86_CHECK(LEAF, REG, BIT, MANDATORY)
#define __X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  ___X86_HAVE(LEAF, REG, BIT, MANDATORY)
#define __X86_NEED(LEAF, REG, BIT, MANDATORY) MANDATORY
#define __X86_WORD(LEAF, REG, BIT, MANDATORY) KCPUIDS(LEAF, REG)
#define __X86_LEAF(LEAF, REG, BIT, MANDATORY) LEAF
#define __X86_REG(LEAF, REG, BIT, MANDATORY)  REG
#define __X86_BIT(LEAF, REG, BIT, MANDATORY)  BIT

#define ___X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  !!(KCPUIDS(LEAF, REG) & (1u << BIT))

#ifndef __ASSEMBLER__
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  !!(MANDATORY || KCPUIDS(LEAF, REG) & (1u << BIT))
#else
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  $1 << (BIT % 8), BIT / 8 + KCPUIDS(LEAF, REG)
#endif

#else
#define X86_HAVE(FEATURE)  0
#define X86_NEED(FEATURE)  0
#define X86_CHECK(FEATURE) 0
#endif /* __x86_64__ */

#define INTRIN_COMMUTATIVE "%"
#define INTRIN_NONCOMMUTATIVE

#if defined(__x86_64__) && !defined(__STRICT_ANSI__)

typedef char __intrin_xmm_t
    __attribute__((__vector_size__(16), __aligned__(16), __may_alias__));

#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C)                    \
  do {                                                                         \
    if (X86_HAVE(ISA)) {                                                       \
      __intrin_xmm_t *Xmm0 = (void *)(A);                                      \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);                \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(C);                \
      if (!X86_NEED(AVX)) {                                                    \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm2), "0"(*Xmm1));        \
      } else {                                                                 \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm1), "x"(*Xmm2)); \
      }                                                                        \
    } else {                                                                   \
      PURE(A, B, C);                                                           \
    }                                                                          \
  } while (0)

#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)                 \
  do {                                                               \
    if (X86_HAVE(ISA)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I));     \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)                 \
  do {                                                          \
    if (X86_HAVE(ISA)) {                                        \
      __intrin_xmm_t *Xmm0 = (void *)(A);                       \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B); \
      if (!X86_NEED(AVX)) {                                     \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "0"(*Xmm1));           \
      } else {                                                  \
        asm("v" OP "\t%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1));       \
      }                                                         \
    } else {                                                    \
      PURE(A, B);                                               \
    }                                                           \
  } while (0)

#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)                   \
  do {                                                               \
    if (!IsModeDbg() && X86_HAVE(ISA)) {                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "i"(I), "0"(*Xmm1));        \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#else
#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C) PURE(A, B, C)
#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)        PURE(A, B, I)
#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)          PURE(A, B, I)
#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)             PURE(A, B)
#endif /* X86 && !ANSI */



/*!BEGIN libc/intrin/newbie.h */

#define COSMOPOLITAN_LIBC_BITS_NEWBIE_H_

#define BYTE_ORDER    __BYTE_ORDER__
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define PDP_ENDIAN    __ORDER_PDP_ENDIAN__

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define htobe16(x) bswap_16(x)
#define be16toh(x) bswap_16(x)
#define betoh16(x) bswap_16(x)
#define htobe32(x) bswap_32(x)
#define be32toh(x) bswap_32(x)
#define betoh32(x) bswap_32(x)
#define htobe64(x) bswap_64(x)
#define be64toh(x) bswap_64(x)
#define betoh64(x) bswap_64(x)
#define htole16(x) (uint16_t)(x)
#define le16toh(x) (uint16_t)(x)
#define letoh16(x) (uint16_t)(x)
#define htole32(x) (uint32_t)(x)
#define le32toh(x) (uint32_t)(x)
#define letoh32(x) (uint32_t)(x)
#define htole64(x) (uint64_t)(x)
#define le64toh(x) (uint64_t)(x)
#define letoh64(x) (uint64_t)(x)
#else
#define htobe16(x) (uint16_t)(x)
#define be16toh(x) (uint16_t)(x)
#define betoh16(x) (uint16_t)(x)
#define htobe32(x) (uint32_t)(x)
#define be32toh(x) (uint32_t)(x)
#define betoh32(x) (uint32_t)(x)
#define htobe64(x) (uint64_t)(x)
#define be64toh(x) (uint64_t)(x)
#define betoh64(x) (uint64_t)(x)
#define htole16(x) bswap_16(x)
#define le16toh(x) bswap_16(x)
#define letoh16(x) bswap_16(x)
#define htole32(x) bswap_32(x)
#define le32toh(x) bswap_32(x)
#define letoh32(x) bswap_32(x)
#define htole64(x) bswap_64(x)
#define le64toh(x) bswap_64(x)
#define letoh64(x) bswap_64(x)
#endif



/*!BEGIN libc/intrin/packsswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKSSWB_H_
COSMOPOLITAN_C_START_

void packsswb(int8_t[16], const int16_t[8], const int16_t[8]);

#define packsswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packsswb, SSE2, "packsswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/packuswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKUSWB_H_
COSMOPOLITAN_C_START_

void packuswb(uint8_t[16], const int16_t[8], const int16_t[8]);

#define packuswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packuswb, SSE2, "packuswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/paddw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PADDW_H_
COSMOPOLITAN_C_START_

void paddw(int16_t[8], const int16_t[8], const int16_t[8]);

#define paddw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(paddw, SSE2, "paddw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/palignr.h */

#define COSMOPOLITAN_LIBC_INTRIN_PALIGNR_H_


/*!BEGIN libc/str/str.h */

#define COSMOPOLITAN_LIBC_STR_STR_H_

#define INVALID_CODEPOINT 0xfffd

#define _tolower(u) (0040 | (u))
#define _toupper(u) (0137 & (u))

#ifdef _COSMO_SOURCE
#define chomp         _chomp
#define chomp16       _chomp16
#define wchomp        _wchomp
#define tpenc         _tpenc
#define isutf8        _isutf8
#define istext        _istext
#define startswith    _startswith
#define startswithi   _startswithi
#define endswith      _endswith
#define wcsendswith   _wcsendswith
#define wcsstartswith _wcsstartswith
#endif /* _COSMO_SOURCE */

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

int isascii(int) libcesque;
int isspace(int) libcesque;
int isalpha(int) libcesque;
int isdigit(int) libcesque;
int isalnum(int) libcesque;
int isxdigit(int) libcesque;
int isprint(int) libcesque;
int islower(int) libcesque;
int isupper(int) libcesque;
int isblank(int) libcesque;
int iscntrl(int) libcesque;
int isgraph(int) libcesque;
int tolower(int) libcesque;
int ispunct(int) libcesque;
int toupper(int) libcesque;
int toascii(int) libcesque;

int iswalnum(wint_t) libcesque;
int iswalpha(wint_t) libcesque;
int iswblank(wint_t) libcesque;
int iswcntrl(wint_t) libcesque;
int iswdigit(wint_t) libcesque;
int iswgraph(wint_t) libcesque;
int iswlower(wint_t) libcesque;
int iswspace(wint_t) libcesque;
int iswupper(wint_t) libcesque;
int iswxdigit(wint_t) libcesque;
int iswpunct(wint_t) libcesque;
int iswprint(wint_t) libcesque;
int iswseparator(wint_t) libcesque;
wint_t towlower(wint_t) libcesque;
wint_t towupper(wint_t) libcesque;

void *memset(void *, int, size_t) memcpyesque;
void *memmove(void *, const void *, size_t) memcpyesque;
void *memcpy(void *restrict, const void *restrict, size_t) memcpyesque;
void *mempcpy(void *restrict, const void *restrict, size_t) memcpyesque;
char *hexpcpy(char *restrict, const void *restrict, size_t) memcpyesque;
void *memccpy(void *restrict, const void *restrict, int, size_t) memcpyesque;
void explicit_bzero(void *, size_t);

int memcmp(const void *, const void *, size_t) strlenesque;
int timingsafe_bcmp(const void *, const void *, size_t) libcesque;
int timingsafe_memcmp(const void *, const void *, size_t) libcesque;

size_t strlen(const char *) strlenesque;
size_t strnlen(const char *, size_t) strlenesque;
size_t strnlen_s(const char *, size_t) libcesque;
char *strchr(const char *, int) strlenesque;
void *memchr(const void *, int, size_t) strlenesque;
char *strchrnul(const char *, int) strlenesque returnsnonnull;
void *rawmemchr(const void *, int) strlenesque returnsnonnull;
size_t wcslen(const wchar_t *) strlenesque;
size_t wcsnlen(const wchar_t *, size_t) strlenesque;
size_t wcsnlen_s(const wchar_t *, size_t) libcesque;
wchar_t *wcschr(const wchar_t *, wchar_t) strlenesque;
wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) strlenesque;
wchar_t *wcschrnul(const wchar_t *, wchar_t)
strlenesque returnsnonnull;
char *strstr(const char *, const char *) strlenesque;
char *strcasestr(const char *, const char *) strlenesque;
wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque;
int strcmp(const char *, const char *) strlenesque;
int strncmp(const char *, const char *, size_t) strlenesque;
int wcscmp(const wchar_t *, const wchar_t *) strlenesque;
int wcsncmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int wmemcmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int strcasecmp(const char *, const char *) strlenesque;
int memcasecmp(const void *, const void *, size_t) strlenesque;
int wcscasecmp(const wchar_t *, const wchar_t *) strlenesque;
int strncasecmp(const char *, const char *, size_t) strlenesque;
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
char *strrchr(const char *, int) strlenesque;
void *memrchr(const void *, int, size_t) strlenesque;
wchar_t *wcsrchr(const wchar_t *, wchar_t) strlenesque;
void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque;
char *strpbrk(const char *, const char *) strlenesque;
wchar_t *wcspbrk(const wchar_t *, const wchar_t *) strlenesque;
size_t strspn(const char *, const char *) strlenesque;
size_t wcsspn(const wchar_t *, const wchar_t *) strlenesque;
size_t strcspn(const char *, const char *) strlenesque;
size_t wcscspn(const wchar_t *, const wchar_t *) strlenesque;
void *memfrob(void *, size_t) memcpyesque;
int strcoll(const char *, const char *) strlenesque;
char *strsep(char **, const char *) libcesque paramsnonnull();
char *stpcpy(char *, const char *) memcpyesque;
char *stpncpy(char *, const char *, size_t) memcpyesque;
char *strcat(char *, const char *) memcpyesque;
wchar_t *wcscat(wchar_t *, const wchar_t *) memcpyesque;
size_t strlcpy(char *, const char *, size_t) libcesque;
size_t strlcat(char *, const char *, size_t) libcesque;
size_t strxfrm(char *, const char *, size_t) libcesque;
char *strcpy(char *, const char *) memcpyesque;
wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque;
char *strncat(char *, const char *, size_t) memcpyesque;
wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t) memcpyesque;
char *strncpy(char *, const char *, size_t) memcpyesque;
char *strtok(char *, const char *) paramsnonnull((2)) libcesque;
char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
int strverscmp(const char *, const char *) libcesque;
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
void *memmem(const void *, size_t, const void *, size_t)
libcesque nosideeffect;
ssize_t strfmon(char *, size_t, const char *, ...) libcesque;
long a64l(const char *) libcesque;
char *l64a(long) libcesque;

typedef unsigned mbstate_t;

wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t) libcesque;
int mbtowc(wchar_t *, const char *, size_t) libcesque;
size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *) libcesque;
size_t mbstowcs(wchar_t *, const char *, size_t) libcesque;
size_t wcrtomb(char *, wchar_t, mbstate_t *) libcesque;
size_t c32rtomb(char *, char32_t, mbstate_t *) libcesque;
size_t mbrtoc32(char32_t *, const char *, size_t, mbstate_t *) libcesque;
size_t c16rtomb(char *, char16_t, mbstate_t *) libcesque;
size_t mbrtoc16(char16_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbrlen(const char *, size_t, mbstate_t *) libcesque;
size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *);
size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *);
size_t wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *) libcesque;
size_t wcstombs(char *, const wchar_t *, size_t) libcesque;
int mbsinit(const mbstate_t *) libcesque;
int mblen(const char *, size_t) libcesque;
int wctomb(char *, wchar_t) libcesque;
int wctob(wint_t) libcesque;
wint_t btowc(int) libcesque;

typedef unsigned wctype_t;
wctype_t wctype(const char *) strlenesque;
pureconst int iswctype(wint_t, wctype_t) libcesque;

typedef const int *wctrans_t;
wctrans_t wctrans(const char *) libcesque;
wint_t towctrans(wint_t, wctrans_t) libcesque;

int getsubopt(char **, char *const *, char **) libcesque paramsnonnull();
char *strsignal(int) returnsnonnull libcesque;
char *strerror(int) returnsnonnull dontthrow dontcallback;
errno_t strerror_r(int, char *, size_t) libcesque;
char *__xpg_strerror_r(int, char *, size_t) libcesque;

#ifdef _COSMO_SOURCE
pureconst uint64_t tpenc(uint32_t) libcesque;
char *chomp(char *) libcesque;
wchar_t *wchomp(wchar_t *) libcesque;
uint64_t __fnv(const void *, size_t) strlenesque;
bool32 startswith(const char *, const char *) strlenesque;
bool32 startswithi(const char *, const char *) strlenesque;
bool32 endswith(const char *, const char *) strlenesque;
bool32 istext(const void *, size_t) libcesque;
bool32 isutf8(const void *, size_t) libcesque;
const char *strsignal_r(int, char[21]) returnsnonnull libcesque __wur;
char16_t *chomp16(char16_t *) libcesque;
size_t strlen16(const char16_t *) strlenesque;
size_t strnlen16(const char16_t *, size_t) strlenesque;
char16_t *strchr16(const char16_t *, int) strlenesque;
void *memchr16(const void *, int, size_t) strlenesque;
char16_t *strchrnul16(const char16_t *, int) strlenesque returnsnonnull;
void *rawmemchr16(const void *, int) strlenesque returnsnonnull;
char16_t *strstr16(const char16_t *, const char16_t *) strlenesque;
int strcmp16(const char16_t *, const char16_t *) strlenesque;
int strncmp16(const char16_t *, const char16_t *, size_t) strlenesque;
int strcasecmp16(const char16_t *, const char16_t *) strlenesque;
int strncasecmp16(const char16_t *, const char16_t *, size_t) strlenesque;
char16_t *strrchr16(const char16_t *, int) strlenesque;
void *memrchr16(const void *, int, size_t) strlenesque;
char16_t *strpbrk16(const char16_t *, const char16_t *) strlenesque;
size_t strspn16(const char16_t *, const char16_t *) strlenesque;
size_t strcspn16(const char16_t *, const char16_t *) strlenesque;
char16_t *strcat16(char16_t *, const char16_t *) memcpyesque;
char16_t *strcpy16(char16_t *, const char16_t *) memcpyesque;
char16_t *strncat16(char16_t *, const char16_t *, size_t) memcpyesque;
char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque;
bool32 startswith16(const char16_t *, const char16_t *) strlenesque;
bool32 endswith16(const char16_t *, const char16_t *) strlenesque;
axdx_t tprecode8to16(char16_t *, size_t, const char *) libcesque;
axdx_t tprecode16to8(char *, size_t, const char16_t *) libcesque;
bool32 wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
bool32 wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
char *__join_paths(char *, size_t, const char *, const char *) libcesque __wur;
int __mkntpathat(int, const char *, int, char16_t[hasatleast 1024]);
#endif /* _COSMO_SOURCE */

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_POSIX_SOURCE) ||                                                 \
    (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE + 0 < 200809L) ||            \
    (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE + 0 < 700)
int bcmp(const void *, const void *, size_t) strlenesque;
void bcopy(const void *, void *, size_t) memcpyesque;
void bzero(void *, size_t) memcpyesque;
char *index(const char *, int) strlenesque;
char *rindex(const char *, int) strlenesque;
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

void palignr(void *, const void *, const void *, unsigned long);

#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__)
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
#define palignr(C, B, A, I)                                                \
  do {                                                                     \
    if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSSE3), \
                         1)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(C);                                  \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);            \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(A);            \
      if (__builtin_constant_p(I)) {                                       \
        if (!X86_NEED(AVX)) {                                              \
          asm("palignr\t%2,%1,%0"                                          \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm2), "i"(I), "0"(*Xmm1));                           \
        } else {                                                           \
          asm("vpalignr\t%3,%2,%1,%0"                                      \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm1), "x"(*Xmm2), "i"(I));                           \
        }                                                                  \
      } else {                                                             \
        unsigned long Vimm = (I);                                          \
        typeof(__palignrs) *Fn;                                            \
        if (__builtin_expect(Vimm < 32, 1)) {                              \
          Fn = (typeof(__palignrs) *)((uintptr_t)&__palignrs + Vimm * 8);  \
          *Xmm0 = Fn(*Xmm1, *Xmm2);                                        \
        } else {                                                           \
          memset(Xmm0, 0, 16);                                             \
        }                                                                  \
      }                                                                    \
    } else {                                                               \
      palignr(C, B, A, I);                                                 \
    }                                                                      \
  } while (0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pandn.h */

#define COSMOPOLITAN_LIBC_INTRIN_PANDN_H_
COSMOPOLITAN_C_START_

void pandn(uint64_t[2], const uint64_t[2], const uint64_t[2]);

#define pandn(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pandn, SSE2, "pandn", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTB_H_
COSMOPOLITAN_C_START_

void pcmpgtb(int8_t[16], const int8_t[16], const int8_t[16]);

#define pcmpgtb(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtb, SSE2, "pcmpgtb", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTW_H_
COSMOPOLITAN_C_START_

void pcmpgtw(int16_t[8], const int16_t[8], const int16_t[8]);

#define pcmpgtw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtw, SSE2, "pcmpgtw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmaddubsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMADDUBSW_H_
COSMOPOLITAN_C_START_

void pmaddubsw(int16_t[8], const uint8_t[16], const int8_t[16]);

#define pmaddubsw(W, B, C)                                                   \
  INTRIN_SSEVEX_X_X_X_(pmaddubsw, SSSE3, "pmaddubsw", INTRIN_NONCOMMUTATIVE, \
                       W, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmovmskb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMOVMSKB_H_
COSMOPOLITAN_C_START_

uint32_t pmovmskb(const uint8_t[16]);

#if defined(__x86_64__) && defined(__GNUC__)
#define pmovmskb(A)                                            \
  ({                                                           \
    uint32_t Mask;                                             \
    if (!IsModeDbg() && X86_HAVE(SSE2)) {                      \
      const __intrin_xmm_t *Xmm = (const __intrin_xmm_t *)(A); \
      if (!X86_NEED(AVX)) {                                    \
        asm("pmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));       \
      } else {                                                 \
        asm("vpmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));      \
      }                                                        \
    } else {                                                   \
      Mask = pmovmskb(A);                                      \
    }                                                          \
    Mask;                                                      \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmulhrsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMULHRSW_H_
COSMOPOLITAN_C_START_

void pmulhrsw(int16_t a[8], const int16_t b[8], const int16_t c[8]);

#define pmulhrsw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pmulhrsw, SSSE3, "pmulhrsw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/popcnt.h */

#define COSMOPOLITAN_LIBC_BITS_POPCNT_H_
COSMOPOLITAN_C_START_

libcesque size_t _countbits(const void *, size_t);
libcesque unsigned long popcnt(unsigned long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define popcnt(X)                                                \
  (__builtin_constant_p(X) ? __builtin_popcountll(X) : ({        \
    unsigned long PoP = (X);                                     \
    if (X86_HAVE(POPCNT)) {                                      \
      asm("popcnt\t%0,%0" : "+r"(PoP) : /* no inputs */ : "cc"); \
    } else {                                                     \
      PoP = (popcnt)(PoP);                                       \
    }                                                            \
    PoP;                                                         \
  }))
#else
#define popcnt(x) __builtin_popcountll(x)
#endif /* GNUC && !ANSI */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/psraw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PSRAW_H_
COSMOPOLITAN_C_START_

void psraw(int16_t[8], const int16_t[8], unsigned char) libcesque;
void psrawv(int16_t[8], const int16_t[8], const uint64_t[2]) libcesque;

#define psraw(A, B, I) INTRIN_SSEVEX_X_I_(psraw, SSE2, "psraw", A, B, I)
#define psrawv(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(psrawv, SSE2, "psraw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHBW_H_
COSMOPOLITAN_C_START_

void punpckhbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpckhbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhbw, SSE2, "punpckhbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHWD_H_
COSMOPOLITAN_C_START_

void punpckhwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpckhwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhwd, SSE2, "punpckhwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLBW_H_
COSMOPOLITAN_C_START_

void punpcklbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpcklbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklbw, SSE2, "punpcklbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLWD_H_
COSMOPOLITAN_C_START_

void punpcklwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpcklwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklwd, SSE2, "punpcklwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/repmovsb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
#ifdef _COSMO_SOURCE

forceinline void repmovsb(void **dest, const void **src, size_t cx) {
  char *di = (char *)*dest;
  const char *si = (const char *)*src;
  while (cx) *di++ = *si++, cx--;
  *dest = di, *src = si;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repmovsb(DI, SI, CX)                                       \
  ({                                                               \
    void *Di = *(DI);                                              \
    const void *Si = *(SI);                                        \
    size_t Cx = (CX);                                              \
    asm("rep movsb"                                                \
        : "=D"(Di), "=S"(Si), "=c"(Cx), "=m"(*(char(*)[Cx])Di)     \
        : "0"(Di), "1"(Si), "2"(Cx), "m"(*(const char(*)[Cx])Si)); \
    *(DI) = Di, *(SI) = Si;                                        \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/repstosb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
#ifdef _COSMO_SOURCE

forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
  unsigned char *di = (unsigned char *)dest;
  while (cx) *di++ = al, cx--;
  return di;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repstosb(DI, AL, CX)                         \
  ({                                                 \
    void *Di = (DI);                                 \
    size_t Cx = (CX);                                \
    unsigned char Al = (AL);                         \
    asm("rep stosb %b5,(%0)"                         \
        : "=D"(Di), "=c"(Cx), "=m"(*(char(*)[Cx])Di) \
        : "0"(Di), "1"(Cx), "a"(Al));                \
    Di;                                              \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/ubsan.h */

#define COSMOPOLITAN_LIBC_INTRIN_UBSAN_H_
COSMOPOLITAN_C_START_

extern bool32 __ubsan_strict;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/ulock.h */

#define COSMOPOLITAN_ULOCK_H_
COSMOPOLITAN_C_START_

/* both wake and wait take one of these */
#define UL_COMPARE_AND_WAIT          1 /* multi-thread */
#define UL_UNFAIR_LOCK               2
#define UL_COMPARE_AND_WAIT_SHARED   3 /* multi-thread/process */
#define UL_UNFAIR_LOCK64_SHARED      4
#define UL_COMPARE_AND_WAIT64        5
#define UL_COMPARE_AND_WAIT64_SHARED 6

#define ULF_WAKE_ALL             0x00000100
#define ULF_WAKE_THREAD          0x00000200 /* takes wake_value */
#define ULF_WAKE_ALLOW_NON_OWNER 0x00000400

#define ULF_WAIT_WORKQ_DATA_CONTENTION 0x00010000
#define ULF_WAIT_CANCEL_POINT          0x00020000 /* raises eintr */
#define ULF_WAIT_ADAPTIVE_SPIN         0x00040000

int ulock_wake(uint32_t, void *, uint64_t) libcesque;
int ulock_wait(uint32_t, void *, uint64_t, uint32_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/weaken.h */

#define COSMOPOLITAN_LIBC_BITS_WEAKEN_H_

#ifndef __chibicc__
#define _weaken(symbol)                                         \
  __extension__({                                               \
    extern __typeof__(symbol) symbol __attribute__((__weak__)); \
    &symbol;                                                    \
  })
#else
#define _weaken(symbol) (&(symbol))
#endif



/*!BEGIN libc/intrin/x86.h */

#define COSMOPOLITAN_LIBC_INTRIN_X86_H_
COSMOPOLITAN_C_START_

enum VendorSignatures {
  SIG_INTEL = 0x756e6547, /* Genu */
  SIG_AMD = 0x68747541,   /* Auth */
};

enum ProcessorVendors {
  VENDOR_INTEL = 1,
  VENDOR_AMD,
  VENDOR_OTHER,
  VENDOR_MAX
};

enum ProcessorTypes {
  INTEL_BONNELL = 1,
  INTEL_CORE2,
  INTEL_COREI7,
  AMDFAM10H,
  AMDFAM15H,
  INTEL_SILVERMONT,
  INTEL_KNL,
  AMD_BTVER1,
  AMD_BTVER2,
  AMDFAM17H,
  INTEL_KNM,
  INTEL_GOLDMONT,
  INTEL_GOLDMONT_PLUS,
  INTEL_TREMONT,
  AMDFAM19H,
  ZHAOXIN_FAM7H,
  INTEL_SIERRAFOREST,
  INTEL_GRANDRIDGE,
  INTEL_CLEARWATERFOREST,
  CPU_TYPE_MAX
};

enum ProcessorSubtypes {
  INTEL_COREI7_NEHALEM = 1,
  INTEL_COREI7_WESTMERE,
  INTEL_COREI7_SANDYBRIDGE,
  AMDFAM10H_BARCELONA,
  AMDFAM10H_SHANGHAI,
  AMDFAM10H_ISTANBUL,
  AMDFAM15H_BDVER1,
  AMDFAM15H_BDVER2,
  AMDFAM15H_BDVER3,
  AMDFAM15H_BDVER4,
  AMDFAM17H_ZNVER1,
  INTEL_COREI7_IVYBRIDGE,
  INTEL_COREI7_HASWELL,
  INTEL_COREI7_BROADWELL,
  INTEL_COREI7_SKYLAKE,
  INTEL_COREI7_SKYLAKE_AVX512,
  INTEL_COREI7_CANNONLAKE,
  INTEL_COREI7_ICELAKE_CLIENT,
  INTEL_COREI7_ICELAKE_SERVER,
  AMDFAM17H_ZNVER2,
  INTEL_COREI7_CASCADELAKE,
  INTEL_COREI7_TIGERLAKE,
  INTEL_COREI7_COOPERLAKE,
  INTEL_COREI7_SAPPHIRERAPIDS,
  INTEL_COREI7_ALDERLAKE,
  AMDFAM19H_ZNVER3,
  INTEL_COREI7_ROCKETLAKE,
  ZHAOXIN_FAM7H_LUJIAZUI,
  AMDFAM19H_ZNVER4,
  INTEL_COREI7_GRANITERAPIDS,
  INTEL_COREI7_GRANITERAPIDS_D,
  INTEL_COREI7_ARROWLAKE,
  INTEL_COREI7_ARROWLAKE_S,
  INTEL_COREI7_PANTHERLAKE,
  CPU_SUBTYPE_MAX
};

enum ProcessorFeatures {
  FEATURE_CMOV = 0,
  FEATURE_MMX,
  FEATURE_POPCNT,
  FEATURE_SSE,
  FEATURE_SSE2,
  FEATURE_SSE3,
  FEATURE_SSSE3,
  FEATURE_SSE4_1,
  FEATURE_SSE4_2,
  FEATURE_AVX,
  FEATURE_AVX2,
  FEATURE_SSE4_A,
  FEATURE_FMA4,
  FEATURE_XOP,
  FEATURE_FMA,
  FEATURE_AVX512F,
  FEATURE_BMI,
  FEATURE_BMI2,
  FEATURE_AES,
  FEATURE_PCLMUL,
  FEATURE_AVX512VL,
  FEATURE_AVX512BW,
  FEATURE_AVX512DQ,
  FEATURE_AVX512CD,
  FEATURE_AVX512ER,
  FEATURE_AVX512PF,
  FEATURE_AVX512VBMI,
  FEATURE_AVX512IFMA,
  FEATURE_AVX5124VNNIW,
  FEATURE_AVX5124FMAPS,
  FEATURE_AVX512VPOPCNTDQ,
  FEATURE_AVX512VBMI2,
  FEATURE_GFNI,
  FEATURE_VPCLMULQDQ,
  FEATURE_AVX512VNNI,
  FEATURE_AVX512BITALG,
  FEATURE_AVX512BF16,
  FEATURE_AVX512VP2INTERSECT,

  FEATURE_CMPXCHG16B = 46,
  FEATURE_F16C = 49,
  FEATURE_LAHF_LM = 54,
  FEATURE_LM,
  FEATURE_WP,
  FEATURE_LZCNT,
  FEATURE_MOVBE,

  FEATURE_AVX512FP16 = 94,
  FEATURE_X86_64_BASELINE,
  FEATURE_X86_64_V2,
  FEATURE_X86_64_V3,
  FEATURE_X86_64_V4,
  CPU_FEATURE_MAX
};

struct __processor_model {
  unsigned __cpu_vendor;
  unsigned __cpu_type;
  unsigned __cpu_subtype;
  unsigned __cpu_features[1];
  const char *__cpu_march;
};

extern struct __processor_model __cpu_model;

const char *__cpu_march(unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/bsd.h */

#define COSMOPOLITAN_LIBC_LOG_BSD_H_
COSMOPOLITAN_C_START_

void err(int, const char *, ...) wontreturn;
void verr(int, const char *, va_list) wontreturn;
void errc(int, int, const char *, ...) wontreturn;
void verrc(int, int, const char *, va_list) wontreturn;
void errx(int, const char *, ...) wontreturn;
void verrx(int, const char *, va_list) wontreturn;
void warn(const char *, ...);
void vwarn(const char *, va_list);
void warnc(int, const char *, ...);
void vwarnc(int, const char *, va_list);
void warnx(const char *, ...);
void vwarnx(const char *, va_list);
void err_set_exit(void (*)(int));

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/check.h */

#define COSMOPOLITAN_LIBC_LOG_CHECK_H_
COSMOPOLITAN_C_START_

#define CHECK(X, ...)         __CHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define CHECK_EQ(Y, X, ...)   __CHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NE(Y, X, ...)   __CHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LE(Y, X, ...)   __CHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LT(Y, X, ...)   __CHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GE(Y, X, ...)   __CHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GT(Y, X, ...)   __CHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NOTNULL(X, ...) __CHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define DCHECK(X, ...)       __DCHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define DCHECK_EQ(Y, X, ...) __DCHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NE(Y, X, ...) __DCHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LE(Y, X, ...) __DCHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LT(Y, X, ...) __DCHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GE(Y, X, ...) __DCHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GT(Y, X, ...) __DCHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NOTNULL(X, ...) \
  __DCHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define CHECK_ALIGNED(BYTES, VAR, ...)                                \
  do {                                                                \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                            \
      __check_fail_aligned(BYTES, (uintptr_t)VAR, __FILE__, __LINE__, \
                           "" __VA_ARGS__);                           \
      __builtin_unreachable();                                        \
    }                                                                 \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES);          \
  } while (0)

#define DCHECK_ALIGNED(BYTES, VAR, ...)                      \
  do {                                                       \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                   \
      __DCHK_ALIGNED(BYTES, (uintptr_t)VAR, "" __VA_ARGS__); \
      __builtin_unreachable();                               \
    }                                                        \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES); \
  } while (0)

#define __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...)                   \
  do {                                                                       \
    autotype(GOT) Got = (GOT);                                               \
    autotype(WANT) Want = (WANT);                                            \
    if (!(Want OP Got)) {                                                    \
      if (!NoDebug()) {                                                      \
        __check_fail(#SUFFIX, #OP, (uint64_t)Want, (WANTSTR), (uint64_t)Got, \
                     (GOTSTR), __FILE__, __LINE__, __VA_ARGS__);             \
      } else {                                                               \
        __check_fail_##SUFFIX((uint64_t)Want, (uint64_t)Got, __FILE__,       \
                              __LINE__, 0, __VA_ARGS__);                     \
      }                                                                      \
      __builtin_unreachable();                                               \
    }                                                                        \
  } while (0)

#ifdef NDEBUG
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, ...) \
  do {                                              \
    autotype(GOT) Got = (GOT);                      \
    autotype(WANT) Want = (WANT);                   \
    if (!(Want OP Got)) {                           \
      __builtin_unreachable();                      \
    }                                               \
  } while (0)
#else
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \
  __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, __VA_ARGS__)
#endif /* NDEBUG */

#ifdef NDEBUG
#define __DCHK_ALIGNED(BYTES, VAR, ...)
#else
#define __DCHK_ALIGNED(BYTES, VAR, ...) \
  __check_fail_aligned(BYTES, VAR, __FILE__, __LINE__, __VA_ARGS__)
#endif

void __check_fail(const char *, const char *, uint64_t, const char *, uint64_t,
                  const char *, const char *, int, const char *,
                  ...) relegated wontreturn;

void __check_fail_eq(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ne(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_le(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_lt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ge(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_gt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_aligned(unsigned, uint64_t, const char *, int, const char *,
                          ...) relegated wontreturn;

#ifdef __VSCODE_INTELLISENSE__
#undef __CHK
#define __CHK(...)
#undef __DCHK
#define __DCHK(...)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countbranch.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTBRANCH_H_
COSMOPOLITAN_C_START_

#define COUNTBRANCH(x) COUNTBRANCH_(x, #x, STRINGIFY(__FILE__), __LINE__)
#define COUNTBRANCH_(x, xs, file, line) \
  COUNTBRANCH__(x, STRINGIFY(xs), STRINGIFY(xs), file, line)
#define COUNTBRANCH__(x, xs, xss, file, line)                   \
  ({                                                            \
    bool Cond;                                                  \
    struct countbranch *Info;                                   \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31338:\t"                                              \
        ".asciz\t" xs "\n"                                      \
        "31339:\t"                                              \
        ".asciz\t" xss "\n"                                     \
        "31340:\t"                                              \
        ".asciz\t" file "\n\t"                                  \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountbranch_data(%%rip)\n\t"                     \
        ".previous\n\t"                                         \
        ".section .sort.data.countbranch.2,\"a\",@progbits\n\t" \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t0\n\t"                                          \
        ".quad\t0\n\t"                                          \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31339b\n\t"                                     \
        ".quad\t31340b\n\t"                                     \
        ".quad\t" #line "\n\t"                                  \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(Info));                                          \
    Cond = (x);                                                 \
    ++Info->total;                                              \
    if (Cond) ++Info->taken;                                    \
    Cond;                                                       \
  })

struct countbranch {
  long total;
  long taken;
  const char *code;
  const char *xcode;
  const char *file;
  long line;
};

extern struct countbranch countbranch_data[];

void countbranch_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countexpr.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_


/*!BEGIN libc/nexgen32e/bench.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_BENCH_H_


/*!BEGIN libc/nexgen32e/rdtsc.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSC_H_
COSMOPOLITAN_C_START_

/**
 * Reads CPU timestamp counter.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(INVTSC)
 */
#define rdtsc() __RDTSC("rdtsc")

/**
 * Reads CPU timestamp counter w/ full serialization.
 *
 * This macro inhibits CPU magic.
 * This macro inhibits compiler magic.
 *
 * The clock isn't read until:
 *
 *   1. previous instructions finish executing; and
 *   2. previous loads are globally visible; and
 *   3. previous stores are globally visible.
 *
 * Later instructions won't dispatch until RDTSC completes.
 *
 * @see X86_HAVE(INVTSC)
 */
#define mfence_lfence_rdtsc_lfence() \
  __RDTSC("mfence\n\tlfence\n\trdtsc\n\tlfence")

#ifdef __x86__
#define __RDTSC(ASM)                                                       \
  ({                                                                       \
    uint64_t Rax, Rdx;                                                     \
    asm volatile(ASM : "=a"(Rax), "=d"(Rdx) : /* no inputs */ : "memory"); \
    Rdx << 32 | Rax;                                                       \
  })
#elif defined(__aarch64__)
#define __RDTSC(ASM)                                \
  ({                                                \
    uint64_t _Ts;                                   \
    asm volatile("mrs\t%0,cntvct_el0" : "=r"(_Ts)); \
    _Ts * 48; /* the fudge factor */                \
  })
#elif defined(__powerpc64__)
#define __RDTSC(ASM)                           \
  ({                                           \
    uint64_t _Ts;                              \
    asm volatile("mfspr\t%0,268" : "=r"(_Ts)); \
    _Ts;                                       \
  })
#elif defined(__riscv)
#define __RDTSC(ASM)                         \
  ({                                         \
    uint64_t _Ts;                            \
    asm volatile("rdcycle\t%0" : "=r"(_Ts)); \
    _Ts;                                     \
  })
#endif

COSMOPOLITAN_C_END_

/**
 * @fileoverview NexGen32e Microbenchmarking.
 *
 * @see X86_HAVE(INVTSC)
 * @see libc/testlib/bench.h
 */

#ifdef __x86__
#define __startbench()                            \
  ({                                              \
    uint64_t Ticks;                               \
    asm volatile("lfence\n\t"                     \
                 "push\t%%rbx\n\t"                \
                 "cpuid\n\t"                      \
                 "pop\t%%rbx\n\t"                 \
                 "rdtsc\n\t"                      \
                 "shl\t%2,%%rdx\n\t"              \
                 "or\t%%rdx,%0"                   \
                 : "=a"(Ticks)                    \
                 : "0"(0), "J"(32)                \
                 : "rcx", "rdx", "memory", "cc"); \
    Ticks;                                        \
  })
#define __endbench()                                     \
  ({                                                     \
    uint64_t Ticks;                                      \
    asm volatile("rdtscp\n\t"                            \
                 "shl\t%1,%%rdx\n\t"                     \
                 "or\t%%rdx,%%rax\n\t"                   \
                 "mov\t%%rax,%0\n\t"                     \
                 "xor\t%%eax,%%eax\n\t"                  \
                 "push\t%%rbx\n\t"                       \
                 "cpuid\n\t"                             \
                 "pop\t%%rbx"                            \
                 : "=r"(Ticks)                           \
                 : "J"(32)                               \
                 : "rax", "rcx", "rdx", "memory", "cc"); \
    Ticks;                                               \
  })
#else
#define __startbench()                \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#define __endbench()                  \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#endif

#define __startbench_m() mfence_lfence_rdtsc_lfence()
#define __endbench_m()   __startbench_m()
#define __marker()       asm("nop")
#define __ordered()      asm volatile("" ::: "memory")
#define __fakeread(X)    asm volatile("" : /* no outputs */ : "g"(X))
#define __fakereadwrite(X)                 \
  ({                                       \
    autotype(X) Res = (X);                 \
    asm volatile("" : "=g"(Res) : "0"(X)); \
    Res;                                   \
  })

COSMOPOLITAN_C_START_

/**
 * Shows nanosecond timings histogram for expr at exit().
 */
#define COUNTEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, rdtsc, rdtsc, \
             "COUNTEXPR")

/**
 * Like COUNTEXPR() but can be used on function calls that return void.
 */
#define COUNTSTMT(stmt)                                                    \
  (void)COUNTEXPR_((stmt, 0), #stmt, STRINGIFY(__FILE__), __LINE__, rdtsc, \
                   rdtsc, "COUNTSTMT")

/**
 * Same as COUNTEXPR() but uses Intel's expensive measurement technique.
 */
#define BENCHEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, __startbench, \
             __endbench, "BENCHEXPR")

#define COUNTEXPR_(expr, code, file, line, start, stop, macro) \
  COUNTEXPR__(expr, STRINGIFY(code), file, line, start, stop, STRINGIFY(macro))

#define COUNTEXPR__(expr, code, file, line, start, stop, macro) \
  ({                                                            \
    struct countexpr *InfO;                                     \
    uint64_t t1_, t2_, TiCkS, NaNoS;                            \
    t1_ = start();                                              \
    asm volatile("" ::: "memory");                              \
    autotype(expr) ReS = (expr);                                \
    asm volatile("" ::: "memory");                              \
    t2_ = stop();                                               \
    TiCkS = t2_ >= t1_ ? t2_ - t1_ : ~t1_ + t2_ + 1;            \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31340:\t.asciz\t" file "\n\t"                          \
        "31338:\t.asciz\t" code "\n"                            \
        "31332:\t.asciz\t" macro "\n"                           \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountexpr_data(%%rip)\n\t"                       \
        ".previous\n\t"                                         \
        ".section .sort.data.countexpr.2,\"a\",@progbits\n\t"   \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t" #line "\n\t"                                  \
        ".quad\t31340b\n\t"                                     \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31332b\n\t"                                     \
        ".rept\t65\n\t"                                         \
        ".quad\t0\n\t"                                          \
        ".endr\n\t"                                             \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(InfO));                                          \
    /* approximation of round(x*.323018) which is usually */    \
    /* the ratio, between x86 rdtsc ticks and nanoseconds */    \
    NaNoS = (TiCkS * 338709) >> 20;                             \
    ++InfO->logos[NaNoS ? bsrl(NaNoS) + 1 : 0];                 \
    ReS;                                                        \
  })

struct countexpr {
  long line; /* zero for last entry */
  const char *file;
  const char *code;
  const char *macro;
  long logos[65];
};

extern struct countexpr countexpr_data[];

void countexpr_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/gdb.h */

#define COSMOPOLITAN_LIBC_LOG_GDB_H_


/*!BEGIN libc/sysv/consts/nr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NR_H_
#ifdef _COSMO_SOURCE
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __NR_exit;
extern const int __NR_exit_group;
extern const int __NR_read;
extern const int __NR_write;
extern const int __NR_open;
extern const int __NR_close;
extern const int __NR_stat;
extern const int __NR_fstat;
extern const int __NR_lstat;
extern const int __NR_poll;
extern const int __NR_ppoll;
extern const int __NR_lseek;
extern const int __NR_mmap;
extern const int __NR_msync;
extern const int __NR_mprotect;
extern const int __NR_munmap;
extern const int __NR_sigaction;
extern const int __NR_sigprocmask;
extern const int __NR_ioctl;
extern const int __NR_pread;
extern const int __NR_pwrite;
extern const int __NR_readv;
extern const int __NR_writev;
extern const int __NR_access;
extern const int __NR_pipe;
extern const int __NR_select;
extern const int __NR_pselect;
extern const int __NR_pselect6;
extern const int __NR_sched_yield;
extern const int __NR_mremap;
extern const int __NR_mincore;
extern const int __NR_madvise;
extern const int __NR_shmget;
extern const int __NR_shmat;
extern const int __NR_shmctl;
extern const int __NR_dup;
extern const int __NR_dup2;
extern const int __NR_pause;
extern const int __NR_nanosleep;
extern const int __NR_getitimer;
extern const int __NR_setitimer;
extern const int __NR_alarm;
extern const int __NR_getpid;
extern const int __NR_sendfile;
extern const int __NR_socket;
extern const int __NR_connect;
extern const int __NR_accept;
extern const int __NR_sendto;
extern const int __NR_recvfrom;
extern const int __NR_sendmsg;
extern const int __NR_recvmsg;
extern const int __NR_shutdown;
extern const int __NR_bind;
extern const int __NR_listen;
extern const int __NR_getsockname;
extern const int __NR_getpeername;
extern const int __NR_socketpair;
extern const int __NR_setsockopt;
extern const int __NR_getsockopt;
extern const int __NR_fork;
extern const int __NR_vfork;
extern const int __NR_posix_spawn;
extern const int __NR_execve;
extern const int __NR_wait4;
extern const int __NR_kill;
extern const int __NR_killpg;
extern const int __NR_clone;
extern const int __NR_tkill;
extern const int __NR_futex;
extern const int __NR_set_robust_list;
extern const int __NR_get_robust_list;
extern const int __NR_uname;
extern const int __NR_semget;
extern const int __NR_semop;
extern const int __NR_semctl;
extern const int __NR_shmdt;
extern const int __NR_msgget;
extern const int __NR_msgsnd;
extern const int __NR_msgrcv;
extern const int __NR_msgctl;
extern const int __NR_fcntl;
extern const int __NR_flock;
extern const int __NR_fsync;
extern const int __NR_fdatasync;
extern const int __NR_truncate;
extern const int __NR_ftruncate;
extern const int __NR_getcwd;
extern const int __NR_chdir;
extern const int __NR_fchdir;
extern const int __NR_rename;
extern const int __NR_mkdir;
extern const int __NR_rmdir;
extern const int __NR_creat;
extern const int __NR_link;
extern const int __NR_unlink;
extern const int __NR_symlink;
extern const int __NR_readlink;
extern const int __NR_chmod;
extern const int __NR_fchmod;
extern const int __NR_chown;
extern const int __NR_fchown;
extern const int __NR_lchown;
extern const int __NR_umask;
extern const int __NR_gettimeofday;
extern const int __NR_getrlimit;
extern const int __NR_getrusage;
extern const int __NR_sysinfo;
extern const int __NR_times;
extern const int __NR_ptrace;
extern const int __NR_syslog;
extern const int __NR_getuid;
extern const int __NR_getgid;
extern const int __NR_getppid;
extern const int __NR_getpgrp;
extern const int __NR_setsid;
extern const int __NR_getsid;
extern const int __NR_getpgid;
extern const int __NR_setpgid;
extern const int __NR_geteuid;
extern const int __NR_getegid;
extern const int __NR_getgroups;
extern const int __NR_setgroups;
extern const int __NR_setreuid;
extern const int __NR_setregid;
extern const int __NR_setuid;
extern const int __NR_setgid;
extern const int __NR_setresuid;
extern const int __NR_setresgid;
extern const int __NR_getresuid;
extern const int __NR_getresgid;
extern const int __NR_sigpending;
extern const int __NR_sigsuspend;
extern const int __NR_sigaltstack;
extern const int __NR_mknod;
extern const int __NR_mknodat;
extern const int __NR_mkfifo;
extern const int __NR_mkfifoat;
extern const int __NR_statfs;
extern const int __NR_fstatfs;
extern const int __NR_getpriority;
extern const int __NR_setpriority;
extern const int __NR_mlock;
extern const int __NR_munlock;
extern const int __NR_mlockall;
extern const int __NR_munlockall;
extern const int __NR_setrlimit;
extern const int __NR_chroot;
extern const int __NR_sync;
extern const int __NR_acct;
extern const int __NR_settimeofday;
extern const int __NR_mount;
extern const int __NR_reboot;
extern const int __NR_quotactl;
extern const int __NR_setfsuid;
extern const int __NR_setfsgid;
extern const int __NR_capget;
extern const int __NR_capset;
extern const int __NR_sigtimedwait;
extern const int __NR_sigqueueinfo;
extern const int __NR_personality;
extern const int __NR_ustat;
extern const int __NR_sysfs;
extern const int __NR_sched_setparam;
extern const int __NR_sched_getparam;
extern const int __NR_sched_setscheduler;
extern const int __NR_sched_getscheduler;
extern const int __NR_sched_get_priority_max;
extern const int __NR_sched_get_priority_min;
extern const int __NR_sched_rr_get_interval;
extern const int __NR_vhangup;
extern const int __NR_modify_ldt;
extern const int __NR_pivot_root;
extern const int __NR__sysctl;
extern const int __NR_prctl;
extern const int __NR_arch_prctl;
extern const int __NR_adjtimex;
extern const int __NR_umount2;
extern const int __NR_swapon;
extern const int __NR_swapoff;
extern const int __NR_sethostname;
extern const int __NR_setdomainname;
extern const int __NR_iopl;
extern const int __NR_ioperm;
extern const int __NR_init_module;
extern const int __NR_delete_module;
extern const int __NR_gettid;
extern const int __NR_readahead;
extern const int __NR_setxattr;
extern const int __NR_fsetxattr;
extern const int __NR_getxattr;
extern const int __NR_fgetxattr;
extern const int __NR_listxattr;
extern const int __NR_flistxattr;
extern const int __NR_removexattr;
extern const int __NR_fremovexattr;
extern const int __NR_lsetxattr;
extern const int __NR_lgetxattr;
extern const int __NR_llistxattr;
extern const int __NR_lremovexattr;
extern const int __NR_sched_setaffinity;
extern const int __NR_sched_getaffinity;
extern const int __NR_cpuset_getaffinity;
extern const int __NR_cpuset_setaffinity;
extern const int __NR_io_setup;
extern const int __NR_io_destroy;
extern const int __NR_io_getevents;
extern const int __NR_io_submit;
extern const int __NR_io_cancel;
extern const int __NR_lookup_dcookie;
extern const int __NR_epoll_create;
extern const int __NR_epoll_wait;
extern const int __NR_epoll_ctl;
extern const int __NR_getdents;
extern const int __NR_set_tid_address;
extern const int __NR_restart_syscall;
extern const int __NR_semtimedop;
extern const int __NR_fadvise;
extern const int __NR_timer_create;
extern const int __NR_timer_settime;
extern const int __NR_timer_gettime;
extern const int __NR_timer_getoverrun;
extern const int __NR_timer_delete;
extern const int __NR_clock_settime;
extern const int __NR_clock_gettime;
extern const int __NR_clock_getres;
extern const int __NR_clock_nanosleep;
extern const int __NR_tgkill;
extern const int __NR_mbind;
extern const int __NR_set_mempolicy;
extern const int __NR_get_mempolicy;
extern const int __NR_mq_open;
extern const int __NR_mq_unlink;
extern const int __NR_mq_timedsend;
extern const int __NR_mq_timedreceive;
extern const int __NR_mq_notify;
extern const int __NR_mq_getsetattr;
extern const int __NR_kexec_load;
extern const int __NR_waitid;
extern const int __NR_add_key;
extern const int __NR_request_key;
extern const int __NR_keyctl;
extern const int __NR_ioprio_set;
extern const int __NR_ioprio_get;
extern const int __NR_inotify_init;
extern const int __NR_inotify_add_watch;
extern const int __NR_inotify_rm_watch;
extern const int __NR_openat;
extern const int __NR_mkdirat;
extern const int __NR_fchownat;
extern const int __NR_utime;
extern const int __NR_utimes;
extern const int __NR_futimesat;
extern const int __NR_futimes;
extern const int __NR_futimens;
extern const int __NR_fstatat;
extern const int __NR_unlinkat;
extern const int __NR_renameat;
extern const int __NR_linkat;
extern const int __NR_symlinkat;
extern const int __NR_readlinkat;
extern const int __NR_fchmodat;
extern const int __NR_faccessat;
extern const int __NR_unshare;
extern const int __NR_splice;
extern const int __NR_tee;
extern const int __NR_vmsplice;
extern const int __NR_migrate_pages;
extern const int __NR_move_pages;
extern const int __NR_preadv;
extern const int __NR_pwritev;
extern const int __NR_utimensat;
extern const int __NR_fallocate;
extern const int __NR_posix_fallocate;
extern const int __NR_accept4;
extern const int __NR_dup3;
extern const int __NR_pipe2;
extern const int __NR_epoll_pwait;
extern const int __NR_epoll_create1;
extern const int __NR_perf_event_open;
extern const int __NR_inotify_init1;
extern const int __NR_tgsigqueueinfo;
extern const int __NR_signalfd;
extern const int __NR_signalfd4;
extern const int __NR_eventfd;
extern const int __NR_eventfd2;
extern const int __NR_timerfd_create;
extern const int __NR_timerfd_settime;
extern const int __NR_timerfd_gettime;
extern const int __NR_recvmmsg;
extern const int __NR_fanotify_init;
extern const int __NR_fanotify_mark;
extern const int __NR_prlimit;
extern const int __NR_name_to_handle_at;
extern const int __NR_open_by_handle_at;
extern const int __NR_clock_adjtime;
extern const int __NR_syncfs;
extern const int __NR_sendmmsg;
extern const int __NR_setns;
extern const int __NR_getcpu;
extern const int __NR_process_vm_readv;
extern const int __NR_process_vm_writev;
extern const int __NR_kcmp;
extern const int __NR_finit_module;
extern const int __NR_sched_setattr;
extern const int __NR_sched_getattr;
extern const int __NR_renameat2;
extern const int __NR_seccomp;
extern const int __NR_getrandom;
extern const int __NR_memfd_create;
extern const int __NR_kexec_file_load;
extern const int __NR_bpf;
extern const int __NR_execveat;
extern const int __NR_userfaultfd;
extern const int __NR_membarrier;
extern const int __NR_mlock2;
extern const int __NR_copy_file_range;
extern const int __NR_preadv2;
extern const int __NR_pwritev2;
extern const int __NR_pkey_mprotect;
extern const int __NR_pkey_alloc;
extern const int __NR_pkey_free;
extern const int __NR_statx;
extern const int __NR_io_pgetevents;
extern const int __NR_rseq;
extern const int __NR_pidfd_send_signal;
extern const int __NR_io_uring_setup;
extern const int __NR_io_uring_enter;
extern const int __NR_io_uring_register;
extern const int __NR_pledge;
extern const int __NR_msyscall;
extern const int __NR_ktrace;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/w.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_W_H_
COSMOPOLITAN_C_START_

extern const int WNOHANG;
extern const int WUNTRACED;
extern const int WCONTINUED;

#define WNOHANG    1
#define WUNTRACED  WUNTRACED
#define WCONTINUED WCONTINUED


COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/**
 * @fileoverview GDB Attach Support Code.
 *
 * The goal of these macros is to make the backtrace into the failing
 * code as short as possible. It also helps avoid GDB getting confused
 * about how we don't use its readability destroying unwind directives.
 */

extern volatile int g_gdbsync;

int gdbexec(const char *);
int AttachDebugger(intptr_t);

#define AttachDebugger(CONTINUE_TO_ADDR) /* shorten backtraces */ \
  SYNCHRONIZE_DEBUGGER((AttachDebugger)(CONTINUE_TO_ADDR))

#define SYNCHRONIZE_DEBUGGER(PID)                                    \
  ({                                                                 \
    int Rc, Pid = (PID);                                             \
    if (Pid != -1) {                                                 \
      while ((Rc = __inline_wait4(Pid, NULL, WNOHANG, NULL)) == 0) { \
        if (g_gdbsync) {                                             \
          g_gdbsync = 0;                                             \
          if (Rc > 0) Pid = 0;                                       \
          break;                                                     \
        } else {                                                     \
          sched_yield();                                             \
        }                                                            \
      }                                                              \
    }                                                                \
    Pid;                                                             \
  })

#ifdef __x86_64__
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE)     \
  ({                                                                      \
    int64_t WaAx;                                                         \
    if (!IsWindows()) {                                                   \
      asm volatile("mov\t%5,%%r10\n\t"                                    \
                   "syscall"                                              \
                   : "=a"(WaAx)                                           \
                   : "0"(__NR_wait4), "D"(PID), "S"(OPT_OUT_WSTATUS),     \
                     "d"(OPTIONS), "g"(OPT_OUT_RUSAGE)                    \
                   : "rcx", "r8", "r9", "r10", "r11", "memory", "cc");    \
    } else {                                                              \
      WaAx = sys_wait4_nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \
    }                                                                     \
    WaAx;                                                                 \
  })
#else
#define __inline_wait4 wait4
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/log.h */

#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
#define COSMOPOLITAN_LIBC_LOG_LOG_H_


/*!BEGIN libc/stdio/stdio.h */

#define COSMOPOLITAN_LIBC_STDIO_H_

#define EOF    -1  /* end of file */
#define WEOF   -1u /* end of file (multibyte) */
#define _IOFBF 0   /* fully buffered */
#define _IOLBF 1   /* line buffered */
#define _IONBF 2   /* no buffering */

#define L_tmpnam     20
#define L_ctermid    20
#define P_tmpdir     "/tmp"
#define FILENAME_MAX 1024
#define FOPEN_MAX    1000
#define TMP_MAX      10000
#define BUFSIZ       4096

COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct FILE;
typedef struct FILE FILE;

extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;

errno_t ferror(FILE *) libcesque paramsnonnull();
void clearerr(FILE *) libcesque paramsnonnull();
int feof(FILE *) libcesque paramsnonnull();
int getc(FILE *) libcesque paramsnonnull();
int putc(int, FILE *) libcesque paramsnonnull();
int fflush(FILE *) libcesque;
int fpurge(FILE *) libcesque;
int fgetc(FILE *) libcesque paramsnonnull();
char *fgetln(FILE *, size_t *) libcesque paramsnonnull((1));
int ungetc(int, FILE *) libcesque paramsnonnull();
int fileno(FILE *) libcesque paramsnonnull() nosideeffect;
int fputc(int, FILE *) libcesque paramsnonnull();
int fputs(const char *, FILE *) libcesque paramsnonnull();
int fputws(const wchar_t *, FILE *) libcesque paramsnonnull();
void flockfile(FILE *) libcesque paramsnonnull();
void funlockfile(FILE *) libcesque paramsnonnull();
int ftrylockfile(FILE *) libcesque paramsnonnull();
char *fgets(char *, int, FILE *) libcesque paramsnonnull();
wchar_t *fgetws(wchar_t *, int, FILE *) libcesque paramsnonnull();
wint_t putwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t fputwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t putwchar(wchar_t) libcesque;
wint_t getwchar(void) libcesque;
wint_t getwc(FILE *) libcesque paramsnonnull();
wint_t fgetwc(FILE *) libcesque paramsnonnull();
wint_t ungetwc(wint_t, FILE *) libcesque paramsnonnull();
int getchar(void) libcesque;
int putchar(int) libcesque;
int puts(const char *) libcesque;
ssize_t getline(char **, size_t *, FILE *) libcesque paramsnonnull();
ssize_t getdelim(char **, size_t *, int, FILE *) libcesque paramsnonnull();
FILE *fopen(const char *, const char *) libcesque paramsnonnull((2)) __wur;
FILE *fdopen(int, const char *) libcesque paramsnonnull() __wur;
FILE *fmemopen(void *, size_t, const char *) libcesque paramsnonnull((3)) __wur;
FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3));
size_t fread(void *, size_t, size_t, FILE *) libcesque paramsnonnull((4));
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4));
int fclose(FILE *) libcesque;
int fseek(FILE *, long, int) libcesque paramsnonnull();
long ftell(FILE *) libcesque paramsnonnull();
int fseeko(FILE *, int64_t, int) libcesque paramsnonnull();
int64_t ftello(FILE *) libcesque paramsnonnull();
void rewind(FILE *) libcesque paramsnonnull();
int fopenflags(const char *) libcesque paramsnonnull();
void setlinebuf(FILE *) libcesque;
void setbuf(FILE *, char *) libcesque;
void setbuffer(FILE *, char *, size_t) libcesque;
int setvbuf(FILE *, char *, int, size_t) libcesque;
int pclose(FILE *) libcesque;
char *ctermid(char *) libcesque;
void perror(const char *) libcesque relegated;

typedef uint64_t fpos_t;
char *gets(char *) libcesque paramsnonnull();
int fgetpos(FILE *, fpos_t *) libcesque paramsnonnull();
int fsetpos(FILE *, const fpos_t *) libcesque paramsnonnull();

FILE *tmpfile(void) libcesque __wur;
char *tmpnam(char *) libcesque __wur;
char *tmpnam_r(char *) libcesque __wur;

FILE *popen(const char *, const char *) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » formatting                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int printf(const char *, ...) printfesque(1) paramsnonnull((1)) libcesque;
int vprintf(const char *, va_list) paramsnonnull() libcesque;
int fprintf(FILE *, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vfprintf(FILE *, const char *, va_list) paramsnonnull() libcesque;
int scanf(const char *, ...) libcesque scanfesque(1);
int vscanf(const char *, va_list) libcesque;
int fscanf(FILE *, const char *, ...) libcesque scanfesque(2);
int vfscanf(FILE *, const char *, va_list) libcesque;

int snprintf(char *, size_t, const char *, ...) printfesque(3) libcesque;
int vsnprintf(char *, size_t, const char *, va_list) libcesque;
int sprintf(char *, const char *, ...) libcesque;
int vsprintf(char *, const char *, va_list) libcesque;

int fwprintf(FILE *, const wchar_t *, ...) libcesque;
int fwscanf(FILE *, const wchar_t *, ...) libcesque;
int swprintf(wchar_t *, size_t, const wchar_t *, ...) libcesque;
int swscanf(const wchar_t *, const wchar_t *, ...) libcesque;
int vfwprintf(FILE *, const wchar_t *, va_list) libcesque;
int vfwscanf(FILE *, const wchar_t *, va_list) libcesque;
int vswprintf(wchar_t *, size_t, const wchar_t *, va_list) libcesque;
int vswscanf(const wchar_t *, const wchar_t *, va_list) libcesque;
int vwprintf(const wchar_t *, va_list) libcesque;
int vwscanf(const wchar_t *, va_list) libcesque;
int wprintf(const wchar_t *, ...) libcesque;
int wscanf(const wchar_t *, ...) libcesque;
int fwide(FILE *, int) libcesque;

int sscanf(const char *, const char *, ...) libcesque scanfesque(2);
int vsscanf(const char *, const char *, va_list) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » allocating                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int asprintf(char **, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » without mutexes                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int getc_unlocked(FILE *) libcesque paramsnonnull();
int puts_unlocked(const char *) libcesque;
int getchar_unlocked(void) libcesque;
int putc_unlocked(int, FILE *) libcesque paramsnonnull();
int putchar_unlocked(int) libcesque;
void clearerr_unlocked(FILE *) libcesque;
int feof_unlocked(FILE *) libcesque;
int ferror_unlocked(FILE *) libcesque;
int fileno_unlocked(FILE *) libcesque;
int fflush_unlocked(FILE *) libcesque;
int fgetc_unlocked(FILE *) libcesque;
int fputc_unlocked(int, FILE *) libcesque;
size_t fread_unlocked(void *, size_t, size_t, FILE *) libcesque;
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *) libcesque;
char *fgets_unlocked(char *, int, FILE *) libcesque;
int fputs_unlocked(const char *, FILE *) libcesque;
wint_t getwc_unlocked(FILE *) libcesque;
wint_t getwchar_unlocked(void) libcesque;
wint_t fgetwc_unlocked(FILE *) libcesque;
wint_t fputwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwchar_unlocked(wchar_t) libcesque;
wchar_t *fgetws_unlocked(wchar_t *, int, FILE *) libcesque;
int fputws_unlocked(const wchar_t *, FILE *) libcesque;
wint_t ungetwc_unlocked(wint_t, FILE *) libcesque paramsnonnull();
int ungetc_unlocked(int, FILE *) libcesque paramsnonnull();
int fseek_unlocked(FILE *, int64_t, int) libcesque paramsnonnull();
ssize_t getdelim_unlocked(char **, size_t *, int, FILE *) paramsnonnull();
int fprintf_unlocked(FILE *, const char *, ...) printfesque(2) libcesque;
int vfprintf_unlocked(FILE *, const char *, va_list) paramsnonnull() libcesque;

COSMOPOLITAN_C_END_

#define kLogFatal   0
#define kLogError   1
#define kLogWarn    2
#define kLogInfo    3
#define kLogVerbose 4
#define kLogDebug   5
#define kLogNoise   6

/**
 * Log level for compile-time DCE.
 */
#ifndef LOGGABLELEVEL
#ifndef TINY
#define LOGGABLELEVEL kLogNoise
/* #elif IsTiny() */
/* #define LOGGABLELEVEL kLogInfo */
#else
#define LOGGABLELEVEL kLogVerbose
#endif
#endif

#ifdef TINY
#define _LOG_TINY 1
#else
#define _LOG_TINY 0
#endif

COSMOPOLITAN_C_START_

extern FILE *__log_file;

int __watch(void *, size_t);
void __die(void) relegated wontreturn; /* print backtrace and abort() */
void _meminfo(int);                    /* shows malloc statistics &c. */
void _memsummary(int);                 /* light version of same thing */
const char *commandvenv(const char *, const char *);
const char *GetAddr2linePath(void);
const char *GetGdbPath(void);
bool32 IsDebuggerPresent(bool32);
bool32 IsRunningUnderMake(void);
char *GetSymbolByAddr(int64_t);
void PrintGarbage(void);
void PrintGarbageNumeric(FILE *);
void PrintWindowsMemory(const char *, size_t);

#ifndef __STRICT_ANSI__

#define _LOG_UNLIKELY(x) __builtin_expect(!!(x), 0)

extern unsigned __log_level; /* log level for runtime check */

#define LOGGABLE(LEVEL)                                          \
  ((!__builtin_constant_p(LEVEL) || (LEVEL) <= LOGGABLELEVEL) && \
   (LEVEL) <= __log_level)

// log a message with the specified log level (not checking if LOGGABLE)
#define LOGF(LEVEL, FMT, ...)                                   \
  do {                                                          \
    if (!_LOG_TINY) _log_untrace();                             \
    flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    if (!_LOG_TINY) _log_retrace();                             \
  } while (0)

// report an error without backtrace and debugger invocation
#define FATALF(FMT, ...)                                            \
  do {                                                              \
    if (!_LOG_TINY) _log_untrace();                                 \
    flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                   \
  } while (0)

#define DIEF(FMT, ...)                                                \
  do {                                                                \
    if (!_LOG_TINY) _log_untrace();                                   \
    ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    __builtin_unreachable();                                          \
  } while (0)

#define ERRORF(FMT, ...)                   \
  do {                                     \
    if (LOGGABLE(kLogError)) {             \
      LOGF(kLogError, FMT, ##__VA_ARGS__); \
    }                                      \
  } while (0)

#define WARNF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogWarn)) {             \
      LOGF(kLogWarn, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define INFOF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogInfo)) {             \
      LOGF(kLogInfo, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define VERBOSEF(FMT, ...)                                                  \
  do {                                                                      \
    if (LOGGABLE(kLogVerbose)) {                                            \
      if (!_LOG_TINY) _log_untrace();                                       \
      fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                       \
    }                                                                       \
  } while (0)

#define DEBUGF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define NOISEF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define FLOGF(F, FMT, ...)                                        \
  do {                                                            \
    if (LOGGABLE(kLogInfo)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FWARNF(F, FMT, ...)                                       \
  do {                                                            \
    if (LOGGABLE(kLogWarn)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FFATALF(F, FMT, ...)                                     \
  do {                                                           \
    if (!_LOG_TINY) _log_untrace();                              \
    flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                \
  } while (0)

#define FDEBUGF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define FNOISEF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define LOGIFNEG1(FORM)                                                \
  ({                                                                   \
    int e = _log_get_errno();                                          \
    autotype(FORM) Ax = (FORM);                                        \
    if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
      if (!_LOG_TINY) _log_untrace();                                  \
      _log_errno(__FILE__, __LINE__, #FORM);                           \
      if (!_LOG_TINY) _log_retrace();                                  \
      _log_set_errno(e);                                               \
    }                                                                  \
    Ax;                                                                \
  })

#define LOGIFNULL(FORM)                      \
  ({                                         \
    int e = _log_get_errno();                \
    autotype(FORM) Ax = (FORM);              \
    if (Ax == NULL && LOGGABLE(kLogWarn)) {  \
      if (!_LOG_TINY) _log_untrace();        \
      _log_errno(__FILE__, __LINE__, #FORM); \
      if (!_LOG_TINY) _log_retrace();        \
      _log_set_errno(e);                     \
    }                                        \
    Ax;                                      \
  })

void _log_errno(const char *, int, const char *) relegated;
int _log_get_errno(void);
void _log_set_errno(int);
void _log_untrace(void);
void _log_retrace(void);
void _log_exit(int) wontreturn;

#define ARGS  unsigned, const char *, int, FILE *, const char *
#define ATTR  paramsnonnull((5)) printfesque(5)
#define ATTRV paramsnonnull((5))
void flogf(ARGS, ...) ATTR libcesque;
void vflogf(ARGS, va_list) ATTRV libcesque;
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfverbosef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fdebugf(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfdebugf(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fnoisef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfnoisef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void ffatalf(ARGS, ...) asm("flogf") ATTR relegated wontreturn libcesque;
void vffatalf(ARGS, va_list) asm("vflogf") ATTRV relegated wontreturn libcesque;
#undef ARGS
#undef ATTR
#undef ATTRV

#endif /* __STRICT_ANSI__ */
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_LOG_LOG_H_ */


/*!BEGIN libc/log/traceme.h */

#define COSMOPOLITAN_LIBC_LOG_TRACEME_H_
COSMOPOLITAN_C_START_

extern int traceme;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alg.h */

#define COSMOPOLITAN_LIBC_ALG_ALG_H_
COSMOPOLITAN_C_START_

void *bsearch(const void *, const void *, size_t, size_t,
              int (*)(const void *, const void *)) paramsnonnull() nosideeffect;
void *bsearch_r(const void *, const void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 2, 5)) nosideeffect;
void djbsort(int32_t *, size_t) libcesque;
void qsort3(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort_r(void *, size_t, size_t,
             int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 4));
void smoothsort(void *, size_t, size_t, int (*)(const void *, const void *));
void smoothsort_r(void *, size_t, size_t,
                  int (*)(const void *, const void *, void *), void *);
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
int heapsort_r(void *, size_t, size_t,
               int (*)(const void *, const void *, void *), void *);
int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
int mergesort_r(void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *);

int radix_sort_int32(int32_t *, size_t) libcesque;
int radix_sort_int64(int64_t *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alloca.h */

#define COSMOPOLITAN_LIBC_MEM_ALLOCA_H_

#define alloca(size) __builtin_alloca(size)



/*!BEGIN libc/mem/critbit0.h */

#define COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § data structures » critical bit tree (for c strings)       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct critbit0 {
  void *root;
  size_t count;
};

bool critbit0_contains(struct critbit0 *, const char *) libcesque nosideeffect
    paramsnonnull();
int critbit0_insert(struct critbit0 *, const char *) paramsnonnull();
bool critbit0_delete(struct critbit0 *, const char *) libcesque paramsnonnull();
void critbit0_clear(struct critbit0 *) libcesque paramsnonnull();
char *critbit0_get(struct critbit0 *, const char *);
intptr_t critbit0_allprefixed(struct critbit0 *, const char *,
                              intptr_t (*)(const char *, void *), void *)
    paramsnonnull((1, 2, 3)) libcesque;
int critbit0_emplace(struct critbit0 *, const void *, size_t) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/gc.h */

#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_
#define COSMOPOLITAN_LIBC_MEM_GC_H_
COSMOPOLITAN_C_START_

libcesque void _gc_free(void *);
libcesque void __defer(void *, void *, void *);
libcesque void gclongjmp(void *, int) wontreturn;
#define gc(THING)  defer((void *)_gc_free, (void *)(THING))
#define _gc(THING) defer((void *)_gc_free, (void *)(THING))
#define defer(FN, ARG)                             \
  ({                                               \
    autotype(ARG) Arg = (ARG);                     \
    /* prevent weird opts like tail call */        \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    __defer(__builtin_frame_address(0), FN, Arg);  \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    Arg;                                           \
  })

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */


/*!BEGIN libc/mem/mem.h */

#define COSMOPOLITAN_LIBC_MEM_MEM_H_

#define M_TRIM_THRESHOLD (-1)
#define M_GRANULARITY    (-2)
#define M_MMAP_THRESHOLD (-3)

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dynamic memory                                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

void free(void *) libcesque;
void *malloc(size_t) attributeallocsize((1)) mallocesque;
void *calloc(size_t, size_t) attributeallocsize((1, 2)) mallocesque;
void *memalign(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
void *realloc(void *, size_t) reallocesque;
void *realloc_in_place(void *, size_t) reallocesque;
void *reallocarray(void *, size_t, size_t) __wur;
void *valloc(size_t) attributeallocsize((1)) vallocesque;
void *pvalloc(size_t) vallocesque;
char *strdup(const char *) paramsnonnull() mallocesque;
char *strndup(const char *, size_t) paramsnonnull() mallocesque;
void *aligned_alloc(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
int posix_memalign(void **, size_t, size_t) libcesque;

int mallopt(int, int) libcesque;
int malloc_trim(size_t) libcesque;
size_t bulk_free(void **, size_t) libcesque;
size_t malloc_usable_size(void *) libcesque;
void **independent_calloc(size_t, size_t, void **) libcesque;
void **independent_comalloc(size_t, size_t *, void **) libcesque;

wchar_t *wcsdup(const wchar_t *) strlenesque __wur;

struct mallinfo {
  size_t arena;    /* non-mmapped space allocated from system */
  size_t ordblks;  /* number of free chunks */
  size_t smblks;   /* always 0 */
  size_t hblks;    /* always 0 */
  size_t hblkhd;   /* space in mmapped regions */
  size_t usmblks;  /* maximum total allocated space */
  size_t fsmblks;  /* always 0 */
  size_t uordblks; /* total allocated space */
  size_t fordblks; /* total free space */
  size_t keepcost; /* releasable (via malloc_trim) space */
};

struct mallinfo mallinfo(void) libcesque;

size_t malloc_footprint(void) libcesque;
size_t malloc_max_footprint(void) libcesque;
size_t malloc_footprint_limit(void) libcesque;
size_t malloc_set_footprint_limit(size_t) libcesque;
void malloc_inspect_all(void (*)(void *, void *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/cachesize.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CACHESIZE_H_

#define kCpuCacheTypeData        1
#define kCpuCacheTypeInstruction 2
#define kCpuCacheTypeUnified     3

COSMOPOLITAN_C_START_

unsigned _getcachesize(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/crc32.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CRC32_H_
COSMOPOLITAN_C_START_

extern const uint32_t kCrc32cTab[256];

void crc32init(uint32_t[hasatleast 256], uint32_t);
uint32_t crc32c(uint32_t, const void *, size_t) nosideeffect;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/ffs.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_
COSMOPOLITAN_C_START_

int ffs(int) pureconst;
int ffsl(long) pureconst;
int ffsll(long long) pureconst;

#ifdef __GNUC__
#define ffs(u)   __builtin_ffs(u)
#define ffsl(u)  __builtin_ffsl(u)
#define ffsll(u) __builtin_ffsll(u)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/kompressor.h */

#define COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
#ifdef _COSMO_SOURCE

#define rldecode  __rldecode
#define rldecode2 __rldecode2
#define lz4check  __lz4check
#define lz4cpy    __lz4cpy
#define lz4len    __lz4len
#define lz4decode __lz4decode

COSMOPOLITAN_C_START_

struct RlDecode {
  uint8_t repititions;
  uint8_t byte;
};

void rldecode(void *dest, const struct RlDecode *);
void rldecode2(void *dest, const struct RlDecode *);
const uint8_t *lz4check(const void *data);
void *lz4cpy(void *dest, const void *blockdata, size_t blocksize);
size_t lz4len(const void *blockdata, size_t blocksize);
void *lz4decode(void *dest, const void *src);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/nexgen32e/lz4.h */

#define COSMOPOLITAN_LIBC_LZ4_H_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4                                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  LZ4 is a brilliant framing format for REP MOVSB designed by Yann Collet.

  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md
  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Block_format.md
  @see http://ticki.github.io/blog/how-lz4-works/ */

#define LZ4_EOF                0
#define LZ4_VERSION            1
#define LZ4_MAGICNUMBER        0x184D2204
#define LZ4_SKIPPABLE0         0x184D2A50
#define LZ4_SKIPPABLEMASK      0xFFFFFFF0
#define LZ4_MAXHEADERSIZE      (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1)
#define LZ4_BLOCKMAXSIZE_64KB  4
#define LZ4_BLOCKMAXSIZE_256KB 5
#define LZ4_BLOCKMAXSIZE_1MB   6
#define LZ4_BLOCKMAXSIZE_4MB   7

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » frames                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_MAGIC(FRAME)                      READ32LE(FRAME)
#define LZ4_FRAME_VERSION(FRAME)              ((_LZ4_FRAME_FLG(FRAME) >> 6) & 3)
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
#define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1)
#define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \
  ((_LZ4_FRAME_FLG(FRAME) >> 2) & 1)
#define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1)
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME)     ((_LZ4_FRAME_BD(FRAME) >> 4) & 7)
#define LZ4_FRAME_RESERVED1(FRAME)        ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
#define LZ4_FRAME_RESERVED2(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
#define LZ4_FRAME_RESERVED3(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 0) & 15)
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
  (LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? READ64LE((FRAME) + 4 + 1 + 1) : 0)
#define LZ4_FRAME_DICTIONARYID(FRAME)                          \
  (LZ4_FRAME_DICTIONARYIDFLAG(FRAME)                           \
       ? READ32LE(((FRAME) + 4 + 1 + 1 +                       \
                   8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME))) \
       : 0)
#define LZ4_FRAME_HEADERCHECKSUM(FRAME)                                \
  (*((FRAME) + 4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
     4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME)))
#define LZ4_FRAME_HEADERSIZE(FRAME)                        \
  (4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
   4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME) + 1)
#define _LZ4_FRAME_FLG(FRAME) (*((FRAME) + 4))
#define _LZ4_FRAME_BD(FRAME)  (*((FRAME) + 5))

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » blocks                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_BLOCK_DATA(block)         (block + sizeof(uint32_t))
#define LZ4_BLOCK_DATASIZE(block)     (READ32LE(block) & 0x7fffffff)
#define LZ4_BLOCK_ISEOF(block)        (READ32LE(block) == LZ4_EOF)
#define LZ4_BLOCK_ISCOMPRESSED(block) ((READ32LE(block) & 0x80000000) == 0)
#define LZ4_BLOCK_SIZE(frame, block)              \
  (sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \
   (LZ4_FRAME_BLOCKCHECKSUMFLAG(frame) ? sizeof(uint8_t) : 0))

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nexgen32e.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NEXGEN32E_H_
COSMOPOLITAN_C_START_

extern long kHalfCache3;
extern const uint64_t kTens[20];
extern const uint32_t kSha256[64];
extern const uint64_t kSha512[80];
extern const unsigned char kTensIndex[64];

void CheckStackIsAligned(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nt2sysv.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_


/*!BEGIN libc/nexgen32e/trampoline.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_

#define TRAMPOLINE(FUNCTION, THUNK)   \
  ({                                  \
    typeof(FUNCTION) *Tramp;          \
    asm(".section .text.trampoline\n" \
        "183:\n\t"                    \
        "mov\t%1,%%eax\n\t"           \
        "jmp\t" #THUNK "\n\t"         \
        ".previous\n\t"               \
        "mov\t$183b,%k0"              \
        : "=r"(Tramp)                 \
        : "i"(FUNCTION));             \
    Tramp;                            \
  })


/**
 * Creates function to thunk FUNCTION from MSX64 to System V ABI.
 *
 * This macro should be used when specifying callbacks in the WIN32 API.
 */
#define NT2SYSV(FUNCTION) TRAMPOLINE(FUNCTION, __nt2sysv)



/*!BEGIN libc/nexgen32e/rdtscp.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_
COSMOPOLITAN_C_START_

#define TSC_AUX_CORE(MSR) ((MSR) & 0xfff)
#define TSC_AUX_NODE(MSR) (((MSR) >> 12) & 0xfff)

/**
 * Reads CPU timestamp counter and IA32_TSC_AUX.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(RDTSCP)
 */
#define rdtscp(OPT_OUT_IA32_TSC_AUX)               \
  ({                                               \
    uint64_t Rax, Rdx;                             \
    uint32_t Ecx, *EcxOut;                         \
    asm volatile("rdtscp"                          \
                 : "=a"(Rax), "=c"(Ecx), "=d"(Rdx) \
                 : /* no inputs */                 \
                 : "memory");                      \
    EcxOut = (OPT_OUT_IA32_TSC_AUX);               \
    if (EcxOut) *EcxOut = Ecx;                     \
    Rdx << 32 | Rax;                               \
  })

/**
 * Reads timestamp counter auxiliary model specific register value.
 */
#define rdpid()                                                           \
  ({                                                                      \
    long Msr;                                                             \
    bool32 Ok;                                                            \
    Ok = false;                                                           \
    if (X86_HAVE(RDPID)) {                                                \
      asm volatile("rdpid\t%0" : "=r"(Msr) : /* no inputs */ : "memory"); \
      Ok = true;                                                          \
    } else if (IsLinux()) {                                               \
      char *p = (char *)0x7b;                                             \
      asm volatile(ZFLAG_ASM("lsl\t%2,%1")                                \
                   : ZFLAG_CONSTRAINT(Ok), "=r"(Msr)                      \
                   : "r"(p)                                               \
                   : "memory");                                           \
    }                                                                     \
    if (!Ok && X86_HAVE(RDTSCP)) {                                        \
      asm volatile("rdtscp"                                               \
                   : "=c"(Msr)                                            \
                   : /* no inputs */                                      \
                   : "eax", "edx", "memory");                             \
      Ok = true;                                                          \
    }                                                                     \
    if (!Ok) {                                                            \
      Msr = -1;                                                           \
    }                                                                     \
    Msr;                                                                  \
  })

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/sha.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_SHA_H_
COSMOPOLITAN_C_START_

void sha1_transform_avx2(uint32_t[hasatleast 5], const void *, unsigned);
void sha1_transform_ni(uint32_t[hasatleast 5], const void *, unsigned);
void sha256_transform_rorx(uint32_t[hasatleast 8], const void *, unsigned);
void sha256_transform_ni(uint32_t[hasatleast 8], const void *, unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/stackframe.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
COSMOPOLITAN_C_START_

struct StackFrame {
  struct StackFrame *next;
  intptr_t addr;
};

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_ */


/*!BEGIN libc/nexgen32e/x86info.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86INFO_H_

#define kX86CpuStepping    ((KCPUIDS(1H, EAX) >> 0) & 15)
#define kX86CpuModelid     ((KCPUIDS(1H, EAX) >> 4) & 15)
#define kX86CpuFamilyid    ((KCPUIDS(1H, EAX) >> 8) & 15)
#define kX86CpuType        ((KCPUIDS(1H, EAX) >> 12) & 3)
#define kX86CpuExtmodelid  ((KCPUIDS(1H, EAX) >> 16) & 15)
#define kX86CpuExtfamilyid ((KCPUIDS(1H, EAX) >> 20) & 255)

#define kX86CpuFamily \
  (kX86CpuFamilyid + (kX86CpuFamilyid == 15 ? kX86CpuExtfamilyid : 0))

#define kX86CpuModel                                                       \
  (kX86CpuModelid |                                                        \
   (kX86CpuFamilyid == 6 || kX86CpuFamilyid == 15 ? kX86CpuExtmodelid : 0) \
       << 4)

#define kX86ProcessorModelKey                                                 \
  (kX86CpuExtfamilyid << 12 | kX86CpuFamilyid << 8 | kX86CpuExtmodelid << 4 | \
   kX86CpuModelid)

#define X86_MARCH_UNKNOWN        0
#define X86_MARCH_CORE2          1
#define X86_MARCH_NEHALEM        2
#define X86_MARCH_WESTMERE       3
#define X86_MARCH_SANDYBRIDGE    4
#define X86_MARCH_IVYBRIDGE      5
#define X86_MARCH_HASWELL        6
#define X86_MARCH_BROADWELL      7
#define X86_MARCH_SKYLAKE        8
#define X86_MARCH_KABYLAKE       9
#define X86_MARCH_CANNONLAKE     10
#define X86_MARCH_ICELAKE        11
#define X86_MARCH_TIGERLAKE      12
#define X86_MARCH_BONNELL        13
#define X86_MARCH_SALTWELL       14
#define X86_MARCH_SILVERMONT     15
#define X86_MARCH_AIRMONT        16
#define X86_MARCH_GOLDMONT       17
#define X86_MARCH_GOLDMONTPLUS   18
#define X86_MARCH_TREMONT        19
#define X86_MARCH_KNIGHTSLANDING 20
#define X86_MARCH_KNIGHTSMILL    21
#define X86_MARCH_SAPPHIRERAPIDS 22
#define X86_MARCH_ALDERLAKE      23
#define X86_MARCH_COMETLAKE      24
#define X86_MARCH_RAPTORLAKE     25
#define X86_MARCH_ROCKETLAKE     26

#define X86_GRADE_UNKNOWN   0
#define X86_GRADE_APPLIANCE 1
#define X86_GRADE_MOBILE    2
#define X86_GRADE_TABLET    3
#define X86_GRADE_DESKTOP   4
#define X86_GRADE_CLIENT    5
#define X86_GRADE_DENSITY   6
#define X86_GRADE_SERVER    7
#define X86_GRADE_SCIENCE   8

struct X86ProcessorModel {
  short key;
  unsigned char march;
  unsigned char grade;
};

extern const size_t kX86ProcessorModelCount;
extern const struct X86ProcessorModel kX86ProcessorModels[];

const struct X86ProcessorModel *getx86processormodel(short) nosideeffect;



/*!BEGIN libc/nt/enum/accessmask.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ACCESSMASK_H_

#define kNtGenericRead            0x80000000u
#define kNtGenericWrite           0x40000000u
#define kNtGenericExecute         0x20000000u
#define kNtGenericAll             0x10000000u
#define kNtDelete                 0x00010000u
#define kNtReadControl            0x00020000u
#define kNtWriteDac               0x00040000u
#define kNtWriteOwner             0x00080000u
#define kNtSynchronize            0x00100000u
#define kNtStandardRightsRequired 0x000F0000u
#define kNtStandardRightsRead     kNtReadControl
#define kNtStandardRightsWrite    kNtReadControl
#define kNtStandardRightsExecute  kNtReadControl
#define kNtStandardRightsAll      0x001F0000u
#define kNtSpecificRightsAll      0x0000FFFFu
#define kNtAccessSystemSecurity   0x01000000u
#define kNtMaximumAllowed         0x02000000u
#define kNtFileReadData           0x0001u
#define kNtFileListDirectory      0x0001u
#define kNtFileWriteData          0x0002u
#define kNtFileAddFile            0x0002u
#define kNtFileAppendData         0x0004u
#define kNtFileAddSubdirectory    0x0004u
#define kNtFileCreatePipeInstance 0x0004u
#define kNtFileReadEa             0x0008u
#define kNtFileWriteEa            0x0010u
#define kNtFileExecute            0x0020u
#define kNtFileTraverse           0x0020u
#define kNtFileDeleteChild        0x0040u
#define kNtFileReadAttributes     0x0080u
#define kNtFileWriteAttributes    0x0100u
#define kNtFileAllAccess          (kNtStandardRightsRequired | kNtSynchronize | 0x1FFu)
#define kNtFileGenericRead                                           \
  (kNtStandardRightsRead | kNtFileReadData | kNtFileReadAttributes | \
   kNtFileReadEa | kNtSynchronize)
#define kNtFileGenericWrite                                             \
  (kNtStandardRightsWrite | kNtFileWriteData | kNtFileWriteAttributes | \
   kNtFileWriteEa | kNtFileAppendData | kNtSynchronize)
#define kNtFileGenericExecute                                          \
  (kNtStandardRightsExecute | kNtFileReadAttributes | kNtFileExecute | \
   kNtSynchronize)
#define kNtTokenAssignPrimary    0x0001u
#define kNtTokenDuplicate        0x0002u
#define kNtTokenImpersonate      0x0004u
#define kNtTokenQuery            0x0008u
#define kNtTokenQuerySource      0x0010u
#define kNtTokenAdjustPrivileges 0x0020u
#define kNtTokenAdjustGroups     0x0040u
#define kNtTokenAdjustDefault    0x0080u
#define kNtTokenAdjustSessionid  0x0100u
#define kNtTokenAllAccessP                                                 \
  (kNtStandardRightsRequired | kNtTokenAssignPrimary | kNtTokenDuplicate | \
   kNtTokenImpersonate | kNtTokenQuery | kNtTokenQuerySource |             \
   kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | kNtTokenAdjustDefault)
#define kNtTokenAllAccess kNtTokenAllAccessP | kNtTokenAdjustSessionid
#define kNtTokenRead      kNtStandardRightsRead | kNtTokenQuery
#define kNtTokenWrite                                                         \
  (kNtStandardRightsWrite | kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | \
   kNtTokenAdjustDefault)
#define kNtTokenExecute kNtStandardRightsExecute
#define kNtTokenTrustConstraintMask \
  (kNtStandardRightsRead | kNtTokenQuery | kNtTokenQuerySource)
#define kNtTokenAccessPseudoHandleWin8 kNtTokenQuery | kNtTokenQuerySource
#define kNtTokenAccessPseudoHandle     kNtTokenAccessPseudoHandleWin8



/*!BEGIN libc/nt/enum/afd.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_AFD_H_

#define kNtAfdPollReceive          0x0001
#define kNtAfdPollReceiveExpedited 0x0002
#define kNtAfdPollSend             0x0004
#define kNtAfdPollDisconnect       0x0008
#define kNtAfdPollAbort            0x0010
#define kNtAfdPollLocalClose       0x0020
#define kNtAfdPollAccept           0x0080
#define kNtAfdPollConnectFail      0x0100



/*!BEGIN libc/nt/enum/bitblt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_BITBLT_H_

#define kNtSrccopy     0x00CC0020u /* src */
#define kNtSrcpaint    0x00EE0086u /* src | dst */
#define kNtSrcand      0x008800C6u /* src & dst */
#define kNtSrcinvert   0x00660046u /* src ^ dst */
#define kNtSrcerase    0x00440328u /* src & ~dst */
#define kNtNotsrccopy  0x00330008u /* ~src */
#define kNtNotsrcerase 0x001100A6u /* ~src & ~dst */
#define kNtMergecopy   0x00C000CAu /* (src & pattern) */
#define kNtMergepaint  0x00BB0226u /* ~src | dst */
#define kNtPatcopy     0x00F00021u /* pat */
#define kNtPatpaint    0x00FB0A09u /* wut */
#define kNtPatinvert   0x005A0049u /* pat ^ dst */
#define kNtDstinvert   0x00550009u /* ~dst */
#define kNtBlackness   0x00000042u /* black */
#define kNtWhiteness   0x00FF0062u /* white */



/*!BEGIN libc/nt/enum/callback.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CALLBACK_H_

#define kNtCallbackChunkFinished 0
#define kNtCallbackStreamSwitch  1



/*!BEGIN libc/nt/enum/color.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COLOR_H_

#define kNtColorScrollbar               0
#define kNtColorBackground              1
#define kNtColorActivecaption           2
#define kNtColorInactivecaption         3
#define kNtColorMenu                    4
#define kNtColorWindow                  5
#define kNtColorWindowframe             6
#define kNtColorMenutext                7
#define kNtColorWindowtext              8
#define kNtColorCaptiontext             9
#define kNtColorActiveborder            10
#define kNtColorInactiveborder          11
#define kNtColorAppworkspace            12
#define kNtColorHighlight               13
#define kNtColorHighlighttext           14
#define kNtColorBtnface                 15
#define kNtColorBtnshadow               16
#define kNtColorGraytext                17
#define kNtColorBtntext                 18
#define kNtColorInactivecaptiontext     19
#define kNtColorBtnhighlight            20
#define kNtColor3ddkshadow              21
#define kNtColor3dlight                 22
#define kNtColorInfotext                23
#define kNtColorInfobk                  24
#define kNtColorHotlight                26
#define kNtColorGradientactivecaption   27
#define kNtColorGradientinactivecaption 28
#define kNtColorMenuhilight             29
#define kNtColorMenubar                 30



/*!BEGIN libc/nt/enum/computernameformat.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COMPUTERNAMEFORMAT_H_

#define kNtComputerNameNetBios                   0
#define kNtComputerNameDnsHostname               1
#define kNtComputerNameDnsDomain                 2
#define kNtComputerNameDnsFullyQualified         3
#define kNtComputerNamePhysicalNetBios           4
#define kNtComputerNamePhysicalDnsHostname       5
#define kNtComputerNamePhysicalDnsDomain         6
#define kNtComputerNamePhysicalDnsFullyQualified 7
#define kNtComputerName_MAX                      8



/*!BEGIN libc/nt/enum/consolemodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLEMODEFLAGS_H_

/* input mode */
#define kNtEnableProcessedInput 0x0001u
#define kNtEnableLineInput 0x0002u
#define kNtEnableEchoInput 0x0004u
#define kNtEnableWindowInput 0x0008u
#define kNtEnableMouseInput 0x0010u
#define kNtEnableInsertMode 0x0020u
#define kNtEnableQuickEditMode 0x0040u
#define kNtEnableExtendedFlags 0x0080u
#define kNtEnableAutoPosition 0x0100u
#define kNtEnableVirtualTerminalInput 0x0200u

/* output mode */
#define kNtEnableProcessedOutput 0x0001u
#define kNtEnableWrapAtEolOutput 0x0002u
#define kNtEnableVirtualTerminalProcessing 0x0004u
#define kNtDisableNewlineAutoReturn 0x0008u
#define kNtEnableLvbGridWorldwide 0x0010u



/*!BEGIN libc/nt/enum/consoleselectionflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLESELECTIONFLAGS_H_

#define kNtConsoleNoSelection 0x0000u
#define kNtConsoleSelectionInProgress 0x0001u
#define kNtConsoleSelectionNotEmpty 0x0002u
#define kNtConsoleMouseSelection 0x0004u
#define kNtConsoleMouseDown 0x0008u



/*!BEGIN libc/nt/enum/context.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONTEXT_H_

#define kNtContextAmd64 0x00100000

#define kNtContextControl        (kNtContextAmd64 | 0x00000001)
#define kNtContextInteger        (kNtContextAmd64 | 0x00000002)
#define kNtContextSegments       (kNtContextAmd64 | 0x00000004)
#define kNtContextFloatingPoint  (kNtContextAmd64 | 0x00000008)
#define kNtContextDebugRegisters (kNtContextAmd64 | 0x00000010)

#define kNtContextFull \
  (kNtContextControl | kNtContextInteger | kNtContextFloatingPoint)

#define kNtContextAll                                           \
  (kNtContextControl | kNtContextInteger | kNtContextSegments | \
   kNtContextFloatingPoint | kNtContextDebugRegisters)

#define kNtContextXstate (kNtContextAmd64 | 0x00000040)



/*!BEGIN libc/nt/enum/copyfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COPYFILE_H_

#define kNtCopyFileFailIfExists              0x00000001
#define kNtCopyFileRestartable               0x00000002
#define kNtCopyFileOpenSourceForWrite        0x00000004
#define kNtCopyFileAllowDecryptedDestination 0x00000008
#define kNtCopyFileCopySymlink               0x00000800
#define kNtCopyFileNoBuffering               0x00001000
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileResumeFromPause           0x00004000 /* Win8+ */
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileNoOffload                 0x00040000 /* Win8+ */
#define kNtCopyFileIgnoreEdpBlock            0x00400000 /* Win10+ */
#define kNtCopyFileIgnoreSourceEncryption    0x00800000 /* Win10+ */



/*!BEGIN libc/nt/enum/creationdisposition.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CREATIONDISPOSITION_H_

#define kNtCreateNew 1
#define kNtCreateAlways 2
#define kNtOpenExisting 3
#define kNtOpenAlways 4
#define kNtTruncateExisting 5



/*!BEGIN libc/nt/enum/cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CS_H_

#define kNtCsVredraw         0x00000001
#define kNtCsHredraw         0x00000002
#define kNtCsDblclks         0x00000008
#define kNtCsOwndc           0x00000020
#define kNtCsClassdc         0x00000040
#define kNtCsParentdc        0x00000080
#define kNtCsNoclose         0x00000200
#define kNtCsSavebits        0x00000800
#define kNtCsBytealignclient 0x00001000
#define kNtCsBytealignwindow 0x00002000
#define kNtCsGlobalclass     0x00004000
#define kNtCsIme             0x00010000
#define kNtCsDropshadow      0x00020000



/*!BEGIN libc/nt/enum/ctrlevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CTRLEVENT_H_

#define kNtCtrlCEvent 0      /* SIGINT */
#define kNtCtrlBreakEvent 1  /* SIGQUIT */
#define kNtCtrlCloseEvent 2  /* SIGHUP */
#define kNtCtrlLogoffEvent 5 /* SIGTERM */
#define kNtCtrlShutdownEvent 6



/*!BEGIN libc/nt/enum/cw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CW_H_

#define kNtCwUsedefault ((int)0x80000000)



/*!BEGIN libc/nt/enum/dialogresult.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_DIALOGRESULT_H_

#define kNtIdok       1
#define kNtIdcancel   2
#define kNtIdabort    3
#define kNtIdretry    4
#define kNtIdignore   5
#define kNtIdyes      6
#define kNtIdno       7
#define kNtIdclose    8
#define kNtIdhelp     9
#define kNtIdtryagain 10
#define kNtIdcontinue 11



/*!BEGIN libc/nt/enum/errormodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ERRORMODEFLAGS_H_

#define kNtErrorModeDefault      0x0
#define kNtSemFailcriticalerrors 0x1
#define kNtSemNogpfaulterrorbox  0x2
#define kNtSemNoopenfileerrorbox 0x8000



/*!BEGIN libc/nt/enum/event.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENT_H_

#define kNtEventSystemSound            0x0001
#define kNtEventSystemAlert            0x0002
#define kNtEventSystemForeground       0x0003
#define kNtEventSystemMenustart        0x0004
#define kNtEventSystemMenuend          0x0005
#define kNtEventSystemMenupopupstart   0x0006
#define kNtEventSystemMenupopupend     0x0007
#define kNtEventSystemCapturestart     0x0008
#define kNtEventSystemCaptureend       0x0009
#define kNtEventSystemMovesizestart    0x000A
#define kNtEventSystemMovesizeend      0x000B
#define kNtEventSystemContexthelpstart 0x000C
#define kNtEventSystemContexthelpend   0x000D
#define kNtEventSystemDragdropstart    0x000E
#define kNtEventSystemDragdropend      0x000F
#define kNtEventSystemDialogstart      0x0010
#define kNtEventSystemDialogend        0x0011
#define kNtEventSystemScrollingstart   0x0012
#define kNtEventSystemScrollingend     0x0013
#define kNtEventSystemSwitchstart      0x0014
#define kNtEventSystemSwitchend        0x0015
#define kNtEventSystemMinimizestart    0x0016
#define kNtEventSystemMinimizeend      0x0017

#define kNtEventConsoleCaret            0x4001
#define kNtEventConsoleUpdateRegion     0x4002
#define kNtEventConsoleUpdateSimple     0x4003
#define kNtEventConsoleUpdateScroll     0x4004
#define kNtEventConsoleLayout           0x4005
#define kNtEventConsoleStartApplication 0x4006
#define kNtEventConsoleEndApplication   0x4007

#define kNtEventObjectCreate            0x8000
#define kNtEventObjectDestroy           0x8001
#define kNtEventObjectShow              0x8002
#define kNtEventObjectHide              0x8003
#define kNtEventObjectReorder           0x8004
#define kNtEventObjectFocus             0x8005
#define kNtEventObjectSelection         0x8006
#define kNtEventObjectSelectionadd      0x8007
#define kNtEventObjectSelectionremove   0x8008
#define kNtEventObjectSelectionwithin   0x8009
#define kNtEventObjectStatechange       0x800A
#define kNtEventObjectLocationchange    0x800B
#define kNtEventObjectNamechange        0x800C
#define kNtEventObjectDescriptionchange 0x800D
#define kNtEventObjectValuechange       0x800E
#define kNtEventObjectParentchange      0x800F
#define kNtEventObjectHelpchange        0x8010
#define kNtEventObjectDefactionchange   0x8011
#define kNtEventObjectAcceleratorchange 0x8012



/*!BEGIN libc/nt/enum/eventtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENTTYPE_H_

#define kNtNotificationEvent    0
#define kNtSynchronizationEvent 1



/*!BEGIN libc/nt/enum/exceptionhandleractions.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EXCEPTIONHANDLERACTIONS_H_

#define kNtExceptionExecuteHandler 0x1u
#define kNtExceptionContinueExecution 0xffffffffu
#define kNtExceptionContinueSearch 0x0u



/*!BEGIN libc/nt/enum/fileflagandattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEFLAGANDATTRIBUTES_H_

/**
 * MS-DOS File Attributes.
 *
 * @see GetFileInformationByHandle()
 * @see libc/sysv/consts.sh
 */
#define kNtFileAttributeReadonly    0x00000001u
#define kNtFileAttributeHidden      0x00000002u
#define kNtFileAttributeSystem      0x00000004u
#define kNtFileAttributeVolumelabel 0x00000008u
#define kNtFileAttributeDirectory   0x00000010u
#define kNtFileAttributeArchive     0x00000020u

/**
 * NT File Attributes.
 */
#define kNtFileAttributeDevice            0x00000040u
#define kNtFileAttributeNormal            0x00000080u
#define kNtFileAttributeTemporary         0x00000100u
#define kNtFileAttributeSparseFile        0x00000200u
#define kNtFileAttributeReparsePoint      0x00000400u
#define kNtFileAttributeCompressed        0x00000800u
#define kNtFileAttributeOffline           0x00001000u
#define kNtFileAttributeNotContentIndexed 0x00002000u
#define kNtFileAttributeEncrypted         0x00004000u

/**
 * NT File Flags.
 */
#define kNtFileFlagWriteThrough      0x80000000u
#define kNtFileFlagOverlapped        0x40000000u
#define kNtFileFlagNoBuffering       0x20000000u
#define kNtFileFlagRandomAccess      0x10000000u
#define kNtFileFlagSequentialScan    0x08000000u
#define kNtFileFlagDeleteOnClose     0x04000000u
#define kNtFileFlagBackupSemantics   0x02000000u
#define kNtFileFlagPosixSemantics    0x01000000u
#define kNtFileFlagOpenReparsePoint  0x00200000u
#define kNtFileFlagOpenNoRecall      0x00100000u
#define kNtFileFlagFirstPipeInstance 0x00080000u



/*!BEGIN libc/nt/enum/fileinfobyhandleclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFOBYHANDLECLASS_H_

#define kNtFileBasicInfo                  0 /* struct NtFileBasicInformation */
#define kNtFileStandardInfo               1 /* struct NtFileStandardInformation */
#define kNtFileNameInfo                   2 /* struct NtFileNameInformation */
#define kNtFileStreamInfo                 7 /* struct NtFileStreamInformation */
#define kNtFileCompressionInfo            8 /* struct NtFileCompressionInfo */
#define kNtFileAttributeTagInfo           9 /* struct NtFileAttributeTagInformation */
#define kNtFileIdBothDirectoryInfo        10
#define kNtFileIdBothDirectoryRestartInfo 11
#define kNtFileRemoteProtocolInfo         13
#define kNtFileFullDirectoryInfo          14 /* NtFileFullDirectoryInformation */
#define kNtFileFullDirectoryRestartInfo   15
#define kNtFileStorageInfo                16 /* win8+ */
#define kNtFileAlignmentInfo              17 /* win8+ */
#define kNtFileIdInfo                     18 /* win8+ */
#define kNtFileIdExtdDirectoryInfo        19 /* win8+ */
#define kNtFileIdExtdDirectoryRestartInfo 20 /* win8+ */

#define kNtFileRenameInfo         4
#define kNtFileDispositionInfo    5
#define kNtFileAllocationInfo     6
#define kNtFileEndOfFileInfo      7
#define kNtFileIoPriorityHintInfo 13
#define kNtFileDispositionInfoEx  22 /* win10+ */
#define kNtFileRenameInfoEx       23 /* win10+ */



/*!BEGIN libc/nt/enum/fileinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFORMATIONCLASS_H_

#define kNtFileDirectoryInformation 1 /*→ struct NtFileDirectoryInformation */
#define kNtFileFullDirectoryInformation 2 /*→ etc. */
#define kNtFileBothDirectoryInformation 3
#define kNtFileBasicInformation 4
#define kNtFileStandardInformation 5
#define kNtFileInternalInformation 6
#define kNtFileEaInformation 7
#define kNtFileAccessInformation 8
#define kNtFileNameInformation 9
#define kNtFileRenameInformation 10
#define kNtFileLinkInformation 11
#define kNtFileNamesInformation 12
#define kNtFileDispositionInformation 13
#define kNtFilePositionInformation 14
#define kNtFileFullEaInformation 15
#define kNtFileModeInformation 16
#define kNtFileAlignmentInformation 17
#define kNtFileAllInformation 18
#define kNtFileAllocationInformation 19
#define kNtFileEndOfFileInformation 20
#define kNtFileAlternateNameInformation 21
#define kNtFileStreamInformation 22
#define kNtFilePipeInformation 23
#define kNtFilePipeLocalInformation 24
#define kNtFilePipeRemoteInformation 25
#define kNtFileMailslotQueryInformation 26
#define kNtFileMailslotSetInformation 27
#define kNtFileCompressionInformation 28
#define kNtFileObjectIdInformation 29
#define kNtFileCompletionInformation 30
#define kNtFileMoveClusterInformation 31
#define kNtFileQuotaInformation 32
#define kNtFileReparsePointInformation 33
#define kNtFileNetworkOpenInformation 34
#define kNtFileAttributeTagInformation 35
#define kNtFileTrackingInformation 36
#define kNtFileIdBothDirectoryInformation 37
#define kNtFileIdFullDirectoryInformation 38
#define kNtFileValidDataLengthInformation 39
#define kNtFileShortNameInformation 40
#define kNtFileInformation_MAX 40



/*!BEGIN libc/nt/enum/filelockflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILELOCKFLAGS_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/filemapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMAPFLAGS_H_

#define kNtFileMapCopy           0x00000001u
#define kNtFileMapWrite          0x00000002u
#define kNtFileMapRead           0x00000004u
#define kNtFileMapExecute        0x00000020u
#define kNtFileMapReserve        0x80000000u
#define kNtFileMapTargetsInvalid 0x40000000u
#define kNtFileMapLargePages     0x20000000u



/*!BEGIN libc/nt/enum/filemovemethod.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMOVEMETHOD_H_

#define kNtFileBegin   0
#define kNtFileCurrent 1
#define kNtFileEnd     2



/*!BEGIN libc/nt/enum/filesharemode.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILESHAREFLAGS_H_

#define kNtFileShareExclusive 0x00000000u
#define kNtFileShareRead 0x00000001u
#define kNtFileShareWrite 0x00000002u
#define kNtFileShareDelete 0x00000004u



/*!BEGIN libc/nt/enum/filetype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILETYPE_H_

#define kNtFileTypeUnknown 0x0000
#define kNtFileTypeDisk    0x0001 /* @see S_ISBLK() */
#define kNtFileTypeChar    0x0002 /* @see S_ISCHR() */
#define kNtFileTypePipe    0x0003 /* @see S_ISFIFO() */
#define kNtFileTypeRemote  0x8000 /* unused -MSDN */



/*!BEGIN libc/nt/enum/fillattribute.h */

#define COSMOPOLITAN_LIBC_NT_NTFILLATTRIBUTE_H_

#define kNtForegroundBlue 0x0001
#define kNtForegroundGreen 0x0002
#define kNtForegroundRed 0x0004
#define kNtForegroundIntensity 0x0008
#define kNtBackgroundBlue 0x0010
#define kNtBackgroundGreen 0x0020
#define kNtBackgroundRed 0x0040
#define kNtBackgroundIntensity 0x0080



/*!BEGIN libc/nt/enum/findexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXINFOLEVELS_H_

#define kNtFindExInfoStandard     0
#define kNtFindExInfoBasic        1
#define kNtFindExInfoMaxInfoLevel 2



/*!BEGIN libc/nt/enum/findexsearchops.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXSEARCHOPS_H_

#define kNtFindExSearchNameMatch          0
#define kNtFindExSearchLimitToDirectories 1
#define kNtFindExSearchLimitToDevices     2
#define kNtFindExSearchMaxSearchOp        3



/*!BEGIN libc/nt/enum/formatmessageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FORMATMESSAGEFLAGS_H_

#define kNtFormatMessageAllocateBuffer 0x100
#define kNtFormatMessageIgnoreInserts  0x200
#define kNtFormatMessageFromString     0x400
#define kNtFormatMessageFromHmodule    0x800
#define kNtFormatMessageFromSystem     0x1000
#define kNtFormatMessageArgumentArray  0x2000
#define kNtFormatMessageMaxWidthMask   0xff



/*!BEGIN libc/nt/enum/fsctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSCTL_H_

#define kNtFsctlDisableLocalBuffering   0x000902B8u
#define kNtFsctlFilePrefetch            0x00090120u
#define kNtFsctlFilesystemGetStatistics 0x00090060u
#define kNtFsctlGetCompression          0x0009003Cu
#define kNtFsctlGetNtfsFileRecord       0x00090068u
#define kNtFsctlGetNtfsVolumeData       0x00090064u
#define kNtFsctlQueryAllocatedRanges    0x000940CFu
#define kNtFsctlScrubData               0x000902B0u
#define kNtFsctlSetCompression          0x0009C040u
#define kNtFsctlSetSparse               0x000900C4u
#define kNtFsctlSetZeroData             0x000980C8u
#define kNtFsctlGetReparsePoint         0x000900a8u
#define kNtFsctlSetReparsePoint         0x000900a4u



/*!BEGIN libc/nt/enum/fsinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSINFORMATIONCLASS_H_

#define kNtFileFsVolumeInformation 1
#define kNtFileFsLabelInformation 2
#define kNtFileFsSizeInformation 3
#define kNtFileFsDeviceInformation 4
#define kNtFileFsAttributeInformation 5
#define kNtFileFsControlInformation 6
#define kNtFileFsFullSizeInformation 7
#define kNtFileFsObjectIdInformation 8
#define kNtFileFsDriverPathInformation 9
#define kNtFileFsInformation_MAX 10



/*!BEGIN libc/nt/enum/getfileexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_GETFILEEXINFOLEVELS_H_

#define kNtGetFileExInfoStandard 0



/*!BEGIN libc/nt/enum/heap.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HEAP_H_

#define kNtHeapNoSerialize        1
#define kNtHeapGenerateExceptions 4
#define kNtHeapZeroMemory         8
#define kNtHeapReallocInPlaceOnly 16



/*!BEGIN libc/nt/enum/ht.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HT_H_

#define kNtHterror       -2
#define kNtHttransparent -1
#define kNtHtnowhere     0
#define kNtHtclient      1
#define kNtHtcaption     2
#define kNtHtsysmenu     3
#define kNtHtgrowbox     4
#define kNtHtsize        kNtHtgrowbox
#define kNtHtmenu        5
#define kNtHthscroll     6
#define kNtHtvscroll     7
#define kNtHtminbutton   8
#define kNtHtmaxbutton   9
#define kNtHtleft        10
#define kNtHtright       11
#define kNtHttop         12
#define kNtHttopleft     13
#define kNtHttopright    14
#define kNtHtbottom      15
#define kNtHtbottomleft  16
#define kNtHtbottomright 17
#define kNtHtborder      18
#define kNtHtreduce      kNtHtminbutton
#define kNtHtzoom        kNtHtmaxbutton
#define kNtHtsizefirst   kNtHtleft
#define kNtHtsizelast    kNtHtbottomright
#define kNtHtobject      19
#define kNtHtclose       20
#define kNtHthelp        21



/*!BEGIN libc/nt/enum/idc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IDC_H_
COSMOPOLITAN_C_START_

#define kNtIdcArrow    ((const char16_t *)32512)
#define kNtIdcIbeam    ((const char16_t *)32513)
#define kNtIdcWait     ((const char16_t *)32514)
#define kNtIdcCross    ((const char16_t *)32515)
#define kNtIdcUparrow  ((const char16_t *)32516)
#define kNtIdcSizenwse ((const char16_t *)32642)
#define kNtIdcSizenesw ((const char16_t *)32643)
#define kNtIdcSizewe   ((const char16_t *)32644)
#define kNtIdcSizens   ((const char16_t *)32645)
#define kNtIdcSizeall  ((const char16_t *)32646)
#define kNtIdcNo       ((const char16_t *)32648)
#define kNtIdcHand     ((const char16_t *)32649)
#define kNtIdcHelp     ((const char16_t *)32651)
#define kNtIdcPin      ((const char16_t *)32671)
#define kNtIdcPerson   ((const char16_t *)32672)

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/imageauxsymboltype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMAGEAUXSYMBOLTYPE_H_

#define kNtImageAuxSymbolTypeTokenDef 1



/*!BEGIN libc/nt/enum/importobjectnametype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTNAMETYPE_H_

enum NtImportObjectNameType {
  IMPORT_OBJECT_ORDINAL,
  IMPORT_OBJECT_NAME,
  IMPORT_OBJECT_NAME_NO_PREFIX,
  IMPORT_OBJECT_NAME_UNDECORATE,
  IMPORT_OBJECT_NAME_EXPORTAS
};



/*!BEGIN libc/nt/enum/importobjecttype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTTYPE_H_

enum NtImportObjectType {
  IMPORT_OBJECT_CODE,
  IMPORT_OBJECT_DATA,
  IMPORT_OBJECT_CONST
};



/*!BEGIN libc/nt/enum/io.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IO_H_

#define kNtIoReparseTagSymlink    0xa000000c
#define kNtIoReparseTagMountPoint 0xa0000003



/*!BEGIN libc/nt/enum/ioctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IOCTL_H_

#define kNtIoctlDiskGetDriveGeometry 0x00070000u
#define kNtIoctlAfdPoll              0x00012024u



/*!BEGIN libc/nt/enum/jobobjectinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_JOBOBJECTINFOCLASS_H_

#define kNtJobObjectBasicAccountingInformation         1
#define kNtJobObjectBasicLimitInformation              2
#define kNtJobObjectBasicProcessIdList                 3
#define kNtJobObjectBasicUIRestrictions                4
#define kNtJobObjectSecurityLimitInformation           5
#define kNtJobObjectEndOfJobTimeInformation            6
#define kNtJobObjectAssociateCompletionPortInformation 7
#define kNtJobObjectBasicAndIoAccountingInformation    8
#define kNtJobObjectExtendedLimitInformation           9
#define kNtJobObjectJobSetInformation                  10



/*!BEGIN libc/nt/enum/keyaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_

#define kNtKeyRead      0x00020019
#define kNtKeyWrite     0x00020006
#define kNtKeyExecute   0x00020019
#define kNtKeyAllAccess 0x000f003f



/*!BEGIN libc/nt/enum/keyedevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYEDEVENT_H_

#define kNtKeyedeventWait 0x00000001u
#define kNtKeyedeventWake 0x00000002u
#define kNtKeyedeventAllAccess \
  (kNtStandardRightsRequired | kNtKeyedeventWait | kNtKeyedeventWake)



/*!BEGIN libc/nt/enum/keyinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYINFORMATIONCLASS_H_

#define kNtKeyBasicInformation 0
#define kNtKeyNodeInformation  1
#define kNtKeyFullInformation  2
#define kNtKeyNameInformation  3



/*!BEGIN libc/nt/enum/kwaitreason.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KWAITREASON_H_

#define kNtExecutive 0
#define kNtFreePage 1
#define kNtPageIn 2
#define kNtPoolAllocation 3
#define kNtDelayExecution 4
#define kNtSuspended 5
#define kNtUserRequest 6
#define kNtWrExecutive 7
#define kNtWrFreePage 8
#define kNtWrPageIn 9
#define kNtWrPoolAllocation 10
#define kNtWrDelayExecution 11
#define kNtWrSuspended 12
#define kNtWrUserRequest 13
#define kNtWrEventPair 14
#define kNtWrQueue 15
#define kNtWrLpcReceive 16
#define kNtWrLpcReply 17
#define kNtWrVirtualMemory 18
#define kNtWrPageOut 19
#define kNtWrRendezvous 20
#define kNtSpare2 21
#define kNtSpare3 22
#define kNtSpare4 23
#define kNtSpare5 24
#define kNtSpare6 25
#define kNtWrKernel 26
#define kNtMaximumWaitReason 27



/*!BEGIN libc/nt/enum/lang.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LANG_H_

#define MAKELANGID(p, s) ((((uint16_t)(s)) << 10) | (uint16_t)(p))

#define kNtLangNeutral            0x00
#define kNtLangInvariant          0x7f
#define kNtLangAfrikaans          0x36
#define kNtLangAlbanian           0x1c
#define kNtLangAlsatian           0x84
#define kNtLangAmharic            0x5e
#define kNtLangArabic             0x01
#define kNtLangArmenian           0x2b
#define kNtLangAssamese           0x4d
#define kNtLangAzeri              0x2c
#define kNtLangAzerbaijani        0x2c
#define kNtLangBangla             0x45
#define kNtLangBashkir            0x6d
#define kNtLangBasque             0x2d
#define kNtLangBelarusian         0x23
#define kNtLangBengali            0x45
#define kNtLangBreton             0x7e
#define kNtLangBosnian            0x1a
#define kNtLangBosnianNeutral     0x781a
#define kNtLangBulgarian          0x02
#define kNtLangCatalan            0x03
#define kNtLangCentralKurdish     0x92
#define kNtLangCherokee           0x5c
#define kNtLangChinese            0x04
#define kNtLangChineseSimplified  0x04
#define kNtLangChineseTraditional 0x7c04
#define kNtLangCorsican           0x83
#define kNtLangCroatian           0x1a
#define kNtLangCzech              0x05
#define kNtLangDanish             0x06
#define kNtLangDari               0x8c
#define kNtLangDivehi             0x65
#define kNtLangDutch              0x13
#define kNtLangEnglish            0x09
#define kNtLangEstonian           0x25
#define kNtLangFaeroese           0x38
#define kNtLangFarsi              0x29
#define kNtLangFilipino           0x64
#define kNtLangFinnish            0x0b
#define kNtLangFrench             0x0c
#define kNtLangFrisian            0x62
#define kNtLangFulah              0x67
#define kNtLangGalician           0x56
#define kNtLangGeorgian           0x37
#define kNtLangGerman             0x07
#define kNtLangGreek              0x08
#define kNtLangGreenlandic        0x6f
#define kNtLangGujarati           0x47
#define kNtLangHausa              0x68
#define kNtLangHawaiian           0x75
#define kNtLangHebrew             0x0d
#define kNtLangHindi              0x39
#define kNtLangHungarian          0x0e
#define kNtLangIcelandic          0x0f
#define kNtLangIgbo               0x70
#define kNtLangIndonesian         0x21
#define kNtLangInuktitut          0x5d
#define kNtLangIrish              0x3c
#define kNtLangItalian            0x10
#define kNtLangJapanese           0x11
#define kNtLangKannada            0x4b
#define kNtLangKashmiri           0x60
#define kNtLangKazak              0x3f
#define kNtLangKhmer              0x53
#define kNtLangKiche              0x86
#define kNtLangKinyarwanda        0x87
#define kNtLangKonkani            0x57
#define kNtLangKorean             0x12
#define kNtLangKyrgyz             0x40
#define kNtLangLao                0x54
#define kNtLangLatvian            0x26
#define kNtLangLithuanian         0x27
#define kNtLangLowerSorbian       0x2e
#define kNtLangLuxembourgish      0x6e
#define kNtLangMacedonian         0x2f
#define kNtLangMalay              0x3e
#define kNtLangMalayalam          0x4c
#define kNtLangMaltese            0x3a
#define kNtLangManipuri           0x58
#define kNtLangMaori              0x81
#define kNtLangMapudungun         0x7a
#define kNtLangMarathi            0x4e
#define kNtLangMohawk             0x7c
#define kNtLangMongolian          0x50
#define kNtLangNepali             0x61
#define kNtLangNorwegian          0x14
#define kNtLangOccitan            0x82
#define kNtLangOdia               0x48
#define kNtLangOriya              0x48
#define kNtLangPashto             0x63
#define kNtLangPersian            0x29
#define kNtLangPolish             0x15
#define kNtLangPortuguese         0x16
#define kNtLangPular              0x67
#define kNtLangPunjabi            0x46
#define kNtLangQuechua            0x6b
#define kNtLangRomanian           0x18
#define kNtLangRomansh            0x17
#define kNtLangRussian            0x19
#define kNtLangSakha              0x85
#define kNtLangSami               0x3b
#define kNtLangSanskrit           0x4f
#define kNtLangScottishGaelic     0x91
#define kNtLangSerbian            0x1a
#define kNtLangSerbianNeutral     0x7c1a
#define kNtLangSindhi             0x59
#define kNtLangSinhalese          0x5b
#define kNtLangSlovak             0x1b
#define kNtLangSlovenian          0x24
#define kNtLangSotho              0x6c
#define kNtLangSpanish            0x0a
#define kNtLangSwahili            0x41
#define kNtLangSwedish            0x1d
#define kNtLangSyriac             0x5a
#define kNtLangTajik              0x28
#define kNtLangTamazight          0x5f
#define kNtLangTamil              0x49
#define kNtLangTatar              0x44
#define kNtLangTelugu             0x4a
#define kNtLangThai               0x1e
#define kNtLangTibetan            0x51
#define kNtLangTigrigna           0x73
#define kNtLangTigrinya           0x73
#define kNtLangTswana             0x32
#define kNtLangTurkish            0x1f
#define kNtLangTurkmen            0x42
#define kNtLangUighur             0x80
#define kNtLangUkrainian          0x22
#define kNtLangUpperSorbian       0x2e
#define kNtLangUrdu               0x20
#define kNtLangUzbek              0x43
#define kNtLangValencian          0x03
#define kNtLangVietnamese         0x2a
#define kNtLangWelsh              0x52
#define kNtLangWolof              0x88
#define kNtLangXhosa              0x34
#define kNtLangYakut              0x85
#define kNtLangYi                 0x78
#define kNtLangYoruba             0x6a
#define kNtLangZulu               0x35

#define kNtSublangNeutral                          0x00
#define kNtSublangDefault                          0x01
#define kNtSublangSysDefault                       0x02
#define kNtSublangCustomDefault                    0x03
#define kNtSublangCustomUnspecified                0x04
#define kNtSublangUiCustomDefault                  0x05
#define kNtSublangAfrikaansSouthAfrica             0x01
#define kNtSublangAlbanianAlbania                  0x01
#define kNtSublangAlsatianFrance                   0x01
#define kNtSublangAmharicEthiopia                  0x01
#define kNtSublangArabicSaudiArabia                0x01
#define kNtSublangArabicIraq                       0x02
#define kNtSublangArabicEgypt                      0x03
#define kNtSublangArabicLibya                      0x04
#define kNtSublangArabicAlgeria                    0x05
#define kNtSublangArabicMorocco                    0x06
#define kNtSublangArabicTunisia                    0x07
#define kNtSublangArabicOman                       0x08
#define kNtSublangArabicYemen                      0x09
#define kNtSublangArabicSyria                      0x0a
#define kNtSublangArabicJordan                     0x0b
#define kNtSublangArabicLebanon                    0x0c
#define kNtSublangArabicKuwait                     0x0d
#define kNtSublangArabicUae                        0x0e
#define kNtSublangArabicBahrain                    0x0f
#define kNtSublangArabicQatar                      0x10
#define kNtSublangArmenianArmenia                  0x01
#define kNtSublangAssameseIndia                    0x01
#define kNtSublangAzeriLatin                       0x01
#define kNtSublangAzeriCyrillic                    0x02
#define kNtSublangAzerbaijaniAzerbaijanLatin       0x01
#define kNtSublangAzerbaijaniAzerbaijanCyrillic    0x02
#define kNtSublangBanglaIndia                      0x01
#define kNtSublangBanglaBangladesh                 0x02
#define kNtSublangBashkirRussia                    0x01
#define kNtSublangBasqueBasque                     0x01
#define kNtSublangBelarusianBelarus                0x01
#define kNtSublangBengaliIndia                     0x01
#define kNtSublangBengaliBangladesh                0x02
#define kNtSublangBosnianBosniaHerzegovinaLatin    0x05
#define kNtSublangBosnianBosniaHerzegovinaCyrillic 0x08
#define kNtSublangBretonFrance                     0x01
#define kNtSublangBulgarianBulgaria                0x01
#define kNtSublangCatalanCatalan                   0x01
#define kNtSublangCentralKurdishIraq               0x01
#define kNtSublangCherokeeCherokee                 0x01
#define kNtSublangChineseTraditional               0x01
#define kNtSublangChineseSimplified                0x02
#define kNtSublangChineseHongkong                  0x03
#define kNtSublangChineseSingapore                 0x04
#define kNtSublangChineseMacau                     0x05
#define kNtSublangCorsicanFrance                   0x01
#define kNtSublangCzechCzechRepublic               0x01
#define kNtSublangCroatianCroatia                  0x01
#define kNtSublangCroatianBosniaHerzegovinaLatin   0x04
#define kNtSublangDanishDenmark                    0x01
#define kNtSublangDariAfghanistan                  0x01
#define kNtSublangDivehiMaldives                   0x01
#define kNtSublangDutch                            0x01
#define kNtSublangDutchBelgian                     0x02
#define kNtSublangEnglishUs                        0x01
#define kNtSublangEnglishUk                        0x02
#define kNtSublangEnglishAus                       0x03
#define kNtSublangEnglishCan                       0x04
#define kNtSublangEnglishNz                        0x05
#define kNtSublangEnglishEire                      0x06
#define kNtSublangEnglishSouthAfrica               0x07
#define kNtSublangEnglishJamaica                   0x08
#define kNtSublangEnglishCaribbean                 0x09
#define kNtSublangEnglishBelize                    0x0a
#define kNtSublangEnglishTrinidad                  0x0b
#define kNtSublangEnglishZimbabwe                  0x0c
#define kNtSublangEnglishPhilippines               0x0d
#define kNtSublangEnglishIndia                     0x10
#define kNtSublangEnglishMalaysia                  0x11
#define kNtSublangEnglishSingapore                 0x12
#define kNtSublangEstonianEstonia                  0x01
#define kNtSublangFaeroeseFaroeIslands             0x01
#define kNtSublangFilipinoPhilippines              0x01
#define kNtSublangFinnishFinland                   0x01
#define kNtSublangFrench                           0x01
#define kNtSublangFrenchBelgian                    0x02
#define kNtSublangFrenchCanadian                   0x03
#define kNtSublangFrenchSwiss                      0x04
#define kNtSublangFrenchLuxembourg                 0x05
#define kNtSublangFrenchMonaco                     0x06
#define kNtSublangFrisianNetherlands               0x01
#define kNtSublangFulahSenegal                     0x02
#define kNtSublangGalicianGalician                 0x01
#define kNtSublangGeorgianGeorgia                  0x01
#define kNtSublangGerman                           0x01
#define kNtSublangGermanSwiss                      0x02
#define kNtSublangGermanAustrian                   0x03
#define kNtSublangGermanLuxembourg                 0x04
#define kNtSublangGermanLiechtenstein              0x05
#define kNtSublangGreekGreece                      0x01
#define kNtSublangGreenlandicGreenland             0x01
#define kNtSublangGujaratiIndia                    0x01
#define kNtSublangHausaNigeriaLatin                0x01
#define kNtSublangHawaiianUs                       0x01
#define kNtSublangHebrewIsrael                     0x01
#define kNtSublangHindiIndia                       0x01
#define kNtSublangHungarianHungary                 0x01
#define kNtSublangIcelandicIceland                 0x01
#define kNtSublangIgboNigeria                      0x01
#define kNtSublangIndonesianIndonesia              0x01
#define kNtSublangInuktitutCanada                  0x01
#define kNtSublangInuktitutCanadaLatin             0x02
#define kNtSublangIrishIreland                     0x02
#define kNtSublangItalian                          0x01
#define kNtSublangItalianSwiss                     0x02
#define kNtSublangJapaneseJapan                    0x01
#define kNtSublangKannadaIndia                     0x01
#define kNtSublangKashmiriSasia                    0x02
#define kNtSublangKashmiriIndia                    0x02
#define kNtSublangKazakKazakhstan                  0x01
#define kNtSublangKhmerCambodia                    0x01
#define kNtSublangKicheGuatemala                   0x01
#define kNtSublangKinyarwandaRwanda                0x01
#define kNtSublangKonkaniIndia                     0x01
#define kNtSublangKorean                           0x01
#define kNtSublangKyrgyzKyrgyzstan                 0x01
#define kNtSublangLaoLao                           0x01
#define kNtSublangLatvianLatvia                    0x01
#define kNtSublangLithuanian                       0x01
#define kNtSublangLowerSorbianGermany              0x02
#define kNtSublangLuxembourgishLuxembourg          0x01
#define kNtSublangMacedonianMacedonia              0x01
#define kNtSublangMalayMalaysia                    0x01
#define kNtSublangMalayBruneiDarussalam            0x02
#define kNtSublangMalayalamIndia                   0x01
#define kNtSublangMalteseMalta                     0x01
#define kNtSublangMaoriNewZealand                  0x01
#define kNtSublangMapudungunChile                  0x01
#define kNtSublangMarathiIndia                     0x01
#define kNtSublangMohawkMohawk                     0x01
#define kNtSublangMongolianCyrillicMongolia        0x01
#define kNtSublangMongolianPrc                     0x02
#define kNtSublangNepaliIndia                      0x02
#define kNtSublangNepaliNepal                      0x01
#define kNtSublangNorwegianBokmal                  0x01
#define kNtSublangNorwegianNynorsk                 0x02
#define kNtSublangOccitanFrance                    0x01
#define kNtSublangOdiaIndia                        0x01
#define kNtSublangOriyaIndia                       0x01
#define kNtSublangPashtoAfghanistan                0x01
#define kNtSublangPersianIran                      0x01
#define kNtSublangPolishPoland                     0x01
#define kNtSublangPortuguese                       0x02
#define kNtSublangPortugueseBrazilian              0x01
#define kNtSublangPularSenegal                     0x02
#define kNtSublangPunjabiIndia                     0x01
#define kNtSublangPunjabiPakistan                  0x02
#define kNtSublangQuechuaBolivia                   0x01
#define kNtSublangQuechuaEcuador                   0x02
#define kNtSublangQuechuaPeru                      0x03
#define kNtSublangRomanianRomania                  0x01
#define kNtSublangRomanshSwitzerland               0x01
#define kNtSublangRussianRussia                    0x01
#define kNtSublangSakhaRussia                      0x01
#define kNtSublangSamiNorthernNorway               0x01
#define kNtSublangSamiNorthernSweden               0x02
#define kNtSublangSamiNorthernFinland              0x03
#define kNtSublangSamiLuleNorway                   0x04
#define kNtSublangSamiLuleSweden                   0x05
#define kNtSublangSamiSouthernNorway               0x06
#define kNtSublangSamiSouthernSweden               0x07
#define kNtSublangSamiSkoltFinland                 0x08
#define kNtSublangSamiInariFinland                 0x09
#define kNtSublangSanskritIndia                    0x01
#define kNtSublangScottishGaelic                   0x01
#define kNtSublangSerbianBosniaHerzegovinaLatin    0x06
#define kNtSublangSerbianBosniaHerzegovinaCyrillic 0x07
#define kNtSublangSerbianMontenegroLatin           0x0b
#define kNtSublangSerbianMontenegroCyrillic        0x0c
#define kNtSublangSerbianSerbiaLatin               0x09
#define kNtSublangSerbianSerbiaCyrillic            0x0a
#define kNtSublangSerbianCroatia                   0x01
#define kNtSublangSerbianLatin                     0x02
#define kNtSublangSerbianCyrillic                  0x03
#define kNtSublangSindhiIndia                      0x01
#define kNtSublangSindhiPakistan                   0x02
#define kNtSublangSindhiAfghanistan                0x02
#define kNtSublangSinhaleseSriLanka                0x01
#define kNtSublangSothoNorthernSouthAfrica         0x01
#define kNtSublangSlovakSlovakia                   0x01
#define kNtSublangSlovenianSlovenia                0x01
#define kNtSublangSpanish                          0x01
#define kNtSublangSpanishMexican                   0x02
#define kNtSublangSpanishModern                    0x03
#define kNtSublangSpanishGuatemala                 0x04
#define kNtSublangSpanishCostaRica                 0x05
#define kNtSublangSpanishPanama                    0x06
#define kNtSublangSpanishDominicanRepublic         0x07
#define kNtSublangSpanishVenezuela                 0x08
#define kNtSublangSpanishColombia                  0x09
#define kNtSublangSpanishPeru                      0x0a
#define kNtSublangSpanishArgentina                 0x0b
#define kNtSublangSpanishEcuador                   0x0c
#define kNtSublangSpanishChile                     0x0d
#define kNtSublangSpanishUruguay                   0x0e
#define kNtSublangSpanishParaguay                  0x0f
#define kNtSublangSpanishBolivia                   0x10
#define kNtSublangSpanishElSalvador                0x11
#define kNtSublangSpanishHonduras                  0x12
#define kNtSublangSpanishNicaragua                 0x13
#define kNtSublangSpanishPuertoRico                0x14
#define kNtSublangSpanishUs                        0x15
#define kNtSublangSwahiliKenya                     0x01
#define kNtSublangSwedish                          0x01
#define kNtSublangSwedishFinland                   0x02
#define kNtSublangSyriacSyria                      0x01
#define kNtSublangTajikTajikistan                  0x01
#define kNtSublangTamazightAlgeriaLatin            0x02
#define kNtSublangTamazightMoroccoTifinagh         0x04
#define kNtSublangTamilIndia                       0x01
#define kNtSublangTamilSriLanka                    0x02
#define kNtSublangTatarRussia                      0x01
#define kNtSublangTeluguIndia                      0x01
#define kNtSublangThaiThailand                     0x01
#define kNtSublangTibetanPrc                       0x01
#define kNtSublangTigrignaEritrea                  0x02
#define kNtSublangTigrinyaEritrea                  0x02
#define kNtSublangTigrinyaEthiopia                 0x01
#define kNtSublangTswanaBotswana                   0x02
#define kNtSublangTswanaSouthAfrica                0x01
#define kNtSublangTurkishTurkey                    0x01
#define kNtSublangTurkmenTurkmenistan              0x01
#define kNtSublangUighurPrc                        0x01
#define kNtSublangUkrainianUkraine                 0x01
#define kNtSublangUpperSorbianGermany              0x01
#define kNtSublangUrduPakistan                     0x01
#define kNtSublangUrduIndia                        0x02
#define kNtSublangUzbekLatin                       0x01
#define kNtSublangUzbekCyrillic                    0x02
#define kNtSublangValencianValencia                0x02
#define kNtSublangVietnameseVietnam                0x01
#define kNtSublangWelshUnitedKingdom               0x01
#define kNtSublangWolofSenegal                     0x01
#define kNtSublangXhosaSouthAfrica                 0x01
#define kNtSublangYakutRussia                      0x01
#define kNtSublangYiPrc                            0x01
#define kNtSublangYorubaNigeria                    0x01
#define kNtSublangZuluSouthAfrica                  0x01



/*!BEGIN libc/nt/enum/loadlibrarysearch.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOADLIBRARYSEARCH_H_

#define kNtLoadLibrarySearchApplicationDir 0x00000200u
#define kNtLoadLibrarySearchSearchSystem32 0x00000800u
#define kNtLoadLibrarySearchUserDirs       0x00000400u
#define kNtLoadLibrarySearchDefaultDirs    0x00001000u



/*!BEGIN libc/nt/enum/lockfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOCKFILE_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/mb.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MB_H_

#define kNtMbOk                      0x00000000
#define kNtMbOkcancel                0x00000001
#define kNtMbAbortretryignore        0x00000002
#define kNtMbYesnocancel             0x00000003
#define kNtMbYesno                   0x00000004
#define kNtMbRetrycancel             0x00000005
#define kNtMbCanceltrycontinue       0x00000006
#define kNtMbIconhand                0x00000010
#define kNtMbIconquestion            0x00000020
#define kNtMbIconexclamation         0x00000030
#define kNtMbIconasterisk            0x00000040
#define kNtMbUsericon                0x00000080
#define kNtMbIconwarning             kNtMbIconexclamation
#define kNtMbIconerror               kNtMbIconhand
#define kNtMbIconinformation         kNtMbIconasterisk
#define kNtMbIconstop                kNtMbIconhand
#define kNtMbDefbutton1              0x00000000
#define kNtMbDefbutton2              0x00000100
#define kNtMbDefbutton3              0x00000200
#define kNtMbDefbutton4              0x00000300
#define kNtMbApplmodal               0x00000000
#define kNtMbSystemmodal             0x00001000
#define kNtMbTaskmodal               0x00002000
#define kNtMbHelp                    0x00004000
#define kNtMbNofocus                 0x00008000
#define kNtMbSetforeground           0x00010000
#define kNtMbDefaultDesktopOnly      0x00020000
#define kNtMbTopmost                 0x00040000
#define kNtMbRight                   0x00080000
#define kNtMbRtlreading              0x00100000
#define kNtMbServiceNotification     0x00200000
#define kNtMbServiceNotificationNt3x 0x00040000
#define kNtMbTypemask                0x0000000F
#define kNtMbIconmask                0x000000F0
#define kNtMbDefmask                 0x00000F00
#define kNtMbModemask                0x00003000
#define kNtMbMiscmask                0x0000C000



/*!BEGIN libc/nt/enum/memflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMFLAGS_H_

#define kNtMemCommit     0x1000 /* perform physical memory reservation step */
#define kNtMemReserve    0x2000 /* perform virtual memory reservation step */
#define kNtMemDecommit   0x4000
#define kNtMemRelease    0x8000
#define kNtMemFree       0x10000
#define kNtMemPrivate    0x20000
#define kNtMemMapped     0x40000
#define kNtMemReset      0x80000
#define kNtMemTopDown    0x100000
#define kNtMemWriteWatch 0x200000
#define kNtMemPhysical   0x400000
#define kNtMemImage      0x1000000
#define kNtMemLargePages 0x20000000
#define kNtMem4mbPages   0x80000000

#define kNtMemReplacePlaceholder 0x00004000



/*!BEGIN libc/nt/enum/memoryinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMORYINFORMATIONCLASS_H_

#define kNtMemoryBasicInformation    0
#define kNtMemoryWorkingSetList      1
#define kNtMemorySectionName         2
#define kNtMemoryBasicVlmInformation 3



/*!BEGIN libc/nt/enum/mf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MF_H_

#define kNtMfInsert          0x00000000
#define kNtMfChange          0x00000080
#define kNtMfAppend          0x00000100
#define kNtMfDelete          0x00000200
#define kNtMfRemove          0x00001000
#define kNtMfBycommand       0x00000000
#define kNtMfByposition      0x00000400
#define kNtMfSeparator       0x00000800
#define kNtMfEnabled         0x00000000
#define kNtMfGrayed          0x00000001
#define kNtMfDisabled        0x00000002
#define kNtMfUnchecked       0x00000000
#define kNtMfChecked         0x00000008
#define kNtMfUsecheckbitmaps 0x00000200
#define kNtMfString          0x00000000
#define kNtMfBitmap          0x00000004
#define kNtMfOwnerdraw       0x00000100
#define kNtMfPopup           0x00000010
#define kNtMfMenubarbreak    0x00000020
#define kNtMfMenubreak       0x00000040
#define kNtMfUnhilite        0x00000000
#define kNtMfHilite          0x00000080
#define kNtMfDefault         0x00001000
#define kNtMfSysmenu         0x00002000
#define kNtMfHelp            0x00004000
#define kNtMfRightjustify    0x00004000
#define kNtMfMouseselect     0x00008000



/*!BEGIN libc/nt/enum/mk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MK_H_

#define kNtMkLbutton  0x0001
#define kNtMkRbutton  0x0002
#define kNtMkShift    0x0004
#define kNtMkControl  0x0008
#define kNtMkMbutton  0x0010
#define kNtMkXbutton1 0x0020
#define kNtMkXbutton2 0x0040



/*!BEGIN libc/nt/enum/movefileexflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MOVEFILEEXFLAGS_H_

#define kNtMovefileReplaceExisting    1
#define kNtMovefileCopyAllowed        2
#define kNtMovefileDelayUntilReboot   4
#define kNtMovefileWriteThrough       8
#define kNtMovefileCreateHardlink     16
#define kNtMovefileFailIfNotTrackable 32



/*!BEGIN libc/nt/enum/objectinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OBJECTINFORMATIONCLASS_H_

#define kNtObjectBasicInformation 0 /*→ struct NtObjectBasicInformation */
#define kNtObjectNameInformation  1 /*→ etc. */
#define kNtObjectTypeInformation  2
#define kNtObjectAllInformation   3
#define kNtObjectDataInformation  4



/*!BEGIN libc/nt/enum/offerpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFFERPRIORITY_H_

/* TODO(jart): Are these values correct? */
#define kNtVmOfferPriorityVeryLow     1 /* 0x00001000? */
#define kNtVmOfferPriorityLow         2 /* 0x00002000? */
#define kNtVmOfferPriorityBelowNormal 3 /* 0x00002000? */
#define kNtVmOfferPriorityNormal      4 /* 0x00002000? */



/*!BEGIN libc/nt/enum/ofn.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFN_H_

#define kNtOfnReadonly             0x00000001
#define kNtOfnOverwriteprompt      0x00000002
#define kNtOfnHidereadonly         0x00000004
#define kNtOfnNochangedir          0x00000008
#define kNtOfnShowhelp             0x00000010
#define kNtOfnEnablehook           0x00000020
#define kNtOfnEnabletemplate       0x00000040
#define kNtOfnEnabletemplatehandle 0x00000080
#define kNtOfnNovalidate           0x00000100
#define kNtOfnAllowmultiselect     0x00000200
#define kNtOfnExtensiondifferent   0x00000400
#define kNtOfnPathmustexist        0x00000800
#define kNtOfnFilemustexist        0x00001000
#define kNtOfnCreateprompt         0x00002000
#define kNtOfnShareaware           0x00004000
#define kNtOfnNoreadonlyreturn     0x00008000
#define kNtOfnNotestfilecreate     0x00010000
#define kNtOfnNonetworkbutton      0x00020000
#define kNtOfnNolongnames          0x00040000
#define kNtOfnExplorer             0x00080000
#define kNtOfnNodereferencelinks   0x00100000
#define kNtOfnLongnames            0x00200000
#define kNtOfnEnableincludenotify  0x00400000
#define kNtOfnEnablesizing         0x00800000
#define kNtOfnDontaddtorecent      0x02000000
#define kNtOfnForceshowhidden      0x10000000



/*!BEGIN libc/nt/enum/pageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PAGEFLAGS_H_

/* Pick One */
#define kNtPageNoaccess         0x001
#define kNtPageReadonly         0x002
#define kNtPageReadwrite        0x004
#define kNtPageWritecopy        0x008
#define kNtPageExecute          0x010
#define kNtPageExecuteRead      0x020
#define kNtPageExecuteReadwrite 0x040
#define kNtPageExecuteWritecopy 0x080
#define kNtPageGuard            0x100
#define kNtPageNocache          0x200
#define kNtPageWritecombine     0x400

/* These may be OR'd */
#define kNtSecReserve        0x04000000
#define kNtSecCommit         0x08000000 /* default */
#define kNtSecImageNoExecute 0x11000000
#define kNtSecImage          0x01000000
#define kNtSecNocache        0x10000000
#define kNtSecLargePages     0x80000000
#define kNtSecWritecombine   0x40000000



/*!BEGIN libc/nt/enum/pdh.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PDH_H_

#define kNtPdhFmtRaw          0x00000010u
#define kNtPdhFmtAnsi         0x00000020u
#define kNtPdhFmtUnicode      0x00000040u
#define kNtPdhFmtLong         0x00000100u
#define kNtPdhFmtDouble       0x00000200u
#define kNtPdhFmtLarge        0x00000400u
#define kNtPdhFmtNoscale      0x00001000u
#define kNtPdhFmt1000         0x00002000u
#define kNtPdhFmtNodata       0x00004000u
#define kNtPdhFmtNocap100     0x00008000u
#define kNtPerfDetailCostly   0x00010000u
#define kNtPerfDetailStandard 0x0000FFFFu



/*!BEGIN libc/nt/enum/processaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSACCESS_H_

#define kNtProcessCreateProcess 0x0080u
#define kNtProcessCreateThread 0x0002u
#define kNtProcessDupHandle 0x0040u
#define kNtProcessQueryInformation 0x0400u
#define kNtProcessQueryLimitedInformation 0x1000u
#define kNtProcessSetInformation 0x0200u
#define kNtProcessSetQuota 0x0100u
#define kNtProcessSuspendResume 0x0800u
#define kNtProcessTerminate 0x0001u
#define kNtProcessVmOperation 0x0008u
#define kNtProcessVmRead 0x0010u
#define kNtProcessVmWrite 0x0020u
#define kNtProcessSynchronize kNtSynchronize
#define kNtProcessAllAccess \
  (kNtStandardRightsRequired | kNtSynchronize | 0xffffu)



/*!BEGIN libc/nt/enum/processcreationflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSCREATIONFLAGS_H_

#define kNtIdlePriorityClass        0x00000040u
#define kNtBelowNormalPriorityClass 0x00004000u
#define kNtNormalPriorityClass      0x00000020u
#define kNtAboveNormalPriorityClass 0x00008000u
#define kNtHighPriorityClass        0x00000080u
#define kNtRealtimePriorityClass    0x00000100u

#define kNtDebugProcess                 0x00000001u
#define kNtDebugOnlyThisProcess         0x00000002u
#define kNtCreateSuspended              0x00000004u
#define kNtDetachedProcess              0x00000008u
#define kNtCreateNewConsole             0x00000010u
#define kNtCreateNewProcessGroup        0x00000200u
#define kNtCreateUnicodeEnvironment     0x00000400u
#define kNtCreateSeparateWowVdm         0x00000800u
#define kNtCreateSharedWowVdm           0x00001000u
#define kNtCreateForcedos               0x00002000u
#define kNtInheritParentAffinity        0x00010000u
#define kNtCreateProtectedProcess       0x00040000u
#define kNtExtendedStartupinfoPresent   0x00080000u
#define kNtProcessModeBackgroundBegin   0x00100000u
#define kNtProcessModeBackgroundEnd     0x00200000u
#define kNtCreateSecureProcess          0x00400000u
#define kNtCreateBreakawayFromJob       0x01000000u
#define kNtCreatePreserveCodeAuthzLevel 0x02000000u
#define kNtCreateDefaultErrorMode       0x04000000u
#define kNtCreateNoWindow               0x08000000u
#define kNtProfileUser                  0x10000000u
#define kNtProfileKernel                0x20000000u
#define kNtProfileServer                0x40000000u
#define kNtCreateIgnoreSystemDefault    0x80000000u

#define kNtStackSizeParamIsAReservation 0x00010000



/*!BEGIN libc/nt/enum/processinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSINFOCLASS_H_

#define kNtProcessBasicInformation 0
#define kNtProcessQuotaLimits      1
#define kNtProcessIoCounters       2
#define kNtProcessVmCounters       3
#define kNtProcessTimes            4
#define kNtProcessBasePriority     5
#define kNtProcessRaisePriority    6
#define kNtProcessDebugPort        7
#define kNtProcessExceptionPort    8
#define kNtProcessAccessToken      9
#define kNtProcessWow64Information 26
#define kNtProcessImageFileName    27



/*!BEGIN libc/nt/enum/procthreadattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCTHREADATTRIBUTES_H_

#define kNtProcThreadAttributeReplaceValue 1
#define kNtProcThreadAttributeHandleList 0x00020002



/*!BEGIN libc/nt/enum/progress.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROGRESS_H_

#define kNtProgressContinue 0
#define kNtProgressCancel   1
#define kNtProgressStop     2
#define kNtProgressQuiet    3



/*!BEGIN libc/nt/enum/pseudoconsole.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PSEUDOCONSOLE_H_

#define kNtPseudoconsoleInheritCursor 1



/*!BEGIN libc/nt/enum/pwr.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PWR_H_

#define kNtPwrOk             1
#define kNtPwrFail           (-1)
#define kNtPwrSuspendrequest 1
#define kNtPwrSuspendresume  2
#define kNtPwrCriticalresume 3



/*!BEGIN libc/nt/enum/rdw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_RDW_H_

#define kNtRdwInvalidate      0x0001
#define kNtRdwInternalpaint   0x0002
#define kNtRdwErase           0x0004
#define kNtRdwValidate        0x0008
#define kNtRdwNointernalpaint 0x0010
#define kNtRdwNoerase         0x0020
#define kNtRdwNochildren      0x0040
#define kNtRdwAllchildren     0x0080
#define kNtRdwUpdatenow       0x0100
#define kNtRdwErasenow        0x0200
#define kNtRdwFrame           0x0400
#define kNtRdwNoframe         0x0800



/*!BEGIN libc/nt/enum/reggetvalueflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGGETVALUEFLAGS_H_

#define kNtRrfRtRegNone        0x00000001
#define kNtRrfRtRegSz          0x00000002
#define kNtRrfRtRegExpandSz    0x00000004
#define kNtRrfRtRegBinary      0x00000008
#define kNtRrfRtRegDword       0x00000010
#define kNtRrfRtRegMultiSz     0x00000020
#define kNtRrfRtRegQword       0x00000040
#define kNtRrfRtDword          (kNtRrfRtRegBinary | kNtRrfRtRegDword)
#define kNtRrfRtQword          (kNtRrfRtRegBinary | kNtRrfRtRegQword)
#define kNtRrfRtAny            0x0000ffff
#define kNtRrfSubkeyWow6464key 0x00010000
#define kNtRrfSubkeyWow6432key 0x00020000
#define kNtRrfWow64Mask        0x00030000
#define kNtRrfNoexpand         0x10000000
#define kNtRrfZeroonfailure    0x20000000



/*!BEGIN libc/nt/enum/regtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGTYPE_H_

#define kNtRegNone                     0
#define kNtRegSz                       1 /* UTF-16 string */
#define kNtRegExpandSz                 2 /* UTF-16 string w/ env vars refs */
#define kNtRegBinary                   3
#define kNtRegDword                    4
#define kNtRegDwordBigEndian           5
#define kNtRegLink                     6
#define kNtRegMultiSz                  7 /* UTF-16 double-nul-terminated */
#define kNtRegResourceList             8
#define kNtRegFullResourceDescriptor   9
#define kNtRegResourceRequirementsList 10
#define kNtRegQword                    11



/*!BEGIN libc/nt/enum/replacefile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REPLACEFILE_H_

#define kNtReplacefileWriteThrough      1
#define kNtReplacefileIgnoreMergeErrors 2
#define kNtReplacefileIgnoreAclErrors   4



/*!BEGIN libc/nt/enum/sc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SC_H_

#define kNtScSize         0xF000
#define kNtScMove         0xF010
#define kNtScMinimize     0xF020
#define kNtScMaximize     0xF030
#define kNtScNextwindow   0xF040
#define kNtScPrevwindow   0xF050
#define kNtScClose        0xF060
#define kNtScVscroll      0xF070
#define kNtScHscroll      0xF080
#define kNtScMousemenu    0xF090
#define kNtScKeymenu      0xF100
#define kNtScArrange      0xF110
#define kNtScRestore      0xF120
#define kNtScTasklist     0xF130
#define kNtScScreensave   0xF140
#define kNtScHotkey       0xF150
#define kNtScDefault      0xF160
#define kNtScMonitorpower 0xF170
#define kNtScContexthelp  0xF180
#define kNtScSeparator    0xF00F



/*!BEGIN libc/nt/enum/sectioninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINFORMATIONCLASS_H_

#define kNtSectionBasicInformation 0
#define kNtSectionImageInformation 1



/*!BEGIN libc/nt/enum/sectioninherit.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINHERIT_H_

enum NtSectionInherit { kNtViewShare = 1, kNtViewUnmap = 2 };



/*!BEGIN libc/nt/enum/sectionmapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONMAPFLAGS_H_

#define kNtSectionQuery              0x0001
#define kNtSectionMapWrite           0x0002
#define kNtSectionMapRead            0x0004
#define kNtSectionMapExecute         0x0008
#define kNtSectionExtendSize         0x0010
#define kNtSectionMapExecuteExplicit 0x0020



/*!BEGIN libc/nt/enum/securityimpersonationlevel.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYIMPERSONATIONLEVEL_H_

#define kNtSecurityAnonymous      0
#define kNtSecurityIdentification 1
#define kNtSecurityImpersonation  2
#define kNtSecurityDelegation     3



/*!BEGIN libc/nt/enum/securityinformation.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYINFORMATION_H_

#define kNtOwnerSecurityInformation 0x00000001
#define kNtGroupSecurityInformation 0x00000002
#define kNtDaclSecurityInformation 0x00000004
#define kNtSaclSecurityInformation 0x00000008
#define kNtLabelSecurityInformation 0x00000010
#define kNtAttributeSecurityInformation 0x00000020
#define kNtScopeSecurityInformation 0x00000040
#define kNtProcessTrustLabelSecurityInformation 0x00000080
#define kNtAccessFilterSecurityInformation 0x00000100
#define kNtBackupSecurityInformation 0x00010000
#define kNtProtectedDaclSecurityInformation 0x80000000
#define kNtProtectedSaclSecurityInformation 0x40000000
#define kNtUnprotectedDaclSecurityInformation 0x20000000
#define kNtUnprotectedSaclSecurityInformation 0x10000000



/*!BEGIN libc/nt/enum/signal.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIGNAL_H_

#define kNtSignalBreakpoint          0x80000003u
#define kNtSignalIllegalInstruction  0xC000001Du
#define kNtSignalPrivInstruction     0xC0000096u
#define kNtSignalGuardPage           0x80000001u
#define kNtSignalAccessViolation     0xC0000005u
#define kNtSignalInPageError         0xC0000006u
#define kNtSignalInvalidHandle       0xC0000008u
#define kNtSignalInvalidParameter    0xC000000du
#define kNtSignalFltDenormalOperand  0xC000008Du
#define kNtSignalFltDivideByZero     0xC000008Eu
#define kNtSignalFltInexactResult    0xC000008Fu
#define kNtSignalFltInvalidOperation 0xC0000090u
#define kNtSignalFltOverflow         0xC0000091u
#define kNtSignalFltStackCheck       0xC0000092u
#define kNtSignalFltUnderflow        0xC0000093u
#define kNtSignalIntegerDivideByZero 0xC0000094u
#define kNtSignalDllNotFound         0xC0000135u
#define kNtSignalOrdinalNotFound     0xC0000138u
#define kNtSignalEntrypointNotFound  0xC0000139u
#define kNtSignalControlCExit        0xC000013Au
#define kNtSignalDllInitFailed       0xC0000142u
#define kNtSignalFloatMultipleFaults 0xC00002B4u
#define kNtSignalFloatMultipleTraps  0xC00002B5u
#define kNtSignalAssertionFailure    0xC0000420u



/*!BEGIN libc/nt/enum/sio.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIO_H_

#define kNtSioAbsorbRtralert                      0x98000005u
#define kNtSioAcquirePortReservation              0x98000064u
#define kNtSioAddressListChange                   0x28000017u
#define kNtSioAddressListQuery                    0x48000016u
#define kNtSioAddressListSort                     0xc8000019u
#define kNtSioApplyTransportSetting               0x98000013u
#define kNtSioAssociateHandle                     0x88000001u
#define kNtSioAssociatePortReservation            0x98000066u
#define kNtSioBaseHandle                          0x48000022u
#define kNtSioBspHandlePoll                       0x4800001Du
#define kNtSioDeletePeerTargetName                0x980000cbu
#define kNtSioEnableCircularQueueing              0x28000002u
#define kNtSioFindRoute                           0x48000003u
#define kNtSioFlush                               0x28000004u
#define kNtSioGetBroadcastAddress                 0x48000005u
#define kNtSioGetExtensionFunctionPointer         0xc8000006u
#define kNtSioGetGroupQos                         0xc8000008u
#define kNtSioGetInterfaceList                    0x4008747fu
#define kNtSioGetMultipleExtensionFunctionPointer 0xc8000024u
#define kNtSioGetQos                              0xc8000007u
#define kNtSioIndexAddMcast                       0x9800000au
#define kNtSioIndexBind                           0x98000008u
#define kNtSioIndexDelMcast                       0x9800000bu
#define kNtSioIndexMcastif                        0x98000009u
#define kNtSioKeepaliveVals                       0x98000004u
#define kNtSioLimitBroadcasts                     0x98000007u
#define kNtSioLoopbackFastPath                    0x98000010u
#define kNtSioMulticastScope                      0x8800000au
#define kNtSioMultipointLoopback                  0x88000009u
#define kNtSioQueryRssProcessorInfo               0x48000025u
#define kNtSioQueryRssScalabilityInfo             0x580000d2u
#define kNtSioQuerySecurity                       0xd80000c9u
#define kNtSioQueryTargetPnpHandle                0x48000018u
#define kNtSioQueryTransportSetting               0x98000014u
#define kNtSioQueryWfpAleEndpointHandle           0x580000cdu
#define kNtSioQueryWfpConnectionRedirectContext   0x980000ddu
#define kNtSioQueryWfpConnectionRedirectRecords   0x980000dcu
#define kNtSioRcvall                              0x98000001u
#define kNtSioRcvallIf                            0x9800000eu
#define kNtSioRcvallIgmpmcast                     0x98000003u
#define kNtSioRcvallMcast                         0x98000002u
#define kNtSioRcvallMcastIf                       0x9800000du
#define kNtSioReleasePortReservation              0x98000065u
#define kNtSioReserved1                           0x8800001au
#define kNtSioReserved2                           0x88000021u
#define kNtSioRoutingInterfaceChange              0x88000015u
#define kNtSioRoutingInterfaceQuery               0xc8000014u
#define kNtSioSetGroupQos                         0x8800000cu
#define kNtSioSetPeerTargetName                   0x980000cau
#define kNtSioSetPriorityHint                     0x98000018u
#define kNtSioSetQos                              0x8800000bu
#define kNtSioSetSecurity                         0x980000c8u
#define kNtSioSetWfpConnectionRedirectRecords     0x980000deu
#define kNtSioSocketCloseNotify                   0x9800000du
#define kNtSioSocketUsageNotification             0x980000ccu
#define kNtSioTcpInfo                             0xd8000027u
#define kNtSioTcpInitialRto                       0x98000011u
#define kNtSioTcpSetAckFrequency                  0x98000017u
#define kNtSioTcpSetIcw                           0x98000016u
#define kNtSioTranslateHandle                     0xc800000du
#define kNtSioUcastIf                             0x98000006u
#define kNtSioUdpConnreset                        0x9800000cu
#define kNtSioUdpNetreset                         0x9800000fu



/*!BEGIN libc/nt/enum/size.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIZE_H_

#define kNtSizeRestored  0
#define kNtSizeMinimized 1
#define kNtSizeMaximized 2
#define kNtSizeMaxshow   3
#define kNtSizeMaxhide   4



/*!BEGIN libc/nt/enum/startf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STARTF_H_

#define kNtStartfUseshowwindow 0x00000001 /* otherwise wShowWindow ignored */
#define kNtStartfUsesize 0x00000002       /* otherwise dwX / dwY ignored */
#define kNtStartfUseposition 0x00000004   /* otherwise dwX/YSize ignored */
#define kNtStartfUsecountchars 0x00000008 /* otherwise dwX/YCountChars ign. */
#define kNtStartfUsefillattribute 0x00000010 /* etc. */
#define kNtStartfRunfullscreen 0x00000020
#define kNtStartfForceonfeedback 0x00000040
#define kNtStartfForceofffeedback 0x00000080
#define kNtStartfUsestdhandles 0x00000100 /* otherwise hStd... ignored */
#define kNtStartfUsehotkey 0x00000200
#define kNtStartfTitleislinkname 0x00000800
#define kNtStartfTitleisappid 0x00001000
#define kNtStartfPreventpinning 0x00002000
#define kNtStartfUntrustedsource 0x00008000



/*!BEGIN libc/nt/enum/statfs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STATFS_H_
COSMOPOLITAN_C_START_

#define kNtFileCasePreservedNames         0x00000002
#define kNtFileCaseSensitiveSearch        0x00000001
#define kNtFileFileCompression            0x00000010
#define kNtFileNamedStreams               0x00040000
#define kNtFilePersistentAcls             0x00000008
#define kNtFileReadOnlyVolume             0x00080000 /* ST_RDONLY */
#define kNtFileSequentialWriteOnce        0x00100000
#define kNtFileSupportsEncryption         0x00020000
#define kNtFileSupportsExtendedAttributes 0x00800000
#define kNtFileSupportsHardLinks          0x00400000
#define kNtFileSupportsObjectIds          0x00010000
#define kNtFileSupportsOpenByFileId       0x01000000
#define kNtFileSupportsReparsePoints      0x00000080
#define kNtFileSupportsSparseFiles        0x00000040
#define kNtFileSupportsTransactions       0x00200000
#define kNtFileSupportsUsnJournal         0x02000000
#define kNtFileUnicodeOnDisk              0x00000004
#define kNtFileVolumeIsCompressed         0x00008000
#define kNtFileVolumeQuotas               0x00000020
#define kNtFileSupportsBlockRefcounting   0x08000000

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/status.h */

#define COSMOPOLITAN_LIBC_NT_STATUS_H_

/* high two bits = {success,informational,warning,error} */
#define kNtStatusSuccess                  0x00000000 /* success statuses */
#define kNtStatusWait0                    0x00000000
#define kNtStatusAbandonedWait0           0x00000080
#define kNtStatusUserApc                  0x000000C0
#define kNtStatusTimeout                  0x00000102
#define kNtStatusPending                  0x00000103
#define kNtStatusGuardPageViolation       0x80000001 /* warning statuses */
#define kNtStatusDatatypeMisalignment     0x80000002
#define kNtStatusBreakpoint               0x80000003
#define kNtStatusSingleStep               0x80000004
#define kNtStatusLongjump                 0x80000026
#define kNtStatusUnwindConsolidate        0x80000029
#define kNtStatusAccessViolation          0xC0000005 /* error statuses */
#define kNtStatusInPageError              0xC0000006
#define kNtStatusInvalidHandle            0xC0000008
#define kNtStatusInvalidParameter         0xC000000D
#define kNtStatusNoMemory                 0xC0000017
#define kNtStatusIllegalInstruction       0xC000001D
#define kNtStatusNoncontinuableException  0xC0000025
#define kNtStatusInvalidDisposition       0xC0000026
#define kNtStatusArrayBoundsExceeded      0xC000008C
#define kNtStatusFloatDenormalOperand     0xC000008D
#define kNtStatusFloatDivideByZero        0xC000008E
#define kNtStatusFloatInexactResult       0xC000008F
#define kNtStatusFloatInvalidOperation    0xC0000090
#define kNtStatusFloatOverflow            0xC0000091
#define kNtStatusFloatStackCheck          0xC0000092
#define kNtStatusFloatUnderflow           0xC0000093
#define kNtStatusIntegerDivideBYZero      0xC0000094
#define kNtStatusIntegerOverflow          0xC0000095
#define kNtStatusPrivilegedInstruction    0xC0000096
#define kNtStatusStackOverflow            0xC00000FD
#define kNtStatusDllNotFound              0xC0000135
#define kNtStatusOrdinalNotFound          0xC0000138
#define kNtStatusEntrypointNotFound       0xC0000139
#define kNtStatusControlCExit             0xC000013A
#define kNtStatusDllInitFailed            0xC0000142
#define kNtStatusFloatMultipleFaults      0xC00002B4
#define kNtStatusFloatMultipleTraps       0xC00002B5
#define kNtStatusRegNatConsumption        0xC00002C9
#define kNtStatusHeapCorruption           0xC0000374
#define kNtStatusStackBufferOverrun       0xC0000409
#define kNtStatusInvalidCruntimeParameter 0xC0000417
#define kNtStatusAssertionFailure         0xC0000420
#define kNtStatusEnclaveViolation         0xC00004A2
#define kNtStatusSegmentNotification      0x40000005
#define kNtStatusFatalAppExit             0x40000015
#define kNtStatusNotFound                 0xC0000225
#define kNtStatusCancelled                0xC0000120

#define kNtDbgExceptionHandled    0x00010001
#define kNtDbgContinue            0x00010002
#define kNtDbgReplyLater          0x40010001
#define kNtDbgTerminateThread     0x40010003
#define kNtDbgTerminateProcess    0x40010004
#define kNtDbgControlC            0x40010005
#define kNtDbgPrintexceptionC     0x40010006
#define kNtDbgRipexception        0x40010007
#define kNtDbgControlBreak        0x40010008
#define kNtDbgCommandException    0x40010009
#define kNtDbgPrintexceptionWideC 0x4001000A
#define kNtDbgExceptionNotHandled 0x80010001
#define kNtStillActive            kNtStatusPending

#if !(__ASSEMBLER__ + __LINKER__ + 0)

typedef uint32_t NtStatus;

#define NtSuccess(s)      ((NtStatus)(s) >= 0)
#define NtInformation(s)  (NtSeverity(s) == 1)
#define NtWarning(s)      (NtSeverity(s) == 2)
#define NtError(s)        (NtSeverity(s) == 3)
#define NtCode(s)         ((NtStatus)(s)&0xffff)
#define NtSeverity(s)     ((NtStatus)(s) >> 30)
#define NtFacility(s)     (((NtStatus)(s) >> 16) & 0xfff)
#define NtFacilityCode(s) ((NtStatus)(s)&0x0FFFFFFF)

#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nt/enum/sw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SW_H_

#define kNtSwHide            0
#define kNtSwShownormal      1
#define kNtSwNormal          1
#define kNtSwShowminimized   2
#define kNtSwShowmaximized   3
#define kNtSwMaximize        3
#define kNtSwShownoactivate  4
#define kNtSwShow            5
#define kNtSwMinimize        6
#define kNtSwShowminnoactive 7
#define kNtSwShowna          8
#define kNtSwRestore         9
#define kNtSwShowdefault     10
#define kNtSwForceminimize   11



/*!BEGIN libc/nt/enum/symboliclink.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYMBOLICLINK_H_

#define kNtSymbolicLinkFlagDirectory               1
#define kNtSymbolicLinkFlagAllowUnprivilegedCreate 2



/*!BEGIN libc/nt/enum/systeminformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYSTEMINFORMATIONCLASS_H_

#define kNtSystemBasicInformation 0
#define kNtSystemProcessorInformation 1
#define kNtSystemPerformanceInformation 2
#define kNtSystemTimeOfDayInformation 3
#define kNtSystemProcessInformation 5
#define kNtSystemProcessorTimes 8
#define kNtSystemGlobalFlag 9
#define kNtSystemModuleInformation 11
#define kNtSystemLockInformation 12
#define kNtSystemHandleInformation 16
#define kNtSystemObjectInformation 17
#define kNtSystemInterruptInformation 23
#define kNtSystemExceptionInformation 33
#define kNtSystemRegistryQuotaInformation 37
#define kNtSystemLookasideInformation 45



/*!BEGIN libc/nt/enum/th32cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TH32CS_H_

#define kNtTh32csInherit      0x80000000
#define kNtTh32csSnapheaplist 0x00000001
#define kNtTh32csSnapmodule   0x00000008
#define kNtTh32csSnapmodule32 0x00000010
#define kNtTh32csSnapprocess  0x00000002
#define kNtTh32csSnapthread   0x00000004



/*!BEGIN libc/nt/enum/threadaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADACCESS_H_

#define kNtThreadTerminate 0x0001
#define kNtThreadSuspendResume 0x0002
#define kNtThreadGetContext 0x0008
#define kNtThreadSetContext 0x0010
#define kNtThreadQueryInformation 0x0040
#define kNtThreadSetInformation 0x0020
#define kNtThreadSetThreadToken 0x0080
#define kNtThreadImpersonate 0x0100
#define kNtThreadDirectImpersonation 0x0200
#define kNtThreadSetLimitedInformation 0x0400
#define kNtThreadQueryLimitedInformation 0x0800
#define kNtThreadResume 0x1000
#define kNtThreadAllAccess (kNtStandardRightsRequired | kNtSynchronize | 0xFFFF)



/*!BEGIN libc/nt/enum/threadinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADINFOCLASS_H_

enum NtThreadInfoClass {
  kNtThreadBasicInformation,
  kNtThreadTimes,
  kNtThreadPriority,
  kNtThreadBasePriority,
  kNtThreadAffinityMask,
  kNtThreadImpersonationToken,
  kNtThreadDescriptorTableEntry,
  kNtThreadEnableAlignmentFaultFixup,
  kNtThreadEventPair_Reusable,
  kNtThreadQuerySetWin32StartAddress,
  kNtThreadZeroTlsCell,
  kNtThreadPerformanceCount,
  kNtThreadAmILastThread,
  kNtThreadIdealProcessor,
  kNtThreadPriorityBoost,
  kNtThreadSetTlsArrayAddress,
  kNtThreadIsIoPending,
  kNtThreadHideFromDebugger,
  kNtThreadInfoClass_MAX
};



/*!BEGIN libc/nt/enum/threadpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADPRIORITY_H_

#define kNtThreadBasePriorityIdle  (-15)
#define kNtThreadBasePriorityMin   (-2)
#define kNtThreadBasePriorityMax   2
#define kNtThreadBasePriorityLowrt 15

#define kNtThreadPriorityIdle         kNtThreadBasePriorityIdle
#define kNtThreadPriorityLowest       kNtThreadBasePriorityMin
#define kNtThreadPriorityBelowNormal  (kNtThreadPriorityLowest + 1)
#define kNtThreadPriorityNormal       0
#define kNtThreadPriorityAboveNormal  (kNtThreadPriorityHighest - 1)
#define kNtThreadPriorityHighest      kNtThreadBasePriorityMax
#define kNtThreadPriorityTimeCritical kNtThreadBasePriorityLowrt



/*!BEGIN libc/nt/enum/threadstate.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADSTATE_H_

#define kNtStateInitialized 0
#define kNtStateReady       1
#define kNtStateRunning     2
#define kNtStateStandby     3
#define kNtStateTerminated  4
#define kNtStateWait        5
#define kNtStateTransition  6
#define kNtStateUnknown     7



/*!BEGIN libc/nt/enum/timezoneid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TIMEZONEID_H_

#define kNtTimeZoneIdUnknown  0
#define kNtTimeZoneIdStandard 1
#define kNtTimeZoneIdDaylight 2



/*!BEGIN libc/nt/enum/tokeninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENINFORMATIONCLASS_H_

#define kNtTokenUser 1
#define kNtTokenGroups 2
#define kNtTokenPrivileges 3
#define kNtTokenOwner 4
#define kNtTokenPrimaryGroup 5
#define kNtTokenDefaultDacl 6
#define kNtTokenSource 7
#define kNtTokenType 8
#define kNtTokenImpersonationLevel 9
#define kNtTokenStatistics 10
#define kNtTokenRestrictedSids 11
#define kNtTokenSessionId 12
#define kNtTokenGroupsAndPrivileges 13
#define kNtTokenSessionReference 14
#define kNtTokenSandBoxInert 15
#define kNtTokenAuditPolicy 16
#define kNtTokenOrigin 17
#define kNtTokenInfoClass_MAX 18



/*!BEGIN libc/nt/enum/tokentype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENTYPE_H_

#define kNtTokenPrimary       1
#define kNtTokenImpersonation 2



/*!BEGIN libc/nt/enum/tpm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TPM_H_

#define kNtTpmLeftbutton      0x00000
#define kNtTpmRightbutton     0x00002
#define kNtTpmLeftalign       0x00000
#define kNtTpmCenteralign     0x00004
#define kNtTpmRightalign      0x00008
#define kNtTpmTopalign        0x00000
#define kNtTpmVcenteralign    0x00010
#define kNtTpmBottomalign     0x00020
#define kNtTpmHorizontal      0x00000
#define kNtTpmVertical        0x00040
#define kNtTpmNonotify        0x00080
#define kNtTpmReturncmd       0x00100
#define kNtTpmRecurse         0x00001
#define kNtTpmHorposanimation 0x00400
#define kNtTpmHorneganimation 0x00800
#define kNtTpmVerposanimation 0x01000
#define kNtTpmVerneganimation 0x02000
#define kNtTpmNoanimation     0x04000
#define kNtTpmLayoutrtl       0x08000
#define kNtTpmWorkarea        0x10000



/*!BEGIN libc/nt/enum/valueinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VALUEINFORMATIONCLASS_H_

#define kNtKeyValueBasicInformation          0
#define kNtKeyValueFullInformation           1
#define kNtKeyValuePartialInformation        2
#define kNtKeyValueFullInformationAlign64    3
#define kNtKeyValuePartialInformationAlign64 4



/*!BEGIN libc/nt/enum/version.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VERSION_H_

/**
 * Known versions of the New Technology executive.
 * @see IsAtLeastWindows10()
 * @see NtGetVersion()
 */
#define kNtVersionWindows10    0x0a00
#define kNtVersionWindows81    0x0603
#define kNtVersionWindows8     0x0602
#define kNtVersionWindows7     0x0601
#define kNtVersionWindowsVista 0x0600 /* intended baseline */
#define kNtVersionWindowsXp64  0x0502 /* end of the road */
#define kNtVersionWindowsXp    0x0501 /* snowball's chance */
#define kNtVersionWindows2000  0x0500 /* the golden age */
#define kNtVersionFuture       0x0b00



/*!BEGIN libc/nt/enum/vk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VK_H_

#define kNtVkLbutton                      0x01
#define kNtVkRbutton                      0x02
#define kNtVkCancel                       0x03
#define kNtVkMbutton                      0x04
#define kNtVkXbutton1                     0x05
#define kNtVkXbutton2                     0x06
#define kNtVkBack                         0x08
#define kNtVkTab                          0x09
#define kNtVkClear                        0x0C
#define kNtVkReturn                       0x0D
#define kNtVkShift                        0x10
#define kNtVkControl                      0x11
#define kNtVkMenu                         0x12 /* alt? */
#define kNtVkPause                        0x13
#define kNtVkCapital                      0x14
#define kNtVkKana                         0x15
#define kNtVkHangul                       0x15
#define kNtVkJunja                        0x17
#define kNtVkFinal                        0x18
#define kNtVkHanja                        0x19
#define kNtVkKanji                        0x19
#define kNtVkEscape                       0x1B
#define kNtVkConvert                      0x1C
#define kNtVkNonconvert                   0x1D
#define kNtVkAccept                       0x1E
#define kNtVkModechange                   0x1F
#define kNtVkSpace                        0x20
#define kNtVkPrior                        0x21 /* page up */
#define kNtVkNext                         0x22 /* page down */
#define kNtVkEnd                          0x23
#define kNtVkHome                         0x24
#define kNtVkLeft                         0x25
#define kNtVkUp                           0x26
#define kNtVkRight                        0x27
#define kNtVkDown                         0x28
#define kNtVkSelect                       0x29
#define kNtVkPrint                        0x2A
#define kNtVkExecute                      0x2B
#define kNtVkSnapshot                     0x2C
#define kNtVkInsert                       0x2D
#define kNtVkDelete                       0x2E
#define kNtVkHelp                         0x2F
#define kNtVkLwin                         0x5B
#define kNtVkRwin                         0x5C
#define kNtVkApps                         0x5D
#define kNtVkSleep                        0x5F
#define kNtVkNumpad0                      0x60
#define kNtVkNumpad1                      0x61
#define kNtVkNumpad2                      0x62
#define kNtVkNumpad3                      0x63
#define kNtVkNumpad4                      0x64
#define kNtVkNumpad5                      0x65
#define kNtVkNumpad6                      0x66
#define kNtVkNumpad7                      0x67
#define kNtVkNumpad8                      0x68
#define kNtVkNumpad9                      0x69
#define kNtVkMultiply                     0x6A
#define kNtVkAdd                          0x6B
#define kNtVkSeparator                    0x6C
#define kNtVkSubtract                     0x6D
#define kNtVkDecimal                      0x6E
#define kNtVkDivide                       0x6F
#define kNtVkF1                           0x70
#define kNtVkF2                           0x71
#define kNtVkF3                           0x72
#define kNtVkF4                           0x73
#define kNtVkF5                           0x74
#define kNtVkF6                           0x75
#define kNtVkF7                           0x76
#define kNtVkF8                           0x77
#define kNtVkF9                           0x78
#define kNtVkF10                          0x79
#define kNtVkF11                          0x7A
#define kNtVkF12                          0x7B
#define kNtVkF13                          0x7C
#define kNtVkF14                          0x7D
#define kNtVkF15                          0x7E
#define kNtVkF16                          0x7F
#define kNtVkF17                          0x80
#define kNtVkF18                          0x81
#define kNtVkF19                          0x82
#define kNtVkF20                          0x83
#define kNtVkF21                          0x84
#define kNtVkF22                          0x85
#define kNtVkF23                          0x86
#define kNtVkF24                          0x87
#define kNtVkNumlock                      0x90
#define kNtVkScroll                       0x91
#define kNtVkLshift                       0xA0
#define kNtVkRshift                       0xA1
#define kNtVkLcontrol                     0xA2
#define kNtVkRcontrol                     0xA3
#define kNtVkLmenu                        0xA4
#define kNtVkRmenu                        0xA5
#define kNtVkBrowserBack                  0xA6
#define kNtVkBrowserForward               0xA7
#define kNtVkBrowserRefresh               0xA8
#define kNtVkBrowserStop                  0xA9
#define kNtVkBrowserSearch                0xAA
#define kNtVkBrowserFavorites             0xAB
#define kNtVkBrowserHome                  0xAC
#define kNtVkVolumeMute                   0xAD
#define kNtVkVolumeDown                   0xAE
#define kNtVkVolumeUp                     0xAF
#define kNtVkMediaNextTrack               0xB0
#define kNtVkMediaPrevTrack               0xB1
#define kNtVkMediaStop                    0xB2
#define kNtVkMediaPlayPause               0xB3
#define kNtVkLaunchMail                   0xB4
#define kNtVkLaunchMediaSelect            0xB5
#define kNtVkLaunchApp1                   0xB6
#define kNtVkLaunchApp2                   0xB7
#define kNtVkOem_1                        0xBA
#define kNtVkOemPlus                      0xBB
#define kNtVkOemComma                     0xBC
#define kNtVkOemMinus                     0xBD
#define kNtVkOemPeriod                    0xBE
#define kNtVkOem_2                        0xBF
#define kNtVkOem_3                        0xC0
#define kNtVkGamepadA                     0xC3
#define kNtVkGamepadB                     0xC4
#define kNtVkGamepadX                     0xC5
#define kNtVkGamepadY                     0xC6
#define kNtVkGamepadRightShoulder         0xC7
#define kNtVkGamepadLeftShoulder          0xC8
#define kNtVkGamepadLeftTrigger           0xC9
#define kNtVkGamepadRightTrigger          0xCA
#define kNtVkGamepadDpadUp                0xCB
#define kNtVkGamepadDpadDown              0xCC
#define kNtVkGamepadDpadLeft              0xCD
#define kNtVkGamepadDpadRight             0xCE
#define kNtVkGamepadMenu                  0xCF
#define kNtVkGamepadView                  0xD0
#define kNtVkGamepadLeftThumbstickButton  0xD1
#define kNtVkGamepadRightThumbstickButton 0xD2
#define kNtVkGamepadLeftThumbstickUp      0xD3
#define kNtVkGamepadLeftThumbstickDown    0xD4
#define kNtVkGamepadLeftThumbstickRight   0xD5
#define kNtVkGamepadLeftThumbstickLeft    0xD6
#define kNtVkGamepadRightThumbstickUp     0xD7
#define kNtVkGamepadRightThumbstickDown   0xD8
#define kNtVkGamepadRightThumbstickRight  0xD9
#define kNtVkGamepadRightThumbstickLeft   0xDA
#define kNtVkOem_4                        0xDB
#define kNtVkOem_5                        0xDC
#define kNtVkOem_6                        0xDD
#define kNtVkOem_7                        0xDE
#define kNtVkOem_8                        0xDF
#define kNtVkOemAx                        0xE1
#define kNtVkOem_102                      0xE2
#define kNtVkIcoHelp                      0xE3
#define kNtVkIco_00                       0xE4
#define kNtVkProcesskey                   0xE5
#define kNtVkIcoClear                     0xE6
#define kNtVkPacket                       0xE7
#define kNtVkOemReset                     0xE9
#define kNtVkOemJump                      0xEA
#define kNtVkOemPa1                       0xEB
#define kNtVkOemPa2                       0xEC
#define kNtVkOemPa3                       0xED
#define kNtVkOemWsctrl                    0xEE
#define kNtVkOemCusel                     0xEF
#define kNtVkOemAttn                      0xF0
#define kNtVkOemFinish                    0xF1
#define kNtVkOemCopy                      0xF2
#define kNtVkOemAuto                      0xF3
#define kNtVkOemEnlw                      0xF4
#define kNtVkOemBacktab                   0xF5
#define kNtVkAttn                         0xF6
#define kNtVkCrsel                        0xF7
#define kNtVkExsel                        0xF8
#define kNtVkEreof                        0xF9
#define kNtVkPlay                         0xFA
#define kNtVkZoom                         0xFB
#define kNtVkNoname                       0xFC
#define kNtVkPa1                          0xFD
#define kNtVkOemClear                     0xFE



/*!BEGIN libc/nt/enum/wa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WA_H_

#define kNtWaInactive    0
#define kNtWaActive      1
#define kNtWaClickactive 2



/*!BEGIN libc/nt/enum/wait.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WAIT_H_

#define kNtWaitFailed    0xffffffffu
#define kNtWaitTimeout   0x00000102u
#define kNtWaitAbandoned 0x00000080u



/*!BEGIN libc/nt/enum/wm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WM_H_

#define kNtWmNull                   0x0000
#define kNtWmCreate                 0x0001
#define kNtWmDestroy                0x0002
#define kNtWmMove                   0x0003
#define kNtWmSize                   0x0005
#define kNtWmActivate               0x0006
#define kNtWmSetfocus               0x0007
#define kNtWmKillfocus              0x0008
#define kNtWmEnable                 0x000A
#define kNtWmSetredraw              0x000B
#define kNtWmSettext                0x000C
#define kNtWmGettext                0x000D
#define kNtWmGettextlength          0x000E
#define kNtWmPaint                  0x000F
#define kNtWmClose                  0x0010
#define kNtWmQueryendsession        0x0011
#define kNtWmQueryopen              0x0013
#define kNtWmEndsession             0x0016
#define kNtWmQuit                   0x0012
#define kNtWmErasebkgnd             0x0014
#define kNtWmSyscolorchange         0x0015
#define kNtWmShowwindow             0x0018
#define kNtWmWininichange           0x001A
#define kNtWmSettingchange          kNtWmWininichange
#define kNtWmDevmodechange          0x001B
#define kNtWmActivateapp            0x001C
#define kNtWmFontchange             0x001D
#define kNtWmTimechange             0x001E
#define kNtWmCancelmode             0x001F
#define kNtWmSetcursor              0x0020
#define kNtWmMouseactivate          0x0021
#define kNtWmChildactivate          0x0022
#define kNtWmQueuesync              0x0023
#define kNtWmGetminmaxinfo          0x0024
#define kNtWmPainticon              0x0026
#define kNtWmIconerasebkgnd         0x0027
#define kNtWmNextdlgctl             0x0028
#define kNtWmSpoolerstatus          0x002A
#define kNtWmDrawitem               0x002B
#define kNtWmMeasureitem            0x002C
#define kNtWmDeleteitem             0x002D
#define kNtWmVkeytoitem             0x002E
#define kNtWmChartoitem             0x002F
#define kNtWmSetfont                0x0030
#define kNtWmGetfont                0x0031
#define kNtWmSethotkey              0x0032
#define kNtWmGethotkey              0x0033
#define kNtWmQuerydragicon          0x0037
#define kNtWmCompareitem            0x0039
#define kNtWmGetobject              0x003D
#define kNtWmCompacting             0x0041
#define kNtWmWindowposchanging      0x0046
#define kNtWmWindowposchanged       0x0047
#define kNtWmPower                  0x0048
#define kNtWmCopydata               0x004A
#define kNtWmCanceljournal          0x004B
#define kNtWmNotify                 0x004E
#define kNtWmInputlangchangerequest 0x0050
#define kNtWmInputlangchange        0x0051
#define kNtWmTcard                  0x0052
#define kNtWmHelp                   0x0053
#define kNtWmUserchanged            0x0054
#define kNtWmNotifyformat           0x0055
#define kNtWmContextmenu            0x007B
#define kNtWmStylechanging          0x007C
#define kNtWmStylechanged           0x007D
#define kNtWmDisplaychange          0x007E
#define kNtWmGeticon                0x007F
#define kNtWmSeticon                0x0080
#define kNtWmNccreate               0x0081
#define kNtWmNcdestroy              0x0082
#define kNtWmNccalcsize             0x0083
#define kNtWmNchittest              0x0084
#define kNtWmNcpaint                0x0085
#define kNtWmNcactivate             0x0086
#define kNtWmGetdlgcode             0x0087
#define kNtWmNcmousemove            0x00A0
#define kNtWmNclbuttondown          0x00A1
#define kNtWmNclbuttonup            0x00A2
#define kNtWmNclbuttondblclk        0x00A3
#define kNtWmNcrbuttondown          0x00A4
#define kNtWmNcrbuttonup            0x00A5
#define kNtWmNcrbuttondblclk        0x00A6
#define kNtWmNcmbuttondown          0x00A7
#define kNtWmNcmbuttonup            0x00A8
#define kNtWmNcmbuttondblclk        0x00A9
#define kNtWmNcxbuttondown          0x00AB
#define kNtWmNcxbuttonup            0x00AC
#define kNtWmNcxbuttondblclk        0x00AD
#define kNtWmKeyfirst               0x0100
#define kNtWmKeydown                0x0100
#define kNtWmKeyup                  0x0101
#define kNtWmChar                   0x0102
#define kNtWmDeadchar               0x0103
#define kNtWmSyskeydown             0x0104
#define kNtWmSyskeyup               0x0105
#define kNtWmSyschar                0x0106
#define kNtWmSysdeadchar            0x0107
#define kNtWmUnichar                0x0109
#define kNtWmKeylast                0x0109
#define kNtWmInitdialog             0x0110
#define kNtWmCommand                0x0111
#define kNtWmSyscommand             0x0112
#define kNtWmTimer                  0x0113
#define kNtWmHscroll                0x0114
#define kNtWmVscroll                0x0115
#define kNtWmInitmenu               0x0116
#define kNtWmInitmenupopup          0x0117
#define kNtWmGesture                0x0119
#define kNtWmGesturenotify          0x011A
#define kNtWmMenuselect             0x011F
#define kNtWmMenuchar               0x0120
#define kNtWmEnteridle              0x0121
#define kNtWmMenurbuttonup          0x0122
#define kNtWmMenudrag               0x0123
#define kNtWmMenugetobject          0x0124
#define kNtWmUninitmenupopup        0x0125
#define kNtWmMenucommand            0x0126
#define kNtWmChangeuistate          0x0127
#define kNtWmUpdateuistate          0x0128
#define kNtWmQueryuistate           0x0129
#define kNtWmMousefirst             0x0200
#define kNtWmMousemove              0x0200
#define kNtWmLbuttondown            0x0201
#define kNtWmLbuttonup              0x0202
#define kNtWmLbuttondblclk          0x0203
#define kNtWmRbuttondown            0x0204
#define kNtWmRbuttonup              0x0205
#define kNtWmRbuttondblclk          0x0206
#define kNtWmMbuttondown            0x0207
#define kNtWmMbuttonup              0x0208
#define kNtWmMbuttondblclk          0x0209
#define kNtWmMousewheel             0x020A
#define kNtWmXbuttondown            0x020B
#define kNtWmXbuttonup              0x020C
#define kNtWmXbuttondblclk          0x020D
#define kNtWmMousehwheel            0x020E
#define kNtWmMouselast              0x020E
#define kNtWmParentnotify           0x0210
#define kNtWmEntermenuloop          0x0211
#define kNtWmExitmenuloop           0x0212
#define kNtWmNextmenu               0x0213
#define kNtWmSizing                 0x0214
#define kNtWmCapturechanged         0x0215
#define kNtWmMoving                 0x0216
#define kNtWmPowerbroadcast         0x0218
#define kNtWmMdicreate              0x0220
#define kNtWmMdidestroy             0x0221
#define kNtWmMdiactivate            0x0222
#define kNtWmMdirestore             0x0223
#define kNtWmMdinext                0x0224
#define kNtWmMdimaximize            0x0225
#define kNtWmMditile                0x0226
#define kNtWmMdicascade             0x0227
#define kNtWmMdiiconarrange         0x0228
#define kNtWmMdigetactive           0x0229
#define kNtWmMdisetmenu             0x0230
#define kNtWmEntersizemove          0x0231
#define kNtWmExitsizemove           0x0232
#define kNtWmDropfiles              0x0233
#define kNtWmMdirefreshmenu         0x0234
#define kNtWmCut                    0x0300
#define kNtWmCopy                   0x0301
#define kNtWmPaste                  0x0302
#define kNtWmClear                  0x0303
#define kNtWmUndo                   0x0304
#define kNtWmRenderformat           0x0305
#define kNtWmRenderallformats       0x0306
#define kNtWmDestroyclipboard       0x0307
#define kNtWmDrawclipboard          0x0308
#define kNtWmPaintclipboard         0x0309
#define kNtWmVscrollclipboard       0x030A
#define kNtWmSizeclipboard          0x030B
#define kNtWmAskcbformatname        0x030C
#define kNtWmChangecbchain          0x030D
#define kNtWmHscrollclipboard       0x030E
#define kNtWmQuerynewpalette        0x030F
#define kNtWmPaletteischanging      0x0310
#define kNtWmPalettechanged         0x0311
#define kNtWmHotkey                 0x0312



/*!BEGIN libc/nt/enum/ws.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WS_H_

#define kNtWsOverlapped   0x00000000
#define kNtWsPopup        0x80000000
#define kNtWsChild        0x40000000
#define kNtWsMinimize     0x20000000
#define kNtWsVisible      0x10000000
#define kNtWsDisabled     0x08000000
#define kNtWsClipsiblings 0x04000000
#define kNtWsClipchildren 0x02000000
#define kNtWsMaximize     0x01000000
#define kNtWsCaption      0x00C00000
#define kNtWsBorder       0x00800000
#define kNtWsDlgframe     0x00400000
#define kNtWsVscroll      0x00200000
#define kNtWsHscroll      0x00100000
#define kNtWsSysmenu      0x00080000
#define kNtWsThickframe   0x00040000
#define kNtWsGroup        0x00020000
#define kNtWsTabstop      0x00010000
#define kNtWsMinimizebox  0x00020000
#define kNtWsMaximizebox  0x00010000
#define kNtWsTiled        kNtWsOverlapped
#define kNtWsIconic       kNtWsMinimize
#define kNtWsSizebox      kNtWsThickframe
#define kNtWsTiledwindow  kNtWsOverlappedwindow
#define kNtWsOverlappedwindow                                        \
  (kNtWsOverlapped | kNtWsCaption | kNtWsSysmenu | kNtWsThickframe | \
   kNtWsMinimizebox | kNtWsMaximizebox)
#define kNtWsPopupwindow (kNtWsPopup | kNtWsBorder | kNtWsSysmenu)

#define kNtWsExDlgmodalframe       0x00000001
#define kNtWsExNoparentnotify      0x00000004
#define kNtWsExTopmost             0x00000008
#define kNtWsExAcceptfiles         0x00000010
#define kNtWsExTransparent         0x00000020
#define kNtWsExMdichild            0x00000040
#define kNtWsExToolwindow          0x00000080
#define kNtWsExWindowedge          0x00000100
#define kNtWsExClientedge          0x00000200
#define kNtWsExContexthelp         0x00000400
#define kNtWsExRight               0x00001000
#define kNtWsExLeft                0x00000000
#define kNtWsExRtlreading          0x00002000
#define kNtWsExLtrreading          0x00000000
#define kNtWsExLeftscrollbar       0x00004000
#define kNtWsExRightscrollbar      0x00000000
#define kNtWsExControlparent       0x00010000
#define kNtWsExStaticedge          0x00020000
#define kNtWsExAppwindow           0x00040000
#define kNtWsExNoinheritlayout     0x00100000
#define kNtWsExNoredirectionbitmap 0x00200000
#define kNtWsExLayoutrtl           0x00400000
#define kNtWsExComposited          0x02000000
#define kNtWsExNoactivate          0x08000000

#define kNtWsExOverlappedwindow (kNtWsExWindowedge | kNtWsExClientedge)
#define kNtWsExPalettewindow \
  (kNtWsExWindowedge | kNtWsExToolwindow | kNtWsExTopmost)



/*!BEGIN libc/nt/enum/wsa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSA_H_


/*!BEGIN libc/nt/errors.h */

#define COSMOPOLITAN_NT_ERRORS_H_

#define kNtNoError 0

#define kNtErrorInsufficientBuffer 122

#define kNtErrorSuccess                                             0
#define kNtErrorInvalidFunction                                     1 /* ENOSYS */
#define kNtErrorFileNotFound                                        2 /* ENOENT */
#define kNtErrorPathNotFound                                        3 /* ENOTDIR */
#define kNtErrorTooManyOpenFiles                                    4 /* EMFILE */
#define kNtErrorAccessDenied                                        5 /* EACCES */
#define kNtErrorInvalidHandle                                       6 /* EBADF */
#define kNtErrorArenaTrashed                                        7
#define kNtErrorNotEnoughMemory                                     8
#define kNtErrorInvalidBlock                                        9
#define kNtErrorBadEnvironment                                      10
#define kNtErrorBadFormat                                           11
#define kNtErrorInvalidAccess                                       12 /* EPERM */
#define kNtErrorInvalidData                                         13
#define kNtErrorOutofmemory                                         14 /* ENOMEM */
#define kNtErrorInvalidDrive                                        15
#define kNtErrorCurrentDirectory                                    16
#define kNtErrorNotSameDevice                                       17
#define kNtErrorNoMoreFiles                                         18
#define kNtErrorWriteProtect                                        19
#define kNtErrorBadUnit                                             20
#define kNtErrorNotReady                                            21
#define kNtErrorBadCommand                                          22
#define kNtErrorCrc                                                 23
#define kNtErrorBadLength                                           24
#define kNtErrorSeek                                                25 /* ESPIPE */
#define kNtErrorNotDosDisk                                          26 /* ENOTBLK */
#define kNtErrorSectorNotFound                                      27
#define kNtErrorOutOfPaper                                          28
#define kNtErrorWriteFault                                          29
#define kNtErrorReadFault                                           30
#define kNtErrorGenFailure                                          31
#define kNtErrorSharingViolation                                    32
#define kNtErrorLockViolation                                       33
#define kNtErrorWrongDisk                                           34
#define kNtErrorSharingBufferExceeded                               36
#define kNtErrorHandleEof                                           38 /* w/ GetOverlappedResult() */
#define kNtErrorHandleDiskFull                                      39
#define kNtErrorNotSupported                                        50
#define kNtErrorRemNotList                                          51
#define kNtErrorDupName                                             52
#define kNtErrorBadNetpath                                          53
#define kNtErrorNetworkBusy                                         54
#define kNtErrorDevNotExist                                         55
#define kNtErrorTooManyCmds                                         56
#define kNtErrorAdapHdwErr                                          57
#define kNtErrorBadNetResp                                          58
#define kNtErrorUnexpNetErr                                         59
#define kNtErrorBadRemAdap                                          60
#define kNtErrorPrintqFull                                          61
#define kNtErrorNoSpoolSpace                                        62
#define kNtErrorPrintCancelled                                      63
#define kNtErrorNetnameDeleted                                      64
#define kNtErrorNetworkAccessDenied                                 65
#define kNtErrorBadDevType                                          66
#define kNtErrorBadNetName                                          67
#define kNtErrorTooManyNames                                        68
#define kNtErrorTooManySess                                         69
#define kNtErrorSharingPaused                                       70
#define kNtErrorReqNotAccep                                         71
#define kNtErrorRedirPaused                                         72
#define kNtErrorFileExists                                          80 /* EEXIST */
#define kNtErrorCannotMake                                          82
#define kNtErrorFailI24                                             83
#define kNtErrorOutOfStructures                                     84
#define kNtErrorAlreadyAssigned                                     85
#define kNtErrorInvalidPassword                                     86
#define kNtErrorInvalidParameter                                    87 /* EINVAL */
#define kNtErrorNetWriteFault                                       88
#define kNtErrorNoProcSlots                                         89
#define kNtErrorTooManySemaphores                                   100
#define kNtErrorExclSemAlreadyOwned                                 101
#define kNtErrorSemIsSet                                            102
#define kNtErrorTooManySemRequests                                  103
#define kNtErrorInvalidAtInterruptTime                              104
#define kNtErrorSemOwnerDied                                        105 /* EOWNERDEAD */
#define kNtErrorSemUserLimit                                        106
#define kNtErrorDiskChange                                          107
#define kNtErrorDriveLocked                                         108
#define kNtErrorBrokenPipe                                          109 /* EPIPE; happens on ReadFile() too */
#define kNtErrorOpenFailed                                          110
#define kNtErrorBufferOverflow                                      111
#define kNtErrorDiskFull                                            112 /* ENOSPC */
#define kNtErrorNoMoreSearchHandles                                 113
#define kNtErrorInvalidTargetHandle                                 114 /* EBADF */
#define kNtErrorInvalidCategory                                     117 /* ENOATTR */
#define kNtErrorInvalidVerifySwitch                                 118
#define kNtErrorBadDriverLevel                                      119
#define kNtErrorCallNotImplemented                                  120
#define kNtErrorSemTimeout                                          121
#define kNtErrorInsufficientBuffer                                  122
#define kNtErrorInvalidName                                         123
#define kNtErrorInvalidLevel                                        124
#define kNtErrorNoVolumeLabel                                       125
#define kNtErrorModNotFound                                         126
#define kNtErrorProcNotFound                                        127
#define kNtErrorWaitNoChildren                                      128 /* ECHILD */
#define kNtErrorChildNotComplete                                    129
#define kNtErrorDirectAccessHandle                                  130 /* EBADF */
#define kNtErrorNegativeSeek                                        131
#define kNtErrorSeekOnDevice                                        132
#define kNtErrorIsJoinTarget                                        133
#define kNtErrorIsJoined                                            134
#define kNtErrorIsSubsted                                           135
#define kNtErrorNotJoined                                           136
#define kNtErrorNotSubsted                                          137
#define kNtErrorJoinToJoin                                          138
#define kNtErrorSubstToSubst                                        139
#define kNtErrorJoinToSubst                                         140
#define kNtErrorSubstToJoin                                         141
#define kNtErrorBusyDrive                                           142
#define kNtErrorSameDrive                                           143
#define kNtErrorDirNotRoot                                          144
#define kNtErrorDirNotEmpty                                         145
#define kNtErrorIsSubstPath                                         146
#define kNtErrorIsJoinPath                                          147
#define kNtErrorPathBusy                                            148 /* ETXTBSY */
#define kNtErrorIsSubstTarget                                       149
#define kNtErrorSystemTrace                                         150
#define kNtErrorInvalidEventCount                                   151
#define kNtErrorTooManyMuxwaiters                                   152
#define kNtErrorInvalidListFormat                                   153
#define kNtErrorLabelTooLong                                        154
#define kNtErrorTooManyTcbs                                         155
#define kNtErrorSignalRefused                                       156
#define kNtErrorDiscarded                                           157
#define kNtErrorNotLocked                                           158 /* ENOLCK */
#define kNtErrorBadThreadidAddr                                     159
#define kNtErrorBadArguments                                        160
#define kNtErrorBadPathname                                         161
#define kNtErrorSignalPending                                       162
#define kNtErrorMaxThrdsReached                                     164
#define kNtErrorLockFailed                                          167
#define kNtErrorBusy                                                170 /* EBUSY */
#define kNtErrorDeviceSupportInProgress                             171
#define kNtErrorCancelViolation                                     173
#define kNtErrorAtomicLocksNotSupported                             174
#define kNtErrorInvalidSegmentNumber                                180
#define kNtErrorInvalidOrdinal                                      182
#define kNtErrorAlreadyExists                                       183 /* EEXIST */
#define kNtErrorInvalidFlagNumber                                   186
#define kNtErrorSemNotFound                                         187
#define kNtErrorInvalidStartingCodeseg                              188
#define kNtErrorInvalidStackseg                                     189
#define kNtErrorInvalidModuletype                                   190
#define kNtErrorInvalidExeSignature                                 191
#define kNtErrorExeMarkedInvalid                                    192 /* EBADEXEC */
#define kNtErrorBadExeFormat                                        193 /* ENOEXEC */
#define kNtErrorIteratedDataExceeds_64k                             194
#define kNtErrorInvalidMinallocsize                                 195
#define kNtErrorDynlinkFromInvalidRing                              196
#define kNtErrorIoplNotEnabled                                      197
#define kNtErrorInvalidSegdpl                                       198
#define kNtErrorAutodatasegExceeds_64k                              199
#define kNtErrorRing2segMustBeMovable                               200
#define kNtErrorRelocChainXeedsSeglim                               201
#define kNtErrorInfloopInRelocChain                                 202
#define kNtErrorEnvvarNotFound                                      203
#define kNtErrorNoSignalSent                                        205
#define kNtErrorFilenameExcedRange                                  206 /* ENAMETOOLONG */
#define kNtErrorRing2StackInUse                                     207
#define kNtErrorMetaExpansionTooLong                                208
#define kNtErrorInvalidSignalNumber                                 209
#define kNtErrorThread_1Inactive                                    210
#define kNtErrorLocked                                              212
#define kNtErrorTooManyModules                                      214
#define kNtErrorNestingNotAllowed                                   215
#define kNtErrorExeMachineTypeMismatch                              216 /* EBADARCH */
#define kNtErrorExeCannotModifySignedBinary                         217
#define kNtErrorExeCannotModifyStrongSignedBinary                   218
#define kNtErrorFileCheckedOut                                      220
#define kNtErrorCheckoutRequired                                    221
#define kNtErrorBadFileType                                         222 /* EFTYPE */
#define kNtErrorFileTooLarge                                        223 /* EFBIG */
#define kNtErrorFormsAuthRequired                                   224 /* ENEEDAUTH */
#define kNtErrorVirusInfected                                       225
#define kNtErrorVirusDeleted                                        226
#define kNtErrorPipeLocal                                           229
#define kNtErrorBadPipe                                             230
#define kNtErrorPipeBusy                                            231
#define kNtErrorNoData                                              232
#define kNtErrorPipeNotConnected                                    233
#define kNtErrorMoreData                                            234
#define kNtErrorNoWorkDone                                          235
#define kNtErrorVcDisconnected                                      240
#define kNtErrorInvalidEaName                                       254
#define kNtErrorEaListInconsistent                                  255
#define kNtErrorNoMoreItems                                         259
#define kNtErrorCannotCopy                                          266
#define kNtErrorDirectory                                           267 /* EISDIR */
#define kNtErrorEasDidntFit                                         275
#define kNtErrorEaFileCorrupt                                       276
#define kNtErrorEaTableFull                                         277
#define kNtErrorInvalidEaHandle                                     278
#define kNtErrorEasNotSupported                                     282
#define kNtErrorNotOwner                                            288
#define kNtErrorTooManyPosts                                        298
#define kNtErrorPartialCopy                                         299
#define kNtErrorOplockNotGranted                                    300
#define kNtErrorInvalidOplockProtocol                               301
#define kNtErrorDiskTooFragmented                                   302
#define kNtErrorDeletePending                                       303
#define kNtErrorIncompatibleWithGlobalShortNameRegistrySetting      304
#define kNtErrorShortNamesNotEnabledOnVolume                        305
#define kNtErrorSecurityStreamIsInconsistent                        306
#define kNtErrorInvalidLockRange                                    307
#define kNtErrorImageSubsystemNotPresent                            308
#define kNtErrorNotificationGuidAlreadyDefined                      309
#define kNtErrorInvalidExceptionHandler                             310
#define kNtErrorDuplicatePrivileges                                 311
#define kNtErrorNoRangesProcessed                                   312
#define kNtErrorNotAllowedOnSystemFile                              313
#define kNtErrorDiskResourcesExhausted                              314
#define kNtErrorInvalidToken                                        315
#define kNtErrorDeviceFeatureNotSupported                           316
#define kNtErrorMrMidNotFound                                       317
#define kNtErrorScopeNotFound                                       318
#define kNtErrorUndefinedScope                                      319
#define kNtErrorInvalidCap                                          320
#define kNtErrorDeviceUnreachable                                   321
#define kNtErrorDeviceNoResources                                   322
#define kNtErrorDataChecksumError                                   323
#define kNtErrorIntermixedKernelEaOperation                         324
#define kNtErrorFileLevelTrimNotSupported                           326
#define kNtErrorOffsetAlignmentViolation                            327
#define kNtErrorInvalidFieldInParameterList                         328
#define kNtErrorOperationInProgress                                 329 /* EPROGUNAVAIL */
#define kNtErrorBadDevicePath                                       330
#define kNtErrorTooManyDescriptors                                  331 /* ENFILE */
#define kNtErrorScrubDataDisabled                                   332
#define kNtErrorNotRedundantStorage                                 333
#define kNtErrorResidentFileNotSupported                            334
#define kNtErrorCompressedFileNotSupported                          335
#define kNtErrorDirectoryNotSupported                               336
#define kNtErrorNotReadFromCopy                                     337
#define kNtErrorFtWriteFailure                                      338
#define kNtErrorFtDiScanRequired                                    339
#define kNtErrorInvalidKernelInfoVersion                            340
#define kNtErrorInvalidPepInfoVersion                               341
#define kNtErrorObjectNotExternallyBacked                           342
#define kNtErrorExternalBackingProviderUnknown                      343
#define kNtErrorCompressionNotBeneficial                            344
#define kNtErrorStorageTopologyIdMismatch                           345
#define kNtErrorBlockedByParentalControls                           346
#define kNtErrorBlockTooManyReferences                              347
#define kNtErrorMarkedToDisallowWrites                              348
#define kNtErrorEnclaveFailure                                      349
#define kNtErrorFailNoactionReboot                                  350
#define kNtErrorFailShutdown                                        351
#define kNtErrorFailRestart                                         352
#define kNtErrorMaxSessionsReached                                  353
#define kNtErrorNetworkAccessDeniedEdp                              354
#define kNtErrorDeviceHintNameBufferTooSmall                        355
#define kNtErrorEdpPolicyDeniesOperation                            356
#define kNtErrorEdpDplPolicyCantBeSatisfied                         357
#define kNtErrorCloudFileSyncRootMetadataCorrupt                    358
#define kNtErrorDeviceInMaintenance                                 359
#define kNtErrorNotSupportedOnDax                                   360
#define kNtErrorDaxMappingExists                                    361
#define kNtErrorCloudFileProviderNotRunning                         362
#define kNtErrorCloudFileMetadataCorrupt                            363
#define kNtErrorCloudFileMetadataTooLarge                           364
#define kNtErrorCloudFilePropertyBlobTooLarge                       365
#define kNtErrorCloudFilePropertyBlobChecksumMismatch               366
#define kNtErrorChildProcessBlocked                                 367
#define kNtErrorStorageLostDataPersistence                          368
#define kNtErrorFileSystemVirtualizationUnavailable                 369
#define kNtErrorFileSystemVirtualizationMetadataCorrupt             370
#define kNtErrorFileSystemVirtualizationBusy                        371
#define kNtErrorFileSystemVirtualizationProviderUnknown             372
#define kNtErrorGdiHandleLeak                                       373
#define kNtErrorCloudFileTooManyPropertyBlobs                       374
#define kNtErrorCloudFilePropertyVersionNotSupported                375
#define kNtErrorNotACloudFile                                       376
#define kNtErrorCloudFileNotInSync                                  377
#define kNtErrorCloudFileAlreadyConnected                           378
#define kNtErrorCloudFileNotSupported                               379
#define kNtErrorCloudFileInvalidRequest                             380
#define kNtErrorCloudFileReadOnlyVolume                             381
#define kNtErrorCloudFileConnectedProviderOnly                      382
#define kNtErrorCloudFileValidationFailed                           383
#define kNtErrorSmb1NotAvailable                                    384
#define kNtErrorFileSystemVirtualizationInvalidOperation            385
#define kNtErrorCloudFileAuthenticationFailed                       386
#define kNtErrorCloudFileInsufficientResources                      387
#define kNtErrorCloudFileNetworkUnavailable                         388
#define kNtErrorCloudFileUnsuccessful                               389
#define kNtErrorCloudFileNotUnderSyncRoot                           390
#define kNtErrorCloudFileInUse                                      391
#define kNtErrorCloudFilePinned                                     392
#define kNtErrorCloudFileRequestAborted                             393
#define kNtErrorCloudFilePropertyCorrupt                            394
#define kNtErrorCloudFileAccessDenied                               395
#define kNtErrorCloudFileIncompatibleHardlinks                      396
#define kNtErrorCloudFilePropertyLockConflict                       397
#define kNtErrorCloudFileRequestCanceled                            398
#define kNtErrorExternalSyskeyNotSupported                          399
#define kNtErrorThreadModeAlreadyBackground                         400
#define kNtErrorThreadModeNotBackground                             401
#define kNtErrorProcessModeAlreadyBackground                        402
#define kNtErrorProcessModeNotBackground                            403
#define kNtErrorCloudFileProviderTerminated                         404
#define kNtErrorNotACloudSyncRoot                                   405
#define kNtErrorFileProtectedUnderDpl                               406
#define kNtErrorVolumeNotClusterAligned                             407
#define kNtErrorNoPhysicallyAlignedFreeSpaceFound                   408
#define kNtErrorAppxFileNotEncrypted                                409
#define kNtErrorRwrawEncryptedFileNotEncrypted                      410
#define kNtErrorRwrawEncryptedInvalidEdatainfoFileoffset            411
#define kNtErrorRwrawEncryptedInvalidEdatainfoFilerange             412
#define kNtErrorRwrawEncryptedInvalidEdatainfoParameter             413
#define kNtErrorLinuxSubsystemNotPresent                            414
#define kNtErrorCapauthzNotDevunlocked                              450
#define kNtErrorCapauthzChangeType                                  451
#define kNtErrorCapauthzNotProvisioned                              452
#define kNtErrorCapauthzNotAuthorized                               453
#define kNtErrorCapauthzNoPolicy                                    454
#define kNtErrorCapauthzDbCorrupted                                 455
#define kNtErrorCapauthzSccdInvalidCatalog                          456
#define kNtErrorCapauthzSccdNoAuthEntity                            457
#define kNtErrorCapauthzSccdParseError                              458
#define kNtErrorCapauthzSccdDevModeRequired                         459
#define kNtErrorCapauthzSccdNoCapabilityMatch                       460
#define kNtErrorPnpQueryRemoveDeviceTimeout                         480
#define kNtErrorPnpQueryRemoveRelatedDeviceTimeout                  481
#define kNtErrorPnpQueryRemoveUnrelatedDeviceTimeout                482
#define kNtErrorDeviceHardwareError                                 483 /* EDEVERR */
#define kNtErrorInvalidAddress                                      487 /* EFAULT */
#define kNtErrorVrfCfgEnabled                                       1183
#define kNtErrorPartitionTerminating                                1184
#define kNtErrorUserProfileLoad                                     500
#define kNtErrorArithmeticOverflow                                  534 /* EOVERFLOW */
#define kNtErrorPipeConnected                                       535
#define kNtErrorPipeListening                                       536
#define kNtErrorVerifierStop                                        537
#define kNtErrorAbiosError                                          538
#define kNtErrorWx86Warning                                         539
#define kNtErrorWx86Error                                           540
#define kNtErrorTimerNotCanceled                                    541
#define kNtErrorUnwind                                              542
#define kNtErrorBadStack                                            543
#define kNtErrorInvalidUnwindTarget                                 544
#define kNtErrorInvalidPortAttributes                               545
#define kNtErrorPortMessageTooLong                                  546
#define kNtErrorInvalidQuotaLower                                   547
#define kNtErrorDeviceAlreadyAttached                               548
#define kNtErrorInstructionMisalignment                             549
#define kNtErrorProfilingNotStarted                                 550
#define kNtErrorProfilingNotStopped                                 551
#define kNtErrorCouldNotInterpret                                   552
#define kNtErrorProfilingAtLimit                                    553
#define kNtErrorCantWait                                            554
#define kNtErrorCantTerminateSelf                                   555
#define kNtErrorUnexpectedMmCreateErr                               556
#define kNtErrorUnexpectedMmMapError                                557
#define kNtErrorUnexpectedMmExtendErr                               558
#define kNtErrorBadFunctionTable                                    559
#define kNtErrorNoGuidTranslation                                   560
#define kNtErrorInvalidLdtSize                                      561
#define kNtErrorInvalidLdtOffset                                    563
#define kNtErrorInvalidLdtDescriptor                                564
#define kNtErrorTooManyThreads                                      565
#define kNtErrorThreadNotInProcess                                  566 /* ESRCH */
#define kNtErrorPagefileQuotaExceeded                               567
#define kNtErrorLogonServerConflict                                 568
#define kNtErrorSynchronizationRequired                             569
#define kNtErrorNetOpenFailed                                       570
#define kNtErrorIoPrivilegeFailed                                   571
#define kNtErrorControlCExit                                        572
#define kNtErrorMissingSystemfile                                   573
#define kNtErrorUnhandledException                                  574
#define kNtErrorAppInitFailure                                      575
#define kNtErrorPagefileCreateFailed                                576
#define kNtErrorInvalidImageHash                                    577
#define kNtErrorNoPagefile                                          578
#define kNtErrorIllegalFloatContext                                 579
#define kNtErrorNoEventPair                                         580
#define kNtErrorDomainCtrlrConfigError                              581
#define kNtErrorIllegalCharacter                                    582 /* EILSEQ */
#define kNtErrorUndefinedCharacter                                  583
#define kNtErrorFloppyVolume                                        584
#define kNtErrorBiosFailedToConnectInterrupt                        585
#define kNtErrorBackupController                                    586
#define kNtErrorMutantLimitExceeded                                 587
#define kNtErrorFsDriverRequired                                    588
#define kNtErrorCannotLoadRegistryFile                              589
#define kNtErrorDebugAttachFailed                                   590
#define kNtErrorSystemProcessTerminated                             591
#define kNtErrorDataNotAccepted                                     592
#define kNtErrorVdmHardError                                        593
#define kNtErrorDriverCancelTimeout                                 594
#define kNtErrorReplyMessageMismatch                                595 /* EPROGMISMATCH */
#define kNtErrorLostWritebehindData                                 596
#define kNtErrorClientServerParametersInvalid                       597
#define kNtErrorNotTinyStream                                       598
#define kNtErrorStackOverflowRead                                   599
#define kNtErrorConvertToLarge                                      600
#define kNtErrorFoundOutOfScope                                     601
#define kNtErrorAllocateBucket                                      602
#define kNtErrorMarshallOverflow                                    603
#define kNtErrorInvalidVariant                                      604
#define kNtErrorBadCompressionBuffer                                605
#define kNtErrorAuditFailed                                         606
#define kNtErrorTimerResolutionNotSet                               607
#define kNtErrorInsufficientLogonInfo                               608
#define kNtErrorBadDllEntrypoint                                    609
#define kNtErrorBadServiceEntrypoint                                610
#define kNtErrorIpAddressConflict1                                  611
#define kNtErrorIpAddressConflict2                                  612
#define kNtErrorRegistryQuotaLimit                                  613
#define kNtErrorNoCallbackActive                                    614
#define kNtErrorPwdTooShort                                         615
#define kNtErrorPwdTooRecent                                        616
#define kNtErrorPwdHistoryConflict                                  617
#define kNtErrorUnsupportedCompression                              618
#define kNtErrorInvalidHwProfile                                    619
#define kNtErrorInvalidPlugplayDevicePath                           620
#define kNtErrorQuotaListInconsistent                               621
#define kNtErrorEvaluationExpiration                                622
#define kNtErrorIllegalDllRelocation                                623
#define kNtErrorDllInitFailedLogoff                                 624
#define kNtErrorValidateContinue                                    625
#define kNtErrorNoMoreMatches                                       626
#define kNtErrorRangeListConflict                                   627
#define kNtErrorServerSidMismatch                                   628
#define kNtErrorCantEnableDenyOnly                                  629
#define kNtErrorFloatMultipleFaults                                 630
#define kNtErrorFloatMultipleTraps                                  631
#define kNtErrorNointerface                                         632
#define kNtErrorDriverFailedSleep                                   633
#define kNtErrorCorruptSystemFile                                   634
#define kNtErrorCommitmentMinimum                                   635
#define kNtErrorPnpRestartEnumeration                               636
#define kNtErrorSystemImageBadSignature                             637
#define kNtErrorPnpRebootRequired                                   638
#define kNtErrorInsufficientPower                                   639 /* EPWROFF */
#define kNtErrorMultipleFaultViolation                              640
#define kNtErrorSystemShutdown                                      641
#define kNtErrorPortNotSet                                          642
#define kNtErrorDsVersionCheckFailure                               643
#define kNtErrorRangeNotFound                                       644
#define kNtErrorNotSafeModeDriver                                   646
#define kNtErrorFailedDriverEntry                                   647
#define kNtErrorDeviceEnumerationError                              648
#define kNtErrorMountPointNotResolved                               649
#define kNtErrorInvalidDeviceObjectParameter                        650
#define kNtErrorMcaOccured                                          651
#define kNtErrorDriverDatabaseError                                 652
#define kNtErrorSystemHiveTooLarge                                  653
#define kNtErrorDriverFailedPriorUnload                             654
#define kNtErrorVolsnapPrepareHibernate                             655
#define kNtErrorHibernationFailure                                  656
#define kNtErrorPwdTooLong                                          657
#define kNtErrorFileSystemLimitation                                665
#define kNtErrorAssertionFailure                                    668
#define kNtErrorAcpiError                                           669
#define kNtErrorWowAssertion                                        670
#define kNtErrorPnpBadMpsTable                                      671
#define kNtErrorPnpTranslationFailed                                672
#define kNtErrorPnpIrqTranslationFailed                             673
#define kNtErrorPnpInvalidId                                        674
#define kNtErrorWakeSystemDebugger                                  675
#define kNtErrorHandlesClosed                                       676
#define kNtErrorExtraneousInformation                               677
#define kNtErrorRxactCommitNecessary                                678
#define kNtErrorMediaCheck                                          679
#define kNtErrorGuidSubstitutionMade                                680
#define kNtErrorStoppedOnSymlink                                    681
#define kNtErrorLongjump                                            682
#define kNtErrorPlugplayQueryVetoed                                 683
#define kNtErrorUnwindConsolidate                                   684
#define kNtErrorRegistryHiveRecovered                               685
#define kNtErrorDllMightBeInsecure                                  686
#define kNtErrorDllMightBeIncompatible                              687
#define kNtErrorDbgExceptionNotHandled                              688
#define kNtErrorDbgReplyLater                                       689
#define kNtErrorDbgUnableToProvideHandle                            690
#define kNtErrorDbgTerminateThread                                  691
#define kNtErrorDbgTerminateProcess                                 692
#define kNtErrorDbgControlC                                         693
#define kNtErrorDbgPrintexceptionC                                  694
#define kNtErrorDbgRipexception                                     695
#define kNtErrorDbgControlBreak                                     696
#define kNtErrorDbgCommandException                                 697
#define kNtErrorObjectNameExists                                    698
#define kNtErrorThreadWasSuspended                                  699
#define kNtErrorImageNotAtBase                                      700
#define kNtErrorRxactStateCreated                                   701
#define kNtErrorSegmentNotification                                 702
#define kNtErrorBadCurrentDirectory                                 703
#define kNtErrorFtReadRecoveryFromBackup                            704
#define kNtErrorFtWriteRecovery                                     705
#define kNtErrorImageMachineTypeMismatch                            706
#define kNtErrorReceivePartial                                      707
#define kNtErrorReceiveExpedited                                    708
#define kNtErrorReceivePartialExpedited                             709
#define kNtErrorEventDone                                           710
#define kNtErrorEventPending                                        711
#define kNtErrorCheckingFileSystem                                  712
#define kNtErrorFatalAppExit                                        713
#define kNtErrorPredefinedHandle                                    714
#define kNtErrorWasUnlocked                                         715
#define kNtErrorServiceNotification                                 716
#define kNtErrorWasLocked                                           717
#define kNtErrorLogHardError                                        718
#define kNtErrorAlreadyWin32                                        719
#define kNtErrorImageMachineTypeMismatchExe                         720
#define kNtErrorNoYieldPerformed                                    721
#define kNtErrorTimerResumeIgnored                                  722
#define kNtErrorArbitrationUnhandled                                723
#define kNtErrorCardbusNotSupported                                 724
#define kNtErrorMpProcessorMismatch                                 725
#define kNtErrorHibernated                                          726
#define kNtErrorResumeHibernation                                   727
#define kNtErrorFirmwareUpdated                                     728
#define kNtErrorDriversLeakingLockedPages                           729
#define kNtErrorWakeSystem                                          730
#define kNtErrorWait_1                                              731
#define kNtErrorWait_2                                              732
#define kNtErrorWait_3                                              733
#define kNtErrorWait_63                                             734
#define kNtErrorAbandonedWait_0                                     735
#define kNtErrorAbandonedWait_63                                    736
#define kNtErrorUserApc                                             737
#define kNtErrorKernelApc                                           738
#define kNtErrorAlerted                                             739
#define kNtErrorElevationRequired                                   740
#define kNtErrorReparse                                             741
#define kNtErrorOplockBreakInProgress                               742
#define kNtErrorVolumeMounted                                       743
#define kNtErrorRxactCommitted                                      744
#define kNtErrorNotifyCleanup                                       745
#define kNtErrorPrimaryTransportConnectFailed                       746
#define kNtErrorPageFaultTransition                                 747
#define kNtErrorPageFaultDemandZero                                 748
#define kNtErrorPageFaultCopyOnWrite                                749
#define kNtErrorPageFaultGuardPage                                  750
#define kNtErrorPageFaultPagingFile                                 751
#define kNtErrorCachePageLocked                                     752
#define kNtErrorCrashDump                                           753
#define kNtErrorBufferAllZeros                                      754
#define kNtErrorReparseObject                                       755
#define kNtErrorResourceRequirementsChanged                         756
#define kNtErrorTranslationComplete                                 757
#define kNtErrorNothingToTerminate                                  758
#define kNtErrorProcessNotInJob                                     759
#define kNtErrorProcessInJob                                        760
#define kNtErrorVolsnapHibernateReady                               761
#define kNtErrorFsfilterOpCompletedSuccessfully                     762
#define kNtErrorInterruptVectorAlreadyConnected                     763
#define kNtErrorInterruptStillConnected                             764
#define kNtErrorWaitForOplock                                       765
#define kNtErrorDbgExceptionHandled                                 766
#define kNtErrorDbgContinue                                         767
#define kNtErrorCallbackPopStack                                    768
#define kNtErrorCompressionDisabled                                 769
#define kNtErrorCantfetchbackwards                                  770
#define kNtErrorCantscrollbackwards                                 771
#define kNtErrorRowsnotreleased                                     772
#define kNtErrorBadAccessorFlags                                    773
#define kNtErrorErrorsEncountered                                   774
#define kNtErrorNotCapable                                          775
#define kNtErrorRequestOutOfSequence                                776
#define kNtErrorVersionParseError                                   777
#define kNtErrorBadstartposition                                    778
#define kNtErrorMemoryHardware                                      779
#define kNtErrorDiskRepairDisabled                                  780
#define kNtErrorInsufficientResourceForSpecifiedSharedSectionSize   781
#define kNtErrorSystemPowerstateTransition                          782
#define kNtErrorSystemPowerstateComplexTransition                   783
#define kNtErrorMcaException                                        784
#define kNtErrorAccessAuditByPolicy                                 785
#define kNtErrorAccessDisabledNoSaferUiByPolicy                     786
#define kNtErrorAbandonHiberfile                                    787
#define kNtErrorLostWritebehindDataNetworkDisconnected              788
#define kNtErrorLostWritebehindDataNetworkServerError               789
#define kNtErrorLostWritebehindDataLocalDiskError                   790
#define kNtErrorBadMcfgTable                                        791
#define kNtErrorDiskRepairRedirected                                792
#define kNtErrorDiskRepairUnsuccessful                              793
#define kNtErrorCorruptLogOverfull                                  794
#define kNtErrorCorruptLogCorrupted                                 795
#define kNtErrorCorruptLogUnavailable                               796
#define kNtErrorCorruptLogDeletedFull                               797
#define kNtErrorCorruptLogCleared                                   798
#define kNtErrorOrphanNameExhausted                                 799
#define kNtErrorOplockSwitchedToNewHandle                           800
#define kNtErrorCannotGrantRequestedOplock                          801
#define kNtErrorCannotBreakOplock                                   802
#define kNtErrorOplockHandleClosed                                  803
#define kNtErrorNoAceCondition                                      804
#define kNtErrorInvalidAceCondition                                 805
#define kNtErrorFileHandleRevoked                                   806
#define kNtErrorImageAtDifferentBase                                807
#define kNtErrorEncryptedIoNotPossible                              808
#define kNtErrorFileMetadataOptimizationInProgress                  809
#define kNtErrorQuotaActivity                                       810
#define kNtErrorHandleRevoked                                       811
#define kNtErrorCallbackInvokeInline                                812
#define kNtErrorCpuSetInvalid                                       813
#define kNtErrorEnclaveNotTerminated                                814
#define kNtErrorEnclaveViolation                                    815
#define kNtErrorEaAccessDenied                                      994
#define kNtErrorOperationAborted                                    995
#define kNtErrorIoIncomplete                                        996
#define kNtErrorIoPending                                           997
#define kNtErrorNoaccess                                            998
#define kNtErrorSwaperror                                           999
#define kNtErrorStackOverflow                                       1001
#define kNtErrorInvalidMessage                                      1002
#define kNtErrorCanNotComplete                                      1003
#define kNtErrorInvalidFlags                                        1004
#define kNtErrorUnrecognizedVolume                                  1005
#define kNtErrorFileInvalid                                         1006
#define kNtErrorFullscreenMode                                      1007
#define kNtErrorNoToken                                             1008
#define kNtErrorBaddb                                               1009
#define kNtErrorBadkey                                              1010
#define kNtErrorCantopen                                            1011
#define kNtErrorCantread                                            1012
#define kNtErrorCantwrite                                           1013
#define kNtErrorRegistryRecovered                                   1014
#define kNtErrorRegistryCorrupt                                     1015
#define kNtErrorRegistryIoFailed                                    1016
#define kNtErrorNotRegistryFile                                     1017
#define kNtErrorKeyDeleted                                          1018
#define kNtErrorNoLogSpace                                          1019
#define kNtErrorKeyHasChildren                                      1020
#define kNtErrorChildMustBeVolatile                                 1021
#define kNtErrorNotifyEnumDir                                       1022
#define kNtErrorDependentServicesRunning                            1051
#define kNtErrorInvalidServiceControl                               1052
#define kNtErrorServiceRequestTimeout                               1053
#define kNtErrorServiceNoThread                                     1054
#define kNtErrorServiceDatabaseLocked                               1055
#define kNtErrorServiceAlreadyRunning                               1056
#define kNtErrorInvalidServiceAccount                               1057
#define kNtErrorServiceDisabled                                     1058
#define kNtErrorCircularDependency                                  1059
#define kNtErrorServiceDoesNotExist                                 1060
#define kNtErrorServiceCannotAcceptCtrl                             1061
#define kNtErrorServiceNotActive                                    1062
#define kNtErrorFailedServiceControllerConnect                      1063
#define kNtErrorExceptionInService                                  1064
#define kNtErrorDatabaseDoesNotExist                                1065
#define kNtErrorServiceSpecificError                                1066
#define kNtErrorProcessAborted                                      1067
#define kNtErrorServiceDependencyFail                               1068
#define kNtErrorServiceLogonFailed                                  1069
#define kNtErrorServiceStartHang                                    1070
#define kNtErrorInvalidServiceLock                                  1071
#define kNtErrorServiceMarkedForDelete                              1072
#define kNtErrorServiceExists                                       1073
#define kNtErrorAlreadyRunningLkg                                   1074
#define kNtErrorServiceDependencyDeleted                            1075
#define kNtErrorBootAlreadyAccepted                                 1076
#define kNtErrorServiceNeverStarted                                 1077
#define kNtErrorDuplicateServiceName                                1078
#define kNtErrorDifferentServiceAccount                             1079
#define kNtErrorCannotDetectDriverFailure                           1080
#define kNtErrorCannotDetectProcessAbort                            1081
#define kNtErrorNoRecoveryProgram                                   1082
#define kNtErrorServiceNotInExe                                     1083
#define kNtErrorNotSafebootService                                  1084
#define kNtErrorEndOfMedia                                          1100
#define kNtErrorFilemarkDetected                                    1101
#define kNtErrorBeginningOfMedia                                    1102
#define kNtErrorSetmarkDetected                                     1103
#define kNtErrorNoDataDetected                                      1104
#define kNtErrorPartitionFailure                                    1105
#define kNtErrorInvalidBlockLength                                  1106
#define kNtErrorDeviceNotPartitioned                                1107
#define kNtErrorUnableToLockMedia                                   1108
#define kNtErrorUnableToUnloadMedia                                 1109
#define kNtErrorMediaChanged                                        1110
#define kNtErrorBusReset                                            1111
#define kNtErrorNoMediaInDrive                                      1112 /* ENXIO */
#define kNtErrorNoUnicodeTranslation                                1113
#define kNtErrorDllInitFailed                                       1114
#define kNtErrorShutdownInProgress                                  1115
#define kNtErrorNoShutdownInProgress                                1116
#define kNtErrorIoDevice                                            1117 /* EIO */
#define kNtErrorSerialNoDevice                                      1118 /* ENOTTY */
#define kNtErrorIrqBusy                                             1119
#define kNtErrorMoreWrites                                          1120
#define kNtErrorCounterTimeout                                      1121
#define kNtErrorFloppyIdMarkNotFound                                1122
#define kNtErrorFloppyWrongCylinder                                 1123
#define kNtErrorFloppyUnknownError                                  1124
#define kNtErrorFloppyBadRegisters                                  1125
#define kNtErrorDiskRecalibrateFailed                               1126
#define kNtErrorDiskOperationFailed                                 1127
#define kNtErrorDiskResetFailed                                     1128
#define kNtErrorEomOverflow                                         1129
#define kNtErrorNotEnoughServerMemory                               1130
#define kNtErrorPossibleDeadlock                                    1131 /* EDEADLK */
#define kNtErrorMappedAlignment                                     1132
#define kNtErrorSetPowerStateVetoed                                 1140
#define kNtErrorSetPowerStateFailed                                 1141
#define kNtErrorTooManyLinks                                        1142
#define kNtErrorOldWinVersion                                       1150
#define kNtErrorAppWrongOs                                          1151
#define kNtErrorSingleInstanceApp                                   1152
#define kNtErrorRmodeApp                                            1153
#define kNtErrorInvalidDll                                          1154
#define kNtErrorNoAssociation                                       1155
#define kNtErrorDdeFail                                             1156
#define kNtErrorDllNotFound                                         1157
#define kNtErrorNoMoreUserHandles                                   1158
#define kNtErrorMessageSyncOnly                                     1159
#define kNtErrorSourceElementEmpty                                  1160
#define kNtErrorDestinationElementFull                              1161
#define kNtErrorIllegalElementAddress                               1162
#define kNtErrorMagazineNotPresent                                  1163
#define kNtErrorDeviceReinitializationNeeded                        1164
#define kNtErrorDeviceRequiresCleaning                              1165
#define kNtErrorDeviceDoorOpen                                      1166
#define kNtErrorDeviceNotConnected                                  1167
#define kNtErrorNotFound                                            1168
#define kNtErrorNoMatch                                             1169
#define kNtErrorSetNotFound                                         1170
#define kNtErrorPointNotFound                                       1171
#define kNtErrorNoTrackingService                                   1172
#define kNtErrorNoVolumeId                                          1173
#define kNtErrorUnableToRemoveReplaced                              1175
#define kNtErrorUnableToMoveReplacement                             1176
#define kNtErrorUnableToMoveReplacement_2                           1177
#define kNtErrorJournalDeleteInProgress                             1178
#define kNtErrorJournalNotActive                                    1179
#define kNtErrorPotentialFileFound                                  1180
#define kNtErrorJournalEntryDeleted                                 1181
#define kNtErrorShutdownIsScheduled                                 1190
#define kNtErrorShutdownUsersLoggedOn                               1191
#define kNtErrorBadDevice                                           1200 /* ENODEV */
#define kNtErrorConnectionUnavail                                   1201
#define kNtErrorDeviceAlreadyRemembered                             1202
#define kNtErrorNoNetOrBadPath                                      1203
#define kNtErrorBadProvider                                         1204
#define kNtErrorCannotOpenProfile                                   1205
#define kNtErrorBadProfile                                          1206
#define kNtErrorNotContainer                                        1207
#define kNtErrorExtendedError                                       1208
#define kNtErrorInvalidGroupname                                    1209
#define kNtErrorInvalidComputername                                 1210
#define kNtErrorInvalidEventname                                    1211
#define kNtErrorInvalidDomainname                                   1212
#define kNtErrorInvalidServicename                                  1213
#define kNtErrorInvalidNetname                                      1214
#define kNtErrorInvalidSharename                                    1215
#define kNtErrorInvalidPasswordname                                 1216
#define kNtErrorInvalidMessagename                                  1217
#define kNtErrorInvalidMessagedest                                  1218
#define kNtErrorSessionCredentialConflict                           1219
#define kNtErrorRemoteSessionLimitExceeded                          1220
#define kNtErrorDupDomainname                                       1221
#define kNtErrorNoNetwork                                           1222
#define kNtErrorCancelled                                           1223 /* ECANCELED */
#define kNtErrorUserMappedFile                                      1224
#define kNtErrorConnectionRefused                                   1225
#define kNtErrorGracefulDisconnect                                  1226
#define kNtErrorAddressAlreadyAssociated                            1227
#define kNtErrorAddressNotAssociated                                1228
#define kNtErrorConnectionInvalid                                   1229
#define kNtErrorConnectionActive                                    1230
#define kNtErrorNetworkUnreachable                                  1231
#define kNtErrorHostUnreachable                                     1232
#define kNtErrorProtocolUnreachable                                 1233 /* multimapped to ENETUNREACH */
#define kNtErrorPortUnreachable                                     1234
#define kNtErrorRequestAborted                                      1235
#define kNtErrorConnectionAborted                                   1236
#define kNtErrorRetry                                               1237
#define kNtErrorConnectionCountLimit                                1238
#define kNtErrorLoginTimeRestriction                                1239
#define kNtErrorLoginWkstaRestriction                               1240
#define kNtErrorIncorrectAddress                                    1241
#define kNtErrorAlreadyRegistered                                   1242
#define kNtErrorServiceNotFound                                     1243
#define kNtErrorNotAuthenticated                                    1244 /* EAUTH */
#define kNtErrorNotLoggedOn                                         1245
#define kNtErrorContinue                                            1246
#define kNtErrorAlreadyInitialized                                  1247
#define kNtErrorNoMoreDevices                                       1248
#define kNtErrorNoSuchSite                                          1249
#define kNtErrorDomainControllerExists                              1250
#define kNtErrorOnlyIfConnected                                     1251
#define kNtErrorOverrideNochanges                                   1252
#define kNtErrorBadUserProfile                                      1253
#define kNtErrorNotSupportedOnSbs                                   1254
#define kNtErrorServerShutdownInProgress                            1255
#define kNtErrorHostDown                                            1256
#define kNtErrorNonAccountSid                                       1257
#define kNtErrorNonDomainSid                                        1258
#define kNtErrorApphelpBlock                                        1259
#define kNtErrorAccessDisabledByPolicy                              1260
#define kNtErrorRegNatConsumption                                   1261
#define kNtErrorCscshareOffline                                     1262
#define kNtErrorPkinitFailure                                       1263
#define kNtErrorSmartcardSubsystemFailure                           1264
#define kNtErrorDowngradeDetected                                   1265
#define kNtErrorMachineLocked                                       1271
#define kNtErrorSmbGuestLogonBlocked                                1272
#define kNtErrorCallbackSuppliedInvalidData                         1273
#define kNtErrorSyncForegroundRefreshRequired                       1274
#define kNtErrorDriverBlocked                                       1275
#define kNtErrorInvalidImportOfNonDll                               1276
#define kNtErrorAccessDisabledWebblade                              1277
#define kNtErrorAccessDisabledWebbladeTamper                        1278
#define kNtErrorRecoveryFailure                                     1279
#define kNtErrorAlreadyFiber                                        1280
#define kNtErrorAlreadyThread                                       1281
#define kNtErrorStackBufferOverrun                                  1282
#define kNtErrorParameterQuotaExceeded                              1283
#define kNtErrorDebuggerInactive                                    1284
#define kNtErrorDelayLoadFailed                                     1285
#define kNtErrorVdmDisallowed                                       1286
#define kNtErrorUnidentifiedError                                   1287 /* EIDRM */
#define kNtErrorInvalidCruntimeParameter                            1288
#define kNtErrorBeyondVdl                                           1289
#define kNtErrorIncompatibleServiceSidType                          1290
#define kNtErrorDriverProcessTerminated                             1291
#define kNtErrorImplementationLimit                                 1292
#define kNtErrorProcessIsProtected                                  1293
#define kNtErrorServiceNotifyClientLagging                          1294
#define kNtErrorDiskQuotaExceeded                                   1295
#define kNtErrorContentBlocked                                      1296
#define kNtErrorIncompatibleServicePrivilege                        1297
#define kNtErrorAppHang                                             1298
#define kNtErrorInvalidLabel                                        1299
#define kNtErrorNotAllAssigned                                      1300
#define kNtErrorSomeNotMapped                                       1301
#define kNtErrorNoQuotasForAccount                                  1302
#define kNtErrorLocalUserSessionKey                                 1303
#define kNtErrorNullLmPassword                                      1304
#define kNtErrorUnknownRevision                                     1305
#define kNtErrorRevisionMismatch                                    1306
#define kNtErrorInvalidOwner                                        1307
#define kNtErrorInvalidPrimaryGroup                                 1308
#define kNtErrorNoImpersonationToken                                1309
#define kNtErrorCantDisableMandatory                                1310
#define kNtErrorNoLogonServers                                      1311
#define kNtErrorNoSuchLogonSession                                  1312
#define kNtErrorNoSuchPrivilege                                     1313
#define kNtErrorPrivilegeNotHeld                                    1314
#define kNtErrorInvalidAccountName                                  1315
#define kNtErrorUserExists                                          1316
#define kNtErrorNoSuchUser                                          1317
#define kNtErrorGroupExists                                         1318
#define kNtErrorNoSuchGroup                                         1319
#define kNtErrorMemberInGroup                                       1320
#define kNtErrorMemberNotInGroup                                    1321
#define kNtErrorLastAdmin                                           1322
#define kNtErrorWrongPassword                                       1323
#define kNtErrorIllFormedPassword                                   1324
#define kNtErrorPasswordRestriction                                 1325
#define kNtErrorLogonFailure                                        1326
#define kNtErrorAccountRestriction                                  1327
#define kNtErrorInvalidLogonHours                                   1328
#define kNtErrorInvalidWorkstation                                  1329
#define kNtErrorPasswordExpired                                     1330
#define kNtErrorAccountDisabled                                     1331
#define kNtErrorNoneMapped                                          1332
#define kNtErrorTooManyLuidsRequested                               1333
#define kNtErrorLuidsExhausted                                      1334
#define kNtErrorInvalidSubAuthority                                 1335
#define kNtErrorInvalidAcl                                          1336
#define kNtErrorInvalidSid                                          1337
#define kNtErrorInvalidSecurityDescr                                1338
#define kNtErrorBadInheritanceAcl                                   1340
#define kNtErrorServerDisabled                                      1341
#define kNtErrorServerNotDisabled                                   1342
#define kNtErrorInvalidIdAuthority                                  1343
#define kNtErrorAllottedSpaceExceeded                               1344
#define kNtErrorInvalidGroupAttributes                              1345
#define kNtErrorBadImpersonationLevel                               1346
#define kNtErrorCantOpenAnonymous                                   1347
#define kNtErrorBadValidationClass                                  1348
#define kNtErrorBadTokenType                                        1349
#define kNtErrorNoSecurityOnObject                                  1350
#define kNtErrorCantAccessDomainInfo                                1351
#define kNtErrorInvalidServerState                                  1352
#define kNtErrorInvalidDomainState                                  1353
#define kNtErrorInvalidDomainRole                                   1354
#define kNtErrorNoSuchDomain                                        1355
#define kNtErrorDomainExists                                        1356
#define kNtErrorDomainLimitExceeded                                 1357
#define kNtErrorInternalDbCorruption                                1358
#define kNtErrorInternalError                                       1359
#define kNtErrorGenericNotMapped                                    1360
#define kNtErrorBadDescriptorFormat                                 1361
#define kNtErrorNotLogonProcess                                     1362
#define kNtErrorLogonSessionExists                                  1363
#define kNtErrorNoSuchPackage                                       1364
#define kNtErrorBadLogonSessionState                                1365
#define kNtErrorLogonSessionCollision                               1366
#define kNtErrorInvalidLogonType                                    1367
#define kNtErrorCannotImpersonate                                   1368
#define kNtErrorRxactInvalidState                                   1369
#define kNtErrorRxactCommitFailure                                  1370
#define kNtErrorSpecialAccount                                      1371
#define kNtErrorSpecialGroup                                        1372
#define kNtErrorSpecialUser                                         1373
#define kNtErrorMembersPrimaryGroup                                 1374
#define kNtErrorTokenAlreadyInUse                                   1375
#define kNtErrorNoSuchAlias                                         1376
#define kNtErrorMemberNotInAlias                                    1377
#define kNtErrorMemberInAlias                                       1378
#define kNtErrorAliasExists                                         1379
#define kNtErrorLogonNotGranted                                     1380
#define kNtErrorTooManySecrets                                      1381
#define kNtErrorSecretTooLong                                       1382
#define kNtErrorInternalDbError                                     1383
#define kNtErrorTooManyContextIds                                   1384
#define kNtErrorLogonTypeNotGranted                                 1385
#define kNtErrorNtCrossEncryptionRequired                           1386
#define kNtErrorNoSuchMember                                        1387
#define kNtErrorInvalidMember                                       1388
#define kNtErrorTooManySids                                         1389
#define kNtErrorLmCrossEncryptionRequired                           1390
#define kNtErrorNoInheritance                                       1391
#define kNtErrorFileCorrupt                                         1392
#define kNtErrorDiskCorrupt                                         1393
#define kNtErrorNoUserSessionKey                                    1394
#define kNtErrorLicenseQuotaExceeded                                1395
#define kNtErrorWrongTargetName                                     1396
#define kNtErrorMutualAuthFailed                                    1397
#define kNtErrorTimeSkew                                            1398
#define kNtErrorCurrentDomainNotAllowed                             1399
#define kNtErrorInvalidWindowHandle                                 1400
#define kNtErrorInvalidMenuHandle                                   1401
#define kNtErrorInvalidCursorHandle                                 1402
#define kNtErrorInvalidAccelHandle                                  1403
#define kNtErrorInvalidHookHandle                                   1404
#define kNtErrorInvalidDwpHandle                                    1405
#define kNtErrorTlwWithWschild                                      1406
#define kNtErrorCannotFindWndClass                                  1407
#define kNtErrorWindowOfOtherThread                                 1408
#define kNtErrorHotkeyAlreadyRegistered                             1409
#define kNtErrorClassAlreadyExists                                  1410
#define kNtErrorClassDoesNotExist                                   1411
#define kNtErrorClassHasWindows                                     1412
#define kNtErrorInvalidIndex                                        1413
#define kNtErrorInvalidIconHandle                                   1414
#define kNtErrorPrivateDialogIndex                                  1415
#define kNtErrorListboxIdNotFound                                   1416
#define kNtErrorNoWildcardCharacters                                1417
#define kNtErrorClipboardNotOpen                                    1418
#define kNtErrorHotkeyNotRegistered                                 1419
#define kNtErrorWindowNotDialog                                     1420
#define kNtErrorControlIdNotFound                                   1421
#define kNtErrorInvalidComboboxMessage                              1422
#define kNtErrorWindowNotCombobox                                   1423
#define kNtErrorInvalidEditHeight                                   1424
#define kNtErrorDcNotFound                                          1425
#define kNtErrorInvalidHookFilter                                   1426
#define kNtErrorInvalidFilterProc                                   1427
#define kNtErrorHookNeedsHmod                                       1428
#define kNtErrorGlobalOnlyHook                                      1429
#define kNtErrorJournalHookSet                                      1430
#define kNtErrorHookNotInstalled                                    1431
#define kNtErrorInvalidLbMessage                                    1432
#define kNtErrorSetcountOnBadLb                                     1433
#define kNtErrorLbWithoutTabstops                                   1434
#define kNtErrorDestroyObjectOfOtherThread                          1435
#define kNtErrorChildWindowMenu                                     1436
#define kNtErrorNoSystemMenu                                        1437
#define kNtErrorInvalidMsgboxStyle                                  1438
#define kNtErrorInvalidSpiValue                                     1439
#define kNtErrorScreenAlreadyLocked                                 1440
#define kNtErrorHwndsHaveDiffParent                                 1441
#define kNtErrorNotChildWindow                                      1442
#define kNtErrorInvalidGwCommand                                    1443
#define kNtErrorInvalidThreadId                                     1444
#define kNtErrorNonMdichildWindow                                   1445
#define kNtErrorPopupAlreadyActive                                  1446
#define kNtErrorNoScrollbars                                        1447
#define kNtErrorInvalidScrollbarRange                               1448
#define kNtErrorInvalidShowwinCommand                               1449
#define kNtErrorNoSystemResources                                   1450
#define kNtErrorNonpagedSystemResources                             1451
#define kNtErrorPagedSystemResources                                1452
#define kNtErrorWorkingSetQuota                                     1453
#define kNtErrorPagefileQuota                                       1454
#define kNtErrorCommitmentLimit                                     1455
#define kNtErrorMenuItemNotFound                                    1456
#define kNtErrorInvalidKeyboardHandle                               1457
#define kNtErrorHookTypeNotAllowed                                  1458
#define kNtErrorRequiresInteractiveWindowstation                    1459
#define kNtErrorTimeout                                             1460 /* ETIMEDOUT */
#define kNtErrorInvalidMonitorHandle                                1461
#define kNtErrorIncorrectSize                                       1462
#define kNtErrorSymlinkClassDisabled                                1463
#define kNtErrorSymlinkNotSupported                                 1464
#define kNtErrorXmlParseError                                       1465
#define kNtErrorXmldsigError                                        1466
#define kNtErrorRestartApplication                                  1467
#define kNtErrorWrongCompartment                                    1468
#define kNtErrorAuthipFailure                                       1469
#define kNtErrorNoNvramResources                                    1470
#define kNtErrorNotGuiProcess                                       1471
#define kNtErrorEventlogFileCorrupt                                 1500
#define kNtErrorEventlogCantStart                                   1501
#define kNtErrorLogFileFull                                         1502
#define kNtErrorEventlogFileChanged                                 1503
#define kNtErrorContainerAssigned                                   1504
#define kNtErrorJobNoContainer                                      1505
#define kNtErrorInvalidTaskName                                     1550
#define kNtErrorInvalidTaskIndex                                    1551
#define kNtErrorThreadAlreadyInTask                                 1552
#define kNtErrorInstallServiceFailure                               1601
#define kNtErrorInstallUserexit                                     1602
#define kNtErrorInstallFailure                                      1603
#define kNtErrorInstallSuspend                                      1604
#define kNtErrorUnknownProduct                                      1605
#define kNtErrorUnknownFeature                                      1606
#define kNtErrorUnknownComponent                                    1607
#define kNtErrorUnknownProperty                                     1608
#define kNtErrorInvalidHandleState                                  1609
#define kNtErrorBadConfiguration                                    1610
#define kNtErrorIndexAbsent                                         1611
#define kNtErrorInstallSourceAbsent                                 1612
#define kNtErrorInstallPackageVersion                               1613
#define kNtErrorProductUninstalled                                  1614
#define kNtErrorBadQuerySyntax                                      1615
#define kNtErrorInvalidField                                        1616
#define kNtErrorDeviceRemoved                                       1617
#define kNtErrorInstallAlreadyRunning                               1618
#define kNtErrorInstallPackageOpenFailed                            1619
#define kNtErrorInstallPackageInvalid                               1620
#define kNtErrorInstallUiFailure                                    1621
#define kNtErrorInstallLogFailure                                   1622
#define kNtErrorInstallLanguageUnsupported                          1623
#define kNtErrorInstallTransformFailure                             1624
#define kNtErrorInstallPackageRejected                              1625
#define kNtErrorFunctionNotCalled                                   1626 /* EBADRPC */
#define kNtErrorFunctionFailed                                      1627 /* ERPCMISMATCH */
#define kNtErrorInvalidTable                                        1628
#define kNtErrorDatatypeMismatch                                    1629
#define kNtErrorUnsupportedType                                     1630
#define kNtErrorCreateFailed                                        1631
#define kNtErrorInstallTempUnwritable                               1632
#define kNtErrorInstallPlatformUnsupported                          1633
#define kNtErrorInstallNotused                                      1634
#define kNtErrorPatchPackageOpenFailed                              1635
#define kNtErrorPatchPackageInvalid                                 1636
#define kNtErrorPatchPackageUnsupported                             1637
#define kNtErrorProductVersion                                      1638
#define kNtErrorInvalidCommandLine                                  1639 /* E2BIG */
#define kNtErrorInstallRemoteDisallowed                             1640
#define kNtErrorSuccessRebootInitiated                              1641
#define kNtErrorPatchTargetNotFound                                 1642
#define kNtErrorPatchPackageRejected                                1643
#define kNtErrorInstallTransformRejected                            1644
#define kNtErrorInstallRemoteProhibited                             1645
#define kNtErrorPatchRemovalUnsupported                             1646
#define kNtErrorUnknownPatch                                        1647
#define kNtErrorPatchNoSequence                                     1648
#define kNtErrorPatchRemovalDisallowed                              1649
#define kNtErrorInvalidPatchXml                                     1650
#define kNtErrorPatchManagedAdvertisedProduct                       1651
#define kNtErrorInstallServiceSafeboot                              1652
#define kNtErrorFailFastException                                   1653
#define kNtErrorInstallRejected                                     1654
#define kNtErrorDynamicCodeBlocked                                  1655
#define kNtErrorNotSameObject                                       1656
#define kNtErrorStrictCfgViolation                                  1657
#define kNtErrorSetContextDenied                                    1660
#define kNtErrorCrossPartitionViolation                             1661
#define kNtErrorInvalidUserBuffer                                   1784
#define kNtErrorUnrecognizedMedia                                   1785
#define kNtErrorNoTrustLsaSecret                                    1786
#define kNtErrorNoTrustSamAccount                                   1787
#define kNtErrorTrustedDomainFailure                                1788
#define kNtErrorTrustedRelationshipFailure                          1789
#define kNtErrorTrustFailure                                        1790
#define kNtErrorNetlogonNotStarted                                  1792
#define kNtErrorAccountExpired                                      1793
#define kNtErrorRedirectorHasOpenHandles                            1794
#define kNtErrorPrinterDriverAlreadyInstalled                       1795
#define kNtErrorUnknownPort                                         1796
#define kNtErrorUnknownPrinterDriver                                1797
#define kNtErrorUnknownPrintprocessor                               1798
#define kNtErrorInvalidSeparatorFile                                1799
#define kNtErrorInvalidPriority                                     1800
#define kNtErrorInvalidPrinterName                                  1801
#define kNtErrorPrinterAlreadyExists                                1802
#define kNtErrorInvalidPrinterCommand                               1803
#define kNtErrorInvalidDatatype                                     1804
#define kNtErrorInvalidEnvironment                                  1805
#define kNtErrorNologonInterdomainTrustAccount                      1807
#define kNtErrorNologonWorkstationTrustAccount                      1808
#define kNtErrorNologonServerTrustAccount                           1809
#define kNtErrorDomainTrustInconsistent                             1810
#define kNtErrorServerHasOpenHandles                                1811
#define kNtErrorResourceDataNotFound                                1812
#define kNtErrorResourceTypeNotFound                                1813
#define kNtErrorResourceNameNotFound                                1814
#define kNtErrorResourceLangNotFound                                1815
#define kNtErrorNotEnoughQuota                                      1816 /* EDQUOT */
#define kNtErrorInvalidTime                                         1901
#define kNtErrorInvalidFormName                                     1902
#define kNtErrorInvalidFormSize                                     1903
#define kNtErrorAlreadyWaiting                                      1904
#define kNtErrorPrinterDeleted                                      1905
#define kNtErrorInvalidPrinterState                                 1906
#define kNtErrorPasswordMustChange                                  1907
#define kNtErrorDomainControllerNotFound                            1908
#define kNtErrorAccountLockedOut                                    1909
#define kNtErrorNoSitename                                          1919
#define kNtErrorCantAccessFile                                      1920
#define kNtErrorCantResolveFilename                                 1921
#define kNtErrorKmDriverBlocked                                     1930
#define kNtErrorContextExpired                                      1931
#define kNtErrorPerUserTrustQuotaExceeded                           1932
#define kNtErrorAllUserTrustQuotaExceeded                           1933
#define kNtErrorUserDeleteTrustQuotaExceeded                        1934
#define kNtErrorAuthenticationFirewallFailed                        1935
#define kNtErrorRemotePrintConnectionsBlocked                       1936
#define kNtErrorNtlmBlocked                                         1937
#define kNtErrorPasswordChangeRequired                              1938
#define kNtErrorLostModeLogonRestriction                            1939
#define kNtErrorInvalidPixelFormat                                  2000
#define kNtErrorBadDriver                                           2001
#define kNtErrorInvalidWindowStyle                                  2002
#define kNtErrorMetafileNotSupported                                2003
#define kNtErrorTransformNotSupported                               2004
#define kNtErrorClippingNotSupported                                2005
#define kNtErrorInvalidCmm                                          2010
#define kNtErrorInvalidProfile                                      2011
#define kNtErrorTagNotFound                                         2012
#define kNtErrorTagNotPresent                                       2013
#define kNtErrorDuplicateTag                                        2014
#define kNtErrorProfileNotAssociatedWithDevice                      2015
#define kNtErrorProfileNotFound                                     2016
#define kNtErrorInvalidColorspace                                   2017
#define kNtErrorIcmNotEnabled                                       2018
#define kNtErrorDeletingIcmXform                                    2019
#define kNtErrorInvalidTransform                                    2020
#define kNtErrorColorspaceMismatch                                  2021
#define kNtErrorInvalidColorindex                                   2022
#define kNtErrorProfileDoesNotMatchDevice                           2023
#define kNtErrorConnectedOtherPassword                              2108
#define kNtErrorConnectedOtherPasswordDefault                       2109
#define kNtErrorBadUsername                                         2202
#define kNtErrorNotConnected                                        2250
#define kNtErrorOpenFiles                                           2401
#define kNtErrorActiveConnections                                   2402
#define kNtErrorDeviceInUse                                         2404
#define kNtErrorUnknownPrintMonitor                                 3000
#define kNtErrorPrinterDriverInUse                                  3001
#define kNtErrorSpoolFileNotFound                                   3002
#define kNtErrorSplNoStartdoc                                       3003
#define kNtErrorSplNoAddjob                                         3004
#define kNtErrorPrintProcessorAlreadyInstalled                      3005
#define kNtErrorPrintMonitorAlreadyInstalled                        3006
#define kNtErrorInvalidPrintMonitor                                 3007
#define kNtErrorPrintMonitorInUse                                   3008
#define kNtErrorPrinterHasJobsQueued                                3009
#define kNtErrorSuccessRebootRequired                               3010
#define kNtErrorSuccessRestartRequired                              3011
#define kNtErrorPrinterNotFound                                     3012
#define kNtErrorPrinterDriverWarned                                 3013
#define kNtErrorPrinterDriverBlocked                                3014
#define kNtErrorPrinterDriverPackageInUse                           3015
#define kNtErrorCoreDriverPackageNotFound                           3016
#define kNtErrorFailRebootRequired                                  3017
#define kNtErrorFailRebootInitiated                                 3018
#define kNtErrorPrinterDriverDownloadNeeded                         3019
#define kNtErrorPrintJobRestartRequired                             3020
#define kNtErrorInvalidPrinterDriverManifest                        3021
#define kNtErrorPrinterNotShareable                                 3022
#define kNtErrorRequestPaused                                       3050
#define kNtErrorAppexecConditionNotSatisfied                        3060
#define kNtErrorAppexecHandleInvalidated                            3061
#define kNtErrorAppexecInvalidHostGeneration                        3062
#define kNtErrorAppexecUnexpectedProcessRegistration                3063
#define kNtErrorAppexecInvalidHostState                             3064
#define kNtErrorAppexecNoDonor                                      3065
#define kNtErrorAppexecHostIdMismatch                               3066
#define kNtErrorIoReissueAsCached                                   3950
#define kNtErrorWinsInternal                                        4000
#define kNtErrorCanNotDelLocalWins                                  4001
#define kNtErrorStaticInit                                          4002
#define kNtErrorIncBackup                                           4003
#define kNtErrorFullBackup                                          4004
#define kNtErrorRecNonExistent                                      4005
#define kNtErrorRplNotAllowed                                       4006
#define kNtErrorDhcpAddressConflict                                 4100
#define kNtErrorWmiGuidNotFound                                     4200
#define kNtErrorWmiInstanceNotFound                                 4201
#define kNtErrorWmiItemidNotFound                                   4202
#define kNtErrorWmiTryAgain                                         4203
#define kNtErrorWmiDpNotFound                                       4204
#define kNtErrorWmiUnresolvedInstanceRef                            4205
#define kNtErrorWmiAlreadyEnabled                                   4206
#define kNtErrorWmiGuidDisconnected                                 4207
#define kNtErrorWmiServerUnavailable                                4208
#define kNtErrorWmiDpFailed                                         4209
#define kNtErrorWmiInvalidMof                                       4210
#define kNtErrorWmiInvalidReginfo                                   4211
#define kNtErrorWmiAlreadyDisabled                                  4212
#define kNtErrorWmiReadOnly                                         4213
#define kNtErrorWmiSetFailure                                       4214
#define kNtErrorNotAppcontainer                                     4250
#define kNtErrorAppcontainerRequired                                4251
#define kNtErrorNotSupportedInAppcontainer                          4252
#define kNtErrorInvalidPackageSidLength                             4253
#define kNtErrorInvalidMedia                                        4300
#define kNtErrorInvalidLibrary                                      4301
#define kNtErrorInvalidMediaPool                                    4302
#define kNtErrorDriveMediaMismatch                                  4303
#define kNtErrorMediaOffline                                        4304
#define kNtErrorLibraryOffline                                      4305
#define kNtErrorEmpty                                               4306 /* ENOMSG */
#define kNtErrorNotEmpty                                            4307
#define kNtErrorMediaUnavailable                                    4308
#define kNtErrorResourceDisabled                                    4309
#define kNtErrorInvalidCleaner                                      4310
#define kNtErrorUnableToClean                                       4311
#define kNtErrorObjectNotFound                                      4312
#define kNtErrorDatabaseFailure                                     4313
#define kNtErrorDatabaseFull                                        4314
#define kNtErrorMediaIncompatible                                   4315
#define kNtErrorResourceNotPresent                                  4316
#define kNtErrorInvalidOperation                                    4317
#define kNtErrorMediaNotAvailable                                   4318
#define kNtErrorDeviceNotAvailable                                  4319
#define kNtErrorRequestRefused                                      4320
#define kNtErrorInvalidDriveObject                                  4321
#define kNtErrorLibraryFull                                         4322
#define kNtErrorMediumNotAccessible                                 4323
#define kNtErrorUnableToLoadMedium                                  4324
#define kNtErrorUnableToInventoryDrive                              4325
#define kNtErrorUnableToInventorySlot                               4326
#define kNtErrorUnableToInventoryTransport                          4327
#define kNtErrorTransportFull                                       4328
#define kNtErrorControllingIeport                                   4329
#define kNtErrorUnableToEjectMountedMedia                           4330
#define kNtErrorCleanerSlotSet                                      4331
#define kNtErrorCleanerSlotNotSet                                   4332
#define kNtErrorCleanerCartridgeSpent                               4333
#define kNtErrorUnexpectedOmid                                      4334
#define kNtErrorCantDeleteLastItem                                  4335
#define kNtErrorMessageExceedsMaxSize                               4336
#define kNtErrorVolumeContainsSysFiles                              4337
#define kNtErrorIndigenousType                                      4338
#define kNtErrorNoSupportingDrives                                  4339
#define kNtErrorCleanerCartridgeInstalled                           4340
#define kNtErrorIeportFull                                          4341
#define kNtErrorFileOffline                                         4350
#define kNtErrorRemoteStorageNotActive                              4351
#define kNtErrorRemoteStorageMediaError                             4352
#define kNtErrorNotAReparsePoint                                    4390
#define kNtErrorReparseAttributeConflict                            4391
#define kNtErrorInvalidReparseData                                  4392
#define kNtErrorReparseTagInvalid                                   4393
#define kNtErrorReparseTagMismatch                                  4394
#define kNtErrorReparsePointEncountered                             4395
#define kNtErrorAppDataNotFound                                     4400
#define kNtErrorAppDataExpired                                      4401
#define kNtErrorAppDataCorrupt                                      4402
#define kNtErrorAppDataLimitExceeded                                4403
#define kNtErrorAppDataRebootRequired                               4404
#define kNtErrorSecurebootRollbackDetected                          4420
#define kNtErrorSecurebootPolicyViolation                           4421
#define kNtErrorSecurebootInvalidPolicy                             4422
#define kNtErrorSecurebootPolicyPublisherNotFound                   4423
#define kNtErrorSecurebootPolicyNotSigned                           4424
#define kNtErrorSecurebootNotEnabled                                4425
#define kNtErrorSecurebootFileReplaced                              4426
#define kNtErrorSecurebootPolicyNotAuthorized                       4427
#define kNtErrorSecurebootPolicyUnknown                             4428
#define kNtErrorSecurebootPolicyMissingAntirollbackversion          4429
#define kNtErrorSecurebootPlatformIdMismatch                        4430
#define kNtErrorSecurebootPolicyRollbackDetected                    4431
#define kNtErrorSecurebootPolicyUpgradeMismatch                     4432
#define kNtErrorSecurebootRequiredPolicyFileMissing                 4433
#define kNtErrorSecurebootNotBasePolicy                             4434
#define kNtErrorSecurebootNotSupplementalPolicy                     4435
#define kNtErrorOffloadReadFltNotSupported                          4440
#define kNtErrorOffloadWriteFltNotSupported                         4441
#define kNtErrorOffloadReadFileNotSupported                         4442
#define kNtErrorOffloadWriteFileNotSupported                        4443
#define kNtErrorAlreadyHasStreamId                                  4444
#define kNtErrorSmrGarbageCollectionRequired                        4445
#define kNtErrorWofWimHeaderCorrupt                                 4446
#define kNtErrorWofWimResourceTableCorrupt                          4447
#define kNtErrorWofFileResourceTableCorrupt                         4448
#define kNtErrorVolumeNotSisEnabled                                 4500
#define kNtErrorSystemIntegrityRollbackDetected                     4550
#define kNtErrorSystemIntegrityPolicyViolation                      4551
#define kNtErrorSystemIntegrityInvalidPolicy                        4552
#define kNtErrorSystemIntegrityPolicyNotSigned                      4553
#define kNtErrorVsmNotInitialized                                   4560
#define kNtErrorVsmDmaProtectionNotInUse                            4561
#define kNtErrorPlatformManifestNotAuthorized                       4570
#define kNtErrorPlatformManifestInvalid                             4571
#define kNtErrorPlatformManifestFileNotAuthorized                   4572
#define kNtErrorPlatformManifestCatalogNotAuthorized                4573
#define kNtErrorPlatformManifestBinaryIdNotFound                    4574
#define kNtErrorPlatformManifestNotActive                           4575
#define kNtErrorPlatformManifestNotSigned                           4576
#define kNtErrorDependentResourceExists                             5001
#define kNtErrorDependencyNotFound                                  5002
#define kNtErrorDependencyAlreadyExists                             5003
#define kNtErrorResourceNotOnline                                   5004
#define kNtErrorHostNodeNotAvailable                                5005
#define kNtErrorResourceNotAvailable                                5006
#define kNtErrorResourceNotFound                                    5007
#define kNtErrorShutdownCluster                                     5008
#define kNtErrorCantEvictActiveNode                                 5009
#define kNtErrorObjectAlreadyExists                                 5010
#define kNtErrorObjectInList                                        5011
#define kNtErrorGroupNotAvailable                                   5012
#define kNtErrorGroupNotFound                                       5013
#define kNtErrorGroupNotOnline                                      5014
#define kNtErrorHostNodeNotResourceOwner                            5015
#define kNtErrorHostNodeNotGroupOwner                               5016
#define kNtErrorResmonCreateFailed                                  5017
#define kNtErrorResmonOnlineFailed                                  5018
#define kNtErrorResourceOnline                                      5019
#define kNtErrorQuorumResource                                      5020
#define kNtErrorNotQuorumCapable                                    5021
#define kNtErrorClusterShuttingDown                                 5022
#define kNtErrorInvalidState                                        5023
#define kNtErrorResourcePropertiesStored                            5024
#define kNtErrorNotQuorumClass                                      5025
#define kNtErrorCoreResource                                        5026
#define kNtErrorQuorumResourceOnlineFailed                          5027
#define kNtErrorQuorumlogOpenFailed                                 5028
#define kNtErrorClusterlogCorrupt                                   5029
#define kNtErrorClusterlogRecordExceedsMaxsize                      5030
#define kNtErrorClusterlogExceedsMaxsize                            5031
#define kNtErrorClusterlogChkpointNotFound                          5032
#define kNtErrorClusterlogNotEnoughSpace                            5033
#define kNtErrorQuorumOwnerAlive                                    5034
#define kNtErrorNetworkNotAvailable                                 5035
#define kNtErrorNodeNotAvailable                                    5036
#define kNtErrorAllNodesNotAvailable                                5037
#define kNtErrorResourceFailed                                      5038
#define kNtErrorClusterInvalidNode                                  5039
#define kNtErrorClusterNodeExists                                   5040
#define kNtErrorClusterJoinInProgress                               5041
#define kNtErrorClusterNodeNotFound                                 5042
#define kNtErrorClusterLocalNodeNotFound                            5043
#define kNtErrorClusterNetworkExists                                5044
#define kNtErrorClusterNetworkNotFound                              5045
#define kNtErrorClusterNetinterfaceExists                           5046
#define kNtErrorClusterNetinterfaceNotFound                         5047
#define kNtErrorClusterInvalidRequest                               5048
#define kNtErrorClusterInvalidNetworkProvider                       5049
#define kNtErrorClusterNodeDown                                     5050
#define kNtErrorClusterNodeUnreachable                              5051
#define kNtErrorClusterNodeNotMember                                5052
#define kNtErrorClusterJoinNotInProgress                            5053
#define kNtErrorClusterInvalidNetwork                               5054
#define kNtErrorClusterNodeUp                                       5056
#define kNtErrorClusterIpaddrInUse                                  5057
#define kNtErrorClusterNodeNotPaused                                5058
#define kNtErrorClusterNoSecurityContext                            5059
#define kNtErrorClusterNetworkNotInternal                           5060
#define kNtErrorClusterNodeAlreadyUp                                5061
#define kNtErrorClusterNodeAlreadyDown                              5062
#define kNtErrorClusterNetworkAlreadyOnline                         5063
#define kNtErrorClusterNetworkAlreadyOffline                        5064
#define kNtErrorClusterNodeAlreadyMember                            5065
#define kNtErrorClusterLastInternalNetwork                          5066
#define kNtErrorClusterNetworkHasDependents                         5067
#define kNtErrorInvalidOperationOnQuorum                            5068
#define kNtErrorDependencyNotAllowed                                5069
#define kNtErrorClusterNodePaused                                   5070
#define kNtErrorNodeCantHostResource                                5071
#define kNtErrorClusterNodeNotReady                                 5072
#define kNtErrorClusterNodeShuttingDown                             5073
#define kNtErrorClusterJoinAborted                                  5074
#define kNtErrorClusterIncompatibleVersions                         5075
#define kNtErrorClusterMaxnumOfResourcesExceeded                    5076
#define kNtErrorClusterSystemConfigChanged                          5077
#define kNtErrorClusterResourceTypeNotFound                         5078
#define kNtErrorClusterRestypeNotSupported                          5079
#define kNtErrorClusterResnameNotFound                              5080
#define kNtErrorClusterNoRpcPackagesRegistered                      5081
#define kNtErrorClusterOwnerNotInPreflist                           5082
#define kNtErrorClusterDatabaseSeqmismatch                          5083
#define kNtErrorResmonInvalidState                                  5084
#define kNtErrorClusterGumNotLocker                                 5085
#define kNtErrorQuorumDiskNotFound                                  5086
#define kNtErrorDatabaseBackupCorrupt                               5087
#define kNtErrorClusterNodeAlreadyHasDfsRoot                        5088
#define kNtErrorResourcePropertyUnchangeable                        5089
#define kNtErrorNoAdminAccessPoint                                  5090
#define kNtErrorClusterMembershipInvalidState                       5890
#define kNtErrorClusterQuorumlogNotFound                            5891
#define kNtErrorClusterMembershipHalt                               5892
#define kNtErrorClusterInstanceIdMismatch                           5893
#define kNtErrorClusterNetworkNotFoundForIp                         5894
#define kNtErrorClusterPropertyDataTypeMismatch                     5895
#define kNtErrorClusterEvictWithoutCleanup                          5896
#define kNtErrorClusterParameterMismatch                            5897
#define kNtErrorNodeCannotBeClustered                               5898
#define kNtErrorClusterWrongOsVersion                               5899
#define kNtErrorClusterCantCreateDupClusterName                     5900
#define kNtErrorCluscfgAlreadyCommitted                             5901
#define kNtErrorCluscfgRollbackFailed                               5902
#define kNtErrorCluscfgSystemDiskDriveLetterConflict                5903
#define kNtErrorClusterOldVersion                                   5904
#define kNtErrorClusterMismatchedComputerAcctName                   5905
#define kNtErrorClusterNoNetAdapters                                5906
#define kNtErrorClusterPoisoned                                     5907
#define kNtErrorClusterGroupMoving                                  5908
#define kNtErrorClusterResourceTypeBusy                             5909
#define kNtErrorResourceCallTimedOut                                5910
#define kNtErrorInvalidClusterIpv6Address                           5911
#define kNtErrorClusterInternalInvalidFunction                      5912
#define kNtErrorClusterParameterOutOfBounds                         5913
#define kNtErrorClusterPartialSend                                  5914
#define kNtErrorClusterRegistryInvalidFunction                      5915
#define kNtErrorClusterInvalidStringTermination                     5916
#define kNtErrorClusterInvalidStringFormat                          5917
#define kNtErrorClusterDatabaseTransactionInProgress                5918
#define kNtErrorClusterDatabaseTransactionNotInProgress             5919
#define kNtErrorClusterNullData                                     5920
#define kNtErrorClusterPartialRead                                  5921
#define kNtErrorClusterPartialWrite                                 5922
#define kNtErrorClusterCantDeserializeData                          5923
#define kNtErrorDependentResourcePropertyConflict                   5924
#define kNtErrorClusterNoQuorum                                     5925
#define kNtErrorClusterInvalidIpv6Network                           5926
#define kNtErrorClusterInvalidIpv6TunnelNetwork                     5927
#define kNtErrorQuorumNotAllowedInThisGroup                         5928
#define kNtErrorDependencyTreeTooComplex                            5929
#define kNtErrorExceptionInResourceCall                             5930
#define kNtErrorClusterRhsFailedInitialization                      5931
#define kNtErrorClusterNotInstalled                                 5932
#define kNtErrorClusterResourcesMustBeOnlineOnTheSameNode           5933
#define kNtErrorClusterMaxNodesInCluster                            5934
#define kNtErrorClusterTooManyNodes                                 5935
#define kNtErrorClusterObjectAlreadyUsed                            5936
#define kNtErrorNoncoreGroupsFound                                  5937
#define kNtErrorFileShareResourceConflict                           5938
#define kNtErrorClusterEvictInvalidRequest                          5939
#define kNtErrorClusterSingletonResource                            5940
#define kNtErrorClusterGroupSingletonResource                       5941
#define kNtErrorClusterResourceProviderFailed                       5942
#define kNtErrorClusterResourceConfigurationError                   5943
#define kNtErrorClusterGroupBusy                                    5944
#define kNtErrorClusterNotSharedVolume                              5945
#define kNtErrorClusterInvalidSecurityDescriptor                    5946
#define kNtErrorClusterSharedVolumesInUse                           5947
#define kNtErrorClusterUseSharedVolumesApi                          5948
#define kNtErrorClusterBackupInProgress                             5949
#define kNtErrorNonCsvPath                                          5950
#define kNtErrorCsvVolumeNotLocal                                   5951
#define kNtErrorClusterWatchdogTerminating                          5952
#define kNtErrorClusterResourceVetoedMoveIncompatibleNodes          5953
#define kNtErrorClusterInvalidNodeWeight                            5954
#define kNtErrorClusterResourceVetoedCall                           5955
#define kNtErrorResmonSystemResourcesLacking                        5956
#define kNtErrorClusterResourceVetoedMoveNotEnoughResourcesOnSource 5958
#define kNtErrorClusterGroupQueued                                  5959
#define kNtErrorClusterResourceLockedStatus                         5960
#define kNtErrorClusterSharedVolumeFailoverNotAllowed               5961
#define kNtErrorClusterNodeDrainInProgress                          5962
#define kNtErrorClusterDiskNotConnected                             5963
#define kNtErrorDiskNotCsvCapable                                   5964
#define kNtErrorResourceNotInAvailableStorage                       5965
#define kNtErrorClusterSharedVolumeRedirected                       5966
#define kNtErrorClusterSharedVolumeNotRedirected                    5967
#define kNtErrorClusterCannotReturnProperties                       5968
#define kNtErrorClusterResourceIsInMaintenanceMode                  5970
#define kNtErrorClusterAffinityConflict                             5971
#define kNtErrorClusterResourceIsReplicaVirtualMachine              5972
#define kNtErrorClusterUpgradeIncompatibleVersions                  5973
#define kNtErrorClusterUpgradeFixQuorumNotSupported                 5974
#define kNtErrorClusterUpgradeRestartRequired                       5975
#define kNtErrorClusterUpgradeInProgress                            5976
#define kNtErrorClusterUpgradeIncomplete                            5977
#define kNtErrorClusterNodeInGracePeriod                            5978
#define kNtErrorClusterCsvIoPauseTimeout                            5979
#define kNtErrorNodeNotActiveClusterMember                          5980
#define kNtErrorClusterResourceNotMonitored                         5981
#define kNtErrorClusterResourceDoesNotSupportUnmonitored            5982
#define kNtErrorClusterResourceIsReplicated                         5983
#define kNtErrorClusterNodeIsolated                                 5984
#define kNtErrorClusterNodeQuarantined                              5985
#define kNtErrorClusterDatabaseUpdateConditionFailed                5986
#define kNtErrorClusterSpaceDegraded                                5987
#define kNtErrorClusterTokenDelegationNotSupported                  5988
#define kNtErrorClusterCsvInvalidHandle                             5989
#define kNtErrorClusterCsvSupportedOnlyOnCoordinator                5990
#define kNtErrorGroupsetNotAvailable                                5991
#define kNtErrorGroupsetNotFound                                    5992
#define kNtErrorGroupsetCantProvide                                 5993
#define kNtErrorClusterFaultDomainParentNotFound                    5994
#define kNtErrorClusterFaultDomainInvalidHierarchy                  5995
#define kNtErrorClusterFaultDomainFailedS2dValidation               5996
#define kNtErrorClusterFaultDomainS2dConnectivityLoss               5997
#define kNtErrorClusterInvalidInfrastructureFileserverName          5998
#define kNtErrorClustersetManagementClusterUnreachable              5999
#define kNtErrorEncryptionFailed                                    6000
#define kNtErrorDecryptionFailed                                    6001
#define kNtErrorFileEncrypted                                       6002
#define kNtErrorNoRecoveryPolicy                                    6003
#define kNtErrorNoEfs                                               6004
#define kNtErrorWrongEfs                                            6005
#define kNtErrorNoUserKeys                                          6006
#define kNtErrorFileNotEncrypted                                    6007
#define kNtErrorNotExportFormat                                     6008
#define kNtErrorFileReadOnly                                        6009 /* EROFS */
#define kNtErrorDirEfsDisallowed                                    6010
#define kNtErrorEfsServerNotTrusted                                 6011
#define kNtErrorBadRecoveryPolicy                                   6012
#define kNtErrorEfsAlgBlobTooBig                                    6013
#define kNtErrorVolumeNotSupportEfs                                 6014
#define kNtErrorEfsDisabled                                         6015
#define kNtErrorEfsVersionNotSupport                                6016
#define kNtErrorCsEncryptionInvalidServerResponse                   6017
#define kNtErrorCsEncryptionUnsupportedServer                       6018
#define kNtErrorCsEncryptionExistingEncryptedFile                   6019
#define kNtErrorCsEncryptionNewEncryptedFile                        6020
#define kNtErrorCsEncryptionFileNotCse                              6021
#define kNtErrorEncryptionPolicyDeniesOperation                     6022
#define kNtErrorNoBrowserServersFound                               6118
#define kNtErrorLogSectorInvalid                                    6600
#define kNtErrorLogSectorParityInvalid                              6601
#define kNtErrorLogSectorRemapped                                   6602
#define kNtErrorLogBlockIncomplete                                  6603
#define kNtErrorLogInvalidRange                                     6604 /* ERANGE */
#define kNtErrorLogBlocksExhausted                                  6605
#define kNtErrorLogReadContextInvalid                               6606
#define kNtErrorLogRestartInvalid                                   6607
#define kNtErrorLogBlockVersion                                     6608
#define kNtErrorLogBlockInvalid                                     6609
#define kNtErrorLogReadModeInvalid                                  6610
#define kNtErrorLogNoRestart                                        6611
#define kNtErrorLogMetadataCorrupt                                  6612
#define kNtErrorLogMetadataInvalid                                  6613
#define kNtErrorLogMetadataInconsistent                             6614
#define kNtErrorLogReservationInvalid                               6615
#define kNtErrorLogCantDelete                                       6616
#define kNtErrorLogContainerLimitExceeded                           6617
#define kNtErrorLogStartOfLog                                       6618
#define kNtErrorLogPolicyAlreadyInstalled                           6619
#define kNtErrorLogPolicyNotInstalled                               6620
#define kNtErrorLogPolicyInvalid                                    6621
#define kNtErrorLogPolicyConflict                                   6622
#define kNtErrorLogPinnedArchiveTail                                6623
#define kNtErrorLogRecordNonexistent                                6624
#define kNtErrorLogRecordsReservedInvalid                           6625
#define kNtErrorLogSpaceReservedInvalid                             6626
#define kNtErrorLogTailInvalid                                      6627
#define kNtErrorLogFull                                             6628
#define kNtErrorCouldNotResizeLog                                   6629
#define kNtErrorLogMultiplexed                                      6630
#define kNtErrorLogDedicated                                        6631
#define kNtErrorLogArchiveNotInProgress                             6632
#define kNtErrorLogArchiveInProgress                                6633
#define kNtErrorLogEphemeral                                        6634
#define kNtErrorLogNotEnoughContainers                              6635
#define kNtErrorLogClientAlreadyRegistered                          6636
#define kNtErrorLogClientNotRegistered                              6637
#define kNtErrorLogFullHandlerInProgress                            6638
#define kNtErrorLogContainerReadFailed                              6639
#define kNtErrorLogContainerWriteFailed                             6640
#define kNtErrorLogContainerOpenFailed                              6641
#define kNtErrorLogContainerStateInvalid                            6642
#define kNtErrorLogStateInvalid                                     6643
#define kNtErrorLogPinned                                           6644
#define kNtErrorLogMetadataFlushFailed                              6645
#define kNtErrorLogInconsistentSecurity                             6646
#define kNtErrorLogAppendedFlushFailed                              6647
#define kNtErrorLogPinnedReservation                                6648
#define kNtErrorInvalidTransaction                                  6700
#define kNtErrorTransactionNotActive                                6701
#define kNtErrorTransactionRequestNotValid                          6702
#define kNtErrorTransactionNotRequested                             6703
#define kNtErrorTransactionAlreadyAborted                           6704
#define kNtErrorTransactionAlreadyCommitted                         6705
#define kNtErrorTmInitializationFailed                              6706
#define kNtErrorResourcemanagerReadOnly                             6707
#define kNtErrorTransactionNotJoined                                6708
#define kNtErrorTransactionSuperiorExists                           6709
#define kNtErrorCrmProtocolAlreadyExists                            6710
#define kNtErrorTransactionPropagationFailed                        6711
#define kNtErrorCrmProtocolNotFound                                 6712
#define kNtErrorTransactionInvalidMarshallBuffer                    6713
#define kNtErrorCurrentTransactionNotValid                          6714
#define kNtErrorTransactionNotFound                                 6715
#define kNtErrorResourcemanagerNotFound                             6716
#define kNtErrorEnlistmentNotFound                                  6717
#define kNtErrorTransactionmanagerNotFound                          6718
#define kNtErrorTransactionmanagerNotOnline                         6719
#define kNtErrorTransactionmanagerRecoveryNameCollision             6720
#define kNtErrorTransactionNotRoot                                  6721
#define kNtErrorTransactionObjectExpired                            6722
#define kNtErrorTransactionResponseNotEnlisted                      6723
#define kNtErrorTransactionRecordTooLong                            6724
#define kNtErrorImplicitTransactionNotSupported                     6725
#define kNtErrorTransactionIntegrityViolated                        6726
#define kNtErrorTransactionmanagerIdentityMismatch                  6727
#define kNtErrorRmCannotBeFrozenForSnapshot                         6728
#define kNtErrorTransactionMustWritethrough                         6729
#define kNtErrorTransactionNoSuperior                               6730
#define kNtErrorHeuristicDamagePossible                             6731
#define kNtErrorTransactionalConflict                               6800
#define kNtErrorRmNotActive                                         6801
#define kNtErrorRmMetadataCorrupt                                   6802
#define kNtErrorDirectoryNotRm                                      6803
#define kNtErrorTransactionsUnsupportedRemote                       6805
#define kNtErrorLogResizeInvalidSize                                6806
#define kNtErrorObjectNoLongerExists                                6807
#define kNtErrorStreamMiniversionNotFound                           6808
#define kNtErrorStreamMiniversionNotValid                           6809
#define kNtErrorMiniversionInaccessibleFromSpecifiedTransaction     6810
#define kNtErrorCantOpenMiniversionWithModifyIntent                 6811
#define kNtErrorCantCreateMoreStreamMiniversions                    6812
#define kNtErrorRemoteFileVersionMismatch                           6814
#define kNtErrorHandleNoLongerValid                                 6815
#define kNtErrorNoTxfMetadata                                       6816
#define kNtErrorLogCorruptionDetected                               6817
#define kNtErrorCantRecoverWithHandleOpen                           6818
#define kNtErrorRmDisconnected                                      6819
#define kNtErrorEnlistmentNotSuperior                               6820
#define kNtErrorRecoveryNotNeeded                                   6821
#define kNtErrorRmAlreadyStarted                                    6822
#define kNtErrorFileIdentityNotPersistent                           6823
#define kNtErrorCantBreakTransactionalDependency                    6824
#define kNtErrorCantCrossRmBoundary                                 6825
#define kNtErrorTxfDirNotEmpty                                      6826
#define kNtErrorIndoubtTransactionsExist                            6827
#define kNtErrorTmVolatile                                          6828
#define kNtErrorRollbackTimerExpired                                6829
#define kNtErrorTxfAttributeCorrupt                                 6830
#define kNtErrorEfsNotAllowedInTransaction                          6831
#define kNtErrorTransactionalOpenNotAllowed                         6832
#define kNtErrorLogGrowthFailed                                     6833
#define kNtErrorTransactedMappingUnsupportedRemote                  6834
#define kNtErrorTxfMetadataAlreadyPresent                           6835
#define kNtErrorTransactionScopeCallbacksNotSet                     6836
#define kNtErrorTransactionRequiredPromotion                        6837
#define kNtErrorCannotExecuteFileInTransaction                      6838
#define kNtErrorTransactionsNotFrozen                               6839
#define kNtErrorTransactionFreezeInProgress                         6840
#define kNtErrorNotSnapshotVolume                                   6841
#define kNtErrorNoSavepointWithOpenFiles                            6842
#define kNtErrorDataLostRepair                                      6843
#define kNtErrorSparseNotAllowedInTransaction                       6844
#define kNtErrorTmIdentityMismatch                                  6845
#define kNtErrorFloatedSection                                      6846
#define kNtErrorCannotAcceptTransactedWork                          6847
#define kNtErrorCannotAbortTransactions                             6848
#define kNtErrorBadClusters                                         6849
#define kNtErrorCompressionNotAllowedInTransaction                  6850
#define kNtErrorVolumeDirty                                         6851
#define kNtErrorNoLinkTrackingInTransaction                         6852
#define kNtErrorOperationNotSupportedInTransaction                  6853
#define kNtErrorExpiredHandle                                       6854
#define kNtErrorTransactionNotEnlisted                              6855
#define kNtErrorCtxWinstationNameInvalid                            7001
#define kNtErrorCtxInvalidPd                                        7002
#define kNtErrorCtxPdNotFound                                       7003
#define kNtErrorCtxWdNotFound                                       7004
#define kNtErrorCtxCannotMakeEventlogEntry                          7005
#define kNtErrorCtxServiceNameCollision                             7006
#define kNtErrorCtxClosePending                                     7007
#define kNtErrorCtxNoOutbuf                                         7008
#define kNtErrorCtxModemInfNotFound                                 7009
#define kNtErrorCtxInvalidModemname                                 7010
#define kNtErrorCtxModemResponseError                               7011
#define kNtErrorCtxModemResponseTimeout                             7012
#define kNtErrorCtxModemResponseNoCarrier                           7013
#define kNtErrorCtxModemResponseNoDialtone                          7014
#define kNtErrorCtxModemResponseBusy                                7015
#define kNtErrorCtxModemResponseVoice                               7016
#define kNtErrorCtxTdError                                          7017
#define kNtErrorCtxWinstationNotFound                               7022
#define kNtErrorCtxWinstationAlreadyExists                          7023
#define kNtErrorCtxWinstationBusy                                   7024
#define kNtErrorCtxBadVideoMode                                     7025
#define kNtErrorCtxGraphicsInvalid                                  7035
#define kNtErrorCtxLogonDisabled                                    7037
#define kNtErrorCtxNotConsole                                       7038
#define kNtErrorCtxClientQueryTimeout                               7040
#define kNtErrorCtxConsoleDisconnect                                7041
#define kNtErrorCtxConsoleConnect                                   7042
#define kNtErrorCtxShadowDenied                                     7044
#define kNtErrorCtxWinstationAccessDenied                           7045
#define kNtErrorCtxInvalidWd                                        7049
#define kNtErrorCtxShadowInvalid                                    7050
#define kNtErrorCtxShadowDisabled                                   7051
#define kNtErrorCtxClientLicenseInUse                               7052
#define kNtErrorCtxClientLicenseNotSet                              7053
#define kNtErrorCtxLicenseNotAvailable                              7054
#define kNtErrorCtxLicenseClientInvalid                             7055
#define kNtErrorCtxLicenseExpired                                   7056
#define kNtErrorCtxShadowNotRunning                                 7057
#define kNtErrorCtxShadowEndedByModeChange                          7058
#define kNtErrorActivationCountExceeded                             7059
#define kNtErrorCtxWinstationsDisabled                              7060
#define kNtErrorCtxEncryptionLevelRequired                          7061
#define kNtErrorCtxSessionInUse                                     7062
#define kNtErrorCtxNoForceLogoff                                    7063
#define kNtErrorCtxAccountRestriction                               7064
#define kNtErrorRdpProtocolError                                    7065 /* EPROTO */
#define kNtErrorCtxCdmConnect                                       7066
#define kNtErrorCtxCdmDisconnect                                    7067
#define kNtErrorCtxSecurityLayerError                               7068
#define kNtErrorTsIncompatibleSessions                              7069
#define kNtErrorTsVideoSubsystemError                               7070
#define kNtErrorDsNotInstalled                                      8200
#define kNtErrorDsMembershipEvaluatedLocally                        8201
#define kNtErrorDsNoAttributeOrValue                                8202
#define kNtErrorDsInvalidAttributeSyntax                            8203
#define kNtErrorDsAttributeTypeUndefined                            8204
#define kNtErrorDsAttributeOrValueExists                            8205
#define kNtErrorDsBusy                                              8206
#define kNtErrorDsUnavailable                                       8207
#define kNtErrorDsNoRidsAllocated                                   8208
#define kNtErrorDsNoMoreRids                                        8209
#define kNtErrorDsIncorrectRoleOwner                                8210
#define kNtErrorDsRidmgrInitError                                   8211
#define kNtErrorDsObjClassViolation                                 8212
#define kNtErrorDsCantOnNonLeaf                                     8213
#define kNtErrorDsCantOnRdn                                         8214
#define kNtErrorDsCantModObjClass                                   8215
#define kNtErrorDsCrossDomMoveError                                 8216
#define kNtErrorDsGcNotAvailable                                    8217
#define kNtErrorSharedPolicy                                        8218
#define kNtErrorPolicyObjectNotFound                                8219
#define kNtErrorPolicyOnlyInDs                                      8220
#define kNtErrorPromotionActive                                     8221
#define kNtErrorNoPromotionActive                                   8222
#define kNtErrorDsOperationsError                                   8224
#define kNtErrorDsProtocolError                                     8225
#define kNtErrorDsTimelimitExceeded                                 8226
#define kNtErrorDsSizelimitExceeded                                 8227
#define kNtErrorDsAdminLimitExceeded                                8228
#define kNtErrorDsCompareFalse                                      8229
#define kNtErrorDsCompareTrue                                       8230
#define kNtErrorDsAuthMethodNotSupported                            8231
#define kNtErrorDsStrongAuthRequired                                8232
#define kNtErrorDsInappropriateAuth                                 8233
#define kNtErrorDsAuthUnknown                                       8234
#define kNtErrorDsReferral                                          8235
#define kNtErrorDsUnavailableCritExtension                          8236
#define kNtErrorDsConfidentialityRequired                           8237
#define kNtErrorDsInappropriateMatching                             8238
#define kNtErrorDsConstraintViolation                               8239
#define kNtErrorDsNoSuchObject                                      8240
#define kNtErrorDsAliasProblem                                      8241
#define kNtErrorDsInvalidDnSyntax                                   8242
#define kNtErrorDsIsLeaf                                            8243
#define kNtErrorDsAliasDerefProblem                                 8244
#define kNtErrorDsUnwillingToPerform                                8245
#define kNtErrorDsLoopDetect                                        8246
#define kNtErrorDsNamingViolation                                   8247
#define kNtErrorDsObjectResultsTooLarge                             8248
#define kNtErrorDsAffectsMultipleDsas                               8249
#define kNtErrorDsServerDown                                        8250
#define kNtErrorDsLocalError                                        8251
#define kNtErrorDsEncodingError                                     8252
#define kNtErrorDsDecodingError                                     8253
#define kNtErrorDsFilterUnknown                                     8254
#define kNtErrorDsParamError                                        8255
#define kNtErrorDsNotSupported                                      8256
#define kNtErrorDsNoResultsReturned                                 8257
#define kNtErrorDsControlNotFound                                   8258
#define kNtErrorDsClientLoop                                        8259
#define kNtErrorDsReferralLimitExceeded                             8260
#define kNtErrorDsSortControlMissing                                8261
#define kNtErrorDsOffsetRangeError                                  8262
#define kNtErrorDsRidmgrDisabled                                    8263
#define kNtErrorDsRootMustBeNc                                      8301
#define kNtErrorDsAddReplicaInhibited                               8302
#define kNtErrorDsAttNotDefInSchema                                 8303
#define kNtErrorDsMaxObjSizeExceeded                                8304
#define kNtErrorDsObjStringNameExists                               8305
#define kNtErrorDsNoRdnDefinedInSchema                              8306
#define kNtErrorDsRdnDoesntMatchSchema                              8307
#define kNtErrorDsNoRequestedAttsFound                              8308
#define kNtErrorDsUserBufferToSmall                                 8309
#define kNtErrorDsAttIsNotOnObj                                     8310
#define kNtErrorDsIllegalModOperation                               8311
#define kNtErrorDsObjTooLarge                                       8312
#define kNtErrorDsBadInstanceType                                   8313
#define kNtErrorDsMasterdsaRequired                                 8314
#define kNtErrorDsObjectClassRequired                               8315
#define kNtErrorDsMissingRequiredAtt                                8316
#define kNtErrorDsAttNotDefForClass                                 8317
#define kNtErrorDsAttAlreadyExists                                  8318
#define kNtErrorDsCantAddAttValues                                  8320
#define kNtErrorDsSingleValueConstraint                             8321
#define kNtErrorDsRangeConstraint                                   8322
#define kNtErrorDsAttValAlreadyExists                               8323
#define kNtErrorDsCantRemMissingAtt                                 8324
#define kNtErrorDsCantRemMissingAttVal                              8325
#define kNtErrorDsRootCantBeSubref                                  8326
#define kNtErrorDsNoChaining                                        8327
#define kNtErrorDsNoChainedEval                                     8328
#define kNtErrorDsNoParentObject                                    8329
#define kNtErrorDsParentIsAnAlias                                   8330
#define kNtErrorDsCantMixMasterAndReps                              8331
#define kNtErrorDsChildrenExist                                     8332
#define kNtErrorDsObjNotFound                                       8333
#define kNtErrorDsAliasedObjMissing                                 8334
#define kNtErrorDsBadNameSyntax                                     8335
#define kNtErrorDsAliasPointsToAlias                                8336
#define kNtErrorDsCantDerefAlias                                    8337
#define kNtErrorDsOutOfScope                                        8338
#define kNtErrorDsObjectBeingRemoved                                8339
#define kNtErrorDsCantDeleteDsaObj                                  8340
#define kNtErrorDsGenericError                                      8341
#define kNtErrorDsDsaMustBeIntMaster                                8342
#define kNtErrorDsClassNotDsa                                       8343
#define kNtErrorDsInsuffAccessRights                                8344
#define kNtErrorDsIllegalSuperior                                   8345
#define kNtErrorDsAttributeOwnedBySam                               8346
#define kNtErrorDsNameTooManyParts                                  8347
#define kNtErrorDsNameTooLong                                       8348
#define kNtErrorDsNameValueTooLong                                  8349
#define kNtErrorDsNameUnparseable                                   8350
#define kNtErrorDsNameTypeUnknown                                   8351
#define kNtErrorDsNotAnObject                                       8352
#define kNtErrorDsSecDescTooShort                                   8353
#define kNtErrorDsSecDescInvalid                                    8354
#define kNtErrorDsNoDeletedName                                     8355
#define kNtErrorDsSubrefMustHaveParent                              8356
#define kNtErrorDsNcnameMustBeNc                                    8357
#define kNtErrorDsCantAddSystemOnly                                 8358
#define kNtErrorDsClassMustBeConcrete                               8359
#define kNtErrorDsInvalidDmd                                        8360
#define kNtErrorDsObjGuidExists                                     8361
#define kNtErrorDsNotOnBacklink                                     8362
#define kNtErrorDsNoCrossrefForNc                                   8363
#define kNtErrorDsShuttingDown                                      8364
#define kNtErrorDsUnknownOperation                                  8365
#define kNtErrorDsInvalidRoleOwner                                  8366
#define kNtErrorDsCouldntContactFsmo                                8367
#define kNtErrorDsCrossNcDnRename                                   8368
#define kNtErrorDsCantModSystemOnly                                 8369
#define kNtErrorDsReplicatorOnly                                    8370
#define kNtErrorDsObjClassNotDefined                                8371
#define kNtErrorDsObjClassNotSubclass                               8372
#define kNtErrorDsNameReferenceInvalid                              8373
#define kNtErrorDsCrossRefExists                                    8374
#define kNtErrorDsCantDelMasterCrossref                             8375
#define kNtErrorDsSubtreeNotifyNotNcHead                            8376
#define kNtErrorDsNotifyFilterTooComplex                            8377
#define kNtErrorDsDupRdn                                            8378
#define kNtErrorDsDupOid                                            8379
#define kNtErrorDsDupMapiId                                         8380
#define kNtErrorDsDupSchemaIdGuid                                   8381
#define kNtErrorDsDupLdapDisplayName                                8382
#define kNtErrorDsSemanticAttTest                                   8383
#define kNtErrorDsSyntaxMismatch                                    8384
#define kNtErrorDsExistsInMustHave                                  8385
#define kNtErrorDsExistsInMayHave                                   8386
#define kNtErrorDsNonexistentMayHave                                8387
#define kNtErrorDsNonexistentMustHave                               8388
#define kNtErrorDsAuxClsTestFail                                    8389
#define kNtErrorDsNonexistentPossSup                                8390
#define kNtErrorDsSubClsTestFail                                    8391
#define kNtErrorDsBadRdnAttIdSyntax                                 8392
#define kNtErrorDsExistsInAuxCls                                    8393
#define kNtErrorDsExistsInSubCls                                    8394
#define kNtErrorDsExistsInPossSup                                   8395
#define kNtErrorDsRecalcschemaFailed                                8396
#define kNtErrorDsTreeDeleteNotFinished                             8397
#define kNtErrorDsCantDelete                                        8398
#define kNtErrorDsAttSchemaReqId                                    8399
#define kNtErrorDsBadAttSchemaSyntax                                8400
#define kNtErrorDsCantCacheAtt                                      8401
#define kNtErrorDsCantCacheClass                                    8402
#define kNtErrorDsCantRemoveAttCache                                8403
#define kNtErrorDsCantRemoveClassCache                              8404
#define kNtErrorDsCantRetrieveDn                                    8405
#define kNtErrorDsMissingSupref                                     8406
#define kNtErrorDsCantRetrieveInstance                              8407
#define kNtErrorDsCodeInconsistency                                 8408
#define kNtErrorDsDatabaseError                                     8409
#define kNtErrorDsGovernsidMissing                                  8410
#define kNtErrorDsMissingExpectedAtt                                8411
#define kNtErrorDsNcnameMissingCrRef                                8412
#define kNtErrorDsSecurityCheckingError                             8413
#define kNtErrorDsSchemaNotLoaded                                   8414
#define kNtErrorDsSchemaAllocFailed                                 8415
#define kNtErrorDsAttSchemaReqSyntax                                8416
#define kNtErrorDsGcverifyError                                     8417
#define kNtErrorDsDraSchemaMismatch                                 8418
#define kNtErrorDsCantFindDsaObj                                    8419
#define kNtErrorDsCantFindExpectedNc                                8420
#define kNtErrorDsCantFindNcInCache                                 8421
#define kNtErrorDsCantRetrieveChild                                 8422
#define kNtErrorDsSecurityIllegalModify                             8423
#define kNtErrorDsCantReplaceHiddenRec                              8424
#define kNtErrorDsBadHierarchyFile                                  8425
#define kNtErrorDsBuildHierarchyTableFailed                         8426
#define kNtErrorDsConfigParamMissing                                8427
#define kNtErrorDsCountingAbIndicesFailed                           8428
#define kNtErrorDsHierarchyTableMallocFailed                        8429
#define kNtErrorDsInternalFailure                                   8430
#define kNtErrorDsUnknownError                                      8431
#define kNtErrorDsRootRequiresClassTop                              8432
#define kNtErrorDsRefusingFsmoRoles                                 8433
#define kNtErrorDsMissingFsmoSettings                               8434
#define kNtErrorDsUnableToSurrenderRoles                            8435
#define kNtErrorDsDraGeneric                                        8436
#define kNtErrorDsDraInvalidParameter                               8437
#define kNtErrorDsDraBusy                                           8438
#define kNtErrorDsDraBadDn                                          8439
#define kNtErrorDsDraBadNc                                          8440
#define kNtErrorDsDraDnExists                                       8441
#define kNtErrorDsDraInternalError                                  8442
#define kNtErrorDsDraInconsistentDit                                8443
#define kNtErrorDsDraConnectionFailed                               8444
#define kNtErrorDsDraBadInstanceType                                8445
#define kNtErrorDsDraOutOfMem                                       8446
#define kNtErrorDsDraMailProblem                                    8447
#define kNtErrorDsDraRefAlreadyExists                               8448
#define kNtErrorDsDraRefNotFound                                    8449
#define kNtErrorDsDraObjIsRepSource                                 8450
#define kNtErrorDsDraDbError                                        8451
#define kNtErrorDsDraNoReplica                                      8452
#define kNtErrorDsDraAccessDenied                                   8453
#define kNtErrorDsDraNotSupported                                   8454
#define kNtErrorDsDraRpcCancelled                                   8455
#define kNtErrorDsDraSourceDisabled                                 8456
#define kNtErrorDsDraSinkDisabled                                   8457
#define kNtErrorDsDraNameCollision                                  8458
#define kNtErrorDsDraSourceReinstalled                              8459
#define kNtErrorDsDraMissingParent                                  8460
#define kNtErrorDsDraPreempted                                      8461
#define kNtErrorDsDraAbandonSync                                    8462
#define kNtErrorDsDraShutdown                                       8463
#define kNtErrorDsDraIncompatiblePartialSet                         8464
#define kNtErrorDsDraSourceIsPartialReplica                         8465
#define kNtErrorDsDraExtnConnectionFailed                           8466
#define kNtErrorDsInstallSchemaMismatch                             8467
#define kNtErrorDsDupLinkId                                         8468
#define kNtErrorDsNameErrorResolving                                8469
#define kNtErrorDsNameErrorNotFound                                 8470
#define kNtErrorDsNameErrorNotUnique                                8471
#define kNtErrorDsNameErrorNoMapping                                8472
#define kNtErrorDsNameErrorDomainOnly                               8473
#define kNtErrorDsNameErrorNoSyntacticalMapping                     8474
#define kNtErrorDsConstructedAttMod                                 8475
#define kNtErrorDsWrongOmObjClass                                   8476
#define kNtErrorDsDraReplPending                                    8477
#define kNtErrorDsDsRequired                                        8478
#define kNtErrorDsInvalidLdapDisplayName                            8479
#define kNtErrorDsNonBaseSearch                                     8480
#define kNtErrorDsCantRetrieveAtts                                  8481
#define kNtErrorDsBacklinkWithoutLink                               8482
#define kNtErrorDsEpochMismatch                                     8483
#define kNtErrorDsSrcNameMismatch                                   8484
#define kNtErrorDsSrcAndDstNcIdentical                              8485
#define kNtErrorDsDstNcMismatch                                     8486
#define kNtErrorDsNotAuthoritiveForDstNc                            8487
#define kNtErrorDsSrcGuidMismatch                                   8488
#define kNtErrorDsCantMoveDeletedObject                             8489
#define kNtErrorDsPdcOperationInProgress                            8490
#define kNtErrorDsCrossDomainCleanupReqd                            8491
#define kNtErrorDsIllegalXdomMoveOperation                          8492
#define kNtErrorDsCantWithAcctGroupMembershps                       8493
#define kNtErrorDsNcMustHaveNcParent                                8494
#define kNtErrorDsCrImpossibleToValidate                            8495
#define kNtErrorDsDstDomainNotNative                                8496
#define kNtErrorDsMissingInfrastructureContainer                    8497
#define kNtErrorDsCantMoveAccountGroup                              8498
#define kNtErrorDsCantMoveResourceGroup                             8499
#define kNtErrorDsInvalidSearchFlag                                 8500
#define kNtErrorDsNoTreeDeleteAboveNc                               8501
#define kNtErrorDsCouldntLockTreeForDelete                          8502
#define kNtErrorDsCouldntIdentifyObjectsForTreeDelete               8503
#define kNtErrorDsSamInitFailure                                    8504
#define kNtErrorDsSensitiveGroupViolation                           8505
#define kNtErrorDsCantModPrimarygroupid                             8506
#define kNtErrorDsIllegalBaseSchemaMod                              8507
#define kNtErrorDsNonsafeSchemaChange                               8508
#define kNtErrorDsSchemaUpdateDisallowed                            8509
#define kNtErrorDsCantCreateUnderSchema                             8510
#define kNtErrorDsInstallNoSrcSchVersion                            8511
#define kNtErrorDsInstallNoSchVersionInInifile                      8512
#define kNtErrorDsInvalidGroupType                                  8513
#define kNtErrorDsNoNestGlobalgroupInMixeddomain                    8514
#define kNtErrorDsNoNestLocalgroupInMixeddomain                     8515
#define kNtErrorDsGlobalCantHaveLocalMember                         8516
#define kNtErrorDsGlobalCantHaveUniversalMember                     8517
#define kNtErrorDsUniversalCantHaveLocalMember                      8518
#define kNtErrorDsGlobalCantHaveCrossdomainMember                   8519
#define kNtErrorDsLocalCantHaveCrossdomainLocalMember               8520
#define kNtErrorDsHavePrimaryMembers                                8521
#define kNtErrorDsStringSdConversionFailed                          8522
#define kNtErrorDsNamingMasterGc                                    8523
#define kNtErrorDsDnsLookupFailure                                  8524
#define kNtErrorDsCouldntUpdateSpns                                 8525
#define kNtErrorDsCantRetrieveSd                                    8526
#define kNtErrorDsKeyNotUnique                                      8527
#define kNtErrorDsWrongLinkedAttSyntax                              8528
#define kNtErrorDsSamNeedBootkeyPassword                            8529
#define kNtErrorDsSamNeedBootkeyFloppy                              8530
#define kNtErrorDsCantStart                                         8531
#define kNtErrorDsInitFailure                                       8532
#define kNtErrorDsNoPktPrivacyOnConnection                          8533
#define kNtErrorDsSourceDomainInForest                              8534
#define kNtErrorDsDestinationDomainNotInForest                      8535
#define kNtErrorDsDestinationAuditingNotEnabled                     8536
#define kNtErrorDsCantFindDcForSrcDomain                            8537
#define kNtErrorDsSrcObjNotGroupOrUser                              8538
#define kNtErrorDsSrcSidExistsInForest                              8539
#define kNtErrorDsSrcAndDstObjectClassMismatch                      8540
#define kNtErrorSamInitFailure                                      8541
#define kNtErrorDsDraSchemaInfoShip                                 8542
#define kNtErrorDsDraSchemaConflict                                 8543
#define kNtErrorDsDraEarlierSchemaConflict                          8544
#define kNtErrorDsDraObjNcMismatch                                  8545
#define kNtErrorDsNcStillHasDsas                                    8546
#define kNtErrorDsGcRequired                                        8547
#define kNtErrorDsLocalMemberOfLocalOnly                            8548
#define kNtErrorDsNoFpoInUniversalGroups                            8549
#define kNtErrorDsCantAddToGc                                       8550
#define kNtErrorDsNoCheckpointWithPdc                               8551
#define kNtErrorDsSourceAuditingNotEnabled                          8552
#define kNtErrorDsCantCreateInNondomainNc                           8553
#define kNtErrorDsInvalidNameForSpn                                 8554
#define kNtErrorDsFilterUsesContructedAttrs                         8555
#define kNtErrorDsUnicodepwdNotInQuotes                             8556
#define kNtErrorDsMachineAccountQuotaExceeded                       8557
#define kNtErrorDsMustBeRunOnDstDc                                  8558
#define kNtErrorDsSrcDcMustBeSp4OrGreater                           8559
#define kNtErrorDsCantTreeDeleteCriticalObj                         8560
#define kNtErrorDsInitFailureConsole                                8561
#define kNtErrorDsSamInitFailureConsole                             8562
#define kNtErrorDsForestVersionTooHigh                              8563
#define kNtErrorDsDomainVersionTooHigh                              8564
#define kNtErrorDsForestVersionTooLow                               8565
#define kNtErrorDsDomainVersionTooLow                               8566
#define kNtErrorDsIncompatibleVersion                               8567
#define kNtErrorDsLowDsaVersion                                     8568
#define kNtErrorDsNoBehaviorVersionInMixeddomain                    8569
#define kNtErrorDsNotSupportedSortOrder                             8570
#define kNtErrorDsNameNotUnique                                     8571
#define kNtErrorDsMachineAccountCreatedPrent4                       8572
#define kNtErrorDsOutOfVersionStore                                 8573
#define kNtErrorDsIncompatibleControlsUsed                          8574
#define kNtErrorDsNoRefDomain                                       8575
#define kNtErrorDsReservedLinkId                                    8576
#define kNtErrorDsLinkIdNotAvailable                                8577
#define kNtErrorDsAgCantHaveUniversalMember                         8578
#define kNtErrorDsModifydnDisallowedByInstanceType                  8579
#define kNtErrorDsNoObjectMoveInSchemaNc                            8580
#define kNtErrorDsModifydnDisallowedByFlag                          8581
#define kNtErrorDsModifydnWrongGrandparent                          8582
#define kNtErrorDsNameErrorTrustReferral                            8583
#define kNtErrorNotSupportedOnStandardServer                        8584
#define kNtErrorDsCantAccessRemotePartOfAd                          8585
#define kNtErrorDsCrImpossibleToValidateV2                          8586
#define kNtErrorDsThreadLimitExceeded                               8587
#define kNtErrorDsNotClosest                                        8588
#define kNtErrorDsCantDeriveSpnWithoutServerRef                     8589
#define kNtErrorDsSingleUserModeFailed                              8590
#define kNtErrorDsNtdscriptSyntaxError                              8591
#define kNtErrorDsNtdscriptProcessError                             8592
#define kNtErrorDsDifferentReplEpochs                               8593
#define kNtErrorDsDrsExtensionsChanged                              8594
#define kNtErrorDsReplicaSetChangeNotAllowedOnDisabledCr            8595
#define kNtErrorDsNoMsdsIntid                                       8596
#define kNtErrorDsDupMsdsIntid                                      8597
#define kNtErrorDsExistsInRdnattid                                  8598
#define kNtErrorDsAuthorizationFailed                               8599
#define kNtErrorDsInvalidScript                                     8600
#define kNtErrorDsRemoteCrossrefOpFailed                            8601
#define kNtErrorDsCrossRefBusy                                      8602
#define kNtErrorDsCantDeriveSpnForDeletedDomain                     8603
#define kNtErrorDsCantDemoteWithWriteableNc                         8604
#define kNtErrorDsDuplicateIdFound                                  8605
#define kNtErrorDsInsufficientAttrToCreateObject                    8606
#define kNtErrorDsGroupConversionError                              8607
#define kNtErrorDsCantMoveAppBasicGroup                             8608
#define kNtErrorDsCantMoveAppQueryGroup                             8609
#define kNtErrorDsRoleNotVerified                                   8610
#define kNtErrorDsWkoContainerCannotBeSpecial                       8611
#define kNtErrorDsDomainRenameInProgress                            8612
#define kNtErrorDsExistingAdChildNc                                 8613
#define kNtErrorDsReplLifetimeExceeded                              8614
#define kNtErrorDsDisallowedInSystemContainer                       8615
#define kNtErrorDsLdapSendQueueFull                                 8616
#define kNtErrorDsDraOutScheduleWindow                              8617
#define kNtErrorDsPolicyNotKnown                                    8618
#define kNtErrorNoSiteSettingsObject                                8619
#define kNtErrorNoSecrets                                           8620
#define kNtErrorNoWritableDcFound                                   8621
#define kNtErrorDsNoServerObject                                    8622
#define kNtErrorDsNoNtdsaObject                                     8623
#define kNtErrorDsNonAsqSearch                                      8624
#define kNtErrorDsAuditFailure                                      8625
#define kNtErrorDsInvalidSearchFlagSubtree                          8626
#define kNtErrorDsInvalidSearchFlagTuple                            8627
#define kNtErrorDsHierarchyTableTooDeep                             8628
#define kNtErrorDsDraCorruptUtdVector                               8629
#define kNtErrorDsDraSecretsDenied                                  8630
#define kNtErrorDsReservedMapiId                                    8631
#define kNtErrorDsMapiIdNotAvailable                                8632
#define kNtErrorDsDraMissingKrbtgtSecret                            8633
#define kNtErrorDsDomainNameExistsInForest                          8634
#define kNtErrorDsFlatNameExistsInForest                            8635
#define kNtErrorInvalidUserPrincipalName                            8636
#define kNtErrorDsOidMappedGroupCantHaveMembers                     8637
#define kNtErrorDsOidNotFound                                       8638
#define kNtErrorDsDraRecycledTarget                                 8639
#define kNtErrorDsDisallowedNcRedirect                              8640
#define kNtErrorDsHighAdldsFfl                                      8641
#define kNtErrorDsHighDsaVersion                                    8642
#define kNtErrorDsLowAdldsFfl                                       8643
#define kNtErrorDomainSidSameAsLocalWorkstation                     8644
#define kNtErrorDsUndeleteSamValidationFailed                       8645
#define kNtErrorIncorrectAccountType                                8646
#define kNtErrorDsSpnValueNotUniqueInForest                         8647
#define kNtErrorDsUpnValueNotUniqueInForest                         8648
#define kNtErrorDsMissingForestTrust                                8649
#define kNtErrorDsValueKeyNotUnique                                 8650
#define kNtErrorIpsecQmPolicyExists                                 13000
#define kNtErrorIpsecQmPolicyNotFound                               13001
#define kNtErrorIpsecQmPolicyInUse                                  13002
#define kNtErrorIpsecMmPolicyExists                                 13003
#define kNtErrorIpsecMmPolicyNotFound                               13004
#define kNtErrorIpsecMmPolicyInUse                                  13005
#define kNtErrorIpsecMmFilterExists                                 13006
#define kNtErrorIpsecMmFilterNotFound                               13007
#define kNtErrorIpsecTransportFilterExists                          13008
#define kNtErrorIpsecTransportFilterNotFound                        13009
#define kNtErrorIpsecMmAuthExists                                   13010
#define kNtErrorIpsecMmAuthNotFound                                 13011
#define kNtErrorIpsecMmAuthInUse                                    13012
#define kNtErrorIpsecDefaultMmPolicyNotFound                        13013
#define kNtErrorIpsecDefaultMmAuthNotFound                          13014
#define kNtErrorIpsecDefaultQmPolicyNotFound                        13015
#define kNtErrorIpsecTunnelFilterExists                             13016
#define kNtErrorIpsecTunnelFilterNotFound                           13017
#define kNtErrorIpsecMmFilterPendingDeletion                        13018
#define kNtErrorIpsecTransportFilterPendingDeletion                 13019
#define kNtErrorIpsecTunnelFilterPendingDeletion                    13020
#define kNtErrorIpsecMmPolicyPendingDeletion                        13021
#define kNtErrorIpsecMmAuthPendingDeletion                          13022
#define kNtErrorIpsecQmPolicyPendingDeletion                        13023
#define kNtErrorIpsecIkeNegStatusBegin                              13800
#define kNtErrorIpsecIkeAuthFail                                    13801
#define kNtErrorIpsecIkeAttribFail                                  13802
#define kNtErrorIpsecIkeNegotiationPending                          13803
#define kNtErrorIpsecIkeGeneralProcessingError                      13804
#define kNtErrorIpsecIkeTimedOut                                    13805
#define kNtErrorIpsecIkeNoCert                                      13806
#define kNtErrorIpsecIkeSaDeleted                                   13807
#define kNtErrorIpsecIkeSaReaped                                    13808
#define kNtErrorIpsecIkeMmAcquireDrop                               13809
#define kNtErrorIpsecIkeQmAcquireDrop                               13810
#define kNtErrorIpsecIkeQueueDropMm                                 13811
#define kNtErrorIpsecIkeQueueDropNoMm                               13812
#define kNtErrorIpsecIkeDropNoResponse                              13813
#define kNtErrorIpsecIkeMmDelayDrop                                 13814
#define kNtErrorIpsecIkeQmDelayDrop                                 13815
#define kNtErrorIpsecIkeError                                       13816
#define kNtErrorIpsecIkeCrlFailed                                   13817
#define kNtErrorIpsecIkeInvalidKeyUsage                             13818
#define kNtErrorIpsecIkeInvalidCertType                             13819
#define kNtErrorIpsecIkeNoPrivateKey                                13820
#define kNtErrorIpsecIkeSimultaneousRekey                           13821
#define kNtErrorIpsecIkeDhFail                                      13822
#define kNtErrorIpsecIkeCriticalPayloadNotRecognized                13823
#define kNtErrorIpsecIkeInvalidHeader                               13824
#define kNtErrorIpsecIkeNoPolicy                                    13825
#define kNtErrorIpsecIkeInvalidSignature                            13826
#define kNtErrorIpsecIkeKerberosError                               13827
#define kNtErrorIpsecIkeNoPublicKey                                 13828
#define kNtErrorIpsecIkeProcessErr                                  13829
#define kNtErrorIpsecIkeProcessErrSa                                13830
#define kNtErrorIpsecIkeProcessErrProp                              13831
#define kNtErrorIpsecIkeProcessErrTrans                             13832
#define kNtErrorIpsecIkeProcessErrKe                                13833
#define kNtErrorIpsecIkeProcessErrId                                13834
#define kNtErrorIpsecIkeProcessErrCert                              13835
#define kNtErrorIpsecIkeProcessErrCertReq                           13836
#define kNtErrorIpsecIkeProcessErrHash                              13837
#define kNtErrorIpsecIkeProcessErrSig                               13838
#define kNtErrorIpsecIkeProcessErrNonce                             13839
#define kNtErrorIpsecIkeProcessErrNotify                            13840
#define kNtErrorIpsecIkeProcessErrDelete                            13841
#define kNtErrorIpsecIkeProcessErrVendor                            13842
#define kNtErrorIpsecIkeInvalidPayload                              13843
#define kNtErrorIpsecIkeLoadSoftSa                                  13844
#define kNtErrorIpsecIkeSoftSaTornDown                              13845
#define kNtErrorIpsecIkeInvalidCookie                               13846
#define kNtErrorIpsecIkeNoPeerCert                                  13847
#define kNtErrorIpsecIkePeerCrlFailed                               13848
#define kNtErrorIpsecIkePolicyChange                                13849
#define kNtErrorIpsecIkeNoMmPolicy                                  13850
#define kNtErrorIpsecIkeNotcbpriv                                   13851
#define kNtErrorIpsecIkeSecloadfail                                 13852
#define kNtErrorIpsecIkeFailsspinit                                 13853
#define kNtErrorIpsecIkeFailqueryssp                                13854
#define kNtErrorIpsecIkeSrvacqfail                                  13855
#define kNtErrorIpsecIkeSrvquerycred                                13856
#define kNtErrorIpsecIkeGetspifail                                  13857
#define kNtErrorIpsecIkeInvalidFilter                               13858
#define kNtErrorIpsecIkeOutOfMemory                                 13859
#define kNtErrorIpsecIkeAddUpdateKeyFailed                          13860
#define kNtErrorIpsecIkeInvalidPolicy                               13861
#define kNtErrorIpsecIkeUnknownDoi                                  13862
#define kNtErrorIpsecIkeInvalidSituation                            13863
#define kNtErrorIpsecIkeDhFailure                                   13864
#define kNtErrorIpsecIkeInvalidGroup                                13865
#define kNtErrorIpsecIkeEncrypt                                     13866
#define kNtErrorIpsecIkeDecrypt                                     13867
#define kNtErrorIpsecIkePolicyMatch                                 13868
#define kNtErrorIpsecIkeUnsupportedId                               13869
#define kNtErrorIpsecIkeInvalidHash                                 13870
#define kNtErrorIpsecIkeInvalidHashAlg                              13871
#define kNtErrorIpsecIkeInvalidHashSize                             13872
#define kNtErrorIpsecIkeInvalidEncryptAlg                           13873
#define kNtErrorIpsecIkeInvalidAuthAlg                              13874
#define kNtErrorIpsecIkeInvalidSig                                  13875
#define kNtErrorIpsecIkeLoadFailed                                  13876
#define kNtErrorIpsecIkeRpcDelete                                   13877
#define kNtErrorIpsecIkeBenignReinit                                13878
#define kNtErrorIpsecIkeInvalidResponderLifetimeNotify              13879
#define kNtErrorIpsecIkeInvalidMajorVersion                         13880
#define kNtErrorIpsecIkeInvalidCertKeylen                           13881
#define kNtErrorIpsecIkeMmLimit                                     13882
#define kNtErrorIpsecIkeNegotiationDisabled                         13883
#define kNtErrorIpsecIkeQmLimit                                     13884
#define kNtErrorIpsecIkeMmExpired                                   13885
#define kNtErrorIpsecIkePeerMmAssumedInvalid                        13886
#define kNtErrorIpsecIkeCertChainPolicyMismatch                     13887
#define kNtErrorIpsecIkeUnexpectedMessageId                         13888
#define kNtErrorIpsecIkeInvalidAuthPayload                          13889
#define kNtErrorIpsecIkeDosCookieSent                               13890
#define kNtErrorIpsecIkeShuttingDown                                13891
#define kNtErrorIpsecIkeCgaAuthFailed                               13892
#define kNtErrorIpsecIkeProcessErrNatoa                             13893
#define kNtErrorIpsecIkeInvalidMmForQm                              13894
#define kNtErrorIpsecIkeQmExpired                                   13895
#define kNtErrorIpsecIkeTooManyFilters                              13896
#define kNtErrorIpsecIkeNegStatusEnd                                13897
#define kNtErrorIpsecIkeKillDummyNapTunnel                          13898
#define kNtErrorIpsecIkeInnerIpAssignmentFailure                    13899
#define kNtErrorIpsecIkeRequireCpPayloadMissing                     13900
#define kNtErrorIpsecKeyModuleImpersonationNegotiationPending       13901
#define kNtErrorIpsecIkeCoexistenceSuppress                         13902
#define kNtErrorIpsecIkeRatelimitDrop                               13903
#define kNtErrorIpsecIkePeerDoesntSupportMobike                     13904
#define kNtErrorIpsecIkeAuthorizationFailure                        13905
#define kNtErrorIpsecIkeStrongCredAuthorizationFailure              13906
#define kNtErrorIpsecIkeAuthorizationFailureWithOptionalRetry       13907
#define kNtErrorIpsecIkeStrongCredAuthorizationAndCertmapFailure    13908
#define kNtErrorIpsecIkeNegStatusExtendedEnd                        13909
#define kNtErrorIpsecBadSpi                                         13910
#define kNtErrorIpsecSaLifetimeExpired                              13911
#define kNtErrorIpsecWrongSa                                        13912
#define kNtErrorIpsecReplayCheckFailed                              13913
#define kNtErrorIpsecInvalidPacket                                  13914
#define kNtErrorIpsecIntegrityCheckFailed                           13915
#define kNtErrorIpsecClearTextDrop                                  13916
#define kNtErrorIpsecAuthFirewallDrop                               13917
#define kNtErrorIpsecThrottleDrop                                   13918
#define kNtErrorIpsecDospBlock                                      13925
#define kNtErrorIpsecDospReceivedMulticast                          13926
#define kNtErrorIpsecDospInvalidPacket                              13927
#define kNtErrorIpsecDospStateLookupFailed                          13928
#define kNtErrorIpsecDospMaxEntries                                 13929
#define kNtErrorIpsecDospKeymodNotAllowed                           13930
#define kNtErrorIpsecDospNotInstalled                               13931
#define kNtErrorIpsecDospMaxPerIpRatelimitQueues                    13932
#define kNtErrorSxsSectionNotFound                                  14000
#define kNtErrorSxsCantGenActctx                                    14001
#define kNtErrorSxsInvalidActctxdataFormat                          14002
#define kNtErrorSxsAssemblyNotFound                                 14003
#define kNtErrorSxsManifestFormatError                              14004
#define kNtErrorSxsManifestParseError                               14005
#define kNtErrorSxsActivationContextDisabled                        14006
#define kNtErrorSxsKeyNotFound                                      14007
#define kNtErrorSxsVersionConflict                                  14008
#define kNtErrorSxsWrongSectionType                                 14009
#define kNtErrorSxsThreadQueriesDisabled                            14010
#define kNtErrorSxsProcessDefaultAlreadySet                         14011
#define kNtErrorSxsUnknownEncodingGroup                             14012
#define kNtErrorSxsUnknownEncoding                                  14013
#define kNtErrorSxsInvalidXmlNamespaceUri                           14014
#define kNtErrorSxsRootManifestDependencyNotInstalled               14015
#define kNtErrorSxsLeafManifestDependencyNotInstalled               14016
#define kNtErrorSxsInvalidAssemblyIdentityAttribute                 14017
#define kNtErrorSxsManifestMissingRequiredDefaultNamespace          14018
#define kNtErrorSxsManifestInvalidRequiredDefaultNamespace          14019
#define kNtErrorSxsPrivateManifestCrossPathWithReparsePoint         14020
#define kNtErrorSxsDuplicateDllName                                 14021
#define kNtErrorSxsDuplicateWindowclassName                         14022
#define kNtErrorSxsDuplicateClsid                                   14023
#define kNtErrorSxsDuplicateIid                                     14024
#define kNtErrorSxsDuplicateTlbid                                   14025
#define kNtErrorSxsDuplicateProgid                                  14026
#define kNtErrorSxsDuplicateAssemblyName                            14027
#define kNtErrorSxsFileHashMismatch                                 14028
#define kNtErrorSxsPolicyParseError                                 14029
#define kNtErrorSxsXmlEMissingquote                                 14030
#define kNtErrorSxsXmlECommentsyntax                                14031
#define kNtErrorSxsXmlEBadstartnamechar                             14032
#define kNtErrorSxsXmlEBadnamechar                                  14033
#define kNtErrorSxsXmlEBadcharinstring                              14034
#define kNtErrorSxsXmlEXmldeclsyntax                                14035
#define kNtErrorSxsXmlEBadchardata                                  14036
#define kNtErrorSxsXmlEMissingwhitespace                            14037
#define kNtErrorSxsXmlEExpectingtagend                              14038
#define kNtErrorSxsXmlEMissingsemicolon                             14039
#define kNtErrorSxsXmlEUnbalancedparen                              14040
#define kNtErrorSxsXmlEInternalerror                                14041
#define kNtErrorSxsXmlEUnexpectedWhitespace                         14042
#define kNtErrorSxsXmlEIncompleteEncoding                           14043
#define kNtErrorSxsXmlEMissingParen                                 14044
#define kNtErrorSxsXmlEExpectingclosequote                          14045
#define kNtErrorSxsXmlEMultipleColons                               14046
#define kNtErrorSxsXmlEInvalidDecimal                               14047
#define kNtErrorSxsXmlEInvalidHexidecimal                           14048
#define kNtErrorSxsXmlEInvalidUnicode                               14049
#define kNtErrorSxsXmlEWhitespaceorquestionmark                     14050
#define kNtErrorSxsXmlEUnexpectedendtag                             14051
#define kNtErrorSxsXmlEUnclosedtag                                  14052
#define kNtErrorSxsXmlEDuplicateattribute                           14053
#define kNtErrorSxsXmlEMultipleroots                                14054
#define kNtErrorSxsXmlEInvalidatrootlevel                           14055
#define kNtErrorSxsXmlEBadxmldecl                                   14056
#define kNtErrorSxsXmlEMissingroot                                  14057
#define kNtErrorSxsXmlEUnexpectedeof                                14058
#define kNtErrorSxsXmlEBadperefinsubset                             14059
#define kNtErrorSxsXmlEUnclosedstarttag                             14060
#define kNtErrorSxsXmlEUnclosedendtag                               14061
#define kNtErrorSxsXmlEUnclosedstring                               14062
#define kNtErrorSxsXmlEUnclosedcomment                              14063
#define kNtErrorSxsXmlEUncloseddecl                                 14064
#define kNtErrorSxsXmlEUnclosedcdata                                14065
#define kNtErrorSxsXmlEReservednamespace                            14066
#define kNtErrorSxsXmlEInvalidencoding                              14067
#define kNtErrorSxsXmlEInvalidswitch                                14068
#define kNtErrorSxsXmlEBadxmlcase                                   14069
#define kNtErrorSxsXmlEInvalidStandalone                            14070
#define kNtErrorSxsXmlEUnexpectedStandalone                         14071
#define kNtErrorSxsXmlEInvalidVersion                               14072
#define kNtErrorSxsXmlEMissingequals                                14073
#define kNtErrorSxsProtectionRecoveryFailed                         14074
#define kNtErrorSxsProtectionPublicKeyTooShort                      14075
#define kNtErrorSxsProtectionCatalogNotValid                        14076
#define kNtErrorSxsUntranslatableHresult                            14077
#define kNtErrorSxsProtectionCatalogFileMissing                     14078
#define kNtErrorSxsMissingAssemblyIdentityAttribute                 14079
#define kNtErrorSxsInvalidAssemblyIdentityAttributeName             14080
#define kNtErrorSxsAssemblyMissing                                  14081
#define kNtErrorSxsCorruptActivationStack                           14082
#define kNtErrorSxsCorruption                                       14083
#define kNtErrorSxsEarlyDeactivation                                14084
#define kNtErrorSxsInvalidDeactivation                              14085
#define kNtErrorSxsMultipleDeactivation                             14086
#define kNtErrorSxsProcessTerminationRequested                      14087
#define kNtErrorSxsReleaseActivationContext                         14088
#define kNtErrorSxsSystemDefaultActivationContextEmpty              14089
#define kNtErrorSxsInvalidIdentityAttributeValue                    14090
#define kNtErrorSxsInvalidIdentityAttributeName                     14091
#define kNtErrorSxsIdentityDuplicateAttribute                       14092
#define kNtErrorSxsIdentityParseError                               14093
#define kNtErrorMalformedSubstitutionString                         14094
#define kNtErrorSxsIncorrectPublicKeyToken                          14095
#define kNtErrorUnmappedSubstitutionString                          14096
#define kNtErrorSxsAssemblyNotLocked                                14097
#define kNtErrorSxsComponentStoreCorrupt                            14098
#define kNtErrorAdvancedInstallerFailed                             14099
#define kNtErrorXmlEncodingMismatch                                 14100
#define kNtErrorSxsManifestIdentitySameButContentsDifferent         14101
#define kNtErrorSxsIdentitiesDifferent                              14102
#define kNtErrorSxsAssemblyIsNotADeployment                         14103
#define kNtErrorSxsFileNotPartOfAssembly                            14104
#define kNtErrorSxsManifestTooBig                                   14105
#define kNtErrorSxsSettingNotRegistered                             14106
#define kNtErrorSxsTransactionClosureIncomplete                     14107
#define kNtErrorSmiPrimitiveInstallerFailed                         14108
#define kNtErrorGenericCommandFailed                                14109
#define kNtErrorSxsFileHashMissing                                  14110
#define kNtErrorEvtInvalidChannelPath                               15000
#define kNtErrorEvtInvalidQuery                                     15001
#define kNtErrorEvtPublisherMetadataNotFound                        15002
#define kNtErrorEvtEventTemplateNotFound                            15003
#define kNtErrorEvtInvalidPublisherName                             15004
#define kNtErrorEvtInvalidEventData                                 15005
#define kNtErrorEvtChannelNotFound                                  15007
#define kNtErrorEvtMalformedXmlText                                 15008
#define kNtErrorEvtSubscriptionToDirectChannel                      15009
#define kNtErrorEvtConfigurationError                               15010
#define kNtErrorEvtQueryResultStale                                 15011
#define kNtErrorEvtQueryResultInvalidPosition                       15012
#define kNtErrorEvtNonValidatingMsxml                               15013
#define kNtErrorEvtFilterAlreadyscoped                              15014
#define kNtErrorEvtFilterNoteltset                                  15015
#define kNtErrorEvtFilterInvarg                                     15016
#define kNtErrorEvtFilterInvtest                                    15017
#define kNtErrorEvtFilterInvtype                                    15018
#define kNtErrorEvtFilterParseerr                                   15019
#define kNtErrorEvtFilterUnsupportedop                              15020
#define kNtErrorEvtFilterUnexpectedtoken                            15021
#define kNtErrorEvtInvalidOperationOverEnabledDirectChannel         15022
#define kNtErrorEvtInvalidChannelPropertyValue                      15023
#define kNtErrorEvtInvalidPublisherPropertyValue                    15024
#define kNtErrorEvtChannelCannotActivate                            15025
#define kNtErrorEvtFilterTooComplex                                 15026
#define kNtErrorEvtMessageNotFound                                  15027
#define kNtErrorEvtMessageIdNotFound                                15028
#define kNtErrorEvtUnresolvedValueInsert                            15029
#define kNtErrorEvtUnresolvedParameterInsert                        15030
#define kNtErrorEvtMaxInsertsReached                                15031
#define kNtErrorEvtEventDefinitionNotFound                          15032
#define kNtErrorEvtMessageLocaleNotFound                            15033
#define kNtErrorEvtVersionTooOld                                    15034
#define kNtErrorEvtVersionTooNew                                    15035
#define kNtErrorEvtCannotOpenChannelOfQuery                         15036
#define kNtErrorEvtPublisherDisabled                                15037
#define kNtErrorEvtFilterOutOfRange                                 15038
#define kNtErrorEcSubscriptionCannotActivate                        15080
#define kNtErrorEcLogDisabled                                       15081
#define kNtErrorEcCircularForwarding                                15082
#define kNtErrorEcCredstoreFull                                     15083
#define kNtErrorEcCredNotFound                                      15084
#define kNtErrorEcNoActiveChannel                                   15085
#define kNtErrorMuiFileNotFound                                     15100
#define kNtErrorMuiInvalidFile                                      15101
#define kNtErrorMuiInvalidRcConfig                                  15102
#define kNtErrorMuiInvalidLocaleName                                15103
#define kNtErrorMuiInvalidUltimatefallbackName                      15104
#define kNtErrorMuiFileNotLoaded                                    15105
#define kNtErrorResourceEnumUserStop                                15106
#define kNtErrorMuiIntlsettingsUilangNotInstalled                   15107
#define kNtErrorMuiIntlsettingsInvalidLocaleName                    15108
#define kNtErrorMrmRuntimeNoDefaultOrNeutralResource                15110
#define kNtErrorMrmInvalidPriconfig                                 15111
#define kNtErrorMrmInvalidFileType                                  15112
#define kNtErrorMrmUnknownQualifier                                 15113
#define kNtErrorMrmInvalidQualifierValue                            15114
#define kNtErrorMrmNoCandidate                                      15115
#define kNtErrorMrmNoMatchOrDefaultCandidate                        15116
#define kNtErrorMrmResourceTypeMismatch                             15117
#define kNtErrorMrmDuplicateMapName                                 15118
#define kNtErrorMrmDuplicateEntry                                   15119
#define kNtErrorMrmInvalidResourceIdentifier                        15120
#define kNtErrorMrmFilepathTooLong                                  15121
#define kNtErrorMrmUnsupportedDirectoryType                         15122
#define kNtErrorMrmInvalidPriFile                                   15126
#define kNtErrorMrmNamedResourceNotFound                            15127
#define kNtErrorMrmMapNotFound                                      15135
#define kNtErrorMrmUnsupportedProfileType                           15136
#define kNtErrorMrmInvalidQualifierOperator                         15137
#define kNtErrorMrmIndeterminateQualifierValue                      15138
#define kNtErrorMrmAutomergeEnabled                                 15139
#define kNtErrorMrmTooManyResources                                 15140
#define kNtErrorMrmUnsupportedFileTypeForMerge                      15141
#define kNtErrorMrmUnsupportedFileTypeForLoadUnloadPriFile          15142
#define kNtErrorMrmNoCurrentViewOnThread                            15143
#define kNtErrorDifferentProfileResourceManagerExist                15144
#define kNtErrorOperationNotAllowedFromSystemComponent              15145
#define kNtErrorMrmDirectRefToNonDefaultResource                    15146
#define kNtErrorMrmGenerationCountMismatch                          15147
#define kNtErrorPriMergeVersionMismatch                             15148
#define kNtErrorPriMergeMissingSchema                               15149
#define kNtErrorPriMergeLoadFileFailed                              15150
#define kNtErrorPriMergeAddFileFailed                               15151
#define kNtErrorPriMergeWriteFileFailed                             15152
#define kNtErrorPriMergeMultiplePackageFamiliesNotAllowed           15153
#define kNtErrorPriMergeMultipleMainPackagesNotAllowed              15154
#define kNtErrorPriMergeBundlePackagesNotAllowed                    15155
#define kNtErrorPriMergeMainPackageRequired                         15156
#define kNtErrorPriMergeResourcePackageRequired                     15157
#define kNtErrorPriMergeInvalidFileName                             15158
#define kNtErrorMcaInvalidCapabilitiesString                        15200
#define kNtErrorMcaInvalidVcpVersion                                15201
#define kNtErrorMcaMonitorViolatesMccsSpecification                 15202
#define kNtErrorMcaMccsVersionMismatch                              15203
#define kNtErrorMcaUnsupportedMccsVersion                           15204
#define kNtErrorMcaInternalError                                    15205
#define kNtErrorMcaInvalidTechnologyTypeReturned                    15206
#define kNtErrorMcaUnsupportedColorTemperature                      15207
#define kNtErrorAmbiguousSystemDevice                               15250
#define kNtErrorSystemDeviceNotFound                                15299
#define kNtErrorHashNotSupported                                    15300
#define kNtErrorHashNotPresent                                      15301
#define kNtErrorSecondaryIcProviderNotRegistered                    15321
#define kNtErrorGpioClientInformationInvalid                        15322
#define kNtErrorGpioVersionNotSupported                             15323
#define kNtErrorGpioInvalidRegistrationPacket                       15324
#define kNtErrorGpioOperationDenied                                 15325
#define kNtErrorGpioIncompatibleConnectMode                         15326
#define kNtErrorGpioInterruptAlreadyUnmasked                        15327
#define kNtErrorCannotSwitchRunlevel                                15400
#define kNtErrorInvalidRunlevelSetting                              15401
#define kNtErrorRunlevelSwitchTimeout                               15402
#define kNtErrorRunlevelSwitchAgentTimeout                          15403
#define kNtErrorRunlevelSwitchInProgress                            15404
#define kNtErrorServicesFailedAutostart                             15405
#define kNtErrorComTaskStopPending                                  15501
#define kNtErrorInstallOpenPackageFailed                            15600
#define kNtErrorInstallPackageNotFound                              15601
#define kNtErrorInstallInvalidPackage                               15602
#define kNtErrorInstallResolveDependencyFailed                      15603
#define kNtErrorInstallOutOfDiskSpace                               15604
#define kNtErrorInstallNetworkFailure                               15605
#define kNtErrorInstallRegistrationFailure                          15606
#define kNtErrorInstallDeregistrationFailure                        15607
#define kNtErrorInstallCancel                                       15608
#define kNtErrorInstallFailed                                       15609
#define kNtErrorRemoveFailed                                        15610
#define kNtErrorPackageAlreadyExists                                15611
#define kNtErrorNeedsRemediation                                    15612
#define kNtErrorInstallPrerequisiteFailed                           15613
#define kNtErrorPackageRepositoryCorrupted                          15614
#define kNtErrorInstallPolicyFailure                                15615
#define kNtErrorPackageUpdating                                     15616
#define kNtErrorDeploymentBlockedByPolicy                           15617
#define kNtErrorPackagesInUse                                       15618
#define kNtErrorRecoveryFileCorrupt                                 15619
#define kNtErrorInvalidStagedSignature                              15620
#define kNtErrorDeletingExistingApplicationdataStoreFailed          15621
#define kNtErrorInstallPackageDowngrade                             15622
#define kNtErrorSystemNeedsRemediation                              15623
#define kNtErrorAppxIntegrityFailureClrNgen                         15624
#define kNtErrorResiliencyFileCorrupt                               15625
#define kNtErrorInstallFirewallServiceNotRunning                    15626
#define kNtErrorPackageMoveFailed                                   15627
#define kNtErrorInstallVolumeNotEmpty                               15628
#define kNtErrorInstallVolumeOffline                                15629
#define kNtErrorInstallVolumeCorrupt                                15630
#define kNtErrorNeedsRegistration                                   15631
#define kNtErrorInstallWrongProcessorArchitecture                   15632
#define kNtErrorDevSideloadLimitExceeded                            15633
#define kNtErrorInstallOptionalPackageRequiresMainPackage           15634
#define kNtErrorPackageNotSupportedOnFilesystem                     15635
#define kNtErrorPackageMoveBlockedByStreaming                       15636
#define kNtErrorInstallOptionalPackageApplicationidNotUnique        15637
#define kNtErrorPackageStagingOnhold                                15638
#define kNtErrorInstallInvalidRelatedSetUpdate                      15639
#define kNtErrorPackagesReputationCheckFailed                       15643
#define kNtErrorPackagesReputationCheckTimedout                     15644
#define kNtErrorStateLoadStoreFailed                                15800
#define kNtErrorStateGetVersionFailed                               15801
#define kNtErrorStateSetVersionFailed                               15802
#define kNtErrorStateStructuredResetFailed                          15803
#define kNtErrorStateOpenContainerFailed                            15804
#define kNtErrorStateCreateContainerFailed                          15805
#define kNtErrorStateDeleteContainerFailed                          15806
#define kNtErrorStateReadSettingFailed                              15807
#define kNtErrorStateWriteSettingFailed                             15808
#define kNtErrorStateDeleteSettingFailed                            15809
#define kNtErrorStateQuerySettingFailed                             15810
#define kNtErrorStateReadCompositeSettingFailed                     15811
#define kNtErrorStateWriteCompositeSettingFailed                    15812
#define kNtErrorStateEnumerateContainerFailed                       15813
#define kNtErrorStateEnumerateSettingsFailed                        15814
#define kNtErrorStateCompositeSettingValueSizeLimitExceeded         15815
#define kNtErrorStateSettingValueSizeLimitExceeded                  15816
#define kNtErrorStateSettingNameSizeLimitExceeded                   15817
#define kNtErrorStateContainerNameSizeLimitExceeded                 15818
#define kNtErrorApiUnavailable                                      15841 /* EPROCUNAVAIL */

#define kNtWaitIoCompletion 0xc0

/* WinSock Error Codes: 10000-11999 */
#define WSABASEERR                  10000
#define WSAEINTR                    10004
#define WSAEBADF                    10009
#define WSAEACCES                   10013
#define WSAEFAULT                   10014
#define WSAEINVAL                   10022
#define WSAEMFILE                   10024
#define WSAEWOULDBLOCK              10035
#define WSAEINPROGRESS              10036
#define WSAEALREADY                 10037
#define WSAENOTSOCK                 10038
#define WSAEDESTADDRREQ             10039
#define WSAEMSGSIZE                 10040
#define WSAEPROTOTYPE               10041
#define WSAENOPROTOOPT              10042
#define WSAEPROTONOSUPPORT          10043
#define WSAESOCKTNOSUPPORT          10044
#define WSAEOPNOTSUPP               10045
#define WSAEPFNOSUPPORT             10046
#define WSAEAFNOSUPPORT             10047
#define WSAEADDRINUSE               10048
#define WSAEADDRNOTAVAIL            10049
#define WSAENETDOWN                 10050
#define WSAENETUNREACH              10051
#define WSAENETRESET                10052
#define WSAECONNABORTED             10053
#define WSAECONNRESET               10054
#define WSAENOBUFS                  10055
#define WSAEISCONN                  10056
#define WSAENOTCONN                 10057
#define WSAESHUTDOWN                10058
#define WSAETOOMANYREFS             10059
#define WSAETIMEDOUT                10060
#define WSAECONNREFUSED             10061
#define WSAELOOP                    10062
#define WSAENAMETOOLONG             10063
#define WSAEHOSTDOWN                10064
#define WSAEHOSTUNREACH             10065
#define WSAENOTEMPTY                10066
#define WSAEPROCLIM                 10067
#define WSAEUSERS                   10068
#define WSAEDQUOT                   10069
#define WSAESTALE                   10070
#define WSAEREMOTE                  10071
#define WSASYSNOTREADY              10091
#define WSAVERNOTSUPPORTED          10092
#define WSANOTINITIALISED           10093
#define WSAEDISCON                  10101
#define WSAENOMORE                  10102
#define WSAECANCELLED               10103
#define WSAEINVALIDPROCTABLE        10104
#define WSAEINVALIDPROVIDER         10105
#define WSAEPROVIDERFAILEDINIT      10106
#define WSASYSCALLFAILURE           10107
#define WSASERVICE_NOT_FOUND        10108
#define WSATYPE_NOT_FOUND           10109
#define WSA_E_NO_MORE               10110
#define WSA_E_CANCELLED             10111
#define WSAEREFUSED                 10112
#define WSAHOST_NOT_FOUND           11001
#define WSATRY_AGAIN                11002
#define WSANO_RECOVERY              11003
#define WSANO_DATA                  11004
#define WSA_QOS_RECEIVERS           11005
#define WSA_QOS_SENDERS             11006
#define WSA_QOS_NO_SENDERS          11007
#define WSA_QOS_NO_RECEIVERS        11008
#define WSA_QOS_REQUEST_CONFIRMED   11009
#define WSA_QOS_ADMISSION_FAILURE   11010
#define WSA_QOS_POLICY_FAILURE      11011
#define WSA_QOS_BAD_STYLE           11012
#define WSA_QOS_BAD_OBJECT          11013
#define WSA_QOS_TRAFFIC_CTRL_ERROR  11014
#define WSA_QOS_GENERIC_ERROR       11015
#define WSA_QOS_ESERVICETYPE        11016
#define WSA_QOS_EFLOWSPEC           11017
#define WSA_QOS_EPROVSPECBUF        11018
#define WSA_QOS_EFILTERSTYLE        11019
#define WSA_QOS_EFILTERTYPE         11020
#define WSA_QOS_EFILTERCOUNT        11021
#define WSA_QOS_EOBJLENGTH          11022
#define WSA_QOS_EFLOWCOUNT          11023
#define WSA_QOS_EUNKOWNPSOBJ        11024
#define WSA_QOS_EPOLICYOBJ          11025
#define WSA_QOS_EFLOWDESC           11026
#define WSA_QOS_EPSFLOWSPEC         11027
#define WSA_QOS_EPSFILTERSPEC       11028
#define WSA_QOS_ESDMODEOBJ          11029
#define WSA_QOS_ESHAPERATEOBJ       11030
#define WSA_QOS_RESERVED_PETYPE     11031
#define WSA_SECURE_HOST_NOT_FOUND   11032
#define WSA_IPSEC_NAME_POLICY_ERROR 11033

#define WSA_WAIT_FAILED         -1u
#define WSA_WAIT_EVENT_0        0
#define WSA_WAIT_IO_COMPLETION  0xc0
#define WSA_WAIT_TIMEOUT        258
#define WSA_MAXIMUM_WAIT_EVENTS 64
#define WSA_IO_PENDING          997


#define kNtWsaInvalidHandle    kNtErrorInvalidHandle
#define kNtWsaNotEnoughMemory  kNtErrorNotEnoughMemory
#define kNtWsaInvalidParameter kNtErrorInvalidParameter
#define kNtWsaIoPending        kNtErrorIoPending
#define kNtWsaIoIncomplete     kNtErrorIoIncomplete
#define kNtWsaOperationAborted kNtErrorOperationAborted



/*!BEGIN libc/nt/enum/wsaid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSAID_H_
COSMOPOLITAN_C_START_

#define WSAID_WSAPOLL                                \
  {                                                  \
    0x18C76F85, 0xDC66, 0x4964, {                    \
      0x97, 0x2E, 0x23, 0xC2, 0x72, 0x38, 0x31, 0x2B \
    }                                                \
  }

#define WSAID_WSARECVMSG                             \
  {                                                  \
    0xf689d7c8, 0x6f1f, 0x436b, {                    \
      0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22 \
    }                                                \
  }

#define WSAID_WSASENDMSG                             \
  {                                                  \
    0xa441e712, 0x754f, 0x43ca, {                    \
      0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d \
    }                                                \
  }

#define WSAID_CONNECTEX                              \
  {                                                  \
    0x25a207b9, 0xddf3, 0x4660, {                    \
      0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e \
    }                                                \
  }

#define WSAID_ACCEPTEX                               \
  {                                                  \
    0xb5367df1, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_GETACCEPTEXSOCKADDRS                   \
  {                                                  \
    0xb5367df2, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITFILE                           \
  {                                                  \
    0xb5367df0, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITPACKETS                        \
  {                                                  \
    0xd9689da0, 0x1f90, 0x11d3, {                    \
      0x99, 0x71, 0x00, 0xc0, 0x4f, 0x68, 0xc8, 0x76 \
    }                                                \
  }

#define WSAID_DISCONNECTEX                           \
  {                                                  \
    0x7fda2e11, 0x8630, 0x436f, {                    \
      0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57 \
    }                                                \
  }

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/wt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WT_H_

#define kNtWtExecutedefault            0x00000000u
#define kNtWtExecuteonlyonce           0x00000008u
#define kNtWtExecuteintimerthread      0x00000020u
#define kNtWtExecuteinpersistentthread 0x00000080u
#define kNtWtExecutelongfunction       0x00000010u
#define kNtWtTransferImpersonation     0𝔵00000100𝔲



/*!BEGIN libc/nt/struct/acl.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ACL_H_

struct NtAcl {
  uint8_t AclRevision;
  uint8_t Sbz1;
  uint16_t AclSize;
  uint16_t AceCount;
  uint16_t Sbz2;
};



/*!BEGIN libc/nt/struct/afd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_AFD_H_
COSMOPOLITAN_C_START_

struct NtAfdPollHandleInfo {
  int64_t Handle;
  uint32_t Events;
  NtStatus Status;
};

struct NtAfdPollInfo {
  int64_t Timeout;
  uint32_t NumberOfHandles;
  uint32_t Exclusive;
  struct NtAfdPollHandleInfo Handles[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ansistring.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ANSISTRING_H_

struct NtAnsiString {
  unsigned short Length;
  unsigned short MaximumLength;
  char *Buffer;
};



/*!BEGIN libc/nt/struct/byhandlefileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_BYHANDLEFILEINFORMATION_H_


/*!BEGIN libc/nt/struct/filetime.h */

#define COSMOPOLITAN_LIBC_NT_FILETIME_H_

struct NtFileTime {
  uint32_t dwLowDateTime;
  uint32_t dwHighDateTime;
};


struct NtByHandleFileInformation {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationFileTime;
  struct NtFileTime ftLastAccessFileTime;
  struct NtFileTime ftLastWriteFileTime;
  uint32_t dwVolumeSerialNumber;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t nNumberOfLinks;
  uint32_t nFileIndexHigh;
  uint32_t nFileIndexLow;
};



/*!BEGIN libc/nt/struct/charinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CHARINFO_H_

struct NtCharInfo {
  union {
    char16_t UnicodeChar;
    char AsciiChar;
  } Char;
  uint16_t Attributes;
};



/*!BEGIN libc/nt/struct/clientid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CLIENTID_H_

struct NtClientId {
  void *UniqueProcess;
  void *UniqueThread;
};



/*!BEGIN libc/nt/struct/consolecursorinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLECURSORINFO_H_

struct NtConsoleCursorInfo {
  uint32_t dwSize;
  bool32 bVisible;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFO_H_


/*!BEGIN libc/nt/struct/coord.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COORD_H_

struct NtCoord {
  int16_t X;
  int16_t Y;
};



/*!BEGIN libc/nt/struct/smallrect.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SMALLRECT_H_

struct NtSmallRect {
  int16_t Left;
  int16_t Top;
  int16_t Right;
  int16_t Bottom;
};


struct NtConsoleScreenBufferInfo {
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes;
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFOEX_H_

struct NtConsoleScreenBufferInfoEx {
  uint32_t cbSize; /* sizeof(struct NtConsoleScreenBufferInfoEx) */
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes; /* kNt{Foreground,Background}... */
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
  uint16_t wPopupAttributes;
  bool32 bFullscreenSupported;
  uint32_t ColorTable[16]; /* 0x00BBGGRR */
};



/*!BEGIN libc/nt/struct/consoleselectioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESELECTIONINFO_H_

struct NtConsoleSelectionInfo {
  uint32_t dwFlags;
  struct NtCoord dwSelectionAnchor;
  struct NtSmallRect srSelection;
};



/*!BEGIN libc/nt/struct/context.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONTEXT_H_

struct NtM128A {
  uint64_t Low;
  int64_t High;
};

struct NtXmmSaveArea32 { /* basically same as struct FpuState */
  uint16_t ControlWord;
  uint16_t StatusWord;
  uint8_t TagWord;
  uint8_t Reserved1;
  uint16_t ErrorOpcode;
  uint32_t ErrorOffset;
  uint16_t ErrorSelector;
  uint16_t Reserved2;
  uint32_t DataOffset;
  uint16_t DataSelector;
  uint16_t Reserved3;
  uint32_t MxCsr;
  uint32_t MxCsr_Mask;
  struct NtM128A FloatRegisters[8];
  struct NtM128A XmmRegisters[16];
  uint8_t Reserved4[96];
};

struct NtContext {
  uint64_t P1Home, P2Home, P3Home, P4Home, P5Home, P6Home;
  uint32_t ContextFlags;
  uint32_t MxCsr;
  uint16_t SegCs, SegDs, SegEs, SegFs, SegGs, SegSs;
  uint32_t EFlags;
  uint64_t Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
  uint64_t Rax, Rcx, Rdx, Rbx, Rsp, Rbp, Rsi, Rdi;
  uint64_t R8, R9, R10, R11, R12, R13, R14, R15;
  uint64_t Rip;
  union {
    struct NtXmmSaveArea32 FltSave;
    struct NtXmmSaveArea32 FloatSave;
    struct {
      struct NtM128A Header[2];
      struct NtM128A Legacy[8];
      struct NtM128A Xmm0, Xmm1, Xmm2, Xmm3, Xmm4, Xmm5, Xmm6, Xmm7;
      struct NtM128A Xmm8, Xmm9, Xmm10, Xmm11, Xmm12, Xmm13, Xmm14, Xmm15;
    };
  };
  struct NtM128A VectorRegister[26];
  uint64_t VectorControl;
  uint64_t DebugControl;
  uint64_t LastBranchToRip;
  uint64_t LastBranchFromRip;
  uint64_t LastExceptionToRip;
  uint64_t LastExceptionFromRip;
} forcealign(16);



/*!BEGIN libc/nt/struct/criticalsection.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTION_H_


/*!BEGIN libc/nt/struct/criticalsectiondebug.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTIONDEBUG_H_


/*!BEGIN libc/nt/struct/linkedlist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINKEDLIST_H_

/**
 * Dynamic linked list overlay.
 */
struct NtLinkedList {
  struct NtLinkedList *Next;
  struct NtLinkedList *Prev;
};


struct NtCriticalSectionDebug {
  uint16_t Type;
  uint16_t CreatorBackTraceIndex;
  struct NtCriticalSection *CriticalSection;
  struct NtLinkedList ProcessLocksList;
  uint32_t EntryCount;
  uint32_t ContentionCount;
  uint32_t Spare[2];
};


struct NtCriticalSection {
  struct NtCriticalSectionDebug *DebugInfo;
  int32_t LockCount;
  int32_t RecursionCount;
  void *OwningThread;
  void *LockSemaphore;
  uintptr_t SpinCount;
};



/*!BEGIN libc/nt/struct/drawtextparams.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DRAWTEXTPARAMS_H_
COSMOPOLITAN_C_START_

struct NtDrawTextParams {
  uint32_t cbSize;
  int32_t iTabLength;
  int32_t iLeftMargin;
  int32_t iRightMargin;
  uint32_t uiLengthDrawn;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/dynamictimezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DYNAMICTIMEZONEINFORMATION_H_


/*!BEGIN libc/nt/struct/systemtime.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIME_H_

struct NtSystemTime {
  uint16_t wYear;
  uint16_t wMonth;
  uint16_t wDayOfWeek;
  uint16_t wDay;
  uint16_t wHour;
  uint16_t wMinute;
  uint16_t wSecond;
  uint16_t wMilliseconds;
};


struct NtDynamicTimeZoneInformation {
  int32_t Bias;
  char16_t StandardName[32];
  struct NtSystemTime StandardDate;
  int32_t StandardBias;
  char16_t DaylightName[32];
  struct NtSystemTime DaylightDate;
  int32_t DaylightBias;
  char16_t TimeZoneKeyName[128];
  bool32 DynamicDaylightTimeDisabled;
};



/*!BEGIN libc/nt/struct/editmenu.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EDITMENU_H_

struct NtEditMenu {
  int64_t hmenu;
  uint16_t idEdit;
  uint16_t idCut;
  uint16_t idCopy;
  uint16_t idPaste;
  uint16_t idClear;
  uint16_t idUndo;
};



/*!BEGIN libc/nt/struct/exceptionframe.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EXCEPTIONFRAME_H_

struct NtExceptionFrame {
  struct NtExceptionFrame *Prev;
};



/*!BEGIN libc/nt/struct/fdset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FDSET_H_
COSMOPOLITAN_C_START_

struct NtFdSet {
  uint32_t fd_count;
  int64_t fd_array[64];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/fileaccessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEACCESSINFORMATION_H_

struct NtFileAccessInformation {
  uint32_t AccessFlags;
};



/*!BEGIN libc/nt/struct/filealignmentinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALIGNMENTINFORMATION_H_

struct NtFileAlignmentInformation {
  uint32_t AlignmentRequirement;
};



/*!BEGIN libc/nt/struct/fileallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLINFORMATION_H_


/*!BEGIN libc/nt/struct/filebasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFORMATION_H_

struct NtFileBasicInformation {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/fileeainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEEAINFORMATION_H_

struct NtFileEaInformation {
  uint32_t EaSize;
};



/*!BEGIN libc/nt/struct/fileinternalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEINTERNALINFORMATION_H_

struct NtFileInternalInformation {
  int64_t IndexNumber;
};



/*!BEGIN libc/nt/struct/filemodeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMODEINFORMATION_H_

struct NtFileModeInformation {
  uint32_t Mode;
};



/*!BEGIN libc/nt/struct/filenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMEINFORMATION_H_

struct NtFileNameInformation {
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filepositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPOSITIONINFORMATION_H_

struct NtFilePositionInformation {
  int64_t CurrentByteOffset;
};



/*!BEGIN libc/nt/struct/filestandardinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTANDARDINFORMATION_H_

struct NtFileStandardInformation {
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t NumberOfLinks;
  bool32 DeletePending;
  bool32 Directory;
};


struct NtFileAllInformation {
  struct NtFileBasicInformation BasicInformation;
  struct NtFileStandardInformation StandardInformation;
  struct NtFileInternalInformation InternalInformation;
  struct NtFileEaInformation EaInformation;
  struct NtFileAccessInformation AccessInformation;
  struct NtFilePositionInformation PositionInformation;
  struct NtFileModeInformation ModeInformation;
  struct NtFileAlignmentInformation AlignmentInformation;
  struct NtFileNameInformation NameInformation;
};



/*!BEGIN libc/nt/struct/fileallocationinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLOCATIONINFORMATION_H_

struct NtFileAllocationInformation {
  int64_t AllocationSize;
};



/*!BEGIN libc/nt/struct/fileattributetaginformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEATTRIBUTETAGINFORMATION_H_

struct NtFileAttributeTagInformation {
  uint32_t FileAttributes;
  uint32_t ReparseTag;
};



/*!BEGIN libc/nt/struct/filebasicinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFO_H_

struct NtFileBasicInfo {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/filebothdirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBOTHDIRECTORYINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileBothDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  unsigned char ShortNameLength;
  char16_t ShortName[12];
  char16_t FileName[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filecompressioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILECOMPRESSIONINFO_H_

struct NtFileCompressionInfo {
  int64_t CompressedFileSize;
  uint16_t CompressionFormat;
  uint8_t CompressionUnitShift;
  uint8_t ChunkShift;
  uint8_t ClusterShift;
  uint8_t Reserved[3];
};



/*!BEGIN libc/nt/struct/filedirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDIRECTORYINFORMATION_H_

struct NtFileDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filedispositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDISPOSITIONINFORMATION_H_

struct NtFileDispositionInformation {
  bool32 DoDeleteFile;
};



/*!BEGIN libc/nt/struct/fileendoffileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEENDOFFILEINFORMATION_H_

struct FileEndOfFileInformation {
  int64_t EndOfFile;
};



/*!BEGIN libc/nt/struct/filefsfullsizeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFSFULLSIZEINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileFsFullSizeInformation {
  int64_t TotalAllocationUnits;
  int64_t CallerAvailableAllocationUnits;
  int64_t ActualAvailableAllocationUnits;
  uint32_t SectorsPerAllocationUnit;
  uint32_t BytesPerSector;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filefulldirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLDIRECTORYINFORMATION_H_

struct NtFileFullDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filefulleainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLEAINFORMATION_H_

struct NtFileFullEaInformation {
  uint32_t NextEntryOffset;
  uint8_t Flags;
  uint8_t EaNameLength;
  uint16_t EaValueLength;
  char EaName[1];
};



/*!BEGIN libc/nt/struct/filemailslotqueryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTQUERYINFORMATION_H_

struct NtFileMailslotQueryInformation {
  uint32_t MaximumMessageSize;
  uint32_t MailslotQuota;
  uint32_t NextMessageSize;
  uint32_t MessagesAvailable;
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filemailslotsetinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTSETINFORMATION_H_

struct NtFileMailslotSetInformation {
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filenamesinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMESINFORMATION_H_

struct NtFileNamesInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filenetworkopeninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENETWORKOPENINFORMATION_H_

struct NtFileNetworkOpenInformation {
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t FileAttributes;
};



/*!BEGIN libc/nt/struct/filepipelocalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPIPELOCALINFORMATION_H_

struct NtFilePipeLocalInformation {
  uint32_t NamedPipeType;
  uint32_t NamedPipeConfiguration;
  uint32_t MaximumInstances;
  uint32_t CurrentInstances;
  uint32_t InboundQuota;
  uint32_t ReadDataAvailable;
  uint32_t OutboundQuota;
  uint32_t WriteQuotaAvailable;
  uint32_t NamedPipeState;
  uint32_t NamedPipeEnd;
};



/*!BEGIN libc/nt/struct/filerenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILERENAMEINFORMATION_H_

struct NtFileRenameInformation {
  bool32 Replace;
  void *RootDir;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filesegmentelement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESEGMENTELEMENT_H_

union NtFileSegmentElement {
  void *Buffer;
  uint64_t Alignment;
};



/*!BEGIN libc/nt/struct/filestreaminformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTREAMINFORMATION_H_

struct NtFileStreamInformation {
  uint32_t NextEntryOffset;
  uint32_t StreamNameLength;
  int64_t StreamSize;
  int64_t StreamAllocationSize;
  char16_t StreamName[1];
};



/*!BEGIN libc/nt/struct/filezerodatainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEZERODATAINFORMATION_H_

struct NtFileZeroDataInformation {
  uint64_t FileOffset;
  uint64_t BeyondFinalZero;
};



/*!BEGIN libc/nt/struct/fpodata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FPODATA_H_

struct NtFpoData {
  /* TODO(jart): No bitfields. */
  uint32_t ulOffStart;
  uint32_t cbProcSize;
  uint32_t cdwLocals;
  uint16_t cdwParams;
  uint16_t cbProlog : 8;
  uint16_t cbRegs : 3;
  uint16_t fHasSEH : 1;
  uint16_t fUseBP : 1;
  uint16_t reserved : 1;
  uint16_t cbFrame : 2;
};



/*!BEGIN libc/nt/struct/genericmapping.h */

#define COSMOPOLITAN_LIBC_NT_GENERICMAPPING_H_

struct NtGenericMapping {
  unsigned int GenericRead;
  unsigned int GenericWrite;
  unsigned int GenericExecute;
  unsigned int GenericAll;
};



/*!BEGIN libc/nt/struct/guid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_GUID_H_
COSMOPOLITAN_C_START_

struct NtGuid {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/inputrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_INPUTRECORD_H_

struct NtKeyEventRecord {
  bool32 bKeyDown;
  uint16_t wRepeatCount;
  uint16_t wVirtualKeyCode;
  uint16_t wVirtualScanCode;
  union {
    uint16_t UnicodeChar;
    char AsciiChar;
  } uChar;
  unsigned int dwControlKeyState;
#define kNtRightAltPressed  0x0001
#define kNtLeftAltPressed   0x0002
#define kNtRightCtrlPressed 0x0004
#define kNtLeftCtrlPressed  0x0008
#define kNtShiftPressed     0x0010
#define kNtNumlockOn        0x0020
#define kNtScrolllockOn     0x0040
#define kNtCapslockOn       0x0080
#define kNtEnhancedKey      0x0100
};

struct NtMouseEventRecord {
  struct NtCoord dwMousePosition;
  uint32_t dwButtonState;
#define kNtFromLeft1stButtonPressed 0x0001
#define kNtRightmostButtonPressed   0x0002
#define kNtFromLeft2ndButtonPressed 0x0004
#define kNtFromLeft3rdButtonPressed 0x0008
#define kNtFromLeft4thButtonPressed 0x0010
  uint32_t dwControlKeyState;
  uint32_t dwEventFlags;
#define kNtMouseMoved    0x0001
#define kNtDoubleClick   0x0002
#define kNtMouseWheeled  0x0004
#define kNtMouseHwheeled 0x0008
};

struct NtWindowBufferSizeRecord {
  struct NtCoord dwSize;
};

struct NtMenuEventRecord {
  uint32_t dwCommandId;
};

struct NtFocusEventRecord {
  bool32 bSetFocus;
};

struct NtInputRecord {
  uint16_t EventType;
#define kNtKeyEvent              0x0001
#define kNtMouseEvent            0x0002
#define kNtWindowBufferSizeEvent 0x0004
#define kNtMenuEvent             0x0008
#define kNtFocusEvent            0x0010
  union {
    struct NtKeyEventRecord KeyEvent;
    struct NtMouseEventRecord MouseEvent;
    struct NtWindowBufferSizeRecord WindowBufferSizeEvent;
    struct NtMenuEventRecord MenuEvent;
    struct NtFocusEventRecord FocusEvent;
  } Event;
};



/*!BEGIN libc/nt/struct/iocounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOCOUNTERS_H_

struct NtIoCounters {
  uint64_t ReadOperationCount;
  uint64_t WriteOperationCount;
  uint64_t OtherOperationCount;
  uint64_t ReadTransferCount;
  uint64_t WriteTransferCount;
  uint64_t OtherTransferCount;
};



/*!BEGIN libc/nt/struct/iostatusblock.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOSTATUSBLOCK_H_

struct NtIoStatusBlock {
  union {
    NtStatus Status;
    void *Pointer; /* reserved for internal use */
  };
  uint32_t *Information; /* request dependent */
};



/*!BEGIN libc/nt/struct/iovec.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct NtIovec {
  uint32_t len;
  char *buf;
};

void DescribeIovNt(const struct NtIovec *, uint32_t, ssize_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ipadapteraddresses.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IP_ADAPTER_ADDRESSES_H_


/*!BEGIN libc/nt/winsock.h */

#define COSMOPOLITAN_LIBC_NT_WINSOCK_H_


/*!BEGIN libc/nt/struct/overlapped.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPED_H_

struct NtOverlapped {
  uintptr_t Internal;
  uintptr_t InternalHigh;
  union {
    struct {
      uint32_t Offset;
      uint32_t OffsetHigh;
    };
    int64_t Pointer;
  };
  int64_t hEvent;
};



/*!BEGIN libc/nt/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POLLFD_H_

struct sys_pollfd_nt {
  int64_t handle;
  int16_t events;
  int16_t revents;
};



/*!BEGIN libc/nt/struct/timeval.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEVAL_H_
COSMOPOLITAN_C_START_

struct NtTimeval {
  int32_t tv_sec; /* [sic] */
  int32_t tv_usec;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thunk/msabi.h */

#define COSMOPOLITAN_LIBC_NT_THUNK_MSABI_H_
#ifdef __x86_64__

#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
     (__has_attribute(__ms_abi__) || defined(__llvm__)))
/**
 * Defines function as using Microsoft x64 calling convention.
 *
 * This can be used to define prototypes that allow modern compilers to
 * generate code that calls MS ABI functions directly, without needing
 * to jump through the assembly thunks.
 */
#define __msabi __attribute__((__ms_abi__))
#endif

/*
 * Returns true if header should provide MS-ABI overrides.
 */
#ifndef ShouldUseMsabiAttribute
#if defined(__msabi) && defined(NDEBUG) && !defined(__PG__) && !defined(FTRACE)
#define ShouldUseMsabiAttribute() 1
#else
#define ShouldUseMsabiAttribute() 0
#endif
#endif

#else
#define __msabi
#ifndef ShouldUseMsabiAttribute
#define ShouldUseMsabiAttribute() 0
#endif
#endif /* __x86_64__ */


/*!BEGIN libc/sock/sock.h */

#define COSMOPOLITAN_LIBC_SOCK_SOCK_H_
COSMOPOLITAN_C_START_

#define INET_ADDRSTRLEN 22
#define IFHWADDRLEN     6

libcesque uint16_t htons(uint16_t) pureconst;
libcesque uint16_t ntohs(uint16_t) pureconst;
libcesque uint32_t htonl(uint32_t) pureconst;
libcesque uint32_t ntohl(uint32_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define htons(x) __builtin_bswap16(x)
#define ntohs(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define ntohl(x) __builtin_bswap32(x)
#endif

const char *inet_ntop(int, const void *, char *, uint32_t) libcesque;
int inet_pton(int, const char *, void *) libcesque;
uint32_t inet_addr(const char *) libcesque;
libcesque uint32_t *GetHostIps(void) __wur;

int socket(int, int, int) libcesque;
int listen(int, int) libcesque;
int shutdown(int, int) libcesque;
ssize_t send(int, const void *, size_t, int) libcesque;
ssize_t recv(int, void *, size_t, int) libcesque;
ssize_t sendfile(int, int, int64_t *, size_t) libcesque;
int getsockopt(int, int, int, void *, uint32_t *) libcesque;
int setsockopt(int, int, int, const void *, uint32_t) libcesque;
int socketpair(int, int, int, int[2]) libcesque;
int sockatmark(int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/sockaddr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_H_
COSMOPOLITAN_C_START_

struct sockaddr {     /* Linux+NT ABI */
  uint16_t sa_family; /* AF_XXX */
  char sa_data[14];
};

struct in_addr { /* ARPA ABI */
  /* e.g. 127|0<<8|0<<16|1<<24 or inet_pton(AF_INET, "127.0.0.1", &s_addr) */
  uint32_t s_addr;
};

struct sockaddr_in {   /* Linux+NT ABI */
  uint16_t sin_family; /* AF_XXX */
  uint16_t sin_port;   /* htons(XXX) i.e. big endian */
  struct in_addr sin_addr;
  uint8_t sin_zero[8];
};

struct sockaddr_un {
  uint16_t sun_family; /* AF_UNIX */
  char sun_path[108];  /* path */
};

struct sockaddr_storage {
  union {
    uint16_t ss_family;
    intptr_t __ss_align;
    char __ss_storage[128];
  };
};

int inet_aton(const char *, struct in_addr *);
char *inet_ntoa(struct in_addr);
int accept(int, struct sockaddr *, uint32_t *);
int accept4(int, struct sockaddr *, uint32_t *, int);
int bind(int, const struct sockaddr *, uint32_t);
int connect(int, const struct sockaddr *, uint32_t);
int getsockname(int, struct sockaddr *, uint32_t *);
int getpeername(int, struct sockaddr *, uint32_t *);
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, uint32_t *);
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
               uint32_t);

COSMOPOLITAN_C_END_
/* ░▓█████████████████████████████████████████████▓▒
   ░█▓░░░░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒░
   ░█▓░ ░▒▒▒▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░ ░▓▓▓▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░       ░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒▒
   ░███████████████████████████████████████████████▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░          ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░             ▒█▓▒▒
   ░█▓░        ░▒░                 ▒█▓░          ▒█▓▒▒
   ░█▓░      ░░░░    ░░░░░░░░      ▒▓▓▓▒░        ▒█▓▒▒
   ░█▓░    ░░░░  ░░░░░▒▒▓███▓░░░░░░░░▒▓▓▓▓▒      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒████▓░░░░░░░░░░▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒▓▓▓▓▓░░░░░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▒▒▒░░░░░ ░▒▒▒▒░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓   ░▓█▓▒▒▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░░▒██▓   ░████▓▒░
   ░█▓░     ░░░░░░░░▒▒░░░░░░░░░▒▒░░░▒▒▓▓▒░░    ░░▓███▓▒░
   ░█▓░      ░░░░░░░░░░░░░░░░░░░░░░▒▓▓▓▒░        ▒████▓▒░░░░░░
   ░█▓░        ░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░        ░▓▓▓▓██▒░░░░░░░░
   ░█▓░          ▒█████████████████▒  ▓█▓▒░      ▒█▓ ░█▓      ░▓▓░
   ░█▓░                              ░▓████▒░    ▒█▓▒░  ░░░░░░░  ▓█▓░
   ░█▓░                                ░▓████▒░  ░▒░  ░░░░░░░░░░░  ░█▓
   ░█▓                                    ▒███▓▒▒░  ░░░░░░░░░░░░░░░  ▒▓▓
   ░██████████████████████████████████████▓▒▓█▓░  ░░░░░░░░░░░░░░░░░░ ▒█▓
    ▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░ ░░░░░░░░░░░░░░░░░░░░▒█▓
         ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒██▒▒▒░░░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░██▒▒▒▒▒░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░▒▓█▓
                                            ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░▒▒▒▒▓▓▒
                                              ░██▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  ░█▓
                                                 ▒█▓▒▒▒▒▒▒▒▒▒▒▒██▓▒░ ░█▓
                                                   ▒█████████████▓▒▒░  ░██▒
╔────────────────────────────────────────────────────────────────▀▀▀▀───▀▀▀▀─│─╗
│ cosmopolitan § new technology » winsock                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtWsaFlagOverlapped      0x01
#define kNtWsaFlagNoHandleInherit 0x80

#define kNtCompEqual   0
#define kNtCompNotless 1

#define kNtTfDisconnect       0x01
#define kNtTfReuseSocket      0x02
#define kNtTfWriteBehind      0x04
#define kNtTfUseDefaultWorker 0x00
#define kNtTfUseSystemThread  0x10
#define kNtTfUseKernelApc     0x20

#define kNtSoConnectTime          0x700C
#define kNtSoUpdateAcceptContext  0x700B
#define kNtSoUpdateConnectContext 0x7010

#define kNtNspNotifyImmediately 0
#define kNtNspNotifyHwnd        1
#define kNtNspNotifyEvent       2
#define kNtNspNotifyPort        3
#define kNtNspNotifyApc         4

COSMOPOLITAN_C_START_

struct NtMsgHdr {
  struct sockaddr *name;
  int32_t namelen;
  struct NtIovec *lpBuffers;
  uint32_t dwBufferCount;
  struct NtIovec Control;
  uint32_t dwFlags;
};

struct NtWsaData {
  uint16_t wVersion;
  uint16_t wHighVersion;
  uint16_t iMaxSockets;
  uint16_t iMaxUdpDg;
  char *lpVendorInfo;
  char szDescription[257];
  char szSystemStatus[129];
};

struct NtSocketAddress {
  struct sockaddr *lpSockaddr;
  int32_t iSockaddrLength;
};

struct NtSocketAddressList {
  int32_t iAddressCount;
  struct NtSocketAddress Address[1];
};

struct NtAddrInfoEx {  /* win8+ */
  int32_t ai_flags;    /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
  int32_t ai_family;   /* PF_XXX */
  int32_t ai_socktype; /* SOCK_XXX */
  int32_t ai_protocol;
  uint64_t ai_addrlen;
  char16_t *ai_canonname;
  struct sockaddr *ai_addr;
  void *ai_blob;
  uint64_t ai_bloblen;
  struct NtGuid *ai_provider;
  struct NtAddrInfoEx *ai_next;
  int32_t ai_version;          /* v2 */
  char16_t *ai_fqdn;           /* v2 */
  int32_t ai_interfaceindex;   /* v3 */
  int64_t ai_resolutionhandle; /* v4 */
};

struct NtWsaProtocolChain {
  int32_t ChainLen;
  uint32_t ChainEntries[7];
};

struct NtWsaProtocolInfo {
  uint32_t dwServiceFlags1;
  uint32_t dwServiceFlags2;
  uint32_t dwServiceFlags3;
  uint32_t dwServiceFlags4;
  uint32_t dwProviderFlags;
  struct NtGuid ProviderId;
  uint32_t dwCatalogEntryId;
  struct NtWsaProtocolChain ProtocolChain;
  int32_t iVersion;
  int32_t iAddressFamily;
  int32_t iMaxSockAddr;
  int32_t iMinSockAddr;
  int32_t iSocketType;
  int32_t iProtocol;
  int32_t iProtocolMaxOffset;
  int32_t iNetworkByteOrder;
  int32_t iSecurityScheme;
  uint32_t dwMessageSize;
  uint32_t dwProviderReserved;
  char16_t szProtocol[256];
};

struct NtFlowSpec {
  uint32_t TokenRate;          /* bytes/sec */
  uint32_t TokenBucketSize;    /* bytes */
  uint32_t PeakBandwidth;      /* bytes/sec */
  uint32_t Latency;            /* µs */
  uint32_t DelayVariation;     /* µs */
  uint32_t ServiceType;        /* kNtServicetypeXxx */
  uint32_t MaxSduSize;         /* bytes */
  uint32_t MinimumPolicedSize; /* bytes */
};

struct NtQos {
  struct NtFlowSpec SendingFlowspec;
  struct NtFlowSpec ReceivingFlowspec;
  struct NtIovec ProviderSpecific;
};

struct NtWsaVersion {
  uint32_t dwVersion;
  int ecHow;
};

struct NtAfProtocols {
  int32_t iAddressFamily;
  int32_t iProtocol;
};

struct NtBlob {
  uint32_t cbSize;
  uint8_t pBlobData;
};

struct NtCsAddrInfo {
  struct NtSocketAddress LocalAddr;
  struct NtSocketAddress RemoteAddr;
  int32_t iSocketType;
  int32_t iProtocol;
};

struct NtWsaQuerySet {
  uint32_t dwSize; /* of this */
  char16_t *lpszServiceInstanceName;
  struct NtGuid *lpServiceClassId;
  struct NtWsaVersion *lpVersion;
  char16_t *lpszComment;
  uint32_t dwNameSpace;
  struct NtGuid *lpNSProviderId;
  char16_t *lpszContext;
  uint32_t dwNumberOfProtocols;
  struct NtAfProtocols *lpafpProtocols /*[dwNumberOfProtocols]*/;
  char16_t *lpszQueryString;
  uint32_t dwNumberOfCsAddrs;
  struct NtCsAddrInfo *lpcsaBuffer /*[dwNumberOfCsAddrs]*/;
  uint32_t dwOutputFlags;
  struct NtBlob *lpBlob;
};

struct NtWsaNamespaceInfoEx {
  struct NtGuid NSProviderId;
  uint32_t dwNameSpace;
  bool32 fActive;
  uint32_t dwVersion;
  char16_t *lpszIdentifier;
  struct NtBlob *ProviderSpecific;
};

struct NtWsansClassInfo {
  char16_t *lpszName;
  uint32_t dwNameSpace;
  uint32_t dwValueType;
  uint32_t dwValueSize;
  void *lpValue;
};

struct NtWsaServiceClassInfo {
  struct NtGuid *lpServiceClassId;
  char16_t *lpszServiceClassName;
  uint32_t dwCount;
  struct NtWsansClassInfo *lpClassInfos;
};

struct NtWsaNetworkEvents {
  int32_t lNetworkEvents;
  int32_t iErrorCode[10];
};

struct NtTransmitFileBuffers {
  void *Head;
  uint32_t HeadLength;
  void *Tail;
  uint32_t TailLength;
};

typedef int (*NtConditionProc)(
    const struct NtIovec *lpCallerId, const struct NtIovec *lpCallerData,
    struct NtQos *inout_lpSQOS, struct NtQos *inout_lpGQOS,
    const struct NtIovec *lpCalleeId, const struct NtIovec *lpCalleeData,
    uint32_t *out_group, const uint32_t *dwCallbackData);

typedef void (*NtWsaOverlappedCompletionRoutine)(
    uint32_t dwError, uint32_t cbTransferred,
    const struct NtOverlapped *lpOverlapped, uint32_t dwFlags);

struct NtWsaCompletion {
  int Type;
  union {
    struct {
      int64_t hWnd;
      uint32_t uMsg;
      uintptr_t context;
    } WindowMessage;
    struct {
      struct NtOverlapped *lpOverlapped;
    } Event;
    struct {
      struct NtOverlapped *lpOverlapped;
      NtWsaOverlappedCompletionRoutine lpfnCompletionProc;
    } Apc;
    struct {
      struct NtOverlapped *lpOverlapped;
      int64_t hPort;
      uint32_t Key;
    } Port;
  } Parameters;
};

struct NtInterfaceInfo {
  uint64_t iiFlags;
  struct sockaddr_in iiAddress;
  struct sockaddr_in iiBroadcastAddress;
  struct sockaddr_in iiNetmask;
};

/**
 * Winsock2 prototypes.
 *
 * @note Some of the functions exported by WS2_32.DLL, e.g. bind(),
 *       overlap with the names used by System V. Prototypes for these
 *       functions are declared within their respective wrappers.
 */

int32_t WSAStartup(uint16_t wVersionRequested, struct NtWsaData *lpWSAData)
    paramsnonnull();

int WSACleanup(void);
int WSAGetLastError(void) nosideeffect;
void WSASetLastError(int);

int64_t __sys_socket_nt(int, int, int);
int __sys_bind_nt(uint64_t, const void *, int);
int __sys_closesocket_nt(uint64_t);
int __sys_getpeername_nt(uint64_t, void *, uint32_t *);
int __sys_getsockname_nt(uint64_t, void *, uint32_t *);
int __sys_getsockopt_nt(uint64_t, int, int, void *, uint32_t *);
int __sys_ioctlsocket_nt(uint64_t, int32_t, uint32_t *);
int __sys_listen_nt(uint64_t, int);
int __sys_setsockopt_nt(uint64_t, int, int, const void *, int);
int __sys_shutdown_nt(uint64_t, int);
int __sys_select_nt(int, struct NtFdSet *, struct NtFdSet *, struct NtFdSet *,
                    struct NtTimeval *);

uint64_t WSASocket(int af, int type, int protocol,
                   const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                   const uint32_t opt_group, uint32_t dwFlags) __wur;

int WSAConnect(uint64_t s, const struct sockaddr *name, const int namelen,
               const struct NtIovec *opt_lpCallerData,
               struct NtIovec *opt_out_lpCalleeData,
               const struct NtQos *opt_lpSQOS, const struct NtQos *opt_lpGQOS)
    paramsnonnull((2));

bool32 WSAConnectByName(uint64_t s, const char16_t *nodename,
                        const char16_t *servicename,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2, 3));

bool32 WSAConnectByList(uint64_t s,
                        const struct NtSocketAddressList *SocketAddress,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2));

int64_t WSAAccept(uint64_t s, struct sockaddr *out_addr,
                  int32_t *opt_inout_addrlen,
                  const NtConditionProc opt_lpfnCondition,
                  const uint32_t *opt_dwCallbackData) paramsnonnull((2)) __wur;

int WSASend(uint64_t s, const struct NtIovec *lpBuffers, uint32_t dwBufferCount,
            uint32_t *opt_out_lpNumberOfBytesSent, uint32_t dwFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendMsg(int64_t Handle, const struct NtMsgHdr *lpMsg, uint32_t dwFlags,
               uint32_t *opt_out_lpNumberOfBytesSent,
               struct NtOverlapped *opt_inout_lpOverlapped,
               const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendTo(uint64_t s, const struct NtIovec *lpBuffers,
              uint32_t dwBufferCount,
              uint32_t *opt_out_lpNumberOfBytesSent /* opt if !overlapped */,
              uint32_t dwFlags, const void *opt_tosockaddr,
              int32_t tosockaddrlen,
              struct NtOverlapped *opt_inout_lpOverlapped,
              const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSAPoll(struct sys_pollfd_nt *inout_fdArray, uint32_t nfds,
            signed timeout_ms) paramsnonnull();

int WSARecv(uint64_t s, const struct NtIovec *inout_lpBuffers,
            uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
            uint32_t *inout_lpFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvFrom(uint64_t s, const struct NtIovec *inout_lpBuffers,
                uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
                uint32_t *inout_lpFlags, void *out_fromsockaddr,
                uint32_t *opt_inout_fromsockaddrlen,
                struct NtOverlapped *opt_inout_lpOverlapped,
                const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvDisconnect(uint64_t s, struct NtIovec *out_InboundDisconnectData);
int WSASendDisconnect(int64_t s, struct NtIovec *opt_OutboundDisconnectData);

int WSADuplicateSocket(uint64_t s, uint32_t dwProcessId,
                       struct NtWsaProtocolInfo *out_lpProtocolInfo)
    paramsnonnull((3));

int WSAIoctl(uint64_t s, uint32_t dwIoControlCode, const void *lpvInBuffer,
             uint32_t cbInBuffer, void *out_lpvOutBuffer, uint32_t cbOutBuffer,
             uint32_t *out_lpcbBytesReturned,
             struct NtOverlapped *opt_inout_lpOverlapped,
             const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((5, 7));

int WSANSPIoctl(int64_t hLookup, uint32_t dwControlCode,
                const void *lpvInBuffer, uint32_t cbInBuffer,
                void *out_lpvOutBuffer, uint32_t cbOutBuffer,
                uint32_t *out_lpcbBytesReturned,
                const struct NtWsaCompletion *opt_lpCompletion)
    paramsnonnull((3, 5, 7));

int64_t WSACreateEvent(void) __wur;
bool32 WSACloseEvent(const int64_t hEvent);
bool32 WSAResetEvent(const int64_t hEvent);
bool32 WSASetEvent(const int64_t hEvent);

int WSAEventSelect(uint64_t s, const int64_t opt_hEventObject,
                   long lNetworkEvents);

uint32_t WSAWaitForMultipleEvents(uint32_t cEvents, const int64_t *lphEvents,
                                  bool32 fWaitAll, uint32_t dwTimeout_ms,
                                  bool32 fAlertable) paramsnonnull();

int WSAEnumNetworkEvents(uint64_t s, const int64_t hEventObject,
                         struct NtWsaNetworkEvents *out_lpNetworkEvents)
    paramsnonnull();

bool32 WSAGetOverlappedResult(uint64_t s,
                              const struct NtOverlapped *lpOverlapped,
                              uint32_t *out_lpcbTransfer, bool32 fWait,
                              uint32_t *out_lpdwFlags) paramsnonnull();

int WSAEnumProtocols(const int32_t *opt_lpiProtocols,
                     struct NtWsaProtocolInfo *out_lpProtocolBuffer,
                     uint32_t *inout_lpdwBufferLength) paramsnonnull();

bool32 WSAGetQOSByName(uint64_t s, const struct NtIovec *lpQOSName,
                       struct NtQos *out_lpQOS) paramsnonnull();

uint64_t WSAJoinLeaf(uint64_t s, const struct sockaddr *name, const int namelen,
                     const struct NtIovec *opt_lpCallerData,
                     struct NtIovec *opt_out_lpCalleeData,
                     const struct NtQos *opt_lpSQOS,
                     const struct NtQos *opt_lpGQOS, uint32_t dwFlags)
    paramsnonnull((2, 4));

int WSALookupServiceBegin(const struct NtWsaQuerySet *lpqsRestrictions,
                          uint32_t dwControlFlags, int64_t *out_lphLookup)
    paramsnonnull();

int WSALookupServiceNext(const int64_t hLookup, uint32_t dwControlFlags,
                         uint32_t *inout_lpdwBufferLength,
                         struct NtWsaQuerySet *out_lpqsResults) paramsnonnull();

int WSALookupServiceEnd(int64_t hLookup);

int WSAAddressToString(const struct sockaddr *lpsaAddress,
                       uint32_t dwAddressLength,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       char16_t *out_lpszAddressString,
                       uint32_t *inout_lpdwAddressStringLength)
    paramsnonnull((1, 4, 5));

int WSAStringToAddress(const char16_t *AddressString, int AddressFamily,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       struct sockaddr *out_lpAddress,
                       int *inout_lpAddressLength) paramsnonnull((1, 3, 4));

int WSAEnumNameSpaceProvidersEx(uint32_t *inout_lpdwBufferLength,
                                struct NtWsaNamespaceInfoEx *out_lpnspBuffer)
    paramsnonnull();

int WSAProviderConfigChange(
    int64_t *inout_lpNotificationHandle,
    struct NtOverlapped *opt_inout_lpOverlapped,
    NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((1));

int WSAInstallServiceClass(
    const struct NtWsaServiceClassInfo *lpServiceClassInfo) paramsnonnull();

int WSARemoveServiceClass(const struct NtGuid *lpServiceClassId)
    paramsnonnull();

int WSAGetServiceClassInfo(const struct NtGuid *lpProviderId,
                           const struct NtGuid *lpServiceClassId,
                           uint32_t *inout_lpdwBufSize,
                           struct NtWsaServiceClassInfo *out_lpServiceClassInfo)
    paramsnonnull((1, 2, 3));

int WSASetService(const struct NtWsaQuerySet *lpqsRegInfo, int essoperation,
                  uint32_t dwControlFlags) paramsnonnull();

int /* success==0 */ WSAGetServiceClassNameByClassId(
    const struct NtGuid *lpServiceClassId, char16_t *out_lpszServiceClassName,
    uint32_t *inout_lpdwBufferLength) paramsnonnull();

void GetAcceptExSockaddrs(
    const void *lpOutputBuffer /*[recvsize+addrsize+addrlen]*/,
    uint32_t dwReceiveDataLength, uint32_t dwLocalAddressLength,
    uint32_t dwRemoteAddressLength,
    struct sockaddr **out_LocalSockaddr /*[*LocalSockaddrLength]*/,
    int *out_LocalSockaddrLength,
    struct sockaddr **out_RemoteSockaddr /*[*RemoteSockaddrLength]*/,
    int *out_RemoteSockaddrLength);

bool32 DisconnectEx(int64_t s, struct NtOverlapped *inout_opt_lpOverlapped,
                    uint32_t dwFlags, uint32_t dwReserved);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/winsock.inc */

extern typeof(WSAGetLastError) *const __imp_WSAGetLastError __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_

/* Constants ----------------------------------------------------------- */

#define kNtMaxAdapterAddressLength  8
#define kNtMaxDnsSuffixStringLength 256
#define kNtMaxDhcpv6DuidLength      130

/* Values for the 'Flags' parameter of GetAdaptersAddresses */
#define kNtGaaFlagSkipUnicast               0x0001
#define kNtGaaFlagSkipAnycast               0x0002
#define kNtGaaFlagSkipMulticast             0x0004
#define kNtGaaFlagSkipDnsServer             0x0008
#define kNtGaaFlagIncludePrefix             0x0010
#define kNtGaaFlagSkipFriendlyName          0x0020
#define kNtGaaFlagIncludeWinsInfo           0x0040
#define kNtGaaFlagIncludeGateways           0x0080
#define kNtGaaFlagIncludeAllInterfaces      0x0100
#define kNtGaaFlagIncludeAllCompartments    0x0200
#define kNtGaaFlagIncludeTunnelBindingorder 0x0400
#define kNtGaaFlagSkipDnsInfo               0x0800

/* Values for the IfType parameter
 * See:
 * https://docs.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_addresses_lh
 */
#define kNtIfTypeOther             1
#define kNtIfTypeEthernetCsmacd    6
#define kNtIfTypeIso88025Tokenring 9
#define kNtIfTypePpp               23
#define kNtIfTypeSoftwareLoopback  24
#define kNtIfTypeAtm               37
#define kNtIfTypeIeee80211         71 /* wifi */
#define kNtIfTypeTunnel            131
#define kNtIfTypeIeee1394          144 /* firewire */

#define kNtIpAdapterDdnsEnabled             0x0001
#define kNtIpAdapterRegisterAdapterSuffix   0x0002
#define kNtIpAdapterDhcpv4Enabled           0x0004
#define kNtIpAdapterReceiveOnly             0x0008
#define kNtIpAdapterNoMulticast             0x0010
#define kNtIpAdapterIpv6OtherStatefulConfig 0x0020
#define kNtIpAdapterNetbiosOverTcpipEnabled 0x0040
#define kNtIpAdapterIpv4Enabled             0x0080
#define kNtIpAdapterIpv6Enabled             0x0100
#define kNtIpAdapterIpv6Managed             0x0200

#define kNtIpPrefixOriginOther               0
#define kNtIpPrefixOriginManual              1
#define kNtIpPrefixOriginWellKnown           2
#define kNtIpPrefixOriginDhcp                3
#define kNtIpPrefixOriginRouterAdvertisement 4
#define kNtIpPrefixOriginUnchanged           16

#define kNtIpSuffixOriginOther            0
#define kNtIpSuffixOriginManual           1
#define kNtIpSuffixOriginWellKnown        2
#define kNtIpSuffixOriginDhcp             3
#define kNtIpSuffixOriginLinkLayerAddress 4
#define kNtIpSuffixOriginRandom           5
#define kNtIpSuffixOriginUnchanged        16

#define kNtIpDadStateInvalid    0
#define kNtIpDadStateTentative  1
#define kNtIpDadStateDuplicate  2
#define kNtIpDadStateDeprecated 3
#define kNtIpDadStatePreferred  4

#define kNtIfOperStatusUp             1
#define kNtIfOperStatusDown           2
#define kNtIfOperStatusTesting        3
#define kNtIfOperStatusUnknown        4
#define kNtIfOperStatusDormant        5
#define kNtIfOperStatusNotPresent     6
#define kNtIfOperStatusLowerLayerDown 7

#define kNtNetIfConnectionDedicated 1
#define kNtNetIfConnectionPassive   2
#define kNtNetIfConnectionDemand    3
#define kNtNetIfConnectionMaximum   4

#define kNtTunnelTypeNone    0
#define kNtTunnelTypeOther   1
#define kNtTunnelTypeDirect  2
#define kNtTunnelType6to4    11
#define kNtTunnelTypeIsatap  13
#define kNtTunnelTypeTeredo  14
#define kNtTunnelTypeIphttps 15

COSMOPOLITAN_C_START_

/* Inner Types --------------------------------------------------------- */

struct NtIpAdapterUnicastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterUnicastAddress *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixOrigin; /* kNtIpPrefixOrigin... */
  uint32_t SuffixOrigin; /* kNtIpSuffixOrigin... */
  uint32_t DadState;     /* kNtIpDadState... */
  uint32_t ValidLifetime;
  uint32_t PreferredLifetime;
  uint32_t LeaseLifetime;
  uint8_t OnLinkPrefixLength;
};

struct NtIpAdapterAnycastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterAnycastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterMulticastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterMulticastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterDnsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterPrefix {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterPrefix *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixLength;
};

struct NtIpAdapterWinsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterWinsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterGatewayAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterGatewayAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsSuffix {
  struct NtIpAdapterDnsSuffix *Next;
  uint16_t String[kNtMaxDnsSuffixStringLength];
};

/* Top level ----------------------------------------------------------- */

struct NtIpAdapterAddresses {
  uint32_t Length;
  uint32_t IfIndex;
  struct NtIpAdapterAddresses *Next;
  char *AdapterName;
  struct NtIpAdapterUnicastAddress *FirstUnicastAddress;
  struct NtIpAdapterAnycastAddress *FirstAnycastAddress;
  struct NtIpAdapterMulticastAddress *FirstMulticastAddress;
  struct NtIpAdapterDnsServerAddress *FirstDnsServerAddress;
  uint16_t *DnsSuffix;
  uint16_t *Description;
  uint16_t *FriendlyName;
  uint8_t PhysicalAddress[kNtMaxAdapterAddressLength];
  uint32_t PhysicalAddressLength;
  uint32_t Flags; /* kNtIpAdapter... */
  uint32_t Mtu;
  uint32_t IfType;     /* kNtIfType... */
  uint32_t OperStatus; /* kNtIfOperStatus... */
  uint32_t Ipv6IfIndex;
  uint32_t ZoneIndices[16];
  struct NtIpAdapterPrefix *FirstPrefix;
  uint64_t TransmitLinkSpeed;
  uint64_t ReceiveLinkSpeed;
  struct NtIpAdapterWinsServerAddress *FirstWinsServerAddress;
  struct NtIpAdapterGatewayAddress *FirstGatewayAddress;
  uint32_t Ipv4Metric;
  uint32_t Ipv6Metric;
  uint64_t Luid; /* reserved(24bits),NetLuidIndex(24b),IfType(16b) */
  struct NtSocketAddress Dhcpv4Server;
  uint32_t CompartmentId;
  struct NtGuid NetworkGuid;
  uint32_t ConnectionType; /* kNtNetIfConnection... */
  uint32_t TunnelType;     /* kNtTunnelType... */
  struct NtSocketAddress Dhcpv6Server;
  uint8_t Dhcpv6ClientDuid[kNtMaxDhcpv6DuidLength];
  uint32_t Dhcpv6ClientDuidLength;
  uint32_t Dhcpv6Iaid;
  struct NtIpAdapterDnsSuffix *FirstDnsSuffix;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/kernelusertimes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_KERNELUSERTIMES_H_

struct NtKernelUserTimes {
  uint64_t CreateFileTime;
  uint64_t ExitFileTime;
  int64_t KernelTime;
  int64_t UserTime;
};



/*!BEGIN libc/nt/struct/ldr.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDR_H_

struct NtLdr {
  uint32_t SizeOfThis;                       /* msdn:reserved */
  uint32_t IsInitialized;                    /* msdn:reserved */
  void *SsHandle;                            /* msdn:reserved */
  struct NtLinkedList InLoadOrderModuleList; /* msdn:reserved */
  struct NtLinkedList /*∩NtLdrDataTableEntry*/ InMemoryOrderModuleList;
  struct NtLinkedList InInitOrderModuleList; /* msdn:reserved */
};



/*!BEGIN libc/nt/struct/ldrdatatableentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDRDATATABLEENTRY_H_


/*!BEGIN libc/nt/struct/unicodestring.h */

#define COSMOPOLITAN_LIBC_NT_UNICODE_H_

struct NtUnicodeString {
  uint16_t Length;
  uint16_t MaxLength;
  char16_t *Data;
};


struct NtLdrDataTableEntry {
  struct NtLinkedList InLoadOrderLinks; /* msdn:reserved */
  struct NtLinkedList InMemoryOrderLinks;
  struct NtLinkedList InInitOrderLinks; /* msdn:reserved */
  void *DllBase;
  void *EntryPoint;
  union {
    uint32_t SizeOfImage;
    unsigned char SizeOfImagePadding[__SIZEOF_POINTER__];
  };
  struct NtUnicodeString FullDllName;
  struct NtUnicodeString BaseDllName;
  uint32_t Flags;
  uint16_t Load_Count;
  uint16_t TlsIndex;
  union {
    struct NtLinkedList HashLinks;
    struct {
      void *SectionPointer;
      uint32_t CheckSum;
    };
  };
  union {
    void *LoadedImports;
    uint32_t TimeDateStamp;
  };
  void *EntryPointActivationContext;
  void *PatchInformation;
  struct NtLinkedList ForwarderLinks;
  struct NtLinkedList ServiceTagLinks;
  struct NtLinkedList StaticLinks;
  void *ContextInformation;
  uintptr_t OriginalBase;
  int64_t LoadTime;
};



/*!BEGIN libc/nt/struct/linger.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger_nt {
  uint16_t l_onoff;  /* on/off */
  uint16_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/luid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUID_H_

struct NtLuid {
  uint32_t LowPart;
  int32_t HighPart;
};



/*!BEGIN libc/nt/struct/luidandattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUIDANDATTRIBUTES_H_

struct NtLuidAndAttributes {
  struct NtLuid Luid;
  uint32_t Attributes;
};



/*!BEGIN libc/nt/struct/memextendedparameter.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMEXTENDEDPARAMETER_H_

#define kNtMemExtendedParameterTypeBits 8

#define kNtMemExtendedParameterInvalidType         0
#define kNtMemExtendedParameterAddressRequirements 1
#define kNtMemExtendedParameterNumaNode            2
#define kNtMemExtendedParameterPartitionHandle     3
#define kNtMemExtendedParameterUserPhysicalHandle  4
#define kNtMemExtendedParameterAttributeFlags      5
#define kNtMemExtendedParameterMax                 6

#define kNtMemExtendedParameterGraphics          0x00000001
#define kNtMemExtendedParameterNonpaged          0x00000002
#define kNtMemExtendedParameterZeroPagesOptional 0x00000004
#define kNtMemExtendedParameterNonpagedLarge     0x00000008
#define kNtMemExtendedParameterNonpagedHuge      0x00000010

struct NtMemExtendedParameter {
  struct {
    uint64_t Type : kNtMemExtendedParameterTypeBits;
    uint64_t Reserved : 64 - kNtMemExtendedParameterTypeBits;
  } DUMMYSTRUCTNAME;
  union {
    uint64_t ULong64;
    void *Pointer;
    size_t Size;
    intptr_t Handle;
    unsigned ULong;
  } DUMMYUNIONNAME;
};



/*!BEGIN libc/nt/struct/memorybasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYBASICINFORMATION_H_

struct NtMemoryBasicInformation {
  void *BaseAddress;
  void *AllocationBase;
  uint32_t AllocationProtect;
  uint64_t RegionSize;
  uint32_t State;
  uint32_t Protect;
  uint32_t Type;
};



/*!BEGIN libc/nt/struct/memoryrangeentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYRANGEENTRY_H_

struct NtMemoryRangeEntry {
  void *VirtualAddress;
  size_t NumberOfBytes;
};



/*!BEGIN libc/nt/struct/memorystatusex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYSTATUSEX_H_

struct NtMemoryStatusEx {
  uint32_t dwLength;
  uint32_t dwMemoryLoad;
  uint64_t ullTotalPhys;
  uint64_t ullAvailPhys;
  uint64_t ullTotalPageFile;
  uint64_t ullAvailPageFile;
  uint64_t ullTotalVirtual;
  uint64_t ullAvailVirtual;
  uint64_t ullAvailExtendedVirtual;
};



/*!BEGIN libc/nt/struct/msg.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MSG_H_


/*!BEGIN libc/nt/struct/point.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POINT_H_

struct NtPoint {
  int32_t x;
  int32_t y;
};


struct NtMsg {
  int64_t hwnd;
  uint32_t dwMessage;
  uint64_t wParam;
  int64_t lParam;
  uint32_t dwTime;
  struct NtPoint pt;
};



/*!BEGIN libc/nt/struct/nonpageddebuginfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NONPAGEDDEBUGINFO_H_

struct NtNonPagedDebugInfo {
  uint16_t Signature;
  uint16_t Flags;
  uint32_t Size;
  uint16_t Machine;
  uint16_t Characteristics;
  uint32_t TimeDateStamp;
  uint32_t CheckSum;
  uint32_t SizeOfImage;
  uint64_t ImageBase;
};



/*!BEGIN libc/nt/struct/ntexceptionpointers.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONPOINTERS_H_


/*!BEGIN libc/nt/struct/ntexceptionrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONRECORD_H_

#define kNtExceptionMaximumParameters 15
#define kNtExceptionNoncontinuable    1


struct NtExceptionRecord {
  uint32_t ExceptionCode;                    /* kNtException... */
  uint32_t ExceptionFlags;                   /* kNtExceptionNoncontinuable */
  struct NtExceptionRecord *ExceptionRecord; /* nested exceptions */
  void *ExceptionAddress;                    /* %rip */
  uint32_t NumberParameters;                 /* #ExceptionInformation */
  uint64_t ExceptionInformation[kNtExceptionMaximumParameters];
};


struct NtExceptionPointers {
  struct NtExceptionRecord *ExceptionRecord;
  struct NtContext *ContextRecord;
};



/*!BEGIN libc/nt/struct/objectallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTALLINFORMATION_H_


/*!BEGIN libc/nt/struct/objecttypeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTTYPEINFORMATION_H_

struct NtObjectTypeInformation {
  struct NtUnicodeString TypeName;
  uint32_t TotalNumberOfObjects;
  uint32_t TotalNumberOfHandles;
  uint32_t TotalPagedPoolUsage;
  uint32_t TotalNonPagedPoolUsage;
  uint32_t TotalNamePoolUsage;
  uint32_t TotalHandleTableUsage;
  uint32_t HighWaterNumberOfObjects;
  uint32_t HighWaterNumberOfHandles;
  uint32_t HighWaterPagedPoolUsage;
  uint32_t HighWaterNonPagedPoolUsage;
  uint32_t HighWaterNamePoolUsage;
  uint32_t HighWaterHandleTableUsage;
  uint32_t InvalidAttributes;
  struct NtGenericMapping GenericMapping;
  uint32_t ValidAccessMask;
  bool32 SecurityRequired;
  bool32 MaintainHandleCount;
  uint32_t PoolType;
  uint32_t DefaultPagedPoolCharge;
  uint32_t DefaultNonPagedPoolCharge;
};


struct NtObjectAllInformation {
  uint32_t NumberOfObjects;
  struct NtObjectTypeInformation ObjectTypeInformation[1];
};



/*!BEGIN libc/nt/struct/objectattributes.h */

#define COSMOPOLITAN_LIBC_NT_I_OBJECTATTRIBUTES_H_


/*!BEGIN libc/nt/struct/rtluserprocessparameters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSPARAMETERS_H_

struct NtRtlUserProcessParameters {
  uint32_t MaximumLength;
  uint32_t Length;
  uint32_t Flags;
  uint32_t DebugFlags;
  int64_t ConsoleHandle;
  uint32_t ConsoleFlags;
  int64_t StdInputHandle;
  int64_t StdOutputHandle;
  int64_t StdErrorHandle;
  struct NtUnicodeString *CurrentDirectoryPath;
  int64_t CurrentDirectoryHandle;
  struct NtUnicodeString *DllPath;
  struct NtUnicodeString *ImagePathName;
  struct NtUnicodeString *CommandLine;
  void *Environment;
  uint32_t StartingPositionLeft;
  uint32_t StartingPositionTop;
  uint32_t Width;
  uint32_t Height;
  uint32_t CharWidth;
  uint32_t CharHeight;
  uint32_t ConsoleTextAttributes;
  uint32_t WindowFlags;
  uint32_t ShowWindowFlags;
  struct NtUnicodeString *WindowTitle;
  struct NtUnicodeString *DesktopName;
  struct NtUnicodeString *ShellInfo;
  struct NtUnicodeString *RuntimeData;
};



/*!BEGIN libc/nt/struct/securityattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYATTRIBUTES_H_


/*!BEGIN libc/nt/struct/securitydescriptor.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYDESCRIPTOR_H_

struct NtSecurityDescriptor {
  uint8_t Revision;
  uint8_t Sbz1;
  uint16_t Control;
  void *Owner;
  void *Group;
  struct NtAcl *Sacl;
  struct NtAcl *Dacl;
};


struct NtSecurityAttributes {
  uint32_t nLength;
  struct NtSecurityDescriptor *lpSecurityDescriptor;
  bool32 bInheritHandle;
};

const char *DescribeNtSecurityAttributes(char[32],
                                         const struct NtSecurityAttributes *);
#define DescribeNtSecurityAttributes(x) \
  DescribeNtSecurityAttributes(alloca(32), x)


struct NtObjectAttributes {
  uint32_t Length;
  int64_t RootDirectory;
  const struct NtUnicodeString *ObjectName;
  uint32_t Attributes; /* OBJ_INHERIT, etc. */
  struct NtSecurityDescriptor *SecurityDescriptor;
  void *SecurityQualityOfService;
};



/*!BEGIN libc/nt/struct/objectbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTBASICINFORMATION_H_

struct NtObjectBasicInformation {
  uint32_t Attributes;
  uint32_t GrantedAccess;
  uint32_t HandleCount;
  uint32_t PointerCount;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t Reserved[3];
  uint32_t NameInformationLength;
  uint32_t TypeInformationLength;
  uint32_t SecurityDescriptorLength;
  int64_t CreateTime;
};



/*!BEGIN libc/nt/struct/objectnameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTNAMEINFORMATION_H_

struct NtObjectNameInformation {
  struct NtUnicodeString Name;
};



/*!BEGIN libc/nt/struct/openfilename.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OPENFILENAME_H_

struct NtOpenFilename {
  uint32_t lStructSize;
  int64_t hwndOwner;
  int64_t hInstance;
  const char16_t *lpstrFilter;
  char16_t *lpstrCustomFilter;
  uint32_t nMaxCustFilter;
  uint32_t nFilterIndex;
  char16_t *lpstrFile;
  uint32_t nMaxFile;
  char16_t *lpstrFileTitle;
  uint32_t nMaxFileTitle;
  const char16_t *lpstrInitialDir;
  const char16_t *lpstrTitle;
  uint32_t Flags;
  uint16_t nFileOffset;
  uint16_t nFileExtension;
  const char16_t *lpstrDefExt;
  intptr_t lCustData;
  uint64_t (*lpfnHook)(int64_t, uint32_t, uint64_t, int64_t);
  const char16_t *lpTemplateName;
  void *pvReserved;
  uint32_t dwReserved;
  uint32_t FlagsEx;
};



/*!BEGIN libc/nt/struct/osversioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OSVERSIONINFO_H_
COSMOPOLITAN_C_START_

struct NtOsVersionInfo {
  uint32_t dwOSVersionInfoSize;
  uint32_t dwMajorVersion;
  uint32_t dwMinorVersion;
  uint32_t dwBuildNumber;
  uint32_t dwPlatformId;
  char16_t szCSDVersion[128];
  uint16_t wServicePackMajor;
  uint16_t wServicePackMinor;
  uint16_t wSuiteMask;
  uint8_t wProductType;
  uint8_t wReserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/overlappedentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPEDENTRY_H_
COSMOPOLITAN_C_START_

struct NtOverlappedEntry {
  uint64_t lpCompletionKey;
  struct NtOverlapped *lpOverlapped;
  uint32_t *Internal;
  uint32_t dwNumberOfBytesTransferred;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/paintstruct.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PAINTSTRUCT_H_


/*!BEGIN libc/nt/struct/rect.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RECT_H_

struct NtRect {
  int32_t left;
  int32_t top;
  int32_t right;
  int32_t bottom;
};


struct NtPaintStruct {
  int64_t hdc;
  bool32 fErase;
  struct NtRect rcPaint;
  bool32 fRestore;
  bool32 fIncUpdate;
  uint8_t rgbReserved[32];
};



/*!BEGIN libc/nt/struct/pdhfmtcountervalue.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PDHFMTCOUNTERVALUE_H_
COSMOPOLITAN_C_START_

struct NtPdhFmtCountervalue {
  uint32_t CStatus;
  union {
    int32_t longValue;
    double doubleValue;
    int64_t largeValue;
    const char *AnsiStringValue;
    const char16_t *WideStringValue;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/peb.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PEB_H_

struct NtPeb {
  union {
    struct {
      unsigned char InheritedAddressSpace;
      unsigned char ReadImageFileExecOptions;
      unsigned char BeingDebugged;
      unsigned char __wut1;
    };
    uint64_t __wut2;
  };
  uint64_t Mutant;
  uint64_t ImageBaseAddress;
  struct NtLdr *Ldr;
  uint64_t ProcessParameters;
  uint64_t SubSystemData;
  uint64_t ProcessHeap;
  uint64_t FastPebLock;
  uint64_t __wut3;
  uint64_t __wut4;
  uint64_t __wut5;
  union {
    uint64_t KernelCallbackTable;
    uint64_t UserSharedInfoPtr;
  };
  uint32_t SystemReserved;
  uint32_t __wut6;
  uint64_t __wut7;
  uint64_t TlsExpansionCounter;
  uint64_t TlsBitmap;
  uint32_t TlsBitmapBits[2];
  uint64_t ReadOnlySharedMemoryBase;
  uint64_t __wut8;
  uint64_t ReadOnlyStaticServerData;
  uint64_t AnsiCodePageData;
  uint64_t OemCodePageData;
  uint64_t UnicodeCaseTableData;
  uint32_t NumberOfProcessors;
#ifdef __x86_64__
  uint32_t NtGlobalFlag;
#else
  uint64_t NtGlobalFlag;
#endif
  int64_t CriticalSectionTimeout;
  uint64_t HeapSegmentReserve;
  uint64_t HeapSegmentCommit;
  uint64_t HeapDeCommitTotalFreeThreshold;
  uint64_t HeapDeCommitFreeBlockThreshold;
  uint32_t NumberOfHeaps;
  uint32_t MaximumNumberOfHeaps;
  uint64_t ProcessHeaps;
  uint64_t GdiSharedHandleTable;
  uint64_t ProcessStarterHelper;
  uint64_t GdiDCAttributeList;
  uint64_t LoaderLock;
  union {
    struct {
      uint32_t OSMajorVersion;
      uint32_t OSMinorVersion;
    };
    uint64_t OSVersion;
  };
  uint16_t OSBuildNumber;
  uint16_t OSCSDVersion;
  uint32_t OSPlatformId;
  uint32_t ImageSubsystem;
  uint32_t ImageSubsystemMajorVersion;
  uint64_t ImageSubsystemMinorVersion;
  union {
    uint64_t ImageProcessAffinityMask;
    uint64_t ActiveProcessAffinityMask;
  };
  uint64_t GdiHandleBuffer[38 - __SIZEOF_POINTER__];
  uint64_t PostProcessInitRoutine;
  uint64_t TlsExpansionBitmap;
  uint32_t TlsExpansionBitmapBits[32];
  uint64_t SessionId;
  uint64_t AppCompatFlags;
  uint64_t AppCompatFlagsUser;
  uint64_t pShimData;
  uint64_t AppCompatInfo;
  struct NtUnicodeString CSDVersion;
  uint64_t ActivationContextData;
  uint64_t ProcessAssemblyStorageMap;
  uint64_t SystemDefaultActivationContextData;
  uint64_t SystemAssemblyStorageMap;
  uint64_t MinimumStackCommit;
};



/*!BEGIN libc/nt/struct/privilegeset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PRIVILEGESET_H_

struct NtPrivilegeSet {
  uint32_t PrivilegeCount;
  uint32_t Control;
  struct NtLuidAndAttributes Privilege[1];
};



/*!BEGIN libc/nt/struct/processbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSBASICINFORMATION_H_

struct NtProcessBasicInformation {
  int32_t ExitStatus;
  struct NtPeb *PebBaseAddress;
  uint32_t *AffinityMask;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
};



/*!BEGIN libc/nt/struct/processentry32.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSENTRY32_H_

struct NtProcessEntry32 {
  uint32_t dwSize;
  uint32_t cntUsage; /* unused */
  uint32_t th32ProcessID;
  uint64_t th32DefaultHeapID; /* unused */
  uint32_t th32ModuleID;      /* unused */
  uint32_t cntThreads;
  uint32_t th32ParentProcessID;
  int32_t cPriClassBase;
  uint32_t dwFlags; /* unused */
  char16_t szExeFile[260];
};



/*!BEGIN libc/nt/struct/processinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSINFORMATION_H_

struct NtProcessInformation {
  int64_t hProcess;
  int64_t hThread;
  uint32_t dwProcessId;
  uint32_t dwThreadId;
};



/*!BEGIN libc/nt/struct/processmemorycounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSMEMORYCOUNTERS_H_
COSMOPOLITAN_C_START_

struct NtProcessMemoryCountersEx {
  uint32_t cb; /* count bytes */
  uint32_t PageFaultCount;
  uint64_t PeakWorkingSetSize;
  uint64_t WorkingSetSize;
  uint64_t QuotaPeakPagedPoolUsage;
  uint64_t QuotaPagedPoolUsage;
  uint64_t QuotaPeakNonPagedPoolUsage;
  uint64_t QuotaNonPagedPoolUsage;
  uint64_t PagefileUsage;
  uint64_t PeakPagefileUsage;
  uint64_t PrivateUsage;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/processornumber.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSORNUMBER_H_
COSMOPOLITAN_C_START_

struct NtProcessorNumber {
  uint16_t Group;
  uint8_t Number;
  uint8_t Reserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/procthreadattributelist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCTHREADATTRIBUTELIST_H_

struct NtProcThreadAttributeList;



/*!BEGIN libc/nt/struct/reparsedatabuffer.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_REPARSEDATABUFFER_H_
COSMOPOLITAN_C_START_

struct NtReparseDataBuffer {
  uint32_t ReparseTag;
  uint16_t ReparseDataLength;
  uint16_t Reserved;
  union {
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      uint32_t Flags;
      char16_t PathBuffer[1];
    } SymbolicLinkReparseBuffer;
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      char16_t PathBuffer[1];
    } MountPointReparseBuffer;
    struct {
      uint8_t DataBuffer[1];
    } GenericReparseBuffer;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/rtluserprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/sectionimageinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECTIONIMAGEINFORMATION_H_

struct NtSectionImageInformation {
  void *EntryPoint;
  uint32_t Unknown1;
  uint32_t StackReserve;
  uint32_t StackCommit;
  uint32_t Subsystem;
  uint16_t MinorSubsystemVersion;
  uint16_t MajorSubsystemVersion;
  uint32_t Unknown2;
  uint32_t Characteristics;
  uint16_t ImageNumber;
  uint32_t IsExecutable;
  uint8_t __wut1;
  uint32_t __wut2[3];
};


struct NtRtlUserProcessInformation {
  uint32_t SizeOfThis;
  int64_t ProcessHandle;
  int64_t ThreadHandle;
  struct NtClientId ClientId;
  struct NtSectionImageInformation ImageInformation;
};



/*!BEGIN libc/nt/struct/size.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SIZE_H_
COSMOPOLITAN_C_START_

struct NtSize {
  int32_t cx;
  int32_t cy;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFO_H_

struct NtStartupInfo {
  uint32_t cb /* = sizeof(struct NtStartupInfo) */;
  uint16_t *lpReserved;
  char16_t *lpDesktop;
  char16_t *lpTitle; /* title of *new* console window only */
  uint32_t dwX;      /* position of window on screen */
  uint32_t dwY;
  uint32_t dwXSize;
  uint32_t dwYSize;
  uint32_t dwXCountChars; /* used to dimension the dos terminal */
  uint32_t dwYCountChars;
  uint32_t dwFillAttribute;
  uint32_t dwFlags;
  uint16_t wShowWindow;
  uint16_t cbReserved2;
  uint8_t *lpReserved2;
  union {
    struct {
      int64_t hStdInput;
      int64_t hStdOutput;
      int64_t hStdError;
    };
    int64_t stdiofds[3];
  };
};



/*!BEGIN libc/nt/struct/startupinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFOEX_H_

struct NtStartupInfoEx {
  struct NtStartupInfo StartupInfo;
  struct NtProcThreadAttributeList *lpAttributeList;
};



/*!BEGIN libc/nt/struct/systembasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMBASICINFORMATION_H_

struct NtSystemBasicInformation {
  unsigned char Reserved1[4];
  uint32_t MaximumIncrement;
  uint32_t PhysicalPageSize;
  uint32_t NumberOfPhysicalPages;
  uint32_t LowestPhysicalPage;
  uint32_t HighestPhysicalPage;
  uint32_t AllocationGranularity;
  uint32_t LowestUserAddress;
  uint32_t HighestUserAddress;
  uint32_t ActiveProcessors;
  char NumberOfProcessors;
};



/*!BEGIN libc/nt/struct/systemexceptioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMEXCEPTIONINFORMATION_H_

struct NtSystemExceptionInformation {
  unsigned char Reserved1[16];
};



/*!BEGIN libc/nt/struct/systemhandleentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEENTRY_H_

struct NtSystemHandleEntry {
  uint32_t OwnerPid;
  unsigned char ObjectType;
  unsigned char HandleFlags;
  unsigned short HandleValue;
  void *ObjectPointer;
  uint32_t AccessMask;
};



/*!BEGIN libc/nt/struct/systemhandleinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEINFORMATION_H_

struct NtSystemHandleInformation {
  uint32_t Count;
  struct NtSystemHandleEntry Handle[1];
};



/*!BEGIN libc/nt/struct/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINFO_H_

struct NtSystemInfo {
  union {
    uint32_t dwOemId;
    struct {
      uint16_t wProcessorArchitecture;
      uint16_t wReserved;
    };
  };
  uint32_t dwPageSize;
  void *lpMinimumApplicationAddress;
  void *lpMaximumApplicationAddress;
  uintptr_t dwActiveProcessorMask;
  uint32_t dwNumberOfProcessors;
  uint32_t dwProcessorType;
  uint32_t dwAllocationGranularity;
  uint16_t wProcessorLevel;
  uint16_t wProcessorRevision;
};



/*!BEGIN libc/nt/struct/systeminterruptinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINTERRUPTINFORMATION_H_

struct NtSystemInterruptInformation {
  unsigned char Reserved1[24];
};



/*!BEGIN libc/nt/struct/systemlookasideinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMLOOKASIDEINFORMATION_H_

struct NtSystemLookasideInformation {
  unsigned char Reserved1[32];
};



/*!BEGIN libc/nt/struct/systemperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPERFORMANCEINFORMATION_H_

struct NtSystemPerformanceInformation {
  int64_t IdleTime;
  int64_t ReadTransferCount;
  int64_t WriteTransferCount;
  int64_t OtherTransferCount;
  uint32_t ReadOperationCount;
  uint32_t WriteOperationCount;
  uint32_t OtherOperationCount;
  uint32_t AvailablePages;
  uint32_t TotalCommittedPages;
  uint32_t TotalCommitLimit;
  uint32_t PeakCommitment;
  uint32_t PageFaults;
  uint32_t WriteCopyFaults;
  uint32_t TransitionFaults;
  uint32_t CacheTransitionFaults;
  uint32_t DemandZeroFaults;
  uint32_t PagesRead;
  uint32_t PageReadIos;
  uint32_t CacheReads;
  uint32_t CacheIos;
  uint32_t PagefilePagesWritten;
  uint32_t PagefilePageWriteIos;
  uint32_t MappedFilePagesWritten;
  uint32_t MappedFilePageWriteIos;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t PagedPoolAllocs;
  uint32_t PagedPoolFrees;
  uint32_t NonPagedPoolAllocs;
  uint32_t NonPagedPoolFrees;
  uint32_t TotalFreeSystemPtes;
  uint32_t SystemCodePage;
  uint32_t TotalSystemDriverPages;
  uint32_t TotalSystemCodePages;
  uint32_t SmallNonPagedLookasideListAllocateHits;
  uint32_t SmallPagedLookasideListAllocateHits;
  uint32_t Reserved3;
  uint32_t MmSystemCachePage;
  uint32_t PagedPoolPage;
  uint32_t SystemDriverPage;
  uint32_t FastReadNoWait;
  uint32_t FastReadWait;
  uint32_t FastReadResourceMiss;
  uint32_t FastReadNotPossible;
  uint32_t FastMdlReadNoWait;
  uint32_t FastMdlReadWait;
  uint32_t FastMdlReadResourceMiss;
  uint32_t FastMdlReadNotPossible;
  uint32_t MapDataNoWait;
  uint32_t MapDataWait;
  uint32_t MapDataNoWaitMiss;
  uint32_t MapDataWaitMiss;
  uint32_t PinMappedDataCount;
  uint32_t PinReadNoWait;
  uint32_t PinReadWait;
  uint32_t PinReadNoWaitMiss;
  uint32_t PinReadWaitMiss;
  uint32_t CopyReadNoWait;
  uint32_t CopyReadWait;
  uint32_t CopyReadNoWaitMiss;
  uint32_t CopyReadWaitMiss;
  uint32_t MdlReadNoWait;
  uint32_t MdlReadWait;
  uint32_t MdlReadNoWaitMiss;
  uint32_t MdlReadWaitMiss;
  uint32_t ReadAheadIos;
  uint32_t LazyWriteIos;
  uint32_t LazyWritePages;
  uint32_t DataFlushes;
  uint32_t DataPages;
  uint32_t ContextSwitches;
  uint32_t FirstLevelTbFills;
  uint32_t SecondLevelTbFills;
  uint32_t SystemCalls;
};



/*!BEGIN libc/nt/struct/systemprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/vmcounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VMCOUNTERS_H_

struct NtVmCounters {
  size_t PeakVirtualSize;
  size_t VirtualSize;
  uint32_t PageFaultCount;
  size_t PeakWorkingSetSize;
  size_t WorkingSetSize;
  size_t QuotaPeakPagedPoolUsage;
  size_t QuotaPagedPoolUsage;
  size_t QuotaPeakNonPagedPoolUsage;
  size_t QuotaNonPagedPoolUsage;
  size_t PagefileUsage;
  size_t PeakPagefileUsage;
};


struct NtSystemProcessInformation {
  uint32_t NextEntryOffset;
  uint32_t NumberOfThreads;
  int64_t Reserved[3];
  int64_t CreateTime;
  int64_t UserTime;
  int64_t KernelTime;
  struct NtUnicodeString ImageName;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
  uint32_t HandleCount;
  uint32_t SessionId;
  uint32_t PageDirectoryBase;
  struct NtVmCounters VirtualMemoryCounters;
  size_t PrivatePageCount;
  struct NtIoCounters IoCounters;
};



/*!BEGIN libc/nt/struct/systemprocessorinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORINFORMATION_H_

struct NtSystemProcessorInformation {
  unsigned short ProcessorArchitecture;
  unsigned short ProcessorLevel;
  unsigned short ProcessorRevision;
  unsigned short Unknown;
  uint32_t FeatureBits;
};



/*!BEGIN libc/nt/struct/systemprocessorperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORPERFORMANCEINFORMATION_H_

struct NtSystemProcessorPerformanceInformation {
  int64_t IdleTime;
  int64_t KernelTime;
  int64_t UserTime;
  int64_t Reserved1[2];
  uint32_t Reserved2;
};



/*!BEGIN libc/nt/struct/systemregistryquotainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMREGISTRYQUOTAINFORMATION_H_

struct NtSystemRegistryQuotaInformation {
  uint32_t RegistryQuotaAllowed;
  uint32_t RegistryQuotaUsed;
  void *Reserved1;
};



/*!BEGIN libc/nt/struct/systemthreads.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTHREADS_H_

struct NtSystemThreads {
  int64_t KernelTime;
  int64_t UserTime;
  int64_t CreateTime;
  uint32_t WaitTime;
  void *StartAddress;
  struct NtClientId ClientId;
  int32_t Priority;
  int32_t BasePriority;
  uint32_t ContextSwitchCount;
  int State;
  uint32_t WaitReason;
};



/*!BEGIN libc/nt/struct/systemtimeofdayinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIMEOFDAYINFORMATION_H_

struct NtSystemTimeofdayInformation {
  int64_t BootTime;
  int64_t CurrentTime;
  int64_t TimeZoneBias;
  uint32_t CurrentTimeZoneId;
  unsigned char Reserved1[20];
};



/*!BEGIN libc/nt/struct/teb.h */

#define COSMOPOLITAN_LIBC_NT_TEB_H_
#ifdef __GNUC__

/*
 * These macros address directly into NT's TEB a.k.a. TIB
 * Any function that does this needs the `dontasan` keyword
 */
#define NtGetPeb()           ((__seg_gs struct NtPeb *)0x60)
#define NtGetTeb()           ((void *)*(__seg_gs uintptr_t *)0x30)
#define NtGetPid()           (*(__seg_gs uint32_t *)0x40)
#define NtGetTid()           (*(__seg_gs uint32_t *)0x48)
#define NtGetErr()           (*(__seg_gs int *)0x68)
#define _NtGetSeh()          ((void *)*(__seg_gs uintptr_t *)0x00)
#define _NtGetStackHigh()    ((void *)*(__seg_gs uintptr_t *)0x08)
#define _NtGetStackLow()     ((void *)*(__seg_gs uintptr_t *)0x10)
#define _NtGetSubsystemTib() ((void *)*(__seg_gs uintptr_t *)0x18)
#define _NtGetFib()          ((void *)*(__seg_gs uintptr_t *)0x20)
#define _NtGetEnv()          ((char16_t *)*(__seg_gs intptr_t *)0x38)
#define _NtGetRpc()          ((void *)*(__seg_gs uintptr_t *)0x50)
#define _NtGetTls()          ((void *)*(__seg_gs uintptr_t *)0x58)

#endif /* __GNUC__ */


/*!BEGIN libc/nt/struct/timezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEZONEINFORMATION_H_

struct NtTimeZoneInformation {
  int Bias;                  /* in minutes e.g. +480 for -8:00 */
  char16_t StandardName[32]; /* e.g. "Pacific Standard Time" */
  struct NtSystemTime StandardDate;
  int StandardBias;
  char16_t DaylightName[32]; /* e.g. "Pacific Daylight Time" */
  struct NtSystemTime DaylightDate;
  int DaylightBias; /* e.g. -60 */
};



/*!BEGIN libc/nt/struct/tokenprivileges.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TOKENPRIVILEGES_H_

struct NtTokenPrivileges {
  uint32_t PrivilegeCount;
  struct NtLuidAndAttributes Privileges[1];
};



/*!BEGIN libc/nt/struct/userstack.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTUSERSTACK_H_

struct NtUserStack {
  void *FixedStackBase;
  void *FixedStackLimit;
  void *ExpandableStackBase;
  void *ExpandableStackLimit;
  void *ExpandableStackBottom;
};



/*!BEGIN libc/nt/struct/valent.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VALENT_H_

struct NtValent {
  char16_t *ve_valuename;
  uint32_t ve_valuelen;
  uintptr_t ve_valueptr;
  uint32_t ve_type;
};



/*!BEGIN libc/nt/struct/win32fileattributedata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FILEATTRIBUTEDATA_H_

struct NtWin32FileAttributeData {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
};



/*!BEGIN libc/nt/struct/win32finddata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FINDDATA_H_

struct NtWin32FindData {
  uint32_t dwFileAttributes;
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t dwReserved0;
  uint32_t dwReserved1;
  char16_t cFileName[260];
  char16_t cAlternateFileName[14];
  uint32_t dwFileType;    /* obsolete */
  uint32_t dwCreatorType; /* obsolete */
  uint16_t wFinderFlags;  /* obsolete */
};



/*!BEGIN libc/nt/struct/windowplacement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WINDOWPLACEMENT_H_

struct NtWindowPlacement {
  uint32_t length;
  uint32_t flags;
  uint32_t showCmd;
  struct NtPoint ptMinPosition;
  struct NtPoint ptMaxPosition;
  struct NtRect rcNormalPosition;
  struct NtRect rcDevice;
};



/*!BEGIN libc/nt/struct/wndclass.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASS_H_


/*!BEGIN libc/nt/typedef/wndproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDPROC_H_
COSMOPOLITAN_C_START_

typedef int64_t (*NtWndProc)(int64_t, uint32_t, uint64_t, int64_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct NtWndClass {
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/wndclassex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASSEX_H_
COSMOPOLITAN_C_START_

struct NtWndClassEx {
  uint32_t cbSize;
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
  int64_t hIconSm;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/exceptionhandler.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_EXCEPTIONHANDLER_H_
COSMOPOLITAN_C_START_

typedef unsigned (*NtExceptionHandler)(struct NtExceptionRecord *,
                                       struct NtExceptionFrame *,
                                       struct NtContext *, void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/handlerroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HANDLERROUTINE_H_

typedef bool32 (*NtHandlerRoutine)(uint32_t);



/*!BEGIN libc/nt/typedef/hookproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HOOKPROC_H_

typedef intptr_t (*NtHookProc)(int code, uintptr_t wParam, intptr_t lParam);



/*!BEGIN libc/nt/typedef/imagetlscallback.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IMAGETLSCALLBACK_H_

typedef void (*NtImageTlsCallback)(void *DllHandle, uint32_t Reason,
                                   void *Reserved);



/*!BEGIN libc/nt/typedef/ioapcroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IOAPCROUTINE_H_

typedef void (*NtIoApcRoutine)(void *ApcContext,
                               struct NtIoStatusBlock *IoStatusBlock,
                               uint32_t Reserved);



/*!BEGIN libc/nt/typedef/pknormalroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_PKNORMALROUTINE_H_

typedef void (*NtPkNormalRoutine)(void *NormalContext, void *SystemArgument1,
                                  void *SystemArgument2);



/*!BEGIN libc/nt/typedef/timerproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_TIMERPROC_H_

typedef void (*NtTimerProc)(int64_t, uint32_t, uintptr_t, uint32_t);



/*!BEGIN libc/nt/typedef/wambda.h */

#define COSMOPOLITAN_LIBC_NT_WAMBDA_H_
COSMOPOLITAN_C_START_

typedef intptr_t (*wambda)();

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/wndenumproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDENUMPROC_H_

typedef int (*NtWndEnumProc)(int64_t foo, intptr_t bar);



/*!BEGIN libc/nt/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » debugging              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtContinue(struct NtContext *Context, int32_t TestAlert);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/file.h */

#define COSMOPOLITAN_LIBC_NT_NT_FILE_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtClose(int64_t handle);

NtStatus NtCreateFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                      const struct NtObjectAttributes *ObjectAttributes,
                      struct NtIoStatusBlock *out_IoStatusBlock,
                      int64_t *opt_AllocationSize, uint32_t FileAttributes,
                      uint32_t ShareAccess, uint32_t CreateDisposition,
                      uint32_t CreateOptions, void *opt_EaBuffer,
                      uint32_t EaLength);

NtStatus NtReadFile(int64_t FileHandle, void *opt_Event,
                    NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                    struct NtIoStatusBlock *out_IoStatusBlock, void *out_Buffer,
                    uint32_t Length, int64_t *opt_ByteOffset,
                    uint32_t *opt_Key);

NtStatus NtWriteFile(int64_t FileHandle, void *opt_Event,
                     NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                     struct NtIoStatusBlock *out_IoStatusBlock,
                     const void *Buffer, uint32_t Length,
                     int64_t *opt_ByteOffset, uint32_t *opt_Key);

NtStatus NtDuplicateObject(int64_t SourceProcessHandle, void *SourceHandle,
                           void *TargetProcessHandle,
                           void **opt_out_TargetHandle, uint32_t DesiredAcess,
                           uint32_t Attributes, uint32_t options_t);

NtStatus NtQueryInformationFile(int64_t FileHandle,
                                struct NtIoStatusBlock *out_IoStatusBlock,
                                void *out_FileInformation,
                                uint32_t FileInformationLength,
                                uint32_t FileInformationClass);

NtStatus NtSetInformationFile(int64_t FileHandle,
                              struct NtIoStatusBlock *out_IoStatusBlock,
                              void *FileInformation,
                              uint32_t FileInformationLength,
                              uint32_t FileInformationClass);

NtStatus NtDeviceIoControlFile(
    int64_t FileHandle, int64_t opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    uint32_t IoControlCode, void *opt_InputBuffer, uint32_t InputBufferLength,
    void *opt_out_OutputBuffer, uint32_t OutputBufferLength);

NtStatus NtCancelIoFileEx(int64_t FileHandle,
                          struct NtIoStatusBlock *IoRequestToCancel,
                          struct NtIoStatusBlock *IoStatusBlock);

NtStatus RtlNtStatusToDosError(NtStatus Status);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntfile.inc */

#define NtQueryInformationFile(...) __imp_NtQueryInformationFile(__VA_ARGS__)

extern typeof(NtQueryInformationFile) *const
    __imp_NtQueryInformationFile __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_NT_IPC_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » ipc                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtCreateNamedPipeFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes,
                               struct NtIoStatusBlock *out_IoStatusBlock,
                               uint32_t ShareAccess, uint32_t CreateDisposition,
                               uint32_t CreateOptions, int32_t TypeMessage,
                               int32_t ReadmodeMessage, int32_t Nonblocking,
                               uint32_t MaxInstances, uint32_t InBufferSize,
                               uint32_t OutBufferSize,
                               int64_t *opt_DefaultTimeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/key.h */

#define COSMOPOLITAN_LIBC_NT_NT_EVENT_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtCreateKeyedEvent(int64_t *KeyedEventHandle, uint32_t DesiredAccess,
                            struct NtObjectAttributes *ObjectAttributes,
                            uint32_t Flags);

NtStatus NtReleaseKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

NtStatus NtWaitForKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/loader.h */

#define COSMOPOLITAN_LIBC_NT_NT_LOADER_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » loader                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtAnsiString;
struct NtLdrDataTableEntry;
struct NtUnicodeString;

NtStatus LdrLoadDll(const char16_t *opt_PathToFile, uint32_t *opt_Flags,
                    struct NtUnicodeString *ModuleFileName,
                    void **out_ModuleHandle);
NtStatus LdrUnloadDll(void *ModuleHandle);
NtStatus LdrGetProcedureAddress(void *ModuleHandle,
                                struct NtAnsiString *opt_ProcedureName,
                                uint32_t opt_Ordinal,
                                wambda *out_ProcedureAddress);
NtStatus LdrGetDllHandle(const char16_t *opt_PathToFile, uint32_t opt_Unused,
                         struct NtUnicodeString *ModuleFileName,
                         void **out_ModuleHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_NT_MEMORY_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » memory                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtAllocateVirtualMemory(int64_t ProcessHandle,
                                 void **inout_BaseAddress, uint32_t dwZeroBits,
                                 uint32_t *inout_AllocationSize,
                                 uint32_t dwMemAllocationType,
                                 uint32_t dwPageProtect);
NtStatus NtFreeVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                             size_t *inout_FreeSize, uint32_t FreeType);
NtStatus NtQueryVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                              int MemoryInformationClass,
                              void *out_MemoryInformation,
                              size_t MemoryInformationLength,
                              size_t *opt_out_ReturnLength);
NtStatus NtProtectVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                                uint32_t *inout_ProtectSize,
                                uint32_t NewProtect, uint32_t *out_OldProtect);
NtStatus NtWriteVirtualMemory(int64_t ProcessHandle, void *BaseAddress,
                              const void *Buffer, size_t BufferLength,
                              size_t *opt_out_ReturnLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_NT_PROCESS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » processes              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtObjectAttributes;
struct NtRtlUserProcessInformation;
struct NtRtlUserProcessParameters;
struct NtSecurityDescriptor;
struct NtUnicodeString;

NtStatus NtCreateProcess(int64_t *out_ProcessHandle, uint32_t dwDesiredAccess,
                         struct NtObjectAttributes *opt_ObjectAttributes,
                         void *InheritFromProcessHandle, int32_t InheritHandles,
                         void *opt_SectionHandle, void *opt_DebugPort,
                         void *opt_ExceptionPort);
NtStatus NtTerminateProcess(int64_t opt_ProcessHandle, int32_t ExitStatus);

NtStatus NtQueryInformationProcess(int64_t ProcessHandle,
                                   int ProcessInformationClass,
                                   void *out_ProcessInformation,
                                   uint32_t ProcessInformationLength,
                                   uint32_t *opt_out_ReturnLength);
NtStatus NtOpenProcessToken(int64_t ProcessToken, uint32_t DesiredAccess,
                            int64_t *out_TokenHandle);
NtStatus NtOpenProcess(int64_t *out_ProcessHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       struct NtClientId *ClientId);

NtStatus RtlCreateProcessParameters(
    struct NtRtlUserProcessParameters **out_ProcessParameters,
    struct NtUnicodeString *ImageFile, struct NtUnicodeString *opt_DllPath,
    struct NtUnicodeString *opt_CurrentDirectory,
    struct NtUnicodeString *opt_CommandLine, uint32_t CreationFlags,
    struct NtUnicodeString *opt_WindowTitle,
    struct NtUnicodeString *opt_Desktop, struct NtUnicodeString *opt_Reserved,
    struct NtUnicodeString *opt_Reserved2);

NtStatus RtlDestroyProcessParameters(
    struct NtRtlUserProcessParameters *ProcessParameters);

NtStatus RtlCloneUserProcess(
    uint32_t ProcessFlags,
    struct NtSecurityDescriptor *opt_ProcessSecurityDescriptor,
    struct NtSecurityDescriptor *opt_ThreadSecurityDescriptor,
    void *opt_DebugPort,
    struct NtRtlUserProcessInformation *ProcessInformation);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/process.inc */

#define NtQueryInformationProcess(...) \
  __imp_NtQueryInformationProcess(__VA_ARGS__)

extern typeof(NtQueryInformationProcess) *const
    __imp_NtQueryInformationProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/sections.h */

#define COSMOPOLITAN_LIBC_NT_NT_SECTIONS_H_
COSMOPOLITAN_C_START_

NtStatus NtCreateSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                         struct NtObjectAttributes *ObjectAttributes,
                         int64_t *opt_SectionSize, uint32_t Protect,
                         uint32_t Attributes, int64_t FileHandle);
NtStatus NtOpenSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes);
NtStatus NtMapViewOfSection(int64_t SectionHandle, int64_t ProcessHandle,
                            void **inout_BaseAddress, uint32_t *ZeroBits,
                            size_t CommitSize, int64_t *opt_inout_SectionOffset,
                            size_t *inout_ViewSize, int InheritDisposition,
                            uint32_t AllocationType, uint32_t Protect);
NtStatus NtUnmapViewOfSection(int64_t ProcessHandle, void *BaseAddress);
NtStatus NtQuerySection(int64_t SectionHandle, int SectionInformationClass,
                        void *out_SectionInformation,
                        uint32_t SectionInformationLength,
                        uint32_t *opt_out_ResultLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/signing.h */

#define COSMOPOLITAN_LIBC_NT_NT_SIGNING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » code signing           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus CsrClientCallServer(void *inout_Message, void *unknown,
                             uint32_t Opcode, uint32_t Size);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » threads                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtContext;
struct NtObjectAttributes;
struct NtUserStack;

NtStatus NtCreateThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                        struct NtObjectAttributes *ObjectAttributes,
                        int64_t ProcessHandle, struct NtClientId *out_ClientId,
                        struct NtContext *ThreadContext,
                        struct NtUserStack *UserStack, int32_t CreateSuspended);

NtStatus NtTerminateThread(void *opt_ThreadHandle, int32_t ExitStatus);

NtStatus NtOpenThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                      struct NtObjectAttributes *ObjectAttributes,
                      struct NtClientId *ClientId);

NtStatus NtQueryInformationThread(int64_t ThreadHandle,
                                  enum NtThreadInfoClass ThreadInformationClass,
                                  void *out_ThreadInformation,
                                  uint32_t ThreadInformationLength,
                                  uint32_t *opt_out_ReturnLength);

NtStatus NtGetContextThread(int64_t ThreadHandle,
                            struct NtContext *out_Context);
NtStatus NtSetContextThread(int64_t ThreadHandle, struct NtContext *Context);
NtStatus NtSuspendThread(int64_t ThreadHandle,
                         uint32_t *opt_out_PreviousSuspendCount);
NtStatus NtResumeThread(int64_t ThreadHandle,
                        uint32_t *opt_out_PreviousSuspendCount);

NtStatus NtOpenThreadToken(int64_t ThreadHandle, uint32_t DesiredAccess,
                           int32_t OpenAsSelf, int64_t *out_TokenHandle);

NtStatus NtSetInformationThread(int64_t ThreadHandle,
                                enum NtThreadInfoClass ThreadInformationClass,
                                void *ThreadInformation,
                                uint32_t ThreadInformationLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » time                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtDelayExecution(bool32 alertable, int64_t *AbsCobolOrNegRelHectoNano);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/time.inc */

#define NtDelayExecution(...) __imp_NtDelayExecution(__VA_ARGS__)

extern typeof(NtDelayExecution) *const __imp_NtDelayExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/accounting.h */

#define COSMOPOLITAN_LIBC_NT_ACCOUNTING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » accounting                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetMaximumProcessorCount(uint16_t GroupNumber);
int GetUserName(char16_t (*buf)[257], uint32_t *in_out_size);
bool32 GlobalMemoryStatusEx(struct NtMemoryStatusEx *lpBuffer);
int32_t GetExitCodeProcess(int64_t hProcess, uint32_t *lpExitCode);
int32_t GetProcessHandleCount(int64_t hProcess, uint32_t *pdwHandleCount);
bool32 GetSystemTimes(struct NtFileTime *opt_out_lpIdleTime,
                      struct NtFileTime *opt_out_lpKernelTime,
                      struct NtFileTime *opt_out_lpUserTime);
bool32 GetProcessTimes(int64_t hProcess,
                       struct NtFileTime *out_lpCreationFileTime,
                       struct NtFileTime *out_lpExitFileTime,
                       struct NtFileTime *out_lpKernelFileTime,
                       struct NtFileTime *out_lpUserFileTime);
bool32 GetThreadTimes(int64_t hThread,
                      struct NtFileTime *out_lpCreationFileTime,
                      struct NtFileTime *out_lpExitFileTime,
                      struct NtFileTime *out_lpKernelFileTime,
                      struct NtFileTime *out_lpUserFileTime);
int32_t GetProcessIoCounters(int64_t hProcess,
                             struct NtIoCounters *lpIoCounters);
int32_t GetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t *lpMinimumWorkingSetSize,
                                 uint64_t *lpMaximumWorkingSetSize);
int32_t GetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t *lpMinimumWorkingSetSize,
                                   uint64_t *lpMaximumWorkingSetSize,
                                   uint32_t *Flags);
int32_t SetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t dwMinimumWorkingSetSize,
                                 uint64_t dwMaximumWorkingSetSize);
int32_t SetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t dwMinimumWorkingSetSize,
                                   uint64_t dwMaximumWorkingSetSize,
                                   uint32_t Flags);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/accounting.inc */

#define GetProcessTimes(...) __imp_GetProcessTimes(__VA_ARGS__)
extern typeof(GetProcessTimes) *const __imp_GetProcessTimes __msabi;

#define GetThreadTimes(...) __imp_GetThreadTimes(__VA_ARGS__)
extern typeof(GetThreadTimes) *const __imp_GetThreadTimes __msabi;

#define GetUserName(...) __imp_GetUserNameW(__VA_ARGS__)
extern typeof(GetUserName) *const __imp_GetUserNameW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/automation.h */

#define COSMOPOLITAN_LIBC_NT_AUTOMATION_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » aol hacking                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int64_t GetShellWindow(void);
int64_t GetDesktopWindow(void);
int64_t GetParent(int64_t hWnd);
int64_t SetParent(int64_t hWndChild, int64_t hWndNewParent);
int32_t EnumChildWindows(int64_t hWndParent, NtWndEnumProc lpEnumFunc,
                         intptr_t lParam);
int64_t FindWindow(const char16_t *lpClassName, const char16_t *lpWindowName);
int64_t FindWindowEx(int64_t hWndParent, int64_t hWndChildAfter,
                     const char16_t *lpszClass, const char16_t *lpszWindow);
int64_t GetWindow(int64_t hWnd, uint32_t uCmd);
int64_t SetWindowsHook(int nFilterType, NtHookProc pfnFilterProc);
int32_t UnhookWindowsHook(int nCode, NtHookProc pfnFilterProc);
int64_t SetWindowsHookEx(int idHook, NtHookProc lpfn, int64_t hmod,
                         uint32_t dwThreadId);
int32_t UnhookWindowsHookEx(int64_t hhk);
intptr_t CallNextHookEx(int64_t hhk, int nCode, uintptr_t wParam,
                        intptr_t lParam);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/codegen.h */

#define COSMOPOLITAN_LIBC_NT_CODEGEN_H_


/*!BEGIN libc/nt/comdlg.h */

#define COSMOPOLITAN_LIBC_NT_COMDLG_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » common dialogs                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 GetOpenFileName(struct NtOpenFilename *arg);
bool32 GetSaveFileName(struct NtOpenFilename *arg);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/comms.h */

#define COSMOPOLITAN_LIBC_NT_COMMS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » communications                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

bool32 PurgeComm(int64_t hFile, uint32_t dwFlags);
bool32 TransmitCommChar(int64_t hFile, char cChar);
bool32 ClearCommBreak(int64_t hFile);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/console.h */

#define COSMOPOLITAN_LIBC_NT_CONSOLE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » console                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtAttachParentProcess -1u

COSMOPOLITAN_C_START_

bool32 WriteConsoleOutput(int64_t hConsoleOutput,
                          const struct NtCharInfo *lpBuffer,
                          struct NtCoord dwBufferSize,
                          struct NtCoord dwBufferCoord,
                          struct NtSmallRect *lpWriteRegion);
bool32 ReadConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 PeekConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 GetNumberOfConsoleInputEvents(int64_t hConsoleInput,
                                     uint32_t *lpNumberOfEvents);
bool32 ReadConsoleOutput(int64_t hConsoleOutput, struct NtCharInfo *lpBuffer,
                         struct NtCoord dwBufferSize,
                         struct NtCoord dwBufferCoord,
                         struct NtSmallRect *lpReadRegion);
bool32 WriteConsoleInput(int64_t hConsoleInput,
                         const struct NtInputRecord *lpBuffer, uint32_t nLength,
                         uint32_t *lpNumberOfEventsWritten);
bool32 FlushConsoleInputBuffer(int64_t hConsoleInput);

int64_t GetConsoleWindow(void);
bool32 GetConsoleMode(int64_t hConsoleHandle, uint32_t *lpMode);
bool32 SetConsoleMode(int64_t hConsoleHandle, uint32_t dwMode);
int32_t AllocConsole(void);
int32_t FreeConsole(void);
int32_t AttachConsole(uint32_t dwProcessId);
uint32_t GetConsoleTitle(char16_t *lpConsoleTitle, uint32_t nSize);
int32_t SetConsoleTitle(const char16_t *lpConsoleTitle);
bool32 GetConsoleScreenBufferInfo(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfo *out_lpConsoleScreenBufferInfo);
bool32 GetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfoEx *in_out_lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    const struct NtConsoleScreenBufferInfoEx *lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferSize(int64_t lpConsoleOutput,
                                  struct NtCoord dwSize);
struct NtCoord GetLargestConsoleWindowSize(int64_t hConsoleHandle);
int32_t ReadConsole(int64_t hConsoleInput, void *lpBuffer,
                    uint32_t nNumberOfCharsToRead,
                    uint32_t *lpNumberOfCharsRead, void *lpReserved);
int32_t WriteConsole(int64_t hConsoleOutput, const void *lpBuffer,
                     uint32_t nNumberOfCharsToWrite,
                     uint32_t *lpNumberOfCharsWritten, void *lpReserved)
    paramsnonnull((2, 4));
bool32 GetNumberOfConsoleMouseButtons(uint32_t *out_lpNumberOfMouseButtons)
    paramsnonnull();
bool32 GetConsoleSelectionInfo(
    struct NtConsoleSelectionInfo *out_lpConsoleSelectionInfo);
uint32_t WaitForInputIdle(int64_t hProcess, uint32_t dwMilliseconds);
uint32_t GetConsoleCP(void);
bool32 SetConsoleCP(uint32_t wCodePageID);
bool32 SetConsoleOutputCP(uint32_t wCodePageID);
uint32_t GetConsoleOutputCP(void);
bool32 SetConsoleCtrlHandler(NtHandlerRoutine opt_HandlerRoutine, bool32 Add);
bool32 GenerateConsoleCtrlEvent(uint32_t dwCtrlEvent,
                                uint32_t dwProcessGroupId);

bool32 GetConsoleCursorInfo(
    int64_t hConsoleOutput,
    struct NtConsoleCursorInfo *out_lpConsoleCursorInfo);
bool32 SetConsoleCursorInfo(
    int64_t hConsoleOutput,
    const struct NtConsoleCursorInfo *lpConsoleCursorInfo);

long CreatePseudoConsole(struct NtCoord size, int64_t hInput, int64_t hOutput,
                         uint32_t dwFlags, int64_t *out_phPC);
long ResizePseudoConsole(int64_t hPC, struct NtCoord size);
void ClosePseudoConsole(int64_t hPC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/console.inc */

#define GetConsoleMode(...) __imp_GetConsoleMode(__VA_ARGS__)
extern typeof(GetConsoleMode) *const __imp_GetConsoleMode __msabi;

#define SetConsoleCP(...) __imp_SetConsoleCP(__VA_ARGS__)
extern typeof(SetConsoleCP) *const __imp_SetConsoleCP __msabi;

#define GetConsoleCP(...) __imp_GetConsoleCP(__VA_ARGS__)
extern typeof(GetConsoleCP) *const __imp_GetConsoleCP __msabi;

#define SetConsoleCtrlHandler(...) __imp_SetConsoleCtrlHandler(__VA_ARGS__)
extern typeof(SetConsoleCtrlHandler) *const __imp_SetConsoleCtrlHandler __msabi;

#define SetConsoleMode(...) __imp_SetConsoleMode(__VA_ARGS__)
extern typeof(SetConsoleMode) *const __imp_SetConsoleMode __msabi;

#define SetConsoleOutputCP(...) __imp_SetConsoleOutputCP(__VA_ARGS__)
extern typeof(SetConsoleOutputCP) *const __imp_SetConsoleOutputCP __msabi;

#define GetConsoleOutputCP(...) __imp_GetConsoleOutputCP(__VA_ARGS__)
extern typeof(GetConsoleOutputCP) *const __imp_GetConsoleOutputCP __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/createfile.h */

#define COSMOPOLITAN_LIBC_NT_CREATEFILE_H_
COSMOPOLITAN_C_START_

int64_t CreateFile(
    const char16_t *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int64_t CreateFileA(
    const char *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int GetNtOpenFlags(int, int, uint32_t *, uint32_t *, uint32_t *, uint32_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » debugging                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* Some of these APIs were moved to system.h and libc.h */
int32_t DebugBreakProcess(void *Process);
int32_t DebugActiveProcess(uint32_t dwProcessId);
int32_t DebugActiveProcessStop(uint32_t dwProcessId);
int32_t CheckRemoteDebuggerPresent(int64_t hProcess, int *pbDebuggerPresent);
int32_t ContinueDebugEvent(uint32_t dwProcessId, uint32_t dwThreadId,
                           uint32_t dwContinueStatus);
void FatalExit(int uExitCode);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/dll.h */

#define COSMOPOLITAN_LIBC_NT_DLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » dynamic link libraries                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t LoadLibrary(const char16_t *lpLibFileName);
int64_t LoadLibraryA(const char *lpLibFileName);
int64_t LoadLibraryEx(const char16_t *lpLibFileName, int64_t hFile,
                      uint32_t dwFlags);
uint32_t GetModuleFileNameA(int64_t hModule, char *lpFilename, uint32_t nSize);
intptr_t GetModuleHandle(const char *opt_lpModuleName);
intptr_t GetModuleHandleW(const char16_t *opt_lpModuleName);
void *GetProcAddress(int64_t hModule, const char *lpProcName);
int32_t FreeResource(int64_t hResData);
intptr_t LockResource(int64_t hResData);
int32_t FreeLibrary(int64_t hLibModule);
void *AddDllDirectory(const char16_t *NewDirectory);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/efi.h */

#define COSMOPOLITAN_LIBC_NT_EFI_H_
/*
    ▐██ ░█████████▓   ▐██▌     ██▓░   ▐█▌  ▐██  ░██░    ▓█▌  ▓██▒     ▓██
    ▐██     ░██░     ▒█▓██░    ████░  ▐█▌  ▐██  ░██░    ▓█▌  ▓███░   ▓███
    ▐██     ░██░     ██░▐█▓    ██▒▓█░ ▐█▌  ▐██  ░██░    ▓█▌  ▓█▌▓█░ ▓█▒██
    ▐██     ░██░    ▐█▌  ▓█▌   ██░░▓█░▐█▌  ▐██  ░██░    ▓█▌  ▓█▌░█▓▓█▒░██
    ▐██     ░██░   ▒██▓█████░  ██░ ░▓▓▓█▌  ▐██  ░██░    ██░  ▓█▌ ░██▌ ░██
    ▐██     ░██░   ▓█▌    ▓█▓  ██░  ░███▌  ▐██   ▐██▄▄▄▓█▓   ▓█▌      ░██
╔────────────────────────────────────────────────────────────────────────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § the unified extensible firmware interface ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define EFI_SUCCESS           0x8000000000000000
#define EFI_LOAD_ERROR        0x8000000000000001
#define EFI_INVALID_PARAMETER 0x8000000000000002
#define EFI_UNSUPPORTED       0x8000000000000003
#define EFI_BAD_BUFFER_SIZE   0x8000000000000004
#define EFI_BUFFER_TOO_SMALL  0x8000000000000005
#define EFI_NOT_READY         0x8000000000000006
#define EFI_DEVICE_ERROR      0x8000000000000007
#define EFI_WRITE_PROTECTED   0x8000000000000008
#define EFI_OUT_OF_RESOURCES  0x8000000000000009
#define EFI_VOLUME_CORRUPTED  0x800000000000000a
#define EFI_VOLUME_FULL       0x800000000000000b
#define EFI_NO_MEDIA          0x800000000000000c
#define EFI_MEDIA_CHANGED     0x800000000000000d
#define EFI_NOT_FOUND         0x800000000000000e
#define EFI_ACCESS_DENIED     0x800000000000000f
#define EFI_NO_RESPONSE       0x8000000000000010
#define EFI_NO_MAPPING        0x8000000000000011
#define EFI_TIMEOUT           0x8000000000000012
#define EFI_NOT_STARTED       0x8000000000000013
#define EFI_ALREADY_STARTED   0x8000000000000014
#define EFI_ABORTED           0x8000000000000015
#define EFI_ICMP_ERROR        0x8000000000000016
#define EFI_TFTP_ERROR        0x8000000000000017
#define EFI_PROTOCOL_ERROR    0x8000000000000018

#define EFI_VARIABLE_NON_VOLATILE                          0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS                    0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS                        0x00000004
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD                 0x00000008
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS            0x00000010
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
#define EFI_VARIABLE_APPEND_WRITE                          0x00000040

#define EFI_MEMORY_UC            0x0000000000000001U
#define EFI_MEMORY_WC            0x0000000000000002U
#define EFI_MEMORY_WT            0x0000000000000004U
#define EFI_MEMORY_WB            0x0000000000000008U
#define EFI_MEMORY_UCE           0x0000000000000010U
#define EFI_MEMORY_WP            0x0000000000001000U
#define EFI_MEMORY_RP            0x0000000000002000U
#define EFI_MEMORY_XP            0x0000000000004000U
#define EFI_MEMORY_RO            0x0000000000020000U
#define EFI_MEMORY_NV            0x0000000000008000U
#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000U
#define EFI_MEMORY_RUNTIME       0x8000000000000000U

#define EFI_OPTIONAL_PTR 0x00000001

#define EFI_SCAN_NULL      0x0000
#define EFI_SCAN_UP        0x0001
#define EFI_SCAN_DOWN      0x0002
#define EFI_SCAN_RIGHT     0x0003
#define EFI_SCAN_LEFT      0x0004
#define EFI_SCAN_HOME      0x0005
#define EFI_SCAN_END       0x0006
#define EFI_SCAN_INSERT    0x0007
#define EFI_SCAN_DELETE    0x0008
#define EFI_SCAN_PAGE_UP   0x0009
#define EFI_SCAN_PAGE_DOWN 0x000A
#define EFI_SCAN_F1        0x000B
#define EFI_SCAN_F2        0x000C
#define EFI_SCAN_F3        0x000D
#define EFI_SCAN_F4        0x000E
#define EFI_SCAN_F5        0x000F
#define EFI_SCAN_F6        0x0010
#define EFI_SCAN_F7        0x0011
#define EFI_SCAN_F8        0x0012
#define EFI_SCAN_F9        0x0013
#define EFI_SCAN_F10       0x0014
#define EFI_SCAN_ESC       0x0017

#define EFI_EVT_TIMER                         0x80000000
#define EFI_EVT_RUNTIME                       0x40000000
#define EFI_EVT_NOTIFY_WAIT                   0x00000100
#define EFI_EVT_NOTIFY_SIGNAL                 0x00000200
#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES     0x00000201
#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
#define EFI_EVT_RUNTIME_CONTEXT               0x20000000

#define LOADED_IMAGE_PROTOCOL                        \
  {                                                  \
    0x5B1B31A1, 0x9562, 0x11d2, {                    \
      0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \
    }                                                \
  }
#define GRAPHICS_OUTPUT_PROTOCOL                     \
  {                                                  \
    0x9042A9DE, 0x23DC, 0x4A38, {                    \
      0x96, 0xFB, 0x7A, 0xDE, 0xD0, 0x80, 0x51, 0x6A \
    }                                                \
  }
#define ACPI_20_TABLE_GUID                           \
  {                                                  \
    0x8868E871, 0xE4F1, 0x11D3, {                    \
      0xBC, 0x22, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 \
    }                                                \
  }
#define ACPI_10_TABLE_GUID                           \
  {                                                  \
    0xEB9D2D30, 0x2D88, 0x11D3, {                    \
      0x9A, 0x16, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D \
    }                                                \
  }

COSMOPOLITAN_C_START_

#if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__chibicc__) && \
    defined(__x86_64__)
#define EFIAPI __attribute__((__ms_abi__))
#else
#define EFIAPI /* TODO(jart): fix me */
#endif

#define EFI_STATUS uint64_t
#define EFI_EVENT  uintptr_t
#define EFI_HANDLE uintptr_t

typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
typedef struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL;

typedef enum {
  EfiReservedMemoryType,
  EfiLoaderCode,
  EfiLoaderData,
  EfiBootServicesCode,
  EfiBootServicesData,
  EfiRuntimeServicesCode,
  EfiRuntimeServicesData,
  EfiConventionalMemory,
  EfiUnusableMemory,
  EfiACPIReclaimMemory,
  EfiACPIMemoryNVS,
  EfiMemoryMappedIO,
  EfiMemoryMappedIOPortSpace,
  EfiPalCode,
  EfiPersistentMemory,
  EfiMaxMemoryType
} EFI_MEMORY_TYPE;

typedef enum {
  EfiResetCold,
  EfiResetWarm,
  EfiResetShutdown,
  EfiResetPlatformSpecific
} EFI_RESET_TYPE;

typedef enum {
  AllocateAnyPages,
  AllocateMaxAddress,
  AllocateAddress,
  MaxAllocateType
} EFI_ALLOCATE_TYPE;

typedef enum {
  TimerCancel,
  TimerPeriodic,
  TimerRelative,
} EFI_TIMER_DELAY;

typedef struct {
  uint32_t Resolution;
  uint32_t Accuracy;
  bool32 SetsToZero;
} EFI_TIME_CAPABILITIES;

typedef struct {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
} EFI_GUID;

typedef struct {
  uint16_t Year;
  uint8_t Month;
  uint8_t Day;
  uint8_t Hour;
  uint8_t Minute;
  uint8_t Second;
  uint8_t Pad1;
  uint32_t Nanosecond;
  int16_t TimeZone;
  uint8_t Daylight;
  uint8_t Pad2;
} EFI_TIME;

typedef struct {
  uint32_t Type;
  uint64_t PhysicalStart;
  uint64_t VirtualStart;
  uint64_t NumberOfPages;
  uint64_t Attribute;
} EFI_MEMORY_DESCRIPTOR;

typedef struct {
  EFI_GUID VendorGuid;
  void *VendorTable;
} EFI_CONFIGURATION_TABLE;

typedef struct {
  EFI_GUID CapsuleGuid;
  uint32_t HeaderSize;
  uint32_t Flags;
  uint32_t CapsuleImageSize;
} EFI_CAPSULE_HEADER;

typedef struct {
  uint16_t ScanCode;
  char16_t UnicodeChar;
} EFI_INPUT_KEY;

typedef struct {
  int32_t MaxMode;
  int32_t Mode;
  int32_t Attribute;
  int32_t CursorColumn;
  int32_t CursorRow;
  bool32 CursorVisible;
} EFI_SIMPLE_TEXT_OUTPUT_MODE;

typedef enum {
  PixelRedGreenBlueReserved8BitPerColor,
  PixelBlueGreenRedReserved8BitPerColor,
  PixelBitMask,
  PixelBltOnly,
  PixelFormatMax
} EFI_GRAPHICS_PIXEL_FORMAT;

typedef struct {
  uint32_t RedMask;
  uint32_t GreenMask;
  uint32_t BlueMask;
  uint32_t ReservedMask;
} EFI_PIXEL_BITMASK;

typedef struct {
  uint32_t Version;
  uint32_t HorizontalResolution;
  uint32_t VerticalResolution;
  EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
  EFI_PIXEL_BITMASK PixelInformation;
  uint32_t PixelsPerScanLine;
} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;

typedef struct {
  uint8_t Blue;
  uint8_t Green;
  uint8_t Red;
  uint8_t Reserved;
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;

typedef enum {
  EfiBltVideoFill,
  EfiBltVideoToBltBuffer,
  EfiBltBufferToVideo,
  EfiBltVideoToVideo,
  EfiGraphicsOutputBltOperationMax
} EFI_GRAPHICS_OUTPUT_BLT_OPERATION;

typedef struct {
  uint32_t MaxMode;
  uint32_t Mode;
  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
  uint32_t SizeOfInfo;
  uint64_t FrameBufferBase;
  uint32_t FrameBufferSize;
} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;

typedef struct {
  uint64_t Signature;
  uint32_t Revision;
  uint32_t HeaderSize;
  uint32_t CRC32;
  uint32_t Reserved;
} EFI_TABLE_HEADER;

typedef struct {
  uint8_t Type;
  uint8_t SubType;
  uint8_t Length[2];
} EFI_DEVICE_PATH_PROTOCOL;

typedef EFI_STATUS(EFIAPI *EFI_EXIT)(EFI_HANDLE ImageHandle,
                                     EFI_STATUS ExitStatus,
                                     uintptr_t ExitDataSize,
                                     char16_t *opt_ExitData);

typedef EFI_STATUS(EFIAPI *EFI_GET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t *outopt_Attributes,
                                             uintptr_t *inout_DataSize,
                                             void *outopt_Data);
typedef EFI_STATUS(EFIAPI *EFI_SET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t Attributes,
                                             uintptr_t DataSize, void *Data);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME)(
    uintptr_t *inout_VariableNameSize, char16_t *inout_VariableName,
    EFI_GUID *inout_VendorGuid);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_VARIABLE_INFO)(
    uint32_t Attributes, uint64_t *out_MaximumVariableStorageSize,
    uint64_t *out_RemainingVariableStorageSize,
    uint64_t *out_MaximumVariableSize);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_PAGES)(EFI_ALLOCATE_TYPE Type,
                                               EFI_MEMORY_TYPE MemoryType,
                                               uintptr_t Pages,
                                               uint64_t *inout_Memory);
typedef EFI_STATUS(EFIAPI *EFI_FREE_PAGES)(uint64_t Memory, uintptr_t Pages);
typedef EFI_STATUS(EFIAPI *EFI_GET_MEMORY_MAP)(
    uintptr_t *inout_MemoryMapSize, EFI_MEMORY_DESCRIPTOR *inout_MemoryMap,
    uintptr_t *out_MapKey, uintptr_t *out_DescriptorSize,
    uint32_t *out_DescriptorVersion);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_POOL)(EFI_MEMORY_TYPE PoolType,
                                              uintptr_t Size, void *out_Buffer);
typedef EFI_STATUS(EFIAPI *EFI_FREE_POOL)(void *Buffer);
typedef void(EFIAPI *EFI_SET_MEM)(void *Buffer, uintptr_t Size, uint8_t Value);
typedef void(EFIAPI *EFI_COPY_MEM)(void *Destination, void *Source,
                                   uintptr_t Length);

typedef EFI_STATUS(EFIAPI *EFI_CHECK_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_CLOSE_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_SIGNAL_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_WAIT_FOR_EVENT)(uintptr_t NumberOfEvents,
                                               EFI_EVENT *Events,
                                               uintptr_t *out_Index);
typedef EFI_STATUS(EFIAPI *EFI_SET_TIMER)(EFI_EVENT Event, EFI_TIMER_DELAY Type,
                                          uint64_t TriggerTime);
typedef void(EFIAPI *EFI_EVENT_NOTIFY)(EFI_EVENT Event, void *Context);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT)(uint32_t Type, uintptr_t NotifyTpl,
                                             EFI_EVENT_NOTIFY NotifyFunction,
                                             void *NotifyContext,
                                             EFI_EVENT *out_Event);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT_EX)(
    uint32_t Type, uintptr_t NotifyTpl, EFI_EVENT_NOTIFY opt_NotifyFunction,
    const void *opt_NotifyContext, const EFI_GUID *opt_EventGroup,
    EFI_EVENT *out_Event);

typedef EFI_STATUS(EFIAPI *EFI_UPDATE_CAPSULE)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t opt_ScatterGatherList);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t *out_MaximumCapsuleSize, EFI_RESET_TYPE *out_ResetType);
typedef EFI_STATUS(EFIAPI *EFI_GET_WAKEUP_TIME)(bool32 *out_Enabled,
                                                bool32 *out_Pending,
                                                EFI_TIME *out_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WAKEUP_TIME)(bool32 Enable,
                                                EFI_TIME *opt_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WATCHDOG_TIMER)(uintptr_t Timeout,
                                                   uint64_t WatchdogCode,
                                                   uintptr_t DataSize,
                                                   char16_t *opt_WatchdogData);
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)(EFI_GUID *Protocol,
                                                void *Registration,
                                                void *Interface);

typedef EFI_STATUS(EFIAPI *EFI_SET_TIME)(EFI_TIME *Time);
typedef EFI_STATUS(EFIAPI *EFI_GET_TIME)(
    EFI_TIME *out_Time, EFI_TIME_CAPABILITIES *outopt_Capabilities);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT)(
    uint32_t *out_HighCount);
typedef EFI_STATUS(EFIAPI *EFI_STALL)(uintptr_t Microseconds);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT)(uint64_t *out_Count);

typedef EFI_STATUS(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP)(
    uintptr_t MemoryMapSize, uintptr_t DescriptorSize,
    uint32_t DescriptorVersion, EFI_MEMORY_DESCRIPTOR *VirtualMap);
typedef void(EFIAPI *EFI_RESET_SYSTEM)(EFI_RESET_TYPE ResetType,
                                       EFI_STATUS ResetStatus,
                                       uintptr_t DataSize, void *opt_ResetData);
typedef EFI_STATUS(EFIAPI *EFI_CONVERT_POINTER)(uintptr_t DebugDisposition,
                                                void **inout_Address);

typedef EFI_STATUS(EFIAPI *EFI_INPUT_RESET)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_INPUT_READ_KEY)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, EFI_INPUT_KEY *out_Key);

typedef EFI_STATUS(EFIAPI *EFI_TEXT_RESET)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_TEST_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_QUERY_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber,
    uint64_t *out_Columns, uint64_t *out_Rows);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_ATTRIBUTE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Attribute);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_CLEAR_SCREEN)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_CURSOR_POSITION)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Column, uint64_t Row);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_ENABLE_CURSOR)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 Visible);

typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber,
    uint32_t *SizeOfInfo, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
    EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
    EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, uint32_t SourceX,
    uint32_t SourceY, uint32_t DestinationX, uint32_t DestinationY,
    uint32_t Width, uint32_t Height, uint32_t Delta);

typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(EFI_HANDLE Handle,
                                                EFI_GUID *Protocol,
                                                void *out_Interface);

typedef EFI_STATUS(EFIAPI *EFI_IMAGE_LOAD)(bool32 BootPolicy,
                                           EFI_HANDLE ParentImageHandle,
                                           EFI_DEVICE_PATH_PROTOCOL *DevicePath,
                                           void *opt_SourceBuffer,
                                           uintptr_t SourceSize,
                                           EFI_HANDLE *out_ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_UNLOAD)(EFI_HANDLE ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_EXIT_BOOT_SERVICES)(EFI_HANDLE ImageHandle,
                                                   uintptr_t MapKey);

typedef struct {
  EFI_TABLE_HEADER Hdr;
  EFI_GET_TIME GetTime;
  EFI_SET_TIME SetTime;
  EFI_GET_WAKEUP_TIME GetWakeupTime;
  EFI_SET_WAKEUP_TIME SetWakeupTime;
  EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap;
  EFI_CONVERT_POINTER ConvertPointer;
  EFI_GET_VARIABLE GetVariable;
  EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName;
  EFI_SET_VARIABLE SetVariable;
  EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount;
  EFI_RESET_SYSTEM ResetSystem;
  EFI_UPDATE_CAPSULE UpdateCapsule;
  EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;
  EFI_QUERY_VARIABLE_INFO QueryVariableInfo;
} EFI_RUNTIME_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  void *RaiseTPL;
  void *RestoreTPL;
  EFI_ALLOCATE_PAGES AllocatePages;
  EFI_FREE_PAGES FreePages;
  EFI_GET_MEMORY_MAP GetMemoryMap;
  EFI_ALLOCATE_POOL AllocatePool;
  EFI_FREE_POOL FreePool;
  EFI_CREATE_EVENT CreateEvent;
  EFI_SET_TIMER SetTimer;
  EFI_WAIT_FOR_EVENT WaitForEvent;
  EFI_SIGNAL_EVENT SignalEvent;
  EFI_CLOSE_EVENT CloseEvent;
  EFI_CHECK_EVENT CheckEvent;
  void *InstallProtocolInterface;
  void *ReinstallProtocolInterface;
  void *UninstallProtocolInterface;
  EFI_HANDLE_PROTOCOL HandleProtocol;
  void *Reserved;
  void *RegisterProtocolNotify;
  void *LocateHandle;
  void *LocateDevicePath;
  void *InstallConfigurationTable;
  EFI_IMAGE_LOAD LoadImage;
  void *StartImage;
  EFI_EXIT Exit;
  EFI_IMAGE_UNLOAD UnloadImage;
  EFI_EXIT_BOOT_SERVICES ExitBootServices;
  EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount;
  EFI_STALL Stall;
  EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;
  void *ConnectController;
  void *DisconnectController;
  void *OpenProtocol;
  void *CloseProtocol;
  void *OpenProtocolInformation;
  void *ProtocolsPerHandle;
  void *LocateHandleBuffer;
  EFI_LOCATE_PROTOCOL LocateProtocol;
  void *InstallMultipleProtocolInterfaces;
  void *UninstallMultipleProtocolInterfaces;
  void *CalculateCrc32;
  EFI_COPY_MEM CopyMem;
  EFI_SET_MEM SetMem;
  EFI_CREATE_EVENT_EX CreateEventEx;
} EFI_BOOT_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  char16_t *FirmwareVendor;
  uint32_t FirmwareRevision;
  EFI_HANDLE ConsoleInHandle;
  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
  EFI_HANDLE ConsoleOutHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
  EFI_HANDLE StandardErrorHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
  EFI_RUNTIME_SERVICES *RuntimeServices;
  EFI_BOOT_SERVICES *BootServices;
  uintptr_t NumberOfTableEntries;
  EFI_CONFIGURATION_TABLE *ConfigurationTable;
} EFI_SYSTEM_TABLE;

struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
  EFI_INPUT_RESET Reset;
  EFI_INPUT_READ_KEY ReadKeyStroke;
  EFI_EVENT WaitForKey;
};

struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
  EFI_TEXT_RESET Reset;
  EFI_TEXT_STRING OutputString;
  EFI_TEXT_TEST_STRING TestString;
  EFI_TEXT_QUERY_MODE QueryMode;
  EFI_TEXT_SET_MODE SetMode;
  EFI_TEXT_SET_ATTRIBUTE SetAttribute;
  EFI_TEXT_CLEAR_SCREEN ClearScreen;
  EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition;
  EFI_TEXT_ENABLE_CURSOR EnableCursor;
  EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;
};

struct _EFI_GRAPHICS_OUTPUT_PROTOCOL {
  EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
};

typedef struct {
  uint32_t Revision;
  EFI_HANDLE ParentHandle;
  EFI_SYSTEM_TABLE *SystemTable;
  EFI_HANDLE DeviceHandle;
  EFI_DEVICE_PATH_PROTOCOL *FilePath;
  void *Reserved;
  uint32_t LoadOptionsSize;
  void *LoadOptions;
  void *ImageBase;
  uint64_t ImageSize;
  EFI_MEMORY_TYPE ImageCodeType;
  EFI_MEMORY_TYPE ImageDataType;
  EFI_IMAGE_UNLOAD Unload;
} EFI_LOADED_IMAGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/events.h */

#define COSMOPOLITAN_LIBC_NT_EVENTS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » events                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int32_t GetMessage(struct NtMsg *lpMsg, int64_t hWnd, uint32_t wMsgFilterMin,
                   uint32_t wMsgFilterMax);
int32_t TranslateMessage(const struct NtMsg *lpMsg);
intptr_t DispatchMessage(const struct NtMsg *lpMsg);
void PostQuitMessage(int nExitCode);
bool32 GetCursorPos(struct NtPoint *lpPoint);
int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                    int64_t lParam);

#define EVENTLOG_SUCCESS          0x00000000
#define EVENTLOG_ERROR_TYPE       0x00000001
#define EVENTLOG_WARNING_TYPE     0x00000002
#define EVENTLOG_INFORMATION_TYPE 0x00000004
#define EVENTLOG_AUDIT_SUCCESS    0x00000008
#define EVENTLOG_AUDIT_FAILURE    0x00000010

int32_t ReportEventA(int64_t handle, uint16_t wType, uint16_t wCategory,
                     uint32_t dwEventID, const char *lpUserId,
                     uint16_t wNumStrings, uint32_t dwDataSize,
                     const char **lpStrings, void **lpRawData);
int64_t RegisterEventSource(const char16_t *lpUNCServerName,
                            const char16_t *lpSourceName);
int32_t DeregisterEventSource(uint64_t handle);

int64_t CreateEvent(const struct NtSecurityAttributes *opt_lpEventAttributes,
                    bool32 bManualReset, bool32 bInitialState,
                    const char16_t *opt_lpName);
int64_t CreateEventA(const struct NtSecurityAttributes *opt_lpEventAttributes,
                     bool32 bManualReset, bool32 bInitialState,
                     const char *opt_lpName);
int64_t CreateEventEx(const struct NtSecurityAttributes *lpEventAttributes,
                      const char16_t *lpName, uint32_t dwFlags,
                      uint32_t dwDesiredAccess);

int32_t SetEvent(int64_t hEvent);
int32_t ResetEvent(int64_t hEvent);
int32_t PulseEvent(int64_t hEvent);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/files.h */

#define COSMOPOLITAN_LIBC_NT_FILES_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » files                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtHandleFlagInherit          1 /* SetHandleInformation */
#define kNtHandleFlagProtectFromClose 2

#define kNtFindFirstExCaseSensitive 1
#define kNtFindFirstExLargeFetch    2

#define kNtDuplicateCloseSource 1
#define kNtDuplicateSameAccess  2

COSMOPOLITAN_C_START_

intptr_t LoadResource(int64_t hModule, int64_t hResInfo);
uint32_t SetHandleCount(uint32_t uNumber);
uint32_t GetLogicalDrives(void);
bool32 FlushFileBuffers(int64_t hFile);

int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess,
                   uint32_t dwShareMode, uint32_t dwFlagsAndAttributes);

bool32 DeleteFile(const char16_t *lpFileName) paramsnonnull();

bool32 CopyFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName, bool32 bFailIfExists)
    paramsnonnull();

bool32 MoveFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName) paramsnonnull();
bool32 MoveFileEx(const char16_t *lpExistingFileName,
                  const char16_t *opt_lpNewFileName, int dwFlags)
    paramsnonnull((1));

bool32 SetCurrentDirectory(const char16_t *lpPathName);
uint32_t GetCurrentDirectory(uint32_t nBufferLength, char16_t *out_lpBuffer);

bool32 CreateDirectory(const char16_t *lpPathName,
                       const struct NtSecurityAttributes *lpSecurityAttributes);
bool32 RemoveDirectory(const char16_t *lpPathName);

bool32 DuplicateHandle(int64_t hSourceProcessHandle, int64_t hSourceHandle,
                       int64_t hTargetProcessHandle, int64_t *lpTargetHandle,
                       uint32_t dwDesiredAccess, bool32 bInheritHandle,
                       uint32_t dwOptions);

bool32 GetHandleInformation(int64_t hObject, uint32_t *out_lpdwFlags);
bool32 SetHandleInformation(int64_t hObject, uint32_t dwMask, uint32_t dwFlags);
int GetFileType(int64_t hFile);

bool32 GetFileInformationByHandleEx(int64_t hFile,
                                    uint32_t FileInformationClass,
                                    void *out_lpFileInformation,
                                    uint32_t dwBufferSize);

bool32 GetFileInformationByHandle(
    int64_t hFile, struct NtByHandleFileInformation *lpFileInformation);
bool32 SetFileInformationByHandle(int64_t hFile, int FileInformationClass,
                                  const void *lpFileInformation,
                                  uint32_t dwBufferSize);

uint32_t GetFileAttributes(const char16_t *lpFileName);
bool32 GetFileAttributesEx(
    const char16_t *lpFileName, int fInfoLevelId /* kNtGetFileExInfoStandard */,
    void *out_lpFileInformation /* → struct NtWin32FileAttributeData * */)
    paramsnonnull();

uint32_t GetCompressedFileSize(const char16_t *lpFileName,
                               uint32_t *lpFileSizeHigh);
bool32 SetFileAttributes(const char16_t *lpFileName, uint32_t dwFileAttributes);
bool32 GetFileTime(int64_t hFile, struct NtFileTime *opt_lpCreationFileTime,
                   struct NtFileTime *opt_lpLastAccessFileTime,
                   struct NtFileTime *opt_lpLastWriteFileTime);
bool32 SetFileTime(int64_t hFile,
                   const struct NtFileTime *opt_lpCreationFileTime,
                   const struct NtFileTime *opt_lpLastAccessFileTime,
                   const struct NtFileTime *opt_lpLastWriteFileTime);

bool32 DeviceIoControl(int64_t hDevice, uint32_t dwIoControlCode,
                       void *lpInBuffer, uint32_t nInBufferSize,
                       void *lpOutBuffer, uint32_t nOutBufferSize,
                       uint32_t *lpBytesReturned,
                       struct NtOverlapped *lpOverlapped);

bool32 LockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToLockLow,
                uint32_t nNumberOfBytesToLockHigh);
bool32 UnlockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                  uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToUnlockLow,
                  uint32_t nNumberOfBytesToUnlockHigh);
bool32 LockFileEx(int64_t hFile, uint32_t dwFlags, uint32_t dwReserved,
                  uint32_t nNumberOfBytesToLockLow,
                  uint32_t nNumberOfBytesToLockHigh,
                  struct NtOverlapped *lpOverlapped) paramsnonnull();
bool32 UnlockFileEx(int64_t hFile, uint32_t dwReserved,
                    uint32_t nNumberOfBytesToUnlockLow,
                    uint32_t nNumberOfBytesToUnlockHigh,
                    struct NtOverlapped *lpOverlapped) paramsnonnull();

bool32 CreateHardLink(const char16_t *lpFileName,
                      const char16_t *lpExistingFileName,
                      const struct NtSecurityAttributes *reserved)
    paramsnonnull((1, 2));
bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName,
                          const char16_t *lpTargetPathName, uint32_t dwFlags)
    paramsnonnull();

bool32 SetEndOfFile(int64_t hFile);
bool32 SetFileValidData(int64_t hFile, int64_t ValidDataLength);

bool32 GetFileSecurity(const char16_t *lpFileName,
                       uint32_t RequestedInformation,
                       struct NtSecurityDescriptor *pSecurityDescriptor,
                       uint32_t nLength, uint32_t *lpnLengthNeeded);

bool32 OpenProcessToken(int64_t hProcessHandle, uint32_t dwDesiredAccess,
                        int64_t *out_hTokenHandle);
bool32 DuplicateToken(int64_t hExistingTokenHandle, int dwImpersonationLevel,
                      int64_t *out_hDuplicateTokenHandle);
bool32 DuplicateTokenEx(int64_t hExistingToken, unsigned int dwDesiredAccess,
                        const struct NtSecurityAttributes *lpTokenAttributes,
                        int ImpersonationLevel, int TokenType,
                        int64_t *out_phNewToken);

bool32 AccessCheck(struct NtSecurityDescriptor *pSecurityDescriptor,
                   int64_t ClientToken, unsigned int DesiredAccess,
                   struct NtGenericMapping *lpGenericMapping,
                   struct NtPrivilegeSet *lpPrivilegeSet,
                   unsigned int *PrivilegeSetLength,
                   unsigned int *GrantedAccess, bool32 *AccessStatus);

void MapGenericMask(uint32_t *AccessMask,
                    struct NtGenericMapping *GenericMapping);

int64_t FindFirstFile(const char16_t *lpFileName,
                      struct NtWin32FindData *out_lpFindFileData);
int64_t FindFirstFileEx(const char16_t *lpFileName, int fInfoLevelId,
                        void *out_lpFindFileData, int fSearchOp,
                        void *reserved_lpSearchFilter,
                        uint32_t dwAdditionalFlags);
bool32 FindNextFile(int64_t hFindFile,
                    struct NtWin32FindData *out_lpFindFileData);
bool32 FindClose(int64_t hFindFile);

int64_t FindFirstVolume(char16_t *out_lpszVolumeName, uint32_t cchBufferLength);
bool32 FindNextVolume(int64_t inout_hFindVolume, char16_t *out_lpszVolumeName,
                      uint32_t cchBufferLength);
bool32 FindVolumeClose(int64_t hFindVolume);

bool32 ReadFileScatter(
    int64_t hFileOpenedWithOverlappedAndNoBuffering,
    const union NtFileSegmentElement
        aNullTerminatedPageAlignedSizedSegmentArray[],
    uint32_t nNumberOfBytesToReadThatsMultipleOfFileVolumeSectorSize,
    uint32_t *lpReserved, struct NtOverlapped *inout_lpOverlapped)
    paramsnonnull();

bool32 WriteFileGather(int64_t hFileOpenedWithOverlappedAndNoBuffering,
                       const union NtFileSegmentElement aSegmentArray[],
                       uint32_t nNumberOfBytesToWrite, uint32_t *lpReserved,
                       struct NtOverlapped inout_lpOverlapped) paramsnonnull();

#define kNtFileNameNormalized 0x0
#define kNtFileNameOpened     0x8
#define kNtVolumeNameDos      0x0 /* e.g. \\?\C:\Users\jart */
#define kNtVolumeNameGuid     0x1 /* e.g. \\?\Volume{ea38-etc.}\Users\jart */
#define kNtVolumeNameNt       0x2 /* e.g. \Device\HarddiskVolume4\Users\jart */
#define kNtVolumeNameNone     0x4 /* e.g. \Users\jart */
uint32_t GetFinalPathNameByHandle(int64_t hFile, char16_t *out_path,
                                  uint32_t arraylen, uint32_t flags);

uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength,
                         char16_t *lpBuffer, char16_t **lpFilePart);

bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped,
                           uint32_t *lpNumberOfBytesTransferred, bool32 bWait);
bool32 GetOverlappedResultEx(int64_t hFile, struct NtOverlapped *lpOverlapped,
                             uint32_t *lpNumberOfBytesTransferred,
                             uint32_t dwMilliseconds, bool32 bAlertable);

bool32 GetVolumePathName(const char16_t *lpszFileName,
                         char16_t *lpszVolumePathName,
                         uint32_t cchBufferLength);

bool32 GetVolumeInformationByHandle(int64_t hFile,
                                    char16_t *opt_out_lpVolumeNameBuffer,
                                    uint32_t nVolumeNameSize,
                                    uint32_t *opt_out_lpVolumeSerialNumber,
                                    uint32_t *opt_out_lpMaximumComponentLength,
                                    uint32_t *opt_out_lpFileSystemFlags,
                                    char16_t *opt_out_lpFileSystemNameBuffer,
                                    uint32_t nFileSystemNameSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/files.inc */

#define CopyFile(...) __imp_CopyFileW(__VA_ARGS__)
extern typeof(CopyFile) *const __imp_CopyFileW __msabi;

#define GetFileType(...) __imp_GetFileType(__VA_ARGS__)
extern typeof(GetFileType) *const __imp_GetFileType __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iocp.h */

#define COSMOPOLITAN_LIBC_NT_IOCP_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » i/o completion ports                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtFileSkipCompletionPortOnSuccess 1
#define kNtFileSkipSetEventOnHandle        2

COSMOPOLITAN_C_START_

typedef void (*NtOverlappedCompletionRoutine)(
    uint32_t dwErrorCode, uint32_t dwNumberOfBytesTransfered,
    struct NtOverlapped *inout_lpOverlapped);

int64_t CreateIoCompletionPort(int64_t FileHandleOrNeg1,
                               int64_t opt_ExistingCompletionPortOrZero,
                               uint64_t CompletionKey,
                               uint32_t NumberOfConcurrentThreads);

bool32 GetQueuedCompletionStatus(int64_t CompletionPort,
                                 uint32_t *lpNumberOfBytesTransferred,
                                 uint64_t *out_lpCompletionKey,
                                 struct NtOverlapped **out_lpOverlapped,
                                 uint32_t dwMilliseconds);

bool32 GetQueuedCompletionStatusEx(
    int64_t CompletionPort,
    struct NtOverlappedEntry *out_lpCompletionPortEntries, uint32_t ulCount,
    uint32_t *out_ulNumEntriesRemoved, uint32_t dwMilliseconds,
    bool32 fAlertable);

bool32 PostQueuedCompletionStatus(int64_t CompletionPort,
                                  uint32_t dwNumberOfBytesTransferred,
                                  uint64_t dwCompletionKey,
                                  struct NtOverlapped *opt_lpOverlapped);

bool32 SetFileCompletionNotificationModes(int64_t FileHandle,
                                          unsigned char Flags);

bool32 ReadFileEx(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                  uint32_t *lpNumberOfBytesRead,
                  struct NtOverlapped *opt_lpOverlapped,
                  NtOverlappedCompletionRoutine lpCompletionRoutine);

bool32 WriteFileEx(int64_t hFile, const void *lpBuffer,
                   uint32_t nNumberOfBytesToWrite,
                   struct NtOverlapped *lpOverlapped,
                   NtOverlappedCompletionRoutine lpCompletionRoutine);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_IPC_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ipc                                      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* CreateNamedPipe:dwOpenMode */
#define kNtPipeAccessInbound  0x00000001
#define kNtPipeAccessOutbound 0x00000002
#define kNtPipeAccessDuplex   0x00000003

/* CreateNamedPipe::dwPipeMode */
#define kNtPipeWait                0x00000000
#define kNtPipeNowait              0x00000001
#define kNtPipeReadmodeByte        0x00000000
#define kNtPipeReadmodeMessage     0x00000002
#define kNtPipeTypeByte            0x00000000
#define kNtPipeTypeMessage         0x00000004
#define kNtPipeAcceptRemoteClients 0x00000000
#define kNtPipeRejectRemoteClients 0x00000008

/* CreateNamedPipe::nMaxInstances */
#define kNtPipeUnlimitedInstances 255

/* GetNamedPipeInfo */
#define kNtPipeClientEnd 0x00000000
#define kNtPipeServerEnd 0x00000001

COSMOPOLITAN_C_START_

bool32 CreatePipe(int64_t *out_hReadPipe, int64_t *out_hWritePipe,
                  const struct NtSecurityAttributes *opt_lpPipeAttributes,
                  uint32_t nSize) paramsnonnull((1, 2));

int64_t CreateNamedPipe(
    const char16_t *lpName, uint32_t dwOpenMode, uint32_t dwPipeMode,
    uint32_t nMaxInstances, uint32_t nOutBufferSize, uint32_t nInBufferSize,
    uint32_t nDefaultTimeOut,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes)
    paramsnonnull((1));

bool32 CallNamedPipe(const char16_t *lpNamedPipeName, void *lpInBuffer,
                     uint32_t nInBufferSize, void *lpOutBuffer,
                     uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                     uint32_t nTimeOut);

bool32 ConnectNamedPipe(int64_t hNamedPipe, struct NtOverlapped *lpOverlapped);
bool32 WaitNamedPipe(const char16_t *lpNamedPipeName, uint32_t nTimeOut);
bool32 DisconnectNamedPipe(int64_t hNamedPipe);

bool32 SetNamedPipeHandleState(int64_t hNamedPipe, uint32_t *lpMode,
                               uint32_t *lpMaxCollectionCount,
                               uint32_t *lpCollectDataTimeout);

bool32 PeekNamedPipe(int64_t hNamedPipe, void *lpBuffer, uint32_t nBufferSize,
                     uint32_t *opt_lpBytesRead, uint32_t *opt_lpTotalBytesAvail,
                     uint32_t *opt_lpBytesLeftThisMessage);

bool32 TransactNamedPipe(int64_t hNamedPipe, void *lpInBuffer,
                         uint32_t nInBufferSize, void *lpOutBuffer,
                         uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                         struct NtOverlapped *lpOverlapped);

bool32 GetNamedPipeInfo(int64_t hNamedPipe, uint32_t *opt_out_lpFlags,
                        uint32_t *opt_out_lpOutBufferSize,
                        uint32_t *opt_out_lpInBufferSize,
                        uint32_t *opt_out_lpMaxInstances);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iphlpapi.h */

#define COSMOPOLITAN_LIBC_NT_IPHLPAPI_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ip helper api                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetAdaptersAddresses(uint32_t Family, uint32_t Flags, void *Reserved,
                              struct NtIpAdapterAddresses *AdapterAddresses,
                              uint32_t *SizePointer);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_MEMORY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » memory                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtNumaNoPreferredNode 0xffffffffu

COSMOPOLITAN_C_START_

void *LocalFree(void *hMem);

int64_t CreateFileMapping(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName);
int64_t CreateFileMappingNuma(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName, uint32_t nndDesiredNumaNode);

void *MapViewOfFileEx(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                      uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                      size_t dwNumberOfBytesToMap,
                      void *opt_lpDesiredBaseAddress);
void *MapViewOfFileExNuma(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                          uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                          size_t dwNumberOfBytesToMap,
                          void *opt_lpDesiredBaseAddress,
                          uint32_t nndDesiredNumaNode);

bool32 UnmapViewOfFile(const void *lpBaseAddress);
bool32 FlushViewOfFile(const void *lpBaseAddress,
                       size_t dwNumberOfBytesToFlush);

void *VirtualAlloc(void *opt_lpAddress, uint64_t dwSize,
                   uint32_t flAllocationType, uint32_t flProtect);
bool32 VirtualFree(void *lpAddress, uint64_t dwSize, uint32_t dwFreeType);
bool32 VirtualProtect(void *lpAddress, uint64_t dwSize, uint32_t flNewProtect,
                      uint32_t *lpflOldProtect) paramsnonnull();
bool32 VirtualLock(const void *lpAddress, size_t dwSize);
bool32 VirtualUnlock(const void *lpAddress, size_t dwSize);
uint64_t VirtualQuery(const void *lpAddress,
                      struct NtMemoryBasicInformation *lpBuffer,
                      uint64_t dwLength);
void *VirtualAllocEx(int64_t hProcess, void *lpAddress, uint64_t dwSize,
                     uint32_t flAllocationType, uint32_t flProtect);

int64_t GetProcessHeap(void);
void *HeapAlloc(int64_t hHeap, uint32_t dwFlags, size_t dwBytes) __wur;
bool32 HeapFree(int64_t hHeap, uint32_t dwFlags, void *opt_lpMem);
void *HeapReAlloc(int64_t hHeap, uint32_t dwFlags, void *lpMem,
                  size_t dwBytes) __wur;

void *GlobalAlloc(uint32_t uFlags, uint64_t dwBytes) __wur;
void *GlobalFree(void *hMem);

/**
 * @param AllocationType
 *     - kNtMemReserve
 *     - kNtMemReplacePlaceholder
 *     - kNtMemLargePages
 */
void *MapViewOfFile3(
    intptr_t FileMapping, intptr_t Process, void *opt_BaseAddress,
    uint64_t Offset, size_t ViewSize, unsigned AllocationType,
    unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

void *VirtualAlloc2(
    intptr_t opt_Process, void *opt_BaseAddress, size_t Size,
    unsigned AllocationType, unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/memory.inc */

extern typeof(LocalFree) *const __imp_LocalFree __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/messagebox.h */

#define COSMOPOLITAN_LIBC_NT_MESSAGEBOX_H_
COSMOPOLITAN_C_START_

int MessageBox(int64_t hWnd, const char16_t *lpText, const char16_t *lpCaption,
               uint32_t mbType);
int MessageBoxEx(int64_t hWnd, const char16_t *lpText,
                 const char16_t *lpCaption, uint32_t mbType,
                 uint16_t wLanguageId);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdll.h */

#define COSMOPOLITAN_LIBC_NT_NTDLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

#define __nt_system_call_dispatcher (wambda *)0x7ffe0308

extern const struct NtUnicodeString *const RtlNtdllName;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » eponymous runtime      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define NT_PROCESS_FLAGS_CREATE_SUSPENDED 0x00000001
#define NT_PROCESS_FLAGS_INHERIT_HANDLES  0x00000002
#define NT_PROCESS_FLAGS_NO_SYNCHRONIZE   0x00000004
#define NT_RTL_CLONE_PARENT               0
#define NT_RTL_CLONE_CHILD                297

NtStatus NtCallbackReturn(void *opt_Result, uint32_t ResultLength,
                          int32_t Status);
NtStatus NtTestAlert(void);

NtStatus NtOpenFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                    struct NtObjectAttributes *ObjectAttributes,
                    struct NtIoStatusBlock *out_IoStatusBlock,
                    uint32_t ShareAccess, uint32_t OpenOptions);

NtStatus NtQueryInformationToken(int64_t TokenHandle,
                                 uint32_t TokenInformationClass,
                                 void *out_TokenInformation,
                                 uint32_t TokenInformationLength,
                                 uint32_t *out_ReturnLength);
NtStatus NtYieldExecution(void);
NtStatus NtQuerySystemInformation(uint32_t info_class, void *out_info,
                                  uint32_t info_size,
                                  uint32_t *out_bytes_received);
NtStatus NtReadVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                             void *out_Buffer, size_t BufferLength,
                             size_t *opt_out_ReturnLength);
NtStatus NtCreateTimer(void **out_TimerHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       uint32_t TimerType);
NtStatus NtSetTimer(void *TimerHandle, int64_t *DueTime, void *TimerApcRoutine,
                    void *TimerContext, int32_t Resume, int32_t Period,
                    int32_t *out_PreviousState);
NtStatus NtQueryObject(void *ObjectHandle, int ObjectInformationClass,
                       void *out_ObjectInformation,
                       uint32_t ObjectInformationLength,
                       uint32_t *opt_out_ReturnLength);
NtStatus NtQueryFullAttributesFile(
    struct NtObjectAttributes *attributes,
    struct NtFileNetworkOpenInformation *out_info);
NtStatus NtCreateKey(void **out_KeyHandle, uint32_t DesiredAccess,
                     struct NtObjectAttributes *ObjectAttributes,
                     uint32_t TitleIndex, struct NtUnicodeString *opt_Class,
                     uint32_t CreateOptions, uint32_t *opt_out_Disposition);
NtStatus NtOpenKey(void **out_KeyHandle, uint32_t DesiredAccess,
                   struct NtObjectAttributes *ObjectAttributes);
NtStatus NtSetValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                       uint32_t opt_TitleIndex, uint32_t Type, void *Data,
                       uint32_t DataSize);
NtStatus NtDeleteKey(void *KeyHandle);
NtStatus NtQueryValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                         int KeyValueInformationClass,
                         void *out_KeyValueInformation, uint32_t Length,
                         uint32_t *out_ResultLength);
NtStatus NtFlushKey(void *KeyHandle);
NtStatus NtEnumerateKey(int64_t hkey, uint32_t index, int info_class,
                        void *out_key_info, uint32_t key_info_size,
                        uint32_t *out_bytes_received);
NtStatus NtEnumerateValueKey(int64_t hKey, uint32_t index, int info_class,
                             void *out_key_info, uint32_t key_info_size,
                             uint32_t *out_bytes_received);
NtStatus NtQuerySystemTime(int64_t *SystemTime);
NtStatus NtDeleteFile(struct NtObjectAttributes *ObjectAttributes);
NtStatus NtFlushBuffersFile(int64_t FileHandle,
                            struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateIoCompletion(void **out_IoCompletionHandle,
                              uint32_t DesiredAccess,
                              struct NtObjectAttributes *ObjectAttributes,
                              uint32_t NumberOfConcurrentThreads);
NtStatus NtRaiseHardError(int32_t ErrorStatus, uint32_t NumberOfArguments,
                          uint32_t UnicodeStringArgumentsMask, void *Arguments,
                          uint32_t MessageBoxType,
                          uint32_t *out_MessageBoxResult);
NtStatus NtRaiseException(struct NtExceptionRecord *ExceptionRecord,
                          struct NtContext *Context, int32_t SearchFrames);
NtStatus NtCreateEvent(void **out_EventHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       int EventType, int32_t InitialState);
NtStatus NtWaitForSingleObject(void *ObjectHandle, int32_t Alertable,
                               int64_t *TimeOut);
NtStatus NtSetEvent(void *EventHandle, int32_t *opt_out_PreviousState);
NtStatus NtClearEvent(void *EventHandle);
NtStatus NtSignalAndWaitForSingleObject(void *ObjectToSignal,
                                        void *WaitableObject, int32_t Alertable,
                                        int64_t *opt_Time);
NtStatus NtQueryPerformanceCounter(int64_t *out_PerformanceCount,
                                   int64_t *opt_out_PerformanceFrequency);
NtStatus NtFsControlFile(int64_t FileHandle, void *opt_Event,
                         NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                         struct NtIoStatusBlock *out_IoStatusBlock,
                         uint32_t FsControlCode, void *opt_InputBuffer,
                         uint32_t InputBufferLength, void *opt_out_OutputBuffer,
                         uint32_t OutputBufferLength);
NtStatus NtCancelIoFile(int64_t FileHandle,
                        struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateProfile(void **out_ProfileHandle, int64_t ProcessHandle,
                         void *Base, uint32_t Size, uint32_t BucketShift,
                         uint32_t *Buffer, uint32_t BufferLength, int Source,
                         uint32_t ProcessorMask);
NtStatus NtSetIntervalProfile(uint32_t Interval, int Source);
NtStatus NtQueryIntervalProfile(int Source, uint32_t *out_Interval);
NtStatus NtStartProfile(void *ProfileHandle);
NtStatus NtStopProfile(void *ProfileHandle);
NtStatus NtCreateDirectoryObject(int64_t *out_DirectoryHandle,
                                 uint32_t DesiredAccess,
                                 struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenDirectoryObject(int64_t *out_DirectoryHandle,
                               uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenSymbolicLinkObject(int64_t *out_DirectoryHandle,
                                  uint32_t DesiredAccess,
                                  struct NtObjectAttributes *ObjectAttributes);
NtStatus NtQuerySymbolicLinkObject(int64_t DirectoryHandle,
                                   struct NtUnicodeString *inout_TargetName,
                                   uint32_t *opt_out_ReturnLength);
NtStatus ZwAreMappedFilesTheSame(void *Address1, void *Address2);
NtStatus NtQueryVolumeInformationFile(int64_t FileHandle,
                                      struct NtIoStatusBlock *out_IoStatusBlock,
                                      void *out_FsInformation, uint32_t Length,
                                      uint32_t FsInformationClass);
NtStatus NtQuerySecurityObject(
    int64_t handle, int RequestedInformation,
    struct NtSecurityDescriptor *out_SecurityDescriptor,
    uint32_t SecurityDescriptorLength, uint32_t *out_ReturnLength);
NtStatus NtQueueApcThread(int64_t ThreadHandle, NtPkNormalRoutine ApcRoutine,
                          void *opt_ApcContext, void *opt_Argument1,
                          void *opt_Argument2);
NtStatus NtFlushInstructionCache(int64_t ProcessHandle, void *opt_BaseAddress,
                                 size_t FlushSize);
NtStatus NtQueryAttributesFile(const struct NtObjectAttributes *object,
                               struct NtFileBasicInformation *file_information);
NtStatus NtQueryDirectoryFile(
    int64_t FileHandle, void *opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    void *out_FileInformation, uint32_t FileInformationLength,
    uint32_t FileInformationClass, int32_t ReturnSingleEntry,
    struct NtUnicodeString *opt_FileName, int32_t RestartScan);
NtStatus NtFlushVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                              uint32_t **inout_FlushSize,
                              struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtQueryInformationJobObject(void *JobHandle, int JobInformationClass,
                                     void *out_JobInformation,
                                     uint32_t JobInformationLength,
                                     uint32_t *opt_out_ReturnLength);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » runtime library        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

NtStatus RtlInitializeCriticalSection(struct NtCriticalSection *out_crit);
NtStatus RtlDeleteCriticalSection(struct NtCriticalSection *crit);
NtStatus RtlEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlLeaveCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlTryEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlInitUnicodeString(struct NtUnicodeString *inout_DestinationString,
                              const char16_t *SourceString);
void RtlFreeUnicodeString(struct NtUnicodeString **string);
NtStatus RtlQueryEnvironmentVariable_U(char16_t *Environment,
                                       struct NtUnicodeString *Name,
                                       struct NtUnicodeString *Value);
NtStatus RtlConvertSidToUnicodeString(struct NtUnicodeString *out_UnicodeString,
                                      void *Sid,
                                      int32_t AllocateDestinationString);
void *RtlCreateHeap(uint32_t flags, void *base, size_t reserve_sz,
                    size_t commit_sz, void *lock, void *params);
NtStatus RtlDestroyHeap(void *base);
void *RtlAllocateHeap(int64_t heap, uint32_t flags, size_t size);
void *RtlReAllocateHeap(int64_t heap, uint32_t flags, void *ptr, size_t size);
NtStatus RtlFreeHeap(int64_t heap, uint32_t flags, void *ptr);
size_t RtlSizeHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlValidateHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlLockHeap(int64_t heap);
NtStatus RtlUnlockHeap(int64_t heap);
NtStatus RtlGetProcessHeaps(uint32_t count, void **out_Heaps);
NtStatus RtlWalkHeap(int64_t heap, void *out_Info);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntdll.inc */

#define NtYieldExecution(...) __imp_NtYieldExecution(__VA_ARGS__)

extern typeof(NtYieldExecution) *const __imp_NtYieldExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdllimport.h */

/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8     -*-│
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8                                 :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney                              │
│                                                                              │
│ Permission to use, copy, modify, and/or distribute this software for         │
│ any purpose with or without fee is hereby granted, provided that the         │
│ above copyright notice and this permission notice appear in all copies.      │
│                                                                              │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             │
│ PERFORMANCE OF THIS SOFTWARE.                                                │
╚─────────────────────────────────────────────────────────────────────────────*/
#define COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_
#ifdef __ASSEMBLER__
/* clang-format off */

.macro	.ntimp	fn:req name:req
#ifdef __x86_64__
	.yoink	_init_ntdll
	.initbss 202,_init_ntdll.\fn
__imp_\fn:
	.quad	0
	.endobj	__imp_\fn,globl,hidden
	.previous
	.initro 202,_init_ntdll.2.\fn
	.quad	RVA(.L\fn)
	.previous
	.section .rodata.str1.1,"aSM",@progbits,1
.L\fn:
	.asciz	"\fn"
	.previous
#elif defined(__aarch64__)
	.section .data.nt.\fn,"aw",@progbits
	.globl	__imp_\fn
	.balign	8
__imp_\fn:
	.quad	\name
	.weak	\name
#endif
.endm

/* clang-format on */
#endif /* __ASSEMBLER__ */


/*!BEGIN libc/nt/paint.h */

#define COSMOPOLITAN_LIBC_NT_PAINT_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » cpu graphics                             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t BeginPaint(int64_t hWnd, struct NtPaintStruct *lpPaint);
int32_t EndPaint(int64_t hWnd, const struct NtPaintStruct *lpPaint);
int32_t BitBlt(int64_t hdc, int x, int y, int cx, int cy, int64_t hdcSrc,
               int x1, int y1, uint32_t rop);
int32_t GetClientRect(int64_t hWnd, struct NtRect *lpRect);
int32_t GetWindowRect(int64_t hWnd, struct NtRect *lpRect);
int32_t SetBkMode(int64_t hdc, int mode);
uint32_t SetTextColor(int64_t hdc, uint32_t color);
uint32_t SetTextAlign(int64_t hdc, uint32_t align);
int32_t SetTextJustification(int64_t hdc, int extra, int count);
int32_t DrawText(int64_t hdc, const char16_t *lpchText, int cchText,
                 struct NtRect *lprc, uint32_t format);
int32_t DrawTextEx(int64_t hdc, char16_t *lpchText, int cchText,
                   struct NtRect *lprc, uint32_t format,
                   struct NtDrawTextParams *lpdtp);
int32_t FillRect(int64_t hDC, const struct NtRect *lpRC, int64_t hBrush);
uint32_t GetPixel(int64_t hdc, int x, int y);
uint32_t SetPixel(int64_t hdc, int x, int y, uint32_t color);
bool32 RedrawWindow(int64_t hWnd, const struct NtRect *opt_lprcUpdate,
                    int64_t opt_hrgnUpdate, uint32_t rdwFlags);
int64_t CreateCompatibleDC(int64_t hdc);
int64_t CreateCompatibleBitmap(int64_t hdc, int cx, int cy);
int64_t SelectObject(int64_t hdc, int64_t h);
bool32 DeleteObject(int64_t ho);
bool32 DeleteDC(int64_t hdc);
int SaveDC(int64_t hdc);
bool32 RestoreDC(int64_t hdc, int nSavedDC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/paint.inc */

#define SetPixel(...) __imp_SetPixel(__VA_ARGS__)
#define GetPixel(...) __imp_GetPixel(__VA_ARGS__)

extern typeof(SetPixel) *const __imp_SetPixel __msabi;
extern typeof(GetPixel) *const __imp_GetPixel __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/pdh.h */

#define COSMOPOLITAN_LIBC_NT_PDH_H_

/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » performance counters                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int PdhOpenQuery(const char16_t *opt_szDataSource, uint32_t *dwUserData,
                 int64_t *out_phQuery);

int PdhAddEnglishCounter(int64_t hQuery, const char16_t *szFullCounterPath,
                         uint32_t *dwUserData, int64_t *out_phCounter);

int PdhCollectQueryDataEx(int64_t hQuery, uint32_t dwIntervalTime,
                          int64_t hNewDataEvent);

int PdhGetFormattedCounterValue(int64_t hCounter, uint32_t dwFormat,
                                uint32_t *out_opt_lpdwType,
                                struct NtPdhFmtCountervalue *out_pValue);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/privilege.h */

#define COSMOPOLITAN_LIBC_NT_PRIVILEGE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » check your privilege                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtSePrivilegeEnabledByDefault 0x00000001u
#define kNtSePrivilegeEnabled          0x00000002u
#define kNtSePrivilegeRemoved          0x00000004u
#define kNtSePrivilegeUsedForAccess    0x80000000u

COSMOPOLITAN_C_START_

bool32 LookupPrivilegeValue(const char16_t *opt_lpSystemName,
                            const char16_t *lpName, struct NtLuid *out_lpLuid);

bool32 AdjustTokenPrivileges(int64_t TokenHandle, bool32 DisableAllPrivileges,
                             const struct NtTokenPrivileges *opt_NewState,
                             uint32_t BufferLength,
                             struct NtTokenPrivileges *opt_out_PreviousState,
                             uint32_t *opt_out_ReturnLength);

bool32 ImpersonateSelf(int kNtSecurityImpersonationLevel);
bool32 RevertToSelf(void);

bool32 OpenThreadToken(intptr_t ThreadHandle, uint32_t DesiredAccess,
                       bool32 OpenAsSelf, intptr_t *TokenHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_PROCESS_H_


/*!BEGIN libc/nt/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_NTSTARTUPINFO_H_
COSMOPOLITAN_C_START_

#define kNtProcThreadAttributeParentProcess 0x00020000
#define kNtProcThreadAttributeHandleList    0x00020002

void GetStartupInfo(struct NtStartupInfo *lpStartupInfo);

bool32 InitializeProcThreadAttributeList(
    struct NtProcThreadAttributeList *opt_inout_lpAttributeList,
    uint32_t dwAttributeCount, uint32_t reserved_dwFlags, size_t *inout_lpSize);
bool32 UpdateProcThreadAttribute(
    struct NtProcThreadAttributeList *inout_lpAttributeList, uint32_t dwFlags,
    uint64_t Attribute, const void *lpValue, size_t cbSize,
    void *reserved_lpPreviousValue, size_t *reserved_lpReturnSize);
void DeleteProcThreadAttributeList(
    struct NtProcThreadAttributeList *inout_lpAttributeList);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/startupinfo.inc */

#define GetStartupInfo(...) __imp_GetStartupInfoW(__VA_ARGS__)

extern typeof(GetStartupInfo) *const __imp_GetStartupInfoW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » processes                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 CreateProcess(const char16_t *opt_lpApplicationName,
                     char16_t *lpCommandLine,
                     const struct NtSecurityAttributes *opt_lpProcessAttributes,
                     const struct NtSecurityAttributes *opt_lpThreadAttributes,
                     bool32 bInheritHandles, uint32_t dwCreationFlags,
                     void *opt_lpEnvironment,
                     const char16_t *opt_lpCurrentDirectory,
                     const struct NtStartupInfo *lpStartupInfo,
                     struct NtProcessInformation *opt_out_lpProcessInformation)
    paramsnonnull((9));

uint32_t GetThreadId(int64_t hThread);   /* cf. NT_TID */
uint32_t GetProcessId(int64_t hProcess); /* cf. NT_PID */
void SetLastError(uint32_t dwErrCode);
uint32_t FormatMessage(uint32_t dwFlags, const void *lpSource,
                       uint32_t dwMessageId, uint32_t dwLanguageId,
                       char16_t *lpBuffer, uint32_t nSize, va_list *Arguments);
uint32_t FormatMessageA(uint32_t dwFlags, const void *lpSource,
                        uint32_t dwMessageId, uint32_t dwLanguageId,
                        char *lpBuffer, uint32_t nSize, va_list *Arguments);
int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                    uint32_t dwProcessId);
uint32_t GetCurrentProcessId(void); /* %gs:0x40 */
uint32_t GetEnvironmentVariable(const char16_t *lpName, char16_t *lpBuffer,
                                uint32_t nSize);
uint32_t SetEnvironmentVariable(const char16_t *lpName,
                                const char16_t *lpValue);
int32_t SetEnvironmentStrings(char16_t *NewEnvironment);
bool32 GetProcessAffinityMask(int64_t hProcess, uint64_t *lpProcessAffinityMask,
                              uint64_t *lpSystemAffinityMask);
uint64_t /*bool32*/ SetProcessAffinityMask(int64_t hProcess,
                                           uint64_t dwProcessAffinityMask);

/* e.g. kNtAboveNormalPriorityClass, kNtHighPriorityClass */
uint32_t GetPriorityClass(int64_t hProcess);
bool32 SetPriorityClass(int64_t hProcess, uint32_t dwPriorityClass);
bool32 SetProcessPriorityBoost(int64_t hProcess, bool32 bDisablePriorityBoost);
bool32 GetProcessPriorityBoost(int64_t hProcess, bool32 *pDisablePriorityBoost);

bool32 GetProcessMemoryInfo(
    int64_t hProcess, struct NtProcessMemoryCountersEx *out_ppsmemCounters,
    uint32_t cb);

int64_t CreateToolhelp32Snapshot(uint32_t dwFlags, uint32_t th32ProcessID);
bool32 Process32First(int64_t hSnapshot, struct NtProcessEntry32 *in_out_lppe);
bool32 Process32Next(int64_t hSnapshot, struct NtProcessEntry32 *out_lppe);

bool32 EnumProcesses(uint32_t *out_lpidProcess, uint32_t cb,
                     uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModules(int64_t hProcess, int64_t *out_lphModule, uint32_t cb,
                          uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModulesEx(int64_t hProcess, int64_t *out_lphModule,
                            uint32_t cb, uint32_t *out_lpcbNeeded,
                            uint32_t dwFilterFlag) paramsnonnull();
uint32_t GetModuleBaseName(int64_t hProcess, int64_t opt_hModule,
                           char16_t *out_lpBaseName, uint32_t nSize)
    paramsnonnull();

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/process.inc */

#define GetEnvironmentVariable(...) __imp_GetEnvironmentVariableW(__VA_ARGS__)
extern typeof(GetEnvironmentVariable) *const __imp_GetEnvironmentVariableW
    __msabi;

#define SetEnvironmentVariable(...) __imp_SetEnvironmentVariableW(__VA_ARGS__)
extern typeof(SetEnvironmentVariable) *const __imp_SetEnvironmentVariableW
    __msabi;

#define GetPriorityClass(...) __imp_GetPriorityClass(__VA_ARGS__)
extern typeof(GetPriorityClass) *const __imp_GetPriorityClass __msabi;

#define SetPriorityClass(...) __imp_SetPriorityClass(__VA_ARGS__)
extern typeof(SetPriorityClass) *const __imp_SetPriorityClass __msabi;

#define GetCurrentProcessId(...) __imp_GetCurrentProcessId(__VA_ARGS__)
extern typeof(GetCurrentProcessId) *const __imp_GetCurrentProcessId __msabi;

extern typeof(FormatMessage) *const __imp_FormatMessageW __msabi;
extern typeof(SetLastError) *const __imp_SetLastError __msabi;
extern typeof(FormatMessage) *const __imp_FormatMessage __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/registry.h */

#define COSMOPOLITAN_LIBC_NT_REGISTRY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » registry                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtMaxKeyNameChars   255
#define kNtMaxValueNameChars 16383
#define kNtMaxValueBytes     0x100000

#define kNtHkeyClassesRoot              0x80000000l
#define kNtHkeyCurrentUser              0x80000001l
#define kNtHkeyLocalMachine             0x80000002l
#define kNtHkeyUsers                    0x80000003l
#define kNtHkeyPerformanceData          0x80000004l
#define kNtHkeyPerformanceText          0x80000050l
#define kNtHkeyPerformanceNlstext       0x80000060l
#define kNtHkeyCurrentConfig            0x80000005l
#define kNtHkeyDynData                  0x80000006l
#define kNtHkeyCurrentUserLocalSettings 0x80000007l

COSMOPOLITAN_C_START_

int RegOpenKey(int64_t hKey, const char16_t *opt_lpSubKey,
               int64_t *out_phkResult) paramsnonnull((3));
int RegOpenKeyEx(int64_t hKey, const char16_t *opt_lpSubKey,
                 uint32_t opt_ulOptions, int samDesired, int64_t *out_phkResult)
    paramsnonnull((5));
int RegCloseKey(int64_t hKey);

int RegGetValue(int64_t hkey, const char16_t *opt_lpSubKey,
                const char16_t *opt_lpValue, unsigned dwFlags, int *opt_pdwType,
                void *opt_out_pvData, uint32_t *opt_inout_pcbDataBytes);
int RegSetValue(int64_t hKey, const char16_t *lpSubKey, int dwType,
                const char16_t *lpData, uint32_t cbData);
int RegSetValueEx(int64_t hKey, const char16_t *lpValueName, uint32_t Reserved,
                  int dwType, const unsigned char *lpData, uint32_t cbData);

int RegQueryInfoKey(int64_t hKey, char16_t *opt_out_lpClass,
                    uint32_t *opt_inout_lpClassLen, uint32_t *lpReserved,
                    uint32_t *opt_out_lpcSubKeys,
                    uint32_t *opt_out_lpcbMaxSubKeyBytes,
                    uint32_t *opt_out_lpcbMaxClassBytes,
                    uint32_t *opt_out_lpcValues,
                    uint32_t *opt_out_lpcbMaxValueNameBytes,
                    uint32_t *opt_out_lpcbMaxValueBytes,
                    uint32_t *opt_out_lpcbSecurityDescriptorBytes,
                    struct NtFileTime *opt_out_lpftLastWriteTime);
int RegEnumKey(int64_t hKey, uint32_t dwIndex, char16_t *opt_lpName,
               uint32_t NameLen);
int RegEnumKeyEx(int64_t hKey, uint32_t dwIndex, char16_t *out_lpName,
                 uint32_t *inout_lpcchName, uint32_t *lpReserved,
                 char16_t *opt_out_lpClass, uint32_t *opt_inout_lpcchClassLen,
                 struct NtFileTime *opt_out_lpftLastWriteTime);

int RegEnumValue(int64_t hKey, uint32_t dwIndex, char16_t *lpValueName,
                 uint32_t *lpValueNameLen, uint32_t *lpReserved,
                 int *opt_out_lpType, unsigned char *opt_out_lpData,
                 uint32_t *opt_inout_lpcbDataBytes);
int RegQueryValue(int64_t hKey, const char16_t *opt_lpSubKey,
                  char16_t *opt_out_lpData, int32_t *opt_inout_lpcbDataBytes);
int RegQueryValueEx(int64_t hKey, const char16_t *opt_lpValueName,
                    uint32_t *lpReserved, int *opt_out_lpType,
                    unsigned char *opt_out_lpData,
                    uint32_t *opt_inout_lpcbDataBytes);

int RegOverridePredefKey(int64_t hKey, int64_t hNewHKey);
int RegOpenUserClassesRoot(void *hToken, uint32_t dwOptions, int samDesired,
                           int64_t *phkResult);
int RegOpenCurrentUser(int samDesired, int64_t *phkResult);
int RegDisablePredefinedCache();
int RegConnectRegistry(const char16_t *lpMachineName, int64_t hKey,
                       int64_t *phkResult);
int RegConnectRegistryEx(const char16_t *lpMachineName, int64_t hKey,
                         uint32_t Flags, int64_t *phkResult);
int RegCreateKey(int64_t hKey, const char16_t *lpSubKey, int64_t *phkResult);
int RegCreateKeyEx(int64_t hKey, const char16_t *lpSubKey, uint32_t Reserved,
                   int16_t *lpClass, uint32_t dwOptions, int samDesired,
                   const struct NtSecurityAttributes *lpSecurityAttributes,
                   int64_t *phkResult, uint32_t *lpdwDisposition);
int RegDeleteKey(int64_t hKey, const char16_t *lpSubKey);
int RegDeleteKeyEx(int64_t hKey, const char16_t *lpSubKey, int samDesired,
                   uint32_t Reserved);
int RegDeleteTree(int64_t hKey, const char16_t *opt_lpSubKey);
int RegDisableReflectionKey(int64_t hBase);
int RegEnableReflectionKey(int64_t hBase);
int RegQueryReflectionKey(int64_t hBase, bool32 *bIsReflectionDisabled);
int RegDeleteValue(int64_t hKey, const char16_t *lpValueName);
int RegFlushKey(int64_t hKey);
int RegGetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor,
                      uint32_t *lpcbSecurityDescriptorBytes);
int RegLoadKey(int64_t hKey, const char16_t *lpSubKey, const char16_t *lpFile);
int RegNotifyChangeKeyValue(int64_t hKey, bool32 bWatchSubtree,
                            uint32_t dwNotifyFilter, void *hEvent,
                            int fAsynchronous);
int RegQueryMultipleValues(int64_t hKey, struct NtValent *inout_val_list,
                           uint32_t num_vals, int16_t *out_lpValueBuf,
                           uint32_t *inout_ldwTotsize) paramsnonnull();
int RegReplaceKey(int64_t hKey, const char16_t *lpSubKey,
                  const char16_t *lpNewFile, const char16_t *lpOldFile);
int RegRestoreKey(int64_t hKey, const char16_t *lpFile, uint32_t dwFlags);
int RegSaveKey(int64_t hKey, const char16_t *lpFile,
               const struct NtSecurityAttributes *lpSecurityAttributes);
int RegSetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor);
int RegUnLoadKey(int64_t hKey, const char16_t *lpSubKey);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/runtime.h */

#define COSMOPOLITAN_LIBC_NT_RUNTIME_H_

/**
 * @fileoverview NT Obligatory Runtime Functions.
 *
 * These functions are placed in their own file because they're (a)
 * abstracted by the Cosmopolitan runtime; and (b) it helps GCC avoid
 * bloating binaries with debug information the user doesn't need.
 */

#define kNtCpUtf8             65001
#define kNtInvalidHandleValue -1L
#define kNtStdInputHandle     -10u
#define kNtStdOutputHandle    -11u
#define kNtStdErrorHandle     -12u

#define GetCurrentProcess() -1

COSMOPOLITAN_C_START_

char16_t *GetCommandLine(void) nosideeffect;
char16_t *GetEnvironmentStrings(void) __wur;
bool32 FreeEnvironmentStrings(char16_t *) paramsnonnull();
bool32 ReadFile(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                uint32_t *lpNumberOfBytesRead,
                struct NtOverlapped *opt_lpOverlapped);
bool32 WriteFile(int64_t hFile, const void *lpBuffer,
                 uint32_t nNumberOfBytesToWrite,
                 uint32_t *lpNumberOfBytesWritten,
                 struct NtOverlapped *opt_lpOverlapped);
bool32 TerminateProcess(int64_t hProcess, uint32_t uExitCode);
void TerminateThisProcess(uint32_t dwWaitStatus) wontreturn;
void ExitProcess(uint32_t uExitCode) wontreturn;
uint32_t GetLastError(void) nosideeffect;
bool32 CloseHandle(int64_t hObject) dontthrow dontcallback;
intptr_t GetStdHandle(uint32_t nStdHandle) nosideeffect;
bool32 SetStdHandle(uint32_t nStdHandle, int64_t hHandle);
bool32 SetDefaultDllDirectories(unsigned dirflags);
bool32 ProcessPrng(void *RandomBuffer, uint32_t RandomBufferLength);
uint32_t GetModuleFileName(int64_t hModule, char16_t *lpFilename,
                           uint32_t nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/runtime.inc */

#define FreeEnvironmentStrings(...) __imp_FreeEnvironmentStringsW(__VA_ARGS__)
extern typeof(FreeEnvironmentStrings) *const __imp_FreeEnvironmentStringsW
    __msabi;

#define GetCommandLine(...) __imp_GetCommandLineW(__VA_ARGS__)
extern typeof(GetCommandLine) *const __imp_GetCommandLineW __msabi;

#define GetEnvironmentStrings(...) __imp_GetEnvironmentStringsW(__VA_ARGS__)
extern typeof(GetEnvironmentStrings) *const __imp_GetEnvironmentStringsW
    __msabi;

#define GetStdHandle(...) __imp_GetStdHandle(__VA_ARGS__)
extern typeof(GetStdHandle) *const __imp_GetStdHandle __msabi;

#define SetStdHandle(...) __imp_SetStdHandle(__VA_ARGS__)
extern typeof(SetStdHandle) *const __imp_SetStdHandle __msabi;

#define ReadFile(...) __imp_ReadFile(__VA_ARGS__)
extern typeof(ReadFile) *const __imp_ReadFile __msabi;

#define WriteFile(...) __imp_WriteFile(__VA_ARGS__)
extern typeof(WriteFile) *const __imp_WriteFile __msabi;

#define SetDefaultDllDirectories(...) \
  __imp_SetDefaultDllDirectories(__VA_ARGS__)
extern typeof(SetDefaultDllDirectories) *const __imp_SetDefaultDllDirectories
    __msabi;

#define GetModuleFileName(...) __imp_GetModuleFileNameW(__VA_ARGS__)
extern typeof(GetModuleFileName) *const __imp_GetModuleFileNameW __msabi;

extern typeof(GetLastError) *const __imp_GetLastError __msabi;
extern typeof(ExitProcess) *const __imp_ExitProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/signals.h */

#define COSMOPOLITAN_LIBC_NT_EXCEPTIONS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » signals                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

typedef int (*NtTopLevelExceptionFilter)(const struct NtExceptionPointers *);
typedef int32_t (*NtVectoredExceptionHandler)(struct NtExceptionPointers *);

int SetErrorMode(int uMode);

int64_t AddVectoredExceptionHandler(uint32_t First,
                                    NtVectoredExceptionHandler pHandler);
int64_t AddVectoredContinueHandler(uint32_t First,
                                   NtVectoredExceptionHandler pHandler);

uint32_t RemoveVectoredExceptionHandler(int64_t hHandle);
uint32_t RemoveVectoredContinueHandler(int64_t hHandle);

NtTopLevelExceptionFilter SetUnhandledExceptionFilter(
    NtTopLevelExceptionFilter opt_lpTopLevelExceptionFilter);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/signals.inc */

#define SetErrorMode(...) __imp_SetErrorMode(__VA_ARGS__)
#define AddVectoredExceptionHandler(...) \
  __imp_AddVectoredExceptionHandler(__VA_ARGS__)
#define AddVectoredContinueHandler(...) \
  __imp_AddVectoredContinueHandler(__VA_ARGS__)
#define RemoveVectoredExceptionHandler(...) \
  __imp_RemoveVectoredExceptionHandler(__VA_ARGS__)
#define RemoveVectoredContinueHandler(...) \
  __imp_RemoveVectoredContinueHandler(__VA_ARGS__)
#define SetUnhandledExceptionFilter(...) \
  __imp_SetUnhandledExceptionFilter(__VA_ARGS__)

extern typeof(SetErrorMode) *const __imp_SetErrorMode __msabi;
extern typeof(AddVectoredExceptionHandler) *const
    __imp_AddVectoredExceptionHandler __msabi;
extern typeof(AddVectoredContinueHandler) *const
    __imp_AddVectoredContinueHandler __msabi;
extern typeof(RemoveVectoredExceptionHandler) *const
    __imp_RemoveVectoredExceptionHandler __msabi;
extern typeof(RemoveVectoredContinueHandler) *const
    __imp_RemoveVectoredContinueHandler __msabi;
extern typeof(SetUnhandledExceptionFilter) *const
    __imp_SetUnhandledExceptionFilter __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/synchronization.h */

#define COSMOPOLITAN_LIBC_NT_SYNCHRONIZATION_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » synchronization                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

static inline int32_t InterlockedAdd(int32_t volatile *p, int32_t x) {
  return atomic_fetch_add((_Atomic(int32_t) *)p, x) + x;
}

static inline int32_t InterlockedExchange(int32_t volatile *p, int32_t x) {
  return atomic_exchange((_Atomic(int32_t) *)p, x);
}

typedef void (*NtTimerapcroutine)(void *lpArgToCompletionRoutine,
                                  uint32_t dwTimerLowValue,
                                  uint32_t dwTimerHighValue);
typedef void (*NtWaitOrTimerCallback)(void *lpParameter,
                                      bool32 TimerOrWaitFired);

void WakeByAddressAll(void *Address);
void WakeByAddressSingle(void *Address);
bool32 WaitOnAddress(const volatile void *Address, void *CompareAddress,
                     size_t AddressSize, uint32_t opt_dwMilliseconds);

void Sleep(uint32_t dwMilliseconds);
uint32_t SleepEx(uint32_t dwMilliseconds, bool32 bAlertable);

void GetSystemTime(struct NtSystemTime *lpSystemTime);
bool32 SystemTimeToFileTime(const struct NtSystemTime *lpSystemTime,
                            struct NtFileTime *lpFileTime);
void GetSystemTimeAsFileTime(struct NtFileTime *);
void GetSystemTimePreciseAsFileTime(struct NtFileTime *); /* win8+ */

uint32_t WaitForSingleObject(int64_t hHandle, uint32_t dwMilliseconds);
uint32_t WaitForMultipleObjects(uint32_t nCount, const int64_t *lpHandles,
                                bool32 bWaitAll, uint32_t dwMilliseconds);
uint32_t WaitForSingleObjectEx(int64_t hHandle, uint32_t dwMilliseconds,
                               bool32 bAlertable);
uint32_t WaitForMultipleObjectsEx(unsigned int nCount, const int64_t *lpHandles,
                                  bool32 bWaitAll, uint32_t dwMilliseconds,
                                  bool32 bAlertable);
bool32 RegisterWaitForSingleObject(int64_t *phNewWaitObject, int64_t hObject,
                                   NtWaitOrTimerCallback Callback,
                                   void *Context, uint32_t dwMilliseconds,
                                   uint32_t dwFlags);

int64_t CreateWaitableTimer(
    const struct NtSecurityAttributes *lpTimerAttributes, bool32 bManualReset,
    const char16_t *lpTimerName);
bool32 SetWaitableTimer(int64_t hTimer, const int64_t *lpDueTimeAsFtOrNegRela,
                        int32_t opt_lPeriodMs, NtTimerapcroutine opt_callback,
                        void *lpArgToCallback, bool32 fUnsleepSystem);

int64_t CreateSemaphore(
    const struct NtSecurityAttributes *opt_lpSemaphoreAttributes,
    uint32_t lInitialCount, uint32_t lMaximumCount, const char16_t *opt_lpName);

int32_t ReleaseMutex(int64_t hMutex);
int32_t ReleaseSemaphore(int64_t hSemaphore, int32_t lReleaseCount,
                         int *lpPreviousCount);

void InitializeCriticalSection(struct NtCriticalSection *lpCriticalSection);
void EnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void LeaveCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t TryEnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void DeleteCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t InitializeCriticalSectionAndSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);
uint32_t SetCriticalSectionSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);

void InitializeSRWLock(intptr_t *);
void AcquireSRWLockExclusive(intptr_t *);
void AcquireSRWLockShared(intptr_t *);
void ReleaseSRWLockExclusive(intptr_t *);
void ReleaseSRWLockShared(intptr_t *);
void TryAcquireSRWLockExclusive(intptr_t *);
void TryAcquireSRWLockShared(intptr_t *);

uint64_t GetTickCount64(void);

bool32 QueryPerformanceFrequency(uint64_t *lpFrequency);
bool32 QueryPerformanceCounter(uint64_t *lpPerformanceCount);
bool32 GetSystemTimeAdjustment(uint32_t *lpTimeAdjustment,
                               uint32_t *lpTimeIncrement,
                               bool32 *lpTimeAdjustmentDisabled);

void GetCurrentProcessorNumberEx(struct NtProcessorNumber *out_ProcNumber);

bool32 GetNumaProcessorNodeEx(const struct NtProcessorNumber *Processor,
                              unsigned short *out_NodeNumber);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/synchronization.inc */

extern typeof(SleepEx) *const __imp_SleepEx __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/system.h */

#define COSMOPOLITAN_LIBC_NT_SYSTEM_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » system control                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

bool32 SetSuspendState(bool32 bHibernate, bool32 bForce,
                       bool32 bWakeupEventsDisabled);

uint32_t InitiateShutdown(const char16_t *lpMachineName,
                          const char16_t *lpMessage, uint32_t dwGracePeriod,
                          uint32_t dwShutdownFlags, uint32_t dwReason);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_INFO_H_
COSMOPOLITAN_C_START_

void GetSystemInfo(struct NtSystemInfo *lpSystemInfo);
uint32_t GetSystemDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetSystemDirectoryA(char *lpBuffer, uint32_t uSize);
uint32_t GetWindowsDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetTempPath(uint32_t uSize, char16_t *lpBuffer);

bool32 GetComputerNameEx(/* enum/computernameformat.h */ int NameType,
                         char16_t *opt_lpBuffer, uint32_t *nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/systeminfo.inc */

#define GetSystemInfo(...) __imp_GetSystemInfo(__VA_ARGS__)
#define GetTempPath(...) __imp_GetTempPathW(__VA_ARGS__)

extern typeof(GetSystemInfo) *const __imp_GetSystemInfo __msabi;
extern typeof(GetTempPath) *const __imp_GetTempPathW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_THREADS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » threads                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t CreateThread(const struct NtSecurityAttributes *lpThreadAttributes,
                     size_t dwStackSize, void *lpStartAddress,
                     void *lpParameter, uint32_t dwCreationFlags,
                     uint32_t *opt_lpThreadId) paramsnonnull((3));

void ExitThread(uint32_t dwExitCode) wontreturn;
int64_t GetCurrentThread(void);
uint32_t GetCurrentThreadId(void);
uint64_t SetThreadAffinityMask(int64_t hThread, uintptr_t dwThreadAffinityMask);
int64_t OpenThread(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                   uint32_t dwThreadId);
bool32 TerminateThread(int64_t hThread, uint32_t dwExitCode);
bool32 GetExitCodeThread(int64_t hThread, uint32_t *lpExitCode);

/* e.g. kNtThreadPriorityAboveNormal, -1u on error */
uint32_t GetThreadPriority(int64_t hThread);
bool32 SetThreadPriority(int64_t hThread, int32_t nPriority);
bool32 SetThreadPriorityBoost(int64_t hThread, bool32 bDisablePriorityBoost);
bool32 GetThreadPriorityBoost(int64_t hThread, bool32 *pDisablePriorityBoost);
bool32 GetThreadIOPendingFlag(int64_t hThread, bool32 *lpIOIsPending);

bool32 CancelSynchronousIo(int64_t hThread);
bool32 CancelIo(int64_t hFile);
bool32 CancelIoEx(int64_t hFile, struct NtOverlapped *opt_lpOverlapped);

uint32_t TlsAlloc(void);
bool32 TlsFree(uint32_t);
bool32 TlsSetValue(uint32_t, void *);
void *TlsGetValue(uint32_t);

uint32_t SuspendThread(int64_t hThread);
uint32_t ResumeThread(int64_t hThread);
bool32 GetThreadContext(int64_t hThread, struct NtContext *in_out_lpContext);
bool32 SetThreadContext(int64_t hThread, const struct NtContext *lpContext);

void *SetThreadDescription(int64_t hThread,
                           const char16_t *lpThreadDescription);
void *GetThreadDescription(int64_t hThread,
                           char16_t *out_ppszThreadDescription);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/thread.inc */

#define GetCurrentThread(...)  __imp_GetCurrentThread(__VA_ARGS__)
#define GetThreadPriority(...) __imp_GetThreadPriority(__VA_ARGS__)
#define SetThreadPriority(...) __imp_SetThreadPriority(__VA_ARGS__)

extern typeof(GetCurrentThread) *const __imp_GetCurrentThread __msabi;
extern typeof(GetThreadPriority) *const __imp_GetThreadPriority __msabi;
extern typeof(SetThreadPriority) *const __imp_SetThreadPriority __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_TIME_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » time                                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetTimeZoneInformation(
    struct NtTimeZoneInformation *out_lpTimeZoneInformation);
uint32_t GetDynamicTimeZoneInformation(
    struct NtDynamicTimeZoneInformation *out_lpTimeZoneInformation);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/version.h */

#define COSMOPOLITAN_LIBC_NT_VERSION_H_
COSMOPOLITAN_C_START_

bool32 IsAtLeastWindows10(void) pureconst;
bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
#define GetNtMajorVersion()        \
  __extension__({                  \
    uintptr_t __x;                 \
    __asm__("mov\t%%gs:96,%q0\r\n" \
            "mov\t280(%q0),%b0"    \
            : "=q"(__x));          \
    (unsigned char)__x;            \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/windows.h */

#define COSMOPOLITAN_LIBC_NT_WINDOWS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » windows                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

int64_t CreateWindowEx(uint32_t dwExStyle, const char16_t *lpClassName,
                       const char16_t *lpWindowName, uint32_t dwStyle, int X,
                       int Y, int nWidth, int nHeight, int64_t hWndParent,
                       int64_t hMenu, int64_t hInstance, int64_t lpParam);

uint16_t RegisterClass(const struct NtWndClass *lpWndClass);

int64_t DefWindowProc(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                      int64_t lParam);

int32_t CloseWindow(int64_t hWnd);
int32_t DestroyWindow(int64_t hWnd);
int32_t ShowWindow(int64_t hWnd, int sw);
int32_t ShowCaret(bool32 bShow);
int32_t AnimateWindow(int64_t hWnd, uint32_t dwTime, uint32_t dwFlags);
int64_t LoadIcon(int64_t hInstance, const char16_t *lpIconName);
int32_t MoveWindow(int64_t hWnd, int X, int Y, int nWidth, int nHeight,
                   bool32 bRepaint);
int32_t BringWindowToTop(int64_t hWnd);
int32_t IsWindowVisible(int64_t hWnd);
int32_t SetWindowText(int64_t hWnd, const char16_t *lpString);
int32_t GetWindowText(int64_t hWnd, char16_t *lpString, int nMaxCount);
int32_t SetWindowPos(int64_t hWnd, int64_t hWndInsertAfter, int X, int Y,
                     int cx, int cy, uint32_t uFlags);
bool32 GetWindowPlacement(int64_t hWnd, struct NtWindowPlacement *lpwndpl);
bool32 SetWindowPlacement(int64_t hWnd,
                          const struct NtWindowPlacement *lpwndpl);

int64_t GetCursor(void);
int64_t SetCursor(int64_t hCursor);
int32_t ShowCursor(bool32 bShow);
int64_t LoadCursor(int64_t opt_hInstance, const char16_t *lpCursorNameOrIdc);

bool32 IsWindow(int64_t hWnd);
bool32 IsMenu(int64_t hMenu);
bool32 IsChild(int64_t hWndParent, int64_t hWnd);
bool32 IsZoomed(int64_t hWnd);
bool32 IsIconic(int64_t hWnd);

uintptr_t SetTimer(int64_t opt_hWnd, uintptr_t nIDEvent, uint32_t uElapseMs,
                   NtTimerProc lpTimerFunc);
int32_t KillTimer(int64_t hWnd, uintptr_t uIDEvent);

int64_t SetCapture(int64_t hWnd);
bool32 ReleaseCapture(void);
int16_t GetKeyState(int32_t nVirtKey);

int64_t CreateMenu(void);
int64_t CreatePopupMenu(void);
int64_t GetMenu(int64_t hWnd);
bool32 DestroyMenu(int64_t hMenu);
int64_t GetSystemMenu(int64_t hWnd, bool32 bRevert);
bool32 AppendMenu(int64_t hMenu, uint32_t mfFlags, uintptr_t uIDNewItem,
                  const char16_t *lpNewItem);
bool32 InsertMenu(int64_t hMenu, uint32_t uPosition, uint32_t uFlags,
                  uintptr_t uIDNewItem, const char16_t *lpNewItem);
bool32 TrackPopupMenu(int64_t hMenu, uint32_t uFlags, int32_t x, int32_t y,
                      int32_t nReserved, int64_t hWnd,
                      const struct NtRect *prcRect);

int WideCharToMultiByte(unsigned int CodePage, uint32_t dwFlags,
                        uint16_t *lpWideCharStr, int cchWideChar,
                        char *lpMultiByteStr, int cbMultiByte,
                        uint16_t *lpDefaultChar, int *lpUsedDefaultChar);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/clktck.h */

#define COSMOPOLITAN_LIBC_RUNTIME_CLKTCK_H_
COSMOPOLITAN_C_START_

#define CLK_TCK (__clk_tck())

int __clk_tck(void) pureconst;

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/fenv.h */

#define COSMOPOLITAN_LIBC_RUNTIME_FENV_H_

#ifdef __x86_64__
#define FE_INVALID    1
#define __FE_DENORM   2
#define FE_DIVBYZERO  4
#define FE_OVERFLOW   8
#define FE_UNDERFLOW  16
#define FE_INEXACT    32
#define FE_ALL_EXCEPT 63
#define FE_TONEAREST  0x0000
#define FE_DOWNWARD   0x0400
#define FE_UPWARD     0x0800
#define FE_TOWARDZERO 0x0c00
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint16_t fexcept_t;

#elif defined(__aarch64__)
#define FE_INVALID    1
#define FE_DIVBYZERO  2
#define FE_OVERFLOW   4
#define FE_UNDERFLOW  8
#define FE_INEXACT    16
#define FE_ALL_EXCEPT 31
#define FE_TONEAREST  0
#define FE_DOWNWARD   0x800000
#define FE_UPWARD     0x400000
#define FE_TOWARDZERO 0xc00000
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint32_t fexcept_t;

#elif defined(__powerpc64__)
#define FE_TONEAREST                  0
#define FE_TOWARDZERO                 1
#define FE_UPWARD                     2
#define FE_DOWNWARD                   3
#define FE_INEXACT                    0x02000000
#define FE_DIVBYZERO                  0x04000000
#define FE_UNDERFLOW                  0x08000000
#define FE_OVERFLOW                   0x10000000
#define FE_INVALID                    0x20000000
#define FE_ALL_EXCEPT                 0x3e000000
#define FE_INVALID_SNAN               0x01000000
#define FE_INVALID_ISI                0x00800000
#define FE_INVALID_IDI                0x00400000
#define FE_INVALID_ZDZ                0x00200000
#define FE_INVALID_IMZ                0x00100000
#define FE_INVALID_COMPARE            0x00080000
#define FE_INVALID_SOFTWARE           0x00000400
#define FE_INVALID_SQRT               0x00000200
#define FE_INVALID_INTEGER_CONVERSION 0x00000100
#define FE_ALL_INVALID                0x01f80700
#define FE_DFL_ENV                    ((const fenv_t *)-1)
typedef unsigned fexcept_t;
typedef double fenv_t;

#endif /* __x86_64__ */

#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD_TS_18661_3__
#elif defined(__FLT_EVAL_METHOD__)
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#else
#define FLT_EVAL_METHOD 0
#endif

COSMOPOLITAN_C_START_

#define FLT_ROUNDS (__flt_rounds())

int feclearexcept(int);
int fegetenv(fenv_t *);
int fegetexceptflag(fexcept_t *, int);
int fegetround(void);
int feholdexcept(fenv_t *);
int feraiseexcept(int);
int fesetenv(const fenv_t *);
int fesetexceptflag(const fexcept_t *, int);
int fesetround(int);
int fetestexcept(int);
int feenableexcept(int);
int fedisableexcept(int);
int feupdateenv(const fenv_t *);
int __flt_rounds(void);
int __fesetround(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/pathconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_PATHCONF_H_

#define _PC_LINK_MAX           0
#define _PC_MAX_CANON          1
#define _PC_MAX_INPUT          2
#define _PC_NAME_MAX           3
#define _PC_PATH_MAX           4
#define _PC_PIPE_BUF           5
#define _PC_CHOWN_RESTRICTED   6
#define _PC_NO_TRUNC           7
#define _PC_VDISABLE           8
#define _PC_SYNC_IO            9
#define _PC_ASYNC_IO           10
#define _PC_PRIO_IO            11
#define _PC_SOCK_MAXBUF        12
#define _PC_FILESIZEBITS       13
#define _PC_REC_INCR_XFER_SIZE 14
#define _PC_REC_MAX_XFER_SIZE  15
#define _PC_REC_MIN_XFER_SIZE  16
#define _PC_REC_XFER_ALIGN     17
#define _PC_ALLOC_SIZE_MIN     18
#define _PC_SYMLINK_MAX        19
#define _PC_2_SYMLINKS         20

COSMOPOLITAN_C_START_

long fpathconf(int, int);
long pathconf(const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/runtime.h */

#define COSMOPOLITAN_LIBC_RUNTIME_RUNTIME_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § runtime                                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#ifdef __x86_64__
typedef long jmp_buf[8];
typedef long sigjmp_buf[11];
#elif defined(__aarch64__)
typedef long jmp_buf[22];
typedef long sigjmp_buf[25];
#elif defined(__powerpc64__)
typedef unsigned __int128 jmp_buf[32];
#elif defined(__s390x__)
typedef unsigned long jmp_buf[18];
#elif defined(__riscv)
typedef unsigned long jmp_buf[26];
#endif

void mcount(void);
int daemon(int, int);
unsigned long getauxval(unsigned long);
int setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
int _setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
void siglongjmp(sigjmp_buf, int) libcesque wontreturn paramsnonnull();
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
void exit(int) wontreturn;
void _exit(int) libcesque wontreturn;
void _Exit(int) libcesque wontreturn;
void quick_exit(int) wontreturn;
void abort(void) wontreturn;
int atexit(void (*)(void)) paramsnonnull() libcesque;
char *getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
int putenv(char *);
int setenv(const char *, const char *, int);
int unsetenv(const char *);
int clearenv(void);
void fpreset(void);
void *mmap(void *, uint64_t, int32_t, int32_t, int32_t, int64_t);
int munmap(void *, uint64_t);
int mprotect(void *, uint64_t, int);
int msync(void *, size_t, int);
int mlock(const void *, size_t);
int munlock(const void *, size_t);
long gethostid(void);
int sethostid(long);
char *getlogin(void);
int getlogin_r(char *, size_t);
int login_tty(int);
int getpagesize(void);
int syncfs(int) dontthrow;
int vhangup(void);
int getdtablesize(void);
int sethostname(const char *, size_t);
int acct(const char *);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
extern char **environ;
char *secure_getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
#endif

#ifdef _COSMO_SOURCE
extern int __argc;
extern char **__argv;
extern char **__envp;
extern unsigned long *__auxv;
extern intptr_t __oldstack;
extern char *__program_executable_name;
extern uint64_t __nosync;
extern int __strace;
extern int __ftrace;
extern uint64_t __syscount;
extern uint64_t kStartTsc;
extern const char kNtSystemDirectory[];
extern const char kNtWindowsDirectory[];
extern size_t __virtualmax;
extern size_t __stackmax;
extern bool32 __isworker;
/* utilities */
void _intsort(int *, size_t);
void _longsort(long *, size_t);
/* diagnostics */
void ShowCrashReports(void);
int ftrace_install(void);
int ftrace_enabled(int);
int strace_enabled(int);
void __print_maps(void);
void __printargs(const char *);
/* builtin sh-like system/popen dsl */
int _cocmd(int, char **, char **);
/* executable program */
char *GetProgramExecutableName(void);
char *GetInterpreterExecutableName(char *, size_t);
int __open_executable(void);
/* execution control */
int verynice(void);
void __warn_if_powersave(void);
void _Exit1(int) libcesque wontreturn;
void __paginate(int, const char *);
void __paginate_file(int, const char *);
/* memory management */
void _weakfree(void *);
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
void CheckForMemoryLeaks(void);
void CheckForFileLeaks(void);
bool32 _isheap(const void *);
void __enable_threads(void);
void __oom_hook(size_t);
/* code morphing */
void __morph_begin(void);
void __morph_end(void);
void __jit_begin(void);
void __jit_end(void);
void __clear_cache(void *, void *);
/* portability */
int NtGetVersion(void) pureconst;
bool32 IsGenuineBlink(void);
bool32 IsCygwin(void);
const char *GetCpuidOs(void);
const char *GetCpuidEmulator(void);
void GetCpuidBrand(char[13], uint32_t);
long __get_rlimit(int);
const char *__describe_os(void);
long __get_sysctl(int, int);
int __get_arg_max(void) pureconst;
int __get_cpu_count(void) pureconst;
long __get_avphys_pages(void) pureconst;
long __get_phys_pages(void) pureconst;
long __get_minsigstksz(void) pureconst;
void __get_main_stack(void **, size_t *, int *);
long __get_safe_size(long, long);
char *__get_tmpdir(void);
forceinline int __trace_disabled(int x) {
  return 0;
}
#ifndef FTRACE
#define ftrace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#ifndef SYSDEBUG
#define strace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/stack.h */

#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_

/**
 * Returns preferred size and alignment of thread stack.
 */
#define GetStackSize() 262144

/**
 * Returns preferred stack guard size.
 *
 * This is the max cpu page size of supported architectures.
 */
#define GetGuardSize() 16384

/**
 * Align APE main thread stack at startup.
 *
 * You need this in your main program module:
 *
 *     STATIC_STACK_ALIGN(GetStackSize());
 *
 * If you want to use GetStackAddr() and HaveStackMemory() safely on
 * your main thread in your process. It causes crt.S to waste a tiny
 * amount of memory to ensure those macros go extremely fast.
 */
#define STATIC_STACK_ALIGN(BYTES) \
  _STACK_SYMBOL("ape_stack_align", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Makes program stack executable if declared, e.g.
 *
 *     STATIC_EXEC_STACK();
 *     int main() {
 *       char code[16] = {
 *           0x55,                          // push %rbp
 *           0xb8, 0007, 0x00, 0x00, 0x00,  // mov  $7,%eax
 *           0x5d,                          // push %rbp
 *           0xc3,                          // ret
 *       };
 *       int (*func)(void) = (void *)code;
 *       printf("result %d should be 7\n", func());
 *     }
 */
#define STATIC_EXEC_STACK() _STACK_SYMBOL("ape_stack_pf", "7")

#define _STACK_STRINGIFY(ADDR) #ADDR
#define _STACK_SYMBOL(NAME, VALUE)       \
  __asm__(".equ\t" NAME "," VALUE "\n\t" \
          ".globl\t" NAME)

#ifdef __SANITIZE_ADDRESS__
#define _STACK_EXTRA "*2"
#else
#define _STACK_EXTRA ""
#endif

#if defined(__GNUC__) && defined(__ELF__)
COSMOPOLITAN_C_START_

extern char ape_stack_prot[] __attribute__((__weak__));
extern char ape_stack_memsz[] __attribute__((__weak__));
extern char ape_stack_align[] __attribute__((__weak__));

/**
 * Returns address of bottom of current stack.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants.
 */
#define GetStackAddr() ((GetStackPointer() - 1) & -GetStackSize())

#define GetStaticStackSize() ((uintptr_t)ape_stack_memsz)

/**
 * Returns true if at least `n` bytes of stack are available.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants,
 * which make this check exceedingly fast.
 */
#define HaveStackMemory(n) \
  (GetStackPointer() >= GetStackAddr() + GetGuardSize() + (n))

/**
 * Extends stack memory by poking large allocations.
 *
 * This can be particularly useful depending on how your system
 * implements guard pages. For example, Windows can make stacks
 * that aren't fully committed, in which case there's only 4096
 * bytes of grows-down guard pages made by portable executable.
 * If you alloca() more memory than that, you should call this,
 * since it'll not only ensure stack overflows are detected, it
 * will also trigger the stack to grow down safely.
 */
forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
  for (; n > 0; n -= 4096) {
    ((char *)p)[n - 1] = 0;
  }
}

void *NewCosmoStack(void) vallocesque;
int FreeCosmoStack(void *) libcesque;

/**
 * Tunes stack size of main thread on Windows.
 *
 * On UNIX systems use `RLIMIT_STACK` to tune the main thread size.
 */
#define STATIC_STACK_SIZE(BYTES) \
  _STACK_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Tunes main thread stack address on Windows.
 */
#define STATIC_STACK_ADDR(ADDR) \
  _STACK_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))

#ifdef __x86_64__
/**
 * Returns preferred bottom address of main thread stack.
 *
 * On UNIX systems we favor the system provided stack, so this only
 * really applies to Windows. It's configurable at link time. It is
 * needed because polyfilling fork requires that we know, precicely
 * where the stack memory begins and ends.
 */
#define GetStaticStackAddr(ADDEND)          \
  ({                                        \
    intptr_t vAddr;                         \
    __asm__(".weak\tape_stack_vaddr\n\t"    \
            "movabs\t%1+ape_stack_vaddr,%0" \
            : "=r"(vAddr)                   \
            : "i"(ADDEND));                 \
    vAddr;                                  \
  })
#else
#define GetStaticStackAddr(ADDEND) (GetStackAddr() + ADDEND)
#endif

#define GetStackPointer()           \
  ({                                \
    uintptr_t __sp;                 \
    __asm__(__mov_sp : "=r"(__sp)); \
    __sp;                           \
  })

#ifdef __x86_64__
#define __mov_sp "mov\t%%rsp,%0"
#elif defined(__aarch64__)
#define __mov_sp "mov\t%0,sp"
#endif

COSMOPOLITAN_C_END_
#endif /* GNU ELF */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_STACK_H_ */


/*!BEGIN libc/runtime/sysconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_SYSCONF_H_

#define _SC_ARG_MAX                      0
#define _SC_CHILD_MAX                    1
#define _SC_CLK_TCK                      2
#define _SC_NGROUPS_MAX                  3
#define _SC_OPEN_MAX                     4
#define _SC_STREAM_MAX                   5
#define _SC_TZNAME_MAX                   6
#define _SC_JOB_CONTROL                  7
#define _SC_SAVED_IDS                    8
#define _SC_REALTIME_SIGNALS             9
#define _SC_PRIORITY_SCHEDULING          10
#define _SC_TIMERS                       11
#define _SC_ASYNCHRONOUS_IO              12
#define _SC_PRIORITIZED_IO               13
#define _SC_SYNCHRONIZED_IO              14
#define _SC_FSYNC                        15
#define _SC_MAPPED_FILES                 16
#define _SC_MEMLOCK                      17
#define _SC_MEMLOCK_RANGE                18
#define _SC_MEMORY_PROTECTION            19
#define _SC_MESSAGE_PASSING              20
#define _SC_SEMAPHORES                   21
#define _SC_SHARED_MEMORY_OBJECTS        22
#define _SC_AIO_LISTIO_MAX               23
#define _SC_AIO_MAX                      24
#define _SC_AIO_PRIO_DELTA_MAX           25
#define _SC_DELAYTIMER_MAX               26
#define _SC_MQ_OPEN_MAX                  27
#define _SC_MQ_PRIO_MAX                  28
#define _SC_VERSION                      29
#define _SC_PAGE_SIZE                    30
#define _SC_PAGESIZE                     30 /* !! */
#define _SC_RTSIG_MAX                    31
#define _SC_SEM_NSEMS_MAX                32
#define _SC_SEM_VALUE_MAX                33
#define _SC_SIGQUEUE_MAX                 34
#define _SC_TIMER_MAX                    35
#define _SC_BC_BASE_MAX                  36
#define _SC_BC_DIM_MAX                   37
#define _SC_BC_SCALE_MAX                 38
#define _SC_BC_STRING_MAX                39
#define _SC_COLL_WEIGHTS_MAX             40
#define _SC_EXPR_NEST_MAX                42
#define _SC_LINE_MAX                     43
#define _SC_RE_DUP_MAX                   44
#define _SC_2_VERSION                    46
#define _SC_2_C_BIND                     47
#define _SC_2_C_DEV                      48
#define _SC_2_FORT_DEV                   49
#define _SC_2_FORT_RUN                   50
#define _SC_2_SW_DEV                     51
#define _SC_2_LOCALEDEF                  52
#define _SC_UIO_MAXIOV                   60 /* !! */
#define _SC_IOV_MAX                      60
#define _SC_THREADS                      67
#define _SC_THREAD_SAFE_FUNCTIONS        68
#define _SC_GETGR_R_SIZE_MAX             69
#define _SC_GETPW_R_SIZE_MAX             70
#define _SC_LOGIN_NAME_MAX               71
#define _SC_TTY_NAME_MAX                 72
#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73
#define _SC_THREAD_KEYS_MAX              74
#define _SC_THREAD_STACK_MIN             75
#define _SC_THREAD_THREADS_MAX           76
#define _SC_THREAD_ATTR_STACKADDR        77
#define _SC_THREAD_ATTR_STACKSIZE        78
#define _SC_THREAD_PRIORITY_SCHEDULING   79
#define _SC_THREAD_PRIO_INHERIT          80
#define _SC_THREAD_PRIO_PROTECT          81
#define _SC_THREAD_PROCESS_SHARED        82
#define _SC_NPROCESSORS_CONF             83
#define _SC_NPROCESSORS_ONLN             84
#define _SC_PHYS_PAGES                   85
#define _SC_AVPHYS_PAGES                 86
#define _SC_ATEXIT_MAX                   87
#define _SC_PASS_MAX                     88
#define _SC_XOPEN_VERSION                89
#define _SC_XOPEN_XCU_VERSION            90
#define _SC_XOPEN_UNIX                   91
#define _SC_XOPEN_CRYPT                  92
#define _SC_XOPEN_ENH_I18N               93
#define _SC_XOPEN_SHM                    94
#define _SC_2_CHAR_TERM                  95
#define _SC_2_UPE                        97
#define _SC_XOPEN_XPG2                   98
#define _SC_XOPEN_XPG3                   99
#define _SC_XOPEN_XPG4                   100
#define _SC_NZERO                        109
#define _SC_XBS5_ILP32_OFF32             125
#define _SC_XBS5_ILP32_OFFBIG            126
#define _SC_XBS5_LP64_OFF64              127
#define _SC_XBS5_LPBIG_OFFBIG            128
#define _SC_XOPEN_LEGACY                 129
#define _SC_XOPEN_REALTIME               130
#define _SC_XOPEN_REALTIME_THREADS       131
#define _SC_ADVISORY_INFO                132
#define _SC_BARRIERS                     133
#define _SC_CLOCK_SELECTION              137
#define _SC_CPUTIME                      138
#define _SC_THREAD_CPUTIME               139
#define _SC_MONOTONIC_CLOCK              149
#define _SC_READER_WRITER_LOCKS          153
#define _SC_SPIN_LOCKS                   154
#define _SC_REGEXP                       155
#define _SC_SHELL                        157
#define _SC_SPAWN                        159
#define _SC_SPORADIC_SERVER              160
#define _SC_THREAD_SPORADIC_SERVER       161
#define _SC_TIMEOUTS                     164
#define _SC_TYPED_MEMORY_OBJECTS         165
#define _SC_2_PBS                        168
#define _SC_2_PBS_ACCOUNTING             169
#define _SC_2_PBS_LOCATE                 170
#define _SC_2_PBS_MESSAGE                171
#define _SC_2_PBS_TRACK                  172
#define _SC_SYMLOOP_MAX                  173
#define _SC_STREAMS                      174
#define _SC_2_PBS_CHECKPOINT             175
#define _SC_V6_ILP32_OFF32               176
#define _SC_V6_ILP32_OFFBIG              177
#define _SC_V6_LP64_OFF64                178
#define _SC_V6_LPBIG_OFFBIG              179
#define _SC_HOST_NAME_MAX                180
#define _SC_TRACE                        181
#define _SC_TRACE_EVENT_FILTER           182
#define _SC_TRACE_INHERIT                183
#define _SC_TRACE_LOG                    184
#define _SC_IPV6                         235
#define _SC_RAW_SOCKETS                  236
#define _SC_V7_ILP32_OFF32               237
#define _SC_V7_ILP32_OFFBIG              238
#define _SC_V7_LP64_OFF64                239
#define _SC_V7_LPBIG_OFFBIG              240
#define _SC_SS_REPL_MAX                  241
#define _SC_TRACE_EVENT_NAME_MAX         242
#define _SC_TRACE_NAME_MAX               243
#define _SC_TRACE_SYS_MAX                244
#define _SC_TRACE_USER_EVENT_MAX         245
#define _SC_XOPEN_STREAMS                246
#define _SC_THREAD_ROBUST_PRIO_INHERIT   247
#define _SC_THREAD_ROBUST_PRIO_PROTECT   248
#define _SC_SIGSTKSZ                     249
#define _SC_MINSIGSTKSZ                  250

COSMOPOLITAN_C_START_

long sysconf(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/utmp.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMP_H_


/*!BEGIN libc/runtime/utmpx.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMPX_H_
COSMOPOLITAN_C_START_

struct utmpx {
  short ut_type;
  pid_t ut_pid;
  char ut_line[32];
  char ut_id[4];
  char ut_user[32];
  char ut_host[256];
  struct {
    short __e_termination;
    short __e_exit;
  } ut_exit;
  long ut_session;
  struct timeval ut_tv;
  unsigned ut_addr_v6[4];
  char __unused[20];
};

void endutxent(void);
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *);
struct utmpx *getutxline(const struct utmpx *);
struct utmpx *pututxline(const struct utmpx *);
void setutxent(void);

#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define e_exit        __e_exit
#define e_termination __e_termination
void updwtmpx(const char *, const struct utmpx *);
int utmpxname(const char *);
#endif

#define EMPTY         0
#define RUN_LVL       1
#define BOOT_TIME     2
#define NEW_TIME      3
#define OLD_TIME      4
#define INIT_PROCESS  5
#define LOGIN_PROCESS 6
#define USER_PROCESS  7
#define DEAD_PROCESS  8

COSMOPOLITAN_C_END_

#define ACCOUNTING  9
#define UT_NAMESIZE 32
#define UT_HOSTSIZE 256
#define UT_LINESIZE 32

COSMOPOLITAN_C_START_

struct lastlog {
  time_t ll_time;
  char ll_line[UT_LINESIZE];
  char ll_host[UT_HOSTSIZE];
};

#define ut_time       ut_tv.tv_sec
#define ut_name       ut_user
#define ut_addr       ut_addr_v6[0]
#define utmp          utmpx
#define e_exit        __e_exit
#define e_termination __e_termination

int login_tty(int);
int utmpname(const char *);
struct utmp *getutent(void);
struct utmp *getutid(const struct utmp *);
struct utmp *getutline(const struct utmp *);
struct utmp *pututline(const struct utmp *);
void endutent(void);
void setutent(void);
void updwtmp(const char *, const struct utmp *);

#define _PATH_UTMP "/dev/null/utmp"
#define _PATH_WTMP "/dev/null/wtmp"

#define UTMP_FILE     _PATH_UTMP
#define WTMP_FILE     _PATH_WTMP
#define UTMP_FILENAME _PATH_UTMP
#define WTMP_FILENAME _PATH_WTMP

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/alg.h */

#define COSMOPOLITAN_LIBC_SOCK_ALG_H_
COSMOPOLITAN_C_START_

struct sockaddr_alg {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[64];
};

struct sockaddr_alg_new {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[]; /* Linux v4.12+ */
};

struct af_alg_iv {
  uint32_t ivlen;
  uint8_t iv[0];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/epoll.h */

#define COSMOPOLITAN_LIBC_SOCK_WEPOLL_H_
COSMOPOLITAN_C_START_

typedef union epoll_data {
  void *ptr;
  int fd;
  uint32_t u32;
  uint64_t u64;
} epoll_data_t;

struct thatispacked epoll_event {
  uint32_t events;
  epoll_data_t data;
};

int epoll_create(int) libcesque;
int epoll_create1(int) libcesque;
int epoll_ctl(int, int, int, struct epoll_event *) libcesque;
int epoll_wait(int, struct epoll_event *, int, int) libcesque;
int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/ifaddrs.h */

#define COSMOPOLITAN_LIBC_SOCK_IFADDRS_H_
COSMOPOLITAN_C_START_

struct ifaddrs {
  struct ifaddrs *ifa_next;
  char *ifa_name;
  unsigned ifa_flags;
  struct sockaddr *ifa_addr;
  struct sockaddr *ifa_netmask;
  union {
    struct sockaddr *ifa_broadaddr;
    struct sockaddr *ifa_dstaddr;
  };
  void *ifa_data;
};

void freeifaddrs(struct ifaddrs *) libcesque;
int getifaddrs(struct ifaddrs **) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/in.h */

#define COSMOPOLITAN_LIBC_SOCK_IN_H_

#define IN_CLASSA(a)       ((((in_addr_t)(a)) & 0x80000000) == 0)
#define IN_CLASSA_NET      0xff000000
#define IN_CLASSA_NSHIFT   24
#define IN_CLASSA_HOST     (0xffffffff & ~IN_CLASSA_NET)
#define IN_CLASSA_MAX      128
#define IN_CLASSB(a)       ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET      0xffff0000
#define IN_CLASSB_NSHIFT   16
#define IN_CLASSB_HOST     (0xffffffff & ~IN_CLASSB_NET)
#define IN_CLASSB_MAX      65536
#define IN_CLASSC(a)       ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET      0xffffff00
#define IN_CLASSC_NSHIFT   8
#define IN_CLASSC_HOST     (0xffffffff & ~IN_CLASSC_NET)
#define IN_CLASSD(a)       ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
#define IN_MULTICAST(a)    IN_CLASSD(a)
#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
#define IN_BADCLASS(a)     ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)

#define IN6_IS_ADDR_UNSPECIFIED(a)                           \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint32_t *)(a))[3] == 0)

#define IN6_IS_ADDR_LOOPBACK(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[12] == 0 && \
   ((uint8_t *)(a))[13] == 0 && ((uint8_t *)(a))[14] == 0 && \
   ((uint8_t *)(a))[15] == 1)

#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *)(a))[0] == 0xff)

#define IN6_IS_ADDR_LINKLOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0x80)

#define IN6_IS_ADDR_SITELOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0xc0)

#define IN6_IS_ADDR_V4MAPPED(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint8_t *)(a))[8] == 0 && ((uint8_t *)(a))[9] == 0 &&   \
   ((uint8_t *)(a))[10] == 0xff && ((uint8_t *)(a))[11] == 0xff)

#define IN6_IS_ADDR_V4COMPAT(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[15] > 1)

#define IN6_IS_ADDR_MC_NODELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x1))

#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x2))

#define IN6_IS_ADDR_MC_SITELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x5))

#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x8))

#define IN6_IS_ADDR_MC_GLOBAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0xe))

#define __ARE_4_EQUAL(a, b) \
  (!((0 [a] - 0 [b]) | (1 [a] - 1 [b]) | (2 [a] - 2 [b]) | (3 [a] - 3 [b])))
#define IN6_ARE_ADDR_EQUAL(a, b) \
  __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))



/*!BEGIN libc/sock/select.h */

#define COSMOPOLITAN_LIBC_SOCK_SELECT_H_

#define FD_SETSIZE 1024 /* it's 64 on windows */

COSMOPOLITAN_C_START_

typedef struct fd_set {
  unsigned long fds_bits[FD_SETSIZE / (sizeof(long) * 8)];
} fd_set;

#define FD_ISSET(FD, SET) (((SET)->fds_bits[(FD) >> 6] >> ((FD)&63)) & 1)
#define FD_SET(FD, SET)   ((SET)->fds_bits[(FD) >> 6] |= 1ull << ((FD)&63))
#define FD_CLR(FD, SET)   ((SET)->fds_bits[(FD) >> 6] &= ~(1ull << ((FD)&63)))
#define FD_ZERO(SET)      bzero((SET)->fds_bits, sizeof((SET)->fds_bits))
#define FD_SIZE(bits)     (((bits) + (sizeof(long) * 8) - 1) / sizeof(long))

int select(int, fd_set *, fd_set *, fd_set *, struct timeval *) libcesque;
int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
            const sigset_t *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/syslog.h */

#define COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_
COSMOPOLITAN_C_START_

int setlogmask(int) libcesque;
void openlog(const char *, int, int) libcesque;
void syslog(int, const char *, ...) libcesque;
void closelog(void) libcesque;
void vsyslog(int, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arphdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPHDR_H_
COSMOPOLITAN_C_START_

struct arphdr {
  uint16_t ar_hrd;
  uint16_t ar_pro;
  uint8_t ar_hln;
  uint8_t ar_pln;
  uint16_t ar_op;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arpreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPREQ_H_
COSMOPOLITAN_C_START_

struct arpreq {
  struct sockaddr arp_pa;
  struct sockaddr arp_ha;
  int arp_flags;
  struct sockaddr arp_netmask;
  char arp_dev[16];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/cmsghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_H_
COSMOPOLITAN_C_START_

#define CMSG_DATA(cmsg) ((unsigned char *)(((struct cmsghdr *)(cmsg)) + 1))

#define CMSG_FIRSTHDR(mhdr)                                 \
  ((size_t)(mhdr)->msg_controllen >= sizeof(struct cmsghdr) \
       ? (struct cmsghdr *)(mhdr)->msg_control              \
       : (struct cmsghdr *)0)

#define CMSG_NXTHDR(mhdr, cmsg)                           \
  ((cmsg)->cmsg_len < sizeof(struct cmsghdr) ||           \
           __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >=   \
               __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
       ? 0                                                \
       : (struct cmsghdr *)__CMSG_NEXT(cmsg))

#define CMSG_ALIGN(len) \
  (((len) + sizeof(size_t) - 1) & (size_t) ~(sizeof(size_t) - 1))

#define CMSG_SPACE(len) (CMSG_ALIGN(len) + CMSG_ALIGN(sizeof(struct cmsghdr)))

#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))

#define __CMSG_LEN(cmsg) \
  (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
#define __MHDR_END(mhdr) \
  ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)

struct cmsghdr { /* linux abi */
  uint32_t cmsg_len;
  uint32_t __pad1;
  int32_t cmsg_level;
  int32_t cmsg_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ether_header.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ETHER_HEADER_H_

#define ETH_ALEN 6

COSMOPOLITAN_C_START_

struct ether_addr {
  uint8_t ether_addr_octet[ETH_ALEN];
};

struct ether_header {
  uint8_t ether_dhost[ETH_ALEN];
  uint8_t ether_shost[ETH_ALEN];
  uint16_t ether_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ifconf.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFCONF_H_


/*!BEGIN libc/sock/struct/ifreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFREQ_H_
COSMOPOLITAN_C_START_

#define IF_NAMESIZE 16
#define IFNAMSIZ    IF_NAMESIZE

struct ifreq {
  union {
    char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0".  */
  } ifr_ifrn;
  union {
    struct sockaddr ifru_addr;      /* SIOCGIFADDR */
    struct sockaddr ifru_dstaddr;   /* SIOCGIFDSTADDR */
    struct sockaddr ifru_netmask;   /* SIOCGIFNETMASK */
    struct sockaddr ifru_broadaddr; /* SIOCGIFBRDADDR */
    short ifru_flags;               /* SIOCGIFFLAGS */
    int ifru_ivalue;                /* todo(jart) */
    char ifru_pad[24];              /* ifru_map is the largest, just pad */
  } ifr_ifru;
};

#define ifr_name      ifr_ifrn.ifrn_name      /* interface name */
#define ifr_addr      ifr_ifru.ifru_addr      /* address */
#define ifr_netmask   ifr_ifru.ifru_netmask   /* netmask */
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
#define ifr_dstaddr   ifr_ifru.ifru_dstaddr   /* destination address */
#define ifr_flags     ifr_ifru.ifru_flags     /* flags */
#define ifr_ifindex   ifr_ifru.ifru_ivalue

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/*
 * Structure used in SIOCGIFCONF request.
 * Used to retrieve interface configuration
 * for machine (useful for programs which
 * must know all networks accessible).
 */
struct ifconf {
  int32_t ifc_len; /* size of buffer */
  int32_t padding;
  union {
    char *ifcu_buf;
    struct ifreq *ifcu_req;
  } ifc_ifcu;
};

/* Shortcuts to the ifconf buffer or ifreq array */
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address   */
#define ifc_req ifc_ifcu.ifcu_req /* array of structures  */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in6_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN6_PKTINFO_H_


/*!BEGIN libc/sock/struct/sockaddr6.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SOCKADDR6_H_

struct in6_addr {
  union {
    uint8_t s6_addr[16];
    uint16_t s6_addr16[8];
    uint32_t s6_addr32[4];
  };
};

struct sockaddr_in6 { /* Linux+NT ABI */
  uint16_t sin6_family;
  uint16_t sin6_port;
  uint32_t sin6_flowinfo;
  struct in6_addr sin6_addr;
  uint32_t sin6_scope_id; /* rfc2553 */
};

extern const struct in6_addr in6addr_any;
extern const struct in6_addr in6addr_loopback;

COSMOPOLITAN_C_START_

struct in6_pktinfo {
  struct in6_addr ipi6_addr;
  unsigned ipi6_ifindex;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN_PKTINFO_H_
COSMOPOLITAN_C_START_

struct in_pktinfo {
  int ipi_ifindex;
  struct in_addr ipi_spec_dst;
  struct in_addr ipi_addr;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ip_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IP_MREQ_H_
COSMOPOLITAN_C_START_

struct ip_mreq {
  struct in_addr imr_multiaddr; /* IP multicast address of group */
  struct in_addr imr_interface; /* local IP address of interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ipv6_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IPV6_MREQ_H_
COSMOPOLITAN_C_START_

struct ipv6_mreq {
  struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address of group */
  unsigned ipv6mr_interface;        /* local interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/linger.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger {     /* Linux+XNU+BSD ABI */
  int32_t l_onoff;  /* on/off */
  int32_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/msghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_H_
COSMOPOLITAN_C_START_

struct msghdr {            /* Linux+NT ABI */
  void *msg_name;          /* optional address */
  uint32_t msg_namelen;    /* size of msg_name */
  struct iovec *msg_iov;   /* scatter/gather array */
  uint64_t msg_iovlen;     /* # elements in msg_iov */
  void *msg_control;       /* ancillary data c. cmsghdr */
  uint64_t msg_controllen; /* ancillary data buffer len */
  uint32_t msg_flags;      /* MSG_XXX */
};

ssize_t recvmsg(int, struct msghdr *, int);
ssize_t sendmsg(int, const struct msghdr *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_
COSMOPOLITAN_C_START_

struct pollfd {
  int32_t fd;
  int16_t events;
  int16_t revents;
};

int poll(struct pollfd *, uint64_t, int32_t);
int ppoll(struct pollfd *, uint64_t, const struct timespec *, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/append.h */

#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_

#define APPEND_COOKIE 21578

#define appendz   __appendz
#define appendr   __appendr
#define appendd   __appendd
#define appendw   __appendw
#define appends   __appends
#define appendf   __appendf
#define vappendf  __vappendf
#define kappendf  __kappendf
#define kvappendf __kvappendf

COSMOPOLITAN_C_START_

struct appendz {
  size_t i;
  size_t n;
};

struct appendz appendz(char *) libcesque;
ssize_t appendr(char **, size_t) libcesque;
ssize_t appendd(char **, const void *, size_t) libcesque;
ssize_t appendw(char **, uint64_t) libcesque;
ssize_t appends(char **, const char *) libcesque;
ssize_t appendf(char **, const char *, ...) libcesque;
ssize_t vappendf(char **, const char *, va_list) libcesque;
ssize_t kappendf(char **, const char *, ...) libcesque;
ssize_t kvappendf(char **, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_STDIO_APPEND_H_ */


/*!BEGIN libc/stdio/dprintf.h */

#define COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_
COSMOPOLITAN_C_START_

libcesque int dprintf(int, const char *, ...) paramsnonnull((2));
libcesque int vdprintf(int, const char *, va_list) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/ftw.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_FTW_H_
COSMOPOLITAN_C_START_

/**
 * Type for file.
 */
#define FTW_F 1

/**
 * Type for directory.
 */
#define FTW_D 2

/**
 * Type for directory that cannot be read.
 */
#define FTW_DNR 3

/**
 * Type for stat() failed and not a symbolic link.
 */
#define FTW_NS 4

/**
 * Type for symbolic link when `FTW_PHYS` is in flags.
 */
#define FTW_SL 5

/**
 * Directory and `FTW_DEPTH` in flags.
 */
#define FTW_DP 6

/**
 * Type for broken symbolic link when `FTW_PHYS` is not in flags.
 */
#define FTW_SLN 7

/**
 * Flag to prevent following symbolic links (recommended).
 * @see nftw() flags
 */
#define FTW_PHYS 1

/**
 * Flag to prevent crossing mount points.
 * @see nftw() flags
 */
#define FTW_MOUNT 2

/**
 * Unsupported.
 * @see nftw() flags
 */
#define FTW_CHDIR 4

/**
 * Flag for post-order traversal.
 *
 * 1. Will use `FTW_DP` instead of `FTW_D` as type.
 * 2. Directory callback happens *after* rather than before.
 *
 * @see nftw() flags
 */
#define FTW_DEPTH 8

struct FTW {

  /**
   * Byte offset of basename component in `fpath` passed to callback.
   */
  int base;

  /**
   * Depth relative to `dirpath` whose level is zero.
   */
  int level;
};

int ftw(const char *, int (*)(const char *, const struct stat *, int),
        int) dontthrow;

int nftw(const char *,
         int (*)(const char *, const struct stat *, int, struct FTW *), int,
         int) dontthrow;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/iconv.h */

#define COSMOPOLITAN_LIBC_STDIO_ICONV_H_
COSMOPOLITAN_C_START_

typedef void *iconv_t;

iconv_t iconv_open(const char *, const char *);
size_t iconv(iconv_t, char **, size_t *, char **, size_t *);
int iconv_close(iconv_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/rand.h */

#define COSMOPOLITAN_LIBC_RAND_RAND_H_
#define RAND_MAX __INT_MAX__
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § random                                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int rand(void) libcesque;
void srand(unsigned) libcesque;
char *strfry(char *) libcesque;
int getentropy(void *, size_t) libcesque;
ssize_t getrandom(void *, size_t, unsigned) libcesque;
char *initstate(unsigned, char *, size_t) libcesque;
char *setstate(char *) libcesque;
long random(void) libcesque;
void srandom(unsigned) libcesque;

#ifdef _COSMO_SOURCE
#define vigna   __vigna
#define vigna_r __vigna_r
#define rngset  __rngset
#define rdrand  __rdrand
#define rdseed  __rdseed
double poz(double) libcesque;
double pochisq(double, int) libcesque;
uint64_t lemur64(void) libcesque;
uint64_t _rand64(void) libcesque;
uint64_t vigna(void) libcesque;
uint64_t vigna_r(uint64_t[hasatleast 1]) libcesque;
void svigna(uint64_t) libcesque;
uint64_t rdrand(void) libcesque;
uint64_t rdseed(void) libcesque;
void _smt19937(uint64_t) libcesque;
void _Smt19937(uint64_t[], size_t) libcesque;
uint64_t _mt19937(void) libcesque;
double _real1(uint64_t) libcesque;
double _real2(uint64_t) libcesque;
double _real3(uint64_t) libcesque;
double MeasureEntropy(const char *, size_t) libcesque;
void *rngset(void *, size_t, uint64_t (*)(void), size_t) libcesque;
void rt_init(int) libcesque;
void rt_add(void *, int) libcesque;
void rt_end(double *, double *, double *, double *, double *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/readpassphrase.h */

#define COSMOPOLITAN_LIBC_STDIO_READPASSPHRASE_H_

#define RPP_ECHO_OFF    0x00
#define RPP_ECHO_ON     0x01
#define RPP_REQUIRE_TTY 0x02
#define RPP_FORCELOWER  0x04
#define RPP_FORCEUPPER  0x08
#define RPP_SEVENBIT    0x10
#define RPP_STDIN       0x20

COSMOPOLITAN_C_START_

char *readpassphrase(const char *, char *, size_t, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/stdio_ext.h */

#define COSMOPOLITAN_LIBC_STDIO_STDIO_EXT_H_

#define FSETLOCKING_QUERY    0
#define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_BYCALLER 2

COSMOPOLITAN_C_START_

size_t __fbufsize(FILE *) libcesque;
size_t __fpending(FILE *) libcesque;
int __flbf(FILE *) libcesque;
int __freadable(FILE *) libcesque;
int __fwritable(FILE *) libcesque;
int __freading(FILE *) libcesque;
int __fwriting(FILE *) libcesque;
int __fsetlocking(FILE *, int) libcesque;
void _flushlbf(void) libcesque;
void __fpurge(FILE *) libcesque;
void __fseterr(FILE *) libcesque;
const char *__freadptr(FILE *, size_t *) libcesque;
size_t __freadahead(FILE *) libcesque;
void __freadptrinc(FILE *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/syscall.h */

#define COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_
COSMOPOLITAN_C_START_

#define SYS_gettid    1
#define SYS_getrandom 2
#define SYS_getcpu    3

long syscall(long, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/sysparam.h */

#define COSMOPOLITAN_LIBC_SYSPARAM_H_

#define MAXSYMLINKS    20
#define MAXHOSTNAMELEN 64
#define MAXNAMLEN      255
#define MAXPATHLEN     PATH_MAX
#define NBBY           8
#define NGROUPS        32
#define CANBSIZ        255
#define NOFILE         256
#define NCARGS         131072
#define DEV_BSIZE      512
#define NOGROUP        (-1)

COSMOPOLITAN_C_START_

#define __bitop(x, i, o) ((x)[(i) / 8] o(1 << (i) % 8))
#define setbit(x, i)     __bitop(x, i, |=)
#define clrbit(x, i)     __bitop(x, i, &= ~)
#define isset(x, i)      __bitop(x, i, &)
#define isclr(x, i)      !isset(x, i)

#undef roundup
#define roundup(n, d) (howmany(n, d) * (d))
#define powerof2(n)   !(((n)-1) & (n))
#define howmany(n, d) (((n) + ((d)-1)) / (d))

#ifdef MIN
#undef MIN
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

#ifdef MAX
#undef MAX
#endif
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/ntspawn.h */

#define COSMOPOLITAN_NTSPAWN_H_
COSMOPOLITAN_C_START_

struct NtSpawnArgs {
  int64_t dirhand;
  const char *prog;
  char *const *argv;
  char *const *envp;
  char *const *extravars;
  uint32_t dwCreationFlags;
  const char16_t *opt_lpCurrentDirectory;
  int64_t opt_hParentProcess;
  int64_t *opt_lpExplicitHandleList;
  uint32_t dwExplicitHandleCount;
  const struct NtStartupInfo *lpStartupInfo;
  struct NtProcessInformation *opt_out_lpProcessInformation;
};

int mkntenvblock(char16_t[32767], char *const[], char *const[], char[32767]);
int ntspawn(struct NtSpawnArgs *);
size_t mkntcmdline(char16_t *, char *const[], size_t);
void mungentpath(char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/posix_spawn.h */

#define COSMOPOLITAN_LIBC_STDIO_SPAWN_H_

#define POSIX_SPAWN_USEVFORK      0
#define POSIX_SPAWN_RESETIDS      1
#define POSIX_SPAWN_SETPGROUP     2
#define POSIX_SPAWN_SETSIGDEF     4
#define POSIX_SPAWN_SETSIGMASK    8
#define POSIX_SPAWN_SETSCHEDPARAM 16
#define POSIX_SPAWN_SETSCHEDULER  32
#define POSIX_SPAWN_SETSID        128
#define POSIX_SPAWN_SETRLIMIT     256

COSMOPOLITAN_C_START_

typedef struct _posix_spawna *posix_spawnattr_t;
typedef struct _posix_faction *posix_spawn_file_actions_t;

int posix_spawn(int *, const char *, const posix_spawn_file_actions_t *,
                const posix_spawnattr_t *, char *const[], char *const[]);
int posix_spawnp(int *, const char *, const posix_spawn_file_actions_t *,
                 const posix_spawnattr_t *, char *const[], char *const[]);

int posix_spawn_file_actions_init(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *,
                                      int) libcesque;
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int,
                                     int) libcesque;
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *, int,
                                     const char *, int, unsigned) libcesque;
int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *,
                                         const char *) libcesque;
int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
                                          int) libcesque;

int posix_spawnattr_init(posix_spawnattr_t *) libcesque;
int posix_spawnattr_destroy(posix_spawnattr_t *) libcesque;
int posix_spawnattr_getflags(const posix_spawnattr_t *, short *) libcesque;
int posix_spawnattr_setflags(posix_spawnattr_t *, short) libcesque;
int posix_spawnattr_getpgroup(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setpgroup(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedparam(const posix_spawnattr_t *,
                                  struct sched_param *) libcesque;
int posix_spawnattr_setschedparam(posix_spawnattr_t *,
                                  const struct sched_param *) libcesque;
int posix_spawnattr_getsigmask(const posix_spawnattr_t *, sigset_t *) libcesque;
int posix_spawnattr_setsigmask(posix_spawnattr_t *, const sigset_t *) libcesque;
int posix_spawnattr_getsigdefault(const posix_spawnattr_t *,
                                  sigset_t *) libcesque;
int posix_spawnattr_setsigdefault(posix_spawnattr_t *,
                                  const sigset_t *) libcesque;
int posix_spawnattr_getrlimit(const posix_spawnattr_t *, int,
                              struct rlimit *) libcesque;
int posix_spawnattr_setrlimit(posix_spawnattr_t *, int,
                              const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/atomic.h */

#define NSYNC_ATOMIC_H_
COSMOPOLITAN_C_START_

#define nsync_atomic_uint32_ atomic_uint

#define NSYNC_ATOMIC_UINT32_INIT_        0
#define NSYNC_ATOMIC_UINT32_LOAD_(p)     (*(p))
#define NSYNC_ATOMIC_UINT32_STORE_(p, v) (*(p) = (v))
#define NSYNC_ATOMIC_UINT32_PTR_(p)      (p)

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/counter.h */

#define NSYNC_COUNTER_H_


/*!BEGIN third_party/nsync/time.h */

#define NSYNC_TIME_H_
COSMOPOLITAN_C_START_

#define NSYNC_TIME_SEC(t)  ((t).tv_sec)
#define NSYNC_TIME_NSEC(t) ((t).tv_nsec)
#define NSYNC_TIME_STATIC_INIT(t, ns) \
  { (t), (ns) }

/* The type nsync_time represents the interval elapsed between two
   moments in time. Often the first such moment is an address-space-wide
   epoch, such as the Unix epoch, but clients should not rely on the
   epoch in one address space being the same as that in another.
   Intervals relative to the epoch are known as absolute times. */
typedef struct timespec nsync_time;

/* A deadline infinitely far in the future. */
#define nsync_time_no_deadline timespec_max

/* The zero delay, or an expired deadline. */
#define nsync_time_zero timespec_zero

/* Return the current time since the epoch.  */
#define nsync_time_now() timespec_real()

/* Sleep for the specified delay. Returns the unslept time which may be
   non-zero if the call was interrupted. */
#define nsync_time_sleep(a) timespec_sleep(a)

/* Sleep until the specified time.  Returns 0 on success, and EINTR
   if the call was interrupted. */
#define nsync_time_sleep_until(a) timespec_sleep_until(a)

/* Return a+b */
#define nsync_time_add(a, b) timespec_add(a, b)

/* Return a-b */
#define nsync_time_sub(a, b) timespec_sub(a, b)

/* Return +ve, 0, or -ve according to whether a>b, a==b, or a<b. */
#define nsync_time_cmp(a, b) timespec_cmp(a, b)

/* Return the specified number of milliseconds as a time. */
#define nsync_time_ms(a) timespec_frommillis(a)

/* Return the specified number of microseconds as a time. */
#define nsync_time_us(a) timespec_frommicros(a)

/* Return the specified number of nanoseconds as a time. */
#define nsync_time_ns(a) timespec_fromnanos(a)

/* Return an nsync_time constructed from second and nanosecond
   components */
#define nsync_time_s_ns(s, ns) ((nsync_time){(int64_t)(s), (unsigned)(ns)})

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/* An nsync_counter represents an unsigned integer that can count up and down,
   and wake waiters when zero.  */
typedef struct nsync_counter_s_ *nsync_counter;

/* Return a freshly allocated nsync_counter with the specified value,
   of NULL if an nsync_counter cannot be created.

   Any non-NULL returned value should be passed to nsync_counter_free() when no
   longer needed.  */
nsync_counter nsync_counter_new(uint32_t value);

/* Free resources associated with c.  Requires that c was allocated by
   nsync_counter_new(), and no concurrent or future operations are applied to
   c.  */
void nsync_counter_free(nsync_counter c);

/* Add delta to c, and return its new value.  It is a checkable runtime error
   to decrement c below 0, or to increment c (i.e., apply a delta > 0) after a
   waiter has waited.  */
uint32_t nsync_counter_add(nsync_counter c, int32_t delta);

/* Return the current value of c.  */
uint32_t nsync_counter_value(nsync_counter c);

/* Wait until c has value 0, or until abs_deadline, then return
   the value of c.  It is a checkable runtime error to increment c after
   a waiter may have been woken due to the counter reaching zero.
   If abs_deadline==nsync_time_no_deadline, the deadline
   is far in the future. */
uint32_t nsync_counter_wait(nsync_counter c, nsync_time abs_deadline);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/cv.h */

#define NSYNC_CV_H_


/*!BEGIN third_party/nsync/mu.h */

#define NSYNC_MU_H_
COSMOPOLITAN_C_START_

/* An nsync_mu is a lock. If initialized to zero, it's valid and unlocked.

   An nsync_mu can be "free", held by a single thread (aka fiber,
   goroutine) in "write" (exclusive) mode, or by many threads in "read"
   (shared) mode. A thread that acquires it should eventually release
   it. It is illegal to acquire an nsync_mu in one thread and release it
   in another. It is illegal for a thread to reacquire an nsync_mu while
   holding it (even a second share of a "read" lock).

   Example usage:

       static struct foo {
         nsync_mu mu; // protects invariant a+b==0 on fields below.
         int a;
         int b;
       } p = { NSYNC_MU_INIT, 0, 0 };
       // ....
       nsync_mu_lock (&p.mu);
       // The current thread now has exclusive access to p.a and p.b;
       // invariant assumed true.
       p.a++;
       p.b--; // restore invariant p.a+p.b==0 before releasing p.mu
       nsync_mu_unlock (&p.mu)

   Mutexes can be used with condition variables; see nsync_cv.h.

   nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. See nsync_mu_wait.h for more details. Example
   use of nsync_mu_wait() to wait for p.a==0, using definition above:

        int a_is_zero (const void *condition_arg) {
                return (((const struct foo *)condition_arg)->a == 0);
        }
        ...
        nsync_mu_lock (&p.mu);
        nsync_mu_wait (&p.mu, &a_is_zero, &p, NULL);
        // The current thread now has exclusive access to
        // p.a and p.b, and p.a==0.
        ...
        nsync_mu_unlock (&p.mu);

*/
typedef struct nsync_mu_s_ {
  nsync_atomic_uint32_ word; /* internal use only */
  int _zero;                 /* c pthread_mutex_t */
  struct Dll *waiters;       /* internal use only */
} nsync_mu;

/* An nsync_mu should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_MU_INIT, or by setting
   the entire structure to all zeroes, or using nsync_mu_init(). */
#define NSYNC_MU_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }
void nsync_mu_init(nsync_mu *mu);

/* Block until *mu is free and then acquire it in writer mode. Requires
   that the calling thread not already hold *mu in any mode. */
void nsync_mu_lock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in write mode by the
   calling thread, and wake waiters, if appropriate. */
void nsync_mu_unlock(nsync_mu *mu);

/* Attempt to acquire *mu in writer mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. */
int nsync_mu_trylock(nsync_mu *mu);

/* Block until *mu can be acquired in reader mode and then acquire it.
   Requires that the calling thread not already hold *mu in any mode. */
void nsync_mu_rlock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in read mode by the calling
   thread, and wake waiters, if appropriate. */
void nsync_mu_runlock(nsync_mu *mu);

/* Attempt to acquire *mu in reader mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. Perhaps fail to acquire if a writer is waiting, to
   avoid starvation. */
int nsync_mu_rtrylock(nsync_mu *mu);

/* May abort if *mu is not held in write mode by the calling thread. */
void nsync_mu_assert_held(const nsync_mu *mu);

/* May abort if *mu is not held in read or write mode
   by the calling thread.  */
void nsync_mu_rassert_held(const nsync_mu *mu);

/* Return whether *mu is held in read mode.
   Requires that the calling thread holds *mu in some mode. */
int nsync_mu_is_reader(const nsync_mu *mu);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

#define NSYNC_CV_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }

struct nsync_note_s_;

/* An nsync_cv is a condition variable in the style of Mesa, Java,
   POSIX, and Go's sync.Cond. It allows a thread to wait for a condition
   on state protected by a mutex, and to proceed with the mutex held and
   the condition true.

   See also nsync_mu_wait() and nsync_mu_wait_with_deadline(), which
   implement conditional critical sections. In many cases, they are
   easier to use than condition variables.

   Usage

   After making the desired predicate true, call:

       nsync_cv_signal (&cv);    // If at most one thread can make use
                                 // of the predicate becoming true.

   or

       nsync_cv_broadcast (&cv); // If multiple threads can make use
                                 // of the predicate becoming true.

   To wait for a predicate with no deadline (assuming
   nsync_cv_broadcast() or nsync_cv_signal() is called whenever the
   predicate becomes true):

       nsync_mu_lock (&mu;)
       while (!some_predicate_protected_by_mu) { // while-loop required
         nsync_cv_wait (&cv, &mu);
       }
       // predicate is now true
       nsync_mu_unlock (&mu);

   To wait for a predicate with a deadline (assuming nsync_cv_broadcast() or
   nsync_cv_signal() is called whenever the predicate becomes true):

       nsync_mu_lock (&mu);
       while (!some_predicate_protected_by_mu &&
         nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                      cancel_note) == 0) {
       }
       if (some_predicate_protected_by_mu) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   or, if the predicate is complex and you wish to write it just once
   and inline, you could use the following instead of the for-loop
   above:

       nsync_mu_lock (&mu);
       int pred_is_true = 0;
       int outcome = 0;
       while (!(pred_is_true = some_predicate_protected_by_mu) &&
              outcome == 0) {
         outcome = nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                                cancel_note);
       }
       if (pred_is_true) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   As the examples show, Mesa-style condition variables require that
   waits use a loop that tests the predicate anew after each wait. It
   may be surprising that these are preferred over the precise wakeups
   offered by the condition variables in Hoare monitors. Imprecise
   wakeups make more efficient use of the critical section, because
   threads can enter it while a woken thread is still emerging from the
   scheduler, which may take thousands of cycles. Further, they make the
   programme easier to read and debug by making the predicate explicit
   locally at the wait, where the predicate is about to be assumed; the
   reader does not have to infer the predicate by examining all the
   places where wakeups may occur. */
typedef struct nsync_cv_s_ {
  /* see bits below */
  nsync_atomic_uint32_ word;
  /* points to tail of list of waiters; under mu. */
  struct Dll *waiters;
} nsync_cv;

/* An nsync_cv should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_CV_INIT, or by setting
   the entire struct to 0, or using nsync_cv_init(). */
void nsync_cv_init(nsync_cv *cv);

/* Wake at least one thread if any are currently blocked on *cv. If the
   chosen thread is a reader on an nsync_mu, wake all readers and, if
   possible, a writer. */
void nsync_cv_signal(nsync_cv *cv);

/* Wake all threads currently blocked on *cv. */
void nsync_cv_broadcast(nsync_cv *cv);

/* Atomically release "mu" (which must be held on entry) and block the
   caller on *cv. Wait until awakened by a call to nsync_cv_signal() or
   nsync_cv_broadcast(), or a spurious wakeup; then reacquire "mu", and
   return. Equivalent to a call to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL. Callers
   should use nsync_cv_wait() in a loop, as with all standard Mesa-style
   condition variables. See examples above. Returns 0 normally, otherwise
   ECANCELED may be returned if calling POSIX thread is cancelled only when
   the PTHREAD_CANCEL_MASKED mode is in play. */
int nsync_cv_wait(nsync_cv *cv, nsync_mu *mu);

/* Atomically release "mu" (which must be held on entry) and block the
   calling thread on *cv. It then waits until awakened by a call to
   nsync_cv_signal() or nsync_cv_broadcast() (or a spurious wakeup), or
   by the time reaching abs_deadline, or by cancel_note being notified.
   In all cases, it reacquires "mu", and returns the reason for the call
   returned (0, ETIMEDOUT, or ECANCELED). Use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no nsync cancellations (however POSIX thread
   cancellations may still happen, and ECANCELED could still be returned
   when the calling thread is cancelled only if PTHREAD_CANCEL_MASKED is
   in play). wait_with_deadline() should be used in a loop, as with all
   Mesa-style condition variables. See examples above.

   There are two reasons for using an absolute deadline, rather than a
   relative timeout---these are why pthread_cond_timedwait() also uses
   an absolute deadline. First, condition variable waits have to be used
   in a loop; with an absolute times, the deadline does not have to be
   recomputed on each iteration. Second, in most real programmes, some
   activity (such as an RPC to a server, or when guaranteeing response
   time in a UI), there is a deadline imposed by the specification or
   the caller/user; relative delays can shift arbitrarily with
   scheduling delays, and so after multiple waits might extend beyond
   the expected deadline. Relative delays tend to be more convenient
   mostly in tests and trivial examples than they are in real
   programmes. */
int nsync_cv_wait_with_deadline(nsync_cv *cv, nsync_mu *mu,
                                nsync_time abs_deadline,
                                struct nsync_note_s_ *cancel_note);

/* Like nsync_cv_wait_with_deadline(), but allow an arbitrary lock *v to be
   used, given its (*lock)(mu) and (*unlock)(mu) routines.  */
int nsync_cv_wait_with_deadline_generic(nsync_cv *cv, void *mu,
                                        void (*lock)(void *),
                                        void (*unlock)(void *),
                                        nsync_time abs_deadline,
                                        struct nsync_note_s_ *cancel_note);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/debug.h */

#define NSYNC_DEBUG_H_
COSMOPOLITAN_C_START_

/* Debugging operations for mutexes and condition variables.

   These operations should not be relied upon for normal functionality.
   The implementation may be slow, output formats may change, and the
   implementation is free to yield the empty string. */

/* Place in buf[0,..,n-1] a nul-terminated, human readable string
   indicative of some of the internal state of the mutex or condition
   variable, and return buf. If n>=4, buffer overflow is indicated by
   placing the characters "..." at the end of the string.

   The *_and_waiters() variants attempt to output the waiter lists in
   addition to the basic state. These variants may acquire internal
   locks and follow internal pointers. Thus, they are riskier if invoked
   in an address space whose overall health is uncertain. */
char *nsync_mu_debug_state(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state(nsync_cv *cv, char *buf, int n);
char *nsync_mu_debug_state_and_waiters(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state_and_waiters(nsync_cv *cv, char *buf, int n);

/* Like nsync_*_debug_state_and_waiters(), but ignoring all locking and
   safety considerations, and using an internal, possibly static buffer
   that may be overwritten by subsequent or concurrent calls to these
   routines. These variants should be used only from an interactive
   debugger, when all other threads are stopped; the debugger is
   expected to recover from errors. */
char *nsync_mu_debugger(nsync_mu *mu);
char *nsync_cv_debugger(nsync_cv *cv);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_semaphore.h */

#define NSYNC_SEM_H_
COSMOPOLITAN_C_START_

typedef struct nsync_semaphore_s_ {
  void *sem_space[3];
} nsync_semaphore;

/* Initialize *s; the initial value is 0. */
void nsync_mu_semaphore_init(nsync_semaphore *s);

/* Wait until the count of *s exceeds 0, and decrement it. */
errno_t nsync_mu_semaphore_p(nsync_semaphore *s);

/* Wait until one of: the count of *s is non-zero, in which case
   decrement *s and return 0; or abs_deadline expires, in which case
   return ETIMEDOUT. */
errno_t nsync_mu_semaphore_p_with_deadline(nsync_semaphore *s,
                                           nsync_time abs_deadline);

/* Ensure that the count of *s is at least 1. */
void nsync_mu_semaphore_v(nsync_semaphore *s);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_wait.h */

#define NSYNC_MU_WAIT_H_
COSMOPOLITAN_C_START_

/* nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. In many straightforward situations they are
   of equivalent performance and are somewhat easier to use, because
   unlike condition variables, they do not require that the waits be
   placed in a loop, and they do not require explicit wakeup calls.
   Example:

   Definitions:

       static nsync_mu mu = NSYNC_MU_INIT;
       static int i = 0;  // protected by mu
       // Condition for use with nsync_mu_wait().
       static int int_is_zero (const void *v) {
         return (*(const int *)v == 0);
       }

   Waiter:

       nsync_mu_lock (&mu);
       // Wait until i is zero.
       nsync_mu_wait (&mu, &int_is_zero, &i, NULL);
       // i is known to be zero here.
       // ...
       nsync_mu_unlock (&mu);

   Thread potentially making i zero:

       nsync_mu_lock (&mu);
       i--;
       // No need to signal that i may have become zero.  The unlock call
       // below will evaluate waiters' conditions to decide which to wake.
       nsync_mu_unlock (&mu);

   It is legal to use conditional critical sections and condition
   variables on the same mutex.

                              --------------

   The implementation benefits from determining whether waiters are
   waiting for the same condition; it may then evaluate a condition once
   on behalf of several waiters. Two waiters have equal condition if
   their "condition" pointers are equal, and either:

     - their "condition_arg" pointers are equal, or

     - "condition_arg_eq" is non-null and (*condition_arg_eq)
       (condition_arg0, condition_arg1) returns non-zero.

   *condition_arg_eq will not be invoked unless the "condition" pointers
   are equal, and the "condition_arg" pointers are unequal.

   If many waiters wait for distinct conditions simultaneously,
   condition variables may be faster.
 */

struct nsync_note_s_; /* forward declaration for an nsync_note */

/* Return when (*condition) (condition_arg) is true. Perhaps unlock and
   relock *mu while blocked waiting for the condition to become true.
   nsync_mu_wait() is equivalent to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL.

   Requires that *mu be held on entry. See nsync_mu_wait_with_deadline()
   for more details on *condition and *condition_arg_eq. */
void nsync_mu_wait(nsync_mu *mu, int (*condition)(const void *condition_arg),
                   const void *condition_arg,
                   int (*condition_arg_eq)(const void *a, const void *b));

/* Return when at least one of: (*condition) (condition_arg) is true,
   the deadline expires, or *cancel_note is notified. Perhaps unlock and
   relock *mu while blocked waiting for one of these events, but always
   return with *mu held. Return 0 iff the (*condition) (condition_arg)
   is true on return, and otherwise either ETIMEDOUT or ECANCELED,
   depending on why the call returned early. Callers should use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no cancellation.

   Requires that *mu be held on entry.

   The implementation may call *condition from any thread using the
   mutex, and while holding *mu in either read or write mode; it
   guarantees that any thread calling *condition will hold *mu in some
   mode. Requires that (*condition) (condition_arg) neither modify state
   protected by *mu, nor return a value dependent on state not protected
   by *mu. To depend on time, use the abs_deadline parameter.
   (Conventional use of condition variables have the same restrictions
   on the conditions tested by the while-loop.) If non-null,
   condition_arg_eq should return whether two condition_arg calls with
   the same "condition" pointer are considered equivalent; it should
   have no side-effects. */
int nsync_mu_wait_with_deadline(
    nsync_mu *mu, int (*condition)(const void *condition_arg),
    const void *condition_arg,
    int (*condition_arg_eq)(const void *a, const void *b),
    nsync_time abs_deadline, struct nsync_note_s_ *cancel_note);

/* Unlock *mu, which must be held in write mode, and wake waiters, if
   appropriate. Unlike nsync_mu_unlock(), this call is not required to
   wake nsync_mu_wait/nsync_mu_wait_with_deadline calls on conditions
   that were false before this thread acquired the lock. This call
   should be used only at the end of critical sections for which:
   - nsync_mu_wait and/or nsync_mu_wait_with_deadline are in use on the same
     mutex,
   - this critical section cannot make the condition true for any of those
     nsync_mu_wait/nsync_mu_wait_with_deadline waits, and
   - when performance is significantly improved by using this call. */
void nsync_mu_unlock_without_wakeup(nsync_mu *mu);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/note.h */

#define NSYNC_NOTE_H_
COSMOPOLITAN_C_START_

/* An nsync_note represents a single bit that can transition from 0 to 1
   at most once. When 1, the note is said to be notified. There are
   operations to wait for the transition, which can be triggered either
   by an explicit call, or timer expiry. Notes can have parent notes; a
   note becomes notified if its parent becomes notified. */
typedef struct nsync_note_s_ *nsync_note;

/* Return a freshly allocated nsync_note, or NULL if an nsync_note
   cannot be created.

   If parent!=NULL, the allocated nsync_note's parent will be parent.
   The newaly allocated note will be automatically notified at
   abs_deadline, and is notified at initialization if
   abs_deadline==nsync_zero_time.

   nsync_notes should be passed to nsync_note_free() when no longer needed. */
nsync_note nsync_note_new(nsync_note parent, nsync_time abs_deadline);

/* Free resources associated with n. Requires that n was allocated by
   nsync_note_new(), and no concurrent or future operations are applied
   to n directly.

   It is legal to call nsync_note_free() on a node even if it has a
   parent or children that are in use; if n has both a parent and
   children, n's parent adopts its children. */
void nsync_note_free(nsync_note n);

/* Notify n and all its descendants. */
void nsync_note_notify(nsync_note n);

/* Return whether n has been notified.  */
int nsync_note_is_notified(nsync_note n);

/* Wait until n has been notified or abs_deadline is reached, and return
   whether n has been notified. If abs_deadline==nsync_time_no_deadline,
   the deadline is far in the future. */
int nsync_note_wait(nsync_note n, nsync_time abs_deadline);

/* Return the expiry time associated with n. This is the minimum of the
   abs_deadline passed on creation and that of any of its ancestors. */
nsync_time nsync_note_expiry(nsync_note n);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/once.h */

#define NSYNC_ONCE_H_
COSMOPOLITAN_C_START_

/* An nsync_once allows a function to be called exactly once, when first
   referenced. */
typedef nsync_atomic_uint32_ nsync_once;

/* An initializer for nsync_once; it is guaranteed to be all zeroes. */
#define NSYNC_ONCE_INIT NSYNC_ATOMIC_UINT32_INIT_

/* The first time nsync_run_once() or nsync_run_once_arg() is applied to
   *once, the supplied function is run (with argument, in the case of
   nsync_run_once_arg()). Other callers will wait until the run of the
   function is complete, and then return without running the function
   again. */
void nsync_run_once(nsync_once *once, void (*f)(void));
void nsync_run_once_arg(nsync_once *once, void (*farg)(void *arg), void *arg);

/* Same as nsync_run_once()/nsync_run_once_arg() but uses a spinloop.
   Can be used on the same nsync_once as
   nsync_run_once/nsync_run_once_arg().

   These *_spin variants should be used only in contexts where normal
   blocking is disallowed, such as within user-space schedulers, when
   the runtime is not fully initialized, etc. They provide no
   significant performance benefit, and they should be avoided in normal
   code. */
void nsync_run_once_spin(nsync_once *once, void (*f)(void));
void nsync_run_once_arg_spin(nsync_once *once, void (*farg)(void *arg),
                             void *arg);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/waiter.h */

#define NSYNC_WAITER_H_
COSMOPOLITAN_C_START_

/* nsync_wait_n() allows the client to wait on multiple objects
   (condition variables, nsync_notes, nsync_counters, etc.) until at
   least one of them becomes ready, or a deadline expires.

   It can be thought of as rather like Unix's select() or poll(), except
   the the objects being waited for are synchronization data structures,
   rather than file descriptors.

   The client can construct new objects that can be waited for by
   implementing three routines.

   Examples:

   To wait on two nsync_notes n0, n1, and a nsync_counter c0, with a
   deadline of abs_deadline:

       // Form an array of struct nsync_waitable_s, identifying the
       // objects and the corresponding descriptors. (Static
       // initialization syntax is used for brevity.)
       static struct nsync_waitable_s w[] = {
         { &n0, &nsync_note_waitable_funcs },
         { &n1, &nsync_note_waitable_funcs },
         { &c0, &nsync_counter_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1], &w[2] };
       int n = sizeof (w) / sizeof (w[0]);

       // Wait. The mu, lock, and unlock arguments are NULL because no
       // condition variables are invovled.
       int i = nsync_wait_n (NULL, NULL, NULL, abs_deadline, n, pw);
       if (i == n) {
         // timeout
       } else {
         // w[i].v became ready.
       }

    To wait on multiple condition variables, the mu/lock/unlock
    parameters are used. Imagine cv0 and cv1 are signalled when
    predicates pred0() (under lock mu0) and pred1() (under lock mu1)
    become true respectively. Assume that mu0 is acquired before mu1.

       static void lock2 (void *v) {  // lock two mutexes in order
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_lock (mu[0]);
         nsync_mu_lock (mu[1]);
       }
       static void unlock2 (void *v) { // unlock two mutexes.
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_unlock (mu[1]);
         nsync_mu_unlock (mu[0]);
       }

       // Describe the condition variables and the locks.
       static struct nsync_waitable_s w[] = {
         { &cv0, &nsync_cv_waitable_funcs },
         { &cv1, &nsync_cv_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1] };
       nsync_mu *lock_list[] = { &mu0, &mu1 };
       int n = sizeof (w) / sizeof (w[0]);

       lock2 (list_list);
       while (!pred0 () && !pred1 ()) {
         // Wait for one of the condition variables to be signalled,
         // with no timeout.
         nsync_wait_n (lock_list, &lock2, &unlock2,
                       nsync_time_no_deadline, n, pw);
       }
       if (pred0 ()) { ... }
       if (pred1 ()) { ... }
       unlock2 (list_list);

   */

/* forward declaration of struct that contains type dependent wait
   operations */
struct nsync_waitable_funcs_s;

/* Clients wait on objects by forming an array of struct
   nsync_waitable_s. Each each element points to one object and its
   type-dependent functions. */
struct nsync_waitable_s {
  /* pointer to object */
  void *v;
  /* pointer to type-dependent functions. Use
     &nsync_note_waitable_funcs for an nsync_note,
     &nsync_counternote_waitable_funcs for an nsync_counter,
     &nsync_cv_waitable_funcs for an nsync_cv. */
  const struct nsync_waitable_funcs_s *funcs;
};

/* Wait until at least one of *waitable[0,..,count-1] is has been
   notified, or abs_deadline is reached. Return the index of the
   notified element of waitable[], or count if no such element exists.
   If mu!=NULL, (*unlock)(mu) is called after the thread is queued on
   the various waiters, and (*lock)(mu) is called before return;
   mu/lock/unlock are used to acquire and release the relevant locks
   whan waiting on condition variables. */
int nsync_wait_n(void *mu, void (*lock)(void *), void (*unlock)(void *),
                 nsync_time abs_deadline, int count,
                 struct nsync_waitable_s *waitable[]);

/* A "struct nsync_waitable_s" implementation must implement these
   functions. Clients should ignore the internals. */
struct nsync_waiter_s;
struct nsync_waitable_funcs_s {

  /* Return the time when *v will be ready (max time if unknown), or 0
     if it is already ready. The parameter nw may be passed as NULL, in
     which case the result should indicate whether the thread would
     block if it were to wait on *v. All calls with the same *v must
     report the same result until the object becomes ready, from which
     point calls must report 0. */
  nsync_time (*ready_time)(void *v, struct nsync_waiter_s *nw);

  /* If *v is ready, return zero; otherwise enqueue *nw on *v and return
     non-zero. */
  int (*enqueue)(void *v, struct nsync_waiter_s *nw);

  /* If nw has been previously dequeued, return zero; otherwise dequeue
   *nw from *v and return non-zero.  */
  int (*dequeue)(void *v, struct nsync_waiter_s *nw);
};

/* The "struct nsync_waitable_s" for nsync_note, nsync_counter, and nsync_cv. */
extern const struct nsync_waitable_funcs_s nsync_note_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_counter_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_cv_waitable_funcs;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/avx512.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
COSMOPOLITAN_C_START_

union XedAvx512Payload1 {
  struct {
    unsigned map : 4;
    unsigned rr_inv : 1;
    unsigned b_inv : 1;
    unsigned x_inv : 1;
    unsigned r_inv : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload2 {
  struct {
    unsigned pp : 2;
    unsigned ubit : 1;
    unsigned vexdest210 : 3;
    unsigned vexdest3 : 1;
    unsigned rexw : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload3 {
  struct {
    unsigned mask : 3;
    unsigned vexdest4p : 1;
    unsigned bcrc : 1;
    unsigned llrc : 2;
    unsigned z : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/private.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_PRIVATE_H_


/*!BEGIN third_party/xed/x86.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86_H_
/*           ▓▓▓▓▓▓▓▓▓▓▓▓▓                      ▄▄▄▄
             ▓▓▓▓▓▓▓▓▓▓▓▓▓     ▄▓▓▓▓▓▓▄      ▄▓▓▓▓▓▓▓▓            ▄▓▓▓▀
             ▓▓▓▓    ▓▓▓▓▓    ▓     ▓▓▓▓    ▓▓       ▓▓▓      ▄▓▓▓▓
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▬▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▬▬▬▬▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓     ▓▓▓▄     ▓▓▓   ▓▓▓▓             │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▀▓▓▓▓▄▄▄▓▓▓▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓▓▓▄   ▄▄▓▓▓▓▓▓▓▓▓  ▓▓▓▓      ▓▓▓▄    │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▄▄▓▓▀  ▀▀▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬║▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▓▓▓ ▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬║▬▬▬
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▓▓▓▓▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
■■■■■■■■║■■■■▓▓▓▓    ▓▓▓▓▓■■■▓▓▓▄▄▄▓▓▓▓■■■■▬▓▓▓▓▄▄▄▄▓▓▓■■■■▬▓▓▓▓▄▄▄▓▓▓▓▀■■■■║■■■
■■■■■■■■■■■■■▓▓▓▓▓▓▓▓▓▓▓▓▓■■■■■▀▓▓▓■■■■■■■■■■■■■■▀▀■■■■■■■■■■■■▀▓▓▀■■■■■■■■■■■■■
        ║▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓║
╔───────╨───────────────────────────────────────────────────────────────────╨──╗
│ cosmopolitan § virtual machine » byte code language                          │
╚─────────────────────────────────────────────────────────────────────────────*/

#define XED_MAX_INSTRUCTION_BYTES 15

#define XED_MODE_REAL   0
#define XED_MODE_LEGACY 1
#define XED_MODE_LONG   2

#define XED_HINT_NTAKEN 2
#define XED_HINT_TAKEN  4
#define XED_HINT_ALTER  6

#define XED_SEG_ES 1
#define XED_SEG_CS 2
#define XED_SEG_SS 3
#define XED_SEG_DS 4
#define XED_SEG_FS 5
#define XED_SEG_GS 6

#define xed_modrm_mod(M)           (((M)&0xff) >> 6)
#define xed_modrm_reg(M)           (((M)&0b00111000) >> 3)
#define xed_modrm_rm(M)            ((M)&7)
#define xed_sib_base(M)            ((M)&7)
#define xed_sib_index(M)           (((M)&0b00111000) >> 3)
#define xed_sib_scale(M)           (((M)&0xff) >> 6)
#define xed_get_modrm_reg_field(M) (((M)&0x38) >> 3)

COSMOPOLITAN_C_START_

#define XED_MACHINE_MODE_REAL           XED_MODE_REAL
#define XED_MACHINE_MODE_LEGACY_32      XED_MODE_LEGACY
#define XED_MACHINE_MODE_LONG_64        XED_MODE_LONG
#define XED_MACHINE_MODE_UNREAL         (1 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LEGACY_16      (2 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_16 (3 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_32 (4 << 2 | XED_MODE_LEGACY)
#define XED_MACHINE_MODE_LAST           (XED_MACHINE_MODE_LONG_COMPAT_32 + 1)

#define XED_ERROR_NONE                         0
#define XED_ERROR_BUFFER_TOO_SHORT             1
#define XED_ERROR_GENERAL_ERROR                2
#define XED_ERROR_INVALID_FOR_CHIP             3
#define XED_ERROR_BAD_REGISTER                 4
#define XED_ERROR_BAD_LOCK_PREFIX              5
#define XED_ERROR_BAD_REP_PREFIX               6
#define XED_ERROR_BAD_LEGACY_PREFIX            7
#define XED_ERROR_BAD_REX_PREFIX               8
#define XED_ERROR_BAD_EVEX_UBIT                9
#define XED_ERROR_BAD_MAP                      10
#define XED_ERROR_BAD_EVEX_V_PRIME             11
#define XED_ERROR_BAD_EVEX_Z_NO_MASKING        12
#define XED_ERROR_NO_OUTPUT_POINTER            13
#define XED_ERROR_NO_AGEN_CALL_BACK_REGISTERED 14
#define XED_ERROR_BAD_MEMOP_INDEX              15
#define XED_ERROR_CALLBACK_PROBLEM             16
#define XED_ERROR_GATHER_REGS                  17
#define XED_ERROR_INSTR_TOO_LONG               18
#define XED_ERROR_INVALID_MODE                 19
#define XED_ERROR_BAD_EVEX_LL                  20
#define XED_ERROR_UNIMPLEMENTED                21
#define XED_ERROR_LAST                         22

#define XED_ADDRESS_WIDTH_INVALID 0
#define XED_ADDRESS_WIDTH_16b     2
#define XED_ADDRESS_WIDTH_32b     4
#define XED_ADDRESS_WIDTH_64b     8
#define XED_ADDRESS_WIDTH_LAST    9

#define XED_ILD_MAP0        0 /* 8086+  ... */
#define XED_ILD_MAP1        1 /* 286+   0x0F,... */
#define XED_ILD_MAP2        2 /* Core2+ 0x0F,0x38,... */
#define XED_ILD_MAP3        3 /* Core2+ 0x0F,0x3A,... */
#define XED_ILD_MAP4        4
#define XED_ILD_MAP5        5
#define XED_ILD_MAP6        6
#define XED_ILD_MAPAMD      7
#define XED_ILD_MAP_XOP8    8
#define XED_ILD_MAP_XOP9    9
#define XED_ILD_MAP_XOPA    10
#define XED_ILD_MAP_LAST    11
#define XED_ILD_MAP_INVALID 12

struct XedOperands { /*
  ┌rep
  │ ┌log₂𝑏
  │ │ ┌mode
  │ │ │ ┌eamode
  │ │ │ │ ┌mod
  │ │ │ │ │
  │ │ │ │ │  ┌sego
  │ │ │ │ │  │
  │ │ │ │ │  │   ┌rex         REGISTER
  │ │ │ │ │  │   │┌rexb       DISPATCH
  │ │ │ │ │  │   ││┌srm       ENCODING
  │ │ │ │ │  │   │││  ┌rex
  │ │ │ │ │  │   │││  │┌rexb
  │ │ │ │ │  │   │││  ││┌rm
  │ │ │ │ │  │   │││  │││  ┌rexw
  │ │ │ │ │  │   │││  │││  │┌osz
  │ │ │ │ │  │   │││  │││  ││┌rex
  │ │ │ │ │  │   │││  │││  │││┌rexr
  │ │ │ │ │  │   │││  │││  ││││┌reg
  │3│2│2│2│2 │   │││  │││  │││││
  │0│8│6│4│2 │18 │││12│││ 7│││││ 0
  ├┐├┐├┐├┐├┐ ├─┐ ││├─┐││├─┐││││├─┐
  00000000000000000000000000000000*/
  uint32_t rde;
  union {
    struct {
      union {
        uint8_t opcode;
        uint8_t srm : 3;
      };
      uint8_t map : 4;
    };
    uint16_t dispatch;
  };
  union {
    uint8_t sib;
    struct {
      uint8_t base : 3;
      uint8_t index : 3;
      uint8_t scale : 2;
    };
  };
  bool osz : 1;   /* operand size override prefix */
  bool rexw : 1;  /* rex.w or rex.wb or etc. 64-bit override */
  bool rexb : 1;  /* rex.b or rex.wb or etc. see modrm table */
  bool rexr : 1;  /* rex.r or rex.wr or etc. see modrm table */
  bool rex : 1;   /* any rex prefix including rex */
  bool rexx : 1;  /* rex.x or rex.wx or etc. see sib table */
  bool rexrr : 1; /* evex */
  bool asz : 1;   /* address size override */
  int64_t disp;   /* displacement(%xxx) mostly sign-extended */
  uint64_t uimm0; /* $immediate mostly sign-extended */
  bool out_of_bytes : 1;
  bool is_intel_specific : 1;
  bool ild_f2 : 1;
  bool ild_f3 : 1;
  bool has_sib : 1;
  bool realmode : 1;
  bool amd3dnow : 1;
  bool lock : 1;
  union {
    uint8_t modrm; /* selects address register */
    struct {
      uint8_t rm : 3;
      uint8_t reg : 3;
      uint8_t mod : 2;
    };
  };
  uint8_t max_bytes;
  uint8_t rep : 2; /* 0, 2 (0xf2 repnz), 3 (0xf3 rep/repe) */
  uint8_t has_modrm : 2;
  bool imm_signed : 1;       /* internal */
  bool disp_unsigned : 1;    /* internal */
  uint8_t seg_ovd : 3;       /* XED_SEG_xx */
  uint8_t error : 5;         /* enum XedError */
  uint8_t mode : 2;          /* real,legacy,long */
  uint8_t hint : 3;          /* static branch prediction */
  uint8_t uimm1;             /* enter $x,$y */
  uint8_t disp_width;        /* in bits */
  uint8_t imm_width;         /* in bits */
  uint8_t mode_first_prefix; /* see xed_set_chip_modes() */
  uint8_t nrexes;
  uint8_t nprefixes;
  uint8_t nseg_prefixes;
  uint8_t ubit;       /* vex */
  uint8_t vexvalid;   /* vex */
  uint8_t vexdest3;   /* vex */
  uint8_t vexdest4;   /* vex */
  uint8_t vexdest210; /* vex */
  uint8_t vex_prefix; /* vex */
  uint8_t zeroing;    /* evex */
  uint8_t bcrc;       /* evex */
  uint8_t llrc;       /* evex */
  uint8_t vl;         /* evex */
  uint8_t mask;       /* evex */
  uint8_t imm1_bytes; /* evex */
  uint8_t pos_disp;
  uint8_t pos_imm;
  uint8_t pos_imm1;
  uint8_t pos_modrm;
  uint8_t pos_opcode;
  uint8_t pos_sib;
};

struct XedDecodedInst {
  unsigned char length;
  uint8_t bytes[15];
  struct XedOperands op;
};

#define xed_operands_set_mode(p, machine_mode) \
  do {                                         \
    struct XedOperands *__p = p;               \
    __p->realmode = false;                     \
    switch (machine_mode) {                    \
      default:                                 \
      case XED_MACHINE_MODE_LONG_64:           \
        __p->mode = XED_MODE_LONG;             \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_32:         \
      case XED_MACHINE_MODE_LONG_COMPAT_32:    \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_REAL:              \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
      case XED_MACHINE_MODE_UNREAL:            \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_16:         \
      case XED_MACHINE_MODE_LONG_COMPAT_16:    \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
    }                                          \
  } while (0)

extern const char kXedErrorNames[];
extern const uint8_t kXedEamode[2][3];

struct XedDecodedInst *xed_decoded_inst_zero_set_mode(struct XedDecodedInst *,
                                                      int);
int xed_instruction_length_decode(struct XedDecodedInst *, const void *,
                                  size_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef int xed_int_t;
typedef unsigned int xed_uint_t;
typedef unsigned int xed_uint_t;
typedef unsigned char xed_bits_t;
typedef intptr_t xed_addr_t;
typedef bool xed_bool_t;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/x86isa.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_
COSMOPOLITAN_C_START_

#define XED_CHIP_INVALID           1
#define XED_CHIP_I86               2
#define XED_CHIP_I86FP             3
#define XED_CHIP_I186              4
#define XED_CHIP_I186FP            5
#define XED_CHIP_I286REAL          6
#define XED_CHIP_I286              7
#define XED_CHIP_I2186FP           8
#define XED_CHIP_I386REAL          9
#define XED_CHIP_I386              10
#define XED_CHIP_I386FP            11
#define XED_CHIP_I486REAL          12
#define XED_CHIP_I486              13
#define XED_CHIP_PENTIUMREAL       14
#define XED_CHIP_PENTIUM           15
#define XED_CHIP_QUARK             16
#define XED_CHIP_PENTIUMMMXREAL    17
#define XED_CHIP_PENTIUMMMX        18
#define XED_CHIP_ALLREAL           19
#define XED_CHIP_PENTIUMPRO        20
#define XED_CHIP_PENTIUM2          21
#define XED_CHIP_PENTIUM3          22
#define XED_CHIP_PENTIUM4          23
#define XED_CHIP_P4PRESCOTT        24
#define XED_CHIP_P4PRESCOTT_NOLAHF 25
#define XED_CHIP_P4PRESCOTT_VTX    26
#define XED_CHIP_CORE2             27
#define XED_CHIP_PENRYN            28
#define XED_CHIP_PENRYN_E          29
#define XED_CHIP_NEHALEM           30
#define XED_CHIP_WESTMERE          31
#define XED_CHIP_BONNELL           32
#define XED_CHIP_SALTWELL          33
#define XED_CHIP_SILVERMONT        34
#define XED_CHIP_AMD               35
#define XED_CHIP_GOLDMONT          36
#define XED_CHIP_GOLDMONT_PLUS     37
#define XED_CHIP_TREMONT           38
#define XED_CHIP_SANDYBRIDGE       39
#define XED_CHIP_IVYBRIDGE         40
#define XED_CHIP_HASWELL           41
#define XED_CHIP_BROADWELL         42
#define XED_CHIP_SKYLAKE           43
#define XED_CHIP_SKYLAKE_SERVER    44
#define XED_CHIP_CASCADE_LAKE      45
#define XED_CHIP_KNL               46
#define XED_CHIP_KNM               47
#define XED_CHIP_CANNONLAKE        48
#define XED_CHIP_ICELAKE           49
#define XED_CHIP_ICELAKE_SERVER    50
#define XED_CHIP_FUTURE            51
#define XED_CHIP_ALL               52
#define XED_CHIP_LAST              53

#define XED_ISA_SET_INVALID               0
#define XED_ISA_SET_3DNOW                 1
#define XED_ISA_SET_ADOX_ADCX             2
#define XED_ISA_SET_AES                   3
#define XED_ISA_SET_AMD                   4
#define XED_ISA_SET_AVX                   5
#define XED_ISA_SET_AVX2                  6
#define XED_ISA_SET_AVX2GATHER            7
#define XED_ISA_SET_AVX512BW_128          8
#define XED_ISA_SET_AVX512BW_128N         9
#define XED_ISA_SET_AVX512BW_256          10
#define XED_ISA_SET_AVX512BW_512          11
#define XED_ISA_SET_AVX512BW_KOP          12
#define XED_ISA_SET_AVX512CD_128          13
#define XED_ISA_SET_AVX512CD_256          14
#define XED_ISA_SET_AVX512CD_512          15
#define XED_ISA_SET_AVX512DQ_128          16
#define XED_ISA_SET_AVX512DQ_128N         17
#define XED_ISA_SET_AVX512DQ_256          18
#define XED_ISA_SET_AVX512DQ_512          19
#define XED_ISA_SET_AVX512DQ_KOP          20
#define XED_ISA_SET_AVX512DQ_SCALAR       21
#define XED_ISA_SET_AVX512ER_512          22
#define XED_ISA_SET_AVX512ER_SCALAR       23
#define XED_ISA_SET_AVX512F_128           24
#define XED_ISA_SET_AVX512F_128N          25
#define XED_ISA_SET_AVX512F_256           26
#define XED_ISA_SET_AVX512F_512           27
#define XED_ISA_SET_AVX512F_KOP           28
#define XED_ISA_SET_AVX512F_SCALAR        29
#define XED_ISA_SET_AVX512PF_512          30
#define XED_ISA_SET_AVX512_4FMAPS_512     31
#define XED_ISA_SET_AVX512_4FMAPS_SCALAR  32
#define XED_ISA_SET_AVX512_4VNNIW_512     33
#define XED_ISA_SET_AVX512_BITALG_128     34
#define XED_ISA_SET_AVX512_BITALG_256     35
#define XED_ISA_SET_AVX512_BITALG_512     36
#define XED_ISA_SET_AVX512_GFNI_128       37
#define XED_ISA_SET_AVX512_GFNI_256       38
#define XED_ISA_SET_AVX512_GFNI_512       39
#define XED_ISA_SET_AVX512_IFMA_128       40
#define XED_ISA_SET_AVX512_IFMA_256       41
#define XED_ISA_SET_AVX512_IFMA_512       42
#define XED_ISA_SET_AVX512_VAES_128       43
#define XED_ISA_SET_AVX512_VAES_256       44
#define XED_ISA_SET_AVX512_VAES_512       45
#define XED_ISA_SET_AVX512_VBMI2_128      46
#define XED_ISA_SET_AVX512_VBMI2_256      47
#define XED_ISA_SET_AVX512_VBMI2_512      48
#define XED_ISA_SET_AVX512_VBMI_128       49
#define XED_ISA_SET_AVX512_VBMI_256       50
#define XED_ISA_SET_AVX512_VBMI_512       51
#define XED_ISA_SET_AVX512_VNNI_128       52
#define XED_ISA_SET_AVX512_VNNI_256       53
#define XED_ISA_SET_AVX512_VNNI_512       54
#define XED_ISA_SET_AVX512_VPCLMULQDQ_128 55
#define XED_ISA_SET_AVX512_VPCLMULQDQ_256 56
#define XED_ISA_SET_AVX512_VPCLMULQDQ_512 57
#define XED_ISA_SET_AVX512_VPOPCNTDQ_128  58
#define XED_ISA_SET_AVX512_VPOPCNTDQ_256  59
#define XED_ISA_SET_AVX512_VPOPCNTDQ_512  60
#define XED_ISA_SET_AVXAES                61
#define XED_ISA_SET_AVX_GFNI              62
#define XED_ISA_SET_BMI1                  63
#define XED_ISA_SET_BMI2                  64
#define XED_ISA_SET_CET                   65
#define XED_ISA_SET_CLDEMOTE              66
#define XED_ISA_SET_CLFLUSHOPT            67
#define XED_ISA_SET_CLFSH                 68
#define XED_ISA_SET_CLWB                  69
#define XED_ISA_SET_CLZERO                70
#define XED_ISA_SET_CMOV                  71
#define XED_ISA_SET_CMPXCHG16B            72
#define XED_ISA_SET_F16C                  73
#define XED_ISA_SET_FAT_NOP               74
#define XED_ISA_SET_FCMOV                 75
#define XED_ISA_SET_FMA                   76
#define XED_ISA_SET_FMA4                  77
#define XED_ISA_SET_FXSAVE                78
#define XED_ISA_SET_FXSAVE64              79
#define XED_ISA_SET_GFNI                  80
#define XED_ISA_SET_I186                  81
#define XED_ISA_SET_I286PROTECTED         82
#define XED_ISA_SET_I286REAL              83
#define XED_ISA_SET_I386                  84
#define XED_ISA_SET_I486                  85
#define XED_ISA_SET_I486REAL              86
#define XED_ISA_SET_I86                   87
#define XED_ISA_SET_INVPCID               88
#define XED_ISA_SET_LAHF                  89
#define XED_ISA_SET_LONGMODE              90
#define XED_ISA_SET_LZCNT                 91
#define XED_ISA_SET_MONITOR               92
#define XED_ISA_SET_MONITORX              93
#define XED_ISA_SET_MOVBE                 94
#define XED_ISA_SET_MOVDIR                95
#define XED_ISA_SET_MPX                   96
#define XED_ISA_SET_PAUSE                 97
#define XED_ISA_SET_PCLMULQDQ             98
#define XED_ISA_SET_PCONFIG               99
#define XED_ISA_SET_PENTIUMMMX            100
#define XED_ISA_SET_PENTIUMREAL           101
#define XED_ISA_SET_PKU                   102
#define XED_ISA_SET_POPCNT                103
#define XED_ISA_SET_PPRO                  104
#define XED_ISA_SET_PREFETCHW             105
#define XED_ISA_SET_PREFETCHWT1           106
#define XED_ISA_SET_PREFETCH_NOP          107
#define XED_ISA_SET_PT                    108
#define XED_ISA_SET_RDPID                 109
#define XED_ISA_SET_RDPMC                 110
#define XED_ISA_SET_RDRAND                111
#define XED_ISA_SET_RDSEED                112
#define XED_ISA_SET_RDTSCP                113
#define XED_ISA_SET_RDWRFSGS              114
#define XED_ISA_SET_RTM                   115
#define XED_ISA_SET_SGX                   116
#define XED_ISA_SET_SGX_ENCLV             117
#define XED_ISA_SET_SHA                   118
#define XED_ISA_SET_SMAP                  119
#define XED_ISA_SET_SMX                   120
#define XED_ISA_SET_SSE                   121
#define XED_ISA_SET_SSE2                  122
#define XED_ISA_SET_SSE2MMX               123
#define XED_ISA_SET_SSE3                  124
#define XED_ISA_SET_SSE3X87               125
#define XED_ISA_SET_SSE4                  126
#define XED_ISA_SET_SSE42                 127
#define XED_ISA_SET_SSE4A                 128
#define XED_ISA_SET_SSEMXCSR              129
#define XED_ISA_SET_SSE_PREFETCH          130
#define XED_ISA_SET_SSSE3                 131
#define XED_ISA_SET_SSSE3MMX              132
#define XED_ISA_SET_SVM                   133
#define XED_ISA_SET_TBM                   134
#define XED_ISA_SET_VAES                  135
#define XED_ISA_SET_VMFUNC                136
#define XED_ISA_SET_VPCLMULQDQ            137
#define XED_ISA_SET_VTX                   138
#define XED_ISA_SET_WAITPKG               139
#define XED_ISA_SET_WBNOINVD              140
#define XED_ISA_SET_X87                   141
#define XED_ISA_SET_XOP                   142
#define XED_ISA_SET_XSAVE                 143
#define XED_ISA_SET_XSAVEC                144
#define XED_ISA_SET_XSAVEOPT              145
#define XED_ISA_SET_XSAVES                146
#define XED_ISA_SET_LAST                  147

struct XedChipFeatures {
  uint64_t f[3];
};

#define xed_set_chip_modes(d, chip)    \
  do {                                 \
    struct XedDecodedInst *__d = d;    \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
        break;                         \
      case XED_CHIP_I86:               \
      case XED_CHIP_I86FP:             \
      case XED_CHIP_I186:              \
      case XED_CHIP_I186FP:            \
      case XED_CHIP_I286REAL:          \
      case XED_CHIP_I286:              \
      case XED_CHIP_I2186FP:           \
      case XED_CHIP_I386REAL:          \
      case XED_CHIP_I386:              \
      case XED_CHIP_I386FP:            \
      case XED_CHIP_I486REAL:          \
      case XED_CHIP_I486:              \
      case XED_CHIP_QUARK:             \
      case XED_CHIP_PENTIUM:           \
      case XED_CHIP_PENTIUMREAL:       \
      case XED_CHIP_PENTIUMMMX:        \
      case XED_CHIP_PENTIUMMMXREAL:    \
        __d->op.mode_first_prefix = 1; \
        break;                         \
      default:                         \
        break;                         \
    }                                  \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
      case XED_CHIP_ALL:               \
      case XED_CHIP_AMD:               \
        break;                         \
      default:                         \
        __d->op.is_intel_specific = 1; \
        break;                         \
    }                                  \
  } while (0)

extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];

bool xed_test_chip_features(struct XedChipFeatures *, int);
void xed_get_chip_features(struct XedChipFeatures *, int);
bool xed_isa_set_is_valid_for_chip(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/blake2.h */

#define COSMOPOLITAN_LIBC_STR_BLAKE2_H_

#define BLAKE2B256_DIGEST_LENGTH 32
#define BLAKE2B_CBLOCK           128

#define BLAKE2B256_Init    __BLAKE2B256_Init
#define BLAKE2B256_Update  __BLAKE2B256_Update
#define BLAKE2B256_Process __BLAKE2B256_Process
#define BLAKE2B256_Final   __BLAKE2B256_Final
#define BLAKE2B256         __BLAKE2B256

COSMOPOLITAN_C_START_

struct Blake2b {
  uint64_t h[8];
  uint64_t t_low;
  uint64_t t_high;
  union {
    uint8_t bytes[BLAKE2B_CBLOCK];
    uint64_t words[16];
  } block;
  size_t block_used;
};

int BLAKE2B256_Init(struct Blake2b *);
int BLAKE2B256_Update(struct Blake2b *, const void *, size_t);
int BLAKE2B256_Process(struct Blake2b *, const uint64_t[BLAKE2B_CBLOCK / 8]);
int BLAKE2B256_Final(struct Blake2b *, uint8_t[BLAKE2B256_DIGEST_LENGTH]);
int BLAKE2B256(const void *, size_t, uint8_t[BLAKE2B256_DIGEST_LENGTH]);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/highwayhash64.h */

#define COSMOPOLITAN_LIBC_STR_HIGHWAYHASH64_H_
COSMOPOLITAN_C_START_

uint64_t HighwayHash64(const void *, size_t, const uint64_t[4]) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/langinfo.h */

#define COSMOPOLITAN_LIBC_STR_LANGINFO_H_
COSMOPOLITAN_C_START_

#define ABDAY_1 0x20000
#define ABDAY_2 0x20001
#define ABDAY_3 0x20002
#define ABDAY_4 0x20003
#define ABDAY_5 0x20004
#define ABDAY_6 0x20005
#define ABDAY_7 0x20006

#define DAY_1 0x20007
#define DAY_2 0x20008
#define DAY_3 0x20009
#define DAY_4 0x2000A
#define DAY_5 0x2000B
#define DAY_6 0x2000C
#define DAY_7 0x2000D

#define ABMON_1  0x2000E
#define ABMON_2  0x2000F
#define ABMON_3  0x20010
#define ABMON_4  0x20011
#define ABMON_5  0x20012
#define ABMON_6  0x20013
#define ABMON_7  0x20014
#define ABMON_8  0x20015
#define ABMON_9  0x20016
#define ABMON_10 0x20017
#define ABMON_11 0x20018
#define ABMON_12 0x20019

#define MON_1  0x2001A
#define MON_2  0x2001B
#define MON_3  0x2001C
#define MON_4  0x2001D
#define MON_5  0x2001E
#define MON_6  0x2001F
#define MON_7  0x20020
#define MON_8  0x20021
#define MON_9  0x20022
#define MON_10 0x20023
#define MON_11 0x20024
#define MON_12 0x20025

#define AM_STR 0x20026
#define PM_STR 0x20027

#define D_T_FMT    0x20028
#define D_FMT      0x20029
#define T_FMT      0x2002A
#define T_FMT_AMPM 0x2002B

#define ERA         0x2002C
#define ERA_D_FMT   0x2002E
#define ALT_DIGITS  0x2002F
#define ERA_D_T_FMT 0x20030
#define ERA_T_FMT   0x20031

#define CODESET 14

#define CRNCYSTR 0x4000F

#define RADIXCHAR 0x10000
#define THOUSEP   0x10001
#define YESEXPR   0x50000
#define NOEXPR    0x50001

#define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff)

#if defined(_GNU_SOURCE)
#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat)
#endif

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define YESSTR 0x50002
#define NOSTR  0x50003
#endif

char *nl_langinfo(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/locale.h */

#define COSMOPOLITAN_LIBC_STR_LOCALE_H_

#define LC_CTYPE         0
#define LC_NUMERIC       1
#define LC_CTYPE_MASK    1
#define LC_TIME          2
#define LC_NUMERIC_MASK  2
#define LC_COLLATE       3
#define LC_MONETARY      4
#define LC_TIME_MASK     4
#define LC_MESSAGES      5
#define LC_ALL           6
#define LC_COLLATE_MASK  8
#define LC_MONETARY_MASK 16
#define LC_MESSAGES_MASK 32
#define LC_ALL_MASK      0x1fbf
#define LOCALE_NAME_MAX  23

COSMOPOLITAN_C_START_

#define LC_GLOBAL_LOCALE ((locale_t) - 1)

struct __locale_map {
  const void *map;
  size_t map_size;
  char name[LOCALE_NAME_MAX + 1];
  const struct __locale_map *next;
};

struct __locale_struct {
  const struct __locale_map *cat[6];
};

typedef struct __locale_struct *locale_t;

extern const struct __locale_map __c_dot_utf8;
extern const struct __locale_struct __c_locale;
extern const struct __locale_struct __c_dot_utf8_locale;

char *nl_langinfo_l(int, locale_t) libcesque;
char *setlocale(int, const char *) libcesque;
double strtod_l(const char *, char **, locale_t) libcesque;
double wcstod_l(const wchar_t *, wchar_t **, locale_t) libcesque;
float strtof_l(const char *, char **, locale_t) libcesque;
float wcstof_l(const wchar_t *, wchar_t **, locale_t) libcesque;
int isdigit_l(int, locale_t) libcesque;
int islower_l(int, locale_t) libcesque;
int isupper_l(int, locale_t) libcesque;
int iswalpha_l(wint_t, locale_t) libcesque;
int iswblank_l(wint_t, locale_t) libcesque;
int iswcntrl_l(wint_t, locale_t) libcesque;
int iswdigit_l(wint_t, locale_t) libcesque;
int iswlower_l(wint_t, locale_t) libcesque;
int iswprint_l(wint_t, locale_t) libcesque;
int iswpunct_l(wint_t, locale_t) libcesque;
int iswspace_l(wint_t, locale_t) libcesque;
int iswupper_l(wint_t, locale_t) libcesque;
int iswxdigit_l(wint_t, locale_t) libcesque;
int isxdigit_l(int, locale_t) libcesque;
int strcoll_l(const char *, const char *, locale_t) libcesque;
int tolower_l(int, locale_t) libcesque;
int toupper_l(int, locale_t) libcesque;
int wcscoll_l(const wchar_t *, const wchar_t *, locale_t) libcesque;
locale_t duplocale(locale_t) libcesque;
locale_t newlocale(int, const char *, locale_t) libcesque;
locale_t uselocale(locale_t) libcesque;
long double strtold_l(const char *, char **, locale_t) libcesque;
long double wcstold_l(const wchar_t *, wchar_t **, locale_t) libcesque;
long long strtoll_l(const char *, char **, int, locale_t) libcesque;
long long wcstoll_l(const wchar_t *, wchar_t **, int, locale_t) libcesque;
size_t strftime_l(char *, size_t, char const *, struct tm const *, locale_t);
size_t strxfrm_l(char *, const char *, size_t, locale_t) libcesque;
size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t) libcesque;
unsigned long long strtoull_l(const char *, char **, int, locale_t) libcesque;
unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t);
void freelocale(locale_t) libcesque;
wint_t towlower_l(wint_t, locale_t) libcesque;
wint_t towupper_l(wint_t, locale_t) libcesque;
int strcasecmp_l(const char *, const char *, locale_t) libcesque;
int strncasecmp_l(const char *, const char *, size_t, locale_t) libcesque;
ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/nltypes.h */

#define COSMOPOLITAN_LIBC_STR_NLTYPES_H_

#define NL_SETD       1
#define NL_CAT_LOCALE 1

COSMOPOLITAN_C_START_

typedef int nl_item;
typedef void *nl_catd;

nl_catd catopen(const char *, int);
char *catgets(nl_catd, int, int, const char *);
int catclose(nl_catd);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/slice.h */

#define COSMOPOLITAN_LIBC_STR_SLICE_H_
COSMOPOLITAN_C_START_

#define SlicesEqual(a, n, b, m)       \
  ({                                  \
    size_t __n = (n);                 \
    __n == (m) && !memcmp(a, b, __n); \
  })

#define SlicesEqualCase(a, n, b, m)       \
  ({                                      \
    size_t __n = (n);                     \
    __n == (m) && !memcasecmp(a, b, __n); \
  })

int CompareSlices(const char *, size_t, const char *, size_t) libcesque;
int CompareSlicesCase(const char *, size_t, const char *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/strwidth.h */

#define COSMOPOLITAN_LIBC_STR_STRWIDTH_H_
COSMOPOLITAN_C_START_

int strwidth(const char *, size_t) strlenesque;
int strnwidth(const char *, size_t, size_t) strlenesque;
int strwidth16(const char16_t *, size_t) strlenesque;
int strnwidth16(const char16_t *, size_t, size_t) strlenesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/thompike.h */

#define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_

#define ThomPikeCont(x)     (0200 == (0300 & (x)))
#define ThomPikeByte(x)     ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
#define ThomPikeLen(x)      (7 - ThomPikeMsb(x))
#define ThomPikeMsb(x)      ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1)
#define ThomPikeMerge(x, y) ((x) << 6 | (077 & (y)))



/*!BEGIN libc/str/unicode.h */

#define COSMOPOLITAN_LIBC_STR_UNICODE_H_
COSMOPOLITAN_C_START_

struct lconv {
  char *decimal_point;
  char *thousands_sep;
  char *grouping;
  char *int_curr_symbol;
  char *currency_symbol;
  char *mon_decimal_point;
  char *mon_thousands_sep;
  char *mon_grouping;
  char *positive_sign;
  char *negative_sign;
  char int_frac_digits;
  char frac_digits;
  char p_cs_precedes;
  char p_sep_by_space;
  char n_cs_precedes;
  char n_sep_by_space;
  char p_sign_posn;
  char n_sign_posn;
  char int_p_cs_precedes;
  char int_n_cs_precedes;
  char int_p_sep_by_space;
  char int_n_sep_by_space;
  char int_p_sign_posn;
  char int_n_sign_posn;
};

pureconst int wcwidth(wchar_t) libcesque;
int wcswidth(const wchar_t *, size_t) strlenesque;
struct lconv *localeconv(void) libcesque;

#ifdef _COSMO_SOURCE
int wcsnwidth(const wchar_t *, size_t, size_t) strlenesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/utf16.h */

#define COSMOPOLITAN_LIBC_STR_UTF16_H_

#define UTF16_MASK 0xfc00
#define UTF16_MOAR 0xd800 /* 0xD800..0xDBFF */
#define UTF16_CONT 0xdc00 /* 0xDC00..0xDFFF */

COSMOPOLITAN_C_START_

#define IsSurrogate(wc)     ((0xf800 & (wc)) == 0xd800)
#define IsHighSurrogate(wc) ((UTF16_MASK & (wc)) == UTF16_MOAR)
#define IsLowSurrogate(wc)  ((UTF16_MASK & (wc)) == UTF16_CONT)
#define IsUcs2(wc)          (((65535 & (wc)) >> 11) != 27)
#define IsUtf16Cont(wc)     IsLowSurrogate(wc) /* TODO: DELETE */
#define MergeUtf16(hi, lo)  ((((hi)-0xD800) << 10) + ((lo)-0xDC00) + 0x10000)
#define EncodeUtf16(wc)                                       \
  (LIKELY((0x0000 <= (wc) && (wc) <= 0xFFFF) ||               \
          (0xE000 <= (wc) && (wc) <= 0xFFFF))                 \
       ? (wc)                                                 \
   : 0x10000 <= (wc) && (wc) <= 0x10FFFF                      \
       ? (((((wc)-0x10000) >> 10) + 0xD800) |                 \
          (unsigned)((((wc)-0x10000) & 1023) + 0xDC00) << 16) \
       : 0xFFFD)

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/errfuns.h */

#define COSMOPOLITAN_LIBC_SYSV_ERRFUNS_H_

/**
 * @fileoverview Optimized error return paths.
 *
 * Saying this:
 *
 *     return einval();
 *
 * Instead of this:
 *
 *     errno = EINVAL;
 *     return -1;
 *
 * Allows the compiler to generate 11 fewer bytes of code each time.
 *
 * @return always -1
 * @see libc/sysv/errfuns.inc (for implementation)
 */

libcesque intptr_t einval(void) relegated;
libcesque intptr_t eperm(void) relegated;
libcesque intptr_t enoent(void) relegated;
libcesque intptr_t esrch(void) relegated;
libcesque intptr_t eintr(void) relegated;
libcesque intptr_t eio(void) relegated;
libcesque intptr_t enxio(void) relegated;
libcesque intptr_t e2big(void) relegated;
libcesque intptr_t enoexec(void) relegated;
libcesque intptr_t ebadf(void) relegated;
libcesque intptr_t echild(void) relegated;
libcesque intptr_t eagain(void) relegated;
libcesque intptr_t enomem(void) relegated;
libcesque intptr_t eacces(void) relegated;
libcesque intptr_t efault(void) relegated;
libcesque intptr_t enotblk(void) relegated;
libcesque intptr_t ebusy(void) relegated;
libcesque intptr_t eexist(void) relegated;
libcesque intptr_t exdev(void) relegated;
libcesque intptr_t enodev(void) relegated;
libcesque intptr_t enotdir(void) relegated;
libcesque intptr_t eisdir(void) relegated;
libcesque intptr_t enfile(void) relegated;
libcesque intptr_t emfile(void) relegated;
libcesque intptr_t enotty(void) relegated;
libcesque intptr_t enotsup(void) relegated;
libcesque intptr_t etxtbsy(void) relegated;
libcesque intptr_t efbig(void) relegated;
libcesque intptr_t enospc(void) relegated;
libcesque intptr_t espipe(void) relegated;
libcesque intptr_t erofs(void) relegated;
libcesque intptr_t emlink(void) relegated;
libcesque intptr_t epipe(void) relegated;
libcesque intptr_t edom(void) relegated;
libcesque intptr_t erange(void) relegated;
libcesque intptr_t edeadlk(void) relegated;
libcesque intptr_t enametoolong(void) relegated;
libcesque intptr_t enolck(void) relegated;
libcesque intptr_t enosys(void) relegated;
libcesque intptr_t enotempty(void) relegated;
libcesque intptr_t eloop(void) relegated;
libcesque intptr_t enomsg(void) relegated;
libcesque intptr_t eidrm(void) relegated;
libcesque intptr_t echrng(void) relegated;
libcesque intptr_t el2nsync(void) relegated;
libcesque intptr_t el3hlt(void) relegated;
libcesque intptr_t el3rst(void) relegated;
libcesque intptr_t elnrng(void) relegated;
libcesque intptr_t eunatch(void) relegated;
libcesque intptr_t enocsi(void) relegated;
libcesque intptr_t el2hlt(void) relegated;
libcesque intptr_t ebade(void) relegated;
libcesque intptr_t ebadr(void) relegated;
libcesque intptr_t exfull(void) relegated;
libcesque intptr_t enoano(void) relegated;
libcesque intptr_t ebadrqc(void) relegated;
libcesque intptr_t ebadslt(void) relegated;
libcesque intptr_t enostr(void) relegated;
libcesque intptr_t enodata(void) relegated;
libcesque intptr_t etime(void) relegated;
libcesque intptr_t enosr(void) relegated;
libcesque intptr_t enonet(void) relegated;
libcesque intptr_t enopkg(void) relegated;
libcesque intptr_t eremote(void) relegated;
libcesque intptr_t enolink(void) relegated;
libcesque intptr_t eadv(void) relegated;
libcesque intptr_t esrmnt(void) relegated;
libcesque intptr_t ecomm(void) relegated;
libcesque intptr_t eproto(void) relegated;
libcesque intptr_t emultihop(void) relegated;
libcesque intptr_t edotdot(void) relegated;
libcesque intptr_t ebadmsg(void) relegated;
libcesque intptr_t eoverflow(void) relegated;
libcesque intptr_t enotuniq(void) relegated;
libcesque intptr_t ebadfd(void) relegated;
libcesque intptr_t eremchg(void) relegated;
libcesque intptr_t elibacc(void) relegated;
libcesque intptr_t elibbad(void) relegated;
libcesque intptr_t elibscn(void) relegated;
libcesque intptr_t elibmax(void) relegated;
libcesque intptr_t elibexec(void) relegated;
libcesque intptr_t eilseq(void) relegated;
libcesque intptr_t erestart(void) relegated;
libcesque intptr_t estrpipe(void) relegated;
libcesque intptr_t eusers(void) relegated;
libcesque intptr_t enotsock(void) relegated;
libcesque intptr_t edestaddrreq(void) relegated;
libcesque intptr_t emsgsize(void) relegated;
libcesque intptr_t eprototype(void) relegated;
libcesque intptr_t enoprotoopt(void) relegated;
libcesque intptr_t eprotonosupport(void) relegated;
libcesque intptr_t esocktnosupport(void) relegated;
libcesque intptr_t eopnotsupp(void) relegated;
libcesque intptr_t epfnosupport(void) relegated;
libcesque intptr_t eafnosupport(void) relegated;
libcesque intptr_t eaddrinuse(void) relegated;
libcesque intptr_t eaddrnotavail(void) relegated;
libcesque intptr_t enetdown(void) relegated;
libcesque intptr_t enetunreach(void) relegated;
libcesque intptr_t enetreset(void) relegated;
libcesque intptr_t econnaborted(void) relegated;
libcesque intptr_t econnreset(void) relegated;
libcesque intptr_t enobufs(void) relegated;
libcesque intptr_t eisconn(void) relegated;
libcesque intptr_t enotconn(void) relegated;
libcesque intptr_t eshutdown(void) relegated;
libcesque intptr_t etoomanyrefs(void) relegated;
libcesque intptr_t etimedout(void) relegated;
libcesque intptr_t econnrefused(void) relegated;
libcesque intptr_t ehostdown(void) relegated;
libcesque intptr_t ehostunreach(void) relegated;
libcesque intptr_t ealready(void) relegated;
libcesque intptr_t einprogress(void) relegated;
libcesque intptr_t estale(void) relegated;
libcesque intptr_t euclean(void) relegated;
libcesque intptr_t enotnam(void) relegated;
libcesque intptr_t enavail(void) relegated;
libcesque intptr_t eisnam(void) relegated;
libcesque intptr_t eremoteio(void) relegated;
libcesque intptr_t edquot(void) relegated;
libcesque intptr_t enomedium(void) relegated;
libcesque intptr_t emediumtype(void) relegated;
libcesque intptr_t ecanceled(void) relegated;
libcesque intptr_t enokey(void) relegated;
libcesque intptr_t ekeyexpired(void) relegated;
libcesque intptr_t ekeyrevoked(void) relegated;
libcesque intptr_t ekeyrejected(void) relegated;
libcesque intptr_t eownerdead(void) relegated;
libcesque intptr_t enotrecoverable(void) relegated;
libcesque intptr_t erfkill(void) relegated;
libcesque intptr_t ehwpoison(void) relegated;

#if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __ERRFUN(FUNC)               \
  ({                                 \
    intptr_t NegOne;                 \
    asm volatile("call\t" FUNC       \
                 : "=a"(NegOne)      \
                 : /* no outputs */  \
                 : "rcx", "memory"); \
    NegOne;                          \
  })
#define einval()          __ERRFUN("einval")
#define eperm()           __ERRFUN("eperm")
#define enoent()          __ERRFUN("enoent")
#define esrch()           __ERRFUN("esrch")
#define eintr()           __ERRFUN("eintr")
#define eio()             __ERRFUN("eio")
#define enxio()           __ERRFUN("enxio")
#define e2big()           __ERRFUN("e2big")
#define enoexec()         __ERRFUN("enoexec")
#define ebadf()           __ERRFUN("ebadf")
#define echild()          __ERRFUN("echild")
#define eagain()          __ERRFUN("eagain")
#define enomem()          __ERRFUN("enomem")
#define eacces()          __ERRFUN("eacces")
#define efault()          __ERRFUN("efault")
#define enotblk()         __ERRFUN("enotblk")
#define ebusy()           __ERRFUN("ebusy")
#define eexist()          __ERRFUN("eexist")
#define exdev()           __ERRFUN("exdev")
#define enodev()          __ERRFUN("enodev")
#define enotdir()         __ERRFUN("enotdir")
#define eisdir()          __ERRFUN("eisdir")
#define enfile()          __ERRFUN("enfile")
#define emfile()          __ERRFUN("emfile")
#define enotty()          __ERRFUN("enotty")
#define enotsup()         __ERRFUN("enotsup")
#define etxtbsy()         __ERRFUN("etxtbsy")
#define efbig()           __ERRFUN("efbig")
#define enospc()          __ERRFUN("enospc")
#define espipe()          __ERRFUN("espipe")
#define erofs()           __ERRFUN("erofs")
#define emlink()          __ERRFUN("emlink")
#define epipe()           __ERRFUN("epipe")
#define edom()            __ERRFUN("edom")
#define erange()          __ERRFUN("erange")
#define edeadlk()         __ERRFUN("edeadlk")
#define enametoolong()    __ERRFUN("enametoolong")
#define enolck()          __ERRFUN("enolck")
#define enosys()          __ERRFUN("enosys")
#define enotempty()       __ERRFUN("enotempty")
#define eloop()           __ERRFUN("eloop")
#define enomsg()          __ERRFUN("enomsg")
#define eidrm()           __ERRFUN("eidrm")
#define echrng()          __ERRFUN("echrng")
#define el2nsync()        __ERRFUN("el2nsync")
#define el3hlt()          __ERRFUN("el3hlt")
#define el3rst()          __ERRFUN("el3rst")
#define elnrng()          __ERRFUN("elnrng")
#define eunatch()         __ERRFUN("eunatch")
#define enocsi()          __ERRFUN("enocsi")
#define el2hlt()          __ERRFUN("el2hlt")
#define ebade()           __ERRFUN("ebade")
#define ebadr()           __ERRFUN("ebadr")
#define exfull()          __ERRFUN("exfull")
#define enoano()          __ERRFUN("enoano")
#define ebadrqc()         __ERRFUN("ebadrqc")
#define ebadslt()         __ERRFUN("ebadslt")
#define enostr()          __ERRFUN("enostr")
#define enodata()         __ERRFUN("enodata")
#define etime()           __ERRFUN("etime")
#define enosr()           __ERRFUN("enosr")
#define enonet()          __ERRFUN("enonet")
#define enopkg()          __ERRFUN("enopkg")
#define eremote()         __ERRFUN("eremote")
#define enolink()         __ERRFUN("enolink")
#define eadv()            __ERRFUN("eadv")
#define esrmnt()          __ERRFUN("esrmnt")
#define ecomm()           __ERRFUN("ecomm")
#define eproto()          __ERRFUN("eproto")
#define emultihop()       __ERRFUN("emultihop")
#define edotdot()         __ERRFUN("edotdot")
#define ebadmsg()         __ERRFUN("ebadmsg")
#define eoverflow()       __ERRFUN("eoverflow")
#define enotuniq()        __ERRFUN("enotuniq")
#define ebadfd()          __ERRFUN("ebadfd")
#define eremchg()         __ERRFUN("eremchg")
#define elibacc()         __ERRFUN("elibacc")
#define elibbad()         __ERRFUN("elibbad")
#define elibscn()         __ERRFUN("elibscn")
#define elibmax()         __ERRFUN("elibmax")
#define elibexec()        __ERRFUN("elibexec")
#define eilseq()          __ERRFUN("eilseq")
#define erestart()        __ERRFUN("erestart")
#define estrpipe()        __ERRFUN("estrpipe")
#define eusers()          __ERRFUN("eusers")
#define enotsock()        __ERRFUN("enotsock")
#define edestaddrreq()    __ERRFUN("edestaddrreq")
#define emsgsize()        __ERRFUN("emsgsize")
#define eprototype()      __ERRFUN("eprototype")
#define enoprotoopt()     __ERRFUN("enoprotoopt")
#define eprotonosupport() __ERRFUN("eprotonosupport")
#define esocktnosupport() __ERRFUN("esocktnosupport")
#define eopnotsupp()      __ERRFUN("eopnotsupp")
#define epfnosupport()    __ERRFUN("epfnosupport")
#define eafnosupport()    __ERRFUN("eafnosupport")
#define eaddrinuse()      __ERRFUN("eaddrinuse")
#define eaddrnotavail()   __ERRFUN("eaddrnotavail")
#define enetdown()        __ERRFUN("enetdown")
#define enetunreach()     __ERRFUN("enetunreach")
#define enetreset()       __ERRFUN("enetreset")
#define econnaborted()    __ERRFUN("econnaborted")
#define econnreset()      __ERRFUN("econnreset")
#define enobufs()         __ERRFUN("enobufs")
#define eisconn()         __ERRFUN("eisconn")
#define enotconn()        __ERRFUN("enotconn")
#define eshutdown()       __ERRFUN("eshutdown")
#define etoomanyrefs()    __ERRFUN("etoomanyrefs")
#define etimedout()       __ERRFUN("etimedout")
#define econnrefused()    __ERRFUN("econnrefused")
#define ehostdown()       __ERRFUN("ehostdown")
#define ehostunreach()    __ERRFUN("ehostunreach")
#define ealready()        __ERRFUN("ealready")
#define einprogress()     __ERRFUN("einprogress")
#define estale()          __ERRFUN("estale")
#define euclean()         __ERRFUN("euclean")
#define enotnam()         __ERRFUN("enotnam")
#define enavail()         __ERRFUN("enavail")
#define eisnam()          __ERRFUN("eisnam")
#define eremoteio()       __ERRFUN("eremoteio")
#define edquot()          __ERRFUN("edquot")
#define enomedium()       __ERRFUN("enomedium")
#define emediumtype()     __ERRFUN("emediumtype")
#define ecanceled()       __ERRFUN("ecanceled")
#define enokey()          __ERRFUN("enokey")
#define ekeyexpired()     __ERRFUN("ekeyexpired")
#define ekeyrevoked()     __ERRFUN("ekeyrevoked")
#define ekeyrejected()    __ERRFUN("ekeyrejected")
#define eownerdead()      __ERRFUN("eownerdead")
#define enotrecoverable() __ERRFUN("enotrecoverable")
#define erfkill()         __ERRFUN("erfkill")
#define ehwpoison()       __ERRFUN("ehwpoison")
#endif



/*!BEGIN libc/sysv/consts/_posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS__POSIX_H_

/* The Open Group Base Specifications Issue 7, 2018 edition */
/* IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)  */

#define _POSIX_AIO_LISTIO_MAX               2
#define _POSIX_CLOCKRES_MIN                 20000000
#define _POSIX_AIO_MAX                      1
#define _POSIX_ARG_MAX                      4096
#define _POSIX_CHILD_MAX                    25
#define _POSIX_DELAYTIMER_MAX               32
#define _POSIX_HOST_NAME_MAX                255
#define _POSIX_LINK_MAX                     8
#define _POSIX_LOGIN_NAME_MAX               9
#define _POSIX_MAX_CANON                    255
#define _POSIX_MAX_INPUT                    255
#define _POSIX_MQ_OPEN_MAX                  8
#define _POSIX_MQ_PRIO_MAX                  32
#define _POSIX_NAME_MAX                     14
#define _POSIX_NGROUPS_MAX                  8
#define _POSIX_OPEN_MAX                     20
#define _POSIX_PATH_MAX                     256
#define _POSIX_PIPE_BUF                     512
#define _POSIX_RE_DUP_MAX                   255
#define _POSIX_RTSIG_MAX                    8
#define _POSIX_SEM_NSEMS_MAX                256
#define _POSIX_SEM_VALUE_MAX                32767
#define _POSIX_SIGQUEUE_MAX                 32
#define _POSIX_SSIZE_MAX                    32767
#define _POSIX_SS_REPL_MAX                  4
#define _POSIX_STREAM_MAX                   8
#define _POSIX_SYMLINK_MAX                  255
#define _POSIX_SYMLOOP_MAX                  8
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
#define _POSIX_THREAD_KEYS_MAX              128
#define _POSIX_THREAD_THREADS_MAX           64
#define _POSIX_TIMER_MAX                    32
#define _POSIX_TRACE_EVENT_NAME_MAX         30
#define _POSIX_TRACE_NAME_MAX               8
#define _POSIX_TRACE_SYS_MAX                8
#define _POSIX_TRACE_USER_EVENT_MAX         32
#define _POSIX_TTY_NAME_MAX                 9
#define _POSIX_TZNAME_MAX                   6

#define _POSIX2_BC_BASE_MAX        99
#define _POSIX2_BC_DIM_MAX         2048
#define _POSIX2_BC_SCALE_MAX       99
#define _POSIX2_BC_STRING_MAX      1000
#define _POSIX2_CHARCLASS_NAME_MAX 14
#define _POSIX2_COLL_WEIGHTS_MAX   2
#define _POSIX2_EXPR_NEST_MAX      32
#define _POSIX2_LINE_MAX           2048
#define _POSIX2_RE_DUP_MAX         255



/*!BEGIN libc/sysv/consts/af.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AF_H_
COSMOPOLITAN_C_START_

extern const int AF_ALG;
extern const int AF_APPLETALK;
extern const int AF_ASH;
extern const int AF_ATMPVC;
extern const int AF_ATMSVC;
extern const int AF_AX25;
extern const int AF_BLUETOOTH;
extern const int AF_BRIDGE;
extern const int AF_CAIF;
extern const int AF_CAN;
extern const int AF_ECONET;
extern const int AF_FILE;
extern const int AF_IB;
extern const int AF_IEEE802154;
extern const int AF_INET6;
extern const int AF_INET;
extern const int AF_IPX;
extern const int AF_IRDA;
extern const int AF_ISDN;
extern const int AF_IUCV;
extern const int AF_KCM;
extern const int AF_KEY;
extern const int AF_LINK;
extern const int AF_LLC;
extern const int AF_LOCAL;
extern const int AF_MAX;
extern const int AF_MPLS;
extern const int AF_NETBEUI;
extern const int AF_NETLINK;
extern const int AF_NETROM;
extern const int AF_NFC;
extern const int AF_PACKET;
extern const int AF_PHONET;
extern const int AF_PPPOX;
extern const int AF_ROSE;
extern const int AF_ROUTE;
extern const int AF_RXRPC;
extern const int AF_SECURITY;
extern const int AF_SNA;
extern const int AF_TIPC;
extern const int AF_UNIX;
extern const int AF_UNSPEC;
extern const int AF_VSOCK;
extern const int AF_WANPIPE;
extern const int AF_X25;

#define AF_ALG        AF_ALG
#define AF_LINK       AF_LINK
#define AF_APPLETALK  AF_APPLETALK
#define AF_ASH        AF_ASH
#define AF_ATMPVC     AF_ATMPVC
#define AF_ATMSVC     AF_ATMSVC
#define AF_AX25       AF_AX25
#define AF_BLUETOOTH  AF_BLUETOOTH
#define AF_BRIDGE     AF_BRIDGE
#define AF_CAIF       AF_CAIF
#define AF_CAN        AF_CAN
#define AF_ECONET     AF_ECONET
#define AF_FILE       AF_FILE
#define AF_IB         AF_IB
#define AF_IEEE802154 AF_IEEE802154
#define AF_INET       2
#define AF_INET6      AF_INET6
#define AF_IPX        AF_IPX
#define AF_IRDA       AF_IRDA
#define AF_ISDN       AF_ISDN
#define AF_IUCV       AF_IUCV
#define AF_KCM        AF_KCM
#define AF_KEY        AF_KEY
#define AF_LLC        AF_LLC
#define AF_LOCAL      AF_LOCAL
#define AF_MAX        AF_MAX
#define AF_MPLS       AF_MPLS
#define AF_NETBEUI    AF_NETBEUI
#define AF_NETLINK    AF_NETLINK
#define AF_NETROM     AF_NETROM
#define AF_NFC        AF_NFC
#define AF_PACKET     AF_PACKET
#define AF_PHONET     AF_PHONET
#define AF_PPPOX      AF_PPPOX
#define AF_ROSE       AF_ROSE
#define AF_ROUTE      AF_ROUTE
#define AF_RXRPC      AF_RXRPC
#define AF_SECURITY   AF_SECURITY
#define AF_SNA        AF_SNA
#define AF_TIPC       AF_TIPC
#define AF_UNIX       1
#define AF_UNSPEC     0
#define AF_VSOCK      AF_VSOCK
#define AF_WANPIPE    AF_WANPIPE
#define AF_X25        AF_X25

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/arch.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARCH_H_

#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004



/*!BEGIN libc/sysv/consts/arp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARP_H_

#define ARPHRD_ETHER 1



/*!BEGIN libc/sysv/consts/at.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AT_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview AT_xxx constants for fcntl(), fopenat(), etc..
 * @see libc/sysv/consts/auxv.h for getauxval() constants
 */

extern const int AT_FDCWD;
extern const int AT_SYMLINK_FOLLOW;
extern const int AT_SYMLINK_NOFOLLOW;
extern const int AT_REMOVEDIR;
extern const int AT_EACCESS;
extern const int AT_EMPTY_PATH;

COSMOPOLITAN_C_END_

#define AT_FDCWD            AT_FDCWD
#define AT_SYMLINK_FOLLOW   AT_SYMLINK_FOLLOW
#define AT_SYMLINK_NOFOLLOW AT_SYMLINK_NOFOLLOW
#define AT_REMOVEDIR        AT_REMOVEDIR
#define AT_EACCESS          AT_EACCESS



/*!BEGIN libc/sysv/consts/audit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AUDIT_H_

#define __AUDIT_ARCH_64BIT                 0x80000000
#define __AUDIT_ARCH_LE                    0x40000000
#define __AUDIT_ARCH_CONVENTION_MASK       0x30000000
#define __AUDIT_ARCH_CONVENTION_MIPS64_N32 0x20000000

#define AUDIT_ARCH_X86_64  (EM_X86_64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_I386    (EM_386 | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_AARCH64 (EM_AARCH64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_PPC64LE (EM_PPC64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_RISCV64 (EM_RISCV | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_S390X   (EM_S390 | __AUDIT_ARCH_64BIT)



/*!BEGIN libc/sysv/consts/auxv.h */

#define COSMOPOLITAN_LIBC_CALLS_AUXV_H_

/*
 * integral getauxval() keys
 */
#define AT_PHDR                     3
#define AT_PHENT                    4
#define AT_PHNUM                    5
#define AT_PAGESZ                   6
#define AT_BASE                     7
#define AT_FLAGS                    8
#define AT_FLAGS_PRESERVE_ARGV0_BIT 0
#define AT_FLAGS_PRESERVE_ARGV0     (1 << AT_FLAGS_PRESERVE_ARGV0_BIT)
#define AT_ENTRY                    9

COSMOPOLITAN_C_START_

/*
 * portable getauxval() keys
 */
extern const unsigned long AT_EXECFN;
extern const unsigned long AT_SECURE;
extern const unsigned long AT_RANDOM;
extern const unsigned long AT_HWCAP;
extern const unsigned long AT_HWCAP2;
extern const unsigned long AT_UID;
extern const unsigned long AT_EUID;
extern const unsigned long AT_GID;
extern const unsigned long AT_EGID;
#define AT_EXECFN AT_EXECFN
#define AT_SECURE AT_SECURE
#define AT_RANDOM AT_RANDOM
#define AT_HWCAP  AT_HWCAP
#define AT_HWCAP2 AT_HWCAP2
#define AT_UID    AT_UID
#define AT_EUID   AT_EUID
#define AT_GID    AT_GID
#define AT_EGID   AT_EGID

/*
 * platform-specific getauxval() keys
 */
extern const unsigned long AT_BASE_PLATFORM;
extern const unsigned long AT_CANARY;
extern const unsigned long AT_CANARYLEN;
extern const unsigned long AT_CLKTCK;
extern const unsigned long AT_DCACHEBSIZE;
extern const unsigned long AT_EHDRFLAGS;
extern const unsigned long AT_EXECFD;
extern const unsigned long AT_EXECPATH;
extern const unsigned long AT_ICACHEBSIZE;
extern const unsigned long AT_MINSIGSTKSZ;
extern const unsigned long AT_NCPUS;
extern const unsigned long AT_NOTELF;
extern const unsigned long AT_NO_AUTOMOUNT;
extern const unsigned long AT_OSRELDATE;
extern const unsigned long AT_PAGESIZES;
extern const unsigned long AT_PAGESIZESLEN;
extern const unsigned long AT_PLATFORM;
extern const unsigned long AT_STACKBASE;
extern const unsigned long AT_STACKPROT;
extern const unsigned long AT_SYSINFO_EHDR;
extern const unsigned long AT_TIMEKEEP;
extern const unsigned long AT_UCACHEBSIZE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/c.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CPIO_H_

#define MAGIC "070707"

#define C_IRUSR 000400
#define C_IWUSR 000200
#define C_IXUSR 000100
#define C_IRGRP 000040
#define C_IWGRP 000020
#define C_IXGRP 000010
#define C_IROTH 000004
#define C_IWOTH 000002
#define C_IXOTH 000001

#define C_ISUID 004000
#define C_ISGID 002000
#define C_ISVTX 001000

#define C_ISBLK  060000
#define C_ISCHR  020000
#define C_ISDIR  040000
#define C_ISFIFO 010000
#define C_ISSOCK 0140000
#define C_ISLNK  0120000
#define C_ISCTG  0110000
#define C_ISREG  0100000



/*!BEGIN libc/sysv/consts/cap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CAP_H_

#define CAP_CHOWN              0
#define CAP_DAC_OVERRIDE       1
#define CAP_DAC_READ_SEARCH    2
#define CAP_FOWNER             3
#define CAP_FSETID             4
#define CAP_KILL               5
#define CAP_SETGID             6
#define CAP_SETUID             7
#define CAP_SETPCAP            8
#define CAP_LINUX_IMMUTABLE    9
#define CAP_NET_BIND_SERVICE   10
#define CAP_NET_BROADCAST      11
#define CAP_NET_ADMIN          12
#define CAP_NET_RAW            13
#define CAP_IPC_LOCK           14
#define CAP_IPC_OWNER          15
#define CAP_SYS_MODULE         16
#define CAP_SYS_RAWIO          17
#define CAP_SYS_CHROOT         18
#define CAP_SYS_PTRACE         19
#define CAP_SYS_PACCT          20
#define CAP_SYS_ADMIN          21
#define CAP_SYS_BOOT           22
#define CAP_SYS_NICE           23
#define CAP_SYS_RESOURCE       24
#define CAP_SYS_TIME           25
#define CAP_SYS_TTY_CONFIG     26
#define CAP_MKNOD              27
#define CAP_LEASE              28
#define CAP_AUDIT_WRITE        29
#define CAP_AUDIT_CONTROL      30
#define CAP_SETFCAP            31
#define CAP_MAC_OVERRIDE       32
#define CAP_MAC_ADMIN          33
#define CAP_SYSLOG             34
#define CAP_WAKE_ALARM         35
#define CAP_BLOCK_SUSPEND      36
#define CAP_AUDIT_READ         37
#define CAP_PERFMON            38
#define CAP_BPF                39
#define CAP_CHECKPOINT_RESTORE 40
#define CAP_LAST_CAP           CAP_CHECKPOINT_RESTORE



/*!BEGIN libc/sysv/consts/clock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOCK_H_
COSMOPOLITAN_C_START_

extern const int CLOCK_BOOTTIME;
extern const int CLOCK_BOOTTIME_ALARM;
extern const int CLOCK_MONOTONIC;
extern const int CLOCK_MONOTONIC_COARSE;
extern const int CLOCK_MONOTONIC_FAST;
extern const int CLOCK_MONOTONIC_PRECISE;
extern const int CLOCK_MONOTONIC_RAW;
extern const int CLOCK_PROCESS_CPUTIME_ID;
extern const int CLOCK_PROF;
extern const int CLOCK_REALTIME_ALARM;
extern const int CLOCK_REALTIME_COARSE;
extern const int CLOCK_REALTIME_FAST;
extern const int CLOCK_REALTIME_PRECISE;
extern const int CLOCK_SECOND;
extern const int CLOCK_TAI;
extern const int CLOCK_THREAD_CPUTIME_ID;
extern const int CLOCK_UPTIME;
extern const int CLOCK_UPTIME_FAST;
extern const int CLOCK_UPTIME_PRECISE;

COSMOPOLITAN_C_END_

#define CLOCK_REALTIME  0
#define CLOCK_MONOTONIC CLOCK_MONOTONIC



/*!BEGIN libc/sysv/consts/clone.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLONE_H_
#ifdef _COSMO_SOURCE

#define CSIGNAL              0x000000ff
#define CLONE_VM             0x00000100
#define CLONE_FS             0x00000200
#define CLONE_FILES          0x00000400
#define CLONE_SIGHAND        0x00000800
#define CLONE_PIDFD          0x00001000
#define CLONE_PTRACE         0x00002000
#define CLONE_VFORK          0x00004000
#define CLONE_PARENT         0x00008000
#define CLONE_THREAD         0x00010000
#define CLONE_NEWNS          0x00020000
#define CLONE_SYSVSEM        0x00040000
#define CLONE_SETTLS         0x00080000
#define CLONE_PARENT_SETTID  0x00100000
#define CLONE_CHILD_CLEARTID 0x00200000
#define CLONE_DETACHED       0x00400000
#define CLONE_UNTRACED       0x00800000
#define CLONE_CHILD_SETTID   0x01000000
#define CLONE_NEWCGROUP      0x02000000
#define CLONE_NEWUTS         0x04000000
#define CLONE_NEWIPC         0x08000000
#define CLONE_NEWUSER        0x10000000
#define CLONE_NEWPID         0x20000000
#define CLONE_NEWNET         0x40000000
#define CLONE_IO             0x80000000

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/close.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOSE_H_
COSMOPOLITAN_C_START_

extern const unsigned int CLOSE_RANGE_UNSHARE;
extern const unsigned int CLOSE_RANGE_CLOEXEC;

COSMOPOLITAN_C_END_

#define CLOSE_RANGE_UNSHARE CLOSE_RANGE_UNSHARE
#define CLOSE_RANGE_CLOEXEC CLOSE_RANGE_CLOEXEC



/*!BEGIN libc/sysv/consts/dn.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DN_H_

#define DN_ACCESS    0x00000001 /* file accessed */
#define DN_MODIFY    0x00000002 /* file modified */
#define DN_CREATE    0x00000004 /* file created */
#define DN_DELETE    0x00000008 /* file removed */
#define DN_RENAME    0x00000010 /* file renamed */
#define DN_ATTRIB    0x00000020 /* file changed attibutes */
#define DN_MULTISHOT 0x80000000 /* don't remove notifier */



/*!BEGIN libc/sysv/consts/dt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DT_H_

#define DT_UNKNOWN 0
#define DT_FIFO    1
#define DT_CHR     2
#define DT_DIR     4
#define DT_BLK     6
#define DT_REG     8
#define DT_LNK     10
#define DT_SOCK    12



/*!BEGIN libc/sysv/consts/endian.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ENDIAN_H_

#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define __BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define __PDP_ENDIAN    __ORDER_PDP_ENDIAN__
#define __BYTE_ORDER    __BYTE_ORDER__



/*!BEGIN libc/sysv/consts/epoll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EPOLL_H_


/*!BEGIN libc/sysv/consts/o.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_

#define O_RDONLY  0
#define O_WRONLY  1
#define O_RDWR    2
#define O_ACCMODE 3

COSMOPOLITAN_C_START_

extern const unsigned O_APPEND;
extern const unsigned O_ASYNC;
extern const unsigned O_CLOEXEC;
extern const unsigned O_COMPRESSED;
extern const unsigned O_CREAT;
extern const unsigned O_DIRECT;
extern const unsigned O_DIRECTORY;
extern const unsigned O_DSYNC;
extern const unsigned O_EXCL;
extern const unsigned O_EXEC;
extern const unsigned O_EXLOCK;
extern const unsigned O_INDEXED;
extern const unsigned O_LARGEFILE;
extern const unsigned O_NOATIME;
extern const unsigned O_NOCTTY;
extern const unsigned O_NOFOLLOW;
extern const unsigned O_NOFOLLOW_ANY;
extern const unsigned O_NONBLOCK;
extern const unsigned O_PATH;
extern const unsigned O_RANDOM;
extern const unsigned O_RSYNC;
extern const unsigned O_SEARCH;
extern const unsigned O_SEQUENTIAL;
extern const unsigned O_SHLOCK;
extern const unsigned O_SYNC;
extern const unsigned O_TMPFILE; /* use tmpfd() or tmpfile() */
extern const unsigned O_TRUNC;
extern const unsigned O_TTY_INIT;
extern const unsigned O_UNLINK;
extern const unsigned O_VERIFY;

#define O_APPEND     O_APPEND
#define O_ASYNC      O_ASYNC
#define O_CLOEXEC    O_CLOEXEC
#define O_COMPRESSED O_COMPRESSED
#define O_CREAT      O_CREAT
#define O_DIRECTORY  O_DIRECTORY
#define O_EXCL       O_EXCL
#define O_EXEC       O_EXEC
#define O_INDEXED    O_INDEXED
#define O_LARGEFILE  O_LARGEFILE
#define O_NDELAY     O_NONBLOCK
#define O_NOATIME    O_NOATIME
#define O_NOCTTY     O_NOCTTY
#define O_NOFOLLOW   O_NOFOLLOW
#define O_NONBLOCK   O_NONBLOCK
#define O_RANDOM     O_RANDOM
#define O_SEQUENTIAL O_SEQUENTIAL
#define O_SYNC       O_SYNC
#define O_TRUNC      O_TRUNC
#define O_UNLINK     O_UNLINK

COSMOPOLITAN_C_END_

#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_DEL 2
#define EPOLL_CTL_MOD 3

#define EPOLLIN        1
#define EPOLLPRI       2
#define EPOLLOUT       4
#define EPOLLERR       8
#define EPOLLHUP       0x10
#define EPOLLRDNORM    0x40
#define EPOLLRDBAND    0x80
#define EPOLLWRNORM    0x0100
#define EPOLLWRBAND    0x0200
#define EPOLLMSG       0x0400
#define EPOLLRDHUP     0x2000
#define EPOLLEXCLUSIVE 0x10000000
#define EPOLLWAKEUP    0x20000000
#define EPOLLONESHOT   0x40000000
#define EPOLLET        0x80000000

COSMOPOLITAN_C_START_

extern const int EPOLL_CLOEXEC;
#define EPOLL_CLOEXEC O_CLOEXEC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ethernet.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ETHERNET_H_

#define ETHERTYPE_PUP      0x0200
#define ETHERTYPE_SPRITE   0x0500
#define ETHERTYPE_IP       0x0800
#define ETHERTYPE_ARP      0x0806
#define ETHERTYPE_REVARP   0x8035
#define ETHERTYPE_AT       0x809B
#define ETHERTYPE_AARP     0x80F3
#define ETHERTYPE_VLAN     0x8100
#define ETHERTYPE_IPX      0x8137
#define ETHERTYPE_IPV6     0x86dd
#define ETHERTYPE_LOOPBACK 0x9000

#define ETHER_ADDR_LEN ETH_ALEN
#define ETHER_TYPE_LEN 2
#define ETHER_CRC_LEN  4
#define ETHER_HDR_LEN  ETH_HLEN
#define ETHER_MIN_LEN  (ETH_ZLEN + ETHER_CRC_LEN)
#define ETHER_MAX_LEN  (ETH_FRAME_LEN + ETHER_CRC_LEN)

#define ETHER_IS_VALID_LEN(foo) \
  ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)

#define ETHERTYPE_TRAIL    0x1000
#define ETHERTYPE_NTRAILER 16

#define ETHERMTU ETH_DATA_LEN
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)



/*!BEGIN libc/sysv/consts/ex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EX_H_

/**
 * @fileoverview Eric Allman's exit() codes
 *
 * - Broadly supported style guideline;
 * - Dating back to 1980 in 4.0BSD;
 * - That won't be standardized.
 *
 */

#define EX_CANTCREAT   73
#define EX_CONFIG      78
#define EX_DATAERR     65
#define EX_IOERR       74
#define EX_NOHOST      68
#define EX_NOINPUT     66
#define EX_NOPERM      77
#define EX_NOUSER      67
#define EX_OK          0
#define EX_OSERR       71
#define EX_OSFILE      72
#define EX_PROTOCOL    76
#define EX_SOFTWARE    70
#define EX_TEMPFAIL    75
#define EX_UNAVAILABLE 69
#define EX_USAGE       64
#define EX__BASE       64
#define EX__MAX        78



/*!BEGIN libc/sysv/consts/exit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EXIT_H_

#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0



/*!BEGIN libc/sysv/consts/f.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_F_H_
COSMOPOLITAN_C_START_

/*
 * full set of fcntl() commands
 * many are only provided by a single platform
 * will be equal to -1 when not available on host
 */
extern const int F_BARRIERFSYNC;
extern const int F_DUPFD;
extern const int F_DUPFD_CLOEXEC;
extern const int F_FULLFSYNC;
extern const int F_GETFD;
extern const int F_GETFL;
extern const int F_GETLEASE;
extern const int F_GETLK;
extern const int F_GETNOSIGPIPE;
extern const int F_GETOWN;
extern const int F_GETPATH;
extern const int F_GETPIPE_SZ;
extern const int F_GETSIG;
extern const int F_MAXFD;
extern const int F_NOCACHE;
extern const int F_NOTIFY;
extern const int F_OFD_GETLK;
extern const int F_OFD_SETLK;
extern const int F_OFD_SETLKW;
extern const int F_RDLCK;
extern const int F_SETFD;
extern const int F_SETFL;
extern const int F_SETLEASE;
extern const int F_SETLK;
extern const int F_SETLKW;
extern const int F_SETNOSIGPIPE;
extern const int F_SETOWN;
extern const int F_SETPIPE_SZ;
extern const int F_SETSIG;
extern const int F_UNLCK;
extern const int F_WRLCK;

COSMOPOLITAN_C_END_

/*
 * portable fcntl() commands
 */
#define F_DUPFD         0
#define F_GETFD         1
#define F_SETFD         2
#define F_GETFL         3
#define F_SETFL         4
#define F_DUPFD_CLOEXEC F_DUPFD_CLOEXEC

/*
 * posix advisory locks
 * polyfilled poorly on windows
 */
#define F_SETLK  F_SETLK
#define F_SETLKW F_SETLKW
#define F_GETLK  F_GETLK
#define F_RDLCK  F_RDLCK
#define F_UNLCK  F_UNLCK
#define F_WRLCK  F_WRLCK



/*!BEGIN libc/sysv/consts/falloc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FALLOC_H_
COSMOPOLITAN_C_START_

extern const int FALLOC_FL_KEEP_SIZE;
extern const int FALLOC_FL_PUNCH_HOLE;
extern const int FALLOC_FL_NO_HIDE_STALE;
extern const int FALLOC_FL_COLLAPSE_RANGE;
extern const int FALLOC_FL_ZERO_RANGE;
extern const int FALLOC_FL_INSERT_RANGE;
extern const int FALLOC_FL_UNSHARE_RANGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fan.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FAN_H_

#define FAN_CLASS_NOTIF              0
#define FAN_ACCESS                   1
#define FAN_ACCESS_PERM              0x020000
#define FAN_ALLOW                    1
#define FAN_ALL_CLASS_BITS           12
#define FAN_ALL_EVENTS               59
#define FAN_ALL_INIT_FLAGS           63
#define FAN_ALL_MARK_FLAGS           255
#define FAN_ALL_OUTGOING_EVENTS      0x03403b
#define FAN_ALL_PERM_EVENTS          0x030000
#define FAN_CLASS_CONTENT            4
#define FAN_CLASS_PRE_CONTENT        8
#define FAN_CLOEXEC                  1
#define FAN_CLOSE                    24
#define FAN_CLOSE_NOWRITE            0x10
#define FAN_CLOSE_WRITE              8
#define FAN_DENY                     2
#define FAN_EVENT_METADATA_LEN       24
#define FAN_EVENT_ON_CHILD           0x08000000
#define FAN_MARK_ADD                 1
#define FAN_MARK_DONT_FOLLOW         4
#define FAN_MARK_FLUSH               0x80
#define FAN_MARK_IGNORED_MASK        0x20
#define FAN_MARK_IGNORED_SURV_MODIFY 0x40
#define FAN_MARK_MOUNT               0x10
#define FAN_MARK_ONLYDIR             8
#define FAN_MARK_REMOVE              2
#define FAN_MODIFY                   2
#define FAN_NOFD                     -1
#define FAN_NONBLOCK                 2
#define FAN_ONDIR                    0x40000000
#define FAN_OPEN                     0x20
#define FAN_OPEN_PERM                0x010000
#define FAN_Q_OVERFLOW               0x4000
#define FAN_UNLIMITED_MARKS          0x20
#define FAN_UNLIMITED_QUEUE          0x10



/*!BEGIN libc/sysv/consts/fbio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FB_H_
COSMOPOLITAN_C_START_

extern const uint64_t FBIOGET_VSCREENINFO;
extern const uint64_t FBIOPUT_VSCREENINFO;
extern const uint64_t FBIOGET_FSCREENINFO;
extern const uint64_t FBIOGETCMAP;
extern const uint64_t FBIOPUTCMAP;
extern const uint64_t FBIOPAN_DISPLAY;
extern const uint64_t FBIO_WAITFORVSYNC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FD_H_
COSMOPOLITAN_C_START_

extern const int FD_CLOEXEC;

#define FD_CLOEXEC 1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fileno.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FILENO_H_

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2



/*!BEGIN libc/sysv/consts/fio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FIO_H_
COSMOPOLITAN_C_START_

extern const uint32_t FIONREAD; /* one of the few encouraged ioctls */
extern const uint32_t FIONBIO;  /* use fcntl(fd, F_SETFL, O_NONBLOCK) */
extern const uint32_t FIOCLEX;  /* use fcntl(fd, F_SETFD, FD_CLOEXEC) */
extern const uint32_t FIONCLEX; /* use fcntl(fd, F_SETFD, 0) */
extern const uint32_t FIOASYNC; /* todo: fcntl(fd, F_SETOWN, pid) */

#define FIONREAD FIONREAD

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fs.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FS_H_

#define FS_IOC_GETFLAGS   0x80086601
#define FS_IOC_SETFLAGS   0x40086602
#define FS_IOC_GETVERSION 0x80087601
#define FS_IOC_SETVERSION 0x40087602
#define FS_IOC_FIEMAP     0xc020660b
#define FS_IOC_FSGETXATTR 0x801c581f
#define FS_IOC_FSSETXATTR 0x401c5820
#define FS_IOC_GETFSLABEL 0x81009431
#define FS_IOC_SETFSLABEL 0x41009432

#define FS_FL_USER_VISIBLE    0x0003DFFF /* user visible flags */
#define FS_FL_USER_MODIFIABLE 0x000380FF /* user modifiable flags */
#define FS_SECRM_FL           0x00000001 /* secure deletion */
#define FS_UNRM_FL            0x00000002 /* undelete */
#define FS_COMPR_FL           0x00000004 /* compress */
#define FS_SYNC_FL            0x00000008 /* synchronous */
#define FS_IMMUTABLE_FL       0x00000010
#define FS_APPEND_FL          0x00000020 /* append-only */
#define FS_NODUMP_FL          0x00000040
#define FS_NOATIME_FL         0x00000080
#define FS_DIRTY_FL           0x00000100
#define FS_COMPRBLK_FL        0x00000200
#define FS_NOCOMP_FL          0x00000400
#define FS_ENCRYPT_FL         0x00000800 /* encrypted file */
#define FS_BTREE_FL           0x00001000
#define FS_INDEX_FL           0x00001000 /* hash-indexed directory */
#define FS_IMAGIC_FL          0x00002000
#define FS_JOURNAL_DATA_FL    0x00004000
#define FS_NOTAIL_FL          0x00008000
#define FS_DIRSYNC_FL         0x00010000
#define FS_TOPDIR_FL          0x00020000
#define FS_HUGE_FILE_FL       0x00040000
#define FS_EXTENT_FL          0x00080000



/*!BEGIN libc/sysv/consts/futex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FUTEX_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_

extern const int FUTEX_WAIT;
extern const int FUTEX_WAKE;
extern const int FUTEX_REQUEUE;

#define FUTEX_WAIT         FUTEX_WAIT
#define FUTEX_WAKE         FUTEX_WAKE
#define FUTEX_REQUEUE      FUTEX_REQUEUE
#define FUTEX_PRIVATE_FLAG 128

#define FUTEX_WAIT_PRIVATE    (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAKE_PRIVATE    (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)

#define FUTEX_WAIT_BITSET      9
#define FUTEX_CLOCK_REALTIME   256
#define FUTEX_BITSET_MATCH_ANY 0xffffffff

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/grnd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_GRND_H_

#define GRND_NONBLOCK 1
#define GRND_RANDOM   2



/*!BEGIN libc/sysv/consts/hwcap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_HWCAP_H_
#ifdef __aarch64__

// Feature bits for getauxval(AT_HWCAP) on AARCH64 GNU/SystemD.

#define HWCAP_FP       (1 << 0)
#define HWCAP_ASIMD    (1 << 1)
#define HWCAP_EVTSTRM  (1 << 2)
#define HWCAP_AES      (1 << 3)
#define HWCAP_PMULL    (1 << 4)
#define HWCAP_SHA1     (1 << 5)
#define HWCAP_SHA2     (1 << 6)
#define HWCAP_CRC32    (1 << 7)
#define HWCAP_ATOMICS  (1 << 8)
#define HWCAP_FPHP     (1 << 9)
#define HWCAP_ASIMDHP  (1 << 10)
#define HWCAP_CPUID    (1 << 11)
#define HWCAP_ASIMDRDM (1 << 12)
#define HWCAP_JSCVT    (1 << 13)
#define HWCAP_FCMA     (1 << 14)
#define HWCAP_LRCPC    (1 << 15)
#define HWCAP_DCPOP    (1 << 16)
#define HWCAP_SHA3     (1 << 17)
#define HWCAP_SM3      (1 << 18)
#define HWCAP_SM4      (1 << 19)
#define HWCAP_ASIMDDP  (1 << 20)
#define HWCAP_SHA512   (1 << 21)
#define HWCAP_SVE      (1 << 22)
#define HWCAP_ASIMDFHM (1 << 23)
#define HWCAP_DIT      (1 << 24)
#define HWCAP_USCAT    (1 << 25)
#define HWCAP_ILRCPC   (1 << 26)
#define HWCAP_FLAGM    (1 << 27)
#define HWCAP_SSBS     (1 << 28)
#define HWCAP_SB       (1 << 29)
#define HWCAP_PACA     (1 << 30)
#define HWCAP_PACG     (1UL << 31)

#define HWCAP2_DCPODP     (1 << 0)
#define HWCAP2_SVE2       (1 << 1)
#define HWCAP2_SVEAES     (1 << 2)
#define HWCAP2_SVEPMULL   (1 << 3)
#define HWCAP2_SVEBITPERM (1 << 4)
#define HWCAP2_SVESHA3    (1 << 5)
#define HWCAP2_SVESM4     (1 << 6)
#define HWCAP2_FLAGM2     (1 << 7)
#define HWCAP2_FRINT      (1 << 8)
#define HWCAP2_SVEI8MM    (1 << 9)
#define HWCAP2_SVEF32MM   (1 << 10)
#define HWCAP2_SVEF64MM   (1 << 11)
#define HWCAP2_SVEBF16    (1 << 12)
#define HWCAP2_I8MM       (1 << 13)
#define HWCAP2_BF16       (1 << 14)
#define HWCAP2_DGH        (1 << 15)
#define HWCAP2_RNG        (1 << 16)
#define HWCAP2_BTI        (1 << 17)
#define HWCAP2_MTE        (1 << 18)

#endif /* __aarch64__ */


/*!BEGIN libc/sysv/consts/icmp6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ICMP6_H_

#define ICMP6_DST_UNREACH ICMP6_DST_UNREACH
#define ICMP6_DST_UNREACH_ADDR ICMP6_DST_UNREACH_ADDR
#define ICMP6_DST_UNREACH_ADMIN ICMP6_DST_UNREACH_ADMIN
#define ICMP6_DST_UNREACH_BEYONDSCOPE ICMP6_DST_UNREACH_BEYONDSCOPE
#define ICMP6_DST_UNREACH_NOPORT ICMP6_DST_UNREACH_NOPORT
#define ICMP6_DST_UNREACH_NOROUTE ICMP6_DST_UNREACH_NOROUTE
#define ICMP6_ECHO_REPLY ICMP6_ECHO_REPLY
#define ICMP6_ECHO_REQUEST ICMP6_ECHO_REQUEST
#define ICMP6_FILTER ICMP6_FILTER
#define ICMP6_INFOMSG_MASK ICMP6_INFOMSG_MASK
#define ICMP6_PACKET_TOO_BIG ICMP6_PACKET_TOO_BIG
#define ICMP6_PARAMPROB_HEADER ICMP6_PARAMPROB_HEADER
#define ICMP6_PARAMPROB_NEXTHEADER ICMP6_PARAMPROB_NEXTHEADER
#define ICMP6_PARAMPROB_OPTION ICMP6_PARAMPROB_OPTION
#define ICMP6_PARAM_PROB ICMP6_PARAM_PROB
#define ICMP6_ROUTER_RENUMBERING ICMP6_ROUTER_RENUMBERING
#define ICMP6_RR_FLAGS_FORCEAPPLY ICMP6_RR_FLAGS_FORCEAPPLY
#define ICMP6_RR_FLAGS_PREVDONE ICMP6_RR_FLAGS_PREVDONE
#define ICMP6_RR_FLAGS_REQRESULT ICMP6_RR_FLAGS_REQRESULT
#define ICMP6_RR_FLAGS_SPECSITE ICMP6_RR_FLAGS_SPECSITE
#define ICMP6_RR_FLAGS_TEST ICMP6_RR_FLAGS_TEST
#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO ICMP6_RR_PCOUSE_RAFLAGS_AUTO
#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN \
  ICMP6_RR_RESULT_FLAGS_FORBIDDEN
#define ICMP6_RR_RESULT_FLAGS_OOB ICMP6_RR_RESULT_FLAGS_OOB
#define ICMP6_TIME_EXCEEDED ICMP6_TIME_EXCEEDED
#define ICMP6_TIME_EXCEED_REASSEMBLY ICMP6_TIME_EXCEED_REASSEMBLY
#define ICMP6_TIME_EXCEED_TRANSIT ICMP6_TIME_EXCEED_TRANSIT

COSMOPOLITAN_C_START_

extern const uint8_t ICMP6_DST_UNREACH;
extern const uint8_t ICMP6_DST_UNREACH_ADDR;
extern const uint8_t ICMP6_DST_UNREACH_ADMIN;
extern const uint8_t ICMP6_DST_UNREACH_BEYONDSCOPE;
extern const uint8_t ICMP6_DST_UNREACH_NOPORT;
extern const uint8_t ICMP6_DST_UNREACH_NOROUTE;
extern const uint8_t ICMP6_ECHO_REPLY;
extern const uint8_t ICMP6_ECHO_REQUEST;
extern const uint8_t ICMP6_FILTER;
extern const uint8_t ICMP6_INFOMSG_MASK;
extern const uint8_t ICMP6_PACKET_TOO_BIG;
extern const uint8_t ICMP6_PARAMPROB_HEADER;
extern const uint8_t ICMP6_PARAMPROB_NEXTHEADER;
extern const uint8_t ICMP6_PARAMPROB_OPTION;
extern const uint8_t ICMP6_PARAM_PROB;
extern const uint8_t ICMP6_ROUTER_RENUMBERING;
extern const uint8_t ICMP6_RR_FLAGS_FORCEAPPLY;
extern const uint8_t ICMP6_RR_FLAGS_PREVDONE;
extern const uint8_t ICMP6_RR_FLAGS_REQRESULT;
extern const uint8_t ICMP6_RR_FLAGS_SPECSITE;
extern const uint8_t ICMP6_RR_FLAGS_TEST;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_AUTO;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_ONLINK;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_FORBIDDEN;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_OOB;
extern const uint8_t ICMP6_TIME_EXCEEDED;
extern const uint8_t ICMP6_TIME_EXCEED_REASSEMBLY;
extern const uint8_t ICMP6_TIME_EXCEED_TRANSIT;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/iff.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IFF_H_
COSMOPOLITAN_C_START_

extern const int IFF_UP;
extern const int IFF_ALLMULTI;
extern const int IFF_AUTOMEDIA;
extern const int IFF_BROADCAST;
extern const int IFF_DEBUG;
extern const int IFF_DYNAMIC;
extern const int IFF_LOOPBACK;
extern const int IFF_MASTER;
extern const int IFF_MULTICAST;
extern const int IFF_NOARP;
extern const int IFF_NOTRAILERS;
extern const int IFF_POINTOPOINT;
extern const int IFF_PORTSEL;
extern const int IFF_PROMISC;
extern const int IFF_RUNNING;
extern const int IFF_SLAVE;

COSMOPOLITAN_C_END_

#define IFF_UP          1
#define IFF_BROADCAST   2
#define IFF_DEBUG       4
#define IFF_LOOPBACK    8
#define IFF_ALLMULTI    IFF_ALLMULTI
#define IFF_AUTOMEDIA   IFF_AUTOMEDIA
#define IFF_DYNAMIC     IFF_DYNAMIC
#define IFF_MASTER      IFF_MASTER
#define IFF_MULTICAST   IFF_MULTICAST
#define IFF_NOARP       IFF_NOARP
#define IFF_NOTRAILERS  IFF_NOTRAILERS
#define IFF_POINTOPOINT IFF_POINTOPOINT
#define IFF_PORTSEL     IFF_PORTSEL
#define IFF_PROMISC     IFF_PROMISC
#define IFF_RUNNING     IFF_RUNNING
#define IFF_SLAVE       IFF_SLAVE




/*!BEGIN libc/sysv/consts/in.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IN_H_

#define IN_ACCESS        1
#define IN_ALL_EVENTS    0x0fff
#define IN_ATTRIB        4
#define IN_CLOEXEC       0x080000
#define IN_CLOSE         24
#define IN_CLOSE_NOWRITE 0x10
#define IN_CLOSE_WRITE   8
#define IN_CREATE        0x0100
#define IN_DELETE        0x0200
#define IN_DELETE_SELF   0x0400
#define IN_DONT_FOLLOW   0x02000000
#define IN_EXCL_UNLINK   0x04000000
#define IN_IGNORED       0x8000
#define IN_ISDIR         0x40000000
#define IN_MASK_ADD      0x20000000
#define IN_MODIFY        2
#define IN_MOVE          192
#define IN_MOVED_FROM    0x40
#define IN_MOVED_TO      0x80
#define IN_MOVE_SELF     0x0800
#define IN_NONBLOCK      0x0800
#define IN_ONESHOT       0x80000000
#define IN_ONLYDIR       0x01000000
#define IN_OPEN          0x20
#define IN_Q_OVERFLOW    0x4000
#define IN_UNMOUNT       0x2000
#define IN_CLASSA_NSHIFT 24



/*!BEGIN libc/sysv/consts/inaddr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INADDR_H_

/**
 * @fileoverview Well-known Internet addresses.
 * These need to be hard-coded as little-endian, so htonl() is needed.
 */

#define INADDR_ANY       0x00000000u /* 0.0.0.0 */
#define INADDR_BROADCAST 0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_NONE      0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_LOOPBACK  0x7F000001u /* 127.0.0.1 */
#define INADDR_TESTNET1  0xC0000200u /* 192.0.2.0/24 (RFC5737§3) */
#define INADDR_TESTNET2  0xC6336400u /* 198.51.100.0/24 */
#define INADDR_TESTNET3  0xCB007100u /* 203.0.113.0/24 */

#define INADDR_ALLHOSTS_GROUP  0xE0000001u
#define INADDR_ALLRTRS_GROUP   0xE0000002u
#define INADDR_MAX_LOCAL_GROUP 0xE00000FFu
#define INADDR_UNSPEC_GROUP    0xE0000000u

#define IN_LOOPBACKNET 127

/* clang-format off */
#define IN6ADDR_ANY_INIT      { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
/* clang-format on */



/*!BEGIN libc/sysv/consts/inet6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INET6_H_

#define INET6_ADDRSTRLEN 48



/*!BEGIN libc/sysv/consts/io.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IO_H_
COSMOPOLITAN_C_START_

#define _IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16))
#define _IOC_NONE        0U
#define _IOC_WRITE       1U
#define _IOC_READ        2U

#define _IO(a, b)      _IOC(_IOC_NONE, (a), (b), 0)
#define _IOW(a, b, c)  _IOC(_IOC_WRITE, (a), (b), sizeof(c))
#define _IOR(a, b, c)  _IOC(_IOC_READ, (a), (b), sizeof(c))
#define _IOWR(a, b, c) _IOC(_IOC_READ | _IOC_WRITE, (a), (b), sizeof(c))

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ioprio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOPRIO_H_
#ifdef _COSMO_SOURCE

#define IOPRIO_WHO_PROCESS 1
#define IOPRIO_WHO_PGRP    2
#define IOPRIO_WHO_USER    3

#define IOPRIO_CLASS_SHIFT 13
#define IOPRIO_CLASS_MASK  0x07
#define IOPRIO_PRIO_MASK   ((1UL << IOPRIO_CLASS_SHIFT) - 1)

#define IOPRIO_PRIO_CLASS(ioprio) \
  (((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)
#define IOPRIO_PRIO_DATA(ioprio) ((ioprio)&IOPRIO_PRIO_MASK)
#define IOPRIO_PRIO_VALUE(class, data)                     \
  ((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \
   ((data)&IOPRIO_PRIO_MASK))

#define IOPRIO_CLASS_NONE 0
#define IOPRIO_CLASS_RT   1
#define IOPRIO_CLASS_BE   2
#define IOPRIO_CLASS_IDLE 3

#define IOPRIO_NR_LEVELS 8
#define IOPRIO_BE_NR     IOPRIO_NR_LEVELS

#define IOPRIO_NORM    4
#define IOPRIO_BE_NORM IOPRIO_NORM

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/iov.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOV_H_
COSMOPOLITAN_C_START_

extern const int IOV_MAX;

COSMOPOLITAN_C_END_

#define IOV_MAX IOV_MAX



/*!BEGIN libc/sysv/consts/ip.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IP_H_
COSMOPOLITAN_C_START_

extern const int IP_ADD_MEMBERSHIP;
extern const int IP_ADD_SOURCE_MEMBERSHIP;
extern const int IP_BIND_ADDRESS_NO_PORT;
extern const int IP_BLOCK_SOURCE;
extern const int IP_CHECKSUM;
extern const int IP_DEFAULT_MULTICAST_LOOP;
extern const int IP_DEFAULT_MULTICAST_TTL;
extern const int IP_DROP_MEMBERSHIP;
extern const int IP_DROP_SOURCE_MEMBERSHIP;
extern const int IP_FREEBIND;
extern const int IP_HDRINCL;
extern const int IP_IPSEC_POLICY;
extern const int IP_MAX_MEMBERSHIPS;
extern const int IP_MINTTL;
extern const int IP_MSFILTER;
extern const int IP_MTU;
extern const int IP_MTU_DISCOVER;
extern const int IP_MULTICAST_ALL;
extern const int IP_MULTICAST_IF;
extern const int IP_MULTICAST_LOOP;
extern const int IP_MULTICAST_TTL;
extern const int IP_NODEFRAG;
extern const int IP_OPTIONS;
extern const int IP_ORIGDSTADDR;
extern const int IP_PASSSEC;
extern const int IP_PKTINFO;
extern const int IP_PKTOPTIONS;
extern const int IP_PMTUDISC;
extern const int IP_PMTUDISC_DO;
extern const int IP_PMTUDISC_DONT;
extern const int IP_PMTUDISC_INTERFACE;
extern const int IP_PMTUDISC_OMIT;
extern const int IP_PMTUDISC_PROBE;
extern const int IP_PMTUDISC_WANT;
extern const int IP_RECVDSTADDR;
extern const int IP_RECVERR;
extern const int IP_RECVOPTS;
extern const int IP_RECVORIGDSTADDR;
extern const int IP_RECVRETOPTS;
extern const int IP_RECVTOS;
extern const int IP_RECVTTL;
extern const int IP_RETOPTS;
extern const int IP_ROUTER_ALERT;
extern const int IP_TOS;
extern const int IP_TRANSPARENT;
extern const int IP_TTL;
extern const int IP_UNBLOCK_SOURCE;
extern const int IP_UNICAST_IF;
extern const int IP_XFRM_POLICY;

#define IP_ADD_MEMBERSHIP         IP_ADD_MEMBERSHIP
#define IP_ADD_SOURCE_MEMBERSHIP  IP_ADD_SOURCE_MEMBERSHIP
#define IP_BIND_ADDRESS_NO_PORT   IP_BIND_ADDRESS_NO_PORT
#define IP_BLOCK_SOURCE           IP_BLOCK_SOURCE
#define IP_CHECKSUM               IP_CHECKSUM
#define IP_DEFAULT_MULTICAST_LOOP IP_DEFAULT_MULTICAST_LOOP
#define IP_DEFAULT_MULTICAST_TTL  IP_DEFAULT_MULTICAST_TTL
#define IP_DROP_MEMBERSHIP        IP_DROP_MEMBERSHIP
#define IP_DROP_SOURCE_MEMBERSHIP IP_DROP_SOURCE_MEMBERSHIP
#define IP_FREEBIND               IP_FREEBIND
#define IP_HDRINCL                IP_HDRINCL
#define IP_IPSEC_POLICY           IP_IPSEC_POLICY
#define IP_MAX_MEMBERSHIPS        IP_MAX_MEMBERSHIPS
#define IP_MINTTL                 IP_MINTTL
#define IP_MSFILTER               IP_MSFILTER
#define IP_MTU                    IP_MTU
#define IP_MTU_DISCOVER           IP_MTU_DISCOVER
#define IP_MULTICAST_ALL          IP_MULTICAST_ALL
#define IP_MULTICAST_IF           IP_MULTICAST_IF
#define IP_MULTICAST_LOOP         IP_MULTICAST_LOOP
#define IP_MULTICAST_TTL          IP_MULTICAST_TTL
#define IP_NODEFRAG               IP_NODEFRAG
#define IP_OPTIONS                IP_OPTIONS
#define IP_ORIGDSTADDR            IP_ORIGDSTADDR
#define IP_PASSSEC                IP_PASSSEC
#define IP_PKTINFO                IP_PKTINFO
#define IP_PKTOPTIONS             IP_PKTOPTIONS
#define IP_PMTUDISC               IP_PMTUDISC
#define IP_PMTUDISC_DO            IP_PMTUDISC_DO
#define IP_PMTUDISC_DONT          IP_PMTUDISC_DONT
#define IP_PMTUDISC_INTERFACE     IP_PMTUDISC_INTERFACE
#define IP_PMTUDISC_OMIT          IP_PMTUDISC_OMIT
#define IP_PMTUDISC_PROBE         IP_PMTUDISC_PROBE
#define IP_PMTUDISC_WANT          IP_PMTUDISC_WANT
#define IP_RECVDSTADDR            IP_RECVDSTADDR
#define IP_RECVERR                IP_RECVERR
#define IP_RECVOPTS               IP_RECVOPTS
#define IP_RECVORIGDSTADDR        IP_RECVORIGDSTADDR
#define IP_RECVRETOPTS            IP_RECVRETOPTS
#define IP_RECVTOS                IP_RECVTOS
#define IP_RECVTTL                IP_RECVTTL
#define IP_RETOPTS                IP_RETOPTS
#define IP_ROUTER_ALERT           IP_ROUTER_ALERT
#define IP_TOS                    IP_TOS
#define IP_TRANSPARENT            IP_TRANSPARENT
#define IP_TTL                    IP_TTL
#define IP_UNBLOCK_SOURCE         IP_UNBLOCK_SOURCE
#define IP_UNICAST_IF             IP_UNICAST_IF
#define IP_XFRM_POLICY            IP_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipport.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPORT_H_

/**
 * ARPA network ports.
 */
#define IPPORT_ECHO         7
#define IPPORT_DISCARD      9
#define IPPORT_SYSTAT       11
#define IPPORT_DAYTIME      13
#define IPPORT_NETSTAT      15
#define IPPORT_FTP          21
#define IPPORT_TELNET       23
#define IPPORT_SMTP         25
#define IPPORT_TIMESERVER   37
#define IPPORT_NAMESERVER   42
#define IPPORT_WHOIS        43
#define IPPORT_MTP          57
#define IPPORT_TFTP         69
#define IPPORT_RJE          77
#define IPPORT_FINGER       79
#define IPPORT_TTYLINK      87
#define IPPORT_SUPDUP       95
#define IPPORT_EXECSERVER   512
#define IPPORT_LOGINSERVER  513
#define IPPORT_CMDSERVER    514
#define IPPORT_EFSSERVER    520
#define IPPORT_BIFFUDP      512
#define IPPORT_WHOSERVER    513
#define IPPORT_ROUTESERVER  520
#define IPPORT_RESERVED     1024
#define IPPORT_USERRESERVED IPPORT_USERRESERVED

/**
 * Modern network ports.
 */
#define IPPORT_SSH         22
#define IPPORT_DOMAIN      53
#define IPPORT_HTTP        80
#define IPPORT_POP3        110
#define IPPORT_SFTP        115
#define IPPORT_NTP         123
#define IPPORT_IMAP2       143
#define IPPORT_NETBIOS_NS  137
#define IPPORT_NETBIOS_DGM 138
#define IPPORT_NETBIOS_SSN 139
#define IPPORT_BGP         179
#define IPPORT_IRC         194
#define IPPORT_HTTPS       443
#define IPPORT_PRINTER     515
#define IPPORT_NFS         2049
#define IPPORT_DISTCC      3632
#define IPPORT_SIP         5060
#define IPPORT_POSTGRESQL  5432
#define IPPORT_X11         6000
#define IPPORT_GIT         9418
#define IPPORT_IRCD        6667
#define IPPORT_IMAPS       993
#define IPPORT_POP3S       995

COSMOPOLITAN_C_START_

extern const int IPPORT_USERRESERVED;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipproto.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPROTO_H_

#define IPPROTO_IP     0
#define IPPROTO_ICMP   1
#define IPPROTO_TCP    6
#define IPPROTO_UDP    17
#define IPPROTO_IPV6   41
#define IPPROTO_ICMPV6 58
#define IPPROTO_RAW    255
#define IPPROTO_MAX    263 /* xxx */



/*!BEGIN libc/sysv/consts/ipv6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPV6_H_
COSMOPOLITAN_C_START_

extern const int IPV6_2292DSTOPTS;
extern const int IPV6_2292HOPLIMIT;
extern const int IPV6_2292HOPOPTS;
extern const int IPV6_2292PKTINFO;
extern const int IPV6_2292PKTOPTIONS;
extern const int IPV6_2292RTHDR;
extern const int IPV6_ADDRFORM;
extern const int IPV6_ADD_MEMBERSHIP;
extern const int IPV6_AUTHHDR;
extern const int IPV6_AUTOFLOWLABEL;
extern const int IPV6_CHECKSUM;
extern const int IPV6_DONTFRAG;
extern const int IPV6_DROP_MEMBERSHIP;
extern const int IPV6_DSTOPTS;
extern const int IPV6_HDRINCL;
extern const int IPV6_HOPLIMIT;
extern const int IPV6_HOPOPTS;
extern const int IPV6_IPSEC_POLICY;
extern const int IPV6_JOIN_ANYCAST;
extern const int IPV6_JOIN_GROUP;
extern const int IPV6_LEAVE_ANYCAST;
extern const int IPV6_LEAVE_GROUP;
extern const int IPV6_MINHOPCOUNT;
extern const int IPV6_MTU;
extern const int IPV6_MTU_DISCOVER;
extern const int IPV6_MULTICAST_HOPS;
extern const int IPV6_MULTICAST_IF;
extern const int IPV6_MULTICAST_LOOP;
extern const int IPV6_NEXTHOP;
extern const int IPV6_ORIGDSTADDR;
extern const int IPV6_PATHMTU;
extern const int IPV6_PKTINFO;
extern const int IPV6_PMTUDISC_DO;
extern const int IPV6_PMTUDISC_DONT;
extern const int IPV6_PMTUDISC_INTERFACE;
extern const int IPV6_PMTUDISC_OMIT;
extern const int IPV6_PMTUDISC_PROBE;
extern const int IPV6_PMTUDISC_WANT;
extern const int IPV6_RECVDSTOPTS;
extern const int IPV6_RECVERR;
extern const int IPV6_RECVHOPLIMIT;
extern const int IPV6_RECVHOPOPTS;
extern const int IPV6_RECVORIGDSTADDR;
extern const int IPV6_RECVPATHMTU;
extern const int IPV6_RECVPKTINFO;
extern const int IPV6_RECVRTHDR;
extern const int IPV6_RECVTCLASS;
extern const int IPV6_ROUTER_ALERT;
extern const int IPV6_RTHDR;
extern const int IPV6_RTHDRDSTOPTS;
extern const int IPV6_RTHDR_LOOSE;
extern const int IPV6_RTHDR_STRICT;
extern const int IPV6_RTHDR_TYPE_0;
extern const int IPV6_RXDSTOPTS;
extern const int IPV6_RXHOPOPTS;
extern const int IPV6_TCLASS;
extern const int IPV6_UNICAST_HOPS;
extern const int IPV6_V6ONLY;
extern const int IPV6_XFRM_POLICY;

#define IPV6_2292DSTOPTS        IPV6_2292DSTOPTS
#define IPV6_2292HOPLIMIT       IPV6_2292HOPLIMIT
#define IPV6_2292HOPOPTS        IPV6_2292HOPOPTS
#define IPV6_2292PKTINFO        IPV6_2292PKTINFO
#define IPV6_2292PKTOPTIONS     IPV6_2292PKTOPTIONS
#define IPV6_2292RTHDR          IPV6_2292RTHDR
#define IPV6_ADDRFORM           IPV6_ADDRFORM
#define IPV6_ADD_MEMBERSHIP     IPV6_ADD_MEMBERSHIP
#define IPV6_AUTHHDR            IPV6_AUTHHDR
#define IPV6_AUTOFLOWLABEL      IPV6_AUTOFLOWLABEL
#define IPV6_CHECKSUM           IPV6_CHECKSUM
#define IPV6_DONTFRAG           IPV6_DONTFRAG
#define IPV6_DROP_MEMBERSHIP    IPV6_DROP_MEMBERSHIP
#define IPV6_DSTOPTS            IPV6_DSTOPTS
#define IPV6_HDRINCL            IPV6_HDRINCL
#define IPV6_HOPLIMIT           IPV6_HOPLIMIT
#define IPV6_HOPOPTS            IPV6_HOPOPTS
#define IPV6_IPSEC_POLICY       IPV6_IPSEC_POLICY
#define IPV6_JOIN_ANYCAST       IPV6_JOIN_ANYCAST
#define IPV6_JOIN_GROUP         IPV6_JOIN_GROUP
#define IPV6_LEAVE_ANYCAST      IPV6_LEAVE_ANYCAST
#define IPV6_LEAVE_GROUP        IPV6_LEAVE_GROUP
#define IPV6_MINHOPCOUNT        IPV6_MINHOPCOUNT
#define IPV6_MTU                IPV6_MTU
#define IPV6_MTU_DISCOVER       IPV6_MTU_DISCOVER
#define IPV6_MULTICAST_HOPS     IPV6_MULTICAST_HOPS
#define IPV6_MULTICAST_IF       IPV6_MULTICAST_IF
#define IPV6_MULTICAST_LOOP     IPV6_MULTICAST_LOOP
#define IPV6_NEXTHOP            IPV6_NEXTHOP
#define IPV6_ORIGDSTADDR        IPV6_ORIGDSTADDR
#define IPV6_PATHMTU            IPV6_PATHMTU
#define IPV6_PKTINFO            IPV6_PKTINFO
#define IPV6_PMTUDISC_DO        IPV6_PMTUDISC_DO
#define IPV6_PMTUDISC_DONT      IPV6_PMTUDISC_DONT
#define IPV6_PMTUDISC_INTERFACE IPV6_PMTUDISC_INTERFACE
#define IPV6_PMTUDISC_OMIT      IPV6_PMTUDISC_OMIT
#define IPV6_PMTUDISC_PROBE     IPV6_PMTUDISC_PROBE
#define IPV6_PMTUDISC_WANT      IPV6_PMTUDISC_WANT
#define IPV6_RECVDSTOPTS        IPV6_RECVDSTOPTS
#define IPV6_RECVERR            IPV6_RECVERR
#define IPV6_RECVHOPLIMIT       IPV6_RECVHOPLIMIT
#define IPV6_RECVHOPOPTS        IPV6_RECVHOPOPTS
#define IPV6_RECVORIGDSTADDR    IPV6_RECVORIGDSTADDR
#define IPV6_RECVPATHMTU        IPV6_RECVPATHMTU
#define IPV6_RECVPKTINFO        IPV6_RECVPKTINFO
#define IPV6_RECVRTHDR          IPV6_RECVRTHDR
#define IPV6_RECVTCLASS         IPV6_RECVTCLASS
#define IPV6_ROUTER_ALERT       IPV6_ROUTER_ALERT
#define IPV6_RTHDR              IPV6_RTHDR
#define IPV6_RTHDRDSTOPTS       IPV6_RTHDRDSTOPTS
#define IPV6_RTHDR_LOOSE        IPV6_RTHDR_LOOSE
#define IPV6_RTHDR_STRICT       IPV6_RTHDR_STRICT
#define IPV6_RTHDR_TYPE_0       IPV6_RTHDR_TYPE_0
#define IPV6_RXDSTOPTS          IPV6_RXDSTOPTS
#define IPV6_RXHOPOPTS          IPV6_RXHOPOPTS
#define IPV6_TCLASS             IPV6_TCLASS
#define IPV6_UNICAST_HOPS       IPV6_UNICAST_HOPS
#define IPV6_V6ONLY             IPV6_V6ONLY
#define IPV6_XFRM_POLICY        IPV6_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/itimer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ITIMER_H_

#define ITIMER_REAL    0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF    2



/*!BEGIN libc/sysv/consts/kd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KD_H_
COSMOPOLITAN_C_START_

extern const uint64_t GIO_FONT;
extern const uint64_t PIO_FONT;
extern const uint64_t GIO_FONTX;
extern const uint64_t PIO_FONTX;
extern const uint64_t PIO_FONT8x8;
extern const uint64_t PIO_FONT8x14;
extern const uint64_t PIO_FONT8x16;
extern const uint64_t PIO_VFONT;
extern const uint64_t PIO_FONTRESET;
extern const uint64_t KDFONTOP;

COSMOPOLITAN_C_END_

#define GIO_FONT      GIO_FONT
#define PIO_FONT      PIO_FONT
#define GIO_FONTX     GIO_FONTX
#define PIO_FONTX     PIO_FONTX
#define PIO_FONT8x8   PIO_FONT8x8
#define PIO_FONT8x14  PIO_FONT8x14
#define PIO_FONT8x16  PIO_FONT8x14
#define PIO_VFONT     PIO_VFONT
#define PIO_FONTRESET PIO_FONTRESET
#define KDFONTOP      KDFONTOP

#ifdef _BSD_SOURCE
#define PIO_VFONT_DEFAULT PIO_FONTRESET
#endif



/*!BEGIN libc/sysv/consts/kern.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KERN_H_
COSMOPOLITAN_C_START_

#define KERN_SOH       "\001"
#define KERN_SOH_ASCII '\001'
#define KERN_EMERG     KERN_SOH "0"
#define KERN_ALERT     KERN_SOH "1"
#define KERN_CRIT      KERN_SOH "2"
#define KERN_ERR       KERN_SOH "3"
#define KERN_WARNING   KERN_SOH "4"
#define KERN_NOTICE    KERN_SOH "5"
#define KERN_INFO      KERN_SOH "6"
#define KERN_DEBUG     KERN_SOH "7"
#define KERN_DEFAULT   ""
#define KERN_CONT      KERN_SOH "c"

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/l.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_L_H_

#define L_SET  SEEK_SET
#define L_INCR SEEK_CUR
#define L_XTND SEEK_END



/*!BEGIN libc/sysv/consts/limits.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIMITS_H_
COSMOPOLITAN_C_START_

extern const int NGROUPS_MAX;
extern const int PIPE_BUF;
extern const int SOMAXCONN;
extern const int _ARG_MAX;
extern const int _NAME_MAX;
extern const int _NSIG;
extern const int _PATH_MAX;
extern const int LINK_MAX;
extern const int MAX_CANON;
extern const int MAX_INPUT;

#define NGROUPS_MAX NGROUPS_MAX
#define PIPE_BUF    PIPE_BUF
#define SOMAXCONN   SOMAXCONN
#define _ARG_MAX    _ARG_MAX
#define _NAME_MAX   _NAME_MAX
#define _NSIG       _NSIG
#define _PATH_MAX   _PATH_MAX
#define LINK_MAX    LINK_MAX
#define MAX_CANON   MAX_CANON
#define MAX_INPUT   MAX_INPUT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIO_H_

#define LIO_NOP LIO_NOP
#define LIO_NOWAIT LIO_NOWAIT
#define LIO_READ LIO_READ
#define LIO_WAIT LIO_WAIT
#define LIO_WRITE LIO_WRITE

COSMOPOLITAN_C_START_

extern const int LIO_NOP;
extern const int LIO_NOWAIT;
extern const int LIO_READ;
extern const int LIO_WAIT;
extern const int LIO_WRITE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOCK_H_
COSMOPOLITAN_C_START_

extern const int LOCK_EX;
extern const int LOCK_NB;
extern const int LOCK_SH;
extern const int LOCK_UN;
extern const int LOCK_UNLOCK_CACHE;

COSMOPOLITAN_C_END_

#define LOCK_EX 2
#define LOCK_NB LOCK_NB
#define LOCK_SH LOCK_SH
#define LOCK_UN LOCK_UN




/*!BEGIN libc/sysv/consts/log.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOG_H_

#define LOG_MASK(pri) (1 << (pri))
#define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)

#define LOG_EMERG   0
#define LOG_ALERT   1
#define LOG_CRIT    2
#define LOG_ERR     3
#define LOG_WARNING 4
#define LOG_NOTICE  5
#define LOG_INFO    6
#define LOG_DEBUG   7

#define LOG_KERN     0000
#define LOG_USER     0010
#define LOG_MAIL     0020
#define LOG_DAEMON   0030
#define LOG_AUTH     0040
#define LOG_SYSLOG   0050
#define LOG_LPR      0060
#define LOG_NEWS     0070
#define LOG_UUCP     0100
#define LOG_CRON     0110
#define LOG_AUTHPRIV 0120
#define LOG_FTP      0130

#define LOG_PID    1
#define LOG_CONS   2
#define LOG_ODELAY 4
#define LOG_NDELAY 8
#define LOG_NOWAIT 16
#define LOG_PERROR 32

#define LOG_LOCAL0 128
#define LOG_LOCAL1 136
#define LOG_LOCAL2 144
#define LOG_LOCAL3 152
#define LOG_LOCAL4 160
#define LOG_LOCAL5 168
#define LOG_LOCAL6 176
#define LOG_LOCAL7 184

#define LOG_NFACILITIES 24
#define LOG_FACMASK     0x03f8
#define LOG_FAC(p)      ((LOG_FACMASK & (p)) >> 3)

#define LOG_PRIMASK       7
#define LOG_PRI(p)        (LOG_PRIMASK & (p))
#define LOG_MAKEPRI(f, p) (((f) << 3) | (p))



/*!BEGIN libc/sysv/consts/loglevel.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOGLEVEL_H_
COSMOPOLITAN_C_START_

#define LOGLEVEL_SCHED   -2
#define LOGLEVEL_DEFAULT -1
#define LOGLEVEL_EMERG   0
#define LOGLEVEL_ALERT   1
#define LOGLEVEL_CRIT    2
#define LOGLEVEL_ERR     3
#define LOGLEVEL_WARNING 4
#define LOGLEVEL_NOTICE  5
#define LOGLEVEL_INFO    6
#define LOGLEVEL_DEBUG   7

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/madv.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MADV_H_
COSMOPOLITAN_C_START_

extern const unsigned MADV_DODUMP;
extern const unsigned MADV_DOFORK;
extern const unsigned MADV_DONTDUMP;
extern const unsigned MADV_DONTFORK;
extern const unsigned MADV_DONTNEED;
extern const unsigned MADV_FREE;
extern const unsigned MADV_HUGEPAGE;
extern const unsigned MADV_HWPOISON;
extern const unsigned MADV_MERGEABLE;
extern const unsigned MADV_NOHUGEPAGE;
extern const unsigned MADV_NORMAL;
extern const unsigned MADV_RANDOM;
extern const unsigned MADV_REMOVE;
extern const unsigned MADV_SEQUENTIAL;
extern const unsigned MADV_UNMERGEABLE;
extern const unsigned MADV_WILLNEED;
extern const unsigned MADV_SOFT_OFFLINE;
extern const unsigned MADV_WIPEONFORK;
extern const unsigned MADV_KEEPONFORK;
extern const unsigned MADV_COLD;
extern const unsigned MADV_PAGEOUT;
extern const unsigned MADV_POPULATE_READ;
extern const unsigned MADV_POPULATE_WRITE;
extern const unsigned MADV_DONTNEED_LOCKED;
extern const unsigned MADV_COLLAPSE;

#define MADV_NORMAL     0
#define MADV_RANDOM     1
#define MADV_SEQUENTIAL 2
#define MADV_WILLNEED   3

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/map.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MAP_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int MAP_32BIT;
extern const int MAP_ANON;
extern const int MAP_ANONYMOUS;
extern const int MAP_CONCEAL;
extern const int MAP_DENYWRITE;
extern const int MAP_EXECUTABLE;
extern const int MAP_FILE;
extern const int MAP_FIXED;
extern const int MAP_FIXED_NOREPLACE;
extern const int MAP_HASSEMAPHORE;
extern const int MAP_HUGETLB;
extern const int MAP_INHERIT;
extern const int MAP_JIT;
extern const int MAP_LOCKED;
extern const int MAP_NOCACHE;
extern const int MAP_NOEXTEND;
extern const int MAP_NONBLOCK;
extern const int MAP_NORESERVE;
extern const int MAP_NOSYNC;
extern const int MAP_POPULATE;
extern const int MAP_PRIVATE;
extern const int MAP_SHARED;
extern const int MAP_SHARED_VALIDATE;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define MAP_FILE    0
#define MAP_SHARED  1
#define MAP_PRIVATE 2
#define MAP_STACK   6
#define MAP_TYPE    15
#define MAP_FIXED   16

#define MAP_ANONYMOUS       MAP_ANONYMOUS
#define MAP_CONCEAL         MAP_CONCEAL
#define MAP_EXECUTABLE      MAP_EXECUTABLE
#define MAP_FIXED_NOREPLACE MAP_FIXED_NOREPLACE
#define MAP_HASSEMAPHORE    MAP_HASSEMAPHORE
#define MAP_POPULATE        MAP_POPULATE
#define MAP_NORESERVE       MAP_NORESERVE

#define MAP_ANON   MAP_ANONYMOUS
#define MAP_NOCORE MAP_CONCEAL



/*!BEGIN libc/sysv/consts/mcast.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MCAST_H_

#define MCAST_BLOCK_SOURCE MCAST_BLOCK_SOURCE
#define MCAST_EXCLUDE MCAST_EXCLUDE
#define MCAST_INCLUDE MCAST_INCLUDE
#define MCAST_JOIN_GROUP MCAST_JOIN_GROUP
#define MCAST_JOIN_SOURCE_GROUP MCAST_JOIN_SOURCE_GROUP
#define MCAST_LEAVE_GROUP MCAST_LEAVE_GROUP
#define MCAST_LEAVE_SOURCE_GROUP MCAST_LEAVE_SOURCE_GROUP
#define MCAST_MSFILTER MCAST_MSFILTER
#define MCAST_UNBLOCK_SOURCE MCAST_UNBLOCK_SOURCE

COSMOPOLITAN_C_START_

extern const int MCAST_BLOCK_SOURCE;
extern const int MCAST_EXCLUDE;
extern const int MCAST_INCLUDE;
extern const int MCAST_JOIN_GROUP;
extern const int MCAST_JOIN_SOURCE_GROUP;
extern const int MCAST_LEAVE_GROUP;
extern const int MCAST_LEAVE_SOURCE_GROUP;
extern const int MCAST_MSFILTER;
extern const int MCAST_UNBLOCK_SOURCE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mfd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MFD_H_

#define MFD_CLOEXEC       1
#define MFD_ALLOW_SEALING 2



/*!BEGIN libc/sysv/consts/mlock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MLOCK_H_
COSMOPOLITAN_C_START_

extern const int MCL_CURRENT;
extern const int MCL_FUTURE;
extern const int MCL_ONFAULT;

COSMOPOLITAN_C_END_

#define MCL_CURRENT 1
#define MCL_FUTURE  2
#define MCL_ONFAULT MCL_ONFAULT



/*!BEGIN libc/sysv/consts/modem.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MODEM_H_
COSMOPOLITAN_C_START_

extern const uint64_t TIOCMGET;
extern const uint64_t TIOCMSET;
extern const uint64_t TIOCMBIC;
extern const uint64_t TIOCMBIS;

extern const int TIOCM_CAR;
extern const int TIOCM_CD;
extern const int TIOCM_CTS;
extern const int TIOCM_DSR;
extern const int TIOCM_DTR;
extern const int TIOCM_LE;
extern const int TIOCM_RI;
extern const int TIOCM_RNG;
extern const int TIOCM_RTS;
extern const int TIOCM_SR;
extern const int TIOCM_ST;

#define TIOCM_LE  0x01
#define TIOCM_DTR 0x02
#define TIOCM_RTS 0x04
#define TIOCM_ST  0x08
#define TIOCM_SR  0x10
#define TIOCM_CTS 0x20
#define TIOCM_CAR 0x40
#define TIOCM_CD  0x40
#define TIOCM_RI  0x80
#define TIOCM_RNG 0x80
#define TIOCM_DSR 0x0100

#define TIOCMGET TIOCMGET
#define TIOCMSET TIOCMSET
#define TIOCMBIC TIOCMBIC
#define TIOCMBIS TIOCMBIS


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const unsigned long MS_RDONLY;
extern const int MNT_RDONLY;
extern const unsigned long MS_NOSUID;
extern const int MNT_NOSUID;
extern const unsigned long MS_NODEV;
extern const int MNT_NODEV;
extern const unsigned long MS_NOEXEC;
extern const int MNT_NOEXEC;
extern const unsigned long MS_SYNCHRONOUS;
extern const int MNT_SYNCHRONOUS;
extern const unsigned long MS_REMOUNT;
extern const int MNT_UPDATE;
extern const unsigned long MS_MANDLOCK;
extern const unsigned long MS_DIRSYNC;
extern const unsigned long MS_NOATIME;
extern const int MNT_NOATIME;
extern const unsigned long MS_NODIRATIME;
extern const unsigned long MS_BIND;
extern const unsigned long MS_MOVE;
extern const unsigned long MS_REC;
extern const unsigned long MS_SILENT;
extern const unsigned long MS_POSIXACL;
extern const unsigned long MS_UNBINDABLE;
extern const unsigned long MS_PRIVATE;
extern const unsigned long MS_SLAVE;
extern const unsigned long MS_SHARED;
extern const unsigned long MS_RELATIME;
extern const int MNT_RELATIME;
extern const unsigned long MS_KERNMOUNT;
extern const unsigned long MS_I_VERSION;
extern const unsigned long MS_STRICTATIME;
extern const int MNT_STRICTATIME;
extern const unsigned long MS_LAZYTIME;
extern const unsigned long MS_ACTIVE;
extern const unsigned long MS_NOUSER;
extern const unsigned long MS_RMT_MASK;
extern const unsigned long MS_MGC_VAL;
extern const unsigned long MS_MGC_MSK;
extern const int MNT_ASYNC;
extern const int MNT_RELOAD;
extern const int MNT_SUIDDIR;
extern const int MNT_NOCLUSTERR;
extern const int MNT_NOCLUSTERW;
extern const int MNT_SNAPSHOT;

#define MS_RDONLY       0x00000001
#define MNT_RDONLY      0x00000001
#define MS_NOSUID       MS_NOSUID
#define MNT_NOSUID      MNT_NOSUID
#define MS_NODEV        MS_NODEV
#define MNT_NODEV       MNT_NODEV
#define MS_NOEXEC       MS_NOEXEC
#define MNT_NOEXEC      MNT_NOEXEC
#define MS_SYNCHRONOUS  MS_SYNCHRONOUS
#define MNT_SYNCHRONOUS MNT_SYNCHRONOUS
#define MS_REMOUNT      MS_REMOUNT
#define MNT_UPDATE      MNT_UPDATE
#define MS_MANDLOCK     MS_MANDLOCK
#define MS_DIRSYNC      MS_DIRSYNC
#define MS_NOATIME      MS_NOATIME
#define MNT_NOATIME     MNT_NOATIME
#define MS_NODIRATIME   MS_NODIRATIME
#define MS_BIND         MS_BIND
#define MS_MOVE         MS_MOVE
#define MS_REC          MS_REC
#define MS_SILENT       MS_SILENT
#define MS_POSIXACL     MS_POSIXACL
#define MS_UNBINDABLE   MS_UNBINDABLE
#define MS_PRIVATE      MS_PRIVATE
#define MS_SLAVE        MS_SLAVE
#define MS_SHARED       MS_SHARED
#define MS_RELATIME     MS_RELATIME
#define MNT_RELATIME    MNT_RELATIME
#define MS_KERNMOUNT    MS_KERNMOUNT
#define MS_I_VERSION    MS_I_VERSION
#define MS_STRICTATIME  MS_STRICTATIME
#define MNT_STRICTATIME MNT_STRICTATIME
#define MS_LAZYTIME     MS_LAZYTIME
#define MS_ACTIVE       MS_ACTIVE
#define MS_NOUSER       MS_NOUSER
#define MS_RMT_MASK     MS_RMT_MASK
#define MS_MGC_VAL      MS_MGC_VAL
#define MS_MGC_MSK      MS_MGC_MSK
#define MNT_ASYNC       MNT_ASYNC
#define MNT_RELOAD      MNT_RELOAD
#define MNT_SUIDDIR     MNT_SUIDDIR
#define MNT_NOCLUSTERR  MNT_NOCLUSTERR
#define MNT_NOCLUSTERW  MNT_NOCLUSTERW
#define MNT_SNAPSHOT    MNT_SNAPSHOT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mremap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MREMAP_H_

#define MREMAP_MAYMOVE 1
#define MREMAP_FIXED   2



/*!BEGIN libc/sysv/consts/msg.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSG_H_
COSMOPOLITAN_C_START_

extern const int MSG_BATCH;
extern const int MSG_BCAST;
extern const int MSG_CMSG_CLOEXEC;
extern const int MSG_CONFIRM;
extern const int MSG_CTRUNC;
extern const int MSG_DONTROUTE;
extern const int MSG_DONTWAIT;
extern const int MSG_EOF;
extern const int MSG_EOR;
extern const int MSG_ERRQUEUE;
extern const int MSG_EXCEPT;
extern const int MSG_FASTOPEN;
extern const int MSG_FIN;
extern const int MSG_INFO;
extern const int MSG_MCAST;
extern const int MSG_MORE;
extern const int MSG_NOERROR;
extern const int MSG_NOSIGNAL;
extern const int MSG_NOTIFICATION;
extern const int MSG_OOB;
extern const int MSG_PARITY_ERROR;
extern const int MSG_PEEK;
extern const int MSG_PROXY;
extern const int MSG_RST;
extern const int MSG_STAT;
extern const int MSG_SYN;
extern const int MSG_TRUNC;
extern const int MSG_WAITALL;
extern const int MSG_WAITFORONE;

#define MSG_OOB       1
#define MSG_PEEK      2
#define MSG_DONTROUTE 4
#define MSG_DONTWAIT  MSG_DONTWAIT
#define MSG_FASTOPEN  MSG_FASTOPEN
#define MSG_WAITALL   MSG_WAITALL
#define MSG_TRUNC     MSG_TRUNC
#define MSG_CTRUNC    MSG_CTRUNC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/msync.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSYNC_H_
COSMOPOLITAN_C_START_

extern const int MS_SYNC;
extern const int MS_ASYNC;
extern const int MS_INVALIDATE;

#define MS_SYNC       MS_SYNC
#define MS_ASYNC      MS_ASYNC
#define MS_INVALIDATE MS_INVALIDATE

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/nrlinux.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NRLINUX_H_
#ifdef _COSMO_SOURCE

#ifdef __x86_64__

#define __NR_linux_exit                    0x003c
#define __NR_linux_exit_group              0x00e7
#define __NR_linux_read                    0x0000
#define __NR_linux_write                   0x0001
#define __NR_linux_open                    0x0002
#define __NR_linux_close                   0x0003
#define __NR_linux_stat                    0x0004
#define __NR_linux_fstat                   0x0005
#define __NR_linux_lstat                   0x0006
#define __NR_linux_poll                    0x0007
#define __NR_linux_ppoll                   0x010f
#define __NR_linux_brk                     0x000c
#define __NR_linux_sigreturn               0x000f
#define __NR_linux_lseek                   0x0008
#define __NR_linux_mmap                    0x0009
#define __NR_linux_msync                   0x001a
#define __NR_linux_mprotect                0x000a
#define __NR_linux_munmap                  0x000b
#define __NR_linux_sigaction               0x000d
#define __NR_linux_sigprocmask             0x000e
#define __NR_linux_ioctl                   0x0010
#define __NR_linux_pread                   0x0011
#define __NR_linux_pwrite                  0x0012
#define __NR_linux_readv                   0x0013
#define __NR_linux_writev                  0x0014
#define __NR_linux_access                  0x0015
#define __NR_linux_pipe                    0x0016
#define __NR_linux_select                  0x0017
#define __NR_linux_pselect6                0x010e
#define __NR_linux_sched_yield             0x0018
#define __NR_linux_mremap                  0x0019
#define __NR_linux_mincore                 0x001b
#define __NR_linux_madvise                 0x001c
#define __NR_linux_shmget                  0x001d
#define __NR_linux_shmat                   0x001e
#define __NR_linux_shmctl                  0x001f
#define __NR_linux_dup                     0x0020
#define __NR_linux_dup2                    0x0021
#define __NR_linux_pause                   0x0022
#define __NR_linux_nanosleep               0x0023
#define __NR_linux_getitimer               0x0024
#define __NR_linux_setitimer               0x0026
#define __NR_linux_alarm                   0x0025
#define __NR_linux_getpid                  0x0027
#define __NR_linux_sendfile                0x0028
#define __NR_linux_socket                  0x0029
#define __NR_linux_connect                 0x002a
#define __NR_linux_accept                  0x002b
#define __NR_linux_sendto                  0x002c
#define __NR_linux_recvfrom                0x002d
#define __NR_linux_sendmsg                 0x002e
#define __NR_linux_recvmsg                 0x002f
#define __NR_linux_shutdown                0x0030
#define __NR_linux_bind                    0x0031
#define __NR_linux_listen                  0x0032
#define __NR_linux_getsockname             0x0033
#define __NR_linux_getpeername             0x0034
#define __NR_linux_socketpair              0x0035
#define __NR_linux_setsockopt              0x0036
#define __NR_linux_getsockopt              0x0037
#define __NR_linux_fork                    0x0039
#define __NR_linux_vfork                   0x003a
#define __NR_linux_execve                  0x003b
#define __NR_linux_wait4                   0x003d
#define __NR_linux_kill                    0x003e
#define __NR_linux_clone                   0x0038
#define __NR_linux_tkill                   0x00c8
#define __NR_linux_futex                   0x00ca
#define __NR_linux_set_robust_list         0x0111
#define __NR_linux_get_robust_list         0x0112
#define __NR_linux_uname                   0x003f
#define __NR_linux_semget                  0x0040
#define __NR_linux_semop                   0x0041
#define __NR_linux_semctl                  0x0042
#define __NR_linux_shmdt                   0x0043
#define __NR_linux_msgget                  0x0044
#define __NR_linux_msgsnd                  0x0045
#define __NR_linux_msgrcv                  0x0046
#define __NR_linux_msgctl                  0x0047
#define __NR_linux_fcntl                   0x0048
#define __NR_linux_flock                   0x0049
#define __NR_linux_fsync                   0x004a
#define __NR_linux_fdatasync               0x004b
#define __NR_linux_truncate                0x004c
#define __NR_linux_ftruncate               0x004d
#define __NR_linux_getcwd                  0x004f
#define __NR_linux_chdir                   0x0050
#define __NR_linux_fchdir                  0x0051
#define __NR_linux_rename                  0x0052
#define __NR_linux_mkdir                   0x0053
#define __NR_linux_rmdir                   0x0054
#define __NR_linux_creat                   0x0055
#define __NR_linux_link                    0x0056
#define __NR_linux_unlink                  0x0057
#define __NR_linux_symlink                 0x0058
#define __NR_linux_readlink                0x0059
#define __NR_linux_chmod                   0x005a
#define __NR_linux_fchmod                  0x005b
#define __NR_linux_chown                   0x005c
#define __NR_linux_fchown                  0x005d
#define __NR_linux_lchown                  0x005e
#define __NR_linux_umask                   0x005f
#define __NR_linux_gettimeofday            0x0060
#define __NR_linux_getrlimit               0x0061
#define __NR_linux_getrusage               0x0062
#define __NR_linux_sysinfo                 0x0063
#define __NR_linux_times                   0x0064
#define __NR_linux_ptrace                  0x0065
#define __NR_linux_syslog                  0x0067
#define __NR_linux_getuid                  0x0066
#define __NR_linux_getgid                  0x0068
#define __NR_linux_getppid                 0x006e
#define __NR_linux_getpgrp                 0x006f
#define __NR_linux_setsid                  0x0070
#define __NR_linux_getsid                  0x007c
#define __NR_linux_getpgid                 0x0079
#define __NR_linux_setpgid                 0x006d
#define __NR_linux_geteuid                 0x006b
#define __NR_linux_getegid                 0x006c
#define __NR_linux_getgroups               0x0073
#define __NR_linux_setgroups               0x0074
#define __NR_linux_setreuid                0x0071
#define __NR_linux_setregid                0x0072
#define __NR_linux_setuid                  0x0069
#define __NR_linux_setgid                  0x006a
#define __NR_linux_setresuid               0x0075
#define __NR_linux_setresgid               0x0077
#define __NR_linux_getresuid               0x0076
#define __NR_linux_getresgid               0x0078
#define __NR_linux_sigpending              0x007f
#define __NR_linux_sigsuspend              0x0082
#define __NR_linux_sigaltstack             0x0083
#define __NR_linux_mknod                   0x0085
#define __NR_linux_mknodat                 0x0103
#define __NR_linux_statfs                  0x0089
#define __NR_linux_fstatfs                 0x008a
#define __NR_linux_getpriority             0x008c
#define __NR_linux_setpriority             0x008d
#define __NR_linux_mlock                   0x0095
#define __NR_linux_munlock                 0x0096
#define __NR_linux_mlockall                0x0097
#define __NR_linux_munlockall              0x0098
#define __NR_linux_setrlimit               0x00a0
#define __NR_linux_chroot                  0x00a1
#define __NR_linux_sync                    0x00a2
#define __NR_linux_acct                    0x00a3
#define __NR_linux_settimeofday            0x00a4
#define __NR_linux_mount                   0x00a5
#define __NR_linux_reboot                  0x00a9
#define __NR_linux_quotactl                0x00b3
#define __NR_linux_setfsuid                0x007a
#define __NR_linux_setfsgid                0x007b
#define __NR_linux_capget                  0x007d
#define __NR_linux_capset                  0x007e
#define __NR_linux_sigtimedwait            0x0080
#define __NR_linux_sigqueueinfo            0x0081
#define __NR_linux_personality             0x0087
#define __NR_linux_ustat                   0x0088
#define __NR_linux_sysfs                   0x008b
#define __NR_linux_sched_setparam          0x008e
#define __NR_linux_sched_getparam          0x008f
#define __NR_linux_sched_setscheduler      0x0090
#define __NR_linux_sched_getscheduler      0x0091
#define __NR_linux_sched_get_priority_max  0x0092
#define __NR_linux_sched_get_priority_min  0x0093
#define __NR_linux_sched_rr_get_interval   0x0094
#define __NR_linux_vhangup                 0x0099
#define __NR_linux_modify_ldt              0x009a
#define __NR_linux_pivot_root              0x009b
#define __NR_linux__sysctl                 0x009c
#define __NR_linux_prctl                   0x009d
#define __NR_linux_arch_prctl              0x009e
#define __NR_linux_adjtimex                0x009f
#define __NR_linux_umount2                 0x00a6
#define __NR_linux_swapon                  0x00a7
#define __NR_linux_swapoff                 0x00a8
#define __NR_linux_sethostname             0x00aa
#define __NR_linux_setdomainname           0x00ab
#define __NR_linux_iopl                    0x00ac
#define __NR_linux_ioperm                  0x00ad
#define __NR_linux_init_module             0x00af
#define __NR_linux_delete_module           0x00b0
#define __NR_linux_gettid                  0x00ba
#define __NR_linux_readahead               0x00bb
#define __NR_linux_setxattr                0x00bc
#define __NR_linux_fsetxattr               0x00be
#define __NR_linux_getxattr                0x00bf
#define __NR_linux_fgetxattr               0x00c1
#define __NR_linux_listxattr               0x00c2
#define __NR_linux_flistxattr              0x00c4
#define __NR_linux_removexattr             0x00c5
#define __NR_linux_fremovexattr            0x00c7
#define __NR_linux_lsetxattr               0x00bd
#define __NR_linux_lgetxattr               0x00c0
#define __NR_linux_llistxattr              0x00c3
#define __NR_linux_lremovexattr            0x00c6
#define __NR_linux_sched_setaffinity       0x00cb
#define __NR_linux_sched_getaffinity       0x00cc
#define __NR_linux_io_setup                0x00ce
#define __NR_linux_io_destroy              0x00cf
#define __NR_linux_io_getevents            0x00d0
#define __NR_linux_io_submit               0x00d1
#define __NR_linux_io_cancel               0x00d2
#define __NR_linux_lookup_dcookie          0x00d4
#define __NR_linux_epoll_create            0x00d5
#define __NR_linux_epoll_wait              0x00e8
#define __NR_linux_epoll_ctl               0x00e9
#define __NR_linux_getdents                0x00d9
#define __NR_linux_oldgetdents             0x004e
#define __NR_linux_set_tid_address         0x00da
#define __NR_linux_restart_syscall         0x00db
#define __NR_linux_semtimedop              0x00dc
#define __NR_linux_fadvise                 0x00dd
#define __NR_linux_timer_create            0x00de
#define __NR_linux_timer_settime           0x00df
#define __NR_linux_timer_gettime           0x00e0
#define __NR_linux_timer_getoverrun        0x00e1
#define __NR_linux_timer_delete            0x00e2
#define __NR_linux_clock_settime           0x00e3
#define __NR_linux_clock_gettime           0x00e4
#define __NR_linux_clock_getres            0x00e5
#define __NR_linux_clock_nanosleep         0x00e6
#define __NR_linux_tgkill                  0x00ea
#define __NR_linux_mbind                   0x00ed
#define __NR_linux_set_mempolicy           0x00ee
#define __NR_linux_get_mempolicy           0x00ef
#define __NR_linux_mq_open                 0x00f0
#define __NR_linux_mq_unlink               0x00f1
#define __NR_linux_mq_timedsend            0x00f2
#define __NR_linux_mq_timedreceive         0x00f3
#define __NR_linux_mq_notify               0x00f4
#define __NR_linux_mq_getsetattr           0x00f5
#define __NR_linux_kexec_load              0x00f6
#define __NR_linux_waitid                  0x00f7
#define __NR_linux_add_key                 0x00f8
#define __NR_linux_request_key             0x00f9
#define __NR_linux_keyctl                  0x00fa
#define __NR_linux_ioprio_set              0x00fb
#define __NR_linux_ioprio_get              0x00fc
#define __NR_linux_inotify_init            0x00fd
#define __NR_linux_inotify_add_watch       0x00fe
#define __NR_linux_inotify_rm_watch        0x00ff
#define __NR_linux_openat                  0x0101
#define __NR_linux_mkdirat                 0x0102
#define __NR_linux_fchownat                0x0104
#define __NR_linux_utime                   0x0084
#define __NR_linux_utimes                  0x00eb
#define __NR_linux_futimesat               0x0105
#define __NR_linux_fstatat                 0x0106
#define __NR_linux_unlinkat                0x0107
#define __NR_linux_renameat                0x0108
#define __NR_linux_linkat                  0x0109
#define __NR_linux_symlinkat               0x010a
#define __NR_linux_readlinkat              0x010b
#define __NR_linux_fchmodat                0x010c
#define __NR_linux_faccessat               0x010d
#define __NR_linux_unshare                 0x0110
#define __NR_linux_splice                  0x0113
#define __NR_linux_tee                     0x0114
#define __NR_linux_sync_file_range         0x0115
#define __NR_linux_vmsplice                0x0116
#define __NR_linux_migrate_pages           0x0100
#define __NR_linux_move_pages              0x0117
#define __NR_linux_preadv                  0x0127
#define __NR_linux_pwritev                 0x0128
#define __NR_linux_utimensat               0x0118
#define __NR_linux_fallocate               0x011d
#define __NR_linux_accept4                 0x0120
#define __NR_linux_dup3                    0x0124
#define __NR_linux_pipe2                   0x0125
#define __NR_linux_epoll_pwait             0x0119
#define __NR_linux_epoll_create1           0x0123
#define __NR_linux_perf_event_open         0x012a
#define __NR_linux_inotify_init1           0x0126
#define __NR_linux_tgsigqueueinfo          0x0129
#define __NR_linux_signalfd                0x011a
#define __NR_linux_signalfd4               0x0121
#define __NR_linux_eventfd                 0x011c
#define __NR_linux_eventfd2                0x0122
#define __NR_linux_timerfd_create          0x011b
#define __NR_linux_timerfd_settime         0x011e
#define __NR_linux_timerfd_gettime         0x011f
#define __NR_linux_recvmmsg                0x012b
#define __NR_linux_fanotify_init           0x012c
#define __NR_linux_fanotify_mark           0x012d
#define __NR_linux_prlimit                 0x012e
#define __NR_linux_name_to_handle_at       0x012f
#define __NR_linux_open_by_handle_at       0x0130
#define __NR_linux_clock_adjtime           0x0131
#define __NR_linux_syncfs                  0x0132
#define __NR_linux_sendmmsg                0x0133
#define __NR_linux_setns                   0x0134
#define __NR_linux_getcpu                  0x0135
#define __NR_linux_process_vm_readv        0x0136
#define __NR_linux_process_vm_writev       0x0137
#define __NR_linux_kcmp                    0x0138
#define __NR_linux_finit_module            0x0139
#define __NR_linux_sched_setattr           0x013a
#define __NR_linux_sched_getattr           0x013b
#define __NR_linux_renameat2               0x013c
#define __NR_linux_seccomp                 0x013d
#define __NR_linux_getrandom               0x013e
#define __NR_linux_memfd_create            0x013f
#define __NR_linux_kexec_file_load         0x0140
#define __NR_linux_bpf                     0x0141
#define __NR_linux_execveat                0x0142
#define __NR_linux_userfaultfd             0x0143
#define __NR_linux_membarrier              0x0144
#define __NR_linux_mlock2                  0x0145
#define __NR_linux_copy_file_range         0x0146
#define __NR_linux_preadv2                 0x0147
#define __NR_linux_pwritev2                0x0148
#define __NR_linux_pkey_mprotect           0x0149
#define __NR_linux_pkey_alloc              0x014a
#define __NR_linux_pkey_free               0x014b
#define __NR_linux_statx                   0x014c
#define __NR_linux_io_pgetevents           0x014d
#define __NR_linux_rseq                    0x014e
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_quotactl_fd             0x01bb
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be
#define __NR_linux_memfd_secret            0x01bf
#define __NR_linux_process_mrelease        0x01c0
#define __NR_linux_futex_waitv             0x01c1
#define __NR_linux_set_mempolicy_home_node 0x01c2

#elif defined(__aarch64__)

#define __NR_linux_exit                    0x005d
#define __NR_linux_exit_group              0x005e
#define __NR_linux_read                    0x003f
#define __NR_linux_write                   0x0040
#define __NR_linux_open                    0x00b4
#define __NR_linux_close                   0x0039
#define __NR_linux_stat                    0x004f
#define __NR_linux_fstat                   0x0050
#define __NR_linux_ppoll                   0x0049
#define __NR_linux_brk                     0x00d6
#define __NR_linux_sigreturn               0x008b
#define __NR_linux_lseek                   0x003e
#define __NR_linux_mmap                    0x00de
#define __NR_linux_msync                   0x00e3
#define __NR_linux_mprotect                0x00e2
#define __NR_linux_munmap                  0x00d7
#define __NR_linux_sigaction               0x0086
#define __NR_linux_sigprocmask             0x0087
#define __NR_linux_ioctl                   0x001d
#define __NR_linux_pread                   0x0043
#define __NR_linux_pwrite                  0x0044
#define __NR_linux_readv                   0x0041
#define __NR_linux_writev                  0x0042
#define __NR_linux_pselect6                0x0048
#define __NR_linux_sched_yield             0x007c
#define __NR_linux_mremap                  0x00d8
#define __NR_linux_mincore                 0x00e8
#define __NR_linux_madvise                 0x00e9
#define __NR_linux_shmget                  0x00c2
#define __NR_linux_shmat                   0x00c4
#define __NR_linux_shmctl                  0x00c3
#define __NR_linux_dup                     0x0017
#define __NR_linux_nanosleep               0x0065
#define __NR_linux_getitimer               0x0066
#define __NR_linux_setitimer               0x0067
#define __NR_linux_getpid                  0x00ac
#define __NR_linux_sendfile                0x0047
#define __NR_linux_socket                  0x00c6
#define __NR_linux_connect                 0x00cb
#define __NR_linux_accept                  0x00ca
#define __NR_linux_sendto                  0x00ce
#define __NR_linux_recvfrom                0x00cf
#define __NR_linux_sendmsg                 0x00d3
#define __NR_linux_recvmsg                 0x00d4
#define __NR_linux_shutdown                0x00d2
#define __NR_linux_bind                    0x00c8
#define __NR_linux_listen                  0x00c9
#define __NR_linux_getsockname             0x00cc
#define __NR_linux_getpeername             0x00cd
#define __NR_linux_socketpair              0x00c7
#define __NR_linux_setsockopt              0x00d0
#define __NR_linux_getsockopt              0x00d1
#define __NR_linux_execve                  0x00dd
#define __NR_linux_wait4                   0x0104
#define __NR_linux_kill                    0x0081
#define __NR_linux_clone                   0x00dc
#define __NR_linux_tkill                   0x0082
#define __NR_linux_futex                   0x0062
#define __NR_linux_set_robust_list         0x0063
#define __NR_linux_get_robust_list         0x0064
#define __NR_linux_uname                   0x00a0
#define __NR_linux_semget                  0x00be
#define __NR_linux_semop                   0x00c1
#define __NR_linux_semctl                  0x00bf
#define __NR_linux_shmdt                   0x00c5
#define __NR_linux_msgget                  0x00ba
#define __NR_linux_msgsnd                  0x00bd
#define __NR_linux_msgrcv                  0x00bc
#define __NR_linux_msgctl                  0x00bb
#define __NR_linux_fcntl                   0x0019
#define __NR_linux_flock                   0x0020
#define __NR_linux_fsync                   0x0052
#define __NR_linux_fdatasync               0x0053
#define __NR_linux_truncate                0x002d
#define __NR_linux_ftruncate               0x002e
#define __NR_linux_getcwd                  0x0011
#define __NR_linux_chdir                   0x0031
#define __NR_linux_fchdir                  0x0032
#define __NR_linux_unlink                  0x00b5
#define __NR_linux_fchmod                  0x0034
#define __NR_linux_fchown                  0x0037
#define __NR_linux_umask                   0x00a6
#define __NR_linux_gettimeofday            0x00a9
#define __NR_linux_getrlimit               0x00a3
#define __NR_linux_getrusage               0x00a5
#define __NR_linux_sysinfo                 0x00b3
#define __NR_linux_times                   0x0099
#define __NR_linux_ptrace                  0x0075
#define __NR_linux_syslog                  0x0074
#define __NR_linux_getuid                  0x00ae
#define __NR_linux_getgid                  0x00b0
#define __NR_linux_getppid                 0x00ad
#define __NR_linux_setsid                  0x009d
#define __NR_linux_getsid                  0x009c
#define __NR_linux_getpgid                 0x009b
#define __NR_linux_setpgid                 0x009a
#define __NR_linux_geteuid                 0x00af
#define __NR_linux_getegid                 0x00b1
#define __NR_linux_getgroups               0x009e
#define __NR_linux_setgroups               0x009f
#define __NR_linux_setreuid                0x0091
#define __NR_linux_setregid                0x008f
#define __NR_linux_setuid                  0x0092
#define __NR_linux_setgid                  0x0090
#define __NR_linux_setresuid               0x0093
#define __NR_linux_setresgid               0x0095
#define __NR_linux_getresuid               0x0094
#define __NR_linux_getresgid               0x0096
#define __NR_linux_sigpending              0x0088
#define __NR_linux_sigsuspend              0x0085
#define __NR_linux_sigaltstack             0x0084
#define __NR_linux_mknodat                 0x0021
#define __NR_linux_statfs                  0x002b
#define __NR_linux_fstatfs                 0x002c
#define __NR_linux_getpriority             0x008d
#define __NR_linux_setpriority             0x008c
#define __NR_linux_mlock                   0x00e4
#define __NR_linux_munlock                 0x00e5
#define __NR_linux_mlockall                0x00e6
#define __NR_linux_munlockall              0x00e7
#define __NR_linux_setrlimit               0x00a4
#define __NR_linux_chroot                  0x0033
#define __NR_linux_sync                    0x0051
#define __NR_linux_acct                    0x0059
#define __NR_linux_settimeofday            0x00aa
#define __NR_linux_mount                   0x0028
#define __NR_linux_reboot                  0x008e
#define __NR_linux_quotactl                0x003c
#define __NR_linux_setfsuid                0x0097
#define __NR_linux_setfsgid                0x0098
#define __NR_linux_capget                  0x005a
#define __NR_linux_capset                  0x005b
#define __NR_linux_sigtimedwait            0x0089
#define __NR_linux_sigqueueinfo            0x008a
#define __NR_linux_personality             0x005c
#define __NR_linux_sched_setparam          0x0076
#define __NR_linux_sched_getparam          0x0079
#define __NR_linux_sched_setscheduler      0x0077
#define __NR_linux_sched_getscheduler      0x0078
#define __NR_linux_sched_get_priority_max  0x007d
#define __NR_linux_sched_get_priority_min  0x007e
#define __NR_linux_sched_rr_get_interval   0x007f
#define __NR_linux_vhangup                 0x003a
#define __NR_linux_pivot_root              0x0029
#define __NR_linux_prctl                   0x00a7
#define __NR_linux_adjtimex                0x00ab
#define __NR_linux_umount2                 0x0027
#define __NR_linux_swapon                  0x00e0
#define __NR_linux_swapoff                 0x00e1
#define __NR_linux_sethostname             0x00a1
#define __NR_linux_setdomainname           0x00a2
#define __NR_linux_init_module             0x0069
#define __NR_linux_delete_module           0x006a
#define __NR_linux_gettid                  0x00b2
#define __NR_linux_readahead               0x00d5
#define __NR_linux_setxattr                0x0005
#define __NR_linux_fsetxattr               0x0007
#define __NR_linux_getxattr                0x0008
#define __NR_linux_fgetxattr               0x000a
#define __NR_linux_listxattr               0x000b
#define __NR_linux_flistxattr              0x000d
#define __NR_linux_removexattr             0x000e
#define __NR_linux_fremovexattr            0x0010
#define __NR_linux_lsetxattr               0x0006
#define __NR_linux_lgetxattr               0x0009
#define __NR_linux_llistxattr              0x000c
#define __NR_linux_lremovexattr            0x000f
#define __NR_linux_sched_setaffinity       0x007a
#define __NR_linux_sched_getaffinity       0x007b
#define __NR_linux_io_setup                0x0000
#define __NR_linux_io_destroy              0x0001
#define __NR_linux_io_getevents            0x0004
#define __NR_linux_io_submit               0x0002
#define __NR_linux_io_cancel               0x0003
#define __NR_linux_lookup_dcookie          0x0012
#define __NR_linux_epoll_ctl               0x0015
#define __NR_linux_getdents                0x003d
#define __NR_linux_set_tid_address         0x0060
#define __NR_linux_restart_syscall         0x0080
#define __NR_linux_semtimedop              0x00c0
#define __NR_linux_fadvise                 0x00df
#define __NR_linux_timer_create            0x006b
#define __NR_linux_timer_settime           0x006e
#define __NR_linux_timer_gettime           0x006c
#define __NR_linux_timer_getoverrun        0x006d
#define __NR_linux_timer_delete            0x006f
#define __NR_linux_clock_settime           0x0070
#define __NR_linux_clock_gettime           0x0071
#define __NR_linux_clock_getres            0x0072
#define __NR_linux_clock_nanosleep         0x0073
#define __NR_linux_tgkill                  0x0083
#define __NR_linux_mbind                   0x00eb
#define __NR_linux_set_mempolicy           0x00ed
#define __NR_linux_get_mempolicy           0x00ec
#define __NR_linux_mq_open                 0x00b4
#define __NR_linux_mq_unlink               0x00b5
#define __NR_linux_mq_timedsend            0x00b6
#define __NR_linux_mq_timedreceive         0x00b7
#define __NR_linux_mq_notify               0x00b8
#define __NR_linux_mq_getsetattr           0x00b9
#define __NR_linux_kexec_load              0x0068
#define __NR_linux_waitid                  0x005f
#define __NR_linux_add_key                 0x00d9
#define __NR_linux_request_key             0x00da
#define __NR_linux_keyctl                  0x00db
#define __NR_linux_ioprio_set              0x001e
#define __NR_linux_ioprio_get              0x001f
#define __NR_linux_openat                  0x0038
#define __NR_linux_mkdirat                 0x0022
#define __NR_linux_fchownat                0x0036
#define __NR_linux_utime                   0x0062
#define __NR_linux_utimes                  0x0058
#define __NR_linux_fstatat                 0x004f
#define __NR_linux_unlinkat                0x0023
#define __NR_linux_renameat                0x0026
#define __NR_linux_linkat                  0x0025
#define __NR_linux_symlinkat               0x0024
#define __NR_linux_readlinkat              0x004e
#define __NR_linux_fchmodat                0x0035
#define __NR_linux_faccessat               0x0030
#define __NR_linux_unshare                 0x0061
#define __NR_linux_splice                  0x004c
#define __NR_linux_tee                     0x004d
#define __NR_linux_sync_file_range         0x0054
#define __NR_linux_vmsplice                0x004b
#define __NR_linux_migrate_pages           0x00ee
#define __NR_linux_move_pages              0x00ef
#define __NR_linux_preadv                  0x0045
#define __NR_linux_pwritev                 0x0046
#define __NR_linux_utimensat               0x0058
#define __NR_linux_fallocate               0x002f
#define __NR_linux_accept4                 0x00f2
#define __NR_linux_dup3                    0x0018
#define __NR_linux_pipe2                   0x003b
#define __NR_linux_epoll_pwait             0x0016
#define __NR_linux_epoll_create1           0x0014
#define __NR_linux_perf_event_open         0x00f1
#define __NR_linux_inotify_init1           0x001a
#define __NR_linux_tgsigqueueinfo          0x00f0
#define __NR_linux_signalfd4               0x004a
#define __NR_linux_eventfd2                0x0013
#define __NR_linux_timerfd_create          0x0055
#define __NR_linux_timerfd_settime         0x0056
#define __NR_linux_timerfd_gettime         0x0057
#define __NR_linux_recvmmsg                0x00f3
#define __NR_linux_fanotify_init           0x0106
#define __NR_linux_fanotify_mark           0x0107
#define __NR_linux_prlimit                 0x0105
#define __NR_linux_name_to_handle_at       0x0108
#define __NR_linux_open_by_handle_at       0x0109
#define __NR_linux_clock_adjtime           0x010a
#define __NR_linux_syncfs                  0x010b
#define __NR_linux_sendmmsg                0x010d
#define __NR_linux_setns                   0x010c
#define __NR_linux_getcpu                  0x00a8
#define __NR_linux_process_vm_readv        0x010e
#define __NR_linux_process_vm_writev       0x010f
#define __NR_linux_kcmp                    0x0110
#define __NR_linux_finit_module            0x0111
#define __NR_linux_sched_setattr           0x0112
#define __NR_linux_sched_getattr           0x0113
#define __NR_linux_renameat2               0x0114
#define __NR_linux_seccomp                 0x0115
#define __NR_linux_getrandom               0x0116
#define __NR_linux_memfd_create            0x0117
#define __NR_linux_bpf                     0x0118
#define __NR_linux_execveat                0x0119
#define __NR_linux_userfaultfd             0x011a
#define __NR_linux_membarrier              0x011b
#define __NR_linux_mlock2                  0x011c
#define __NR_linux_copy_file_range         0x011d
#define __NR_linux_preadv2                 0x011e
#define __NR_linux_pwritev2                0x011f
#define __NR_linux_pkey_mprotect           0x0120
#define __NR_linux_pkey_alloc              0x0121
#define __NR_linux_pkey_free               0x0122
#define __NR_linux_statx                   0x0123
#define __NR_linux_io_pgetevents           0x0124
#define __NR_linux_rseq                    0x0125
#define __NR_linux_kexec_file_load         0x0126
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be

#endif /* __x86_64__ */

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/ok.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_OK_H_

#define F_OK 0
#define X_OK X_OK
#define W_OK W_OK
#define R_OK R_OK

COSMOPOLITAN_C_START_

extern const int X_OK;
extern const int W_OK;
extern const unsigned R_OK; /* warning: is sign bit on windows */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/personality.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PERSONALITY_H_

#define ADDR_COMPAT_LAYOUT 0x0200000
#define READ_IMPLIES_EXEC  0x0400000
#define ADDR_LIMIT_3GB     0x8000000
#define FDPIC_FUNCPTRS     0x0080000
#define STICKY_TIMEOUTS    0x4000000
#define MMAP_PAGE_ZERO     0x0100000
#define ADDR_LIMIT_32BIT   0x0800000
#define WHOLE_SECONDS      0x2000000
#define ADDR_NO_RANDOMIZE  0x0040000
#define SHORT_INODE        0x1000000
#define UNAME26            0x0020000



/*!BEGIN libc/sysv/consts/pf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PF_H_
COSMOPOLITAN_C_START_

extern const int PF_ALG;
extern const int PF_APPLETALK;
extern const int PF_ASH;
extern const int PF_ATMPVC;
extern const int PF_ATMSVC;
extern const int PF_AX25;
extern const int PF_BLUETOOTH;
extern const int PF_BRIDGE;
extern const int PF_CAIF;
extern const int PF_CAN;
extern const int PF_ECONET;
extern const int PF_FILE;
extern const int PF_IB;
extern const int PF_IEEE802154;
extern const int PF_INET6;
extern const int PF_INET;
extern const int PF_IPX;
extern const int PF_IRDA;
extern const int PF_ISDN;
extern const int PF_IUCV;
extern const int PF_KCM;
extern const int PF_KEY;
extern const int PF_LLC;
extern const int PF_LOCAL;
extern const int PF_MAX;
extern const int PF_MPLS;
extern const int PF_NETBEUI;
extern const int PF_NETLINK;
extern const int PF_NETROM;
extern const int PF_NFC;
extern const int PF_PACKET;
extern const int PF_PHONET;
extern const int PF_PPPOX;
extern const int PF_RDS;
extern const int PF_ROSE;
extern const int PF_ROUTE;
extern const int PF_RXRPC;
extern const int PF_SECURITY;
extern const int PF_SNA;
extern const int PF_TIPC;
extern const int PF_UNIX;
extern const int PF_UNSPEC;
extern const int PF_VSOCK;
extern const int PF_WANPIPE;
extern const int PF_X25;

#define PF_ALG        PF_ALG
#define PF_APPLETALK  PF_APPLETALK
#define PF_ASH        PF_ASH
#define PF_ATMPVC     PF_ATMPVC
#define PF_ATMSVC     PF_ATMSVC
#define PF_AX25       PF_AX25
#define PF_BLUETOOTH  PF_BLUETOOTH
#define PF_BRIDGE     PF_BRIDGE
#define PF_CAIF       PF_CAIF
#define PF_CAN        PF_CAN
#define PF_ECONET     PF_ECONET
#define PF_FILE       PF_FILE
#define PF_IB         PF_IB
#define PF_IEEE802154 PF_IEEE802154
#define PF_INET       PF_INET
#define PF_INET6      PF_INET6
#define PF_IPX        PF_IPX
#define PF_IRDA       PF_IRDA
#define PF_ISDN       PF_ISDN
#define PF_IUCV       PF_IUCV
#define PF_KCM        PF_KCM
#define PF_KEY        PF_KEY
#define PF_LLC        PF_LLC
#define PF_LOCAL      PF_LOCAL
#define PF_MAX        PF_MAX
#define PF_MPLS       PF_MPLS
#define PF_NETBEUI    PF_NETBEUI
#define PF_NETLINK    PF_NETLINK
#define PF_NETROM     PF_NETROM
#define PF_NFC        PF_NFC
#define PF_PACKET     PF_PACKET
#define PF_PHONET     PF_PHONET
#define PF_PPPOX      PF_PPPOX
#define PF_RDS        PF_RDS
#define PF_ROSE       PF_ROSE
#define PF_ROUTE      PF_ROUTE
#define PF_RXRPC      PF_RXRPC
#define PF_SECURITY   PF_SECURITY
#define PF_SNA        PF_SNA
#define PF_TIPC       PF_TIPC
#define PF_UNIX       PF_UNIX
#define PF_UNSPEC     PF_UNSPEC
#define PF_VSOCK      PF_VSOCK
#define PF_WANPIPE    PF_WANPIPE
#define PF_X25        PF_X25


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/poll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POLL_H_
COSMOPOLITAN_C_START_

extern const int16_t POLLERR;
extern const int16_t POLLHUP;
extern const int16_t POLLIN;
extern const int16_t POLLNVAL;
extern const int16_t POLLOUT;
extern const int16_t POLLPRI;
extern const int16_t POLLRDBAND;
extern const int16_t POLLRDHUP;
extern const int16_t POLLRDNORM;
extern const int16_t POLLWRBAND;
extern const int16_t POLLWRNORM;

#define INFTIM     (-1)
#define POLLERR    POLLERR
#define POLLHUP    POLLHUP
#define POLLIN     POLLIN
#define POLLNVAL   POLLNVAL
#define POLLOUT    POLLOUT
#define POLLPRI    POLLPRI
#define POLLRDBAND POLLRDBAND
#define POLLRDHUP  POLLRDHUP
#define POLLRDNORM POLLRDNORM
#define POLLWRBAND POLLWRBAND
#define POLLWRNORM POLLWRNORM


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_
COSMOPOLITAN_C_START_

extern const int POSIX_FADV_DONTNEED;
extern const int POSIX_FADV_NOREUSE;
extern const int POSIX_MADV_DONTNEED;
extern const int POSIX_MADV_DONTNEED;

#define POSIX_FADV_NORMAL     0
#define POSIX_FADV_RANDOM     1
#define POSIX_FADV_SEQUENTIAL 2
#define POSIX_FADV_WILLNEED   3

#define POSIX_FADV_DONTNEED POSIX_FADV_DONTNEED
#define POSIX_FADV_NOREUSE  POSIX_FADV_NOREUSE

#define POSIX_MADV_NORMAL     0
#define POSIX_MADV_RANDOM     1
#define POSIX_MADV_SEQUENTIAL 2
#define POSIX_MADV_WILLNEED   3

#define POSIX_MADV_DONTNEED POSIX_MADV_DONTNEED


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/pr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PR_H_

#define PR_GET_SECCOMP        21
#define PR_SET_SECCOMP        22
#define SECCOMP_MODE_DISABLED 0
#define SECCOMP_MODE_STRICT   1
#define SECCOMP_MODE_FILTER   2

#define PR_CAPBSET_READ 23
#define PR_CAPBSET_DROP 24

#define PR_SET_NO_NEW_PRIVS 38
#define PR_GET_NO_NEW_PRIVS 39

#define PR_SET_NAME 15
#define PR_GET_NAME 16

#define PR_GET_TSC     25
#define PR_SET_TSC     26
#define PR_TSC_ENABLE  1
#define PR_TSC_SIGSEGV 2

#define PR_GET_FPEXC        11
#define PR_SET_FPEXC        12
#define PR_FP_EXC_SW_ENABLE 0x80
#define PR_FP_EXC_DIV       0x010000
#define PR_FP_EXC_OVF       0x020000
#define PR_FP_EXC_UND       0x040000
#define PR_FP_EXC_RES       0x080000
#define PR_FP_EXC_INV       0x100000
#define PR_FP_EXC_DISABLED  0
#define PR_FP_EXC_NONRECOV  1
#define PR_FP_EXC_ASYNC     2
#define PR_FP_EXC_PRECISE   3

#define PR_MCE_KILL_CLEAR           0
#define PR_MCE_KILL_LATE            0
#define PR_SPEC_NOT_AFFECTED        0
#define PR_SPEC_STORE_BYPASS        0
#define PR_CAP_AMBIENT_IS_SET       1
#define PR_FPEMU_NOPRINT            1
#define PR_MCE_KILL_EARLY           1
#define PR_MCE_KILL_SET             1
#define PR_SET_MM_START_CODE        1
#define PR_SET_PDEATHSIG            1
#define PR_SPEC_PRCTL               1
#define PR_CAP_AMBIENT_RAISE        2
#define PR_FPEMU_SIGFPE             2
#define PR_GET_PDEATHSIG            2
#define PR_MCE_KILL_DEFAULT         2
#define PR_SET_MM_END_CODE          2
#define PR_SPEC_ENABLE              2
#define PR_CAP_AMBIENT_LOWER        3
#define PR_GET_DUMPABLE             3
#define PR_SET_MM_START_DATA        3
#define PR_CAP_AMBIENT_CLEAR_ALL    4
#define PR_SET_DUMPABLE             4
#define PR_SET_MM_END_DATA          4
#define PR_SPEC_DISABLE             4
#define PR_SET_MM_START_STACK       5
#define PR_SET_MM_START_BRK         6
#define PR_GET_KEEPCAPS             7
#define PR_SET_MM_BRK               7
#define PR_SET_KEEPCAPS             8
#define PR_SET_MM_ARG_START         8
#define PR_SPEC_FORCE_DISABLE       8
#define PR_GET_FPEMU                9
#define PR_SET_MM_ARG_END           9
#define PR_SET_FPEMU                10
#define PR_SET_MM_ENV_START         10
#define PR_GET_FPEXC                11
#define PR_SET_MM_ENV_END           11
#define PR_SET_FPEXC                12
#define PR_SET_MM_AUXV              12
#define PR_SET_MM_EXE_FILE          13
#define PR_SET_MM_MAP               14
#define PR_SET_MM_MAP_SIZE          15
#define PR_GET_TSC                  25
#define PR_SET_TSC                  26
#define PR_GET_SECUREBITS           27
#define PR_SET_SECUREBITS           28
#define PR_SET_TIMERSLACK           29
#define PR_GET_TIMERSLACK           30
#define PR_TASK_PERF_EVENTS_DISABLE 31
#define PR_TASK_PERF_EVENTS_ENABLE  0x20
#define PR_MCE_KILL                 33
#define PR_MCE_KILL_GET             34
#define PR_SET_MM                   35
#define PR_SET_CHILD_SUBREAPER      36
#define PR_GET_CHILD_SUBREAPER      37
#define PR_GET_TID_ADDRESS          40
#define PR_SET_THP_DISABLE          41
#define PR_GET_THP_DISABLE          42
#define PR_MPX_ENABLE_MANAGEMENT    43
#define PR_MPX_DISABLE_MANAGEMENT   44
#define PR_CAP_AMBIENT              47
#define PR_GET_SPECULATION_CTRL     52
#define PR_SET_SPECULATION_CTRL     53
#define PR_SET_TAGGED_ADDR_CTRL     55
#define PR_GET_TAGGED_ADDR_CTRL     56
#define PR_SET_IO_FLUSHER           57
#define PR_GET_IO_FLUSHER           58
#define PR_SET_PTRACER              0x59616d61
#define PR_SET_PTRACER_ANY          -1
#define PR_SET_VMA                  0x53564d41
#define PR_SET_VMA_ANON_NAME        0



/*!BEGIN libc/sysv/consts/prio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PRIO_H_
COSMOPOLITAN_C_START_

extern const int PRIO_MAX;
extern const int PRIO_MIN;
extern const int PRIO_PGRP;
extern const int PRIO_PROCESS;
extern const int PRIO_USER;

#define PRIO_PROCESS 0
#define PRIO_PGRP    1
#define PRIO_USER    2
#define PRIO_MIN     -20
#define PRIO_MAX     20

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/prot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PROT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int PROT_NONE;
extern const int PROT_READ;
extern const int PROT_WRITE;
extern const int PROT_EXEC;
extern const int PROT_GROWSDOWN;
extern const int PROT_GROWSUP;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define PROT_NONE  0
#define PROT_READ  1
#define PROT_WRITE 2
#define PROT_EXEC  4



/*!BEGIN libc/sysv/consts/pt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PT_H_


/*!BEGIN libc/sysv/consts/ptrace.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTRACE_H_
COSMOPOLITAN_C_START_

extern const int PTRACE_TRACEME;
extern const int PTRACE_PEEKTEXT;
extern const int PTRACE_PEEKDATA;
extern const int PTRACE_PEEKUSER;
extern const int PTRACE_POKETEXT;
extern const int PTRACE_POKEDATA;
extern const int PTRACE_POKEUSER;
extern const int PTRACE_CONT;
extern const int PTRACE_KILL;
extern const int PTRACE_SINGLESTEP;
extern const int PTRACE_GETREGS;
extern const int PTRACE_SETREGS;
extern const int PTRACE_GETFPREGS;
extern const int PTRACE_SETFPREGS;
extern const int PTRACE_ATTACH;
extern const int PTRACE_DETACH;
extern const int PTRACE_GETFPXREGS;
extern const int PTRACE_SETFPXREGS;
extern const int PTRACE_SYSCALL;
extern const int PTRACE_GETEVENTMSG;
extern const int PTRACE_GETSIGINFO;
extern const int PTRACE_SETOPTIONS;
extern const int PTRACE_SETSIGINFO;
extern const int PTRACE_GETREGSET;
extern const int PTRACE_GETSIGMASK;
extern const int PTRACE_INTERRUPT;
extern const int PTRACE_LISTEN;
extern const int PTRACE_PEEKSIGINFO;
extern const int PTRACE_SECCOMP_GET_FILTER;
extern const int PTRACE_SECCOMP_GET_METADATA;
extern const int PTRACE_SEIZE;
extern const int PTRACE_SETREGSET;
extern const int PTRACE_SETSIGMASK;
extern const int PTRACE_O_TRACESYSGOOD;
extern const int PTRACE_O_TRACEFORK;
extern const int PTRACE_O_TRACEVFORK;
extern const int PTRACE_O_TRACECLONE;
extern const int PTRACE_O_TRACEEXEC;
extern const int PTRACE_O_TRACEVFORKDONE;
extern const int PTRACE_O_TRACEEXIT;
extern const int PTRACE_O_TRACESECCOMP;
extern const int PTRACE_O_MASK;
extern const int PTRACE_EVENT_FORK;
extern const int PTRACE_EVENT_VFORK;
extern const int PTRACE_EVENT_CLONE;
extern const int PTRACE_EVENT_EXEC;
extern const int PTRACE_EVENT_VFORK_DONE;
extern const int PTRACE_EVENT_EXIT;
extern const int PTRACE_EVENT_STOP;
extern const int PTRACE_EVENT_SECCOMP;

COSMOPOLITAN_C_END_

#define PTRACE_TRACEME              PTRACE_TRACEME
#define PTRACE_PEEKTEXT             PTRACE_PEEKTEXT
#define PTRACE_PEEKDATA             PTRACE_PEEKDATA
#define PTRACE_PEEKUSER             PTRACE_PEEKUSER
#define PTRACE_POKETEXT             PTRACE_POKETEXT
#define PTRACE_POKEDATA             PTRACE_POKEDATA
#define PTRACE_POKEUSER             PTRACE_POKEUSER
#define PTRACE_CONT                 PTRACE_CONT
#define PTRACE_KILL                 PTRACE_KILL
#define PTRACE_SINGLESTEP           PTRACE_SINGLESTEP
#define PTRACE_GETREGS              PTRACE_GETREGS
#define PTRACE_SETREGS              PTRACE_SETREGS
#define PTRACE_GETFPREGS            PTRACE_GETFPREGS
#define PTRACE_SETFPREGS            PTRACE_SETFPREGS
#define PTRACE_ATTACH               PTRACE_ATTACH
#define PTRACE_DETACH               PTRACE_DETACH
#define PTRACE_GETFPXREGS           PTRACE_GETFPXREGS
#define PTRACE_SETFPXREGS           PTRACE_SETFPXREGS
#define PTRACE_SYSCALL              PTRACE_SYSCALL
#define PTRACE_GETEVENTMSG          PTRACE_GETEVENTMSG
#define PTRACE_GETSIGINFO           PTRACE_GETSIGINFO
#define PTRACE_SETOPTIONS           PTRACE_SETOPTIONS
#define PTRACE_SETSIGINFO           PTRACE_SETSIGINFO
#define PTRACE_GETREGSET            PTRACE_GETREGSET
#define PTRACE_GETSIGMASK           PTRACE_GETSIGMASK
#define PTRACE_INTERRUPT            PTRACE_INTERRUPT
#define PTRACE_LISTEN               PTRACE_LISTEN
#define PTRACE_PEEKSIGINFO          PTRACE_PEEKSIGINFO
#define PTRACE_SECCOMP_GET_FILTER   PTRACE_SECCOMP_GET_FILTER
#define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
#define PTRACE_SEIZE                PTRACE_SEIZE
#define PTRACE_SETREGSET            PTRACE_SETREGSET
#define PTRACE_SETSIGMASK           PTRACE_SETSIGMASK
#define PTRACE_O_TRACESYSGOOD       PTRACE_O_TRACESYSGOOD
#define PTRACE_O_TRACEFORK          PTRACE_O_TRACEFORK
#define PTRACE_O_TRACEVFORK         PTRACE_O_TRACEVFORK
#define PTRACE_O_TRACECLONE         PTRACE_O_TRACECLONE
#define PTRACE_O_TRACEEXEC          PTRACE_O_TRACEEXEC
#define PTRACE_O_TRACEVFORKDONE     PTRACE_O_TRACEVFORKDONE
#define PTRACE_O_TRACEEXIT          PTRACE_O_TRACEEXIT
#define PTRACE_O_TRACESECCOMP       PTRACE_O_TRACESECCOMP
#define PTRACE_O_MASK               PTRACE_O_MASK
#define PTRACE_EVENT_FORK           PTRACE_EVENT_FORK
#define PTRACE_EVENT_VFORK          PTRACE_EVENT_VFORK
#define PTRACE_EVENT_CLONE          PTRACE_EVENT_CLONE
#define PTRACE_EVENT_EXEC           PTRACE_EVENT_EXEC
#define PTRACE_EVENT_VFORK_DONE     PTRACE_EVENT_VFORK_DONE
#define PTRACE_EVENT_EXIT           PTRACE_EVENT_EXIT
#define PTRACE_EVENT_STOP           PTRACE_EVENT_STOP
#define PTRACE_EVENT_SECCOMP        PTRACE_EVENT_SECCOMP


#define PT_ATTACH      PTRACE_ATTACH
#define PT_CONTINUE    PTRACE_CONT
#define PT_DETACH      PTRACE_DETACH
#define PT_GETEVENTMSG PTRACE_GETEVENTMSG
#define PT_GETFPREGS   PTRACE_GETFPREGS
#define PT_GETFPXREGS  PTRACE_GETFPXREGS
#define PT_GETREGS     PTRACE_GETREGS
#define PT_GETSIGINFO  PTRACE_GETSIGINFO
#define PT_KILL        PTRACE_KILL
#define PT_READ_D      PTRACE_PEEKDATA
#define PT_READ_I      PTRACE_PEEKTEXT
#define PT_READ_U      PTRACE_PEEKUSER
#define PT_SETFPREGS   PTRACE_SETFPREGS
#define PT_SETFPXREGS  PTRACE_SETFPXREGS
#define PT_SETOPTIONS  PTRACE_SETOPTIONS
#define PT_SETREGS     PTRACE_SETREGS
#define PT_SETSIGINFO  PTRACE_SETSIGINFO
#define PT_STEP        PTRACE_SINGLESTEP
#define PT_SYSCALL     PTRACE_SYSCALL
#define PT_WRITE_D     PTRACE_POKEDATA
#define PT_WRITE_I     PTRACE_POKETEXT
#define PT_WRITE_U     PTRACE_POKEUSER



/*!BEGIN libc/sysv/consts/pty.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTY_H_
COSMOPOLITAN_C_START_

extern const int TIOCPKT;
extern const int TIOCPKT_DATA;
extern const int TIOCPKT_DOSTOP;
extern const int TIOCPKT_FLUSHREAD;
extern const int TIOCPKT_FLUSHWRITE;
extern const int TIOCPKT_IOCTL;
extern const int TIOCPKT_NOSTOP;
extern const int TIOCPKT_START;
extern const int TIOCPKT_STOP;

#define TIOCPKT_DATA       0x00
#define TIOCPKT_DOSTOP     0x01
#define TIOCPKT_FLUSHREAD  0x02
#define TIOCPKT_FLUSHWRITE 0x04
#define TIOCPKT_IOCTL      0x08
#define TIOCPKT_NOSTOP     0x10
#define TIOCPKT_START      0x20
#define TIOCPKT_STOP       0x40

#define TIOCPKT TIOCPKT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/read.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_READ_H_

#define READ_10 READ_10
#define READ_12 READ_12
#define READ_6 READ_6
#define READ_BLOCK_LIMITS READ_BLOCK_LIMITS
#define READ_BUFFER READ_BUFFER
#define READ_CAPACITY READ_CAPACITY
#define READ_DEFECT_DATA READ_DEFECT_DATA
#define READ_ELEMENT_STATUS READ_ELEMENT_STATUS
#define READ_LONG READ_LONG
#define READ_POSITION READ_POSITION
#define READ_REVERSE READ_REVERSE
#define READ_TOC READ_TOC

COSMOPOLITAN_C_START_

extern const long READ_10;
extern const long READ_12;
extern const long READ_6;
extern const long READ_BLOCK_LIMITS;
extern const long READ_BUFFER;
extern const long READ_CAPACITY;
extern const long READ_DEFECT_DATA;
extern const long READ_ELEMENT_STATUS;
extern const long READ_LONG;
extern const long READ_POSITION;
extern const long READ_REVERSE;
extern const long READ_TOC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/reboot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_REBOOT_H_
COSMOPOLITAN_C_START_

extern const unsigned RB_AUTOBOOT;
extern const unsigned RB_POWER_OFF;
extern const unsigned RB_POWERDOWN;
extern const unsigned RB_POWEROFF;
extern const unsigned RB_HALT_SYSTEM;
extern const unsigned RB_HALT;
extern const unsigned RB_SW_SUSPEND;
extern const unsigned RB_KEXEC;
extern const unsigned RB_ENABLE_CAD;
extern const unsigned RB_DISABLE_CAD;
extern const unsigned RB_NOSYNC;

#define RB_AUTOBOOT    RB_AUTOBOOT
#define RB_POWER_OFF   RB_POWER_OFF
#define RB_POWERDOWN   RB_POWERDOWN
#define RB_POWEROFF    RB_POWEROFF
#define RB_HALT_SYSTEM RB_HALT_SYSTEM
#define RB_HALT        RB_HALT
#define RB_SW_SUSPEND  RB_SW_SUSPEND
#define RB_KEXEC       RB_KEXEC
#define RB_ENABLE_CAD  RB_ENABLE_CAD
#define RB_DISABLE_CAD RB_DISABLE_CAD
#define RB_NOSYNC      RB_NOSYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlim.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIM_H_
COSMOPOLITAN_C_START_

extern const uint64_t RLIM_INFINITY;
extern const uint64_t RLIM_NLIMITS;
extern const uint64_t RLIM_SAVED_CUR;
extern const uint64_t RLIM_SAVED_MAX;

#define RLIM_INFINITY  RLIM_INFINITY
#define RLIM_NLIMITS   RLIM_NLIMITS
#define RLIM_SAVED_CUR RLIM_SAVED_CUR
#define RLIM_SAVED_MAX RLIM_SAVED_MAX


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlimit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIMIT_H_
COSMOPOLITAN_C_START_

extern const unsigned RLIMIT_AS;
extern const unsigned RLIMIT_CORE;
extern const unsigned RLIMIT_CPU;
extern const unsigned RLIMIT_DATA;
extern const unsigned RLIMIT_FSIZE;
extern const unsigned RLIMIT_LOCKS;
extern const unsigned RLIMIT_MEMLOCK;
extern const unsigned RLIMIT_MSGQUEUE;
extern const unsigned RLIMIT_NICE;
extern const unsigned RLIMIT_NOFILE;
extern const unsigned RLIMIT_NPROC;
extern const unsigned RLIMIT_NPTS;
extern const unsigned RLIMIT_RSS;
extern const unsigned RLIMIT_RTPRIO;
extern const unsigned RLIMIT_RTTIME;
extern const unsigned RLIMIT_SBSIZE;
extern const unsigned RLIMIT_SIGPENDING;
extern const unsigned RLIMIT_STACK;
extern const unsigned RLIMIT_SWAP;
extern const unsigned RLIMIT_VMEM;

#define RLIMIT_AS         RLIMIT_AS
#define RLIMIT_CORE       RLIMIT_CORE
#define RLIMIT_CPU        RLIMIT_CPU
#define RLIMIT_DATA       RLIMIT_DATA
#define RLIMIT_FSIZE      RLIMIT_FSIZE
#define RLIMIT_LOCKS      RLIMIT_LOCKS
#define RLIMIT_MEMLOCK    RLIMIT_MEMLOCK
#define RLIMIT_MSGQUEUE   RLIMIT_MSGQUEUE
#define RLIMIT_NICE       RLIMIT_NICE
#define RLIMIT_NOFILE     RLIMIT_NOFILE
#define RLIMIT_NPROC      RLIMIT_NPROC
#define RLIMIT_NPTS       RLIMIT_NPTS
#define RLIMIT_RSS        RLIMIT_RSS
#define RLIMIT_RTPRIO     RLIMIT_RTPRIO
#define RLIMIT_RTTIME     RLIMIT_RTTIME
#define RLIMIT_SBSIZE     RLIMIT_SBSIZE
#define RLIMIT_SIGPENDING RLIMIT_SIGPENDING
#define RLIMIT_STACK      RLIMIT_STACK
#define RLIMIT_SWAP       RLIMIT_SWAP
#define RLIMIT_VMEM       RLIMIT_VMEM

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rusage.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RUSAGE_H_
COSMOPOLITAN_C_START_

extern const int RUSAGE_THREAD;
extern const int RUSAGE_CHILDREN;
extern const int RUSAGE_BOTH;

#define RUSAGE_SELF     0
#define RUSAGE_CHILDREN RUSAGE_CHILDREN

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/s.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_S_H_

#define S_IFIFO  0010000 /* pipe */
#define S_IFCHR  0020000 /* character device */
#define S_IFDIR  0040000 /* directory */
#define S_IFBLK  0060000 /* block device */
#define S_IFREG  0100000 /* regular file */
#define S_IFLNK  0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
#define S_IFMT   0170000 /* mask of file types above */

#define S_ISVTX  0001000 /* THE STICKY BIT */
#define S_ISGID  0002000 /* the setgid bit */
#define S_ISUID  0004000 /* the setuid bit */
#define S_IXUSR  0000100 /* user  --x; just use octal */
#define S_IWUSR  0000200 /* user  -w-; just use octal */
#define S_IRUSR  0000400 /* user  r--; just use octal */
#define S_IRWXU  0000700 /* user  rwx; just use octal */
#define S_IXGRP  0000010 /* group --x; just use octal */
#define S_IWGRP  0000020 /* group -w-; just use octal */
#define S_IRGRP  0000040 /* group r--; just use octal */
#define S_IRWXG  0000070 /* group rwx; just use octal */
#define S_IXOTH  0000001 /* other --x; just use octal */
#define S_IWOTH  0000002 /* other -w-; just use octal */
#define S_IROTH  0000004 /* other r--; just use octal */
#define S_IRWXO  0000007 /* other rwx; just use octal */
#define S_IREAD  0000400 /* just use octal */
#define S_IEXEC  0000100 /* just use octal */
#define S_IWRITE 0000200 /* just use octal */
#define S_ISTXT  0001000 /* just use octal */

#define S_ISDIR(mode)  (((mode)&S_IFMT) == S_IFDIR)
#define S_ISCHR(mode)  (((mode)&S_IFMT) == S_IFCHR)
#define S_ISBLK(mode)  (((mode)&S_IFMT) == S_IFBLK)
#define S_ISREG(mode)  (((mode)&S_IFMT) == S_IFREG)
#define S_ISFIFO(mode) (((mode)&S_IFMT) == S_IFIFO)
#define S_ISLNK(mode)  (((mode)&S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)

#define S_BLKSIZE   512
#define ALLPERMS    (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO)
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)



/*!BEGIN libc/sysv/consts/sa.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SA_H_
COSMOPOLITAN_C_START_

extern const uint64_t SA_NOCLDSTOP;
extern const uint64_t SA_NOCLDWAIT;
extern const uint64_t SA_NODEFER;
extern const uint64_t SA_NOMASK;
extern const uint64_t SA_ONESHOT;
extern const uint64_t SA_ONSTACK;
extern const uint64_t SA_RESETHAND;
extern const uint64_t SA_RESTART;
extern const uint64_t SA_SIGINFO;

#define SA_NOCLDSTOP SA_NOCLDSTOP
#define SA_NOCLDWAIT SA_NOCLDWAIT
#define SA_NODEFER   SA_NODEFER
#define SA_NOMASK    SA_NOMASK
#define SA_ONESHOT   SA_ONESHOT
#define SA_ONSTACK   SA_ONSTACK
#define SA_RESETHAND SA_RESETHAND
#define SA_RESTART   SA_RESTART
#define SA_SIGINFO   SA_SIGINFO


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sched.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCHED_H_
COSMOPOLITAN_C_START_

extern const int SCHED_BATCH;
extern const int SCHED_DEADLINE;
extern const int SCHED_FIFO;
extern const int SCHED_IDLE;
extern const int SCHED_OTHER;
extern const int SCHED_RESET_ON_FORK;
extern const int SCHED_RR;

#define SCHED_BATCH         SCHED_BATCH
#define SCHED_DEADLINE      SCHED_DEADLINE
#define SCHED_FIFO          SCHED_FIFO
#define SCHED_IDLE          SCHED_IDLE
#define SCHED_NORMAL        SCHED_OTHER
#define SCHED_OTHER         SCHED_OTHER
#define SCHED_RESET_ON_FORK SCHED_RESET_ON_FORK
#define SCHED_RR            SCHED_RR


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/scm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCM_H_
COSMOPOLITAN_C_START_

extern const int SCM_TIMESTAMP;
extern const int SCM_CREDENTIALS;
extern const int SCM_TIMESTAMPING;
extern const int SCM_TIMESTAMPNS;
extern const int SCM_WIFI_STATUS;

COSMOPOLITAN_C_END_

#define SCM_RIGHTS       1
#define SCM_TIMESTAMP    SCM_TIMESTAMP
#define SCM_CREDENTIALS  SCM_CREDENTIALS
#define SCM_TIMESTAMPING SCM_TIMESTAMPING
#define SCM_TIMESTAMPNS  SCM_TIMESTAMPNS
#define SCM_WIFI_STATUS  SCM_WIFI_STATUS




/*!BEGIN libc/sysv/consts/seek.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SEEK_H_
COSMOPOLITAN_C_START_

extern const int SEEK_DATA;
extern const int SEEK_HOLE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SF_H_
COSMOPOLITAN_C_START_

struct sf_hdtr {
  struct iovec *headers;
  int hdr_cnt;
  struct iovec *trailers;
  int trl_cnt;
};

extern const int SF_MNOWAIT;
extern const int SF_NODISKIO;
extern const int SF_SYNC;

#define SF_MNOWAIT  SF_MNOWAIT
#define SF_NODISKIO SF_NODISKIO
#define SF_SYNC     SF_SYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHM_H_

#define SHM_ANON      SHM_ANON
#define SHM_DEST      SHM_DEST
#define SHM_EXEC      SHM_EXEC
#define SHM_HUGETLB   SHM_HUGETLB
#define SHM_INFO      SHM_INFO
#define SHM_LOCK      SHM_LOCK
#define SHM_LOCKED    SHM_LOCKED
#define SHM_NORESERVE SHM_NORESERVE
#define SHM_R         SHM_R
#define SHM_RDONLY    SHM_RDONLY
#define SHM_REMAP     SHM_REMAP
#define SHM_RND       SHM_RND
#define SHM_STAT      SHM_STAT
#define SHM_UNLOCK    SHM_UNLOCK
#define SHM_W         SHM_W

COSMOPOLITAN_C_START_

extern const char *SHM_ANON;
extern const int SHM_DEST;
extern const int SHM_EXEC;
extern const int SHM_HUGETLB;
extern const int SHM_INFO;
extern const int SHM_LOCK;
extern const int SHM_LOCKED;
extern const int SHM_NORESERVE;
extern const int SHM_R;
extern const int SHM_RDONLY;
extern const int SHM_REMAP;
extern const int SHM_RND;
extern const int SHM_STAT;
extern const int SHM_UNLOCK;
extern const int SHM_W;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shut.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHUT_H_
COSMOPOLITAN_C_START_

extern const int SHUT_RD;
extern const int SHUT_RDWR;
extern const int SHUT_WR;

#define SHUT_RD   0
#define SHUT_RDWR 2
#define SHUT_WR   1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sicode.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SICODE_H_
COSMOPOLITAN_C_START_

extern const int32_t SI_USER;
extern const int32_t SI_QUEUE;
extern const int32_t SI_TIMER;
extern const int32_t SI_MESGQ;
extern const int32_t SI_ASYNCIO;
extern const int32_t SI_TKILL;
extern const int32_t SI_ASYNCNL;
extern const int32_t SI_KERNEL;
extern const int32_t SI_NOINFO;
extern const int32_t CLD_EXITED;
extern const int32_t CLD_KILLED;
extern const int32_t CLD_DUMPED;
extern const int32_t CLD_TRAPPED;
extern const int32_t CLD_STOPPED;
extern const int32_t CLD_CONTINUED;
extern const int32_t TRAP_BRKPT;
extern const int32_t TRAP_TRACE;
extern const int32_t SEGV_MAPERR;
extern const int32_t SEGV_ACCERR;
extern const int32_t SEGV_PKUERR;
extern const int32_t FPE_INTDIV;
extern const int32_t FPE_INTOVF;
extern const int32_t FPE_FLTDIV;
extern const int32_t FPE_FLTOVF;
extern const int32_t FPE_FLTUND;
extern const int32_t FPE_FLTRES;
extern const int32_t FPE_FLTINV;
extern const int32_t FPE_FLTSUB;
extern const int32_t ILL_ILLOPC;
extern const int32_t ILL_ILLOPN;
extern const int32_t ILL_ILLADR;
extern const int32_t ILL_ILLTRP;
extern const int32_t ILL_PRVOPC;
extern const int32_t ILL_PRVREG;
extern const int32_t ILL_COPROC;
extern const int32_t ILL_BADSTK;
extern const int32_t BUS_ADRALN;
extern const int32_t BUS_ADRERR;
extern const int32_t BUS_OBJERR;
extern const int32_t BUS_MCEERR_AR;
extern const int32_t BUS_MCEERR_AO;
extern const int32_t BUS_OOMERR;
extern const int32_t POLL_IN;
extern const int32_t POLL_OUT;
extern const int32_t POLL_MSG;
extern const int32_t POLL_ERR;
extern const int32_t POLL_PRI;
extern const int32_t POLL_HUP;
extern const int32_t SYS_SECCOMP;
extern const int32_t SYS_USER_DISPATCH;

#define CLD_EXITED    1
#define CLD_KILLED    2
#define CLD_DUMPED    3
#define CLD_TRAPPED   4
#define CLD_STOPPED   5
#define CLD_CONTINUED 6
#define TRAP_BRKPT    1
#define TRAP_TRACE    2
#define SEGV_MAPERR   1
#define SEGV_ACCERR   2
#define ILL_ILLOPC    1
#define ILL_PRVREG    6
#define ILL_COPROC    7
#define ILL_BADSTK    8
#define BUS_ADRALN    1
#define BUS_ADRERR    2
#define BUS_OBJERR    3
#define POLL_IN       1
#define POLL_OUT      2
#define POLL_MSG      3
#define POLL_ERR      4
#define POLL_PRI      5
#define POLL_HUP      6

#define SI_USER           SI_USER
#define SI_QUEUE          SI_QUEUE
#define SI_TIMER          SI_TIMER
#define SI_MESGQ          SI_MESGQ
#define SI_ASYNCIO        SI_ASYNCIO
#define SI_TKILL          SI_TKILL
#define SI_ASYNCNL        SI_ASYNCNL
#define SI_KERNEL         SI_KERNEL
#define SI_NOINFO         SI_NOINFO
#define SEGV_PKUERR       SEGV_PKUERR
#define FPE_INTDIV        FPE_INTDIV
#define FPE_INTOVF        FPE_INTOVF
#define FPE_FLTDIV        FPE_FLTDIV
#define FPE_FLTOVF        FPE_FLTOVF
#define FPE_FLTUND        FPE_FLTUND
#define FPE_FLTRES        FPE_FLTRES
#define FPE_FLTINV        FPE_FLTINV
#define FPE_FLTSUB        FPE_FLTSUB
#define ILL_ILLOPN        ILL_ILLOPN
#define ILL_ILLADR        ILL_ILLADR
#define ILL_ILLTRP        ILL_ILLTRP
#define ILL_PRVOPC        ILL_PRVOPC
#define BUS_OOMERR        BUS_OOMERR
#define BUS_MCEERR_AR     BUS_MCEERR_AR
#define BUS_MCEERR_AO     BUS_MCEERR_AO
#define SYS_SECCOMP       SYS_SECCOMP
#define SYS_USER_DISPATCH SYS_USER_DISPATCH


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sig.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIG_H_
COSMOPOLITAN_C_START_

extern const int SIGABRT;
extern const int SIGALRM;
extern const int SIGBUS;
extern const int SIGTHR;
extern const int SIGCHLD;
extern const int SIGCONT;
extern const int SIGEMT;
extern const int SIGFPE;
extern const int SIGHUP;
extern const int SIGILL;
extern const int SIGINFO;
extern const int SIGINT;
extern const int SIGIO;
extern const int SIGIOT;
extern const int SIGKILL;
extern const int SIGPIPE;
extern const int SIGPOLL;
extern const int SIGPROF;
extern const int SIGPWR;
extern const int SIGQUIT;
extern const int SIGRTMAX;
extern const int SIGRTMIN;
extern const int SIGSEGV;
extern const int SIGSTKFLT;
extern const int SIGSTOP;
extern const int SIGSYS;
extern const int SIGTERM;
extern const int SIGTRAP;
extern const int SIGTSTP;
extern const int SIGTTIN;
extern const int SIGTTOU;
extern const int SIGUNUSED;
extern const int SIGURG;
extern const int SIGUSR1;
extern const int SIGUSR2;
extern const int SIGVTALRM;
extern const int SIGWINCH;
extern const int SIGXCPU;
extern const int SIGXFSZ;

extern const int SIG_BLOCK;
extern const int SIG_SETMASK;
extern const int SIG_UNBLOCK;

COSMOPOLITAN_C_END_

#define SIGABRT   6
#define SIGALRM   14
#define SIGFPE    8
#define SIGHUP    1
#define SIGILL    4
#define SIGINT    2
#define SIGIOT    6
#define SIGKILL   9
#define SIGPIPE   13
#define SIGPROF   27
#define SIGQUIT   3
#define SIGSEGV   11
#define SIGTERM   15
#define SIGTRAP   5
#define SIGTTIN   21
#define SIGTTOU   22
#define SIGVTALRM 26
#define SIGWINCH  28
#define SIGXCPU   24
#define SIGXFSZ   25

/*
 * - No macro is define for SIGIO and SIGPOLL in order to persuade
 *   ./configure scripts to favor using poll() or select() instead of
 *   interrupt-based i/o.
 *
 * - No macros are defined for SIGRTMIN and SIGRTMAX because the project
 *   hasn't fleshed them out yet.
 *
 * - SIGTHR doesn't have a macro since it's internal to posix threads.
 *
 * - SIGSTKFLT is Linux-only so no macro is defined.
 */

#define SIGBUS  SIGBUS
#define SIGCHLD SIGCHLD
#define SIGCONT SIGCONT
#define SIGEMT  SIGEMT
#define SIGINFO SIGINFO
#define SIGPWR  SIGPWR
#define SIGSTOP SIGSTOP
#define SIGSYS  SIGSYS
#define SIGTSTP SIGTSTP
#define SIGURG  SIGURG
#define SIGUSR1 SIGUSR1
#define SIGUSR2 SIGUSR2

#define SIG_BLOCK   SIG_BLOCK
#define SIG_SETMASK SIG_SETMASK
#define SIG_UNBLOCK SIG_UNBLOCK



/*!BEGIN libc/sysv/consts/sio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIO_H_
COSMOPOLITAN_C_START_

extern const unsigned long SIOCADDDLCI;
extern const unsigned long SIOCADDMULTI;
extern const unsigned long SIOCADDRT;
extern const unsigned long SIOCDARP;
extern const unsigned long SIOCDELDLCI;
extern const unsigned long SIOCDELMULTI;
extern const unsigned long SIOCDELRT;
extern const unsigned long SIOCDEVPRIVATE;
extern const unsigned long SIOCDIFADDR;
extern const unsigned long SIOCDRARP;
extern const unsigned long SIOCGARP;
extern const unsigned long SIOCGIFADDR;
extern const unsigned long SIOCGIFBR;
extern const unsigned long SIOCGIFBRDADDR;
extern const unsigned long SIOCGIFCONF;
extern const unsigned long SIOCGIFCOUNT;
extern const unsigned long SIOCGIFDSTADDR;
extern const unsigned long SIOCGIFENCAP;
extern const unsigned long SIOCGIFFLAGS;
extern const unsigned long SIOCGIFHWADDR;
extern const unsigned long SIOCGIFINDEX;
extern const unsigned long SIOCGIFMAP;
extern const unsigned long SIOCGIFMEM;
extern const unsigned long SIOCGIFMETRIC;
extern const unsigned long SIOCGIFMTU;
extern const unsigned long SIOCGIFNAME;
extern const unsigned long SIOCGIFNETMASK;
extern const unsigned long SIOCGIFPFLAGS;
extern const unsigned long SIOCGIFSLAVE;
extern const unsigned long SIOCGIFTXQLEN;
extern const unsigned long SIOCGPGRP;
extern const unsigned long SIOCGRARP;
extern const unsigned long SIOCGSTAMP;
extern const unsigned long SIOCGSTAMPNS;
extern const unsigned long SIOCPROTOPRIVATE;
extern const unsigned long SIOCRTMSG;
extern const unsigned long SIOCSARP;
extern const unsigned long SIOCSIFADDR;
extern const unsigned long SIOCSIFBR;
extern const unsigned long SIOCSIFBRDADDR;
extern const unsigned long SIOCSIFDSTADDR;
extern const unsigned long SIOCSIFENCAP;
extern const unsigned long SIOCSIFFLAGS;
extern const unsigned long SIOCSIFHWADDR;
extern const unsigned long SIOCSIFHWBROADCAST;
extern const unsigned long SIOCSIFLINK;
extern const unsigned long SIOCSIFMAP;
extern const unsigned long SIOCSIFMEM;
extern const unsigned long SIOCSIFMETRIC;
extern const unsigned long SIOCSIFMTU;
extern const unsigned long SIOCSIFNAME;
extern const unsigned long SIOCSIFNETMASK;
extern const unsigned long SIOCSIFPFLAGS;
extern const unsigned long SIOCSIFSLAVE;
extern const unsigned long SIOCSIFTXQLEN;
extern const unsigned long SIOCSPGRP;
extern const unsigned long SIOCSRARP;
extern const unsigned long SIOGIFINDEX;

#define SIOCGIFCONF    SIOCGIFCONF
#define SIOCGIFADDR    SIOCGIFADDR
#define SIOCSIFADDR    SIOCSIFADDR
#define SIOCDIFADDR    SIOCDIFADDR
#define SIOCGIFBRDADDR SIOCGIFBRDADDR
#define SIOCGIFNETMASK SIOCGIFNETMASK
#define SIOCGIFFLAGS   SIOCGIFFLAGS
#define SIOCSIFFLAGS   SIOCSIFFLAGS
#define SIOCGIFMETRIC  SIOCGIFMETRIC
#define SIOCSIFMETRIC  SIOCSIFMETRIC
#define SIOCSIFBRDADDR SIOCSIFBRDADDR
#define SIOCSIFNETMASK SIOCSIFNETMASK
#define SIOCGIFDSTADDR SIOCGIFDSTADDR
#define SIOCSIFDSTADDR SIOCSIFDSTADDR
#define SIOCGIFMTU     SIOCGIFMTU
#define SIOCSIFMTU     SIOCSIFMTU

#define SIOCGPGRP SIOCGPGRP
#define SIOCSPGRP SIOCSPGRP

#define SIOCADDMULTI SIOCADDMULTI
#define SIOCDELMULTI SIOCDELMULTI

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/so.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SO_H_

#define SO_DEBUG 1

COSMOPOLITAN_C_START_

extern const int SO_TYPE;
extern const int SO_ERROR;
extern const int SO_ACCEPTCONN;
extern const int SO_REUSEADDR;
extern const int SO_KEEPALIVE;
extern const int SO_DONTROUTE;
extern const int SO_BROADCAST;
extern const int SO_USELOOPBACK;
extern const int SO_LINGER;
extern const int SO_OOBINLINE;
extern const int SO_SNDBUF;
extern const int SO_RCVBUF;
extern const int SO_RCVTIMEO;
extern const int SO_SNDTIMEO;
extern const int SO_RCVLOWAT;
extern const int SO_SNDLOWAT;

#define SO_TYPE        SO_TYPE
#define SO_ERROR       SO_ERROR
#define SO_ACCEPTCONN  SO_ACCEPTCONN
#define SO_REUSEADDR   SO_REUSEADDR
#define SO_KEEPALIVE   SO_KEEPALIVE
#define SO_DONTROUTE   SO_DONTROUTE
#define SO_BROADCAST   SO_BROADCAST
#define SO_USELOOPBACK SO_USELOOPBACK
#define SO_LINGER      SO_LINGER
#define SO_OOBINLINE   SO_OOBINLINE
#define SO_SNDBUF      SO_SNDBUF
#define SO_RCVBUF      SO_RCVBUF
#define SO_RCVTIMEO    SO_RCVTIMEO
#define SO_SNDTIMEO    SO_SNDTIMEO
#define SO_RCVLOWAT    SO_RCVLOWAT
#define SO_SNDLOWAT    SO_SNDLOWAT

/*
 * this isn't available on windows, but it should be fine to use anyway,
 * setsockopt will return ENOPROTOOPT which is perfectly fine to ignore.
 */
extern const int SO_REUSEPORT;
#define SO_REUSEPORT SO_REUSEPORT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOCK_H_
COSMOPOLITAN_C_START_

extern const int SOCK_CLOEXEC;
extern const int SOCK_DCCP;
extern const int SOCK_DGRAM;
extern const int SOCK_NONBLOCK;
extern const int SOCK_PACKET;
extern const int SOCK_RAW;
extern const int SOCK_RDM;
extern const int SOCK_SEQPACKET;
extern const int SOCK_STREAM;

#define SOCK_STREAM    1
#define SOCK_DGRAM     2
#define SOCK_RAW       3
#define SOCK_RDM       4
#define SOCK_SEQPACKET 5
#define SOCK_CLOEXEC   SOCK_CLOEXEC
#define SOCK_NONBLOCK  SOCK_NONBLOCK

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sol.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOL_H_

#define SOL_IP     0
#define SOL_ICMP   1
#define SOL_TCP    6
#define SOL_UDP    17
#define SOL_IPV6   41
#define SOL_ICMPV6 58
#define SOL_RAW    255

COSMOPOLITAN_C_START_

extern const int SOL_SOCKET;
#define SOL_SOCKET SOL_SOCKET

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/splice.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SPLICE_H_
COSMOPOLITAN_C_START_

extern const unsigned int SPLICE_F_GIFT;
extern const unsigned int SPLICE_F_MORE;
extern const unsigned int SPLICE_F_MOVE;
extern const unsigned int SPLICE_F_NONBLOCK;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ss.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SS_H_
COSMOPOLITAN_C_START_

extern const int SS_DISABLE;
extern const int _SIGSTKSZ;
extern const int _MINSIGSTKSZ;

COSMOPOLITAN_C_END_

#define SIGSTKSZ    32768
#define MINSIGSTKSZ 32768 /* xnu defines the highest minimum */
#define SS_ONSTACK  1
#define SS_DISABLE  SS_DISABLE



/*!BEGIN libc/sysv/consts/st.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ST_H_
COSMOPOLITAN_C_START_

extern const int ST_APPEND;
extern const int ST_IMMUTABLE;
extern const int ST_MANDLOCK;
extern const int ST_NOATIME;
extern const int ST_NODEV;
extern const int ST_NODIRATIME;
extern const int ST_NOEXEC;
extern const int ST_NOSUID;
extern const int ST_RDONLY;
extern const int ST_RELATIME;
extern const int ST_SYNCHRONOUS;
extern const int ST_WRITE;

#define ST_APPEND      ST_APPEND
#define ST_IMMUTABLE   ST_IMMUTABLE
#define ST_MANDLOCK    ST_MANDLOCK
#define ST_NOATIME     ST_NOATIME
#define ST_NODEV       ST_NODEV
#define ST_NODIRATIME  ST_NODIRATIME
#define ST_NOEXEC      ST_NOEXEC
#define ST_NOSUID      ST_NOSUID
#define ST_RDONLY      ST_RDONLY
#define ST_RELATIME    ST_RELATIME
#define ST_SYNCHRONOUS ST_SYNCHRONOUS
#define ST_WRITE       ST_WRITE


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCP_H_
COSMOPOLITAN_C_START_

extern const int TCP_CC_INFO;
extern const int TCP_CONGESTION;
extern const int TCP_COOKIE_TRANSACTIONS;
extern const int TCP_CORK;
extern const int TCP_DEFER_ACCEPT;
extern const int TCP_FASTOPEN;
extern const int TCP_FASTOPEN_CONNECT;
extern const int TCP_INFO;
extern const int TCP_KEEPCNT;
extern const int TCP_KEEPIDLE;
extern const int TCP_KEEPINTVL;
extern const int TCP_LINGER2;
extern const int TCP_MAXSEG;
extern const int TCP_MD5SIG;
extern const int TCP_MD5SIG_MAXKEYLEN;
extern const int TCP_NODELAY;
extern const int TCP_NOTSENT_LOWAT;
extern const int TCP_QUEUE_SEQ;
extern const int TCP_QUICKACK;
extern const int TCP_REPAIR;
extern const int TCP_REPAIR_OPTIONS;
extern const int TCP_REPAIR_QUEUE;
extern const int TCP_SAVED_SYN;
extern const int TCP_SAVE_SYN;
extern const int TCP_SYNCNT;
extern const int TCP_THIN_DUPACK;
extern const int TCP_THIN_LINEAR_TIMEOUTS;
extern const int TCP_TIMESTAMP;
extern const int TCP_ULP;
extern const int TCP_USER_TIMEOUT;
extern const int TCP_WINDOW_CLAMP;

#define TCP_NODELAY              1
#define TCP_CC_INFO              TCP_CC_INFO
#define TCP_CONGESTION           TCP_CONGESTION
#define TCP_COOKIE_TRANSACTIONS  TCP_COOKIE_TRANSACTIONS
#define TCP_CORK                 TCP_CORK
#define TCP_DEFER_ACCEPT         TCP_DEFER_ACCEPT
#define TCP_FASTOPEN             TCP_FASTOPEN
#define TCP_FASTOPEN_CONNECT     TCP_FASTOPEN_CONNECT
#define TCP_INFO                 TCP_INFO
#define TCP_KEEPCNT              TCP_KEEPCNT
#define TCP_KEEPIDLE             TCP_KEEPIDLE
#define TCP_KEEPINTVL            TCP_KEEPINTVL
#define TCP_LINGER2              TCP_LINGER2
#define TCP_MAXSEG               TCP_MAXSEG
#define TCP_MD5SIG               TCP_MD5SIG
#define TCP_MD5SIG_MAXKEYLEN     TCP_MD5SIG_MAXKEYLEN
#define TCP_NOTSENT_LOWAT        TCP_NOTSENT_LOWAT
#define TCP_QUEUE_SEQ            TCP_QUEUE_SEQ
#define TCP_QUICKACK             TCP_QUICKACK
#define TCP_REPAIR               TCP_REPAIR
#define TCP_REPAIR_OPTIONS       TCP_REPAIR_OPTIONS
#define TCP_REPAIR_QUEUE         TCP_REPAIR_QUEUE
#define TCP_SAVED_SYN            TCP_SAVED_SYN
#define TCP_SAVE_SYN             TCP_SAVE_SYN
#define TCP_SYNCNT               TCP_SYNCNT
#define TCP_THIN_DUPACK          TCP_THIN_DUPACK
#define TCP_THIN_LINEAR_TIMEOUTS TCP_THIN_LINEAR_TIMEOUTS
#define TCP_TIMESTAMP            TCP_TIMESTAMP
#define TCP_ULP                  TCP_ULP
#define TCP_USER_TIMEOUT         TCP_USER_TIMEOUT
#define TCP_WINDOW_CLAMP         TCP_WINDOW_CLAMP


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcpopt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCPOPT_H_

#define TCPOPT_EOL            0
#define TCPOPT_NOP            1
#define TCPOPT_MAXSEG         2
#define TCPOPT_WINDOW         3
#define TCPOPT_SACK_PERMITTED 4
#define TCPOPT_SACK           5
#define TCPOPT_TIMESTAMP      8

#define TCPOLEN_SACK_PERMITTED 2
#define TCPOLEN_WINDOW         3
#define TCPOLEN_MAXSEG         4
#define TCPOLEN_TIMESTAMP      10



/*!BEGIN libc/sysv/consts/th.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TH_H_

#define TH_FIN  1
#define TH_SYN  2
#define TH_RST  4
#define TH_PUSH 8
#define TH_URG  32
#define TH_ACK  16



/*!BEGIN libc/sysv/consts/timer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TIMER_H_

#define TIMER_ABSTIME 1



/*!BEGIN libc/sysv/consts/uc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UC_H_
COSMOPOLITAN_C_START_

#define UC_FP_XSTATE         1
#define UC_SIGCONTEXT_SS     2
#define UC_STRICT_RESTORE_SS 4

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/unmount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const int MNT_FORCE;
extern const int MNT_DETACH;
extern const int MNT_EXPIRE;
extern const int UMOUNT_NOFOLLOW;
extern const int MNT_BYFSID;

COSMOPOLITAN_C_END_

#define MNT_FORCE       MNT_FORCE
#define MNT_DETACH      MNT_DETACH
#define MNT_EXPIRE      MNT_EXPIRE
#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW
#define MNT_BYFSID      MNT_BYFSID



/*!BEGIN libc/sysv/consts/utime.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UTIME_H_
COSMOPOLITAN_C_START_

extern const int UTIME_NOW;
extern const int UTIME_OMIT;

COSMOPOLITAN_C_END_

#define UTIME_NOW  UTIME_NOW
#define UTIME_OMIT UTIME_OMIT




/*!BEGIN libc/sysv/consts/waitid.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_WAITID_H_
COSMOPOLITAN_C_START_

extern const int WEXITED;
extern const int WSTOPPED;
extern const int WNOWAIT;

#define WEXITED  WEXITED
#define WSTOPPED WSTOPPED
#define WNOWAIT  WNOWAIT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/xopen.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_XOPEN_H_

#define _XOPEN_IOV_MAX  16
#define _XOPEN_ENH_I18N 1
#define _XOPEN_UNIX     1
#define _XOPEN_NAME_MAX 63
#define _XOPEN_PATH_MAX 1024
#define _XOPEN_SOURCE   700



/*!BEGIN libc/thread/semaphore.h */

#define COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
COSMOPOLITAN_C_START_

#define SEM_FAILED        ((sem_t *)0)
#define SEM_MAGIC_NAMED   0xDEADBEEFu
#define SEM_MAGIC_UNNAMED 0xFEEDABEEu
#define SEM_MAGIC_KERNEL  0xCAFEBABEu

typedef struct {
  union {
    struct {
      _Atomic(int) sem_value;
      _Atomic(int) sem_waiters;
      _Atomic(int) sem_prefs; /* named only */
      unsigned sem_magic;
      int64_t sem_dev;     /* named only */
      int64_t sem_ino;     /* named only */
      int sem_pid;         /* unnamed only */
      char sem_lazydelete; /* named only */
      char sem_pshared;
      int *sem_kernel;
    };
    void *sem_space[32];
  };
} sem_t;

int sem_init(sem_t *, int, unsigned) libcesque;
int sem_destroy(sem_t *) libcesque;
int sem_post(sem_t *) libcesque;
int sem_wait(sem_t *) libcesque;
int sem_trywait(sem_t *) libcesque;
int sem_timedwait(sem_t *, const struct timespec *) libcesque;
int sem_getvalue(sem_t *, int *) libcesque;
sem_t *sem_open(const char *, int, ...) libcesque;
int sem_close(sem_t *) libcesque;
int sem_unlink(const char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/thread.h */

#define COSMOPOLITAN_LIBC_THREAD_THREAD_H_

#define PTHREAD_KEYS_MAX              128
#define PTHREAD_STACK_MIN             65536
#define PTHREAD_DESTRUCTOR_ITERATIONS 4

#define PTHREAD_BARRIER_SERIAL_THREAD 31337

#define PTHREAD_MUTEX_DEFAULT    0
#define PTHREAD_MUTEX_NORMAL     0
#define PTHREAD_MUTEX_RECURSIVE  1
#define PTHREAD_MUTEX_ERRORCHECK 2
#define PTHREAD_MUTEX_STALLED    0
#define PTHREAD_MUTEX_ROBUST     1

#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED  1

#define PTHREAD_CREATE_JOINABLE 0
#define PTHREAD_CREATE_DETACHED 1

#define PTHREAD_INHERIT_SCHED  0
#define PTHREAD_EXPLICIT_SCHED 1

#define PTHREAD_CANCELED ((void *)-1)

#define PTHREAD_CANCEL_ENABLE  0
#define PTHREAD_CANCEL_DISABLE 1
#define PTHREAD_CANCEL_MASKED  2

#define PTHREAD_CANCEL_DEFERRED     0
#define PTHREAD_CANCEL_ASYNCHRONOUS 1

#define PTHREAD_SCOPE_SYSTEM  0
#define PTHREAD_SCOPE_PROCESS 1

#define PTHREAD_ATTR_NO_SIGMASK_NP -1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

#define PTHREAD_ONCE_INIT          _PTHREAD_INIT
#define PTHREAD_COND_INITIALIZER   _PTHREAD_INIT
#define PTHREAD_RWLOCK_INITIALIZER _PTHREAD_INIT
#define PTHREAD_MUTEX_INITIALIZER  _PTHREAD_INIT
#define _PTHREAD_INIT \
  { 0 }

typedef uintptr_t pthread_t;
typedef int pthread_id_np_t;
typedef char pthread_condattr_t;
typedef char pthread_rwlockattr_t;
typedef char pthread_barrierattr_t;
typedef unsigned pthread_key_t;
typedef void (*pthread_key_dtor)(void *);

typedef struct pthread_once_s {
  _Atomic(uint32_t) _lock;
} pthread_once_t;

typedef struct pthread_spinlock_s {
  _Atomic(int) _lock;
} pthread_spinlock_t;

typedef struct pthread_mutex_s {
  _Atomic(int32_t) _lock;
  unsigned _type : 2;
  unsigned _pshared : 1;
  unsigned _depth : 6;
  unsigned _owner : 23;
  long _pid;
} pthread_mutex_t;

typedef struct pthread_mutexattr_s {
  char _type;
  char _pshared;
} pthread_mutexattr_t;

typedef struct pthread_cond_s {
  void *_nsync[2];
} pthread_cond_t;

typedef struct pthread_rwlock_s {
  void *_nsync[2];
  char _iswrite;
} pthread_rwlock_t;

typedef struct pthread_barrier_s {
  void *_nsync;
} pthread_barrier_t;

typedef struct pthread_attr_s {
  char __detachstate;
  char __inheritsched;
  char __havesigmask;
  int __schedparam;
  int __schedpolicy;
  int __contentionscope;
  int __guardsize;
  size_t __stacksize;
  uint64_t __sigmask;
  void *__stackaddr;
} pthread_attr_t;

struct _pthread_cleanup_buffer {
  void (*__routine)(void *);
  void *__arg;
  int __canceltype;
  struct _pthread_cleanup_buffer *__prev;
};

/* clang-format off */

int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) dontthrow;
int pthread_attr_destroy(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_getdetachstate(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getguardsize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_getinheritsched(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getschedpolicy(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getscope(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getstack(const pthread_attr_t *, void **, size_t *) libcesque paramsnonnull();
int pthread_attr_getstacksize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_init(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_setdetachstate(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setguardsize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_attr_setinheritsched(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setschedpolicy(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setscope(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setstack(pthread_attr_t *, void *, size_t) libcesque paramsnonnull((1));
int pthread_attr_setstacksize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_barrier_destroy(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned) libcesque paramsnonnull((1));
int pthread_barrier_wait(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrierattr_destroy(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *) libcesque paramsnonnull();
int pthread_barrierattr_init(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int) libcesque paramsnonnull();
int pthread_cancel(pthread_t) libcesque;
int pthread_cond_broadcast(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_destroy(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *) libcesque paramsnonnull((1));
int pthread_cond_signal(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *) libcesque paramsnonnull();
int pthread_condattr_destroy(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_getpshared(const pthread_condattr_t *, int *) libcesque paramsnonnull();
int pthread_condattr_init(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_setpshared(pthread_condattr_t *, int) libcesque paramsnonnull();
int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *) dontthrow paramsnonnull((1));
int pthread_detach(pthread_t) libcesque;
int pthread_equal(pthread_t, pthread_t) libcesque;
int pthread_getattr_np(pthread_t, pthread_attr_t *) libcesque paramsnonnull();
int pthread_getname_np(pthread_t, char *, size_t) libcesque paramsnonnull();
int pthread_getunique_np(pthread_t, pthread_id_np_t *) libcesque paramsnonnull();
int pthread_join(pthread_t, void **) libcesque;
int pthread_key_create(pthread_key_t *, pthread_key_dtor) libcesque paramsnonnull((1));
int pthread_key_delete(pthread_key_t) libcesque;
int pthread_kill(pthread_t, int) libcesque;
int pthread_mutex_consistent(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_destroy(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *) libcesque paramsnonnull((1));
int pthread_mutex_lock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_trylock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_unlock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutexattr_destroy(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_init(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_mutexattr_settype(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_once(pthread_once_t *, void (*)(void)) paramsnonnull();
int pthread_orphan_np(void) libcesque;
int pthread_rwlock_destroy(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *) libcesque paramsnonnull((1));
int pthread_rwlock_rdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_tryrdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_trywrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_unlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_wrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, int *) libcesque paramsnonnull();
int pthread_rwlockattr_init(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int) libcesque paramsnonnull();
int pthread_setcancelstate(int, int *) libcesque;
int pthread_setcanceltype(int, int *) libcesque;
int pthread_setname_np(pthread_t, const char *) libcesque paramsnonnull();
int pthread_setschedprio(pthread_t, int) libcesque;
int pthread_setspecific(pthread_key_t, const void *) libcesque;
int pthread_spin_destroy(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_init(pthread_spinlock_t *, int) libcesque paramsnonnull();
int pthread_spin_lock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_trylock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_unlock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_testcancel_np(void) libcesque;
int pthread_tryjoin_np(pthread_t, void **) libcesque;
int pthread_yield_np(void) libcesque;
int pthread_yield(void) libcesque;
pthread_id_np_t pthread_getthreadid_np(void) libcesque;
pthread_t pthread_self(void) libcesque pureconst;
void *pthread_getspecific(pthread_key_t) libcesque;
void pthread_cleanup_pop(struct _pthread_cleanup_buffer *, int) libcesque paramsnonnull();
void pthread_cleanup_push(struct _pthread_cleanup_buffer *, void (*)(void *), void *) libcesque paramsnonnull((1));
void pthread_exit(void *) libcesque wontreturn;
void pthread_testcancel(void) libcesque;
void pthread_pause_np(void) libcesque;

/* clang-format on */

#define pthread_cleanup_push(routine, arg)  \
  {                                         \
    struct _pthread_cleanup_buffer _buffer; \
    pthread_cleanup_push(&_buffer, (routine), (arg));

#define pthread_cleanup_pop(execute)        \
  pthread_cleanup_pop(&_buffer, (execute)); \
  }

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/thread/thread2.h */

#define COSMOPOLITAN_LIBC_INTRIN_PTHREAD2_H_
COSMOPOLITAN_C_START_
/* clang-format off */

int pthread_attr_getschedparam(const pthread_attr_t *, struct sched_param *) libcesque paramsnonnull();
int pthread_attr_getsigmask_np(const pthread_attr_t *, sigset_t *) libcesque paramsnonnull((1));
int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *) libcesque paramsnonnull();
int pthread_attr_setsigmask_np(pthread_attr_t *, const sigset_t *) libcesque paramsnonnull((1));
int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *) libcesque paramsnonnull((1, 2));
int pthread_getaffinity_np(pthread_t, size_t, cpu_set_t *) libcesque paramsnonnull();
int pthread_getschedparam(pthread_t, int *, struct sched_param *) libcesque paramsnonnull();
int pthread_setaffinity_np(pthread_t, size_t, const cpu_set_t *) libcesque paramsnonnull();
int pthread_setschedparam(pthread_t, int, const struct sched_param *) libcesque paramsnonnull();
int pthread_timedjoin_np(pthread_t, void **, struct timespec *) libcesque;

/* clang-format off */
COSMOPOLITAN_C_END_
/* clang-format on */


/*!BEGIN libc/thread/threads.h */

#define COSMOPOLITAN_LIBC_THREAD_THREADS_H_
COSMOPOLITAN_C_START_

#if !defined(__cplusplus) &&                   \
    (!(defined(__GNUC__) && __GNUC__ >= 13) || \
     !(defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L))
#define thread_local _Thread_local
#endif

#define TSS_DTOR_ITERATIONS 4

enum {
  thrd_success = 0,
  thrd_busy = 1,
  thrd_error = 2,
  thrd_nomem = 3,
  thrd_timedout = 4,
};

enum {
  mtx_plain = 0,
  mtx_recursive = 1,
  mtx_timed = 2,
};

typedef uintptr_t thrd_t;
typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *);
typedef _Atomic(uint32_t) once_flag;

void call_once(once_flag *, void (*)(void));
int thrd_create(thrd_t *, thrd_start_t, void *);
void thrd_exit(int) wontreturn;
int thrd_join(thrd_t, int *);
int thrd_detach(thrd_t);
int thrd_equal(thrd_t, thrd_t);
thrd_t thrd_current(void);
void thrd_yield(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/tls.h */

#define COSMOPOLITAN_LIBC_THREAD_TLS_H_

#define TLS_ALIGNMENT 64

#define TIB_FLAG_VFORKED 1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct CosmoFtrace {   /* 16 */
  char ft_once;        /*  0 */
  char ft_noreentry;   /*  1 */
  int ft_skew;         /*  4 */
  int64_t ft_lastaddr; /*  8 */
};

/* NOTE: update aarch64 libc/errno.h if sizeof changes */
/* NOTE: update aarch64 libc/proc/vfork.S if sizeof changes */
/* NOTE: update aarch64 libc/nexgen32e/gc.S if sizeof changes */
struct CosmoTib {
  struct CosmoTib *tib_self;      /* 0x00 */
  struct CosmoFtrace tib_ftracer; /* 0x08 */
  void *tib_garbages;             /* 0x18 */
  intptr_t tib_locale;            /* 0x20 */
  intptr_t tib_pthread;           /* 0x28 */
  struct CosmoTib *tib_self2;     /* 0x30 */
  _Atomic(int32_t) tib_tid;       /* 0x38 transitions -1 → tid → 0 */
  int32_t tib_errno;              /* 0x3c */
  uint64_t tib_flags;             /* 0x40 */
  int tib_ftrace;                 /* inherited */
  int tib_strace;                 /* inherited */
  _Atomic(uint64_t) tib_sigmask;  /* inherited */
  _Atomic(uint64_t) tib_sigpending;
  _Atomic(uint64_t) tib_syshand; /* win32=kThread, xnusilicon=pthread_t */
  char *tib_sigstack_addr;
  uint32_t tib_sigstack_size;
  uint32_t tib_sigstack_flags;
  void **tib_keys;
  void *tib_nsync;
  void *tib_todo[7];
} __attribute__((__aligned__(64)));

extern int __threaded;
extern char __tls_morphed;
extern unsigned __tls_index;

char *_mktls(struct CosmoTib **) libcesque;
void __bootstrap_tls(struct CosmoTib *, char *) libcesque;

#ifdef __x86_64__
extern char __tls_enabled;
#define __tls_enabled_set(x) __tls_enabled = x
#elif defined(__aarch64__)
#define __tls_enabled        true
#define __tls_enabled_set(x) (void)0
#else
#error "unsupported architecture"
#endif

void __set_tls(struct CosmoTib *) libcesque;

/**
 * Returns location of thread information block.
 *
 * This can't be used in privileged functions.
 */
forceinline pureconst struct CosmoTib *__get_tls(void) {
#ifdef __chibicc__
  return 0;
#elif __x86_64__
  struct CosmoTib *__tib;
  __asm__("mov\t%%gs:0x30,%0" : "=r"(__tib));
  return __tib;
#elif defined(__aarch64__)
  register struct CosmoTib *__tls __asm__("x28");
  return __tls - 1;
#endif
}

#ifdef __x86_64__
#define __adj_tls(tib) (tib)
#elif defined(__aarch64__)
#define __adj_tls(tib) ((struct CosmoTib *)(tib) + 1)
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/tinymath/emod.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMOD_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmod()
 */
#define emod(x, y)                            \
  ({                                          \
    double __x = x;                           \
    double __y = y;                           \
    __x - fabs(__y) * floor(__x / fabs(__y)); \
  })



/*!BEGIN libc/tinymath/emodl.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmodl()
 */
#define emodl(x, y)                              \
  ({                                             \
    long double __x = x;                         \
    long double __y = y;                         \
    __x - fabsl(__y) * floorl(__x / fabsl(__y)); \
  })



/*!BEGIN libc/tinymath/magicu.h */

#define COSMOPOLITAN_LIBC_TINYMATH_MAGICU_H_
COSMOPOLITAN_C_START_

struct magicu {
  uint32_t M;
  uint32_t s;
};

struct magicu __magicu_get(uint32_t);

/**
 * Performs fast division using precomputed magic for constant divisor.
 *
 * @param x is unsigned integer that shall be divided
 * @param d should be `__magicu_get(y)` if computing `x / y`
 * @return result of unsigned integer division
 */
forceinline uint32_t __magicu_div(uint32_t x, struct magicu d) {
  return ((((uint64_t)x * d.M) >> 32) + ((d.s & 64) ? x : 0)) >> (d.s & 63);
}

/**
 * Checks if 𝑑 contains a valid initialized divisor.
 */
static inline bool32 __magicu_valid(struct magicu d) {
  if (!d.M && !d.s) return false;     /* uninitialized */
  if (d.s & ~(64 | 63)) return false; /* corrupted */
  return true;
}

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/x.h */

#ifndef COSMOPOLITAN_LIBC_X_H_
#define COSMOPOLITAN_LIBC_X_H_

#define xwrite        __xwrite
#define xdie          __xdie
#define xmalloc       __xmalloc
#define xrealloc      __xrealloc
#define xcalloc       __xcalloc
#define xvalloc       __xvalloc
#define xmemalign     __xmemalign
#define xmemalignzero __xmemalignzero
#define xstrdup       __xstrdup
#define xstrndup      __xstrndup
#define xstrmul       __xstrmul
#define xinet_ntop    __xinet_ntop
#define xunbinga      __xunbinga
#define xunbing       __xunbing
#define utf8to16      __utf8to16
#define utf16to8      __utf16to8
#define utf8to32      __utf8to32
#define utf16to32     __utf16to32
#define utf32to8      __utf32to8
#define xhomedir      __xhomedir
#define xstripext     __xstripext
#define xstripexts    __xstripexts
#define xload         __xload
#define rmrf          __rmrf
#define xbasename     __xbasename
#define xdirname      __xdirname
#define xjoinpaths    __xjoinpaths
#define xfixpath      __xfixpath
#define xslurp        __xslurp
#define xbarf         __xbarf

COSMOPOLITAN_C_START_

int xwrite(int, const void *, uint64_t);
void xdie(void) wontreturn;
char *xdtoa(double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoaf(float)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoal(long double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmalloc(size_t) attributeallocsize((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xrealloc(void *, size_t)
    attributeallocsize((2)) dontthrow dontcallback __wur;
void *xcalloc(size_t, size_t) attributeallocsize((1, 2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xvalloc(size_t) attributeallocsize((1)) returnsaligned((65536))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalign(size_t, size_t) attributeallocalign((1)) attributeallocsize((2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalignzero(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2))
        returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrdup(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrndup(const char *, size_t) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrcat(const char *, ...) paramsnonnull((1)) nullterminated()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
#define xstrcat(...) (xstrcat)(__VA_ARGS__, NULL)
char *xstrmul(const char *, size_t) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xinet_ntop(int, const void *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xunbinga(size_t, const char16_t *)
    attributeallocalign((1)) returnspointerwithnoaliases dontthrow dontcallback
    __wur returnsnonnull dontthrow dontcallback __wur returnsnonnull;
void *xunbing(const char16_t *)
    returnspointerwithnoaliases dontthrow dontcallback __wur
    returnsnonnull dontthrow dontcallback __wur returnsnonnull;
char16_t *utf8to16(const char *, size_t, size_t *) __wur;
char *utf16to8(const char16_t *, size_t, size_t *) __wur;
wchar_t *utf8to32(const char *, size_t, size_t *) __wur;
wchar_t *utf16to32(const char16_t *, size_t, size_t *) __wur;
char *utf32to8(const wchar_t *, size_t, size_t *) __wur;
char *xhomedir(void) __wur;
char *xstripext(const char *) __wur;
char *xstripexts(const char *) __wur;
void *xload(_Atomic(void *) *, const void *, size_t, size_t);
int rmrf(const char *);
char *xbasename(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdirname(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xjoinpaths(const char *, const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void xfixpath(void);
void *xslurp(const char *, size_t *)
    paramsnonnull((1)) returnspointerwithnoaliases returnsaligned((4096)) __wur;
int xbarf(const char *, const void *, size_t);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_X_H_ */


/*!BEGIN libc/x/xasprintf.h */

#define COSMOPOLITAN_LIBC_X_XASPRINTF_H_
COSMOPOLITAN_C_START_

char *xasprintf(const char *, ...) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xvasprintf(const char *, va_list) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xgetline.h */

#define COSMOPOLITAN_LIBC_X_XGETLINE_H_
COSMOPOLITAN_C_START_

char *xgetline(FILE *) paramsnonnull() mallocesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xsigaction.h */

#define COSMOPOLITAN_LIBC_X_XSIGACTION_H_
COSMOPOLITAN_C_START_

int xsigaction(int, void *, uint64_t, uint64_t, struct sigaction *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xspawn.h */

#define COSMOPOLITAN_LIBC_X_XSPAWN_H_
COSMOPOLITAN_C_START_

int xspawn(struct rusage *);
int xvspawn(void (*)(void *), void *, struct rusage *) returnstwice;

COSMOPOLITAN_C_END_


/*!BEGIN net/http/csscolor.h */

#define COSMOPOLITAN_NET_HTTP_CSSCOLOR_H_

#define ALICEBLUE            0xFFFFF8F0u
#define ANTIQUEWHITE         0xFFD7EBFAu
#define ANTIQUEWHITE1        0xFFDBEFFFu
#define ANTIQUEWHITE2        0xFFCCDFEEu
#define ANTIQUEWHITE3        0xFFB0C0CDu
#define ANTIQUEWHITE4        0xFF78838Bu
#define AQUAMARINE           0xFFD4FF7Fu
#define AQUAMARINE1          0xFFD4FF7Fu
#define AQUAMARINE2          0xFFC6EE76u
#define AQUAMARINE3          0xFFAACD66u
#define AQUAMARINE4          0xFF748B45u
#define AZURE                0xFFFFFFF0u
#define AZURE1               0xFFFFFFF0u
#define AZURE2               0xFFEEEEE0u
#define AZURE3               0xFFCDCDC1u
#define AZURE4               0xFF8B8B83u
#define BEIGE                0xFFDCF5F5u
#define BISQUE               0xFFC4E4FFu
#define BISQUE1              0xFFC4E4FFu
#define BISQUE2              0xFFB7D5EEu
#define BISQUE3              0xFF9EB7CDu
#define BISQUE4              0xFF6B7D8Bu
#define BLACK                0xFF000000u
#define BLANCHEDALMOND       0xFFCDEBFFu
#define BLUE                 0xFFFF0000u
#define BLUE1                0xFFFF0000u
#define BLUE2                0xFFEE0000u
#define BLUE3                0xFFCD0000u
#define BLUE4                0xFF8B0000u
#define BLUEVIOLET           0xFFE22B8Au
#define BROWN                0xFF2A2AA5u
#define BROWN1               0xFF4040FFu
#define BROWN2               0xFF3B3BEEu
#define BROWN3               0xFF3333CDu
#define BROWN4               0xFF23238Bu
#define BURLYWOOD            0xFF87B8DEu
#define BURLYWOOD1           0xFF9BD3FFu
#define BURLYWOOD2           0xFF91C5EEu
#define BURLYWOOD3           0xFF7DAACDu
#define BURLYWOOD4           0xFF55738Bu
#define CADETBLUE            0xFFA09E5Fu
#define CADETBLUE1           0xFFFFF598u
#define CADETBLUE2           0xFFEEE58Eu
#define CADETBLUE3           0xFFCDC57Au
#define CADETBLUE4           0xFF8B8653u
#define CHARTREUSE           0xFF00FF7Fu
#define CHARTREUSE1          0xFF00FF7Fu
#define CHARTREUSE2          0xFF00EE76u
#define CHARTREUSE3          0xFF00CD66u
#define CHARTREUSE4          0xFF008B45u
#define CHOCOLATE            0xFF1E69D2u
#define CHOCOLATE1           0xFF247FFFu
#define CHOCOLATE2           0xFF2176EEu
#define CHOCOLATE3           0xFF1D66CDu
#define CHOCOLATE4           0xFF13458Bu
#define CORAL                0xFF507FFFu
#define CORAL1               0xFF5672FFu
#define CORAL2               0xFF506AEEu
#define CORAL3               0xFF455BCDu
#define CORAL4               0xFF2F3E8Bu
#define CORNFLOWERBLUE       0xFFED9564u
#define CORNSILK             0xFFDCF8FFu
#define CORNSILK1            0xFFDCF8FFu
#define CORNSILK2            0xFFCDE8EEu
#define CORNSILK3            0xFFB1C8CDu
#define CORNSILK4            0xFF78888Bu
#define CYAN                 0xFFFFFF00u
#define CYAN1                0xFFFFFF00u
#define CYAN2                0xFFEEEE00u
#define CYAN3                0xFFCDCD00u
#define CYAN4                0xFF8B8B00u
#define DARKBLUE             0xFF8B0000u
#define DARKCYAN             0xFF8B8B00u
#define DARKGOLDENROD        0xFF0B86B8u
#define DARKGOLDENROD1       0xFF0FB9FFu
#define DARKGOLDENROD2       0xFF0EADEEu
#define DARKGOLDENROD3       0xFF0C95CDu
#define DARKGOLDENROD4       0xFF08658Bu
#define DARKGRAY             0xFFA9A9A9u
#define DARKGREEN            0xFF006400u
#define DARKGREY             0xFFA9A9A9u
#define DARKKHAKI            0xFF6BB7BDu
#define DARKMAGENTA          0xFF8B008Bu
#define DARKOLIVEGREEN       0xFF2F6B55u
#define DARKOLIVEGREEN1      0xFF70FFCAu
#define DARKOLIVEGREEN2      0xFF68EEBCu
#define DARKOLIVEGREEN3      0xFF5ACDA2u
#define DARKOLIVEGREEN4      0xFF3D8B6Eu
#define DARKORANGE           0xFF008CFFu
#define DARKORANGE1          0xFF007FFFu
#define DARKORANGE2          0xFF0076EEu
#define DARKORANGE3          0xFF0066CDu
#define DARKORANGE4          0xFF00458Bu
#define DARKORCHID           0xFFCC3299u
#define DARKORCHID1          0xFFFF3EBFu
#define DARKORCHID2          0xFFEE3AB2u
#define DARKORCHID3          0xFFCD329Au
#define DARKORCHID4          0xFF8B2268u
#define DARKRED              0xFF00008Bu
#define DARKSALMON           0xFF7A96E9u
#define DARKSEAGREEN         0xFF8FBC8Fu
#define DARKSEAGREEN1        0xFFC1FFC1u
#define DARKSEAGREEN2        0xFFB4EEB4u
#define DARKSEAGREEN3        0xFF9BCD9Bu
#define DARKSEAGREEN4        0xFF698B69u
#define DARKSLATEBLUE        0xFF8B3D48u
#define DARKSLATEGRAY        0xFF4F4F2Fu
#define DARKSLATEGRAY1       0xFFFFFF97u
#define DARKSLATEGRAY2       0xFFEEEE8Du
#define DARKSLATEGRAY3       0xFFCDCD79u
#define DARKSLATEGRAY4       0xFF8B8B52u
#define DARKSLATEGREY        0xFF4F4F2Fu
#define DARKTURQUOISE        0xFFD1CE00u
#define DARKVIOLET           0xFFD30094u
#define DEEPPINK             0xFF9314FFu
#define DEEPPINK1            0xFF9314FFu
#define DEEPPINK2            0xFF8912EEu
#define DEEPPINK3            0xFF7610CDu
#define DEEPPINK4            0xFF500A8Bu
#define DEEPSKYBLUE          0xFFFFBF00u
#define DEEPSKYBLUE1         0xFFFFBF00u
#define DEEPSKYBLUE2         0xFFEEB200u
#define DEEPSKYBLUE3         0xFFCD9A00u
#define DEEPSKYBLUE4         0xFF8B6800u
#define DIMGRAY              0xFF696969u
#define DIMGREY              0xFF696969u
#define DODGERBLUE           0xFFFF901Eu
#define DODGERBLUE1          0xFFFF901Eu
#define DODGERBLUE2          0xFFEE861Cu
#define DODGERBLUE3          0xFFCD7418u
#define DODGERBLUE4          0xFF8B4E10u
#define FIREBRICK            0xFF2222B2u
#define FIREBRICK1           0xFF3030FFu
#define FIREBRICK2           0xFF2C2CEEu
#define FIREBRICK3           0xFF2626CDu
#define FIREBRICK4           0xFF1A1A8Bu
#define FLORALWHITE          0xFFF0FAFFu
#define FORESTGREEN          0xFF228B22u
#define GAINSBORO            0xFFDCDCDCu
#define GHOSTWHITE           0xFFFFF8F8u
#define GOLD                 0xFF00D7FFu
#define GOLD1                0xFF00D7FFu
#define GOLD2                0xFF00C9EEu
#define GOLD3                0xFF00ADCDu
#define GOLD4                0xFF00758Bu
#define GOLDENROD            0xFF20A5DAu
#define GOLDENROD1           0xFF25C1FFu
#define GOLDENROD2           0xFF22B4EEu
#define GOLDENROD3           0xFF1D9BCDu
#define GOLDENROD4           0xFF14698Bu
#define GRAY                 0xFFBEBEBEu
#define GRAY0                0xFF000000u
#define GRAY1                0xFF030303u
#define GRAY10               0xFF1A1A1Au
#define GRAY100              0xFFFFFFFFu
#define GRAY11               0xFF1C1C1Cu
#define GRAY12               0xFF1F1F1Fu
#define GRAY13               0xFF212121u
#define GRAY14               0xFF242424u
#define GRAY15               0xFF262626u
#define GRAY16               0xFF292929u
#define GRAY17               0xFF2B2B2Bu
#define GRAY18               0xFF2E2E2Eu
#define GRAY19               0xFF303030u
#define GRAY2                0xFF050505u
#define GRAY20               0xFF333333u
#define GRAY21               0xFF363636u
#define GRAY22               0xFF383838u
#define GRAY23               0xFF3B3B3Bu
#define GRAY24               0xFF3D3D3Du
#define GRAY25               0xFF404040u
#define GRAY26               0xFF424242u
#define GRAY27               0xFF454545u
#define GRAY28               0xFF474747u
#define GRAY29               0xFF4A4A4Au
#define GRAY3                0xFF080808u
#define GRAY30               0xFF4D4D4Du
#define GRAY31               0xFF4F4F4Fu
#define GRAY32               0xFF525252u
#define GRAY33               0xFF545454u
#define GRAY34               0xFF575757u
#define GRAY35               0xFF595959u
#define GRAY36               0xFF5C5C5Cu
#define GRAY37               0xFF5E5E5Eu
#define GRAY38               0xFF616161u
#define GRAY39               0xFF636363u
#define GRAY4                0xFF0A0A0Au
#define GRAY40               0xFF666666u
#define GRAY41               0xFF696969u
#define GRAY42               0xFF6B6B6Bu
#define GRAY43               0xFF6E6E6Eu
#define GRAY44               0xFF707070u
#define GRAY45               0xFF737373u
#define GRAY46               0xFF757575u
#define GRAY47               0xFF787878u
#define GRAY48               0xFF7A7A7Au
#define GRAY49               0xFF7D7D7Du
#define GRAY5                0xFF0D0D0Du
#define GRAY50               0xFF7F7F7Fu
#define GRAY51               0xFF828282u
#define GRAY52               0xFF858585u
#define GRAY53               0xFF878787u
#define GRAY54               0xFF8A8A8Au
#define GRAY55               0xFF8C8C8Cu
#define GRAY56               0xFF8F8F8Fu
#define GRAY57               0xFF919191u
#define GRAY58               0xFF949494u
#define GRAY59               0xFF969696u
#define GRAY6                0xFF0F0F0Fu
#define GRAY60               0xFF999999u
#define GRAY61               0xFF9C9C9Cu
#define GRAY62               0xFF9E9E9Eu
#define GRAY63               0xFFA1A1A1u
#define GRAY64               0xFFA3A3A3u
#define GRAY65               0xFFA6A6A6u
#define GRAY66               0xFFA8A8A8u
#define GRAY67               0xFFABABABu
#define GRAY68               0xFFADADADu
#define GRAY69               0xFFB0B0B0u
#define GRAY7                0xFF121212u
#define GRAY70               0xFFB3B3B3u
#define GRAY71               0xFFB5B5B5u
#define GRAY72               0xFFB8B8B8u
#define GRAY73               0xFFBABABAu
#define GRAY74               0xFFBDBDBDu
#define GRAY75               0xFFBFBFBFu
#define GRAY76               0xFFC2C2C2u
#define GRAY77               0xFFC4C4C4u
#define GRAY78               0xFFC7C7C7u
#define GRAY79               0xFFC9C9C9u
#define GRAY8                0xFF141414u
#define GRAY80               0xFFCCCCCCu
#define GRAY81               0xFFCFCFCFu
#define GRAY82               0xFFD1D1D1u
#define GRAY83               0xFFD4D4D4u
#define GRAY84               0xFFD6D6D6u
#define GRAY85               0xFFD9D9D9u
#define GRAY86               0xFFDBDBDBu
#define GRAY87               0xFFDEDEDEu
#define GRAY88               0xFFE0E0E0u
#define GRAY89               0xFFE3E3E3u
#define GRAY9                0xFF171717u
#define GRAY90               0xFFE5E5E5u
#define GRAY91               0xFFE8E8E8u
#define GRAY92               0xFFEBEBEBu
#define GRAY93               0xFFEDEDEDu
#define GRAY94               0xFFF0F0F0u
#define GRAY95               0xFFF2F2F2u
#define GRAY96               0xFFF5F5F5u
#define GRAY97               0xFFF7F7F7u
#define GRAY98               0xFFFAFAFAu
#define GRAY99               0xFFFCFCFCu
#define GREEN                0xFF00FF00u
#define GREEN1               0xFF00FF00u
#define GREEN2               0xFF00EE00u
#define GREEN3               0xFF00CD00u
#define GREEN4               0xFF008B00u
#define GREENYELLOW          0xFF2FFFADu
#define GREY                 0xFFBEBEBEu
#define GREY0                0xFF000000u
#define GREY1                0xFF030303u
#define GREY10               0xFF1A1A1Au
#define GREY100              0xFFFFFFFFu
#define GREY11               0xFF1C1C1Cu
#define GREY12               0xFF1F1F1Fu
#define GREY13               0xFF212121u
#define GREY14               0xFF242424u
#define GREY15               0xFF262626u
#define GREY16               0xFF292929u
#define GREY17               0xFF2B2B2Bu
#define GREY18               0xFF2E2E2Eu
#define GREY19               0xFF303030u
#define GREY2                0xFF050505u
#define GREY20               0xFF333333u
#define GREY21               0xFF363636u
#define GREY22               0xFF383838u
#define GREY23               0xFF3B3B3Bu
#define GREY24               0xFF3D3D3Du
#define GREY25               0xFF404040u
#define GREY26               0xFF424242u
#define GREY27               0xFF454545u
#define GREY28               0xFF474747u
#define GREY29               0xFF4A4A4Au
#define GREY3                0xFF080808u
#define GREY30               0xFF4D4D4Du
#define GREY31               0xFF4F4F4Fu
#define GREY32               0xFF525252u
#define GREY33               0xFF545454u
#define GREY34               0xFF575757u
#define GREY35               0xFF595959u
#define GREY36               0xFF5C5C5Cu
#define GREY37               0xFF5E5E5Eu
#define GREY38               0xFF616161u
#define GREY39               0xFF636363u
#define GREY4                0xFF0A0A0Au
#define GREY40               0xFF666666u
#define GREY41               0xFF696969u
#define GREY42               0xFF6B6B6Bu
#define GREY43               0xFF6E6E6Eu
#define GREY44               0xFF707070u
#define GREY45               0xFF737373u
#define GREY46               0xFF757575u
#define GREY47               0xFF787878u
#define GREY48               0xFF7A7A7Au
#define GREY49               0xFF7D7D7Du
#define GREY5                0xFF0D0D0Du
#define GREY50               0xFF7F7F7Fu
#define GREY51               0xFF828282u
#define GREY52               0xFF858585u
#define GREY53               0xFF878787u
#define GREY54               0xFF8A8A8Au
#define GREY55               0xFF8C8C8Cu
#define GREY56               0xFF8F8F8Fu
#define GREY57               0xFF919191u
#define GREY58               0xFF949494u
#define GREY59               0xFF969696u
#define GREY6                0xFF0F0F0Fu
#define GREY60               0xFF999999u
#define GREY61               0xFF9C9C9Cu
#define GREY62               0xFF9E9E9Eu
#define GREY63               0xFFA1A1A1u
#define GREY64               0xFFA3A3A3u
#define GREY65               0xFFA6A6A6u
#define GREY66               0xFFA8A8A8u
#define GREY67               0xFFABABABu
#define GREY68               0xFFADADADu
#define GREY69               0xFFB0B0B0u
#define GREY7                0xFF121212u
#define GREY70               0xFFB3B3B3u
#define GREY71               0xFFB5B5B5u
#define GREY72               0xFFB8B8B8u
#define GREY73               0xFFBABABAu
#define GREY74               0xFFBDBDBDu
#define GREY75               0xFFBFBFBFu
#define GREY76               0xFFC2C2C2u
#define GREY77               0xFFC4C4C4u
#define GREY78               0xFFC7C7C7u
#define GREY79               0xFFC9C9C9u
#define GREY8                0xFF141414u
#define GREY80               0xFFCCCCCCu
#define GREY81               0xFFCFCFCFu
#define GREY82               0xFFD1D1D1u
#define GREY83               0xFFD4D4D4u
#define GREY84               0xFFD6D6D6u
#define GREY85               0xFFD9D9D9u
#define GREY86               0xFFDBDBDBu
#define GREY87               0xFFDEDEDEu
#define GREY88               0xFFE0E0E0u
#define GREY89               0xFFE3E3E3u
#define GREY9                0xFF171717u
#define GREY90               0xFFE5E5E5u
#define GREY91               0xFFE8E8E8u
#define GREY92               0xFFEBEBEBu
#define GREY93               0xFFEDEDEDu
#define GREY94               0xFFF0F0F0u
#define GREY95               0xFFF2F2F2u
#define GREY96               0xFFF5F5F5u
#define GREY97               0xFFF7F7F7u
#define GREY98               0xFFFAFAFAu
#define GREY99               0xFFFCFCFCu
#define HONEYDEW             0xFFF0FFF0u
#define HONEYDEW1            0xFFF0FFF0u
#define HONEYDEW2            0xFFE0EEE0u
#define HONEYDEW3            0xFFC1CDC1u
#define HONEYDEW4            0xFF838B83u
#define HOTPINK              0xFFB469FFu
#define HOTPINK1             0xFFB46EFFu
#define HOTPINK2             0xFFA76AEEu
#define HOTPINK3             0xFF9060CDu
#define HOTPINK4             0xFF623A8Bu
#define INDIANRED            0xFF5C5CCDu
#define INDIANRED1           0xFF6A6AFFu
#define INDIANRED2           0xFF6363EEu
#define INDIANRED3           0xFF5555CDu
#define INDIANRED4           0xFF3A3A8Bu
#define IVORY                0xFFF0FFFFu
#define IVORY1               0xFFF0FFFFu
#define IVORY2               0xFFE0EEEEu
#define IVORY3               0xFFC1CDCDu
#define IVORY4               0xFF838B8Bu
#define KHAKI                0xFF8CE6F0u
#define KHAKI1               0xFF8FF6FFu
#define KHAKI2               0xFF85E6EEu
#define KHAKI3               0xFF73C6CDu
#define KHAKI4               0xFF4E868Bu
#define LAVENDER             0xFFFAE6E6u
#define LAVENDERBLUSH        0xFFF5F0FFu
#define LAVENDERBLUSH1       0xFFF5F0FFu
#define LAVENDERBLUSH2       0xFFE5E0EEu
#define LAVENDERBLUSH3       0xFFC5C1CDu
#define LAVENDERBLUSH4       0xFF86838Bu
#define LAWNGREEN            0xFF00FC7Cu
#define LEMONCHIFFON         0xFFCDFAFFu
#define LEMONCHIFFON1        0xFFCDFAFFu
#define LEMONCHIFFON2        0xFFBFE9EEu
#define LEMONCHIFFON3        0xFFA5C9CDu
#define LEMONCHIFFON4        0xFF70898Bu
#define LIGHTBLUE            0xFFE6D8ADu
#define LIGHTBLUE1           0xFFFFEFBFu
#define LIGHTBLUE2           0xFFEEDFB2u
#define LIGHTBLUE3           0xFFCDC09Au
#define LIGHTBLUE4           0xFF8B8368u
#define LIGHTCORAL           0xFF8080F0u
#define LIGHTCYAN            0xFFFFFFE0u
#define LIGHTCYAN1           0xFFFFFFE0u
#define LIGHTCYAN2           0xFFEEEED1u
#define LIGHTCYAN3           0xFFCDCDB4u
#define LIGHTCYAN4           0xFF8B8B7Au
#define LIGHTGOLDENROD       0xFF82DDEEu
#define LIGHTGOLDENROD1      0xFF8BECFFu
#define LIGHTGOLDENROD2      0xFF82DCEEu
#define LIGHTGOLDENROD3      0xFF70BECDu
#define LIGHTGOLDENROD4      0xFF4C818Bu
#define LIGHTGOLDENRODYELLOW 0xFFD2FAFAu
#define LIGHTGRAY            0xFFD3D3D3u
#define LIGHTGREEN           0xFF90EE90u
#define LIGHTGREY            0xFFD3D3D3u
#define LIGHTPINK            0xFFC1B6FFu
#define LIGHTPINK1           0xFFB9AEFFu
#define LIGHTPINK2           0xFFADA2EEu
#define LIGHTPINK3           0xFF958CCDu
#define LIGHTPINK4           0xFF655F8Bu
#define LIGHTSALMON          0xFF7AA0FFu
#define LIGHTSALMON1         0xFF7AA0FFu
#define LIGHTSALMON2         0xFF7295EEu
#define LIGHTSALMON3         0xFF6281CDu
#define LIGHTSALMON4         0xFF42578Bu
#define LIGHTSEAGREEN        0xFFAAB220u
#define LIGHTSKYBLUE         0xFFFACE87u
#define LIGHTSKYBLUE1        0xFFFFE2B0u
#define LIGHTSKYBLUE2        0xFFEED3A4u
#define LIGHTSKYBLUE3        0xFFCDB68Du
#define LIGHTSKYBLUE4        0xFF8B7B60u
#define LIGHTSLATEBLUE       0xFFFF7084u
#define LIGHTSLATEGRAY       0xFF998877u
#define LIGHTSLATEGREY       0xFF998877u
#define LIGHTSTEELBLUE       0xFFDEC4B0u
#define LIGHTSTEELBLUE1      0xFFFFE1CAu
#define LIGHTSTEELBLUE2      0xFFEED2BCu
#define LIGHTSTEELBLUE3      0xFFCDB5A2u
#define LIGHTSTEELBLUE4      0xFF8B7B6Eu
#define LIGHTYELLOW          0xFFE0FFFFu
#define LIGHTYELLOW1         0xFFE0FFFFu
#define LIGHTYELLOW2         0xFFD1EEEEu
#define LIGHTYELLOW3         0xFFB4CDCDu
#define LIGHTYELLOW4         0xFF7A8B8Bu
#define LIMEGREEN            0xFF32CD32u
#define LINEN                0xFFE6F0FAu
#define MAGENTA              0xFFFF00FFu
#define MAGENTA1             0xFFFF00FFu
#define MAGENTA2             0xFFEE00EEu
#define MAGENTA3             0xFFCD00CDu
#define MAGENTA4             0xFF8B008Bu
#define MAROON               0xFF6030B0u
#define MAROON1              0xFFB334FFu
#define MAROON2              0xFFA730EEu
#define MAROON3              0xFF9029CDu
#define MAROON4              0xFF621C8Bu
#define MEDIUMAQUAMARINE     0xFFAACD66u
#define MEDIUMBLUE           0xFFCD0000u
#define MEDIUMORCHID         0xFFD355BAu
#define MEDIUMORCHID1        0xFFFF66E0u
#define MEDIUMORCHID2        0xFFEE5FD1u
#define MEDIUMORCHID3        0xFFCD52B4u
#define MEDIUMORCHID4        0xFF8B377Au
#define MEDIUMPURPLE         0xFFDB7093u
#define MEDIUMPURPLE1        0xFFFF82ABu
#define MEDIUMPURPLE2        0xFFEE799Fu
#define MEDIUMPURPLE3        0xFFCD6889u
#define MEDIUMPURPLE4        0xFF8B475Du
#define MEDIUMSEAGREEN       0xFF71B33Cu
#define MEDIUMSLATEBLUE      0xFFEE687Bu
#define MEDIUMSPRINGGREEN    0xFF9AFA00u
#define MEDIUMTURQUOISE      0xFFCCD148u
#define MEDIUMVIOLETRED      0xFF8515C7u
#define MIDNIGHTBLUE         0xFF701919u
#define MINTCREAM            0xFFFAFFF5u
#define MISTYROSE            0xFFE1E4FFu
#define MISTYROSE1           0xFFE1E4FFu
#define MISTYROSE2           0xFFD2D5EEu
#define MISTYROSE3           0xFFB5B7CDu
#define MISTYROSE4           0xFF7B7D8Bu
#define MOCCASIN             0xFFB5E4FFu
#define NAVAJOWHITE          0xFFADDEFFu
#define NAVAJOWHITE1         0xFFADDEFFu
#define NAVAJOWHITE2         0xFFA1CFEEu
#define NAVAJOWHITE3         0xFF8BB3CDu
#define NAVAJOWHITE4         0xFF5E798Bu
#define NAVY                 0xFF800000u
#define NAVYBLUE             0xFF800000u
#define OLDLACE              0xFFE6F5FDu
#define OLIVEDRAB            0xFF238E6Bu
#define OLIVEDRAB1           0xFF3EFFC0u
#define OLIVEDRAB2           0xFF3AEEB3u
#define OLIVEDRAB3           0xFF32CD9Au
#define OLIVEDRAB4           0xFF228B69u
#define ORANGE               0xFF00A5FFu
#define ORANGE1              0xFF00A5FFu
#define ORANGE2              0xFF009AEEu
#define ORANGE3              0xFF0085CDu
#define ORANGE4              0xFF005A8Bu
#define ORANGERED            0xFF0045FFu
#define ORANGERED1           0xFF0045FFu
#define ORANGERED2           0xFF0040EEu
#define ORANGERED3           0xFF0037CDu
#define ORANGERED4           0xFF00258Bu
#define ORCHID               0xFFD670DAu
#define ORCHID1              0xFFFA83FFu
#define ORCHID2              0xFFE97AEEu
#define ORCHID3              0xFFC969CDu
#define ORCHID4              0xFF89478Bu
#define PALEGOLDENROD        0xFFAAE8EEu
#define PALEGREEN            0xFF98FB98u
#define PALEGREEN1           0xFF9AFF9Au
#define PALEGREEN2           0xFF90EE90u
#define PALEGREEN3           0xFF7CCD7Cu
#define PALEGREEN4           0xFF548B54u
#define PALETURQUOISE        0xFFEEEEAFu
#define PALETURQUOISE1       0xFFFFFFBBu
#define PALETURQUOISE2       0xFFEEEEAEu
#define PALETURQUOISE3       0xFFCDCD96u
#define PALETURQUOISE4       0xFF8B8B66u
#define PALEVIOLETRED        0xFF9370DBu
#define PALEVIOLETRED1       0xFFAB82FFu
#define PALEVIOLETRED2       0xFF9F79EEu
#define PALEVIOLETRED3       0xFF8968CDu
#define PALEVIOLETRED4       0xFF5D478Bu
#define PAPAYAWHIP           0xFFD5EFFFu
#define PEACHPUFF            0xFFB9DAFFu
#define PEACHPUFF1           0xFFB9DAFFu
#define PEACHPUFF2           0xFFADCBEEu
#define PEACHPUFF3           0xFF95AFCDu
#define PEACHPUFF4           0xFF65778Bu
#define PERU                 0xFF3F85CDu
#define PINK                 0xFFCBC0FFu
#define PINK1                0xFFC5B5FFu
#define PINK2                0xFFB8A9EEu
#define PINK3                0xFF9E91CDu
#define PINK4                0xFF6C638Bu
#define PLUM                 0xFFDDA0DDu
#define PLUM1                0xFFFFBBFFu
#define PLUM2                0xFFEEAEEEu
#define PLUM3                0xFFCD96CDu
#define PLUM4                0xFF8B668Bu
#define POWDERBLUE           0xFFE6E0B0u
#define PURPLE               0xFFF020A0u
#define PURPLE1              0xFFFF309Bu
#define PURPLE2              0xFFEE2C91u
#define PURPLE3              0xFFCD267Du
#define PURPLE4              0xFF8B1A55u
#define RED                  0xFF0000FFu
#define RED1                 0xFF0000FFu
#define RED2                 0xFF0000EEu
#define RED3                 0xFF0000CDu
#define RED4                 0xFF00008Bu
#define ROSYBROWN            0xFF8F8FBCu
#define ROSYBROWN1           0xFFC1C1FFu
#define ROSYBROWN2           0xFFB4B4EEu
#define ROSYBROWN3           0xFF9B9BCDu
#define ROSYBROWN4           0xFF69698Bu
#define ROYALBLUE            0xFFE16941u
#define ROYALBLUE1           0xFFFF7648u
#define ROYALBLUE2           0xFFEE6E43u
#define ROYALBLUE3           0xFFCD5F3Au
#define ROYALBLUE4           0xFF8B4027u
#define SADDLEBROWN          0xFF13458Bu
#define SALMON               0xFF7280FAu
#define SALMON1              0xFF698CFFu
#define SALMON2              0xFF6282EEu
#define SALMON3              0xFF5470CDu
#define SALMON4              0xFF394C8Bu
#define SANDYBROWN           0xFF60A4F4u
#define SEAGREEN             0xFF578B2Eu
#define SEAGREEN1            0xFF9FFF54u
#define SEAGREEN2            0xFF94EE4Eu
#define SEAGREEN3            0xFF80CD43u
#define SEAGREEN4            0xFF578B2Eu
#define SEASHELL             0xFFEEF5FFu
#define SEASHELL1            0xFFEEF5FFu
#define SEASHELL2            0xFFDEE5EEu
#define SEASHELL3            0xFFBFC5CDu
#define SEASHELL4            0xFF82868Bu
#define SIENNA               0xFF2D52A0u
#define SIENNA1              0xFF4782FFu
#define SIENNA2              0xFF4279EEu
#define SIENNA3              0xFF3968CDu
#define SIENNA4              0xFF26478Bu
#define SKYBLUE              0xFFEBCE87u
#define SKYBLUE1             0xFFFFCE87u
#define SKYBLUE2             0xFFEEC07Eu
#define SKYBLUE3             0xFFCDA66Cu
#define SKYBLUE4             0xFF8B704Au
#define SLATEBLUE            0xFFCD5A6Au
#define SLATEBLUE1           0xFFFF6F83u
#define SLATEBLUE2           0xFFEE677Au
#define SLATEBLUE3           0xFFCD5969u
#define SLATEBLUE4           0xFF8B3C47u
#define SLATEGRAY            0xFF908070u
#define SLATEGRAY1           0xFFFFE2C6u
#define SLATEGRAY2           0xFFEED3B9u
#define SLATEGRAY3           0xFFCDB69Fu
#define SLATEGRAY4           0xFF8B7B6Cu
#define SLATEGREY            0xFF908070u
#define SNOW                 0xFFFAFAFFu
#define SNOW1                0xFFFAFAFFu
#define SNOW2                0xFFE9E9EEu
#define SNOW3                0xFFC9C9CDu
#define SNOW4                0xFF89898Bu
#define SPRINGGREEN          0xFF7FFF00u
#define SPRINGGREEN1         0xFF7FFF00u
#define SPRINGGREEN2         0xFF76EE00u
#define SPRINGGREEN3         0xFF66CD00u
#define SPRINGGREEN4         0xFF458B00u
#define STEELBLUE            0xFFB48246u
#define STEELBLUE1           0xFFFFB863u
#define STEELBLUE2           0xFFEEAC5Cu
#define STEELBLUE3           0xFFCD944Fu
#define STEELBLUE4           0xFF8B6436u
#define TAN                  0xFF8CB4D2u
#define TAN1                 0xFF4FA5FFu
#define TAN2                 0xFF499AEEu
#define TAN3                 0xFF3F85CDu
#define TAN4                 0xFF2B5A8Bu
#define THISTLE              0xFFD8BFD8u
#define THISTLE1             0xFFFFE1FFu
#define THISTLE2             0xFFEED2EEu
#define THISTLE3             0xFFCDB5CDu
#define THISTLE4             0xFF8B7B8Bu
#define TOMATO               0xFF4763FFu
#define TOMATO1              0xFF4763FFu
#define TOMATO2              0xFF425CEEu
#define TOMATO3              0xFF394FCDu
#define TOMATO4              0xFF26368Bu
#define TURQUOISE            0xFFD0E040u
#define TURQUOISE1           0xFFFFF500u
#define TURQUOISE2           0xFFEEE500u
#define TURQUOISE3           0xFFCDC500u
#define TURQUOISE4           0xFF8B8600u
#define VIOLET               0xFFEE82EEu
#define VIOLETRED            0xFF9020D0u
#define VIOLETRED1           0xFF963EFFu
#define VIOLETRED2           0xFF8C3AEEu
#define VIOLETRED3           0xFF7832CDu
#define VIOLETRED4           0xFF52228Bu
#define WHEAT                0xFFB3DEF5u
#define WHEAT1               0xFFBAE7FFu
#define WHEAT2               0xFFAED8EEu
#define WHEAT3               0xFF96BACDu
#define WHEAT4               0xFF667E8Bu
#define WHITE                0xFFFFFFFFu
#define WHITESMOKE           0xFFF5F5F5u
#define YELLOW               0xFF00FFFFu
#define YELLOW1              0xFF00FFFFu
#define YELLOW2              0xFF00EEEEu
#define YELLOW3              0xFF00CDCDu
#define YELLOW4              0xFF008B8Bu
#define YELLOWGREEN          0xFF32CD9Au



/*!BEGIN net/http/escape.h */

#define COSMOPOLITAN_NET_HTTP_ESCAPE_H_

#define kControlWs 1
#define kControlC0 2
#define kControlC1 4

COSMOPOLITAN_C_START_

extern const char kEscapeAuthority[256];
extern const char kEscapeIp[256];
extern const char kEscapePath[256];
extern const char kEscapeSegment[256];
extern const char kEscapeParam[256];
extern const char kEscapeFragment[256];

char *EscapeHtml(const char *, size_t, size_t *);
char *EscapeUrl(const char *, size_t, size_t *, const char[256]);
char *EscapeUser(const char *, size_t, size_t *);
char *EscapePass(const char *, size_t, size_t *);
char *EscapeIp(const char *, size_t, size_t *);
char *EscapeHost(const char *, size_t, size_t *);
char *EscapePath(const char *, size_t, size_t *);
char *EscapeParam(const char *, size_t, size_t *);
char *EscapeFragment(const char *, size_t, size_t *);
char *EscapeSegment(const char *, size_t, size_t *);
char *EscapeJsStringLiteral(char **, size_t *, const char *, size_t, size_t *);

ssize_t HasControlCodes(const char *, size_t, int);
char *Underlong(const char *, size_t, size_t *);
char *DecodeLatin1(const char *, size_t, size_t *);
char *EncodeLatin1(const char *, size_t, size_t *, int);
char *EncodeHttpHeaderValue(const char *, size_t, size_t *);
char *VisualizeControlCodes(const char *, size_t, size_t *);
char *IndentLines(const char *, size_t, size_t *, size_t);
char *EncodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *DecodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *EncodeBase64(const char *, size_t, size_t *);
char *DecodeBase64(const char *, size_t, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/http.h */

#define COSMOPOLITAN_LIBC_HTTP_HTTP_H_

#define kHttpRequest  0
#define kHttpResponse 1

#define kHttpGet     READ32LE("GET")
#define kHttpHead    READ32LE("HEAD")
#define kHttpPost    READ32LE("POST")
#define kHttpPut     READ32LE("PUT")
#define kHttpDelete  READ64LE("DELETE\0")
#define kHttpOptions READ64LE("OPTIONS")
#define kHttpConnect READ64LE("CONNECT")
#define kHttpTrace   READ64LE("TRACE\0\0")

#define kHttpStateStart   0
#define kHttpStateMethod  1
#define kHttpStateUri     2
#define kHttpStateVersion 3
#define kHttpStateStatus  4
#define kHttpStateMessage 5
#define kHttpStateName    6
#define kHttpStateColon   7
#define kHttpStateValue   8
#define kHttpStateCr      9
#define kHttpStateLf1     10
#define kHttpStateLf2     11

#define kHttpClientStateHeaders      0
#define kHttpClientStateBody         1
#define kHttpClientStateBodyChunked  2
#define kHttpClientStateBodyLengthed 3

#define kHttpStateChunkStart   0
#define kHttpStateChunkSize    1
#define kHttpStateChunkExt     2
#define kHttpStateChunkLf1     3
#define kHttpStateChunk        4
#define kHttpStateChunkCr2     5
#define kHttpStateChunkLf2     6
#define kHttpStateTrailerStart 7
#define kHttpStateTrailer      8
#define kHttpStateTrailerLf1   9
#define kHttpStateTrailerLf2   10

#define kHttpHost                          0
#define kHttpCacheControl                  1
#define kHttpConnection                    2
#define kHttpAccept                        3
#define kHttpAcceptLanguage                4
#define kHttpAcceptEncoding                5
#define kHttpUserAgent                     6
#define kHttpReferer                       7
#define kHttpXForwardedFor                 8
#define kHttpOrigin                        9
#define kHttpUpgradeInsecureRequests       10
#define kHttpPragma                        11
#define kHttpCookie                        12
#define kHttpDnt                           13
#define kHttpSecGpc                        14
#define kHttpFrom                          15
#define kHttpIfModifiedSince               16
#define kHttpXRequestedWith                17
#define kHttpXForwardedHost                18
#define kHttpXForwardedProto               19
#define kHttpXCsrfToken                    20
#define kHttpSaveData                      21
#define kHttpRange                         22
#define kHttpContentLength                 23
#define kHttpContentType                   24
#define kHttpVary                          25
#define kHttpDate                          26
#define kHttpServer                        27
#define kHttpExpires                       28
#define kHttpContentEncoding               29
#define kHttpLastModified                  30
#define kHttpEtag                          31
#define kHttpAllow                         32
#define kHttpContentRange                  33
#define kHttpAcceptCharset                 34
#define kHttpAccessControlAllowCredentials 35
#define kHttpAccessControlAllowHeaders     36
#define kHttpAccessControlAllowMethods     37
#define kHttpAccessControlAllowOrigin      38
#define kHttpAccessControlMaxAge           39
#define kHttpAccessControlMethod           40
#define kHttpAccessControlRequestHeaders   41
#define kHttpAccessControlRequestMethod    42
#define kHttpAccessControlRequestMethods   43
#define kHttpAge                           44
#define kHttpAuthorization                 45
#define kHttpContentBase                   46
#define kHttpContentDescription            47
#define kHttpContentDisposition            48
#define kHttpContentLanguage               49
#define kHttpContentLocation               50
#define kHttpContentMd5                    51
#define kHttpExpect                        52
#define kHttpIfMatch                       53
#define kHttpIfNoneMatch                   54
#define kHttpIfRange                       55
#define kHttpIfUnmodifiedSince             56
#define kHttpKeepAlive                     57
#define kHttpLink                          58
#define kHttpLocation                      59
#define kHttpMaxForwards                   60
#define kHttpProxyAuthenticate             61
#define kHttpProxyAuthorization            62
#define kHttpProxyConnection               63
#define kHttpPublic                        64
#define kHttpRetryAfter                    65
#define kHttpTe                            66
#define kHttpTrailer                       67
#define kHttpTransferEncoding              68
#define kHttpUpgrade                       69
#define kHttpWarning                       70
#define kHttpWwwAuthenticate               71
#define kHttpVia                           72
#define kHttpStrictTransportSecurity       73
#define kHttpXFrameOptions                 74
#define kHttpXContentTypeOptions           75
#define kHttpAltSvc                        76
#define kHttpReferrerPolicy                77
#define kHttpXXssProtection                78
#define kHttpAcceptRanges                  79
#define kHttpSetCookie                     80
#define kHttpSecChUa                       81
#define kHttpSecChUaMobile                 82
#define kHttpSecFetchSite                  83
#define kHttpSecFetchMode                  84
#define kHttpSecFetchUser                  85
#define kHttpSecFetchDest                  86
#define kHttpCfRay                         87
#define kHttpCfVisitor                     88
#define kHttpCfConnectingIp                89
#define kHttpCfIpcountry                   90
#define kHttpSecChUaPlatform               91
#define kHttpCdnLoop                       92
#define kHttpHeadersMax                    93

COSMOPOLITAN_C_START_

struct HttpSlice {
  short a, b;
};

struct HttpHeader {
  struct HttpSlice k;
  struct HttpSlice v;
};

struct HttpHeaders {
  unsigned n, c;
  struct HttpHeader *p;
};

struct HttpMessage {
  int i, a, status;
  unsigned char t;
  unsigned char type;
  unsigned char version;
  uint64_t method;
  struct HttpSlice k;
  struct HttpSlice uri;
  struct HttpSlice scratch;
  struct HttpSlice message;
  struct HttpSlice headers[kHttpHeadersMax];
  struct HttpHeaders xheaders;
};

struct HttpUnchunker {
  int t;
  size_t i;
  size_t j;
  ssize_t m;
};

extern const char kHttpToken[256];
extern const bool kHttpRepeatable[kHttpHeadersMax];

const char *GetHttpReason(int);
const char *GetHttpHeaderName(int);
int GetHttpHeader(const char *, size_t);
void InitHttpMessage(struct HttpMessage *, int);
void DestroyHttpMessage(struct HttpMessage *);
int ParseHttpMessage(struct HttpMessage *, const char *, size_t);
bool HeaderHas(struct HttpMessage *, const char *, int, const char *, size_t);
int64_t ParseContentLength(const char *, size_t);
char *FormatHttpDateTime(char[hasatleast 30], struct tm *);
bool ParseHttpRange(const char *, size_t, long, long *, long *);
int64_t ParseHttpDateTime(const char *, size_t);
uint64_t ParseHttpMethod(const char *, size_t);
bool IsValidHttpToken(const char *, size_t);
bool IsValidCookieValue(const char *, size_t);
bool IsAcceptablePath(const char *, size_t);
bool IsAcceptableHost(const char *, size_t);
bool IsAcceptablePort(const char *, size_t);
bool IsReasonablePath(const char *, size_t);
int ParseForwarded(const char *, size_t, uint32_t *, uint16_t *);
bool IsMimeType(const char *, size_t, const char *);
ssize_t Unchunk(struct HttpUnchunker *, char *, size_t, size_t *);
const char *FindContentType(const char *, size_t);
bool IsNoCompressExt(const char *, size_t);
char *FoldHeader(struct HttpMessage *, const char *, int, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/ip.h */

#define COSMOPOLITAN_NET_HTTP_IP_H_

#define kIpUnknown    0
#define kIpMulticast  1
#define kIpLoopback   2
#define kIpPrivate    3
#define kIpTestnet    4
#define kIpAfrinic    5
#define kIpLacnic     6
#define kIpApnic      7
#define kIpArin       8
#define kIpRipe       9
#define kIpDod        10
#define kIpAtt        11
#define kIpApple      12
#define kIpFord       13
#define kIpCogent     14
#define kIpPrudential 15
#define kIpUsps       16
#define kIpComcast    17
#define kIpFuture     18
#define kIpAnonymous  19

COSMOPOLITAN_C_START_

struct Cidr {
  int64_t addr;
  int cidr;
};

int64_t ParseIp(const char *, size_t);
struct Cidr ParseCidr(const char *, size_t);
bool IsDodIp(uint32_t);
bool IsArinIp(uint32_t);
bool IsRipeIp(uint32_t);
bool IsApnicIp(uint32_t);
bool IsLacnicIp(uint32_t);
bool IsPublicIp(uint32_t);
bool IsPrivateIp(uint32_t);
bool IsAfrinicIp(uint32_t);
bool IsTestnetIp(uint32_t);
bool IsLoopbackIp(uint32_t);
bool IsMulticastIp(uint32_t);
bool IsAnonymousIp(uint32_t);
int CategorizeIp(uint32_t);
const char *GetIpCategoryName(int);
bool IsCloudflareIp(uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/tokenbucket.h */

#define COSMOPOLITAN_NET_HTTP_TOKENBUCKET_H_
COSMOPOLITAN_C_START_

void ReplenishTokens(atomic_uint_fast64_t *, size_t);
int AcquireToken(atomic_schar *, uint32_t, int);
int CountTokens(atomic_schar *, uint32_t, int);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/url.h */

#define COSMOPOLITAN_NET_HTTP_URL_H_

#define kUrlPlus   1
#define kUrlLatin1 2
#define kUrlOpaque 4

COSMOPOLITAN_C_START_

struct UrlView {
  size_t n;
  char *p;
};

struct UrlParams {
  size_t n;
  struct UrlParam {
    struct UrlView key;
    struct UrlView val;
  } * p;
};

struct Url {
  struct UrlView scheme; /* must be [A-Za-z][-+.0-9A-Za-z]* or empty */
  struct UrlView user;   /* depends on host non-absence */
  struct UrlView pass;   /* depends on user non-absence */
  struct UrlView host;   /* or reg_name */
  struct UrlView port;   /* depends on host non-absence */
  struct UrlView path;   /* or opaque_part */
  struct UrlParams params;
  struct UrlView fragment;
};

char *EncodeUrl(struct Url *, size_t *);
char *ParseUrl(const char *, size_t, struct Url *, int);
char *ParseParams(const char *, size_t, struct UrlParams *);
char *ParseHost(const char *, size_t, struct Url *);
char *EscapeUrlView(char *, struct UrlView *, const char[256]);

COSMOPOLITAN_C_END_


/*!BEGIN tool/args/args.h */

#define COSMOPOLITAN_TOOL_ARGS_ARGS_H_
COSMOPOLITAN_C_START_

int LoadZipArgs(int *, char ***);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/dlmalloc/dlmalloc.h */

#define COSMOPOLITAN_THIRD_PARTY_DLMALLOC_DLMALLOC_H_

#define dlbulk_free                  __dlbulk_free
#define dlcalloc                     __dlcalloc
#define dlfree                       __dlfree
#define dlindependent_calloc         __dlindependent_calloc
#define dlindependent_comalloc       __dlindependent_comalloc
#define dlmallinfo                   __dlmallinfo
#define dlmalloc                     __dlmalloc
#define dlmalloc_abort               __dlmalloc_abort
#define dlmalloc_atfork              __dlmalloc_atfork
#define dlmalloc_footprint           __dlmalloc_footprint
#define dlmalloc_footprint_limit     __dlmalloc_footprint_limit
#define dlmalloc_inspect_all         __dlmalloc_inspect_all
#define dlmalloc_max_footprint       __dlmalloc_max_footprint
#define dlmalloc_set_footprint_limit __dlmalloc_set_footprint_limit
#define dlmalloc_stats               __dlmalloc_stats
#define dlmalloc_trim                __dlmalloc_trim
#define dlmalloc_usable_size         __dlmalloc_usable_size
#define dlmallopt                    __dlmallopt
#define dlmallopt                    __dlmallopt
#define dlmemalign                   __dlmemalign
#define dlrealloc                    __dlrealloc
#define dlrealloc_in_place           __dlrealloc_in_place
#define dlrealloc_in_place           __dlrealloc_in_place

COSMOPOLITAN_C_START_

/*
  malloc(size_t n)
  Returns a pointer to a newly allocated chunk of at least n bytes, or
  null if no space is available, in which case errno is set to ENOMEM
  on ANSI C systems.

  If n is zero, malloc returns a minimum-sized chunk. (The minimum
  size is 16 bytes on most 32bit systems, and 32 bytes on 64bit
  systems.)  Note that size_t is an unsigned type, so calls with
  arguments that would be negative if signed are interpreted as
  requests for huge amounts of space, which will often fail. The
  maximum supported value of n differs across systems, but is in all
  cases less than the maximum representable value of a size_t.
*/
void* dlmalloc(size_t);

/*
  free(void* p)
  Releases the chunk of memory pointed to by p, that had been previously
  allocated using malloc or a related routine such as realloc.
  It has no effect if p is null. If p was not malloced or already
  freed, free(p) will by default cuase the current program to abort.
*/
void dlfree(void*);

/*
  calloc(size_t n_elements, size_t element_size);
  Returns a pointer to n_elements * element_size bytes, with all locations
  set to zero.
*/
void* dlcalloc(size_t, size_t);

/*
  realloc(void* p, size_t n)
  Returns a pointer to a chunk of size n that contains the same data
  as does chunk p up to the minimum of (n, p's size) bytes, or null
  if no space is available.

  The returned pointer may or may not be the same as p. The algorithm
  prefers extending p in most cases when possible, otherwise it
  employs the equivalent of a malloc-copy-free sequence.

  If p is null, realloc is equivalent to malloc.

  If space is not available, realloc returns null, errno is set (if on
  ANSI) and p is NOT freed.

  if n is for fewer bytes than already held by p, the newly unused
  space is lopped off and freed if possible.  realloc with a size
  argument of zero (re)allocates a minimum-sized chunk.

  The old unix realloc convention of allowing the last-free'd chunk
  to be used as an argument to realloc is not supported.
*/
void* dlrealloc(void*, size_t);

/*
  realloc_in_place(void* p, size_t n)
  Resizes the space allocated for p to size n, only if this can be
  done without moving p (i.e., only if there is adjacent space
  available if n is greater than p's current allocated size, or n is
  less than or equal to p's size). This may be used instead of plain
  realloc if an alternative allocation strategy is needed upon failure
  to expand space; for example, reallocation of a buffer that must be
  memory-aligned or cleared. You can use realloc_in_place to trigger
  these alternatives only when needed.

  Returns p if successful; otherwise null.
*/
void* dlrealloc_in_place(void*, size_t);

/*
  memalign(size_t alignment, size_t n);
  Returns a pointer to a newly allocated chunk of n bytes, aligned
  in accord with the alignment argument.

  The alignment argument should be a power of two. If the argument is
  not a power of two, the nearest greater power is used.
  8-byte alignment is guaranteed by normal malloc calls, so don't
  bother calling memalign with an argument of 8 or less.

  Overreliance on memalign is a sure way to fragment space.
*/
void* dlmemalign(size_t, size_t);

/*
  mallopt(int parameter_number, int parameter_value)
  Sets tunable parameters The format is to provide a
  (parameter-number, parameter-value) pair.  mallopt then sets the
  corresponding parameter to the argument value if it can (i.e., so
  long as the value is meaningful), and returns 1 if successful else
  0.  SVID/XPG/ANSI defines four standard param numbers for mallopt,
  normally defined in malloc.h.  None of these are use in this malloc,
  so setting them has no effect. But this malloc also supports other
  options in mallopt:

  Symbol            param #  default    allowed param values
  M_TRIM_THRESHOLD     -1   2*1024*1024   any   (-1U disables trimming)
  M_GRANULARITY        -2     page size   any power of 2 >= page size
  M_MMAP_THRESHOLD     -3      256*1024   any   (or 0 if no MMAP support)
*/
int dlmallopt(int, int);

/*
  malloc_footprint();
  Returns the number of bytes obtained from the system.  The total
  number of bytes allocated by malloc, realloc etc., is less than this
  value. Unlike mallinfo, this function returns only a precomputed
  result, so can be called frequently to monitor memory consumption.
  Even if locks are otherwise defined, this function does not use them,
  so results might not be up to date.
*/
size_t dlmalloc_footprint(void);

/*
  malloc_max_footprint();
  Returns the maximum number of bytes obtained from the system. This
  value will be greater than current footprint if deallocated space
  has been reclaimed by the system. The peak number of bytes allocated
  by malloc, realloc etc., is less than this value. Unlike mallinfo,
  this function returns only a precomputed result, so can be called
  frequently to monitor memory consumption.  Even if locks are
  otherwise defined, this function does not use them, so results might
  not be up to date.
*/
size_t dlmalloc_max_footprint(void);

/*
  malloc_footprint_limit();
  Returns the number of bytes that the heap is allowed to obtain from
  the system, returning the last value returned by
  malloc_set_footprint_limit, or the maximum size_t value if
  never set. The returned value reflects a permission. There is no
  guarantee that this number of bytes can actually be obtained from
  the system.
*/
size_t dlmalloc_footprint_limit(void);

/*
  malloc_set_footprint_limit();
  Sets the maximum number of bytes to obtain from the system, causing
  failure returns from malloc and related functions upon attempts to
  exceed this value. The argument value may be subject to page
  rounding to an enforceable limit; this actual value is returned.
  Using an argument of the maximum possible size_t effectively
  disables checks. If the argument is less than or equal to the
  current malloc_footprint, then all future allocations that require
  additional system memory will fail. However, invocation cannot
  retroactively deallocate existing used memory.
*/
size_t dlmalloc_set_footprint_limit(size_t bytes);

/*
  malloc_inspect_all(void(*handler)(void *start,
                                    void *end,
                                    size_t used_bytes,
                                    void* callback_arg),
                      void* arg);
  Traverses the heap and calls the given handler for each managed
  region, skipping all bytes that are (or may be) used for bookkeeping
  purposes.  Traversal does not include include chunks that have been
  directly memory mapped. Each reported region begins at the start
  address, and continues up to but not including the end address.  The
  first used_bytes of the region contain allocated data. If
  used_bytes is zero, the region is unallocated. The handler is
  invoked with the given callback argument. If locks are defined, they
  are held during the entire traversal. It is a bad idea to invoke
  other malloc functions from within the handler.

  For example, to count the number of in-use chunks with size greater
  than 1000, you could write:
  static int count = 0;
  void count_chunks(void* start, void* end, size_t used, void* arg) {
    if (used >= 1000) ++count;
  }
  then:
    malloc_inspect_all(count_chunks, NULL);

  malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined.
*/
void dlmalloc_inspect_all(void (*handler)(void*, void*, size_t, void*),
                          void* arg);

/*
  mallinfo()
  Returns (by copy) a struct containing various summary statistics:

  arena:     current total non-mmapped bytes allocated from system
  ordblks:   the number of free chunks
  smblks:    always zero.
  hblks:     current number of mmapped regions
  hblkhd:    total bytes held in mmapped regions
  usmblks:   the maximum total allocated space. This will be greater
                than current total if trimming has occurred.
  fsmblks:   always zero
  uordblks:  current total allocated space (normal or mmapped)
  fordblks:  total free space
  keepcost:  the maximum number of bytes that could ideally be released
               back to system via malloc_trim. ("ideally" means that
               it ignores page restrictions etc.)

  Because these fields are ints, but internal bookkeeping may
  be kept as longs, the reported values may wrap around zero and
  thus be inaccurate.
*/

struct mallinfo dlmallinfo(void);

/*
  independent_calloc(size_t n_elements, size_t element_size, void* chunks[]);

  independent_calloc is similar to calloc, but instead of returning a
  single cleared space, it returns an array of pointers to n_elements
  independent elements that can hold contents of size elem_size, each
  of which starts out cleared, and can be independently freed,
  realloc'ed etc. The elements are guaranteed to be adjacently
  allocated (this is not guaranteed to occur with multiple callocs or
  mallocs), which may also improve cache locality in some
  applications.

  The "chunks" argument is optional (i.e., may be null, which is
  probably the most typical usage). If it is null, the returned array
  is itself dynamically allocated and should also be freed when it is
  no longer needed. Otherwise, the chunks array must be of at least
  n_elements in length. It is filled in with the pointers to the
  chunks.

  In either case, independent_calloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and "chunks"
  is null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_calloc simplifies and speeds up implementations of many
  kinds of pools.  It may also be useful when constructing large data
  structures that initially have a fixed number of fixed-sized nodes,
  but the number is not known at compile time, and some of the nodes
  may later need to be freed. For example:

  struct Node { int item; struct Node* next; };

  struct Node* build_list() {
    struct Node** pool;
    int n = read_number_of_nodes_needed();
    if (n <= 0) return 0;
    pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
    if (pool == 0) die();
    // organize into a linked list...
    struct Node* first = pool[0];
    for (i = 0; i < n-1; ++i)
      pool[i]->next = pool[i+1];
    free(pool);     // Can now free the array (or not, if it is needed later)
    return first;
  }
*/
void** dlindependent_calloc(size_t, size_t, void**);

/*
  independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);

  independent_comalloc allocates, all at once, a set of n_elements
  chunks with sizes indicated in the "sizes" array.    It returns
  an array of pointers to these elements, each of which can be
  independently freed, realloc'ed etc. The elements are guaranteed to
  be adjacently allocated (this is not guaranteed to occur with
  multiple callocs or mallocs), which may also improve cache locality
  in some applications.

  The "chunks" argument is optional (i.e., may be null). If it is null
  the returned array is itself dynamically allocated and should also
  be freed when it is no longer needed. Otherwise, the chunks array
  must be of at least n_elements in length. It is filled in with the
  pointers to the chunks.

  In either case, independent_comalloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and chunks is
  null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_comallac differs from independent_calloc in that each
  element may have a different size, and also that it does not
  automatically clear elements.

  independent_comalloc can be used to speed up allocation in cases
  where several structs or objects must always be allocated at the
  same time.  For example:

  struct Head { ... }
  struct Foot { ... }

  void send_message(char* msg) {
    int msglen = strlen(msg);
    size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
    void* chunks[3];
    if (independent_comalloc(3, sizes, chunks) == 0)
      die();
    struct Head* head = (struct Head*)(chunks[0]);
    char*        body = (char*)(chunks[1]);
    struct Foot* foot = (struct Foot*)(chunks[2]);
    // ...
  }

  In general though, independent_comalloc is worth using only for
  larger values of n_elements. For small values, you probably won't
  detect enough difference from series of malloc calls to bother.

  Overuse of independent_comalloc can increase overall memory usage,
  since it cannot reuse existing noncontiguous small chunks that
  might be available for some of the elements.
*/
void** dlindependent_comalloc(size_t, size_t*, void**);

/*
  bulk_free(void* array[], size_t n_elements)
  Frees and clears (sets to null) each non-null pointer in the given
  array.  This is likely to be faster than freeing them one-by-one.
  If footers are used, pointers that have been allocated in different
  mspaces are not freed or cleared, and the count of all such pointers
  is returned.  For large arrays of pointers with poor locality, it
  may be worthwhile to sort this array before calling bulk_free.
*/
size_t dlbulk_free(void**, size_t n_elements);

/*
  malloc_trim(size_t pad);

  If possible, gives memory back to the system (via negative arguments
  to sbrk) if there is unused memory at the `high' end of the malloc
  pool or in unused MMAP segments. You can call this after freeing
  large blocks of memory to potentially reduce the system-level memory
  requirements of a program. However, it cannot guarantee to reduce
  memory. Under some allocation patterns, some large free blocks of
  memory will be locked between two used chunks, so they cannot be
  given back to the system.

  The `pad' argument to malloc_trim represents the amount of free
  trailing space to leave untrimmed. If this argument is zero, only
  the minimum amount of memory to maintain internal data structures
  will be left. Non-zero arguments can be supplied to maintain enough
  trailing space to service future expected allocations without having
  to re-obtain memory from the system.

  Malloc_trim returns 1 if it actually released any memory, else 0.
*/
int dlmalloc_trim(size_t);

/*
  malloc_stats();
  Prints on stderr the amount of space obtained from the system (both
  via sbrk and mmap), the maximum amount (which may be more than
  current if malloc_trim and/or munmap got called), and the current
  number of bytes allocated via malloc (or realloc, etc) but not yet
  freed. Note that this is the number of bytes allocated, not the
  number requested. It will be larger than the number requested
  because of alignment and bookkeeping overhead. Because it includes
  alignment wastage as being in use, this figure may be greater than
  zero even when no user-level chunks are allocated.

  The reported current and maximum system memory can be inaccurate if
  a program makes other calls to system memory allocation functions
  (normally sbrk) outside of malloc.

  malloc_stats prints only the most commonly interesting statistics.
  More information can be obtained by calling mallinfo.

  malloc_stats is not compiled if NO_MALLOC_STATS is defined.
*/
void dlmalloc_stats(void);

/*
  malloc_usable_size(void* p);

  Returns the number of bytes you can actually use in
  an allocated chunk, which may be more than you requested (although
  often not) due to alignment and minimum size constraints.
  You can use this many bytes without worrying about
  overwriting other allocated objects. This is not a particularly great
  programming practice. malloc_usable_size can be more useful in
  debugging and assertions, for example:

  p = malloc(n);
  assert(malloc_usable_size(p) >= 256);
*/
size_t dlmalloc_usable_size(void*);

/*
  mspace is an opaque type representing an independent
  region of space that supports mspace_malloc, etc.
*/
typedef void* mspace;

/*
  create_mspace creates and returns a new independent space with the
  given initial capacity, or, if 0, the default granularity size.  It
  returns null if there is no system memory available to create the
  space.  If argument locked is non-zero, the space uses a separate
  lock to control access. The capacity of the space will grow
  dynamically as needed to service mspace_malloc requests.  You can
  control the sizes of incremental increases of this space by
  compiling with a different DEFAULT_GRANULARITY or dynamically
  setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
  destroy_mspace destroys the given space, and attempts to return all
  of its memory back to the system, returning the total number of
  bytes freed. After destruction, the results of access to all memory
  used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

/*
  create_mspace_with_base uses the memory supplied as the initial base
  of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this
  space is used for bookkeeping, so the capacity must be at least this
  large. (Otherwise 0 is returned.) When this initial space is
  exhausted, additional memory will be obtained from the system.
  Destroying this space will deallocate all additionally allocated
  space (if possible) but not the initial base.
*/
mspace create_mspace_with_base(void* base, size_t capacity, int locked);

/*
  mspace_track_large_chunks controls whether requests for large chunks
  are allocated in their own untracked mmapped regions, separate from
  others in this mspace. By default large chunks are not tracked,
  which reduces fragmentation. However, such chunks are not
  necessarily released to the system upon destroy_mspace.  Enabling
  tracking by setting to true may increase fragmentation, but avoids
  leakage when relying on destroy_mspace to release all memory
  allocated using this space.  The function returns the previous
  setting.
*/
int mspace_track_large_chunks(mspace msp, int enable);

/*
  mspace_mallinfo behaves as mallinfo, but reports properties of
  the given space.
*/
struct mallinfo mspace_mallinfo(mspace msp);

/*
  An alias for mallopt.
*/
int mspace_mallopt(int, int);

/*
  The following operate identically to their malloc counterparts
  but operate only for the given mspace argument
*/
void* mspace_malloc(mspace msp, size_t bytes);
void mspace_free(mspace msp, void* mem);
void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
void* mspace_realloc(mspace msp, void* mem, size_t newsize);
void* mspace_realloc_in_place(mspace msp, void* mem, size_t newsize);
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
void** mspace_independent_calloc(mspace msp, size_t n_elements,
                                 size_t elem_size, void* chunks[]);
void** mspace_independent_comalloc(mspace msp, size_t n_elements,
                                   size_t sizes[], void* chunks[]);
size_t mspace_bulk_free(mspace msp, void**, size_t n_elements);
size_t mspace_usable_size(const void* mem);
void mspace_malloc_stats(mspace msp);
int mspace_trim(mspace msp, size_t pad);
size_t mspace_footprint(mspace msp);
size_t mspace_max_footprint(mspace msp);
size_t mspace_footprint_limit(mspace msp);
size_t mspace_set_footprint_limit(mspace msp, size_t bytes);
void mspace_inspect_all(mspace msp,
                        void (*handler)(void*, void*, size_t, void*),
                        void* arg);

void dlmalloc_atfork(void);
void dlmalloc_abort(void) relegated wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/gdtoa/gdtoa.h */

#define COSMOPOLITAN_THIRD_PARTY_GDTOA_GDTOA_H_
COSMOPOLITAN_C_START_

#define dtoa      __dtoa
#define gdtoa     __gdtoa
#define strtodg   __strtodg
#define freedtoa  __freedtoa
#define g_ddfmt   __g_ddfmt
#define g_ddfmt_p __g_ddfmt_p
#define g_dfmt    __g_dfmt
#define g_dfmt_p  __g_dfmt_p
#define g_ffmt    __g_ffmt
#define g_ffmt_p  __g_ffmt_p
#define g_Qfmt    __g_Qfmt
#define g_Qfmt_p  __g_Qfmt_p
#define g_xfmt    __g_xfmt
#define g_xfmt_p  __g_xfmt_p
#define g_xLfmt   __g_xLfmt
#define g_xLfmt_p __g_xLfmt_p
#define strtoId   __strtoId
#define strtoIdd  __strtoIdd
#define strtoIf   __strtoIf
#define strtoIQ   __strtoIQ
#define strtoIx   __strtoIx
#define strtoIxL  __strtoIxL
#define strtord   __strtord
#define strtordd  __strtordd
#define strtorf   __strtorf
#define strtorQ   __strtorQ
#define strtorx   __strtorx
#define strtorxL  __strtorxL
#define strtodI   __strtodI
#define strtopd   __strtopd
#define strtopdd  __strtopdd
#define strtopf   __strtopf
#define strtopQ   __strtopQ
#define strtopx   __strtopx
#define strtopxL  __strtopxL

/**
 * Configures g_*fmt()
 *
 * @param ic
 * 	0 ==> Infinity or NaN
 * 	1 ==> infinity or nan
 * 	2 ==> INFINITY or NAN
 * 	3 ==> Inf or NaN
 * 	4 ==> inf or nan
 * 	5 ==> INF or NAN
 * @param ic determines if NaNs are rendered as NaN(...)
 * 	0 ==> no
 * 	1 ==> yes
 * 	2 ==> no for default NaN values; yes otherwise
 * @param ns determines sign of NaN values reported
 * 	0 ==> distinguish NaN and -NaN
 * 	1 ==> report both as NaN
 */
#define NIK(ic, nb, ns) (ic + 6 * (nb + 3 * ns))

enum {
  /* return values from strtodg */
  STRTOG_Zero = 0,
  STRTOG_Normal = 1,
  STRTOG_Denormal = 2,
  STRTOG_Infinite = 3,
  STRTOG_NaN = 4,
  STRTOG_NaNbits = 5,
  STRTOG_NoNumber = 6,
  STRTOG_Retmask = 7,
  /* The following may be or-ed into one of the above values. */
  STRTOG_Neg = 0x08,    /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
  STRTOG_Inexlo = 0x10, /* returned result rounded toward zero */
  STRTOG_Inexhi = 0x20, /* returned result rounded away from zero */
  STRTOG_Inexact = 0x30,
  STRTOG_Underflow = 0x40,
  STRTOG_Overflow = 0x80
};

typedef struct FPI {
  int nbits;
  int emin;
  int emax;
  int rounding;
  int sudden_underflow;
  int int_max;
} FPI;

enum {
  /* FPI.rounding values: same as FLT_ROUNDS */
  FPI_Round_zero = 0,
  FPI_Round_near = 1,
  FPI_Round_up = 2,
  FPI_Round_down = 3
};

char *dtoa(double, int, int, int *, int *, char **);
char *gdtoa(const FPI *, int, unsigned *, int *, int, int, int *, char **);
int strtodg(const char *, char **, const FPI *, int *, unsigned *);
void freedtoa(char *);

char *g_ddfmt(char *, double *, int, size_t);
char *g_ddfmt_p(char *, double *, int, size_t, int);
char *g_dfmt(char *, double *, int, size_t);
char *g_dfmt_p(char *, double *, int, size_t, int);
char *g_ffmt(char *, float *, int, size_t);
char *g_ffmt_p(char *, float *, int, size_t, int);
char *g_Qfmt(char *, void *, int, size_t);
char *g_Qfmt_p(char *, void *, int, size_t, int);
char *g_xfmt(char *, void *, int, size_t);
char *g_xfmt_p(char *, void *, int, size_t, int);
char *g_xLfmt(char *, void *, int, size_t);
char *g_xLfmt_p(char *, void *, int, size_t, int);

int strtoId(const char *, char **, double *, double *);
int strtoIdd(const char *, char **, double *, double *);
int strtoIf(const char *, char **, float *, float *);
int strtoIQ(const char *, char **, void *, void *);
int strtoIx(const char *, char **, void *, void *);
int strtoIxL(const char *, char **, void *, void *);
int strtord(const char *, char **, int, double *);
int strtordd(const char *, char **, int, double *);
int strtorf(const char *, char **, int, float *);
int strtorQ(const char *, char **, int, void *);
int strtorx(const char *, char **, int, void *);
int strtorxL(const char *, char **, int, void *);

int strtodI(const char *, char **, double *);
int strtopd(const char *, char **, double *);
int strtopdd(const char *, char **, double *);
int strtopf(const char *, char **, float *);
int strtopQ(const char *, char **, void *);
int strtopx(const char *, char **, void *);
int strtopxL(const char *, char **, void *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long1.h */

#define _GETOPT_CORE_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif
COSMOPOLITAN_C_START_

extern char *optarg;
extern int optind, opterr, optopt, optreset;

int getopt(int, char *const *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long2.h */

#define _GETOPT_EXT_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif

#define no_argument       0
#define required_argument 1
#define optional_argument 2

COSMOPOLITAN_C_START_

struct option {
  const char *name;
  int has_arg;
  int *flag;
  int val;
};

int getopt_long(int, char *const *, const char *, const struct option *, int *);
int getopt_long_only(int, char *const *, const char *, const struct option *,
                     int *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/crypt.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_CRYPT_H_
COSMOPOLITAN_C_START_

struct crypt_data {
  int initialized;
  char __buf[256];
};

char *crypt(const char *, const char *) libcesque;
char *crypt_r(const char *, const char *, struct crypt_data *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/fnmatch.h */

#define COSMOPOLITAN_THIRD_PARTY_REGEX_FNMATCH_H_
COSMOPOLITAN_C_START_

#define FNM_PATHNAME    0x1
#define FNM_NOESCAPE    0x2
#define FNM_PERIOD      0x4
#define FNM_LEADING_DIR 0x8
#define FNM_CASEFOLD    0x10
#define FNM_FILE_NAME   FNM_PATHNAME

#define FNM_NOMATCH 1
#define FNM_NOSYS   (-1)

int fnmatch(const char *, const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/glob.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_GLOB_H_
COSMOPOLITAN_C_START_

#define GLOB_ERR      0x01
#define GLOB_MARK     0x02
#define GLOB_NOSORT   0x04
#define GLOB_DOOFFS   0x08 /* reserves null slots at start of gl_pathv */
#define GLOB_NOCHECK  0x10 /* just yield pattern if GLOB_NOMATCH happens */
#define GLOB_APPEND   0x20 /* enables us to call glob() multiple times */
#define GLOB_NOESCAPE 0x40 /* don't allow things like \*\?\[\] escaping */
#define GLOB_PERIOD   0x80

#define GLOB_TILDE       0x1000
#define GLOB_TILDE_CHECK 0x4000

#define GLOB_NOSPACE 1
#define GLOB_ABORTED 2
#define GLOB_NOMATCH 3
#define GLOB_NOSYS   4

typedef struct {
  size_t gl_pathc;
  char **gl_pathv;
  size_t gl_offs;
  int __dummy1;
  void *__dummy2[5];
} glob_t;

int glob(const char *, int, int (*)(const char *, int), glob_t *);
void globfree(glob_t *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/lockf.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_LOCKF_H_

#define F_ULOCK 0
#define F_LOCK  1
#define F_TLOCK 2
#define F_TEST  3

COSMOPOLITAN_C_START_

int lockf(int, int, int64_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/mntent.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_MNTENT_H_
COSMOPOLITAN_C_START_

#define MOUNTED "/etc/mtab"

#define MNTTYPE_IGNORE  "ignore"
#define MNTTYPE_NFS     "nfs"
#define MNTTYPE_SWAP    "swap"
#define MNTOPT_DEFAULTS "defaults"
#define MNTOPT_RO       "ro"
#define MNTOPT_RW       "rw"
#define MNTOPT_SUID     "suid"
#define MNTOPT_NOSUID   "nosuid"
#define MNTOPT_NOAUTO   "noauto"

struct mntent {
  char *mnt_fsname;
  char *mnt_dir;
  char *mnt_type;
  char *mnt_opts;
  int mnt_freq;
  int mnt_passno;
};

FILE *setmntent(const char *, const char *);
int endmntent(FILE *);
struct mntent *getmntent(FILE *);
struct mntent *getmntent_r(FILE *, struct mntent *, char *, int);
int addmntent(FILE *, const struct mntent *);
char *hasmntopt(const struct mntent *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/nameser.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NAMESER_H_
COSMOPOLITAN_C_START_

#define __NAMESER	19991006
#define NS_PACKETSZ	512
#define NS_MAXDNAME	1025
#define NS_MAXMSG	65535
#define NS_MAXCDNAME	255
#define NS_MAXLABEL	63
#define NS_HFIXEDSZ	12
#define NS_QFIXEDSZ	4
#define NS_RRFIXEDSZ	10
#define NS_INT32SZ	4
#define NS_INT16SZ	2
#define NS_INT8SZ	1
#define NS_INADDRSZ	4
#define NS_IN6ADDRSZ	16
#define NS_CMPRSFLGS	0xc0
#define NS_DEFAULTPORT	53

typedef enum __ns_sect {
	ns_s_qd = 0,
	ns_s_zn = 0,
	ns_s_an = 1,
	ns_s_pr = 1,
	ns_s_ns = 2,
	ns_s_ud = 2,
	ns_s_ar = 3,
	ns_s_max = 4
} ns_sect;

typedef struct __ns_msg {
	const unsigned char *_msg, *_eom;
	uint16_t _id, _flags, _counts[ns_s_max];
	const unsigned char *_sections[ns_s_max];
	ns_sect _sect;
	int _rrnum;
	const unsigned char *_msg_ptr;
} ns_msg;

struct _ns_flagdata {  int mask, shift;  };
extern const struct _ns_flagdata _ns_flagdata[];

#define ns_msg_id(handle) ((handle)._id + 0)
#define ns_msg_base(handle) ((handle)._msg + 0)
#define ns_msg_end(handle) ((handle)._eom + 0)
#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
#define ns_msg_getflag(handle, flag) \
	(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)

typedef	struct __ns_rr {
	char		name[NS_MAXDNAME];
	uint16_t	type;
	uint16_t	rr_class;
	uint32_t	ttl;
	uint16_t	rdlength;
	const unsigned char *rdata;
} ns_rr;

#define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
#define ns_rr_type(rr)	((ns_type)((rr).type + 0))
#define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0))
#define ns_rr_ttl(rr)	((rr).ttl + 0)
#define ns_rr_rdlen(rr)	((rr).rdlength + 0)
#define ns_rr_rdata(rr)	((rr).rdata + 0)

typedef enum __ns_flag {
	ns_f_qr,
	ns_f_opcode,
	ns_f_aa,
	ns_f_tc,
	ns_f_rd,
	ns_f_ra,
	ns_f_z,
	ns_f_ad,
	ns_f_cd,
	ns_f_rcode,
	ns_f_max
} ns_flag;

typedef enum __ns_opcode {
	ns_o_query = 0,
	ns_o_iquery = 1,
	ns_o_status = 2,
	ns_o_notify = 4,
	ns_o_update = 5,
	ns_o_max = 6
} ns_opcode;

typedef	enum __ns_rcode {
	ns_r_noerror = 0,
	ns_r_formerr = 1,
	ns_r_servfail = 2,
	ns_r_nxdomain = 3,
	ns_r_notimpl = 4,
	ns_r_refused = 5,
	ns_r_yxdomain = 6,
	ns_r_yxrrset = 7,
	ns_r_nxrrset = 8,
	ns_r_notauth = 9,
	ns_r_notzone = 10,
	ns_r_max = 11,
	ns_r_badvers = 16,
	ns_r_badsig = 16,
	ns_r_badkey = 17,
	ns_r_badtime = 18
} ns_rcode;

typedef enum __ns_update_operation {
	ns_uop_delete = 0,
	ns_uop_add = 1,
	ns_uop_max = 2
} ns_update_operation;

struct ns_tsig_key {
        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
        unsigned char *data;
        int len;
};
typedef struct ns_tsig_key ns_tsig_key;

struct ns_tcp_tsig_state {
	int counter;
	struct dst_key *key;
	void *ctx;
	unsigned char sig[NS_PACKETSZ];
	int siglen;
};
typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;

#define NS_TSIG_FUDGE 300
#define NS_TSIG_TCP_COUNT 100
#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"

#define NS_TSIG_ERROR_NO_TSIG -10
#define NS_TSIG_ERROR_NO_SPACE -11
#define NS_TSIG_ERROR_FORMERR -12

typedef enum __ns_type {
	ns_t_invalid = 0,
	ns_t_a = 1,
	ns_t_ns = 2,
	ns_t_md = 3,
	ns_t_mf = 4,
	ns_t_cname = 5,
	ns_t_soa = 6,
	ns_t_mb = 7,
	ns_t_mg = 8,
	ns_t_mr = 9,
	ns_t_null = 10,
	ns_t_wks = 11,
	ns_t_ptr = 12,
	ns_t_hinfo = 13,
	ns_t_minfo = 14,
	ns_t_mx = 15,
	ns_t_txt = 16,
	ns_t_rp = 17,
	ns_t_afsdb = 18,
	ns_t_x25 = 19,
	ns_t_isdn = 20,
	ns_t_rt = 21,
	ns_t_nsap = 22,
	ns_t_nsap_ptr = 23,
	ns_t_sig = 24,
	ns_t_key = 25,
	ns_t_px = 26,
	ns_t_gpos = 27,
	ns_t_aaaa = 28,
	ns_t_loc = 29,
	ns_t_nxt = 30,
	ns_t_eid = 31,
	ns_t_nimloc = 32,
	ns_t_srv = 33,
	ns_t_atma = 34,
	ns_t_naptr = 35,
	ns_t_kx = 36,
	ns_t_cert = 37,
	ns_t_a6 = 38,
	ns_t_dname = 39,
	ns_t_sink = 40,
	ns_t_opt = 41,
	ns_t_apl = 42,
	ns_t_tkey = 249,
	ns_t_tsig = 250,
	ns_t_ixfr = 251,
	ns_t_axfr = 252,
	ns_t_mailb = 253,
	ns_t_maila = 254,
	ns_t_any = 255,
	ns_t_zxfr = 256,
	ns_t_max = 65536
} ns_type;

#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
		      (t) == ns_t_mailb || (t) == ns_t_maila)
#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
		       (t) == ns_t_zxfr)

typedef enum __ns_class {
	ns_c_invalid = 0,
	ns_c_in = 1,
	ns_c_2 = 2,
	ns_c_chaos = 3,
	ns_c_hs = 4,
	ns_c_none = 254,
	ns_c_any = 255,
	ns_c_max = 65536
} ns_class;

typedef enum __ns_key_types {
	ns_kt_rsa = 1,
	ns_kt_dh  = 2,
	ns_kt_dsa = 3,
	ns_kt_private = 254
} ns_key_types;

typedef enum __ns_cert_types {
	cert_t_pkix = 1,
	cert_t_spki = 2,
	cert_t_pgp  = 3,
	cert_t_url  = 253,
	cert_t_oid  = 254
} ns_cert_types;

#define	NS_KEY_TYPEMASK		0xC000
#define	NS_KEY_TYPE_AUTH_CONF	0x0000
#define	NS_KEY_TYPE_CONF_ONLY	0x8000
#define	NS_KEY_TYPE_AUTH_ONLY	0x4000
#define	NS_KEY_TYPE_NO_KEY	0xC000
#define	NS_KEY_NO_AUTH		0x8000
#define	NS_KEY_NO_CONF		0x4000
#define	NS_KEY_RESERVED2	0x2000
#define	NS_KEY_EXTENDED_FLAGS	0x1000
#define	NS_KEY_RESERVED4	0x0800
#define	NS_KEY_RESERVED5	0x0400
#define	NS_KEY_NAME_TYPE	0x0300
#define	NS_KEY_NAME_USER	0x0000
#define	NS_KEY_NAME_ENTITY	0x0200
#define	NS_KEY_NAME_ZONE	0x0100
#define	NS_KEY_NAME_RESERVED	0x0300
#define	NS_KEY_RESERVED8	0x0080
#define	NS_KEY_RESERVED9	0x0040
#define	NS_KEY_RESERVED10	0x0020
#define	NS_KEY_RESERVED11	0x0010
#define	NS_KEY_SIGNATORYMASK	0x000F
#define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
				  NS_KEY_RESERVED4 | \
				  NS_KEY_RESERVED5 | \
				  NS_KEY_RESERVED8 | \
				  NS_KEY_RESERVED9 | \
				  NS_KEY_RESERVED10 | \
				  NS_KEY_RESERVED11 )
#define NS_KEY_RESERVED_BITMASK2 0xFFFF
#define	NS_ALG_MD5RSA		1
#define	NS_ALG_DH               2
#define	NS_ALG_DSA              3
#define	NS_ALG_DSS              NS_ALG_DSA
#define	NS_ALG_EXPIRE_ONLY	253
#define	NS_ALG_PRIVATE_OID	254

#define NS_KEY_PROT_TLS         1
#define NS_KEY_PROT_EMAIL       2
#define NS_KEY_PROT_DNSSEC      3
#define NS_KEY_PROT_IPSEC       4
#define NS_KEY_PROT_ANY		255

#define	NS_MD5RSA_MIN_BITS	 512
#define	NS_MD5RSA_MAX_BITS	4096
#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
#define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
#define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
#define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)

#define NS_DSA_SIG_SIZE         41
#define NS_DSA_MIN_SIZE         213
#define NS_DSA_MAX_BYTES        405

#define	NS_SIG_TYPE	0
#define	NS_SIG_ALG	2
#define	NS_SIG_LABELS	3
#define	NS_SIG_OTTL	4
#define	NS_SIG_EXPIR	8
#define	NS_SIG_SIGNED	12
#define	NS_SIG_FOOT	16
#define	NS_SIG_SIGNER	18
#define	NS_NXT_BITS 8
#define	NS_NXT_BIT_SET(  n,p) (p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
#define NS_NXT_MAX 127

#define NS_OPT_DNSSEC_OK        0x8000U
#define NS_OPT_NSID		3

#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2))
#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4))
#define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2)
#define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4)

unsigned ns_get16(const unsigned char *);
unsigned long ns_get32(const unsigned char *);
void ns_put16(unsigned, unsigned char *);
void ns_put32(unsigned long, unsigned char *);

int ns_initparse(const unsigned char *, int, ns_msg *);
int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int);
int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t);


#define	__BIND		19950621

typedef struct {
	unsigned	id :16;
#if __BYTE_ORDER == __BIG_ENDIAN
	unsigned	qr: 1;
	unsigned	opcode: 4;
	unsigned	aa: 1;
	unsigned	tc: 1;
	unsigned	rd: 1;
	unsigned	ra: 1;
	unsigned	unused :1;
	unsigned	ad: 1;
	unsigned	cd: 1;
	unsigned	rcode :4;
#else
	unsigned	rd :1;
	unsigned	tc :1;
	unsigned	aa :1;
	unsigned	opcode :4;
	unsigned	qr :1;
	unsigned	rcode :4;
	unsigned	cd: 1;
	unsigned	ad: 1;
	unsigned	unused :1;
	unsigned	ra :1;
#endif
	unsigned	qdcount :16;
	unsigned	ancount :16;
	unsigned	nscount :16;
	unsigned	arcount :16;
} HEADER;

#define PACKETSZ	NS_PACKETSZ
#define MAXDNAME	NS_MAXDNAME
#define MAXCDNAME	NS_MAXCDNAME
#define MAXLABEL	NS_MAXLABEL
#define	HFIXEDSZ	NS_HFIXEDSZ
#define QFIXEDSZ	NS_QFIXEDSZ
#define RRFIXEDSZ	NS_RRFIXEDSZ
#define	INT32SZ		NS_INT32SZ
#define	INT16SZ		NS_INT16SZ
#define INT8SZ		NS_INT8SZ
#define	INADDRSZ	NS_INADDRSZ
#define	IN6ADDRSZ	NS_IN6ADDRSZ
#define	INDIR_MASK	NS_CMPRSFLGS
#define NAMESERVER_PORT	NS_DEFAULTPORT

#define S_ZONE		ns_s_zn
#define S_PREREQ	ns_s_pr
#define S_UPDATE	ns_s_ud
#define S_ADDT		ns_s_ar

#define QUERY		ns_o_query
#define IQUERY		ns_o_iquery
#define STATUS		ns_o_status
#define	NS_NOTIFY_OP	ns_o_notify
#define	NS_UPDATE_OP	ns_o_update

#define NOERROR		ns_r_noerror
#define FORMERR		ns_r_formerr
#define SERVFAIL	ns_r_servfail
#define NXDOMAIN	ns_r_nxdomain
#define NOTIMP		ns_r_notimpl
#define REFUSED		ns_r_refused
#define YXDOMAIN	ns_r_yxdomain
#define YXRRSET		ns_r_yxrrset
#define NXRRSET		ns_r_nxrrset
#define NOTAUTH		ns_r_notauth
#define NOTZONE		ns_r_notzone

#define DELETE		ns_uop_delete
#define ADD		ns_uop_add

#define T_A		ns_t_a
#define T_NS		ns_t_ns
#define T_MD		ns_t_md
#define T_MF		ns_t_mf
#define T_CNAME		ns_t_cname
#define T_SOA		ns_t_soa
#define T_MB		ns_t_mb
#define T_MG		ns_t_mg
#define T_MR		ns_t_mr
#define T_NULL		ns_t_null
#define T_WKS		ns_t_wks
#define T_PTR		ns_t_ptr
#define T_HINFO		ns_t_hinfo
#define T_MINFO		ns_t_minfo
#define T_MX		ns_t_mx
#define T_TXT		ns_t_txt
#define	T_RP		ns_t_rp
#define T_AFSDB		ns_t_afsdb
#define T_X25		ns_t_x25
#define T_ISDN		ns_t_isdn
#define T_RT		ns_t_rt
#define T_NSAP		ns_t_nsap
#define T_NSAP_PTR	ns_t_nsap_ptr
#define	T_SIG		ns_t_sig
#define	T_KEY		ns_t_key
#define	T_PX		ns_t_px
#define	T_GPOS		ns_t_gpos
#define	T_AAAA		ns_t_aaaa
#define	T_LOC		ns_t_loc
#define	T_NXT		ns_t_nxt
#define	T_EID		ns_t_eid
#define	T_NIMLOC	ns_t_nimloc
#define	T_SRV		ns_t_srv
#define T_ATMA		ns_t_atma
#define T_NAPTR		ns_t_naptr
#define T_A6		ns_t_a6
#define T_DNAME		ns_t_dname
#define	T_TSIG		ns_t_tsig
#define	T_IXFR		ns_t_ixfr
#define T_AXFR		ns_t_axfr
#define T_MAILB		ns_t_mailb
#define T_MAILA		ns_t_maila
#define T_ANY		ns_t_any

#define C_IN		ns_c_in
#define C_CHAOS		ns_c_chaos
#define C_HS		ns_c_hs
#define C_NONE		ns_c_none
#define C_ANY		ns_c_any

#define	GETSHORT		NS_GET16
#define	GETLONG			NS_GET32
#define	PUTSHORT		NS_PUT16
#define	PUTLONG			NS_PUT32

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/netdb.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NETDB_H_
COSMOPOLITAN_C_START_

struct addrinfo {
	int ai_flags;
	int ai_family;
	int ai_socktype;
	int ai_protocol;
	uint32_t ai_addrlen;
	struct sockaddr *ai_addr;
	char *ai_canonname;
	struct addrinfo *ai_next;
};

#define AI_PASSIVE      0x01
#define AI_CANONNAME    0x02
#define AI_NUMERICHOST  0x04
#define AI_V4MAPPED     0x08
#define AI_ALL          0x10
#define AI_ADDRCONFIG   0x20
#define AI_NUMERICSERV  0x400

#define NI_NUMERICHOST  0x01
#define NI_NUMERICSERV  0x02
#define NI_NOFQDN       0x04
#define NI_NAMEREQD     0x08
#define NI_DGRAM        0x10
#define NI_NUMERICSCOPE 0x100

#define EAI_BADFLAGS   -1
#define EAI_NONAME     -2
#define EAI_AGAIN      -3
#define EAI_FAIL       -4
#define EAI_FAMILY     -6
#define EAI_SOCKTYPE   -7
#define EAI_SERVICE    -8
#define EAI_MEMORY     -10
#define EAI_SYSTEM     -11
#define EAI_OVERFLOW   -12

int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
void freeaddrinfo (struct addrinfo *);
int getnameinfo (const struct sockaddr *, uint32_t, char *, uint32_t, char *, uint32_t, int);
const char *gai_strerror(int);


/* Legacy functions follow (marked OBsolete in SUS) */

struct netent {
	char *n_name;
	char **n_aliases;
	int n_addrtype;
	uint32_t n_net;
};

struct hostent {
	char *h_name;
	char **h_aliases;
	int h_addrtype;
	int h_length;
	char **h_addr_list;
};
#define h_addr h_addr_list[0]

struct servent {
	char *s_name;
	char **s_aliases;
	int s_port;
	char *s_proto;
};

struct protoent {
	char *p_name;
	char **p_aliases;
	int p_proto;
};

void sethostent (int);
void endhostent (void);
struct hostent *gethostent (void);

void setnetent (int);
void endnetent (void);
struct netent *getnetent (void);
struct netent *getnetbyaddr (uint32_t, int);
struct netent *getnetbyname (const char *);

void setservent (int);
void endservent (void);
struct servent *getservent (void);
struct servent *getservbyname (const char *, const char *);
struct servent *getservbyport (int, const char *);

void setprotoent (int);
void endprotoent (void);
struct protoent *getprotoent (void);
struct protoent *getprotobyname (const char *);
struct protoent *getprotobynumber (int);

#define NI_MAXHOST 255
#define NI_MAXSERV 32

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
struct hostent *gethostbyname (const char *);
struct hostent *gethostbyaddr (const void *, uint32_t, int);
errno_t *__h_errno_location(void) dontthrow pureconst;
#define h_errno (*__h_errno_location())
#define HOST_NOT_FOUND 1
#define TRY_AGAIN      2
#define NO_RECOVERY    3
#define NO_DATA        4
#define NO_ADDRESS     NO_DATA
#endif

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
void herror(const char *);
const char *hstrerror(int);
int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
struct hostent *gethostbyname2(const char *, int);
int gethostbyaddr_r(const void *, uint32_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
#define EAI_NODATA     -5
#define EAI_ADDRFAMILY -9
#define EAI_INPROGRESS -100
#define EAI_CANCELED   -101
#define EAI_NOTCANCELED -102
#define EAI_ALLDONE    -103
#define EAI_INTR       -104
#define EAI_IDN_ENCODE -105
#endif

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/passwd.h */

#define COSMOPOLITAN_LIBC_PASSWD_H_
COSMOPOLITAN_C_START_

struct passwd {
  char *pw_name;
  char *pw_passwd;
  uid_t pw_uid;
  gid_t pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};

void setpwent(void);
void endpwent(void);
struct passwd *getpwent(void);
struct passwd *getpwuid(uid_t);
struct passwd *getpwnam(const char *);
int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
struct passwd *fgetpwent(FILE *);
int putpwent(const struct passwd *, FILE *);

struct group {
  char *gr_name;
  char *gr_passwd;
  gid_t gr_gid;
  char **gr_mem;
};

struct group *getgrgid(gid_t);
struct group *getgrnam(const char *);
int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
struct group *getgrent(void);
void endgrent(void);
void setgrent(void);
struct group *fgetgrent(FILE *);
int putgrent(const struct group *, FILE *);
int getgrouplist(const char *, gid_t, gid_t *, int *);
int initgroups(const char *, gid_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/rand48.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RAND48_H_
COSMOPOLITAN_C_START_

double drand48(void);
double erand48(unsigned short[3]);
long int lrand48(void);
long int nrand48(unsigned short[3]);
long mrand48(void);
long jrand48(unsigned short[3]);
void srand48(long);
unsigned short *seed48(unsigned short[3]);
void lcong48(unsigned short[7]);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/resolv.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RESOLV_H_
COSMOPOLITAN_C_START_

#define MAXNS			3
#define MAXDFLSRCH		3
#define MAXDNSRCH		6
#define LOCALDOMAINPARTS	2

#define RES_TIMEOUT		5
#define MAXRESOLVSORT		10
#define RES_MAXNDOTS		15
#define RES_MAXRETRANS		30
#define RES_MAXRETRY		5
#define RES_DFLRETRY		2
#define RES_MAXTIME		65535

/* unused; purely for broken apps */
typedef struct __res_state {
	int retrans;
	int retry;
	unsigned long options;
	int nscount;
	struct sockaddr_in nsaddr_list[MAXNS];
# define nsaddr	nsaddr_list[0]
	unsigned short id;
	char *dnsrch[MAXDNSRCH+1];
	char defdname[256];
	unsigned long pfcode;
	unsigned ndots:4;
	unsigned nsort:4;
	unsigned ipv6_unavail:1;
	unsigned unused:23;
	struct {
		struct in_addr addr;
		uint32_t mask;
	} sort_list[MAXRESOLVSORT];
	void *qhook;
	void *rhook;
	int res_h_errno;
	int _vcsock;
	unsigned _flags;
	union {
		char pad[52];
		struct {
			uint16_t		nscount;
			uint16_t		nsmap[MAXNS];
			int			nssocks[MAXNS];
			uint16_t		nscount6;
			uint16_t		nsinit;
			struct sockaddr_in6	*nsaddrs[MAXNS];
			unsigned int		_initstamp[2];
		} _ext;
	} _u;
} *res_state;

#define	__RES	19960801

#ifndef _PATH_RESCONF
#define _PATH_RESCONF        "/etc/resolv.conf"
#endif

struct res_sym {
	int number;
	char *name;
	char *humanname;
};

#define	RES_F_VC	0x00000001
#define	RES_F_CONN	0x00000002
#define RES_F_EDNS0ERR	0x00000004

#define	RES_EXHAUSTIVE	0x00000001

#define RES_INIT	0x00000001
#define RES_DEBUG	0x00000002
#define RES_AAONLY	0x00000004
#define RES_USEVC	0x00000008
#define RES_PRIMARY	0x00000010
#define RES_IGNTC	0x00000020
#define RES_RECURSE	0x00000040
#define RES_DEFNAMES	0x00000080
#define RES_STAYOPEN	0x00000100
#define RES_DNSRCH	0x00000200
#define	RES_INSECURE1	0x00000400
#define	RES_INSECURE2	0x00000800
#define	RES_NOALIASES	0x00001000
#define	RES_USE_INET6	0x00002000
#define RES_ROTATE	0x00004000
#define	RES_NOCHECKNAME	0x00008000
#define	RES_KEEPTSIG	0x00010000
#define	RES_BLAST	0x00020000
#define RES_USEBSTRING	0x00040000
#define RES_NOIP6DOTINT	0x00080000
#define RES_USE_EDNS0	0x00100000
#define RES_SNGLKUP	0x00200000
#define RES_SNGLKUPREOP	0x00400000
#define RES_USE_DNSSEC	0x00800000

#define RES_DEFAULT	(RES_RECURSE|RES_DEFNAMES|RES_DNSRCH|RES_NOIP6DOTINT)

#define RES_PRF_STATS	0x00000001
#define RES_PRF_UPDATE	0x00000002
#define RES_PRF_CLASS   0x00000004
#define RES_PRF_CMD	0x00000008
#define RES_PRF_QUES	0x00000010
#define RES_PRF_ANS	0x00000020
#define RES_PRF_AUTH	0x00000040
#define RES_PRF_ADD	0x00000080
#define RES_PRF_HEAD1	0x00000100
#define RES_PRF_HEAD2	0x00000200
#define RES_PRF_TTLID	0x00000400
#define RES_PRF_HEADX	0x00000800
#define RES_PRF_QUERY	0x00001000
#define RES_PRF_REPLY	0x00002000
#define RES_PRF_INIT	0x00004000

struct __res_state *__res_state(void);
#define _res (*__res_state())

int res_init(void);
int res_query(const char *, int, int, unsigned char *, int);
int res_querydomain(const char *, const char *, int, int, unsigned char *, int);
int res_search(const char *, int, int, unsigned char *, int);
int res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
int res_send(const unsigned char *, int, unsigned char *, int);
int dn_comp(const char *, unsigned char *, int, unsigned char **, unsigned char **);
int dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
int dn_skipname(const unsigned char *, const unsigned char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/search.h */

#define COSMOPOLITAN_THIRDPARTY_MUSL_SEARCH_H

typedef enum { FIND, ENTER } ACTION;
typedef enum { preorder, postorder, endorder, leaf } VISIT;

typedef struct entry {
	char *key;
	void *data;
} ENTRY;

int hcreate(size_t);
void hdestroy(void);
ENTRY *hsearch(ENTRY, ACTION);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct hsearch_data {
	struct __tab *__tab;
	unsigned int __unused1;
	unsigned int __unused2;
};

int hcreate_r(size_t, struct hsearch_data *);
void hdestroy_r(struct hsearch_data *);
int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *);
#endif

void insque(void *, void *);
void remque(void *);

void *lsearch(const void *, void *, size_t *, size_t,
	int (*)(const void *, const void *));
void *lfind(const void *, const void *, size_t *, size_t,
	int (*)(const void *, const void *));

void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *));
void *tfind(const void *, void *const *, int(*)(const void *, const void *));
void *tsearch(const void *, void **, int (*)(const void *, const void *));
void twalk(const void *, void (*)(const void *, VISIT, int));

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct qelem {
	struct qelem *q_forw, *q_back;
	char q_data[1];
};

void tdestroy(void *, void (*)(void *));
#endif



/*!BEGIN third_party/musl/shadow.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_SHADOW_H_
COSMOPOLITAN_C_START_

#define	SHADOW "/etc/shadow"

struct spwd {
	char *sp_namp;
	char *sp_pwdp;
	long sp_lstchg;
	long sp_min;
	long sp_max;
	long sp_warn;
	long sp_inact;
	long sp_expire;
	unsigned long sp_flag;
};

void setspent(void);
void endspent(void);
struct spwd *getspent(void);
struct spwd *fgetspent(FILE *);
struct spwd *sgetspent(const char *);
int putspent(const struct spwd *, FILE *);

struct spwd *getspnam(const char *);
int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **);

int lckpwdf(void);
int ulckpwdf(void);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/tempnam.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_TEMPNAM_H_
COSMOPOLITAN_C_START_

char *tempnam(const char *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/zlib/zconf.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZCONF_H_

#define STDC
#define STDC99
#define MAX_MEM_LEVEL 9
#define DEF_MEM_LEVEL 8
#define MAX_WBITS     15 /* 32K LZ77 window */

#ifdef MODE_DBG
#define ZLIB_DEBUG
#endif

#define z_const const

#define Z_COSMO_PREFIX_SET

#define Bytef                    _Cz_Bytef
#define _dist_code               _Cz__dist_code
#define _length_code             _Cz__length_code
#define _tr_align                _Cz__tr_align
#define _tr_flush_bits           _Cz__tr_flush_bits
#define _tr_flush_block          _Cz__tr_flush_block
#define _tr_init                 _Cz__tr_init
#define _tr_stored_block         _Cz__tr_stored_block
#define _tr_tally                _Cz__tr_tally
#define adler32                  _Cz_adler32
#define adler32_combine          _Cz_adler32_combine
#define adler32_combine64        _Cz_adler32_combine64
#define adler32_simd_            _Cz_adler32_simd_
#define adler32_z                _Cz_adler32_z
#define alloc_func               _Cz_alloc_func
#define arm_check_features       _Cz_arm_check_features
#define arm_cpu_enable_crc32     _Cz_arm_cpu_enable_crc32
#define arm_cpu_enable_pmull     _Cz_arm_cpu_enable_pmull
#define armv8_crc32_little       _Cz_armv8_crc32_little
#define armv8_crc32_pmull_little _Cz_armv8_crc32_pmull_little
#define charf                    _Cz_charf
#define compress                 _Cz_compress
#define compress2                _Cz_compress2
#define compressBound            _Cz_compressBound
#define copy_with_crc            _Cz_copy_with_crc
#define cpu_check_features       _Cz_cpu_check_features
#define crc32                    _Cz_crc32
#define crc32_combine            _Cz_crc32_combine
#define crc32_combine64          _Cz_crc32_combine64
#define crc32_combine_gen        _Cz_crc32_combine_gen
#define crc32_combine_gen64      _Cz_crc32_combine_gen64
#define crc32_combine_op         _Cz_crc32_combine_op
#define crc32_sse42_simd_        _Cz_crc32_sse42_simd_
#define crc32_z                  _Cz_crc32_z
#define crc_finalize             _Cz_crc_finalize
#define crc_fold_512to32         _Cz_crc_fold_512to32
#define crc_fold_copy            _Cz_crc_fold_copy
#define crc_fold_init            _Cz_crc_fold_init
#define crc_reset                _Cz_crc_reset
#define deflate                  _Cz_deflate
#define deflateBound             _Cz_deflateBound
#define deflateCopy              _Cz_deflateCopy
#define deflateEnd               _Cz_deflateEnd
#define deflateGetDictionary     _Cz_deflateGetDictionary
#define deflateInit              _Cz_deflateInit
#define deflateInit2             _Cz_deflateInit2
#define deflateParams            _Cz_deflateParams
#define deflatePending           _Cz_deflatePending
#define deflatePrime             _Cz_deflatePrime
#define deflateReset             _Cz_deflateReset
#define deflateResetKeep         _Cz_deflateResetKeep
#define deflateSetDictionary     _Cz_deflateSetDictionary
#define deflateSetHeader         _Cz_deflateSetHeader
#define deflateTune              _Cz_deflateTune
#define deflate_copyright        _Cz_deflate_copyright
#define deflate_read_buf         _Cz_deflate_read_buf
#define fill_window_sse          _Cz_fill_window_sse
#define free_func                _Cz_free_func
#define get_crc_table            _Cz_get_crc_table
#define gzFile                   _Cz_gzFile
#define gz_error                 _Cz_gz_error
#define gz_header                _Cz_gz_header
#define gz_header_s              _Cz_gz_header_s
#define gz_headerp               _Cz_gz_headerp
#define gz_intmax                _Cz_gz_intmax
#define gz_strwinerror           _Cz_gz_strwinerror
#define gzbuffer                 _Cz_gzbuffer
#define gzclearerr               _Cz_gzclearerr
#define gzclose                  _Cz_gzclose
#define gzclose_r                _Cz_gzclose_r
#define gzclose_w                _Cz_gzclose_w
#define gzdirect                 _Cz_gzdirect
#define gzdopen                  _Cz_gzdopen
#define gzeof                    _Cz_gzeof
#define gzerror                  _Cz_gzerror
#define gzflush                  _Cz_gzflush
#define gzfread                  _Cz_gzfread
#define gzfwrite                 _Cz_gzfwrite
#define gzgetc                   _Cz_gzgetc
#define gzgetc_                  _Cz_gzgetc_
#define gzgets                   _Cz_gzgets
#define gzoffset                 _Cz_gzoffset
#define gzoffset64               _Cz_gzoffset64
#define gzopen                   _Cz_gzopen
#define gzopen64                 _Cz_gzopen64
#define gzopen_w                 _Cz_gzopen_w
#define gzprintf                 _Cz_gzprintf
#define gzputc                   _Cz_gzputc
#define gzputs                   _Cz_gzputs
#define gzread                   _Cz_gzread
#define gzrewind                 _Cz_gzrewind
#define gzseek                   _Cz_gzseek
#define gzseek64                 _Cz_gzseek64
#define gzsetparams              _Cz_gzsetparams
#define gztell                   _Cz_gztell
#define gztell64                 _Cz_gztell64
#define gzungetc                 _Cz_gzungetc
#define gzvprintf                _Cz_gzvprintf
#define gzwrite                  _Cz_gzwrite
#define in_func                  _Cz_in_func
#define inflate                  _Cz_inflate
#define inflateBack              _Cz_inflateBack
#define inflateBackEnd           _Cz_inflateBackEnd
#define inflateBackInit_         _Cz_inflateBackInit_
#define inflateCodesUsed         _Cz_inflateCodesUsed
#define inflateCopy              _Cz_inflateCopy
#define inflateEnd               _Cz_inflateEnd
#define inflateGetDictionary     _Cz_inflateGetDictionary
#define inflateGetHeader         _Cz_inflateGetHeader
#define inflateInit              _Cz_inflateInit
#define inflateInit2             _Cz_inflateInit2
#define inflateMark              _Cz_inflateMark
#define inflatePrime             _Cz_inflatePrime
#define inflateReset             _Cz_inflateReset
#define inflateReset2            _Cz_inflateReset2
#define inflateResetKeep         _Cz_inflateResetKeep
#define inflateSetDictionary     _Cz_inflateSetDictionary
#define inflateSync              _Cz_inflateSync
#define inflateSyncPoint         _Cz_inflateSyncPoint
#define inflateUndermine         _Cz_inflateUndermine
#define inflateValidate          _Cz_inflateValidate
#define inflate_copyright        _Cz_inflate_copyright
#define inflate_fast             _Cz_inflate_fast
#define inflate_fast_chunk_      _Cz_inflate_fast_chunk_
#define inflate_table            _Cz_inflate_table
#define intf                     _Cz_intf
#define out_func                 _Cz_out_func
#define uInt                     _Cz_uInt
#define uIntf                    _Cz_uIntf
#define uLong                    _Cz_uLong
#define uLongf                   _Cz_uLongf
#define uncompress               _Cz_uncompress
#define uncompress2              _Cz_uncompress2
#define voidp                    _Cz_voidp
#define voidpc                   _Cz_voidpc
#define voidpf                   _Cz_voidpf
#define x86_check_features       _Cz_x86_check_features
#define x86_cpu_enable_simd      _Cz_x86_cpu_enable_simd
#define x86_cpu_enable_sse2      _Cz_x86_cpu_enable_sse2
#define x86_cpu_enable_ssse3     _Cz_x86_cpu_enable_ssse3
#define zError                   _Cz_zError
#define z_errmsg                 _Cz_z_errmsg
#define zcalloc                  _Cz_zcalloc
#define zcfree                   _Cz_zcfree
#define zlibCompileFlags         _Cz_zlibCompileFlags
#define zlibVersion              _Cz_zlibVersion


typedef unsigned char Byte;
typedef unsigned int uInt;   /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef Byte Bytef;
typedef char charf;
typedef int intf;
typedef uInt uIntf;
typedef uLong uLongf;
typedef void const *voidpc;
typedef void *voidpf;
typedef void *voidp;
typedef uint32_t z_crc_t;
typedef int64_t z_off64_t;
typedef size_t z_size_t;



/*!BEGIN third_party/zlib/zlib.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZLIB_H_

/**
 * @fileoverview zlib
 *
 * The 'zlib' compression library provides in-memory
 * compression and decompression functions, including integrity checks
 * of the uncompressed data. This version of the library supports only
 * one compression method (deflation) but other algorithms will be added
 * later and will have the same stream interface.
 *
 * Compression can be done in a single step if the buffers are large enough,
 * or can be done by repeated calls of the compression function.  In the latter
 * case, the application must provide more input and/or consume the output
 * (providing more output space) before each call.
 *
 * The compressed data format used by default by the in-memory functions is
 * the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
 * around a deflate stream, which is itself documented in RFC 1951.
 *
 * The library also supports reading and writing files in gzip (.gz) format
 * with an interface similar to that of stdio using the functions that start
 * with "gz".  The gzip format is different from the zlib format.  gzip is a
 * gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
 *
 * This library can optionally read and write gzip and raw deflate streams in
 * memory as well.
 *
 * The zlib format was designed to be compact and fast for use in memory
 * and on communications channels.  The gzip format was designed for single-
 * file compression on file systems, has a larger header than zlib to maintain
 * directory information, and uses a different, slower check method than zlib.
 *
 * The library does not install any signal handler.  The decoder checks
 * the consistency of the compressed data, so the library should never crash
 * even in the case of corrupted input.
 */

#define ZLIB_VERSION         "1.2.11"
#define ZLIB_VERNUM          0x12b0
#define ZLIB_VER_MAJOR       1
#define ZLIB_VER_MINOR       2
#define ZLIB_VER_REVISION    11
#define ZLIB_VER_SUBREVISION 0

/**
 * The application must update next_in and avail_in when avail_in has
 * dropped to zero. It must update next_out and avail_out when avail_out
 * has dropped to zero. The application must initialize zalloc, zfree
 * and opaque before calling the init function. All other fields are set
 * by the compression library and must not be updated by the
 * application.
 *
 * The opaque value provided by the application will be passed as the
 * first parameter for calls of zalloc and zfree. This can be useful for
 * custom memory management. The compression library attaches no meaning
 * to the opaque value.
 *
 * zalloc must return Z_NULL if there is not enough memory for the
 * object. If zlib is used in a multi-threaded application, zalloc and
 * zfree must be thread safe. In that case, zlib is thread-safe. When
 * zalloc and zfree are Z_NULL on entry to the initialization function,
 * they are set to internal routines that use the standard library
 * functions malloc() and free().
 *
 * On 16-bit systems, the functions zalloc and zfree must be able to
 * allocate exactly 65536 bytes, but will not be required to allocate
 * more than this if the symbol MAXSEG_64K is defined (see zconf.h).
 * WARNING: On MSDOS, pointers returned by zalloc for objects of exactly
 * 65536 bytes *must* have their offset normalized to zero. The default
 * allocation function provided by this library ensures this (see
 * zutil.c). To reduce memory requirements and avoid any allocation of
 * 64K objects, at the expense of compression ratio, compile the library
 * with -DMAX_WBITS=14 (see zconf.h).
 *
 * The fields total_in and total_out can be used for statistics or
 * progress reports. After compression, total_in holds the total size of
 * the uncompressed data and may be saved for use by the decompressor
 * (particularly if the decompressor wants to decompress everything in a
 * single step).
 */
#define Z_NO_FLUSH      0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH    2
#define Z_FULL_FLUSH    3
#define Z_FINISH        4
#define Z_BLOCK         5
#define Z_TREES         6

/**
 * Allowed flush values; see deflate() and inflate() below for details.
 */
#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO         (-1)
#define Z_STREAM_ERROR  (-2)
#define Z_DATA_ERROR    (-3)
#define Z_MEM_ERROR     (-4)
#define Z_BUF_ERROR     (-5)
#define Z_VERSION_ERROR (-6)

/**
 * Return codes for the compression/decompression functions. Negative
 * values are errors, positive values are used for special but normal
 * events.
 */
#define Z_NO_COMPRESSION      0
#define Z_BEST_SPEED          1
#define Z_BEST_COMPRESSION    9
#define Z_DEFAULT_COMPRESSION (-1)

/**
 * Compression levels.
 */
#define Z_FILTERED         1
#define Z_HUFFMAN_ONLY     2
#define Z_RLE              3
#define Z_FIXED            4
#define Z_DEFAULT_STRATEGY 0

/**
 * Compression strategy; see deflateInit2() below for details
 */
#define Z_BINARY  0
#define Z_TEXT    1
#define Z_ASCII   Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN 2

/**
 * Possible values of the data_type field for deflate()
 */
#define Z_DEFLATED 8

/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */

COSMOPOLITAN_C_START_

typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
typedef void (*free_func)(voidpf opaque, voidpf address);

struct internal_state;

typedef struct z_stream_s {
  const Bytef *next_in;         /* next input byte */
  uInt avail_in;                /* number of bytes available at next_in */
  uLong total_in;               /* total number of input bytes read so far */
  Bytef *next_out;              /* next output byte will go here */
  uInt avail_out;               /* remaining free space at next_out */
  uLong total_out;              /* total number of bytes output so far */
  const char *msg;              /* last error message, NULL if no error */
  struct internal_state *state; /* not visible by applications */
  alloc_func zalloc;            /* used to allocate the internal state */
  free_func zfree;              /* used to free the internal state */
  voidpf opaque;  /* private data object passed to zalloc and zfree */
  int data_type;  /* best guess about the data type: binary or text
                     for deflate, or the decoding state for inflate */
  uLong adler;    /* Adler-32 or CRC-32 value of the uncompressed data */
  uLong reserved; /* reserved for future use */
} z_stream;

typedef z_stream *z_streamp;

/**
 * gzip header information passed to and from zlib routines. See RFC
 * 1952 for more details on the meanings of these fields.
 */
typedef struct gz_header_s {
  int text;       /* true if compressed data believed to be text */
  uLong time_;    /* modification time */
  int xflags;     /* extra flags (not used when writing a gzip file) */
  int os;         /* operating system */
  Bytef *extra;   /* pointer to extra field or Z_NULL if none */
  uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  uInt extra_max; /* space at extra (only when reading header) */
  Bytef *name;    /* pointer to zero-terminated file name or Z_NULL */
  uInt name_max;  /* space at name (only when reading header) */
  Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  uInt comm_max;  /* space at comment (only when reading header) */
  int hcrc;       /* true if there was or will be a header crc */
  int done;       /* true when done reading gzip header (not used
                     when writing a gzip file) */
} gz_header;

typedef gz_header *gz_headerp;

#define zlib_version zlibVersion()

/**
 * The application can compare zlibVersion and ZLIB_VERSION for consistency.
 * If the first character differs, the library code actually used is not
 * compatible with the zlib.h header file used by the application.  This check
 * is automatically made by deflateInit and inflateInit.
 */
const char *zlibVersion(void);

/**
 * Initializes the internal stream state for compression.  The fields
 * zalloc, zfree and opaque must be initialized before by the caller.  If
 * zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
 * allocation functions.
 *
 * The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
 * 1 gives best speed, 9 gives best compression, 0 gives no compression at all
 * (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION
 * requests a default compromise between speed and compression (currently
 * equivalent to level 6).
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if level is not a valid compression level. msg
 *     is set to null if there is no error message. deflateInit does not
 *     perform any compression: this will be done by deflate().
 */
int deflateInit(z_streamp strm, int level);

/**
 * deflate compresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full. It may
 * introduce some output latency (reading input without producing any
 * output) except when forced to flush.
 *
 * The detailed semantics are as follows. deflate performs one or both
 * of the following actions:
 *
 * - Compress more input starting at next_in and update next_in and
 *  avail_in accordingly. If not all input can be processed (because
 *  there is not enough room in the output buffer), next_in and avail_in
 *  are updated and processing will resume at this point for the next
 *  call of deflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *  avail_out accordingly. This action is forced if the parameter flush
 *  is non zero. Forcing flush frequently degrades the compression
 *  ratio, so this parameter should be set only when necessary. Some
 *  output may be provided even if flush is zero.
 *
 * Before the call of deflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating avail_in or avail_out
 * accordingly; avail_out should never be zero before the call. The
 * application can consume the compressed output when it wants, for
 * example when the output buffer is full (avail_out == 0), or after
 * each call of deflate(). If deflate returns Z_OK and with zero
 * avail_out, it must be called again after making room in the output
 * buffer because there might be more output pending. See
 * deflatePending(), which can be used if desired to determine whether
 * or not there is more ouput in that case.
 *
 * Normally the parameter flush is set to Z_NO_FLUSH, which allows
 * deflate to decide how much data to accumulate before producing
 * output, in order to maximize compression.
 *
 * If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
 * flushed to the output buffer and the output is aligned on a byte
 * boundary, so that the decompressor can get all input data available
 * so far. (In particular avail_in is zero after the call if enough
 * output space has been provided before the call.) Flushing may degrade
 * compression for some compression algorithms and so it should be used
 * only when necessary. This completes the current deflate block and
 * follows it with an empty stored block that is three bits plus filler
 * bits to the next byte, followed by four bytes (00 00 ff ff).
 *
 * If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to
 * the output buffer, but the output is not aligned to a byte boundary.
 * All of the input data so far will be available to the decompressor,
 * as for Z_SYNC_FLUSH. This completes the current deflate block and
 * follows it with an empty fixed codes block that is 10 bits long. This
 * assures that enough bytes are output in order for the decompressor to
 * finish the block before the empty fixed codes block.
 *
 * If flush is set to Z_BLOCK, a deflate block is completed and emitted,
 * as for Z_SYNC_FLUSH, but the output is not aligned on a byte
 * boundary, and up to seven bits of the current block are held to be
 * written as the next byte after the next deflate block is completed.
 * In this case, the decompressor may not be provided enough bits at
 * this point in order to complete decompression of the data provided so
 * far to the compressor. It may need to wait for the next block to be
 * emitted. This is for advanced applications that need to control the
 * emission of deflate blocks.
 *
 * If flush is set to Z_FULL_FLUSH, all output is flushed as with
 * Z_SYNC_FLUSH, and the compression state is reset so that
 * decompression can restart from this point if previous compressed data
 * has been damaged or if random access is desired. Using Z_FULL_FLUSH
 * too often can seriously degrade compression.
 *
 * If deflate returns with avail_out == 0, this function must be called
 * again with the same value of the flush parameter and more output
 * space (updated avail_out), until the flush is complete (deflate
 * returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or
 * Z_SYNC_FLUSH, make sure that avail_out is greater than six to avoid
 * repeated flush markers due to avail_out == 0 on return.
 *
 * If the parameter flush is set to Z_FINISH, pending input is
 * processed, pending output is flushed and deflate returns with
 * Z_STREAM_END if there was enough output space. If deflate returns
 * with Z_OK or Z_BUF_ERROR, this function must be called again with
 * Z_FINISH and more output space (updated avail_out) but no more input
 * data, until it returns with Z_STREAM_END or an error. After deflate
 * has returned Z_STREAM_END, the only possible operations on the stream
 * are deflateReset or deflateEnd.
 *
 * Z_FINISH can be used in the first deflate call after deflateInit if
 * all the compression is to be done in a single step. In order to
 * complete in one call, avail_out must be at least the value returned
 * by deflateBound (see below). Then deflate is guaranteed to return
 * Z_STREAM_END. If not enough output space is provided, deflate will
 * not return Z_STREAM_END, and it must be called again as described
 * above.
 *
 * deflate() sets strm->adler to the Adler-32 checksum of all input read
 * so far (that is, total_in bytes). If a gzip stream is being
 * generated, then strm->adler will be the CRC-32 checksum of the input
 * read so far. (See deflateInit2 below.)
 *
 * deflate() may update strm->data_type if it can make a good guess about
 * the input data type (Z_BINARY or Z_TEXT).  If in doubt, the data is
 * considered binary.  This field is only for information purposes and does not
 * affect the compression algorithm in any manner.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if all input has been
 *     consumed and all output has been produced (only when flush is set
 *     to Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent
 *     (for example if next_in or next_out was Z_NULL or the state was
 *     inadvertently written over by the application), or Z_BUF_ERROR if
 *     no progress is possible (for example avail_in or avail_out was
 *     zero). Note that Z_BUF_ERROR is not fatal, and deflate() can be
 *     called again with more input and more output space to continue
 *     compressing.
 */
int deflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the stream state was
 *     inconsistent, Z_DATA_ERROR if the stream was freed prematurely
 *     (some input or output was discarded). In the error case, msg may
 *     be set but then points to a static string (which must not be
 *     deallocated).
 */
int deflateEnd(z_streamp strm);

/**
 * Initializes the internal stream state for decompression. The fields
 * next_in, avail_in, zalloc, zfree and opaque must be initialized
 * before by the caller. In the current version of inflate, the provided
 * input is not read or consumed. The allocation of a sliding window
 * will be deferred to the first call of inflate (if the decompression
 * does not complete on the first call). If zalloc and zfree are set to
 * Z_NULL, inflateInit updates them to use default allocation functions.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit does not perform any decompression. Actual
 *     decompression will be done by inflate(). So next_in, and
 *     avail_in, next_out, and avail_out are unused and unchanged. The
 *     current implementation of inflateInit() does not process any
 *     header information -- that is deferred until inflate() is called.
 */
int inflateInit(z_streamp strm);

/**
 * inflate decompresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full.  It may introduce
 * some output latency (reading input without producing any output) except when
 * forced to flush.
 *
 * The detailed semantics are as follows.  inflate performs one or both of the
 * following actions:
 *
 * - Decompress more input starting at next_in and update next_in and
 *   avail_in accordingly. If not all input can be processed (because
 *   there is not enough room in the output buffer), then next_in and
 *   avail_in are updated accordingly, and processing will resume at
 *   this point for the next call of inflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *   avail_out accordingly. inflate() provides as much output as
 *   possible, until there is no more input data or no more space in the
 *   output buffer (see below about the flush parameter).
 *
 * Before the call of inflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating the next_* and avail_* values
 * accordingly. If the caller of inflate() does not provide both
 * available input and available output space, it is possible that there
 * will be no progress made. The application can consume the
 * uncompressed output when it wants, for example when the output buffer
 * is full (avail_out == 0), or after each call of inflate(). If inflate
 * returns Z_OK and with zero avail_out, it must be called again after
 * making room in the output buffer because there might be more output
 * pending.
 *
 * The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
 * Z_FINISH, Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate()
 * flush as much output as possible to the output buffer. Z_BLOCK
 * requests that inflate() stop if and when it gets to the next deflate
 * block boundary. When decoding the zlib or gzip format, this will
 * cause inflate() to return immediately after the header and before the
 * first block. When doing a raw inflate, inflate() will go ahead and
 * process the first block, and will return when it gets to the end of
 * that block, or when it runs out of data.
 *
 * The Z_BLOCK option assists in appending to or combining deflate
 * streams. To assist in this, on return inflate() always sets
 * strm->data_type to the number of unused bits in the last byte taken
 * from strm->next_in, plus 64 if inflate() is currently decoding the
 * last block in the deflate stream, plus 128 if inflate() returned
 * immediately after decoding an end-of-block code or decoding the
 * complete header up to just before the first byte of the deflate
 * stream. The end-of-block will not be indicated until all of the
 * uncompressed data from that block has been written to strm->next_out.
 * The number of unused bits may in general be greater than seven,
 * except when bit 7 of data_type is set, in which case the number of
 * unused bits will be less than eight. data_type is set as noted here
 * every time inflate() returns for all flush options, and so can be
 * used to determine the amount of currently consumed input in bits.
 *
 * The Z_TREES option behaves as Z_BLOCK does, but it also returns when
 * the end of each deflate block header is reached, before any actual
 * data in that block is decoded. This allows the caller to determine
 * the length of the deflate block header for later use in random access
 * within a deflate block. 256 is added to the value of strm->data_type
 * when inflate() returns immediately after reaching the end of the
 * deflate block header.
 *
 * inflate() should normally be called until it returns Z_STREAM_END or
 * an error. However if all decompression is to be performed in a single
 * step (a single call of inflate), the parameter flush should be set to
 * Z_FINISH. In this case all pending input is processed and all pending
 * output is flushed; avail_out must be large enough to hold all of the
 * uncompressed data for the operation to complete. (The size of the
 * uncompressed data may have been saved by the compressor for this
 * purpose.) The use of Z_FINISH is not required to perform an inflation
 * in one step. However it may be used to inform inflate that a faster
 * approach can be used for the single inflate() call. Z_FINISH also
 * informs inflate to not maintain a sliding window if the stream
 * completes, which reduces inflate's memory footprint. If the stream
 * does not complete, either because not all of the stream is provided
 * or not enough output space is provided, then a sliding window will be
 * allocated and inflate() can be called again to continue the operation
 * as if Z_NO_FLUSH had been used.
 *
 * In this implementation, inflate() always flushes as much output as
 * possible to the output buffer, and always uses the faster approach on
 * the first call. So the effects of the flush parameter in this
 * implementation are on the return value of inflate() as noted below,
 * when inflate() returns early when Z_BLOCK or Z_TREES is used, and
 * when inflate() avoids the allocation of memory for a sliding window
 * when Z_FINISH is used.
 *
 * If a preset dictionary is needed after this call (see
 * inflateSetDictionary below), inflate sets strm->adler to the Adler-32
 * checksum of the dictionary chosen by the compressor and returns
 * Z_NEED_DICT; otherwise it sets strm->adler to the Adler-32 checksum
 * of all output produced so far (that is, total_out bytes) and returns
 * Z_OK, Z_STREAM_END or an error code as described below. At the end of
 * the stream, inflate() checks that its computed Adler-32 checksum is
 * equal to that saved by the compressor and returns Z_STREAM_END only
 * if the checksum is correct.
 *
 * inflate() can decompress and check either zlib-wrapped or
 * gzip-wrapped deflate data. The header type is detected automatically,
 * if requested when initializing with inflateInit2(). Any information
 * contained in the gzip header is not retained unless
 * inflateGetHeader() is used. When processing gzip-wrapped deflate
 * data, strm->adler32 is set to the CRC-32 of the output produced so
 * far. The CRC-32 is checked against the gzip trailer, as is the
 * uncompressed length, modulo 2^32.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if the end of the compressed
 *     data has been reached and all uncompressed output has been
 *     produced, Z_NEED_DICT if a preset dictionary is needed at this
 *     point, Z_DATA_ERROR if the input data was corrupted (input stream
 *     not conforming to the zlib format or incorrect check value, in
 *     which case strm->msg points to a string with a more specific
 *     error), Z_STREAM_ERROR if the stream structure was inconsistent
 *     (for example next_in or next_out was Z_NULL, or the state was
 *     inadvertently written over by the application), Z_MEM_ERROR if
 *     there was not enough memory, Z_BUF_ERROR if no progress was
 *     possible or if there was not enough room in the output buffer
 *     when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
 *     inflate() can be called again with more input and more output
 *     space to continue decompressing. If Z_DATA_ERROR is returned, the
 *     application may then call inflateSync() to look for a good
 *     compression block if a partial recovery of the data is to be
 *     attempted.
 */
int inflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK or Z_STREAM_ERROR if stream state inconsistent
 */
int inflateEnd(z_streamp strm);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » special functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  the following functions are needed only in some special applications */

/**
 * This is another version of deflateInit with more compression options.
 * The fields next_in, zalloc, zfree and opaque must be initialized
 * before by the caller.
 *
 * The method parameter is the compression method. It must be Z_DEFLATED
 * in this version of the library.
 *
 * The windowBits parameter is the base two logarithm of the window size
 * (the size of the history buffer). It should be in the range 8..15 for
 * this version of the library. Larger values of this parameter result
 * in better compression at the expense of memory usage. The default
 * value is 15 if deflateInit is used instead.
 *
 * For the current implementation of deflate(), a windowBits value of 8
 * (a window size of 256 bytes) is not supported. As a result, a request
 * for 8 will result in 9 (a 512-byte window). In that case, providing 8
 * to inflateInit2() will result in an error when the zlib header with 9
 * is checked against the initialization of inflate(). The remedy is to
 * not use 8 with deflateInit2() with this initialization, or at least
 * in that case use 9 with inflateInit2().
 *
 * windowBits can also be -8..-15 for raw deflate. In this case,
 * -windowBits determines the window size. deflate() will then generate
 * raw deflate data with no zlib header or trailer, and will not compute
 * a check value.
 *
 * windowBits can also be greater than 15 for optional gzip encoding.
 * Add 16 to windowBits to write a simple gzip header and trailer around
 * the compressed data instead of a zlib wrapper. The gzip header will
 * have no file name, no extra data, no comment, no modification time
 * (set to zero), no header crc, and the operating system will be set to
 * the appropriate value, if the operating system was determined at
 * compile time. If a gzip stream is being written, strm->adler is a
 * CRC-32 instead of an Adler-32.
 *
 * For raw deflate or gzip encoding, a request for a 256-byte window is
 * rejected as invalid, since only the zlib header provides a means of
 * transmitting the window size to the decompressor.
 *
 * The memLevel parameter specifies how much memory should be allocated
 * for the internal compression state. memLevel=1 uses minimum memory
 * but is slow and reduces compression ratio; memLevel=9 uses maximum
 * memory for optimal speed. The default value is 8. See zconf.h for
 * total memory usage as a function of windowBits and memLevel.
 *
 * The strategy parameter is used to tune the compression algorithm. Use
 * the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
 * produced by a filter (or predictor), Z_HUFFMAN_ONLY to force Huffman
 * encoding only (no string match), or Z_RLE to limit match distances to
 * one (run-length encoding). Filtered data consists mostly of small
 * values with a somewhat random distribution. In this case, the
 * compression algorithm is tuned to compress them better. The effect of
 * Z_FILTERED is to force more Huffman coding and less string matching;
 * it is somewhat intermediate between Z_DEFAULT_STRATEGY and
 * Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
 * Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
 * strategy parameter only affects the compression ratio but not the
 * correctness of the compressed output even if it is not set
 * appropriately. Z_FIXED prevents the use of dynamic Huffman codes,
 * allowing for a simpler decoder for special applications.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if any parameter is invalid (such as an invalid
 *     method). msg is set to null if there is no error message.
 *     deflateInit2 does not perform any compression: this will be done
 *     by deflate().
 */
int deflateInit2(z_streamp strm, int level, int method, int windowBits,
                 int memLevel, int strategy);

/**
 * Initializes the compression dictionary from the given byte sequence
 * without producing any compressed output. When using the zlib format,
 * this function must be called immediately after deflateInit,
 * deflateInit2 or deflateReset, and before any call of deflate. When
 * doing raw deflate, this function must be called either before any
 * call of deflate, or immediately after the completion of a deflate
 * block, i.e. after all input has been consumed and all output has been
 * delivered when using any of the flush options Z_BLOCK,
 * Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The compressor and
 * decompressor must use exactly the same dictionary (see
 * inflateSetDictionary).
 *
 * The dictionary should consist of strings (byte sequences) that are
 * likely to be encountered later in the data to be compressed, with the
 * most commonly used strings preferably put towards the end of the
 * dictionary. Using a dictionary is most useful when the data to be
 * compressed is short and can be predicted with good accuracy; the data
 * can then be compressed better than with the default empty dictionary.
 *
 * Depending on the size of the compression data structures selected by
 * deflateInit or deflateInit2, a part of the dictionary may in effect
 * be discarded, for example if the dictionary is larger than the window
 * size provided in deflateInit or deflateInit2. Thus the strings most
 * likely to be useful should be put at the end of the dictionary, not
 * at the front. In addition, the current implementation of deflate will
 * use at most the window size minus 262 bytes of the provided
 * dictionary.
 *
 * Upon return of this function, strm->adler is set to the Adler-32
 * value of the dictionary; the decompressor may later use this value to
 * determine which dictionary has been used by the compressor. (The
 * Adler-32 value applies to the whole dictionary even if only a subset
 * of the dictionary is actually used by the compressor.) If a raw
 * deflate was requested, then the Adler-32 value is not computed and
 * strm->adler is not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent (for example if deflate has already been called for
 *     this stream or if not at a block boundary for raw deflate).
 *     deflateSetDictionary does not perform any compression: this will
 *     be done by deflate().
 */
int deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by deflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If deflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * deflateGetDictionary() may return a length less than the window size, even
 * when more than the window size in input has been provided. It may return up
 * to 258 bytes less in that case, due to how zlib's implementation of deflate
 * manages the sliding window and lookahead for matches, where matches can be
 * up to 258 bytes long. If the application needs the last window-size bytes of
 * input, then that would need to be saved by the application outside of zlib.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int deflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Sets destination stream as a complete copy of the source stream.
 *
 * This function can be useful when several compression strategies will be
 * tried, for example when there are several ways of pre-processing the input
 * data with a filter.  The streams that will be discarded should then be freed
 * by calling deflateEnd.  Note that deflateCopy duplicates the internal
 * compression state which can be quite large, so this strategy is slow and can
 * consume lots of memory.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int deflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to deflateEnd followed by deflateInit, but
 * does not free and reallocate the internal compression state.  The stream
 * will leave the compression level and any other attributes that may have been
 * set unchanged.
 *
 * deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 * stream state was inconsistent (such as zalloc or state being Z_NULL).
 */
int deflateReset(z_streamp strm);

/**
 * Dynamically update the compression level and compression strategy.  The
 * interpretation of level and strategy is as in deflateInit2().  This can be
 * used to switch between compression and straight copy of the input data, or
 * to switch to a different kind of input data requiring a different strategy.
 * If the compression approach (which is a function of the level) or the
 * strategy is changed, and if any input has been consumed in a previous
 * deflate() call, then the input available so far is compressed with the old
 * level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
 * for the compression levels 0, 1..3, and 4..9 respectively.  The new level
 * and strategy will take effect at the next call of deflate().
 *
 * If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
 * not have enough output space to complete, then the parameter change will not
 * take effect.  In this case, deflateParams() can be called again with the
 * same parameters and more output space to try again.
 *
 * In order to assure a change in the parameters on the first try, the
 * deflate stream should be flushed using deflate() with Z_BLOCK or other flush
 * request until strm.avail_out is not zero, before calling deflateParams().
 * Then no more input data should be provided before the deflateParams() call.
 * If this is done, the old level and strategy will be applied to the data
 * compressed before deflateParams(), and the new level and strategy will be
 * applied to the the data compressed after deflateParams().
 *
 * deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
 * state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
 * there was not enough output space to complete the compression of the
 * available input data before a change in the strategy or approach.  Note that
 * in the case of a Z_BUF_ERROR, the parameters are not changed.  A return
 * value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
 * retried with more output space.
 */
int deflateParams(z_streamp strm, int level, int strategy);

/**
 * Fine tune deflate's internal compression parameters. This should only
 * be used by someone who understands the algorithm used by zlib's
 * deflate for searching for the best matching string, and even then
 * only by the most fanatic optimizer trying to squeeze out the last
 * compressed bit for their specific input data. Read the deflate.c
 * source code for the meaning of the max_lazy, good_length,
 * nice_length, and max_chain parameters.
 *
 * deflateTune() can be called after deflateInit() or deflateInit2(), and
 * returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
 */
int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
                int max_chain);

/**
 * deflateBound() returns an upper bound on the compressed size after
 * deflation of sourceLen bytes. It must be called after deflateInit()
 * or deflateInit2(), and after deflateSetHeader(), if used. This would
 * be used to allocate an output buffer for deflation in a single pass,
 * and so would be called before deflate(). If that first deflate() call
 * is provided the sourceLen input bytes, an output buffer allocated to
 * the size returned by deflateBound(), and the flush value Z_FINISH,
 * then deflate() is guaranteed to return Z_STREAM_END. Note that it is
 * possible for the compressed size to be larger than the value returned
 * by deflateBound() if flush options other than Z_FINISH or Z_NO_FLUSH
 * are used.
 */
uLong deflateBound(z_streamp strm, uLong sourceLen);

/**
 * deflatePending() returns the number of bytes and bits of output that
 * have been generated, but not yet provided in the available output.
 * The bytes not provided would be due to the available output space
 * having being consumed. The number of bits of output not provided are
 * between 0 and 7, where they await more bits to join them in order to
 * fill out a full byte. If pending or bits are Z_NULL, then those
 * values are not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int deflatePending(z_streamp strm, unsigned *pending, int *bits);

/**
 * deflatePrime() inserts bits in the deflate output stream.  The intent
 * is that this function is used to start off the deflate output with the bits
 * leftover from a previous deflate stream when appending to it.  As such, this
 * function can only be used for raw deflate, and must be used before the first
 * deflate() call after a deflateInit2() or deflateReset().  bits must be less
 * than or equal to 16, and that many of the least significant bits of value
 * will be inserted in the output.
 *
 * @return Z_OK if success, Z_BUF_ERROR if there was not enough room in
 *     the internal buffer to insert the bits, or Z_STREAM_ERROR if the
 *     source stream state was inconsistent.
 */
int deflatePrime(z_streamp strm, int bits, int value);

/**
 * Provides gzip header information for when a gzip stream is requested
 * by deflateInit2(). deflateSetHeader() may be called after
 * deflateInit2() or deflateReset() and before the first call of
 * deflate(). The text, time, os, extra field, name, and comment
 * information in the provided gz_header structure are written to the
 * gzip header (xflag is ignored -- the extra flags are set according to
 * the compression level). The caller must assure that, if not Z_NULL,
 * name and comment are terminated with a zero byte, and that if extra
 * is not Z_NULL, that extra_len bytes are available there. If hcrc is
 * true, a gzip header crc is included. Note that the current versions
 * of the command-line version of gzip (up through version 1.3.x) do not
 * support header crc's, and will report that it is a "multi-part gzip
 * file" and give up.
 *
 * If deflateSetHeader is not used, the default gzip header has text
 * false, the time set to zero, and os set to 255, with no extra, name,
 * or comment fields. The gzip header is returned to the default state
 * by deflateReset().
 *
 * deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the
 * source stream state was inconsistent.
 */
int deflateSetHeader(z_streamp strm, gz_headerp head);

/**
 * This is another version of inflateInit with an extra parameter. The
 * fields next_in, avail_in, zalloc, zfree and opaque must be
 * initialized before by the caller.
 *
 * The windowBits parameter is the base two logarithm of the maximum
 * window size (the size of the history buffer). It should be in the
 * range 8..15 for this version of the library. The default value is 15
 * if inflateInit is used instead. windowBits must be greater than or
 * equal to the windowBits value provided to deflateInit2() while
 * compressing, or it must be equal to 15 if deflateInit2() was not
 * used. If a compressed stream with a larger window size is given as
 * input, inflate() will return with the error code Z_DATA_ERROR instead
 * of trying to allocate a larger window.
 *
 * windowBits can also be zero to request that inflate use the window
 * size in the zlib header of the compressed stream.
 *
 * windowBits can also be -8..-15 for raw inflate. In this case,
 * -windowBits determines the window size. inflate() will then process
 * raw deflate data, not looking for a zlib or gzip header, not
 * generating a check value, and not looking for any check values for
 * comparison at the end of the stream. This is for use with other
 * formats that use the deflate compressed data format such as zip.
 * Those formats provide their own check values. If a custom format is
 * developed using the raw deflate format for compressed data, it is
 * recommended that a check value such as an Adler-32 or a CRC-32 be
 * applied to the uncompressed data as is done in the zlib, gzip, and
 * zip formats. For most applications, the zlib format should be used as
 * is. Note that comments above on the use in deflateInit2() applies to
 * the magnitude of windowBits.
 *
 * windowBits can also be greater than 15 for optional gzip decoding.
 * Add 32 to windowBits to enable zlib and gzip decoding with automatic
 * header detection, or add 16 to decode only the gzip format (the zlib
 * format will return a Z_DATA_ERROR). If a gzip stream is being
 * decoded, strm->adler is a CRC-32 instead of an Adler-32. Unlike the
 * gunzip utility and gzread() (see below), inflate() will not
 * automatically decode concatenated gzip streams. inflate() will return
 * Z_STREAM_END at the end of the gzip stream. The state would need to
 * be reset to continue decoding a subsequent gzip stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit2 does not perform any decompression apart
 *     from possibly reading the zlib header if present: actual
 *     decompression will be done by inflate(). (So next_in and avail_in
 *     may be modified, but next_out and avail_out are unused and
 *     unchanged.) The current implementation of inflateInit2() does not
 *     process any header information -- that is deferred until
 *     inflate() is called.
 */
int inflateInit2(z_streamp strm, int windowBits);

/**
 * Initializes the decompression dictionary from the given uncompressed
 * byte sequence. This function must be called immediately after a call
 * of inflate, if that call returned Z_NEED_DICT. The dictionary chosen
 * by the compressor can be determined from the Adler-32 value returned
 * by that call of inflate. The compressor and decompressor must use
 * exactly the same dictionary (see deflateSetDictionary). For raw
 * inflate, this function can be called at any time to set the
 * dictionary. If the provided dictionary is smaller than the window and
 * there is already data in the window, then the provided dictionary
 * will amend what's there. The application must insure that the
 * dictionary that was used for compression is provided.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent, Z_DATA_ERROR if the given dictionary doesn't match
 *     the expected one (incorrect Adler-32 value). inflateSetDictionary
 *     does not perform any decompression: this will be done by
 *     subsequent calls of inflate().
 */
int inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by inflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If inflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Skips invalid compressed data until a possible full flush point (see
 * above for the description of deflate with Z_FULL_FLUSH) can be found,
 * or until all available input is skipped. No output is provided.
 *
 * inflateSync searches for a 00 00 FF FF pattern in the compressed
 * data. All full flush points have this pattern, but not all
 * occurrences of this pattern are full flush points.
 *
 * @return Z_OK if a possible full flush point has been found,
 *     Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no
 *     flush point has been found, or Z_STREAM_ERROR if the stream
 *     structure was inconsistent. In the success case, the application
 *     may save the current current value of total_in which indicates
 *     where valid compressed data was found. In the error case, the
 *     application may repeatedly call inflateSync, providing more input
 *     each time, until success or end of the input data.
 */
int inflateSync(z_streamp strm);

/**
 * Sets the destination stream as a complete copy of the source stream.
 *
 * This function can be useful when randomly accessing a large stream.
 * The first pass through the stream can periodically record the inflate
 * state, allowing restarting inflate at those points when randomly
 * accessing the stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int inflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to inflateEnd followed by inflateInit,
 * but does not free and reallocate the internal decompression state.  The
 * stream will keep attributes that may have been set by inflateInit2.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL).
 */
int inflateReset(z_streamp strm);

/**
 * This function is the same as inflateReset, but it also permits changing
 * the wrap and window size requests.  The windowBits parameter is interpreted
 * the same as it is for inflateInit2.  If the window size is changed, then the
 * memory allocated for the window is freed, and the window will be reallocated
 * by inflate() if needed.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL), or if
 *     the windowBits parameter is invalid.
 */
int inflateReset2(z_streamp strm, int windowBits);

/**
 * This function inserts bits in the inflate input stream.  The intent is
 * that this function is used to start inflating at a bit position in the
 * middle of a byte.  The provided bits will be used before any bytes are used
 * from next_in.  This function should only be used with raw inflate, and
 * should be used before the first inflate() call after inflateInit2() or
 * inflateReset().  bits must be less than or equal to 16, and that many of the
 * least significant bits of value will be inserted in the input.
 *
 * If bits is negative, then the input stream bit buffer is emptied.  Then
 * inflatePrime() can be called again to put bits in the buffer.  This is used
 * to clear out bits leftover after feeding inflate a block description prior
 * to feeding inflate codes.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflatePrime(z_streamp strm, int bits, int value);

/**
 * Returns two values, one in the lower 16 bits of the return value, and
 * the other in the remaining upper bits, obtained by shifting the
 * return value down 16 bits. If the upper value is -1 and the lower
 * value is zero, then inflate() is currently decoding information
 * outside of a block. If the upper value is -1 and the lower value is
 * non-zero, then inflate is in the middle of a stored block, with the
 * lower value equaling the number of bytes from the input remaining to
 * copy. If the upper value is not -1, then it is the number of bits
 * back from the current bit position in the input of the code (literal
 * or length/distance pair) currently being processed. In that case the
 * lower value is the number of bytes already emitted for that code.
 *
 * A code is being processed if inflate is waiting for more input to
 * complete decoding of the code, or if it has completed decoding but is
 * waiting for more output space to write the literal or match data.
 *
 * inflateMark() is used to mark locations in the input data for random
 * access, which may be at bit positions, and to note those cases where
 * the output of a code may span boundaries of random access blocks. The
 * current location in the input stream can be determined from avail_in
 * and data_type as noted in the description for the Z_BLOCK flush
 * parameter for inflate.
 *
 * @return the value noted above, or -65536 if the provided source
 *     stream state was inconsistent.
 */
long inflateMark(z_streamp strm);

/**
 * inflateGetHeader() requests that gzip header information be stored in
 * the provided gz_header structure. inflateGetHeader() may be called
 * after inflateInit2() or inflateReset(), and before the first call of
 * inflate(). As inflate() processes the gzip stream, head->done is zero
 * until the header is completed, at which time head->done is set to
 * one. If a zlib stream is being decoded, then head->done is set to -1
 * to indicate that there will be no gzip header information
 * forthcoming. Note that Z_BLOCK or Z_TREES can be used to force
 * inflate() to return immediately after header processing is complete
 * and before any actual data is decompressed.
 *
 * The text, time, xflags, and os fields are filled in with the gzip
 * header contents. hcrc is set to true if there is a header CRC. (The
 * header CRC was valid if done is set to one.) If extra is not Z_NULL,
 * then extra_max contains the maximum number of bytes to write to
 * extra. Once done is true, extra_len contains the actual extra field
 * length, and extra contains the extra field, or that field truncated
 * if extra_max is less than extra_len. If name is not Z_NULL, then up
 * to name_max characters are written there, terminated with a zero
 * unless the length is greater than name_max. If comment is not Z_NULL,
 * then up to comm_max characters are written there, terminated with a
 * zero unless the length is greater than comm_max. When any of extra,
 * name, or comment are not Z_NULL and the respective field is not
 * present in the header, then that field is set to Z_NULL to signal its
 * absence. This allows the use of deflateSetHeader() with the returned
 * structure to duplicate the header. However if those fields are set to
 * allocated memory, then the application will need to save those
 * pointers elsewhere so that they can be eventually freed.
 *
 * If inflateGetHeader is not used, then the header information is
 * simply discarded. The header is always checked for validity,
 * including the header CRC if present. inflateReset() will reset the
 * process to discard the header information. The application would need
 * to call inflateGetHeader() again to retrieve the header from the next
 * gzip stream.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflateGetHeader(z_streamp strm, gz_headerp head);

/**
 * Initialize internal stream state for decompression using
 * inflateBack() calls. The fields zalloc, zfree and opaque in strm must
 * be initialized before the call. If zalloc and zfree are Z_NULL, then
 * the default library- derived memory allocation routines are used.
 * windowBits is the base two logarithm of the window size, in the range
 * 8..15. window is a caller supplied buffer of that size. Except for
 * special applications where it is assured that deflate was used with
 * small window sizes, windowBits must be 15 and a 32K byte window must
 * be supplied to be able to decompress general deflate streams.
 *
 * See inflateBack() for the usage of these routines.
 *
 * @return Z_OK on success, Z_STREAM_ERROR if any of the parameters are
 *     invalid, or Z_MEM_ERROR if the internal state could not be
 *     allocated.
 */
int inflateBackInit(z_streamp strm, int windowBits, unsigned char *window);

typedef unsigned (*in_func)(void *, const unsigned char **);
typedef int (*out_func)(void *, unsigned char *, unsigned);

/**
 * inflateBack() does a raw inflate with a single call using a call-back
 * interface for input and output. This is potentially more efficient
 * than inflate() for file i/o applications, in that it avoids copying
 * between the output and the sliding window by simply making the window
 * itself the output buffer. inflate() can be faster on modern CPUs when
 * used with large buffers. inflateBack() trusts the application to not
 * change the output buffer passed by the output function, at least
 * until inflateBack() returns.
 *
 * inflateBackInit() must be called first to allocate the internal state
 * and to initialize the state with the user-provided window buffer.
 * inflateBack() may then be used multiple times to inflate a complete,
 * raw deflate stream with each call. inflateBackEnd() is then called to
 * free the allocated state.
 *
 * A raw deflate stream is one with no zlib or gzip header or trailer.
 * This routine would normally be used in a utility that reads zip or
 * gzip files and writes out uncompressed files. The utility would
 * decode the header and process the trailer on its own, hence this
 * routine expects only the raw deflate stream to decompress. This is
 * different from the default behavior of inflate(), which expects a
 * zlib header and trailer around the deflate stream.
 *
 * inflateBack() uses two subroutines supplied by the caller that are
 * then called by inflateBack() for input and output. inflateBack()
 * calls those routines until it reads a complete deflate stream and
 * writes out all of the uncompressed data, or until it encounters an
 * error. The function's parameters and return types are defined above
 * in the in_func and out_func typedefs. inflateBack() will call
 * in(in_desc, &buf) which should return the number of bytes of provided
 * input, and a pointer to that input in buf. If there is no input
 * available, in() must return zero -- buf is ignored in that case --
 * and inflateBack() will return a buffer error. inflateBack() will call
 * out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
 * out() should return zero on success, or non-zero on failure. If out()
 * returns non-zero, inflateBack() will return with an error. Neither
 * in() nor out() are permitted to change the contents of the window
 * provided to inflateBackInit(), which is also the buffer that out()
 * uses to write from. The length written by out() will be at most the
 * window size. Any non-zero amount of input may be provided by in().
 *
 * For convenience, inflateBack() can be provided input on the first
 * call by setting strm->next_in and strm->avail_in. If that input is
 * exhausted, then in() will be called. Therefore strm->next_in must be
 * initialized before calling inflateBack(). If strm->next_in is Z_NULL,
 * then in() will be called immediately for input. If strm->next_in is
 * not Z_NULL, then strm->avail_in must also be initialized, and then if
 * strm->avail_in is not zero, input will initially be taken from
 * strm->next_in[0 .. strm->avail_in - 1].
 *
 * The in_desc and out_desc parameters of inflateBack() is passed as the
 * first parameter of in() and out() respectively when they are called.
 * These descriptors can be optionally used to pass any information that
 * the caller- supplied in() and out() functions need to do their job.
 *
 * On return, inflateBack() will set strm->next_in and strm->avail_in to
 * pass back any unused input that was provided by the last in() call.
 * The return values of inflateBack() can be Z_STREAM_END on success,
 * Z_BUF_ERROR if in() or out() returned an error, Z_DATA_ERROR if there
 * was a format error in the deflate stream (in which case strm->msg is
 * set to indicate the nature of the error), or Z_STREAM_ERROR if the
 * stream was not properly initialized. In the case of Z_BUF_ERROR, an
 * input or output error can be distinguished using strm->next_in which
 * will be Z_NULL only if in() returned an error. If strm->next_in is
 * not Z_NULL, then the Z_BUF_ERROR was due to out() returning non-zero.
 * (in() will always be called before out(), so strm->next_in is assured
 * to be defined if out() returns non-zero.) Note that inflateBack()
 * cannot return Z_OK.
 */
int inflateBack(z_streamp strm, in_func in, void *in_desc, out_func out,
                void *out_desc);

/**
 * All memory allocated by inflateBackInit() is freed.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state was
 *     inconsistent.
 */
int inflateBackEnd(z_streamp strm);

/*
 * Return flags indicating compile-time options.
 *
 * Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
 *   1.0: size of uInt
 *   3.2: size of uLong
 *   5.4: size of voidpf (pointer)
 *   7.6: size of off_t
 *
 * Compiler, assembler, and debug options:
 *   8: ZLIB_DEBUG
 *   9: ASMV or ASMINF -- use ASM code
 *   10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
 *   11: 0 (reserved)
 *
 * One-time table building (smaller code, but not thread-safe if true):
 *   12: BUILDFIXED -- build static block decoding tables when needed
 *   13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
 *   14,15: 0 (reserved)
 *
 * Library content (indicates missing functionality):
 *
 *   16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
 *   deflate code when not needed)
 *
 *   17: NO_GZIP -- deflate can't write gzip streams, and inflate can't
 *   detect and decode gzip streams (to avoid linking crc code)
 *
 *   18-19: 0 (reserved)
 *
 * Operation variations (changes in library functionality):
 *   20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
 *   21: FASTEST -- deflate algorithm with only one, lowest compression level
 *   22,23: 0 (reserved)
 *
 * The sprintf variant used by gzprintf (zero is best):
 *   24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
 *   25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
 *   26: 0 = returns value, 1 = void -- 1 means inferred string length returned
 *
 * Remainder is:
 *   27-31: 0 (reserved)
 */
uLong zlibCompileFlags(void);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » utility functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  The following utility functions are implemented on top of the basic
  stream-oriented functions. To simplify the interface, some default
  options are assumed (compression level and memory usage, standard
  memory allocation functions). The source code of these utility
  functions can be modified if you need special options. */

/**
 * Compresses source buffer into the destination buffer. sourceLen is
 * the byte length of the source buffer. Upon entry, destLen is the
 * total size of the destination buffer, which must be at least the
 * value returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data. compress() is equivalent to
 * compress2() with a level parameter of Z_DEFAULT_COMPRESSION.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer.
 */
int compress(Bytef *dest, uLongf *destLen, const Bytef *source,
             uLong sourceLen);

/**
 * Compresses source buffer into the destination buffer. The level
 * parameter has the same meaning as in deflateInit. sourceLen is the
 * byte length of the source buffer. Upon entry, destLen is the total
 * size of the destination buffer, which must be at least the value
 * returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer,
 *     Z_STREAM_ERROR if the level parameter is invalid.
 */
int compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
              uLong sourceLen, int level);

/**
 * Returns an upper bound on the compressed size after compress() or
 * compress2() on sourceLen bytes. It would be used before a compress()
 * or compress2() call to allocate the destination buffer.
 */
uLong compressBound(uLong sourceLen);

/**
 * Decompresses the source buffer into the destination buffer.  sourceLen is
 * the byte length of the source buffer.  Upon entry, destLen is the total size
 * of the destination buffer, which must be large enough to hold the entire
 * uncompressed data.  (The size of the uncompressed data must have been saved
 * previously by the compressor and transmitted to the decompressor by some
 * mechanism outside the scope of this compression library.) Upon exit, destLen
 * is the actual size of the uncompressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer, or
 *     Z_DATA_ERROR if the input data was corrupted or incomplete. In
 *     the case where there is not enough room, uncompress() will fill
 *     the output buffer with the uncompressed data up to that point.
 */
int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
               uLong sourceLen);

/**
 * Same as uncompress, except that sourceLen is a pointer, where the
 * length of the source is *sourceLen.  On return, *sourceLen is the number of
 * source bytes consumed.
 */
int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
                uLong *sourceLen);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » gzip                                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  This library supports reading and writing files in gzip (.gz) format
  with an interface similar to that of stdio, using the functions that
  start with "gz". The gzip format is different from the zlib format.
  gzip is a gzip wrapper, documented in RFC 1952, wrapped around a
  deflate stream. */

typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */

/**
 * Opens a gzip (.gz) file for reading or writing.
 *
 * The mode parameter is as in fopen ("rb" or "wb") but can also include
 * a compression level ("wb9") or a strategy: 'f' for filtered data as
 * in "wb6f", 'h' for Huffman-only compression as in "wb1h", 'R' for
 * run-length encoding as in "wb1R", or 'F' for fixed code compression
 * as in "wb9F". (See the description of deflateInit2 for more
 * information about the strategy parameter.) 'T' will request
 * transparent writing or appending with no compression and not using
 * the gzip format.
 *
 * "a" can be used instead of "w" to request that the gzip stream that
 * will be written be appended to the file. "+" will result in an error,
 * since reading and writing to the same gzip file is not supported. The
 * addition of "x" when writing will create the file exclusively, which
 * fails if the file already exists. On systems that support it, the
 * addition of "e" when reading or writing will set the flag to close
 * the file on an execve() call.
 *
 * These functions, as well as gzip, will read and decode a sequence of
 * gzip streams in a file. The append function of gzopen() can be used
 * to create such a file. (Also see gzflush() for another way to do
 * this.) When appending, gzopen does not test whether the file begins
 * with a gzip stream, nor does it look for the end of the gzip streams
 * to begin appending. gzopen will simply append a gzip stream to the
 * existing file.
 *
 * gzopen can be used to read a file which is not in gzip format; in
 * this case gzread will directly read from the file without
 * decompression. When reading, this will be detected automatically by
 * looking for the magic two- byte gzip header.
 *
 * @return Z_OK if the file could not be opened, if there was insufficient
 *     memory to allocate the gzFile state, or if an invalid mode was
 *     specified (an 'r', 'w', or 'a' was not provided, or '+' was
 *     provided). errno can be checked to determine if the reason gzopen
 *     failed was that the file could not be opened.
 */
gzFile gzopen(const char *path, const char *mode);

/**
 * Associates gzFile with the file descriptor.
 *
 * File descriptors are obtained from calls like open, dup, creat, pipe
 * or fileno (if the file has been previously opened with fopen). The
 * mode parameter is as in gzopen.
 *
 * The next call of gzclose on the returned gzFile will also close the file
 * descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
 * fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
 * mode);.  The duplicated descriptor should be saved to avoid a leak, since
 * gzdopen does not close fd if it fails.  If you are using fileno() to get the
 * file descriptor from a FILE *, then you will have to use dup() to avoid
 * double-close()ing the file descriptor.  Both gzclose() and fclose() will
 * close the associated file descriptor, so they need to have different file
 * descriptors.
 *
 * @return Z_OK if there was insufficient memory to allocate the gzFile
 *     state, if an invalid mode was specified (an 'r', 'w', or 'a' was
 *     not provided, or '+' was provided), or if fd is -1. The file
 *     descriptor is not used until the next gz* read, write, seek, or
 *     close operation, so gzdopen will not detect if fd is invalid
 *     (unless fd is -1).
 */
gzFile gzdopen(int fd, const char *mode);

/**
 * Sets internal buffer size used by this library's functions. The
 * default buffer size is 8192 bytes. This function must be called after
 * gzopen() or gzdopen(), and before any other calls that read or write
 * the file. The buffer memory allocation is always deferred to the
 * first read or write. Three times that size in buffer space is
 * allocated. A larger buffer size of, for example, 64K or 128K bytes
 * will noticeably increase the speed of decompression (reading).
 *
 * The new buffer size also affects the maximum length for gzprintf().
 *
 * @return Z_OK on success, or -1 on failure, such as being called too
 *     late.
 */
int gzbuffer(gzFile file, unsigned size);

/**
 * Dynamically update the compression level or strategy.  See the description
 * of deflateInit2 for the meaning of these parameters.  Previously provided
 * data is flushed before the parameter change.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the file was not opened for
 *     writing, Z_ERRNO if there is an error writing the flushed data,
 *     or Z_MEM_ERROR if there is a memory allocation error.
 */
int gzsetparams(gzFile file, int level, int strategy);

/**
 * Reads given number of uncompressed bytes from the compressed file. If
 * the input file is not in gzip format, gzread copies the given number
 * of bytes into the buffer directly from the file.
 *
 * After reaching the end of a gzip stream in the input, gzread will continue
 * to read, looking for another gzip stream.  Any number of gzip streams may be
 * concatenated in the input file, and will all be decompressed by gzread().
 * If something other than a gzip stream is encountered after a gzip stream,
 * that remaining trailing garbage is ignored (and no error is returned).
 *
 * gzread can be used to read a gzip file that is being concurrently written.
 * Upon reaching the end of the input, gzread will return with the available
 * data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
 * gzclearerr can be used to clear the end of file indicator in order to permit
 * gzread to be tried again.  Z_OK indicates that a gzip stream was completed
 * on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
 * middle of a gzip stream.  Note that gzread does not return -1 in the event
 * of an incomplete gzip stream.  This error is deferred until gzclose(), which
 * will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
 * stream.  Alternatively, gzerror can be used before gzclose to detect this
 * case.
 *
 * @return Z_OK number of uncompressed bytes actually read, less than
 *     len for end of file, or -1 for error. If len is too large to fit
 *     in an int, then nothing is read, -1 is returned, and the error
 *     state is set to Z_STREAM_ERROR.
 */
int gzread(gzFile file, voidp buf, unsigned len);

/**
 * Read up to nitems items of size size from file to buf, otherwise operating
 * as gzread() does.  This duplicates the interface of stdio's fread(), with
 * size_t request and return types.  If the library defines size_t, then
 * size_t is identical to size_t.  If not, then size_t is an unsigned
 * integer type that can contain a pointer.
 *
 * gzfread() returns the number of full items read of size size, or zero if
 * the end of the file was reached and a full item could not be read, or if
 * there was an error.  gzerror() must be consulted if zero is returned in
 * order to determine if there was an error.  If the multiplication of size and
 * nitems overflows, i.e. the product does not fit in a size_t, then nothing
 * is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
 *
 * In the event that the end of file is reached and only a partial item is
 * available at the end, i.e. the remaining uncompressed data length is not a
 * multiple of size, then the final partial item is nevetheless read into buf
 * and the end-of-file flag is set.  The length of the partial item read is not
 * provided, but could be inferred from the result of gztell().  This behavior
 * is the same as the behavior of fread() implementations in common libraries,
 * but it prevents the direct use of gzfread() to read a concurrently written
 * file, reseting and retrying on end-of-file, when size is not 1.
 */
size_t gzfread(voidp buf, size_t size, size_t nitems, gzFile file);

/**
 * Writes given number of uncompressed bytes into the compressed file.
 * gzwrite returns the number of uncompressed bytes written or 0 in case
 * of error.
 */
int gzwrite(gzFile file, voidpc buf, unsigned len);

/**
 * Writes nitems items of size size from buf to file, duplicating the
 * interface of stdio's fwrite(), with size_t request and return types.
 * If the library defines size_t, then size_t is identical to size_t. If
 * not, then size_t is an unsigned integer type that can contain a
 * pointer.
 *
 * gzfwrite() returns the number of full items written of size size, or zero
 * if there was an error.  If the multiplication of size and nitems overflows,
 * i.e. the product does not fit in a size_t, then nothing is written, zero
 * is returned, and the error state is set to Z_STREAM_ERROR.
 */
size_t gzfwrite(voidpc buf, size_t size, size_t nitems, gzFile file);

/**
 * Converts, formats, and writes the arguments to the compressed file
 * under control of the format string, as in fprintf. gzprintf returns
 * the number of uncompressed bytes actually written, or a negative zlib
 * error code in case of error. The number of uncompressed bytes written
 * is limited to 8191, or one less than the buffer size given to
 * gzbuffer(). The caller should assure that this limit is not exceeded.
 * If it is exceeded, then gzprintf() will return an error (0) with
 * nothing written. In this case, there may also be a buffer overflow
 * with unpredictable consequences, which is possible only if zlib was
 * compiled with the insecure functions sprintf() or vsprintf() because
 * the secure snprintf() or vsnprintf() functions were not available.
 * This can be determined using zlibCompileFlags().
 */
int gzprintf(gzFile file, const char *format, ...);

/**
 * Writes the given null-terminated string to the compressed file, excluding
 * the terminating null character.
 *
 * @return Z_OK number of characters written, or -1 in case of error.
 */
int gzputs(gzFile file, const char *s);

/**
 * Reads bytes from the compressed file until len-1 characters are read,
 * or a newline character is read and transferred to buf, or an
 * end-of-file condition is encountered. If any characters are read or
 * if len == 1, the string is terminated with a null character. If no
 * characters are read due to an end-of-file or len < 1, then the buffer
 * is left untouched.
 *
 * @return buf which is a null-terminated string, or it returns NULL for
 *     end-of-file or in case of error. If there was an error, the
 *     contents at buf are indeterminate.
 */
char *gzgets(gzFile file, char *buf, int len);

/**
 * Writes character converted to an unsigned char into compressed file.
 * @return value that was written, or -1 on error
 */
int gzputc(gzFile file, int c);

/**
 * Reads one byte from the compressed file. gzgetc returns this byte or
 * -1 in case of end of file or error. This is implemented as a macro
 * for speed. As such, it does not do all of the checking the other
 * functions do. I.e. it does not check to see if file is NULL, nor
 * whether the structure file points to has been clobbered or not.
 */
int gzgetc(gzFile file);

/**
 * Pushes one character back onto the stream to be read as the first
 * character on the next read. At least one character of push-back is
 * allowed. gzungetc() returns the character pushed, or -1 on failure.
 * gzungetc() will fail if c is -1, and may fail if a character has been
 * pushed but not read yet. If gzungetc is used immediately after gzopen
 * or gzdopen, at least the output buffer size of pushed characters is
 * allowed. (See gzbuffer above.) The pushed character will be discarded
 * if the stream is repositioned with gzseek() or gzrewind().
 */
int gzungetc(int c, gzFile file);

/**
 * Flushes all pending output into the compressed file. The parameter
 * flush is as in the deflate() function. The return value is the zlib
 * error number (see function gzerror below). gzflush is only permitted
 * when writing.
 *
 * If the flush parameter is Z_FINISH, the remaining data is written and
 * the gzip stream is completed in the output. If gzwrite() is called
 * again, a new gzip stream will be started in the output. gzread() is
 * able to read such concatenated gzip streams.
 *
 * gzflush should be called only when strictly necessary because it will
 * degrade compression if called too often.
 */
int gzflush(gzFile file, int flush);

/**
 * Sets starting position for the next gzread or gzwrite on the given
 * compressed file. The offset represents a number of bytes in the
 * uncompressed data stream. The whence parameter is defined as in
 * lseek(2); the value SEEK_END is not supported.
 *
 * If the file is opened for reading, this function is emulated but can be
 * extremely slow.  If the file is opened for writing, only forward seeks are
 * supported; gzseek then compresses a sequence of zeroes up to the new
 * starting position.
 *
 * @return resulting offset location as measured in bytes from the
 *     beginning of the uncompressed stream, or -1 in case of error, in
 *     particular if the file is opened for writing and the new starting
 *     position would be before the current position.
 */
ssize_t gzseek(gzFile file, int64_t offset, int whence);

/**
 * Rewinds file.
 *
 * This function is supported only for reading.
 *
 * @note gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
 */
int gzrewind(gzFile file);

/**
 * Returns starting position for the next gzread or gzwrite on the given
 * compressed file. This position represents a number of bytes in the
 * uncompressed data stream, and is zero when starting, even if
 * appending or reading a gzip stream from the middle of a file using
 * gzdopen().
 *
 * @note gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 */
ssize_t gztell(gzFile file);

/**
 * Returns current offset in the file being read or written. This offset
 * includes the count of bytes that precede the gzip stream, for example
 * when appending or when using gzdopen() for reading. When reading, the
 * offset does not include as yet unused buffered input. This
 * information can be used for a progress indicator. On error,
 * gzoffset() returns -1.
 */
ssize_t gzoffset(gzFile file);

/**
 * Returns true (1) if the end-of-file indicator has been set while
 * reading, false (0) otherwise. Note that the end-of-file indicator is
 * set only if the read tried to go past the end of the input, but came
 * up short. Therefore, just like feof(), gzeof() may return false even
 * if there is no more data to read, in the event that the last read
 * request was for the exact number of bytes remaining in the input
 * file. This will happen if the input file size is an exact multiple of
 * the buffer size.
 *
 * If gzeof() returns true, then the read functions will return no more
 * data, unless the end-of-file indicator is reset by gzclearerr() and
 * the input file has grown since the previous end of file was detected.
 */
int gzeof(gzFile file);

/**
 * Returns true (1) if file is being copied directly while reading, or
 * false (0) if file is a gzip stream being decompressed.
 *
 * If the input file is empty, gzdirect() will return true, since the
 * input does not contain a gzip stream.
 *
 * If gzdirect() is used immediately after gzopen() or gzdopen() it will
 * cause buffers to be allocated to allow reading the file to determine
 * if it is a gzip file. Therefore if gzbuffer() is used, it should be
 * called before gzdirect().
 *
 * When writing, gzdirect() returns true (1) if transparent writing was
 * requested ("wT" for the gzopen() mode), or false (0) otherwise.
 * (Note: gzdirect() is not needed when writing. Transparent writing
 * must be explicitly requested, so the application already knows the
 * answer. When linking statically, using gzdirect() will include all of
 * the zlib code for gzip file reading and decompression, which may not
 * be desired.)
 */
int gzdirect(gzFile file);

/**
 * Flushes all pending output if necessary, closes the compressed file
 * and deallocates the (de)compression state. Note that once file is
 * closed, you cannot call gzerror with file, since its structures have
 * been deallocated. gzclose must not be called more than once on the
 * same file, just as free must not be called more than once on the same
 * allocation.
 *
 * @return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a file
 *     operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
 *     last read ended in the middle of a gzip stream, or Z_OK on
 *     success.
 */
int gzclose(gzFile file);

/**
 * Same as gzclose(), but gzclose_r() is only for use when reading, and
 * gzclose_w() is only for use when writing or appending. The advantage
 * to using these instead of gzclose() is that they avoid linking in
 * zlib compression or decompression code that is not used when only
 * reading or only writing respectively. If gzclose() is used, then both
 * compression and decompression code will be included the application
 * when linking to a static zlib library.
 */
int gzclose_r(gzFile file);
int gzclose_w(gzFile file);

/**
 * Returns the error message for the last error which occurred on the given
 * compressed file.  errnum is set to zlib error number.  If an error occurred
 * in the file system and not in the compression library, errnum is set to
 * Z_ERRNO and the application may consult errno to get the exact error code.
 *
 * The application must not modify the returned string.  Future calls to
 * this function may invalidate the previously returned string.  If file is
 * closed, then the string previously returned by gzerror will no longer be
 * available.
 *
 * gzerror() should be used to distinguish errors from end-of-file for those
 * functions above that do not distinguish those cases in their return values.
 */
const char *gzerror(gzFile file, int *errnum);

/**
 * Clears the error and end-of-file flags for file.  This is analogous to the
 * clearerr() function in stdio.  This is useful for continuing to read a gzip
 * file that is being written concurrently.
 */
void gzclearerr(gzFile file);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » checksums                                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/**
 * Updates running Adler-32 checksum with the bytes buf[0..len-1] and
 * return the updated checksum. If buf is Z_NULL, this function returns
 * the required initial value for the checksum.
 */
uLong adler32(uLong adler, const Bytef *buf, uInt len);

/**
 * Same as adler32(), but with a size_t length.
 */
uLong adler32_z(uLong adler, const Bytef *buf, size_t len);

/**
 * Combine two Adler-32 checksums into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were
 * calculated for each, adler1 and adler2. adler32_combine() returns the
 * Adler-32 checksum of seq1 and seq2 concatenated, requiring only
 * adler1, adler2, and len2. Note that the off_t type (like off_t) is a
 * signed integer. If len2 is negative, the result has no meaning or
 * utility.
 */
uLong adler32_combine(uLong adler1, uLong adler2, int64_t len2);

/**
 * Update a running CRC-32 with the bytes buf[0..len-1] and return the
 * updated CRC-32.  If buf is Z_NULL, this function returns the required
 * initial value for the crc.  Pre- and post-conditioning (one's complement) is
 * performed within this function so it shouldn't be done by the application.
 *
 * Usage example:
 *
 *     uLong crc = crc32(0L, Z_NULL, 0);
 *     while (read_buffer(buffer, length) != EOF) {
 *       crc = crc32(crc, buffer, length);
 *     }
 *     if (crc != original_crc) error();
 */
uLong crc32(uLong crc, const Bytef *buf, uInt len);

/**
 * Same as crc32(), but with a size_t length.
 */
uint32_t crc32_z(uint32_t crc, const void *buf, size_t len);

/**
 * Combine two CRC-32 check values into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
 * calculated for each, crc1 and crc2. crc32_combine() returns the
 * CRC-32 check value of seq1 and seq2 concatenated, requiring only
 * crc1, crc2, and len2.
 */
uLong crc32_combine(uLong crc1, uLong crc2, int64_t len2);

/**
 * gzgetc() macro and its supporting function and exposed data
 * structure. Note that the real internal state is much larger than the
 * exposed structure. This abbreviated structure exposes just enough for
 * the gzgetc() macro. The user should not mess with these exposed
 * elements, since their names or behavior could change in the future,
 * perhaps even capriciously. They can only be used by the gzgetc()
 * macro. You have been warned.
 */
struct gzFile_s {
  unsigned have;
  unsigned char *next;
  int64_t pos;
};

int gzgetc_(gzFile file); /* backward compatibility */
#ifdef Z_PREFIX_SET
#undef z_gzgetc
#define z_gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#elif defined(Z_COSMO_PREFIX_SET)
#undef gzgetc
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (__gzgetc)(g))
#else
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#endif

/* undocumented functions */
const char *zError(int);
int inflateSyncPoint(z_streamp);
int inflateUndermine(z_streamp, int);
int inflateValidate(z_streamp, int);
unsigned long inflateCodesUsed(z_streamp);
int inflateResetKeep(z_streamp);
int deflateResetKeep(z_streamp);
int gzvprintf(gzFile file, const char *format, va_list va);
void inflate_fast_chunk(z_streamp strm, unsigned start);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/regex/regex.h */

#define COSMOPOLITAN_LIBC_REGEX_REGEX_H_
COSMOPOLITAN_C_START_

#if 0
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § regular expressions                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
#endif

#define REG_EXTENDED 1
#define REG_ICASE    2
#define REG_NEWLINE  4
#define REG_NOSUB    8

#define REG_NOTBOL 1 /* ^ should not match beginning of string */
#define REG_NOTEOL 2 /* $ should not match end of string */

#define REG_OK       0
#define REG_NOMATCH  1
#define REG_BADPAT   2
#define REG_ECOLLATE 3
#define REG_ECTYPE   4
#define REG_EESCAPE  5
#define REG_ESUBREG  6
#define REG_EBRACK   7
#define REG_EPAREN   8
#define REG_EBRACE   9
#define REG_BADBR    10
#define REG_ERANGE   11
#define REG_ESPACE   12
#define REG_BADRPT   13

#define REG_ENOSYS -1

typedef long regoff_t;

struct PosixRegex {
  size_t re_nsub;
  void *__opaque, *__padding[4];
  size_t __nsub2;
  char __padding2;
};

struct PosixRegexMatch {
  regoff_t rm_so;
  regoff_t rm_eo;
};

typedef struct PosixRegex regex_t;
typedef struct PosixRegexMatch regmatch_t;

int regcomp(regex_t *, const char *, int);
int regexec(const regex_t *, const char *, size_t, regmatch_t *, int);
size_t regerror(int, const regex_t *, char *, size_t);
void regfree(regex_t *);

COSMOPOLITAN_C_END_

#endif /* COSMOPOLITAN_H_ */
#ifndef COSMOPOLITAN_H_
#define COSMOPOLITAN_H_


/*!BEGIN libc/integral/normalize.inc */

#ifdef __COSMOPOLITAN__
#undef __COSMOPOLITAN__
#endif

#define __COSMOPOLITAN_MAJOR__ 3
#define __COSMOPOLITAN_MINOR__ 3
#define __COSMOPOLITAN_PATCH__ 9
#define __COSMOPOLITAN__                                                   \
  (100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
   __COSMOPOLITAN_PATCH__)

#ifndef __COUNTER__
#define __COUNTER__ __LINE__
#endif

#if __GNUC__ + 0 < 2
#undef __GNUC__
#elif defined(__GNUC__) && defined(SWIG) /* lool */
#undef __GNUC__
#elif defined(__GNUC__) && defined(__NVCC__) /* lool */
#undef __GNUC__
#elif !defined(__GNUC__) && defined(__APPLE__) /* modesty */
#define __GNUC__            4
#define __GNUC_MINOR__      2
#define __GNUC_PATCHLEVEL__ 1
#elif !defined(__GNUC__) && defined(__TINYC__)
#define __GNUC__            2
#define __GNUC_MINOR__      0
#define __GNUC_PATCHLEVEL__ 0
#endif

#if !defined(__x86_64__) && \
    (defined(__amd64__) || (defined(_M_AMD64) && defined(_M_X64)))
#define __x86_64__ 1
#elif !defined(__i386__) && ((defined(__i486__) || defined(__i586__) ||  \
                              defined(__i686__) || defined(__i786__)) || \
                             _M_IX86 + 0 >= 400)
#define __i386__ 1
#elif !defined(__ia16__) && (defined(__MSDOS__) || defined(__BCC__))
#define __ia16__ 1
#endif
#if __ia16__ + __i386__ + __x86_64__ + 0
#define __x86__ 1
#endif

#ifdef _MSC_VER
#define __STRICT_ANSI__
#ifndef __STDC__
#define __STDC__
#endif
#endif

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif
#ifndef __has_extension
#define __has_extension(x) 0
#endif

#ifdef unix
#undef unix
#endif

#ifdef linux
#undef linux
#endif

#ifdef __linux
#undef __linux
#endif

#ifdef __linux__
#undef __linux__
#endif

#ifndef __BIGGEST_ALIGNMENT__
#define __BIGGEST_ALIGNMENT__ 16
#endif

#ifdef _COSMO_SOURCE
#define FRAMESIZE 65536
#define _PAGESIZE 4096
#endif

#if defined(__LP64__) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/lp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xfffffffffffffffful
#define __SIZE_MAX__    0xfffffffffffffffful
#define __INTPTR_MAX__  0x7fffffffffffffffl
#define __UINTPTR_MAX__ 0xfffffffffffffffful
#define __WINT_MAX__    0xffffffffu
#define __UINTMAX_MAX__ 0xffffffffffffffffUL
#define __INTMAX_MAX__  0x7fffffffffffffffL

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        8
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      8
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __INT16_TYPE__   short int
#define __INT32_TYPE__   int
#define __INT64_TYPE__   long int
#define __INT8_TYPE__    signed char
#define __INTMAX_TYPE__  long int
#define __INTPTR_TYPE__  long int
#define __PTRDIFF_TYPE__ long int
#define __SIZE_TYPE__    long unsigned int
#define __UINT16_TYPE__  short unsigned int
#define __UINT32_TYPE__  unsigned int
#define __UINT64_TYPE__  long unsigned int
#define __UINT8_TYPE__   unsigned char
#define __UINTMAX_TYPE__ long unsigned int
#define __UINTPTR_TYPE__ long unsigned int
#define __WCHAR_TYPE__   int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#elif defined(_MSC_VER) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/llp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xffffffffffffffffull
#define __SIZE_MAX__    0xffffffffffffffffull
#define __INTPTR_MAX__  0x7fffffffffffffffll
#define __UINTPTR_MAX__ 0xffffffffffffffffull
#define __WINT_MAX__    0xffffffffu

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        4
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      4
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#define __INT8_C(c)   c
#define __UINT8_C(c)  c
#define __INT16_C(c)  c
#define __UINT16_C(c) c
#define __INT32_C(c)  c
#define __UINT32_C(c) c##U
#define __INT64_C(c)  c##LL
#define __UINT64_C(c) c##ULL

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __INT8_TYPE__    signed char
#define __UINT8_TYPE__   unsigned char
#define __INT16_TYPE__   short int
#define __UINT16_TYPE__  short unsigned int
#define __INT32_TYPE__   int
#define __UINT32_TYPE__  unsigned int
#define __INT64_TYPE__   long long int
#define __UINT64_TYPE__  long long unsigned int
#define __INTPTR_TYPE__  long long int
#define __UINTPTR_TYPE__ long long unsigned int
#define __PTRDIFF_TYPE__ long long int
#define __SIZE_TYPE__    unsigned int
#define __WCHAR_TYPE__   int
#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef __STDC__


/*!BEGIN libc/integral/c.inc */

#if __GNUC__ + 0 < 2
#define __attribute__(x)
#endif

#ifndef __cplusplus
#define COSMOPOLITAN_C_START_
#define COSMOPOLITAN_C_END_
#define COSMOPOLITAN_CXX_START_
#define COSMOPOLITAN_CXX_END_
#define COSMOPOLITAN_CXX_USING_
#endif

#ifndef __ia16__
#define __far
#endif

#if !defined(__GNUC__) && __cplusplus + 0 >= 201103L
#define typeof(x) decltype(x)
#elif !defined(__GNUC__) && __STDC_VERSION__ + 0 < 201112
#define typeof(x) __typeof(x)
#endif

#ifdef __cplusplus
#if __cplusplus >= 201103L
#define _Alignof(x) alignof(x)
#endif /* C++11 */
#else  /* __cplusplus */
#if __STDC_VERSION__ + 0 < 201112
#if __GNUC__ + _MSC_VER + 0
#define _Alignof(x) __alignof(x)
#else
#define _Alignof(x) /* basically all it ever did lool */ sizeof(x)
#endif /* GNU/MSVC/!ANSI */
#endif /* C11 */
#endif /* __cplusplus */

#if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901
#if defined(__GNUC__) || defined(_MSC_VER)
#define inline __inline
#else
#define inline
#define __inline
#endif
#endif

#ifdef __chibicc__
#define __extension__
#endif

#if __STDC_VERSION__ + 0 < 201112
#ifdef __GNUC__
#define _Alignas(x) __attribute__((__aligned__(x)))
#elif defined(_MSC_VER)
#define _Alignas(x) __declspec(align(x))
#endif
#endif

#ifdef _MSC_VER
#define __builtin_unreachable() __assume(false)
#elif !((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
        defined(__clang__) || defined(__INTEL_COMPILER) ||    \
        __has_builtin(__builtin_unreachable))
#define __builtin_unreachable() \
  for (;;) {                    \
  }
#endif

#if (!defined(__llvm__) && !__has_builtin(__builtin_assume))
#define __builtin_assume(x)    \
  do {                         \
    if (!(x))                  \
      __builtin_unreachable(); \
  } while (0)
#endif

#if __STDC_VERSION__ + 0 < 201112
#define _Atomic(TYPE) TYPE volatile
#endif

#ifdef __llvm__
#define __gnu_printf__ __printf__
#define __gnu_scanf__  __scanf__
#endif

#if __cplusplus + 0 >= 201103L
#define NULL nullptr
#elif !defined(__cplusplus)
#define NULL ((void *)0)
#else
#define NULL 0
#endif

#ifndef __cplusplus
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wc++-compat"
#endif
typedef __WCHAR_TYPE__ wchar_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC pop_options
#endif
#endif /* __cplusplus */

#ifndef __COSMOCC__


/*!BEGIN libc/stdbool.h */

#define COSMOPOLITAN_LIBC_STDBOOL_H_

#ifndef __cplusplus

#define bool _Bool
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
#define true  ((_Bool) + 1u)
#define false ((_Bool) + 0u)
#else
#define true  1
#define false 0
#endif

#else /* __cplusplus */

#define _Bool bool

#endif /* __cplusplus */

#define __bool_true_false_are_defined 1

#endif

#define _LIBCPP_STDINT_H

typedef int errno_t;
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __WINT_TYPE__ wint_t; /* uint32_t on linux but int32_t on xnu */
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ bool32;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;

#define __DEFINED_max_align_t
typedef long double max_align_t;

#ifdef _COSMO_SOURCE
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || defined(__llvm__)
typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t;
#endif
#endif /* _COSMO_SOURCE */

#ifndef __AXDX_T
#define __AXDX_T
typedef struct {
  intptr_t ax, dx;
} axdx_t;
#endif

#ifndef __chibicc__
#define va_list            __builtin_va_list
#define va_arg(ap, type)   __builtin_va_arg(ap, type)
#define va_copy(dest, src) __builtin_va_copy(dest, src)
#define va_end(ap)         __builtin_va_end(ap)
#define va_start(ap, last) __builtin_va_start(ap, last)
#else


/*!BEGIN libc/integral/lp64arg.inc */

/* variadic arguments for chibicc */

/* <sync libc/runtime/valist.c> */
struct __va_list {
  uint32_t gp_offset;
  uint32_t fp_offset;
  void *overflow_arg_area;
  void *reg_save_area;
};
/* </sync libc/runtime/valist.c> */

void *__va_arg(struct __va_list *, size_t, unsigned, unsigned);

#define __GNUC_VA_LIST 1
#define __gnuc_va_list va_list

#define va_end(AP)
#define va_copy(DST, SRC) ((DST)[0] = (SRC)[0])
#define va_start(AP, LAST)                    \
  do {                                        \
    *(AP) = *(struct __va_list *)__va_area__; \
  } while (0)

#define va_arg(AP, TYPE)                               \
  (*(TYPE *)__va_arg(AP, sizeof(TYPE), _Alignof(TYPE), \
                     __builtin_reg_class(TYPE)))

typedef struct __va_list va_list[1];
#endif

#define libcesque   dontthrow dontcallback
#define memcpyesque libcesque
#define strlenesque libcesque nosideeffect paramsnonnull()
#define vallocesque \
  libcesque __wur returnsaligned((65536)) returnspointerwithnoaliases
#define reallocesque libcesque returnsaligned((16))
#define mallocesque  reallocesque returnspointerwithnoaliases
#define interruptfn  nocallersavedregisters forcealignargpointer

#ifndef pureconst
#define pureconst __attribute__((__const__))
#endif

#ifndef forcealign
#define forcealign(bytes) __attribute__((__aligned__(bytes)))
#endif
#define thatispacked __attribute__((__packed__))

#define printfesque(n)   __attribute__((__format__(__gnu_printf__, n, n + 1)))
#define scanfesque(n)    __attribute__((__format__(__gnu_scanf__, n, n + 1)))
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))

#ifndef privileged
#define privileged \
  _Section(".privileged") dontinline dontinstrument dontubsan dontasan
#endif

#ifndef wontreturn
#if (__has_attribute(__noreturn__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208)
#define wontreturn __attribute__((__noreturn__))
#else
#define wontreturn
#endif
#endif

#ifndef nosideeffect
#if (__has_attribute(__pure__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296)
#define nosideeffect __attribute__((__pure__))
#else
#define nosideeffect
#endif
#endif

#ifndef dontinline
#ifdef _MSC_VER
#define dontinline __declspec(noinline)
#elif (__has_attribute(__noinline__) || \
       (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
#define dontinline __attribute__((__noinline__))
#else
#define dontinline
#endif
#endif

#ifndef dontclone
#if (__has_attribute(__noclone__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405)
#define dontclone __attribute__((__noclone__))
#else
#define dontclone
#endif
#endif

#ifndef forceinline
#ifdef __cplusplus
#define forceinline inline
#else
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
    !defined(__cplusplus) ||                              \
    (defined(__clang__) &&                                \
     (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define forceinline                                                 \
  static __inline __attribute__((__always_inline__, __gnu_inline__, \
                                 __no_instrument_function__, __unused__))
#else
#define forceinline                                 \
  static __inline __attribute__((__always_inline__, \
                                 __no_instrument_function__, __unused__))
#endif /* __GNUC_STDC_INLINE__ */
#endif /* GCC >= 4.3 */
#elif defined(_MSC_VER)
#define forceinline __forceinline
#else
#define forceinline static inline
#endif /* !ANSI && GCC >= 3.2 */
#endif /* __cplusplus */
#endif /* forceinline */

#ifndef __wur
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
     __has_attribute(__warn_unused_result__))
#define __wur __attribute__((__warn_unused_result__))
#else
#define __wur
#endif
#endif

#ifndef nullterminated
#if __has_attribute(__sentinel__) || __GNUC__ + 0 >= 4
#define nullterminated(x) __attribute__((__sentinel__ x))
#else
#define nullterminated(x)
#endif
#endif

#ifndef flattenout
#if __has_attribute(__flatten__) || \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401 && !defined(__llvm__))
#define flattenout __attribute__((__flatten__))
#else
#define flattenout
#endif
#endif

#ifndef externinline
#if (!defined(__cplusplus) ||                              \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
     (defined(__clang__) &&                                \
      (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__))))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define externinline extern __inline __attribute__((__gnu_inline__))
#else
#define externinline extern __inline __attribute__((__always_inline__))
#endif
#else
#define externinline inline
#endif
#endif

#ifndef relegated
#if (__has_attribute(__cold__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define relegated __attribute__((__cold__))
#else
#define relegated
#endif
#endif

#if (__has_attribute(__warning__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define warnifused(s) __attribute__((__warning__(s)))
#else
#define warnifused(s)
#endif

#ifndef firstclass
#if (__has_attribute(__hot__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define firstclass __attribute__((__hot__))
#else
#define firstclass
#endif
#endif

#ifndef paramsnonnull
#if (__has_attribute(__nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs))
#else
#define paramsnonnull(opt_1idxs)
#endif
#endif

#if __STDC_VERSION__ + 0 >= 199901L
#define hasatleast static
#else
#define hasatleast
#endif

#if __STDC_VERSION__ + 0 < 199901L && !defined(restrict)
#if !defined(__cplusplus) && \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER))
#define restrict __restrict__
#else
#define restrict
#define __restrict
#endif
#endif

#ifndef dontcallback
#if (__has_attribute(__leaf__) || \
     (!defined(__llvm__) &&       \
      (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406))
#define dontcallback __attribute__((__leaf__))
#else
#define dontcallback
#endif
#endif

#ifndef dontthrow
#if defined(__cplusplus) &&        \
    (__has_attribute(dontthrow) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define dontthrow __attribute__((__nothrow__))
#elif defined(_MSC_VER)
#define dontthrow __declspec(nothrow)
#else
#define dontthrow
#endif
#endif

#ifndef returnstwice
#if (__has_attribute(__returns_twice__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402)
#define returnstwice __attribute__((__returns_twice__))
#else
#define returnstwice
#endif
#endif

#ifndef nodebuginfo
#if __has_attribute(__nodebug__) || defined(__llvm__)
#define nodebuginfo __attribute__((__nodebug__))
#else
#define nodebuginfo
#endif
#endif

#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
    __has_attribute(__force_align_arg_pointer__)
#define forcealignargpointer __attribute__((__force_align_arg_pointer__))
#else
#define forcealignargpointer "need modern compiler"
#endif

#ifndef returnsnonnull
#if (__has_attribute(__returns_nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsnonnull __attribute__((__returns_nonnull__))
#else
#define returnsnonnull
#endif
#endif

#if (__has_attribute(__assume_aligned__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsaligned(x) __attribute__((__assume_aligned__ x))
#else
#define returnsaligned(x)
#endif

#ifndef returnspointerwithnoaliases
#if (__has_attribute(__malloc__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnspointerwithnoaliases __attribute__((__malloc__))
#elif defined(_MSC_VER)
#define returnspointerwithnoaliases __declspec(allocator)
#else
#define returnspointerwithnoaliases
#endif
#endif

#ifndef attributeallocsize
#if (__has_attribute(__alloc_size__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocsize(x) __attribute__((__alloc_size__ x))
#else
#define attributeallocsize(x)
#endif
#endif

#ifndef attributeallocalign
#if (__has_attribute(__alloc_align__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocalign(x) __attribute__((__alloc_align__ x))
#else
#define attributeallocalign(x)
#endif
#endif

#if __cplusplus + 0 >= 201103L
#define autotype(x) auto
#elif ((__has_builtin(__auto_type) || defined(__llvm__) ||     \
        (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) && \
       !defined(__chibicc__))
#define autotype(x) __auto_type
#else
#define autotype(x) typeof(x)
#endif

#define offsetof(type, member) __builtin_offsetof(type, member)

#ifdef _COSMO_SOURCE

#ifndef dontinstrument
#if (__has_attribute(__no_instrument_function__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
#if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \
    __has_attribute(__patchable_function_entry__)
#define dontinstrument                       \
  __attribute__((__no_instrument_function__, \
                 __patchable_function_entry__(0, 0)))
#else
#define dontinstrument __attribute__((__no_instrument_function__))
#endif
#else
#define dontinstrument
#endif
#endif

#ifndef mayalias
#if (__has_attribute(__may_alias__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define mayalias __attribute__((__may_alias__))
#else
#define mayalias
#endif
#endif

#ifndef dontoptimize
#if defined(__llvm__) || __has_attribute(__optnone__)
#define dontoptimize __attribute__((__optnone__))
#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define dontoptimize __attribute__((__optimize__(0)))
#endif
#endif

#ifndef optimizesize
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define optimizesize __attribute__((__optimize__("s")))
#elif defined(__llvm__) || __has_attribute(__optnone__)
#define optimizesize __attribute__((__optnone__))
#endif
#endif

#ifndef optimizespeed
/* warning: corrupts frame pointer; only use on leaf functions */
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define optimizespeed __attribute__((__optimize__(3)))
#else
#define optimizespeed
#endif
#endif

#ifndef unrollloops
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define unrollloops __attribute__((__optimize__("unroll-loops")))
#else
#define unrollloops
#endif
#endif

#ifndef _Microarchitecture
#if (__has_attribute(__target__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
#define _Microarchitecture(march) __attribute__((__target__(march)))
#else
#define _Microarchitecture(march)
#endif
#endif

#ifdef __x86_64__
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
#else
#define nocallersavedregisters "need modern compiler"
#endif
#else
#define nocallersavedregisters
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_address__))
#define dontasan __attribute__((__no_sanitize_address__))
#else
#define dontasan
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_undefined__))
#define dontubsan __attribute__((__no_sanitize_undefined__))
#else
#define dontubsan
#endif

#ifdef __x86_64__
#define notpossible          \
  do {                       \
    __asm__("nop\n\t"        \
            "ud2\n\t"        \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#elif defined(__aarch64__)
#define notpossible          \
  do {                       \
    __asm__("udf\t#0\n\t"    \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#else
#define notpossible __builtin_trap()
#endif

#define donothing \
  do {            \
  } while (0)

#define textstartup _Section(".text.startup")
#define textexit    _Section(".text.exit")
#define textreal    _Section(".text.real")
#define texthead    _Section(".text.head")
#define textwindows _Section(".text.windows")
#define antiquity   _Section(".text.antiquity")

#ifdef __llvm__
#define __builtin_ia32_movntdq(x, y) (*(x) = (y))
#endif

#ifndef _Section
#define _Section(s) __attribute__((__section__(s)))
#endif

#ifndef __llvm__
#pragma GCC diagnostic ignored "-Wformat=0" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
#pragma GCC diagnostic warning "-Wunknown-pragmas"
#else
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wconstant-logical-operand" /* what */
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wstring-plus-int"       /* features 4 losers */
#pragma GCC diagnostic ignored "-Wkeyword-compat"        /* c++ upgrade */
#pragma GCC diagnostic ignored "-Wuser-defined-literals" /* reserved for me */
#endif

#pragma GCC diagnostic ignored "-Wformat-extra-args"     /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wunused-function"       /* contradicts dce */
#pragma GCC diagnostic ignored "-Wunused-const-variable" /* sooo ridiculous */
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */
#endif

#ifdef __x86_64__
#define DebugBreak() __asm__("int3")
#elif defined(__aarch64__)
#define DebugBreak() __asm__("brk\t#0x666")
#else
#define DebugBreak() __builtin_trap()
#endif

#ifdef __aarch64__
/* raise sigill (not sigtrap) like x86 does */
#define __builtin_trap()     \
  do {                       \
    __asm__("udf\t#0x666");  \
    __builtin_unreachable(); \
  } while (0)
#endif

#endif /* _COSMO_SOURCE */

#define __veil(CONSTRAINT, EXPRESSION)                               \
  __extension__({                                                    \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                 \
    __asm__("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                     \
  })

#define __conceal(CONSTRAINT, EXPRESSION)                                     \
  __extension__({                                                             \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                          \
    __asm__ volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                              \
  })

#define __expropriate(EXPRESSION)                      \
  __extension__({                                      \
    __asm__ volatile("" ::"g"(EXPRESSION) : "memory"); \
    0;                                                 \
  })

#if !defined(__APPLE__) && defined(__x86_64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
#elif defined(__aarch64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
#else
#define __yoink(SYMBOL) (void)0
#endif

#if !defined(__APPLE__) && defined(__x86_64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#elif defined(__aarch64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
#else
#define __static_yoink(SYMBOLSTR)
#endif

#if !defined(IM_FEELING_NAUGHTY)
#define __static_yoink_source(PATH) __static_yoink(PATH)
#else
#define __static_yoink_source(PATH)
#endif

#define __weak_reference(sym, alias) __weak_reference_impl(sym, alias)
#define __weak_reference_impl(sym, alias)  \
  __asm__(".weak\t" #alias "\n\t"          \
          ".equ\t" #alias ", " #sym "\n\t" \
          ".type\t" #alias ",@notype")

#ifndef __chibicc__
#define __strong_reference(sym, alias) \
  extern __typeof(sym) alias __attribute__((__alias__(#sym)))
#else
#define __strong_reference(sym, alias) __weak_reference(sym, alias)
#endif

#if defined(__GNUC__) || defined(__llvm__)
#define __funline \
  extern __inline \
      __attribute__((__gnu_inline__, __always_inline__, __artificial__))
#else
#define __funline static inline
#endif

#if defined(__x86_64__) && (defined(__GNUC__) || defined(__llvm__)) && \
    !defined(__chibicc__) && defined(__OPTIMIZE__)
#define __target_clones(x) __attribute__((__target_clones__(x ",default")))
#else
#define __target_clones(x)
#endif

#if !defined(TINY) && !defined(__AVX__)
#define __vex __target_clones("avx")
#else
#define __vex
#endif

#define __notice(sym, str)                                                   \
  __attribute__((__section__(".notice"), __aligned__(1))) const char sym[] = \
      "\n\n" str

#define MACHINE_CODE_ANALYSIS_BEGIN_
#define MACHINE_CODE_ANALYSIS_END_
#else
#define const
#define volatile
#endif
#ifdef __cplusplus


/*!BEGIN libc/integral/cxx.inc */

#define COSMOPOLITAN_CXX_START_ namespace cosmo {
#define COSMOPOLITAN_CXX_END_   }
#define COSMOPOLITAN_CXX_USING_ using namespace cosmo;
#define COSMOPOLITAN_C_START_   extern "C" {
#define COSMOPOLITAN_C_END_     }

#if !defined(__builtin_types_compatible_p) && !__has_builtin(types_compatible_p)
#if 0 /* todo jart whyyyy */


/*!BEGIN libc/integral/cxxtypescompat.inc */

#define NAME __cxx_types_compatible
#define QUALIFIED(Q1, Q2)       \
  template <class _T, class _U> \
  struct NAME<_T Q1, _U Q2> : NAME<_T, _U> {}

template <class, class>
struct NAME {
  enum { _value = 0 };
};

template <class _T>
struct NAME<_T, _T> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[], _T[N]> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[N], _T[]> {
  enum { _value = 1 };
};

QUALIFIED(const volatile, );
QUALIFIED(const volatile, const);
QUALIFIED(const, const volatile);
QUALIFIED(volatile, const volatile);
QUALIFIED(const volatile, volatile);
QUALIFIED(const, volatile);
QUALIFIED(volatile, const);
QUALIFIED(, const);
QUALIFIED(const, );
QUALIFIED(, volatile);
QUALIFIED(volatile, );

#undef QUALIFIED
#undef NAME
#define __builtin_types_compatible_p(A, B) \
  (__cxx_types_compatible<A, B>::_value)
#else
#define __builtin_types_compatible_p(A, B) 0
#endif
#endif

#if !defined(__builtin_choose_expr) && !__has_builtin(choose_expr)
#if 1
template <bool _P, typename _T, typename _U>
struct __cxx_choose_expr {
  __cxx_choose_expr(_T _a, _U _b) : _value(_a) {
  }
  const _T _value;
};
template <typename _T, typename _U>
struct __cxx_choose_expr<false, _T, _U> {
  __cxx_choose_expr(_T _a, _U _b) : _value(_b) {
  }
  const _U _value;
};
#define __builtin_choose_expr(X, A, B) \
  (__cxx_choose_expr<X, typeof(A), typeof(B)>(A, B)._value)
#else
#define __builtin_choose_expr(X, A, B) ((X) ? (A) : (B))
#endif
#endif

#ifdef __aarch64__
/* todo jart whyyyy */
#define _Float16 __fp16
#endif
#endif
#endif


/*!BEGIN ape/ape.h */

#define COSMOPOLITAN_APE_APE_H_

#define APE_VERSION_MAJOR 1
#define APE_VERSION_MINOR 10
#define APE_VERSION_STR   APE_VERSION_STR_(APE_VERSION_MAJOR, APE_VERSION_MINOR)
#define APE_VERSION_NOTE  APE_VERSION_NOTE_(APE_VERSION_MAJOR, APE_VERSION_MINOR)

#define APE_VERSION_STR__(x, y) #x "." #y
#define APE_VERSION_STR_(x, y)  APE_VERSION_STR__(x, y)
#define APE_VERSION_NOTE_(x, y) (100000000 * (x) + 1000000 * (y))



/*!BEGIN ape/relocations.h */

#define COSMOPOLITAN_APE_RELOCATIONS_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ αcτµαlly pδrταblε εxεcµταblε § relocations                                   │
╚──────────────────────────────────────────────────────────────────────────────╝
  One of the things αcτµαlly pδrταblε εxεcµταblε does a good job
  abstracting, is how a program needs to exist at three addresses
  simultaneously during the early stages of the loading process.

  By default, the linker calculates all symbols using virtual addresses.
  In some cases it's necessary to use addend macros that change virtual
  addresses into the other two types: physical and real. */

#define IMAGE_BASE_REAL 0x2000

#ifndef IMAGE_BASE_VIRTUAL
#define IMAGE_BASE_VIRTUAL 0x400000
#endif

#ifndef IMAGE_BASE_PHYSICAL
#define IMAGE_BASE_PHYSICAL 0x100000
#endif

/**
 * Returns Relative Virtual Address.
 */
#define RVA(x) ((x) - (IMAGE_BASE_VIRTUAL))

/**
 * Adjusts virtual address so it's relative to load address.
 */
#define PHYSICAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_PHYSICAL))

/**
 * Makes high-entropy read-only addresses relocatable in real mode.
 */
#define REAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_REAL))

#if IMAGE_BASE_VIRTUAL % 0x1000 != 0
#error "IMAGE_BASE_VIRTUAL must be 4kb aligned"
#endif
#if IMAGE_BASE_PHYSICAL % 0x1000 != 0
#error "IMAGE_BASE_PHYSICAL must be 4kb aligned"
#endif
#if IMAGE_BASE_REAL % 0x1000 != 0
#error "IMAGE_BASE_REAL must be 4kb aligned"
#endif



/*!BEGIN libc/ar.h */

#define COSMOPOLITAN_LIBC_AR_H_
COSMOPOLITAN_C_START_

#define ARMAG  "!<arch>\n"
#define SARMAG 8
#define ARFMAG "`\n"

struct ar_hdr {
  char ar_name[16];
  char ar_date[12];
  char ar_uid[6];
  char ar_gid[6];
  char ar_mode[8];
  char ar_size[10];
  char ar_fmag[2];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/assert.h */

#undef _ASSERT_H
#undef assert
#ifdef _COSMO_SOURCE
#undef unassert
#undef npassert
#ifndef NDEBUG
#undef __assert_macro
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

#define _ASSERT_H
COSMOPOLITAN_C_START_

void __assert_fail(const char *, const char *, int) libcesque;
void unassert(const char *, const char *, int) libcesque;

#ifdef NDEBUG
#define assert(x) ((void)0)
#else
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0)))
#endif

#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
#undef static_assert
#define static_assert _Static_assert
#endif

#ifdef _COSMO_SOURCE
#ifndef NDEBUG
#define unassert(x) __assert_macro(x, #x)
#define npassert(x) __assert_macro(x, #x)
#define __assert_macro(x, s)             \
  ({                                     \
    if (__builtin_expect(!(x), 0)) {     \
      (unassert)(s, __FILE__, __LINE__); \
      __asm__("nop");                    \
      __builtin_unreachable();           \
    }                                    \
    (void)0;                             \
  })
#else
#define npassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_trap();              \
    }                                \
    (void)0;                         \
  })
#define unassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_unreachable();       \
    }                                \
    (void)0;                         \
  })
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/atomic.h */

#define COSMOPOLITAN_LIBC_ATOMIC_H_

#define atomic_bool           _Atomic(_Bool)
#define atomic_bool32         _Atomic(__INT32_TYPE__)
#define atomic_char           _Atomic(char)
#define atomic_schar          _Atomic(signed char)
#define atomic_uchar          _Atomic(unsigned char)
#define atomic_short          _Atomic(short)
#define atomic_ushort         _Atomic(unsigned short)
#define atomic_int            _Atomic(int)
#define atomic_uint           _Atomic(unsigned int)
#define atomic_long           _Atomic(long)
#define atomic_ulong          _Atomic(unsigned long)
#define atomic_llong          _Atomic(long long)
#define atomic_ullong         _Atomic(unsigned long long)
#define atomic_char16_t       _Atomic(__CHAR16_TYPE__)
#define atomic_char32_t       _Atomic(__CHAR32_TYPE__)
#define atomic_wchar_t        _Atomic(__WCHAR_TYPE__)
#define atomic_intptr_t       _Atomic(__INTPTR_TYPE__)
#define atomic_uintptr_t      _Atomic(__UINTPTR_TYPE__)
#define atomic_size_t         _Atomic(__SIZE_TYPE__)
#define atomic_ptrdiff_t      _Atomic(__PTRDIFF_TYPE__)
#define atomic_int_fast8_t    _Atomic(__INT_FAST8_TYPE__)
#define atomic_uint_fast8_t   _Atomic(__UINT_FAST8_TYPE__)
#define atomic_int_fast16_t   _Atomic(__INT_FAST16_TYPE__)
#define atomic_uint_fast16_t  _Atomic(__UINT_FAST16_TYPE__)
#define atomic_int_fast32_t   _Atomic(__INT_FAST32_TYPE__)
#define atomic_uint_fast32_t  _Atomic(__UINT_FAST32_TYPE__)
#define atomic_int_fast64_t   _Atomic(__INT_FAST64_TYPE__)
#define atomic_uint_fast64_t  _Atomic(__UINT_FAST64_TYPE__)
#define atomic_int_least8_t   _Atomic(__INT_LEAST8_TYPE__)
#define atomic_uint_least8_t  _Atomic(__UINT_LEAST8_TYPE__)
#define atomic_int_least16_t  _Atomic(__INT_LEAST16_TYPE__)
#define atomic_uint_least16_t _Atomic(__UINT_LEAST16_TYPE__)
#define atomic_int_least32_t  _Atomic(__INT_LEAST32_TYPE__)
#define atomic_uint_least32_t _Atomic(__UINT_LEAST32_TYPE__)
#define atomic_int_least64_t  _Atomic(__INT_LEAST64_TYPE__)
#define atomic_uint_least64_t _Atomic(__UINT_LEAST64_TYPE__)

#ifdef __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_BOOL_LOCK_FREE     __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __CLANG_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __CLANG_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __CLANG_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __CLANG_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __CLANG_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __CLANG_ATOMIC_POINTER_LOCK_FREE
#else
#define ATOMIC_BOOL_LOCK_FREE     __GCC_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __GCC_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __GCC_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __GCC_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __GCC_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __GCC_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __GCC_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __GCC_ATOMIC_POINTER_LOCK_FREE
#endif



/*!BEGIN libc/complex.h */

#define COSMOPOLITAN_LIBC_COMPLEX_H_
COSMOPOLITAN_C_START_
#if __STDC_VERSION__ + 0 >= 201112 && !defined(__STDC_NO_COMPLEX__)

#define complex   _Complex
#define imaginary _Imaginary

double cabs(complex double) libcesque;
double carg(complex double) libcesque;
double cimag(complex double) libcesque;
double creal(complex double) libcesque;

float cabsf(complex float) libcesque;
float cargf(complex float) libcesque;
float cimagf(complex float) libcesque;
float crealf(complex float) libcesque;

long double cabsl(complex long double) libcesque;
long double cargl(complex long double) libcesque;
long double cimagl(complex long double) libcesque;
long double creall(complex long double) libcesque;

complex double cacos(complex double) libcesque;
complex double cacosh(complex double) libcesque;
complex double casin(complex double) libcesque;
complex double casinh(complex double) libcesque;
complex double catan(complex double) libcesque;
complex double catanh(complex double) libcesque;
complex double ccos(complex double) libcesque;
complex double ccosh(complex double) libcesque;
complex double cexp(complex double) libcesque;
complex double cexp2(complex double) libcesque;
complex double clog(complex double) libcesque;
complex double conj(complex double) libcesque;
complex double cpow(complex double, complex double) libcesque;
complex double cproj(complex double) libcesque;
complex double csin(complex double) libcesque;
complex double csinh(complex double) libcesque;
complex double csqrt(complex double) libcesque;
complex double ctan(complex double) libcesque;
complex double ctanh(complex double) libcesque;

complex float cacosf(complex float) libcesque;
complex float cacoshf(complex float) libcesque;
complex float casinf(complex float) libcesque;
complex float casinhf(complex float) libcesque;
complex float catanf(complex float) libcesque;
complex float catanhf(complex float) libcesque;
complex float ccosf(complex float) libcesque;
complex float ccoshf(complex float) libcesque;
complex float cexpf(complex float) libcesque;
complex float cexp2f(complex float) libcesque;
complex float clogf(complex float) libcesque;
complex float conjf(complex float) libcesque;
complex float cpowf(complex float, complex float) libcesque;
complex float cprojf(complex float) libcesque;
complex float csinf(complex float) libcesque;
complex float csinhf(complex float) libcesque;
complex float csqrtf(complex float) libcesque;
complex float ctanf(complex float) libcesque;
complex float ctanhf(complex float) libcesque;

complex long double cprojl(complex long double) libcesque;
complex long double csinhl(complex long double) libcesque;
complex long double csinl(complex long double) libcesque;
complex long double csqrtl(complex long double) libcesque;
complex long double ctanhl(complex long double) libcesque;
complex long double ctanl(complex long double) libcesque;
complex long double cacoshl(complex long double) libcesque;
complex long double cacosl(complex long double) libcesque;
complex long double casinhl(complex long double) libcesque;
complex long double casinl(complex long double) libcesque;
complex long double catanhl(complex long double) libcesque;
complex long double catanl(complex long double) libcesque;
complex long double ccoshl(complex long double) libcesque;
complex long double ccosl(complex long double) libcesque;
complex long double cexpl(complex long double) libcesque;
complex long double cexp2l(complex long double) libcesque;
complex long double clogl(complex long double) libcesque;
complex long double conjl(complex long double) libcesque;
complex long double cpowl(complex long double, complex long double) libcesque;

#ifndef __cplusplus
#define __CIMAG(x, t)   \
  (+(union {            \
      _Complex t __z;   \
      t __xy[2];        \
    }){(_Complex t)(x)} \
        .__xy[1])
#define creal(x)  ((double)(x))
#define crealf(x) ((float)(x))
#define creall(x) ((long double)(x))
#define cimag(x)  __CIMAG(x, double)
#define cimagf(x) __CIMAG(x, float)
#define cimagl(x) __CIMAG(x, long double)
#endif

#ifdef __GNUC__
#define _Complex_I (__extension__(0.0f + 1.0fi))
#else
#define _Complex_I (0.0f + 1.0fi)
#endif

#ifdef _Imaginary_I
#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I * (t)(y))
#elif defined(__clang__)
#define __CMPLX(x, y, t) (+(_Complex t){(t)(x), (t)(y)})
#else
#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y)))
#endif

#define CMPLX(x, y)  __CMPLX(x, y, double)
#define CMPLXF(x, y) __CMPLX(x, y, float)
#define CMPLXL(x, y) __CMPLX(x, y, long double)

#endif /* C11 */
COSMOPOLITAN_C_END_


/*!BEGIN libc/cosmo.h */

#define COSMOPOLITAN_LIBC_COSMO_H_
COSMOPOLITAN_C_START_

errno_t cosmo_once(_Atomic(uint32_t) *, void (*)(void));
int systemvpe(const char *, char *const[], char *const[]) libcesque;
char *GetProgramExecutableName(void);
void unleaf(void);
int __demangle(char *, const char *, size_t);
int __is_mangled(const char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/cxxabi.h */

#define _CXXABI_H
COSMOPOLITAN_C_START_

#ifdef __cplusplus
namespace __cxxabiv1 {
#endif /* __cplusplus */

char *__cxa_demangle(const char *, char *, size_t *, int *);
int __cxa_atexit(void (*)(void *), void *, void *) paramsnonnull((1)) dontthrow;
int __cxa_thread_atexit(void (*)(void *), void *, void *) dontthrow;
void __cxa_finalize(void *);

#ifdef __cplusplus
} /* namespace __cxxabiv1 */
#endif /* __cplusplus */

COSMOPOLITAN_C_END_


/*!BEGIN libc/dce.h */

#ifndef COSMOPOLITAN_LIBC_DCE_H_
#define COSMOPOLITAN_LIBC_DCE_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § autotune » dead code elimination                              │
╚─────────────────────────────────────────────────────────────────────────────*/

#ifndef SUPPORT_VECTOR
#ifdef __x86_64__
/**
 * Supported Platforms Tuning Knob (Runtime & Compile-Time)
 * Tuning this bitmask will remove platform polyfills at compile-time.
 */
#define SUPPORT_VECTOR 255
#else
#define SUPPORT_VECTOR (_HOSTLINUX | _HOSTXNU | _HOSTFREEBSD)
#endif
#endif

#define _HOSTLINUX   1
#define _HOSTMETAL   2
#define _HOSTWINDOWS 4
#define _HOSTXNU     8
#define _HOSTOPENBSD 16
#define _HOSTFREEBSD 32
#define _HOSTNETBSD  64

#ifdef NDEBUG
#define NoDebug() 1
#else
#define NoDebug() 0
#endif

#ifdef MODE_DBG
#define IsModeDbg() 1
#else
#define IsModeDbg() 0
#endif

#ifdef TRUSTWORTHY
#define IsTrustworthy() 1
#else
#define IsTrustworthy() 0
#endif

#ifdef TINY
#define IsTiny() 1
#else
#define IsTiny() 0
#endif

#ifdef __OPTIMIZE__
#define IsOptimized() 1
#else
#define IsOptimized() 0
#endif

#ifdef __SANITIZE_ADDRESS__
#define IsAsan() 1
#else
#define IsAsan() 0
#endif

#ifdef __aarch64__
#define IsAarch64()    1
#define IsXnuSilicon() IsXnu()
#else
#define IsAarch64()    0
#define IsXnuSilicon() 0
#endif

#if defined(__x86_64__)
#define _ARCH_NAME "amd64"
#elif defined(__aarch64__)
#define _ARCH_NAME "arm64"
#elif defined(__powerpc64__)
#define _ARCH_NAME "ppc64"
#elif defined(__s390x__)
#define _ARCH_NAME "s390x"
#elif defined(__riscv)
#define _ARCH_NAME "riscv"
#endif

#define SupportsLinux()   ((SUPPORT_VECTOR & _HOSTLINUX) == _HOSTLINUX)
#define SupportsMetal()   ((SUPPORT_VECTOR & _HOSTMETAL) == _HOSTMETAL)
#define SupportsWindows() ((SUPPORT_VECTOR & _HOSTWINDOWS) == _HOSTWINDOWS)
#define SupportsXnu()     ((SUPPORT_VECTOR & _HOSTXNU) == _HOSTXNU)
#define SupportsFreebsd() ((SUPPORT_VECTOR & _HOSTFREEBSD) == _HOSTFREEBSD)
#define SupportsOpenbsd() ((SUPPORT_VECTOR & _HOSTOPENBSD) == _HOSTOPENBSD)
#define SupportsNetbsd()  ((SUPPORT_VECTOR & _HOSTNETBSD) == _HOSTNETBSD)
#define SupportsBsd() \
  (!!(SUPPORT_VECTOR & (_HOSTXNU | _HOSTFREEBSD | _HOSTOPENBSD | _HOSTNETBSD)))
#define SupportsSystemv() \
  (!!(SUPPORT_VECTOR &    \
      (_HOSTLINUX | _HOSTXNU | _HOSTOPENBSD | _HOSTFREEBSD | _HOSTNETBSD)))

#ifndef __ASSEMBLER__
#define IsLinux()   (SupportsLinux() && (__hostos & _HOSTLINUX))
#define IsMetal()   (SupportsMetal() && (__hostos & _HOSTMETAL))
#define IsWindows() (SupportsWindows() && (__hostos & _HOSTWINDOWS))
#define IsXnu()     (SupportsXnu() && (__hostos & _HOSTXNU))
#define IsFreebsd() (SupportsFreebsd() && (__hostos & _HOSTFREEBSD))
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & _HOSTOPENBSD))
#define IsNetbsd()  (SupportsNetbsd() && (__hostos & _HOSTNETBSD))
#define IsBsd()     (IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd())
#else
/* clang-format off */
#define IsLinux() $_HOSTLINUX,__hostos(%rip)
#define IsMetal() $_HOSTMETAL,__hostos(%rip)
#define IsWindows() $_HOSTWINDOWS,__hostos(%rip)
#define IsBsd() $_HOSTXNU|_HOSTFREEBSD|_HOSTOPENBSD|_HOSTNETBSD,__hostos(%rip)
#define IsXnu() $_HOSTXNU,__hostos(%rip)
#define IsFreebsd() $_HOSTFREEBSD,__hostos(%rip)
#define IsOpenbsd() $_HOSTOPENBSD,__hostos(%rip)
#define IsNetbsd() $_HOSTNETBSD,__hostos(%rip)
/* clang-format on */
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __hostos;

int IsQemuUser(void);

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_DCE_H_ */


/*!BEGIN libc/errno.h */

#define COSMOPOLITAN_LIBC_ERRNO_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview System Five error codes.
 *
 * This file defines the `errno` global variable. When system calls
 * (e.g. read(), write(), etc.) fail they return -1 to indicate the
 * failure, and that is *the only* error return value. System calls
 * also update `errno` too whenever -1 is returned (otherwise errno
 * isn't changed) to be a non-zero value holding one of the numbers
 * below, in order to indicate why the system call failed.
 *
 * There is only one exception to the above rule; some system calls
 * are documented with the `@returnserrno` tag, which means they'll
 * return the error number rather than stuffing it in a global. You
 * can usually spot these system calls easily since most of them'll
 * have names like `posix_foo()` or `pthread_bar()`.
 *
 * @see libc/sysv/consts.sh for assigned numbers
 * @see libc/sysv/dos2errno.sh for multimapped numbers
 */

#if defined(__GNUC__) && defined(__aarch64__) && !defined(__cplusplus)
/* this header is included by 700+ files; therefore we */
/* hand-roll &__get_tls()->tib_errno to avoid #include */
/* cosmopolitan uses x28 as the tls register b/c apple */
#define errno                                      \
  (*__extension__({                                \
    errno_t *__ep;                                 \
    __asm__("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
    __ep;                                          \
  }))
#else
#define errno (*__errno_location())
#endif

/**
 * System call unavailable.
 * @note kNtErrorInvalidFunction on NT
 */
extern const errno_t ENOSYS;

/**
 * Operation not permitted.
 * @note kNtErrorInvalidAccess on NT
 */
extern const errno_t EPERM;

/**
 * No such file or directory.
 */
extern const errno_t ENOENT;

/**
 * No such process.
 */
extern const errno_t ESRCH;

/**
 * The greatest of all errnos.
 */
extern const errno_t EINTR;

/**
 * Unix consensus.
 */
extern const errno_t EIO;

/**
 * No such device or address.
 */
extern const errno_t ENXIO;

/**
 * Argument list too long.
 */
extern const errno_t E2BIG;

/**
 * Exec format error.
 */
extern const errno_t ENOEXEC;

/**
 * Bad file descriptor.
 */
extern const errno_t EBADF;

/**
 * No child process.
 */
extern const errno_t ECHILD;

/**
 * Resource temporarily unavailable (e.g. SO_RCVTIMEO expired, too many
 * processes, too much memory locked, read or write with O_NONBLOCK needs
 * polling, etc.).
 */
extern const errno_t EAGAIN;

/**
 * We require more vespene gas.
 */
extern const errno_t ENOMEM;

/**
 * Permission denied.
 */
extern const errno_t EACCES;

/**
 * Pointer passed to system call that would otherwise segfault.
 */
extern const errno_t EFAULT;

/**
 * Block device required.
 */
extern const errno_t ENOTBLK;

/**
 * Device or resource busy.
 */
extern const errno_t EBUSY;

/**
 * File exists.
 */
extern const errno_t EEXIST;

/**
 * Improper link.
 */
extern const errno_t EXDEV;

/**
 * No such device.
 */
extern const errno_t ENODEV;

/**
 * Not a directory.
 */
extern const errno_t ENOTDIR;

/**
 * Is a a directory.
 */
extern const errno_t EISDIR;

/**
 * Invalid argument.
 */
extern const errno_t EINVAL;

/**
 * Too many open files in system.
 */
extern const errno_t ENFILE;

/**
 * Too many open files.
 */
extern const errno_t EMFILE;

/**
 * Inappropriate i/o control operation.
 */
extern const errno_t ENOTTY;

/**
 * Won't open executable that's executing in write mode.
 */
extern const errno_t ETXTBSY;

/**
 * File too large.
 */
extern const errno_t EFBIG;

/**
 * No space left on device.
 */
extern const errno_t ENOSPC;

/**
 * Disk quota exceeded.
 */
extern const errno_t EDQUOT;

/**
 * Invalid seek.
 */
extern const errno_t ESPIPE;

/**
 * Read-only filesystem.
 */
extern const errno_t EROFS;

/**
 * Too many links.
 */
extern const errno_t EMLINK;

/**
 * Broken pipe.
 */
extern const errno_t EPIPE;

/**
 * Mathematics argument out of domain of function.
 */
extern const errno_t EDOM;

/**
 * Result too large.
 */
extern const errno_t ERANGE;

/**
 * Resource deadlock avoided.
 */
extern const errno_t EDEADLK;

/**
 * Filename too long.
 */
extern const errno_t ENAMETOOLONG;

/**
 * No locks available.
 */
extern const errno_t ENOLCK;

/**
 * Directory not empty.
 */
extern const errno_t ENOTEMPTY;

/**
 * Too many levels of symbolic links.
 */
extern const errno_t ELOOP;

/**
 * No message error.
 */
extern const errno_t ENOMSG;

/**
 * Identifier removed.
 */
extern const errno_t EIDRM;

/**
 * Timer expired.
 */
extern const errno_t ETIME;

/**
 * Protocol error.
 */
extern const errno_t EPROTO;

/**
 * Overflow error.
 */
extern const errno_t EOVERFLOW;

/**
 * Unicode decoding error.
 */
extern const errno_t EILSEQ;

/**
 * Too many users.
 */
extern const errno_t EUSERS;

/**
 * Not a socket.
 */
extern const errno_t ENOTSOCK;

/**
 * Destination address required.
 */
extern const errno_t EDESTADDRREQ;

/**
 * Message too long.
 */
extern const errno_t EMSGSIZE;

/**
 * Protocol wrong type for socket.
 */
extern const errno_t EPROTOTYPE;

/**
 * Protocol not available.
 */
extern const errno_t ENOPROTOOPT;

/**
 * Protocol not supported.
 */
extern const errno_t EPROTONOSUPPORT;

/**
 * Socket type not supported.
 */
extern const errno_t ESOCKTNOSUPPORT;

/**
 * Operation not supported.
 */
extern const errno_t ENOTSUP;

/**
 * Socket operation not supported.
 */
extern const errno_t EOPNOTSUPP;

/**
 * Protocol family not supported.
 */
extern const errno_t EPFNOSUPPORT;

/**
 * Address family not supported.
 */
extern const errno_t EAFNOSUPPORT;

/**
 * Address already in use.
 */
extern const errno_t EADDRINUSE;

/**
 * Address not available.
 */
extern const errno_t EADDRNOTAVAIL;

/**
 * Network is down.
 */
extern const errno_t ENETDOWN;

/**
 * Host is unreachable.
 */
extern const errno_t ENETUNREACH;

/**
 * Connection reset by network.
 */
extern const errno_t ENETRESET;

/**
 * Connection reset before accept.
 */
extern const errno_t ECONNABORTED;

/**
 * Connection reset by client.
 */
extern const errno_t ECONNRESET;

/**
 * No buffer space available.
 */
extern const errno_t ENOBUFS;

/**
 * Socket is connected.
 */
extern const errno_t EISCONN;

/**
 * Socket is not connected.
 */
extern const errno_t ENOTCONN;

/**
 * Cannot send after transport endpoint shutdown.
 */
extern const errno_t ESHUTDOWN;

/**
 * Too many references: cannot splice.
 */
extern const errno_t ETOOMANYREFS;

/**
 * Connection timed out.
 */
extern const errno_t ETIMEDOUT;

/**
 * Connection refused error.
 */
extern const errno_t ECONNREFUSED;

/**
 * Host down error.
 */
extern const errno_t EHOSTDOWN;

/**
 * Host unreachable error.
 */
extern const errno_t EHOSTUNREACH;

/**
 * Connection already in progress.
 */
extern const errno_t EALREADY;

/**
 * Operation already in progress.
 */
extern const errno_t EINPROGRESS;

/**
 * Stale error.
 */
extern const errno_t ESTALE;

/**
 * Remote error.
 */
extern const errno_t EREMOTE;

/**
 * Bad message.
 */
extern const errno_t EBADMSG;

/**
 * Operation canceled.
 */
extern const errno_t ECANCELED;

/**
 * Owner died.
 */
extern const errno_t EOWNERDEAD;

/**
 * State not recoverable.
 */
extern const errno_t ENOTRECOVERABLE;

/**
 * No network.
 */
extern const errno_t ENONET;

/**
 * Please restart syscall.
 */
extern const errno_t ERESTART;

/**
 * Out of streams resources.
 */
extern const errno_t ENOSR;

/**
 * No string.
 */
extern const errno_t ENOSTR;

/**
 * No data.
 */
extern const errno_t ENODATA;

/**
 * Multihop attempted.
 */
extern const errno_t EMULTIHOP;

/**
 * Link severed.
 */
extern const errno_t ENOLINK;

/**
 * No medium found.
 */
extern const errno_t ENOMEDIUM;

/**
 * Wrong medium type.
 */
extern const errno_t EMEDIUMTYPE;

/**
 * Inappropriate file type or format.
 */
extern const errno_t EFTYPE;

extern const errno_t EAUTH;
extern const errno_t EBADARCH;
extern const errno_t EBADEXEC;
extern const errno_t EBADMACHO;
extern const errno_t EBADRPC;
extern const errno_t EDEVERR;
extern const errno_t ENEEDAUTH;
extern const errno_t ENOATTR;
extern const errno_t ENOPOLICY;
extern const errno_t EPROCLIM;
extern const errno_t EPROCUNAVAIL;
extern const errno_t EPROGMISMATCH;
extern const errno_t EPROGUNAVAIL;
extern const errno_t EPWROFF;
extern const errno_t ERPCMISMATCH;
extern const errno_t ESHLIBVERS;
extern const errno_t EADV;
extern const errno_t EBADE;
extern const errno_t EBADFD;
extern const errno_t EBADR;
extern const errno_t EBADRQC;
extern const errno_t EBADSLT;
extern const errno_t ECHRNG;
extern const errno_t ECOMM;
extern const errno_t EDOTDOT;
extern const errno_t EHWPOISON;
extern const errno_t EISNAM;
extern const errno_t EKEYEXPIRED;
extern const errno_t EKEYREJECTED;
extern const errno_t EKEYREVOKED;
extern const errno_t EL2HLT;
extern const errno_t EL2NSYNC;
extern const errno_t EL3HLT;
extern const errno_t EL3RST;
extern const errno_t ELIBACC;
extern const errno_t ELIBBAD;
extern const errno_t ELIBEXEC;
extern const errno_t ELIBMAX;
extern const errno_t ELIBSCN;
extern const errno_t ELNRNG;
extern const errno_t ENAVAIL;
extern const errno_t ENOANO;
extern const errno_t ENOCSI;
extern const errno_t ENOKEY;
extern const errno_t ENOPKG;
extern const errno_t ENOTNAM;
extern const errno_t ENOTUNIQ;
extern const errno_t EREMCHG;
extern const errno_t EREMOTEIO;
extern const errno_t ERFKILL;
extern const errno_t ESRMNT;
extern const errno_t ESTRPIPE;
extern const errno_t EUCLEAN;
extern const errno_t EUNATCH;
extern const errno_t EXFULL;

#define E2BIG           E2BIG
#define EACCES          EACCES
#define EADDRINUSE      EADDRINUSE
#define EADDRNOTAVAIL   EADDRNOTAVAIL
#define EAFNOSUPPORT    EAFNOSUPPORT
#define EAGAIN          EAGAIN
#define EALREADY        EALREADY
#define EBADF           EBADF
#define EBADMSG         EBADMSG
#define EBUSY           EBUSY
#define ECANCELED       ECANCELED
#define ECHILD          ECHILD
#define ECONNABORTED    ECONNABORTED
#define ECONNREFUSED    ECONNREFUSED
#define ECONNRESET      ECONNRESET
#define EDEADLK         EDEADLK
#define EDESTADDRREQ    EDESTADDRREQ
#define EDOM            EDOM
#define EDQUOT          EDQUOT
#define EEXIST          EEXIST
#define EFAULT          EFAULT
#define EFBIG           EFBIG
#define EFTYPE          EFTYPE
#define EHOSTDOWN       EHOSTDOWN
#define EHOSTUNREACH    EHOSTUNREACH
#define EIDRM           EIDRM
#define EILSEQ          EILSEQ
#define EINPROGRESS     EINPROGRESS
#define EINTR           EINTR
#define EINVAL          EINVAL
#define EIO             EIO
#define EISCONN         EISCONN
#define EISDIR          EISDIR
#define ELOOP           ELOOP
#define EMEDIUMTYPE     EMEDIUMTYPE
#define EMFILE          EMFILE
#define EMLINK          EMLINK
#define EMSGSIZE        EMSGSIZE
#define EMULTIHOP       EMULTIHOP
#define ENAMETOOLONG    ENAMETOOLONG
#define ENETDOWN        ENETDOWN
#define ENETRESET       ENETRESET
#define ENETUNREACH     ENETUNREACH
#define ENFILE          ENFILE
#define ENOBUFS         ENOBUFS
#define ENODATA         ENODATA
#define ENODEV          ENODEV
#define ENOENT          ENOENT
#define ENOEXEC         ENOEXEC
#define ENOLCK          ENOLCK
#define ENOLINK         ENOLINK
#define ENOMEDIUM       ENOMEDIUM
#define ENOMEM          ENOMEM
#define ENOMSG          ENOMSG
#define ENONET          ENONET
#define ENOPROTOOPT     ENOPROTOOPT
#define ENOSPC          ENOSPC
#define ENOSR           ENOSR
#define ENOSTR          ENOSTR
#define ENOSYS          ENOSYS
#define ENOTBLK         ENOTBLK
#define ENOTCONN        ENOTCONN
#define ENOTDIR         ENOTDIR
#define ENOTEMPTY       ENOTEMPTY
#define ENOTRECOVERABLE ENOTRECOVERABLE
#define ENOTSOCK        ENOTSOCK
#define ENOTSUP         ENOTSUP
#define ENOTTY          ENOTTY
#define ENXIO           ENXIO
#define EOPNOTSUPP      EOPNOTSUPP
#define EOVERFLOW       EOVERFLOW
#define EOWNERDEAD      EOWNERDEAD
#define EPERM           EPERM
#define EPFNOSUPPORT    EPFNOSUPPORT
#define EPIPE           EPIPE
#define EPROTO          EPROTO
#define EPROTONOSUPPORT EPROTONOSUPPORT
#define EPROTOTYPE      EPROTOTYPE
#define ERANGE          ERANGE
#define EREMOTE         EREMOTE
#define ERESTART        ERESTART
#define EROFS           EROFS
#define ESHUTDOWN       ESHUTDOWN
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT
#define ESPIPE          ESPIPE
#define ESRCH           ESRCH
#define ESTALE          ESTALE
#define ETIME           ETIME
#define ETIMEDOUT       ETIMEDOUT
#define ETOOMANYREFS    ETOOMANYREFS
#define ETXTBSY         ETXTBSY
#define EUSERS          EUSERS
#define EWOULDBLOCK     EAGAIN
#define EXDEV           EXDEV

extern errno_t __errno;
errno_t *__errno_location(void) dontthrow pureconst;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
extern char *program_invocation_short_name;
extern char *program_invocation_name;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/inttypes.h */

#define COSMOPOLITAN_LIBC_INTTYPES_H_

typedef __INT_LEAST8_TYPE__ int_least8_t;
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
typedef __INT_LEAST16_TYPE__ int_least16_t;
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
typedef __INT_LEAST32_TYPE__ int_least32_t;
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
typedef __INT_LEAST64_TYPE__ int_least64_t;
typedef __UINT_LEAST64_TYPE__ uint_least64_t;

typedef __INT_FAST8_TYPE__ int_fast8_t;
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
typedef __INT_FAST16_TYPE__ int_fast16_t;
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
typedef __INT_FAST32_TYPE__ int_fast32_t;
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
typedef __INT_FAST64_TYPE__ int_fast64_t;
typedef __UINT_FAST64_TYPE__ uint_fast64_t;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define __PRI8 "hh"

#if __SIZEOF_INT__ == 2
#define __PRI16 ""
#elif __SIZEOF_SHORT__ == 2
#define __PRI16 "h"
#elif __SIZEOF_LONG__ == 2
#define __PRI16 "l"
#endif

#if __SIZEOF_INT__ == 4
#define __PRI32 ""
#elif __SIZEOF_LONG__ == 4
#define __PRI32 "l"
#elif __SIZEOF_LONG_LONG__ == 4
#define __PRI32 "ll"
#endif

#if __SIZEOF_INT__ == 8
#define __PRI64 ""
#elif __SIZEOF_LONG__ == 8
#define __PRI64 "l"
#elif __SIZEOF_LONG_LONG__ == 8
#define __PRI64 "ll"
#endif

#if __SIZEOF_INT__ == 16
#define __PRI128 ""
#elif __SIZEOF_LONG__ == 16
#define __PRI128 "l"
#elif __SIZEOF_LONG_LONG__ == 16
#define __PRI128 "ll"
#elif __SIZEOF_INTMAX__ == 16
#define __PRI128 "j"
#else
#define __PRI128 "jj"
#endif

#if __SIZEOF_POINTER__ == __SIZEOF_INT__
#define __PRIPTR ""
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG__
#define __PRIPTR "l"
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__
#define __PRIPTR "ll"
#endif

#if __INT_FAST16_WIDTH__ == 16
#define __PRIFAST16 "h"
#elif __INT_FAST16_WIDTH__ == 32
#define __PRIFAST16 ""
#else
#define __PRIFAST16 "l"
#endif

#if __INT_FAST32_WIDTH__ == 32
#define __PRIFAST32 ""
#else
#define __PRIFAST32 "l"
#endif

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » decimal                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRId8   __PRI8 "d"
#define PRId16  __PRI16 "d"
#define PRId32  __PRI32 "d"
#define PRId64  __PRI64 "d"
#define PRId128 __PRI128 "d"

#define PRIdLEAST8   __PRI8 "d"
#define PRIdLEAST16  __PRI16 "d"
#define PRIdLEAST32  __PRI32 "d"
#define PRIdLEAST64  __PRI64 "d"
#define PRIdLEAST128 __PRI128 "d"

#define PRIdFAST8   __PRI8 "d"
#define PRIdFAST16  __PRIFAST16 "d"
#define PRIdFAST32  __PRIFAST32 "d"
#define PRIdFAST64  __PRI64 "d"
#define PRIdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » unsigned decimal        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIu8   __PRI8 "u"
#define PRIu16  __PRI16 "u"
#define PRIu32  __PRI32 "u"
#define PRIu64  __PRI64 "u"
#define PRIu128 __PRI128 "u"

#define PRIuLEAST8   __PRI8 "u"
#define PRIuLEAST16  __PRI16 "u"
#define PRIuLEAST32  __PRI32 "u"
#define PRIuLEAST64  __PRI64 "u"
#define PRIuLEAST128 __PRI128 "u"

#define PRIuFAST8   __PRI8 "u"
#define PRIuFAST16  __PRIFAST16 "u"
#define PRIuFAST32  __PRIFAST32 "u"
#define PRIuFAST64  __PRI64 "u"
#define PRIuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » wut                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIi8   __PRI8 "i"
#define PRIi16  __PRI16 "i"
#define PRIi32  __PRI32 "i"
#define PRIi64  __PRI64 "i"
#define PRIi128 __PRI128 "i"

#define PRIiLEAST8   __PRI8 "i"
#define PRIiLEAST16  __PRI16 "i"
#define PRIiLEAST32  __PRI32 "i"
#define PRIiLEAST64  __PRI64 "i"
#define PRIiLEAST128 __PRI128 "i"

#define PRIiFAST8   __PRI8 "i"
#define PRIiFAST16  __PRIFAST16 "i"
#define PRIiFAST32  __PRIFAST32 "i"
#define PRIiFAST64  __PRI64 "i"
#define PRIiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » octal                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIo8   __PRI8 "o"
#define PRIo16  __PRI16 "o"
#define PRIo32  __PRI32 "o"
#define PRIo64  __PRI64 "o"
#define PRIo128 __PRI128 "o"

#define PRIoLEAST8   __PRI8 "o"
#define PRIoLEAST16  __PRI16 "o"
#define PRIoLEAST32  __PRI32 "o"
#define PRIoLEAST64  __PRI64 "o"
#define PRIoLEAST128 __PRI128 "o"

#define PRIoFAST8   __PRI8 "o"
#define PRIoFAST16  __PRIFAST16 "o"
#define PRIoFAST32  __PRIFAST32 "o"
#define PRIoFAST64  __PRI64 "o"
#define PRIoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » hexadecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIx8   __PRI8 "x"
#define PRIx16  __PRI16 "x"
#define PRIx32  __PRI32 "x"
#define PRIx64  __PRI64 "x"
#define PRIx128 __PRI128 "x"

#define PRIxLEAST8   __PRI8 "x"
#define PRIxLEAST16  __PRI16 "x"
#define PRIxLEAST32  __PRI32 "x"
#define PRIxLEAST64  __PRI64 "x"
#define PRIxLEAST128 __PRI128 "x"

#define PRIxFAST8   __PRI8 "x"
#define PRIxFAST16  __PRIFAST16 "x"
#define PRIxFAST32  __PRIFAST32 "x"
#define PRIxFAST64  __PRI64 "x"
#define PRIxFAST128 __PRI128 "x"

#define PRIX8   __PRI8 "X"
#define PRIX16  __PRI16 "X"
#define PRIX32  __PRI32 "X"
#define PRIX64  __PRI64 "X"
#define PRIX128 __PRI128 "X"

#define PRIXLEAST8   __PRI8 "X"
#define PRIXLEAST16  __PRI16 "X"
#define PRIXLEAST32  __PRI32 "X"
#define PRIXLEAST64  __PRI64 "X"
#define PRIXLEAST128 __PRI128 "X"

#define PRIXFAST8   __PRI8 "X"
#define PRIXFAST16  __PRIFAST16 "X"
#define PRIXFAST32  __PRIFAST32 "X"
#define PRIXFAST64  __PRI64 "X"
#define PRIXFAST128 __PRI128 "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » binary                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIb8   __PRI8 "b"
#define PRIb16  __PRI16 "b"
#define PRIb32  __PRI32 "b"
#define PRIb64  __PRI64 "b"
#define PRIb128 __PRI128 "b"

#define PRIbLEAST8   __PRI8 "b"
#define PRIbLEAST16  __PRI16 "b"
#define PRIbLEAST32  __PRI32 "b"
#define PRIbLEAST64  __PRI64 "b"
#define PRIbLEAST128 __PRI128 "b"

#define PRIbFAST8   __PRI8 "b"
#define PRIbFAST16  __PRIFAST16 "b"
#define PRIbFAST32  __PRIFAST32 "b"
#define PRIbFAST64  __PRI64 "b"
#define PRIbFAST128 __PRI128 "b"

#define PRIB8   __PRI8 "B"
#define PRIB16  __PRI16 "B"
#define PRIB32  __PRI32 "B"
#define PRIB64  __PRI64 "B"
#define PRIB128 __PRI128 "B"

#define PRIBLEAST8   __PRI8 "B"
#define PRIBLEAST16  __PRI16 "B"
#define PRIBLEAST32  __PRI32 "B"
#define PRIBLEAST64  __PRI64 "B"
#define PRIBLEAST128 __PRI128 "B"

#define PRIBFAST8   __PRI8 "B"
#define PRIBFAST16  __PRIFAST16 "B"
#define PRIBFAST32  __PRIFAST32 "B"
#define PRIBFAST64  __PRI64 "B"
#define PRIBFAST128 __PRI128 "B"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » miscellaneous           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIdMAX "jd"
#define PRIiMAX "ji"
#define PRIoMAX "jo"
#define PRIuMAX "ju"
#define PRIxMAX "jx"
#define PRIXMAX "jX"

#define PRIdPTR __PRIPTR "d"
#define PRIiPTR __PRIPTR "i"
#define PRIoPTR __PRIPTR "o"
#define PRIuPTR __PRIPTR "u"
#define PRIxPTR __PRIPTR "x"
#define PRIXPTR __PRIPTR "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » decimal                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNd8   __PRI8 "d"
#define SCNd16  __PRI16 "d"
#define SCNd32  __PRI32 "d"
#define SCNd64  __PRI64 "d"
#define SCNd128 __PRI128 "d"

#define SCNdLEAST8   __PRI8 "d"
#define SCNdLEAST16  __PRI16 "d"
#define SCNdLEAST32  __PRI32 "d"
#define SCNdLEAST64  __PRI64 "d"
#define SCNdLEAST128 __PRI128 "d"

#define SCNdFAST8   __PRI8 "d"
#define SCNdFAST16  __PRIFAST16 "d"
#define SCNdFAST32  __PRIFAST32 "d"
#define SCNdFAST64  __PRI64 "d"
#define SCNdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » flexidecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNi8   __PRI8 "i"
#define SCNi16  __PRI16 "i"
#define SCNi32  __PRI32 "i"
#define SCNi64  __PRI64 "i"
#define SCNi128 __PRI128 "i"

#define SCNiLEAST8   __PRI8 "i"
#define SCNiLEAST16  __PRI16 "i"
#define SCNiLEAST32  __PRI32 "i"
#define SCNiLEAST64  __PRI64 "i"
#define SCNiLEAST128 __PRI128 "i"

#define SCNiFAST8   __PRI8 "i"
#define SCNiFAST16  __PRIFAST16 "i"
#define SCNiFAST32  __PRIFAST32 "i"
#define SCNiFAST64  __PRI64 "i"
#define SCNiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » unsigned decimal         ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNu8   __PRI8 "u"
#define SCNu16  __PRI16 "u"
#define SCNu32  __PRI32 "u"
#define SCNu64  __PRI64 "u"
#define SCNu128 __PRI128 "u"

#define SCNuLEAST8   __PRI8 "u"
#define SCNuLEAST16  __PRI16 "u"
#define SCNuLEAST32  __PRI32 "u"
#define SCNuLEAST64  __PRI64 "u"
#define SCNuLEAST128 __PRI128 "u"

#define SCNuFAST8   __PRI8 "u"
#define SCNuFAST16  __PRIFAST16 "u"
#define SCNuFAST32  __PRIFAST32 "u"
#define SCNuFAST64  __PRI64 "u"
#define SCNuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » octal                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNo8   __PRI8 "o"
#define SCNo16  __PRI16 "o"
#define SCNo32  __PRI32 "o"
#define SCNo64  __PRI64 "o"
#define SCNo128 __PRI128 "o"

#define SCNoLEAST8   __PRI8 "o"
#define SCNoLEAST16  __PRI16 "o"
#define SCNoLEAST32  __PRI32 "o"
#define SCNoLEAST64  __PRI64 "o"
#define SCNoLEAST128 __PRI128 "o"

#define SCNoFAST8   __PRI8 "o"
#define SCNoFAST16  __PRIFAST16 "o"
#define SCNoFAST32  __PRIFAST32 "o"
#define SCNoFAST64  __PRI64 "o"
#define SCNoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » hexadecimal              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNx8   __PRI8 "x"
#define SCNx16  __PRI16 "x"
#define SCNx32  __PRI32 "x"
#define SCNx64  __PRI64 "x"
#define SCNx128 __PRI128 "x"

#define SCNxLEAST8   __PRI8 "x"
#define SCNxLEAST16  __PRI16 "x"
#define SCNxLEAST32  __PRI32 "x"
#define SCNxLEAST64  __PRI64 "x"
#define SCNxLEAST128 __PRI128 "x"

#define SCNxFAST8   __PRI8 "x"
#define SCNxFAST16  __PRIFAST16 "x"
#define SCNxFAST32  __PRIFAST32 "x"
#define SCNxFAST64  __PRI64 "x"
#define SCNxFAST128 __PRI128 "x"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » binary                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNb8   __PRI8 "b"
#define SCNb16  __PRI16 "b"
#define SCNb32  __PRI32 "b"
#define SCNb64  __PRI64 "b"
#define SCNb128 __PRI128 "b"

#define SCNbLEAST8   __PRI8 "b"
#define SCNbLEAST16  __PRI16 "b"
#define SCNbLEAST32  __PRI32 "b"
#define SCNbLEAST64  __PRI64 "b"
#define SCNbLEAST128 __PRI128 "b"

#define SCNbFAST8   __PRI8 "b"
#define SCNbFAST16  __PRIFAST16 "b"
#define SCNbFAST32  __PRIFAST32 "b"
#define SCNbFAST64  __PRI64 "b"
#define SCNbFAST128 __PRI128 "b"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » miscellaneous            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNdMAX "jd"
#define SCNiMAX "ji"
#define SCNoMAX "jo"
#define SCNuMAX "ju"
#define SCNxMAX "jx"

#define SCNdPTR __PRIPTR "d"
#define SCNiPTR __PRIPTR "i"
#define SCNoPTR __PRIPTR "o"
#define SCNuPTR __PRIPTR "u"
#define SCNxPTR __PRIPTR "x"



/*!BEGIN libc/limits.h */

#define COSMOPOLITAN_LIBC_LIMITS_H_
#define __STDC_LIMIT_MACROS

#define CHAR_BIT 8
#define PATH_MAX 1024
#define NAME_MAX 255
#define ARG_MAX  131074

#define UCHAR_MIN 0
#define UCHAR_MAX 255

#if '\200' < 0
#define CHAR_MIN '\200'
#define CHAR_MAX '\177'
#else
#define CHAR_MIN '\0'
#define CHAR_MAX '\377'
#endif

#define SCHAR_MAX     __SCHAR_MAX__
#define SHRT_MAX      __SHRT_MAX__
#define INT_MAX       __INT_MAX__
#define LONG_MAX      __LONG_MAX__
#define LLONG_MAX     LONG_LONG_MAX
#define LONG_LONG_MAX __LONG_LONG_MAX__
#define SIZE_MAX      __SIZE_MAX__
#define INT8_MAX      __INT8_MAX__
#define INT16_MAX     __INT16_MAX__
#define INT32_MAX     __INT32_MAX__
#define INT64_MAX     __INT64_MAX__
#define WINT_MAX      __WINT_MAX__
#define WCHAR_MAX     __WCHAR_MAX__
#define INTPTR_MAX    __INTPTR_MAX__
#define PTRDIFF_MAX   __PTRDIFF_MAX__
#define UINTPTR_MAX   __UINTPTR_MAX__
#define UINT8_MAX     __UINT8_MAX__
#define UINT16_MAX    __UINT16_MAX__
#define UINT32_MAX    __UINT32_MAX__
#define UINT64_MAX    __UINT64_MAX__
#define INTMAX_MAX    __INTMAX_MAX__
#define UINTMAX_MAX   __UINTMAX_MAX__
#define SSIZE_MAX     __INT64_MAX__

#define SCHAR_MIN     (-SCHAR_MAX - 1)
#define SHRT_MIN      (-SHRT_MAX - 1)
#define INT_MIN       (-INT_MAX - 1)
#define LONG_MIN      (-LONG_MAX - 1)
#define LLONG_MIN     (-LLONG_MAX - 1)
#define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
#define SIZE_MIN      (-SIZE_MAX - 1)
#define INT8_MIN      (-INT8_MAX - 1)
#define INT16_MIN     (-INT16_MAX - 1)
#define INT32_MIN     (-INT32_MAX - 1)
#define INT64_MIN     (-INT64_MAX - 1)
#define INTMAX_MIN    (-INTMAX_MAX - 1)
#define INTPTR_MIN    (-INTPTR_MAX - 1)
#define WINT_MIN      __WINT_MIN__
#define WCHAR_MIN     (-WCHAR_MAX - 1)
#define PTRDIFF_MIN   (-PTRDIFF_MAX - 1)

#define USHRT_MAX 65535
#define UINT_MAX  0xffffffffu
#if __SIZEOF_LONG__ == 8
#define ULONG_MAX 0xfffffffffffffffful
#else
#define ULONG_MAX 0xfffffffful
#endif
#define ULLONG_MAX     0xffffffffffffffffull
#define ULONG_LONG_MAX 0xffffffffffffffffull

#define USHRT_MIN      0
#define UINT_MIN       0u
#define ULONG_MIN      0ul
#define ULLONG_MIN     0ull
#define ULONG_LONG_MIN 0ull
#define UINT8_MIN      0
#define UINT16_MIN     0
#define UINT32_MIN     0u
#define UINT64_MIN     0ull
#define UINTPTR_MIN    0ull
#define UINTMAX_MIN    ((uintmax_t)0)

#define MB_CUR_MAX 4
#define MB_LEN_MAX 4

#ifdef _COSMO_SOURCE
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 406 || defined(__llvm__)
#define INT128_MIN  (-INT128_MAX - 1)
#define UINT128_MIN ((uint128_t)0)
#define INT128_MAX \
  ((int128_t)0x7fffffffffffffff << 64 | (int128_t)0xffffffffffffffff)
#define UINT128_MAX \
  ((uint128_t)0xffffffffffffffff << 64 | (uint128_t)0xffffffffffffffff)
#endif /* GCC 4.6+ */
#endif /* _COSMO_SOURCE */

#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX

#define FILESIZEBITS   64
#define SYMLOOP_MAX    40
#define TTY_NAME_MAX   32
#define HOST_NAME_MAX  255
#define TZNAME_MAX     6
#define WORD_BIT       32
#define SEM_VALUE_MAX  0x7fffffff
#define SEM_NSEMS_MAX  256
#define DELAYTIMER_MAX 0x7fffffff
#define MQ_PRIO_MAX    32768
#define LOGIN_NAME_MAX 256

#define NL_ARGMAX  9
#define NL_MSGMAX  32767
#define NL_SETMAX  255
#define NL_TEXTMAX 2048

#define INT_FAST8_MIN    (-__INT_FAST8_MAX__ - 1)
#define INT_FAST16_MIN   (-__INT_FAST16_MAX__ - 1)
#define INT_FAST32_MIN   (-__INT_FAST32_MAX__ - 1)
#define INT_FAST64_MIN   (-__INT_FAST64_MAX__ - 1)
#define INT_LEAST8_MIN   (-__INT_LEAST8_MAX__ - 1)
#define INT_LEAST16_MIN  (-__INT_LEAST16_MAX__ - 1)
#define INT_LEAST32_MIN  (-__INT_LEAST32_MAX__ - 1)
#define INT_LEAST64_MIN  (-__INT_LEAST64_MAX__ - 1)
#define INT_FAST8_MAX    __INT_FAST8_MAX__
#define INT_FAST16_MAX   __INT_FAST16_MAX__
#define INT_FAST32_MAX   __INT_FAST32_MAX__
#define INT_FAST64_MAX   __INT_FAST64_MAX__
#define INT_LEAST8_MAX   __INT_LEAST8_MAX__
#define INT_LEAST16_MAX  __INT_LEAST16_MAX__
#define INT_LEAST32_MAX  __INT_LEAST32_MAX__
#define INT_LEAST64_MAX  __INT_LEAST64_MAX__
#define UINT_FAST8_MAX   __UINT_FAST8_MAX__
#define UINT_FAST16_MAX  __UINT_FAST16_MAX__
#define UINT_FAST32_MAX  __UINT_FAST32_MAX__
#define UINT_FAST64_MAX  __UINT_FAST64_MAX__
#define UINT_LEAST8_MAX  __UINT_LEAST8_MAX__
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__

#define BC_BASE_MAX        99
#define BC_DIM_MAX         2048
#define BC_SCALE_MAX       99
#define BC_STRING_MAX      1000
#define CHARCLASS_NAME_MAX 14
#define COLL_WEIGHTS_MAX   2
#define EXPR_NEST_MAX      32
#define LINE_MAX           4096
#define RE_DUP_MAX         255
#define LONG_BIT           64
#define NZERO              20
#define NL_LANGMAX         32



/*!BEGIN libc/literal.h */

#define COSMOPOLITAN_LIBC_LITERAL_H_
#define __STDC_CONSTANT_MACROS

#ifdef __INT8_C
#define INT8_C(c)   __INT8_C(c)
#define UINT8_C(c)  __UINT8_C(c)
#define INT16_C(c)  __INT16_C(c)
#define UINT16_C(c) __UINT16_C(c)
#define INT32_C(c)  __INT32_C(c)
#define UINT32_C(c) __UINT32_C(c)
#define INT64_C(c)  __INT64_C(c)
#define UINT64_C(c) __UINT64_C(c)
#else
#define INT8_C(c)   c
#define UINT8_C(c)  c
#define INT16_C(c)  c
#define UINT16_C(c) c
#define INT32_C(c)  c
#define UINT32_C(c) c##U
#define INT64_C(c)  c##L
#define UINT64_C(c) c##UL
#endif

#if UINTPTR_MAX == UINT64_MAX
#define INTMAX_C(c)  c##L
#define UINTMAX_C(c) c##UL
#else
#define INTMAX_C(c)  c##LL
#define UINTMAX_C(c) c##ULL
#endif



/*!BEGIN libc/math.h */

#define COSMOPOLITAN_LIBC_MATH_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § mathematics                                                   │
╚─────────────────────────────────────────────────────────────────────────────*/

#define M_E        2.7182818284590452354  /* 𝑒 */
#define M_LOG2E    1.4426950408889634074  /* log₂𝑒 */
#define M_LOG10E   0.43429448190325182765 /* log₁₀𝑒 */
#define M_LN2      0.69314718055994530942 /* logₑ2 */
#define M_LN10     2.30258509299404568402 /* logₑ10 */
#define M_PI       3.14159265358979323846 /* 𝜋 */
#define M_PI_2     1.57079632679489661923 /* 𝜋/2 */
#define M_PI_4     0.78539816339744830962 /* 𝜋/4 */
#define M_1_PI     0.31830988618379067154 /* 1/𝜋 */
#define M_2_PI     0.63661977236758134308 /* 2/𝜋 */
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(𝜋) */
#define M_SQRT2    1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2  0.70710678118654752440 /* 1/sqrt(2) */

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_Ef        2.7182818284590452354f  /* 𝑒 */
#define M_LOG2Ef    1.4426950408889634074f  /* log₂𝑒 */
#define M_LOG10Ef   0.43429448190325182765f /* log₁₀𝑒 */
#define M_LN2f      0.69314718055994530942f /* logₑ2 */
#define M_LN10f     2.30258509299404568402f /* logₑ10 */
#define M_PIf       3.14159265358979323846f /* 𝜋 */
#define M_PI_2f     1.57079632679489661923f /* 𝜋/2 */
#define M_PI_4f     0.78539816339744830962f /* 𝜋/4 */
#define M_1_PIf     0.31830988618379067154f /* 1/𝜋 */
#define M_2_PIf     0.63661977236758134308f /* 2/𝜋 */
#define M_2_SQRTPIf 1.12837916709551257390f /* 2/sqrt(𝜋) */
#define M_SQRT2f    1.41421356237309504880f /* sqrt(2) */
#define M_SQRT1_2f  0.70710678118654752440f /* 1/sqrt(2) */
#endif

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_El        2.718281828459045235360287471352662498L /* 𝑒 */
#define M_LOG2El    1.442695040888963407359924681001892137L /* log₂𝑒 */
#define M_LOG10El   0.434294481903251827651128918916605082L /* log₁₀𝑒 */
#define M_LN2l      0.693147180559945309417232121458176568L /* logₑ2 */
#define M_LN10l     2.302585092994045684017991454684364208L /* logₑ10 */
#define M_PIl       3.141592653589793238462643383279502884L /* 𝜋 */
#define M_PI_2l     1.570796326794896619231321691639751442L /* 𝜋/2 */
#define M_PI_4l     0.785398163397448309615660845819875721L /* 𝜋/4 */
#define M_1_PIl     0.318309886183790671537767526745028724L /* 1/𝜋 */
#define M_2_PIl     0.636619772367581343075535053490057448L /* 2/𝜋 */
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(𝜋) */
#define M_SQRT2l    1.414213562373095048801688724209698079L /* sqrt(2) */
#define M_SQRT1_2l  0.707106781186547524400844362104849039L /* 1/sqrt(2) */
#endif

#define DBL_DECIMAL_DIG   __DBL_DECIMAL_DIG__
#define DBL_DIG           __DBL_DIG__
#define DBL_EPSILON       __DBL_EPSILON__
#define DBL_HAS_SUBNORM   __DBL_HAS_DENORM__
#define DBL_IS_IEC_60559  __DBL_IS_IEC_60559__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MAX           __DBL_MAX__
#define DBL_MAX_10_EXP    __DBL_MAX_10_EXP__
#define DBL_MAX_EXP       __DBL_MAX_EXP__
#define DBL_MIN           __DBL_MIN__ /* 2.23e–308 ↔ 1.79e308 */
#define DBL_MIN_10_EXP    __DBL_MIN_10_EXP__
#define DBL_MIN_EXP       __DBL_MIN_EXP__
#define DBL_NORM_MAX      __DBL_NORM_MAX__
#define DBL_TRUE_MIN      __DBL_DENORM_MIN__
#define DECIMAL_DIG       __LDBL_DECIMAL_DIG__
#define FLT_DECIMAL_DIG   __FLT_DECIMAL_DIG__
#define FLT_DIG           __FLT_DIG__
#define FLT_EPSILON       __FLT_EPSILON__
#define FLT_HAS_SUBNORM   __FLT_HAS_DENORM__
#define FLT_IS_IEC_60559  __FLT_IS_IEC_60559__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MAX           __FLT_MAX__
#define FLT_MAX_10_EXP    __FLT_MAX_10_EXP__
#define FLT_MAX_EXP       __FLT_MAX_EXP__
#define FLT_MIN           __FLT_MIN__ /* 1.18e–38 ↔ 3.40e38 */
#define FLT_MIN_10_EXP    __FLT_MIN_10_EXP__
#define FLT_MIN_EXP       __FLT_MIN_EXP__
#define FLT_NORM_MAX      __FLT_NORM_MAX__
#define FLT_RADIX         __FLT_RADIX__
#define FLT_TRUE_MIN      __FLT_DENORM_MIN__
#define HLF_MAX           6.50e4f
#define HLF_MIN           3.10e-5f
#define LDBL_DECIMAL_DIG  __LDBL_DECIMAL_DIG__
#define LDBL_DIG          __LDBL_DIG__
#define LDBL_EPSILON      __LDBL_EPSILON__
#define LDBL_HAS_SUBNORM  __LDBL_HAS_DENORM__
#define LDBL_IS_IEC_60559 __LDBL_IS_IEC_60559__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MAX          __LDBL_MAX__
#define LDBL_MAX_10_EXP   __LDBL_MAX_10_EXP__
#define LDBL_MAX_EXP      __LDBL_MAX_EXP__
#define LDBL_MIN          __LDBL_MIN__ /* 3.37e–4932 ↔ 1.18e4932 */
#define LDBL_MIN_10_EXP   __LDBL_MIN_10_EXP__
#define LDBL_MIN_EXP      __LDBL_MIN_EXP__
#define LDBL_NORM_MAX     __LDBL_NORM_MAX__
#define LDBL_TRUE_MIN     __LDBL_DENORM_MIN__

#define FP_NAN       0
#define FP_INFINITE  1
#define FP_ZERO      2
#define FP_SUBNORMAL 3
#define FP_NORMAL    4
#define FP_ILOGB0    (-2147483647 - 1)
#define FP_ILOGBNAN  (-2147483647 - 1)

#define MATH_ERRNO     1
#define MATH_ERREXCEPT 2

#ifdef __FAST_MATH__
#define math_errhandling 0
#elif defined(__NO_MATH_ERRNO__)
#define math_errhandling (MATH_ERREXCEPT)
#else
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
#endif

#ifdef __FP_FAST_FMA
#define FP_FAST_FMA 1
#endif
#ifdef __FP_FAST_FMAF
#define FP_FAST_FMAF 1
#endif
#ifdef __FP_FAST_FMAL
#define FP_FAST_FMAL 1
#endif

COSMOPOLITAN_C_START_

#define NAN       __builtin_nanf("")
#define INFINITY  __builtin_inff()
#define HUGE_VAL  __builtin_inf()
#define HUGE_VALF __builtin_inff()
#define HUGE_VALL __builtin_infl()

#if __FLT_EVAL_METHOD__ + 0 == 2
typedef long double float_t;
typedef long double double_t;
#else
typedef float float_t;
typedef double double_t;
#endif

#define isinf(x)             __builtin_isinf(x)
#define isnan(x)             __builtin_isnan(x)
#define isfinite(x)          __builtin_isfinite(x)
#define isnormal(x)          __builtin_isnormal(x)
#define isgreater(x, y)      __builtin_isgreater(x, y)
#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
#define isless(x, y)         __builtin_isless(x, y)
#define islessequal(x, y)    __builtin_islessequal(x, y)
#define islessgreater(x, y)  __builtin_islessgreater(x, y)
#define isunordered(x, y)    __builtin_isunordered(x, y)

#define fpclassify(x) \
  __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)

#define signbit(x)                                          \
  (sizeof(x) == sizeof(long double) ? __builtin_signbitl(x) \
   : sizeof(x) == sizeof(float)     ? __builtin_signbitf(x) \
                                    : __builtin_signbit(x))

extern int signgam;

double acos(double) libcesque;
double acosh(double) libcesque;
double asin(double) libcesque;
double asinh(double) libcesque;
double atan(double) libcesque;
double atan2(double, double) libcesque;
double atanh(double) libcesque;
double cbrt(double) libcesque;
double ceil(double) libcesque;
double copysign(double, double) libcesque;
double cos(double) libcesque;
double cosh(double) libcesque;
double drem(double, double) libcesque;
double erf(double) libcesque;
double erfc(double) libcesque;
double exp(double) libcesque;
double exp10(double) libcesque;
double exp2(double) libcesque;
double expm1(double) libcesque;
double fabs(double) libcesque;
double fdim(double, double) libcesque;
double floor(double) libcesque;
double fma(double, double, double) libcesque;
double fmax(double, double) libcesque;
double fmin(double, double) libcesque;
double fmod(double, double) libcesque;
double hypot(double, double) libcesque;
double ldexp(double, int) libcesque;
double log(double) libcesque;
double log10(double) libcesque;
double log1p(double) libcesque;
double log2(double) libcesque;
double logb(double) libcesque;
double nearbyint(double) libcesque;
double nextafter(double, double) libcesque;
double nexttoward(double, long double) libcesque;
double pow(double, double) libcesque;
double pow10(double) libcesque;
double powi(double, int) libcesque;
double remainder(double, double) libcesque;
double rint(double) libcesque;
double round(double) libcesque;
double scalb(double, double) libcesque;
double scalbln(double, long int) libcesque;
double scalbn(double, int) libcesque;
double significand(double) libcesque;
double sin(double) libcesque;
double sinh(double) libcesque;
double sqrt(double) libcesque;
double tan(double) libcesque;
double tanh(double) libcesque;
double trunc(double) libcesque;
double tgamma(double) libcesque;
double lgamma(double) libcesque;
double lgamma_r(double, int *) libcesque;
int finite(double) libcesque;

float acosf(float) libcesque;
float acoshf(float) libcesque;
float asinf(float) libcesque;
float asinhf(float) libcesque;
float atan2f(float, float) libcesque;
float atanf(float) libcesque;
float atanhf(float) libcesque;
float cbrtf(float) libcesque;
float ceilf(float) libcesque;
float copysignf(float, float) libcesque;
float cosf(float) libcesque;
float coshf(float) libcesque;
float dremf(float, float) libcesque;
float erfcf(float) libcesque;
float erff(float) libcesque;
float exp10f(float) libcesque;
float exp2f(float) libcesque;
float expf(float) libcesque;
float expm1f(float) libcesque;
float fabsf(float) libcesque;
float fdimf(float, float) libcesque;
float floorf(float) libcesque;
float fmaf(float, float, float) libcesque;
float fmaxf(float, float) libcesque;
float fminf(float, float) libcesque;
float fmodf(float, float) libcesque;
float hypotf(float, float) libcesque;
float ldexpf(float, int) libcesque;
float lgammaf(float) libcesque;
float lgammaf_r(float, int *) libcesque;
float log10f(float) libcesque;
float log1pf(float) libcesque;
float log2f(float) libcesque;
float logbf(float) libcesque;
float logf(float) libcesque;
float nearbyintf(float) libcesque;
float nextafterf(float, float) libcesque;
float nexttowardf(float, long double) libcesque;
float pow10f(float) libcesque;
float powf(float, float) libcesque;
float powif(float, int) libcesque;
float remainderf(float, float) libcesque;
float rintf(float) libcesque;
float roundf(float) libcesque;
float scalbf(float, float) libcesque;
float scalblnf(float, long int) libcesque;
float scalbnf(float, int) libcesque;
float significandf(float) libcesque;
float sinf(float) libcesque;
float sinhf(float) libcesque;
float sqrtf(float) libcesque;
float tanf(float) libcesque;
float tanhf(float) libcesque;
float tgammaf(float) libcesque;
float truncf(float) libcesque;
int finitef(float) libcesque;

int finitel(long double) libcesque;
long double acoshl(long double) libcesque;
long double acosl(long double) libcesque;
long double asinhl(long double) libcesque;
long double asinl(long double) libcesque;
long double atan2l(long double, long double) libcesque;
long double atanhl(long double) libcesque;
long double atanl(long double) libcesque;
long double cbrtl(long double) libcesque;
long double ceill(long double) libcesque;
long double copysignl(long double, long double) libcesque;
long double coshl(long double) libcesque;
long double cosl(long double) libcesque;
long double dreml(long double, long double) libcesque;
long double erfcl(long double) libcesque;
long double erfl(long double) libcesque;
long double exp10l(long double) libcesque;
long double exp2l(long double) libcesque;
long double expl(long double) libcesque;
long double expm1l(long double) libcesque;
long double fabsl(long double) libcesque;
long double fdiml(long double, long double) libcesque;
long double floorl(long double) libcesque;
long double fmal(long double, long double, long double) libcesque;
long double fmaxl(long double, long double) libcesque;
long double fminl(long double, long double) libcesque;
long double fmodl(long double, long double) libcesque;
long double hypotl(long double, long double) libcesque;
long double ldexpl(long double, int) libcesque;
long double lgammal(long double) libcesque;
long double lgammal_r(long double, int *) libcesque;
long double log10l(long double) libcesque;
long double log1pl(long double) libcesque;
long double log2l(long double) libcesque;
long double logbl(long double) libcesque;
long double logl(long double) libcesque;
long double nearbyintl(long double) libcesque;
long double nextafterl(long double, long double) libcesque;
long double nexttowardl(long double, long double) libcesque;
long double pow10l(long double) libcesque;
long double powl(long double, long double) libcesque;
long double remainderl(long double, long double) libcesque;
long double rintl(long double) libcesque;
long double roundl(long double) libcesque;
long double scalbl(long double, long double) libcesque;
long double scalblnl(long double, long int) libcesque;
long double scalbnl(long double, int) libcesque;
long double significandl(long double) libcesque;
long double sinhl(long double) libcesque;
long double sinl(long double) libcesque;
long double sqrtl(long double) libcesque;
long double tanhl(long double) libcesque;
long double tanl(long double) libcesque;
long double tgammal(long double) libcesque;
long double truncl(long double) libcesque;

long lrint(double) libcesque;
long lrintf(float) libcesque;
long lrintl(long double) libcesque;
long lround(double) libcesque;
long lroundf(float) libcesque;
long lroundl(long double) libcesque;

int ilogbf(float) libcesque;
int ilogb(double) libcesque;
int ilogbl(long double) libcesque;

long long llrint(double) libcesque;
long long llrintf(float) libcesque;
long long llrintl(long double) libcesque;
long long llround(double) libcesque;
long long llroundf(float) libcesque;
long long llroundl(long double) libcesque;

double frexp(double, int *) libcesque;
double modf(double, double *) libcesque;
double nan(const char *) libcesque;
double remquo(double, double, int *) libcesque;
float frexpf(float, int *) libcesque;
float modff(float, float *) libcesque;
float nanf(const char *) libcesque;
float remquof(float, float, int *) libcesque;
long double frexpl(long double, int *) libcesque;
long double modfl(long double, long double *) libcesque;
long double nanl(const char *) libcesque;
long double remquol(long double, long double, int *) libcesque;
void sincos(double, double *, double *) libcesque;
void sincosf(float, float *, float *) libcesque;
void sincosl(long double, long double *, long double *) libcesque;

double fsumf(const float *, size_t) libcesque;
double fsum(const double *, size_t) libcesque;

double j0(double) libcesque;
double j1(double) libcesque;
double jn(int, double) libcesque;
float j0f(float) libcesque;
float j1f(float) libcesque;
float jnf(int, float) libcesque;

double y0(double) libcesque;
double y1(double) libcesque;
double yn(int, double) libcesque;
float y0f(float) libcesque;
float y1f(float) libcesque;
float ynf(int, float) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/paths.h */

#define COSMOPOLITAN_LIBC_PATHS_H_

#define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin"
#define _PATH_STDPATH "/bin:/usr/bin:/sbin:/usr/sbin"

#define _PATH_BSHELL   "/bin/sh"
#define _PATH_CONSOLE  "/dev/console"
#define _PATH_DEVNULL  "/dev/null"
#define _PATH_KLOG     "/proc/kmsg"
#define _PATH_LASTLOG  "/var/log/lastlog"
#define _PATH_MAILDIR  "/var/mail"
#define _PATH_MAN      "/usr/share/man"
#define _PATH_MNTTAB   "/etc/fstab"
#define _PATH_MOUNTED  "/etc/mtab"
#define _PATH_NOLOGIN  "/etc/nologin"
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
#define _PATH_SHADOW   "/etc/shadow"
#define _PATH_SHELLS   "/etc/shells"
#define _PATH_TTY      "/dev/tty"
#define _PATH_UTMP     "/dev/null/utmp"
#define _PATH_VI       "/usr/bin/vi"
#define _PATH_WTMP     "/dev/null/wtmp"

#define _PATH_DEV    "/dev/"
#define _PATH_TMP    "/tmp/"
#define _PATH_VARDB  "/var/lib/misc/"
#define _PATH_VARRUN "/var/run/"
#define _PATH_VARTMP "/var/tmp/"



/*!BEGIN libc/serialize.h */

#define COSMOPOLITAN_SERIALIZE_H_
#ifdef _COSMO_SOURCE

#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define __SWAPBE16(x) (x)
#define __SWAPBE32(x) (x)
#define __SWAPBE64(x) (x)
#else
#define __SWAPBE16(x) __builtin_bswap16(x)
#define __SWAPBE32(x) __builtin_bswap32(x)
#define __SWAPBE64(x) __builtin_bswap64(x)
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __SWAPLE16(x) (x)
#define __SWAPLE32(x) (x)
#define __SWAPLE64(x) (x)
#else
#define __SWAPLE16(x) __builtin_bswap16(x)
#define __SWAPLE32(x) __builtin_bswap32(x)
#define __SWAPLE64(x) __builtin_bswap64(x)
#endif

#define READ16LE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPLE16(__x);                   \
  }))

#define READ16BE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPBE16(__x);                   \
  }))

#define READ32LE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ32BE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPBE32(__x);                   \
  }))

#define READ64LE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ64BE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPBE64(__x);                   \
  }))

#define WRITE16LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPLE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE16BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPBE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE32LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPLE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE32BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPBE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE64LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPLE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#define WRITE64BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPBE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/stdckdint.h */

#define COSMOPOLITAN_LIBC_STDCKDINT_H_
/* clang-format off */

/**
 * @fileoverview C23 Checked Arithmetic
 *
 * This header defines three type generic functions:
 *
 *   - `bool ckd_add(res, a, b)`
 *   - `bool ckd_sub(res, a, b)`
 *   - `bool ckd_mul(res, a, b)`
 *
 * Which allow integer arithmetic errors to be detected. There are many
 * kinds of integer errors, e.g. overflow, truncation, etc. These funcs
 * catch them all. Here's an example of how it works:
 *
 *     uint32_t c;
 *     int32_t a = 0x7fffffff;
 *     int32_t b = 2;
 *     assert(!ckd_add(&c, a, b));
 *     assert(c == 0x80000001u);
 *
 * Experienced C / C++ users should find this example counter-intuitive
 * because the expression `0x7fffffff + 2` not only overflows it's also
 * undefined behavior. However here we see it's specified, and does not
 * result in an error. That's because C23 checked arithmetic is not the
 * arithmetic you're used to. The new standard changes the mathematics.
 *
 * C23 checked arithmetic is defined as performing the arithmetic using
 * infinite precision and then checking if the resulting value will fit
 * in the output type. Our example above did not result in an error due
 * to `0x80000001` being a legal value for `uint32_t`.
 *
 * This implementation will use the GNU compiler builtins, when they're
 * available, only if you don't use build flags like `-std=c11` because
 * they define `__STRICT_ANSI__` and GCC extensions aren't really ANSI.
 * Instead, you'll get a pretty good pure C11 and C++11 implementation.
 *
 * @see https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
 * @version 0.1 (2023-07-22)
 */

#define __STDC_VERSION_STDCKDINT_H__ 202311L

#if ((defined(__llvm__) ||                                              \
      (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406)) && \
     !defined(__STRICT_ANSI__))
#define __ckd_have_int128
#define __ckd_intmax __int128
#elif ((defined(__cplusplus) && __cplusplus >= 201103L) ||              \
       (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L))
#define __ckd_intmax long long
#else
#define __ckd_intmax long
#endif

typedef signed __ckd_intmax __ckd_intmax_t;
typedef unsigned __ckd_intmax __ckd_uintmax_t;

#if (!defined(__STRICT_ANSI__) &&                       \
     ((defined(__GNUC__) && __GNUC__ >= 5 &&            \
       !defined(__chibicc__) && !defined(__ICC)) ||     \
      (__has_builtin(__builtin_add_overflow) &&         \
       __has_builtin(__builtin_sub_overflow) &&         \
       __has_builtin(__builtin_mul_overflow))))
#define ckd_add(res, x, y) __builtin_add_overflow((x), (y), (res))
#define ckd_sub(res, x, y) __builtin_sub_overflow((x), (y), (res))
#define ckd_mul(res, x, y) __builtin_mul_overflow((x), (y), (res))

#elif defined(__cplusplus) && __cplusplus >= 201103L

template <typename __T, typename __U, typename __V>
inline bool ckd_add(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x + __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u + u
      return __truncated | (__z < __x);
    case 1:  // u = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 2:  // u = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 3:  // u = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z | __x) &  __y) |
                                       ((__z & __x) & ~__y)) < 0);
    case 4:  // s = u + u
      return __truncated | (__z < __x) | (static_cast<__ckd_intmax_t>(__z) < 0);
    case 5:  // s = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __y);
    case 6:  // s = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __x);
    case 7:  // s = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_sub(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x - __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u - u
      return __truncated | (__x < __y);
    case 1:  // u = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    case 2:  // u = s - u
      return __truncated | (__y > __x) | (static_cast<__ckd_intmax_t>(__x) < 0);
    case 3:  // u = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z & __x) &  __y) |
                                       ((__z | __x) & ~__y)) < 0);
    case 4:  // s = u - u
      return __truncated |
          ((__x < __y) ^ (static_cast<__ckd_intmax_t>(__z) < 0));
    case 5:  // s = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x >= __y);
    case 6:  // s = s - u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x < __y);
    case 7:  // s = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_mul(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  if ((sizeof(__U) * 8 - std::is_signed<__U>::value) +
      (sizeof(__V) * 8 - std::is_signed<__V>::value) <=
      (sizeof(__T) * 8 - std::is_signed<__T>::value)) {
    if (sizeof(__ckd_uintmax_t) > sizeof(__T) || std::is_signed<__T>::value) {
      __ckd_intmax_t __z = __x * __y;
      return __z != (*__res = __z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0: {  // u = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 1: {  // u = u * s
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__y) < 0) & !!__x) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 2: {  // u = s * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__x) < 0) & !!__y) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 3: { // u = s * s
      int __o = false;
      if (static_cast<__ckd_intmax_t>(__x & __y) < 0) {
        __x = -__x;
        __y = -__y;
      } else if (static_cast<__ckd_intmax_t>(__x ^ __y) < 0) {
        __o = __x && __y;
      }
      __ckd_uintmax_t __z = __x * __y;
      __o |= __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 4: {  // s = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | (static_cast<__ckd_intmax_t>(__z) < 0) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 5: {  // s = u * s
      __ckd_uintmax_t __t = -__y;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __y : __t;
      __ckd_uintmax_t __p = __t * __x;
      int __o = __t && __p / __t != __x;
      int __n = static_cast<__ckd_intmax_t>(__y) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 6: {  // s = s * u
      __ckd_uintmax_t __t = -__x;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __x : __t;
      __ckd_uintmax_t __p = __t * __y;
      int __o = __t && __p / __t != __y;
      int __n = static_cast<__ckd_intmax_t>(__x) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 7: {  // s = s * s
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return ((((static_cast<__ckd_intmax_t>(__y) < 0) &&
                (static_cast<__ckd_intmax_t>(__x) ==
                 std::numeric_limits<__ckd_intmax_t>::min())) ||
               (__y && ((static_cast<__ckd_intmax_t>(__z) /
                         static_cast<__ckd_intmax_t>(__y)) !=
                        static_cast<__ckd_intmax_t>(__x)))) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    default:
      for (;;) (void)0;
  }
}

#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L

#define ckd_add(res, a, b) __ckd_expr(add, (res), (a), (b))
#define ckd_sub(res, a, b) __ckd_expr(sub, (res), (a), (b))
#define ckd_mul(res, a, b) __ckd_expr(mul, (res), (a), (b))

#if defined(__GNUC__) || defined(__llvm__)
#define __ckd_inline                                    \
  extern __inline __attribute__((__gnu_inline__,        \
                                 __always_inline__,     \
                                 __artificial__))
#else
#define __ckd_inline static inline
#endif

#ifdef __ckd_have_int128
#define __ckd_generic_int128(x, y) , signed __int128: x, unsigned __int128: y
#else
#define __ckd_generic_int128(x, y)
#endif

#define __ckd_sign(T)                           \
  ((T)1 << (sizeof(T) * 8 - 1))

#define __ckd_is_signed(x)                      \
  _Generic(x,                                   \
           signed char: 1,                      \
           unsigned char: 0,                    \
           signed short: 1,                     \
           unsigned short: 0,                   \
           signed int: 1,                       \
           unsigned int: 0,                     \
           signed long: 1,                      \
           unsigned long: 0,                    \
           signed long long: 1,                 \
           unsigned long long: 0                \
           __ckd_generic_int128(1, 0))

#define __ckd_expr(op, res, a, b)                       \
  (_Generic(*res,                                       \
            signed char: __ckd_##op##_schar,            \
            unsigned char: __ckd_##op##_uchar,          \
            signed short: __ckd_##op##_sshort,          \
            unsigned short: __ckd_##op##_ushort,        \
            signed int: __ckd_##op##_sint,              \
            unsigned int: __ckd_##op##_uint,            \
            signed long: __ckd_##op##_slong,            \
            unsigned long: __ckd_##op##_ulong,          \
            signed long long: __ckd_##op##_slonger,     \
            unsigned long long: __ckd_##op##_ulonger    \
            __ckd_generic_int128(                       \
                __ckd_##op##_sint128,                   \
                __ckd_##op##_uint128))(                 \
                    res, a, b,                          \
                    __ckd_is_signed(a),                 \
                    __ckd_is_signed(b)))

#define __ckd_declare_add(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x + __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u + u */                                          \
        return __truncated | (__z < __x);                               \
      case 1:  /* u = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 2:  /* u = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 3:  /* u = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z | __x) &  __y) |                    \
                              ((__z & __x) & ~__y)) < 0);               \
      case 4:  /* s = u + u */                                          \
        return __truncated | (__z < __x) | ((__ckd_intmax_t)__z < 0);   \
      case 5:  /* s = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __y);                         \
      case 6:  /* s = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __x);                         \
      case 7:  /* s = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_add(__ckd_add_schar, signed char)
__ckd_declare_add(__ckd_add_uchar, unsigned char)
__ckd_declare_add(__ckd_add_sshort, signed short)
__ckd_declare_add(__ckd_add_ushort, unsigned short)
__ckd_declare_add(__ckd_add_sint, signed int)
__ckd_declare_add(__ckd_add_uint, unsigned int)
__ckd_declare_add(__ckd_add_slong, signed long)
__ckd_declare_add(__ckd_add_ulong, unsigned long)
__ckd_declare_add(__ckd_add_slonger, signed long long)
__ckd_declare_add(__ckd_add_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_add(__ckd_add_sint128, signed __int128)
__ckd_declare_add(__ckd_add_uint128, unsigned __int128)
#endif

#define __ckd_declare_sub(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x - __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u - u */                                          \
        return __truncated | (__x < __y);                               \
      case 1:  /* u = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      case 2:  /* u = s - u */                                          \
        return __truncated | (__y > __x) | ((__ckd_intmax_t)__x < 0);   \
      case 3:  /* u = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z & __x) &  __y) |                    \
                              ((__z | __x) & ~__y)) < 0);               \
      case 4:  /* s = u - u */                                          \
        return __truncated | ((__x < __y) ^ ((__ckd_intmax_t)__z < 0)); \
      case 5:  /* s = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x >= __y);                              \
      case 6:  /* s = s - u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x < __y);                               \
      case 7:  /* s = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_sub(__ckd_sub_schar, signed char)
__ckd_declare_sub(__ckd_sub_uchar, unsigned char)
__ckd_declare_sub(__ckd_sub_sshort, signed short)
__ckd_declare_sub(__ckd_sub_ushort, unsigned short)
__ckd_declare_sub(__ckd_sub_sint, signed int)
__ckd_declare_sub(__ckd_sub_uint, unsigned int)
__ckd_declare_sub(__ckd_sub_slong, signed long)
__ckd_declare_sub(__ckd_sub_ulong, unsigned long)
__ckd_declare_sub(__ckd_sub_slonger, signed long long)
__ckd_declare_sub(__ckd_sub_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_sub(__ckd_sub_sint128, signed __int128)
__ckd_declare_sub(__ckd_sub_uint128, unsigned __int128)
#endif

#define __ckd_declare_mul(S, T)                                 \
  __ckd_inline char S(void *__res,                              \
                      __ckd_uintmax_t __x,                      \
                      __ckd_uintmax_t __y,                      \
                      char __a_signed,                          \
                      char __b_signed) {                        \
    switch (__ckd_is_signed((T)0) << 2 |                        \
            __a_signed << 1 | __b_signed) {                     \
      case 0: {  /* u = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 1: {  /* u = u * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__y < 0) & !!__x) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 2: {  /* u = s * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__x < 0) & !!__y) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 3: {  /* u = s * s */                                \
        int __o = 0;                                            \
        if ((__ckd_intmax_t)(__x & __y) < 0) {                  \
          __x = -__x;                                           \
          __y = -__y;                                           \
        } else if ((__ckd_intmax_t)(__x ^ __y) < 0) {           \
          __o = __x && __y;                                     \
        }                                                       \
        __ckd_uintmax_t __z = __x * __y;                        \
        __o |= __x && __z / __x != __y;                         \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 4: {  /* s = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | ((__ckd_intmax_t)(__z) < 0) |             \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 5: {  /* s = u * s */                                \
        __ckd_uintmax_t __t = -__y;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __y : __t;            \
        __ckd_uintmax_t __p = __t * __x;                        \
        int __o = __t && __p / __t != __x;                      \
        int __n = (__ckd_intmax_t)__y < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 6: {  /* s = s * u */                                \
        __ckd_uintmax_t __t = -__x;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __x : __t;            \
        __ckd_uintmax_t __p = __t * __y;                        \
        int __o = __t && __p / __t != __y;                      \
        int __n = (__ckd_intmax_t)__x < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 7: {  /* s = s * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        *(T *)__res = __z;                                      \
        return (((((__ckd_intmax_t)__y < 0) &&                  \
                  (__x == __ckd_sign(__ckd_uintmax_t))) ||      \
                 (__y && (((__ckd_intmax_t)__z /                \
                           (__ckd_intmax_t)__y) !=              \
                          (__ckd_intmax_t)__x))) |              \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      default:                                                  \
        for (;;) (void)0;                                       \
    }                                                           \
  }

__ckd_declare_mul(__ckd_mul_schar, signed char)
__ckd_declare_mul(__ckd_mul_uchar, unsigned char)
__ckd_declare_mul(__ckd_mul_sshort, signed short)
__ckd_declare_mul(__ckd_mul_ushort, unsigned short)
__ckd_declare_mul(__ckd_mul_sint, signed int)
__ckd_declare_mul(__ckd_mul_uint, unsigned int)
__ckd_declare_mul(__ckd_mul_slong, signed long)
__ckd_declare_mul(__ckd_mul_ulong, unsigned long)
__ckd_declare_mul(__ckd_mul_slonger, signed long long)
__ckd_declare_mul(__ckd_mul_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_mul(__ckd_mul_sint128, signed __int128)
__ckd_declare_mul(__ckd_mul_uint128, unsigned __int128)
#endif

#else
#pragma message "checked integer arithmetic unsupported in this environment"

#define ckd_add(res, x, y) (*(res) = (x) + (y), 0)
#define ckd_sub(res, x, y) (*(res) = (x) - (y), 0)
#define ckd_mul(res, x, y) (*(res) = (x) * (y), 0)

#endif /* GNU */
/* clang-format on */


/*!BEGIN libc/stdlib.h */

#define COSMOPOLITAN_LIBC_STDLIB_H_
COSMOPOLITAN_C_START_

char *fcvt(double, int, int *, int *) libcesque;
char *ecvt(double, int, int *, int *) libcesque;
char *gcvt(double, int, char *) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void setkey(const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/temp.h */

#define COSMOPOLITAN_LIBC_TEMP_H_
COSMOPOLITAN_C_START_

char *mktemp(char *) libcesque returnsnonnull paramsnonnull();
char *mkdtemp(char *) libcesque paramsnonnull() __wur;
int mkstemp(char *) libcesque paramsnonnull() __wur;
int mkstemps(char *, int) libcesque paramsnonnull() __wur;

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
int mkostemp(char *, unsigned) libcesque paramsnonnull() __wur;
int mkostemps(char *, int, unsigned) libcesque paramsnonnull() __wur;
#endif

#ifdef _COSMO_SOURCE
int openatemp(int, char *, int, int, int) libcesque paramsnonnull() __wur;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/time.h */

#define COSMOPOLITAN_LIBC_TIME_H_

#define TIME_UTC 1

COSMOPOLITAN_C_START_

struct tm {
  int32_t tm_sec;
  int32_t tm_min;
  int32_t tm_hour;
  int32_t tm_mday; /* 1-indexed */
  int32_t tm_mon;  /* 0-indexed */
  int32_t tm_year; /* minus 1900 */
  int32_t tm_wday;
  int32_t tm_yday;
  int32_t tm_isdst;
  int64_t tm_gmtoff;
  const char *tm_zone;
};

struct timezone {
  int32_t tz_minuteswest;
  int32_t tz_dsttime;
};

extern char *tzname[2];
extern long timezone;
extern int daylight;

void tzset(void) libcesque;
char *asctime(const struct tm *) libcesque;
char *asctime_r(const struct tm *, char *) libcesque;
char *strptime(const char *, const char *, struct tm *) libcesque;
int64_t mktime(struct tm *) libcesque;
int64_t timegm(struct tm *) libcesque;
int64_t timelocal(struct tm *) libcesque;
int64_t timeoff(struct tm *, long) libcesque;
size_t strftime(char *, size_t, const char *, const struct tm *) libcesque
    strftimeesque(3) libcesque;
size_t wcsftime(wchar_t *, size_t, const wchar_t *,
                const struct tm *) libcesque;
struct tm *gmtime(const int64_t *) libcesque;
struct tm *gmtime_r(const int64_t *, struct tm *) libcesque;
struct tm *localtime(const int64_t *) libcesque;
struct tm *localtime_r(const int64_t *, struct tm *) libcesque;

char *ctime(const int64_t *) libcesque;
char *ctime_r(const int64_t *, char *) libcesque;
double difftime(int64_t, int64_t)
pureconst libcesque;
int stime(const int64_t *) libcesque;
void tzset(void) libcesque;

#ifdef _COSMO_SOURCE
extern const char kWeekdayNameShort[7][4];
extern const char kWeekdayName[7][10];
extern const char kMonthNameShort[12][4];
extern const char kMonthName[12][10];
extern const unsigned short kMonthYearDay[2][12];
#define iso8601 __iso8601
char *iso8601(char[hasatleast 20], struct tm *) libcesque;
#define iso8601us __iso8601us
char *iso8601us(char[hasatleast 27], struct tm *, long) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/type2str.h */

#define COSMOPOLITAN_LIBC_TYPE2STR_H_
#if __STDC_VERSION__ + 0 >= 201112
/* clang-format off */

#define _TYPE2STR(X)                          \
  _Generic(X,                                 \
    _Bool:              "_Bool",              \
    signed char:        "signed char",        \
    unsigned char:      "unsigned char",      \
    char:               "char",               \
    short:              "short",              \
    unsigned short:     "unsigned short",     \
    int:                "int",                \
    unsigned:           "unsigned",           \
    long:               "long",               \
    unsigned long:      "unsigned long",      \
    long long:          "long long",          \
    unsigned long long: "unsigned long long", \
    __int128:           "__int128",           \
    unsigned __int128:  "unsigned __int128",  \
    float:              "float",              \
    double:             "double",             \
    long double:        "long double")

#define _PRINTF_GENERIC(X, D, U) \
  _Generic(X,                    \
    _Bool:              "hhh" U, \
    signed char:        "hh" D,  \
    unsigned char:      "hh" U,  \
    char:               "hh" D,  \
    short:              "h" D,   \
    unsigned short:     "h" U,   \
    int:                D,       \
    unsigned:           U,       \
    long:               "l" D,   \
    unsigned long:      "l" U,   \
    long long:          "ll" D,  \
    unsigned long long: "ll" U,  \
    float:              "f",     \
    double:             "f",     \
    long double:        "Lf")

/* clang-format on */
#endif /* C11 */


/*!BEGIN libc/unistd.h */

#define COSMOPOLITAN_LIBC_UNISTD_H_
COSMOPOLITAN_C_START_

#define _CS_PATH 0

size_t confstr(int, char *, size_t) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void encrypt(char *, int) libcesque;
char *crypt(const char *, const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/utime.h */

#define COSMOPOLITAN_LIBC_UTIME_H_
COSMOPOLITAN_C_START_

struct utimbuf {
  int64_t actime;  /* access time */
  int64_t modtime; /* modified time */
};

int utime(const char *, const struct utimbuf *) libcesque;

#ifdef _COSMO_SOURCE
int sys_utime(const char *, const struct utimbuf *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/typedef/u.h */

#define COSMOPOLITAN_LIBC_CALLS_TYPEDEF_U_H_
COSMOPOLITAN_C_START_

typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
typedef unsigned u_int32_t;
typedef char *caddr_t;
typedef unsigned char u_char;
typedef unsigned short u_short, ushort;
typedef unsigned u_int, uint;
typedef unsigned long u_long, ulong;
typedef long long quad_t;
typedef unsigned long long u_quad_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/cpuset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_

#define CPU_SETSIZE 1024

COSMOPOLITAN_C_START_

typedef struct cpu_set_t {
  uint64_t __bits[16];
} cpu_set_t;

int sched_getcpu(void) libcesque;
int sched_getaffinity(int, size_t, cpu_set_t *) libcesque;
int sched_setaffinity(int, size_t, const cpu_set_t *) libcesque;

#define CPU_SET(i, s)   ((s)->__bits[(i) / 64] |= 1ull << ((i) % 64))
#define CPU_CLR(i, s)   ((s)->__bits[(i) / 64] &= ~(1ull << ((i) % 64)))
#define CPU_ISSET(i, s) (!!((s)->__bits[(i) / 64] & (1ull << ((i) % 64))))

void CPU_ZERO(cpu_set_t *) libcesque;
#define CPU_ZERO(x) CPU_ZERO(x)

int CPU_COUNT(cpu_set_t *) libcesque;
#define CPU_COUNT(x) CPU_COUNT(x)

int CPU_EQUAL(cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_EQUAL(x, y) CPU_EQUAL(x, y)

void CPU_AND(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_AND(x, y, z) CPU_AND(x, y, z)

void CPU_OR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_OR(x, y, z) CPU_OR(x, y, z)

void CPU_XOR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_XOR(x, y, z) CPU_XOR(x, y, z)

int CPU_COUNT_S(size_t, const cpu_set_t *) libcesque;
#define CPU_COUNT_S(x, y) CPU_COUNT_S(x, y)

#define CPU_ALLOC_SIZE(n) \
  ((((n) + (8 * sizeof(long) - 1)) & -(8 * sizeof(long))) / sizeof(long))

#define CPU_ALLOC(n)                  ((cpu_set_t *)calloc(1, CPU_ALLOC_SIZE(n)))
#define CPU_FREE(set)                 free(set)
#define CPU_ZERO_S(size, set)         memset(set, 0, size)
#define CPU_EQUAL_S(size, set1, set2) (!memcmp(set1, set2, size))
#define _CPU_S(i, size, set, op)                                              \
  ((i) / 8U >= (size) ? 0                                                     \
                      : (((unsigned long *)(set))[(i) / 8 / sizeof(long)] op( \
                            1UL << ((i) % (8 * sizeof(long))))))
#define CPU_SET_S(i, size, set)   _CPU_S(i, size, set, |=)
#define CPU_CLR_S(i, size, set)   _CPU_S(i, size, set, &= ~)
#define CPU_ISSET_S(i, size, set) _CPU_S(i, size, set, &)

typedef cpu_set_t cpuset_t; /* for freebsd compatibility */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/dirent.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_
COSMOPOLITAN_C_START_

struct dirent {      /* linux getdents64 abi */
  uint64_t d_ino;    /* inode number */
  int64_t d_off;     /* implementation-dependent location number */
  uint16_t d_reclen; /* byte length of this whole struct and string */
  uint8_t d_type;    /* DT_REG, DT_DIR, DT_UNKNOWN, DT_BLK, etc. */
  char d_name[256];  /* NUL-terminated basename */
};

struct dirstream;
typedef struct dirstream DIR;

DIR *fdopendir(int) libcesque __wur;
DIR *opendir(const char *) libcesque __wur;
int closedir(DIR *) libcesque;
int dirfd(DIR *) libcesque;
long telldir(DIR *) libcesque;
struct dirent *readdir(DIR *) libcesque;
int readdir_r(DIR *, struct dirent *, struct dirent **) libcesque;
void rewinddir(DIR *) libcesque;
void seekdir(DIR *, long) libcesque;
int alphasort(const struct dirent **, const struct dirent **) libcesque;
int versionsort(const struct dirent **, const struct dirent **) libcesque;
int scandir(const char *, struct dirent ***, int (*)(const struct dirent *),
            int (*)(const struct dirent **, const struct dirent **)) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/flock.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FLOCK_H_
COSMOPOLITAN_C_START_

struct flock {      /* cosmopolitan abi */
  int16_t l_type;   /* F_RDLCK, F_WRLCK, F_UNLCK */
  int16_t l_whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
  int64_t l_start;  /* starting offset */
  int64_t l_len;    /* no. bytes (0 means to end of file) */
  int32_t l_pid;    /* lock owner */
  int32_t l_sysid;  /* remote system id or zero for local (freebsd) */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/framebuffercolormap.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERCOLORMAP_H_

struct FrameBufferColorMap {
  uint32_t start;
  uint32_t len;
  uint16_t *red;
  uint16_t *green;
  uint16_t *blue;
  uint16_t *transp;
};



/*!BEGIN libc/calls/struct/framebufferfixedscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERFIXEDSCREENINFO_H_

struct FrameBufferFixedScreenInfo {
  char id[16];
  uint64_t smem_start;
  uint32_t smem_len;
  uint32_t type;
  uint32_t type_aux;
  uint32_t visual;
  uint16_t xpanstep;
  uint16_t ypanstep;
  uint16_t ywrapstep;
  uint32_t line_length;
  uint64_t mmio_start;
  uint32_t mmio_len;
  uint32_t accel;
  uint16_t capabilities;
  uint16_t reserved[2];
};



/*!BEGIN libc/calls/struct/framebuffervirtualscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERVIRTUALSCREENINFO_H_

struct FrameBufferBitField {
  uint32_t offset;
  uint32_t length;
  uint32_t msb_right;
};

struct FrameBufferVirtualScreenInfo {
  uint32_t xres;
  uint32_t yres;
  uint32_t xres_virtual;
  uint32_t yres_virtual;
  uint32_t xoffset;
  uint32_t yoffset;
  uint32_t bits_per_pixel;
  uint32_t grayscale;
  struct FrameBufferBitField red;
  struct FrameBufferBitField green;
  struct FrameBufferBitField blue;
  struct FrameBufferBitField transp;
  uint32_t nonstd;
  uint32_t activate;
  uint32_t height;
  uint32_t width;
  uint32_t accel_flags;
  uint32_t pixclock;
  uint32_t left_margin;
  uint32_t right_margin;
  uint32_t upper_margin;
  uint32_t lower_margin;
  uint32_t hsync_len;
  uint32_t vsync_len;
  uint32_t sync;
  uint32_t vmode;
  uint32_t rotate;
  uint32_t colorspace;
  uint32_t reserved[4];
};



/*!BEGIN libc/calls/struct/fsid.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FSID_H_
COSMOPOLITAN_C_START_

typedef struct fsid_t {
  uint32_t __val[2];
} fsid_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/iovec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct iovec {
  void *iov_base;
  size_t iov_len;
};

ssize_t preadv(int, struct iovec *, int, int64_t) libcesque;
ssize_t pwritev(int, const struct iovec *, int, int64_t) libcesque;
ssize_t readv(int, const struct iovec *, int) libcesque;
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t) libcesque;
ssize_t writev(int, const struct iovec *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/itimerval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_H_


/*!BEGIN libc/calls/struct/timeval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_


/*!BEGIN libc/calls/struct/timespec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct timespec {
  int64_t tv_sec;
  int64_t tv_nsec; /* nanoseconds */
};

int clock_getres(int, struct timespec *) libcesque;
int clock_gettime(int, struct timespec *) libcesque;
int clock_settime(int, const struct timespec *) libcesque;
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int futimens(int, const struct timespec[2]) libcesque;
int nanosleep(const struct timespec *, struct timespec *) libcesque;
int utimensat(int, const char *, const struct timespec[2], int) libcesque;
int timespec_getres(struct timespec *, int) libcesque;
int timespec_get(struct timespec *, int) libcesque;

#ifdef _COSMO_SOURCE
int sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int cosmo_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
#define timespec_zero ((struct timespec){0})
#define timespec_max  ((struct timespec){0x7fffffffffffffff, 999999999})
libcesque int timespec_cmp(struct timespec, struct timespec) pureconst;
libcesque int64_t timespec_tomicros(struct timespec) pureconst;
libcesque int64_t timespec_tomillis(struct timespec) pureconst;
libcesque int64_t timespec_tonanos(struct timespec) pureconst;
libcesque struct timespec timespec_add(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_fromnanos(int64_t) pureconst;
libcesque struct timespec timespec_frommicros(int64_t) pureconst;
libcesque struct timespec timespec_frommillis(int64_t) pureconst;
libcesque struct timespec timespec_real(void) libcesque;
libcesque struct timespec timespec_mono(void) libcesque;
libcesque struct timespec timespec_sleep(struct timespec) libcesque;
libcesque int timespec_sleep_until(struct timespec) libcesque;
libcesque struct timespec timespec_sub(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_subz(struct timespec,
                                        struct timespec) pureconst;
int sys_futex(int *, int, int, const struct timespec *, int *);
static inline struct timespec timespec_fromseconds(int64_t __x) {
  return (struct timespec){__x};
}
static inline int timespec_iszero(struct timespec __ts) {
  return !(__ts.tv_sec | __ts.tv_nsec);
}
static inline int timespec_isvalid(struct timespec __ts) {
  return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
}
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

struct timeval {
  int64_t tv_sec;
  int64_t tv_usec; /* microseconds */
};

int futimes(int, const struct timeval[2]);
int futimesat(int, const char *, const struct timeval[2]);
int gettimeofday(struct timeval *, struct timezone *);
int settimeofday(const struct timeval *, const struct timezone *);
int lutimes(const char *, const struct timeval[2]);
int utimes(const char *, const struct timeval[2]);

#ifdef _COSMO_SOURCE
/* cosmopolitan libc's non-posix timevals library
   removed by default due to emacs codebase clash */
#define timeval_zero ((struct timeval){0})
#define timeval_max  ((struct timeval){0x7fffffffffffffff, 999999})
int timeval_cmp(struct timeval, struct timeval) pureconst;
struct timeval timeval_real(void);
struct timeval timeval_frommicros(int64_t) pureconst;
struct timeval timeval_frommillis(int64_t) pureconst;
struct timeval timeval_add(struct timeval, struct timeval) pureconst;
struct timeval timeval_sub(struct timeval, struct timeval) pureconst;
struct timeval timeval_subz(struct timeval, struct timeval) pureconst;
int64_t timeval_toseconds(struct timeval);
int64_t timeval_tomicros(struct timeval);
int64_t timeval_tomillis(struct timeval);
struct timeval timespec_totimeval(struct timespec) pureconst;
static inline struct timeval timeval_fromseconds(int64_t __x) {
  return (struct timeval){__x};
}
static inline struct timespec timeval_totimespec(struct timeval __tv) {
  return (struct timespec){__tv.tv_sec, __tv.tv_usec * 1000};
}
static inline int timeval_iszero(struct timeval __tv) {
  return !(__tv.tv_sec | __tv.tv_usec);
}
static inline int timeval_isvalid(struct timeval __tv) {
  return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull;
}
#endif /* _COSMO_SOURCE */

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
#define timercmp(s, t, op)                                  \
  ((s)->tv_sec == (t)->tv_sec ? (s)->tv_usec op(t)->tv_usec \
                              : (s)->tv_sec op(t)->tv_sec)
#define timeradd(s, t, a)                                           \
  (void)((a)->tv_sec = (s)->tv_sec + (t)->tv_sec,                   \
         ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
             ((a)->tv_usec -= 1000000, (a)->tv_sec++))
#define timersub(s, t, a)                                    \
  (void)((a)->tv_sec = (s)->tv_sec - (t)->tv_sec,            \
         ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
             ((a)->tv_usec += 1000000, (a)->tv_sec--))
#endif

#ifdef _GNU_SOURCE
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
  ((ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0)
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
  ((tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0)
#endif

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct itimerval {
  struct timeval it_interval; /* {0,0} means singleshot */
  struct timeval it_value;    /* {0,0} means disarm */
};

int getitimer(int, struct itimerval *);
int setitimer(int, const struct itimerval *, struct itimerval *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/metasigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METASIGALTSTACK_H_


/*!BEGIN libc/calls/struct/sigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGALTSTACK_H_
COSMOPOLITAN_C_START_

struct sigaltstack {
  void *ss_sp;
  int ss_flags;
  size_t ss_size;
};

typedef struct sigaltstack stack_t;

int sigaltstack(const struct sigaltstack *, struct sigaltstack *) libcesque;

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct sigaltstack_bsd {
  void *ss_sp;
  uint64_t ss_size;
  int32_t ss_flags;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rlimit.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_
COSMOPOLITAN_C_START_

struct rlimit {
  uint64_t rlim_cur; /* current (soft) limit in bytes */
  uint64_t rlim_max; /* maximum limit in bytes */
};

int getrlimit(int, struct rlimit *) libcesque;
int setrlimit(int, const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rusage.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_
COSMOPOLITAN_C_START_

struct rusage {
  struct timeval ru_utime; /* user CPU time used */
  struct timeval ru_stime; /* system CPU time used */
  int64_t ru_maxrss;       /* maximum resident set size in (kb) */
  int64_t ru_ixrss;        /* shared memory size (integral kb CLK_TCK) */
  int64_t ru_idrss;        /* unshared data size (integral kb CLK_TCK) */
  int64_t ru_isrss;        /* unshared stack size (integral kb CLK_TCK) */
  int64_t ru_minflt;       /* page reclaims */
  int64_t ru_majflt;       /* page faults */
  int64_t ru_nswap;        /* swaps */
  int64_t ru_inblock;      /* block input operations */
  int64_t ru_oublock;      /* block output operations */
  int64_t ru_msgsnd;       /* IPC messages sent */
  int64_t ru_msgrcv;       /* IPC messages received */
  int64_t ru_nsignals;     /* signals received */
  int64_t ru_nvcsw;        /* voluntary context switches */
  int64_t ru_nivcsw;       /* involuntary context switches */
};

int getrusage(int, struct rusage *) libcesque;
int wait3(int *, int, struct rusage *) libcesque;
int wait4(int, int *, int, struct rusage *) libcesque;
void rusage_add(struct rusage *, const struct rusage *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sched_param.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SCHED_PARAM_H_
COSMOPOLITAN_C_START_

struct sched_param {
  int32_t sched_priority;
};

int sched_get_priority_max(int) libcesque;
int sched_get_priority_min(int) libcesque;
int sched_getparam(int, struct sched_param *) libcesque;
int sched_getscheduler(int) libcesque;
int sched_rr_get_interval(int, struct timespec *) libcesque;
int sched_setparam(int, const struct sched_param *) libcesque;
int sched_setscheduler(int, int, const struct sched_param *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigaction.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_


/*!BEGIN libc/calls/struct/siginfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_H_


/*!BEGIN libc/calls/struct/sigval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_
COSMOPOLITAN_C_START_

union sigval {
  int32_t sival_int;
  void *sival_ptr;
};

int sigqueue(int, int, const union sigval);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct siginfo {
  int32_t si_signo;
  int32_t si_errno;
  int32_t si_code; /* {SICODE,SEGV,ILL,FPE,POLL}_xxx */
  union {
    struct {
      union {
        struct {
          /* signals sent by kill() and sigqueue() set these */
          int32_t si_pid;
          uint32_t si_uid;
        };
        struct {
          /* SIGALRM sets these */
          int32_t si_timerid;
          int32_t si_overrun;
        };
      };
      union {
        union sigval si_value; /* provided by third arg of sigqueue(2) */
        struct {
          int32_t si_status;
          int64_t si_utime;
          int64_t si_stime;
        };
      };
    };
    struct {
      void *si_addr;
      int16_t si_addr_lsb;
      union {
        struct {
          void *si_lower;
          void *si_upper;
        };
        uint32_t si_pkey;
      };
    };
    struct {
      int64_t si_band; /* SIGPOLL */
      int32_t si_fd;
    };
    struct {
      void *si_call_addr;
      int32_t si_syscall;
      uint32_t si_arch;
    };
    char __ignoreme[128 - 2 * sizeof(int32_t) - sizeof(int64_t)];
  };
};

typedef struct siginfo siginfo_t;

#ifdef _COSMO_SOURCE
void __minicrash(int, siginfo_t *, void *) libcesque;
char __is_stack_overflow(siginfo_t *, void *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_
COSMOPOLITAN_C_START_

typedef uint64_t sigset_t;

int sigaddset(sigset_t *, int) paramsnonnull();
int sigdelset(sigset_t *, int) paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull();
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect;
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect;
int sigprocmask(int, const sigset_t *, sigset_t *);
int sigsuspend(const sigset_t *);
int sigpending(sigset_t *);
int pthread_sigmask(int, const sigset_t *, sigset_t *);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef void (*sighandler_t)(int);
typedef void (*sigaction_f)(int, struct siginfo *, void *);

struct sigaction {
  union {
    sighandler_t sa_handler;
    sigaction_f sa_sigaction;
  };
  uint64_t sa_flags;
  void (*sa_restorer)(void);
  sigset_t sa_mask;
};

sighandler_t signal(int, sighandler_t) libcesque;
int sigaction(int, const struct sigaction *, struct sigaction *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_H_
COSMOPOLITAN_C_START_

struct stat {              /* cosmo abi */
  uint64_t st_dev;         /* 0: id of device with file */
  uint64_t st_ino;         /* 8: inode number in disk b-tree */
  uint64_t st_nlink;       /* 16: hard link count */
  uint32_t st_mode;        /* 24: octal file mask thing */
  uint32_t st_uid;         /* 28: user id of owner */
  uint32_t st_gid;         /* group id of owning group */
  uint32_t st_flags;       /* nt/xnu/bsd-only */
  uint64_t st_rdev;        /* id of device if a special file */
  int64_t st_size;         /* bytes in file */
  int64_t st_blksize;      /* preferred chunking for underlying filesystem */
  int64_t st_blocks;       /* number of 512-byte pages allocated to file */
  struct timespec st_atim; /* access time */
  struct timespec st_mtim; /* modified time */
  struct timespec st_ctim; /* complicated time */
  struct timespec st_birthtim;
  uint64_t st_gen; /* xnu/bsd only */
};

int stat(const char *, struct stat *);
int lstat(const char *, struct stat *);
int fstat(int, struct stat *);
int fstatat(int, const char *, struct stat *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.macros.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_MACROS_H_

#define STAT_HAVE_NSEC 1

#define st_atime st_atim.tv_sec
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec

#define st_atime_nsec st_atim.tv_nsec
#define st_mtime_nsec st_mtim.tv_nsec
#define st_ctime_nsec st_ctim.tv_nsec

#define st_atimensec st_atim.tv_nsec
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
#define st_birthtime st_birthtim.tv_sec

#define st_file_attributes st_flags

#define INIT_STRUCT_STAT_PADDING(st) (void)st



/*!BEGIN libc/calls/struct/statfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
COSMOPOLITAN_C_START_

struct statfs {       /* cosmo abi */
  int64_t f_type;     /* type of filesystem */
  int64_t f_bsize;    /* optimal transfer block size */
  int64_t f_blocks;   /* total data blocks in filesystem */
  int64_t f_bfree;    /* free blocks in filesystem */
  int64_t f_bavail;   /* free blocks available to unprivileged users */
  int64_t f_files;    /* total file nodes in filesystem */
  int64_t f_ffree;    /* free file nodes in filesystem */
  fsid_t f_fsid;      /* filesystem id */
  int64_t f_namelen;  /* maximum length of filenames */
  int64_t f_frsize;   /* fragment size */
  int64_t f_flags;    /* mount flags of filesystem 2.6.36 */
  int64_t f_spare[4]; /* end of linux abi */
  uint32_t f_owner;
  char f_fstypename[16];
};

int statfs(const char *, struct statfs *) libcesque;
int fstatfs(int, struct statfs *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/statvfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
COSMOPOLITAN_C_START_

struct statvfs {
  unsigned long f_bsize;   /* Filesystem block size */
  unsigned long f_frsize;  /* Fragment size */
  uint64_t f_blocks;       /* Size of fs in f_frsize units */
  uint64_t f_bfree;        /* Number of free blocks */
  uint64_t f_bavail;       /* Number of free blocks for unprivileged users */
  uint64_t f_files;        /* Number of inodes */
  uint64_t f_ffree;        /* Number of free inodes */
  uint64_t f_favail;       /* Number of free inodes for unprivileged users */
  unsigned long f_fsid;    /* Filesystem ID */
  unsigned long f_flag;    /* Mount flags */
  unsigned long f_namemax; /* Maximum filename length */
};

int statvfs(const char *, struct statvfs *);
int fstatvfs(int, struct statvfs *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sysinfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_
COSMOPOLITAN_C_START_

struct sysinfo {
  int64_t uptime;     /* seconds since boot */
  uint64_t loads[3];  /* 1-5-15 min active process averages */
  uint64_t totalram;  /* system physical memory */
  uint64_t freeram;   /* amount of ram currently going to waste */
  uint64_t sharedram; /* bytes w/ pages mapped into multiple progs */
  uint64_t bufferram; /* lingering disk pages; see fadvise */
  uint64_t totalswap; /* size of emergency memory */
  uint64_t freeswap;  /* hopefully equal to totalswap */
  uint16_t procs;     /* number of processes */
  int16_t __ignore1;  /* padding */
  int32_t __ignore2;  /* padding */
  uint64_t totalhigh; /* wut */
  uint64_t freehigh;  /* wut */
  uint32_t mem_unit;  /* ram stuff above is multiples of this */
};

int sysinfo(struct sysinfo *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TERMIOS_H_

#define NCCS 20

COSMOPOLITAN_C_START_

struct termios {      /* cosmo abi */
  uint32_t c_iflag;   /* input modes */
  uint32_t c_oflag;   /* output modes */
  uint32_t c_cflag;   /* control modes */
  uint32_t c_lflag;   /* local modes */
  uint8_t c_cc[NCCS]; /* code mappings */
  uint32_t _c_ispeed; /* use cfgetispeed() and cfsetispeed() */
  uint32_t _c_ospeed; /* use cfgetospeed() and cfsetospeed() */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/tms.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_
COSMOPOLITAN_C_START_

struct tms {
  int64_t tms_utime;  /* userspace time */
  int64_t tms_stime;  /* kernelspace time */
  int64_t tms_cutime; /* children userspace time */
  int64_t tms_cstime; /* children kernelspace time */
};

long times(struct tms *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/user_regs_struct.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_USER_REGS_STRUCT_H_
COSMOPOLITAN_C_START_

/**
 * Linux Kernel user registers.
 *
 * @note superset of struct pt_regs
 * @see ptrace() w/ PTRACE_SYSCALL
 */
struct user_regs_struct {
  uint64_t r15;
  uint64_t r14;
  uint64_t r13;
  uint64_t r12;
  uint64_t rbp;
  uint64_t rbx;
  uint64_t r11;
  uint64_t r10;
  uint64_t r9;
  uint64_t r8;
  uint64_t rax;
  uint64_t rcx;
  uint64_t rdx;
  uint64_t rsi;
  uint64_t rdi;
  uint64_t orig_rax;
  uint64_t rip;
  uint64_t cs;
  uint64_t eflags;
  uint64_t rsp;
  uint64_t ss;
  uint64_t fs_base;
  uint64_t gs_base;
  uint64_t ds;
  uint64_t es;
  uint64_t fs;
  uint64_t gs;
};

struct useregs_struct_freebsd {
  int64_t r15;
  int64_t r14;
  int64_t r13;
  int64_t r12;
  int64_t r11;
  int64_t r10;
  int64_t r9;
  int64_t r8;
  int64_t rdi;
  int64_t rsi;
  int64_t rbp;
  int64_t rbx;
  int64_t rdx;
  int64_t rcx;
  int64_t rax;
  uint32_t trapno;
  uint16_t fs;
  uint16_t gs;
  uint32_t err;
  uint16_t es;
  uint16_t ds;
  int64_t rip;
  int64_t cs;
  int64_t rflags;
  int64_t rsp;
  int64_t ss;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/utsname.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UTSNAME_H_

#define SYS_NMLN 150

COSMOPOLITAN_C_START_

struct utsname {             /* cosmo abi */
  char sysname[SYS_NMLN];    /* name of os */
  char nodename[SYS_NMLN];   /* name of network node */
  char release[SYS_NMLN];    /* release level */
  char version[SYS_NMLN];    /* version level */
  char machine[SYS_NMLN];    /* hardware type */
  char domainname[SYS_NMLN]; /* domain name */
};

int uname(struct utsname *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/winsize.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_
COSMOPOLITAN_C_START_

struct winsize {
  uint16_t ws_row;
  uint16_t ws_col;
  uint16_t ws_xpixel;
  uint16_t ws_ypixel;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/cachestat.h */

#define COSMOPOLITAN_LIBC_CALLS_CACHESTAT_H_

COSMOPOLITAN_C_START_

struct cachestat_range {
  uint64_t off;
  uint64_t len;
};

struct cachestat {
  /** Number of cached pages. */
  uint64_t nr_cache;
  /** Number of dirty pages */
  uint64_t nr_dirty;
  /** Number of pages marked for writeback. */
  uint64_t nr_writeback;
  /** Number of pages evicted from the cache. */
  uint64_t nr_evicted;
  /**
   * Number of recently evicted pages.
   * A page is recently evicted if its last eviction was recent enough that its
   * reentry to the cache would indicate that it is actively being used by the
   * system, and that there is memory pressure on the system.
   */
  uint64_t nr_recently_evicted;
};

int cachestat(int, struct cachestat_range *, struct cachestat *, uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/calls.h */

#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_

#define _POSIX_VERSION  200809L
#define _POSIX2_VERSION _POSIX_VERSION
#define _XOPEN_VERSION  700

#define _POSIX_MAPPED_FILES               _POSIX_VERSION
#define _POSIX_FSYNC                      _POSIX_VERSION
#define _POSIX_IPV6                       _POSIX_VERSION
#define _POSIX_THREADS                    _POSIX_VERSION
#define _POSIX_THREAD_PROCESS_SHARED      _POSIX_VERSION
#define _POSIX_THREAD_SAFE_FUNCTIONS      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKADDR      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKSIZE      _POSIX_VERSION
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
#define _POSIX_THREAD_CPUTIME             _POSIX_VERSION
#define _POSIX_TIMEOUTS                   _POSIX_VERSION
#define _POSIX_MONOTONIC_CLOCK            _POSIX_VERSION
#define _POSIX_CPUTIME                    _POSIX_VERSION
#define _POSIX_BARRIERS                   _POSIX_VERSION
#define _POSIX_SPIN_LOCKS                 _POSIX_VERSION
#define _POSIX_READER_WRITER_LOCKS        _POSIX_VERSION
#define _POSIX_SEMAPHORES                 _POSIX_VERSION
#define _POSIX_SHARED_MEMORY_OBJECTS      _POSIX_VERSION
#define _POSIX_MEMLOCK_RANGE              _POSIX_VERSION
#define _POSIX_SPAWN                      _POSIX_VERSION

#define NSIG 64

#define SEEK_SET 0          /* relative to beginning */
#define SEEK_CUR 1          /* relative to current position */
#define SEEK_END 2          /* relative to end */
#define __WALL   0x40000000 /* Wait on all children, regardless of type */
#define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */

#define SIG_ERR ((void (*)(int))(-1))
#define SIG_DFL ((void (*)(int))0)
#define SIG_IGN ((void (*)(int))1)

#define CLOCKS_PER_SEC 1000000L

#define MAP_FAILED ((void *)-1)

#define WTERMSIG(x)     (127 & (x))
#define WCOREDUMP(x)    (128 & (x))
#define WIFEXITED(x)    (!WTERMSIG(x))
#define WEXITSTATUS(x)  ((x) >> 8)
#define WSTOPSIG(x)     ((0xff00 & (x)) >> 8)
#define WIFSTOPPED(x)   __wifstopped(x)
#define WIFSIGNALED(x)  __wifsignaled(x)
#define WIFCONTINUED(x) __wifcontinued(x)
#define W_STOPCODE(x)   ((x) << 8 | 0177)

#ifdef _COSMO_SOURCE
#define clone         __clone
#define commandv      __commandv
#define fileexists    __fileexists
#define ischardev     __ischardev
#define isdirectory   __isdirectory
#define isexecutable  __isexecutable
#define isregularfile __isregularfile
#define issymlink     __issymlink
#define makedirs      __makedirs
#define tmpfd         __tmpfd
#endif

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § system calls                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

typedef int sig_atomic_t;

bool32 isatty(int) libcesque;
char *getcwd(char *, size_t) dontthrow;
char *realpath(const char *, char *) libcesque __wur;
char *ttyname(int) libcesque;
int access(const char *, int) libcesque;
int chdir(const char *) libcesque;
int chmod(const char *, unsigned) libcesque;
int chown(const char *, unsigned, unsigned) libcesque;
int chroot(const char *) libcesque;
int close(int) libcesque;
int close_range(unsigned, unsigned, unsigned) libcesque;
int closefrom(int) libcesque;
int creat(const char *, unsigned) libcesque;
int dup(int) libcesque;
int dup2(int, int) libcesque;
int dup3(int, int, int) libcesque;
int execl(const char *, const char *, ...) nullterminated() libcesque;
int execle(const char *, const char *, ...) nullterminated((1)) libcesque;
int execlp(const char *, const char *, ...) nullterminated() libcesque;
int execv(const char *, char *const[]) libcesque;
int execve(const char *, char *const[], char *const[]) libcesque;
int execvp(const char *, char *const[]) libcesque;
int faccessat(int, const char *, int, int) libcesque;
int fchdir(int) libcesque;
int fchmod(int, unsigned) libcesque;
int fchmodat(int, const char *, unsigned, int) libcesque;
int fchown(int, unsigned, unsigned) libcesque;
int fchownat(int, const char *, unsigned, unsigned, int) libcesque;
int fcntl(int, int, ...) libcesque;
int fdatasync(int) libcesque;
int fexecve(int, char *const[], char *const[]) libcesque;
int flock(int, int) libcesque;
int fork(void) libcesque;
int fsync(int) libcesque;
int ftruncate(int, int64_t) libcesque;
int getdomainname(char *, size_t) libcesque;
int getgroups(int, unsigned[]) libcesque;
int gethostname(char *, size_t) libcesque;
int getloadavg(double *, int) libcesque;
int getpgid(int) libcesque;
int getpgrp(void) libcesque nosideeffect;
int getpid(void) libcesque nosideeffect;
int getppid(void) libcesque;
int getpriority(int, unsigned) libcesque;
int getsid(int) nosideeffect libcesque;
int ioctl(int, unsigned long, ...) libcesque;
int issetugid(void) libcesque;
int kill(int, int) libcesque;
int killpg(int, int) libcesque;
int lchmod(const char *, unsigned) libcesque;
int lchown(const char *, unsigned, unsigned) libcesque;
int link(const char *, const char *) libcesque;
int linkat(int, const char *, int, const char *, int) libcesque;
int mincore(void *, size_t, unsigned char *) libcesque;
int mkdir(const char *, unsigned) libcesque;
int mkdirat(int, const char *, unsigned) libcesque;
int mknod(const char *, unsigned, uint64_t) libcesque;
int nice(int) libcesque;
int open(const char *, int, ...) libcesque;
int openat(int, const char *, int, ...) libcesque;
int pause(void) libcesque;
int pipe(int[hasatleast 2]) libcesque;
int pipe2(int[hasatleast 2], int) libcesque;
int posix_fadvise(int, int64_t, int64_t, int) libcesque;
int posix_madvise(void *, uint64_t, int) libcesque;
int raise(int) libcesque;
int reboot(int) libcesque;
int remove(const char *) libcesque;
int rename(const char *, const char *) libcesque;
int renameat(int, const char *, int, const char *) libcesque;
int rmdir(const char *) libcesque;
int sched_yield(void) libcesque;
int setegid(unsigned) libcesque;
int seteuid(unsigned) libcesque;
int setfsgid(unsigned) libcesque;
int setfsuid(unsigned) libcesque;
int setgid(unsigned) libcesque;
int setgroups(size_t, const unsigned[]) libcesque;
int setpgid(int, int) libcesque;
int setpgrp(void) libcesque;
int setpriority(int, unsigned, int) libcesque;
int setregid(unsigned, unsigned) libcesque;
int setreuid(unsigned, unsigned) libcesque;
int setsid(void) libcesque;
int setuid(unsigned) libcesque;
int shm_open(const char *, int, unsigned) libcesque;
int shm_unlink(const char *) libcesque;
int sigignore(int) libcesque;
int siginterrupt(int, int) libcesque;
int symlink(const char *, const char *) libcesque;
int symlinkat(const char *, int, const char *) libcesque;
int tcgetpgrp(int) libcesque;
int tcsetpgrp(int, int) libcesque;
int truncate(const char *, int64_t) libcesque;
int ttyname_r(int, char *, size_t) libcesque;
int unlink(const char *) libcesque;
int unlinkat(int, const char *, int) libcesque;
int usleep(uint64_t) libcesque;
int vfork(void) libcesque returnstwice;
int wait(int *) libcesque;
int waitpid(int, int *, int) libcesque;
int64_t clock(void) libcesque;
int64_t time(int64_t *) libcesque;
ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned) libcesque;
ssize_t lseek(int, int64_t, int) libcesque;
ssize_t pread(int, void *, size_t, int64_t) libcesque;
ssize_t pwrite(int, const void *, size_t, int64_t) libcesque;
ssize_t read(int, void *, size_t) libcesque;
ssize_t readlink(const char *, char *, size_t) libcesque;
ssize_t readlinkat(int, const char *, char *, size_t) libcesque;
ssize_t write(int, const void *, size_t) libcesque;
unsigned alarm(unsigned) libcesque;
unsigned getegid(void) libcesque nosideeffect;
unsigned geteuid(void) libcesque nosideeffect;
unsigned getgid(void) libcesque nosideeffect;
unsigned getuid(void) libcesque;
unsigned sleep(unsigned) libcesque;
unsigned ualarm(unsigned, unsigned) libcesque;
unsigned umask(unsigned) libcesque;
void sync(void) libcesque;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
int syncfs(int) libcesque;
int prctl(int, ...) libcesque;
int gettid(void) libcesque;
int setresgid(unsigned, unsigned, unsigned) libcesque;
int setresuid(unsigned, unsigned, unsigned) libcesque;
int getresgid(unsigned *, unsigned *, unsigned *) libcesque;
int getresuid(unsigned *, unsigned *, unsigned *) libcesque;
char *get_current_dir_name(void) libcesque __wur;
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned) libcesque;
int memfd_create(const char *, unsigned int) libcesque;
int execvpe(const char *, char *const[], char *const[]) libcesque;
int euidaccess(const char *, int) libcesque;
int eaccess(const char *, int) libcesque;
int madvise(void *, uint64_t, int) libcesque;
int getcpu(unsigned *, unsigned *) libcesque;
#endif

#ifdef _COSMO_SOURCE
bool32 fdexists(int) libcesque;
bool32 fileexists(const char *) libcesque;
bool32 ischardev(int) libcesque;
bool32 isdirectory(const char *) libcesque;
bool32 isexecutable(const char *) libcesque;
bool32 isregularfile(const char *) libcesque;
bool32 issymlink(const char *) libcesque;
char *commandv(const char *, char *, size_t) libcesque;
int __getcwd(char *, size_t) libcesque;
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
int fadvise(int, uint64_t, uint64_t, int) libcesque;
int makedirs(const char *, unsigned) libcesque;
int pivot_root(const char *, const char *) libcesque;
int pledge(const char *, const char *) libcesque;
int seccomp(unsigned, unsigned, void *) libcesque;
int sys_iopl(int) libcesque;
int sys_ioprio_get(int, int) libcesque;
int sys_ioprio_set(int, int, int) libcesque;
int sys_mlock(const void *, size_t) libcesque;
int sys_mlock2(const void *, size_t, int) libcesque;
int sys_mlockall(int) libcesque;
int sys_munlock(const void *, size_t) libcesque;
int sys_munlockall(void) libcesque;
int sys_personality(uint64_t) libcesque;
int sys_ptrace(int, ...) libcesque;
int sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque;
int sysctlbyname(const char *, void *, size_t *, void *, size_t) libcesque;
int sysctlnametomib(const char *, int *, size_t *) libcesque;
int tmpfd(void) libcesque;
int touch(const char *, unsigned) libcesque;
int unveil(const char *, const char *) libcesque;
long ptrace(int, ...) libcesque;
ssize_t copyfd(int, int, size_t) libcesque;
ssize_t readansi(int, char *, size_t) libcesque;
ssize_t tinyprint(int, const char *, ...) libcesque nullterminated();
void shm_path_np(const char *, char[hasatleast 78]) libcesque;
#endif /* _COSMO_SOURCE */

int system(const char *) libcesque;

int __wifstopped(int) libcesque pureconst;
int __wifcontinued(int) libcesque pureconst;
int __wifsignaled(int) libcesque pureconst;

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define lseek64     lseek
#define pread64     pread
#define pwrite64    pwrite
#define truncate64  truncate
#define ftruncate64 ftruncate
#define lockf64     lockf
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ipc.h */

#define COSMOPOLITAN_LIBC_CALLS_IPC_H_

#define IPC_PRIVATE 0
#define IPC_RMID    0
#define IPC_SET     1
#define IPC_STAT    2
#define IPC_INFO    3
#define IPC_CREAT   01000
#define IPC_EXCL    02000
#define IPC_NOWAIT  04000

COSMOPOLITAN_C_START_

int ftok(const char *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/landlock.h */

#define COSMOPOLITAN_LIBC_CALLS_LANDLOCK_H_

#define LANDLOCK_CREATE_RULESET_VERSION 0x0001ul

#define LANDLOCK_ACCESS_FS_EXECUTE     0x0001ul
#define LANDLOCK_ACCESS_FS_WRITE_FILE  0x0002ul
#define LANDLOCK_ACCESS_FS_READ_FILE   0x0004ul
#define LANDLOCK_ACCESS_FS_READ_DIR    0x0008ul
#define LANDLOCK_ACCESS_FS_REMOVE_DIR  0x0010ul
#define LANDLOCK_ACCESS_FS_REMOVE_FILE 0x0020ul
#define LANDLOCK_ACCESS_FS_MAKE_CHAR   0x0040ul
#define LANDLOCK_ACCESS_FS_MAKE_DIR    0x0080ul
#define LANDLOCK_ACCESS_FS_MAKE_REG    0x0100ul
#define LANDLOCK_ACCESS_FS_MAKE_SOCK   0x0200ul
#define LANDLOCK_ACCESS_FS_MAKE_FIFO   0x0400ul
#define LANDLOCK_ACCESS_FS_MAKE_BLOCK  0x0800ul
#define LANDLOCK_ACCESS_FS_MAKE_SYM    0x1000ul

/**
 * Allow renaming or linking file to a different directory.
 *
 * @see https://lore.kernel.org/r/20220329125117.1393824-8-mic@digikod.net
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 2+
 */
#define LANDLOCK_ACCESS_FS_REFER 0x2000ul

/**
 * Control file truncation.
 *
 * @see
 * https://lore.kernel.org/all/20221018182216.301684-1-gnoack3000@gmail.com/
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 3+
 */
#define LANDLOCK_ACCESS_FS_TRUNCATE 0x4000ul

COSMOPOLITAN_C_START_

enum landlock_rule_type {
  LANDLOCK_RULE_PATH_BENEATH = 1,
};

struct landlock_ruleset_attr {
  uint64_t handled_access_fs;
};

struct thatispacked landlock_path_beneath_attr {
  uint64_t allowed_access;
  int32_t parent_fd;
};

int landlock_restrict_self(int, uint32_t);
int landlock_add_rule(int, enum landlock_rule_type, const void *, uint32_t);
int landlock_create_ruleset(const struct landlock_ruleset_attr *, size_t,
                            uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/makedev.h */

#define COSMOPOLITAN_LIBC_CALLS_MAKEDEV_H_

uint64_t makedev(uint32_t, uint32_t) libcesque;
uint32_t major(uint64_t) libcesque;
uint32_t minor(uint64_t) libcesque;

#define major(x)      major(x)
#define minor(x)      minor(x)
#define makedev(x, y) makedev(x, y)



/*!BEGIN libc/calls/mount.h */

#define COSMOPOLITAN_LIBC_CALLS_MOUNT_H_
COSMOPOLITAN_C_START_

int mount(const char *, const char *, const char *, unsigned long,
          const void *);
int unmount(const char *, int);

#ifdef _GNU_SOURCE
int umount(const char *);
int umount2(const char *, int);
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/pledge.h */

#define COSMOPOLITAN_LIBC_CALLS_PLEDGE_H_

#define PLEDGE_PENALTY_KILL_THREAD  0x0000
#define PLEDGE_PENALTY_KILL_PROCESS 0x0001
#define PLEDGE_PENALTY_RETURN_EPERM 0x0002
#define PLEDGE_PENALTY_MASK         0x000f
#define PLEDGE_STDERR_LOGGING       0x0010

COSMOPOLITAN_C_START_

extern int __pledge_mode;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/sigtimedwait.h */

#define COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_H_
COSMOPOLITAN_C_START_

int sigwait(const sigset_t *, int *);
int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *);
int sigwaitinfo(const sigset_t *, siginfo_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_H_
COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § teletypewriter control                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int tcgetattr(int, struct termios *) libcesque;
int tcsetattr(int, int, const struct termios *) libcesque;

int openpty(int *, int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2));
int forkpty(int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2)) __wur;
char *ptsname(int) libcesque;
errno_t ptsname_r(int, char *, size_t) libcesque;

int grantpt(int) libcesque;
int unlockpt(int) libcesque;
int posix_openpt(int) libcesque __wur;

int tcdrain(int) libcesque;
int tcgetsid(int) libcesque;
int tcflow(int, int) libcesque;
int tcflush(int, int) libcesque;
int tcsetsid(int, int) libcesque;
int tcsendbreak(int, int) libcesque;
void cfmakeraw(struct termios *) libcesque;
int cfsetspeed(struct termios *, uint32_t) libcesque;
int cfsetospeed(struct termios *, uint32_t) libcesque;
int cfsetispeed(struct termios *, uint32_t) libcesque;
uint32_t cfgetospeed(const struct termios *) libcesque;
uint32_t cfgetispeed(const struct termios *) libcesque;
int tcsetwinsize(int, const struct winsize *) libcesque;
int tcgetwinsize(int, struct winsize *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ttydefaults.h */

#define COSMOPOLITAN_LIBC_CALLS_TTYDEFAULTS_H_


/*!BEGIN libc/sysv/consts/termios.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TERMIOS_H_
COSMOPOLITAN_C_START_

#define EXTA B19200
#define EXTB B38400

extern const int _POSIX_VDISABLE;
extern const uint32_t BRKINT;
extern const uint32_t BS1;
extern const uint32_t BS2;
extern const uint32_t BSDLY;
extern const uint32_t CLOCAL;
extern const uint32_t CMSPAR;
extern const uint32_t CR1;
extern const uint32_t CR2;
extern const uint32_t CR3;
extern const uint32_t CRDLY;
extern const uint32_t CREAD;
extern const uint32_t CS5;
extern const uint32_t CS6;
extern const uint32_t CS7;
extern const uint32_t CS8;
extern const uint32_t CSIZE;
extern const uint32_t CSTOPB;
extern const uint32_t ECHOCTL;
extern const uint32_t ECHOE;
extern const uint32_t ECHOK;
extern const uint32_t ECHOKE;
extern const uint32_t ECHONL;
extern const uint32_t ECHOPRT;
extern const long EXTPROC;
extern const uint32_t FF1;
extern const uint32_t FF2;
extern const uint32_t FFDLY;
extern const uint32_t FLUSHO;
extern const uint32_t HUPCL;
extern const uint32_t ICANON;
extern const uint32_t ICRNL;
extern const uint32_t IEXTEN;
extern const uint32_t IGNBRK;
extern const uint32_t IGNCR;
extern const uint32_t IGNPAR;
extern const uint32_t IMAXBEL;
extern const uint32_t INLCR;
extern const uint32_t INPCK;
extern const uint32_t ISIG;
extern const uint32_t ISTRIP;
extern const uint32_t IUCLC;
extern const uint32_t IUTF8;
extern const uint32_t IXANY;
extern const uint32_t IXOFF;
extern const uint32_t IXON;
extern const uint32_t NL1;
extern const uint32_t NL2;
extern const uint32_t NL3;
extern const uint32_t NLDLY;
extern const uint32_t NOFLSH;
extern const uint32_t OCRNL;
extern const uint32_t OFDEL;
extern const uint32_t OFILL;
extern const uint32_t OLCUC;
extern const uint32_t ONLCR;
extern const uint32_t ONLRET;
extern const uint32_t ONOCR;
extern const uint32_t OPOST;
extern const uint32_t PARENB;
extern const uint32_t PARMRK;
extern const uint32_t PARODD;
extern const uint32_t PENDIN;
extern const uint32_t TAB1;
extern const uint32_t TAB2;
extern const uint32_t TAB3;
extern const uint32_t TABDLY;
extern const uint64_t TIOCCONS;
extern const uint64_t TIOCGETD;
extern const uint64_t TIOCGWINSZ;
extern const uint64_t TIOCNOTTY;
extern const uint64_t TIOCNXCL;
extern const uint64_t TIOCOUTQ;
extern const uint64_t TIOCSCTTY;
extern const uint64_t TIOCSETD;
extern const uint64_t TIOCSIG;
extern const uint64_t TIOCSPGRP;
extern const uint64_t TIOCSTI;
extern const uint64_t TIOCSWINSZ;
extern const long TOSTOP;
extern const uint8_t VDISCARD;
extern const uint8_t VEOF;
extern const uint8_t VEOL2;
extern const uint8_t VEOL;
extern const uint8_t VERASE;
extern const uint8_t VINTR;
extern const uint8_t VKILL;
extern const uint8_t VLNEXT;
extern const uint8_t VMIN;
extern const uint8_t VQUIT;
extern const uint8_t VREPRINT;
extern const uint8_t VSTART;
extern const uint8_t VSTOP;
extern const uint8_t VSUSP;
extern const uint8_t VSWTC;
extern const uint32_t VT1;
extern const uint32_t VT2;
extern const uint32_t VTDLY;
extern const uint8_t VTIME;
extern const uint8_t VWERASE;
extern const uint32_t XCASE;
extern const uint32_t XTABS;
extern const uint32_t CRTSCTS;

#define BRKINT  0x02
#define ICRNL   0x0100
#define IGNBRK  0x01
#define IGNCR   0x80
#define IGNPAR  0x04
#define IMAXBEL 0x2000
#define INLCR   0x40
#define INPCK   0x10
#define ISTRIP  0x20
#define IXANY   0x0800
#define OPOST   0x01
#define PARMRK  0x08

#define _POSIX_VDISABLE _POSIX_VDISABLE

#define NLDLY   NLDLY
#define NL0     0
#define NL1     NL1
#define NL2     NL2
#define NL3     NL3
#define CRDLY   CRDLY
#define CR0     0
#define CR1     CR1
#define CR2     CR2
#define CR3     CR3
#define TABDLY  TABDLY
#define TAB0    0
#define TAB1    TAB1
#define TAB2    TAB2
#define TAB3    TAB3
#define XTABS   XTABS
#define CRTSCTS CRTSCTS
#define BSDLY   BSDLY
#define BS0     0
#define BS1     BS1
#define BS2     BS2
#define VTDLY   VTDLY
#define VT0     0
#define VT1     VT1
#define VT2     VT2
#define FFDLY   FFDLY
#define FF0     0
#define FF1     FF1
#define FF2     FF2

#define CLOCAL   CLOCAL
#define CREAD    CREAD
#define CS5      CS5
#define CS6      CS6
#define CS7      CS7
#define CS8      CS8
#define CSIZE    CSIZE
#define CSTOPB   CSTOPB
#define ECHO     8
#define ECHOCTL  ECHOCTL
#define ECHOE    ECHOE
#define ECHOK    ECHOK
#define ECHOKE   ECHOKE
#define ECHONL   ECHONL
#define ECHOPRT  ECHOPRT
#define EXTPROC  EXTPROC
#define FLUSHO   FLUSHO
#define HUPCL    HUPCL
#define ICANON   ICANON
#define IEXTEN   IEXTEN
#define ISIG     ISIG
#define IUCLC    IUCLC
#define IUTF8    IUTF8
#define IXOFF    IXOFF
#define IXON     IXON
#define NOFLSH   NOFLSH
#define OCRNL    OCRNL
#define OFDEL    OFDEL
#define OFILL    OFILL
#define OLCUC    OLCUC
#define ONLCR    ONLCR
#define ONLRET   ONLRET
#define ONOCR    ONOCR
#define PARENB   PARENB
#define PARODD   PARODD
#define PENDIN   PENDIN
#define TOSTOP   TOSTOP
#define VDISCARD VDISCARD
#define VEOF     VEOF
#define VEOL     VEOL
#define VEOL2    VEOL2
#define VERASE   VERASE
#define VINTR    VINTR
#define VKILL    VKILL
#define VLNEXT   VLNEXT
#define VMIN     VMIN
#define VQUIT    VQUIT
#define VREPRINT VREPRINT
#define VSTART   VSTART
#define VSTOP    VSTOP
#define VSUSP    VSUSP
#define VSWTC    VSWTC
#define VTIME    VTIME
#define VWERASE  VWERASE
#define XCASE    XCASE

/* terminal ioctls */
#define TIOCGWINSZ TIOCGWINSZ /* get tty dimensions */
#define TIOCSWINSZ TIOCSWINSZ /* set tty dimensions */
#define TIOCCONS   TIOCCONS   /* redirect terminal */
#define TIOCGETD   TIOCGETD   /* get line discipline */
#define TIOCSETD   TIOCSETD   /* set line discipline */
#define TIOCNOTTY  TIOCNOTTY  /* give up terminal */
#define TIOCNXCL   TIOCNXCL   /* disable exclusive mode */
#define TIOCOUTQ   TIOCOUTQ   /* bytes in output buffer */
#define TIOCSCTTY  TIOCSCTTY  /* make controlling terminal */
#define TIOCSIG    TIOCSIG    /* generate pty signal */
#define TIOCSTI    TIOCSTI    /* insert fake tty input */

/* tcsetattr() */
#define TCSANOW   0
#define TCSAFLUSH 2
#define TCSADRAIN 1
extern const unsigned long TCGETS; /* use tcgetattr() */
extern const unsigned long TCSETS; /* use tcsetattr() */

/* tcflush() */
extern const int TCIFLUSH;
extern const int TCOFLUSH;
extern const int TCIOFLUSH;
#define TCIFLUSH  TCIFLUSH
#define TCOFLUSH  TCOFLUSH
#define TCIOFLUSH TCIOFLUSH

/* tcflow() */
#define TCOOFF 0
#define TCOON  1
#define TCIOFF 2
#define TCION  3

COSMOPOLITAN_C_END_

#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS)
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE | ECHOKE | ECHOCTL)
#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
#define TTYDEF_SPEED (B9600)

#define CTRL(x)  ((x) ^ 0100)
#define CEOF     CTRL('D')
#define CERASE   CTRL('?')
#define CINTR    CTRL('C')
#define CKILL    CTRL('U')
#define CQUIT    CTRL('\\')
#define CSUSP    CTRL('Z')
#define CDSUSP   CTRL('Y')
#define CSTART   CTRL('Q')
#define CSTOP    CTRL('S')
#define CLNEXT   CTRL('V')
#define CDISCARD CTRL('O')
#define CWERASE  CTRL('W')
#define CREPRINT CTRL('R')
#define CEOT     CEOF
#define CBRK     CEOL
#define CRPRNT   CREPRINT
#define CFLUSH   CDISCARD
#define CEOL     255
#define CMIN     1
#define CTIME    0



/*!BEGIN libc/calls/ucontext.h */

#define COSMOPOLITAN_LIBC_CALLS_UCONTEXT_H_
COSMOPOLITAN_C_START_

#ifdef __x86_64__

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define REG_R8      0
#define REG_R9      1
#define REG_R10     2
#define REG_R11     3
#define REG_R12     4
#define REG_R13     5
#define REG_R14     6
#define REG_R15     7
#define REG_RDI     8
#define REG_RSI     9
#define REG_RBP     10
#define REG_RBX     11
#define REG_RDX     12
#define REG_RAX     13
#define REG_RCX     14
#define REG_RSP     15
#define REG_RIP     16
#define REG_EFL     17
#define REG_CSGSFS  18
#define REG_ERR     19
#define REG_TRAPNO  20
#define REG_OLDMASK 21
#define REG_CR2     22
#endif

struct XmmRegister {
  uint64_t u64[2];
};

struct FpuStackEntry {
  uint16_t significand[4];
  uint16_t exponent;
  uint16_t padding[3];
};

struct thatispacked FpuState {

  /* 8087 FPU Control Word
      IM: Invalid Operation ───────────────┐
      DM: Denormal Operand ───────────────┐│
      ZM: Zero Divide ───────────────────┐││
      OM: Overflow ─────────────────────┐│││
      UM: Underflow ───────────────────┐││││
      PM: Precision ──────────────────┐│││││
      PC: Precision Control ───────┐  ││││││
       {float,∅,double,long double}│  ││││││
      RC: Rounding Control ──────┐ │  ││││││
       {even, →-∞, →+∞, →0}      │┌┤  ││││││
                                ┌┤││  ││││││
                               d││││rr││││││
                          0b0000001001111111 */
  uint16_t cwd;

  /* 8087 FPU Status Word */
  uint16_t swd;

  uint16_t ftw;
  uint16_t fop;
  uint64_t rip;
  uint64_t rdp;

  /* SSE CONTROL AND STATUS REGISTER
     IE: Invalid Operation Flag ──────────────┐
     DE: Denormal Flag ──────────────────────┐│
     ZE: Divide-by-Zero Flag ───────────────┐││
     OE: Overflow Flag ────────────────────┐│││
     UE: Underflow Flag ──────────────────┐││││
     PE: Precision Flag ─────────────────┐│││││
     DAZ: Denormals Are Zeros ──────────┐││││││
     IM: Invalid Operation Mask ───────┐│││││││
     DM: Denormal Operation Mask ─────┐││││││││
     ZM: Divide-by-Zero Mask ────────┐│││││││││
     OM: Overflow Mask ─────────────┐││││││││││
     UM: Underflow Mask ───────────┐│││││││││││
     PM: Precision Mask ──────────┐││││││││││││
     RC: Rounding Control ───────┐│││││││││││││
       {even, →-∞, →+∞, →0}      ││││││││││││││
     FTZ: Flush To Zero ───────┐ ││││││││││││││
                               │┌┤│││││││││││││
               ┌──────────────┐││││││││││││││││
               │   reserved   │││││││││││││││││
             0b00000000000000000001111110000000 */
  uint32_t mxcsr;
  uint32_t mxcr_mask;

  struct FpuStackEntry st[8];
  struct XmmRegister xmm[16];
  uint32_t __padding[24];
};

typedef long long greg_t;
typedef greg_t gregset_t[23];
typedef struct FpuState *fpregset_t;

#endif /* __x86_64__ */

struct sigcontext {
#ifdef __x86_64__
  union {
    struct {
      uint64_t r8;     /* 40 */
      uint64_t r9;     /* 48 */
      uint64_t r10;    /* 56 */
      uint64_t r11;    /* 64 */
      uint64_t r12;    /* 72 */
      uint64_t r13;    /* 80 */
      uint64_t r14;    /* 88 */
      uint64_t r15;    /* 96 */
      uint64_t rdi;    /* 104 */
      uint64_t rsi;    /* 112 */
      uint64_t rbp;    /* 120 */
      uint64_t rbx;    /* 128 */
      uint64_t rdx;    /* 136 */
      uint64_t rax;    /* 144 */
      uint64_t rcx;    /* 152 */
      uint64_t rsp;    /* 160 */
      uint64_t rip;    /* 168 */
      uint64_t eflags; /* 176 */
      uint16_t cs;
      uint16_t gs;
      uint16_t fs;
      uint16_t __pad0;
      uint64_t err;
      uint64_t trapno;
      uint64_t oldmask;
      uint64_t cr2;
    };
    gregset_t gregs;
  };
  struct FpuState *fpregs; /* zero when no fpu context */
  uint64_t __pad1[8];
#elif defined(__aarch64__)
  uint64_t fault_address;
  uint64_t regs[31];
  uint64_t sp;
  uint64_t pc;
  uint64_t pstate;
  uint8_t __reserved[4096] __attribute__((__aligned__(16)));
#endif /* __x86_64__ */
};

typedef struct sigcontext mcontext_t;

struct ucontext {
  uint64_t uc_flags; /* don't use this */
  struct ucontext *uc_link;
  stack_t uc_stack;
#ifdef __x86_64__
  struct sigcontext uc_mcontext;
  sigset_t uc_sigmask;
  uint64_t __pad[2];
  struct FpuState __fpustate; /* for cosmo on non-linux */
#elif defined(__aarch64__)
  sigset_t uc_sigmask;
  uint8_t __unused[1024 / 8];
  struct sigcontext uc_mcontext;
#endif
} forcealign(16);

typedef struct ucontext ucontext_t;

int getcontext(ucontext_t *) dontthrow;
int setcontext(const ucontext_t *) dontthrow;
int swapcontext(ucontext_t *, const ucontext_t *) dontthrow returnstwice;
void makecontext(ucontext_t *, void *, int, ...) dontthrow dontcallback;
void __sig_restore(const ucontext_t *) wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/weirdtypes.h */

#define COSMOPOLITAN_LIBC_CALLS_WEIRDTYPES_H_

/**
 * @fileoverview Types we'd prefer hadn't been invented.
 */

typedef int64_t blkcnt_t;
typedef uint8_t cc_t;
typedef int64_t clock_t; /* uint64_t on xnu */
typedef uint64_t dev_t;  /* int32_t on xnu */
typedef uint64_t fsblkcnt_t;
typedef int64_t fsfilcnt_t; /* uint32_t on xnu */
typedef uint32_t gid_t;
typedef int32_t id_t; /* int32_t on linux/freebsd/etc. */
typedef uint32_t in_addr_t;
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
typedef uint64_t ino_t;
typedef int32_t key_t;
typedef int64_t loff_t;
typedef uint32_t mode_t; /* uint16_t on xnu */
typedef uint64_t nfds_t;
typedef int64_t off_t;
typedef int32_t pid_t;
typedef int64_t register_t;
typedef uint16_t sa_family_t; /* bsd:uint8_t */
typedef uint32_t socklen_t;
typedef uint32_t speed_t;
typedef uint32_t suseconds_t;
typedef uint64_t useconds_t;   /* uint32_t on xnu */
typedef int64_t syscall_arg_t; /* uint64_t on xnu */
typedef uint32_t tcflag_t;
typedef int64_t time_t;
typedef void *timer_t;
typedef uint32_t uid_t;
typedef uint64_t rlim_t; /* int64_t on bsd */
typedef int32_t clockid_t;

#ifdef __x86_64__
typedef int64_t blksize_t; /* int32_t on xnu */
typedef uint64_t nlink_t;
#elif defined(__aarch64__)
typedef int32_t blksize_t;
typedef uint32_t nlink_t; /* uint16_t on xnu */
#endif

#define TIME_T_MAX __INT64_MAX__
#define TIME_T_MIN (-TIME_T_MAX - 1)

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define F_GETLK64         F_GETLK
#define F_SETLK64         F_SETLK
#define F_SETLKW64        F_SETLKW
#define RLIM64_INFINITY   RLIM_INFINITY
#define RLIM64_SAVED_CUR  RLIM_SAVED_CUR
#define RLIM64_SAVED_MAX  RLIM_SAVED_MAX
#define alphasort64       alphasort
#define blkcnt64_t        blkcnt_t
#define dirent64          dirent
#define flock64           flock
#define fsfilcnt64_t      fsfilcnt_t
#define fstat64           fstat
#define fstatat64         fstatat
#define fstatfs64         fstatfs
#define fstatvfs64        fstatvfs
#define getrlimit64       getrlimit
#define ino64_t           ino_t
#define lockf64           lockf
#define lstat64           lstat
#define mmap64            mmap
#define off64_t           off_t
#define open64            open
#define openat64          openat
#define posix_fadvise64   posix_fadvise
#define posix_fallocate64 posix_fallocate
#define readdir64         readdir
#define readdir64_r       readdir_r
#define rlim64_t          rlim_t
#define rlimit64          rlimit
#define scandir64         scandir
#define sendfile64        sendfile
#define setrlimit64       setrlimit
#define stat64            stat
#define statfs64          statfs
#define statvfs64         statvfs
#define versionsort64     versionsort
#endif



/*!BEGIN libc/elf/def.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DEF_H_

/**
 * @fileoverview Executable and Linkable Format Definitions.
 */

#define EI_NIDENT 16

#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3

#define ELFMAG  "\177ELF"
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define SELFMAG 4

#define EI_CLASS     4
#define ELFCLASSNONE 0
#define ELFCLASS32   1
#define ELFCLASS64   2
#define ELFCLASSNUM  3

#define EI_DATA     5
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define ELFDATANUM  3

#define EI_VERSION 6

#define EI_OSABI            7
#define ELFOSABI_NONE       0
#define ELFOSABI_SYSV       0
#define ELFOSABI_HPUX       1
#define ELFOSABI_NETBSD     2
#define ELFOSABI_LINUX      3
#define ELFOSABI_GNU        3
#define ELFOSABI_SOLARIS    6
#define ELFOSABI_AIX        7
#define ELFOSABI_IRIX       8
#define ELFOSABI_FREEBSD    9
#define ELFOSABI_TRU64      10
#define ELFOSABI_MODESTO    11
#define ELFOSABI_OPENBSD    12
#define ELFOSABI_ARM        97
#define ELFOSABI_STANDALONE 255

#define EI_ABIVERSION 8

#define EI_PAD 9

#define ET_NONE   0
#define ET_REL    1
#define ET_EXEC   2
#define ET_DYN    3
#define ET_CORE   4
#define ET_NUM    5
#define ET_LOOS   0xfe00
#define ET_HIOS   0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff

#define EM_NONE      0
#define EM_M32       1
#define EM_386       3
#define EM_PPC64     21
#define EM_S390      22
#define EM_ARM       40
#define EM_NEXGEN32E 62
#define EM_X86_64    EM_NEXGEN32E
#define EM_IA32E     EM_NEXGEN32E
#define EM_AMD64     EM_NEXGEN32E
#define EM_PDP11     65
#define EM_CRAYNV2   172
#define EM_L10M      180
#define EM_K10M      181
#define EM_AARCH64   183
#define EM_CUDA      190
#define EM_Z80       220
#define EM_RISCV     243
#define EM_BPF       247

/* the ape flag, "lol cat 5" */
#define EF_APE_MODERN      0x101ca75
#define EF_APE_MODERN_MASK 0x1ffffff

#define GRP_COMDAT 1
#define STN_UNDEF  0

#define EV_NONE    0
#define EV_CURRENT 1
#define EV_NUM     2

#define SYMINFO_NONE          0
#define SYMINFO_CURRENT       1
#define SYMINFO_NUM           2
#define SYMINFO_BT_SELF       0xffff
#define SYMINFO_BT_PARENT     0xfffe
#define SYMINFO_BT_LOWRESERVE 0xff00
#define SYMINFO_FLG_DIRECT    0x0001
#define SYMINFO_FLG_PASSTHRU  0x0002
#define SYMINFO_FLG_COPY      0x0004
#define SYMINFO_FLG_LAZYLOAD  0x0008

#define PT_NULL         0
#define PT_LOAD         1
#define PT_DYNAMIC      2
#define PT_INTERP       3
#define PT_NOTE         4
#define PT_SHLIB        5
#define PT_PHDR         6
#define PT_TLS          7
#define PT_NUM          8
#define PT_LOOS         0x60000000
#define PT_GNU_EH_FRAME 0x6474e550
#define PT_GNU_STACK    0x6474e551
#define PT_GNU_RELRO    0x6474e552
#define PT_LOSUNW       0x6ffffffa
#define PT_SUNWBSS      0x6ffffffa
#define PT_SUNWSTACK    0x6ffffffb
#define PT_HISUNW       0x6fffffff
#define PT_HIOS         0x6fffffff
#define PT_LOPROC       0x70000000
#define PT_HIPROC       0x7fffffff

#define PN_XNUM 0xffff

#define PF_X        1
#define PF_W        2
#define PF_R        4
#define PF_MASKOS   0x0ff00000
#define PF_MASKPROC 0xf0000000

#define R_X86_64_NONE            0
#define R_X86_64_64              1
#define R_X86_64_PC32            2
#define R_X86_64_GOT32           3
#define R_X86_64_PLT32           4
#define R_X86_64_COPY            5
#define R_X86_64_GLOB_DAT        6
#define R_X86_64_JUMP_SLOT       7
#define R_X86_64_RELATIVE        8
#define R_X86_64_GOTPCREL        9
#define R_X86_64_32              10
#define R_X86_64_32S             11
#define R_X86_64_16              12
#define R_X86_64_PC16            13
#define R_X86_64_8               14
#define R_X86_64_PC8             15
#define R_X86_64_DTPMOD64        16
#define R_X86_64_DTPOFF64        17
#define R_X86_64_TPOFF64         18
#define R_X86_64_TLSGD           19
#define R_X86_64_TLSLD           20
#define R_X86_64_DTPOFF32        21
#define R_X86_64_GOTTPOFF        22
#define R_X86_64_TPOFF32         23
#define R_X86_64_PC64            24
#define R_X86_64_GOTOFF64        25
#define R_X86_64_GOTPC32         26
#define R_X86_64_GOT64           27
#define R_X86_64_GOTPCREL64      28
#define R_X86_64_GOTPC64         29
#define R_X86_64_GOTPLT64        30
#define R_X86_64_PLTOFF64        31
#define R_X86_64_SIZE32          32
#define R_X86_64_SIZE64          33
#define R_X86_64_GOTPC32_TLSDESC 34
#define R_X86_64_TLSDESC_CALL    35
#define R_X86_64_TLSDESC         36
#define R_X86_64_IRELATIVE       37
#define R_X86_64_RELATIVE64      38
#define R_X86_64_GOTPCRELX       41 /* 6 bytes */
#define R_X86_64_REX_GOTPCRELX   42 /* 7 bytes */
#define R_X86_64_NUM             43

#define R_AARCH64_NONE   0
#define R_AARCH64_ABS64  257
#define R_AARCH64_ABS32  258
#define R_AARCH64_ABS16  259
#define R_AARCH64_PREL64 260
#define R_AARCH64_PREL32 261
#define R_AARCH64_PREL16 262

#define R_PPC_NONE   0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR24 2
#define R_PPC_ADDR16 3
#define R_PPC_REL32  26

#define R_PPC64_NONE   R_PPC_NONE
#define R_PPC64_ADDR32 R_PPC_ADDR32
#define R_PPC64_ADDR24 R_PPC_ADDR24
#define R_PPC64_ADDR16 R_PPC_ADDR16
#define R_PPC64_REL32  R_PPC_REL32

#define R_RISCV_NONE     0
#define R_RISCV_32       1
#define R_RISCV_64       2
#define R_RISCV_RELATIVE 3

#define R_390_NONE 0
#define R_390_8    1
#define R_390_12   2
#define R_390_16   3
#define R_390_32   4
#define R_390_PC32 5

#define STB_LOCAL      0
#define STB_GLOBAL     1
#define STB_WEAK       2
#define STB_NUM        3
#define STB_LOOS       10
#define STB_GNU_UNIQUE 10
#define STB_HIOS       12
#define STB_LOPROC     13
#define STB_HIPROC     15

#define STT_NOTYPE    0
#define STT_OBJECT    1
#define STT_FUNC      2
#define STT_SECTION   3
#define STT_FILE      4
#define STT_COMMON    5
#define STT_TLS       6
#define STT_NUM       7
#define STT_LOOS      10
#define STT_GNU_IFUNC 10
#define STT_HIOS      12
#define STT_LOPROC    13
#define STT_HIPROC    15

#define STV_DEFAULT   0
#define STV_INTERNAL  1
#define STV_HIDDEN    2
#define STV_PROTECTED 3

#define SHN_UNDEF     0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC    0xff00
#define SHN_BEFORE    0xff00
#define SHN_AFTER     0xff01
#define SHN_HIPROC    0xff1f
#define SHN_LOOS      0xff20
#define SHN_HIOS      0xff3f
#define SHN_ABS       0xfff1
#define SHN_COMMON    0xfff2
#define SHN_XINDEX    0xffff
#define SHN_HIRESERVE 0xffff

#define SHF_WRITE            (1 << 0)
#define SHF_ALLOC            (1 << 1)
#define SHF_EXECINSTR        (1 << 2)
#define SHF_MERGE            (1 << 4)
#define SHF_STRINGS          (1 << 5)
#define SHF_INFO_LINK        (1 << 6)
#define SHF_LINK_ORDER       (1 << 7)
#define SHF_OS_NONCONFORMING (1 << 8)
#define SHF_GROUP            (1 << 9)
#define SHF_TLS              (1 << 10)
#define SHF_COMPRESSED       (1 << 11)
#define SHF_MASKOS           0x0ff00000
#define SHF_MASKPROC         0xf0000000
#define SHF_ORDERED          (1 << 30)
#define SHF_EXCLUDE          (1U << 31)

#define ELFCOMPRESS_ZLIB   1
#define ELFCOMPRESS_LOOS   0x60000000
#define ELFCOMPRESS_HIOS   0x6fffffff
#define ELFCOMPRESS_LOPROC 0x70000000
#define ELFCOMPRESS_HIPROC 0x7fffffff

#define SHT_NULL           0
#define SHT_PROGBITS       1
#define SHT_SYMTAB         2
#define SHT_STRTAB         3
#define SHT_RELA           4
#define SHT_HASH           5
#define SHT_DYNAMIC        6
#define SHT_NOTE           7
#define SHT_NOBITS         8
#define SHT_REL            9
#define SHT_SHLIB          10
#define SHT_DYNSYM         11
#define SHT_INIT_ARRAY     14
#define SHT_FINI_ARRAY     15
#define SHT_PREINIT_ARRAY  16
#define SHT_GROUP          17
#define SHT_SYMTAB_SHNDX   18
#define SHT_NUM            19
#define SHT_LOOS           0x60000000
#define SHT_GNU_ATTRIBUTES 0x6ffffff5
#define SHT_GNU_HASH       0x6ffffff6
#define SHT_GNU_LIBLIST    0x6ffffff7
#define SHT_CHECKSUM       0x6ffffff8
#define SHT_LOSUNW         0x6ffffffa
#define SHT_SUNW_move      0x6ffffffa
#define SHT_SUNW_COMDAT    0x6ffffffb
#define SHT_SUNW_syminfo   0x6ffffffc
#define SHT_GNU_verdef     0x6ffffffd
#define SHT_GNU_verneed    0x6ffffffe
#define SHT_GNU_versym     0x6fffffff
#define SHT_HISUNW         0x6fffffff
#define SHT_HIOS           0x6fffffff
#define SHT_LOPROC         0x70000000
#define SHT_HIPROC         0x7fffffff
#define SHT_LOUSER         0x80000000
#define SHT_HIUSER         0x8fffffff

#define DT_NULL               0
#define DT_NEEDED             1
#define DT_PLTRELSZ           2
#define DT_PLTGOT             3
#define DT_HASH               4
#define DT_STRTAB             5
#define DT_SYMTAB             6
#define DT_RELA               7
#define DT_RELASZ             8
#define DT_RELAENT            9
#define DT_STRSZ              10
#define DT_SYMENT             11
#define DT_INIT               12
#define DT_FINI               13
#define DT_SONAME             14
#define DT_RPATH              15
#define DT_SYMBOLIC           16
#define DT_REL                17
#define DT_RELSZ              18
#define DT_RELENT             19
#define DT_PLTREL             20
#define DT_DEBUG              21
#define DT_TEXTREL            22
#define DT_JMPREL             23
#define DT_BIND_NOW           24
#define DT_INIT_ARRAY         25
#define DT_FINI_ARRAY         26
#define DT_INIT_ARRAYSZ       27
#define DT_FINI_ARRAYSZ       28
#define DT_RUNPATH            29
#define DT_FLAGS              30
#define DT_ENCODING           32
#define DT_PREINIT_ARRAY      32
#define DT_PREINIT_ARRAYSZ    33
#define DT_SYMTAB_SHNDX       34
#define DT_NUM                35
#define DT_LOOS               0x6000000d
#define DT_HIOS               0x6ffff000
#define DT_LOPROC             0x70000000
#define DT_HIPROC             0x7fffffff
#define DT_VALRNGLO           0x6ffffd00
#define DT_GNU_PRELINKED      0x6ffffdf5
#define DT_GNU_CONFLICTSZ     0x6ffffdf6
#define DT_GNU_LIBLISTSZ      0x6ffffdf7
#define DT_CHECKSUM           0x6ffffdf8
#define DT_PLTPADSZ           0x6ffffdf9
#define DT_MOVEENT            0x6ffffdfa
#define DT_MOVESZ             0x6ffffdfb
#define DT_FEATURE_1          0x6ffffdfc
#define DT_POSFLAG_1          0x6ffffdfd
#define DT_SYMINSZ            0x6ffffdfe
#define DT_SYMINENT           0x6ffffdff
#define DT_VALRNGHI           0x6ffffdff
#define DT_VALTAGIDX(tag)     (DT_VALRNGHI - (tag))
#define DT_VALNUM             12
#define DT_ADDRRNGLO          0x6ffffe00
#define DT_GNU_HASH           0x6ffffef5
#define DT_TLSDESC_PLT        0x6ffffef6
#define DT_TLSDESC_GOT        0x6ffffef7
#define DT_GNU_CONFLICT       0x6ffffef8
#define DT_GNU_LIBLIST        0x6ffffef9
#define DT_CONFIG             0x6ffffefa
#define DT_DEPAUDIT           0x6ffffefb
#define DT_AUDIT              0x6ffffefc
#define DT_PLTPAD             0x6ffffefd
#define DT_MOVETAB            0x6ffffefe
#define DT_SYMINFO            0x6ffffeff
#define DT_ADDRRNGHI          0x6ffffeff
#define DT_ADDRTAGIDX(tag)    (DT_ADDRRNGHI - (tag))
#define DT_ADDRNUM            11
#define DT_VERSYM             0x6ffffff0
#define DT_RELACOUNT          0x6ffffff9
#define DT_RELCOUNT           0x6ffffffa
#define DT_FLAGS_1            0x6ffffffb
#define DT_VERDEF             0x6ffffffc
#define DT_VERDEFNUM          0x6ffffffd
#define DT_VERNEED            0x6ffffffe
#define DT_VERNEEDNUM         0x6fffffff
#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag))
#define DT_VERSIONTAGNUM      16
#define DT_AUXILIARY          0x7ffffffd
#define DT_FILTER             0x7fffffff
#define DT_EXTRATAGIDX(tag)   ((Elf32_Word) - ((Elf32_Sword)(tag) << 1 >> 1) - 1)
#define DT_EXTRANUM           3

#define VER_NEED_NONE    0
#define VER_NEED_CURRENT 1
#define VER_NEED_NUM     2
#define VER_FLG_WEAK     0x2

#define ELF_NOTE_SOLARIS       "SUNW Solaris"
#define ELF_NOTE_GNU           "GNU"
#define ELF_NOTE_PAGESIZE_HINT 1
#define ELF_NOTE_ABI           NT_GNU_ABI_TAG
#define ELF_NOTE_OS_LINUX      0
#define ELF_NOTE_OS_GNU        1
#define ELF_NOTE_OS_SOLARIS2   2
#define ELF_NOTE_OS_FREEBSD    3

#define NT_GNU_ABI_TAG      1
#define NT_GNU_BUILD_ID     3
#define NT_GNU_GOLD_VERSION 4

#define EF_CPU32 0x00810000

#define DF_ORIGIN       0x00000001
#define DF_SYMBOLIC     0x00000002
#define DF_TEXTREL      0x00000004
#define DF_BIND_NOW     0x00000008
#define DF_STATIC_TLS   0x00000010
#define DF_1_NOW        0x00000001
#define DF_1_GLOBAL     0x00000002
#define DF_1_GROUP      0x00000004
#define DF_1_NODELETE   0x00000008
#define DF_1_LOADFLTR   0x00000010
#define DF_1_INITFIRST  0x00000020
#define DF_1_NOOPEN     0x00000040
#define DF_1_ORIGIN     0x00000080
#define DF_1_DIRECT     0x00000100
#define DF_1_TRANS      0x00000200
#define DF_1_INTERPOSE  0x00000400
#define DF_1_NODEFLIB   0x00000800
#define DF_1_NODUMP     0x00001000
#define DF_1_CONFALT    0x00002000
#define DF_1_ENDFILTEE  0x00004000
#define DF_1_DISPRELDNE 0x00008000
#define DF_1_DISPRELPND 0x00010000
#define DF_1_NODIRECT   0x00020000
#define DF_1_IGNMULDEF  0x00040000
#define DF_1_NOKSYMS    0x00080000
#define DF_1_NOHDR      0x00100000
#define DF_1_EDITED     0x00200000
#define DF_1_NORELOC    0x00400000
#define DF_1_SYMINTPOSE 0x00800000
#define DF_1_GLOBAUDIT  0x01000000
#define DF_1_SINGLETON  0x02000000
#define DF_1_STUB       0x04000000
#define DF_1_PIE        0x08000000
#define DTF_1_PARINIT   0x00000001
#define DTF_1_CONFEXP   0x00000002
#define DF_P1_LAZYLOAD  0x00000001
#define DF_P1_GROUPPERM 0x00000002

#define ELF64_ST_BIND(val)        (((unsigned char)(val)) >> 4)
#define ELF64_ST_TYPE(val)        ((val)&0xf)
#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf))
#define ELF64_ST_VISIBILITY(o)    ((o)&0x03)

#define ELF64_R_SYM(i)          ((i) >> 32)
#define ELF64_R_TYPE(i)         ((i)&0xffffffff)
#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type))

#define ELF64_M_SYM(info)       ((info) >> 8)
#define ELF64_M_SIZE(info)      ((unsigned char)(info))
#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))

#define NT_PRSTATUS         1
#define NT_PRFPREG          2
#define NT_FPREGSET         2
#define NT_PRPSINFO         3
#define NT_PRXREG           4
#define NT_TASKSTRUCT       4
#define NT_PLATFORM         5
#define NT_AUXV             6
#define NT_GWINDOWS         7
#define NT_ASRS             8
#define NT_PSTATUS          10
#define NT_PSINFO           13
#define NT_PRCRED           14
#define NT_UTSNAME          15
#define NT_LWPSTATUS        16
#define NT_LWPSINFO         17
#define NT_PRFPXREG         20
#define NT_SIGINFO          0x53494749
#define NT_FILE             0x46494c45
#define NT_PRXFPREG         0x46e62b7f
#define NT_PPC_VMX          0x100
#define NT_PPC_SPE          0x101
#define NT_PPC_VSX          0x102
#define NT_PPC_TAR          0x103
#define NT_PPC_PPR          0x104
#define NT_PPC_DSCR         0x105
#define NT_PPC_EBB          0x106
#define NT_PPC_PMU          0x107
#define NT_PPC_TM_CGPR      0x108
#define NT_PPC_TM_CFPR      0x109
#define NT_PPC_TM_CVMX      0x10a
#define NT_PPC_TM_CVSX      0x10b
#define NT_PPC_TM_SPR       0x10c
#define NT_PPC_TM_CTAR      0x10d
#define NT_PPC_TM_CPPR      0x10e
#define NT_PPC_TM_CDSCR     0x10f
#define NT_X86_XSTATE       0x202
#define NT_S390_HIGH_GPRS   0x300
#define NT_S390_TIMER       0x301
#define NT_S390_TODCMP      0x302
#define NT_S390_TODPREG     0x303
#define NT_S390_CTRS        0x304
#define NT_S390_PREFIX      0x305
#define NT_S390_LAST_BREAK  0x306
#define NT_S390_SYSTEM_CALL 0x307
#define NT_S390_TDB         0x308
#define NT_S390_VXRS_LOW    0x309
#define NT_S390_VXRS_HIGH   0x30a
#define NT_S390_GS_CB       0x30b
#define NT_S390_GS_BC       0x30c
#define NT_S390_RI_CB       0x30d
#define NT_ARM_VFP          0x400
#define NT_ARM_TLS          0x401
#define NT_ARM_HW_BREAK     0x402
#define NT_ARM_HW_WATCH     0x403
#define NT_ARM_SYSTEM_CALL  0x404
#define NT_ARM_SVE          0x405
#define NT_ARM_PAC_MASK     0x406
#define NT_METAG_CBUF       0x500
#define NT_METAG_RPIPE      0x501
#define NT_METAG_TLS        0x502
#define NT_ARC_V2           0x600
#define NT_VMCOREDD         0x700
#define NT_VERSION          1

#define VER_DEF_NONE      0
#define VER_DEF_CURRENT   1
#define VER_DEF_NUM       2
#define VER_FLG_BASE      0x1
#define VER_FLG_WEAK      0x2
#define VER_NDX_LOCAL     0
#define VER_NDX_GLOBAL    1
#define VER_NDX_LORESERVE 0xff00
#define VER_NDX_ELIMINATE 0xff01

#define LL_NONE           0
#define LL_EXACT_MATCH    (1 << 0)
#define LL_IGNORE_INT_VER (1 << 1)
#define LL_REQUIRE_MINOR  (1 << 2)
#define LL_EXPORTS        (1 << 3)
#define LL_DELAY_LOAD     (1 << 4)
#define LL_DELTA          (1 << 5)

#define R_BPF_NONE   0
#define R_BPF_MAP_FD 1



/*!BEGIN libc/elf/elf.h */

#define COSMOPOLITAN_LIBC_ELF_H_


/*!BEGIN libc/elf/struct/ehdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_EHDR_H_


/*!BEGIN libc/elf/scalar.h */

#define COSMOPOLITAN_LIBC_ELF_SCALAR_H_

#define Elf64_Addr    uint64_t
#define Elf64_Half    uint16_t
#define Elf64_Off     uint64_t
#define Elf64_Section uint16_t
#define Elf64_Sword   int32_t
#define Elf64_Sxword  int64_t
#define Elf64_Versym  Elf64_Half
#define Elf64_Word    uint32_t
#define Elf64_Xword   uint64_t
#define Elf_Symndx    uint32_t


/*
 * ELF header.
 */
typedef struct Elf64_Ehdr {

  /*
   * Leading bytes of ELF header.
   *
   * - `e_ident[0]` is always `127`
   * - `e_ident[1]` is always `'E'`
   * - `e_ident[2]` is always `'L'`
   * - `e_ident[3]` is always `'F'`
   *
   * - `e_ident[EI_CLASS]` is mandatory and should be:
   *
   *   - `ELFCLASSNONE64` if it's an Elf64 image
   *   - `ELFCLASSNONE32` if it's an Elf32 image
   *   - Otherwise we assume it's an Elf64 image
   *
   * - `e_ident[EI_DATA]` is advisory and could be:
   *
   *   - `ELFDATANONE` isn't strictly valid
   *   - `ELFDATA2LSB` for little-endian
   *   - `ELFDATA2MSB` for big-endian
   *
   * - `e_ident[EI_VERSION]` is advisory and should be:
   *
   *   - `EV_NONE` if it's zero or unspecified
   *   - `EV_CURRENT` for current ELF version (which is 1)
   *
   * - `e_ident[EI_OSABI]` is mandatory and could be:
   *
   *   - `ELFOSABI_NONE` is zero
   *   - `ELFOSABI_GNU` is for GNU
   *   - `ELFOSABI_SYSV` used by GNU
   *   - `ELFOSABI_LINUX` doesn't care
   *   - `ELFOSABI_FREEBSD` does care (recommended)
   *   - `ELFOSABI_NETBSD` doesn't care (see `PT_NOTE`)
   *   - `ELFOSABI_OPENBSD` doesn't care (see `PT_NOTE`)
   *
   * - `e_ident[EI_ABIVERSION]` is advisory
   *
   */
  unsigned char e_ident[16];

  /*
   * ELF image type.
   *
   * This field is mandatory and should be one of:
   *
   * - `ET_REL` for `.o` object files
   * - `ET_DYN` for `.so` files and `-pie` executables
   * - `ET_EXEC` for statically-linked executables
   *
   */
  Elf64_Half e_type;

  /*
   * ELF machine type.
   *
   * This field is mandatory and could be one of:
   *
   * - `EM_M32` for Bellmac
   * - `EM_X86_64` for Amd64
   * - `EM_AARCH64` for Arm64
   * - `EM_PPC64` for Raptors
   * - `EM_RISCV` for Berkeley
   * - `EM_S390` for System/360
   *
   */
  Elf64_Half e_machine;

  /*
   * ELF version.
   *
   * This field is advisory and could be:
   *
   * - `EV_NONE` if it's zero or unspecified
   * - `EV_CURRENT` for current ELF version (which is 1)
   *
   * @see `e_ident[EI_VERSION]`
   */
  Elf64_Word e_version;

  /*
   * ELF executable entrypoint.
   *
   * Static executables should use this field to store the virtual
   * address of the _start() function. This field may be zero, for
   * unspecified.
   */
  Elf64_Addr e_entry;

  /*
   * `Elf64_Phdr` file offset.
   *
   * This field is mandatory. Object files should set it to zero.
   */
  Elf64_Off e_phoff;

  /*
   * `Elf64_Shdr` file offset.
   *
   * This field is advisory.
   */
  Elf64_Off e_shoff;

  /*
   * ELF flags.
   *
   * This field is advisory.
   */
  Elf64_Word e_flags;

  /*
   * `Elf64_Ehdr` size.
   *
   * This field is advisory and should be 64.
   */
  Elf64_Half e_ehsize;

  /*
   * `Elf64_Phdr` element size.
   *
   * This field *is* cared about and should be set to 56. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_phentsize;

  /*
   * `Elf64_Phdr` array count.
   */
  Elf64_Half e_phnum;

  /*
   * `Elf64_Shdr` element size.
   *
   * This field is advisory and should be set to 64. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_shentsize;

  /*
   * `Elf64_Shdr` count.
   *
   * This field is advisory.
   */
  Elf64_Half e_shnum;

  /*
   * Section header index of section name string table.
   */
  Elf64_Half e_shstrndx;

} Elf64_Ehdr;



/*!BEGIN libc/elf/struct/phdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_PHDR_H_

typedef struct Elf64_Phdr {
  Elf64_Word p_type;
  Elf64_Word p_flags;
  Elf64_Off p_offset;
  Elf64_Addr p_vaddr;
  Elf64_Addr p_paddr;
  Elf64_Xword p_filesz;
  Elf64_Xword p_memsz;
  Elf64_Xword p_align;
} Elf64_Phdr;



/*!BEGIN libc/elf/struct/shdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SHDR_H_

/**
 * Section header.
 * @see https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html
 */
typedef struct Elf64_Shdr {

  Elf64_Word sh_name;

  Elf64_Word sh_type; /* SHT_{PROGBITS,NOBITS,STRTAB,SYMTAB,RELA,...} */

  Elf64_Xword sh_flags; /* SHF_{WRITE,ALLOC,EXECINSTR,TLS,MERGE,STRINGS,,...} */

  Elf64_Addr sh_addr;

  Elf64_Off sh_offset;

  Elf64_Xword sh_size;

  /*
   * Index of linked section header.
   *
   * If `sh_type` is `SHT_RELA` then `sh_link` holds the section header
   * index of the associated symbol table.
   *
   * If `sh_type` is `SHT_SYMTAB` then `sh_link` holds the section
   * header index of the associated string table.
   */
  Elf64_Word sh_link;

  /*
   * If `sh_type` is `SHT_RELA` then `sh_info` contains the index of the
   * section to which relocations apply.
   *
   * If `sh_type` is `SHT_SYMTAB` or `SHT_DYNSYM` then `sh_info`
   * contains an index that's one greater than symbol table index of
   * last `STB_LOCAL` symbol.
   */
  Elf64_Word sh_info;

  Elf64_Xword sh_addralign;

  Elf64_Xword sh_entsize;

} Elf64_Shdr;



/*!BEGIN libc/elf/struct/sym.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYM_H_

typedef struct Elf64_Sym {

  /*
   * Symbol name.
   *
   * This value is a byte offset into the `.strtab` section. If this
   * value is zero, then the symbol has no name.
   */
  Elf64_Word st_name;

  /*
   * Symbol type and binding.
   *
   * This value may be created using:
   *
   *     sym.st_info = ELF64_ST_INFO(bind, type);
   *
   * This value may be read using:
   *
   *     int bind = ELF64_ST_BIND(sym.st_info);
   *     int type = ELF64_ST_TYPE(sym.st_info);
   *
   * Where `bind` is typically:
   *
   * - `STB_LOCAL`
   * - `STB_GLOBAL`
   * - `STB_WEAK`
   *
   * Where `type` is typically:
   *
   * - `STT_NOTYPE`
   * - `STT_OBJECT`
   * - `STT_FUNC`
   * - `STT_SECTION`
   * - `STT_FILE`
   * - `STT_COMMON`
   * - `STT_TLS`
   */
  uint8_t st_info;

  /*
   * Symbol visibility.
   *
   * This value should be accessed using:
   *
   *     int visibility = ELF64_ST_VISIBILITY(sym.st_other);
   *
   * Where `visibility` is typically:
   *
   * - `STV_DEFAULT`
   * - `STV_INTERNAL`
   * - `STV_HIDDEN`
   * - `STV_PROTECTED`
   */
  uint8_t st_other;

  /*
   * Symbol section.
   *
   * If `st_shndx` is within `(SHN_UNDEF,SHN_LORESERVE)` then it holds
   * an index into the section header table.
   *
   * Otherwise `st_shndx` is usually one of the following magic numbers:
   *
   * - `SHN_UNDEF` means symbol is undefined
   * - `SHN_ABS` means symbol is a linker integer
   * - `SHN_COMMON` means symbol is defined traditionally
   */
  Elf64_Section st_shndx;

  /*
   * Symbol value.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is `SHN_COMMON`, then
   * `st_value` holds the required symbol alignment, or ≤ 1 if no
   * alignment is required.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is a section index, then
   * `st_value` holds a byte offset into the section memory.
   *
   * If `e_type` isn't `ET_REL` then `st_value` holds a virtual address.
   */
  Elf64_Addr st_value;

  /* byte length optionally set by .size directive */
  Elf64_Xword st_size;

} Elf64_Sym;

#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § executable linkable format                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
/* clang-format off */

bool32 IsElfSymbolContent(const Elf64_Sym *);
bool32 IsElf64Binary(const Elf64_Ehdr *, size_t);
char *GetElfStringTable(const Elf64_Ehdr *, size_t, const char *);
Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
/* clang-format on */


/*!BEGIN libc/elf/link.h */

#define COSMOPOLITAN_ELF_LINK_H_


/*!BEGIN libc/elf/struct/dyn.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DYN_H_

typedef struct Elf64_Dyn {
  Elf64_Sxword d_tag;
  union {
    Elf64_Xword d_val;
    Elf64_Addr d_ptr;
  } d_un;
} Elf64_Dyn;

COSMOPOLITAN_C_START_

#define ElfW(type) Elf64_##type

struct dl_phdr_info {
  Elf64_Addr dlpi_addr;
  const char *dlpi_name;
  const Elf64_Phdr *dlpi_phdr;
  Elf64_Half dlpi_phnum;
  unsigned long long int dlpi_adds;
  unsigned long long int dlpi_subs;
  size_t dlpi_tls_modid;
  void *dlpi_tls_data;
};

struct link_map {
  Elf64_Addr l_addr;
  char *l_name;
  Elf64_Dyn *l_ld;
  struct link_map *l_next;
  struct link_map *l_prev;
};

struct r_debug {
  int r_version;
  struct link_map *r_map;
  Elf64_Addr r_brk;
  enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state;
  Elf64_Addr r_ldbase;
};

int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/elf/struct/auxv.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_AUXV_H_

typedef struct Elf64_auxv_t {
  uint64_t a_type;
  union {
    uint64_t a_val;
  } a_un;
} Elf64_auxv_t;



/*!BEGIN libc/elf/struct/chdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_CHDR_H_

typedef struct Elf64_Chdr {
  Elf64_Word ch_type;
  Elf64_Word ch_reserved;
  Elf64_Xword ch_size;
  Elf64_Xword ch_addralign;
} Elf64_Chdr;



/*!BEGIN libc/elf/struct/lib.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_LIB_H_

typedef struct Elf64_Lib {
  Elf64_Word l_name;
  Elf64_Word l_time_stamp;
  Elf64_Word l_checksum;
  Elf64_Word l_version;
  Elf64_Word l_flags;
} Elf64_Lib;



/*!BEGIN libc/elf/struct/move.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_MOVE_H_

typedef struct Elf64_Move {
  Elf64_Xword m_value;
  Elf64_Xword m_info;
  Elf64_Xword m_poffset;
  Elf64_Half m_repeat;
  Elf64_Half m_stride;
} Elf64_Move;



/*!BEGIN libc/elf/struct/nhdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_NHDR_H_

typedef struct Elf64_Nhdr {
  Elf64_Word n_namesz;
  Elf64_Word n_descsz;
  Elf64_Word n_type;
} Elf64_Nhdr;



/*!BEGIN libc/elf/struct/rel.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_REL_H_

/*
 * ELF relocation.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_REL`.
 *
 * @see Elf64_Rela
 */
typedef struct Elf64_Rel {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` might be:
   *
   * - `R_X86_64_64`
   * - `R_X86_64_PC32`
   * - `R_X86_64_GOTPCRELX`
   * - `R_AARCH64_ABS64`
   *
   * Each relocation type specifies a mathematical formula that's used
   * to compute the appropriate value for the fixed-up object code. If
   * it needs an addend, then this struct doesn't have one, but it can
   * still be embedded by the compiler in the location to be modified.
   */
  Elf64_Xword r_info;

} Elf64_Rel;



/*!BEGIN libc/elf/struct/rela.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_RELA_H_

/*
 * ELF relocation w/ explicit addend.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_RELA`
 *
 * @see Elf64_Rel
 */
typedef struct Elf64_Rela {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` will likely be:
   *
   * - `R_X86_64_PC32`
   * - `R_X86_64_PLT32`
   * - `R_X86_64_32`
   * - `R_X86_64_64`
   * - `R_X86_64_32S`
   * - `R_X86_64_8`
   * - `R_X86_64_16`
   * - `R_X86_64_DTPOFF32`
   * - `R_X86_64_GOTPCREL`
   * - `R_X86_64_PC16`
   * - `R_X86_64_REX_GOTPCRELX`
   * - `R_X86_64_TPOFF32`
   *
   */
  Elf64_Xword r_info;

  /*
   * Relocation parameter.
   *
   * Each relocation type has its own mathematical formula, which should
   * incorporate this value in its own unique way.
   */
  Elf64_Sxword r_addend;

} Elf64_Rela;



/*!BEGIN libc/elf/struct/syminfo.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYMINFO_H_

typedef struct Elf64_Syminfo {
  Elf64_Half si_boundto;
  Elf64_Half si_flags;
} Elf64_Syminfo;



/*!BEGIN libc/elf/struct/verdaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDAUX_H_

typedef struct Elf64_Verdaux {
  Elf64_Word vda_name;
  Elf64_Word vda_next;
} Elf64_Verdaux;



/*!BEGIN libc/elf/struct/verdef.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDEF_H_

typedef struct Elf64_Verdef {
  Elf64_Half vd_version;
  Elf64_Half vd_flags;
  Elf64_Half vd_ndx;
  Elf64_Half vd_cnt;
  Elf64_Word vd_hash;
  Elf64_Word vd_aux;
  Elf64_Word vd_next;
} Elf64_Verdef;



/*!BEGIN libc/elf/struct/vernaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNAUX_H_

typedef struct Elf64_Vernaux {
  Elf64_Word vna_hash;
  Elf64_Half vna_flags;
  Elf64_Half vna_other;
  Elf64_Word vna_name;
  Elf64_Word vna_next;
} Elf64_Vernaux;



/*!BEGIN libc/elf/struct/verneed.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNEED_H_

typedef struct Elf64_Verneed {
  Elf64_Half vn_version;
  Elf64_Half vn_cnt;
  Elf64_Word vn_file;
  Elf64_Word vn_aux;
  Elf64_Word vn_next;
} Elf64_Verneed;



/*!BEGIN libc/fmt/conv.h */

#define COSMOPOLITAN_LIBC_FMT_CONV_H_
COSMOPOLITAN_C_START_

int abs(int) libcesque pureconst;
long labs(long) libcesque pureconst;
long long llabs(long long) libcesque pureconst;
libcesque intmax_t imaxabs(intmax_t) pureconst;
int atoi(const char *) paramsnonnull() libcesque;
long atol(const char *) paramsnonnull() libcesque;
long long atoll(const char *) paramsnonnull() libcesque;
unsigned long strtoul(const char *, char **, int) libcesque paramsnonnull((1));
long long strtoll(const char *, char **, int) libcesque paramsnonnull((1));
unsigned long long strtoull(const char *, char **, int) paramsnonnull((1));
intmax_t strtoimax(const char *, char **, int) libcesque paramsnonnull((1));
uintmax_t strtoumax(const char *, char **, int) libcesque paramsnonnull((1));
intmax_t wcstoimax(const wchar_t *, wchar_t **, int) libcesque;
uintmax_t wcstoumax(const wchar_t *, wchar_t **, int) libcesque;
long wcstol(const wchar_t *, wchar_t **, int) libcesque;
unsigned long wcstoul(const wchar_t *, wchar_t **, int) libcesque;
long strtol(const char *, char **, int) paramsnonnull((1)) libcesque;
long sizetol(const char *, long) paramsnonnull() libcesque;
char *sizefmt(char *, uint64_t, uint64_t) libcesque;
long long wcstoll(const wchar_t *, wchar_t **, int) libcesque;
unsigned long long wcstoull(const wchar_t *, wchar_t **, int) libcesque;
int wcscoll(const wchar_t *, const wchar_t *) libcesque;
size_t wcsxfrm(wchar_t *, const wchar_t *, size_t) libcesque;

double atof(const char *) libcesque;
float strtof(const char *, char **) libcesque;
double strtod(const char *, char **) libcesque;
long double strtold(const char *, char **) libcesque;
float wcstof(const wchar_t *, wchar_t **) libcesque;
double wcstod(const wchar_t *, wchar_t **) libcesque;
long double wcstold(const wchar_t *, wchar_t **) libcesque;

#ifdef _COSMO_SOURCE
char *stripext(char *) libcesque;
char *stripexts(char *) libcesque;
#endif /* _COSMO_SOURCE */

typedef struct {
  int quot;
  int rem;
} div_t;

typedef struct {
  long int quot;
  long int rem;
} ldiv_t;

typedef struct {
  long long int quot;
  long long int rem;
} lldiv_t;

typedef struct {
  intmax_t quot;
  intmax_t rem;
} imaxdiv_t;

libcesque div_t div(int, int) pureconst;
libcesque ldiv_t ldiv(long, long) pureconst;
libcesque lldiv_t lldiv(long long, long long) pureconst;
libcesque imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;

#if __STDC_VERSION__ + 0 >= 199901L
#define div(num, den)   ((div_t){(num) / (den), (num) % (den)})
#define ldiv(num, den)  ((ldiv_t){(num) / (den), (num) % (den)})
#define lldiv(num, den) ((lldiv_t){(num) / (den), (num) % (den)})
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/fmt/itoa.h */

#ifndef COSMOPOLITAN_LIBC_FMT_ITOA_H_
#define COSMOPOLITAN_LIBC_FMT_ITOA_H_
COSMOPOLITAN_C_START_

#define LengthInt64           __LengthInt64
#define LengthUint64          __LengthUint64
#define LengthInt64Thousands  __LengthInt64Thousands
#define LengthUint64Thousands __LengthUint64Thousands
#define FormatInt32           __FormatInt32
#define FormatUint32          __FormatUint32
#define FormatInt64           __FormatInt64
#define FormatUint64          __FormatUint64
#define FormatInt64Thousands  __FormatInt64Thousands
#define FormatUint64Thousands __FormatUint64Thousands
#define FormatOctal32         __FormatOctal32
#define FormatOctal64         __FormatOctal64
#define FormatBinary64        __FormatBinary64
#define FormatHex64           __FormatHex64
#define FormatFlex64          __FormatFlex64
#define uint64toarray_radix16 __uint64toarray_radix16
#define uint64toarray_fixed16 __uint64toarray_fixed16
#define uint64toarray_radix8  __uint64toarray_radix8

libcesque unsigned LengthInt64(int64_t) pureconst;
libcesque unsigned LengthUint64(uint64_t) pureconst;
libcesque unsigned LengthInt64Thousands(int64_t) pureconst;
libcesque unsigned LengthUint64Thousands(uint64_t) pureconst;
libcesque char *FormatInt32(char[hasatleast 12], int32_t);
libcesque char *FormatUint32(char[hasatleast 12], uint32_t);
libcesque char *FormatInt64(char[hasatleast 21], int64_t);
libcesque char *FormatUint64(char[hasatleast 21], uint64_t);
libcesque char *FormatInt64Thousands(char[hasatleast 27], int64_t);
libcesque char *FormatUint64Thousands(char[hasatleast 27], uint64_t);
libcesque char *FormatOctal32(char[hasatleast 13], uint32_t, bool32);
libcesque char *FormatOctal64(char[hasatleast 24], uint64_t, bool32);
libcesque char *FormatBinary64(char[hasatleast 67], uint64_t, char);
libcesque char *FormatHex64(char[hasatleast 19], uint64_t, char);
libcesque char *FormatFlex64(char[hasatleast 24], int64_t, char);
libcesque size_t uint64toarray_radix16(uint64_t, char[hasatleast 17]);
libcesque size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
libcesque size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_ITOA_H_ */


/*!BEGIN libc/fmt/leb128.h */

#ifndef COSMOPOLITAN_LIBC_FMT_LEB128_H_
#define COSMOPOLITAN_LIBC_FMT_LEB128_H_
COSMOPOLITAN_C_START_

#define sleb64   __sleb64
#define zleb64   __zleb64
#define uleb64   __uleb64
#define unzleb64 __unzleb64
#define unuleb64 __unuleb64

char *sleb64(char *, int64_t) libcesque;
char *zleb64(char[hasatleast 10], int64_t) libcesque;
char *uleb64(char[hasatleast 10], uint64_t) libcesque;
int unzleb64(const char *, size_t, int64_t *) libcesque;
int unuleb64(const char *, size_t, uint64_t *) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_LEB128_H_ */


/*!BEGIN libc/fmt/libgen.h */

#define COSMOPOLITAN_LIBC_FMT_LIBGEN_H_
COSMOPOLITAN_C_START_

char *dirname(char *) libcesque;
char *basename(char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/dlopen/dlfcn.h */

#define COSMOPOLITAN_LIBC_DLFCN_H_

#define RTLD_LOCAL  0
#define RTLD_LAZY   1
#define RTLD_NOW    2
#define RTLD_GLOBAL 256

COSMOPOLITAN_C_START_

#define RTLD_NEXT    ((void *)-1)
#define RTLD_DEFAULT ((void *)0)

char *dlerror(void) libcesque;
void *dlopen(const char *, int) libcesque;
void *dlsym(void *, const char *) libcesque;
int dlclose(void *) libcesque;

char *cosmo_dlerror(void) libcesque;
void *cosmo_dlopen(const char *, int) libcesque;
void *cosmo_dlsym(void *, const char *) libcesque;
void *cosmo_dltramp(void *) libcesque;
int cosmo_dlclose(void *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/asancodes.h */

#define COSMOPOLITAN_LIBC_INTRIN_ASANCODES_H_

#define kAsanScale           3
#define kAsanMagic           0x7fff8000
#define kAsanNullPage        -1  /* ∅ 0xff */
#define kAsanProtected       -2  /* P 0xfe */
#define kAsanHeapFree        -3  /* F 0xfd */
#define kAsanHeapRelocated   -4  /* R 0xfc */
#define kAsanAllocaOverrun   -5  /* 𝑂 0xfb */
#define kAsanHeapUnderrun    -6  /* U 0xfa */
#define kAsanHeapOverrun     -7  /* O 0xf9 */
#define kAsanStackUnscoped   -8  /* s 0xf8 */
#define kAsanStackOverflow   -9  /* ! 0xf7 */
#define kAsanGlobalOrder     -10 /* I 0xf6 */
#define kAsanStackFree       -11 /* r 0xf5 */
#define kAsanStackPartial    -12 /* p 0xf4 */
#define kAsanStackOverrun    -13 /* o 0xf3 */
#define kAsanStackMiddle     -14 /* m 0xf2 */
#define kAsanStackUnderrun   -15 /* u 0xf1 */
#define kAsanAllocaUnderrun  -16 /* 𝑈 0xf0 */
#define kAsanUnmapped        -17 /* M 0xef */
#define kAsanGlobalRedzone   -18 /* G 0xee */
#define kAsanGlobalGone      -19 /* 𝐺 0xed */
#define kAsanGlobalUnderrun  -20 /* μ 0xec */
#define kAsanGlobalOverrun   -21 /* Ω 0xeb */
#define kAsanMmapSizeOverrun -22 /* Z 0xea */



/*!BEGIN libc/intrin/asmflag.h */

#define COSMOPOLITAN_LIBC_BITS_ASMFLAG_H_

/*
 * Constraints for virtual machine flags.
 * @note we beseech clang devs for flag constraints
 */
#ifdef __GCC_ASM_FLAG_OUTPUTS__ /* GCC6+ CLANG10+ */
#define CFLAG_CONSTRAINT  "=@ccc"
#define CFLAG_ASM(OP)     OP
#define ZFLAG_CONSTRAINT  "=@ccz"
#define ZFLAG_ASM(OP)     OP
#define OFLAG_CONSTRAINT  "=@cco"
#define OFLAG_ASM(OP)     OP
#define SFLAG_CONSTRAINT  "=@ccs"
#define SFLAG_ASM(SP)     SP
#define ABOVE_CONSTRAINT  "=@cca" /* i.e. !ZF && !CF */
#define ABOVEFLAG_ASM(OP) OP
#else
#define CFLAG_CONSTRAINT  "=q"
#define CFLAG_ASM(OP)     OP "\n\tsetc\t%b0"
#define ZFLAG_CONSTRAINT  "=q"
#define ZFLAG_ASM(OP)     OP "\n\tsetz\t%b0"
#define OFLAG_CONSTRAINT  "=q"
#define OFLAG_ASM(OP)     OP "\n\tseto\t%b0"
#define SFLAG_CONSTRAINT  "=q"
#define SFLAG_ASM(SP)     OP "\n\tsets\t%b0"
#define ABOVE_CONSTRAINT  "=@cca"
#define ABOVEFLAG_ASM(OP) OP "\n\tseta\t%b0"
#endif



/*!BEGIN libc/intrin/atomic.h */

#define COSMOPOLITAN_LIBC_BITS_ATOMIC_H_

/**
 * @fileoverview Cosmopolitan C11 Atomics Library
 *
 * - Forty-two different ways to say MOV.
 * - Fourteen different ways to say XCHG.
 * - Twenty different ways to say LOCK CMPXCHG.
 *
 * @see libc/atomic.h
 */

typedef int memory_order;

enum {
  memory_order_relaxed,
  memory_order_consume,
  memory_order_acquire,
  memory_order_release,
  memory_order_acq_rel,
  memory_order_seq_cst,
};

#define ATOMIC_VAR_INIT(...)     __VA_ARGS__
#define atomic_is_lock_free(obj) ((void)(obj), sizeof(obj) <= sizeof(void *))

#define atomic_flag      atomic_bool
#define ATOMIC_FLAG_INIT ATOMIC_VAR_INIT(0)
#define atomic_flag_test_and_set_explicit(x, order) \
  atomic_exchange_explicit(x, 1, order)
#define atomic_flag_clear_explicit(x, order) atomic_store_explicit(x, 0, order)

#define atomic_compare_exchange_strong(pObject, pExpected, desired) \
  atomic_compare_exchange_strong_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_compare_exchange_weak(pObject, pExpected, desired) \
  atomic_compare_exchange_weak_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_exchange(pObject, desired) \
  atomic_exchange_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_fetch_add(pObject, operand) \
  atomic_fetch_add_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_and(pObject, operand) \
  atomic_fetch_and_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_or(pObject, operand) \
  atomic_fetch_or_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_sub(pObject, operand) \
  atomic_fetch_sub_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_xor(pObject, operand) \
  atomic_fetch_xor_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_load(pObject) atomic_load_explicit(pObject, memory_order_seq_cst)
#define atomic_store(pObject, desired) \
  atomic_store_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_flag_test_and_set(x) \
  atomic_flag_test_and_set_explicit(x, memory_order_seq_cst)
#define atomic_flag_clear(x) atomic_flag_clear_explicit(x, memory_order_seq_cst)

#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)

#define atomic_init(obj, value)    __c11_atomic_init(obj, value)
#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
#define atomic_signal_fence(order) __c11_atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(object, expected, desired, \
                                                success, failure)          \
  __c11_atomic_compare_exchange_strong(object, expected, desired, success, \
                                       failure)
#define atomic_compare_exchange_weak_explicit(object, expected, desired, \
                                              success, failure)          \
  __c11_atomic_compare_exchange_weak(object, expected, desired, success, \
                                     failure)
#define atomic_exchange_explicit(object, desired, order) \
  __c11_atomic_exchange(object, desired, order)
#define atomic_fetch_add_explicit(object, operand, order) \
  __c11_atomic_fetch_add(object, operand, order)
#define atomic_fetch_and_explicit(object, operand, order) \
  __c11_atomic_fetch_and(object, operand, order)
#define atomic_fetch_or_explicit(object, operand, order) \
  __c11_atomic_fetch_or(object, operand, order)
#define atomic_fetch_sub_explicit(object, operand, order) \
  __c11_atomic_fetch_sub(object, operand, order)
#define atomic_fetch_xor_explicit(object, operand, order) \
  __c11_atomic_fetch_xor(object, operand, order)
#define atomic_load_explicit(object, order) __c11_atomic_load(object, order)
#define atomic_store_explicit(object, desired, order) \
  __c11_atomic_store(object, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __atomic_thread_fence(order)
#define atomic_signal_fence(order) __atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(pObject, pExpected, desired, \
                                                success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 0, success, failure)
#define atomic_compare_exchange_weak_explicit(pObject, pExpected, desired, \
                                              success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 1, success, failure)
#define atomic_exchange_explicit(pObject, desired, order) \
  __atomic_exchange_n(pObject, desired, order)
#define atomic_fetch_add_explicit(pObject, operand, order) \
  __atomic_fetch_add(pObject, operand, order)
#define atomic_fetch_and_explicit(pObject, operand, order) \
  __atomic_fetch_and(pObject, operand, order)
#define atomic_fetch_or_explicit(pObject, operand, order) \
  __atomic_fetch_or(pObject, operand, order)
#define atomic_fetch_sub_explicit(pObject, operand, order) \
  __atomic_fetch_sub(pObject, operand, order)
#define atomic_fetch_xor_explicit(pObject, operand, order) \
  __atomic_fetch_xor(pObject, operand, order)
#define atomic_load_explicit(pObject, order) __atomic_load_n(pObject, order)
#define atomic_store_explicit(pObject, desired, order) \
  __atomic_store_n(pObject, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __sync_synchronize()
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define __atomic_apply_stride(object, operand) \
  (((__typeof__(*(object)))0) + (operand))
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    __typeof__(expected) __ep = (expected);                                   \
    __typeof__(*__ep) __e = *__ep;                                            \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    (*__ep = __sync_val_compare_and_swap(object, __e, desired)) == __e;       \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#if __has_builtin(__sync_swap)
#define atomic_exchange_explicit(object, desired, order) \
  ((void)(order), __sync_swap(object, desired))
#else
#define atomic_exchange_explicit(object, desired, order) \
  __extension__({                                        \
    __typeof__(object) __o = (object);                   \
    __typeof__(desired) __d = (desired);                 \
    (void)(order);                                       \
    __sync_synchronize();                                \
    __sync_lock_test_and_set(__o, __d);                  \
  })
#endif
#define atomic_fetch_add_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_add(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_and_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_and(object, operand))
#define atomic_fetch_or_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_or(object, operand))
#define atomic_fetch_sub_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_sub(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_xor_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_xor(object, operand))
#define atomic_load_explicit(object, order) \
  ((void)(order), __sync_fetch_and_add(object, 0))
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#elif defined(__GNUC__) && defined(__x86__) /* x86 with gcc 4.0 and earlier */

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __asm__ volatile("mfence" ::: "memory")
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    char DidIt;                                                               \
    __typeof__(object) IfThing = (object);                                    \
    __typeof__(IfThing) IsEqualToMe = (expected);                             \
    __typeof__(*IfThing) ReplaceItWithMe = (desired), ax;                     \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    __asm__ volatile("lock cmpxchg\t%3,(%1)\n\t"                              \
                     "setz\t%b0"                                              \
                     : "=q"(DidIt), "=r"(IfThing), "+a"(ax)                   \
                     : "r"(ReplaceItWithMe), "2"(*IsEqualToMe)                \
                     : "memory", "cc");                                       \
    *IsEqualToMe = ax;                                                        \
    DidIt;                                                                    \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#define atomic_exchange_explicit(object, desired, order)                \
  __extension__({                                                       \
    __typeof__(object) __o = (object);                                  \
    __typeof__(*__o) __d = (desired);                                   \
    (void)(order);                                                      \
    __asm__ volatile("xchg\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                \
  })
#define atomic_fetch_add_explicit(object, operand, order)                    \
  __extension__({                                                            \
    __typeof__(object) __o = (object);                                       \
    __typeof__(*__o) __d = (desired);                                        \
    (void)(order);                                                           \
    __asm__ volatile("lock xadd\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                     \
  })
#define atomic_fetch_sub_explicit(object, operand, order) \
  atomic_fetch_add_explicit(object, -(operand), order)
#define atomic_load_explicit(object, order) \
  atomic_fetch_add_explicit(object, 0, order)
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#else /* non-gcc or old gcc w/o x86 */
#error "atomic operations not supported with this compiler and/or architecture"
#endif



/*!BEGIN libc/intrin/bsf.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
COSMOPOLITAN_C_START_

libcesque int bsf(int) pureconst;
libcesque int bsfl(long) pureconst;
libcesque int bsfll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsf(x)   __builtin_ctz(x)
#define bsfl(x)  __builtin_ctzl(x)
#define bsfll(x) __builtin_ctzll(x)
#endif

/* deprecated */
#define _bsf(x)   bsf(x)
#define _bsfl(x)  bsfl(x)
#define _bsfll(x) bsfll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */


/*!BEGIN libc/intrin/bsr.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
COSMOPOLITAN_C_START_

libcesque int bsr(int) pureconst;
libcesque int bsrl(long) pureconst;
libcesque int bsrll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsr(x)   (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
#define bsrl(x)  (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
#define bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
#endif

/* deprecated */
#define _bsr(x)   bsr(x)
#define _bsrl(x)  bsrl(x)
#define _bsrll(x) bsrll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */


/*!BEGIN libc/intrin/bswap.h */

#define COSMOPOLITAN_LIBC_BITS_BSWAP_H_
COSMOPOLITAN_C_START_

libcesque uint16_t bswap_16(uint16_t) pureconst;
libcesque uint32_t bswap_32(uint32_t) pureconst;
libcesque uint64_t bswap_64(uint64_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bswap_16(x) __builtin_bswap16(x)
#define bswap_32(x) __builtin_bswap32(x)
#define bswap_64(x) __builtin_bswap64(x)
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/cmpxchg.h */

#define COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
COSMOPOLITAN_C_START_

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME)                       \
  ({                                                                          \
    bool32 DidIt;                                                             \
    autotype(IFTHING) IfThing = (IFTHING);                                    \
    typeof(*IfThing) IsEqualToMe = (ISEQUALTOME);                             \
    typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME);                     \
    asm volatile(ZFLAG_ASM("cmpxchg\t%3,%1")                                  \
                 : ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
                 : "r"(ReplaceItWithMe)                                       \
                 : "cc");                                                     \
    DidIt;                                                                    \
  })
#else
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
  (*(IFTHING) == (ISEQUALTOME) ? (*(IFTHING) = (REPLACEITWITHME), 1) : 0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/dll.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define dll_make_first   __dll_make_first
#define dll_make_last    __dll_make_last
#define dll_remove       __dll_remove
#define dll_splice_after __dll_splice_after
COSMOPOLITAN_C_START_

#define DLL_CONTAINER(t, f, p) ((t *)(((char *)(p)) - offsetof(t, f)))

struct Dll {
  struct Dll *next;
  struct Dll *prev;
};

static inline void dll_init(struct Dll *e) {
  e->next = e;
  e->prev = e;
}

static inline int dll_is_alone(struct Dll *e) {
  return e->next == e && e->prev == e;
}

static inline int dll_is_empty(struct Dll *list) {
  return !list;
}

static inline struct Dll *dll_last(struct Dll *list) {
  return list;
}

static inline struct Dll *dll_first(struct Dll *list) {
  struct Dll *first = 0;
  if (list) first = list->next;
  return first;
}

static inline struct Dll *dll_next(struct Dll *list, struct Dll *e) {
  struct Dll *next = 0;
  if (e != list) next = e->next;
  return next;
}

static inline struct Dll *dll_prev(struct Dll *list, struct Dll *e) {
  struct Dll *prev = 0;
  if (e != list->next) prev = e->prev;
  return prev;
}

void dll_remove(struct Dll **, struct Dll *) paramsnonnull() libcesque;
void dll_make_last(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_make_first(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */


/*!BEGIN libc/intrin/hilbert.h */

#define COSMOPOLITAN_LIBC_BITS_HILBERT_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#define hilbert   __hilbert
#define unhilbert __unhilbert

libcesque long hilbert(long, long, long) pureconst;
libcesque axdx_t unhilbert(long, long) pureconst;

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/kprintf.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
#define COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_

#define klog         __klog
#define kprintf      __kprintf
#define ksnprintf    __ksnprintf
#define kvprintf     __kvprintf
#define kvsnprintf   __kvsnprintf
#define kloghandle   __kloghandle
#define kisdangerous __kisdangerous
#define uprintf      __uprintf
#define uvprintf     __uvprintf

#if !(__ASSEMBLER__ + __LINKER__ + 0)

COSMOPOLITAN_C_START_

void kprintf(const char *, ...) libcesque;
size_t ksnprintf(char *, size_t, const char *, ...) libcesque;
void kvprintf(const char *, va_list) libcesque;
size_t kvsnprintf(char *, size_t, const char *, va_list) libcesque;

bool32 kisdangerous(const void *) libcesque;

void klog(const char *, size_t) libcesque;
void _klog_serial(const char *, size_t) libcesque;
long kloghandle(void) libcesque;

void uprintf(const char *, ...) libcesque;
void uvprintf(const char *, va_list) libcesque;

#ifndef TINY
#define KINFOF(FMT, ...)                                         \
  do {                                                           \
    uprintf("\r\e[35m%s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                      \
  } while (0)
#define KWARNF(FMT, ...)                                                  \
  do {                                                                    \
    uprintf("\r\e[94;49mwarn: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                               \
  } while (0)
#else
#define KINFOF(FMT, ...) ((void)0)
#define KWARNF(FMT, ...) ((void)0)
#endif
#define KDIEF(FMT, ...)                                                     \
  do {                                                                      \
    kprintf("\r\e[30;101mfatal: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                                 \
    for (;;) asm volatile("cli\n\thlt");                                    \
  } while (0)

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_ */


/*!BEGIN libc/intrin/likely.h */

#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
#ifdef _COSMO_SOURCE

#define LIKELY(x)   __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_LIKELY(x) __builtin_expect_with_probability(!!(x), 1, 0.999)
#else
#define VERY_LIKELY(x) LIKELY(x)
#endif

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_UNLIKELY(x) __builtin_expect_with_probability(!!(x), 0, 0.999)
#else
#define VERY_UNLIKELY(x) UNLIKELY(x)
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/macros.h */

#define COSMOPOLITAN_LIBC_INTRIN_MACROS_H_


/*!BEGIN libc/nexgen32e/x86feature.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86FEATURE_H_
#ifdef __x86_64__


/*!BEGIN libc/nexgen32e/kcpuids.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_KCPUIDS_H_

#define KCPUIDS_0H        0
#define KCPUIDS_1H        1
#define KCPUIDS_2H        2
#define KCPUIDS_7H        3
#define KCPUIDS_80000001H 4
#define KCPUIDS_80000007H 5
#define KCPUIDS_16H       6
#define KCPUIDS_7H_1H     7
#define KCPUIDS_LEN       8
#define KCPUIDS_6H        -1 /* TBD: Thermal and Power Management */
#define KCPUIDS_DH        -1 /* TBD: Extended state features */
#define KCPUIDS_80000008H -1 /* TBD: AMD Miscellaneous */
#define KCPUIDS_8000000AH -1 /* TBD: AMD SVM */

#define KCPUIDS_EAX 0
#define KCPUIDS_EBX 1
#define KCPUIDS_ECX 2
#define KCPUIDS_EDX 3

#define KCPUIDS(LEAF, REG) _KCPUIDS(LEAF, REG)
#ifdef __ASSEMBLER__
#define _KCPUIDS(LEAF, REG) KCPUIDS_##LEAF * 16 + KCPUIDS_##REG * 4
#else
#define _KCPUIDS(LEAF, REG) kCpuids[KCPUIDS_##LEAF][KCPUIDS_##REG]
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const unsigned kCpuids[KCPUIDS_LEN][4];

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nexgen32e/x86compiler.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86COMPILER_H_
#ifdef __x86_64__

/**
 * @fileoverview x86 cpu feature compile-time requirement detection.
 * @see -march=native, -mavx2, etc.
 */

#ifdef __AES__
#define _X86_CC_AES 1
#else
#define _X86_CC_AES 0
#endif

#ifdef __AVX__
#define _X86_CC_AVX 1
#else
#define _X86_CC_AVX 0
#endif

#ifdef __AVX2__
#define _X86_CC_AVX2 1
#else
#define _X86_CC_AVX2 0
#endif

#ifdef __F16C__
#define _X86_CC_F16C 1
#else
#define _X86_CC_F16C 0
#endif

#ifdef __AVXVNNI__
#define _X86_CC_AVXVNNI 1
#else
#define _X86_CC_AVXVNNI 0
#endif

#ifdef __AVXVNNIINT8__
#define _X86_CC_AVXVNNIINT8 1
#else
#define _X86_CC_AVXVNNIINT8 0
#endif

#ifdef __AVXVNNIINT16__
#define _X86_CC_AVXVNNIINT16 1
#else
#define _X86_CC_AVXVNNIINT16 0
#endif

#ifdef __AVX512F__
#define _X86_CC_AVX512F 1
#else
#define _X86_CC_AVX512F 0
#endif

#ifdef __AVX512BF16__
#define _X86_CC_AVX512BF16 1
#else
#define _X86_CC_AVX512BF16 0
#endif

#ifdef __AVX512FP16__
#define _X86_CC_AVX512FP16 1
#else
#define _X86_CC_AVX512FP16 0
#endif

#ifdef __AVX512VBMI__
#define _X86_CC_AVX512VBMI 1
#else
#define _X86_CC_AVX512VBMI 0
#endif

#ifdef __AVX512VNNI__
#define _X86_CC_AVX512VNNI 1
#else
#define _X86_CC_AVX512VNNI 0
#endif

#ifdef __AVX5124VNNIW__
#define _X86_CC_AVX5124VNNIW 1
#else
#define _X86_CC_AVX5124VNNIW 0
#endif

#ifdef __ABM__
#define _X86_CC_ABM 1
#else
#define _X86_CC_ABM 0
#endif

#ifdef __BMI__
#define _X86_CC_BMI 1
#else
#define _X86_CC_BMI 0
#endif

#ifdef __BMI2__
#define _X86_CC_BMI2 1
#else
#define _X86_CC_BMI2 0
#endif

#ifdef __FMA__
#define _X86_CC_FMA 1
#else
#define _X86_CC_FMA 0
#endif

#ifdef __ADX__
#define _X86_CC_ADX 1
#else
#define _X86_CC_ADX 0
#endif

#ifdef __PCLMUL__
#define _X86_CC_PCLMUL 1
#else
#define _X86_CC_PCLMUL 0
#endif

#ifdef __POPCNT__
#define _X86_CC_POPCNT 1
#else
#define _X86_CC_POPCNT 0
#endif

#ifdef __RDRND__
#define _X86_CC_RDRND 1
#else
#define _X86_CC_RDRND 0
#endif

#ifdef __RDSEED__
#define _X86_CC_RDSEED 1
#else
#define _X86_CC_RDSEED 0
#endif

#ifdef __SHA__
#define _X86_CC_SHA 1
#else
#define _X86_CC_SHA 0
#endif

#ifdef __SSSE3__
#define _X86_CC_SSSE3 1
#else
#define _X86_CC_SSSE3 0
#endif

#ifdef __SSE__
#define _X86_CC_SSE 1
#else
#define _X86_CC_SSE 0
#endif

#ifdef __SSE2__
#define _X86_CC_SSE2 1
#else
#define _X86_CC_SSE2 0
#endif

#ifdef __SSE3__
#define _X86_CC_SSE3 1
#else
#define _X86_CC_SSE3 0
#endif

#ifdef __SSE4_1__
#define _X86_CC_SSE4_1 1
#else
#define _X86_CC_SSE4_1 0
#endif

#ifdef __SSE4_2__
#define _X86_CC_SSE4_2 1
#else
#define _X86_CC_SSE4_2 0
#endif

#ifdef __XSAVE__
#define _X86_CC_XSAVE 1
#else
#define _X86_CC_XSAVE 0
#endif

#ifdef __CLFLUSHOPT__
#define _X86_CC_CLFLUSHOPT 1
#else
#define _X86_CC_CLFLUSHOPT 0
#endif

#ifdef __RDPID__
#define _X86_CC_RDPID 1
#else
#define _X86_CC_RDPID 0
#endif

#endif /* __x86_64__ */

/* Returns true if x86 FEATURE is present.
   This performs a runtime check in normal portable builds.
   It's usually dead code eliminated for -march=native builds. */
#define X86_HAVE(FEATURE) _X86_HAVE(X86_##FEATURE)

/* Returns true if x86 FEATURE is present.
   This will *always* perform a runtime check.
   It's useful for checking compile-time cpu features are present. */
#define X86_CHECK(FEATURE) _X86_CHECK(X86_##FEATURE)

/* Returns true if x86 FEATURE is mandatory at build time.
   This will never perform runtime checks; it's always constant. */
#define X86_NEED(FEATURE) _X86_NEED(X86_##FEATURE)

/* clang-format off */
/*      --- FEATURE              LEAF       REG BIT  COMPILE-TIME-DEFINE */
#define X86_ACC                  1H,        EDX, 29, 0
#define X86_ACPI                 1H,        EDX, 22, 0
#define X86_ADX                  7H,        EBX, 19, _X86_CC_ADX              /* broadwell c. 2014 */
#define X86_AES                  1H,        ECX, 25, _X86_CC_AES              /* westmere c. 2010 */
#define X86_APIC                 1H,        EDX,  9, 0
#define X86_ARCH_CAPABILITIES    7H,        EDX, 29, 0
#define X86_AVX                  1H,        ECX, 28, _X86_CC_AVX              /* sandybridge c. 2012 */
#define X86_AVX2                 7H,        EBX,  5, _X86_CC_AVX2             /* haswell c. 2013 */
#define X86_AVXVNNI              7H_1H,     EAX,  4, _X86_CC_AVXVNNI
#define X86_AVXVNNIINT8          7H_1H,     EDX,  4, _X86_CC_AVXVNNIINT8
#define X86_AVXVNNIINT16         7H_1H,     EDX, 10, _X86_CC_AVXVNNIINT16
#define X86_AVX512BW             7H,        EBX, 30, 0
#define X86_AVX512CD             7H,        EBX, 28, 0
#define X86_AVX512DQ             7H,        EBX, 17, 0
#define X86_AVX512ER             7H,        EBX, 27, 0
#define X86_AVX512F              7H,        EBX, 16, _X86_CC_AVX512F
#define X86_AVX512IFMA           7H,        EBX, 21, 0
#define X86_AVX512PF             7H,        EBX, 26, 0
#define X86_AVX512VBMI           7H,        ECX,  1, _X86_CC_AVX512VBMI
#define X86_AVX512VL             7H,        EBX, 31, 0
#define X86_AVX512_4FMAPS        7H,        EDX,  3, 0
#define X86_AVX512_4VNNIW        7H,        EDX,  2, _X86_CC_AVX5124VNNIW
#define X86_AVX512_FP16          7H,        EDX, 23, _X86_CC_AVX512FP16
#define X86_AVX512_BF16          7H_1H,     EAX,  5, _X86_CC_AVX512BF16
#define X86_AVX512_BITALG        7H,        ECX, 12, 0
#define X86_AVX512_VBMI2         7H,        ECX,  6, 0
#define X86_AVX512_VNNI          7H,        ECX, 11, _X86_CC_AVX512VNNI
#define X86_AVX512_VP2INTERSECT  7H,        EDX,  8, 0
#define X86_AVX512_VPOPCNTDQ     7H,        ECX, 14, 0
#define X86_BMI                  7H,        EBX,  3, _X86_CC_BMI              /* haswell c. 2013 */
#define X86_BMI2                 7H,        EBX,  8, _X86_CC_BMI2             /* haswell c. 2013 */
#define X86_CID                  1H,        ECX, 10, 0
#define X86_CLDEMOTE             7H,        ECX, 25, 0
#define X86_CLFLUSH              1H,        EDX, 19, _X86_CC_SSE2
#define X86_CLFLUSHOPT           7H,        EBX, 23, _X86_CC_CLFLUSHOPT       /* skylake/zen  */
#define X86_CLWB                 7H,        EBX, 24, 0                        /* skylake/zen2 */
#define X86_CMOV                 1H,        EDX, 15, 0
#define X86_CQM                  7H,        EBX, 12, 0
#define X86_CX16                 1H,        ECX, 13, 0
#define X86_CX8                  1H,        EDX,  8, 0
#define X86_DCA                  1H,        ECX, 18, 0
#define X86_DE                   1H,        EDX,  2, 0
#define X86_DS                   1H,        EDX, 21, 0
#define X86_DSCPL                1H,        ECX,  4, 0
#define X86_DTES64               1H,        ECX,  2, 0
#define X86_ERMS                 7H,        EBX,  9, 0                        /* broaadwell c. 2014 */
#define X86_EST                  1H,        ECX,  7, 0
#define X86_F16C                 1H,        ECX, 29, _X86_CC_F16C
#define X86_FDP_EXCPTN_ONLY      7H,        EBX,  6, 0
#define X86_FLUSH_L1D            7H,        EDX, 28, 0
#define X86_FMA                  1H,        ECX, 12, _X86_CC_FMA              /* haswell c. 2013 */
#define X86_FPU                  1H,        EDX,  0, 0
#define X86_FSGSBASE             7H,        EBX,  0, 0
#define X86_FXSR                 1H,        EDX, 24, 0
#define X86_GBPAGES              80000001H, EDX, 26, 0
#define X86_GFNI                 7H,        ECX,  8, 0
#define X86_HLE                  7H,        EBX,  4, 0
#define X86_HT                   1H,        EDX, 28, 0
#define X86_HYPERVISOR           1H,        ECX, 31, 0
#define X86_IA64                 1H,        EDX, 30, 0
#define X86_INTEL_PT             7H,        EBX, 25, 0
#define X86_INTEL_STIBP          7H,        EDX, 27, 0
#define X86_INVPCID              1H,        EBX, 10, 0
#define X86_INVTSC               80000007H, EDX,  8, _X86_CC_POPCNT           /* i.e. not a K8 */
#define X86_LA57                 7H,        ECX, 16, 0
#define X86_LAHF_LM              80000001H, ECX,  0, 0
#define X86_LM                   80000001H, EDX, 29, 0
#define X86_MCA                  1H,        EDX, 14, 0
#define X86_MCE                  1H,        EDX,  7, 0
#define X86_MD_CLEAR             7H,        EDX, 10, 0
#define X86_MMX                  1H,        EDX, 23, 0
#define X86_MOVBE                1H,        ECX, 22, 0
#define X86_MOVDIR64B            7H,        ECX, 28, 0
#define X86_MOVDIRI              7H,        ECX, 27, 0
#define X86_MP                   80000001H, EDX, 19, 0
#define X86_MPX                  7H,        EBX, 14, 0
#define X86_MSR                  1H,        EDX,  5, 0
#define X86_MTRR                 1H,        EDX, 12, 0
#define X86_MWAIT                1H,        ECX,  3, 0
#define X86_NX                   80000001H, EDX, 20, 0
#define X86_OSPKE                7H,        ECX,  4, 0
#define X86_OSXSAVE              1H,        ECX, 27, 0
#define X86_PAE                  1H,        EDX,  6, 0
#define X86_PAT                  1H,        EDX, 16, 0
#define X86_PBE                  1H,        EDX, 31, 0
#define X86_PCID                 1H,        ECX, 17, 0
#define X86_PCLMUL               1H,        ECX,  1, _X86_CC_PCLMUL           /* westmere c. 2010 */
#define X86_PCONFIG              7H,        EDX, 18, 0
#define X86_PDCM                 1H,        ECX, 15, 0
#define X86_PGE                  1H,        EDX, 13, 0
#define X86_PKU                  7H,        ECX,  3, 0
#define X86_PN                   1H,        EDX, 18, 0
#define X86_POPCNT               1H,        ECX, 23, _X86_CC_POPCNT           /* nehalem c. 2008 */
#define X86_PSE                  1H,        EDX,  3, 0
#define X86_PSE36                1H,        EDX, 17, 0
#define X86_RDPID                7H,        ECX, 22, _X86_CC_RDPID            /* cannonlake c. 2018 */
#define X86_RDRND                1H,        ECX, 30, _X86_CC_RDRND            /* ivybridge c. 2012 */
#define X86_RDSEED               7H,        EBX, 18, _X86_CC_RDSEED           /* broadwell c. 2014 */
#define X86_RDTSCP               80000001H, EDX, 27, 0
#define X86_RDT_A                7H,        EBX, 15, 0
#define X86_RTM                  7H,        EBX, 11, 0
#define X86_SDBG                 1H,        ECX, 11, 0
#define X86_SELFSNOOP            1H,        EDX, 27, 0
#define X86_SEP                  1H,        EDX, 11, 0
#define X86_SHA                  7H,        EBX, 29, _X86_CC_SHA              /* goldmont (2016) */
#define X86_SMAP                 7H,        EBX, 20, 0
#define X86_SMEP                 7H,        EBX,  7, 0
#define X86_SMX                  1H,        ECX,  6, 0
#define X86_SPEC_CTRL            7H,        EDX, 26, 0
#define X86_SPEC_CTRL_SSBD       7H,        EDX, 31, 0
#define X86_SSE                  1H,        EDX, 25, _X86_CC_SSE              /* pentium c. 1999 */
#define X86_SSE2                 1H,        EDX, 26, _X86_CC_SSE2             /* pentium c. 2001 */
#define X86_SSE3                 1H,        ECX,  0, _X86_CC_SSE3             /* k8 c. 2005 */
#define X86_SSE4_1               1H,        ECX, 19, _X86_CC_SSE4_1           /* core c. 2006 */
#define X86_SSE4_2               1H,        ECX, 20, _X86_CC_SSE4_2           /* nehalem c. 2008 */
#define X86_SSSE3                1H,        ECX,  9, _X86_CC_SSSE3            /* westmere c. 2010 */
#define X86_SYSCALL              80000001H, EDX, 11, 0
#define X86_TM2                  1H,        ECX,  8, 0
#define X86_TME                  7H,        ECX, 13, 0
#define X86_TSC                  1H,        EDX,  4, 0
#define X86_TSC_ADJUST           7H,        EBX,  1, 0
#define X86_TSC_DEADLINE_TIMER   1H,        ECX, 24, 0
#define X86_TSX_FORCE_ABORT      7H,        EDX, 13, 0
#define X86_UMIP                 7H,        ECX,  2, 0
#define X86_VAES                 7H,        ECX,  9, 0
#define X86_VME                  1H,        EDX,  1, 0
#define X86_VMX                  1H,        ECX,  5, 0
#define X86_VPCLMULQDQ           7H,        ECX, 10, 0
#define X86_WAITPKG              7H,        ECX,  5, 0
#define X86_X2APIC               1H,        ECX, 21, 0
#define X86_XSAVE                1H,        ECX, 26, _X86_CC_XSAVE            /* sandybridge c. 2012 */
#define X86_XTPR                 1H,        ECX, 14, 0
#define X86_ZERO_FCS_FDS         7H,        EBX, 13, 0
#define X86_JIT                  80000001H, ECX, 31, 0                        /* IsGenuineBlink() */
#define X86_HYBRID_CPU           7H,        EDX, 15, 0                        /* Has performance and efficiency cores */
/* clang-format on */

/* AMD specific features */
#define X86_ABM            80000001H, ECX, 5, _X86_CC_ABM
#define X86_3DNOW          80000001H, EDX, 31, 0
#define X86_3DNOWEXT       80000001H, EDX, 30, 0
#define X86_3DNOWPREFETCH  80000001H, ECX, 8, 0
#define X86_BPEXT          80000001H, ECX, 26, 0
#define X86_CMP_LEGACY     80000001H, ECX, 1, 0
#define X86_CR8_LEGACY     80000001H, ECX, 4, 0
#define X86_EXTAPIC        80000001H, ECX, 3, 0
#define X86_FMA4           80000001H, ECX, 16, 0
#define X86_FXSR_OPT       80000001H, EDX, 25, 0
#define X86_IBS            80000001H, ECX, 10, 0
#define X86_LWP            80000001H, ECX, 15, 0
#define X86_MISALIGNSSE    80000001H, ECX, 7, 0
#define X86_MMXEXT         80000001H, EDX, 22, 0
#define X86_MWAITX         80000001H, ECX, 29, 0
#define X86_NODEID_MSR     80000001H, ECX, 19, 0
#define X86_OSVW           80000001H, ECX, 9, 0
#define X86_OVERFLOW_RECOV 80000007H, EBX, 0, 0
#define X86_PERFCTR_CORE   80000001H, ECX, 23, 0
#define X86_PERFCTR_LLC    80000001H, ECX, 28, 0
#define X86_PERFCTR_NB     80000001H, ECX, 24, 0
#define X86_PTSC           80000001H, ECX, 27, 0
#define X86_SKINIT         80000001H, ECX, 12, 0
#define X86_SMCA           80000007H, EBX, 3, 0
#define X86_SSE4A          80000001H, ECX, 6, 0
#define X86_SUCCOR         80000007H, EBX, 1, 0
#define X86_SVM            80000001H, ECX, 2, 0
#define X86_TBM            80000001H, ECX, 21, 0
#define X86_TCE            80000001H, ECX, 17, 0
#define X86_TOPOEXT        80000001H, ECX, 22, 0
#define X86_WDT            80000001H, ECX, 13, 0
#define X86_XOP            80000001H, ECX, 11, 0

/* Defined but not loaded by kCpuids.S */
#define X86_ARAT            6H, EAX, 2, 0
#define X86_AVIC            8000000AH, EDX, 13, 0
#define X86_CLZERO          80000008H, EBX, 0, 0
#define X86_DECODEASSISTS   8000000AH, EDX, 7, 0
#define X86_DTHERM          6H, EAX, 0, 0
#define X86_FLUSHBYASID     8000000AH, EDX, 6, 0
#define X86_HWP             6H, EAX, 7, 0
#define X86_HWP_ACT_WINDOW  6H, EAX, 9, 0
#define X86_HWP_EPP         6H, EAX, 10, 0
#define X86_HWP_NOTIFY      6H, EAX, 8, 0
#define X86_HWP_PKG_REQ     6H, EAX, 11, 0
#define X86_IBPB            80000008H, EBX, 12, 0
#define X86_IBRS            80000008H, EBX, 14, 0
#define X86_IDA             6H, EAX, 1, 0
#define X86_IRPERF          80000008H, EBX, 1, 0
#define X86_LBRV            8000000AH, EDX, 1, 0
#define X86_NPT             8000000AH, EDX, 0, 0
#define X86_NRIPS           8000000AH, EDX, 3, 0
#define X86_PAUSEFILTER     8000000AH, EDX, 10, 0
#define X86_PFTHRESHOLD     8000000AH, EDX, 12, 0
#define X86_PLN             6H, EAX, 4, 0
#define X86_PTS             6H, EAX, 6, 0
#define X86_SSBD            80000008H, EBX, 24, 0
#define X86_SSB_NO          80000008H, EBX, 26, 0
#define X86_STIBP           80000008H, EBX, 15, 0
#define X86_STIBP_ALWAYS_ON 80000008H, EBX, 17, 0
#define X86_SVML            8000000AH, EDX, 2, 0
#define X86_TSCRATEMSR      8000000AH, EDX, 4, 0
#define X86_VGIF            8000000AH, EDX, 16, 0
#define X86_VIRT_SSBD       80000008H, EBX, 25, 0
#define X86_VMCBCLEAN       8000000AH, EDX, 5, 0
#define X86_V_VMSAVE_VMLOAD 8000000AH, EDX, 15, 0
#define X86_WBNOINVD        80000008H, EBX, 9, 0
#define X86_XGETBV1         DH, EAX, 2, 0
#define X86_XSAVEC          DH, EAX, 1, 0
#define X86_XSAVEERPTR      80000008H, EBX, 2, 0
#define X86_XSAVEOPT        DH, EAX, 0, 0
#define X86_XSAVES          DH, EAX, 3, 0

#define X86_WORD(FEATURE) _X86_WORD(X86_##FEATURE)
#define X86_LEAF(FEATURE) _X86_LEAF(X86_##FEATURE)
#define X86_REG(FEATURE)  _X86_REG(X86_##FEATURE)
#define X86_BIT(FEATURE)  _X86_BIT(X86_##FEATURE)

#define _X86_CHECK(FEATURE) __X86_CHECK(FEATURE)
#define _X86_HAVE(FEATURE)  __X86_HAVE(FEATURE)
#define _X86_NEED(FEATURE)  __X86_NEED(FEATURE)
#define _X86_WORD(FEATURE)  __X86_WORD(FEATURE)
#define _X86_LEAF(FEATURE)  __X86_LEAF(FEATURE)
#define _X86_REG(FEATURE)   __X86_REG(FEATURE)
#define _X86_BIT(FEATURE)   __X86_BIT(FEATURE)

#define __X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  ___X86_CHECK(LEAF, REG, BIT, MANDATORY)
#define __X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  ___X86_HAVE(LEAF, REG, BIT, MANDATORY)
#define __X86_NEED(LEAF, REG, BIT, MANDATORY) MANDATORY
#define __X86_WORD(LEAF, REG, BIT, MANDATORY) KCPUIDS(LEAF, REG)
#define __X86_LEAF(LEAF, REG, BIT, MANDATORY) LEAF
#define __X86_REG(LEAF, REG, BIT, MANDATORY)  REG
#define __X86_BIT(LEAF, REG, BIT, MANDATORY)  BIT

#define ___X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  !!(KCPUIDS(LEAF, REG) & (1u << BIT))

#ifndef __ASSEMBLER__
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  !!(MANDATORY || KCPUIDS(LEAF, REG) & (1u << BIT))
#else
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  $1 << (BIT % 8), BIT / 8 + KCPUIDS(LEAF, REG)
#endif

#else
#define X86_HAVE(FEATURE)  0
#define X86_NEED(FEATURE)  0
#define X86_CHECK(FEATURE) 0
#endif /* __x86_64__ */

#define INTRIN_COMMUTATIVE "%"
#define INTRIN_NONCOMMUTATIVE

#if defined(__x86_64__) && !defined(__STRICT_ANSI__)

typedef char __intrin_xmm_t
    __attribute__((__vector_size__(16), __aligned__(16), __may_alias__));

#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C)                    \
  do {                                                                         \
    if (X86_HAVE(ISA)) {                                                       \
      __intrin_xmm_t *Xmm0 = (void *)(A);                                      \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);                \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(C);                \
      if (!X86_NEED(AVX)) {                                                    \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm2), "0"(*Xmm1));        \
      } else {                                                                 \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm1), "x"(*Xmm2)); \
      }                                                                        \
    } else {                                                                   \
      PURE(A, B, C);                                                           \
    }                                                                          \
  } while (0)

#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)                 \
  do {                                                               \
    if (X86_HAVE(ISA)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I));     \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)                 \
  do {                                                          \
    if (X86_HAVE(ISA)) {                                        \
      __intrin_xmm_t *Xmm0 = (void *)(A);                       \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B); \
      if (!X86_NEED(AVX)) {                                     \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "0"(*Xmm1));           \
      } else {                                                  \
        asm("v" OP "\t%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1));       \
      }                                                         \
    } else {                                                    \
      PURE(A, B);                                               \
    }                                                           \
  } while (0)

#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)                   \
  do {                                                               \
    if (!IsModeDbg() && X86_HAVE(ISA)) {                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "i"(I), "0"(*Xmm1));        \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#else
#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C) PURE(A, B, C)
#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)        PURE(A, B, I)
#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)          PURE(A, B, I)
#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)             PURE(A, B)
#endif /* X86 && !ANSI */



/*!BEGIN libc/intrin/newbie.h */

#define COSMOPOLITAN_LIBC_BITS_NEWBIE_H_

#define BYTE_ORDER    __BYTE_ORDER__
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define PDP_ENDIAN    __ORDER_PDP_ENDIAN__

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define htobe16(x) bswap_16(x)
#define be16toh(x) bswap_16(x)
#define betoh16(x) bswap_16(x)
#define htobe32(x) bswap_32(x)
#define be32toh(x) bswap_32(x)
#define betoh32(x) bswap_32(x)
#define htobe64(x) bswap_64(x)
#define be64toh(x) bswap_64(x)
#define betoh64(x) bswap_64(x)
#define htole16(x) (uint16_t)(x)
#define le16toh(x) (uint16_t)(x)
#define letoh16(x) (uint16_t)(x)
#define htole32(x) (uint32_t)(x)
#define le32toh(x) (uint32_t)(x)
#define letoh32(x) (uint32_t)(x)
#define htole64(x) (uint64_t)(x)
#define le64toh(x) (uint64_t)(x)
#define letoh64(x) (uint64_t)(x)
#else
#define htobe16(x) (uint16_t)(x)
#define be16toh(x) (uint16_t)(x)
#define betoh16(x) (uint16_t)(x)
#define htobe32(x) (uint32_t)(x)
#define be32toh(x) (uint32_t)(x)
#define betoh32(x) (uint32_t)(x)
#define htobe64(x) (uint64_t)(x)
#define be64toh(x) (uint64_t)(x)
#define betoh64(x) (uint64_t)(x)
#define htole16(x) bswap_16(x)
#define le16toh(x) bswap_16(x)
#define letoh16(x) bswap_16(x)
#define htole32(x) bswap_32(x)
#define le32toh(x) bswap_32(x)
#define letoh32(x) bswap_32(x)
#define htole64(x) bswap_64(x)
#define le64toh(x) bswap_64(x)
#define letoh64(x) bswap_64(x)
#endif



/*!BEGIN libc/intrin/packsswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKSSWB_H_
COSMOPOLITAN_C_START_

void packsswb(int8_t[16], const int16_t[8], const int16_t[8]);

#define packsswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packsswb, SSE2, "packsswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/packuswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKUSWB_H_
COSMOPOLITAN_C_START_

void packuswb(uint8_t[16], const int16_t[8], const int16_t[8]);

#define packuswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packuswb, SSE2, "packuswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/paddw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PADDW_H_
COSMOPOLITAN_C_START_

void paddw(int16_t[8], const int16_t[8], const int16_t[8]);

#define paddw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(paddw, SSE2, "paddw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/palignr.h */

#define COSMOPOLITAN_LIBC_INTRIN_PALIGNR_H_


/*!BEGIN libc/str/str.h */

#define COSMOPOLITAN_LIBC_STR_STR_H_

#define INVALID_CODEPOINT 0xfffd

#define _tolower(u) (0040 | (u))
#define _toupper(u) (0137 & (u))

#ifdef _COSMO_SOURCE
#define chomp         _chomp
#define chomp16       _chomp16
#define wchomp        _wchomp
#define tpenc         _tpenc
#define isutf8        _isutf8
#define istext        _istext
#define startswith    _startswith
#define startswithi   _startswithi
#define endswith      _endswith
#define wcsendswith   _wcsendswith
#define wcsstartswith _wcsstartswith
#endif /* _COSMO_SOURCE */

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

int isascii(int) libcesque;
int isspace(int) libcesque;
int isalpha(int) libcesque;
int isdigit(int) libcesque;
int isalnum(int) libcesque;
int isxdigit(int) libcesque;
int isprint(int) libcesque;
int islower(int) libcesque;
int isupper(int) libcesque;
int isblank(int) libcesque;
int iscntrl(int) libcesque;
int isgraph(int) libcesque;
int tolower(int) libcesque;
int ispunct(int) libcesque;
int toupper(int) libcesque;
int toascii(int) libcesque;

int iswalnum(wint_t) libcesque;
int iswalpha(wint_t) libcesque;
int iswblank(wint_t) libcesque;
int iswcntrl(wint_t) libcesque;
int iswdigit(wint_t) libcesque;
int iswgraph(wint_t) libcesque;
int iswlower(wint_t) libcesque;
int iswspace(wint_t) libcesque;
int iswupper(wint_t) libcesque;
int iswxdigit(wint_t) libcesque;
int iswpunct(wint_t) libcesque;
int iswprint(wint_t) libcesque;
int iswseparator(wint_t) libcesque;
wint_t towlower(wint_t) libcesque;
wint_t towupper(wint_t) libcesque;

void *memset(void *, int, size_t) memcpyesque;
void *memmove(void *, const void *, size_t) memcpyesque;
void *memcpy(void *restrict, const void *restrict, size_t) memcpyesque;
void *mempcpy(void *restrict, const void *restrict, size_t) memcpyesque;
char *hexpcpy(char *restrict, const void *restrict, size_t) memcpyesque;
void *memccpy(void *restrict, const void *restrict, int, size_t) memcpyesque;
void explicit_bzero(void *, size_t);

int memcmp(const void *, const void *, size_t) strlenesque;
int timingsafe_bcmp(const void *, const void *, size_t) libcesque;
int timingsafe_memcmp(const void *, const void *, size_t) libcesque;

size_t strlen(const char *) strlenesque;
size_t strnlen(const char *, size_t) strlenesque;
size_t strnlen_s(const char *, size_t) libcesque;
char *strchr(const char *, int) strlenesque;
void *memchr(const void *, int, size_t) strlenesque;
char *strchrnul(const char *, int) strlenesque returnsnonnull;
void *rawmemchr(const void *, int) strlenesque returnsnonnull;
size_t wcslen(const wchar_t *) strlenesque;
size_t wcsnlen(const wchar_t *, size_t) strlenesque;
size_t wcsnlen_s(const wchar_t *, size_t) libcesque;
wchar_t *wcschr(const wchar_t *, wchar_t) strlenesque;
wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) strlenesque;
wchar_t *wcschrnul(const wchar_t *, wchar_t)
strlenesque returnsnonnull;
char *strstr(const char *, const char *) strlenesque;
char *strcasestr(const char *, const char *) strlenesque;
wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque;
int strcmp(const char *, const char *) strlenesque;
int strncmp(const char *, const char *, size_t) strlenesque;
int wcscmp(const wchar_t *, const wchar_t *) strlenesque;
int wcsncmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int wmemcmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int strcasecmp(const char *, const char *) strlenesque;
int memcasecmp(const void *, const void *, size_t) strlenesque;
int wcscasecmp(const wchar_t *, const wchar_t *) strlenesque;
int strncasecmp(const char *, const char *, size_t) strlenesque;
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
char *strrchr(const char *, int) strlenesque;
void *memrchr(const void *, int, size_t) strlenesque;
wchar_t *wcsrchr(const wchar_t *, wchar_t) strlenesque;
void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque;
char *strpbrk(const char *, const char *) strlenesque;
wchar_t *wcspbrk(const wchar_t *, const wchar_t *) strlenesque;
size_t strspn(const char *, const char *) strlenesque;
size_t wcsspn(const wchar_t *, const wchar_t *) strlenesque;
size_t strcspn(const char *, const char *) strlenesque;
size_t wcscspn(const wchar_t *, const wchar_t *) strlenesque;
void *memfrob(void *, size_t) memcpyesque;
int strcoll(const char *, const char *) strlenesque;
char *strsep(char **, const char *) libcesque paramsnonnull();
char *stpcpy(char *, const char *) memcpyesque;
char *stpncpy(char *, const char *, size_t) memcpyesque;
char *strcat(char *, const char *) memcpyesque;
wchar_t *wcscat(wchar_t *, const wchar_t *) memcpyesque;
size_t strlcpy(char *, const char *, size_t) libcesque;
size_t strlcat(char *, const char *, size_t) libcesque;
size_t strxfrm(char *, const char *, size_t) libcesque;
char *strcpy(char *, const char *) memcpyesque;
wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque;
char *strncat(char *, const char *, size_t) memcpyesque;
wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t) memcpyesque;
char *strncpy(char *, const char *, size_t) memcpyesque;
char *strtok(char *, const char *) paramsnonnull((2)) libcesque;
char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
int strverscmp(const char *, const char *) libcesque;
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
void *memmem(const void *, size_t, const void *, size_t)
libcesque nosideeffect;
ssize_t strfmon(char *, size_t, const char *, ...) libcesque;
long a64l(const char *) libcesque;
char *l64a(long) libcesque;

typedef unsigned mbstate_t;

wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t) libcesque;
int mbtowc(wchar_t *, const char *, size_t) libcesque;
size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *) libcesque;
size_t mbstowcs(wchar_t *, const char *, size_t) libcesque;
size_t wcrtomb(char *, wchar_t, mbstate_t *) libcesque;
size_t c32rtomb(char *, char32_t, mbstate_t *) libcesque;
size_t mbrtoc32(char32_t *, const char *, size_t, mbstate_t *) libcesque;
size_t c16rtomb(char *, char16_t, mbstate_t *) libcesque;
size_t mbrtoc16(char16_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbrlen(const char *, size_t, mbstate_t *) libcesque;
size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *);
size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *);
size_t wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *) libcesque;
size_t wcstombs(char *, const wchar_t *, size_t) libcesque;
int mbsinit(const mbstate_t *) libcesque;
int mblen(const char *, size_t) libcesque;
int wctomb(char *, wchar_t) libcesque;
int wctob(wint_t) libcesque;
wint_t btowc(int) libcesque;

typedef unsigned wctype_t;
wctype_t wctype(const char *) strlenesque;
pureconst int iswctype(wint_t, wctype_t) libcesque;

typedef const int *wctrans_t;
wctrans_t wctrans(const char *) libcesque;
wint_t towctrans(wint_t, wctrans_t) libcesque;

int getsubopt(char **, char *const *, char **) libcesque paramsnonnull();
char *strsignal(int) returnsnonnull libcesque;
char *strerror(int) returnsnonnull dontthrow dontcallback;
errno_t strerror_r(int, char *, size_t) libcesque;
char *__xpg_strerror_r(int, char *, size_t) libcesque;

#ifdef _COSMO_SOURCE
pureconst uint64_t tpenc(uint32_t) libcesque;
char *chomp(char *) libcesque;
wchar_t *wchomp(wchar_t *) libcesque;
uint64_t __fnv(const void *, size_t) strlenesque;
bool32 startswith(const char *, const char *) strlenesque;
bool32 startswithi(const char *, const char *) strlenesque;
bool32 endswith(const char *, const char *) strlenesque;
bool32 istext(const void *, size_t) libcesque;
bool32 isutf8(const void *, size_t) libcesque;
const char *strsignal_r(int, char[21]) returnsnonnull libcesque __wur;
char16_t *chomp16(char16_t *) libcesque;
size_t strlen16(const char16_t *) strlenesque;
size_t strnlen16(const char16_t *, size_t) strlenesque;
char16_t *strchr16(const char16_t *, int) strlenesque;
void *memchr16(const void *, int, size_t) strlenesque;
char16_t *strchrnul16(const char16_t *, int) strlenesque returnsnonnull;
void *rawmemchr16(const void *, int) strlenesque returnsnonnull;
char16_t *strstr16(const char16_t *, const char16_t *) strlenesque;
int strcmp16(const char16_t *, const char16_t *) strlenesque;
int strncmp16(const char16_t *, const char16_t *, size_t) strlenesque;
int strcasecmp16(const char16_t *, const char16_t *) strlenesque;
int strncasecmp16(const char16_t *, const char16_t *, size_t) strlenesque;
char16_t *strrchr16(const char16_t *, int) strlenesque;
void *memrchr16(const void *, int, size_t) strlenesque;
char16_t *strpbrk16(const char16_t *, const char16_t *) strlenesque;
size_t strspn16(const char16_t *, const char16_t *) strlenesque;
size_t strcspn16(const char16_t *, const char16_t *) strlenesque;
char16_t *strcat16(char16_t *, const char16_t *) memcpyesque;
char16_t *strcpy16(char16_t *, const char16_t *) memcpyesque;
char16_t *strncat16(char16_t *, const char16_t *, size_t) memcpyesque;
char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque;
bool32 startswith16(const char16_t *, const char16_t *) strlenesque;
bool32 endswith16(const char16_t *, const char16_t *) strlenesque;
axdx_t tprecode8to16(char16_t *, size_t, const char *) libcesque;
axdx_t tprecode16to8(char *, size_t, const char16_t *) libcesque;
bool32 wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
bool32 wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
char *__join_paths(char *, size_t, const char *, const char *) libcesque __wur;
int __mkntpathat(int, const char *, int, char16_t[hasatleast 1024]);
#endif /* _COSMO_SOURCE */

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_POSIX_SOURCE) ||                                                 \
    (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE + 0 < 200809L) ||            \
    (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE + 0 < 700)
int bcmp(const void *, const void *, size_t) strlenesque;
void bcopy(const void *, void *, size_t) memcpyesque;
void bzero(void *, size_t) memcpyesque;
char *index(const char *, int) strlenesque;
char *rindex(const char *, int) strlenesque;
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

void palignr(void *, const void *, const void *, unsigned long);

#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__)
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
#define palignr(C, B, A, I)                                                \
  do {                                                                     \
    if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSSE3), \
                         1)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(C);                                  \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);            \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(A);            \
      if (__builtin_constant_p(I)) {                                       \
        if (!X86_NEED(AVX)) {                                              \
          asm("palignr\t%2,%1,%0"                                          \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm2), "i"(I), "0"(*Xmm1));                           \
        } else {                                                           \
          asm("vpalignr\t%3,%2,%1,%0"                                      \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm1), "x"(*Xmm2), "i"(I));                           \
        }                                                                  \
      } else {                                                             \
        unsigned long Vimm = (I);                                          \
        typeof(__palignrs) *Fn;                                            \
        if (__builtin_expect(Vimm < 32, 1)) {                              \
          Fn = (typeof(__palignrs) *)((uintptr_t)&__palignrs + Vimm * 8);  \
          *Xmm0 = Fn(*Xmm1, *Xmm2);                                        \
        } else {                                                           \
          memset(Xmm0, 0, 16);                                             \
        }                                                                  \
      }                                                                    \
    } else {                                                               \
      palignr(C, B, A, I);                                                 \
    }                                                                      \
  } while (0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pandn.h */

#define COSMOPOLITAN_LIBC_INTRIN_PANDN_H_
COSMOPOLITAN_C_START_

void pandn(uint64_t[2], const uint64_t[2], const uint64_t[2]);

#define pandn(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pandn, SSE2, "pandn", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTB_H_
COSMOPOLITAN_C_START_

void pcmpgtb(int8_t[16], const int8_t[16], const int8_t[16]);

#define pcmpgtb(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtb, SSE2, "pcmpgtb", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTW_H_
COSMOPOLITAN_C_START_

void pcmpgtw(int16_t[8], const int16_t[8], const int16_t[8]);

#define pcmpgtw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtw, SSE2, "pcmpgtw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmaddubsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMADDUBSW_H_
COSMOPOLITAN_C_START_

void pmaddubsw(int16_t[8], const uint8_t[16], const int8_t[16]);

#define pmaddubsw(W, B, C)                                                   \
  INTRIN_SSEVEX_X_X_X_(pmaddubsw, SSSE3, "pmaddubsw", INTRIN_NONCOMMUTATIVE, \
                       W, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmovmskb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMOVMSKB_H_
COSMOPOLITAN_C_START_

uint32_t pmovmskb(const uint8_t[16]);

#if defined(__x86_64__) && defined(__GNUC__)
#define pmovmskb(A)                                            \
  ({                                                           \
    uint32_t Mask;                                             \
    if (!IsModeDbg() && X86_HAVE(SSE2)) {                      \
      const __intrin_xmm_t *Xmm = (const __intrin_xmm_t *)(A); \
      if (!X86_NEED(AVX)) {                                    \
        asm("pmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));       \
      } else {                                                 \
        asm("vpmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));      \
      }                                                        \
    } else {                                                   \
      Mask = pmovmskb(A);                                      \
    }                                                          \
    Mask;                                                      \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmulhrsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMULHRSW_H_
COSMOPOLITAN_C_START_

void pmulhrsw(int16_t a[8], const int16_t b[8], const int16_t c[8]);

#define pmulhrsw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pmulhrsw, SSSE3, "pmulhrsw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/popcnt.h */

#define COSMOPOLITAN_LIBC_BITS_POPCNT_H_
COSMOPOLITAN_C_START_

libcesque size_t _countbits(const void *, size_t);
libcesque unsigned long popcnt(unsigned long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define popcnt(X)                                                \
  (__builtin_constant_p(X) ? __builtin_popcountll(X) : ({        \
    unsigned long PoP = (X);                                     \
    if (X86_HAVE(POPCNT)) {                                      \
      asm("popcnt\t%0,%0" : "+r"(PoP) : /* no inputs */ : "cc"); \
    } else {                                                     \
      PoP = (popcnt)(PoP);                                       \
    }                                                            \
    PoP;                                                         \
  }))
#else
#define popcnt(x) __builtin_popcountll(x)
#endif /* GNUC && !ANSI */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/psraw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PSRAW_H_
COSMOPOLITAN_C_START_

void psraw(int16_t[8], const int16_t[8], unsigned char) libcesque;
void psrawv(int16_t[8], const int16_t[8], const uint64_t[2]) libcesque;

#define psraw(A, B, I) INTRIN_SSEVEX_X_I_(psraw, SSE2, "psraw", A, B, I)
#define psrawv(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(psrawv, SSE2, "psraw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHBW_H_
COSMOPOLITAN_C_START_

void punpckhbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpckhbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhbw, SSE2, "punpckhbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHWD_H_
COSMOPOLITAN_C_START_

void punpckhwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpckhwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhwd, SSE2, "punpckhwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLBW_H_
COSMOPOLITAN_C_START_

void punpcklbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpcklbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklbw, SSE2, "punpcklbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLWD_H_
COSMOPOLITAN_C_START_

void punpcklwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpcklwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklwd, SSE2, "punpcklwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/repmovsb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
#ifdef _COSMO_SOURCE

forceinline void repmovsb(void **dest, const void **src, size_t cx) {
  char *di = (char *)*dest;
  const char *si = (const char *)*src;
  while (cx) *di++ = *si++, cx--;
  *dest = di, *src = si;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repmovsb(DI, SI, CX)                                       \
  ({                                                               \
    void *Di = *(DI);                                              \
    const void *Si = *(SI);                                        \
    size_t Cx = (CX);                                              \
    asm("rep movsb"                                                \
        : "=D"(Di), "=S"(Si), "=c"(Cx), "=m"(*(char(*)[Cx])Di)     \
        : "0"(Di), "1"(Si), "2"(Cx), "m"(*(const char(*)[Cx])Si)); \
    *(DI) = Di, *(SI) = Si;                                        \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/repstosb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
#ifdef _COSMO_SOURCE

forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
  unsigned char *di = (unsigned char *)dest;
  while (cx) *di++ = al, cx--;
  return di;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repstosb(DI, AL, CX)                         \
  ({                                                 \
    void *Di = (DI);                                 \
    size_t Cx = (CX);                                \
    unsigned char Al = (AL);                         \
    asm("rep stosb %b5,(%0)"                         \
        : "=D"(Di), "=c"(Cx), "=m"(*(char(*)[Cx])Di) \
        : "0"(Di), "1"(Cx), "a"(Al));                \
    Di;                                              \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/ubsan.h */

#define COSMOPOLITAN_LIBC_INTRIN_UBSAN_H_
COSMOPOLITAN_C_START_

extern bool32 __ubsan_strict;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/ulock.h */

#define COSMOPOLITAN_ULOCK_H_
COSMOPOLITAN_C_START_

/* both wake and wait take one of these */
#define UL_COMPARE_AND_WAIT          1 /* multi-thread */
#define UL_UNFAIR_LOCK               2
#define UL_COMPARE_AND_WAIT_SHARED   3 /* multi-thread/process */
#define UL_UNFAIR_LOCK64_SHARED      4
#define UL_COMPARE_AND_WAIT64        5
#define UL_COMPARE_AND_WAIT64_SHARED 6

#define ULF_WAKE_ALL             0x00000100
#define ULF_WAKE_THREAD          0x00000200 /* takes wake_value */
#define ULF_WAKE_ALLOW_NON_OWNER 0x00000400

#define ULF_WAIT_WORKQ_DATA_CONTENTION 0x00010000
#define ULF_WAIT_CANCEL_POINT          0x00020000 /* raises eintr */
#define ULF_WAIT_ADAPTIVE_SPIN         0x00040000

int ulock_wake(uint32_t, void *, uint64_t) libcesque;
int ulock_wait(uint32_t, void *, uint64_t, uint32_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/weaken.h */

#define COSMOPOLITAN_LIBC_BITS_WEAKEN_H_

#ifndef __chibicc__
#define _weaken(symbol)                                         \
  __extension__({                                               \
    extern __typeof__(symbol) symbol __attribute__((__weak__)); \
    &symbol;                                                    \
  })
#else
#define _weaken(symbol) (&(symbol))
#endif



/*!BEGIN libc/intrin/x86.h */

#define COSMOPOLITAN_LIBC_INTRIN_X86_H_
COSMOPOLITAN_C_START_

enum VendorSignatures {
  SIG_INTEL = 0x756e6547, /* Genu */
  SIG_AMD = 0x68747541,   /* Auth */
};

enum ProcessorVendors {
  VENDOR_INTEL = 1,
  VENDOR_AMD,
  VENDOR_OTHER,
  VENDOR_MAX
};

enum ProcessorTypes {
  INTEL_BONNELL = 1,
  INTEL_CORE2,
  INTEL_COREI7,
  AMDFAM10H,
  AMDFAM15H,
  INTEL_SILVERMONT,
  INTEL_KNL,
  AMD_BTVER1,
  AMD_BTVER2,
  AMDFAM17H,
  INTEL_KNM,
  INTEL_GOLDMONT,
  INTEL_GOLDMONT_PLUS,
  INTEL_TREMONT,
  AMDFAM19H,
  ZHAOXIN_FAM7H,
  INTEL_SIERRAFOREST,
  INTEL_GRANDRIDGE,
  INTEL_CLEARWATERFOREST,
  CPU_TYPE_MAX
};

enum ProcessorSubtypes {
  INTEL_COREI7_NEHALEM = 1,
  INTEL_COREI7_WESTMERE,
  INTEL_COREI7_SANDYBRIDGE,
  AMDFAM10H_BARCELONA,
  AMDFAM10H_SHANGHAI,
  AMDFAM10H_ISTANBUL,
  AMDFAM15H_BDVER1,
  AMDFAM15H_BDVER2,
  AMDFAM15H_BDVER3,
  AMDFAM15H_BDVER4,
  AMDFAM17H_ZNVER1,
  INTEL_COREI7_IVYBRIDGE,
  INTEL_COREI7_HASWELL,
  INTEL_COREI7_BROADWELL,
  INTEL_COREI7_SKYLAKE,
  INTEL_COREI7_SKYLAKE_AVX512,
  INTEL_COREI7_CANNONLAKE,
  INTEL_COREI7_ICELAKE_CLIENT,
  INTEL_COREI7_ICELAKE_SERVER,
  AMDFAM17H_ZNVER2,
  INTEL_COREI7_CASCADELAKE,
  INTEL_COREI7_TIGERLAKE,
  INTEL_COREI7_COOPERLAKE,
  INTEL_COREI7_SAPPHIRERAPIDS,
  INTEL_COREI7_ALDERLAKE,
  AMDFAM19H_ZNVER3,
  INTEL_COREI7_ROCKETLAKE,
  ZHAOXIN_FAM7H_LUJIAZUI,
  AMDFAM19H_ZNVER4,
  INTEL_COREI7_GRANITERAPIDS,
  INTEL_COREI7_GRANITERAPIDS_D,
  INTEL_COREI7_ARROWLAKE,
  INTEL_COREI7_ARROWLAKE_S,
  INTEL_COREI7_PANTHERLAKE,
  CPU_SUBTYPE_MAX
};

enum ProcessorFeatures {
  FEATURE_CMOV = 0,
  FEATURE_MMX,
  FEATURE_POPCNT,
  FEATURE_SSE,
  FEATURE_SSE2,
  FEATURE_SSE3,
  FEATURE_SSSE3,
  FEATURE_SSE4_1,
  FEATURE_SSE4_2,
  FEATURE_AVX,
  FEATURE_AVX2,
  FEATURE_SSE4_A,
  FEATURE_FMA4,
  FEATURE_XOP,
  FEATURE_FMA,
  FEATURE_AVX512F,
  FEATURE_BMI,
  FEATURE_BMI2,
  FEATURE_AES,
  FEATURE_PCLMUL,
  FEATURE_AVX512VL,
  FEATURE_AVX512BW,
  FEATURE_AVX512DQ,
  FEATURE_AVX512CD,
  FEATURE_AVX512ER,
  FEATURE_AVX512PF,
  FEATURE_AVX512VBMI,
  FEATURE_AVX512IFMA,
  FEATURE_AVX5124VNNIW,
  FEATURE_AVX5124FMAPS,
  FEATURE_AVX512VPOPCNTDQ,
  FEATURE_AVX512VBMI2,
  FEATURE_GFNI,
  FEATURE_VPCLMULQDQ,
  FEATURE_AVX512VNNI,
  FEATURE_AVX512BITALG,
  FEATURE_AVX512BF16,
  FEATURE_AVX512VP2INTERSECT,

  FEATURE_CMPXCHG16B = 46,
  FEATURE_F16C = 49,
  FEATURE_LAHF_LM = 54,
  FEATURE_LM,
  FEATURE_WP,
  FEATURE_LZCNT,
  FEATURE_MOVBE,

  FEATURE_AVX512FP16 = 94,
  FEATURE_X86_64_BASELINE,
  FEATURE_X86_64_V2,
  FEATURE_X86_64_V3,
  FEATURE_X86_64_V4,
  CPU_FEATURE_MAX
};

struct __processor_model {
  unsigned __cpu_vendor;
  unsigned __cpu_type;
  unsigned __cpu_subtype;
  unsigned __cpu_features[1];
  const char *__cpu_march;
};

extern struct __processor_model __cpu_model;

const char *__cpu_march(unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/bsd.h */

#define COSMOPOLITAN_LIBC_LOG_BSD_H_
COSMOPOLITAN_C_START_

void err(int, const char *, ...) wontreturn;
void verr(int, const char *, va_list) wontreturn;
void errc(int, int, const char *, ...) wontreturn;
void verrc(int, int, const char *, va_list) wontreturn;
void errx(int, const char *, ...) wontreturn;
void verrx(int, const char *, va_list) wontreturn;
void warn(const char *, ...);
void vwarn(const char *, va_list);
void warnc(int, const char *, ...);
void vwarnc(int, const char *, va_list);
void warnx(const char *, ...);
void vwarnx(const char *, va_list);
void err_set_exit(void (*)(int));

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/check.h */

#define COSMOPOLITAN_LIBC_LOG_CHECK_H_
COSMOPOLITAN_C_START_

#define CHECK(X, ...)         __CHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define CHECK_EQ(Y, X, ...)   __CHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NE(Y, X, ...)   __CHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LE(Y, X, ...)   __CHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LT(Y, X, ...)   __CHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GE(Y, X, ...)   __CHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GT(Y, X, ...)   __CHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NOTNULL(X, ...) __CHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define DCHECK(X, ...)       __DCHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define DCHECK_EQ(Y, X, ...) __DCHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NE(Y, X, ...) __DCHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LE(Y, X, ...) __DCHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LT(Y, X, ...) __DCHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GE(Y, X, ...) __DCHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GT(Y, X, ...) __DCHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NOTNULL(X, ...) \
  __DCHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define CHECK_ALIGNED(BYTES, VAR, ...)                                \
  do {                                                                \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                            \
      __check_fail_aligned(BYTES, (uintptr_t)VAR, __FILE__, __LINE__, \
                           "" __VA_ARGS__);                           \
      __builtin_unreachable();                                        \
    }                                                                 \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES);          \
  } while (0)

#define DCHECK_ALIGNED(BYTES, VAR, ...)                      \
  do {                                                       \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                   \
      __DCHK_ALIGNED(BYTES, (uintptr_t)VAR, "" __VA_ARGS__); \
      __builtin_unreachable();                               \
    }                                                        \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES); \
  } while (0)

#define __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...)                   \
  do {                                                                       \
    autotype(GOT) Got = (GOT);                                               \
    autotype(WANT) Want = (WANT);                                            \
    if (!(Want OP Got)) {                                                    \
      if (!NoDebug()) {                                                      \
        __check_fail(#SUFFIX, #OP, (uint64_t)Want, (WANTSTR), (uint64_t)Got, \
                     (GOTSTR), __FILE__, __LINE__, __VA_ARGS__);             \
      } else {                                                               \
        __check_fail_##SUFFIX((uint64_t)Want, (uint64_t)Got, __FILE__,       \
                              __LINE__, 0, __VA_ARGS__);                     \
      }                                                                      \
      __builtin_unreachable();                                               \
    }                                                                        \
  } while (0)

#ifdef NDEBUG
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, ...) \
  do {                                              \
    autotype(GOT) Got = (GOT);                      \
    autotype(WANT) Want = (WANT);                   \
    if (!(Want OP Got)) {                           \
      __builtin_unreachable();                      \
    }                                               \
  } while (0)
#else
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \
  __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, __VA_ARGS__)
#endif /* NDEBUG */

#ifdef NDEBUG
#define __DCHK_ALIGNED(BYTES, VAR, ...)
#else
#define __DCHK_ALIGNED(BYTES, VAR, ...) \
  __check_fail_aligned(BYTES, VAR, __FILE__, __LINE__, __VA_ARGS__)
#endif

void __check_fail(const char *, const char *, uint64_t, const char *, uint64_t,
                  const char *, const char *, int, const char *,
                  ...) relegated wontreturn;

void __check_fail_eq(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ne(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_le(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_lt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ge(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_gt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_aligned(unsigned, uint64_t, const char *, int, const char *,
                          ...) relegated wontreturn;

#ifdef __VSCODE_INTELLISENSE__
#undef __CHK
#define __CHK(...)
#undef __DCHK
#define __DCHK(...)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countbranch.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTBRANCH_H_
COSMOPOLITAN_C_START_

#define COUNTBRANCH(x) COUNTBRANCH_(x, #x, STRINGIFY(__FILE__), __LINE__)
#define COUNTBRANCH_(x, xs, file, line) \
  COUNTBRANCH__(x, STRINGIFY(xs), STRINGIFY(xs), file, line)
#define COUNTBRANCH__(x, xs, xss, file, line)                   \
  ({                                                            \
    bool Cond;                                                  \
    struct countbranch *Info;                                   \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31338:\t"                                              \
        ".asciz\t" xs "\n"                                      \
        "31339:\t"                                              \
        ".asciz\t" xss "\n"                                     \
        "31340:\t"                                              \
        ".asciz\t" file "\n\t"                                  \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountbranch_data(%%rip)\n\t"                     \
        ".previous\n\t"                                         \
        ".section .sort.data.countbranch.2,\"a\",@progbits\n\t" \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t0\n\t"                                          \
        ".quad\t0\n\t"                                          \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31339b\n\t"                                     \
        ".quad\t31340b\n\t"                                     \
        ".quad\t" #line "\n\t"                                  \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(Info));                                          \
    Cond = (x);                                                 \
    ++Info->total;                                              \
    if (Cond) ++Info->taken;                                    \
    Cond;                                                       \
  })

struct countbranch {
  long total;
  long taken;
  const char *code;
  const char *xcode;
  const char *file;
  long line;
};

extern struct countbranch countbranch_data[];

void countbranch_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countexpr.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_


/*!BEGIN libc/nexgen32e/bench.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_BENCH_H_


/*!BEGIN libc/nexgen32e/rdtsc.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSC_H_
COSMOPOLITAN_C_START_

/**
 * Reads CPU timestamp counter.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(INVTSC)
 */
#define rdtsc() __RDTSC("rdtsc")

/**
 * Reads CPU timestamp counter w/ full serialization.
 *
 * This macro inhibits CPU magic.
 * This macro inhibits compiler magic.
 *
 * The clock isn't read until:
 *
 *   1. previous instructions finish executing; and
 *   2. previous loads are globally visible; and
 *   3. previous stores are globally visible.
 *
 * Later instructions won't dispatch until RDTSC completes.
 *
 * @see X86_HAVE(INVTSC)
 */
#define mfence_lfence_rdtsc_lfence() \
  __RDTSC("mfence\n\tlfence\n\trdtsc\n\tlfence")

#ifdef __x86__
#define __RDTSC(ASM)                                                       \
  ({                                                                       \
    uint64_t Rax, Rdx;                                                     \
    asm volatile(ASM : "=a"(Rax), "=d"(Rdx) : /* no inputs */ : "memory"); \
    Rdx << 32 | Rax;                                                       \
  })
#elif defined(__aarch64__)
#define __RDTSC(ASM)                                \
  ({                                                \
    uint64_t _Ts;                                   \
    asm volatile("mrs\t%0,cntvct_el0" : "=r"(_Ts)); \
    _Ts * 48; /* the fudge factor */                \
  })
#elif defined(__powerpc64__)
#define __RDTSC(ASM)                           \
  ({                                           \
    uint64_t _Ts;                              \
    asm volatile("mfspr\t%0,268" : "=r"(_Ts)); \
    _Ts;                                       \
  })
#elif defined(__riscv)
#define __RDTSC(ASM)                         \
  ({                                         \
    uint64_t _Ts;                            \
    asm volatile("rdcycle\t%0" : "=r"(_Ts)); \
    _Ts;                                     \
  })
#endif

COSMOPOLITAN_C_END_

/**
 * @fileoverview NexGen32e Microbenchmarking.
 *
 * @see X86_HAVE(INVTSC)
 * @see libc/testlib/bench.h
 */

#ifdef __x86__
#define __startbench()                            \
  ({                                              \
    uint64_t Ticks;                               \
    asm volatile("lfence\n\t"                     \
                 "push\t%%rbx\n\t"                \
                 "cpuid\n\t"                      \
                 "pop\t%%rbx\n\t"                 \
                 "rdtsc\n\t"                      \
                 "shl\t%2,%%rdx\n\t"              \
                 "or\t%%rdx,%0"                   \
                 : "=a"(Ticks)                    \
                 : "0"(0), "J"(32)                \
                 : "rcx", "rdx", "memory", "cc"); \
    Ticks;                                        \
  })
#define __endbench()                                     \
  ({                                                     \
    uint64_t Ticks;                                      \
    asm volatile("rdtscp\n\t"                            \
                 "shl\t%1,%%rdx\n\t"                     \
                 "or\t%%rdx,%%rax\n\t"                   \
                 "mov\t%%rax,%0\n\t"                     \
                 "xor\t%%eax,%%eax\n\t"                  \
                 "push\t%%rbx\n\t"                       \
                 "cpuid\n\t"                             \
                 "pop\t%%rbx"                            \
                 : "=r"(Ticks)                           \
                 : "J"(32)                               \
                 : "rax", "rcx", "rdx", "memory", "cc"); \
    Ticks;                                               \
  })
#else
#define __startbench()                \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#define __endbench()                  \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#endif

#define __startbench_m() mfence_lfence_rdtsc_lfence()
#define __endbench_m()   __startbench_m()
#define __marker()       asm("nop")
#define __ordered()      asm volatile("" ::: "memory")
#define __fakeread(X)    asm volatile("" : /* no outputs */ : "g"(X))
#define __fakereadwrite(X)                 \
  ({                                       \
    autotype(X) Res = (X);                 \
    asm volatile("" : "=g"(Res) : "0"(X)); \
    Res;                                   \
  })

COSMOPOLITAN_C_START_

/**
 * Shows nanosecond timings histogram for expr at exit().
 */
#define COUNTEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, rdtsc, rdtsc, \
             "COUNTEXPR")

/**
 * Like COUNTEXPR() but can be used on function calls that return void.
 */
#define COUNTSTMT(stmt)                                                    \
  (void)COUNTEXPR_((stmt, 0), #stmt, STRINGIFY(__FILE__), __LINE__, rdtsc, \
                   rdtsc, "COUNTSTMT")

/**
 * Same as COUNTEXPR() but uses Intel's expensive measurement technique.
 */
#define BENCHEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, __startbench, \
             __endbench, "BENCHEXPR")

#define COUNTEXPR_(expr, code, file, line, start, stop, macro) \
  COUNTEXPR__(expr, STRINGIFY(code), file, line, start, stop, STRINGIFY(macro))

#define COUNTEXPR__(expr, code, file, line, start, stop, macro) \
  ({                                                            \
    struct countexpr *InfO;                                     \
    uint64_t t1_, t2_, TiCkS, NaNoS;                            \
    t1_ = start();                                              \
    asm volatile("" ::: "memory");                              \
    autotype(expr) ReS = (expr);                                \
    asm volatile("" ::: "memory");                              \
    t2_ = stop();                                               \
    TiCkS = t2_ >= t1_ ? t2_ - t1_ : ~t1_ + t2_ + 1;            \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31340:\t.asciz\t" file "\n\t"                          \
        "31338:\t.asciz\t" code "\n"                            \
        "31332:\t.asciz\t" macro "\n"                           \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountexpr_data(%%rip)\n\t"                       \
        ".previous\n\t"                                         \
        ".section .sort.data.countexpr.2,\"a\",@progbits\n\t"   \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t" #line "\n\t"                                  \
        ".quad\t31340b\n\t"                                     \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31332b\n\t"                                     \
        ".rept\t65\n\t"                                         \
        ".quad\t0\n\t"                                          \
        ".endr\n\t"                                             \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(InfO));                                          \
    /* approximation of round(x*.323018) which is usually */    \
    /* the ratio, between x86 rdtsc ticks and nanoseconds */    \
    NaNoS = (TiCkS * 338709) >> 20;                             \
    ++InfO->logos[NaNoS ? bsrl(NaNoS) + 1 : 0];                 \
    ReS;                                                        \
  })

struct countexpr {
  long line; /* zero for last entry */
  const char *file;
  const char *code;
  const char *macro;
  long logos[65];
};

extern struct countexpr countexpr_data[];

void countexpr_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/gdb.h */

#define COSMOPOLITAN_LIBC_LOG_GDB_H_


/*!BEGIN libc/sysv/consts/nr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NR_H_
#ifdef _COSMO_SOURCE
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __NR_exit;
extern const int __NR_exit_group;
extern const int __NR_read;
extern const int __NR_write;
extern const int __NR_open;
extern const int __NR_close;
extern const int __NR_stat;
extern const int __NR_fstat;
extern const int __NR_lstat;
extern const int __NR_poll;
extern const int __NR_ppoll;
extern const int __NR_lseek;
extern const int __NR_mmap;
extern const int __NR_msync;
extern const int __NR_mprotect;
extern const int __NR_munmap;
extern const int __NR_sigaction;
extern const int __NR_sigprocmask;
extern const int __NR_ioctl;
extern const int __NR_pread;
extern const int __NR_pwrite;
extern const int __NR_readv;
extern const int __NR_writev;
extern const int __NR_access;
extern const int __NR_pipe;
extern const int __NR_select;
extern const int __NR_pselect;
extern const int __NR_pselect6;
extern const int __NR_sched_yield;
extern const int __NR_mremap;
extern const int __NR_mincore;
extern const int __NR_madvise;
extern const int __NR_shmget;
extern const int __NR_shmat;
extern const int __NR_shmctl;
extern const int __NR_dup;
extern const int __NR_dup2;
extern const int __NR_pause;
extern const int __NR_nanosleep;
extern const int __NR_getitimer;
extern const int __NR_setitimer;
extern const int __NR_alarm;
extern const int __NR_getpid;
extern const int __NR_sendfile;
extern const int __NR_socket;
extern const int __NR_connect;
extern const int __NR_accept;
extern const int __NR_sendto;
extern const int __NR_recvfrom;
extern const int __NR_sendmsg;
extern const int __NR_recvmsg;
extern const int __NR_shutdown;
extern const int __NR_bind;
extern const int __NR_listen;
extern const int __NR_getsockname;
extern const int __NR_getpeername;
extern const int __NR_socketpair;
extern const int __NR_setsockopt;
extern const int __NR_getsockopt;
extern const int __NR_fork;
extern const int __NR_vfork;
extern const int __NR_posix_spawn;
extern const int __NR_execve;
extern const int __NR_wait4;
extern const int __NR_kill;
extern const int __NR_killpg;
extern const int __NR_clone;
extern const int __NR_tkill;
extern const int __NR_futex;
extern const int __NR_set_robust_list;
extern const int __NR_get_robust_list;
extern const int __NR_uname;
extern const int __NR_semget;
extern const int __NR_semop;
extern const int __NR_semctl;
extern const int __NR_shmdt;
extern const int __NR_msgget;
extern const int __NR_msgsnd;
extern const int __NR_msgrcv;
extern const int __NR_msgctl;
extern const int __NR_fcntl;
extern const int __NR_flock;
extern const int __NR_fsync;
extern const int __NR_fdatasync;
extern const int __NR_truncate;
extern const int __NR_ftruncate;
extern const int __NR_getcwd;
extern const int __NR_chdir;
extern const int __NR_fchdir;
extern const int __NR_rename;
extern const int __NR_mkdir;
extern const int __NR_rmdir;
extern const int __NR_creat;
extern const int __NR_link;
extern const int __NR_unlink;
extern const int __NR_symlink;
extern const int __NR_readlink;
extern const int __NR_chmod;
extern const int __NR_fchmod;
extern const int __NR_chown;
extern const int __NR_fchown;
extern const int __NR_lchown;
extern const int __NR_umask;
extern const int __NR_gettimeofday;
extern const int __NR_getrlimit;
extern const int __NR_getrusage;
extern const int __NR_sysinfo;
extern const int __NR_times;
extern const int __NR_ptrace;
extern const int __NR_syslog;
extern const int __NR_getuid;
extern const int __NR_getgid;
extern const int __NR_getppid;
extern const int __NR_getpgrp;
extern const int __NR_setsid;
extern const int __NR_getsid;
extern const int __NR_getpgid;
extern const int __NR_setpgid;
extern const int __NR_geteuid;
extern const int __NR_getegid;
extern const int __NR_getgroups;
extern const int __NR_setgroups;
extern const int __NR_setreuid;
extern const int __NR_setregid;
extern const int __NR_setuid;
extern const int __NR_setgid;
extern const int __NR_setresuid;
extern const int __NR_setresgid;
extern const int __NR_getresuid;
extern const int __NR_getresgid;
extern const int __NR_sigpending;
extern const int __NR_sigsuspend;
extern const int __NR_sigaltstack;
extern const int __NR_mknod;
extern const int __NR_mknodat;
extern const int __NR_mkfifo;
extern const int __NR_mkfifoat;
extern const int __NR_statfs;
extern const int __NR_fstatfs;
extern const int __NR_getpriority;
extern const int __NR_setpriority;
extern const int __NR_mlock;
extern const int __NR_munlock;
extern const int __NR_mlockall;
extern const int __NR_munlockall;
extern const int __NR_setrlimit;
extern const int __NR_chroot;
extern const int __NR_sync;
extern const int __NR_acct;
extern const int __NR_settimeofday;
extern const int __NR_mount;
extern const int __NR_reboot;
extern const int __NR_quotactl;
extern const int __NR_setfsuid;
extern const int __NR_setfsgid;
extern const int __NR_capget;
extern const int __NR_capset;
extern const int __NR_sigtimedwait;
extern const int __NR_sigqueueinfo;
extern const int __NR_personality;
extern const int __NR_ustat;
extern const int __NR_sysfs;
extern const int __NR_sched_setparam;
extern const int __NR_sched_getparam;
extern const int __NR_sched_setscheduler;
extern const int __NR_sched_getscheduler;
extern const int __NR_sched_get_priority_max;
extern const int __NR_sched_get_priority_min;
extern const int __NR_sched_rr_get_interval;
extern const int __NR_vhangup;
extern const int __NR_modify_ldt;
extern const int __NR_pivot_root;
extern const int __NR__sysctl;
extern const int __NR_prctl;
extern const int __NR_arch_prctl;
extern const int __NR_adjtimex;
extern const int __NR_umount2;
extern const int __NR_swapon;
extern const int __NR_swapoff;
extern const int __NR_sethostname;
extern const int __NR_setdomainname;
extern const int __NR_iopl;
extern const int __NR_ioperm;
extern const int __NR_init_module;
extern const int __NR_delete_module;
extern const int __NR_gettid;
extern const int __NR_readahead;
extern const int __NR_setxattr;
extern const int __NR_fsetxattr;
extern const int __NR_getxattr;
extern const int __NR_fgetxattr;
extern const int __NR_listxattr;
extern const int __NR_flistxattr;
extern const int __NR_removexattr;
extern const int __NR_fremovexattr;
extern const int __NR_lsetxattr;
extern const int __NR_lgetxattr;
extern const int __NR_llistxattr;
extern const int __NR_lremovexattr;
extern const int __NR_sched_setaffinity;
extern const int __NR_sched_getaffinity;
extern const int __NR_cpuset_getaffinity;
extern const int __NR_cpuset_setaffinity;
extern const int __NR_io_setup;
extern const int __NR_io_destroy;
extern const int __NR_io_getevents;
extern const int __NR_io_submit;
extern const int __NR_io_cancel;
extern const int __NR_lookup_dcookie;
extern const int __NR_epoll_create;
extern const int __NR_epoll_wait;
extern const int __NR_epoll_ctl;
extern const int __NR_getdents;
extern const int __NR_set_tid_address;
extern const int __NR_restart_syscall;
extern const int __NR_semtimedop;
extern const int __NR_fadvise;
extern const int __NR_timer_create;
extern const int __NR_timer_settime;
extern const int __NR_timer_gettime;
extern const int __NR_timer_getoverrun;
extern const int __NR_timer_delete;
extern const int __NR_clock_settime;
extern const int __NR_clock_gettime;
extern const int __NR_clock_getres;
extern const int __NR_clock_nanosleep;
extern const int __NR_tgkill;
extern const int __NR_mbind;
extern const int __NR_set_mempolicy;
extern const int __NR_get_mempolicy;
extern const int __NR_mq_open;
extern const int __NR_mq_unlink;
extern const int __NR_mq_timedsend;
extern const int __NR_mq_timedreceive;
extern const int __NR_mq_notify;
extern const int __NR_mq_getsetattr;
extern const int __NR_kexec_load;
extern const int __NR_waitid;
extern const int __NR_add_key;
extern const int __NR_request_key;
extern const int __NR_keyctl;
extern const int __NR_ioprio_set;
extern const int __NR_ioprio_get;
extern const int __NR_inotify_init;
extern const int __NR_inotify_add_watch;
extern const int __NR_inotify_rm_watch;
extern const int __NR_openat;
extern const int __NR_mkdirat;
extern const int __NR_fchownat;
extern const int __NR_utime;
extern const int __NR_utimes;
extern const int __NR_futimesat;
extern const int __NR_futimes;
extern const int __NR_futimens;
extern const int __NR_fstatat;
extern const int __NR_unlinkat;
extern const int __NR_renameat;
extern const int __NR_linkat;
extern const int __NR_symlinkat;
extern const int __NR_readlinkat;
extern const int __NR_fchmodat;
extern const int __NR_faccessat;
extern const int __NR_unshare;
extern const int __NR_splice;
extern const int __NR_tee;
extern const int __NR_vmsplice;
extern const int __NR_migrate_pages;
extern const int __NR_move_pages;
extern const int __NR_preadv;
extern const int __NR_pwritev;
extern const int __NR_utimensat;
extern const int __NR_fallocate;
extern const int __NR_posix_fallocate;
extern const int __NR_accept4;
extern const int __NR_dup3;
extern const int __NR_pipe2;
extern const int __NR_epoll_pwait;
extern const int __NR_epoll_create1;
extern const int __NR_perf_event_open;
extern const int __NR_inotify_init1;
extern const int __NR_tgsigqueueinfo;
extern const int __NR_signalfd;
extern const int __NR_signalfd4;
extern const int __NR_eventfd;
extern const int __NR_eventfd2;
extern const int __NR_timerfd_create;
extern const int __NR_timerfd_settime;
extern const int __NR_timerfd_gettime;
extern const int __NR_recvmmsg;
extern const int __NR_fanotify_init;
extern const int __NR_fanotify_mark;
extern const int __NR_prlimit;
extern const int __NR_name_to_handle_at;
extern const int __NR_open_by_handle_at;
extern const int __NR_clock_adjtime;
extern const int __NR_syncfs;
extern const int __NR_sendmmsg;
extern const int __NR_setns;
extern const int __NR_getcpu;
extern const int __NR_process_vm_readv;
extern const int __NR_process_vm_writev;
extern const int __NR_kcmp;
extern const int __NR_finit_module;
extern const int __NR_sched_setattr;
extern const int __NR_sched_getattr;
extern const int __NR_renameat2;
extern const int __NR_seccomp;
extern const int __NR_getrandom;
extern const int __NR_memfd_create;
extern const int __NR_kexec_file_load;
extern const int __NR_bpf;
extern const int __NR_execveat;
extern const int __NR_userfaultfd;
extern const int __NR_membarrier;
extern const int __NR_mlock2;
extern const int __NR_copy_file_range;
extern const int __NR_preadv2;
extern const int __NR_pwritev2;
extern const int __NR_pkey_mprotect;
extern const int __NR_pkey_alloc;
extern const int __NR_pkey_free;
extern const int __NR_statx;
extern const int __NR_io_pgetevents;
extern const int __NR_rseq;
extern const int __NR_pidfd_send_signal;
extern const int __NR_io_uring_setup;
extern const int __NR_io_uring_enter;
extern const int __NR_io_uring_register;
extern const int __NR_pledge;
extern const int __NR_msyscall;
extern const int __NR_ktrace;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/w.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_W_H_
COSMOPOLITAN_C_START_

extern const int WNOHANG;
extern const int WUNTRACED;
extern const int WCONTINUED;

#define WNOHANG    1
#define WUNTRACED  WUNTRACED
#define WCONTINUED WCONTINUED


COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/**
 * @fileoverview GDB Attach Support Code.
 *
 * The goal of these macros is to make the backtrace into the failing
 * code as short as possible. It also helps avoid GDB getting confused
 * about how we don't use its readability destroying unwind directives.
 */

extern volatile int g_gdbsync;

int gdbexec(const char *);
int AttachDebugger(intptr_t);

#define AttachDebugger(CONTINUE_TO_ADDR) /* shorten backtraces */ \
  SYNCHRONIZE_DEBUGGER((AttachDebugger)(CONTINUE_TO_ADDR))

#define SYNCHRONIZE_DEBUGGER(PID)                                    \
  ({                                                                 \
    int Rc, Pid = (PID);                                             \
    if (Pid != -1) {                                                 \
      while ((Rc = __inline_wait4(Pid, NULL, WNOHANG, NULL)) == 0) { \
        if (g_gdbsync) {                                             \
          g_gdbsync = 0;                                             \
          if (Rc > 0) Pid = 0;                                       \
          break;                                                     \
        } else {                                                     \
          sched_yield();                                             \
        }                                                            \
      }                                                              \
    }                                                                \
    Pid;                                                             \
  })

#ifdef __x86_64__
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE)     \
  ({                                                                      \
    int64_t WaAx;                                                         \
    if (!IsWindows()) {                                                   \
      asm volatile("mov\t%5,%%r10\n\t"                                    \
                   "syscall"                                              \
                   : "=a"(WaAx)                                           \
                   : "0"(__NR_wait4), "D"(PID), "S"(OPT_OUT_WSTATUS),     \
                     "d"(OPTIONS), "g"(OPT_OUT_RUSAGE)                    \
                   : "rcx", "r8", "r9", "r10", "r11", "memory", "cc");    \
    } else {                                                              \
      WaAx = sys_wait4_nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \
    }                                                                     \
    WaAx;                                                                 \
  })
#else
#define __inline_wait4 wait4
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/log.h */

#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
#define COSMOPOLITAN_LIBC_LOG_LOG_H_


/*!BEGIN libc/stdio/stdio.h */

#define COSMOPOLITAN_LIBC_STDIO_H_

#define EOF    -1  /* end of file */
#define WEOF   -1u /* end of file (multibyte) */
#define _IOFBF 0   /* fully buffered */
#define _IOLBF 1   /* line buffered */
#define _IONBF 2   /* no buffering */

#define L_tmpnam     20
#define L_ctermid    20
#define P_tmpdir     "/tmp"
#define FILENAME_MAX 1024
#define FOPEN_MAX    1000
#define TMP_MAX      10000
#define BUFSIZ       4096

COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct FILE;
typedef struct FILE FILE;

extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;

errno_t ferror(FILE *) libcesque paramsnonnull();
void clearerr(FILE *) libcesque paramsnonnull();
int feof(FILE *) libcesque paramsnonnull();
int getc(FILE *) libcesque paramsnonnull();
int putc(int, FILE *) libcesque paramsnonnull();
int fflush(FILE *) libcesque;
int fpurge(FILE *) libcesque;
int fgetc(FILE *) libcesque paramsnonnull();
char *fgetln(FILE *, size_t *) libcesque paramsnonnull((1));
int ungetc(int, FILE *) libcesque paramsnonnull();
int fileno(FILE *) libcesque paramsnonnull() nosideeffect;
int fputc(int, FILE *) libcesque paramsnonnull();
int fputs(const char *, FILE *) libcesque paramsnonnull();
int fputws(const wchar_t *, FILE *) libcesque paramsnonnull();
void flockfile(FILE *) libcesque paramsnonnull();
void funlockfile(FILE *) libcesque paramsnonnull();
int ftrylockfile(FILE *) libcesque paramsnonnull();
char *fgets(char *, int, FILE *) libcesque paramsnonnull();
wchar_t *fgetws(wchar_t *, int, FILE *) libcesque paramsnonnull();
wint_t putwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t fputwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t putwchar(wchar_t) libcesque;
wint_t getwchar(void) libcesque;
wint_t getwc(FILE *) libcesque paramsnonnull();
wint_t fgetwc(FILE *) libcesque paramsnonnull();
wint_t ungetwc(wint_t, FILE *) libcesque paramsnonnull();
int getchar(void) libcesque;
int putchar(int) libcesque;
int puts(const char *) libcesque;
ssize_t getline(char **, size_t *, FILE *) libcesque paramsnonnull();
ssize_t getdelim(char **, size_t *, int, FILE *) libcesque paramsnonnull();
FILE *fopen(const char *, const char *) libcesque paramsnonnull((2)) __wur;
FILE *fdopen(int, const char *) libcesque paramsnonnull() __wur;
FILE *fmemopen(void *, size_t, const char *) libcesque paramsnonnull((3)) __wur;
FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3));
size_t fread(void *, size_t, size_t, FILE *) libcesque paramsnonnull((4));
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4));
int fclose(FILE *) libcesque;
int fseek(FILE *, long, int) libcesque paramsnonnull();
long ftell(FILE *) libcesque paramsnonnull();
int fseeko(FILE *, int64_t, int) libcesque paramsnonnull();
int64_t ftello(FILE *) libcesque paramsnonnull();
void rewind(FILE *) libcesque paramsnonnull();
int fopenflags(const char *) libcesque paramsnonnull();
void setlinebuf(FILE *) libcesque;
void setbuf(FILE *, char *) libcesque;
void setbuffer(FILE *, char *, size_t) libcesque;
int setvbuf(FILE *, char *, int, size_t) libcesque;
int pclose(FILE *) libcesque;
char *ctermid(char *) libcesque;
void perror(const char *) libcesque relegated;

typedef uint64_t fpos_t;
char *gets(char *) libcesque paramsnonnull();
int fgetpos(FILE *, fpos_t *) libcesque paramsnonnull();
int fsetpos(FILE *, const fpos_t *) libcesque paramsnonnull();

FILE *tmpfile(void) libcesque __wur;
char *tmpnam(char *) libcesque __wur;
char *tmpnam_r(char *) libcesque __wur;

FILE *popen(const char *, const char *) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » formatting                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int printf(const char *, ...) printfesque(1) paramsnonnull((1)) libcesque;
int vprintf(const char *, va_list) paramsnonnull() libcesque;
int fprintf(FILE *, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vfprintf(FILE *, const char *, va_list) paramsnonnull() libcesque;
int scanf(const char *, ...) libcesque scanfesque(1);
int vscanf(const char *, va_list) libcesque;
int fscanf(FILE *, const char *, ...) libcesque scanfesque(2);
int vfscanf(FILE *, const char *, va_list) libcesque;

int snprintf(char *, size_t, const char *, ...) printfesque(3) libcesque;
int vsnprintf(char *, size_t, const char *, va_list) libcesque;
int sprintf(char *, const char *, ...) libcesque;
int vsprintf(char *, const char *, va_list) libcesque;

int fwprintf(FILE *, const wchar_t *, ...) libcesque;
int fwscanf(FILE *, const wchar_t *, ...) libcesque;
int swprintf(wchar_t *, size_t, const wchar_t *, ...) libcesque;
int swscanf(const wchar_t *, const wchar_t *, ...) libcesque;
int vfwprintf(FILE *, const wchar_t *, va_list) libcesque;
int vfwscanf(FILE *, const wchar_t *, va_list) libcesque;
int vswprintf(wchar_t *, size_t, const wchar_t *, va_list) libcesque;
int vswscanf(const wchar_t *, const wchar_t *, va_list) libcesque;
int vwprintf(const wchar_t *, va_list) libcesque;
int vwscanf(const wchar_t *, va_list) libcesque;
int wprintf(const wchar_t *, ...) libcesque;
int wscanf(const wchar_t *, ...) libcesque;
int fwide(FILE *, int) libcesque;

int sscanf(const char *, const char *, ...) libcesque scanfesque(2);
int vsscanf(const char *, const char *, va_list) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » allocating                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int asprintf(char **, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » without mutexes                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int getc_unlocked(FILE *) libcesque paramsnonnull();
int puts_unlocked(const char *) libcesque;
int getchar_unlocked(void) libcesque;
int putc_unlocked(int, FILE *) libcesque paramsnonnull();
int putchar_unlocked(int) libcesque;
void clearerr_unlocked(FILE *) libcesque;
int feof_unlocked(FILE *) libcesque;
int ferror_unlocked(FILE *) libcesque;
int fileno_unlocked(FILE *) libcesque;
int fflush_unlocked(FILE *) libcesque;
int fgetc_unlocked(FILE *) libcesque;
int fputc_unlocked(int, FILE *) libcesque;
size_t fread_unlocked(void *, size_t, size_t, FILE *) libcesque;
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *) libcesque;
char *fgets_unlocked(char *, int, FILE *) libcesque;
int fputs_unlocked(const char *, FILE *) libcesque;
wint_t getwc_unlocked(FILE *) libcesque;
wint_t getwchar_unlocked(void) libcesque;
wint_t fgetwc_unlocked(FILE *) libcesque;
wint_t fputwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwchar_unlocked(wchar_t) libcesque;
wchar_t *fgetws_unlocked(wchar_t *, int, FILE *) libcesque;
int fputws_unlocked(const wchar_t *, FILE *) libcesque;
wint_t ungetwc_unlocked(wint_t, FILE *) libcesque paramsnonnull();
int ungetc_unlocked(int, FILE *) libcesque paramsnonnull();
int fseek_unlocked(FILE *, int64_t, int) libcesque paramsnonnull();
ssize_t getdelim_unlocked(char **, size_t *, int, FILE *) paramsnonnull();
int fprintf_unlocked(FILE *, const char *, ...) printfesque(2) libcesque;
int vfprintf_unlocked(FILE *, const char *, va_list) paramsnonnull() libcesque;

COSMOPOLITAN_C_END_

#define kLogFatal   0
#define kLogError   1
#define kLogWarn    2
#define kLogInfo    3
#define kLogVerbose 4
#define kLogDebug   5
#define kLogNoise   6

/**
 * Log level for compile-time DCE.
 */
#ifndef LOGGABLELEVEL
#ifndef TINY
#define LOGGABLELEVEL kLogNoise
/* #elif IsTiny() */
/* #define LOGGABLELEVEL kLogInfo */
#else
#define LOGGABLELEVEL kLogVerbose
#endif
#endif

#ifdef TINY
#define _LOG_TINY 1
#else
#define _LOG_TINY 0
#endif

COSMOPOLITAN_C_START_

extern FILE *__log_file;

int __watch(void *, size_t);
void __die(void) relegated wontreturn; /* print backtrace and abort() */
void _meminfo(int);                    /* shows malloc statistics &c. */
void _memsummary(int);                 /* light version of same thing */
const char *commandvenv(const char *, const char *);
const char *GetAddr2linePath(void);
const char *GetGdbPath(void);
bool32 IsDebuggerPresent(bool32);
bool32 IsRunningUnderMake(void);
char *GetSymbolByAddr(int64_t);
void PrintGarbage(void);
void PrintGarbageNumeric(FILE *);
void PrintWindowsMemory(const char *, size_t);

#ifndef __STRICT_ANSI__

#define _LOG_UNLIKELY(x) __builtin_expect(!!(x), 0)

extern unsigned __log_level; /* log level for runtime check */

#define LOGGABLE(LEVEL)                                          \
  ((!__builtin_constant_p(LEVEL) || (LEVEL) <= LOGGABLELEVEL) && \
   (LEVEL) <= __log_level)

// log a message with the specified log level (not checking if LOGGABLE)
#define LOGF(LEVEL, FMT, ...)                                   \
  do {                                                          \
    if (!_LOG_TINY) _log_untrace();                             \
    flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    if (!_LOG_TINY) _log_retrace();                             \
  } while (0)

// report an error without backtrace and debugger invocation
#define FATALF(FMT, ...)                                            \
  do {                                                              \
    if (!_LOG_TINY) _log_untrace();                                 \
    flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                   \
  } while (0)

#define DIEF(FMT, ...)                                                \
  do {                                                                \
    if (!_LOG_TINY) _log_untrace();                                   \
    ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    __builtin_unreachable();                                          \
  } while (0)

#define ERRORF(FMT, ...)                   \
  do {                                     \
    if (LOGGABLE(kLogError)) {             \
      LOGF(kLogError, FMT, ##__VA_ARGS__); \
    }                                      \
  } while (0)

#define WARNF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogWarn)) {             \
      LOGF(kLogWarn, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define INFOF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogInfo)) {             \
      LOGF(kLogInfo, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define VERBOSEF(FMT, ...)                                                  \
  do {                                                                      \
    if (LOGGABLE(kLogVerbose)) {                                            \
      if (!_LOG_TINY) _log_untrace();                                       \
      fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                       \
    }                                                                       \
  } while (0)

#define DEBUGF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define NOISEF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define FLOGF(F, FMT, ...)                                        \
  do {                                                            \
    if (LOGGABLE(kLogInfo)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FWARNF(F, FMT, ...)                                       \
  do {                                                            \
    if (LOGGABLE(kLogWarn)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FFATALF(F, FMT, ...)                                     \
  do {                                                           \
    if (!_LOG_TINY) _log_untrace();                              \
    flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                \
  } while (0)

#define FDEBUGF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define FNOISEF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define LOGIFNEG1(FORM)                                                \
  ({                                                                   \
    int e = _log_get_errno();                                          \
    autotype(FORM) Ax = (FORM);                                        \
    if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
      if (!_LOG_TINY) _log_untrace();                                  \
      _log_errno(__FILE__, __LINE__, #FORM);                           \
      if (!_LOG_TINY) _log_retrace();                                  \
      _log_set_errno(e);                                               \
    }                                                                  \
    Ax;                                                                \
  })

#define LOGIFNULL(FORM)                      \
  ({                                         \
    int e = _log_get_errno();                \
    autotype(FORM) Ax = (FORM);              \
    if (Ax == NULL && LOGGABLE(kLogWarn)) {  \
      if (!_LOG_TINY) _log_untrace();        \
      _log_errno(__FILE__, __LINE__, #FORM); \
      if (!_LOG_TINY) _log_retrace();        \
      _log_set_errno(e);                     \
    }                                        \
    Ax;                                      \
  })

void _log_errno(const char *, int, const char *) relegated;
int _log_get_errno(void);
void _log_set_errno(int);
void _log_untrace(void);
void _log_retrace(void);
void _log_exit(int) wontreturn;

#define ARGS  unsigned, const char *, int, FILE *, const char *
#define ATTR  paramsnonnull((5)) printfesque(5)
#define ATTRV paramsnonnull((5))
void flogf(ARGS, ...) ATTR libcesque;
void vflogf(ARGS, va_list) ATTRV libcesque;
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfverbosef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fdebugf(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfdebugf(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fnoisef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfnoisef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void ffatalf(ARGS, ...) asm("flogf") ATTR relegated wontreturn libcesque;
void vffatalf(ARGS, va_list) asm("vflogf") ATTRV relegated wontreturn libcesque;
#undef ARGS
#undef ATTR
#undef ATTRV

#endif /* __STRICT_ANSI__ */
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_LOG_LOG_H_ */


/*!BEGIN libc/log/traceme.h */

#define COSMOPOLITAN_LIBC_LOG_TRACEME_H_
COSMOPOLITAN_C_START_

extern int traceme;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alg.h */

#define COSMOPOLITAN_LIBC_ALG_ALG_H_
COSMOPOLITAN_C_START_

void *bsearch(const void *, const void *, size_t, size_t,
              int (*)(const void *, const void *)) paramsnonnull() nosideeffect;
void *bsearch_r(const void *, const void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 2, 5)) nosideeffect;
void djbsort(int32_t *, size_t) libcesque;
void qsort3(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort_r(void *, size_t, size_t,
             int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 4));
void smoothsort(void *, size_t, size_t, int (*)(const void *, const void *));
void smoothsort_r(void *, size_t, size_t,
                  int (*)(const void *, const void *, void *), void *);
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
int heapsort_r(void *, size_t, size_t,
               int (*)(const void *, const void *, void *), void *);
int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
int mergesort_r(void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *);

int radix_sort_int32(int32_t *, size_t) libcesque;
int radix_sort_int64(int64_t *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alloca.h */

#define COSMOPOLITAN_LIBC_MEM_ALLOCA_H_

#define alloca(size) __builtin_alloca(size)



/*!BEGIN libc/mem/critbit0.h */

#define COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § data structures » critical bit tree (for c strings)       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct critbit0 {
  void *root;
  size_t count;
};

bool critbit0_contains(struct critbit0 *, const char *) libcesque nosideeffect
    paramsnonnull();
int critbit0_insert(struct critbit0 *, const char *) paramsnonnull();
bool critbit0_delete(struct critbit0 *, const char *) libcesque paramsnonnull();
void critbit0_clear(struct critbit0 *) libcesque paramsnonnull();
char *critbit0_get(struct critbit0 *, const char *);
intptr_t critbit0_allprefixed(struct critbit0 *, const char *,
                              intptr_t (*)(const char *, void *), void *)
    paramsnonnull((1, 2, 3)) libcesque;
int critbit0_emplace(struct critbit0 *, const void *, size_t) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/gc.h */

#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_
#define COSMOPOLITAN_LIBC_MEM_GC_H_
COSMOPOLITAN_C_START_

libcesque void _gc_free(void *);
libcesque void __defer(void *, void *, void *);
libcesque void gclongjmp(void *, int) wontreturn;
#define gc(THING)  defer((void *)_gc_free, (void *)(THING))
#define _gc(THING) defer((void *)_gc_free, (void *)(THING))
#define defer(FN, ARG)                             \
  ({                                               \
    autotype(ARG) Arg = (ARG);                     \
    /* prevent weird opts like tail call */        \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    __defer(__builtin_frame_address(0), FN, Arg);  \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    Arg;                                           \
  })

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */


/*!BEGIN libc/mem/mem.h */

#define COSMOPOLITAN_LIBC_MEM_MEM_H_

#define M_TRIM_THRESHOLD (-1)
#define M_GRANULARITY    (-2)
#define M_MMAP_THRESHOLD (-3)

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dynamic memory                                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

void free(void *) libcesque;
void *malloc(size_t) attributeallocsize((1)) mallocesque;
void *calloc(size_t, size_t) attributeallocsize((1, 2)) mallocesque;
void *memalign(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
void *realloc(void *, size_t) reallocesque;
void *realloc_in_place(void *, size_t) reallocesque;
void *reallocarray(void *, size_t, size_t) __wur;
void *valloc(size_t) attributeallocsize((1)) vallocesque;
void *pvalloc(size_t) vallocesque;
char *strdup(const char *) paramsnonnull() mallocesque;
char *strndup(const char *, size_t) paramsnonnull() mallocesque;
void *aligned_alloc(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
int posix_memalign(void **, size_t, size_t) libcesque;

int mallopt(int, int) libcesque;
int malloc_trim(size_t) libcesque;
size_t bulk_free(void **, size_t) libcesque;
size_t malloc_usable_size(void *) libcesque;
void **independent_calloc(size_t, size_t, void **) libcesque;
void **independent_comalloc(size_t, size_t *, void **) libcesque;

wchar_t *wcsdup(const wchar_t *) strlenesque __wur;

struct mallinfo {
  size_t arena;    /* non-mmapped space allocated from system */
  size_t ordblks;  /* number of free chunks */
  size_t smblks;   /* always 0 */
  size_t hblks;    /* always 0 */
  size_t hblkhd;   /* space in mmapped regions */
  size_t usmblks;  /* maximum total allocated space */
  size_t fsmblks;  /* always 0 */
  size_t uordblks; /* total allocated space */
  size_t fordblks; /* total free space */
  size_t keepcost; /* releasable (via malloc_trim) space */
};

struct mallinfo mallinfo(void) libcesque;

size_t malloc_footprint(void) libcesque;
size_t malloc_max_footprint(void) libcesque;
size_t malloc_footprint_limit(void) libcesque;
size_t malloc_set_footprint_limit(size_t) libcesque;
void malloc_inspect_all(void (*)(void *, void *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/cachesize.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CACHESIZE_H_

#define kCpuCacheTypeData        1
#define kCpuCacheTypeInstruction 2
#define kCpuCacheTypeUnified     3

COSMOPOLITAN_C_START_

unsigned _getcachesize(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/crc32.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CRC32_H_
COSMOPOLITAN_C_START_

extern const uint32_t kCrc32cTab[256];

void crc32init(uint32_t[hasatleast 256], uint32_t);
uint32_t crc32c(uint32_t, const void *, size_t) nosideeffect;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/ffs.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_
COSMOPOLITAN_C_START_

int ffs(int) pureconst;
int ffsl(long) pureconst;
int ffsll(long long) pureconst;

#ifdef __GNUC__
#define ffs(u)   __builtin_ffs(u)
#define ffsl(u)  __builtin_ffsl(u)
#define ffsll(u) __builtin_ffsll(u)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/kompressor.h */

#define COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
#ifdef _COSMO_SOURCE

#define rldecode  __rldecode
#define rldecode2 __rldecode2
#define lz4check  __lz4check
#define lz4cpy    __lz4cpy
#define lz4len    __lz4len
#define lz4decode __lz4decode

COSMOPOLITAN_C_START_

struct RlDecode {
  uint8_t repititions;
  uint8_t byte;
};

void rldecode(void *dest, const struct RlDecode *);
void rldecode2(void *dest, const struct RlDecode *);
const uint8_t *lz4check(const void *data);
void *lz4cpy(void *dest, const void *blockdata, size_t blocksize);
size_t lz4len(const void *blockdata, size_t blocksize);
void *lz4decode(void *dest, const void *src);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/nexgen32e/lz4.h */

#define COSMOPOLITAN_LIBC_LZ4_H_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4                                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  LZ4 is a brilliant framing format for REP MOVSB designed by Yann Collet.

  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md
  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Block_format.md
  @see http://ticki.github.io/blog/how-lz4-works/ */

#define LZ4_EOF                0
#define LZ4_VERSION            1
#define LZ4_MAGICNUMBER        0x184D2204
#define LZ4_SKIPPABLE0         0x184D2A50
#define LZ4_SKIPPABLEMASK      0xFFFFFFF0
#define LZ4_MAXHEADERSIZE      (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1)
#define LZ4_BLOCKMAXSIZE_64KB  4
#define LZ4_BLOCKMAXSIZE_256KB 5
#define LZ4_BLOCKMAXSIZE_1MB   6
#define LZ4_BLOCKMAXSIZE_4MB   7

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » frames                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_MAGIC(FRAME)                      READ32LE(FRAME)
#define LZ4_FRAME_VERSION(FRAME)              ((_LZ4_FRAME_FLG(FRAME) >> 6) & 3)
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
#define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1)
#define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \
  ((_LZ4_FRAME_FLG(FRAME) >> 2) & 1)
#define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1)
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME)     ((_LZ4_FRAME_BD(FRAME) >> 4) & 7)
#define LZ4_FRAME_RESERVED1(FRAME)        ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
#define LZ4_FRAME_RESERVED2(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
#define LZ4_FRAME_RESERVED3(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 0) & 15)
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
  (LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? READ64LE((FRAME) + 4 + 1 + 1) : 0)
#define LZ4_FRAME_DICTIONARYID(FRAME)                          \
  (LZ4_FRAME_DICTIONARYIDFLAG(FRAME)                           \
       ? READ32LE(((FRAME) + 4 + 1 + 1 +                       \
                   8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME))) \
       : 0)
#define LZ4_FRAME_HEADERCHECKSUM(FRAME)                                \
  (*((FRAME) + 4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
     4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME)))
#define LZ4_FRAME_HEADERSIZE(FRAME)                        \
  (4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
   4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME) + 1)
#define _LZ4_FRAME_FLG(FRAME) (*((FRAME) + 4))
#define _LZ4_FRAME_BD(FRAME)  (*((FRAME) + 5))

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » blocks                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_BLOCK_DATA(block)         (block + sizeof(uint32_t))
#define LZ4_BLOCK_DATASIZE(block)     (READ32LE(block) & 0x7fffffff)
#define LZ4_BLOCK_ISEOF(block)        (READ32LE(block) == LZ4_EOF)
#define LZ4_BLOCK_ISCOMPRESSED(block) ((READ32LE(block) & 0x80000000) == 0)
#define LZ4_BLOCK_SIZE(frame, block)              \
  (sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \
   (LZ4_FRAME_BLOCKCHECKSUMFLAG(frame) ? sizeof(uint8_t) : 0))

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nexgen32e.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NEXGEN32E_H_
COSMOPOLITAN_C_START_

extern long kHalfCache3;
extern const uint64_t kTens[20];
extern const uint32_t kSha256[64];
extern const uint64_t kSha512[80];
extern const unsigned char kTensIndex[64];

void CheckStackIsAligned(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nt2sysv.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_


/*!BEGIN libc/nexgen32e/trampoline.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_

#define TRAMPOLINE(FUNCTION, THUNK)   \
  ({                                  \
    typeof(FUNCTION) *Tramp;          \
    asm(".section .text.trampoline\n" \
        "183:\n\t"                    \
        "mov\t%1,%%eax\n\t"           \
        "jmp\t" #THUNK "\n\t"         \
        ".previous\n\t"               \
        "mov\t$183b,%k0"              \
        : "=r"(Tramp)                 \
        : "i"(FUNCTION));             \
    Tramp;                            \
  })


/**
 * Creates function to thunk FUNCTION from MSX64 to System V ABI.
 *
 * This macro should be used when specifying callbacks in the WIN32 API.
 */
#define NT2SYSV(FUNCTION) TRAMPOLINE(FUNCTION, __nt2sysv)



/*!BEGIN libc/nexgen32e/rdtscp.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_
COSMOPOLITAN_C_START_

#define TSC_AUX_CORE(MSR) ((MSR) & 0xfff)
#define TSC_AUX_NODE(MSR) (((MSR) >> 12) & 0xfff)

/**
 * Reads CPU timestamp counter and IA32_TSC_AUX.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(RDTSCP)
 */
#define rdtscp(OPT_OUT_IA32_TSC_AUX)               \
  ({                                               \
    uint64_t Rax, Rdx;                             \
    uint32_t Ecx, *EcxOut;                         \
    asm volatile("rdtscp"                          \
                 : "=a"(Rax), "=c"(Ecx), "=d"(Rdx) \
                 : /* no inputs */                 \
                 : "memory");                      \
    EcxOut = (OPT_OUT_IA32_TSC_AUX);               \
    if (EcxOut) *EcxOut = Ecx;                     \
    Rdx << 32 | Rax;                               \
  })

/**
 * Reads timestamp counter auxiliary model specific register value.
 */
#define rdpid()                                                           \
  ({                                                                      \
    long Msr;                                                             \
    bool32 Ok;                                                            \
    Ok = false;                                                           \
    if (X86_HAVE(RDPID)) {                                                \
      asm volatile("rdpid\t%0" : "=r"(Msr) : /* no inputs */ : "memory"); \
      Ok = true;                                                          \
    } else if (IsLinux()) {                                               \
      char *p = (char *)0x7b;                                             \
      asm volatile(ZFLAG_ASM("lsl\t%2,%1")                                \
                   : ZFLAG_CONSTRAINT(Ok), "=r"(Msr)                      \
                   : "r"(p)                                               \
                   : "memory");                                           \
    }                                                                     \
    if (!Ok && X86_HAVE(RDTSCP)) {                                        \
      asm volatile("rdtscp"                                               \
                   : "=c"(Msr)                                            \
                   : /* no inputs */                                      \
                   : "eax", "edx", "memory");                             \
      Ok = true;                                                          \
    }                                                                     \
    if (!Ok) {                                                            \
      Msr = -1;                                                           \
    }                                                                     \
    Msr;                                                                  \
  })

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/sha.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_SHA_H_
COSMOPOLITAN_C_START_

void sha1_transform_avx2(uint32_t[hasatleast 5], const void *, unsigned);
void sha1_transform_ni(uint32_t[hasatleast 5], const void *, unsigned);
void sha256_transform_rorx(uint32_t[hasatleast 8], const void *, unsigned);
void sha256_transform_ni(uint32_t[hasatleast 8], const void *, unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/stackframe.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
COSMOPOLITAN_C_START_

struct StackFrame {
  struct StackFrame *next;
  intptr_t addr;
};

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_ */


/*!BEGIN libc/nexgen32e/x86info.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86INFO_H_

#define kX86CpuStepping    ((KCPUIDS(1H, EAX) >> 0) & 15)
#define kX86CpuModelid     ((KCPUIDS(1H, EAX) >> 4) & 15)
#define kX86CpuFamilyid    ((KCPUIDS(1H, EAX) >> 8) & 15)
#define kX86CpuType        ((KCPUIDS(1H, EAX) >> 12) & 3)
#define kX86CpuExtmodelid  ((KCPUIDS(1H, EAX) >> 16) & 15)
#define kX86CpuExtfamilyid ((KCPUIDS(1H, EAX) >> 20) & 255)

#define kX86CpuFamily \
  (kX86CpuFamilyid + (kX86CpuFamilyid == 15 ? kX86CpuExtfamilyid : 0))

#define kX86CpuModel                                                       \
  (kX86CpuModelid |                                                        \
   (kX86CpuFamilyid == 6 || kX86CpuFamilyid == 15 ? kX86CpuExtmodelid : 0) \
       << 4)

#define kX86ProcessorModelKey                                                 \
  (kX86CpuExtfamilyid << 12 | kX86CpuFamilyid << 8 | kX86CpuExtmodelid << 4 | \
   kX86CpuModelid)

#define X86_MARCH_UNKNOWN        0
#define X86_MARCH_CORE2          1
#define X86_MARCH_NEHALEM        2
#define X86_MARCH_WESTMERE       3
#define X86_MARCH_SANDYBRIDGE    4
#define X86_MARCH_IVYBRIDGE      5
#define X86_MARCH_HASWELL        6
#define X86_MARCH_BROADWELL      7
#define X86_MARCH_SKYLAKE        8
#define X86_MARCH_KABYLAKE       9
#define X86_MARCH_CANNONLAKE     10
#define X86_MARCH_ICELAKE        11
#define X86_MARCH_TIGERLAKE      12
#define X86_MARCH_BONNELL        13
#define X86_MARCH_SALTWELL       14
#define X86_MARCH_SILVERMONT     15
#define X86_MARCH_AIRMONT        16
#define X86_MARCH_GOLDMONT       17
#define X86_MARCH_GOLDMONTPLUS   18
#define X86_MARCH_TREMONT        19
#define X86_MARCH_KNIGHTSLANDING 20
#define X86_MARCH_KNIGHTSMILL    21
#define X86_MARCH_SAPPHIRERAPIDS 22
#define X86_MARCH_ALDERLAKE      23
#define X86_MARCH_COMETLAKE      24
#define X86_MARCH_RAPTORLAKE     25
#define X86_MARCH_ROCKETLAKE     26

#define X86_GRADE_UNKNOWN   0
#define X86_GRADE_APPLIANCE 1
#define X86_GRADE_MOBILE    2
#define X86_GRADE_TABLET    3
#define X86_GRADE_DESKTOP   4
#define X86_GRADE_CLIENT    5
#define X86_GRADE_DENSITY   6
#define X86_GRADE_SERVER    7
#define X86_GRADE_SCIENCE   8

struct X86ProcessorModel {
  short key;
  unsigned char march;
  unsigned char grade;
};

extern const size_t kX86ProcessorModelCount;
extern const struct X86ProcessorModel kX86ProcessorModels[];

const struct X86ProcessorModel *getx86processormodel(short) nosideeffect;



/*!BEGIN libc/nt/enum/accessmask.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ACCESSMASK_H_

#define kNtGenericRead            0x80000000u
#define kNtGenericWrite           0x40000000u
#define kNtGenericExecute         0x20000000u
#define kNtGenericAll             0x10000000u
#define kNtDelete                 0x00010000u
#define kNtReadControl            0x00020000u
#define kNtWriteDac               0x00040000u
#define kNtWriteOwner             0x00080000u
#define kNtSynchronize            0x00100000u
#define kNtStandardRightsRequired 0x000F0000u
#define kNtStandardRightsRead     kNtReadControl
#define kNtStandardRightsWrite    kNtReadControl
#define kNtStandardRightsExecute  kNtReadControl
#define kNtStandardRightsAll      0x001F0000u
#define kNtSpecificRightsAll      0x0000FFFFu
#define kNtAccessSystemSecurity   0x01000000u
#define kNtMaximumAllowed         0x02000000u
#define kNtFileReadData           0x0001u
#define kNtFileListDirectory      0x0001u
#define kNtFileWriteData          0x0002u
#define kNtFileAddFile            0x0002u
#define kNtFileAppendData         0x0004u
#define kNtFileAddSubdirectory    0x0004u
#define kNtFileCreatePipeInstance 0x0004u
#define kNtFileReadEa             0x0008u
#define kNtFileWriteEa            0x0010u
#define kNtFileExecute            0x0020u
#define kNtFileTraverse           0x0020u
#define kNtFileDeleteChild        0x0040u
#define kNtFileReadAttributes     0x0080u
#define kNtFileWriteAttributes    0x0100u
#define kNtFileAllAccess          (kNtStandardRightsRequired | kNtSynchronize | 0x1FFu)
#define kNtFileGenericRead                                           \
  (kNtStandardRightsRead | kNtFileReadData | kNtFileReadAttributes | \
   kNtFileReadEa | kNtSynchronize)
#define kNtFileGenericWrite                                             \
  (kNtStandardRightsWrite | kNtFileWriteData | kNtFileWriteAttributes | \
   kNtFileWriteEa | kNtFileAppendData | kNtSynchronize)
#define kNtFileGenericExecute                                          \
  (kNtStandardRightsExecute | kNtFileReadAttributes | kNtFileExecute | \
   kNtSynchronize)
#define kNtTokenAssignPrimary    0x0001u
#define kNtTokenDuplicate        0x0002u
#define kNtTokenImpersonate      0x0004u
#define kNtTokenQuery            0x0008u
#define kNtTokenQuerySource      0x0010u
#define kNtTokenAdjustPrivileges 0x0020u
#define kNtTokenAdjustGroups     0x0040u
#define kNtTokenAdjustDefault    0x0080u
#define kNtTokenAdjustSessionid  0x0100u
#define kNtTokenAllAccessP                                                 \
  (kNtStandardRightsRequired | kNtTokenAssignPrimary | kNtTokenDuplicate | \
   kNtTokenImpersonate | kNtTokenQuery | kNtTokenQuerySource |             \
   kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | kNtTokenAdjustDefault)
#define kNtTokenAllAccess kNtTokenAllAccessP | kNtTokenAdjustSessionid
#define kNtTokenRead      kNtStandardRightsRead | kNtTokenQuery
#define kNtTokenWrite                                                         \
  (kNtStandardRightsWrite | kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | \
   kNtTokenAdjustDefault)
#define kNtTokenExecute kNtStandardRightsExecute
#define kNtTokenTrustConstraintMask \
  (kNtStandardRightsRead | kNtTokenQuery | kNtTokenQuerySource)
#define kNtTokenAccessPseudoHandleWin8 kNtTokenQuery | kNtTokenQuerySource
#define kNtTokenAccessPseudoHandle     kNtTokenAccessPseudoHandleWin8



/*!BEGIN libc/nt/enum/afd.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_AFD_H_

#define kNtAfdPollReceive          0x0001
#define kNtAfdPollReceiveExpedited 0x0002
#define kNtAfdPollSend             0x0004
#define kNtAfdPollDisconnect       0x0008
#define kNtAfdPollAbort            0x0010
#define kNtAfdPollLocalClose       0x0020
#define kNtAfdPollAccept           0x0080
#define kNtAfdPollConnectFail      0x0100



/*!BEGIN libc/nt/enum/bitblt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_BITBLT_H_

#define kNtSrccopy     0x00CC0020u /* src */
#define kNtSrcpaint    0x00EE0086u /* src | dst */
#define kNtSrcand      0x008800C6u /* src & dst */
#define kNtSrcinvert   0x00660046u /* src ^ dst */
#define kNtSrcerase    0x00440328u /* src & ~dst */
#define kNtNotsrccopy  0x00330008u /* ~src */
#define kNtNotsrcerase 0x001100A6u /* ~src & ~dst */
#define kNtMergecopy   0x00C000CAu /* (src & pattern) */
#define kNtMergepaint  0x00BB0226u /* ~src | dst */
#define kNtPatcopy     0x00F00021u /* pat */
#define kNtPatpaint    0x00FB0A09u /* wut */
#define kNtPatinvert   0x005A0049u /* pat ^ dst */
#define kNtDstinvert   0x00550009u /* ~dst */
#define kNtBlackness   0x00000042u /* black */
#define kNtWhiteness   0x00FF0062u /* white */



/*!BEGIN libc/nt/enum/callback.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CALLBACK_H_

#define kNtCallbackChunkFinished 0
#define kNtCallbackStreamSwitch  1



/*!BEGIN libc/nt/enum/color.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COLOR_H_

#define kNtColorScrollbar               0
#define kNtColorBackground              1
#define kNtColorActivecaption           2
#define kNtColorInactivecaption         3
#define kNtColorMenu                    4
#define kNtColorWindow                  5
#define kNtColorWindowframe             6
#define kNtColorMenutext                7
#define kNtColorWindowtext              8
#define kNtColorCaptiontext             9
#define kNtColorActiveborder            10
#define kNtColorInactiveborder          11
#define kNtColorAppworkspace            12
#define kNtColorHighlight               13
#define kNtColorHighlighttext           14
#define kNtColorBtnface                 15
#define kNtColorBtnshadow               16
#define kNtColorGraytext                17
#define kNtColorBtntext                 18
#define kNtColorInactivecaptiontext     19
#define kNtColorBtnhighlight            20
#define kNtColor3ddkshadow              21
#define kNtColor3dlight                 22
#define kNtColorInfotext                23
#define kNtColorInfobk                  24
#define kNtColorHotlight                26
#define kNtColorGradientactivecaption   27
#define kNtColorGradientinactivecaption 28
#define kNtColorMenuhilight             29
#define kNtColorMenubar                 30



/*!BEGIN libc/nt/enum/computernameformat.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COMPUTERNAMEFORMAT_H_

#define kNtComputerNameNetBios                   0
#define kNtComputerNameDnsHostname               1
#define kNtComputerNameDnsDomain                 2
#define kNtComputerNameDnsFullyQualified         3
#define kNtComputerNamePhysicalNetBios           4
#define kNtComputerNamePhysicalDnsHostname       5
#define kNtComputerNamePhysicalDnsDomain         6
#define kNtComputerNamePhysicalDnsFullyQualified 7
#define kNtComputerName_MAX                      8



/*!BEGIN libc/nt/enum/consolemodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLEMODEFLAGS_H_

/* input mode */
#define kNtEnableProcessedInput 0x0001u
#define kNtEnableLineInput 0x0002u
#define kNtEnableEchoInput 0x0004u
#define kNtEnableWindowInput 0x0008u
#define kNtEnableMouseInput 0x0010u
#define kNtEnableInsertMode 0x0020u
#define kNtEnableQuickEditMode 0x0040u
#define kNtEnableExtendedFlags 0x0080u
#define kNtEnableAutoPosition 0x0100u
#define kNtEnableVirtualTerminalInput 0x0200u

/* output mode */
#define kNtEnableProcessedOutput 0x0001u
#define kNtEnableWrapAtEolOutput 0x0002u
#define kNtEnableVirtualTerminalProcessing 0x0004u
#define kNtDisableNewlineAutoReturn 0x0008u
#define kNtEnableLvbGridWorldwide 0x0010u



/*!BEGIN libc/nt/enum/consoleselectionflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLESELECTIONFLAGS_H_

#define kNtConsoleNoSelection 0x0000u
#define kNtConsoleSelectionInProgress 0x0001u
#define kNtConsoleSelectionNotEmpty 0x0002u
#define kNtConsoleMouseSelection 0x0004u
#define kNtConsoleMouseDown 0x0008u



/*!BEGIN libc/nt/enum/context.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONTEXT_H_

#define kNtContextAmd64 0x00100000

#define kNtContextControl        (kNtContextAmd64 | 0x00000001)
#define kNtContextInteger        (kNtContextAmd64 | 0x00000002)
#define kNtContextSegments       (kNtContextAmd64 | 0x00000004)
#define kNtContextFloatingPoint  (kNtContextAmd64 | 0x00000008)
#define kNtContextDebugRegisters (kNtContextAmd64 | 0x00000010)

#define kNtContextFull \
  (kNtContextControl | kNtContextInteger | kNtContextFloatingPoint)

#define kNtContextAll                                           \
  (kNtContextControl | kNtContextInteger | kNtContextSegments | \
   kNtContextFloatingPoint | kNtContextDebugRegisters)

#define kNtContextXstate (kNtContextAmd64 | 0x00000040)



/*!BEGIN libc/nt/enum/copyfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COPYFILE_H_

#define kNtCopyFileFailIfExists              0x00000001
#define kNtCopyFileRestartable               0x00000002
#define kNtCopyFileOpenSourceForWrite        0x00000004
#define kNtCopyFileAllowDecryptedDestination 0x00000008
#define kNtCopyFileCopySymlink               0x00000800
#define kNtCopyFileNoBuffering               0x00001000
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileResumeFromPause           0x00004000 /* Win8+ */
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileNoOffload                 0x00040000 /* Win8+ */
#define kNtCopyFileIgnoreEdpBlock            0x00400000 /* Win10+ */
#define kNtCopyFileIgnoreSourceEncryption    0x00800000 /* Win10+ */



/*!BEGIN libc/nt/enum/creationdisposition.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CREATIONDISPOSITION_H_

#define kNtCreateNew 1
#define kNtCreateAlways 2
#define kNtOpenExisting 3
#define kNtOpenAlways 4
#define kNtTruncateExisting 5



/*!BEGIN libc/nt/enum/cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CS_H_

#define kNtCsVredraw         0x00000001
#define kNtCsHredraw         0x00000002
#define kNtCsDblclks         0x00000008
#define kNtCsOwndc           0x00000020
#define kNtCsClassdc         0x00000040
#define kNtCsParentdc        0x00000080
#define kNtCsNoclose         0x00000200
#define kNtCsSavebits        0x00000800
#define kNtCsBytealignclient 0x00001000
#define kNtCsBytealignwindow 0x00002000
#define kNtCsGlobalclass     0x00004000
#define kNtCsIme             0x00010000
#define kNtCsDropshadow      0x00020000



/*!BEGIN libc/nt/enum/ctrlevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CTRLEVENT_H_

#define kNtCtrlCEvent 0      /* SIGINT */
#define kNtCtrlBreakEvent 1  /* SIGQUIT */
#define kNtCtrlCloseEvent 2  /* SIGHUP */
#define kNtCtrlLogoffEvent 5 /* SIGTERM */
#define kNtCtrlShutdownEvent 6



/*!BEGIN libc/nt/enum/cw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CW_H_

#define kNtCwUsedefault ((int)0x80000000)



/*!BEGIN libc/nt/enum/dialogresult.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_DIALOGRESULT_H_

#define kNtIdok       1
#define kNtIdcancel   2
#define kNtIdabort    3
#define kNtIdretry    4
#define kNtIdignore   5
#define kNtIdyes      6
#define kNtIdno       7
#define kNtIdclose    8
#define kNtIdhelp     9
#define kNtIdtryagain 10
#define kNtIdcontinue 11



/*!BEGIN libc/nt/enum/errormodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ERRORMODEFLAGS_H_

#define kNtErrorModeDefault      0x0
#define kNtSemFailcriticalerrors 0x1
#define kNtSemNogpfaulterrorbox  0x2
#define kNtSemNoopenfileerrorbox 0x8000



/*!BEGIN libc/nt/enum/event.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENT_H_

#define kNtEventSystemSound            0x0001
#define kNtEventSystemAlert            0x0002
#define kNtEventSystemForeground       0x0003
#define kNtEventSystemMenustart        0x0004
#define kNtEventSystemMenuend          0x0005
#define kNtEventSystemMenupopupstart   0x0006
#define kNtEventSystemMenupopupend     0x0007
#define kNtEventSystemCapturestart     0x0008
#define kNtEventSystemCaptureend       0x0009
#define kNtEventSystemMovesizestart    0x000A
#define kNtEventSystemMovesizeend      0x000B
#define kNtEventSystemContexthelpstart 0x000C
#define kNtEventSystemContexthelpend   0x000D
#define kNtEventSystemDragdropstart    0x000E
#define kNtEventSystemDragdropend      0x000F
#define kNtEventSystemDialogstart      0x0010
#define kNtEventSystemDialogend        0x0011
#define kNtEventSystemScrollingstart   0x0012
#define kNtEventSystemScrollingend     0x0013
#define kNtEventSystemSwitchstart      0x0014
#define kNtEventSystemSwitchend        0x0015
#define kNtEventSystemMinimizestart    0x0016
#define kNtEventSystemMinimizeend      0x0017

#define kNtEventConsoleCaret            0x4001
#define kNtEventConsoleUpdateRegion     0x4002
#define kNtEventConsoleUpdateSimple     0x4003
#define kNtEventConsoleUpdateScroll     0x4004
#define kNtEventConsoleLayout           0x4005
#define kNtEventConsoleStartApplication 0x4006
#define kNtEventConsoleEndApplication   0x4007

#define kNtEventObjectCreate            0x8000
#define kNtEventObjectDestroy           0x8001
#define kNtEventObjectShow              0x8002
#define kNtEventObjectHide              0x8003
#define kNtEventObjectReorder           0x8004
#define kNtEventObjectFocus             0x8005
#define kNtEventObjectSelection         0x8006
#define kNtEventObjectSelectionadd      0x8007
#define kNtEventObjectSelectionremove   0x8008
#define kNtEventObjectSelectionwithin   0x8009
#define kNtEventObjectStatechange       0x800A
#define kNtEventObjectLocationchange    0x800B
#define kNtEventObjectNamechange        0x800C
#define kNtEventObjectDescriptionchange 0x800D
#define kNtEventObjectValuechange       0x800E
#define kNtEventObjectParentchange      0x800F
#define kNtEventObjectHelpchange        0x8010
#define kNtEventObjectDefactionchange   0x8011
#define kNtEventObjectAcceleratorchange 0x8012



/*!BEGIN libc/nt/enum/eventtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENTTYPE_H_

#define kNtNotificationEvent    0
#define kNtSynchronizationEvent 1



/*!BEGIN libc/nt/enum/exceptionhandleractions.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EXCEPTIONHANDLERACTIONS_H_

#define kNtExceptionExecuteHandler 0x1u
#define kNtExceptionContinueExecution 0xffffffffu
#define kNtExceptionContinueSearch 0x0u



/*!BEGIN libc/nt/enum/fileflagandattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEFLAGANDATTRIBUTES_H_

/**
 * MS-DOS File Attributes.
 *
 * @see GetFileInformationByHandle()
 * @see libc/sysv/consts.sh
 */
#define kNtFileAttributeReadonly    0x00000001u
#define kNtFileAttributeHidden      0x00000002u
#define kNtFileAttributeSystem      0x00000004u
#define kNtFileAttributeVolumelabel 0x00000008u
#define kNtFileAttributeDirectory   0x00000010u
#define kNtFileAttributeArchive     0x00000020u

/**
 * NT File Attributes.
 */
#define kNtFileAttributeDevice            0x00000040u
#define kNtFileAttributeNormal            0x00000080u
#define kNtFileAttributeTemporary         0x00000100u
#define kNtFileAttributeSparseFile        0x00000200u
#define kNtFileAttributeReparsePoint      0x00000400u
#define kNtFileAttributeCompressed        0x00000800u
#define kNtFileAttributeOffline           0x00001000u
#define kNtFileAttributeNotContentIndexed 0x00002000u
#define kNtFileAttributeEncrypted         0x00004000u

/**
 * NT File Flags.
 */
#define kNtFileFlagWriteThrough      0x80000000u
#define kNtFileFlagOverlapped        0x40000000u
#define kNtFileFlagNoBuffering       0x20000000u
#define kNtFileFlagRandomAccess      0x10000000u
#define kNtFileFlagSequentialScan    0x08000000u
#define kNtFileFlagDeleteOnClose     0x04000000u
#define kNtFileFlagBackupSemantics   0x02000000u
#define kNtFileFlagPosixSemantics    0x01000000u
#define kNtFileFlagOpenReparsePoint  0x00200000u
#define kNtFileFlagOpenNoRecall      0x00100000u
#define kNtFileFlagFirstPipeInstance 0x00080000u



/*!BEGIN libc/nt/enum/fileinfobyhandleclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFOBYHANDLECLASS_H_

#define kNtFileBasicInfo                  0 /* struct NtFileBasicInformation */
#define kNtFileStandardInfo               1 /* struct NtFileStandardInformation */
#define kNtFileNameInfo                   2 /* struct NtFileNameInformation */
#define kNtFileStreamInfo                 7 /* struct NtFileStreamInformation */
#define kNtFileCompressionInfo            8 /* struct NtFileCompressionInfo */
#define kNtFileAttributeTagInfo           9 /* struct NtFileAttributeTagInformation */
#define kNtFileIdBothDirectoryInfo        10
#define kNtFileIdBothDirectoryRestartInfo 11
#define kNtFileRemoteProtocolInfo         13
#define kNtFileFullDirectoryInfo          14 /* NtFileFullDirectoryInformation */
#define kNtFileFullDirectoryRestartInfo   15
#define kNtFileStorageInfo                16 /* win8+ */
#define kNtFileAlignmentInfo              17 /* win8+ */
#define kNtFileIdInfo                     18 /* win8+ */
#define kNtFileIdExtdDirectoryInfo        19 /* win8+ */
#define kNtFileIdExtdDirectoryRestartInfo 20 /* win8+ */

#define kNtFileRenameInfo         4
#define kNtFileDispositionInfo    5
#define kNtFileAllocationInfo     6
#define kNtFileEndOfFileInfo      7
#define kNtFileIoPriorityHintInfo 13
#define kNtFileDispositionInfoEx  22 /* win10+ */
#define kNtFileRenameInfoEx       23 /* win10+ */



/*!BEGIN libc/nt/enum/fileinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFORMATIONCLASS_H_

#define kNtFileDirectoryInformation 1 /*→ struct NtFileDirectoryInformation */
#define kNtFileFullDirectoryInformation 2 /*→ etc. */
#define kNtFileBothDirectoryInformation 3
#define kNtFileBasicInformation 4
#define kNtFileStandardInformation 5
#define kNtFileInternalInformation 6
#define kNtFileEaInformation 7
#define kNtFileAccessInformation 8
#define kNtFileNameInformation 9
#define kNtFileRenameInformation 10
#define kNtFileLinkInformation 11
#define kNtFileNamesInformation 12
#define kNtFileDispositionInformation 13
#define kNtFilePositionInformation 14
#define kNtFileFullEaInformation 15
#define kNtFileModeInformation 16
#define kNtFileAlignmentInformation 17
#define kNtFileAllInformation 18
#define kNtFileAllocationInformation 19
#define kNtFileEndOfFileInformation 20
#define kNtFileAlternateNameInformation 21
#define kNtFileStreamInformation 22
#define kNtFilePipeInformation 23
#define kNtFilePipeLocalInformation 24
#define kNtFilePipeRemoteInformation 25
#define kNtFileMailslotQueryInformation 26
#define kNtFileMailslotSetInformation 27
#define kNtFileCompressionInformation 28
#define kNtFileObjectIdInformation 29
#define kNtFileCompletionInformation 30
#define kNtFileMoveClusterInformation 31
#define kNtFileQuotaInformation 32
#define kNtFileReparsePointInformation 33
#define kNtFileNetworkOpenInformation 34
#define kNtFileAttributeTagInformation 35
#define kNtFileTrackingInformation 36
#define kNtFileIdBothDirectoryInformation 37
#define kNtFileIdFullDirectoryInformation 38
#define kNtFileValidDataLengthInformation 39
#define kNtFileShortNameInformation 40
#define kNtFileInformation_MAX 40



/*!BEGIN libc/nt/enum/filelockflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILELOCKFLAGS_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/filemapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMAPFLAGS_H_

#define kNtFileMapCopy           0x00000001u
#define kNtFileMapWrite          0x00000002u
#define kNtFileMapRead           0x00000004u
#define kNtFileMapExecute        0x00000020u
#define kNtFileMapReserve        0x80000000u
#define kNtFileMapTargetsInvalid 0x40000000u
#define kNtFileMapLargePages     0x20000000u



/*!BEGIN libc/nt/enum/filemovemethod.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMOVEMETHOD_H_

#define kNtFileBegin   0
#define kNtFileCurrent 1
#define kNtFileEnd     2



/*!BEGIN libc/nt/enum/filesharemode.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILESHAREFLAGS_H_

#define kNtFileShareExclusive 0x00000000u
#define kNtFileShareRead 0x00000001u
#define kNtFileShareWrite 0x00000002u
#define kNtFileShareDelete 0x00000004u



/*!BEGIN libc/nt/enum/filetype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILETYPE_H_

#define kNtFileTypeUnknown 0x0000
#define kNtFileTypeDisk    0x0001 /* @see S_ISBLK() */
#define kNtFileTypeChar    0x0002 /* @see S_ISCHR() */
#define kNtFileTypePipe    0x0003 /* @see S_ISFIFO() */
#define kNtFileTypeRemote  0x8000 /* unused -MSDN */



/*!BEGIN libc/nt/enum/fillattribute.h */

#define COSMOPOLITAN_LIBC_NT_NTFILLATTRIBUTE_H_

#define kNtForegroundBlue 0x0001
#define kNtForegroundGreen 0x0002
#define kNtForegroundRed 0x0004
#define kNtForegroundIntensity 0x0008
#define kNtBackgroundBlue 0x0010
#define kNtBackgroundGreen 0x0020
#define kNtBackgroundRed 0x0040
#define kNtBackgroundIntensity 0x0080



/*!BEGIN libc/nt/enum/findexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXINFOLEVELS_H_

#define kNtFindExInfoStandard     0
#define kNtFindExInfoBasic        1
#define kNtFindExInfoMaxInfoLevel 2



/*!BEGIN libc/nt/enum/findexsearchops.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXSEARCHOPS_H_

#define kNtFindExSearchNameMatch          0
#define kNtFindExSearchLimitToDirectories 1
#define kNtFindExSearchLimitToDevices     2
#define kNtFindExSearchMaxSearchOp        3



/*!BEGIN libc/nt/enum/formatmessageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FORMATMESSAGEFLAGS_H_

#define kNtFormatMessageAllocateBuffer 0x100
#define kNtFormatMessageIgnoreInserts  0x200
#define kNtFormatMessageFromString     0x400
#define kNtFormatMessageFromHmodule    0x800
#define kNtFormatMessageFromSystem     0x1000
#define kNtFormatMessageArgumentArray  0x2000
#define kNtFormatMessageMaxWidthMask   0xff



/*!BEGIN libc/nt/enum/fsctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSCTL_H_

#define kNtFsctlDisableLocalBuffering   0x000902B8u
#define kNtFsctlFilePrefetch            0x00090120u
#define kNtFsctlFilesystemGetStatistics 0x00090060u
#define kNtFsctlGetCompression          0x0009003Cu
#define kNtFsctlGetNtfsFileRecord       0x00090068u
#define kNtFsctlGetNtfsVolumeData       0x00090064u
#define kNtFsctlQueryAllocatedRanges    0x000940CFu
#define kNtFsctlScrubData               0x000902B0u
#define kNtFsctlSetCompression          0x0009C040u
#define kNtFsctlSetSparse               0x000900C4u
#define kNtFsctlSetZeroData             0x000980C8u
#define kNtFsctlGetReparsePoint         0x000900a8u
#define kNtFsctlSetReparsePoint         0x000900a4u



/*!BEGIN libc/nt/enum/fsinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSINFORMATIONCLASS_H_

#define kNtFileFsVolumeInformation 1
#define kNtFileFsLabelInformation 2
#define kNtFileFsSizeInformation 3
#define kNtFileFsDeviceInformation 4
#define kNtFileFsAttributeInformation 5
#define kNtFileFsControlInformation 6
#define kNtFileFsFullSizeInformation 7
#define kNtFileFsObjectIdInformation 8
#define kNtFileFsDriverPathInformation 9
#define kNtFileFsInformation_MAX 10



/*!BEGIN libc/nt/enum/getfileexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_GETFILEEXINFOLEVELS_H_

#define kNtGetFileExInfoStandard 0



/*!BEGIN libc/nt/enum/heap.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HEAP_H_

#define kNtHeapNoSerialize        1
#define kNtHeapGenerateExceptions 4
#define kNtHeapZeroMemory         8
#define kNtHeapReallocInPlaceOnly 16



/*!BEGIN libc/nt/enum/ht.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HT_H_

#define kNtHterror       -2
#define kNtHttransparent -1
#define kNtHtnowhere     0
#define kNtHtclient      1
#define kNtHtcaption     2
#define kNtHtsysmenu     3
#define kNtHtgrowbox     4
#define kNtHtsize        kNtHtgrowbox
#define kNtHtmenu        5
#define kNtHthscroll     6
#define kNtHtvscroll     7
#define kNtHtminbutton   8
#define kNtHtmaxbutton   9
#define kNtHtleft        10
#define kNtHtright       11
#define kNtHttop         12
#define kNtHttopleft     13
#define kNtHttopright    14
#define kNtHtbottom      15
#define kNtHtbottomleft  16
#define kNtHtbottomright 17
#define kNtHtborder      18
#define kNtHtreduce      kNtHtminbutton
#define kNtHtzoom        kNtHtmaxbutton
#define kNtHtsizefirst   kNtHtleft
#define kNtHtsizelast    kNtHtbottomright
#define kNtHtobject      19
#define kNtHtclose       20
#define kNtHthelp        21



/*!BEGIN libc/nt/enum/idc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IDC_H_
COSMOPOLITAN_C_START_

#define kNtIdcArrow    ((const char16_t *)32512)
#define kNtIdcIbeam    ((const char16_t *)32513)
#define kNtIdcWait     ((const char16_t *)32514)
#define kNtIdcCross    ((const char16_t *)32515)
#define kNtIdcUparrow  ((const char16_t *)32516)
#define kNtIdcSizenwse ((const char16_t *)32642)
#define kNtIdcSizenesw ((const char16_t *)32643)
#define kNtIdcSizewe   ((const char16_t *)32644)
#define kNtIdcSizens   ((const char16_t *)32645)
#define kNtIdcSizeall  ((const char16_t *)32646)
#define kNtIdcNo       ((const char16_t *)32648)
#define kNtIdcHand     ((const char16_t *)32649)
#define kNtIdcHelp     ((const char16_t *)32651)
#define kNtIdcPin      ((const char16_t *)32671)
#define kNtIdcPerson   ((const char16_t *)32672)

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/imageauxsymboltype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMAGEAUXSYMBOLTYPE_H_

#define kNtImageAuxSymbolTypeTokenDef 1



/*!BEGIN libc/nt/enum/importobjectnametype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTNAMETYPE_H_

enum NtImportObjectNameType {
  IMPORT_OBJECT_ORDINAL,
  IMPORT_OBJECT_NAME,
  IMPORT_OBJECT_NAME_NO_PREFIX,
  IMPORT_OBJECT_NAME_UNDECORATE,
  IMPORT_OBJECT_NAME_EXPORTAS
};



/*!BEGIN libc/nt/enum/importobjecttype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTTYPE_H_

enum NtImportObjectType {
  IMPORT_OBJECT_CODE,
  IMPORT_OBJECT_DATA,
  IMPORT_OBJECT_CONST
};



/*!BEGIN libc/nt/enum/io.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IO_H_

#define kNtIoReparseTagSymlink    0xa000000c
#define kNtIoReparseTagMountPoint 0xa0000003



/*!BEGIN libc/nt/enum/ioctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IOCTL_H_

#define kNtIoctlDiskGetDriveGeometry 0x00070000u
#define kNtIoctlAfdPoll              0x00012024u



/*!BEGIN libc/nt/enum/jobobjectinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_JOBOBJECTINFOCLASS_H_

#define kNtJobObjectBasicAccountingInformation         1
#define kNtJobObjectBasicLimitInformation              2
#define kNtJobObjectBasicProcessIdList                 3
#define kNtJobObjectBasicUIRestrictions                4
#define kNtJobObjectSecurityLimitInformation           5
#define kNtJobObjectEndOfJobTimeInformation            6
#define kNtJobObjectAssociateCompletionPortInformation 7
#define kNtJobObjectBasicAndIoAccountingInformation    8
#define kNtJobObjectExtendedLimitInformation           9
#define kNtJobObjectJobSetInformation                  10



/*!BEGIN libc/nt/enum/keyaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_

#define kNtKeyRead      0x00020019
#define kNtKeyWrite     0x00020006
#define kNtKeyExecute   0x00020019
#define kNtKeyAllAccess 0x000f003f



/*!BEGIN libc/nt/enum/keyedevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYEDEVENT_H_

#define kNtKeyedeventWait 0x00000001u
#define kNtKeyedeventWake 0x00000002u
#define kNtKeyedeventAllAccess \
  (kNtStandardRightsRequired | kNtKeyedeventWait | kNtKeyedeventWake)



/*!BEGIN libc/nt/enum/keyinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYINFORMATIONCLASS_H_

#define kNtKeyBasicInformation 0
#define kNtKeyNodeInformation  1
#define kNtKeyFullInformation  2
#define kNtKeyNameInformation  3



/*!BEGIN libc/nt/enum/kwaitreason.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KWAITREASON_H_

#define kNtExecutive 0
#define kNtFreePage 1
#define kNtPageIn 2
#define kNtPoolAllocation 3
#define kNtDelayExecution 4
#define kNtSuspended 5
#define kNtUserRequest 6
#define kNtWrExecutive 7
#define kNtWrFreePage 8
#define kNtWrPageIn 9
#define kNtWrPoolAllocation 10
#define kNtWrDelayExecution 11
#define kNtWrSuspended 12
#define kNtWrUserRequest 13
#define kNtWrEventPair 14
#define kNtWrQueue 15
#define kNtWrLpcReceive 16
#define kNtWrLpcReply 17
#define kNtWrVirtualMemory 18
#define kNtWrPageOut 19
#define kNtWrRendezvous 20
#define kNtSpare2 21
#define kNtSpare3 22
#define kNtSpare4 23
#define kNtSpare5 24
#define kNtSpare6 25
#define kNtWrKernel 26
#define kNtMaximumWaitReason 27



/*!BEGIN libc/nt/enum/lang.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LANG_H_

#define MAKELANGID(p, s) ((((uint16_t)(s)) << 10) | (uint16_t)(p))

#define kNtLangNeutral            0x00
#define kNtLangInvariant          0x7f
#define kNtLangAfrikaans          0x36
#define kNtLangAlbanian           0x1c
#define kNtLangAlsatian           0x84
#define kNtLangAmharic            0x5e
#define kNtLangArabic             0x01
#define kNtLangArmenian           0x2b
#define kNtLangAssamese           0x4d
#define kNtLangAzeri              0x2c
#define kNtLangAzerbaijani        0x2c
#define kNtLangBangla             0x45
#define kNtLangBashkir            0x6d
#define kNtLangBasque             0x2d
#define kNtLangBelarusian         0x23
#define kNtLangBengali            0x45
#define kNtLangBreton             0x7e
#define kNtLangBosnian            0x1a
#define kNtLangBosnianNeutral     0x781a
#define kNtLangBulgarian          0x02
#define kNtLangCatalan            0x03
#define kNtLangCentralKurdish     0x92
#define kNtLangCherokee           0x5c
#define kNtLangChinese            0x04
#define kNtLangChineseSimplified  0x04
#define kNtLangChineseTraditional 0x7c04
#define kNtLangCorsican           0x83
#define kNtLangCroatian           0x1a
#define kNtLangCzech              0x05
#define kNtLangDanish             0x06
#define kNtLangDari               0x8c
#define kNtLangDivehi             0x65
#define kNtLangDutch              0x13
#define kNtLangEnglish            0x09
#define kNtLangEstonian           0x25
#define kNtLangFaeroese           0x38
#define kNtLangFarsi              0x29
#define kNtLangFilipino           0x64
#define kNtLangFinnish            0x0b
#define kNtLangFrench             0x0c
#define kNtLangFrisian            0x62
#define kNtLangFulah              0x67
#define kNtLangGalician           0x56
#define kNtLangGeorgian           0x37
#define kNtLangGerman             0x07
#define kNtLangGreek              0x08
#define kNtLangGreenlandic        0x6f
#define kNtLangGujarati           0x47
#define kNtLangHausa              0x68
#define kNtLangHawaiian           0x75
#define kNtLangHebrew             0x0d
#define kNtLangHindi              0x39
#define kNtLangHungarian          0x0e
#define kNtLangIcelandic          0x0f
#define kNtLangIgbo               0x70
#define kNtLangIndonesian         0x21
#define kNtLangInuktitut          0x5d
#define kNtLangIrish              0x3c
#define kNtLangItalian            0x10
#define kNtLangJapanese           0x11
#define kNtLangKannada            0x4b
#define kNtLangKashmiri           0x60
#define kNtLangKazak              0x3f
#define kNtLangKhmer              0x53
#define kNtLangKiche              0x86
#define kNtLangKinyarwanda        0x87
#define kNtLangKonkani            0x57
#define kNtLangKorean             0x12
#define kNtLangKyrgyz             0x40
#define kNtLangLao                0x54
#define kNtLangLatvian            0x26
#define kNtLangLithuanian         0x27
#define kNtLangLowerSorbian       0x2e
#define kNtLangLuxembourgish      0x6e
#define kNtLangMacedonian         0x2f
#define kNtLangMalay              0x3e
#define kNtLangMalayalam          0x4c
#define kNtLangMaltese            0x3a
#define kNtLangManipuri           0x58
#define kNtLangMaori              0x81
#define kNtLangMapudungun         0x7a
#define kNtLangMarathi            0x4e
#define kNtLangMohawk             0x7c
#define kNtLangMongolian          0x50
#define kNtLangNepali             0x61
#define kNtLangNorwegian          0x14
#define kNtLangOccitan            0x82
#define kNtLangOdia               0x48
#define kNtLangOriya              0x48
#define kNtLangPashto             0x63
#define kNtLangPersian            0x29
#define kNtLangPolish             0x15
#define kNtLangPortuguese         0x16
#define kNtLangPular              0x67
#define kNtLangPunjabi            0x46
#define kNtLangQuechua            0x6b
#define kNtLangRomanian           0x18
#define kNtLangRomansh            0x17
#define kNtLangRussian            0x19
#define kNtLangSakha              0x85
#define kNtLangSami               0x3b
#define kNtLangSanskrit           0x4f
#define kNtLangScottishGaelic     0x91
#define kNtLangSerbian            0x1a
#define kNtLangSerbianNeutral     0x7c1a
#define kNtLangSindhi             0x59
#define kNtLangSinhalese          0x5b
#define kNtLangSlovak             0x1b
#define kNtLangSlovenian          0x24
#define kNtLangSotho              0x6c
#define kNtLangSpanish            0x0a
#define kNtLangSwahili            0x41
#define kNtLangSwedish            0x1d
#define kNtLangSyriac             0x5a
#define kNtLangTajik              0x28
#define kNtLangTamazight          0x5f
#define kNtLangTamil              0x49
#define kNtLangTatar              0x44
#define kNtLangTelugu             0x4a
#define kNtLangThai               0x1e
#define kNtLangTibetan            0x51
#define kNtLangTigrigna           0x73
#define kNtLangTigrinya           0x73
#define kNtLangTswana             0x32
#define kNtLangTurkish            0x1f
#define kNtLangTurkmen            0x42
#define kNtLangUighur             0x80
#define kNtLangUkrainian          0x22
#define kNtLangUpperSorbian       0x2e
#define kNtLangUrdu               0x20
#define kNtLangUzbek              0x43
#define kNtLangValencian          0x03
#define kNtLangVietnamese         0x2a
#define kNtLangWelsh              0x52
#define kNtLangWolof              0x88
#define kNtLangXhosa              0x34
#define kNtLangYakut              0x85
#define kNtLangYi                 0x78
#define kNtLangYoruba             0x6a
#define kNtLangZulu               0x35

#define kNtSublangNeutral                          0x00
#define kNtSublangDefault                          0x01
#define kNtSublangSysDefault                       0x02
#define kNtSublangCustomDefault                    0x03
#define kNtSublangCustomUnspecified                0x04
#define kNtSublangUiCustomDefault                  0x05
#define kNtSublangAfrikaansSouthAfrica             0x01
#define kNtSublangAlbanianAlbania                  0x01
#define kNtSublangAlsatianFrance                   0x01
#define kNtSublangAmharicEthiopia                  0x01
#define kNtSublangArabicSaudiArabia                0x01
#define kNtSublangArabicIraq                       0x02
#define kNtSublangArabicEgypt                      0x03
#define kNtSublangArabicLibya                      0x04
#define kNtSublangArabicAlgeria                    0x05
#define kNtSublangArabicMorocco                    0x06
#define kNtSublangArabicTunisia                    0x07
#define kNtSublangArabicOman                       0x08
#define kNtSublangArabicYemen                      0x09
#define kNtSublangArabicSyria                      0x0a
#define kNtSublangArabicJordan                     0x0b
#define kNtSublangArabicLebanon                    0x0c
#define kNtSublangArabicKuwait                     0x0d
#define kNtSublangArabicUae                        0x0e
#define kNtSublangArabicBahrain                    0x0f
#define kNtSublangArabicQatar                      0x10
#define kNtSublangArmenianArmenia                  0x01
#define kNtSublangAssameseIndia                    0x01
#define kNtSublangAzeriLatin                       0x01
#define kNtSublangAzeriCyrillic                    0x02
#define kNtSublangAzerbaijaniAzerbaijanLatin       0x01
#define kNtSublangAzerbaijaniAzerbaijanCyrillic    0x02
#define kNtSublangBanglaIndia                      0x01
#define kNtSublangBanglaBangladesh                 0x02
#define kNtSublangBashkirRussia                    0x01
#define kNtSublangBasqueBasque                     0x01
#define kNtSublangBelarusianBelarus                0x01
#define kNtSublangBengaliIndia                     0x01
#define kNtSublangBengaliBangladesh                0x02
#define kNtSublangBosnianBosniaHerzegovinaLatin    0x05
#define kNtSublangBosnianBosniaHerzegovinaCyrillic 0x08
#define kNtSublangBretonFrance                     0x01
#define kNtSublangBulgarianBulgaria                0x01
#define kNtSublangCatalanCatalan                   0x01
#define kNtSublangCentralKurdishIraq               0x01
#define kNtSublangCherokeeCherokee                 0x01
#define kNtSublangChineseTraditional               0x01
#define kNtSublangChineseSimplified                0x02
#define kNtSublangChineseHongkong                  0x03
#define kNtSublangChineseSingapore                 0x04
#define kNtSublangChineseMacau                     0x05
#define kNtSublangCorsicanFrance                   0x01
#define kNtSublangCzechCzechRepublic               0x01
#define kNtSublangCroatianCroatia                  0x01
#define kNtSublangCroatianBosniaHerzegovinaLatin   0x04
#define kNtSublangDanishDenmark                    0x01
#define kNtSublangDariAfghanistan                  0x01
#define kNtSublangDivehiMaldives                   0x01
#define kNtSublangDutch                            0x01
#define kNtSublangDutchBelgian                     0x02
#define kNtSublangEnglishUs                        0x01
#define kNtSublangEnglishUk                        0x02
#define kNtSublangEnglishAus                       0x03
#define kNtSublangEnglishCan                       0x04
#define kNtSublangEnglishNz                        0x05
#define kNtSublangEnglishEire                      0x06
#define kNtSublangEnglishSouthAfrica               0x07
#define kNtSublangEnglishJamaica                   0x08
#define kNtSublangEnglishCaribbean                 0x09
#define kNtSublangEnglishBelize                    0x0a
#define kNtSublangEnglishTrinidad                  0x0b
#define kNtSublangEnglishZimbabwe                  0x0c
#define kNtSublangEnglishPhilippines               0x0d
#define kNtSublangEnglishIndia                     0x10
#define kNtSublangEnglishMalaysia                  0x11
#define kNtSublangEnglishSingapore                 0x12
#define kNtSublangEstonianEstonia                  0x01
#define kNtSublangFaeroeseFaroeIslands             0x01
#define kNtSublangFilipinoPhilippines              0x01
#define kNtSublangFinnishFinland                   0x01
#define kNtSublangFrench                           0x01
#define kNtSublangFrenchBelgian                    0x02
#define kNtSublangFrenchCanadian                   0x03
#define kNtSublangFrenchSwiss                      0x04
#define kNtSublangFrenchLuxembourg                 0x05
#define kNtSublangFrenchMonaco                     0x06
#define kNtSublangFrisianNetherlands               0x01
#define kNtSublangFulahSenegal                     0x02
#define kNtSublangGalicianGalician                 0x01
#define kNtSublangGeorgianGeorgia                  0x01
#define kNtSublangGerman                           0x01
#define kNtSublangGermanSwiss                      0x02
#define kNtSublangGermanAustrian                   0x03
#define kNtSublangGermanLuxembourg                 0x04
#define kNtSublangGermanLiechtenstein              0x05
#define kNtSublangGreekGreece                      0x01
#define kNtSublangGreenlandicGreenland             0x01
#define kNtSublangGujaratiIndia                    0x01
#define kNtSublangHausaNigeriaLatin                0x01
#define kNtSublangHawaiianUs                       0x01
#define kNtSublangHebrewIsrael                     0x01
#define kNtSublangHindiIndia                       0x01
#define kNtSublangHungarianHungary                 0x01
#define kNtSublangIcelandicIceland                 0x01
#define kNtSublangIgboNigeria                      0x01
#define kNtSublangIndonesianIndonesia              0x01
#define kNtSublangInuktitutCanada                  0x01
#define kNtSublangInuktitutCanadaLatin             0x02
#define kNtSublangIrishIreland                     0x02
#define kNtSublangItalian                          0x01
#define kNtSublangItalianSwiss                     0x02
#define kNtSublangJapaneseJapan                    0x01
#define kNtSublangKannadaIndia                     0x01
#define kNtSublangKashmiriSasia                    0x02
#define kNtSublangKashmiriIndia                    0x02
#define kNtSublangKazakKazakhstan                  0x01
#define kNtSublangKhmerCambodia                    0x01
#define kNtSublangKicheGuatemala                   0x01
#define kNtSublangKinyarwandaRwanda                0x01
#define kNtSublangKonkaniIndia                     0x01
#define kNtSublangKorean                           0x01
#define kNtSublangKyrgyzKyrgyzstan                 0x01
#define kNtSublangLaoLao                           0x01
#define kNtSublangLatvianLatvia                    0x01
#define kNtSublangLithuanian                       0x01
#define kNtSublangLowerSorbianGermany              0x02
#define kNtSublangLuxembourgishLuxembourg          0x01
#define kNtSublangMacedonianMacedonia              0x01
#define kNtSublangMalayMalaysia                    0x01
#define kNtSublangMalayBruneiDarussalam            0x02
#define kNtSublangMalayalamIndia                   0x01
#define kNtSublangMalteseMalta                     0x01
#define kNtSublangMaoriNewZealand                  0x01
#define kNtSublangMapudungunChile                  0x01
#define kNtSublangMarathiIndia                     0x01
#define kNtSublangMohawkMohawk                     0x01
#define kNtSublangMongolianCyrillicMongolia        0x01
#define kNtSublangMongolianPrc                     0x02
#define kNtSublangNepaliIndia                      0x02
#define kNtSublangNepaliNepal                      0x01
#define kNtSublangNorwegianBokmal                  0x01
#define kNtSublangNorwegianNynorsk                 0x02
#define kNtSublangOccitanFrance                    0x01
#define kNtSublangOdiaIndia                        0x01
#define kNtSublangOriyaIndia                       0x01
#define kNtSublangPashtoAfghanistan                0x01
#define kNtSublangPersianIran                      0x01
#define kNtSublangPolishPoland                     0x01
#define kNtSublangPortuguese                       0x02
#define kNtSublangPortugueseBrazilian              0x01
#define kNtSublangPularSenegal                     0x02
#define kNtSublangPunjabiIndia                     0x01
#define kNtSublangPunjabiPakistan                  0x02
#define kNtSublangQuechuaBolivia                   0x01
#define kNtSublangQuechuaEcuador                   0x02
#define kNtSublangQuechuaPeru                      0x03
#define kNtSublangRomanianRomania                  0x01
#define kNtSublangRomanshSwitzerland               0x01
#define kNtSublangRussianRussia                    0x01
#define kNtSublangSakhaRussia                      0x01
#define kNtSublangSamiNorthernNorway               0x01
#define kNtSublangSamiNorthernSweden               0x02
#define kNtSublangSamiNorthernFinland              0x03
#define kNtSublangSamiLuleNorway                   0x04
#define kNtSublangSamiLuleSweden                   0x05
#define kNtSublangSamiSouthernNorway               0x06
#define kNtSublangSamiSouthernSweden               0x07
#define kNtSublangSamiSkoltFinland                 0x08
#define kNtSublangSamiInariFinland                 0x09
#define kNtSublangSanskritIndia                    0x01
#define kNtSublangScottishGaelic                   0x01
#define kNtSublangSerbianBosniaHerzegovinaLatin    0x06
#define kNtSublangSerbianBosniaHerzegovinaCyrillic 0x07
#define kNtSublangSerbianMontenegroLatin           0x0b
#define kNtSublangSerbianMontenegroCyrillic        0x0c
#define kNtSublangSerbianSerbiaLatin               0x09
#define kNtSublangSerbianSerbiaCyrillic            0x0a
#define kNtSublangSerbianCroatia                   0x01
#define kNtSublangSerbianLatin                     0x02
#define kNtSublangSerbianCyrillic                  0x03
#define kNtSublangSindhiIndia                      0x01
#define kNtSublangSindhiPakistan                   0x02
#define kNtSublangSindhiAfghanistan                0x02
#define kNtSublangSinhaleseSriLanka                0x01
#define kNtSublangSothoNorthernSouthAfrica         0x01
#define kNtSublangSlovakSlovakia                   0x01
#define kNtSublangSlovenianSlovenia                0x01
#define kNtSublangSpanish                          0x01
#define kNtSublangSpanishMexican                   0x02
#define kNtSublangSpanishModern                    0x03
#define kNtSublangSpanishGuatemala                 0x04
#define kNtSublangSpanishCostaRica                 0x05
#define kNtSublangSpanishPanama                    0x06
#define kNtSublangSpanishDominicanRepublic         0x07
#define kNtSublangSpanishVenezuela                 0x08
#define kNtSublangSpanishColombia                  0x09
#define kNtSublangSpanishPeru                      0x0a
#define kNtSublangSpanishArgentina                 0x0b
#define kNtSublangSpanishEcuador                   0x0c
#define kNtSublangSpanishChile                     0x0d
#define kNtSublangSpanishUruguay                   0x0e
#define kNtSublangSpanishParaguay                  0x0f
#define kNtSublangSpanishBolivia                   0x10
#define kNtSublangSpanishElSalvador                0x11
#define kNtSublangSpanishHonduras                  0x12
#define kNtSublangSpanishNicaragua                 0x13
#define kNtSublangSpanishPuertoRico                0x14
#define kNtSublangSpanishUs                        0x15
#define kNtSublangSwahiliKenya                     0x01
#define kNtSublangSwedish                          0x01
#define kNtSublangSwedishFinland                   0x02
#define kNtSublangSyriacSyria                      0x01
#define kNtSublangTajikTajikistan                  0x01
#define kNtSublangTamazightAlgeriaLatin            0x02
#define kNtSublangTamazightMoroccoTifinagh         0x04
#define kNtSublangTamilIndia                       0x01
#define kNtSublangTamilSriLanka                    0x02
#define kNtSublangTatarRussia                      0x01
#define kNtSublangTeluguIndia                      0x01
#define kNtSublangThaiThailand                     0x01
#define kNtSublangTibetanPrc                       0x01
#define kNtSublangTigrignaEritrea                  0x02
#define kNtSublangTigrinyaEritrea                  0x02
#define kNtSublangTigrinyaEthiopia                 0x01
#define kNtSublangTswanaBotswana                   0x02
#define kNtSublangTswanaSouthAfrica                0x01
#define kNtSublangTurkishTurkey                    0x01
#define kNtSublangTurkmenTurkmenistan              0x01
#define kNtSublangUighurPrc                        0x01
#define kNtSublangUkrainianUkraine                 0x01
#define kNtSublangUpperSorbianGermany              0x01
#define kNtSublangUrduPakistan                     0x01
#define kNtSublangUrduIndia                        0x02
#define kNtSublangUzbekLatin                       0x01
#define kNtSublangUzbekCyrillic                    0x02
#define kNtSublangValencianValencia                0x02
#define kNtSublangVietnameseVietnam                0x01
#define kNtSublangWelshUnitedKingdom               0x01
#define kNtSublangWolofSenegal                     0x01
#define kNtSublangXhosaSouthAfrica                 0x01
#define kNtSublangYakutRussia                      0x01
#define kNtSublangYiPrc                            0x01
#define kNtSublangYorubaNigeria                    0x01
#define kNtSublangZuluSouthAfrica                  0x01



/*!BEGIN libc/nt/enum/loadlibrarysearch.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOADLIBRARYSEARCH_H_

#define kNtLoadLibrarySearchApplicationDir 0x00000200u
#define kNtLoadLibrarySearchSearchSystem32 0x00000800u
#define kNtLoadLibrarySearchUserDirs       0x00000400u
#define kNtLoadLibrarySearchDefaultDirs    0x00001000u



/*!BEGIN libc/nt/enum/lockfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOCKFILE_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/mb.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MB_H_

#define kNtMbOk                      0x00000000
#define kNtMbOkcancel                0x00000001
#define kNtMbAbortretryignore        0x00000002
#define kNtMbYesnocancel             0x00000003
#define kNtMbYesno                   0x00000004
#define kNtMbRetrycancel             0x00000005
#define kNtMbCanceltrycontinue       0x00000006
#define kNtMbIconhand                0x00000010
#define kNtMbIconquestion            0x00000020
#define kNtMbIconexclamation         0x00000030
#define kNtMbIconasterisk            0x00000040
#define kNtMbUsericon                0x00000080
#define kNtMbIconwarning             kNtMbIconexclamation
#define kNtMbIconerror               kNtMbIconhand
#define kNtMbIconinformation         kNtMbIconasterisk
#define kNtMbIconstop                kNtMbIconhand
#define kNtMbDefbutton1              0x00000000
#define kNtMbDefbutton2              0x00000100
#define kNtMbDefbutton3              0x00000200
#define kNtMbDefbutton4              0x00000300
#define kNtMbApplmodal               0x00000000
#define kNtMbSystemmodal             0x00001000
#define kNtMbTaskmodal               0x00002000
#define kNtMbHelp                    0x00004000
#define kNtMbNofocus                 0x00008000
#define kNtMbSetforeground           0x00010000
#define kNtMbDefaultDesktopOnly      0x00020000
#define kNtMbTopmost                 0x00040000
#define kNtMbRight                   0x00080000
#define kNtMbRtlreading              0x00100000
#define kNtMbServiceNotification     0x00200000
#define kNtMbServiceNotificationNt3x 0x00040000
#define kNtMbTypemask                0x0000000F
#define kNtMbIconmask                0x000000F0
#define kNtMbDefmask                 0x00000F00
#define kNtMbModemask                0x00003000
#define kNtMbMiscmask                0x0000C000



/*!BEGIN libc/nt/enum/memflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMFLAGS_H_

#define kNtMemCommit     0x1000 /* perform physical memory reservation step */
#define kNtMemReserve    0x2000 /* perform virtual memory reservation step */
#define kNtMemDecommit   0x4000
#define kNtMemRelease    0x8000
#define kNtMemFree       0x10000
#define kNtMemPrivate    0x20000
#define kNtMemMapped     0x40000
#define kNtMemReset      0x80000
#define kNtMemTopDown    0x100000
#define kNtMemWriteWatch 0x200000
#define kNtMemPhysical   0x400000
#define kNtMemImage      0x1000000
#define kNtMemLargePages 0x20000000
#define kNtMem4mbPages   0x80000000

#define kNtMemReplacePlaceholder 0x00004000



/*!BEGIN libc/nt/enum/memoryinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMORYINFORMATIONCLASS_H_

#define kNtMemoryBasicInformation    0
#define kNtMemoryWorkingSetList      1
#define kNtMemorySectionName         2
#define kNtMemoryBasicVlmInformation 3



/*!BEGIN libc/nt/enum/mf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MF_H_

#define kNtMfInsert          0x00000000
#define kNtMfChange          0x00000080
#define kNtMfAppend          0x00000100
#define kNtMfDelete          0x00000200
#define kNtMfRemove          0x00001000
#define kNtMfBycommand       0x00000000
#define kNtMfByposition      0x00000400
#define kNtMfSeparator       0x00000800
#define kNtMfEnabled         0x00000000
#define kNtMfGrayed          0x00000001
#define kNtMfDisabled        0x00000002
#define kNtMfUnchecked       0x00000000
#define kNtMfChecked         0x00000008
#define kNtMfUsecheckbitmaps 0x00000200
#define kNtMfString          0x00000000
#define kNtMfBitmap          0x00000004
#define kNtMfOwnerdraw       0x00000100
#define kNtMfPopup           0x00000010
#define kNtMfMenubarbreak    0x00000020
#define kNtMfMenubreak       0x00000040
#define kNtMfUnhilite        0x00000000
#define kNtMfHilite          0x00000080
#define kNtMfDefault         0x00001000
#define kNtMfSysmenu         0x00002000
#define kNtMfHelp            0x00004000
#define kNtMfRightjustify    0x00004000
#define kNtMfMouseselect     0x00008000



/*!BEGIN libc/nt/enum/mk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MK_H_

#define kNtMkLbutton  0x0001
#define kNtMkRbutton  0x0002
#define kNtMkShift    0x0004
#define kNtMkControl  0x0008
#define kNtMkMbutton  0x0010
#define kNtMkXbutton1 0x0020
#define kNtMkXbutton2 0x0040



/*!BEGIN libc/nt/enum/movefileexflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MOVEFILEEXFLAGS_H_

#define kNtMovefileReplaceExisting    1
#define kNtMovefileCopyAllowed        2
#define kNtMovefileDelayUntilReboot   4
#define kNtMovefileWriteThrough       8
#define kNtMovefileCreateHardlink     16
#define kNtMovefileFailIfNotTrackable 32



/*!BEGIN libc/nt/enum/objectinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OBJECTINFORMATIONCLASS_H_

#define kNtObjectBasicInformation 0 /*→ struct NtObjectBasicInformation */
#define kNtObjectNameInformation  1 /*→ etc. */
#define kNtObjectTypeInformation  2
#define kNtObjectAllInformation   3
#define kNtObjectDataInformation  4



/*!BEGIN libc/nt/enum/offerpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFFERPRIORITY_H_

/* TODO(jart): Are these values correct? */
#define kNtVmOfferPriorityVeryLow     1 /* 0x00001000? */
#define kNtVmOfferPriorityLow         2 /* 0x00002000? */
#define kNtVmOfferPriorityBelowNormal 3 /* 0x00002000? */
#define kNtVmOfferPriorityNormal      4 /* 0x00002000? */



/*!BEGIN libc/nt/enum/ofn.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFN_H_

#define kNtOfnReadonly             0x00000001
#define kNtOfnOverwriteprompt      0x00000002
#define kNtOfnHidereadonly         0x00000004
#define kNtOfnNochangedir          0x00000008
#define kNtOfnShowhelp             0x00000010
#define kNtOfnEnablehook           0x00000020
#define kNtOfnEnabletemplate       0x00000040
#define kNtOfnEnabletemplatehandle 0x00000080
#define kNtOfnNovalidate           0x00000100
#define kNtOfnAllowmultiselect     0x00000200
#define kNtOfnExtensiondifferent   0x00000400
#define kNtOfnPathmustexist        0x00000800
#define kNtOfnFilemustexist        0x00001000
#define kNtOfnCreateprompt         0x00002000
#define kNtOfnShareaware           0x00004000
#define kNtOfnNoreadonlyreturn     0x00008000
#define kNtOfnNotestfilecreate     0x00010000
#define kNtOfnNonetworkbutton      0x00020000
#define kNtOfnNolongnames          0x00040000
#define kNtOfnExplorer             0x00080000
#define kNtOfnNodereferencelinks   0x00100000
#define kNtOfnLongnames            0x00200000
#define kNtOfnEnableincludenotify  0x00400000
#define kNtOfnEnablesizing         0x00800000
#define kNtOfnDontaddtorecent      0x02000000
#define kNtOfnForceshowhidden      0x10000000



/*!BEGIN libc/nt/enum/pageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PAGEFLAGS_H_

/* Pick One */
#define kNtPageNoaccess         0x001
#define kNtPageReadonly         0x002
#define kNtPageReadwrite        0x004
#define kNtPageWritecopy        0x008
#define kNtPageExecute          0x010
#define kNtPageExecuteRead      0x020
#define kNtPageExecuteReadwrite 0x040
#define kNtPageExecuteWritecopy 0x080
#define kNtPageGuard            0x100
#define kNtPageNocache          0x200
#define kNtPageWritecombine     0x400

/* These may be OR'd */
#define kNtSecReserve        0x04000000
#define kNtSecCommit         0x08000000 /* default */
#define kNtSecImageNoExecute 0x11000000
#define kNtSecImage          0x01000000
#define kNtSecNocache        0x10000000
#define kNtSecLargePages     0x80000000
#define kNtSecWritecombine   0x40000000



/*!BEGIN libc/nt/enum/pdh.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PDH_H_

#define kNtPdhFmtRaw          0x00000010u
#define kNtPdhFmtAnsi         0x00000020u
#define kNtPdhFmtUnicode      0x00000040u
#define kNtPdhFmtLong         0x00000100u
#define kNtPdhFmtDouble       0x00000200u
#define kNtPdhFmtLarge        0x00000400u
#define kNtPdhFmtNoscale      0x00001000u
#define kNtPdhFmt1000         0x00002000u
#define kNtPdhFmtNodata       0x00004000u
#define kNtPdhFmtNocap100     0x00008000u
#define kNtPerfDetailCostly   0x00010000u
#define kNtPerfDetailStandard 0x0000FFFFu



/*!BEGIN libc/nt/enum/processaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSACCESS_H_

#define kNtProcessCreateProcess 0x0080u
#define kNtProcessCreateThread 0x0002u
#define kNtProcessDupHandle 0x0040u
#define kNtProcessQueryInformation 0x0400u
#define kNtProcessQueryLimitedInformation 0x1000u
#define kNtProcessSetInformation 0x0200u
#define kNtProcessSetQuota 0x0100u
#define kNtProcessSuspendResume 0x0800u
#define kNtProcessTerminate 0x0001u
#define kNtProcessVmOperation 0x0008u
#define kNtProcessVmRead 0x0010u
#define kNtProcessVmWrite 0x0020u
#define kNtProcessSynchronize kNtSynchronize
#define kNtProcessAllAccess \
  (kNtStandardRightsRequired | kNtSynchronize | 0xffffu)



/*!BEGIN libc/nt/enum/processcreationflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSCREATIONFLAGS_H_

#define kNtIdlePriorityClass        0x00000040u
#define kNtBelowNormalPriorityClass 0x00004000u
#define kNtNormalPriorityClass      0x00000020u
#define kNtAboveNormalPriorityClass 0x00008000u
#define kNtHighPriorityClass        0x00000080u
#define kNtRealtimePriorityClass    0x00000100u

#define kNtDebugProcess                 0x00000001u
#define kNtDebugOnlyThisProcess         0x00000002u
#define kNtCreateSuspended              0x00000004u
#define kNtDetachedProcess              0x00000008u
#define kNtCreateNewConsole             0x00000010u
#define kNtCreateNewProcessGroup        0x00000200u
#define kNtCreateUnicodeEnvironment     0x00000400u
#define kNtCreateSeparateWowVdm         0x00000800u
#define kNtCreateSharedWowVdm           0x00001000u
#define kNtCreateForcedos               0x00002000u
#define kNtInheritParentAffinity        0x00010000u
#define kNtCreateProtectedProcess       0x00040000u
#define kNtExtendedStartupinfoPresent   0x00080000u
#define kNtProcessModeBackgroundBegin   0x00100000u
#define kNtProcessModeBackgroundEnd     0x00200000u
#define kNtCreateSecureProcess          0x00400000u
#define kNtCreateBreakawayFromJob       0x01000000u
#define kNtCreatePreserveCodeAuthzLevel 0x02000000u
#define kNtCreateDefaultErrorMode       0x04000000u
#define kNtCreateNoWindow               0x08000000u
#define kNtProfileUser                  0x10000000u
#define kNtProfileKernel                0x20000000u
#define kNtProfileServer                0x40000000u
#define kNtCreateIgnoreSystemDefault    0x80000000u

#define kNtStackSizeParamIsAReservation 0x00010000



/*!BEGIN libc/nt/enum/processinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSINFOCLASS_H_

#define kNtProcessBasicInformation 0
#define kNtProcessQuotaLimits      1
#define kNtProcessIoCounters       2
#define kNtProcessVmCounters       3
#define kNtProcessTimes            4
#define kNtProcessBasePriority     5
#define kNtProcessRaisePriority    6
#define kNtProcessDebugPort        7
#define kNtProcessExceptionPort    8
#define kNtProcessAccessToken      9
#define kNtProcessWow64Information 26
#define kNtProcessImageFileName    27



/*!BEGIN libc/nt/enum/procthreadattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCTHREADATTRIBUTES_H_

#define kNtProcThreadAttributeReplaceValue 1
#define kNtProcThreadAttributeHandleList 0x00020002



/*!BEGIN libc/nt/enum/progress.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROGRESS_H_

#define kNtProgressContinue 0
#define kNtProgressCancel   1
#define kNtProgressStop     2
#define kNtProgressQuiet    3



/*!BEGIN libc/nt/enum/pseudoconsole.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PSEUDOCONSOLE_H_

#define kNtPseudoconsoleInheritCursor 1



/*!BEGIN libc/nt/enum/pwr.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PWR_H_

#define kNtPwrOk             1
#define kNtPwrFail           (-1)
#define kNtPwrSuspendrequest 1
#define kNtPwrSuspendresume  2
#define kNtPwrCriticalresume 3



/*!BEGIN libc/nt/enum/rdw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_RDW_H_

#define kNtRdwInvalidate      0x0001
#define kNtRdwInternalpaint   0x0002
#define kNtRdwErase           0x0004
#define kNtRdwValidate        0x0008
#define kNtRdwNointernalpaint 0x0010
#define kNtRdwNoerase         0x0020
#define kNtRdwNochildren      0x0040
#define kNtRdwAllchildren     0x0080
#define kNtRdwUpdatenow       0x0100
#define kNtRdwErasenow        0x0200
#define kNtRdwFrame           0x0400
#define kNtRdwNoframe         0x0800



/*!BEGIN libc/nt/enum/reggetvalueflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGGETVALUEFLAGS_H_

#define kNtRrfRtRegNone        0x00000001
#define kNtRrfRtRegSz          0x00000002
#define kNtRrfRtRegExpandSz    0x00000004
#define kNtRrfRtRegBinary      0x00000008
#define kNtRrfRtRegDword       0x00000010
#define kNtRrfRtRegMultiSz     0x00000020
#define kNtRrfRtRegQword       0x00000040
#define kNtRrfRtDword          (kNtRrfRtRegBinary | kNtRrfRtRegDword)
#define kNtRrfRtQword          (kNtRrfRtRegBinary | kNtRrfRtRegQword)
#define kNtRrfRtAny            0x0000ffff
#define kNtRrfSubkeyWow6464key 0x00010000
#define kNtRrfSubkeyWow6432key 0x00020000
#define kNtRrfWow64Mask        0x00030000
#define kNtRrfNoexpand         0x10000000
#define kNtRrfZeroonfailure    0x20000000



/*!BEGIN libc/nt/enum/regtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGTYPE_H_

#define kNtRegNone                     0
#define kNtRegSz                       1 /* UTF-16 string */
#define kNtRegExpandSz                 2 /* UTF-16 string w/ env vars refs */
#define kNtRegBinary                   3
#define kNtRegDword                    4
#define kNtRegDwordBigEndian           5
#define kNtRegLink                     6
#define kNtRegMultiSz                  7 /* UTF-16 double-nul-terminated */
#define kNtRegResourceList             8
#define kNtRegFullResourceDescriptor   9
#define kNtRegResourceRequirementsList 10
#define kNtRegQword                    11



/*!BEGIN libc/nt/enum/replacefile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REPLACEFILE_H_

#define kNtReplacefileWriteThrough      1
#define kNtReplacefileIgnoreMergeErrors 2
#define kNtReplacefileIgnoreAclErrors   4



/*!BEGIN libc/nt/enum/sc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SC_H_

#define kNtScSize         0xF000
#define kNtScMove         0xF010
#define kNtScMinimize     0xF020
#define kNtScMaximize     0xF030
#define kNtScNextwindow   0xF040
#define kNtScPrevwindow   0xF050
#define kNtScClose        0xF060
#define kNtScVscroll      0xF070
#define kNtScHscroll      0xF080
#define kNtScMousemenu    0xF090
#define kNtScKeymenu      0xF100
#define kNtScArrange      0xF110
#define kNtScRestore      0xF120
#define kNtScTasklist     0xF130
#define kNtScScreensave   0xF140
#define kNtScHotkey       0xF150
#define kNtScDefault      0xF160
#define kNtScMonitorpower 0xF170
#define kNtScContexthelp  0xF180
#define kNtScSeparator    0xF00F



/*!BEGIN libc/nt/enum/sectioninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINFORMATIONCLASS_H_

#define kNtSectionBasicInformation 0
#define kNtSectionImageInformation 1



/*!BEGIN libc/nt/enum/sectioninherit.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINHERIT_H_

enum NtSectionInherit { kNtViewShare = 1, kNtViewUnmap = 2 };



/*!BEGIN libc/nt/enum/sectionmapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONMAPFLAGS_H_

#define kNtSectionQuery              0x0001
#define kNtSectionMapWrite           0x0002
#define kNtSectionMapRead            0x0004
#define kNtSectionMapExecute         0x0008
#define kNtSectionExtendSize         0x0010
#define kNtSectionMapExecuteExplicit 0x0020



/*!BEGIN libc/nt/enum/securityimpersonationlevel.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYIMPERSONATIONLEVEL_H_

#define kNtSecurityAnonymous      0
#define kNtSecurityIdentification 1
#define kNtSecurityImpersonation  2
#define kNtSecurityDelegation     3



/*!BEGIN libc/nt/enum/securityinformation.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYINFORMATION_H_

#define kNtOwnerSecurityInformation 0x00000001
#define kNtGroupSecurityInformation 0x00000002
#define kNtDaclSecurityInformation 0x00000004
#define kNtSaclSecurityInformation 0x00000008
#define kNtLabelSecurityInformation 0x00000010
#define kNtAttributeSecurityInformation 0x00000020
#define kNtScopeSecurityInformation 0x00000040
#define kNtProcessTrustLabelSecurityInformation 0x00000080
#define kNtAccessFilterSecurityInformation 0x00000100
#define kNtBackupSecurityInformation 0x00010000
#define kNtProtectedDaclSecurityInformation 0x80000000
#define kNtProtectedSaclSecurityInformation 0x40000000
#define kNtUnprotectedDaclSecurityInformation 0x20000000
#define kNtUnprotectedSaclSecurityInformation 0x10000000



/*!BEGIN libc/nt/enum/signal.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIGNAL_H_

#define kNtSignalBreakpoint          0x80000003u
#define kNtSignalIllegalInstruction  0xC000001Du
#define kNtSignalPrivInstruction     0xC0000096u
#define kNtSignalGuardPage           0x80000001u
#define kNtSignalAccessViolation     0xC0000005u
#define kNtSignalInPageError         0xC0000006u
#define kNtSignalInvalidHandle       0xC0000008u
#define kNtSignalInvalidParameter    0xC000000du
#define kNtSignalFltDenormalOperand  0xC000008Du
#define kNtSignalFltDivideByZero     0xC000008Eu
#define kNtSignalFltInexactResult    0xC000008Fu
#define kNtSignalFltInvalidOperation 0xC0000090u
#define kNtSignalFltOverflow         0xC0000091u
#define kNtSignalFltStackCheck       0xC0000092u
#define kNtSignalFltUnderflow        0xC0000093u
#define kNtSignalIntegerDivideByZero 0xC0000094u
#define kNtSignalDllNotFound         0xC0000135u
#define kNtSignalOrdinalNotFound     0xC0000138u
#define kNtSignalEntrypointNotFound  0xC0000139u
#define kNtSignalControlCExit        0xC000013Au
#define kNtSignalDllInitFailed       0xC0000142u
#define kNtSignalFloatMultipleFaults 0xC00002B4u
#define kNtSignalFloatMultipleTraps  0xC00002B5u
#define kNtSignalAssertionFailure    0xC0000420u



/*!BEGIN libc/nt/enum/sio.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIO_H_

#define kNtSioAbsorbRtralert                      0x98000005u
#define kNtSioAcquirePortReservation              0x98000064u
#define kNtSioAddressListChange                   0x28000017u
#define kNtSioAddressListQuery                    0x48000016u
#define kNtSioAddressListSort                     0xc8000019u
#define kNtSioApplyTransportSetting               0x98000013u
#define kNtSioAssociateHandle                     0x88000001u
#define kNtSioAssociatePortReservation            0x98000066u
#define kNtSioBaseHandle                          0x48000022u
#define kNtSioBspHandlePoll                       0x4800001Du
#define kNtSioDeletePeerTargetName                0x980000cbu
#define kNtSioEnableCircularQueueing              0x28000002u
#define kNtSioFindRoute                           0x48000003u
#define kNtSioFlush                               0x28000004u
#define kNtSioGetBroadcastAddress                 0x48000005u
#define kNtSioGetExtensionFunctionPointer         0xc8000006u
#define kNtSioGetGroupQos                         0xc8000008u
#define kNtSioGetInterfaceList                    0x4008747fu
#define kNtSioGetMultipleExtensionFunctionPointer 0xc8000024u
#define kNtSioGetQos                              0xc8000007u
#define kNtSioIndexAddMcast                       0x9800000au
#define kNtSioIndexBind                           0x98000008u
#define kNtSioIndexDelMcast                       0x9800000bu
#define kNtSioIndexMcastif                        0x98000009u
#define kNtSioKeepaliveVals                       0x98000004u
#define kNtSioLimitBroadcasts                     0x98000007u
#define kNtSioLoopbackFastPath                    0x98000010u
#define kNtSioMulticastScope                      0x8800000au
#define kNtSioMultipointLoopback                  0x88000009u
#define kNtSioQueryRssProcessorInfo               0x48000025u
#define kNtSioQueryRssScalabilityInfo             0x580000d2u
#define kNtSioQuerySecurity                       0xd80000c9u
#define kNtSioQueryTargetPnpHandle                0x48000018u
#define kNtSioQueryTransportSetting               0x98000014u
#define kNtSioQueryWfpAleEndpointHandle           0x580000cdu
#define kNtSioQueryWfpConnectionRedirectContext   0x980000ddu
#define kNtSioQueryWfpConnectionRedirectRecords   0x980000dcu
#define kNtSioRcvall                              0x98000001u
#define kNtSioRcvallIf                            0x9800000eu
#define kNtSioRcvallIgmpmcast                     0x98000003u
#define kNtSioRcvallMcast                         0x98000002u
#define kNtSioRcvallMcastIf                       0x9800000du
#define kNtSioReleasePortReservation              0x98000065u
#define kNtSioReserved1                           0x8800001au
#define kNtSioReserved2                           0x88000021u
#define kNtSioRoutingInterfaceChange              0x88000015u
#define kNtSioRoutingInterfaceQuery               0xc8000014u
#define kNtSioSetGroupQos                         0x8800000cu
#define kNtSioSetPeerTargetName                   0x980000cau
#define kNtSioSetPriorityHint                     0x98000018u
#define kNtSioSetQos                              0x8800000bu
#define kNtSioSetSecurity                         0x980000c8u
#define kNtSioSetWfpConnectionRedirectRecords     0x980000deu
#define kNtSioSocketCloseNotify                   0x9800000du
#define kNtSioSocketUsageNotification             0x980000ccu
#define kNtSioTcpInfo                             0xd8000027u
#define kNtSioTcpInitialRto                       0x98000011u
#define kNtSioTcpSetAckFrequency                  0x98000017u
#define kNtSioTcpSetIcw                           0x98000016u
#define kNtSioTranslateHandle                     0xc800000du
#define kNtSioUcastIf                             0x98000006u
#define kNtSioUdpConnreset                        0x9800000cu
#define kNtSioUdpNetreset                         0x9800000fu



/*!BEGIN libc/nt/enum/size.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIZE_H_

#define kNtSizeRestored  0
#define kNtSizeMinimized 1
#define kNtSizeMaximized 2
#define kNtSizeMaxshow   3
#define kNtSizeMaxhide   4



/*!BEGIN libc/nt/enum/startf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STARTF_H_

#define kNtStartfUseshowwindow 0x00000001 /* otherwise wShowWindow ignored */
#define kNtStartfUsesize 0x00000002       /* otherwise dwX / dwY ignored */
#define kNtStartfUseposition 0x00000004   /* otherwise dwX/YSize ignored */
#define kNtStartfUsecountchars 0x00000008 /* otherwise dwX/YCountChars ign. */
#define kNtStartfUsefillattribute 0x00000010 /* etc. */
#define kNtStartfRunfullscreen 0x00000020
#define kNtStartfForceonfeedback 0x00000040
#define kNtStartfForceofffeedback 0x00000080
#define kNtStartfUsestdhandles 0x00000100 /* otherwise hStd... ignored */
#define kNtStartfUsehotkey 0x00000200
#define kNtStartfTitleislinkname 0x00000800
#define kNtStartfTitleisappid 0x00001000
#define kNtStartfPreventpinning 0x00002000
#define kNtStartfUntrustedsource 0x00008000



/*!BEGIN libc/nt/enum/statfs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STATFS_H_
COSMOPOLITAN_C_START_

#define kNtFileCasePreservedNames         0x00000002
#define kNtFileCaseSensitiveSearch        0x00000001
#define kNtFileFileCompression            0x00000010
#define kNtFileNamedStreams               0x00040000
#define kNtFilePersistentAcls             0x00000008
#define kNtFileReadOnlyVolume             0x00080000 /* ST_RDONLY */
#define kNtFileSequentialWriteOnce        0x00100000
#define kNtFileSupportsEncryption         0x00020000
#define kNtFileSupportsExtendedAttributes 0x00800000
#define kNtFileSupportsHardLinks          0x00400000
#define kNtFileSupportsObjectIds          0x00010000
#define kNtFileSupportsOpenByFileId       0x01000000
#define kNtFileSupportsReparsePoints      0x00000080
#define kNtFileSupportsSparseFiles        0x00000040
#define kNtFileSupportsTransactions       0x00200000
#define kNtFileSupportsUsnJournal         0x02000000
#define kNtFileUnicodeOnDisk              0x00000004
#define kNtFileVolumeIsCompressed         0x00008000
#define kNtFileVolumeQuotas               0x00000020
#define kNtFileSupportsBlockRefcounting   0x08000000

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/status.h */

#define COSMOPOLITAN_LIBC_NT_STATUS_H_

/* high two bits = {success,informational,warning,error} */
#define kNtStatusSuccess                  0x00000000 /* success statuses */
#define kNtStatusWait0                    0x00000000
#define kNtStatusAbandonedWait0           0x00000080
#define kNtStatusUserApc                  0x000000C0
#define kNtStatusTimeout                  0x00000102
#define kNtStatusPending                  0x00000103
#define kNtStatusGuardPageViolation       0x80000001 /* warning statuses */
#define kNtStatusDatatypeMisalignment     0x80000002
#define kNtStatusBreakpoint               0x80000003
#define kNtStatusSingleStep               0x80000004
#define kNtStatusLongjump                 0x80000026
#define kNtStatusUnwindConsolidate        0x80000029
#define kNtStatusAccessViolation          0xC0000005 /* error statuses */
#define kNtStatusInPageError              0xC0000006
#define kNtStatusInvalidHandle            0xC0000008
#define kNtStatusInvalidParameter         0xC000000D
#define kNtStatusNoMemory                 0xC0000017
#define kNtStatusIllegalInstruction       0xC000001D
#define kNtStatusNoncontinuableException  0xC0000025
#define kNtStatusInvalidDisposition       0xC0000026
#define kNtStatusArrayBoundsExceeded      0xC000008C
#define kNtStatusFloatDenormalOperand     0xC000008D
#define kNtStatusFloatDivideByZero        0xC000008E
#define kNtStatusFloatInexactResult       0xC000008F
#define kNtStatusFloatInvalidOperation    0xC0000090
#define kNtStatusFloatOverflow            0xC0000091
#define kNtStatusFloatStackCheck          0xC0000092
#define kNtStatusFloatUnderflow           0xC0000093
#define kNtStatusIntegerDivideBYZero      0xC0000094
#define kNtStatusIntegerOverflow          0xC0000095
#define kNtStatusPrivilegedInstruction    0xC0000096
#define kNtStatusStackOverflow            0xC00000FD
#define kNtStatusDllNotFound              0xC0000135
#define kNtStatusOrdinalNotFound          0xC0000138
#define kNtStatusEntrypointNotFound       0xC0000139
#define kNtStatusControlCExit             0xC000013A
#define kNtStatusDllInitFailed            0xC0000142
#define kNtStatusFloatMultipleFaults      0xC00002B4
#define kNtStatusFloatMultipleTraps       0xC00002B5
#define kNtStatusRegNatConsumption        0xC00002C9
#define kNtStatusHeapCorruption           0xC0000374
#define kNtStatusStackBufferOverrun       0xC0000409
#define kNtStatusInvalidCruntimeParameter 0xC0000417
#define kNtStatusAssertionFailure         0xC0000420
#define kNtStatusEnclaveViolation         0xC00004A2
#define kNtStatusSegmentNotification      0x40000005
#define kNtStatusFatalAppExit             0x40000015
#define kNtStatusNotFound                 0xC0000225
#define kNtStatusCancelled                0xC0000120

#define kNtDbgExceptionHandled    0x00010001
#define kNtDbgContinue            0x00010002
#define kNtDbgReplyLater          0x40010001
#define kNtDbgTerminateThread     0x40010003
#define kNtDbgTerminateProcess    0x40010004
#define kNtDbgControlC            0x40010005
#define kNtDbgPrintexceptionC     0x40010006
#define kNtDbgRipexception        0x40010007
#define kNtDbgControlBreak        0x40010008
#define kNtDbgCommandException    0x40010009
#define kNtDbgPrintexceptionWideC 0x4001000A
#define kNtDbgExceptionNotHandled 0x80010001
#define kNtStillActive            kNtStatusPending

#if !(__ASSEMBLER__ + __LINKER__ + 0)

typedef uint32_t NtStatus;

#define NtSuccess(s)      ((NtStatus)(s) >= 0)
#define NtInformation(s)  (NtSeverity(s) == 1)
#define NtWarning(s)      (NtSeverity(s) == 2)
#define NtError(s)        (NtSeverity(s) == 3)
#define NtCode(s)         ((NtStatus)(s)&0xffff)
#define NtSeverity(s)     ((NtStatus)(s) >> 30)
#define NtFacility(s)     (((NtStatus)(s) >> 16) & 0xfff)
#define NtFacilityCode(s) ((NtStatus)(s)&0x0FFFFFFF)

#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nt/enum/sw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SW_H_

#define kNtSwHide            0
#define kNtSwShownormal      1
#define kNtSwNormal          1
#define kNtSwShowminimized   2
#define kNtSwShowmaximized   3
#define kNtSwMaximize        3
#define kNtSwShownoactivate  4
#define kNtSwShow            5
#define kNtSwMinimize        6
#define kNtSwShowminnoactive 7
#define kNtSwShowna          8
#define kNtSwRestore         9
#define kNtSwShowdefault     10
#define kNtSwForceminimize   11



/*!BEGIN libc/nt/enum/symboliclink.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYMBOLICLINK_H_

#define kNtSymbolicLinkFlagDirectory               1
#define kNtSymbolicLinkFlagAllowUnprivilegedCreate 2



/*!BEGIN libc/nt/enum/systeminformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYSTEMINFORMATIONCLASS_H_

#define kNtSystemBasicInformation 0
#define kNtSystemProcessorInformation 1
#define kNtSystemPerformanceInformation 2
#define kNtSystemTimeOfDayInformation 3
#define kNtSystemProcessInformation 5
#define kNtSystemProcessorTimes 8
#define kNtSystemGlobalFlag 9
#define kNtSystemModuleInformation 11
#define kNtSystemLockInformation 12
#define kNtSystemHandleInformation 16
#define kNtSystemObjectInformation 17
#define kNtSystemInterruptInformation 23
#define kNtSystemExceptionInformation 33
#define kNtSystemRegistryQuotaInformation 37
#define kNtSystemLookasideInformation 45



/*!BEGIN libc/nt/enum/th32cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TH32CS_H_

#define kNtTh32csInherit      0x80000000
#define kNtTh32csSnapheaplist 0x00000001
#define kNtTh32csSnapmodule   0x00000008
#define kNtTh32csSnapmodule32 0x00000010
#define kNtTh32csSnapprocess  0x00000002
#define kNtTh32csSnapthread   0x00000004



/*!BEGIN libc/nt/enum/threadaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADACCESS_H_

#define kNtThreadTerminate 0x0001
#define kNtThreadSuspendResume 0x0002
#define kNtThreadGetContext 0x0008
#define kNtThreadSetContext 0x0010
#define kNtThreadQueryInformation 0x0040
#define kNtThreadSetInformation 0x0020
#define kNtThreadSetThreadToken 0x0080
#define kNtThreadImpersonate 0x0100
#define kNtThreadDirectImpersonation 0x0200
#define kNtThreadSetLimitedInformation 0x0400
#define kNtThreadQueryLimitedInformation 0x0800
#define kNtThreadResume 0x1000
#define kNtThreadAllAccess (kNtStandardRightsRequired | kNtSynchronize | 0xFFFF)



/*!BEGIN libc/nt/enum/threadinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADINFOCLASS_H_

enum NtThreadInfoClass {
  kNtThreadBasicInformation,
  kNtThreadTimes,
  kNtThreadPriority,
  kNtThreadBasePriority,
  kNtThreadAffinityMask,
  kNtThreadImpersonationToken,
  kNtThreadDescriptorTableEntry,
  kNtThreadEnableAlignmentFaultFixup,
  kNtThreadEventPair_Reusable,
  kNtThreadQuerySetWin32StartAddress,
  kNtThreadZeroTlsCell,
  kNtThreadPerformanceCount,
  kNtThreadAmILastThread,
  kNtThreadIdealProcessor,
  kNtThreadPriorityBoost,
  kNtThreadSetTlsArrayAddress,
  kNtThreadIsIoPending,
  kNtThreadHideFromDebugger,
  kNtThreadInfoClass_MAX
};



/*!BEGIN libc/nt/enum/threadpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADPRIORITY_H_

#define kNtThreadBasePriorityIdle  (-15)
#define kNtThreadBasePriorityMin   (-2)
#define kNtThreadBasePriorityMax   2
#define kNtThreadBasePriorityLowrt 15

#define kNtThreadPriorityIdle         kNtThreadBasePriorityIdle
#define kNtThreadPriorityLowest       kNtThreadBasePriorityMin
#define kNtThreadPriorityBelowNormal  (kNtThreadPriorityLowest + 1)
#define kNtThreadPriorityNormal       0
#define kNtThreadPriorityAboveNormal  (kNtThreadPriorityHighest - 1)
#define kNtThreadPriorityHighest      kNtThreadBasePriorityMax
#define kNtThreadPriorityTimeCritical kNtThreadBasePriorityLowrt



/*!BEGIN libc/nt/enum/threadstate.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADSTATE_H_

#define kNtStateInitialized 0
#define kNtStateReady       1
#define kNtStateRunning     2
#define kNtStateStandby     3
#define kNtStateTerminated  4
#define kNtStateWait        5
#define kNtStateTransition  6
#define kNtStateUnknown     7



/*!BEGIN libc/nt/enum/timezoneid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TIMEZONEID_H_

#define kNtTimeZoneIdUnknown  0
#define kNtTimeZoneIdStandard 1
#define kNtTimeZoneIdDaylight 2



/*!BEGIN libc/nt/enum/tokeninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENINFORMATIONCLASS_H_

#define kNtTokenUser 1
#define kNtTokenGroups 2
#define kNtTokenPrivileges 3
#define kNtTokenOwner 4
#define kNtTokenPrimaryGroup 5
#define kNtTokenDefaultDacl 6
#define kNtTokenSource 7
#define kNtTokenType 8
#define kNtTokenImpersonationLevel 9
#define kNtTokenStatistics 10
#define kNtTokenRestrictedSids 11
#define kNtTokenSessionId 12
#define kNtTokenGroupsAndPrivileges 13
#define kNtTokenSessionReference 14
#define kNtTokenSandBoxInert 15
#define kNtTokenAuditPolicy 16
#define kNtTokenOrigin 17
#define kNtTokenInfoClass_MAX 18



/*!BEGIN libc/nt/enum/tokentype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENTYPE_H_

#define kNtTokenPrimary       1
#define kNtTokenImpersonation 2



/*!BEGIN libc/nt/enum/tpm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TPM_H_

#define kNtTpmLeftbutton      0x00000
#define kNtTpmRightbutton     0x00002
#define kNtTpmLeftalign       0x00000
#define kNtTpmCenteralign     0x00004
#define kNtTpmRightalign      0x00008
#define kNtTpmTopalign        0x00000
#define kNtTpmVcenteralign    0x00010
#define kNtTpmBottomalign     0x00020
#define kNtTpmHorizontal      0x00000
#define kNtTpmVertical        0x00040
#define kNtTpmNonotify        0x00080
#define kNtTpmReturncmd       0x00100
#define kNtTpmRecurse         0x00001
#define kNtTpmHorposanimation 0x00400
#define kNtTpmHorneganimation 0x00800
#define kNtTpmVerposanimation 0x01000
#define kNtTpmVerneganimation 0x02000
#define kNtTpmNoanimation     0x04000
#define kNtTpmLayoutrtl       0x08000
#define kNtTpmWorkarea        0x10000



/*!BEGIN libc/nt/enum/valueinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VALUEINFORMATIONCLASS_H_

#define kNtKeyValueBasicInformation          0
#define kNtKeyValueFullInformation           1
#define kNtKeyValuePartialInformation        2
#define kNtKeyValueFullInformationAlign64    3
#define kNtKeyValuePartialInformationAlign64 4



/*!BEGIN libc/nt/enum/version.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VERSION_H_

/**
 * Known versions of the New Technology executive.
 * @see IsAtLeastWindows10()
 * @see NtGetVersion()
 */
#define kNtVersionWindows10    0x0a00
#define kNtVersionWindows81    0x0603
#define kNtVersionWindows8     0x0602
#define kNtVersionWindows7     0x0601
#define kNtVersionWindowsVista 0x0600 /* intended baseline */
#define kNtVersionWindowsXp64  0x0502 /* end of the road */
#define kNtVersionWindowsXp    0x0501 /* snowball's chance */
#define kNtVersionWindows2000  0x0500 /* the golden age */
#define kNtVersionFuture       0x0b00



/*!BEGIN libc/nt/enum/vk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VK_H_

#define kNtVkLbutton                      0x01
#define kNtVkRbutton                      0x02
#define kNtVkCancel                       0x03
#define kNtVkMbutton                      0x04
#define kNtVkXbutton1                     0x05
#define kNtVkXbutton2                     0x06
#define kNtVkBack                         0x08
#define kNtVkTab                          0x09
#define kNtVkClear                        0x0C
#define kNtVkReturn                       0x0D
#define kNtVkShift                        0x10
#define kNtVkControl                      0x11
#define kNtVkMenu                         0x12 /* alt? */
#define kNtVkPause                        0x13
#define kNtVkCapital                      0x14
#define kNtVkKana                         0x15
#define kNtVkHangul                       0x15
#define kNtVkJunja                        0x17
#define kNtVkFinal                        0x18
#define kNtVkHanja                        0x19
#define kNtVkKanji                        0x19
#define kNtVkEscape                       0x1B
#define kNtVkConvert                      0x1C
#define kNtVkNonconvert                   0x1D
#define kNtVkAccept                       0x1E
#define kNtVkModechange                   0x1F
#define kNtVkSpace                        0x20
#define kNtVkPrior                        0x21 /* page up */
#define kNtVkNext                         0x22 /* page down */
#define kNtVkEnd                          0x23
#define kNtVkHome                         0x24
#define kNtVkLeft                         0x25
#define kNtVkUp                           0x26
#define kNtVkRight                        0x27
#define kNtVkDown                         0x28
#define kNtVkSelect                       0x29
#define kNtVkPrint                        0x2A
#define kNtVkExecute                      0x2B
#define kNtVkSnapshot                     0x2C
#define kNtVkInsert                       0x2D
#define kNtVkDelete                       0x2E
#define kNtVkHelp                         0x2F
#define kNtVkLwin                         0x5B
#define kNtVkRwin                         0x5C
#define kNtVkApps                         0x5D
#define kNtVkSleep                        0x5F
#define kNtVkNumpad0                      0x60
#define kNtVkNumpad1                      0x61
#define kNtVkNumpad2                      0x62
#define kNtVkNumpad3                      0x63
#define kNtVkNumpad4                      0x64
#define kNtVkNumpad5                      0x65
#define kNtVkNumpad6                      0x66
#define kNtVkNumpad7                      0x67
#define kNtVkNumpad8                      0x68
#define kNtVkNumpad9                      0x69
#define kNtVkMultiply                     0x6A
#define kNtVkAdd                          0x6B
#define kNtVkSeparator                    0x6C
#define kNtVkSubtract                     0x6D
#define kNtVkDecimal                      0x6E
#define kNtVkDivide                       0x6F
#define kNtVkF1                           0x70
#define kNtVkF2                           0x71
#define kNtVkF3                           0x72
#define kNtVkF4                           0x73
#define kNtVkF5                           0x74
#define kNtVkF6                           0x75
#define kNtVkF7                           0x76
#define kNtVkF8                           0x77
#define kNtVkF9                           0x78
#define kNtVkF10                          0x79
#define kNtVkF11                          0x7A
#define kNtVkF12                          0x7B
#define kNtVkF13                          0x7C
#define kNtVkF14                          0x7D
#define kNtVkF15                          0x7E
#define kNtVkF16                          0x7F
#define kNtVkF17                          0x80
#define kNtVkF18                          0x81
#define kNtVkF19                          0x82
#define kNtVkF20                          0x83
#define kNtVkF21                          0x84
#define kNtVkF22                          0x85
#define kNtVkF23                          0x86
#define kNtVkF24                          0x87
#define kNtVkNumlock                      0x90
#define kNtVkScroll                       0x91
#define kNtVkLshift                       0xA0
#define kNtVkRshift                       0xA1
#define kNtVkLcontrol                     0xA2
#define kNtVkRcontrol                     0xA3
#define kNtVkLmenu                        0xA4
#define kNtVkRmenu                        0xA5
#define kNtVkBrowserBack                  0xA6
#define kNtVkBrowserForward               0xA7
#define kNtVkBrowserRefresh               0xA8
#define kNtVkBrowserStop                  0xA9
#define kNtVkBrowserSearch                0xAA
#define kNtVkBrowserFavorites             0xAB
#define kNtVkBrowserHome                  0xAC
#define kNtVkVolumeMute                   0xAD
#define kNtVkVolumeDown                   0xAE
#define kNtVkVolumeUp                     0xAF
#define kNtVkMediaNextTrack               0xB0
#define kNtVkMediaPrevTrack               0xB1
#define kNtVkMediaStop                    0xB2
#define kNtVkMediaPlayPause               0xB3
#define kNtVkLaunchMail                   0xB4
#define kNtVkLaunchMediaSelect            0xB5
#define kNtVkLaunchApp1                   0xB6
#define kNtVkLaunchApp2                   0xB7
#define kNtVkOem_1                        0xBA
#define kNtVkOemPlus                      0xBB
#define kNtVkOemComma                     0xBC
#define kNtVkOemMinus                     0xBD
#define kNtVkOemPeriod                    0xBE
#define kNtVkOem_2                        0xBF
#define kNtVkOem_3                        0xC0
#define kNtVkGamepadA                     0xC3
#define kNtVkGamepadB                     0xC4
#define kNtVkGamepadX                     0xC5
#define kNtVkGamepadY                     0xC6
#define kNtVkGamepadRightShoulder         0xC7
#define kNtVkGamepadLeftShoulder          0xC8
#define kNtVkGamepadLeftTrigger           0xC9
#define kNtVkGamepadRightTrigger          0xCA
#define kNtVkGamepadDpadUp                0xCB
#define kNtVkGamepadDpadDown              0xCC
#define kNtVkGamepadDpadLeft              0xCD
#define kNtVkGamepadDpadRight             0xCE
#define kNtVkGamepadMenu                  0xCF
#define kNtVkGamepadView                  0xD0
#define kNtVkGamepadLeftThumbstickButton  0xD1
#define kNtVkGamepadRightThumbstickButton 0xD2
#define kNtVkGamepadLeftThumbstickUp      0xD3
#define kNtVkGamepadLeftThumbstickDown    0xD4
#define kNtVkGamepadLeftThumbstickRight   0xD5
#define kNtVkGamepadLeftThumbstickLeft    0xD6
#define kNtVkGamepadRightThumbstickUp     0xD7
#define kNtVkGamepadRightThumbstickDown   0xD8
#define kNtVkGamepadRightThumbstickRight  0xD9
#define kNtVkGamepadRightThumbstickLeft   0xDA
#define kNtVkOem_4                        0xDB
#define kNtVkOem_5                        0xDC
#define kNtVkOem_6                        0xDD
#define kNtVkOem_7                        0xDE
#define kNtVkOem_8                        0xDF
#define kNtVkOemAx                        0xE1
#define kNtVkOem_102                      0xE2
#define kNtVkIcoHelp                      0xE3
#define kNtVkIco_00                       0xE4
#define kNtVkProcesskey                   0xE5
#define kNtVkIcoClear                     0xE6
#define kNtVkPacket                       0xE7
#define kNtVkOemReset                     0xE9
#define kNtVkOemJump                      0xEA
#define kNtVkOemPa1                       0xEB
#define kNtVkOemPa2                       0xEC
#define kNtVkOemPa3                       0xED
#define kNtVkOemWsctrl                    0xEE
#define kNtVkOemCusel                     0xEF
#define kNtVkOemAttn                      0xF0
#define kNtVkOemFinish                    0xF1
#define kNtVkOemCopy                      0xF2
#define kNtVkOemAuto                      0xF3
#define kNtVkOemEnlw                      0xF4
#define kNtVkOemBacktab                   0xF5
#define kNtVkAttn                         0xF6
#define kNtVkCrsel                        0xF7
#define kNtVkExsel                        0xF8
#define kNtVkEreof                        0xF9
#define kNtVkPlay                         0xFA
#define kNtVkZoom                         0xFB
#define kNtVkNoname                       0xFC
#define kNtVkPa1                          0xFD
#define kNtVkOemClear                     0xFE



/*!BEGIN libc/nt/enum/wa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WA_H_

#define kNtWaInactive    0
#define kNtWaActive      1
#define kNtWaClickactive 2



/*!BEGIN libc/nt/enum/wait.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WAIT_H_

#define kNtWaitFailed    0xffffffffu
#define kNtWaitTimeout   0x00000102u
#define kNtWaitAbandoned 0x00000080u



/*!BEGIN libc/nt/enum/wm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WM_H_

#define kNtWmNull                   0x0000
#define kNtWmCreate                 0x0001
#define kNtWmDestroy                0x0002
#define kNtWmMove                   0x0003
#define kNtWmSize                   0x0005
#define kNtWmActivate               0x0006
#define kNtWmSetfocus               0x0007
#define kNtWmKillfocus              0x0008
#define kNtWmEnable                 0x000A
#define kNtWmSetredraw              0x000B
#define kNtWmSettext                0x000C
#define kNtWmGettext                0x000D
#define kNtWmGettextlength          0x000E
#define kNtWmPaint                  0x000F
#define kNtWmClose                  0x0010
#define kNtWmQueryendsession        0x0011
#define kNtWmQueryopen              0x0013
#define kNtWmEndsession             0x0016
#define kNtWmQuit                   0x0012
#define kNtWmErasebkgnd             0x0014
#define kNtWmSyscolorchange         0x0015
#define kNtWmShowwindow             0x0018
#define kNtWmWininichange           0x001A
#define kNtWmSettingchange          kNtWmWininichange
#define kNtWmDevmodechange          0x001B
#define kNtWmActivateapp            0x001C
#define kNtWmFontchange             0x001D
#define kNtWmTimechange             0x001E
#define kNtWmCancelmode             0x001F
#define kNtWmSetcursor              0x0020
#define kNtWmMouseactivate          0x0021
#define kNtWmChildactivate          0x0022
#define kNtWmQueuesync              0x0023
#define kNtWmGetminmaxinfo          0x0024
#define kNtWmPainticon              0x0026
#define kNtWmIconerasebkgnd         0x0027
#define kNtWmNextdlgctl             0x0028
#define kNtWmSpoolerstatus          0x002A
#define kNtWmDrawitem               0x002B
#define kNtWmMeasureitem            0x002C
#define kNtWmDeleteitem             0x002D
#define kNtWmVkeytoitem             0x002E
#define kNtWmChartoitem             0x002F
#define kNtWmSetfont                0x0030
#define kNtWmGetfont                0x0031
#define kNtWmSethotkey              0x0032
#define kNtWmGethotkey              0x0033
#define kNtWmQuerydragicon          0x0037
#define kNtWmCompareitem            0x0039
#define kNtWmGetobject              0x003D
#define kNtWmCompacting             0x0041
#define kNtWmWindowposchanging      0x0046
#define kNtWmWindowposchanged       0x0047
#define kNtWmPower                  0x0048
#define kNtWmCopydata               0x004A
#define kNtWmCanceljournal          0x004B
#define kNtWmNotify                 0x004E
#define kNtWmInputlangchangerequest 0x0050
#define kNtWmInputlangchange        0x0051
#define kNtWmTcard                  0x0052
#define kNtWmHelp                   0x0053
#define kNtWmUserchanged            0x0054
#define kNtWmNotifyformat           0x0055
#define kNtWmContextmenu            0x007B
#define kNtWmStylechanging          0x007C
#define kNtWmStylechanged           0x007D
#define kNtWmDisplaychange          0x007E
#define kNtWmGeticon                0x007F
#define kNtWmSeticon                0x0080
#define kNtWmNccreate               0x0081
#define kNtWmNcdestroy              0x0082
#define kNtWmNccalcsize             0x0083
#define kNtWmNchittest              0x0084
#define kNtWmNcpaint                0x0085
#define kNtWmNcactivate             0x0086
#define kNtWmGetdlgcode             0x0087
#define kNtWmNcmousemove            0x00A0
#define kNtWmNclbuttondown          0x00A1
#define kNtWmNclbuttonup            0x00A2
#define kNtWmNclbuttondblclk        0x00A3
#define kNtWmNcrbuttondown          0x00A4
#define kNtWmNcrbuttonup            0x00A5
#define kNtWmNcrbuttondblclk        0x00A6
#define kNtWmNcmbuttondown          0x00A7
#define kNtWmNcmbuttonup            0x00A8
#define kNtWmNcmbuttondblclk        0x00A9
#define kNtWmNcxbuttondown          0x00AB
#define kNtWmNcxbuttonup            0x00AC
#define kNtWmNcxbuttondblclk        0x00AD
#define kNtWmKeyfirst               0x0100
#define kNtWmKeydown                0x0100
#define kNtWmKeyup                  0x0101
#define kNtWmChar                   0x0102
#define kNtWmDeadchar               0x0103
#define kNtWmSyskeydown             0x0104
#define kNtWmSyskeyup               0x0105
#define kNtWmSyschar                0x0106
#define kNtWmSysdeadchar            0x0107
#define kNtWmUnichar                0x0109
#define kNtWmKeylast                0x0109
#define kNtWmInitdialog             0x0110
#define kNtWmCommand                0x0111
#define kNtWmSyscommand             0x0112
#define kNtWmTimer                  0x0113
#define kNtWmHscroll                0x0114
#define kNtWmVscroll                0x0115
#define kNtWmInitmenu               0x0116
#define kNtWmInitmenupopup          0x0117
#define kNtWmGesture                0x0119
#define kNtWmGesturenotify          0x011A
#define kNtWmMenuselect             0x011F
#define kNtWmMenuchar               0x0120
#define kNtWmEnteridle              0x0121
#define kNtWmMenurbuttonup          0x0122
#define kNtWmMenudrag               0x0123
#define kNtWmMenugetobject          0x0124
#define kNtWmUninitmenupopup        0x0125
#define kNtWmMenucommand            0x0126
#define kNtWmChangeuistate          0x0127
#define kNtWmUpdateuistate          0x0128
#define kNtWmQueryuistate           0x0129
#define kNtWmMousefirst             0x0200
#define kNtWmMousemove              0x0200
#define kNtWmLbuttondown            0x0201
#define kNtWmLbuttonup              0x0202
#define kNtWmLbuttondblclk          0x0203
#define kNtWmRbuttondown            0x0204
#define kNtWmRbuttonup              0x0205
#define kNtWmRbuttondblclk          0x0206
#define kNtWmMbuttondown            0x0207
#define kNtWmMbuttonup              0x0208
#define kNtWmMbuttondblclk          0x0209
#define kNtWmMousewheel             0x020A
#define kNtWmXbuttondown            0x020B
#define kNtWmXbuttonup              0x020C
#define kNtWmXbuttondblclk          0x020D
#define kNtWmMousehwheel            0x020E
#define kNtWmMouselast              0x020E
#define kNtWmParentnotify           0x0210
#define kNtWmEntermenuloop          0x0211
#define kNtWmExitmenuloop           0x0212
#define kNtWmNextmenu               0x0213
#define kNtWmSizing                 0x0214
#define kNtWmCapturechanged         0x0215
#define kNtWmMoving                 0x0216
#define kNtWmPowerbroadcast         0x0218
#define kNtWmMdicreate              0x0220
#define kNtWmMdidestroy             0x0221
#define kNtWmMdiactivate            0x0222
#define kNtWmMdirestore             0x0223
#define kNtWmMdinext                0x0224
#define kNtWmMdimaximize            0x0225
#define kNtWmMditile                0x0226
#define kNtWmMdicascade             0x0227
#define kNtWmMdiiconarrange         0x0228
#define kNtWmMdigetactive           0x0229
#define kNtWmMdisetmenu             0x0230
#define kNtWmEntersizemove          0x0231
#define kNtWmExitsizemove           0x0232
#define kNtWmDropfiles              0x0233
#define kNtWmMdirefreshmenu         0x0234
#define kNtWmCut                    0x0300
#define kNtWmCopy                   0x0301
#define kNtWmPaste                  0x0302
#define kNtWmClear                  0x0303
#define kNtWmUndo                   0x0304
#define kNtWmRenderformat           0x0305
#define kNtWmRenderallformats       0x0306
#define kNtWmDestroyclipboard       0x0307
#define kNtWmDrawclipboard          0x0308
#define kNtWmPaintclipboard         0x0309
#define kNtWmVscrollclipboard       0x030A
#define kNtWmSizeclipboard          0x030B
#define kNtWmAskcbformatname        0x030C
#define kNtWmChangecbchain          0x030D
#define kNtWmHscrollclipboard       0x030E
#define kNtWmQuerynewpalette        0x030F
#define kNtWmPaletteischanging      0x0310
#define kNtWmPalettechanged         0x0311
#define kNtWmHotkey                 0x0312



/*!BEGIN libc/nt/enum/ws.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WS_H_

#define kNtWsOverlapped   0x00000000
#define kNtWsPopup        0x80000000
#define kNtWsChild        0x40000000
#define kNtWsMinimize     0x20000000
#define kNtWsVisible      0x10000000
#define kNtWsDisabled     0x08000000
#define kNtWsClipsiblings 0x04000000
#define kNtWsClipchildren 0x02000000
#define kNtWsMaximize     0x01000000
#define kNtWsCaption      0x00C00000
#define kNtWsBorder       0x00800000
#define kNtWsDlgframe     0x00400000
#define kNtWsVscroll      0x00200000
#define kNtWsHscroll      0x00100000
#define kNtWsSysmenu      0x00080000
#define kNtWsThickframe   0x00040000
#define kNtWsGroup        0x00020000
#define kNtWsTabstop      0x00010000
#define kNtWsMinimizebox  0x00020000
#define kNtWsMaximizebox  0x00010000
#define kNtWsTiled        kNtWsOverlapped
#define kNtWsIconic       kNtWsMinimize
#define kNtWsSizebox      kNtWsThickframe
#define kNtWsTiledwindow  kNtWsOverlappedwindow
#define kNtWsOverlappedwindow                                        \
  (kNtWsOverlapped | kNtWsCaption | kNtWsSysmenu | kNtWsThickframe | \
   kNtWsMinimizebox | kNtWsMaximizebox)
#define kNtWsPopupwindow (kNtWsPopup | kNtWsBorder | kNtWsSysmenu)

#define kNtWsExDlgmodalframe       0x00000001
#define kNtWsExNoparentnotify      0x00000004
#define kNtWsExTopmost             0x00000008
#define kNtWsExAcceptfiles         0x00000010
#define kNtWsExTransparent         0x00000020
#define kNtWsExMdichild            0x00000040
#define kNtWsExToolwindow          0x00000080
#define kNtWsExWindowedge          0x00000100
#define kNtWsExClientedge          0x00000200
#define kNtWsExContexthelp         0x00000400
#define kNtWsExRight               0x00001000
#define kNtWsExLeft                0x00000000
#define kNtWsExRtlreading          0x00002000
#define kNtWsExLtrreading          0x00000000
#define kNtWsExLeftscrollbar       0x00004000
#define kNtWsExRightscrollbar      0x00000000
#define kNtWsExControlparent       0x00010000
#define kNtWsExStaticedge          0x00020000
#define kNtWsExAppwindow           0x00040000
#define kNtWsExNoinheritlayout     0x00100000
#define kNtWsExNoredirectionbitmap 0x00200000
#define kNtWsExLayoutrtl           0x00400000
#define kNtWsExComposited          0x02000000
#define kNtWsExNoactivate          0x08000000

#define kNtWsExOverlappedwindow (kNtWsExWindowedge | kNtWsExClientedge)
#define kNtWsExPalettewindow \
  (kNtWsExWindowedge | kNtWsExToolwindow | kNtWsExTopmost)



/*!BEGIN libc/nt/enum/wsa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSA_H_


/*!BEGIN libc/nt/errors.h */

#define COSMOPOLITAN_NT_ERRORS_H_

#define kNtNoError 0

#define kNtErrorInsufficientBuffer 122

#define kNtErrorSuccess                                             0
#define kNtErrorInvalidFunction                                     1 /* ENOSYS */
#define kNtErrorFileNotFound                                        2 /* ENOENT */
#define kNtErrorPathNotFound                                        3 /* ENOTDIR */
#define kNtErrorTooManyOpenFiles                                    4 /* EMFILE */
#define kNtErrorAccessDenied                                        5 /* EACCES */
#define kNtErrorInvalidHandle                                       6 /* EBADF */
#define kNtErrorArenaTrashed                                        7
#define kNtErrorNotEnoughMemory                                     8
#define kNtErrorInvalidBlock                                        9
#define kNtErrorBadEnvironment                                      10
#define kNtErrorBadFormat                                           11
#define kNtErrorInvalidAccess                                       12 /* EPERM */
#define kNtErrorInvalidData                                         13
#define kNtErrorOutofmemory                                         14 /* ENOMEM */
#define kNtErrorInvalidDrive                                        15
#define kNtErrorCurrentDirectory                                    16
#define kNtErrorNotSameDevice                                       17
#define kNtErrorNoMoreFiles                                         18
#define kNtErrorWriteProtect                                        19
#define kNtErrorBadUnit                                             20
#define kNtErrorNotReady                                            21
#define kNtErrorBadCommand                                          22
#define kNtErrorCrc                                                 23
#define kNtErrorBadLength                                           24
#define kNtErrorSeek                                                25 /* ESPIPE */
#define kNtErrorNotDosDisk                                          26 /* ENOTBLK */
#define kNtErrorSectorNotFound                                      27
#define kNtErrorOutOfPaper                                          28
#define kNtErrorWriteFault                                          29
#define kNtErrorReadFault                                           30
#define kNtErrorGenFailure                                          31
#define kNtErrorSharingViolation                                    32
#define kNtErrorLockViolation                                       33
#define kNtErrorWrongDisk                                           34
#define kNtErrorSharingBufferExceeded                               36
#define kNtErrorHandleEof                                           38 /* w/ GetOverlappedResult() */
#define kNtErrorHandleDiskFull                                      39
#define kNtErrorNotSupported                                        50
#define kNtErrorRemNotList                                          51
#define kNtErrorDupName                                             52
#define kNtErrorBadNetpath                                          53
#define kNtErrorNetworkBusy                                         54
#define kNtErrorDevNotExist                                         55
#define kNtErrorTooManyCmds                                         56
#define kNtErrorAdapHdwErr                                          57
#define kNtErrorBadNetResp                                          58
#define kNtErrorUnexpNetErr                                         59
#define kNtErrorBadRemAdap                                          60
#define kNtErrorPrintqFull                                          61
#define kNtErrorNoSpoolSpace                                        62
#define kNtErrorPrintCancelled                                      63
#define kNtErrorNetnameDeleted                                      64
#define kNtErrorNetworkAccessDenied                                 65
#define kNtErrorBadDevType                                          66
#define kNtErrorBadNetName                                          67
#define kNtErrorTooManyNames                                        68
#define kNtErrorTooManySess                                         69
#define kNtErrorSharingPaused                                       70
#define kNtErrorReqNotAccep                                         71
#define kNtErrorRedirPaused                                         72
#define kNtErrorFileExists                                          80 /* EEXIST */
#define kNtErrorCannotMake                                          82
#define kNtErrorFailI24                                             83
#define kNtErrorOutOfStructures                                     84
#define kNtErrorAlreadyAssigned                                     85
#define kNtErrorInvalidPassword                                     86
#define kNtErrorInvalidParameter                                    87 /* EINVAL */
#define kNtErrorNetWriteFault                                       88
#define kNtErrorNoProcSlots                                         89
#define kNtErrorTooManySemaphores                                   100
#define kNtErrorExclSemAlreadyOwned                                 101
#define kNtErrorSemIsSet                                            102
#define kNtErrorTooManySemRequests                                  103
#define kNtErrorInvalidAtInterruptTime                              104
#define kNtErrorSemOwnerDied                                        105 /* EOWNERDEAD */
#define kNtErrorSemUserLimit                                        106
#define kNtErrorDiskChange                                          107
#define kNtErrorDriveLocked                                         108
#define kNtErrorBrokenPipe                                          109 /* EPIPE; happens on ReadFile() too */
#define kNtErrorOpenFailed                                          110
#define kNtErrorBufferOverflow                                      111
#define kNtErrorDiskFull                                            112 /* ENOSPC */
#define kNtErrorNoMoreSearchHandles                                 113
#define kNtErrorInvalidTargetHandle                                 114 /* EBADF */
#define kNtErrorInvalidCategory                                     117 /* ENOATTR */
#define kNtErrorInvalidVerifySwitch                                 118
#define kNtErrorBadDriverLevel                                      119
#define kNtErrorCallNotImplemented                                  120
#define kNtErrorSemTimeout                                          121
#define kNtErrorInsufficientBuffer                                  122
#define kNtErrorInvalidName                                         123
#define kNtErrorInvalidLevel                                        124
#define kNtErrorNoVolumeLabel                                       125
#define kNtErrorModNotFound                                         126
#define kNtErrorProcNotFound                                        127
#define kNtErrorWaitNoChildren                                      128 /* ECHILD */
#define kNtErrorChildNotComplete                                    129
#define kNtErrorDirectAccessHandle                                  130 /* EBADF */
#define kNtErrorNegativeSeek                                        131
#define kNtErrorSeekOnDevice                                        132
#define kNtErrorIsJoinTarget                                        133
#define kNtErrorIsJoined                                            134
#define kNtErrorIsSubsted                                           135
#define kNtErrorNotJoined                                           136
#define kNtErrorNotSubsted                                          137
#define kNtErrorJoinToJoin                                          138
#define kNtErrorSubstToSubst                                        139
#define kNtErrorJoinToSubst                                         140
#define kNtErrorSubstToJoin                                         141
#define kNtErrorBusyDrive                                           142
#define kNtErrorSameDrive                                           143
#define kNtErrorDirNotRoot                                          144
#define kNtErrorDirNotEmpty                                         145
#define kNtErrorIsSubstPath                                         146
#define kNtErrorIsJoinPath                                          147
#define kNtErrorPathBusy                                            148 /* ETXTBSY */
#define kNtErrorIsSubstTarget                                       149
#define kNtErrorSystemTrace                                         150
#define kNtErrorInvalidEventCount                                   151
#define kNtErrorTooManyMuxwaiters                                   152
#define kNtErrorInvalidListFormat                                   153
#define kNtErrorLabelTooLong                                        154
#define kNtErrorTooManyTcbs                                         155
#define kNtErrorSignalRefused                                       156
#define kNtErrorDiscarded                                           157
#define kNtErrorNotLocked                                           158 /* ENOLCK */
#define kNtErrorBadThreadidAddr                                     159
#define kNtErrorBadArguments                                        160
#define kNtErrorBadPathname                                         161
#define kNtErrorSignalPending                                       162
#define kNtErrorMaxThrdsReached                                     164
#define kNtErrorLockFailed                                          167
#define kNtErrorBusy                                                170 /* EBUSY */
#define kNtErrorDeviceSupportInProgress                             171
#define kNtErrorCancelViolation                                     173
#define kNtErrorAtomicLocksNotSupported                             174
#define kNtErrorInvalidSegmentNumber                                180
#define kNtErrorInvalidOrdinal                                      182
#define kNtErrorAlreadyExists                                       183 /* EEXIST */
#define kNtErrorInvalidFlagNumber                                   186
#define kNtErrorSemNotFound                                         187
#define kNtErrorInvalidStartingCodeseg                              188
#define kNtErrorInvalidStackseg                                     189
#define kNtErrorInvalidModuletype                                   190
#define kNtErrorInvalidExeSignature                                 191
#define kNtErrorExeMarkedInvalid                                    192 /* EBADEXEC */
#define kNtErrorBadExeFormat                                        193 /* ENOEXEC */
#define kNtErrorIteratedDataExceeds_64k                             194
#define kNtErrorInvalidMinallocsize                                 195
#define kNtErrorDynlinkFromInvalidRing                              196
#define kNtErrorIoplNotEnabled                                      197
#define kNtErrorInvalidSegdpl                                       198
#define kNtErrorAutodatasegExceeds_64k                              199
#define kNtErrorRing2segMustBeMovable                               200
#define kNtErrorRelocChainXeedsSeglim                               201
#define kNtErrorInfloopInRelocChain                                 202
#define kNtErrorEnvvarNotFound                                      203
#define kNtErrorNoSignalSent                                        205
#define kNtErrorFilenameExcedRange                                  206 /* ENAMETOOLONG */
#define kNtErrorRing2StackInUse                                     207
#define kNtErrorMetaExpansionTooLong                                208
#define kNtErrorInvalidSignalNumber                                 209
#define kNtErrorThread_1Inactive                                    210
#define kNtErrorLocked                                              212
#define kNtErrorTooManyModules                                      214
#define kNtErrorNestingNotAllowed                                   215
#define kNtErrorExeMachineTypeMismatch                              216 /* EBADARCH */
#define kNtErrorExeCannotModifySignedBinary                         217
#define kNtErrorExeCannotModifyStrongSignedBinary                   218
#define kNtErrorFileCheckedOut                                      220
#define kNtErrorCheckoutRequired                                    221
#define kNtErrorBadFileType                                         222 /* EFTYPE */
#define kNtErrorFileTooLarge                                        223 /* EFBIG */
#define kNtErrorFormsAuthRequired                                   224 /* ENEEDAUTH */
#define kNtErrorVirusInfected                                       225
#define kNtErrorVirusDeleted                                        226
#define kNtErrorPipeLocal                                           229
#define kNtErrorBadPipe                                             230
#define kNtErrorPipeBusy                                            231
#define kNtErrorNoData                                              232
#define kNtErrorPipeNotConnected                                    233
#define kNtErrorMoreData                                            234
#define kNtErrorNoWorkDone                                          235
#define kNtErrorVcDisconnected                                      240
#define kNtErrorInvalidEaName                                       254
#define kNtErrorEaListInconsistent                                  255
#define kNtErrorNoMoreItems                                         259
#define kNtErrorCannotCopy                                          266
#define kNtErrorDirectory                                           267 /* EISDIR */
#define kNtErrorEasDidntFit                                         275
#define kNtErrorEaFileCorrupt                                       276
#define kNtErrorEaTableFull                                         277
#define kNtErrorInvalidEaHandle                                     278
#define kNtErrorEasNotSupported                                     282
#define kNtErrorNotOwner                                            288
#define kNtErrorTooManyPosts                                        298
#define kNtErrorPartialCopy                                         299
#define kNtErrorOplockNotGranted                                    300
#define kNtErrorInvalidOplockProtocol                               301
#define kNtErrorDiskTooFragmented                                   302
#define kNtErrorDeletePending                                       303
#define kNtErrorIncompatibleWithGlobalShortNameRegistrySetting      304
#define kNtErrorShortNamesNotEnabledOnVolume                        305
#define kNtErrorSecurityStreamIsInconsistent                        306
#define kNtErrorInvalidLockRange                                    307
#define kNtErrorImageSubsystemNotPresent                            308
#define kNtErrorNotificationGuidAlreadyDefined                      309
#define kNtErrorInvalidExceptionHandler                             310
#define kNtErrorDuplicatePrivileges                                 311
#define kNtErrorNoRangesProcessed                                   312
#define kNtErrorNotAllowedOnSystemFile                              313
#define kNtErrorDiskResourcesExhausted                              314
#define kNtErrorInvalidToken                                        315
#define kNtErrorDeviceFeatureNotSupported                           316
#define kNtErrorMrMidNotFound                                       317
#define kNtErrorScopeNotFound                                       318
#define kNtErrorUndefinedScope                                      319
#define kNtErrorInvalidCap                                          320
#define kNtErrorDeviceUnreachable                                   321
#define kNtErrorDeviceNoResources                                   322
#define kNtErrorDataChecksumError                                   323
#define kNtErrorIntermixedKernelEaOperation                         324
#define kNtErrorFileLevelTrimNotSupported                           326
#define kNtErrorOffsetAlignmentViolation                            327
#define kNtErrorInvalidFieldInParameterList                         328
#define kNtErrorOperationInProgress                                 329 /* EPROGUNAVAIL */
#define kNtErrorBadDevicePath                                       330
#define kNtErrorTooManyDescriptors                                  331 /* ENFILE */
#define kNtErrorScrubDataDisabled                                   332
#define kNtErrorNotRedundantStorage                                 333
#define kNtErrorResidentFileNotSupported                            334
#define kNtErrorCompressedFileNotSupported                          335
#define kNtErrorDirectoryNotSupported                               336
#define kNtErrorNotReadFromCopy                                     337
#define kNtErrorFtWriteFailure                                      338
#define kNtErrorFtDiScanRequired                                    339
#define kNtErrorInvalidKernelInfoVersion                            340
#define kNtErrorInvalidPepInfoVersion                               341
#define kNtErrorObjectNotExternallyBacked                           342
#define kNtErrorExternalBackingProviderUnknown                      343
#define kNtErrorCompressionNotBeneficial                            344
#define kNtErrorStorageTopologyIdMismatch                           345
#define kNtErrorBlockedByParentalControls                           346
#define kNtErrorBlockTooManyReferences                              347
#define kNtErrorMarkedToDisallowWrites                              348
#define kNtErrorEnclaveFailure                                      349
#define kNtErrorFailNoactionReboot                                  350
#define kNtErrorFailShutdown                                        351
#define kNtErrorFailRestart                                         352
#define kNtErrorMaxSessionsReached                                  353
#define kNtErrorNetworkAccessDeniedEdp                              354
#define kNtErrorDeviceHintNameBufferTooSmall                        355
#define kNtErrorEdpPolicyDeniesOperation                            356
#define kNtErrorEdpDplPolicyCantBeSatisfied                         357
#define kNtErrorCloudFileSyncRootMetadataCorrupt                    358
#define kNtErrorDeviceInMaintenance                                 359
#define kNtErrorNotSupportedOnDax                                   360
#define kNtErrorDaxMappingExists                                    361
#define kNtErrorCloudFileProviderNotRunning                         362
#define kNtErrorCloudFileMetadataCorrupt                            363
#define kNtErrorCloudFileMetadataTooLarge                           364
#define kNtErrorCloudFilePropertyBlobTooLarge                       365
#define kNtErrorCloudFilePropertyBlobChecksumMismatch               366
#define kNtErrorChildProcessBlocked                                 367
#define kNtErrorStorageLostDataPersistence                          368
#define kNtErrorFileSystemVirtualizationUnavailable                 369
#define kNtErrorFileSystemVirtualizationMetadataCorrupt             370
#define kNtErrorFileSystemVirtualizationBusy                        371
#define kNtErrorFileSystemVirtualizationProviderUnknown             372
#define kNtErrorGdiHandleLeak                                       373
#define kNtErrorCloudFileTooManyPropertyBlobs                       374
#define kNtErrorCloudFilePropertyVersionNotSupported                375
#define kNtErrorNotACloudFile                                       376
#define kNtErrorCloudFileNotInSync                                  377
#define kNtErrorCloudFileAlreadyConnected                           378
#define kNtErrorCloudFileNotSupported                               379
#define kNtErrorCloudFileInvalidRequest                             380
#define kNtErrorCloudFileReadOnlyVolume                             381
#define kNtErrorCloudFileConnectedProviderOnly                      382
#define kNtErrorCloudFileValidationFailed                           383
#define kNtErrorSmb1NotAvailable                                    384
#define kNtErrorFileSystemVirtualizationInvalidOperation            385
#define kNtErrorCloudFileAuthenticationFailed                       386
#define kNtErrorCloudFileInsufficientResources                      387
#define kNtErrorCloudFileNetworkUnavailable                         388
#define kNtErrorCloudFileUnsuccessful                               389
#define kNtErrorCloudFileNotUnderSyncRoot                           390
#define kNtErrorCloudFileInUse                                      391
#define kNtErrorCloudFilePinned                                     392
#define kNtErrorCloudFileRequestAborted                             393
#define kNtErrorCloudFilePropertyCorrupt                            394
#define kNtErrorCloudFileAccessDenied                               395
#define kNtErrorCloudFileIncompatibleHardlinks                      396
#define kNtErrorCloudFilePropertyLockConflict                       397
#define kNtErrorCloudFileRequestCanceled                            398
#define kNtErrorExternalSyskeyNotSupported                          399
#define kNtErrorThreadModeAlreadyBackground                         400
#define kNtErrorThreadModeNotBackground                             401
#define kNtErrorProcessModeAlreadyBackground                        402
#define kNtErrorProcessModeNotBackground                            403
#define kNtErrorCloudFileProviderTerminated                         404
#define kNtErrorNotACloudSyncRoot                                   405
#define kNtErrorFileProtectedUnderDpl                               406
#define kNtErrorVolumeNotClusterAligned                             407
#define kNtErrorNoPhysicallyAlignedFreeSpaceFound                   408
#define kNtErrorAppxFileNotEncrypted                                409
#define kNtErrorRwrawEncryptedFileNotEncrypted                      410
#define kNtErrorRwrawEncryptedInvalidEdatainfoFileoffset            411
#define kNtErrorRwrawEncryptedInvalidEdatainfoFilerange             412
#define kNtErrorRwrawEncryptedInvalidEdatainfoParameter             413
#define kNtErrorLinuxSubsystemNotPresent                            414
#define kNtErrorCapauthzNotDevunlocked                              450
#define kNtErrorCapauthzChangeType                                  451
#define kNtErrorCapauthzNotProvisioned                              452
#define kNtErrorCapauthzNotAuthorized                               453
#define kNtErrorCapauthzNoPolicy                                    454
#define kNtErrorCapauthzDbCorrupted                                 455
#define kNtErrorCapauthzSccdInvalidCatalog                          456
#define kNtErrorCapauthzSccdNoAuthEntity                            457
#define kNtErrorCapauthzSccdParseError                              458
#define kNtErrorCapauthzSccdDevModeRequired                         459
#define kNtErrorCapauthzSccdNoCapabilityMatch                       460
#define kNtErrorPnpQueryRemoveDeviceTimeout                         480
#define kNtErrorPnpQueryRemoveRelatedDeviceTimeout                  481
#define kNtErrorPnpQueryRemoveUnrelatedDeviceTimeout                482
#define kNtErrorDeviceHardwareError                                 483 /* EDEVERR */
#define kNtErrorInvalidAddress                                      487 /* EFAULT */
#define kNtErrorVrfCfgEnabled                                       1183
#define kNtErrorPartitionTerminating                                1184
#define kNtErrorUserProfileLoad                                     500
#define kNtErrorArithmeticOverflow                                  534 /* EOVERFLOW */
#define kNtErrorPipeConnected                                       535
#define kNtErrorPipeListening                                       536
#define kNtErrorVerifierStop                                        537
#define kNtErrorAbiosError                                          538
#define kNtErrorWx86Warning                                         539
#define kNtErrorWx86Error                                           540
#define kNtErrorTimerNotCanceled                                    541
#define kNtErrorUnwind                                              542
#define kNtErrorBadStack                                            543
#define kNtErrorInvalidUnwindTarget                                 544
#define kNtErrorInvalidPortAttributes                               545
#define kNtErrorPortMessageTooLong                                  546
#define kNtErrorInvalidQuotaLower                                   547
#define kNtErrorDeviceAlreadyAttached                               548
#define kNtErrorInstructionMisalignment                             549
#define kNtErrorProfilingNotStarted                                 550
#define kNtErrorProfilingNotStopped                                 551
#define kNtErrorCouldNotInterpret                                   552
#define kNtErrorProfilingAtLimit                                    553
#define kNtErrorCantWait                                            554
#define kNtErrorCantTerminateSelf                                   555
#define kNtErrorUnexpectedMmCreateErr                               556
#define kNtErrorUnexpectedMmMapError                                557
#define kNtErrorUnexpectedMmExtendErr                               558
#define kNtErrorBadFunctionTable                                    559
#define kNtErrorNoGuidTranslation                                   560
#define kNtErrorInvalidLdtSize                                      561
#define kNtErrorInvalidLdtOffset                                    563
#define kNtErrorInvalidLdtDescriptor                                564
#define kNtErrorTooManyThreads                                      565
#define kNtErrorThreadNotInProcess                                  566 /* ESRCH */
#define kNtErrorPagefileQuotaExceeded                               567
#define kNtErrorLogonServerConflict                                 568
#define kNtErrorSynchronizationRequired                             569
#define kNtErrorNetOpenFailed                                       570
#define kNtErrorIoPrivilegeFailed                                   571
#define kNtErrorControlCExit                                        572
#define kNtErrorMissingSystemfile                                   573
#define kNtErrorUnhandledException                                  574
#define kNtErrorAppInitFailure                                      575
#define kNtErrorPagefileCreateFailed                                576
#define kNtErrorInvalidImageHash                                    577
#define kNtErrorNoPagefile                                          578
#define kNtErrorIllegalFloatContext                                 579
#define kNtErrorNoEventPair                                         580
#define kNtErrorDomainCtrlrConfigError                              581
#define kNtErrorIllegalCharacter                                    582 /* EILSEQ */
#define kNtErrorUndefinedCharacter                                  583
#define kNtErrorFloppyVolume                                        584
#define kNtErrorBiosFailedToConnectInterrupt                        585
#define kNtErrorBackupController                                    586
#define kNtErrorMutantLimitExceeded                                 587
#define kNtErrorFsDriverRequired                                    588
#define kNtErrorCannotLoadRegistryFile                              589
#define kNtErrorDebugAttachFailed                                   590
#define kNtErrorSystemProcessTerminated                             591
#define kNtErrorDataNotAccepted                                     592
#define kNtErrorVdmHardError                                        593
#define kNtErrorDriverCancelTimeout                                 594
#define kNtErrorReplyMessageMismatch                                595 /* EPROGMISMATCH */
#define kNtErrorLostWritebehindData                                 596
#define kNtErrorClientServerParametersInvalid                       597
#define kNtErrorNotTinyStream                                       598
#define kNtErrorStackOverflowRead                                   599
#define kNtErrorConvertToLarge                                      600
#define kNtErrorFoundOutOfScope                                     601
#define kNtErrorAllocateBucket                                      602
#define kNtErrorMarshallOverflow                                    603
#define kNtErrorInvalidVariant                                      604
#define kNtErrorBadCompressionBuffer                                605
#define kNtErrorAuditFailed                                         606
#define kNtErrorTimerResolutionNotSet                               607
#define kNtErrorInsufficientLogonInfo                               608
#define kNtErrorBadDllEntrypoint                                    609
#define kNtErrorBadServiceEntrypoint                                610
#define kNtErrorIpAddressConflict1                                  611
#define kNtErrorIpAddressConflict2                                  612
#define kNtErrorRegistryQuotaLimit                                  613
#define kNtErrorNoCallbackActive                                    614
#define kNtErrorPwdTooShort                                         615
#define kNtErrorPwdTooRecent                                        616
#define kNtErrorPwdHistoryConflict                                  617
#define kNtErrorUnsupportedCompression                              618
#define kNtErrorInvalidHwProfile                                    619
#define kNtErrorInvalidPlugplayDevicePath                           620
#define kNtErrorQuotaListInconsistent                               621
#define kNtErrorEvaluationExpiration                                622
#define kNtErrorIllegalDllRelocation                                623
#define kNtErrorDllInitFailedLogoff                                 624
#define kNtErrorValidateContinue                                    625
#define kNtErrorNoMoreMatches                                       626
#define kNtErrorRangeListConflict                                   627
#define kNtErrorServerSidMismatch                                   628
#define kNtErrorCantEnableDenyOnly                                  629
#define kNtErrorFloatMultipleFaults                                 630
#define kNtErrorFloatMultipleTraps                                  631
#define kNtErrorNointerface                                         632
#define kNtErrorDriverFailedSleep                                   633
#define kNtErrorCorruptSystemFile                                   634
#define kNtErrorCommitmentMinimum                                   635
#define kNtErrorPnpRestartEnumeration                               636
#define kNtErrorSystemImageBadSignature                             637
#define kNtErrorPnpRebootRequired                                   638
#define kNtErrorInsufficientPower                                   639 /* EPWROFF */
#define kNtErrorMultipleFaultViolation                              640
#define kNtErrorSystemShutdown                                      641
#define kNtErrorPortNotSet                                          642
#define kNtErrorDsVersionCheckFailure                               643
#define kNtErrorRangeNotFound                                       644
#define kNtErrorNotSafeModeDriver                                   646
#define kNtErrorFailedDriverEntry                                   647
#define kNtErrorDeviceEnumerationError                              648
#define kNtErrorMountPointNotResolved                               649
#define kNtErrorInvalidDeviceObjectParameter                        650
#define kNtErrorMcaOccured                                          651
#define kNtErrorDriverDatabaseError                                 652
#define kNtErrorSystemHiveTooLarge                                  653
#define kNtErrorDriverFailedPriorUnload                             654
#define kNtErrorVolsnapPrepareHibernate                             655
#define kNtErrorHibernationFailure                                  656
#define kNtErrorPwdTooLong                                          657
#define kNtErrorFileSystemLimitation                                665
#define kNtErrorAssertionFailure                                    668
#define kNtErrorAcpiError                                           669
#define kNtErrorWowAssertion                                        670
#define kNtErrorPnpBadMpsTable                                      671
#define kNtErrorPnpTranslationFailed                                672
#define kNtErrorPnpIrqTranslationFailed                             673
#define kNtErrorPnpInvalidId                                        674
#define kNtErrorWakeSystemDebugger                                  675
#define kNtErrorHandlesClosed                                       676
#define kNtErrorExtraneousInformation                               677
#define kNtErrorRxactCommitNecessary                                678
#define kNtErrorMediaCheck                                          679
#define kNtErrorGuidSubstitutionMade                                680
#define kNtErrorStoppedOnSymlink                                    681
#define kNtErrorLongjump                                            682
#define kNtErrorPlugplayQueryVetoed                                 683
#define kNtErrorUnwindConsolidate                                   684
#define kNtErrorRegistryHiveRecovered                               685
#define kNtErrorDllMightBeInsecure                                  686
#define kNtErrorDllMightBeIncompatible                              687
#define kNtErrorDbgExceptionNotHandled                              688
#define kNtErrorDbgReplyLater                                       689
#define kNtErrorDbgUnableToProvideHandle                            690
#define kNtErrorDbgTerminateThread                                  691
#define kNtErrorDbgTerminateProcess                                 692
#define kNtErrorDbgControlC                                         693
#define kNtErrorDbgPrintexceptionC                                  694
#define kNtErrorDbgRipexception                                     695
#define kNtErrorDbgControlBreak                                     696
#define kNtErrorDbgCommandException                                 697
#define kNtErrorObjectNameExists                                    698
#define kNtErrorThreadWasSuspended                                  699
#define kNtErrorImageNotAtBase                                      700
#define kNtErrorRxactStateCreated                                   701
#define kNtErrorSegmentNotification                                 702
#define kNtErrorBadCurrentDirectory                                 703
#define kNtErrorFtReadRecoveryFromBackup                            704
#define kNtErrorFtWriteRecovery                                     705
#define kNtErrorImageMachineTypeMismatch                            706
#define kNtErrorReceivePartial                                      707
#define kNtErrorReceiveExpedited                                    708
#define kNtErrorReceivePartialExpedited                             709
#define kNtErrorEventDone                                           710
#define kNtErrorEventPending                                        711
#define kNtErrorCheckingFileSystem                                  712
#define kNtErrorFatalAppExit                                        713
#define kNtErrorPredefinedHandle                                    714
#define kNtErrorWasUnlocked                                         715
#define kNtErrorServiceNotification                                 716
#define kNtErrorWasLocked                                           717
#define kNtErrorLogHardError                                        718
#define kNtErrorAlreadyWin32                                        719
#define kNtErrorImageMachineTypeMismatchExe                         720
#define kNtErrorNoYieldPerformed                                    721
#define kNtErrorTimerResumeIgnored                                  722
#define kNtErrorArbitrationUnhandled                                723
#define kNtErrorCardbusNotSupported                                 724
#define kNtErrorMpProcessorMismatch                                 725
#define kNtErrorHibernated                                          726
#define kNtErrorResumeHibernation                                   727
#define kNtErrorFirmwareUpdated                                     728
#define kNtErrorDriversLeakingLockedPages                           729
#define kNtErrorWakeSystem                                          730
#define kNtErrorWait_1                                              731
#define kNtErrorWait_2                                              732
#define kNtErrorWait_3                                              733
#define kNtErrorWait_63                                             734
#define kNtErrorAbandonedWait_0                                     735
#define kNtErrorAbandonedWait_63                                    736
#define kNtErrorUserApc                                             737
#define kNtErrorKernelApc                                           738
#define kNtErrorAlerted                                             739
#define kNtErrorElevationRequired                                   740
#define kNtErrorReparse                                             741
#define kNtErrorOplockBreakInProgress                               742
#define kNtErrorVolumeMounted                                       743
#define kNtErrorRxactCommitted                                      744
#define kNtErrorNotifyCleanup                                       745
#define kNtErrorPrimaryTransportConnectFailed                       746
#define kNtErrorPageFaultTransition                                 747
#define kNtErrorPageFaultDemandZero                                 748
#define kNtErrorPageFaultCopyOnWrite                                749
#define kNtErrorPageFaultGuardPage                                  750
#define kNtErrorPageFaultPagingFile                                 751
#define kNtErrorCachePageLocked                                     752
#define kNtErrorCrashDump                                           753
#define kNtErrorBufferAllZeros                                      754
#define kNtErrorReparseObject                                       755
#define kNtErrorResourceRequirementsChanged                         756
#define kNtErrorTranslationComplete                                 757
#define kNtErrorNothingToTerminate                                  758
#define kNtErrorProcessNotInJob                                     759
#define kNtErrorProcessInJob                                        760
#define kNtErrorVolsnapHibernateReady                               761
#define kNtErrorFsfilterOpCompletedSuccessfully                     762
#define kNtErrorInterruptVectorAlreadyConnected                     763
#define kNtErrorInterruptStillConnected                             764
#define kNtErrorWaitForOplock                                       765
#define kNtErrorDbgExceptionHandled                                 766
#define kNtErrorDbgContinue                                         767
#define kNtErrorCallbackPopStack                                    768
#define kNtErrorCompressionDisabled                                 769
#define kNtErrorCantfetchbackwards                                  770
#define kNtErrorCantscrollbackwards                                 771
#define kNtErrorRowsnotreleased                                     772
#define kNtErrorBadAccessorFlags                                    773
#define kNtErrorErrorsEncountered                                   774
#define kNtErrorNotCapable                                          775
#define kNtErrorRequestOutOfSequence                                776
#define kNtErrorVersionParseError                                   777
#define kNtErrorBadstartposition                                    778
#define kNtErrorMemoryHardware                                      779
#define kNtErrorDiskRepairDisabled                                  780
#define kNtErrorInsufficientResourceForSpecifiedSharedSectionSize   781
#define kNtErrorSystemPowerstateTransition                          782
#define kNtErrorSystemPowerstateComplexTransition                   783
#define kNtErrorMcaException                                        784
#define kNtErrorAccessAuditByPolicy                                 785
#define kNtErrorAccessDisabledNoSaferUiByPolicy                     786
#define kNtErrorAbandonHiberfile                                    787
#define kNtErrorLostWritebehindDataNetworkDisconnected              788
#define kNtErrorLostWritebehindDataNetworkServerError               789
#define kNtErrorLostWritebehindDataLocalDiskError                   790
#define kNtErrorBadMcfgTable                                        791
#define kNtErrorDiskRepairRedirected                                792
#define kNtErrorDiskRepairUnsuccessful                              793
#define kNtErrorCorruptLogOverfull                                  794
#define kNtErrorCorruptLogCorrupted                                 795
#define kNtErrorCorruptLogUnavailable                               796
#define kNtErrorCorruptLogDeletedFull                               797
#define kNtErrorCorruptLogCleared                                   798
#define kNtErrorOrphanNameExhausted                                 799
#define kNtErrorOplockSwitchedToNewHandle                           800
#define kNtErrorCannotGrantRequestedOplock                          801
#define kNtErrorCannotBreakOplock                                   802
#define kNtErrorOplockHandleClosed                                  803
#define kNtErrorNoAceCondition                                      804
#define kNtErrorInvalidAceCondition                                 805
#define kNtErrorFileHandleRevoked                                   806
#define kNtErrorImageAtDifferentBase                                807
#define kNtErrorEncryptedIoNotPossible                              808
#define kNtErrorFileMetadataOptimizationInProgress                  809
#define kNtErrorQuotaActivity                                       810
#define kNtErrorHandleRevoked                                       811
#define kNtErrorCallbackInvokeInline                                812
#define kNtErrorCpuSetInvalid                                       813
#define kNtErrorEnclaveNotTerminated                                814
#define kNtErrorEnclaveViolation                                    815
#define kNtErrorEaAccessDenied                                      994
#define kNtErrorOperationAborted                                    995
#define kNtErrorIoIncomplete                                        996
#define kNtErrorIoPending                                           997
#define kNtErrorNoaccess                                            998
#define kNtErrorSwaperror                                           999
#define kNtErrorStackOverflow                                       1001
#define kNtErrorInvalidMessage                                      1002
#define kNtErrorCanNotComplete                                      1003
#define kNtErrorInvalidFlags                                        1004
#define kNtErrorUnrecognizedVolume                                  1005
#define kNtErrorFileInvalid                                         1006
#define kNtErrorFullscreenMode                                      1007
#define kNtErrorNoToken                                             1008
#define kNtErrorBaddb                                               1009
#define kNtErrorBadkey                                              1010
#define kNtErrorCantopen                                            1011
#define kNtErrorCantread                                            1012
#define kNtErrorCantwrite                                           1013
#define kNtErrorRegistryRecovered                                   1014
#define kNtErrorRegistryCorrupt                                     1015
#define kNtErrorRegistryIoFailed                                    1016
#define kNtErrorNotRegistryFile                                     1017
#define kNtErrorKeyDeleted                                          1018
#define kNtErrorNoLogSpace                                          1019
#define kNtErrorKeyHasChildren                                      1020
#define kNtErrorChildMustBeVolatile                                 1021
#define kNtErrorNotifyEnumDir                                       1022
#define kNtErrorDependentServicesRunning                            1051
#define kNtErrorInvalidServiceControl                               1052
#define kNtErrorServiceRequestTimeout                               1053
#define kNtErrorServiceNoThread                                     1054
#define kNtErrorServiceDatabaseLocked                               1055
#define kNtErrorServiceAlreadyRunning                               1056
#define kNtErrorInvalidServiceAccount                               1057
#define kNtErrorServiceDisabled                                     1058
#define kNtErrorCircularDependency                                  1059
#define kNtErrorServiceDoesNotExist                                 1060
#define kNtErrorServiceCannotAcceptCtrl                             1061
#define kNtErrorServiceNotActive                                    1062
#define kNtErrorFailedServiceControllerConnect                      1063
#define kNtErrorExceptionInService                                  1064
#define kNtErrorDatabaseDoesNotExist                                1065
#define kNtErrorServiceSpecificError                                1066
#define kNtErrorProcessAborted                                      1067
#define kNtErrorServiceDependencyFail                               1068
#define kNtErrorServiceLogonFailed                                  1069
#define kNtErrorServiceStartHang                                    1070
#define kNtErrorInvalidServiceLock                                  1071
#define kNtErrorServiceMarkedForDelete                              1072
#define kNtErrorServiceExists                                       1073
#define kNtErrorAlreadyRunningLkg                                   1074
#define kNtErrorServiceDependencyDeleted                            1075
#define kNtErrorBootAlreadyAccepted                                 1076
#define kNtErrorServiceNeverStarted                                 1077
#define kNtErrorDuplicateServiceName                                1078
#define kNtErrorDifferentServiceAccount                             1079
#define kNtErrorCannotDetectDriverFailure                           1080
#define kNtErrorCannotDetectProcessAbort                            1081
#define kNtErrorNoRecoveryProgram                                   1082
#define kNtErrorServiceNotInExe                                     1083
#define kNtErrorNotSafebootService                                  1084
#define kNtErrorEndOfMedia                                          1100
#define kNtErrorFilemarkDetected                                    1101
#define kNtErrorBeginningOfMedia                                    1102
#define kNtErrorSetmarkDetected                                     1103
#define kNtErrorNoDataDetected                                      1104
#define kNtErrorPartitionFailure                                    1105
#define kNtErrorInvalidBlockLength                                  1106
#define kNtErrorDeviceNotPartitioned                                1107
#define kNtErrorUnableToLockMedia                                   1108
#define kNtErrorUnableToUnloadMedia                                 1109
#define kNtErrorMediaChanged                                        1110
#define kNtErrorBusReset                                            1111
#define kNtErrorNoMediaInDrive                                      1112 /* ENXIO */
#define kNtErrorNoUnicodeTranslation                                1113
#define kNtErrorDllInitFailed                                       1114
#define kNtErrorShutdownInProgress                                  1115
#define kNtErrorNoShutdownInProgress                                1116
#define kNtErrorIoDevice                                            1117 /* EIO */
#define kNtErrorSerialNoDevice                                      1118 /* ENOTTY */
#define kNtErrorIrqBusy                                             1119
#define kNtErrorMoreWrites                                          1120
#define kNtErrorCounterTimeout                                      1121
#define kNtErrorFloppyIdMarkNotFound                                1122
#define kNtErrorFloppyWrongCylinder                                 1123
#define kNtErrorFloppyUnknownError                                  1124
#define kNtErrorFloppyBadRegisters                                  1125
#define kNtErrorDiskRecalibrateFailed                               1126
#define kNtErrorDiskOperationFailed                                 1127
#define kNtErrorDiskResetFailed                                     1128
#define kNtErrorEomOverflow                                         1129
#define kNtErrorNotEnoughServerMemory                               1130
#define kNtErrorPossibleDeadlock                                    1131 /* EDEADLK */
#define kNtErrorMappedAlignment                                     1132
#define kNtErrorSetPowerStateVetoed                                 1140
#define kNtErrorSetPowerStateFailed                                 1141
#define kNtErrorTooManyLinks                                        1142
#define kNtErrorOldWinVersion                                       1150
#define kNtErrorAppWrongOs                                          1151
#define kNtErrorSingleInstanceApp                                   1152
#define kNtErrorRmodeApp                                            1153
#define kNtErrorInvalidDll                                          1154
#define kNtErrorNoAssociation                                       1155
#define kNtErrorDdeFail                                             1156
#define kNtErrorDllNotFound                                         1157
#define kNtErrorNoMoreUserHandles                                   1158
#define kNtErrorMessageSyncOnly                                     1159
#define kNtErrorSourceElementEmpty                                  1160
#define kNtErrorDestinationElementFull                              1161
#define kNtErrorIllegalElementAddress                               1162
#define kNtErrorMagazineNotPresent                                  1163
#define kNtErrorDeviceReinitializationNeeded                        1164
#define kNtErrorDeviceRequiresCleaning                              1165
#define kNtErrorDeviceDoorOpen                                      1166
#define kNtErrorDeviceNotConnected                                  1167
#define kNtErrorNotFound                                            1168
#define kNtErrorNoMatch                                             1169
#define kNtErrorSetNotFound                                         1170
#define kNtErrorPointNotFound                                       1171
#define kNtErrorNoTrackingService                                   1172
#define kNtErrorNoVolumeId                                          1173
#define kNtErrorUnableToRemoveReplaced                              1175
#define kNtErrorUnableToMoveReplacement                             1176
#define kNtErrorUnableToMoveReplacement_2                           1177
#define kNtErrorJournalDeleteInProgress                             1178
#define kNtErrorJournalNotActive                                    1179
#define kNtErrorPotentialFileFound                                  1180
#define kNtErrorJournalEntryDeleted                                 1181
#define kNtErrorShutdownIsScheduled                                 1190
#define kNtErrorShutdownUsersLoggedOn                               1191
#define kNtErrorBadDevice                                           1200 /* ENODEV */
#define kNtErrorConnectionUnavail                                   1201
#define kNtErrorDeviceAlreadyRemembered                             1202
#define kNtErrorNoNetOrBadPath                                      1203
#define kNtErrorBadProvider                                         1204
#define kNtErrorCannotOpenProfile                                   1205
#define kNtErrorBadProfile                                          1206
#define kNtErrorNotContainer                                        1207
#define kNtErrorExtendedError                                       1208
#define kNtErrorInvalidGroupname                                    1209
#define kNtErrorInvalidComputername                                 1210
#define kNtErrorInvalidEventname                                    1211
#define kNtErrorInvalidDomainname                                   1212
#define kNtErrorInvalidServicename                                  1213
#define kNtErrorInvalidNetname                                      1214
#define kNtErrorInvalidSharename                                    1215
#define kNtErrorInvalidPasswordname                                 1216
#define kNtErrorInvalidMessagename                                  1217
#define kNtErrorInvalidMessagedest                                  1218
#define kNtErrorSessionCredentialConflict                           1219
#define kNtErrorRemoteSessionLimitExceeded                          1220
#define kNtErrorDupDomainname                                       1221
#define kNtErrorNoNetwork                                           1222
#define kNtErrorCancelled                                           1223 /* ECANCELED */
#define kNtErrorUserMappedFile                                      1224
#define kNtErrorConnectionRefused                                   1225
#define kNtErrorGracefulDisconnect                                  1226
#define kNtErrorAddressAlreadyAssociated                            1227
#define kNtErrorAddressNotAssociated                                1228
#define kNtErrorConnectionInvalid                                   1229
#define kNtErrorConnectionActive                                    1230
#define kNtErrorNetworkUnreachable                                  1231
#define kNtErrorHostUnreachable                                     1232
#define kNtErrorProtocolUnreachable                                 1233 /* multimapped to ENETUNREACH */
#define kNtErrorPortUnreachable                                     1234
#define kNtErrorRequestAborted                                      1235
#define kNtErrorConnectionAborted                                   1236
#define kNtErrorRetry                                               1237
#define kNtErrorConnectionCountLimit                                1238
#define kNtErrorLoginTimeRestriction                                1239
#define kNtErrorLoginWkstaRestriction                               1240
#define kNtErrorIncorrectAddress                                    1241
#define kNtErrorAlreadyRegistered                                   1242
#define kNtErrorServiceNotFound                                     1243
#define kNtErrorNotAuthenticated                                    1244 /* EAUTH */
#define kNtErrorNotLoggedOn                                         1245
#define kNtErrorContinue                                            1246
#define kNtErrorAlreadyInitialized                                  1247
#define kNtErrorNoMoreDevices                                       1248
#define kNtErrorNoSuchSite                                          1249
#define kNtErrorDomainControllerExists                              1250
#define kNtErrorOnlyIfConnected                                     1251
#define kNtErrorOverrideNochanges                                   1252
#define kNtErrorBadUserProfile                                      1253
#define kNtErrorNotSupportedOnSbs                                   1254
#define kNtErrorServerShutdownInProgress                            1255
#define kNtErrorHostDown                                            1256
#define kNtErrorNonAccountSid                                       1257
#define kNtErrorNonDomainSid                                        1258
#define kNtErrorApphelpBlock                                        1259
#define kNtErrorAccessDisabledByPolicy                              1260
#define kNtErrorRegNatConsumption                                   1261
#define kNtErrorCscshareOffline                                     1262
#define kNtErrorPkinitFailure                                       1263
#define kNtErrorSmartcardSubsystemFailure                           1264
#define kNtErrorDowngradeDetected                                   1265
#define kNtErrorMachineLocked                                       1271
#define kNtErrorSmbGuestLogonBlocked                                1272
#define kNtErrorCallbackSuppliedInvalidData                         1273
#define kNtErrorSyncForegroundRefreshRequired                       1274
#define kNtErrorDriverBlocked                                       1275
#define kNtErrorInvalidImportOfNonDll                               1276
#define kNtErrorAccessDisabledWebblade                              1277
#define kNtErrorAccessDisabledWebbladeTamper                        1278
#define kNtErrorRecoveryFailure                                     1279
#define kNtErrorAlreadyFiber                                        1280
#define kNtErrorAlreadyThread                                       1281
#define kNtErrorStackBufferOverrun                                  1282
#define kNtErrorParameterQuotaExceeded                              1283
#define kNtErrorDebuggerInactive                                    1284
#define kNtErrorDelayLoadFailed                                     1285
#define kNtErrorVdmDisallowed                                       1286
#define kNtErrorUnidentifiedError                                   1287 /* EIDRM */
#define kNtErrorInvalidCruntimeParameter                            1288
#define kNtErrorBeyondVdl                                           1289
#define kNtErrorIncompatibleServiceSidType                          1290
#define kNtErrorDriverProcessTerminated                             1291
#define kNtErrorImplementationLimit                                 1292
#define kNtErrorProcessIsProtected                                  1293
#define kNtErrorServiceNotifyClientLagging                          1294
#define kNtErrorDiskQuotaExceeded                                   1295
#define kNtErrorContentBlocked                                      1296
#define kNtErrorIncompatibleServicePrivilege                        1297
#define kNtErrorAppHang                                             1298
#define kNtErrorInvalidLabel                                        1299
#define kNtErrorNotAllAssigned                                      1300
#define kNtErrorSomeNotMapped                                       1301
#define kNtErrorNoQuotasForAccount                                  1302
#define kNtErrorLocalUserSessionKey                                 1303
#define kNtErrorNullLmPassword                                      1304
#define kNtErrorUnknownRevision                                     1305
#define kNtErrorRevisionMismatch                                    1306
#define kNtErrorInvalidOwner                                        1307
#define kNtErrorInvalidPrimaryGroup                                 1308
#define kNtErrorNoImpersonationToken                                1309
#define kNtErrorCantDisableMandatory                                1310
#define kNtErrorNoLogonServers                                      1311
#define kNtErrorNoSuchLogonSession                                  1312
#define kNtErrorNoSuchPrivilege                                     1313
#define kNtErrorPrivilegeNotHeld                                    1314
#define kNtErrorInvalidAccountName                                  1315
#define kNtErrorUserExists                                          1316
#define kNtErrorNoSuchUser                                          1317
#define kNtErrorGroupExists                                         1318
#define kNtErrorNoSuchGroup                                         1319
#define kNtErrorMemberInGroup                                       1320
#define kNtErrorMemberNotInGroup                                    1321
#define kNtErrorLastAdmin                                           1322
#define kNtErrorWrongPassword                                       1323
#define kNtErrorIllFormedPassword                                   1324
#define kNtErrorPasswordRestriction                                 1325
#define kNtErrorLogonFailure                                        1326
#define kNtErrorAccountRestriction                                  1327
#define kNtErrorInvalidLogonHours                                   1328
#define kNtErrorInvalidWorkstation                                  1329
#define kNtErrorPasswordExpired                                     1330
#define kNtErrorAccountDisabled                                     1331
#define kNtErrorNoneMapped                                          1332
#define kNtErrorTooManyLuidsRequested                               1333
#define kNtErrorLuidsExhausted                                      1334
#define kNtErrorInvalidSubAuthority                                 1335
#define kNtErrorInvalidAcl                                          1336
#define kNtErrorInvalidSid                                          1337
#define kNtErrorInvalidSecurityDescr                                1338
#define kNtErrorBadInheritanceAcl                                   1340
#define kNtErrorServerDisabled                                      1341
#define kNtErrorServerNotDisabled                                   1342
#define kNtErrorInvalidIdAuthority                                  1343
#define kNtErrorAllottedSpaceExceeded                               1344
#define kNtErrorInvalidGroupAttributes                              1345
#define kNtErrorBadImpersonationLevel                               1346
#define kNtErrorCantOpenAnonymous                                   1347
#define kNtErrorBadValidationClass                                  1348
#define kNtErrorBadTokenType                                        1349
#define kNtErrorNoSecurityOnObject                                  1350
#define kNtErrorCantAccessDomainInfo                                1351
#define kNtErrorInvalidServerState                                  1352
#define kNtErrorInvalidDomainState                                  1353
#define kNtErrorInvalidDomainRole                                   1354
#define kNtErrorNoSuchDomain                                        1355
#define kNtErrorDomainExists                                        1356
#define kNtErrorDomainLimitExceeded                                 1357
#define kNtErrorInternalDbCorruption                                1358
#define kNtErrorInternalError                                       1359
#define kNtErrorGenericNotMapped                                    1360
#define kNtErrorBadDescriptorFormat                                 1361
#define kNtErrorNotLogonProcess                                     1362
#define kNtErrorLogonSessionExists                                  1363
#define kNtErrorNoSuchPackage                                       1364
#define kNtErrorBadLogonSessionState                                1365
#define kNtErrorLogonSessionCollision                               1366
#define kNtErrorInvalidLogonType                                    1367
#define kNtErrorCannotImpersonate                                   1368
#define kNtErrorRxactInvalidState                                   1369
#define kNtErrorRxactCommitFailure                                  1370
#define kNtErrorSpecialAccount                                      1371
#define kNtErrorSpecialGroup                                        1372
#define kNtErrorSpecialUser                                         1373
#define kNtErrorMembersPrimaryGroup                                 1374
#define kNtErrorTokenAlreadyInUse                                   1375
#define kNtErrorNoSuchAlias                                         1376
#define kNtErrorMemberNotInAlias                                    1377
#define kNtErrorMemberInAlias                                       1378
#define kNtErrorAliasExists                                         1379
#define kNtErrorLogonNotGranted                                     1380
#define kNtErrorTooManySecrets                                      1381
#define kNtErrorSecretTooLong                                       1382
#define kNtErrorInternalDbError                                     1383
#define kNtErrorTooManyContextIds                                   1384
#define kNtErrorLogonTypeNotGranted                                 1385
#define kNtErrorNtCrossEncryptionRequired                           1386
#define kNtErrorNoSuchMember                                        1387
#define kNtErrorInvalidMember                                       1388
#define kNtErrorTooManySids                                         1389
#define kNtErrorLmCrossEncryptionRequired                           1390
#define kNtErrorNoInheritance                                       1391
#define kNtErrorFileCorrupt                                         1392
#define kNtErrorDiskCorrupt                                         1393
#define kNtErrorNoUserSessionKey                                    1394
#define kNtErrorLicenseQuotaExceeded                                1395
#define kNtErrorWrongTargetName                                     1396
#define kNtErrorMutualAuthFailed                                    1397
#define kNtErrorTimeSkew                                            1398
#define kNtErrorCurrentDomainNotAllowed                             1399
#define kNtErrorInvalidWindowHandle                                 1400
#define kNtErrorInvalidMenuHandle                                   1401
#define kNtErrorInvalidCursorHandle                                 1402
#define kNtErrorInvalidAccelHandle                                  1403
#define kNtErrorInvalidHookHandle                                   1404
#define kNtErrorInvalidDwpHandle                                    1405
#define kNtErrorTlwWithWschild                                      1406
#define kNtErrorCannotFindWndClass                                  1407
#define kNtErrorWindowOfOtherThread                                 1408
#define kNtErrorHotkeyAlreadyRegistered                             1409
#define kNtErrorClassAlreadyExists                                  1410
#define kNtErrorClassDoesNotExist                                   1411
#define kNtErrorClassHasWindows                                     1412
#define kNtErrorInvalidIndex                                        1413
#define kNtErrorInvalidIconHandle                                   1414
#define kNtErrorPrivateDialogIndex                                  1415
#define kNtErrorListboxIdNotFound                                   1416
#define kNtErrorNoWildcardCharacters                                1417
#define kNtErrorClipboardNotOpen                                    1418
#define kNtErrorHotkeyNotRegistered                                 1419
#define kNtErrorWindowNotDialog                                     1420
#define kNtErrorControlIdNotFound                                   1421
#define kNtErrorInvalidComboboxMessage                              1422
#define kNtErrorWindowNotCombobox                                   1423
#define kNtErrorInvalidEditHeight                                   1424
#define kNtErrorDcNotFound                                          1425
#define kNtErrorInvalidHookFilter                                   1426
#define kNtErrorInvalidFilterProc                                   1427
#define kNtErrorHookNeedsHmod                                       1428
#define kNtErrorGlobalOnlyHook                                      1429
#define kNtErrorJournalHookSet                                      1430
#define kNtErrorHookNotInstalled                                    1431
#define kNtErrorInvalidLbMessage                                    1432
#define kNtErrorSetcountOnBadLb                                     1433
#define kNtErrorLbWithoutTabstops                                   1434
#define kNtErrorDestroyObjectOfOtherThread                          1435
#define kNtErrorChildWindowMenu                                     1436
#define kNtErrorNoSystemMenu                                        1437
#define kNtErrorInvalidMsgboxStyle                                  1438
#define kNtErrorInvalidSpiValue                                     1439
#define kNtErrorScreenAlreadyLocked                                 1440
#define kNtErrorHwndsHaveDiffParent                                 1441
#define kNtErrorNotChildWindow                                      1442
#define kNtErrorInvalidGwCommand                                    1443
#define kNtErrorInvalidThreadId                                     1444
#define kNtErrorNonMdichildWindow                                   1445
#define kNtErrorPopupAlreadyActive                                  1446
#define kNtErrorNoScrollbars                                        1447
#define kNtErrorInvalidScrollbarRange                               1448
#define kNtErrorInvalidShowwinCommand                               1449
#define kNtErrorNoSystemResources                                   1450
#define kNtErrorNonpagedSystemResources                             1451
#define kNtErrorPagedSystemResources                                1452
#define kNtErrorWorkingSetQuota                                     1453
#define kNtErrorPagefileQuota                                       1454
#define kNtErrorCommitmentLimit                                     1455
#define kNtErrorMenuItemNotFound                                    1456
#define kNtErrorInvalidKeyboardHandle                               1457
#define kNtErrorHookTypeNotAllowed                                  1458
#define kNtErrorRequiresInteractiveWindowstation                    1459
#define kNtErrorTimeout                                             1460 /* ETIMEDOUT */
#define kNtErrorInvalidMonitorHandle                                1461
#define kNtErrorIncorrectSize                                       1462
#define kNtErrorSymlinkClassDisabled                                1463
#define kNtErrorSymlinkNotSupported                                 1464
#define kNtErrorXmlParseError                                       1465
#define kNtErrorXmldsigError                                        1466
#define kNtErrorRestartApplication                                  1467
#define kNtErrorWrongCompartment                                    1468
#define kNtErrorAuthipFailure                                       1469
#define kNtErrorNoNvramResources                                    1470
#define kNtErrorNotGuiProcess                                       1471
#define kNtErrorEventlogFileCorrupt                                 1500
#define kNtErrorEventlogCantStart                                   1501
#define kNtErrorLogFileFull                                         1502
#define kNtErrorEventlogFileChanged                                 1503
#define kNtErrorContainerAssigned                                   1504
#define kNtErrorJobNoContainer                                      1505
#define kNtErrorInvalidTaskName                                     1550
#define kNtErrorInvalidTaskIndex                                    1551
#define kNtErrorThreadAlreadyInTask                                 1552
#define kNtErrorInstallServiceFailure                               1601
#define kNtErrorInstallUserexit                                     1602
#define kNtErrorInstallFailure                                      1603
#define kNtErrorInstallSuspend                                      1604
#define kNtErrorUnknownProduct                                      1605
#define kNtErrorUnknownFeature                                      1606
#define kNtErrorUnknownComponent                                    1607
#define kNtErrorUnknownProperty                                     1608
#define kNtErrorInvalidHandleState                                  1609
#define kNtErrorBadConfiguration                                    1610
#define kNtErrorIndexAbsent                                         1611
#define kNtErrorInstallSourceAbsent                                 1612
#define kNtErrorInstallPackageVersion                               1613
#define kNtErrorProductUninstalled                                  1614
#define kNtErrorBadQuerySyntax                                      1615
#define kNtErrorInvalidField                                        1616
#define kNtErrorDeviceRemoved                                       1617
#define kNtErrorInstallAlreadyRunning                               1618
#define kNtErrorInstallPackageOpenFailed                            1619
#define kNtErrorInstallPackageInvalid                               1620
#define kNtErrorInstallUiFailure                                    1621
#define kNtErrorInstallLogFailure                                   1622
#define kNtErrorInstallLanguageUnsupported                          1623
#define kNtErrorInstallTransformFailure                             1624
#define kNtErrorInstallPackageRejected                              1625
#define kNtErrorFunctionNotCalled                                   1626 /* EBADRPC */
#define kNtErrorFunctionFailed                                      1627 /* ERPCMISMATCH */
#define kNtErrorInvalidTable                                        1628
#define kNtErrorDatatypeMismatch                                    1629
#define kNtErrorUnsupportedType                                     1630
#define kNtErrorCreateFailed                                        1631
#define kNtErrorInstallTempUnwritable                               1632
#define kNtErrorInstallPlatformUnsupported                          1633
#define kNtErrorInstallNotused                                      1634
#define kNtErrorPatchPackageOpenFailed                              1635
#define kNtErrorPatchPackageInvalid                                 1636
#define kNtErrorPatchPackageUnsupported                             1637
#define kNtErrorProductVersion                                      1638
#define kNtErrorInvalidCommandLine                                  1639 /* E2BIG */
#define kNtErrorInstallRemoteDisallowed                             1640
#define kNtErrorSuccessRebootInitiated                              1641
#define kNtErrorPatchTargetNotFound                                 1642
#define kNtErrorPatchPackageRejected                                1643
#define kNtErrorInstallTransformRejected                            1644
#define kNtErrorInstallRemoteProhibited                             1645
#define kNtErrorPatchRemovalUnsupported                             1646
#define kNtErrorUnknownPatch                                        1647
#define kNtErrorPatchNoSequence                                     1648
#define kNtErrorPatchRemovalDisallowed                              1649
#define kNtErrorInvalidPatchXml                                     1650
#define kNtErrorPatchManagedAdvertisedProduct                       1651
#define kNtErrorInstallServiceSafeboot                              1652
#define kNtErrorFailFastException                                   1653
#define kNtErrorInstallRejected                                     1654
#define kNtErrorDynamicCodeBlocked                                  1655
#define kNtErrorNotSameObject                                       1656
#define kNtErrorStrictCfgViolation                                  1657
#define kNtErrorSetContextDenied                                    1660
#define kNtErrorCrossPartitionViolation                             1661
#define kNtErrorInvalidUserBuffer                                   1784
#define kNtErrorUnrecognizedMedia                                   1785
#define kNtErrorNoTrustLsaSecret                                    1786
#define kNtErrorNoTrustSamAccount                                   1787
#define kNtErrorTrustedDomainFailure                                1788
#define kNtErrorTrustedRelationshipFailure                          1789
#define kNtErrorTrustFailure                                        1790
#define kNtErrorNetlogonNotStarted                                  1792
#define kNtErrorAccountExpired                                      1793
#define kNtErrorRedirectorHasOpenHandles                            1794
#define kNtErrorPrinterDriverAlreadyInstalled                       1795
#define kNtErrorUnknownPort                                         1796
#define kNtErrorUnknownPrinterDriver                                1797
#define kNtErrorUnknownPrintprocessor                               1798
#define kNtErrorInvalidSeparatorFile                                1799
#define kNtErrorInvalidPriority                                     1800
#define kNtErrorInvalidPrinterName                                  1801
#define kNtErrorPrinterAlreadyExists                                1802
#define kNtErrorInvalidPrinterCommand                               1803
#define kNtErrorInvalidDatatype                                     1804
#define kNtErrorInvalidEnvironment                                  1805
#define kNtErrorNologonInterdomainTrustAccount                      1807
#define kNtErrorNologonWorkstationTrustAccount                      1808
#define kNtErrorNologonServerTrustAccount                           1809
#define kNtErrorDomainTrustInconsistent                             1810
#define kNtErrorServerHasOpenHandles                                1811
#define kNtErrorResourceDataNotFound                                1812
#define kNtErrorResourceTypeNotFound                                1813
#define kNtErrorResourceNameNotFound                                1814
#define kNtErrorResourceLangNotFound                                1815
#define kNtErrorNotEnoughQuota                                      1816 /* EDQUOT */
#define kNtErrorInvalidTime                                         1901
#define kNtErrorInvalidFormName                                     1902
#define kNtErrorInvalidFormSize                                     1903
#define kNtErrorAlreadyWaiting                                      1904
#define kNtErrorPrinterDeleted                                      1905
#define kNtErrorInvalidPrinterState                                 1906
#define kNtErrorPasswordMustChange                                  1907
#define kNtErrorDomainControllerNotFound                            1908
#define kNtErrorAccountLockedOut                                    1909
#define kNtErrorNoSitename                                          1919
#define kNtErrorCantAccessFile                                      1920
#define kNtErrorCantResolveFilename                                 1921
#define kNtErrorKmDriverBlocked                                     1930
#define kNtErrorContextExpired                                      1931
#define kNtErrorPerUserTrustQuotaExceeded                           1932
#define kNtErrorAllUserTrustQuotaExceeded                           1933
#define kNtErrorUserDeleteTrustQuotaExceeded                        1934
#define kNtErrorAuthenticationFirewallFailed                        1935
#define kNtErrorRemotePrintConnectionsBlocked                       1936
#define kNtErrorNtlmBlocked                                         1937
#define kNtErrorPasswordChangeRequired                              1938
#define kNtErrorLostModeLogonRestriction                            1939
#define kNtErrorInvalidPixelFormat                                  2000
#define kNtErrorBadDriver                                           2001
#define kNtErrorInvalidWindowStyle                                  2002
#define kNtErrorMetafileNotSupported                                2003
#define kNtErrorTransformNotSupported                               2004
#define kNtErrorClippingNotSupported                                2005
#define kNtErrorInvalidCmm                                          2010
#define kNtErrorInvalidProfile                                      2011
#define kNtErrorTagNotFound                                         2012
#define kNtErrorTagNotPresent                                       2013
#define kNtErrorDuplicateTag                                        2014
#define kNtErrorProfileNotAssociatedWithDevice                      2015
#define kNtErrorProfileNotFound                                     2016
#define kNtErrorInvalidColorspace                                   2017
#define kNtErrorIcmNotEnabled                                       2018
#define kNtErrorDeletingIcmXform                                    2019
#define kNtErrorInvalidTransform                                    2020
#define kNtErrorColorspaceMismatch                                  2021
#define kNtErrorInvalidColorindex                                   2022
#define kNtErrorProfileDoesNotMatchDevice                           2023
#define kNtErrorConnectedOtherPassword                              2108
#define kNtErrorConnectedOtherPasswordDefault                       2109
#define kNtErrorBadUsername                                         2202
#define kNtErrorNotConnected                                        2250
#define kNtErrorOpenFiles                                           2401
#define kNtErrorActiveConnections                                   2402
#define kNtErrorDeviceInUse                                         2404
#define kNtErrorUnknownPrintMonitor                                 3000
#define kNtErrorPrinterDriverInUse                                  3001
#define kNtErrorSpoolFileNotFound                                   3002
#define kNtErrorSplNoStartdoc                                       3003
#define kNtErrorSplNoAddjob                                         3004
#define kNtErrorPrintProcessorAlreadyInstalled                      3005
#define kNtErrorPrintMonitorAlreadyInstalled                        3006
#define kNtErrorInvalidPrintMonitor                                 3007
#define kNtErrorPrintMonitorInUse                                   3008
#define kNtErrorPrinterHasJobsQueued                                3009
#define kNtErrorSuccessRebootRequired                               3010
#define kNtErrorSuccessRestartRequired                              3011
#define kNtErrorPrinterNotFound                                     3012
#define kNtErrorPrinterDriverWarned                                 3013
#define kNtErrorPrinterDriverBlocked                                3014
#define kNtErrorPrinterDriverPackageInUse                           3015
#define kNtErrorCoreDriverPackageNotFound                           3016
#define kNtErrorFailRebootRequired                                  3017
#define kNtErrorFailRebootInitiated                                 3018
#define kNtErrorPrinterDriverDownloadNeeded                         3019
#define kNtErrorPrintJobRestartRequired                             3020
#define kNtErrorInvalidPrinterDriverManifest                        3021
#define kNtErrorPrinterNotShareable                                 3022
#define kNtErrorRequestPaused                                       3050
#define kNtErrorAppexecConditionNotSatisfied                        3060
#define kNtErrorAppexecHandleInvalidated                            3061
#define kNtErrorAppexecInvalidHostGeneration                        3062
#define kNtErrorAppexecUnexpectedProcessRegistration                3063
#define kNtErrorAppexecInvalidHostState                             3064
#define kNtErrorAppexecNoDonor                                      3065
#define kNtErrorAppexecHostIdMismatch                               3066
#define kNtErrorIoReissueAsCached                                   3950
#define kNtErrorWinsInternal                                        4000
#define kNtErrorCanNotDelLocalWins                                  4001
#define kNtErrorStaticInit                                          4002
#define kNtErrorIncBackup                                           4003
#define kNtErrorFullBackup                                          4004
#define kNtErrorRecNonExistent                                      4005
#define kNtErrorRplNotAllowed                                       4006
#define kNtErrorDhcpAddressConflict                                 4100
#define kNtErrorWmiGuidNotFound                                     4200
#define kNtErrorWmiInstanceNotFound                                 4201
#define kNtErrorWmiItemidNotFound                                   4202
#define kNtErrorWmiTryAgain                                         4203
#define kNtErrorWmiDpNotFound                                       4204
#define kNtErrorWmiUnresolvedInstanceRef                            4205
#define kNtErrorWmiAlreadyEnabled                                   4206
#define kNtErrorWmiGuidDisconnected                                 4207
#define kNtErrorWmiServerUnavailable                                4208
#define kNtErrorWmiDpFailed                                         4209
#define kNtErrorWmiInvalidMof                                       4210
#define kNtErrorWmiInvalidReginfo                                   4211
#define kNtErrorWmiAlreadyDisabled                                  4212
#define kNtErrorWmiReadOnly                                         4213
#define kNtErrorWmiSetFailure                                       4214
#define kNtErrorNotAppcontainer                                     4250
#define kNtErrorAppcontainerRequired                                4251
#define kNtErrorNotSupportedInAppcontainer                          4252
#define kNtErrorInvalidPackageSidLength                             4253
#define kNtErrorInvalidMedia                                        4300
#define kNtErrorInvalidLibrary                                      4301
#define kNtErrorInvalidMediaPool                                    4302
#define kNtErrorDriveMediaMismatch                                  4303
#define kNtErrorMediaOffline                                        4304
#define kNtErrorLibraryOffline                                      4305
#define kNtErrorEmpty                                               4306 /* ENOMSG */
#define kNtErrorNotEmpty                                            4307
#define kNtErrorMediaUnavailable                                    4308
#define kNtErrorResourceDisabled                                    4309
#define kNtErrorInvalidCleaner                                      4310
#define kNtErrorUnableToClean                                       4311
#define kNtErrorObjectNotFound                                      4312
#define kNtErrorDatabaseFailure                                     4313
#define kNtErrorDatabaseFull                                        4314
#define kNtErrorMediaIncompatible                                   4315
#define kNtErrorResourceNotPresent                                  4316
#define kNtErrorInvalidOperation                                    4317
#define kNtErrorMediaNotAvailable                                   4318
#define kNtErrorDeviceNotAvailable                                  4319
#define kNtErrorRequestRefused                                      4320
#define kNtErrorInvalidDriveObject                                  4321
#define kNtErrorLibraryFull                                         4322
#define kNtErrorMediumNotAccessible                                 4323
#define kNtErrorUnableToLoadMedium                                  4324
#define kNtErrorUnableToInventoryDrive                              4325
#define kNtErrorUnableToInventorySlot                               4326
#define kNtErrorUnableToInventoryTransport                          4327
#define kNtErrorTransportFull                                       4328
#define kNtErrorControllingIeport                                   4329
#define kNtErrorUnableToEjectMountedMedia                           4330
#define kNtErrorCleanerSlotSet                                      4331
#define kNtErrorCleanerSlotNotSet                                   4332
#define kNtErrorCleanerCartridgeSpent                               4333
#define kNtErrorUnexpectedOmid                                      4334
#define kNtErrorCantDeleteLastItem                                  4335
#define kNtErrorMessageExceedsMaxSize                               4336
#define kNtErrorVolumeContainsSysFiles                              4337
#define kNtErrorIndigenousType                                      4338
#define kNtErrorNoSupportingDrives                                  4339
#define kNtErrorCleanerCartridgeInstalled                           4340
#define kNtErrorIeportFull                                          4341
#define kNtErrorFileOffline                                         4350
#define kNtErrorRemoteStorageNotActive                              4351
#define kNtErrorRemoteStorageMediaError                             4352
#define kNtErrorNotAReparsePoint                                    4390
#define kNtErrorReparseAttributeConflict                            4391
#define kNtErrorInvalidReparseData                                  4392
#define kNtErrorReparseTagInvalid                                   4393
#define kNtErrorReparseTagMismatch                                  4394
#define kNtErrorReparsePointEncountered                             4395
#define kNtErrorAppDataNotFound                                     4400
#define kNtErrorAppDataExpired                                      4401
#define kNtErrorAppDataCorrupt                                      4402
#define kNtErrorAppDataLimitExceeded                                4403
#define kNtErrorAppDataRebootRequired                               4404
#define kNtErrorSecurebootRollbackDetected                          4420
#define kNtErrorSecurebootPolicyViolation                           4421
#define kNtErrorSecurebootInvalidPolicy                             4422
#define kNtErrorSecurebootPolicyPublisherNotFound                   4423
#define kNtErrorSecurebootPolicyNotSigned                           4424
#define kNtErrorSecurebootNotEnabled                                4425
#define kNtErrorSecurebootFileReplaced                              4426
#define kNtErrorSecurebootPolicyNotAuthorized                       4427
#define kNtErrorSecurebootPolicyUnknown                             4428
#define kNtErrorSecurebootPolicyMissingAntirollbackversion          4429
#define kNtErrorSecurebootPlatformIdMismatch                        4430
#define kNtErrorSecurebootPolicyRollbackDetected                    4431
#define kNtErrorSecurebootPolicyUpgradeMismatch                     4432
#define kNtErrorSecurebootRequiredPolicyFileMissing                 4433
#define kNtErrorSecurebootNotBasePolicy                             4434
#define kNtErrorSecurebootNotSupplementalPolicy                     4435
#define kNtErrorOffloadReadFltNotSupported                          4440
#define kNtErrorOffloadWriteFltNotSupported                         4441
#define kNtErrorOffloadReadFileNotSupported                         4442
#define kNtErrorOffloadWriteFileNotSupported                        4443
#define kNtErrorAlreadyHasStreamId                                  4444
#define kNtErrorSmrGarbageCollectionRequired                        4445
#define kNtErrorWofWimHeaderCorrupt                                 4446
#define kNtErrorWofWimResourceTableCorrupt                          4447
#define kNtErrorWofFileResourceTableCorrupt                         4448
#define kNtErrorVolumeNotSisEnabled                                 4500
#define kNtErrorSystemIntegrityRollbackDetected                     4550
#define kNtErrorSystemIntegrityPolicyViolation                      4551
#define kNtErrorSystemIntegrityInvalidPolicy                        4552
#define kNtErrorSystemIntegrityPolicyNotSigned                      4553
#define kNtErrorVsmNotInitialized                                   4560
#define kNtErrorVsmDmaProtectionNotInUse                            4561
#define kNtErrorPlatformManifestNotAuthorized                       4570
#define kNtErrorPlatformManifestInvalid                             4571
#define kNtErrorPlatformManifestFileNotAuthorized                   4572
#define kNtErrorPlatformManifestCatalogNotAuthorized                4573
#define kNtErrorPlatformManifestBinaryIdNotFound                    4574
#define kNtErrorPlatformManifestNotActive                           4575
#define kNtErrorPlatformManifestNotSigned                           4576
#define kNtErrorDependentResourceExists                             5001
#define kNtErrorDependencyNotFound                                  5002
#define kNtErrorDependencyAlreadyExists                             5003
#define kNtErrorResourceNotOnline                                   5004
#define kNtErrorHostNodeNotAvailable                                5005
#define kNtErrorResourceNotAvailable                                5006
#define kNtErrorResourceNotFound                                    5007
#define kNtErrorShutdownCluster                                     5008
#define kNtErrorCantEvictActiveNode                                 5009
#define kNtErrorObjectAlreadyExists                                 5010
#define kNtErrorObjectInList                                        5011
#define kNtErrorGroupNotAvailable                                   5012
#define kNtErrorGroupNotFound                                       5013
#define kNtErrorGroupNotOnline                                      5014
#define kNtErrorHostNodeNotResourceOwner                            5015
#define kNtErrorHostNodeNotGroupOwner                               5016
#define kNtErrorResmonCreateFailed                                  5017
#define kNtErrorResmonOnlineFailed                                  5018
#define kNtErrorResourceOnline                                      5019
#define kNtErrorQuorumResource                                      5020
#define kNtErrorNotQuorumCapable                                    5021
#define kNtErrorClusterShuttingDown                                 5022
#define kNtErrorInvalidState                                        5023
#define kNtErrorResourcePropertiesStored                            5024
#define kNtErrorNotQuorumClass                                      5025
#define kNtErrorCoreResource                                        5026
#define kNtErrorQuorumResourceOnlineFailed                          5027
#define kNtErrorQuorumlogOpenFailed                                 5028
#define kNtErrorClusterlogCorrupt                                   5029
#define kNtErrorClusterlogRecordExceedsMaxsize                      5030
#define kNtErrorClusterlogExceedsMaxsize                            5031
#define kNtErrorClusterlogChkpointNotFound                          5032
#define kNtErrorClusterlogNotEnoughSpace                            5033
#define kNtErrorQuorumOwnerAlive                                    5034
#define kNtErrorNetworkNotAvailable                                 5035
#define kNtErrorNodeNotAvailable                                    5036
#define kNtErrorAllNodesNotAvailable                                5037
#define kNtErrorResourceFailed                                      5038
#define kNtErrorClusterInvalidNode                                  5039
#define kNtErrorClusterNodeExists                                   5040
#define kNtErrorClusterJoinInProgress                               5041
#define kNtErrorClusterNodeNotFound                                 5042
#define kNtErrorClusterLocalNodeNotFound                            5043
#define kNtErrorClusterNetworkExists                                5044
#define kNtErrorClusterNetworkNotFound                              5045
#define kNtErrorClusterNetinterfaceExists                           5046
#define kNtErrorClusterNetinterfaceNotFound                         5047
#define kNtErrorClusterInvalidRequest                               5048
#define kNtErrorClusterInvalidNetworkProvider                       5049
#define kNtErrorClusterNodeDown                                     5050
#define kNtErrorClusterNodeUnreachable                              5051
#define kNtErrorClusterNodeNotMember                                5052
#define kNtErrorClusterJoinNotInProgress                            5053
#define kNtErrorClusterInvalidNetwork                               5054
#define kNtErrorClusterNodeUp                                       5056
#define kNtErrorClusterIpaddrInUse                                  5057
#define kNtErrorClusterNodeNotPaused                                5058
#define kNtErrorClusterNoSecurityContext                            5059
#define kNtErrorClusterNetworkNotInternal                           5060
#define kNtErrorClusterNodeAlreadyUp                                5061
#define kNtErrorClusterNodeAlreadyDown                              5062
#define kNtErrorClusterNetworkAlreadyOnline                         5063
#define kNtErrorClusterNetworkAlreadyOffline                        5064
#define kNtErrorClusterNodeAlreadyMember                            5065
#define kNtErrorClusterLastInternalNetwork                          5066
#define kNtErrorClusterNetworkHasDependents                         5067
#define kNtErrorInvalidOperationOnQuorum                            5068
#define kNtErrorDependencyNotAllowed                                5069
#define kNtErrorClusterNodePaused                                   5070
#define kNtErrorNodeCantHostResource                                5071
#define kNtErrorClusterNodeNotReady                                 5072
#define kNtErrorClusterNodeShuttingDown                             5073
#define kNtErrorClusterJoinAborted                                  5074
#define kNtErrorClusterIncompatibleVersions                         5075
#define kNtErrorClusterMaxnumOfResourcesExceeded                    5076
#define kNtErrorClusterSystemConfigChanged                          5077
#define kNtErrorClusterResourceTypeNotFound                         5078
#define kNtErrorClusterRestypeNotSupported                          5079
#define kNtErrorClusterResnameNotFound                              5080
#define kNtErrorClusterNoRpcPackagesRegistered                      5081
#define kNtErrorClusterOwnerNotInPreflist                           5082
#define kNtErrorClusterDatabaseSeqmismatch                          5083
#define kNtErrorResmonInvalidState                                  5084
#define kNtErrorClusterGumNotLocker                                 5085
#define kNtErrorQuorumDiskNotFound                                  5086
#define kNtErrorDatabaseBackupCorrupt                               5087
#define kNtErrorClusterNodeAlreadyHasDfsRoot                        5088
#define kNtErrorResourcePropertyUnchangeable                        5089
#define kNtErrorNoAdminAccessPoint                                  5090
#define kNtErrorClusterMembershipInvalidState                       5890
#define kNtErrorClusterQuorumlogNotFound                            5891
#define kNtErrorClusterMembershipHalt                               5892
#define kNtErrorClusterInstanceIdMismatch                           5893
#define kNtErrorClusterNetworkNotFoundForIp                         5894
#define kNtErrorClusterPropertyDataTypeMismatch                     5895
#define kNtErrorClusterEvictWithoutCleanup                          5896
#define kNtErrorClusterParameterMismatch                            5897
#define kNtErrorNodeCannotBeClustered                               5898
#define kNtErrorClusterWrongOsVersion                               5899
#define kNtErrorClusterCantCreateDupClusterName                     5900
#define kNtErrorCluscfgAlreadyCommitted                             5901
#define kNtErrorCluscfgRollbackFailed                               5902
#define kNtErrorCluscfgSystemDiskDriveLetterConflict                5903
#define kNtErrorClusterOldVersion                                   5904
#define kNtErrorClusterMismatchedComputerAcctName                   5905
#define kNtErrorClusterNoNetAdapters                                5906
#define kNtErrorClusterPoisoned                                     5907
#define kNtErrorClusterGroupMoving                                  5908
#define kNtErrorClusterResourceTypeBusy                             5909
#define kNtErrorResourceCallTimedOut                                5910
#define kNtErrorInvalidClusterIpv6Address                           5911
#define kNtErrorClusterInternalInvalidFunction                      5912
#define kNtErrorClusterParameterOutOfBounds                         5913
#define kNtErrorClusterPartialSend                                  5914
#define kNtErrorClusterRegistryInvalidFunction                      5915
#define kNtErrorClusterInvalidStringTermination                     5916
#define kNtErrorClusterInvalidStringFormat                          5917
#define kNtErrorClusterDatabaseTransactionInProgress                5918
#define kNtErrorClusterDatabaseTransactionNotInProgress             5919
#define kNtErrorClusterNullData                                     5920
#define kNtErrorClusterPartialRead                                  5921
#define kNtErrorClusterPartialWrite                                 5922
#define kNtErrorClusterCantDeserializeData                          5923
#define kNtErrorDependentResourcePropertyConflict                   5924
#define kNtErrorClusterNoQuorum                                     5925
#define kNtErrorClusterInvalidIpv6Network                           5926
#define kNtErrorClusterInvalidIpv6TunnelNetwork                     5927
#define kNtErrorQuorumNotAllowedInThisGroup                         5928
#define kNtErrorDependencyTreeTooComplex                            5929
#define kNtErrorExceptionInResourceCall                             5930
#define kNtErrorClusterRhsFailedInitialization                      5931
#define kNtErrorClusterNotInstalled                                 5932
#define kNtErrorClusterResourcesMustBeOnlineOnTheSameNode           5933
#define kNtErrorClusterMaxNodesInCluster                            5934
#define kNtErrorClusterTooManyNodes                                 5935
#define kNtErrorClusterObjectAlreadyUsed                            5936
#define kNtErrorNoncoreGroupsFound                                  5937
#define kNtErrorFileShareResourceConflict                           5938
#define kNtErrorClusterEvictInvalidRequest                          5939
#define kNtErrorClusterSingletonResource                            5940
#define kNtErrorClusterGroupSingletonResource                       5941
#define kNtErrorClusterResourceProviderFailed                       5942
#define kNtErrorClusterResourceConfigurationError                   5943
#define kNtErrorClusterGroupBusy                                    5944
#define kNtErrorClusterNotSharedVolume                              5945
#define kNtErrorClusterInvalidSecurityDescriptor                    5946
#define kNtErrorClusterSharedVolumesInUse                           5947
#define kNtErrorClusterUseSharedVolumesApi                          5948
#define kNtErrorClusterBackupInProgress                             5949
#define kNtErrorNonCsvPath                                          5950
#define kNtErrorCsvVolumeNotLocal                                   5951
#define kNtErrorClusterWatchdogTerminating                          5952
#define kNtErrorClusterResourceVetoedMoveIncompatibleNodes          5953
#define kNtErrorClusterInvalidNodeWeight                            5954
#define kNtErrorClusterResourceVetoedCall                           5955
#define kNtErrorResmonSystemResourcesLacking                        5956
#define kNtErrorClusterResourceVetoedMoveNotEnoughResourcesOnSource 5958
#define kNtErrorClusterGroupQueued                                  5959
#define kNtErrorClusterResourceLockedStatus                         5960
#define kNtErrorClusterSharedVolumeFailoverNotAllowed               5961
#define kNtErrorClusterNodeDrainInProgress                          5962
#define kNtErrorClusterDiskNotConnected                             5963
#define kNtErrorDiskNotCsvCapable                                   5964
#define kNtErrorResourceNotInAvailableStorage                       5965
#define kNtErrorClusterSharedVolumeRedirected                       5966
#define kNtErrorClusterSharedVolumeNotRedirected                    5967
#define kNtErrorClusterCannotReturnProperties                       5968
#define kNtErrorClusterResourceIsInMaintenanceMode                  5970
#define kNtErrorClusterAffinityConflict                             5971
#define kNtErrorClusterResourceIsReplicaVirtualMachine              5972
#define kNtErrorClusterUpgradeIncompatibleVersions                  5973
#define kNtErrorClusterUpgradeFixQuorumNotSupported                 5974
#define kNtErrorClusterUpgradeRestartRequired                       5975
#define kNtErrorClusterUpgradeInProgress                            5976
#define kNtErrorClusterUpgradeIncomplete                            5977
#define kNtErrorClusterNodeInGracePeriod                            5978
#define kNtErrorClusterCsvIoPauseTimeout                            5979
#define kNtErrorNodeNotActiveClusterMember                          5980
#define kNtErrorClusterResourceNotMonitored                         5981
#define kNtErrorClusterResourceDoesNotSupportUnmonitored            5982
#define kNtErrorClusterResourceIsReplicated                         5983
#define kNtErrorClusterNodeIsolated                                 5984
#define kNtErrorClusterNodeQuarantined                              5985
#define kNtErrorClusterDatabaseUpdateConditionFailed                5986
#define kNtErrorClusterSpaceDegraded                                5987
#define kNtErrorClusterTokenDelegationNotSupported                  5988
#define kNtErrorClusterCsvInvalidHandle                             5989
#define kNtErrorClusterCsvSupportedOnlyOnCoordinator                5990
#define kNtErrorGroupsetNotAvailable                                5991
#define kNtErrorGroupsetNotFound                                    5992
#define kNtErrorGroupsetCantProvide                                 5993
#define kNtErrorClusterFaultDomainParentNotFound                    5994
#define kNtErrorClusterFaultDomainInvalidHierarchy                  5995
#define kNtErrorClusterFaultDomainFailedS2dValidation               5996
#define kNtErrorClusterFaultDomainS2dConnectivityLoss               5997
#define kNtErrorClusterInvalidInfrastructureFileserverName          5998
#define kNtErrorClustersetManagementClusterUnreachable              5999
#define kNtErrorEncryptionFailed                                    6000
#define kNtErrorDecryptionFailed                                    6001
#define kNtErrorFileEncrypted                                       6002
#define kNtErrorNoRecoveryPolicy                                    6003
#define kNtErrorNoEfs                                               6004
#define kNtErrorWrongEfs                                            6005
#define kNtErrorNoUserKeys                                          6006
#define kNtErrorFileNotEncrypted                                    6007
#define kNtErrorNotExportFormat                                     6008
#define kNtErrorFileReadOnly                                        6009 /* EROFS */
#define kNtErrorDirEfsDisallowed                                    6010
#define kNtErrorEfsServerNotTrusted                                 6011
#define kNtErrorBadRecoveryPolicy                                   6012
#define kNtErrorEfsAlgBlobTooBig                                    6013
#define kNtErrorVolumeNotSupportEfs                                 6014
#define kNtErrorEfsDisabled                                         6015
#define kNtErrorEfsVersionNotSupport                                6016
#define kNtErrorCsEncryptionInvalidServerResponse                   6017
#define kNtErrorCsEncryptionUnsupportedServer                       6018
#define kNtErrorCsEncryptionExistingEncryptedFile                   6019
#define kNtErrorCsEncryptionNewEncryptedFile                        6020
#define kNtErrorCsEncryptionFileNotCse                              6021
#define kNtErrorEncryptionPolicyDeniesOperation                     6022
#define kNtErrorNoBrowserServersFound                               6118
#define kNtErrorLogSectorInvalid                                    6600
#define kNtErrorLogSectorParityInvalid                              6601
#define kNtErrorLogSectorRemapped                                   6602
#define kNtErrorLogBlockIncomplete                                  6603
#define kNtErrorLogInvalidRange                                     6604 /* ERANGE */
#define kNtErrorLogBlocksExhausted                                  6605
#define kNtErrorLogReadContextInvalid                               6606
#define kNtErrorLogRestartInvalid                                   6607
#define kNtErrorLogBlockVersion                                     6608
#define kNtErrorLogBlockInvalid                                     6609
#define kNtErrorLogReadModeInvalid                                  6610
#define kNtErrorLogNoRestart                                        6611
#define kNtErrorLogMetadataCorrupt                                  6612
#define kNtErrorLogMetadataInvalid                                  6613
#define kNtErrorLogMetadataInconsistent                             6614
#define kNtErrorLogReservationInvalid                               6615
#define kNtErrorLogCantDelete                                       6616
#define kNtErrorLogContainerLimitExceeded                           6617
#define kNtErrorLogStartOfLog                                       6618
#define kNtErrorLogPolicyAlreadyInstalled                           6619
#define kNtErrorLogPolicyNotInstalled                               6620
#define kNtErrorLogPolicyInvalid                                    6621
#define kNtErrorLogPolicyConflict                                   6622
#define kNtErrorLogPinnedArchiveTail                                6623
#define kNtErrorLogRecordNonexistent                                6624
#define kNtErrorLogRecordsReservedInvalid                           6625
#define kNtErrorLogSpaceReservedInvalid                             6626
#define kNtErrorLogTailInvalid                                      6627
#define kNtErrorLogFull                                             6628
#define kNtErrorCouldNotResizeLog                                   6629
#define kNtErrorLogMultiplexed                                      6630
#define kNtErrorLogDedicated                                        6631
#define kNtErrorLogArchiveNotInProgress                             6632
#define kNtErrorLogArchiveInProgress                                6633
#define kNtErrorLogEphemeral                                        6634
#define kNtErrorLogNotEnoughContainers                              6635
#define kNtErrorLogClientAlreadyRegistered                          6636
#define kNtErrorLogClientNotRegistered                              6637
#define kNtErrorLogFullHandlerInProgress                            6638
#define kNtErrorLogContainerReadFailed                              6639
#define kNtErrorLogContainerWriteFailed                             6640
#define kNtErrorLogContainerOpenFailed                              6641
#define kNtErrorLogContainerStateInvalid                            6642
#define kNtErrorLogStateInvalid                                     6643
#define kNtErrorLogPinned                                           6644
#define kNtErrorLogMetadataFlushFailed                              6645
#define kNtErrorLogInconsistentSecurity                             6646
#define kNtErrorLogAppendedFlushFailed                              6647
#define kNtErrorLogPinnedReservation                                6648
#define kNtErrorInvalidTransaction                                  6700
#define kNtErrorTransactionNotActive                                6701
#define kNtErrorTransactionRequestNotValid                          6702
#define kNtErrorTransactionNotRequested                             6703
#define kNtErrorTransactionAlreadyAborted                           6704
#define kNtErrorTransactionAlreadyCommitted                         6705
#define kNtErrorTmInitializationFailed                              6706
#define kNtErrorResourcemanagerReadOnly                             6707
#define kNtErrorTransactionNotJoined                                6708
#define kNtErrorTransactionSuperiorExists                           6709
#define kNtErrorCrmProtocolAlreadyExists                            6710
#define kNtErrorTransactionPropagationFailed                        6711
#define kNtErrorCrmProtocolNotFound                                 6712
#define kNtErrorTransactionInvalidMarshallBuffer                    6713
#define kNtErrorCurrentTransactionNotValid                          6714
#define kNtErrorTransactionNotFound                                 6715
#define kNtErrorResourcemanagerNotFound                             6716
#define kNtErrorEnlistmentNotFound                                  6717
#define kNtErrorTransactionmanagerNotFound                          6718
#define kNtErrorTransactionmanagerNotOnline                         6719
#define kNtErrorTransactionmanagerRecoveryNameCollision             6720
#define kNtErrorTransactionNotRoot                                  6721
#define kNtErrorTransactionObjectExpired                            6722
#define kNtErrorTransactionResponseNotEnlisted                      6723
#define kNtErrorTransactionRecordTooLong                            6724
#define kNtErrorImplicitTransactionNotSupported                     6725
#define kNtErrorTransactionIntegrityViolated                        6726
#define kNtErrorTransactionmanagerIdentityMismatch                  6727
#define kNtErrorRmCannotBeFrozenForSnapshot                         6728
#define kNtErrorTransactionMustWritethrough                         6729
#define kNtErrorTransactionNoSuperior                               6730
#define kNtErrorHeuristicDamagePossible                             6731
#define kNtErrorTransactionalConflict                               6800
#define kNtErrorRmNotActive                                         6801
#define kNtErrorRmMetadataCorrupt                                   6802
#define kNtErrorDirectoryNotRm                                      6803
#define kNtErrorTransactionsUnsupportedRemote                       6805
#define kNtErrorLogResizeInvalidSize                                6806
#define kNtErrorObjectNoLongerExists                                6807
#define kNtErrorStreamMiniversionNotFound                           6808
#define kNtErrorStreamMiniversionNotValid                           6809
#define kNtErrorMiniversionInaccessibleFromSpecifiedTransaction     6810
#define kNtErrorCantOpenMiniversionWithModifyIntent                 6811
#define kNtErrorCantCreateMoreStreamMiniversions                    6812
#define kNtErrorRemoteFileVersionMismatch                           6814
#define kNtErrorHandleNoLongerValid                                 6815
#define kNtErrorNoTxfMetadata                                       6816
#define kNtErrorLogCorruptionDetected                               6817
#define kNtErrorCantRecoverWithHandleOpen                           6818
#define kNtErrorRmDisconnected                                      6819
#define kNtErrorEnlistmentNotSuperior                               6820
#define kNtErrorRecoveryNotNeeded                                   6821
#define kNtErrorRmAlreadyStarted                                    6822
#define kNtErrorFileIdentityNotPersistent                           6823
#define kNtErrorCantBreakTransactionalDependency                    6824
#define kNtErrorCantCrossRmBoundary                                 6825
#define kNtErrorTxfDirNotEmpty                                      6826
#define kNtErrorIndoubtTransactionsExist                            6827
#define kNtErrorTmVolatile                                          6828
#define kNtErrorRollbackTimerExpired                                6829
#define kNtErrorTxfAttributeCorrupt                                 6830
#define kNtErrorEfsNotAllowedInTransaction                          6831
#define kNtErrorTransactionalOpenNotAllowed                         6832
#define kNtErrorLogGrowthFailed                                     6833
#define kNtErrorTransactedMappingUnsupportedRemote                  6834
#define kNtErrorTxfMetadataAlreadyPresent                           6835
#define kNtErrorTransactionScopeCallbacksNotSet                     6836
#define kNtErrorTransactionRequiredPromotion                        6837
#define kNtErrorCannotExecuteFileInTransaction                      6838
#define kNtErrorTransactionsNotFrozen                               6839
#define kNtErrorTransactionFreezeInProgress                         6840
#define kNtErrorNotSnapshotVolume                                   6841
#define kNtErrorNoSavepointWithOpenFiles                            6842
#define kNtErrorDataLostRepair                                      6843
#define kNtErrorSparseNotAllowedInTransaction                       6844
#define kNtErrorTmIdentityMismatch                                  6845
#define kNtErrorFloatedSection                                      6846
#define kNtErrorCannotAcceptTransactedWork                          6847
#define kNtErrorCannotAbortTransactions                             6848
#define kNtErrorBadClusters                                         6849
#define kNtErrorCompressionNotAllowedInTransaction                  6850
#define kNtErrorVolumeDirty                                         6851
#define kNtErrorNoLinkTrackingInTransaction                         6852
#define kNtErrorOperationNotSupportedInTransaction                  6853
#define kNtErrorExpiredHandle                                       6854
#define kNtErrorTransactionNotEnlisted                              6855
#define kNtErrorCtxWinstationNameInvalid                            7001
#define kNtErrorCtxInvalidPd                                        7002
#define kNtErrorCtxPdNotFound                                       7003
#define kNtErrorCtxWdNotFound                                       7004
#define kNtErrorCtxCannotMakeEventlogEntry                          7005
#define kNtErrorCtxServiceNameCollision                             7006
#define kNtErrorCtxClosePending                                     7007
#define kNtErrorCtxNoOutbuf                                         7008
#define kNtErrorCtxModemInfNotFound                                 7009
#define kNtErrorCtxInvalidModemname                                 7010
#define kNtErrorCtxModemResponseError                               7011
#define kNtErrorCtxModemResponseTimeout                             7012
#define kNtErrorCtxModemResponseNoCarrier                           7013
#define kNtErrorCtxModemResponseNoDialtone                          7014
#define kNtErrorCtxModemResponseBusy                                7015
#define kNtErrorCtxModemResponseVoice                               7016
#define kNtErrorCtxTdError                                          7017
#define kNtErrorCtxWinstationNotFound                               7022
#define kNtErrorCtxWinstationAlreadyExists                          7023
#define kNtErrorCtxWinstationBusy                                   7024
#define kNtErrorCtxBadVideoMode                                     7025
#define kNtErrorCtxGraphicsInvalid                                  7035
#define kNtErrorCtxLogonDisabled                                    7037
#define kNtErrorCtxNotConsole                                       7038
#define kNtErrorCtxClientQueryTimeout                               7040
#define kNtErrorCtxConsoleDisconnect                                7041
#define kNtErrorCtxConsoleConnect                                   7042
#define kNtErrorCtxShadowDenied                                     7044
#define kNtErrorCtxWinstationAccessDenied                           7045
#define kNtErrorCtxInvalidWd                                        7049
#define kNtErrorCtxShadowInvalid                                    7050
#define kNtErrorCtxShadowDisabled                                   7051
#define kNtErrorCtxClientLicenseInUse                               7052
#define kNtErrorCtxClientLicenseNotSet                              7053
#define kNtErrorCtxLicenseNotAvailable                              7054
#define kNtErrorCtxLicenseClientInvalid                             7055
#define kNtErrorCtxLicenseExpired                                   7056
#define kNtErrorCtxShadowNotRunning                                 7057
#define kNtErrorCtxShadowEndedByModeChange                          7058
#define kNtErrorActivationCountExceeded                             7059
#define kNtErrorCtxWinstationsDisabled                              7060
#define kNtErrorCtxEncryptionLevelRequired                          7061
#define kNtErrorCtxSessionInUse                                     7062
#define kNtErrorCtxNoForceLogoff                                    7063
#define kNtErrorCtxAccountRestriction                               7064
#define kNtErrorRdpProtocolError                                    7065 /* EPROTO */
#define kNtErrorCtxCdmConnect                                       7066
#define kNtErrorCtxCdmDisconnect                                    7067
#define kNtErrorCtxSecurityLayerError                               7068
#define kNtErrorTsIncompatibleSessions                              7069
#define kNtErrorTsVideoSubsystemError                               7070
#define kNtErrorDsNotInstalled                                      8200
#define kNtErrorDsMembershipEvaluatedLocally                        8201
#define kNtErrorDsNoAttributeOrValue                                8202
#define kNtErrorDsInvalidAttributeSyntax                            8203
#define kNtErrorDsAttributeTypeUndefined                            8204
#define kNtErrorDsAttributeOrValueExists                            8205
#define kNtErrorDsBusy                                              8206
#define kNtErrorDsUnavailable                                       8207
#define kNtErrorDsNoRidsAllocated                                   8208
#define kNtErrorDsNoMoreRids                                        8209
#define kNtErrorDsIncorrectRoleOwner                                8210
#define kNtErrorDsRidmgrInitError                                   8211
#define kNtErrorDsObjClassViolation                                 8212
#define kNtErrorDsCantOnNonLeaf                                     8213
#define kNtErrorDsCantOnRdn                                         8214
#define kNtErrorDsCantModObjClass                                   8215
#define kNtErrorDsCrossDomMoveError                                 8216
#define kNtErrorDsGcNotAvailable                                    8217
#define kNtErrorSharedPolicy                                        8218
#define kNtErrorPolicyObjectNotFound                                8219
#define kNtErrorPolicyOnlyInDs                                      8220
#define kNtErrorPromotionActive                                     8221
#define kNtErrorNoPromotionActive                                   8222
#define kNtErrorDsOperationsError                                   8224
#define kNtErrorDsProtocolError                                     8225
#define kNtErrorDsTimelimitExceeded                                 8226
#define kNtErrorDsSizelimitExceeded                                 8227
#define kNtErrorDsAdminLimitExceeded                                8228
#define kNtErrorDsCompareFalse                                      8229
#define kNtErrorDsCompareTrue                                       8230
#define kNtErrorDsAuthMethodNotSupported                            8231
#define kNtErrorDsStrongAuthRequired                                8232
#define kNtErrorDsInappropriateAuth                                 8233
#define kNtErrorDsAuthUnknown                                       8234
#define kNtErrorDsReferral                                          8235
#define kNtErrorDsUnavailableCritExtension                          8236
#define kNtErrorDsConfidentialityRequired                           8237
#define kNtErrorDsInappropriateMatching                             8238
#define kNtErrorDsConstraintViolation                               8239
#define kNtErrorDsNoSuchObject                                      8240
#define kNtErrorDsAliasProblem                                      8241
#define kNtErrorDsInvalidDnSyntax                                   8242
#define kNtErrorDsIsLeaf                                            8243
#define kNtErrorDsAliasDerefProblem                                 8244
#define kNtErrorDsUnwillingToPerform                                8245
#define kNtErrorDsLoopDetect                                        8246
#define kNtErrorDsNamingViolation                                   8247
#define kNtErrorDsObjectResultsTooLarge                             8248
#define kNtErrorDsAffectsMultipleDsas                               8249
#define kNtErrorDsServerDown                                        8250
#define kNtErrorDsLocalError                                        8251
#define kNtErrorDsEncodingError                                     8252
#define kNtErrorDsDecodingError                                     8253
#define kNtErrorDsFilterUnknown                                     8254
#define kNtErrorDsParamError                                        8255
#define kNtErrorDsNotSupported                                      8256
#define kNtErrorDsNoResultsReturned                                 8257
#define kNtErrorDsControlNotFound                                   8258
#define kNtErrorDsClientLoop                                        8259
#define kNtErrorDsReferralLimitExceeded                             8260
#define kNtErrorDsSortControlMissing                                8261
#define kNtErrorDsOffsetRangeError                                  8262
#define kNtErrorDsRidmgrDisabled                                    8263
#define kNtErrorDsRootMustBeNc                                      8301
#define kNtErrorDsAddReplicaInhibited                               8302
#define kNtErrorDsAttNotDefInSchema                                 8303
#define kNtErrorDsMaxObjSizeExceeded                                8304
#define kNtErrorDsObjStringNameExists                               8305
#define kNtErrorDsNoRdnDefinedInSchema                              8306
#define kNtErrorDsRdnDoesntMatchSchema                              8307
#define kNtErrorDsNoRequestedAttsFound                              8308
#define kNtErrorDsUserBufferToSmall                                 8309
#define kNtErrorDsAttIsNotOnObj                                     8310
#define kNtErrorDsIllegalModOperation                               8311
#define kNtErrorDsObjTooLarge                                       8312
#define kNtErrorDsBadInstanceType                                   8313
#define kNtErrorDsMasterdsaRequired                                 8314
#define kNtErrorDsObjectClassRequired                               8315
#define kNtErrorDsMissingRequiredAtt                                8316
#define kNtErrorDsAttNotDefForClass                                 8317
#define kNtErrorDsAttAlreadyExists                                  8318
#define kNtErrorDsCantAddAttValues                                  8320
#define kNtErrorDsSingleValueConstraint                             8321
#define kNtErrorDsRangeConstraint                                   8322
#define kNtErrorDsAttValAlreadyExists                               8323
#define kNtErrorDsCantRemMissingAtt                                 8324
#define kNtErrorDsCantRemMissingAttVal                              8325
#define kNtErrorDsRootCantBeSubref                                  8326
#define kNtErrorDsNoChaining                                        8327
#define kNtErrorDsNoChainedEval                                     8328
#define kNtErrorDsNoParentObject                                    8329
#define kNtErrorDsParentIsAnAlias                                   8330
#define kNtErrorDsCantMixMasterAndReps                              8331
#define kNtErrorDsChildrenExist                                     8332
#define kNtErrorDsObjNotFound                                       8333
#define kNtErrorDsAliasedObjMissing                                 8334
#define kNtErrorDsBadNameSyntax                                     8335
#define kNtErrorDsAliasPointsToAlias                                8336
#define kNtErrorDsCantDerefAlias                                    8337
#define kNtErrorDsOutOfScope                                        8338
#define kNtErrorDsObjectBeingRemoved                                8339
#define kNtErrorDsCantDeleteDsaObj                                  8340
#define kNtErrorDsGenericError                                      8341
#define kNtErrorDsDsaMustBeIntMaster                                8342
#define kNtErrorDsClassNotDsa                                       8343
#define kNtErrorDsInsuffAccessRights                                8344
#define kNtErrorDsIllegalSuperior                                   8345
#define kNtErrorDsAttributeOwnedBySam                               8346
#define kNtErrorDsNameTooManyParts                                  8347
#define kNtErrorDsNameTooLong                                       8348
#define kNtErrorDsNameValueTooLong                                  8349
#define kNtErrorDsNameUnparseable                                   8350
#define kNtErrorDsNameTypeUnknown                                   8351
#define kNtErrorDsNotAnObject                                       8352
#define kNtErrorDsSecDescTooShort                                   8353
#define kNtErrorDsSecDescInvalid                                    8354
#define kNtErrorDsNoDeletedName                                     8355
#define kNtErrorDsSubrefMustHaveParent                              8356
#define kNtErrorDsNcnameMustBeNc                                    8357
#define kNtErrorDsCantAddSystemOnly                                 8358
#define kNtErrorDsClassMustBeConcrete                               8359
#define kNtErrorDsInvalidDmd                                        8360
#define kNtErrorDsObjGuidExists                                     8361
#define kNtErrorDsNotOnBacklink                                     8362
#define kNtErrorDsNoCrossrefForNc                                   8363
#define kNtErrorDsShuttingDown                                      8364
#define kNtErrorDsUnknownOperation                                  8365
#define kNtErrorDsInvalidRoleOwner                                  8366
#define kNtErrorDsCouldntContactFsmo                                8367
#define kNtErrorDsCrossNcDnRename                                   8368
#define kNtErrorDsCantModSystemOnly                                 8369
#define kNtErrorDsReplicatorOnly                                    8370
#define kNtErrorDsObjClassNotDefined                                8371
#define kNtErrorDsObjClassNotSubclass                               8372
#define kNtErrorDsNameReferenceInvalid                              8373
#define kNtErrorDsCrossRefExists                                    8374
#define kNtErrorDsCantDelMasterCrossref                             8375
#define kNtErrorDsSubtreeNotifyNotNcHead                            8376
#define kNtErrorDsNotifyFilterTooComplex                            8377
#define kNtErrorDsDupRdn                                            8378
#define kNtErrorDsDupOid                                            8379
#define kNtErrorDsDupMapiId                                         8380
#define kNtErrorDsDupSchemaIdGuid                                   8381
#define kNtErrorDsDupLdapDisplayName                                8382
#define kNtErrorDsSemanticAttTest                                   8383
#define kNtErrorDsSyntaxMismatch                                    8384
#define kNtErrorDsExistsInMustHave                                  8385
#define kNtErrorDsExistsInMayHave                                   8386
#define kNtErrorDsNonexistentMayHave                                8387
#define kNtErrorDsNonexistentMustHave                               8388
#define kNtErrorDsAuxClsTestFail                                    8389
#define kNtErrorDsNonexistentPossSup                                8390
#define kNtErrorDsSubClsTestFail                                    8391
#define kNtErrorDsBadRdnAttIdSyntax                                 8392
#define kNtErrorDsExistsInAuxCls                                    8393
#define kNtErrorDsExistsInSubCls                                    8394
#define kNtErrorDsExistsInPossSup                                   8395
#define kNtErrorDsRecalcschemaFailed                                8396
#define kNtErrorDsTreeDeleteNotFinished                             8397
#define kNtErrorDsCantDelete                                        8398
#define kNtErrorDsAttSchemaReqId                                    8399
#define kNtErrorDsBadAttSchemaSyntax                                8400
#define kNtErrorDsCantCacheAtt                                      8401
#define kNtErrorDsCantCacheClass                                    8402
#define kNtErrorDsCantRemoveAttCache                                8403
#define kNtErrorDsCantRemoveClassCache                              8404
#define kNtErrorDsCantRetrieveDn                                    8405
#define kNtErrorDsMissingSupref                                     8406
#define kNtErrorDsCantRetrieveInstance                              8407
#define kNtErrorDsCodeInconsistency                                 8408
#define kNtErrorDsDatabaseError                                     8409
#define kNtErrorDsGovernsidMissing                                  8410
#define kNtErrorDsMissingExpectedAtt                                8411
#define kNtErrorDsNcnameMissingCrRef                                8412
#define kNtErrorDsSecurityCheckingError                             8413
#define kNtErrorDsSchemaNotLoaded                                   8414
#define kNtErrorDsSchemaAllocFailed                                 8415
#define kNtErrorDsAttSchemaReqSyntax                                8416
#define kNtErrorDsGcverifyError                                     8417
#define kNtErrorDsDraSchemaMismatch                                 8418
#define kNtErrorDsCantFindDsaObj                                    8419
#define kNtErrorDsCantFindExpectedNc                                8420
#define kNtErrorDsCantFindNcInCache                                 8421
#define kNtErrorDsCantRetrieveChild                                 8422
#define kNtErrorDsSecurityIllegalModify                             8423
#define kNtErrorDsCantReplaceHiddenRec                              8424
#define kNtErrorDsBadHierarchyFile                                  8425
#define kNtErrorDsBuildHierarchyTableFailed                         8426
#define kNtErrorDsConfigParamMissing                                8427
#define kNtErrorDsCountingAbIndicesFailed                           8428
#define kNtErrorDsHierarchyTableMallocFailed                        8429
#define kNtErrorDsInternalFailure                                   8430
#define kNtErrorDsUnknownError                                      8431
#define kNtErrorDsRootRequiresClassTop                              8432
#define kNtErrorDsRefusingFsmoRoles                                 8433
#define kNtErrorDsMissingFsmoSettings                               8434
#define kNtErrorDsUnableToSurrenderRoles                            8435
#define kNtErrorDsDraGeneric                                        8436
#define kNtErrorDsDraInvalidParameter                               8437
#define kNtErrorDsDraBusy                                           8438
#define kNtErrorDsDraBadDn                                          8439
#define kNtErrorDsDraBadNc                                          8440
#define kNtErrorDsDraDnExists                                       8441
#define kNtErrorDsDraInternalError                                  8442
#define kNtErrorDsDraInconsistentDit                                8443
#define kNtErrorDsDraConnectionFailed                               8444
#define kNtErrorDsDraBadInstanceType                                8445
#define kNtErrorDsDraOutOfMem                                       8446
#define kNtErrorDsDraMailProblem                                    8447
#define kNtErrorDsDraRefAlreadyExists                               8448
#define kNtErrorDsDraRefNotFound                                    8449
#define kNtErrorDsDraObjIsRepSource                                 8450
#define kNtErrorDsDraDbError                                        8451
#define kNtErrorDsDraNoReplica                                      8452
#define kNtErrorDsDraAccessDenied                                   8453
#define kNtErrorDsDraNotSupported                                   8454
#define kNtErrorDsDraRpcCancelled                                   8455
#define kNtErrorDsDraSourceDisabled                                 8456
#define kNtErrorDsDraSinkDisabled                                   8457
#define kNtErrorDsDraNameCollision                                  8458
#define kNtErrorDsDraSourceReinstalled                              8459
#define kNtErrorDsDraMissingParent                                  8460
#define kNtErrorDsDraPreempted                                      8461
#define kNtErrorDsDraAbandonSync                                    8462
#define kNtErrorDsDraShutdown                                       8463
#define kNtErrorDsDraIncompatiblePartialSet                         8464
#define kNtErrorDsDraSourceIsPartialReplica                         8465
#define kNtErrorDsDraExtnConnectionFailed                           8466
#define kNtErrorDsInstallSchemaMismatch                             8467
#define kNtErrorDsDupLinkId                                         8468
#define kNtErrorDsNameErrorResolving                                8469
#define kNtErrorDsNameErrorNotFound                                 8470
#define kNtErrorDsNameErrorNotUnique                                8471
#define kNtErrorDsNameErrorNoMapping                                8472
#define kNtErrorDsNameErrorDomainOnly                               8473
#define kNtErrorDsNameErrorNoSyntacticalMapping                     8474
#define kNtErrorDsConstructedAttMod                                 8475
#define kNtErrorDsWrongOmObjClass                                   8476
#define kNtErrorDsDraReplPending                                    8477
#define kNtErrorDsDsRequired                                        8478
#define kNtErrorDsInvalidLdapDisplayName                            8479
#define kNtErrorDsNonBaseSearch                                     8480
#define kNtErrorDsCantRetrieveAtts                                  8481
#define kNtErrorDsBacklinkWithoutLink                               8482
#define kNtErrorDsEpochMismatch                                     8483
#define kNtErrorDsSrcNameMismatch                                   8484
#define kNtErrorDsSrcAndDstNcIdentical                              8485
#define kNtErrorDsDstNcMismatch                                     8486
#define kNtErrorDsNotAuthoritiveForDstNc                            8487
#define kNtErrorDsSrcGuidMismatch                                   8488
#define kNtErrorDsCantMoveDeletedObject                             8489
#define kNtErrorDsPdcOperationInProgress                            8490
#define kNtErrorDsCrossDomainCleanupReqd                            8491
#define kNtErrorDsIllegalXdomMoveOperation                          8492
#define kNtErrorDsCantWithAcctGroupMembershps                       8493
#define kNtErrorDsNcMustHaveNcParent                                8494
#define kNtErrorDsCrImpossibleToValidate                            8495
#define kNtErrorDsDstDomainNotNative                                8496
#define kNtErrorDsMissingInfrastructureContainer                    8497
#define kNtErrorDsCantMoveAccountGroup                              8498
#define kNtErrorDsCantMoveResourceGroup                             8499
#define kNtErrorDsInvalidSearchFlag                                 8500
#define kNtErrorDsNoTreeDeleteAboveNc                               8501
#define kNtErrorDsCouldntLockTreeForDelete                          8502
#define kNtErrorDsCouldntIdentifyObjectsForTreeDelete               8503
#define kNtErrorDsSamInitFailure                                    8504
#define kNtErrorDsSensitiveGroupViolation                           8505
#define kNtErrorDsCantModPrimarygroupid                             8506
#define kNtErrorDsIllegalBaseSchemaMod                              8507
#define kNtErrorDsNonsafeSchemaChange                               8508
#define kNtErrorDsSchemaUpdateDisallowed                            8509
#define kNtErrorDsCantCreateUnderSchema                             8510
#define kNtErrorDsInstallNoSrcSchVersion                            8511
#define kNtErrorDsInstallNoSchVersionInInifile                      8512
#define kNtErrorDsInvalidGroupType                                  8513
#define kNtErrorDsNoNestGlobalgroupInMixeddomain                    8514
#define kNtErrorDsNoNestLocalgroupInMixeddomain                     8515
#define kNtErrorDsGlobalCantHaveLocalMember                         8516
#define kNtErrorDsGlobalCantHaveUniversalMember                     8517
#define kNtErrorDsUniversalCantHaveLocalMember                      8518
#define kNtErrorDsGlobalCantHaveCrossdomainMember                   8519
#define kNtErrorDsLocalCantHaveCrossdomainLocalMember               8520
#define kNtErrorDsHavePrimaryMembers                                8521
#define kNtErrorDsStringSdConversionFailed                          8522
#define kNtErrorDsNamingMasterGc                                    8523
#define kNtErrorDsDnsLookupFailure                                  8524
#define kNtErrorDsCouldntUpdateSpns                                 8525
#define kNtErrorDsCantRetrieveSd                                    8526
#define kNtErrorDsKeyNotUnique                                      8527
#define kNtErrorDsWrongLinkedAttSyntax                              8528
#define kNtErrorDsSamNeedBootkeyPassword                            8529
#define kNtErrorDsSamNeedBootkeyFloppy                              8530
#define kNtErrorDsCantStart                                         8531
#define kNtErrorDsInitFailure                                       8532
#define kNtErrorDsNoPktPrivacyOnConnection                          8533
#define kNtErrorDsSourceDomainInForest                              8534
#define kNtErrorDsDestinationDomainNotInForest                      8535
#define kNtErrorDsDestinationAuditingNotEnabled                     8536
#define kNtErrorDsCantFindDcForSrcDomain                            8537
#define kNtErrorDsSrcObjNotGroupOrUser                              8538
#define kNtErrorDsSrcSidExistsInForest                              8539
#define kNtErrorDsSrcAndDstObjectClassMismatch                      8540
#define kNtErrorSamInitFailure                                      8541
#define kNtErrorDsDraSchemaInfoShip                                 8542
#define kNtErrorDsDraSchemaConflict                                 8543
#define kNtErrorDsDraEarlierSchemaConflict                          8544
#define kNtErrorDsDraObjNcMismatch                                  8545
#define kNtErrorDsNcStillHasDsas                                    8546
#define kNtErrorDsGcRequired                                        8547
#define kNtErrorDsLocalMemberOfLocalOnly                            8548
#define kNtErrorDsNoFpoInUniversalGroups                            8549
#define kNtErrorDsCantAddToGc                                       8550
#define kNtErrorDsNoCheckpointWithPdc                               8551
#define kNtErrorDsSourceAuditingNotEnabled                          8552
#define kNtErrorDsCantCreateInNondomainNc                           8553
#define kNtErrorDsInvalidNameForSpn                                 8554
#define kNtErrorDsFilterUsesContructedAttrs                         8555
#define kNtErrorDsUnicodepwdNotInQuotes                             8556
#define kNtErrorDsMachineAccountQuotaExceeded                       8557
#define kNtErrorDsMustBeRunOnDstDc                                  8558
#define kNtErrorDsSrcDcMustBeSp4OrGreater                           8559
#define kNtErrorDsCantTreeDeleteCriticalObj                         8560
#define kNtErrorDsInitFailureConsole                                8561
#define kNtErrorDsSamInitFailureConsole                             8562
#define kNtErrorDsForestVersionTooHigh                              8563
#define kNtErrorDsDomainVersionTooHigh                              8564
#define kNtErrorDsForestVersionTooLow                               8565
#define kNtErrorDsDomainVersionTooLow                               8566
#define kNtErrorDsIncompatibleVersion                               8567
#define kNtErrorDsLowDsaVersion                                     8568
#define kNtErrorDsNoBehaviorVersionInMixeddomain                    8569
#define kNtErrorDsNotSupportedSortOrder                             8570
#define kNtErrorDsNameNotUnique                                     8571
#define kNtErrorDsMachineAccountCreatedPrent4                       8572
#define kNtErrorDsOutOfVersionStore                                 8573
#define kNtErrorDsIncompatibleControlsUsed                          8574
#define kNtErrorDsNoRefDomain                                       8575
#define kNtErrorDsReservedLinkId                                    8576
#define kNtErrorDsLinkIdNotAvailable                                8577
#define kNtErrorDsAgCantHaveUniversalMember                         8578
#define kNtErrorDsModifydnDisallowedByInstanceType                  8579
#define kNtErrorDsNoObjectMoveInSchemaNc                            8580
#define kNtErrorDsModifydnDisallowedByFlag                          8581
#define kNtErrorDsModifydnWrongGrandparent                          8582
#define kNtErrorDsNameErrorTrustReferral                            8583
#define kNtErrorNotSupportedOnStandardServer                        8584
#define kNtErrorDsCantAccessRemotePartOfAd                          8585
#define kNtErrorDsCrImpossibleToValidateV2                          8586
#define kNtErrorDsThreadLimitExceeded                               8587
#define kNtErrorDsNotClosest                                        8588
#define kNtErrorDsCantDeriveSpnWithoutServerRef                     8589
#define kNtErrorDsSingleUserModeFailed                              8590
#define kNtErrorDsNtdscriptSyntaxError                              8591
#define kNtErrorDsNtdscriptProcessError                             8592
#define kNtErrorDsDifferentReplEpochs                               8593
#define kNtErrorDsDrsExtensionsChanged                              8594
#define kNtErrorDsReplicaSetChangeNotAllowedOnDisabledCr            8595
#define kNtErrorDsNoMsdsIntid                                       8596
#define kNtErrorDsDupMsdsIntid                                      8597
#define kNtErrorDsExistsInRdnattid                                  8598
#define kNtErrorDsAuthorizationFailed                               8599
#define kNtErrorDsInvalidScript                                     8600
#define kNtErrorDsRemoteCrossrefOpFailed                            8601
#define kNtErrorDsCrossRefBusy                                      8602
#define kNtErrorDsCantDeriveSpnForDeletedDomain                     8603
#define kNtErrorDsCantDemoteWithWriteableNc                         8604
#define kNtErrorDsDuplicateIdFound                                  8605
#define kNtErrorDsInsufficientAttrToCreateObject                    8606
#define kNtErrorDsGroupConversionError                              8607
#define kNtErrorDsCantMoveAppBasicGroup                             8608
#define kNtErrorDsCantMoveAppQueryGroup                             8609
#define kNtErrorDsRoleNotVerified                                   8610
#define kNtErrorDsWkoContainerCannotBeSpecial                       8611
#define kNtErrorDsDomainRenameInProgress                            8612
#define kNtErrorDsExistingAdChildNc                                 8613
#define kNtErrorDsReplLifetimeExceeded                              8614
#define kNtErrorDsDisallowedInSystemContainer                       8615
#define kNtErrorDsLdapSendQueueFull                                 8616
#define kNtErrorDsDraOutScheduleWindow                              8617
#define kNtErrorDsPolicyNotKnown                                    8618
#define kNtErrorNoSiteSettingsObject                                8619
#define kNtErrorNoSecrets                                           8620
#define kNtErrorNoWritableDcFound                                   8621
#define kNtErrorDsNoServerObject                                    8622
#define kNtErrorDsNoNtdsaObject                                     8623
#define kNtErrorDsNonAsqSearch                                      8624
#define kNtErrorDsAuditFailure                                      8625
#define kNtErrorDsInvalidSearchFlagSubtree                          8626
#define kNtErrorDsInvalidSearchFlagTuple                            8627
#define kNtErrorDsHierarchyTableTooDeep                             8628
#define kNtErrorDsDraCorruptUtdVector                               8629
#define kNtErrorDsDraSecretsDenied                                  8630
#define kNtErrorDsReservedMapiId                                    8631
#define kNtErrorDsMapiIdNotAvailable                                8632
#define kNtErrorDsDraMissingKrbtgtSecret                            8633
#define kNtErrorDsDomainNameExistsInForest                          8634
#define kNtErrorDsFlatNameExistsInForest                            8635
#define kNtErrorInvalidUserPrincipalName                            8636
#define kNtErrorDsOidMappedGroupCantHaveMembers                     8637
#define kNtErrorDsOidNotFound                                       8638
#define kNtErrorDsDraRecycledTarget                                 8639
#define kNtErrorDsDisallowedNcRedirect                              8640
#define kNtErrorDsHighAdldsFfl                                      8641
#define kNtErrorDsHighDsaVersion                                    8642
#define kNtErrorDsLowAdldsFfl                                       8643
#define kNtErrorDomainSidSameAsLocalWorkstation                     8644
#define kNtErrorDsUndeleteSamValidationFailed                       8645
#define kNtErrorIncorrectAccountType                                8646
#define kNtErrorDsSpnValueNotUniqueInForest                         8647
#define kNtErrorDsUpnValueNotUniqueInForest                         8648
#define kNtErrorDsMissingForestTrust                                8649
#define kNtErrorDsValueKeyNotUnique                                 8650
#define kNtErrorIpsecQmPolicyExists                                 13000
#define kNtErrorIpsecQmPolicyNotFound                               13001
#define kNtErrorIpsecQmPolicyInUse                                  13002
#define kNtErrorIpsecMmPolicyExists                                 13003
#define kNtErrorIpsecMmPolicyNotFound                               13004
#define kNtErrorIpsecMmPolicyInUse                                  13005
#define kNtErrorIpsecMmFilterExists                                 13006
#define kNtErrorIpsecMmFilterNotFound                               13007
#define kNtErrorIpsecTransportFilterExists                          13008
#define kNtErrorIpsecTransportFilterNotFound                        13009
#define kNtErrorIpsecMmAuthExists                                   13010
#define kNtErrorIpsecMmAuthNotFound                                 13011
#define kNtErrorIpsecMmAuthInUse                                    13012
#define kNtErrorIpsecDefaultMmPolicyNotFound                        13013
#define kNtErrorIpsecDefaultMmAuthNotFound                          13014
#define kNtErrorIpsecDefaultQmPolicyNotFound                        13015
#define kNtErrorIpsecTunnelFilterExists                             13016
#define kNtErrorIpsecTunnelFilterNotFound                           13017
#define kNtErrorIpsecMmFilterPendingDeletion                        13018
#define kNtErrorIpsecTransportFilterPendingDeletion                 13019
#define kNtErrorIpsecTunnelFilterPendingDeletion                    13020
#define kNtErrorIpsecMmPolicyPendingDeletion                        13021
#define kNtErrorIpsecMmAuthPendingDeletion                          13022
#define kNtErrorIpsecQmPolicyPendingDeletion                        13023
#define kNtErrorIpsecIkeNegStatusBegin                              13800
#define kNtErrorIpsecIkeAuthFail                                    13801
#define kNtErrorIpsecIkeAttribFail                                  13802
#define kNtErrorIpsecIkeNegotiationPending                          13803
#define kNtErrorIpsecIkeGeneralProcessingError                      13804
#define kNtErrorIpsecIkeTimedOut                                    13805
#define kNtErrorIpsecIkeNoCert                                      13806
#define kNtErrorIpsecIkeSaDeleted                                   13807
#define kNtErrorIpsecIkeSaReaped                                    13808
#define kNtErrorIpsecIkeMmAcquireDrop                               13809
#define kNtErrorIpsecIkeQmAcquireDrop                               13810
#define kNtErrorIpsecIkeQueueDropMm                                 13811
#define kNtErrorIpsecIkeQueueDropNoMm                               13812
#define kNtErrorIpsecIkeDropNoResponse                              13813
#define kNtErrorIpsecIkeMmDelayDrop                                 13814
#define kNtErrorIpsecIkeQmDelayDrop                                 13815
#define kNtErrorIpsecIkeError                                       13816
#define kNtErrorIpsecIkeCrlFailed                                   13817
#define kNtErrorIpsecIkeInvalidKeyUsage                             13818
#define kNtErrorIpsecIkeInvalidCertType                             13819
#define kNtErrorIpsecIkeNoPrivateKey                                13820
#define kNtErrorIpsecIkeSimultaneousRekey                           13821
#define kNtErrorIpsecIkeDhFail                                      13822
#define kNtErrorIpsecIkeCriticalPayloadNotRecognized                13823
#define kNtErrorIpsecIkeInvalidHeader                               13824
#define kNtErrorIpsecIkeNoPolicy                                    13825
#define kNtErrorIpsecIkeInvalidSignature                            13826
#define kNtErrorIpsecIkeKerberosError                               13827
#define kNtErrorIpsecIkeNoPublicKey                                 13828
#define kNtErrorIpsecIkeProcessErr                                  13829
#define kNtErrorIpsecIkeProcessErrSa                                13830
#define kNtErrorIpsecIkeProcessErrProp                              13831
#define kNtErrorIpsecIkeProcessErrTrans                             13832
#define kNtErrorIpsecIkeProcessErrKe                                13833
#define kNtErrorIpsecIkeProcessErrId                                13834
#define kNtErrorIpsecIkeProcessErrCert                              13835
#define kNtErrorIpsecIkeProcessErrCertReq                           13836
#define kNtErrorIpsecIkeProcessErrHash                              13837
#define kNtErrorIpsecIkeProcessErrSig                               13838
#define kNtErrorIpsecIkeProcessErrNonce                             13839
#define kNtErrorIpsecIkeProcessErrNotify                            13840
#define kNtErrorIpsecIkeProcessErrDelete                            13841
#define kNtErrorIpsecIkeProcessErrVendor                            13842
#define kNtErrorIpsecIkeInvalidPayload                              13843
#define kNtErrorIpsecIkeLoadSoftSa                                  13844
#define kNtErrorIpsecIkeSoftSaTornDown                              13845
#define kNtErrorIpsecIkeInvalidCookie                               13846
#define kNtErrorIpsecIkeNoPeerCert                                  13847
#define kNtErrorIpsecIkePeerCrlFailed                               13848
#define kNtErrorIpsecIkePolicyChange                                13849
#define kNtErrorIpsecIkeNoMmPolicy                                  13850
#define kNtErrorIpsecIkeNotcbpriv                                   13851
#define kNtErrorIpsecIkeSecloadfail                                 13852
#define kNtErrorIpsecIkeFailsspinit                                 13853
#define kNtErrorIpsecIkeFailqueryssp                                13854
#define kNtErrorIpsecIkeSrvacqfail                                  13855
#define kNtErrorIpsecIkeSrvquerycred                                13856
#define kNtErrorIpsecIkeGetspifail                                  13857
#define kNtErrorIpsecIkeInvalidFilter                               13858
#define kNtErrorIpsecIkeOutOfMemory                                 13859
#define kNtErrorIpsecIkeAddUpdateKeyFailed                          13860
#define kNtErrorIpsecIkeInvalidPolicy                               13861
#define kNtErrorIpsecIkeUnknownDoi                                  13862
#define kNtErrorIpsecIkeInvalidSituation                            13863
#define kNtErrorIpsecIkeDhFailure                                   13864
#define kNtErrorIpsecIkeInvalidGroup                                13865
#define kNtErrorIpsecIkeEncrypt                                     13866
#define kNtErrorIpsecIkeDecrypt                                     13867
#define kNtErrorIpsecIkePolicyMatch                                 13868
#define kNtErrorIpsecIkeUnsupportedId                               13869
#define kNtErrorIpsecIkeInvalidHash                                 13870
#define kNtErrorIpsecIkeInvalidHashAlg                              13871
#define kNtErrorIpsecIkeInvalidHashSize                             13872
#define kNtErrorIpsecIkeInvalidEncryptAlg                           13873
#define kNtErrorIpsecIkeInvalidAuthAlg                              13874
#define kNtErrorIpsecIkeInvalidSig                                  13875
#define kNtErrorIpsecIkeLoadFailed                                  13876
#define kNtErrorIpsecIkeRpcDelete                                   13877
#define kNtErrorIpsecIkeBenignReinit                                13878
#define kNtErrorIpsecIkeInvalidResponderLifetimeNotify              13879
#define kNtErrorIpsecIkeInvalidMajorVersion                         13880
#define kNtErrorIpsecIkeInvalidCertKeylen                           13881
#define kNtErrorIpsecIkeMmLimit                                     13882
#define kNtErrorIpsecIkeNegotiationDisabled                         13883
#define kNtErrorIpsecIkeQmLimit                                     13884
#define kNtErrorIpsecIkeMmExpired                                   13885
#define kNtErrorIpsecIkePeerMmAssumedInvalid                        13886
#define kNtErrorIpsecIkeCertChainPolicyMismatch                     13887
#define kNtErrorIpsecIkeUnexpectedMessageId                         13888
#define kNtErrorIpsecIkeInvalidAuthPayload                          13889
#define kNtErrorIpsecIkeDosCookieSent                               13890
#define kNtErrorIpsecIkeShuttingDown                                13891
#define kNtErrorIpsecIkeCgaAuthFailed                               13892
#define kNtErrorIpsecIkeProcessErrNatoa                             13893
#define kNtErrorIpsecIkeInvalidMmForQm                              13894
#define kNtErrorIpsecIkeQmExpired                                   13895
#define kNtErrorIpsecIkeTooManyFilters                              13896
#define kNtErrorIpsecIkeNegStatusEnd                                13897
#define kNtErrorIpsecIkeKillDummyNapTunnel                          13898
#define kNtErrorIpsecIkeInnerIpAssignmentFailure                    13899
#define kNtErrorIpsecIkeRequireCpPayloadMissing                     13900
#define kNtErrorIpsecKeyModuleImpersonationNegotiationPending       13901
#define kNtErrorIpsecIkeCoexistenceSuppress                         13902
#define kNtErrorIpsecIkeRatelimitDrop                               13903
#define kNtErrorIpsecIkePeerDoesntSupportMobike                     13904
#define kNtErrorIpsecIkeAuthorizationFailure                        13905
#define kNtErrorIpsecIkeStrongCredAuthorizationFailure              13906
#define kNtErrorIpsecIkeAuthorizationFailureWithOptionalRetry       13907
#define kNtErrorIpsecIkeStrongCredAuthorizationAndCertmapFailure    13908
#define kNtErrorIpsecIkeNegStatusExtendedEnd                        13909
#define kNtErrorIpsecBadSpi                                         13910
#define kNtErrorIpsecSaLifetimeExpired                              13911
#define kNtErrorIpsecWrongSa                                        13912
#define kNtErrorIpsecReplayCheckFailed                              13913
#define kNtErrorIpsecInvalidPacket                                  13914
#define kNtErrorIpsecIntegrityCheckFailed                           13915
#define kNtErrorIpsecClearTextDrop                                  13916
#define kNtErrorIpsecAuthFirewallDrop                               13917
#define kNtErrorIpsecThrottleDrop                                   13918
#define kNtErrorIpsecDospBlock                                      13925
#define kNtErrorIpsecDospReceivedMulticast                          13926
#define kNtErrorIpsecDospInvalidPacket                              13927
#define kNtErrorIpsecDospStateLookupFailed                          13928
#define kNtErrorIpsecDospMaxEntries                                 13929
#define kNtErrorIpsecDospKeymodNotAllowed                           13930
#define kNtErrorIpsecDospNotInstalled                               13931
#define kNtErrorIpsecDospMaxPerIpRatelimitQueues                    13932
#define kNtErrorSxsSectionNotFound                                  14000
#define kNtErrorSxsCantGenActctx                                    14001
#define kNtErrorSxsInvalidActctxdataFormat                          14002
#define kNtErrorSxsAssemblyNotFound                                 14003
#define kNtErrorSxsManifestFormatError                              14004
#define kNtErrorSxsManifestParseError                               14005
#define kNtErrorSxsActivationContextDisabled                        14006
#define kNtErrorSxsKeyNotFound                                      14007
#define kNtErrorSxsVersionConflict                                  14008
#define kNtErrorSxsWrongSectionType                                 14009
#define kNtErrorSxsThreadQueriesDisabled                            14010
#define kNtErrorSxsProcessDefaultAlreadySet                         14011
#define kNtErrorSxsUnknownEncodingGroup                             14012
#define kNtErrorSxsUnknownEncoding                                  14013
#define kNtErrorSxsInvalidXmlNamespaceUri                           14014
#define kNtErrorSxsRootManifestDependencyNotInstalled               14015
#define kNtErrorSxsLeafManifestDependencyNotInstalled               14016
#define kNtErrorSxsInvalidAssemblyIdentityAttribute                 14017
#define kNtErrorSxsManifestMissingRequiredDefaultNamespace          14018
#define kNtErrorSxsManifestInvalidRequiredDefaultNamespace          14019
#define kNtErrorSxsPrivateManifestCrossPathWithReparsePoint         14020
#define kNtErrorSxsDuplicateDllName                                 14021
#define kNtErrorSxsDuplicateWindowclassName                         14022
#define kNtErrorSxsDuplicateClsid                                   14023
#define kNtErrorSxsDuplicateIid                                     14024
#define kNtErrorSxsDuplicateTlbid                                   14025
#define kNtErrorSxsDuplicateProgid                                  14026
#define kNtErrorSxsDuplicateAssemblyName                            14027
#define kNtErrorSxsFileHashMismatch                                 14028
#define kNtErrorSxsPolicyParseError                                 14029
#define kNtErrorSxsXmlEMissingquote                                 14030
#define kNtErrorSxsXmlECommentsyntax                                14031
#define kNtErrorSxsXmlEBadstartnamechar                             14032
#define kNtErrorSxsXmlEBadnamechar                                  14033
#define kNtErrorSxsXmlEBadcharinstring                              14034
#define kNtErrorSxsXmlEXmldeclsyntax                                14035
#define kNtErrorSxsXmlEBadchardata                                  14036
#define kNtErrorSxsXmlEMissingwhitespace                            14037
#define kNtErrorSxsXmlEExpectingtagend                              14038
#define kNtErrorSxsXmlEMissingsemicolon                             14039
#define kNtErrorSxsXmlEUnbalancedparen                              14040
#define kNtErrorSxsXmlEInternalerror                                14041
#define kNtErrorSxsXmlEUnexpectedWhitespace                         14042
#define kNtErrorSxsXmlEIncompleteEncoding                           14043
#define kNtErrorSxsXmlEMissingParen                                 14044
#define kNtErrorSxsXmlEExpectingclosequote                          14045
#define kNtErrorSxsXmlEMultipleColons                               14046
#define kNtErrorSxsXmlEInvalidDecimal                               14047
#define kNtErrorSxsXmlEInvalidHexidecimal                           14048
#define kNtErrorSxsXmlEInvalidUnicode                               14049
#define kNtErrorSxsXmlEWhitespaceorquestionmark                     14050
#define kNtErrorSxsXmlEUnexpectedendtag                             14051
#define kNtErrorSxsXmlEUnclosedtag                                  14052
#define kNtErrorSxsXmlEDuplicateattribute                           14053
#define kNtErrorSxsXmlEMultipleroots                                14054
#define kNtErrorSxsXmlEInvalidatrootlevel                           14055
#define kNtErrorSxsXmlEBadxmldecl                                   14056
#define kNtErrorSxsXmlEMissingroot                                  14057
#define kNtErrorSxsXmlEUnexpectedeof                                14058
#define kNtErrorSxsXmlEBadperefinsubset                             14059
#define kNtErrorSxsXmlEUnclosedstarttag                             14060
#define kNtErrorSxsXmlEUnclosedendtag                               14061
#define kNtErrorSxsXmlEUnclosedstring                               14062
#define kNtErrorSxsXmlEUnclosedcomment                              14063
#define kNtErrorSxsXmlEUncloseddecl                                 14064
#define kNtErrorSxsXmlEUnclosedcdata                                14065
#define kNtErrorSxsXmlEReservednamespace                            14066
#define kNtErrorSxsXmlEInvalidencoding                              14067
#define kNtErrorSxsXmlEInvalidswitch                                14068
#define kNtErrorSxsXmlEBadxmlcase                                   14069
#define kNtErrorSxsXmlEInvalidStandalone                            14070
#define kNtErrorSxsXmlEUnexpectedStandalone                         14071
#define kNtErrorSxsXmlEInvalidVersion                               14072
#define kNtErrorSxsXmlEMissingequals                                14073
#define kNtErrorSxsProtectionRecoveryFailed                         14074
#define kNtErrorSxsProtectionPublicKeyTooShort                      14075
#define kNtErrorSxsProtectionCatalogNotValid                        14076
#define kNtErrorSxsUntranslatableHresult                            14077
#define kNtErrorSxsProtectionCatalogFileMissing                     14078
#define kNtErrorSxsMissingAssemblyIdentityAttribute                 14079
#define kNtErrorSxsInvalidAssemblyIdentityAttributeName             14080
#define kNtErrorSxsAssemblyMissing                                  14081
#define kNtErrorSxsCorruptActivationStack                           14082
#define kNtErrorSxsCorruption                                       14083
#define kNtErrorSxsEarlyDeactivation                                14084
#define kNtErrorSxsInvalidDeactivation                              14085
#define kNtErrorSxsMultipleDeactivation                             14086
#define kNtErrorSxsProcessTerminationRequested                      14087
#define kNtErrorSxsReleaseActivationContext                         14088
#define kNtErrorSxsSystemDefaultActivationContextEmpty              14089
#define kNtErrorSxsInvalidIdentityAttributeValue                    14090
#define kNtErrorSxsInvalidIdentityAttributeName                     14091
#define kNtErrorSxsIdentityDuplicateAttribute                       14092
#define kNtErrorSxsIdentityParseError                               14093
#define kNtErrorMalformedSubstitutionString                         14094
#define kNtErrorSxsIncorrectPublicKeyToken                          14095
#define kNtErrorUnmappedSubstitutionString                          14096
#define kNtErrorSxsAssemblyNotLocked                                14097
#define kNtErrorSxsComponentStoreCorrupt                            14098
#define kNtErrorAdvancedInstallerFailed                             14099
#define kNtErrorXmlEncodingMismatch                                 14100
#define kNtErrorSxsManifestIdentitySameButContentsDifferent         14101
#define kNtErrorSxsIdentitiesDifferent                              14102
#define kNtErrorSxsAssemblyIsNotADeployment                         14103
#define kNtErrorSxsFileNotPartOfAssembly                            14104
#define kNtErrorSxsManifestTooBig                                   14105
#define kNtErrorSxsSettingNotRegistered                             14106
#define kNtErrorSxsTransactionClosureIncomplete                     14107
#define kNtErrorSmiPrimitiveInstallerFailed                         14108
#define kNtErrorGenericCommandFailed                                14109
#define kNtErrorSxsFileHashMissing                                  14110
#define kNtErrorEvtInvalidChannelPath                               15000
#define kNtErrorEvtInvalidQuery                                     15001
#define kNtErrorEvtPublisherMetadataNotFound                        15002
#define kNtErrorEvtEventTemplateNotFound                            15003
#define kNtErrorEvtInvalidPublisherName                             15004
#define kNtErrorEvtInvalidEventData                                 15005
#define kNtErrorEvtChannelNotFound                                  15007
#define kNtErrorEvtMalformedXmlText                                 15008
#define kNtErrorEvtSubscriptionToDirectChannel                      15009
#define kNtErrorEvtConfigurationError                               15010
#define kNtErrorEvtQueryResultStale                                 15011
#define kNtErrorEvtQueryResultInvalidPosition                       15012
#define kNtErrorEvtNonValidatingMsxml                               15013
#define kNtErrorEvtFilterAlreadyscoped                              15014
#define kNtErrorEvtFilterNoteltset                                  15015
#define kNtErrorEvtFilterInvarg                                     15016
#define kNtErrorEvtFilterInvtest                                    15017
#define kNtErrorEvtFilterInvtype                                    15018
#define kNtErrorEvtFilterParseerr                                   15019
#define kNtErrorEvtFilterUnsupportedop                              15020
#define kNtErrorEvtFilterUnexpectedtoken                            15021
#define kNtErrorEvtInvalidOperationOverEnabledDirectChannel         15022
#define kNtErrorEvtInvalidChannelPropertyValue                      15023
#define kNtErrorEvtInvalidPublisherPropertyValue                    15024
#define kNtErrorEvtChannelCannotActivate                            15025
#define kNtErrorEvtFilterTooComplex                                 15026
#define kNtErrorEvtMessageNotFound                                  15027
#define kNtErrorEvtMessageIdNotFound                                15028
#define kNtErrorEvtUnresolvedValueInsert                            15029
#define kNtErrorEvtUnresolvedParameterInsert                        15030
#define kNtErrorEvtMaxInsertsReached                                15031
#define kNtErrorEvtEventDefinitionNotFound                          15032
#define kNtErrorEvtMessageLocaleNotFound                            15033
#define kNtErrorEvtVersionTooOld                                    15034
#define kNtErrorEvtVersionTooNew                                    15035
#define kNtErrorEvtCannotOpenChannelOfQuery                         15036
#define kNtErrorEvtPublisherDisabled                                15037
#define kNtErrorEvtFilterOutOfRange                                 15038
#define kNtErrorEcSubscriptionCannotActivate                        15080
#define kNtErrorEcLogDisabled                                       15081
#define kNtErrorEcCircularForwarding                                15082
#define kNtErrorEcCredstoreFull                                     15083
#define kNtErrorEcCredNotFound                                      15084
#define kNtErrorEcNoActiveChannel                                   15085
#define kNtErrorMuiFileNotFound                                     15100
#define kNtErrorMuiInvalidFile                                      15101
#define kNtErrorMuiInvalidRcConfig                                  15102
#define kNtErrorMuiInvalidLocaleName                                15103
#define kNtErrorMuiInvalidUltimatefallbackName                      15104
#define kNtErrorMuiFileNotLoaded                                    15105
#define kNtErrorResourceEnumUserStop                                15106
#define kNtErrorMuiIntlsettingsUilangNotInstalled                   15107
#define kNtErrorMuiIntlsettingsInvalidLocaleName                    15108
#define kNtErrorMrmRuntimeNoDefaultOrNeutralResource                15110
#define kNtErrorMrmInvalidPriconfig                                 15111
#define kNtErrorMrmInvalidFileType                                  15112
#define kNtErrorMrmUnknownQualifier                                 15113
#define kNtErrorMrmInvalidQualifierValue                            15114
#define kNtErrorMrmNoCandidate                                      15115
#define kNtErrorMrmNoMatchOrDefaultCandidate                        15116
#define kNtErrorMrmResourceTypeMismatch                             15117
#define kNtErrorMrmDuplicateMapName                                 15118
#define kNtErrorMrmDuplicateEntry                                   15119
#define kNtErrorMrmInvalidResourceIdentifier                        15120
#define kNtErrorMrmFilepathTooLong                                  15121
#define kNtErrorMrmUnsupportedDirectoryType                         15122
#define kNtErrorMrmInvalidPriFile                                   15126
#define kNtErrorMrmNamedResourceNotFound                            15127
#define kNtErrorMrmMapNotFound                                      15135
#define kNtErrorMrmUnsupportedProfileType                           15136
#define kNtErrorMrmInvalidQualifierOperator                         15137
#define kNtErrorMrmIndeterminateQualifierValue                      15138
#define kNtErrorMrmAutomergeEnabled                                 15139
#define kNtErrorMrmTooManyResources                                 15140
#define kNtErrorMrmUnsupportedFileTypeForMerge                      15141
#define kNtErrorMrmUnsupportedFileTypeForLoadUnloadPriFile          15142
#define kNtErrorMrmNoCurrentViewOnThread                            15143
#define kNtErrorDifferentProfileResourceManagerExist                15144
#define kNtErrorOperationNotAllowedFromSystemComponent              15145
#define kNtErrorMrmDirectRefToNonDefaultResource                    15146
#define kNtErrorMrmGenerationCountMismatch                          15147
#define kNtErrorPriMergeVersionMismatch                             15148
#define kNtErrorPriMergeMissingSchema                               15149
#define kNtErrorPriMergeLoadFileFailed                              15150
#define kNtErrorPriMergeAddFileFailed                               15151
#define kNtErrorPriMergeWriteFileFailed                             15152
#define kNtErrorPriMergeMultiplePackageFamiliesNotAllowed           15153
#define kNtErrorPriMergeMultipleMainPackagesNotAllowed              15154
#define kNtErrorPriMergeBundlePackagesNotAllowed                    15155
#define kNtErrorPriMergeMainPackageRequired                         15156
#define kNtErrorPriMergeResourcePackageRequired                     15157
#define kNtErrorPriMergeInvalidFileName                             15158
#define kNtErrorMcaInvalidCapabilitiesString                        15200
#define kNtErrorMcaInvalidVcpVersion                                15201
#define kNtErrorMcaMonitorViolatesMccsSpecification                 15202
#define kNtErrorMcaMccsVersionMismatch                              15203
#define kNtErrorMcaUnsupportedMccsVersion                           15204
#define kNtErrorMcaInternalError                                    15205
#define kNtErrorMcaInvalidTechnologyTypeReturned                    15206
#define kNtErrorMcaUnsupportedColorTemperature                      15207
#define kNtErrorAmbiguousSystemDevice                               15250
#define kNtErrorSystemDeviceNotFound                                15299
#define kNtErrorHashNotSupported                                    15300
#define kNtErrorHashNotPresent                                      15301
#define kNtErrorSecondaryIcProviderNotRegistered                    15321
#define kNtErrorGpioClientInformationInvalid                        15322
#define kNtErrorGpioVersionNotSupported                             15323
#define kNtErrorGpioInvalidRegistrationPacket                       15324
#define kNtErrorGpioOperationDenied                                 15325
#define kNtErrorGpioIncompatibleConnectMode                         15326
#define kNtErrorGpioInterruptAlreadyUnmasked                        15327
#define kNtErrorCannotSwitchRunlevel                                15400
#define kNtErrorInvalidRunlevelSetting                              15401
#define kNtErrorRunlevelSwitchTimeout                               15402
#define kNtErrorRunlevelSwitchAgentTimeout                          15403
#define kNtErrorRunlevelSwitchInProgress                            15404
#define kNtErrorServicesFailedAutostart                             15405
#define kNtErrorComTaskStopPending                                  15501
#define kNtErrorInstallOpenPackageFailed                            15600
#define kNtErrorInstallPackageNotFound                              15601
#define kNtErrorInstallInvalidPackage                               15602
#define kNtErrorInstallResolveDependencyFailed                      15603
#define kNtErrorInstallOutOfDiskSpace                               15604
#define kNtErrorInstallNetworkFailure                               15605
#define kNtErrorInstallRegistrationFailure                          15606
#define kNtErrorInstallDeregistrationFailure                        15607
#define kNtErrorInstallCancel                                       15608
#define kNtErrorInstallFailed                                       15609
#define kNtErrorRemoveFailed                                        15610
#define kNtErrorPackageAlreadyExists                                15611
#define kNtErrorNeedsRemediation                                    15612
#define kNtErrorInstallPrerequisiteFailed                           15613
#define kNtErrorPackageRepositoryCorrupted                          15614
#define kNtErrorInstallPolicyFailure                                15615
#define kNtErrorPackageUpdating                                     15616
#define kNtErrorDeploymentBlockedByPolicy                           15617
#define kNtErrorPackagesInUse                                       15618
#define kNtErrorRecoveryFileCorrupt                                 15619
#define kNtErrorInvalidStagedSignature                              15620
#define kNtErrorDeletingExistingApplicationdataStoreFailed          15621
#define kNtErrorInstallPackageDowngrade                             15622
#define kNtErrorSystemNeedsRemediation                              15623
#define kNtErrorAppxIntegrityFailureClrNgen                         15624
#define kNtErrorResiliencyFileCorrupt                               15625
#define kNtErrorInstallFirewallServiceNotRunning                    15626
#define kNtErrorPackageMoveFailed                                   15627
#define kNtErrorInstallVolumeNotEmpty                               15628
#define kNtErrorInstallVolumeOffline                                15629
#define kNtErrorInstallVolumeCorrupt                                15630
#define kNtErrorNeedsRegistration                                   15631
#define kNtErrorInstallWrongProcessorArchitecture                   15632
#define kNtErrorDevSideloadLimitExceeded                            15633
#define kNtErrorInstallOptionalPackageRequiresMainPackage           15634
#define kNtErrorPackageNotSupportedOnFilesystem                     15635
#define kNtErrorPackageMoveBlockedByStreaming                       15636
#define kNtErrorInstallOptionalPackageApplicationidNotUnique        15637
#define kNtErrorPackageStagingOnhold                                15638
#define kNtErrorInstallInvalidRelatedSetUpdate                      15639
#define kNtErrorPackagesReputationCheckFailed                       15643
#define kNtErrorPackagesReputationCheckTimedout                     15644
#define kNtErrorStateLoadStoreFailed                                15800
#define kNtErrorStateGetVersionFailed                               15801
#define kNtErrorStateSetVersionFailed                               15802
#define kNtErrorStateStructuredResetFailed                          15803
#define kNtErrorStateOpenContainerFailed                            15804
#define kNtErrorStateCreateContainerFailed                          15805
#define kNtErrorStateDeleteContainerFailed                          15806
#define kNtErrorStateReadSettingFailed                              15807
#define kNtErrorStateWriteSettingFailed                             15808
#define kNtErrorStateDeleteSettingFailed                            15809
#define kNtErrorStateQuerySettingFailed                             15810
#define kNtErrorStateReadCompositeSettingFailed                     15811
#define kNtErrorStateWriteCompositeSettingFailed                    15812
#define kNtErrorStateEnumerateContainerFailed                       15813
#define kNtErrorStateEnumerateSettingsFailed                        15814
#define kNtErrorStateCompositeSettingValueSizeLimitExceeded         15815
#define kNtErrorStateSettingValueSizeLimitExceeded                  15816
#define kNtErrorStateSettingNameSizeLimitExceeded                   15817
#define kNtErrorStateContainerNameSizeLimitExceeded                 15818
#define kNtErrorApiUnavailable                                      15841 /* EPROCUNAVAIL */

#define kNtWaitIoCompletion 0xc0

/* WinSock Error Codes: 10000-11999 */
#define WSABASEERR                  10000
#define WSAEINTR                    10004
#define WSAEBADF                    10009
#define WSAEACCES                   10013
#define WSAEFAULT                   10014
#define WSAEINVAL                   10022
#define WSAEMFILE                   10024
#define WSAEWOULDBLOCK              10035
#define WSAEINPROGRESS              10036
#define WSAEALREADY                 10037
#define WSAENOTSOCK                 10038
#define WSAEDESTADDRREQ             10039
#define WSAEMSGSIZE                 10040
#define WSAEPROTOTYPE               10041
#define WSAENOPROTOOPT              10042
#define WSAEPROTONOSUPPORT          10043
#define WSAESOCKTNOSUPPORT          10044
#define WSAEOPNOTSUPP               10045
#define WSAEPFNOSUPPORT             10046
#define WSAEAFNOSUPPORT             10047
#define WSAEADDRINUSE               10048
#define WSAEADDRNOTAVAIL            10049
#define WSAENETDOWN                 10050
#define WSAENETUNREACH              10051
#define WSAENETRESET                10052
#define WSAECONNABORTED             10053
#define WSAECONNRESET               10054
#define WSAENOBUFS                  10055
#define WSAEISCONN                  10056
#define WSAENOTCONN                 10057
#define WSAESHUTDOWN                10058
#define WSAETOOMANYREFS             10059
#define WSAETIMEDOUT                10060
#define WSAECONNREFUSED             10061
#define WSAELOOP                    10062
#define WSAENAMETOOLONG             10063
#define WSAEHOSTDOWN                10064
#define WSAEHOSTUNREACH             10065
#define WSAENOTEMPTY                10066
#define WSAEPROCLIM                 10067
#define WSAEUSERS                   10068
#define WSAEDQUOT                   10069
#define WSAESTALE                   10070
#define WSAEREMOTE                  10071
#define WSASYSNOTREADY              10091
#define WSAVERNOTSUPPORTED          10092
#define WSANOTINITIALISED           10093
#define WSAEDISCON                  10101
#define WSAENOMORE                  10102
#define WSAECANCELLED               10103
#define WSAEINVALIDPROCTABLE        10104
#define WSAEINVALIDPROVIDER         10105
#define WSAEPROVIDERFAILEDINIT      10106
#define WSASYSCALLFAILURE           10107
#define WSASERVICE_NOT_FOUND        10108
#define WSATYPE_NOT_FOUND           10109
#define WSA_E_NO_MORE               10110
#define WSA_E_CANCELLED             10111
#define WSAEREFUSED                 10112
#define WSAHOST_NOT_FOUND           11001
#define WSATRY_AGAIN                11002
#define WSANO_RECOVERY              11003
#define WSANO_DATA                  11004
#define WSA_QOS_RECEIVERS           11005
#define WSA_QOS_SENDERS             11006
#define WSA_QOS_NO_SENDERS          11007
#define WSA_QOS_NO_RECEIVERS        11008
#define WSA_QOS_REQUEST_CONFIRMED   11009
#define WSA_QOS_ADMISSION_FAILURE   11010
#define WSA_QOS_POLICY_FAILURE      11011
#define WSA_QOS_BAD_STYLE           11012
#define WSA_QOS_BAD_OBJECT          11013
#define WSA_QOS_TRAFFIC_CTRL_ERROR  11014
#define WSA_QOS_GENERIC_ERROR       11015
#define WSA_QOS_ESERVICETYPE        11016
#define WSA_QOS_EFLOWSPEC           11017
#define WSA_QOS_EPROVSPECBUF        11018
#define WSA_QOS_EFILTERSTYLE        11019
#define WSA_QOS_EFILTERTYPE         11020
#define WSA_QOS_EFILTERCOUNT        11021
#define WSA_QOS_EOBJLENGTH          11022
#define WSA_QOS_EFLOWCOUNT          11023
#define WSA_QOS_EUNKOWNPSOBJ        11024
#define WSA_QOS_EPOLICYOBJ          11025
#define WSA_QOS_EFLOWDESC           11026
#define WSA_QOS_EPSFLOWSPEC         11027
#define WSA_QOS_EPSFILTERSPEC       11028
#define WSA_QOS_ESDMODEOBJ          11029
#define WSA_QOS_ESHAPERATEOBJ       11030
#define WSA_QOS_RESERVED_PETYPE     11031
#define WSA_SECURE_HOST_NOT_FOUND   11032
#define WSA_IPSEC_NAME_POLICY_ERROR 11033

#define WSA_WAIT_FAILED         -1u
#define WSA_WAIT_EVENT_0        0
#define WSA_WAIT_IO_COMPLETION  0xc0
#define WSA_WAIT_TIMEOUT        258
#define WSA_MAXIMUM_WAIT_EVENTS 64
#define WSA_IO_PENDING          997


#define kNtWsaInvalidHandle    kNtErrorInvalidHandle
#define kNtWsaNotEnoughMemory  kNtErrorNotEnoughMemory
#define kNtWsaInvalidParameter kNtErrorInvalidParameter
#define kNtWsaIoPending        kNtErrorIoPending
#define kNtWsaIoIncomplete     kNtErrorIoIncomplete
#define kNtWsaOperationAborted kNtErrorOperationAborted



/*!BEGIN libc/nt/enum/wsaid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSAID_H_
COSMOPOLITAN_C_START_

#define WSAID_WSAPOLL                                \
  {                                                  \
    0x18C76F85, 0xDC66, 0x4964, {                    \
      0x97, 0x2E, 0x23, 0xC2, 0x72, 0x38, 0x31, 0x2B \
    }                                                \
  }

#define WSAID_WSARECVMSG                             \
  {                                                  \
    0xf689d7c8, 0x6f1f, 0x436b, {                    \
      0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22 \
    }                                                \
  }

#define WSAID_WSASENDMSG                             \
  {                                                  \
    0xa441e712, 0x754f, 0x43ca, {                    \
      0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d \
    }                                                \
  }

#define WSAID_CONNECTEX                              \
  {                                                  \
    0x25a207b9, 0xddf3, 0x4660, {                    \
      0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e \
    }                                                \
  }

#define WSAID_ACCEPTEX                               \
  {                                                  \
    0xb5367df1, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_GETACCEPTEXSOCKADDRS                   \
  {                                                  \
    0xb5367df2, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITFILE                           \
  {                                                  \
    0xb5367df0, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITPACKETS                        \
  {                                                  \
    0xd9689da0, 0x1f90, 0x11d3, {                    \
      0x99, 0x71, 0x00, 0xc0, 0x4f, 0x68, 0xc8, 0x76 \
    }                                                \
  }

#define WSAID_DISCONNECTEX                           \
  {                                                  \
    0x7fda2e11, 0x8630, 0x436f, {                    \
      0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57 \
    }                                                \
  }

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/wt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WT_H_

#define kNtWtExecutedefault            0x00000000u
#define kNtWtExecuteonlyonce           0x00000008u
#define kNtWtExecuteintimerthread      0x00000020u
#define kNtWtExecuteinpersistentthread 0x00000080u
#define kNtWtExecutelongfunction       0x00000010u
#define kNtWtTransferImpersonation     0𝔵00000100𝔲



/*!BEGIN libc/nt/struct/acl.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ACL_H_

struct NtAcl {
  uint8_t AclRevision;
  uint8_t Sbz1;
  uint16_t AclSize;
  uint16_t AceCount;
  uint16_t Sbz2;
};



/*!BEGIN libc/nt/struct/afd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_AFD_H_
COSMOPOLITAN_C_START_

struct NtAfdPollHandleInfo {
  int64_t Handle;
  uint32_t Events;
  NtStatus Status;
};

struct NtAfdPollInfo {
  int64_t Timeout;
  uint32_t NumberOfHandles;
  uint32_t Exclusive;
  struct NtAfdPollHandleInfo Handles[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ansistring.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ANSISTRING_H_

struct NtAnsiString {
  unsigned short Length;
  unsigned short MaximumLength;
  char *Buffer;
};



/*!BEGIN libc/nt/struct/byhandlefileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_BYHANDLEFILEINFORMATION_H_


/*!BEGIN libc/nt/struct/filetime.h */

#define COSMOPOLITAN_LIBC_NT_FILETIME_H_

struct NtFileTime {
  uint32_t dwLowDateTime;
  uint32_t dwHighDateTime;
};


struct NtByHandleFileInformation {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationFileTime;
  struct NtFileTime ftLastAccessFileTime;
  struct NtFileTime ftLastWriteFileTime;
  uint32_t dwVolumeSerialNumber;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t nNumberOfLinks;
  uint32_t nFileIndexHigh;
  uint32_t nFileIndexLow;
};



/*!BEGIN libc/nt/struct/charinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CHARINFO_H_

struct NtCharInfo {
  union {
    char16_t UnicodeChar;
    char AsciiChar;
  } Char;
  uint16_t Attributes;
};



/*!BEGIN libc/nt/struct/clientid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CLIENTID_H_

struct NtClientId {
  void *UniqueProcess;
  void *UniqueThread;
};



/*!BEGIN libc/nt/struct/consolecursorinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLECURSORINFO_H_

struct NtConsoleCursorInfo {
  uint32_t dwSize;
  bool32 bVisible;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFO_H_


/*!BEGIN libc/nt/struct/coord.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COORD_H_

struct NtCoord {
  int16_t X;
  int16_t Y;
};



/*!BEGIN libc/nt/struct/smallrect.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SMALLRECT_H_

struct NtSmallRect {
  int16_t Left;
  int16_t Top;
  int16_t Right;
  int16_t Bottom;
};


struct NtConsoleScreenBufferInfo {
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes;
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFOEX_H_

struct NtConsoleScreenBufferInfoEx {
  uint32_t cbSize; /* sizeof(struct NtConsoleScreenBufferInfoEx) */
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes; /* kNt{Foreground,Background}... */
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
  uint16_t wPopupAttributes;
  bool32 bFullscreenSupported;
  uint32_t ColorTable[16]; /* 0x00BBGGRR */
};



/*!BEGIN libc/nt/struct/consoleselectioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESELECTIONINFO_H_

struct NtConsoleSelectionInfo {
  uint32_t dwFlags;
  struct NtCoord dwSelectionAnchor;
  struct NtSmallRect srSelection;
};



/*!BEGIN libc/nt/struct/context.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONTEXT_H_

struct NtM128A {
  uint64_t Low;
  int64_t High;
};

struct NtXmmSaveArea32 { /* basically same as struct FpuState */
  uint16_t ControlWord;
  uint16_t StatusWord;
  uint8_t TagWord;
  uint8_t Reserved1;
  uint16_t ErrorOpcode;
  uint32_t ErrorOffset;
  uint16_t ErrorSelector;
  uint16_t Reserved2;
  uint32_t DataOffset;
  uint16_t DataSelector;
  uint16_t Reserved3;
  uint32_t MxCsr;
  uint32_t MxCsr_Mask;
  struct NtM128A FloatRegisters[8];
  struct NtM128A XmmRegisters[16];
  uint8_t Reserved4[96];
};

struct NtContext {
  uint64_t P1Home, P2Home, P3Home, P4Home, P5Home, P6Home;
  uint32_t ContextFlags;
  uint32_t MxCsr;
  uint16_t SegCs, SegDs, SegEs, SegFs, SegGs, SegSs;
  uint32_t EFlags;
  uint64_t Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
  uint64_t Rax, Rcx, Rdx, Rbx, Rsp, Rbp, Rsi, Rdi;
  uint64_t R8, R9, R10, R11, R12, R13, R14, R15;
  uint64_t Rip;
  union {
    struct NtXmmSaveArea32 FltSave;
    struct NtXmmSaveArea32 FloatSave;
    struct {
      struct NtM128A Header[2];
      struct NtM128A Legacy[8];
      struct NtM128A Xmm0, Xmm1, Xmm2, Xmm3, Xmm4, Xmm5, Xmm6, Xmm7;
      struct NtM128A Xmm8, Xmm9, Xmm10, Xmm11, Xmm12, Xmm13, Xmm14, Xmm15;
    };
  };
  struct NtM128A VectorRegister[26];
  uint64_t VectorControl;
  uint64_t DebugControl;
  uint64_t LastBranchToRip;
  uint64_t LastBranchFromRip;
  uint64_t LastExceptionToRip;
  uint64_t LastExceptionFromRip;
} forcealign(16);



/*!BEGIN libc/nt/struct/criticalsection.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTION_H_


/*!BEGIN libc/nt/struct/criticalsectiondebug.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTIONDEBUG_H_


/*!BEGIN libc/nt/struct/linkedlist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINKEDLIST_H_

/**
 * Dynamic linked list overlay.
 */
struct NtLinkedList {
  struct NtLinkedList *Next;
  struct NtLinkedList *Prev;
};


struct NtCriticalSectionDebug {
  uint16_t Type;
  uint16_t CreatorBackTraceIndex;
  struct NtCriticalSection *CriticalSection;
  struct NtLinkedList ProcessLocksList;
  uint32_t EntryCount;
  uint32_t ContentionCount;
  uint32_t Spare[2];
};


struct NtCriticalSection {
  struct NtCriticalSectionDebug *DebugInfo;
  int32_t LockCount;
  int32_t RecursionCount;
  void *OwningThread;
  void *LockSemaphore;
  uintptr_t SpinCount;
};



/*!BEGIN libc/nt/struct/drawtextparams.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DRAWTEXTPARAMS_H_
COSMOPOLITAN_C_START_

struct NtDrawTextParams {
  uint32_t cbSize;
  int32_t iTabLength;
  int32_t iLeftMargin;
  int32_t iRightMargin;
  uint32_t uiLengthDrawn;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/dynamictimezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DYNAMICTIMEZONEINFORMATION_H_


/*!BEGIN libc/nt/struct/systemtime.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIME_H_

struct NtSystemTime {
  uint16_t wYear;
  uint16_t wMonth;
  uint16_t wDayOfWeek;
  uint16_t wDay;
  uint16_t wHour;
  uint16_t wMinute;
  uint16_t wSecond;
  uint16_t wMilliseconds;
};


struct NtDynamicTimeZoneInformation {
  int32_t Bias;
  char16_t StandardName[32];
  struct NtSystemTime StandardDate;
  int32_t StandardBias;
  char16_t DaylightName[32];
  struct NtSystemTime DaylightDate;
  int32_t DaylightBias;
  char16_t TimeZoneKeyName[128];
  bool32 DynamicDaylightTimeDisabled;
};



/*!BEGIN libc/nt/struct/editmenu.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EDITMENU_H_

struct NtEditMenu {
  int64_t hmenu;
  uint16_t idEdit;
  uint16_t idCut;
  uint16_t idCopy;
  uint16_t idPaste;
  uint16_t idClear;
  uint16_t idUndo;
};



/*!BEGIN libc/nt/struct/exceptionframe.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EXCEPTIONFRAME_H_

struct NtExceptionFrame {
  struct NtExceptionFrame *Prev;
};



/*!BEGIN libc/nt/struct/fdset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FDSET_H_
COSMOPOLITAN_C_START_

struct NtFdSet {
  uint32_t fd_count;
  int64_t fd_array[64];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/fileaccessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEACCESSINFORMATION_H_

struct NtFileAccessInformation {
  uint32_t AccessFlags;
};



/*!BEGIN libc/nt/struct/filealignmentinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALIGNMENTINFORMATION_H_

struct NtFileAlignmentInformation {
  uint32_t AlignmentRequirement;
};



/*!BEGIN libc/nt/struct/fileallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLINFORMATION_H_


/*!BEGIN libc/nt/struct/filebasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFORMATION_H_

struct NtFileBasicInformation {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/fileeainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEEAINFORMATION_H_

struct NtFileEaInformation {
  uint32_t EaSize;
};



/*!BEGIN libc/nt/struct/fileinternalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEINTERNALINFORMATION_H_

struct NtFileInternalInformation {
  int64_t IndexNumber;
};



/*!BEGIN libc/nt/struct/filemodeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMODEINFORMATION_H_

struct NtFileModeInformation {
  uint32_t Mode;
};



/*!BEGIN libc/nt/struct/filenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMEINFORMATION_H_

struct NtFileNameInformation {
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filepositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPOSITIONINFORMATION_H_

struct NtFilePositionInformation {
  int64_t CurrentByteOffset;
};



/*!BEGIN libc/nt/struct/filestandardinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTANDARDINFORMATION_H_

struct NtFileStandardInformation {
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t NumberOfLinks;
  bool32 DeletePending;
  bool32 Directory;
};


struct NtFileAllInformation {
  struct NtFileBasicInformation BasicInformation;
  struct NtFileStandardInformation StandardInformation;
  struct NtFileInternalInformation InternalInformation;
  struct NtFileEaInformation EaInformation;
  struct NtFileAccessInformation AccessInformation;
  struct NtFilePositionInformation PositionInformation;
  struct NtFileModeInformation ModeInformation;
  struct NtFileAlignmentInformation AlignmentInformation;
  struct NtFileNameInformation NameInformation;
};



/*!BEGIN libc/nt/struct/fileallocationinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLOCATIONINFORMATION_H_

struct NtFileAllocationInformation {
  int64_t AllocationSize;
};



/*!BEGIN libc/nt/struct/fileattributetaginformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEATTRIBUTETAGINFORMATION_H_

struct NtFileAttributeTagInformation {
  uint32_t FileAttributes;
  uint32_t ReparseTag;
};



/*!BEGIN libc/nt/struct/filebasicinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFO_H_

struct NtFileBasicInfo {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/filebothdirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBOTHDIRECTORYINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileBothDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  unsigned char ShortNameLength;
  char16_t ShortName[12];
  char16_t FileName[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filecompressioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILECOMPRESSIONINFO_H_

struct NtFileCompressionInfo {
  int64_t CompressedFileSize;
  uint16_t CompressionFormat;
  uint8_t CompressionUnitShift;
  uint8_t ChunkShift;
  uint8_t ClusterShift;
  uint8_t Reserved[3];
};



/*!BEGIN libc/nt/struct/filedirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDIRECTORYINFORMATION_H_

struct NtFileDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filedispositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDISPOSITIONINFORMATION_H_

struct NtFileDispositionInformation {
  bool32 DoDeleteFile;
};



/*!BEGIN libc/nt/struct/fileendoffileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEENDOFFILEINFORMATION_H_

struct FileEndOfFileInformation {
  int64_t EndOfFile;
};



/*!BEGIN libc/nt/struct/filefsfullsizeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFSFULLSIZEINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileFsFullSizeInformation {
  int64_t TotalAllocationUnits;
  int64_t CallerAvailableAllocationUnits;
  int64_t ActualAvailableAllocationUnits;
  uint32_t SectorsPerAllocationUnit;
  uint32_t BytesPerSector;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filefulldirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLDIRECTORYINFORMATION_H_

struct NtFileFullDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filefulleainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLEAINFORMATION_H_

struct NtFileFullEaInformation {
  uint32_t NextEntryOffset;
  uint8_t Flags;
  uint8_t EaNameLength;
  uint16_t EaValueLength;
  char EaName[1];
};



/*!BEGIN libc/nt/struct/filemailslotqueryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTQUERYINFORMATION_H_

struct NtFileMailslotQueryInformation {
  uint32_t MaximumMessageSize;
  uint32_t MailslotQuota;
  uint32_t NextMessageSize;
  uint32_t MessagesAvailable;
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filemailslotsetinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTSETINFORMATION_H_

struct NtFileMailslotSetInformation {
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filenamesinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMESINFORMATION_H_

struct NtFileNamesInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filenetworkopeninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENETWORKOPENINFORMATION_H_

struct NtFileNetworkOpenInformation {
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t FileAttributes;
};



/*!BEGIN libc/nt/struct/filepipelocalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPIPELOCALINFORMATION_H_

struct NtFilePipeLocalInformation {
  uint32_t NamedPipeType;
  uint32_t NamedPipeConfiguration;
  uint32_t MaximumInstances;
  uint32_t CurrentInstances;
  uint32_t InboundQuota;
  uint32_t ReadDataAvailable;
  uint32_t OutboundQuota;
  uint32_t WriteQuotaAvailable;
  uint32_t NamedPipeState;
  uint32_t NamedPipeEnd;
};



/*!BEGIN libc/nt/struct/filerenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILERENAMEINFORMATION_H_

struct NtFileRenameInformation {
  bool32 Replace;
  void *RootDir;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filesegmentelement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESEGMENTELEMENT_H_

union NtFileSegmentElement {
  void *Buffer;
  uint64_t Alignment;
};



/*!BEGIN libc/nt/struct/filestreaminformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTREAMINFORMATION_H_

struct NtFileStreamInformation {
  uint32_t NextEntryOffset;
  uint32_t StreamNameLength;
  int64_t StreamSize;
  int64_t StreamAllocationSize;
  char16_t StreamName[1];
};



/*!BEGIN libc/nt/struct/filezerodatainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEZERODATAINFORMATION_H_

struct NtFileZeroDataInformation {
  uint64_t FileOffset;
  uint64_t BeyondFinalZero;
};



/*!BEGIN libc/nt/struct/fpodata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FPODATA_H_

struct NtFpoData {
  /* TODO(jart): No bitfields. */
  uint32_t ulOffStart;
  uint32_t cbProcSize;
  uint32_t cdwLocals;
  uint16_t cdwParams;
  uint16_t cbProlog : 8;
  uint16_t cbRegs : 3;
  uint16_t fHasSEH : 1;
  uint16_t fUseBP : 1;
  uint16_t reserved : 1;
  uint16_t cbFrame : 2;
};



/*!BEGIN libc/nt/struct/genericmapping.h */

#define COSMOPOLITAN_LIBC_NT_GENERICMAPPING_H_

struct NtGenericMapping {
  unsigned int GenericRead;
  unsigned int GenericWrite;
  unsigned int GenericExecute;
  unsigned int GenericAll;
};



/*!BEGIN libc/nt/struct/guid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_GUID_H_
COSMOPOLITAN_C_START_

struct NtGuid {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/inputrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_INPUTRECORD_H_

struct NtKeyEventRecord {
  bool32 bKeyDown;
  uint16_t wRepeatCount;
  uint16_t wVirtualKeyCode;
  uint16_t wVirtualScanCode;
  union {
    uint16_t UnicodeChar;
    char AsciiChar;
  } uChar;
  unsigned int dwControlKeyState;
#define kNtRightAltPressed  0x0001
#define kNtLeftAltPressed   0x0002
#define kNtRightCtrlPressed 0x0004
#define kNtLeftCtrlPressed  0x0008
#define kNtShiftPressed     0x0010
#define kNtNumlockOn        0x0020
#define kNtScrolllockOn     0x0040
#define kNtCapslockOn       0x0080
#define kNtEnhancedKey      0x0100
};

struct NtMouseEventRecord {
  struct NtCoord dwMousePosition;
  uint32_t dwButtonState;
#define kNtFromLeft1stButtonPressed 0x0001
#define kNtRightmostButtonPressed   0x0002
#define kNtFromLeft2ndButtonPressed 0x0004
#define kNtFromLeft3rdButtonPressed 0x0008
#define kNtFromLeft4thButtonPressed 0x0010
  uint32_t dwControlKeyState;
  uint32_t dwEventFlags;
#define kNtMouseMoved    0x0001
#define kNtDoubleClick   0x0002
#define kNtMouseWheeled  0x0004
#define kNtMouseHwheeled 0x0008
};

struct NtWindowBufferSizeRecord {
  struct NtCoord dwSize;
};

struct NtMenuEventRecord {
  uint32_t dwCommandId;
};

struct NtFocusEventRecord {
  bool32 bSetFocus;
};

struct NtInputRecord {
  uint16_t EventType;
#define kNtKeyEvent              0x0001
#define kNtMouseEvent            0x0002
#define kNtWindowBufferSizeEvent 0x0004
#define kNtMenuEvent             0x0008
#define kNtFocusEvent            0x0010
  union {
    struct NtKeyEventRecord KeyEvent;
    struct NtMouseEventRecord MouseEvent;
    struct NtWindowBufferSizeRecord WindowBufferSizeEvent;
    struct NtMenuEventRecord MenuEvent;
    struct NtFocusEventRecord FocusEvent;
  } Event;
};



/*!BEGIN libc/nt/struct/iocounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOCOUNTERS_H_

struct NtIoCounters {
  uint64_t ReadOperationCount;
  uint64_t WriteOperationCount;
  uint64_t OtherOperationCount;
  uint64_t ReadTransferCount;
  uint64_t WriteTransferCount;
  uint64_t OtherTransferCount;
};



/*!BEGIN libc/nt/struct/iostatusblock.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOSTATUSBLOCK_H_

struct NtIoStatusBlock {
  union {
    NtStatus Status;
    void *Pointer; /* reserved for internal use */
  };
  uint32_t *Information; /* request dependent */
};



/*!BEGIN libc/nt/struct/iovec.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct NtIovec {
  uint32_t len;
  char *buf;
};

void DescribeIovNt(const struct NtIovec *, uint32_t, ssize_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ipadapteraddresses.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IP_ADAPTER_ADDRESSES_H_


/*!BEGIN libc/nt/winsock.h */

#define COSMOPOLITAN_LIBC_NT_WINSOCK_H_


/*!BEGIN libc/nt/struct/overlapped.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPED_H_

struct NtOverlapped {
  uintptr_t Internal;
  uintptr_t InternalHigh;
  union {
    struct {
      uint32_t Offset;
      uint32_t OffsetHigh;
    };
    int64_t Pointer;
  };
  int64_t hEvent;
};



/*!BEGIN libc/nt/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POLLFD_H_

struct sys_pollfd_nt {
  int64_t handle;
  int16_t events;
  int16_t revents;
};



/*!BEGIN libc/nt/struct/timeval.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEVAL_H_
COSMOPOLITAN_C_START_

struct NtTimeval {
  int32_t tv_sec; /* [sic] */
  int32_t tv_usec;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thunk/msabi.h */

#define COSMOPOLITAN_LIBC_NT_THUNK_MSABI_H_
#ifdef __x86_64__

#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
     (__has_attribute(__ms_abi__) || defined(__llvm__)))
/**
 * Defines function as using Microsoft x64 calling convention.
 *
 * This can be used to define prototypes that allow modern compilers to
 * generate code that calls MS ABI functions directly, without needing
 * to jump through the assembly thunks.
 */
#define __msabi __attribute__((__ms_abi__))
#endif

/*
 * Returns true if header should provide MS-ABI overrides.
 */
#ifndef ShouldUseMsabiAttribute
#if defined(__msabi) && defined(NDEBUG) && !defined(__PG__) && !defined(FTRACE)
#define ShouldUseMsabiAttribute() 1
#else
#define ShouldUseMsabiAttribute() 0
#endif
#endif

#else
#define __msabi
#ifndef ShouldUseMsabiAttribute
#define ShouldUseMsabiAttribute() 0
#endif
#endif /* __x86_64__ */


/*!BEGIN libc/sock/sock.h */

#define COSMOPOLITAN_LIBC_SOCK_SOCK_H_
COSMOPOLITAN_C_START_

#define INET_ADDRSTRLEN 22
#define IFHWADDRLEN     6

libcesque uint16_t htons(uint16_t) pureconst;
libcesque uint16_t ntohs(uint16_t) pureconst;
libcesque uint32_t htonl(uint32_t) pureconst;
libcesque uint32_t ntohl(uint32_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define htons(x) __builtin_bswap16(x)
#define ntohs(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define ntohl(x) __builtin_bswap32(x)
#endif

const char *inet_ntop(int, const void *, char *, uint32_t) libcesque;
int inet_pton(int, const char *, void *) libcesque;
uint32_t inet_addr(const char *) libcesque;
libcesque uint32_t *GetHostIps(void) __wur;

int socket(int, int, int) libcesque;
int listen(int, int) libcesque;
int shutdown(int, int) libcesque;
ssize_t send(int, const void *, size_t, int) libcesque;
ssize_t recv(int, void *, size_t, int) libcesque;
ssize_t sendfile(int, int, int64_t *, size_t) libcesque;
int getsockopt(int, int, int, void *, uint32_t *) libcesque;
int setsockopt(int, int, int, const void *, uint32_t) libcesque;
int socketpair(int, int, int, int[2]) libcesque;
int sockatmark(int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/sockaddr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_H_
COSMOPOLITAN_C_START_

struct sockaddr {     /* Linux+NT ABI */
  uint16_t sa_family; /* AF_XXX */
  char sa_data[14];
};

struct in_addr { /* ARPA ABI */
  /* e.g. 127|0<<8|0<<16|1<<24 or inet_pton(AF_INET, "127.0.0.1", &s_addr) */
  uint32_t s_addr;
};

struct sockaddr_in {   /* Linux+NT ABI */
  uint16_t sin_family; /* AF_XXX */
  uint16_t sin_port;   /* htons(XXX) i.e. big endian */
  struct in_addr sin_addr;
  uint8_t sin_zero[8];
};

struct sockaddr_un {
  uint16_t sun_family; /* AF_UNIX */
  char sun_path[108];  /* path */
};

struct sockaddr_storage {
  union {
    uint16_t ss_family;
    intptr_t __ss_align;
    char __ss_storage[128];
  };
};

int inet_aton(const char *, struct in_addr *);
char *inet_ntoa(struct in_addr);
int accept(int, struct sockaddr *, uint32_t *);
int accept4(int, struct sockaddr *, uint32_t *, int);
int bind(int, const struct sockaddr *, uint32_t);
int connect(int, const struct sockaddr *, uint32_t);
int getsockname(int, struct sockaddr *, uint32_t *);
int getpeername(int, struct sockaddr *, uint32_t *);
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, uint32_t *);
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
               uint32_t);

COSMOPOLITAN_C_END_
/* ░▓█████████████████████████████████████████████▓▒
   ░█▓░░░░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒░
   ░█▓░ ░▒▒▒▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░ ░▓▓▓▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░       ░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒▒
   ░███████████████████████████████████████████████▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░          ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░             ▒█▓▒▒
   ░█▓░        ░▒░                 ▒█▓░          ▒█▓▒▒
   ░█▓░      ░░░░    ░░░░░░░░      ▒▓▓▓▒░        ▒█▓▒▒
   ░█▓░    ░░░░  ░░░░░▒▒▓███▓░░░░░░░░▒▓▓▓▓▒      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒████▓░░░░░░░░░░▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒▓▓▓▓▓░░░░░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▒▒▒░░░░░ ░▒▒▒▒░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓   ░▓█▓▒▒▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░░▒██▓   ░████▓▒░
   ░█▓░     ░░░░░░░░▒▒░░░░░░░░░▒▒░░░▒▒▓▓▒░░    ░░▓███▓▒░
   ░█▓░      ░░░░░░░░░░░░░░░░░░░░░░▒▓▓▓▒░        ▒████▓▒░░░░░░
   ░█▓░        ░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░        ░▓▓▓▓██▒░░░░░░░░
   ░█▓░          ▒█████████████████▒  ▓█▓▒░      ▒█▓ ░█▓      ░▓▓░
   ░█▓░                              ░▓████▒░    ▒█▓▒░  ░░░░░░░  ▓█▓░
   ░█▓░                                ░▓████▒░  ░▒░  ░░░░░░░░░░░  ░█▓
   ░█▓                                    ▒███▓▒▒░  ░░░░░░░░░░░░░░░  ▒▓▓
   ░██████████████████████████████████████▓▒▓█▓░  ░░░░░░░░░░░░░░░░░░ ▒█▓
    ▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░ ░░░░░░░░░░░░░░░░░░░░▒█▓
         ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒██▒▒▒░░░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░██▒▒▒▒▒░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░▒▓█▓
                                            ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░▒▒▒▒▓▓▒
                                              ░██▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  ░█▓
                                                 ▒█▓▒▒▒▒▒▒▒▒▒▒▒██▓▒░ ░█▓
                                                   ▒█████████████▓▒▒░  ░██▒
╔────────────────────────────────────────────────────────────────▀▀▀▀───▀▀▀▀─│─╗
│ cosmopolitan § new technology » winsock                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtWsaFlagOverlapped      0x01
#define kNtWsaFlagNoHandleInherit 0x80

#define kNtCompEqual   0
#define kNtCompNotless 1

#define kNtTfDisconnect       0x01
#define kNtTfReuseSocket      0x02
#define kNtTfWriteBehind      0x04
#define kNtTfUseDefaultWorker 0x00
#define kNtTfUseSystemThread  0x10
#define kNtTfUseKernelApc     0x20

#define kNtSoConnectTime          0x700C
#define kNtSoUpdateAcceptContext  0x700B
#define kNtSoUpdateConnectContext 0x7010

#define kNtNspNotifyImmediately 0
#define kNtNspNotifyHwnd        1
#define kNtNspNotifyEvent       2
#define kNtNspNotifyPort        3
#define kNtNspNotifyApc         4

COSMOPOLITAN_C_START_

struct NtMsgHdr {
  struct sockaddr *name;
  int32_t namelen;
  struct NtIovec *lpBuffers;
  uint32_t dwBufferCount;
  struct NtIovec Control;
  uint32_t dwFlags;
};

struct NtWsaData {
  uint16_t wVersion;
  uint16_t wHighVersion;
  uint16_t iMaxSockets;
  uint16_t iMaxUdpDg;
  char *lpVendorInfo;
  char szDescription[257];
  char szSystemStatus[129];
};

struct NtSocketAddress {
  struct sockaddr *lpSockaddr;
  int32_t iSockaddrLength;
};

struct NtSocketAddressList {
  int32_t iAddressCount;
  struct NtSocketAddress Address[1];
};

struct NtAddrInfoEx {  /* win8+ */
  int32_t ai_flags;    /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
  int32_t ai_family;   /* PF_XXX */
  int32_t ai_socktype; /* SOCK_XXX */
  int32_t ai_protocol;
  uint64_t ai_addrlen;
  char16_t *ai_canonname;
  struct sockaddr *ai_addr;
  void *ai_blob;
  uint64_t ai_bloblen;
  struct NtGuid *ai_provider;
  struct NtAddrInfoEx *ai_next;
  int32_t ai_version;          /* v2 */
  char16_t *ai_fqdn;           /* v2 */
  int32_t ai_interfaceindex;   /* v3 */
  int64_t ai_resolutionhandle; /* v4 */
};

struct NtWsaProtocolChain {
  int32_t ChainLen;
  uint32_t ChainEntries[7];
};

struct NtWsaProtocolInfo {
  uint32_t dwServiceFlags1;
  uint32_t dwServiceFlags2;
  uint32_t dwServiceFlags3;
  uint32_t dwServiceFlags4;
  uint32_t dwProviderFlags;
  struct NtGuid ProviderId;
  uint32_t dwCatalogEntryId;
  struct NtWsaProtocolChain ProtocolChain;
  int32_t iVersion;
  int32_t iAddressFamily;
  int32_t iMaxSockAddr;
  int32_t iMinSockAddr;
  int32_t iSocketType;
  int32_t iProtocol;
  int32_t iProtocolMaxOffset;
  int32_t iNetworkByteOrder;
  int32_t iSecurityScheme;
  uint32_t dwMessageSize;
  uint32_t dwProviderReserved;
  char16_t szProtocol[256];
};

struct NtFlowSpec {
  uint32_t TokenRate;          /* bytes/sec */
  uint32_t TokenBucketSize;    /* bytes */
  uint32_t PeakBandwidth;      /* bytes/sec */
  uint32_t Latency;            /* µs */
  uint32_t DelayVariation;     /* µs */
  uint32_t ServiceType;        /* kNtServicetypeXxx */
  uint32_t MaxSduSize;         /* bytes */
  uint32_t MinimumPolicedSize; /* bytes */
};

struct NtQos {
  struct NtFlowSpec SendingFlowspec;
  struct NtFlowSpec ReceivingFlowspec;
  struct NtIovec ProviderSpecific;
};

struct NtWsaVersion {
  uint32_t dwVersion;
  int ecHow;
};

struct NtAfProtocols {
  int32_t iAddressFamily;
  int32_t iProtocol;
};

struct NtBlob {
  uint32_t cbSize;
  uint8_t pBlobData;
};

struct NtCsAddrInfo {
  struct NtSocketAddress LocalAddr;
  struct NtSocketAddress RemoteAddr;
  int32_t iSocketType;
  int32_t iProtocol;
};

struct NtWsaQuerySet {
  uint32_t dwSize; /* of this */
  char16_t *lpszServiceInstanceName;
  struct NtGuid *lpServiceClassId;
  struct NtWsaVersion *lpVersion;
  char16_t *lpszComment;
  uint32_t dwNameSpace;
  struct NtGuid *lpNSProviderId;
  char16_t *lpszContext;
  uint32_t dwNumberOfProtocols;
  struct NtAfProtocols *lpafpProtocols /*[dwNumberOfProtocols]*/;
  char16_t *lpszQueryString;
  uint32_t dwNumberOfCsAddrs;
  struct NtCsAddrInfo *lpcsaBuffer /*[dwNumberOfCsAddrs]*/;
  uint32_t dwOutputFlags;
  struct NtBlob *lpBlob;
};

struct NtWsaNamespaceInfoEx {
  struct NtGuid NSProviderId;
  uint32_t dwNameSpace;
  bool32 fActive;
  uint32_t dwVersion;
  char16_t *lpszIdentifier;
  struct NtBlob *ProviderSpecific;
};

struct NtWsansClassInfo {
  char16_t *lpszName;
  uint32_t dwNameSpace;
  uint32_t dwValueType;
  uint32_t dwValueSize;
  void *lpValue;
};

struct NtWsaServiceClassInfo {
  struct NtGuid *lpServiceClassId;
  char16_t *lpszServiceClassName;
  uint32_t dwCount;
  struct NtWsansClassInfo *lpClassInfos;
};

struct NtWsaNetworkEvents {
  int32_t lNetworkEvents;
  int32_t iErrorCode[10];
};

struct NtTransmitFileBuffers {
  void *Head;
  uint32_t HeadLength;
  void *Tail;
  uint32_t TailLength;
};

typedef int (*NtConditionProc)(
    const struct NtIovec *lpCallerId, const struct NtIovec *lpCallerData,
    struct NtQos *inout_lpSQOS, struct NtQos *inout_lpGQOS,
    const struct NtIovec *lpCalleeId, const struct NtIovec *lpCalleeData,
    uint32_t *out_group, const uint32_t *dwCallbackData);

typedef void (*NtWsaOverlappedCompletionRoutine)(
    uint32_t dwError, uint32_t cbTransferred,
    const struct NtOverlapped *lpOverlapped, uint32_t dwFlags);

struct NtWsaCompletion {
  int Type;
  union {
    struct {
      int64_t hWnd;
      uint32_t uMsg;
      uintptr_t context;
    } WindowMessage;
    struct {
      struct NtOverlapped *lpOverlapped;
    } Event;
    struct {
      struct NtOverlapped *lpOverlapped;
      NtWsaOverlappedCompletionRoutine lpfnCompletionProc;
    } Apc;
    struct {
      struct NtOverlapped *lpOverlapped;
      int64_t hPort;
      uint32_t Key;
    } Port;
  } Parameters;
};

struct NtInterfaceInfo {
  uint64_t iiFlags;
  struct sockaddr_in iiAddress;
  struct sockaddr_in iiBroadcastAddress;
  struct sockaddr_in iiNetmask;
};

/**
 * Winsock2 prototypes.
 *
 * @note Some of the functions exported by WS2_32.DLL, e.g. bind(),
 *       overlap with the names used by System V. Prototypes for these
 *       functions are declared within their respective wrappers.
 */

int32_t WSAStartup(uint16_t wVersionRequested, struct NtWsaData *lpWSAData)
    paramsnonnull();

int WSACleanup(void);
int WSAGetLastError(void) nosideeffect;
void WSASetLastError(int);

int64_t __sys_socket_nt(int, int, int);
int __sys_bind_nt(uint64_t, const void *, int);
int __sys_closesocket_nt(uint64_t);
int __sys_getpeername_nt(uint64_t, void *, uint32_t *);
int __sys_getsockname_nt(uint64_t, void *, uint32_t *);
int __sys_getsockopt_nt(uint64_t, int, int, void *, uint32_t *);
int __sys_ioctlsocket_nt(uint64_t, int32_t, uint32_t *);
int __sys_listen_nt(uint64_t, int);
int __sys_setsockopt_nt(uint64_t, int, int, const void *, int);
int __sys_shutdown_nt(uint64_t, int);
int __sys_select_nt(int, struct NtFdSet *, struct NtFdSet *, struct NtFdSet *,
                    struct NtTimeval *);

uint64_t WSASocket(int af, int type, int protocol,
                   const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                   const uint32_t opt_group, uint32_t dwFlags) __wur;

int WSAConnect(uint64_t s, const struct sockaddr *name, const int namelen,
               const struct NtIovec *opt_lpCallerData,
               struct NtIovec *opt_out_lpCalleeData,
               const struct NtQos *opt_lpSQOS, const struct NtQos *opt_lpGQOS)
    paramsnonnull((2));

bool32 WSAConnectByName(uint64_t s, const char16_t *nodename,
                        const char16_t *servicename,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2, 3));

bool32 WSAConnectByList(uint64_t s,
                        const struct NtSocketAddressList *SocketAddress,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2));

int64_t WSAAccept(uint64_t s, struct sockaddr *out_addr,
                  int32_t *opt_inout_addrlen,
                  const NtConditionProc opt_lpfnCondition,
                  const uint32_t *opt_dwCallbackData) paramsnonnull((2)) __wur;

int WSASend(uint64_t s, const struct NtIovec *lpBuffers, uint32_t dwBufferCount,
            uint32_t *opt_out_lpNumberOfBytesSent, uint32_t dwFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendMsg(int64_t Handle, const struct NtMsgHdr *lpMsg, uint32_t dwFlags,
               uint32_t *opt_out_lpNumberOfBytesSent,
               struct NtOverlapped *opt_inout_lpOverlapped,
               const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendTo(uint64_t s, const struct NtIovec *lpBuffers,
              uint32_t dwBufferCount,
              uint32_t *opt_out_lpNumberOfBytesSent /* opt if !overlapped */,
              uint32_t dwFlags, const void *opt_tosockaddr,
              int32_t tosockaddrlen,
              struct NtOverlapped *opt_inout_lpOverlapped,
              const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSAPoll(struct sys_pollfd_nt *inout_fdArray, uint32_t nfds,
            signed timeout_ms) paramsnonnull();

int WSARecv(uint64_t s, const struct NtIovec *inout_lpBuffers,
            uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
            uint32_t *inout_lpFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvFrom(uint64_t s, const struct NtIovec *inout_lpBuffers,
                uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
                uint32_t *inout_lpFlags, void *out_fromsockaddr,
                uint32_t *opt_inout_fromsockaddrlen,
                struct NtOverlapped *opt_inout_lpOverlapped,
                const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvDisconnect(uint64_t s, struct NtIovec *out_InboundDisconnectData);
int WSASendDisconnect(int64_t s, struct NtIovec *opt_OutboundDisconnectData);

int WSADuplicateSocket(uint64_t s, uint32_t dwProcessId,
                       struct NtWsaProtocolInfo *out_lpProtocolInfo)
    paramsnonnull((3));

int WSAIoctl(uint64_t s, uint32_t dwIoControlCode, const void *lpvInBuffer,
             uint32_t cbInBuffer, void *out_lpvOutBuffer, uint32_t cbOutBuffer,
             uint32_t *out_lpcbBytesReturned,
             struct NtOverlapped *opt_inout_lpOverlapped,
             const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((5, 7));

int WSANSPIoctl(int64_t hLookup, uint32_t dwControlCode,
                const void *lpvInBuffer, uint32_t cbInBuffer,
                void *out_lpvOutBuffer, uint32_t cbOutBuffer,
                uint32_t *out_lpcbBytesReturned,
                const struct NtWsaCompletion *opt_lpCompletion)
    paramsnonnull((3, 5, 7));

int64_t WSACreateEvent(void) __wur;
bool32 WSACloseEvent(const int64_t hEvent);
bool32 WSAResetEvent(const int64_t hEvent);
bool32 WSASetEvent(const int64_t hEvent);

int WSAEventSelect(uint64_t s, const int64_t opt_hEventObject,
                   long lNetworkEvents);

uint32_t WSAWaitForMultipleEvents(uint32_t cEvents, const int64_t *lphEvents,
                                  bool32 fWaitAll, uint32_t dwTimeout_ms,
                                  bool32 fAlertable) paramsnonnull();

int WSAEnumNetworkEvents(uint64_t s, const int64_t hEventObject,
                         struct NtWsaNetworkEvents *out_lpNetworkEvents)
    paramsnonnull();

bool32 WSAGetOverlappedResult(uint64_t s,
                              const struct NtOverlapped *lpOverlapped,
                              uint32_t *out_lpcbTransfer, bool32 fWait,
                              uint32_t *out_lpdwFlags) paramsnonnull();

int WSAEnumProtocols(const int32_t *opt_lpiProtocols,
                     struct NtWsaProtocolInfo *out_lpProtocolBuffer,
                     uint32_t *inout_lpdwBufferLength) paramsnonnull();

bool32 WSAGetQOSByName(uint64_t s, const struct NtIovec *lpQOSName,
                       struct NtQos *out_lpQOS) paramsnonnull();

uint64_t WSAJoinLeaf(uint64_t s, const struct sockaddr *name, const int namelen,
                     const struct NtIovec *opt_lpCallerData,
                     struct NtIovec *opt_out_lpCalleeData,
                     const struct NtQos *opt_lpSQOS,
                     const struct NtQos *opt_lpGQOS, uint32_t dwFlags)
    paramsnonnull((2, 4));

int WSALookupServiceBegin(const struct NtWsaQuerySet *lpqsRestrictions,
                          uint32_t dwControlFlags, int64_t *out_lphLookup)
    paramsnonnull();

int WSALookupServiceNext(const int64_t hLookup, uint32_t dwControlFlags,
                         uint32_t *inout_lpdwBufferLength,
                         struct NtWsaQuerySet *out_lpqsResults) paramsnonnull();

int WSALookupServiceEnd(int64_t hLookup);

int WSAAddressToString(const struct sockaddr *lpsaAddress,
                       uint32_t dwAddressLength,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       char16_t *out_lpszAddressString,
                       uint32_t *inout_lpdwAddressStringLength)
    paramsnonnull((1, 4, 5));

int WSAStringToAddress(const char16_t *AddressString, int AddressFamily,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       struct sockaddr *out_lpAddress,
                       int *inout_lpAddressLength) paramsnonnull((1, 3, 4));

int WSAEnumNameSpaceProvidersEx(uint32_t *inout_lpdwBufferLength,
                                struct NtWsaNamespaceInfoEx *out_lpnspBuffer)
    paramsnonnull();

int WSAProviderConfigChange(
    int64_t *inout_lpNotificationHandle,
    struct NtOverlapped *opt_inout_lpOverlapped,
    NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((1));

int WSAInstallServiceClass(
    const struct NtWsaServiceClassInfo *lpServiceClassInfo) paramsnonnull();

int WSARemoveServiceClass(const struct NtGuid *lpServiceClassId)
    paramsnonnull();

int WSAGetServiceClassInfo(const struct NtGuid *lpProviderId,
                           const struct NtGuid *lpServiceClassId,
                           uint32_t *inout_lpdwBufSize,
                           struct NtWsaServiceClassInfo *out_lpServiceClassInfo)
    paramsnonnull((1, 2, 3));

int WSASetService(const struct NtWsaQuerySet *lpqsRegInfo, int essoperation,
                  uint32_t dwControlFlags) paramsnonnull();

int /* success==0 */ WSAGetServiceClassNameByClassId(
    const struct NtGuid *lpServiceClassId, char16_t *out_lpszServiceClassName,
    uint32_t *inout_lpdwBufferLength) paramsnonnull();

void GetAcceptExSockaddrs(
    const void *lpOutputBuffer /*[recvsize+addrsize+addrlen]*/,
    uint32_t dwReceiveDataLength, uint32_t dwLocalAddressLength,
    uint32_t dwRemoteAddressLength,
    struct sockaddr **out_LocalSockaddr /*[*LocalSockaddrLength]*/,
    int *out_LocalSockaddrLength,
    struct sockaddr **out_RemoteSockaddr /*[*RemoteSockaddrLength]*/,
    int *out_RemoteSockaddrLength);

bool32 DisconnectEx(int64_t s, struct NtOverlapped *inout_opt_lpOverlapped,
                    uint32_t dwFlags, uint32_t dwReserved);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/winsock.inc */

extern typeof(WSAGetLastError) *const __imp_WSAGetLastError __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_

/* Constants ----------------------------------------------------------- */

#define kNtMaxAdapterAddressLength  8
#define kNtMaxDnsSuffixStringLength 256
#define kNtMaxDhcpv6DuidLength      130

/* Values for the 'Flags' parameter of GetAdaptersAddresses */
#define kNtGaaFlagSkipUnicast               0x0001
#define kNtGaaFlagSkipAnycast               0x0002
#define kNtGaaFlagSkipMulticast             0x0004
#define kNtGaaFlagSkipDnsServer             0x0008
#define kNtGaaFlagIncludePrefix             0x0010
#define kNtGaaFlagSkipFriendlyName          0x0020
#define kNtGaaFlagIncludeWinsInfo           0x0040
#define kNtGaaFlagIncludeGateways           0x0080
#define kNtGaaFlagIncludeAllInterfaces      0x0100
#define kNtGaaFlagIncludeAllCompartments    0x0200
#define kNtGaaFlagIncludeTunnelBindingorder 0x0400
#define kNtGaaFlagSkipDnsInfo               0x0800

/* Values for the IfType parameter
 * See:
 * https://docs.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_addresses_lh
 */
#define kNtIfTypeOther             1
#define kNtIfTypeEthernetCsmacd    6
#define kNtIfTypeIso88025Tokenring 9
#define kNtIfTypePpp               23
#define kNtIfTypeSoftwareLoopback  24
#define kNtIfTypeAtm               37
#define kNtIfTypeIeee80211         71 /* wifi */
#define kNtIfTypeTunnel            131
#define kNtIfTypeIeee1394          144 /* firewire */

#define kNtIpAdapterDdnsEnabled             0x0001
#define kNtIpAdapterRegisterAdapterSuffix   0x0002
#define kNtIpAdapterDhcpv4Enabled           0x0004
#define kNtIpAdapterReceiveOnly             0x0008
#define kNtIpAdapterNoMulticast             0x0010
#define kNtIpAdapterIpv6OtherStatefulConfig 0x0020
#define kNtIpAdapterNetbiosOverTcpipEnabled 0x0040
#define kNtIpAdapterIpv4Enabled             0x0080
#define kNtIpAdapterIpv6Enabled             0x0100
#define kNtIpAdapterIpv6Managed             0x0200

#define kNtIpPrefixOriginOther               0
#define kNtIpPrefixOriginManual              1
#define kNtIpPrefixOriginWellKnown           2
#define kNtIpPrefixOriginDhcp                3
#define kNtIpPrefixOriginRouterAdvertisement 4
#define kNtIpPrefixOriginUnchanged           16

#define kNtIpSuffixOriginOther            0
#define kNtIpSuffixOriginManual           1
#define kNtIpSuffixOriginWellKnown        2
#define kNtIpSuffixOriginDhcp             3
#define kNtIpSuffixOriginLinkLayerAddress 4
#define kNtIpSuffixOriginRandom           5
#define kNtIpSuffixOriginUnchanged        16

#define kNtIpDadStateInvalid    0
#define kNtIpDadStateTentative  1
#define kNtIpDadStateDuplicate  2
#define kNtIpDadStateDeprecated 3
#define kNtIpDadStatePreferred  4

#define kNtIfOperStatusUp             1
#define kNtIfOperStatusDown           2
#define kNtIfOperStatusTesting        3
#define kNtIfOperStatusUnknown        4
#define kNtIfOperStatusDormant        5
#define kNtIfOperStatusNotPresent     6
#define kNtIfOperStatusLowerLayerDown 7

#define kNtNetIfConnectionDedicated 1
#define kNtNetIfConnectionPassive   2
#define kNtNetIfConnectionDemand    3
#define kNtNetIfConnectionMaximum   4

#define kNtTunnelTypeNone    0
#define kNtTunnelTypeOther   1
#define kNtTunnelTypeDirect  2
#define kNtTunnelType6to4    11
#define kNtTunnelTypeIsatap  13
#define kNtTunnelTypeTeredo  14
#define kNtTunnelTypeIphttps 15

COSMOPOLITAN_C_START_

/* Inner Types --------------------------------------------------------- */

struct NtIpAdapterUnicastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterUnicastAddress *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixOrigin; /* kNtIpPrefixOrigin... */
  uint32_t SuffixOrigin; /* kNtIpSuffixOrigin... */
  uint32_t DadState;     /* kNtIpDadState... */
  uint32_t ValidLifetime;
  uint32_t PreferredLifetime;
  uint32_t LeaseLifetime;
  uint8_t OnLinkPrefixLength;
};

struct NtIpAdapterAnycastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterAnycastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterMulticastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterMulticastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterDnsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterPrefix {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterPrefix *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixLength;
};

struct NtIpAdapterWinsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterWinsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterGatewayAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterGatewayAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsSuffix {
  struct NtIpAdapterDnsSuffix *Next;
  uint16_t String[kNtMaxDnsSuffixStringLength];
};

/* Top level ----------------------------------------------------------- */

struct NtIpAdapterAddresses {
  uint32_t Length;
  uint32_t IfIndex;
  struct NtIpAdapterAddresses *Next;
  char *AdapterName;
  struct NtIpAdapterUnicastAddress *FirstUnicastAddress;
  struct NtIpAdapterAnycastAddress *FirstAnycastAddress;
  struct NtIpAdapterMulticastAddress *FirstMulticastAddress;
  struct NtIpAdapterDnsServerAddress *FirstDnsServerAddress;
  uint16_t *DnsSuffix;
  uint16_t *Description;
  uint16_t *FriendlyName;
  uint8_t PhysicalAddress[kNtMaxAdapterAddressLength];
  uint32_t PhysicalAddressLength;
  uint32_t Flags; /* kNtIpAdapter... */
  uint32_t Mtu;
  uint32_t IfType;     /* kNtIfType... */
  uint32_t OperStatus; /* kNtIfOperStatus... */
  uint32_t Ipv6IfIndex;
  uint32_t ZoneIndices[16];
  struct NtIpAdapterPrefix *FirstPrefix;
  uint64_t TransmitLinkSpeed;
  uint64_t ReceiveLinkSpeed;
  struct NtIpAdapterWinsServerAddress *FirstWinsServerAddress;
  struct NtIpAdapterGatewayAddress *FirstGatewayAddress;
  uint32_t Ipv4Metric;
  uint32_t Ipv6Metric;
  uint64_t Luid; /* reserved(24bits),NetLuidIndex(24b),IfType(16b) */
  struct NtSocketAddress Dhcpv4Server;
  uint32_t CompartmentId;
  struct NtGuid NetworkGuid;
  uint32_t ConnectionType; /* kNtNetIfConnection... */
  uint32_t TunnelType;     /* kNtTunnelType... */
  struct NtSocketAddress Dhcpv6Server;
  uint8_t Dhcpv6ClientDuid[kNtMaxDhcpv6DuidLength];
  uint32_t Dhcpv6ClientDuidLength;
  uint32_t Dhcpv6Iaid;
  struct NtIpAdapterDnsSuffix *FirstDnsSuffix;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/kernelusertimes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_KERNELUSERTIMES_H_

struct NtKernelUserTimes {
  uint64_t CreateFileTime;
  uint64_t ExitFileTime;
  int64_t KernelTime;
  int64_t UserTime;
};



/*!BEGIN libc/nt/struct/ldr.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDR_H_

struct NtLdr {
  uint32_t SizeOfThis;                       /* msdn:reserved */
  uint32_t IsInitialized;                    /* msdn:reserved */
  void *SsHandle;                            /* msdn:reserved */
  struct NtLinkedList InLoadOrderModuleList; /* msdn:reserved */
  struct NtLinkedList /*∩NtLdrDataTableEntry*/ InMemoryOrderModuleList;
  struct NtLinkedList InInitOrderModuleList; /* msdn:reserved */
};



/*!BEGIN libc/nt/struct/ldrdatatableentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDRDATATABLEENTRY_H_


/*!BEGIN libc/nt/struct/unicodestring.h */

#define COSMOPOLITAN_LIBC_NT_UNICODE_H_

struct NtUnicodeString {
  uint16_t Length;
  uint16_t MaxLength;
  char16_t *Data;
};


struct NtLdrDataTableEntry {
  struct NtLinkedList InLoadOrderLinks; /* msdn:reserved */
  struct NtLinkedList InMemoryOrderLinks;
  struct NtLinkedList InInitOrderLinks; /* msdn:reserved */
  void *DllBase;
  void *EntryPoint;
  union {
    uint32_t SizeOfImage;
    unsigned char SizeOfImagePadding[__SIZEOF_POINTER__];
  };
  struct NtUnicodeString FullDllName;
  struct NtUnicodeString BaseDllName;
  uint32_t Flags;
  uint16_t Load_Count;
  uint16_t TlsIndex;
  union {
    struct NtLinkedList HashLinks;
    struct {
      void *SectionPointer;
      uint32_t CheckSum;
    };
  };
  union {
    void *LoadedImports;
    uint32_t TimeDateStamp;
  };
  void *EntryPointActivationContext;
  void *PatchInformation;
  struct NtLinkedList ForwarderLinks;
  struct NtLinkedList ServiceTagLinks;
  struct NtLinkedList StaticLinks;
  void *ContextInformation;
  uintptr_t OriginalBase;
  int64_t LoadTime;
};



/*!BEGIN libc/nt/struct/linger.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger_nt {
  uint16_t l_onoff;  /* on/off */
  uint16_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/luid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUID_H_

struct NtLuid {
  uint32_t LowPart;
  int32_t HighPart;
};



/*!BEGIN libc/nt/struct/luidandattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUIDANDATTRIBUTES_H_

struct NtLuidAndAttributes {
  struct NtLuid Luid;
  uint32_t Attributes;
};



/*!BEGIN libc/nt/struct/memextendedparameter.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMEXTENDEDPARAMETER_H_

#define kNtMemExtendedParameterTypeBits 8

#define kNtMemExtendedParameterInvalidType         0
#define kNtMemExtendedParameterAddressRequirements 1
#define kNtMemExtendedParameterNumaNode            2
#define kNtMemExtendedParameterPartitionHandle     3
#define kNtMemExtendedParameterUserPhysicalHandle  4
#define kNtMemExtendedParameterAttributeFlags      5
#define kNtMemExtendedParameterMax                 6

#define kNtMemExtendedParameterGraphics          0x00000001
#define kNtMemExtendedParameterNonpaged          0x00000002
#define kNtMemExtendedParameterZeroPagesOptional 0x00000004
#define kNtMemExtendedParameterNonpagedLarge     0x00000008
#define kNtMemExtendedParameterNonpagedHuge      0x00000010

struct NtMemExtendedParameter {
  struct {
    uint64_t Type : kNtMemExtendedParameterTypeBits;
    uint64_t Reserved : 64 - kNtMemExtendedParameterTypeBits;
  } DUMMYSTRUCTNAME;
  union {
    uint64_t ULong64;
    void *Pointer;
    size_t Size;
    intptr_t Handle;
    unsigned ULong;
  } DUMMYUNIONNAME;
};



/*!BEGIN libc/nt/struct/memorybasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYBASICINFORMATION_H_

struct NtMemoryBasicInformation {
  void *BaseAddress;
  void *AllocationBase;
  uint32_t AllocationProtect;
  uint64_t RegionSize;
  uint32_t State;
  uint32_t Protect;
  uint32_t Type;
};



/*!BEGIN libc/nt/struct/memoryrangeentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYRANGEENTRY_H_

struct NtMemoryRangeEntry {
  void *VirtualAddress;
  size_t NumberOfBytes;
};



/*!BEGIN libc/nt/struct/memorystatusex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYSTATUSEX_H_

struct NtMemoryStatusEx {
  uint32_t dwLength;
  uint32_t dwMemoryLoad;
  uint64_t ullTotalPhys;
  uint64_t ullAvailPhys;
  uint64_t ullTotalPageFile;
  uint64_t ullAvailPageFile;
  uint64_t ullTotalVirtual;
  uint64_t ullAvailVirtual;
  uint64_t ullAvailExtendedVirtual;
};



/*!BEGIN libc/nt/struct/msg.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MSG_H_


/*!BEGIN libc/nt/struct/point.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POINT_H_

struct NtPoint {
  int32_t x;
  int32_t y;
};


struct NtMsg {
  int64_t hwnd;
  uint32_t dwMessage;
  uint64_t wParam;
  int64_t lParam;
  uint32_t dwTime;
  struct NtPoint pt;
};



/*!BEGIN libc/nt/struct/nonpageddebuginfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NONPAGEDDEBUGINFO_H_

struct NtNonPagedDebugInfo {
  uint16_t Signature;
  uint16_t Flags;
  uint32_t Size;
  uint16_t Machine;
  uint16_t Characteristics;
  uint32_t TimeDateStamp;
  uint32_t CheckSum;
  uint32_t SizeOfImage;
  uint64_t ImageBase;
};



/*!BEGIN libc/nt/struct/ntexceptionpointers.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONPOINTERS_H_


/*!BEGIN libc/nt/struct/ntexceptionrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONRECORD_H_

#define kNtExceptionMaximumParameters 15
#define kNtExceptionNoncontinuable    1


struct NtExceptionRecord {
  uint32_t ExceptionCode;                    /* kNtException... */
  uint32_t ExceptionFlags;                   /* kNtExceptionNoncontinuable */
  struct NtExceptionRecord *ExceptionRecord; /* nested exceptions */
  void *ExceptionAddress;                    /* %rip */
  uint32_t NumberParameters;                 /* #ExceptionInformation */
  uint64_t ExceptionInformation[kNtExceptionMaximumParameters];
};


struct NtExceptionPointers {
  struct NtExceptionRecord *ExceptionRecord;
  struct NtContext *ContextRecord;
};



/*!BEGIN libc/nt/struct/objectallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTALLINFORMATION_H_


/*!BEGIN libc/nt/struct/objecttypeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTTYPEINFORMATION_H_

struct NtObjectTypeInformation {
  struct NtUnicodeString TypeName;
  uint32_t TotalNumberOfObjects;
  uint32_t TotalNumberOfHandles;
  uint32_t TotalPagedPoolUsage;
  uint32_t TotalNonPagedPoolUsage;
  uint32_t TotalNamePoolUsage;
  uint32_t TotalHandleTableUsage;
  uint32_t HighWaterNumberOfObjects;
  uint32_t HighWaterNumberOfHandles;
  uint32_t HighWaterPagedPoolUsage;
  uint32_t HighWaterNonPagedPoolUsage;
  uint32_t HighWaterNamePoolUsage;
  uint32_t HighWaterHandleTableUsage;
  uint32_t InvalidAttributes;
  struct NtGenericMapping GenericMapping;
  uint32_t ValidAccessMask;
  bool32 SecurityRequired;
  bool32 MaintainHandleCount;
  uint32_t PoolType;
  uint32_t DefaultPagedPoolCharge;
  uint32_t DefaultNonPagedPoolCharge;
};


struct NtObjectAllInformation {
  uint32_t NumberOfObjects;
  struct NtObjectTypeInformation ObjectTypeInformation[1];
};



/*!BEGIN libc/nt/struct/objectattributes.h */

#define COSMOPOLITAN_LIBC_NT_I_OBJECTATTRIBUTES_H_


/*!BEGIN libc/nt/struct/rtluserprocessparameters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSPARAMETERS_H_

struct NtRtlUserProcessParameters {
  uint32_t MaximumLength;
  uint32_t Length;
  uint32_t Flags;
  uint32_t DebugFlags;
  int64_t ConsoleHandle;
  uint32_t ConsoleFlags;
  int64_t StdInputHandle;
  int64_t StdOutputHandle;
  int64_t StdErrorHandle;
  struct NtUnicodeString *CurrentDirectoryPath;
  int64_t CurrentDirectoryHandle;
  struct NtUnicodeString *DllPath;
  struct NtUnicodeString *ImagePathName;
  struct NtUnicodeString *CommandLine;
  void *Environment;
  uint32_t StartingPositionLeft;
  uint32_t StartingPositionTop;
  uint32_t Width;
  uint32_t Height;
  uint32_t CharWidth;
  uint32_t CharHeight;
  uint32_t ConsoleTextAttributes;
  uint32_t WindowFlags;
  uint32_t ShowWindowFlags;
  struct NtUnicodeString *WindowTitle;
  struct NtUnicodeString *DesktopName;
  struct NtUnicodeString *ShellInfo;
  struct NtUnicodeString *RuntimeData;
};



/*!BEGIN libc/nt/struct/securityattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYATTRIBUTES_H_


/*!BEGIN libc/nt/struct/securitydescriptor.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYDESCRIPTOR_H_

struct NtSecurityDescriptor {
  uint8_t Revision;
  uint8_t Sbz1;
  uint16_t Control;
  void *Owner;
  void *Group;
  struct NtAcl *Sacl;
  struct NtAcl *Dacl;
};


struct NtSecurityAttributes {
  uint32_t nLength;
  struct NtSecurityDescriptor *lpSecurityDescriptor;
  bool32 bInheritHandle;
};

const char *DescribeNtSecurityAttributes(char[32],
                                         const struct NtSecurityAttributes *);
#define DescribeNtSecurityAttributes(x) \
  DescribeNtSecurityAttributes(alloca(32), x)


struct NtObjectAttributes {
  uint32_t Length;
  int64_t RootDirectory;
  const struct NtUnicodeString *ObjectName;
  uint32_t Attributes; /* OBJ_INHERIT, etc. */
  struct NtSecurityDescriptor *SecurityDescriptor;
  void *SecurityQualityOfService;
};



/*!BEGIN libc/nt/struct/objectbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTBASICINFORMATION_H_

struct NtObjectBasicInformation {
  uint32_t Attributes;
  uint32_t GrantedAccess;
  uint32_t HandleCount;
  uint32_t PointerCount;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t Reserved[3];
  uint32_t NameInformationLength;
  uint32_t TypeInformationLength;
  uint32_t SecurityDescriptorLength;
  int64_t CreateTime;
};



/*!BEGIN libc/nt/struct/objectnameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTNAMEINFORMATION_H_

struct NtObjectNameInformation {
  struct NtUnicodeString Name;
};



/*!BEGIN libc/nt/struct/openfilename.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OPENFILENAME_H_

struct NtOpenFilename {
  uint32_t lStructSize;
  int64_t hwndOwner;
  int64_t hInstance;
  const char16_t *lpstrFilter;
  char16_t *lpstrCustomFilter;
  uint32_t nMaxCustFilter;
  uint32_t nFilterIndex;
  char16_t *lpstrFile;
  uint32_t nMaxFile;
  char16_t *lpstrFileTitle;
  uint32_t nMaxFileTitle;
  const char16_t *lpstrInitialDir;
  const char16_t *lpstrTitle;
  uint32_t Flags;
  uint16_t nFileOffset;
  uint16_t nFileExtension;
  const char16_t *lpstrDefExt;
  intptr_t lCustData;
  uint64_t (*lpfnHook)(int64_t, uint32_t, uint64_t, int64_t);
  const char16_t *lpTemplateName;
  void *pvReserved;
  uint32_t dwReserved;
  uint32_t FlagsEx;
};



/*!BEGIN libc/nt/struct/osversioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OSVERSIONINFO_H_
COSMOPOLITAN_C_START_

struct NtOsVersionInfo {
  uint32_t dwOSVersionInfoSize;
  uint32_t dwMajorVersion;
  uint32_t dwMinorVersion;
  uint32_t dwBuildNumber;
  uint32_t dwPlatformId;
  char16_t szCSDVersion[128];
  uint16_t wServicePackMajor;
  uint16_t wServicePackMinor;
  uint16_t wSuiteMask;
  uint8_t wProductType;
  uint8_t wReserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/overlappedentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPEDENTRY_H_
COSMOPOLITAN_C_START_

struct NtOverlappedEntry {
  uint64_t lpCompletionKey;
  struct NtOverlapped *lpOverlapped;
  uint32_t *Internal;
  uint32_t dwNumberOfBytesTransferred;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/paintstruct.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PAINTSTRUCT_H_


/*!BEGIN libc/nt/struct/rect.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RECT_H_

struct NtRect {
  int32_t left;
  int32_t top;
  int32_t right;
  int32_t bottom;
};


struct NtPaintStruct {
  int64_t hdc;
  bool32 fErase;
  struct NtRect rcPaint;
  bool32 fRestore;
  bool32 fIncUpdate;
  uint8_t rgbReserved[32];
};



/*!BEGIN libc/nt/struct/pdhfmtcountervalue.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PDHFMTCOUNTERVALUE_H_
COSMOPOLITAN_C_START_

struct NtPdhFmtCountervalue {
  uint32_t CStatus;
  union {
    int32_t longValue;
    double doubleValue;
    int64_t largeValue;
    const char *AnsiStringValue;
    const char16_t *WideStringValue;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/peb.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PEB_H_

struct NtPeb {
  union {
    struct {
      unsigned char InheritedAddressSpace;
      unsigned char ReadImageFileExecOptions;
      unsigned char BeingDebugged;
      unsigned char __wut1;
    };
    uint64_t __wut2;
  };
  uint64_t Mutant;
  uint64_t ImageBaseAddress;
  struct NtLdr *Ldr;
  uint64_t ProcessParameters;
  uint64_t SubSystemData;
  uint64_t ProcessHeap;
  uint64_t FastPebLock;
  uint64_t __wut3;
  uint64_t __wut4;
  uint64_t __wut5;
  union {
    uint64_t KernelCallbackTable;
    uint64_t UserSharedInfoPtr;
  };
  uint32_t SystemReserved;
  uint32_t __wut6;
  uint64_t __wut7;
  uint64_t TlsExpansionCounter;
  uint64_t TlsBitmap;
  uint32_t TlsBitmapBits[2];
  uint64_t ReadOnlySharedMemoryBase;
  uint64_t __wut8;
  uint64_t ReadOnlyStaticServerData;
  uint64_t AnsiCodePageData;
  uint64_t OemCodePageData;
  uint64_t UnicodeCaseTableData;
  uint32_t NumberOfProcessors;
#ifdef __x86_64__
  uint32_t NtGlobalFlag;
#else
  uint64_t NtGlobalFlag;
#endif
  int64_t CriticalSectionTimeout;
  uint64_t HeapSegmentReserve;
  uint64_t HeapSegmentCommit;
  uint64_t HeapDeCommitTotalFreeThreshold;
  uint64_t HeapDeCommitFreeBlockThreshold;
  uint32_t NumberOfHeaps;
  uint32_t MaximumNumberOfHeaps;
  uint64_t ProcessHeaps;
  uint64_t GdiSharedHandleTable;
  uint64_t ProcessStarterHelper;
  uint64_t GdiDCAttributeList;
  uint64_t LoaderLock;
  union {
    struct {
      uint32_t OSMajorVersion;
      uint32_t OSMinorVersion;
    };
    uint64_t OSVersion;
  };
  uint16_t OSBuildNumber;
  uint16_t OSCSDVersion;
  uint32_t OSPlatformId;
  uint32_t ImageSubsystem;
  uint32_t ImageSubsystemMajorVersion;
  uint64_t ImageSubsystemMinorVersion;
  union {
    uint64_t ImageProcessAffinityMask;
    uint64_t ActiveProcessAffinityMask;
  };
  uint64_t GdiHandleBuffer[38 - __SIZEOF_POINTER__];
  uint64_t PostProcessInitRoutine;
  uint64_t TlsExpansionBitmap;
  uint32_t TlsExpansionBitmapBits[32];
  uint64_t SessionId;
  uint64_t AppCompatFlags;
  uint64_t AppCompatFlagsUser;
  uint64_t pShimData;
  uint64_t AppCompatInfo;
  struct NtUnicodeString CSDVersion;
  uint64_t ActivationContextData;
  uint64_t ProcessAssemblyStorageMap;
  uint64_t SystemDefaultActivationContextData;
  uint64_t SystemAssemblyStorageMap;
  uint64_t MinimumStackCommit;
};



/*!BEGIN libc/nt/struct/privilegeset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PRIVILEGESET_H_

struct NtPrivilegeSet {
  uint32_t PrivilegeCount;
  uint32_t Control;
  struct NtLuidAndAttributes Privilege[1];
};



/*!BEGIN libc/nt/struct/processbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSBASICINFORMATION_H_

struct NtProcessBasicInformation {
  int32_t ExitStatus;
  struct NtPeb *PebBaseAddress;
  uint32_t *AffinityMask;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
};



/*!BEGIN libc/nt/struct/processentry32.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSENTRY32_H_

struct NtProcessEntry32 {
  uint32_t dwSize;
  uint32_t cntUsage; /* unused */
  uint32_t th32ProcessID;
  uint64_t th32DefaultHeapID; /* unused */
  uint32_t th32ModuleID;      /* unused */
  uint32_t cntThreads;
  uint32_t th32ParentProcessID;
  int32_t cPriClassBase;
  uint32_t dwFlags; /* unused */
  char16_t szExeFile[260];
};



/*!BEGIN libc/nt/struct/processinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSINFORMATION_H_

struct NtProcessInformation {
  int64_t hProcess;
  int64_t hThread;
  uint32_t dwProcessId;
  uint32_t dwThreadId;
};



/*!BEGIN libc/nt/struct/processmemorycounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSMEMORYCOUNTERS_H_
COSMOPOLITAN_C_START_

struct NtProcessMemoryCountersEx {
  uint32_t cb; /* count bytes */
  uint32_t PageFaultCount;
  uint64_t PeakWorkingSetSize;
  uint64_t WorkingSetSize;
  uint64_t QuotaPeakPagedPoolUsage;
  uint64_t QuotaPagedPoolUsage;
  uint64_t QuotaPeakNonPagedPoolUsage;
  uint64_t QuotaNonPagedPoolUsage;
  uint64_t PagefileUsage;
  uint64_t PeakPagefileUsage;
  uint64_t PrivateUsage;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/processornumber.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSORNUMBER_H_
COSMOPOLITAN_C_START_

struct NtProcessorNumber {
  uint16_t Group;
  uint8_t Number;
  uint8_t Reserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/procthreadattributelist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCTHREADATTRIBUTELIST_H_

struct NtProcThreadAttributeList;



/*!BEGIN libc/nt/struct/reparsedatabuffer.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_REPARSEDATABUFFER_H_
COSMOPOLITAN_C_START_

struct NtReparseDataBuffer {
  uint32_t ReparseTag;
  uint16_t ReparseDataLength;
  uint16_t Reserved;
  union {
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      uint32_t Flags;
      char16_t PathBuffer[1];
    } SymbolicLinkReparseBuffer;
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      char16_t PathBuffer[1];
    } MountPointReparseBuffer;
    struct {
      uint8_t DataBuffer[1];
    } GenericReparseBuffer;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/rtluserprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/sectionimageinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECTIONIMAGEINFORMATION_H_

struct NtSectionImageInformation {
  void *EntryPoint;
  uint32_t Unknown1;
  uint32_t StackReserve;
  uint32_t StackCommit;
  uint32_t Subsystem;
  uint16_t MinorSubsystemVersion;
  uint16_t MajorSubsystemVersion;
  uint32_t Unknown2;
  uint32_t Characteristics;
  uint16_t ImageNumber;
  uint32_t IsExecutable;
  uint8_t __wut1;
  uint32_t __wut2[3];
};


struct NtRtlUserProcessInformation {
  uint32_t SizeOfThis;
  int64_t ProcessHandle;
  int64_t ThreadHandle;
  struct NtClientId ClientId;
  struct NtSectionImageInformation ImageInformation;
};



/*!BEGIN libc/nt/struct/size.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SIZE_H_
COSMOPOLITAN_C_START_

struct NtSize {
  int32_t cx;
  int32_t cy;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFO_H_

struct NtStartupInfo {
  uint32_t cb /* = sizeof(struct NtStartupInfo) */;
  uint16_t *lpReserved;
  char16_t *lpDesktop;
  char16_t *lpTitle; /* title of *new* console window only */
  uint32_t dwX;      /* position of window on screen */
  uint32_t dwY;
  uint32_t dwXSize;
  uint32_t dwYSize;
  uint32_t dwXCountChars; /* used to dimension the dos terminal */
  uint32_t dwYCountChars;
  uint32_t dwFillAttribute;
  uint32_t dwFlags;
  uint16_t wShowWindow;
  uint16_t cbReserved2;
  uint8_t *lpReserved2;
  union {
    struct {
      int64_t hStdInput;
      int64_t hStdOutput;
      int64_t hStdError;
    };
    int64_t stdiofds[3];
  };
};



/*!BEGIN libc/nt/struct/startupinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFOEX_H_

struct NtStartupInfoEx {
  struct NtStartupInfo StartupInfo;
  struct NtProcThreadAttributeList *lpAttributeList;
};



/*!BEGIN libc/nt/struct/systembasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMBASICINFORMATION_H_

struct NtSystemBasicInformation {
  unsigned char Reserved1[4];
  uint32_t MaximumIncrement;
  uint32_t PhysicalPageSize;
  uint32_t NumberOfPhysicalPages;
  uint32_t LowestPhysicalPage;
  uint32_t HighestPhysicalPage;
  uint32_t AllocationGranularity;
  uint32_t LowestUserAddress;
  uint32_t HighestUserAddress;
  uint32_t ActiveProcessors;
  char NumberOfProcessors;
};



/*!BEGIN libc/nt/struct/systemexceptioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMEXCEPTIONINFORMATION_H_

struct NtSystemExceptionInformation {
  unsigned char Reserved1[16];
};



/*!BEGIN libc/nt/struct/systemhandleentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEENTRY_H_

struct NtSystemHandleEntry {
  uint32_t OwnerPid;
  unsigned char ObjectType;
  unsigned char HandleFlags;
  unsigned short HandleValue;
  void *ObjectPointer;
  uint32_t AccessMask;
};



/*!BEGIN libc/nt/struct/systemhandleinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEINFORMATION_H_

struct NtSystemHandleInformation {
  uint32_t Count;
  struct NtSystemHandleEntry Handle[1];
};



/*!BEGIN libc/nt/struct/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINFO_H_

struct NtSystemInfo {
  union {
    uint32_t dwOemId;
    struct {
      uint16_t wProcessorArchitecture;
      uint16_t wReserved;
    };
  };
  uint32_t dwPageSize;
  void *lpMinimumApplicationAddress;
  void *lpMaximumApplicationAddress;
  uintptr_t dwActiveProcessorMask;
  uint32_t dwNumberOfProcessors;
  uint32_t dwProcessorType;
  uint32_t dwAllocationGranularity;
  uint16_t wProcessorLevel;
  uint16_t wProcessorRevision;
};



/*!BEGIN libc/nt/struct/systeminterruptinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINTERRUPTINFORMATION_H_

struct NtSystemInterruptInformation {
  unsigned char Reserved1[24];
};



/*!BEGIN libc/nt/struct/systemlookasideinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMLOOKASIDEINFORMATION_H_

struct NtSystemLookasideInformation {
  unsigned char Reserved1[32];
};



/*!BEGIN libc/nt/struct/systemperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPERFORMANCEINFORMATION_H_

struct NtSystemPerformanceInformation {
  int64_t IdleTime;
  int64_t ReadTransferCount;
  int64_t WriteTransferCount;
  int64_t OtherTransferCount;
  uint32_t ReadOperationCount;
  uint32_t WriteOperationCount;
  uint32_t OtherOperationCount;
  uint32_t AvailablePages;
  uint32_t TotalCommittedPages;
  uint32_t TotalCommitLimit;
  uint32_t PeakCommitment;
  uint32_t PageFaults;
  uint32_t WriteCopyFaults;
  uint32_t TransitionFaults;
  uint32_t CacheTransitionFaults;
  uint32_t DemandZeroFaults;
  uint32_t PagesRead;
  uint32_t PageReadIos;
  uint32_t CacheReads;
  uint32_t CacheIos;
  uint32_t PagefilePagesWritten;
  uint32_t PagefilePageWriteIos;
  uint32_t MappedFilePagesWritten;
  uint32_t MappedFilePageWriteIos;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t PagedPoolAllocs;
  uint32_t PagedPoolFrees;
  uint32_t NonPagedPoolAllocs;
  uint32_t NonPagedPoolFrees;
  uint32_t TotalFreeSystemPtes;
  uint32_t SystemCodePage;
  uint32_t TotalSystemDriverPages;
  uint32_t TotalSystemCodePages;
  uint32_t SmallNonPagedLookasideListAllocateHits;
  uint32_t SmallPagedLookasideListAllocateHits;
  uint32_t Reserved3;
  uint32_t MmSystemCachePage;
  uint32_t PagedPoolPage;
  uint32_t SystemDriverPage;
  uint32_t FastReadNoWait;
  uint32_t FastReadWait;
  uint32_t FastReadResourceMiss;
  uint32_t FastReadNotPossible;
  uint32_t FastMdlReadNoWait;
  uint32_t FastMdlReadWait;
  uint32_t FastMdlReadResourceMiss;
  uint32_t FastMdlReadNotPossible;
  uint32_t MapDataNoWait;
  uint32_t MapDataWait;
  uint32_t MapDataNoWaitMiss;
  uint32_t MapDataWaitMiss;
  uint32_t PinMappedDataCount;
  uint32_t PinReadNoWait;
  uint32_t PinReadWait;
  uint32_t PinReadNoWaitMiss;
  uint32_t PinReadWaitMiss;
  uint32_t CopyReadNoWait;
  uint32_t CopyReadWait;
  uint32_t CopyReadNoWaitMiss;
  uint32_t CopyReadWaitMiss;
  uint32_t MdlReadNoWait;
  uint32_t MdlReadWait;
  uint32_t MdlReadNoWaitMiss;
  uint32_t MdlReadWaitMiss;
  uint32_t ReadAheadIos;
  uint32_t LazyWriteIos;
  uint32_t LazyWritePages;
  uint32_t DataFlushes;
  uint32_t DataPages;
  uint32_t ContextSwitches;
  uint32_t FirstLevelTbFills;
  uint32_t SecondLevelTbFills;
  uint32_t SystemCalls;
};



/*!BEGIN libc/nt/struct/systemprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/vmcounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VMCOUNTERS_H_

struct NtVmCounters {
  size_t PeakVirtualSize;
  size_t VirtualSize;
  uint32_t PageFaultCount;
  size_t PeakWorkingSetSize;
  size_t WorkingSetSize;
  size_t QuotaPeakPagedPoolUsage;
  size_t QuotaPagedPoolUsage;
  size_t QuotaPeakNonPagedPoolUsage;
  size_t QuotaNonPagedPoolUsage;
  size_t PagefileUsage;
  size_t PeakPagefileUsage;
};


struct NtSystemProcessInformation {
  uint32_t NextEntryOffset;
  uint32_t NumberOfThreads;
  int64_t Reserved[3];
  int64_t CreateTime;
  int64_t UserTime;
  int64_t KernelTime;
  struct NtUnicodeString ImageName;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
  uint32_t HandleCount;
  uint32_t SessionId;
  uint32_t PageDirectoryBase;
  struct NtVmCounters VirtualMemoryCounters;
  size_t PrivatePageCount;
  struct NtIoCounters IoCounters;
};



/*!BEGIN libc/nt/struct/systemprocessorinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORINFORMATION_H_

struct NtSystemProcessorInformation {
  unsigned short ProcessorArchitecture;
  unsigned short ProcessorLevel;
  unsigned short ProcessorRevision;
  unsigned short Unknown;
  uint32_t FeatureBits;
};



/*!BEGIN libc/nt/struct/systemprocessorperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORPERFORMANCEINFORMATION_H_

struct NtSystemProcessorPerformanceInformation {
  int64_t IdleTime;
  int64_t KernelTime;
  int64_t UserTime;
  int64_t Reserved1[2];
  uint32_t Reserved2;
};



/*!BEGIN libc/nt/struct/systemregistryquotainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMREGISTRYQUOTAINFORMATION_H_

struct NtSystemRegistryQuotaInformation {
  uint32_t RegistryQuotaAllowed;
  uint32_t RegistryQuotaUsed;
  void *Reserved1;
};



/*!BEGIN libc/nt/struct/systemthreads.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTHREADS_H_

struct NtSystemThreads {
  int64_t KernelTime;
  int64_t UserTime;
  int64_t CreateTime;
  uint32_t WaitTime;
  void *StartAddress;
  struct NtClientId ClientId;
  int32_t Priority;
  int32_t BasePriority;
  uint32_t ContextSwitchCount;
  int State;
  uint32_t WaitReason;
};



/*!BEGIN libc/nt/struct/systemtimeofdayinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIMEOFDAYINFORMATION_H_

struct NtSystemTimeofdayInformation {
  int64_t BootTime;
  int64_t CurrentTime;
  int64_t TimeZoneBias;
  uint32_t CurrentTimeZoneId;
  unsigned char Reserved1[20];
};



/*!BEGIN libc/nt/struct/teb.h */

#define COSMOPOLITAN_LIBC_NT_TEB_H_
#ifdef __GNUC__

/*
 * These macros address directly into NT's TEB a.k.a. TIB
 * Any function that does this needs the `dontasan` keyword
 */
#define NtGetPeb()           ((__seg_gs struct NtPeb *)0x60)
#define NtGetTeb()           ((void *)*(__seg_gs uintptr_t *)0x30)
#define NtGetPid()           (*(__seg_gs uint32_t *)0x40)
#define NtGetTid()           (*(__seg_gs uint32_t *)0x48)
#define NtGetErr()           (*(__seg_gs int *)0x68)
#define _NtGetSeh()          ((void *)*(__seg_gs uintptr_t *)0x00)
#define _NtGetStackHigh()    ((void *)*(__seg_gs uintptr_t *)0x08)
#define _NtGetStackLow()     ((void *)*(__seg_gs uintptr_t *)0x10)
#define _NtGetSubsystemTib() ((void *)*(__seg_gs uintptr_t *)0x18)
#define _NtGetFib()          ((void *)*(__seg_gs uintptr_t *)0x20)
#define _NtGetEnv()          ((char16_t *)*(__seg_gs intptr_t *)0x38)
#define _NtGetRpc()          ((void *)*(__seg_gs uintptr_t *)0x50)
#define _NtGetTls()          ((void *)*(__seg_gs uintptr_t *)0x58)

#endif /* __GNUC__ */


/*!BEGIN libc/nt/struct/timezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEZONEINFORMATION_H_

struct NtTimeZoneInformation {
  int Bias;                  /* in minutes e.g. +480 for -8:00 */
  char16_t StandardName[32]; /* e.g. "Pacific Standard Time" */
  struct NtSystemTime StandardDate;
  int StandardBias;
  char16_t DaylightName[32]; /* e.g. "Pacific Daylight Time" */
  struct NtSystemTime DaylightDate;
  int DaylightBias; /* e.g. -60 */
};



/*!BEGIN libc/nt/struct/tokenprivileges.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TOKENPRIVILEGES_H_

struct NtTokenPrivileges {
  uint32_t PrivilegeCount;
  struct NtLuidAndAttributes Privileges[1];
};



/*!BEGIN libc/nt/struct/userstack.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTUSERSTACK_H_

struct NtUserStack {
  void *FixedStackBase;
  void *FixedStackLimit;
  void *ExpandableStackBase;
  void *ExpandableStackLimit;
  void *ExpandableStackBottom;
};



/*!BEGIN libc/nt/struct/valent.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VALENT_H_

struct NtValent {
  char16_t *ve_valuename;
  uint32_t ve_valuelen;
  uintptr_t ve_valueptr;
  uint32_t ve_type;
};



/*!BEGIN libc/nt/struct/win32fileattributedata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FILEATTRIBUTEDATA_H_

struct NtWin32FileAttributeData {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
};



/*!BEGIN libc/nt/struct/win32finddata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FINDDATA_H_

struct NtWin32FindData {
  uint32_t dwFileAttributes;
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t dwReserved0;
  uint32_t dwReserved1;
  char16_t cFileName[260];
  char16_t cAlternateFileName[14];
  uint32_t dwFileType;    /* obsolete */
  uint32_t dwCreatorType; /* obsolete */
  uint16_t wFinderFlags;  /* obsolete */
};



/*!BEGIN libc/nt/struct/windowplacement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WINDOWPLACEMENT_H_

struct NtWindowPlacement {
  uint32_t length;
  uint32_t flags;
  uint32_t showCmd;
  struct NtPoint ptMinPosition;
  struct NtPoint ptMaxPosition;
  struct NtRect rcNormalPosition;
  struct NtRect rcDevice;
};



/*!BEGIN libc/nt/struct/wndclass.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASS_H_


/*!BEGIN libc/nt/typedef/wndproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDPROC_H_
COSMOPOLITAN_C_START_

typedef int64_t (*NtWndProc)(int64_t, uint32_t, uint64_t, int64_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct NtWndClass {
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/wndclassex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASSEX_H_
COSMOPOLITAN_C_START_

struct NtWndClassEx {
  uint32_t cbSize;
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
  int64_t hIconSm;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/exceptionhandler.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_EXCEPTIONHANDLER_H_
COSMOPOLITAN_C_START_

typedef unsigned (*NtExceptionHandler)(struct NtExceptionRecord *,
                                       struct NtExceptionFrame *,
                                       struct NtContext *, void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/handlerroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HANDLERROUTINE_H_

typedef bool32 (*NtHandlerRoutine)(uint32_t);



/*!BEGIN libc/nt/typedef/hookproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HOOKPROC_H_

typedef intptr_t (*NtHookProc)(int code, uintptr_t wParam, intptr_t lParam);



/*!BEGIN libc/nt/typedef/imagetlscallback.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IMAGETLSCALLBACK_H_

typedef void (*NtImageTlsCallback)(void *DllHandle, uint32_t Reason,
                                   void *Reserved);



/*!BEGIN libc/nt/typedef/ioapcroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IOAPCROUTINE_H_

typedef void (*NtIoApcRoutine)(void *ApcContext,
                               struct NtIoStatusBlock *IoStatusBlock,
                               uint32_t Reserved);



/*!BEGIN libc/nt/typedef/pknormalroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_PKNORMALROUTINE_H_

typedef void (*NtPkNormalRoutine)(void *NormalContext, void *SystemArgument1,
                                  void *SystemArgument2);



/*!BEGIN libc/nt/typedef/timerproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_TIMERPROC_H_

typedef void (*NtTimerProc)(int64_t, uint32_t, uintptr_t, uint32_t);



/*!BEGIN libc/nt/typedef/wambda.h */

#define COSMOPOLITAN_LIBC_NT_WAMBDA_H_
COSMOPOLITAN_C_START_

typedef intptr_t (*wambda)();

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/wndenumproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDENUMPROC_H_

typedef int (*NtWndEnumProc)(int64_t foo, intptr_t bar);



/*!BEGIN libc/nt/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » debugging              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtContinue(struct NtContext *Context, int32_t TestAlert);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/file.h */

#define COSMOPOLITAN_LIBC_NT_NT_FILE_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtClose(int64_t handle);

NtStatus NtCreateFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                      const struct NtObjectAttributes *ObjectAttributes,
                      struct NtIoStatusBlock *out_IoStatusBlock,
                      int64_t *opt_AllocationSize, uint32_t FileAttributes,
                      uint32_t ShareAccess, uint32_t CreateDisposition,
                      uint32_t CreateOptions, void *opt_EaBuffer,
                      uint32_t EaLength);

NtStatus NtReadFile(int64_t FileHandle, void *opt_Event,
                    NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                    struct NtIoStatusBlock *out_IoStatusBlock, void *out_Buffer,
                    uint32_t Length, int64_t *opt_ByteOffset,
                    uint32_t *opt_Key);

NtStatus NtWriteFile(int64_t FileHandle, void *opt_Event,
                     NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                     struct NtIoStatusBlock *out_IoStatusBlock,
                     const void *Buffer, uint32_t Length,
                     int64_t *opt_ByteOffset, uint32_t *opt_Key);

NtStatus NtDuplicateObject(int64_t SourceProcessHandle, void *SourceHandle,
                           void *TargetProcessHandle,
                           void **opt_out_TargetHandle, uint32_t DesiredAcess,
                           uint32_t Attributes, uint32_t options_t);

NtStatus NtQueryInformationFile(int64_t FileHandle,
                                struct NtIoStatusBlock *out_IoStatusBlock,
                                void *out_FileInformation,
                                uint32_t FileInformationLength,
                                uint32_t FileInformationClass);

NtStatus NtSetInformationFile(int64_t FileHandle,
                              struct NtIoStatusBlock *out_IoStatusBlock,
                              void *FileInformation,
                              uint32_t FileInformationLength,
                              uint32_t FileInformationClass);

NtStatus NtDeviceIoControlFile(
    int64_t FileHandle, int64_t opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    uint32_t IoControlCode, void *opt_InputBuffer, uint32_t InputBufferLength,
    void *opt_out_OutputBuffer, uint32_t OutputBufferLength);

NtStatus NtCancelIoFileEx(int64_t FileHandle,
                          struct NtIoStatusBlock *IoRequestToCancel,
                          struct NtIoStatusBlock *IoStatusBlock);

NtStatus RtlNtStatusToDosError(NtStatus Status);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntfile.inc */

#define NtQueryInformationFile(...) __imp_NtQueryInformationFile(__VA_ARGS__)

extern typeof(NtQueryInformationFile) *const
    __imp_NtQueryInformationFile __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_NT_IPC_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » ipc                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtCreateNamedPipeFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes,
                               struct NtIoStatusBlock *out_IoStatusBlock,
                               uint32_t ShareAccess, uint32_t CreateDisposition,
                               uint32_t CreateOptions, int32_t TypeMessage,
                               int32_t ReadmodeMessage, int32_t Nonblocking,
                               uint32_t MaxInstances, uint32_t InBufferSize,
                               uint32_t OutBufferSize,
                               int64_t *opt_DefaultTimeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/key.h */

#define COSMOPOLITAN_LIBC_NT_NT_EVENT_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtCreateKeyedEvent(int64_t *KeyedEventHandle, uint32_t DesiredAccess,
                            struct NtObjectAttributes *ObjectAttributes,
                            uint32_t Flags);

NtStatus NtReleaseKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

NtStatus NtWaitForKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/loader.h */

#define COSMOPOLITAN_LIBC_NT_NT_LOADER_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » loader                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtAnsiString;
struct NtLdrDataTableEntry;
struct NtUnicodeString;

NtStatus LdrLoadDll(const char16_t *opt_PathToFile, uint32_t *opt_Flags,
                    struct NtUnicodeString *ModuleFileName,
                    void **out_ModuleHandle);
NtStatus LdrUnloadDll(void *ModuleHandle);
NtStatus LdrGetProcedureAddress(void *ModuleHandle,
                                struct NtAnsiString *opt_ProcedureName,
                                uint32_t opt_Ordinal,
                                wambda *out_ProcedureAddress);
NtStatus LdrGetDllHandle(const char16_t *opt_PathToFile, uint32_t opt_Unused,
                         struct NtUnicodeString *ModuleFileName,
                         void **out_ModuleHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_NT_MEMORY_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » memory                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtAllocateVirtualMemory(int64_t ProcessHandle,
                                 void **inout_BaseAddress, uint32_t dwZeroBits,
                                 uint32_t *inout_AllocationSize,
                                 uint32_t dwMemAllocationType,
                                 uint32_t dwPageProtect);
NtStatus NtFreeVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                             size_t *inout_FreeSize, uint32_t FreeType);
NtStatus NtQueryVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                              int MemoryInformationClass,
                              void *out_MemoryInformation,
                              size_t MemoryInformationLength,
                              size_t *opt_out_ReturnLength);
NtStatus NtProtectVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                                uint32_t *inout_ProtectSize,
                                uint32_t NewProtect, uint32_t *out_OldProtect);
NtStatus NtWriteVirtualMemory(int64_t ProcessHandle, void *BaseAddress,
                              const void *Buffer, size_t BufferLength,
                              size_t *opt_out_ReturnLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_NT_PROCESS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » processes              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtObjectAttributes;
struct NtRtlUserProcessInformation;
struct NtRtlUserProcessParameters;
struct NtSecurityDescriptor;
struct NtUnicodeString;

NtStatus NtCreateProcess(int64_t *out_ProcessHandle, uint32_t dwDesiredAccess,
                         struct NtObjectAttributes *opt_ObjectAttributes,
                         void *InheritFromProcessHandle, int32_t InheritHandles,
                         void *opt_SectionHandle, void *opt_DebugPort,
                         void *opt_ExceptionPort);
NtStatus NtTerminateProcess(int64_t opt_ProcessHandle, int32_t ExitStatus);

NtStatus NtQueryInformationProcess(int64_t ProcessHandle,
                                   int ProcessInformationClass,
                                   void *out_ProcessInformation,
                                   uint32_t ProcessInformationLength,
                                   uint32_t *opt_out_ReturnLength);
NtStatus NtOpenProcessToken(int64_t ProcessToken, uint32_t DesiredAccess,
                            int64_t *out_TokenHandle);
NtStatus NtOpenProcess(int64_t *out_ProcessHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       struct NtClientId *ClientId);

NtStatus RtlCreateProcessParameters(
    struct NtRtlUserProcessParameters **out_ProcessParameters,
    struct NtUnicodeString *ImageFile, struct NtUnicodeString *opt_DllPath,
    struct NtUnicodeString *opt_CurrentDirectory,
    struct NtUnicodeString *opt_CommandLine, uint32_t CreationFlags,
    struct NtUnicodeString *opt_WindowTitle,
    struct NtUnicodeString *opt_Desktop, struct NtUnicodeString *opt_Reserved,
    struct NtUnicodeString *opt_Reserved2);

NtStatus RtlDestroyProcessParameters(
    struct NtRtlUserProcessParameters *ProcessParameters);

NtStatus RtlCloneUserProcess(
    uint32_t ProcessFlags,
    struct NtSecurityDescriptor *opt_ProcessSecurityDescriptor,
    struct NtSecurityDescriptor *opt_ThreadSecurityDescriptor,
    void *opt_DebugPort,
    struct NtRtlUserProcessInformation *ProcessInformation);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/process.inc */

#define NtQueryInformationProcess(...) \
  __imp_NtQueryInformationProcess(__VA_ARGS__)

extern typeof(NtQueryInformationProcess) *const
    __imp_NtQueryInformationProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/sections.h */

#define COSMOPOLITAN_LIBC_NT_NT_SECTIONS_H_
COSMOPOLITAN_C_START_

NtStatus NtCreateSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                         struct NtObjectAttributes *ObjectAttributes,
                         int64_t *opt_SectionSize, uint32_t Protect,
                         uint32_t Attributes, int64_t FileHandle);
NtStatus NtOpenSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes);
NtStatus NtMapViewOfSection(int64_t SectionHandle, int64_t ProcessHandle,
                            void **inout_BaseAddress, uint32_t *ZeroBits,
                            size_t CommitSize, int64_t *opt_inout_SectionOffset,
                            size_t *inout_ViewSize, int InheritDisposition,
                            uint32_t AllocationType, uint32_t Protect);
NtStatus NtUnmapViewOfSection(int64_t ProcessHandle, void *BaseAddress);
NtStatus NtQuerySection(int64_t SectionHandle, int SectionInformationClass,
                        void *out_SectionInformation,
                        uint32_t SectionInformationLength,
                        uint32_t *opt_out_ResultLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/signing.h */

#define COSMOPOLITAN_LIBC_NT_NT_SIGNING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » code signing           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus CsrClientCallServer(void *inout_Message, void *unknown,
                             uint32_t Opcode, uint32_t Size);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » threads                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtContext;
struct NtObjectAttributes;
struct NtUserStack;

NtStatus NtCreateThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                        struct NtObjectAttributes *ObjectAttributes,
                        int64_t ProcessHandle, struct NtClientId *out_ClientId,
                        struct NtContext *ThreadContext,
                        struct NtUserStack *UserStack, int32_t CreateSuspended);

NtStatus NtTerminateThread(void *opt_ThreadHandle, int32_t ExitStatus);

NtStatus NtOpenThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                      struct NtObjectAttributes *ObjectAttributes,
                      struct NtClientId *ClientId);

NtStatus NtQueryInformationThread(int64_t ThreadHandle,
                                  enum NtThreadInfoClass ThreadInformationClass,
                                  void *out_ThreadInformation,
                                  uint32_t ThreadInformationLength,
                                  uint32_t *opt_out_ReturnLength);

NtStatus NtGetContextThread(int64_t ThreadHandle,
                            struct NtContext *out_Context);
NtStatus NtSetContextThread(int64_t ThreadHandle, struct NtContext *Context);
NtStatus NtSuspendThread(int64_t ThreadHandle,
                         uint32_t *opt_out_PreviousSuspendCount);
NtStatus NtResumeThread(int64_t ThreadHandle,
                        uint32_t *opt_out_PreviousSuspendCount);

NtStatus NtOpenThreadToken(int64_t ThreadHandle, uint32_t DesiredAccess,
                           int32_t OpenAsSelf, int64_t *out_TokenHandle);

NtStatus NtSetInformationThread(int64_t ThreadHandle,
                                enum NtThreadInfoClass ThreadInformationClass,
                                void *ThreadInformation,
                                uint32_t ThreadInformationLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » time                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtDelayExecution(bool32 alertable, int64_t *AbsCobolOrNegRelHectoNano);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/time.inc */

#define NtDelayExecution(...) __imp_NtDelayExecution(__VA_ARGS__)

extern typeof(NtDelayExecution) *const __imp_NtDelayExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/accounting.h */

#define COSMOPOLITAN_LIBC_NT_ACCOUNTING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » accounting                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetMaximumProcessorCount(uint16_t GroupNumber);
int GetUserName(char16_t (*buf)[257], uint32_t *in_out_size);
bool32 GlobalMemoryStatusEx(struct NtMemoryStatusEx *lpBuffer);
int32_t GetExitCodeProcess(int64_t hProcess, uint32_t *lpExitCode);
int32_t GetProcessHandleCount(int64_t hProcess, uint32_t *pdwHandleCount);
bool32 GetSystemTimes(struct NtFileTime *opt_out_lpIdleTime,
                      struct NtFileTime *opt_out_lpKernelTime,
                      struct NtFileTime *opt_out_lpUserTime);
bool32 GetProcessTimes(int64_t hProcess,
                       struct NtFileTime *out_lpCreationFileTime,
                       struct NtFileTime *out_lpExitFileTime,
                       struct NtFileTime *out_lpKernelFileTime,
                       struct NtFileTime *out_lpUserFileTime);
bool32 GetThreadTimes(int64_t hThread,
                      struct NtFileTime *out_lpCreationFileTime,
                      struct NtFileTime *out_lpExitFileTime,
                      struct NtFileTime *out_lpKernelFileTime,
                      struct NtFileTime *out_lpUserFileTime);
int32_t GetProcessIoCounters(int64_t hProcess,
                             struct NtIoCounters *lpIoCounters);
int32_t GetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t *lpMinimumWorkingSetSize,
                                 uint64_t *lpMaximumWorkingSetSize);
int32_t GetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t *lpMinimumWorkingSetSize,
                                   uint64_t *lpMaximumWorkingSetSize,
                                   uint32_t *Flags);
int32_t SetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t dwMinimumWorkingSetSize,
                                 uint64_t dwMaximumWorkingSetSize);
int32_t SetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t dwMinimumWorkingSetSize,
                                   uint64_t dwMaximumWorkingSetSize,
                                   uint32_t Flags);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/accounting.inc */

#define GetProcessTimes(...) __imp_GetProcessTimes(__VA_ARGS__)
extern typeof(GetProcessTimes) *const __imp_GetProcessTimes __msabi;

#define GetThreadTimes(...) __imp_GetThreadTimes(__VA_ARGS__)
extern typeof(GetThreadTimes) *const __imp_GetThreadTimes __msabi;

#define GetUserName(...) __imp_GetUserNameW(__VA_ARGS__)
extern typeof(GetUserName) *const __imp_GetUserNameW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/automation.h */

#define COSMOPOLITAN_LIBC_NT_AUTOMATION_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » aol hacking                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int64_t GetShellWindow(void);
int64_t GetDesktopWindow(void);
int64_t GetParent(int64_t hWnd);
int64_t SetParent(int64_t hWndChild, int64_t hWndNewParent);
int32_t EnumChildWindows(int64_t hWndParent, NtWndEnumProc lpEnumFunc,
                         intptr_t lParam);
int64_t FindWindow(const char16_t *lpClassName, const char16_t *lpWindowName);
int64_t FindWindowEx(int64_t hWndParent, int64_t hWndChildAfter,
                     const char16_t *lpszClass, const char16_t *lpszWindow);
int64_t GetWindow(int64_t hWnd, uint32_t uCmd);
int64_t SetWindowsHook(int nFilterType, NtHookProc pfnFilterProc);
int32_t UnhookWindowsHook(int nCode, NtHookProc pfnFilterProc);
int64_t SetWindowsHookEx(int idHook, NtHookProc lpfn, int64_t hmod,
                         uint32_t dwThreadId);
int32_t UnhookWindowsHookEx(int64_t hhk);
intptr_t CallNextHookEx(int64_t hhk, int nCode, uintptr_t wParam,
                        intptr_t lParam);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/codegen.h */

#define COSMOPOLITAN_LIBC_NT_CODEGEN_H_


/*!BEGIN libc/nt/comdlg.h */

#define COSMOPOLITAN_LIBC_NT_COMDLG_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » common dialogs                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 GetOpenFileName(struct NtOpenFilename *arg);
bool32 GetSaveFileName(struct NtOpenFilename *arg);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/comms.h */

#define COSMOPOLITAN_LIBC_NT_COMMS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » communications                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

bool32 PurgeComm(int64_t hFile, uint32_t dwFlags);
bool32 TransmitCommChar(int64_t hFile, char cChar);
bool32 ClearCommBreak(int64_t hFile);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/console.h */

#define COSMOPOLITAN_LIBC_NT_CONSOLE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » console                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtAttachParentProcess -1u

COSMOPOLITAN_C_START_

bool32 WriteConsoleOutput(int64_t hConsoleOutput,
                          const struct NtCharInfo *lpBuffer,
                          struct NtCoord dwBufferSize,
                          struct NtCoord dwBufferCoord,
                          struct NtSmallRect *lpWriteRegion);
bool32 ReadConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 PeekConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 GetNumberOfConsoleInputEvents(int64_t hConsoleInput,
                                     uint32_t *lpNumberOfEvents);
bool32 ReadConsoleOutput(int64_t hConsoleOutput, struct NtCharInfo *lpBuffer,
                         struct NtCoord dwBufferSize,
                         struct NtCoord dwBufferCoord,
                         struct NtSmallRect *lpReadRegion);
bool32 WriteConsoleInput(int64_t hConsoleInput,
                         const struct NtInputRecord *lpBuffer, uint32_t nLength,
                         uint32_t *lpNumberOfEventsWritten);
bool32 FlushConsoleInputBuffer(int64_t hConsoleInput);

int64_t GetConsoleWindow(void);
bool32 GetConsoleMode(int64_t hConsoleHandle, uint32_t *lpMode);
bool32 SetConsoleMode(int64_t hConsoleHandle, uint32_t dwMode);
int32_t AllocConsole(void);
int32_t FreeConsole(void);
int32_t AttachConsole(uint32_t dwProcessId);
uint32_t GetConsoleTitle(char16_t *lpConsoleTitle, uint32_t nSize);
int32_t SetConsoleTitle(const char16_t *lpConsoleTitle);
bool32 GetConsoleScreenBufferInfo(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfo *out_lpConsoleScreenBufferInfo);
bool32 GetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfoEx *in_out_lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    const struct NtConsoleScreenBufferInfoEx *lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferSize(int64_t lpConsoleOutput,
                                  struct NtCoord dwSize);
struct NtCoord GetLargestConsoleWindowSize(int64_t hConsoleHandle);
int32_t ReadConsole(int64_t hConsoleInput, void *lpBuffer,
                    uint32_t nNumberOfCharsToRead,
                    uint32_t *lpNumberOfCharsRead, void *lpReserved);
int32_t WriteConsole(int64_t hConsoleOutput, const void *lpBuffer,
                     uint32_t nNumberOfCharsToWrite,
                     uint32_t *lpNumberOfCharsWritten, void *lpReserved)
    paramsnonnull((2, 4));
bool32 GetNumberOfConsoleMouseButtons(uint32_t *out_lpNumberOfMouseButtons)
    paramsnonnull();
bool32 GetConsoleSelectionInfo(
    struct NtConsoleSelectionInfo *out_lpConsoleSelectionInfo);
uint32_t WaitForInputIdle(int64_t hProcess, uint32_t dwMilliseconds);
uint32_t GetConsoleCP(void);
bool32 SetConsoleCP(uint32_t wCodePageID);
bool32 SetConsoleOutputCP(uint32_t wCodePageID);
uint32_t GetConsoleOutputCP(void);
bool32 SetConsoleCtrlHandler(NtHandlerRoutine opt_HandlerRoutine, bool32 Add);
bool32 GenerateConsoleCtrlEvent(uint32_t dwCtrlEvent,
                                uint32_t dwProcessGroupId);

bool32 GetConsoleCursorInfo(
    int64_t hConsoleOutput,
    struct NtConsoleCursorInfo *out_lpConsoleCursorInfo);
bool32 SetConsoleCursorInfo(
    int64_t hConsoleOutput,
    const struct NtConsoleCursorInfo *lpConsoleCursorInfo);

long CreatePseudoConsole(struct NtCoord size, int64_t hInput, int64_t hOutput,
                         uint32_t dwFlags, int64_t *out_phPC);
long ResizePseudoConsole(int64_t hPC, struct NtCoord size);
void ClosePseudoConsole(int64_t hPC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/console.inc */

#define GetConsoleMode(...) __imp_GetConsoleMode(__VA_ARGS__)
extern typeof(GetConsoleMode) *const __imp_GetConsoleMode __msabi;

#define SetConsoleCP(...) __imp_SetConsoleCP(__VA_ARGS__)
extern typeof(SetConsoleCP) *const __imp_SetConsoleCP __msabi;

#define GetConsoleCP(...) __imp_GetConsoleCP(__VA_ARGS__)
extern typeof(GetConsoleCP) *const __imp_GetConsoleCP __msabi;

#define SetConsoleCtrlHandler(...) __imp_SetConsoleCtrlHandler(__VA_ARGS__)
extern typeof(SetConsoleCtrlHandler) *const __imp_SetConsoleCtrlHandler __msabi;

#define SetConsoleMode(...) __imp_SetConsoleMode(__VA_ARGS__)
extern typeof(SetConsoleMode) *const __imp_SetConsoleMode __msabi;

#define SetConsoleOutputCP(...) __imp_SetConsoleOutputCP(__VA_ARGS__)
extern typeof(SetConsoleOutputCP) *const __imp_SetConsoleOutputCP __msabi;

#define GetConsoleOutputCP(...) __imp_GetConsoleOutputCP(__VA_ARGS__)
extern typeof(GetConsoleOutputCP) *const __imp_GetConsoleOutputCP __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/createfile.h */

#define COSMOPOLITAN_LIBC_NT_CREATEFILE_H_
COSMOPOLITAN_C_START_

int64_t CreateFile(
    const char16_t *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int64_t CreateFileA(
    const char *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int GetNtOpenFlags(int, int, uint32_t *, uint32_t *, uint32_t *, uint32_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » debugging                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* Some of these APIs were moved to system.h and libc.h */
int32_t DebugBreakProcess(void *Process);
int32_t DebugActiveProcess(uint32_t dwProcessId);
int32_t DebugActiveProcessStop(uint32_t dwProcessId);
int32_t CheckRemoteDebuggerPresent(int64_t hProcess, int *pbDebuggerPresent);
int32_t ContinueDebugEvent(uint32_t dwProcessId, uint32_t dwThreadId,
                           uint32_t dwContinueStatus);
void FatalExit(int uExitCode);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/dll.h */

#define COSMOPOLITAN_LIBC_NT_DLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » dynamic link libraries                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t LoadLibrary(const char16_t *lpLibFileName);
int64_t LoadLibraryA(const char *lpLibFileName);
int64_t LoadLibraryEx(const char16_t *lpLibFileName, int64_t hFile,
                      uint32_t dwFlags);
uint32_t GetModuleFileNameA(int64_t hModule, char *lpFilename, uint32_t nSize);
intptr_t GetModuleHandle(const char *opt_lpModuleName);
intptr_t GetModuleHandleW(const char16_t *opt_lpModuleName);
void *GetProcAddress(int64_t hModule, const char *lpProcName);
int32_t FreeResource(int64_t hResData);
intptr_t LockResource(int64_t hResData);
int32_t FreeLibrary(int64_t hLibModule);
void *AddDllDirectory(const char16_t *NewDirectory);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/efi.h */

#define COSMOPOLITAN_LIBC_NT_EFI_H_
/*
    ▐██ ░█████████▓   ▐██▌     ██▓░   ▐█▌  ▐██  ░██░    ▓█▌  ▓██▒     ▓██
    ▐██     ░██░     ▒█▓██░    ████░  ▐█▌  ▐██  ░██░    ▓█▌  ▓███░   ▓███
    ▐██     ░██░     ██░▐█▓    ██▒▓█░ ▐█▌  ▐██  ░██░    ▓█▌  ▓█▌▓█░ ▓█▒██
    ▐██     ░██░    ▐█▌  ▓█▌   ██░░▓█░▐█▌  ▐██  ░██░    ▓█▌  ▓█▌░█▓▓█▒░██
    ▐██     ░██░   ▒██▓█████░  ██░ ░▓▓▓█▌  ▐██  ░██░    ██░  ▓█▌ ░██▌ ░██
    ▐██     ░██░   ▓█▌    ▓█▓  ██░  ░███▌  ▐██   ▐██▄▄▄▓█▓   ▓█▌      ░██
╔────────────────────────────────────────────────────────────────────────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § the unified extensible firmware interface ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define EFI_SUCCESS           0x8000000000000000
#define EFI_LOAD_ERROR        0x8000000000000001
#define EFI_INVALID_PARAMETER 0x8000000000000002
#define EFI_UNSUPPORTED       0x8000000000000003
#define EFI_BAD_BUFFER_SIZE   0x8000000000000004
#define EFI_BUFFER_TOO_SMALL  0x8000000000000005
#define EFI_NOT_READY         0x8000000000000006
#define EFI_DEVICE_ERROR      0x8000000000000007
#define EFI_WRITE_PROTECTED   0x8000000000000008
#define EFI_OUT_OF_RESOURCES  0x8000000000000009
#define EFI_VOLUME_CORRUPTED  0x800000000000000a
#define EFI_VOLUME_FULL       0x800000000000000b
#define EFI_NO_MEDIA          0x800000000000000c
#define EFI_MEDIA_CHANGED     0x800000000000000d
#define EFI_NOT_FOUND         0x800000000000000e
#define EFI_ACCESS_DENIED     0x800000000000000f
#define EFI_NO_RESPONSE       0x8000000000000010
#define EFI_NO_MAPPING        0x8000000000000011
#define EFI_TIMEOUT           0x8000000000000012
#define EFI_NOT_STARTED       0x8000000000000013
#define EFI_ALREADY_STARTED   0x8000000000000014
#define EFI_ABORTED           0x8000000000000015
#define EFI_ICMP_ERROR        0x8000000000000016
#define EFI_TFTP_ERROR        0x8000000000000017
#define EFI_PROTOCOL_ERROR    0x8000000000000018

#define EFI_VARIABLE_NON_VOLATILE                          0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS                    0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS                        0x00000004
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD                 0x00000008
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS            0x00000010
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
#define EFI_VARIABLE_APPEND_WRITE                          0x00000040

#define EFI_MEMORY_UC            0x0000000000000001U
#define EFI_MEMORY_WC            0x0000000000000002U
#define EFI_MEMORY_WT            0x0000000000000004U
#define EFI_MEMORY_WB            0x0000000000000008U
#define EFI_MEMORY_UCE           0x0000000000000010U
#define EFI_MEMORY_WP            0x0000000000001000U
#define EFI_MEMORY_RP            0x0000000000002000U
#define EFI_MEMORY_XP            0x0000000000004000U
#define EFI_MEMORY_RO            0x0000000000020000U
#define EFI_MEMORY_NV            0x0000000000008000U
#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000U
#define EFI_MEMORY_RUNTIME       0x8000000000000000U

#define EFI_OPTIONAL_PTR 0x00000001

#define EFI_SCAN_NULL      0x0000
#define EFI_SCAN_UP        0x0001
#define EFI_SCAN_DOWN      0x0002
#define EFI_SCAN_RIGHT     0x0003
#define EFI_SCAN_LEFT      0x0004
#define EFI_SCAN_HOME      0x0005
#define EFI_SCAN_END       0x0006
#define EFI_SCAN_INSERT    0x0007
#define EFI_SCAN_DELETE    0x0008
#define EFI_SCAN_PAGE_UP   0x0009
#define EFI_SCAN_PAGE_DOWN 0x000A
#define EFI_SCAN_F1        0x000B
#define EFI_SCAN_F2        0x000C
#define EFI_SCAN_F3        0x000D
#define EFI_SCAN_F4        0x000E
#define EFI_SCAN_F5        0x000F
#define EFI_SCAN_F6        0x0010
#define EFI_SCAN_F7        0x0011
#define EFI_SCAN_F8        0x0012
#define EFI_SCAN_F9        0x0013
#define EFI_SCAN_F10       0x0014
#define EFI_SCAN_ESC       0x0017

#define EFI_EVT_TIMER                         0x80000000
#define EFI_EVT_RUNTIME                       0x40000000
#define EFI_EVT_NOTIFY_WAIT                   0x00000100
#define EFI_EVT_NOTIFY_SIGNAL                 0x00000200
#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES     0x00000201
#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
#define EFI_EVT_RUNTIME_CONTEXT               0x20000000

#define LOADED_IMAGE_PROTOCOL                        \
  {                                                  \
    0x5B1B31A1, 0x9562, 0x11d2, {                    \
      0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \
    }                                                \
  }
#define GRAPHICS_OUTPUT_PROTOCOL                     \
  {                                                  \
    0x9042A9DE, 0x23DC, 0x4A38, {                    \
      0x96, 0xFB, 0x7A, 0xDE, 0xD0, 0x80, 0x51, 0x6A \
    }                                                \
  }
#define ACPI_20_TABLE_GUID                           \
  {                                                  \
    0x8868E871, 0xE4F1, 0x11D3, {                    \
      0xBC, 0x22, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 \
    }                                                \
  }
#define ACPI_10_TABLE_GUID                           \
  {                                                  \
    0xEB9D2D30, 0x2D88, 0x11D3, {                    \
      0x9A, 0x16, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D \
    }                                                \
  }

COSMOPOLITAN_C_START_

#if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__chibicc__) && \
    defined(__x86_64__)
#define EFIAPI __attribute__((__ms_abi__))
#else
#define EFIAPI /* TODO(jart): fix me */
#endif

#define EFI_STATUS uint64_t
#define EFI_EVENT  uintptr_t
#define EFI_HANDLE uintptr_t

typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
typedef struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL;

typedef enum {
  EfiReservedMemoryType,
  EfiLoaderCode,
  EfiLoaderData,
  EfiBootServicesCode,
  EfiBootServicesData,
  EfiRuntimeServicesCode,
  EfiRuntimeServicesData,
  EfiConventionalMemory,
  EfiUnusableMemory,
  EfiACPIReclaimMemory,
  EfiACPIMemoryNVS,
  EfiMemoryMappedIO,
  EfiMemoryMappedIOPortSpace,
  EfiPalCode,
  EfiPersistentMemory,
  EfiMaxMemoryType
} EFI_MEMORY_TYPE;

typedef enum {
  EfiResetCold,
  EfiResetWarm,
  EfiResetShutdown,
  EfiResetPlatformSpecific
} EFI_RESET_TYPE;

typedef enum {
  AllocateAnyPages,
  AllocateMaxAddress,
  AllocateAddress,
  MaxAllocateType
} EFI_ALLOCATE_TYPE;

typedef enum {
  TimerCancel,
  TimerPeriodic,
  TimerRelative,
} EFI_TIMER_DELAY;

typedef struct {
  uint32_t Resolution;
  uint32_t Accuracy;
  bool32 SetsToZero;
} EFI_TIME_CAPABILITIES;

typedef struct {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
} EFI_GUID;

typedef struct {
  uint16_t Year;
  uint8_t Month;
  uint8_t Day;
  uint8_t Hour;
  uint8_t Minute;
  uint8_t Second;
  uint8_t Pad1;
  uint32_t Nanosecond;
  int16_t TimeZone;
  uint8_t Daylight;
  uint8_t Pad2;
} EFI_TIME;

typedef struct {
  uint32_t Type;
  uint64_t PhysicalStart;
  uint64_t VirtualStart;
  uint64_t NumberOfPages;
  uint64_t Attribute;
} EFI_MEMORY_DESCRIPTOR;

typedef struct {
  EFI_GUID VendorGuid;
  void *VendorTable;
} EFI_CONFIGURATION_TABLE;

typedef struct {
  EFI_GUID CapsuleGuid;
  uint32_t HeaderSize;
  uint32_t Flags;
  uint32_t CapsuleImageSize;
} EFI_CAPSULE_HEADER;

typedef struct {
  uint16_t ScanCode;
  char16_t UnicodeChar;
} EFI_INPUT_KEY;

typedef struct {
  int32_t MaxMode;
  int32_t Mode;
  int32_t Attribute;
  int32_t CursorColumn;
  int32_t CursorRow;
  bool32 CursorVisible;
} EFI_SIMPLE_TEXT_OUTPUT_MODE;

typedef enum {
  PixelRedGreenBlueReserved8BitPerColor,
  PixelBlueGreenRedReserved8BitPerColor,
  PixelBitMask,
  PixelBltOnly,
  PixelFormatMax
} EFI_GRAPHICS_PIXEL_FORMAT;

typedef struct {
  uint32_t RedMask;
  uint32_t GreenMask;
  uint32_t BlueMask;
  uint32_t ReservedMask;
} EFI_PIXEL_BITMASK;

typedef struct {
  uint32_t Version;
  uint32_t HorizontalResolution;
  uint32_t VerticalResolution;
  EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
  EFI_PIXEL_BITMASK PixelInformation;
  uint32_t PixelsPerScanLine;
} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;

typedef struct {
  uint8_t Blue;
  uint8_t Green;
  uint8_t Red;
  uint8_t Reserved;
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;

typedef enum {
  EfiBltVideoFill,
  EfiBltVideoToBltBuffer,
  EfiBltBufferToVideo,
  EfiBltVideoToVideo,
  EfiGraphicsOutputBltOperationMax
} EFI_GRAPHICS_OUTPUT_BLT_OPERATION;

typedef struct {
  uint32_t MaxMode;
  uint32_t Mode;
  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
  uint32_t SizeOfInfo;
  uint64_t FrameBufferBase;
  uint32_t FrameBufferSize;
} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;

typedef struct {
  uint64_t Signature;
  uint32_t Revision;
  uint32_t HeaderSize;
  uint32_t CRC32;
  uint32_t Reserved;
} EFI_TABLE_HEADER;

typedef struct {
  uint8_t Type;
  uint8_t SubType;
  uint8_t Length[2];
} EFI_DEVICE_PATH_PROTOCOL;

typedef EFI_STATUS(EFIAPI *EFI_EXIT)(EFI_HANDLE ImageHandle,
                                     EFI_STATUS ExitStatus,
                                     uintptr_t ExitDataSize,
                                     char16_t *opt_ExitData);

typedef EFI_STATUS(EFIAPI *EFI_GET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t *outopt_Attributes,
                                             uintptr_t *inout_DataSize,
                                             void *outopt_Data);
typedef EFI_STATUS(EFIAPI *EFI_SET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t Attributes,
                                             uintptr_t DataSize, void *Data);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME)(
    uintptr_t *inout_VariableNameSize, char16_t *inout_VariableName,
    EFI_GUID *inout_VendorGuid);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_VARIABLE_INFO)(
    uint32_t Attributes, uint64_t *out_MaximumVariableStorageSize,
    uint64_t *out_RemainingVariableStorageSize,
    uint64_t *out_MaximumVariableSize);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_PAGES)(EFI_ALLOCATE_TYPE Type,
                                               EFI_MEMORY_TYPE MemoryType,
                                               uintptr_t Pages,
                                               uint64_t *inout_Memory);
typedef EFI_STATUS(EFIAPI *EFI_FREE_PAGES)(uint64_t Memory, uintptr_t Pages);
typedef EFI_STATUS(EFIAPI *EFI_GET_MEMORY_MAP)(
    uintptr_t *inout_MemoryMapSize, EFI_MEMORY_DESCRIPTOR *inout_MemoryMap,
    uintptr_t *out_MapKey, uintptr_t *out_DescriptorSize,
    uint32_t *out_DescriptorVersion);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_POOL)(EFI_MEMORY_TYPE PoolType,
                                              uintptr_t Size, void *out_Buffer);
typedef EFI_STATUS(EFIAPI *EFI_FREE_POOL)(void *Buffer);
typedef void(EFIAPI *EFI_SET_MEM)(void *Buffer, uintptr_t Size, uint8_t Value);
typedef void(EFIAPI *EFI_COPY_MEM)(void *Destination, void *Source,
                                   uintptr_t Length);

typedef EFI_STATUS(EFIAPI *EFI_CHECK_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_CLOSE_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_SIGNAL_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_WAIT_FOR_EVENT)(uintptr_t NumberOfEvents,
                                               EFI_EVENT *Events,
                                               uintptr_t *out_Index);
typedef EFI_STATUS(EFIAPI *EFI_SET_TIMER)(EFI_EVENT Event, EFI_TIMER_DELAY Type,
                                          uint64_t TriggerTime);
typedef void(EFIAPI *EFI_EVENT_NOTIFY)(EFI_EVENT Event, void *Context);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT)(uint32_t Type, uintptr_t NotifyTpl,
                                             EFI_EVENT_NOTIFY NotifyFunction,
                                             void *NotifyContext,
                                             EFI_EVENT *out_Event);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT_EX)(
    uint32_t Type, uintptr_t NotifyTpl, EFI_EVENT_NOTIFY opt_NotifyFunction,
    const void *opt_NotifyContext, const EFI_GUID *opt_EventGroup,
    EFI_EVENT *out_Event);

typedef EFI_STATUS(EFIAPI *EFI_UPDATE_CAPSULE)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t opt_ScatterGatherList);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t *out_MaximumCapsuleSize, EFI_RESET_TYPE *out_ResetType);
typedef EFI_STATUS(EFIAPI *EFI_GET_WAKEUP_TIME)(bool32 *out_Enabled,
                                                bool32 *out_Pending,
                                                EFI_TIME *out_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WAKEUP_TIME)(bool32 Enable,
                                                EFI_TIME *opt_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WATCHDOG_TIMER)(uintptr_t Timeout,
                                                   uint64_t WatchdogCode,
                                                   uintptr_t DataSize,
                                                   char16_t *opt_WatchdogData);
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)(EFI_GUID *Protocol,
                                                void *Registration,
                                                void *Interface);

typedef EFI_STATUS(EFIAPI *EFI_SET_TIME)(EFI_TIME *Time);
typedef EFI_STATUS(EFIAPI *EFI_GET_TIME)(
    EFI_TIME *out_Time, EFI_TIME_CAPABILITIES *outopt_Capabilities);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT)(
    uint32_t *out_HighCount);
typedef EFI_STATUS(EFIAPI *EFI_STALL)(uintptr_t Microseconds);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT)(uint64_t *out_Count);

typedef EFI_STATUS(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP)(
    uintptr_t MemoryMapSize, uintptr_t DescriptorSize,
    uint32_t DescriptorVersion, EFI_MEMORY_DESCRIPTOR *VirtualMap);
typedef void(EFIAPI *EFI_RESET_SYSTEM)(EFI_RESET_TYPE ResetType,
                                       EFI_STATUS ResetStatus,
                                       uintptr_t DataSize, void *opt_ResetData);
typedef EFI_STATUS(EFIAPI *EFI_CONVERT_POINTER)(uintptr_t DebugDisposition,
                                                void **inout_Address);

typedef EFI_STATUS(EFIAPI *EFI_INPUT_RESET)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_INPUT_READ_KEY)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, EFI_INPUT_KEY *out_Key);

typedef EFI_STATUS(EFIAPI *EFI_TEXT_RESET)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_TEST_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_QUERY_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber,
    uint64_t *out_Columns, uint64_t *out_Rows);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_ATTRIBUTE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Attribute);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_CLEAR_SCREEN)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_CURSOR_POSITION)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Column, uint64_t Row);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_ENABLE_CURSOR)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 Visible);

typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber,
    uint32_t *SizeOfInfo, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
    EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
    EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, uint32_t SourceX,
    uint32_t SourceY, uint32_t DestinationX, uint32_t DestinationY,
    uint32_t Width, uint32_t Height, uint32_t Delta);

typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(EFI_HANDLE Handle,
                                                EFI_GUID *Protocol,
                                                void *out_Interface);

typedef EFI_STATUS(EFIAPI *EFI_IMAGE_LOAD)(bool32 BootPolicy,
                                           EFI_HANDLE ParentImageHandle,
                                           EFI_DEVICE_PATH_PROTOCOL *DevicePath,
                                           void *opt_SourceBuffer,
                                           uintptr_t SourceSize,
                                           EFI_HANDLE *out_ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_UNLOAD)(EFI_HANDLE ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_EXIT_BOOT_SERVICES)(EFI_HANDLE ImageHandle,
                                                   uintptr_t MapKey);

typedef struct {
  EFI_TABLE_HEADER Hdr;
  EFI_GET_TIME GetTime;
  EFI_SET_TIME SetTime;
  EFI_GET_WAKEUP_TIME GetWakeupTime;
  EFI_SET_WAKEUP_TIME SetWakeupTime;
  EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap;
  EFI_CONVERT_POINTER ConvertPointer;
  EFI_GET_VARIABLE GetVariable;
  EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName;
  EFI_SET_VARIABLE SetVariable;
  EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount;
  EFI_RESET_SYSTEM ResetSystem;
  EFI_UPDATE_CAPSULE UpdateCapsule;
  EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;
  EFI_QUERY_VARIABLE_INFO QueryVariableInfo;
} EFI_RUNTIME_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  void *RaiseTPL;
  void *RestoreTPL;
  EFI_ALLOCATE_PAGES AllocatePages;
  EFI_FREE_PAGES FreePages;
  EFI_GET_MEMORY_MAP GetMemoryMap;
  EFI_ALLOCATE_POOL AllocatePool;
  EFI_FREE_POOL FreePool;
  EFI_CREATE_EVENT CreateEvent;
  EFI_SET_TIMER SetTimer;
  EFI_WAIT_FOR_EVENT WaitForEvent;
  EFI_SIGNAL_EVENT SignalEvent;
  EFI_CLOSE_EVENT CloseEvent;
  EFI_CHECK_EVENT CheckEvent;
  void *InstallProtocolInterface;
  void *ReinstallProtocolInterface;
  void *UninstallProtocolInterface;
  EFI_HANDLE_PROTOCOL HandleProtocol;
  void *Reserved;
  void *RegisterProtocolNotify;
  void *LocateHandle;
  void *LocateDevicePath;
  void *InstallConfigurationTable;
  EFI_IMAGE_LOAD LoadImage;
  void *StartImage;
  EFI_EXIT Exit;
  EFI_IMAGE_UNLOAD UnloadImage;
  EFI_EXIT_BOOT_SERVICES ExitBootServices;
  EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount;
  EFI_STALL Stall;
  EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;
  void *ConnectController;
  void *DisconnectController;
  void *OpenProtocol;
  void *CloseProtocol;
  void *OpenProtocolInformation;
  void *ProtocolsPerHandle;
  void *LocateHandleBuffer;
  EFI_LOCATE_PROTOCOL LocateProtocol;
  void *InstallMultipleProtocolInterfaces;
  void *UninstallMultipleProtocolInterfaces;
  void *CalculateCrc32;
  EFI_COPY_MEM CopyMem;
  EFI_SET_MEM SetMem;
  EFI_CREATE_EVENT_EX CreateEventEx;
} EFI_BOOT_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  char16_t *FirmwareVendor;
  uint32_t FirmwareRevision;
  EFI_HANDLE ConsoleInHandle;
  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
  EFI_HANDLE ConsoleOutHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
  EFI_HANDLE StandardErrorHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
  EFI_RUNTIME_SERVICES *RuntimeServices;
  EFI_BOOT_SERVICES *BootServices;
  uintptr_t NumberOfTableEntries;
  EFI_CONFIGURATION_TABLE *ConfigurationTable;
} EFI_SYSTEM_TABLE;

struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
  EFI_INPUT_RESET Reset;
  EFI_INPUT_READ_KEY ReadKeyStroke;
  EFI_EVENT WaitForKey;
};

struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
  EFI_TEXT_RESET Reset;
  EFI_TEXT_STRING OutputString;
  EFI_TEXT_TEST_STRING TestString;
  EFI_TEXT_QUERY_MODE QueryMode;
  EFI_TEXT_SET_MODE SetMode;
  EFI_TEXT_SET_ATTRIBUTE SetAttribute;
  EFI_TEXT_CLEAR_SCREEN ClearScreen;
  EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition;
  EFI_TEXT_ENABLE_CURSOR EnableCursor;
  EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;
};

struct _EFI_GRAPHICS_OUTPUT_PROTOCOL {
  EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
};

typedef struct {
  uint32_t Revision;
  EFI_HANDLE ParentHandle;
  EFI_SYSTEM_TABLE *SystemTable;
  EFI_HANDLE DeviceHandle;
  EFI_DEVICE_PATH_PROTOCOL *FilePath;
  void *Reserved;
  uint32_t LoadOptionsSize;
  void *LoadOptions;
  void *ImageBase;
  uint64_t ImageSize;
  EFI_MEMORY_TYPE ImageCodeType;
  EFI_MEMORY_TYPE ImageDataType;
  EFI_IMAGE_UNLOAD Unload;
} EFI_LOADED_IMAGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/events.h */

#define COSMOPOLITAN_LIBC_NT_EVENTS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » events                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int32_t GetMessage(struct NtMsg *lpMsg, int64_t hWnd, uint32_t wMsgFilterMin,
                   uint32_t wMsgFilterMax);
int32_t TranslateMessage(const struct NtMsg *lpMsg);
intptr_t DispatchMessage(const struct NtMsg *lpMsg);
void PostQuitMessage(int nExitCode);
bool32 GetCursorPos(struct NtPoint *lpPoint);
int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                    int64_t lParam);

#define EVENTLOG_SUCCESS          0x00000000
#define EVENTLOG_ERROR_TYPE       0x00000001
#define EVENTLOG_WARNING_TYPE     0x00000002
#define EVENTLOG_INFORMATION_TYPE 0x00000004
#define EVENTLOG_AUDIT_SUCCESS    0x00000008
#define EVENTLOG_AUDIT_FAILURE    0x00000010

int32_t ReportEventA(int64_t handle, uint16_t wType, uint16_t wCategory,
                     uint32_t dwEventID, const char *lpUserId,
                     uint16_t wNumStrings, uint32_t dwDataSize,
                     const char **lpStrings, void **lpRawData);
int64_t RegisterEventSource(const char16_t *lpUNCServerName,
                            const char16_t *lpSourceName);
int32_t DeregisterEventSource(uint64_t handle);

int64_t CreateEvent(const struct NtSecurityAttributes *opt_lpEventAttributes,
                    bool32 bManualReset, bool32 bInitialState,
                    const char16_t *opt_lpName);
int64_t CreateEventA(const struct NtSecurityAttributes *opt_lpEventAttributes,
                     bool32 bManualReset, bool32 bInitialState,
                     const char *opt_lpName);
int64_t CreateEventEx(const struct NtSecurityAttributes *lpEventAttributes,
                      const char16_t *lpName, uint32_t dwFlags,
                      uint32_t dwDesiredAccess);

int32_t SetEvent(int64_t hEvent);
int32_t ResetEvent(int64_t hEvent);
int32_t PulseEvent(int64_t hEvent);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/files.h */

#define COSMOPOLITAN_LIBC_NT_FILES_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » files                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtHandleFlagInherit          1 /* SetHandleInformation */
#define kNtHandleFlagProtectFromClose 2

#define kNtFindFirstExCaseSensitive 1
#define kNtFindFirstExLargeFetch    2

#define kNtDuplicateCloseSource 1
#define kNtDuplicateSameAccess  2

COSMOPOLITAN_C_START_

intptr_t LoadResource(int64_t hModule, int64_t hResInfo);
uint32_t SetHandleCount(uint32_t uNumber);
uint32_t GetLogicalDrives(void);
bool32 FlushFileBuffers(int64_t hFile);

int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess,
                   uint32_t dwShareMode, uint32_t dwFlagsAndAttributes);

bool32 DeleteFile(const char16_t *lpFileName) paramsnonnull();

bool32 CopyFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName, bool32 bFailIfExists)
    paramsnonnull();

bool32 MoveFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName) paramsnonnull();
bool32 MoveFileEx(const char16_t *lpExistingFileName,
                  const char16_t *opt_lpNewFileName, int dwFlags)
    paramsnonnull((1));

bool32 SetCurrentDirectory(const char16_t *lpPathName);
uint32_t GetCurrentDirectory(uint32_t nBufferLength, char16_t *out_lpBuffer);

bool32 CreateDirectory(const char16_t *lpPathName,
                       const struct NtSecurityAttributes *lpSecurityAttributes);
bool32 RemoveDirectory(const char16_t *lpPathName);

bool32 DuplicateHandle(int64_t hSourceProcessHandle, int64_t hSourceHandle,
                       int64_t hTargetProcessHandle, int64_t *lpTargetHandle,
                       uint32_t dwDesiredAccess, bool32 bInheritHandle,
                       uint32_t dwOptions);

bool32 GetHandleInformation(int64_t hObject, uint32_t *out_lpdwFlags);
bool32 SetHandleInformation(int64_t hObject, uint32_t dwMask, uint32_t dwFlags);
int GetFileType(int64_t hFile);

bool32 GetFileInformationByHandleEx(int64_t hFile,
                                    uint32_t FileInformationClass,
                                    void *out_lpFileInformation,
                                    uint32_t dwBufferSize);

bool32 GetFileInformationByHandle(
    int64_t hFile, struct NtByHandleFileInformation *lpFileInformation);
bool32 SetFileInformationByHandle(int64_t hFile, int FileInformationClass,
                                  const void *lpFileInformation,
                                  uint32_t dwBufferSize);

uint32_t GetFileAttributes(const char16_t *lpFileName);
bool32 GetFileAttributesEx(
    const char16_t *lpFileName, int fInfoLevelId /* kNtGetFileExInfoStandard */,
    void *out_lpFileInformation /* → struct NtWin32FileAttributeData * */)
    paramsnonnull();

uint32_t GetCompressedFileSize(const char16_t *lpFileName,
                               uint32_t *lpFileSizeHigh);
bool32 SetFileAttributes(const char16_t *lpFileName, uint32_t dwFileAttributes);
bool32 GetFileTime(int64_t hFile, struct NtFileTime *opt_lpCreationFileTime,
                   struct NtFileTime *opt_lpLastAccessFileTime,
                   struct NtFileTime *opt_lpLastWriteFileTime);
bool32 SetFileTime(int64_t hFile,
                   const struct NtFileTime *opt_lpCreationFileTime,
                   const struct NtFileTime *opt_lpLastAccessFileTime,
                   const struct NtFileTime *opt_lpLastWriteFileTime);

bool32 DeviceIoControl(int64_t hDevice, uint32_t dwIoControlCode,
                       void *lpInBuffer, uint32_t nInBufferSize,
                       void *lpOutBuffer, uint32_t nOutBufferSize,
                       uint32_t *lpBytesReturned,
                       struct NtOverlapped *lpOverlapped);

bool32 LockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToLockLow,
                uint32_t nNumberOfBytesToLockHigh);
bool32 UnlockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                  uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToUnlockLow,
                  uint32_t nNumberOfBytesToUnlockHigh);
bool32 LockFileEx(int64_t hFile, uint32_t dwFlags, uint32_t dwReserved,
                  uint32_t nNumberOfBytesToLockLow,
                  uint32_t nNumberOfBytesToLockHigh,
                  struct NtOverlapped *lpOverlapped) paramsnonnull();
bool32 UnlockFileEx(int64_t hFile, uint32_t dwReserved,
                    uint32_t nNumberOfBytesToUnlockLow,
                    uint32_t nNumberOfBytesToUnlockHigh,
                    struct NtOverlapped *lpOverlapped) paramsnonnull();

bool32 CreateHardLink(const char16_t *lpFileName,
                      const char16_t *lpExistingFileName,
                      const struct NtSecurityAttributes *reserved)
    paramsnonnull((1, 2));
bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName,
                          const char16_t *lpTargetPathName, uint32_t dwFlags)
    paramsnonnull();

bool32 SetEndOfFile(int64_t hFile);
bool32 SetFileValidData(int64_t hFile, int64_t ValidDataLength);

bool32 GetFileSecurity(const char16_t *lpFileName,
                       uint32_t RequestedInformation,
                       struct NtSecurityDescriptor *pSecurityDescriptor,
                       uint32_t nLength, uint32_t *lpnLengthNeeded);

bool32 OpenProcessToken(int64_t hProcessHandle, uint32_t dwDesiredAccess,
                        int64_t *out_hTokenHandle);
bool32 DuplicateToken(int64_t hExistingTokenHandle, int dwImpersonationLevel,
                      int64_t *out_hDuplicateTokenHandle);
bool32 DuplicateTokenEx(int64_t hExistingToken, unsigned int dwDesiredAccess,
                        const struct NtSecurityAttributes *lpTokenAttributes,
                        int ImpersonationLevel, int TokenType,
                        int64_t *out_phNewToken);

bool32 AccessCheck(struct NtSecurityDescriptor *pSecurityDescriptor,
                   int64_t ClientToken, unsigned int DesiredAccess,
                   struct NtGenericMapping *lpGenericMapping,
                   struct NtPrivilegeSet *lpPrivilegeSet,
                   unsigned int *PrivilegeSetLength,
                   unsigned int *GrantedAccess, bool32 *AccessStatus);

void MapGenericMask(uint32_t *AccessMask,
                    struct NtGenericMapping *GenericMapping);

int64_t FindFirstFile(const char16_t *lpFileName,
                      struct NtWin32FindData *out_lpFindFileData);
int64_t FindFirstFileEx(const char16_t *lpFileName, int fInfoLevelId,
                        void *out_lpFindFileData, int fSearchOp,
                        void *reserved_lpSearchFilter,
                        uint32_t dwAdditionalFlags);
bool32 FindNextFile(int64_t hFindFile,
                    struct NtWin32FindData *out_lpFindFileData);
bool32 FindClose(int64_t hFindFile);

int64_t FindFirstVolume(char16_t *out_lpszVolumeName, uint32_t cchBufferLength);
bool32 FindNextVolume(int64_t inout_hFindVolume, char16_t *out_lpszVolumeName,
                      uint32_t cchBufferLength);
bool32 FindVolumeClose(int64_t hFindVolume);

bool32 ReadFileScatter(
    int64_t hFileOpenedWithOverlappedAndNoBuffering,
    const union NtFileSegmentElement
        aNullTerminatedPageAlignedSizedSegmentArray[],
    uint32_t nNumberOfBytesToReadThatsMultipleOfFileVolumeSectorSize,
    uint32_t *lpReserved, struct NtOverlapped *inout_lpOverlapped)
    paramsnonnull();

bool32 WriteFileGather(int64_t hFileOpenedWithOverlappedAndNoBuffering,
                       const union NtFileSegmentElement aSegmentArray[],
                       uint32_t nNumberOfBytesToWrite, uint32_t *lpReserved,
                       struct NtOverlapped inout_lpOverlapped) paramsnonnull();

#define kNtFileNameNormalized 0x0
#define kNtFileNameOpened     0x8
#define kNtVolumeNameDos      0x0 /* e.g. \\?\C:\Users\jart */
#define kNtVolumeNameGuid     0x1 /* e.g. \\?\Volume{ea38-etc.}\Users\jart */
#define kNtVolumeNameNt       0x2 /* e.g. \Device\HarddiskVolume4\Users\jart */
#define kNtVolumeNameNone     0x4 /* e.g. \Users\jart */
uint32_t GetFinalPathNameByHandle(int64_t hFile, char16_t *out_path,
                                  uint32_t arraylen, uint32_t flags);

uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength,
                         char16_t *lpBuffer, char16_t **lpFilePart);

bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped,
                           uint32_t *lpNumberOfBytesTransferred, bool32 bWait);
bool32 GetOverlappedResultEx(int64_t hFile, struct NtOverlapped *lpOverlapped,
                             uint32_t *lpNumberOfBytesTransferred,
                             uint32_t dwMilliseconds, bool32 bAlertable);

bool32 GetVolumePathName(const char16_t *lpszFileName,
                         char16_t *lpszVolumePathName,
                         uint32_t cchBufferLength);

bool32 GetVolumeInformationByHandle(int64_t hFile,
                                    char16_t *opt_out_lpVolumeNameBuffer,
                                    uint32_t nVolumeNameSize,
                                    uint32_t *opt_out_lpVolumeSerialNumber,
                                    uint32_t *opt_out_lpMaximumComponentLength,
                                    uint32_t *opt_out_lpFileSystemFlags,
                                    char16_t *opt_out_lpFileSystemNameBuffer,
                                    uint32_t nFileSystemNameSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/files.inc */

#define CopyFile(...) __imp_CopyFileW(__VA_ARGS__)
extern typeof(CopyFile) *const __imp_CopyFileW __msabi;

#define GetFileType(...) __imp_GetFileType(__VA_ARGS__)
extern typeof(GetFileType) *const __imp_GetFileType __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iocp.h */

#define COSMOPOLITAN_LIBC_NT_IOCP_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » i/o completion ports                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtFileSkipCompletionPortOnSuccess 1
#define kNtFileSkipSetEventOnHandle        2

COSMOPOLITAN_C_START_

typedef void (*NtOverlappedCompletionRoutine)(
    uint32_t dwErrorCode, uint32_t dwNumberOfBytesTransfered,
    struct NtOverlapped *inout_lpOverlapped);

int64_t CreateIoCompletionPort(int64_t FileHandleOrNeg1,
                               int64_t opt_ExistingCompletionPortOrZero,
                               uint64_t CompletionKey,
                               uint32_t NumberOfConcurrentThreads);

bool32 GetQueuedCompletionStatus(int64_t CompletionPort,
                                 uint32_t *lpNumberOfBytesTransferred,
                                 uint64_t *out_lpCompletionKey,
                                 struct NtOverlapped **out_lpOverlapped,
                                 uint32_t dwMilliseconds);

bool32 GetQueuedCompletionStatusEx(
    int64_t CompletionPort,
    struct NtOverlappedEntry *out_lpCompletionPortEntries, uint32_t ulCount,
    uint32_t *out_ulNumEntriesRemoved, uint32_t dwMilliseconds,
    bool32 fAlertable);

bool32 PostQueuedCompletionStatus(int64_t CompletionPort,
                                  uint32_t dwNumberOfBytesTransferred,
                                  uint64_t dwCompletionKey,
                                  struct NtOverlapped *opt_lpOverlapped);

bool32 SetFileCompletionNotificationModes(int64_t FileHandle,
                                          unsigned char Flags);

bool32 ReadFileEx(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                  uint32_t *lpNumberOfBytesRead,
                  struct NtOverlapped *opt_lpOverlapped,
                  NtOverlappedCompletionRoutine lpCompletionRoutine);

bool32 WriteFileEx(int64_t hFile, const void *lpBuffer,
                   uint32_t nNumberOfBytesToWrite,
                   struct NtOverlapped *lpOverlapped,
                   NtOverlappedCompletionRoutine lpCompletionRoutine);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_IPC_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ipc                                      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* CreateNamedPipe:dwOpenMode */
#define kNtPipeAccessInbound  0x00000001
#define kNtPipeAccessOutbound 0x00000002
#define kNtPipeAccessDuplex   0x00000003

/* CreateNamedPipe::dwPipeMode */
#define kNtPipeWait                0x00000000
#define kNtPipeNowait              0x00000001
#define kNtPipeReadmodeByte        0x00000000
#define kNtPipeReadmodeMessage     0x00000002
#define kNtPipeTypeByte            0x00000000
#define kNtPipeTypeMessage         0x00000004
#define kNtPipeAcceptRemoteClients 0x00000000
#define kNtPipeRejectRemoteClients 0x00000008

/* CreateNamedPipe::nMaxInstances */
#define kNtPipeUnlimitedInstances 255

/* GetNamedPipeInfo */
#define kNtPipeClientEnd 0x00000000
#define kNtPipeServerEnd 0x00000001

COSMOPOLITAN_C_START_

bool32 CreatePipe(int64_t *out_hReadPipe, int64_t *out_hWritePipe,
                  const struct NtSecurityAttributes *opt_lpPipeAttributes,
                  uint32_t nSize) paramsnonnull((1, 2));

int64_t CreateNamedPipe(
    const char16_t *lpName, uint32_t dwOpenMode, uint32_t dwPipeMode,
    uint32_t nMaxInstances, uint32_t nOutBufferSize, uint32_t nInBufferSize,
    uint32_t nDefaultTimeOut,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes)
    paramsnonnull((1));

bool32 CallNamedPipe(const char16_t *lpNamedPipeName, void *lpInBuffer,
                     uint32_t nInBufferSize, void *lpOutBuffer,
                     uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                     uint32_t nTimeOut);

bool32 ConnectNamedPipe(int64_t hNamedPipe, struct NtOverlapped *lpOverlapped);
bool32 WaitNamedPipe(const char16_t *lpNamedPipeName, uint32_t nTimeOut);
bool32 DisconnectNamedPipe(int64_t hNamedPipe);

bool32 SetNamedPipeHandleState(int64_t hNamedPipe, uint32_t *lpMode,
                               uint32_t *lpMaxCollectionCount,
                               uint32_t *lpCollectDataTimeout);

bool32 PeekNamedPipe(int64_t hNamedPipe, void *lpBuffer, uint32_t nBufferSize,
                     uint32_t *opt_lpBytesRead, uint32_t *opt_lpTotalBytesAvail,
                     uint32_t *opt_lpBytesLeftThisMessage);

bool32 TransactNamedPipe(int64_t hNamedPipe, void *lpInBuffer,
                         uint32_t nInBufferSize, void *lpOutBuffer,
                         uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                         struct NtOverlapped *lpOverlapped);

bool32 GetNamedPipeInfo(int64_t hNamedPipe, uint32_t *opt_out_lpFlags,
                        uint32_t *opt_out_lpOutBufferSize,
                        uint32_t *opt_out_lpInBufferSize,
                        uint32_t *opt_out_lpMaxInstances);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iphlpapi.h */

#define COSMOPOLITAN_LIBC_NT_IPHLPAPI_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ip helper api                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetAdaptersAddresses(uint32_t Family, uint32_t Flags, void *Reserved,
                              struct NtIpAdapterAddresses *AdapterAddresses,
                              uint32_t *SizePointer);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_MEMORY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » memory                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtNumaNoPreferredNode 0xffffffffu

COSMOPOLITAN_C_START_

void *LocalFree(void *hMem);

int64_t CreateFileMapping(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName);
int64_t CreateFileMappingNuma(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName, uint32_t nndDesiredNumaNode);

void *MapViewOfFileEx(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                      uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                      size_t dwNumberOfBytesToMap,
                      void *opt_lpDesiredBaseAddress);
void *MapViewOfFileExNuma(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                          uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                          size_t dwNumberOfBytesToMap,
                          void *opt_lpDesiredBaseAddress,
                          uint32_t nndDesiredNumaNode);

bool32 UnmapViewOfFile(const void *lpBaseAddress);
bool32 FlushViewOfFile(const void *lpBaseAddress,
                       size_t dwNumberOfBytesToFlush);

void *VirtualAlloc(void *opt_lpAddress, uint64_t dwSize,
                   uint32_t flAllocationType, uint32_t flProtect);
bool32 VirtualFree(void *lpAddress, uint64_t dwSize, uint32_t dwFreeType);
bool32 VirtualProtect(void *lpAddress, uint64_t dwSize, uint32_t flNewProtect,
                      uint32_t *lpflOldProtect) paramsnonnull();
bool32 VirtualLock(const void *lpAddress, size_t dwSize);
bool32 VirtualUnlock(const void *lpAddress, size_t dwSize);
uint64_t VirtualQuery(const void *lpAddress,
                      struct NtMemoryBasicInformation *lpBuffer,
                      uint64_t dwLength);
void *VirtualAllocEx(int64_t hProcess, void *lpAddress, uint64_t dwSize,
                     uint32_t flAllocationType, uint32_t flProtect);

int64_t GetProcessHeap(void);
void *HeapAlloc(int64_t hHeap, uint32_t dwFlags, size_t dwBytes) __wur;
bool32 HeapFree(int64_t hHeap, uint32_t dwFlags, void *opt_lpMem);
void *HeapReAlloc(int64_t hHeap, uint32_t dwFlags, void *lpMem,
                  size_t dwBytes) __wur;

void *GlobalAlloc(uint32_t uFlags, uint64_t dwBytes) __wur;
void *GlobalFree(void *hMem);

/**
 * @param AllocationType
 *     - kNtMemReserve
 *     - kNtMemReplacePlaceholder
 *     - kNtMemLargePages
 */
void *MapViewOfFile3(
    intptr_t FileMapping, intptr_t Process, void *opt_BaseAddress,
    uint64_t Offset, size_t ViewSize, unsigned AllocationType,
    unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

void *VirtualAlloc2(
    intptr_t opt_Process, void *opt_BaseAddress, size_t Size,
    unsigned AllocationType, unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/memory.inc */

extern typeof(LocalFree) *const __imp_LocalFree __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/messagebox.h */

#define COSMOPOLITAN_LIBC_NT_MESSAGEBOX_H_
COSMOPOLITAN_C_START_

int MessageBox(int64_t hWnd, const char16_t *lpText, const char16_t *lpCaption,
               uint32_t mbType);
int MessageBoxEx(int64_t hWnd, const char16_t *lpText,
                 const char16_t *lpCaption, uint32_t mbType,
                 uint16_t wLanguageId);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdll.h */

#define COSMOPOLITAN_LIBC_NT_NTDLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

#define __nt_system_call_dispatcher (wambda *)0x7ffe0308

extern const struct NtUnicodeString *const RtlNtdllName;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » eponymous runtime      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define NT_PROCESS_FLAGS_CREATE_SUSPENDED 0x00000001
#define NT_PROCESS_FLAGS_INHERIT_HANDLES  0x00000002
#define NT_PROCESS_FLAGS_NO_SYNCHRONIZE   0x00000004
#define NT_RTL_CLONE_PARENT               0
#define NT_RTL_CLONE_CHILD                297

NtStatus NtCallbackReturn(void *opt_Result, uint32_t ResultLength,
                          int32_t Status);
NtStatus NtTestAlert(void);

NtStatus NtOpenFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                    struct NtObjectAttributes *ObjectAttributes,
                    struct NtIoStatusBlock *out_IoStatusBlock,
                    uint32_t ShareAccess, uint32_t OpenOptions);

NtStatus NtQueryInformationToken(int64_t TokenHandle,
                                 uint32_t TokenInformationClass,
                                 void *out_TokenInformation,
                                 uint32_t TokenInformationLength,
                                 uint32_t *out_ReturnLength);
NtStatus NtYieldExecution(void);
NtStatus NtQuerySystemInformation(uint32_t info_class, void *out_info,
                                  uint32_t info_size,
                                  uint32_t *out_bytes_received);
NtStatus NtReadVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                             void *out_Buffer, size_t BufferLength,
                             size_t *opt_out_ReturnLength);
NtStatus NtCreateTimer(void **out_TimerHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       uint32_t TimerType);
NtStatus NtSetTimer(void *TimerHandle, int64_t *DueTime, void *TimerApcRoutine,
                    void *TimerContext, int32_t Resume, int32_t Period,
                    int32_t *out_PreviousState);
NtStatus NtQueryObject(void *ObjectHandle, int ObjectInformationClass,
                       void *out_ObjectInformation,
                       uint32_t ObjectInformationLength,
                       uint32_t *opt_out_ReturnLength);
NtStatus NtQueryFullAttributesFile(
    struct NtObjectAttributes *attributes,
    struct NtFileNetworkOpenInformation *out_info);
NtStatus NtCreateKey(void **out_KeyHandle, uint32_t DesiredAccess,
                     struct NtObjectAttributes *ObjectAttributes,
                     uint32_t TitleIndex, struct NtUnicodeString *opt_Class,
                     uint32_t CreateOptions, uint32_t *opt_out_Disposition);
NtStatus NtOpenKey(void **out_KeyHandle, uint32_t DesiredAccess,
                   struct NtObjectAttributes *ObjectAttributes);
NtStatus NtSetValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                       uint32_t opt_TitleIndex, uint32_t Type, void *Data,
                       uint32_t DataSize);
NtStatus NtDeleteKey(void *KeyHandle);
NtStatus NtQueryValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                         int KeyValueInformationClass,
                         void *out_KeyValueInformation, uint32_t Length,
                         uint32_t *out_ResultLength);
NtStatus NtFlushKey(void *KeyHandle);
NtStatus NtEnumerateKey(int64_t hkey, uint32_t index, int info_class,
                        void *out_key_info, uint32_t key_info_size,
                        uint32_t *out_bytes_received);
NtStatus NtEnumerateValueKey(int64_t hKey, uint32_t index, int info_class,
                             void *out_key_info, uint32_t key_info_size,
                             uint32_t *out_bytes_received);
NtStatus NtQuerySystemTime(int64_t *SystemTime);
NtStatus NtDeleteFile(struct NtObjectAttributes *ObjectAttributes);
NtStatus NtFlushBuffersFile(int64_t FileHandle,
                            struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateIoCompletion(void **out_IoCompletionHandle,
                              uint32_t DesiredAccess,
                              struct NtObjectAttributes *ObjectAttributes,
                              uint32_t NumberOfConcurrentThreads);
NtStatus NtRaiseHardError(int32_t ErrorStatus, uint32_t NumberOfArguments,
                          uint32_t UnicodeStringArgumentsMask, void *Arguments,
                          uint32_t MessageBoxType,
                          uint32_t *out_MessageBoxResult);
NtStatus NtRaiseException(struct NtExceptionRecord *ExceptionRecord,
                          struct NtContext *Context, int32_t SearchFrames);
NtStatus NtCreateEvent(void **out_EventHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       int EventType, int32_t InitialState);
NtStatus NtWaitForSingleObject(void *ObjectHandle, int32_t Alertable,
                               int64_t *TimeOut);
NtStatus NtSetEvent(void *EventHandle, int32_t *opt_out_PreviousState);
NtStatus NtClearEvent(void *EventHandle);
NtStatus NtSignalAndWaitForSingleObject(void *ObjectToSignal,
                                        void *WaitableObject, int32_t Alertable,
                                        int64_t *opt_Time);
NtStatus NtQueryPerformanceCounter(int64_t *out_PerformanceCount,
                                   int64_t *opt_out_PerformanceFrequency);
NtStatus NtFsControlFile(int64_t FileHandle, void *opt_Event,
                         NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                         struct NtIoStatusBlock *out_IoStatusBlock,
                         uint32_t FsControlCode, void *opt_InputBuffer,
                         uint32_t InputBufferLength, void *opt_out_OutputBuffer,
                         uint32_t OutputBufferLength);
NtStatus NtCancelIoFile(int64_t FileHandle,
                        struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateProfile(void **out_ProfileHandle, int64_t ProcessHandle,
                         void *Base, uint32_t Size, uint32_t BucketShift,
                         uint32_t *Buffer, uint32_t BufferLength, int Source,
                         uint32_t ProcessorMask);
NtStatus NtSetIntervalProfile(uint32_t Interval, int Source);
NtStatus NtQueryIntervalProfile(int Source, uint32_t *out_Interval);
NtStatus NtStartProfile(void *ProfileHandle);
NtStatus NtStopProfile(void *ProfileHandle);
NtStatus NtCreateDirectoryObject(int64_t *out_DirectoryHandle,
                                 uint32_t DesiredAccess,
                                 struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenDirectoryObject(int64_t *out_DirectoryHandle,
                               uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenSymbolicLinkObject(int64_t *out_DirectoryHandle,
                                  uint32_t DesiredAccess,
                                  struct NtObjectAttributes *ObjectAttributes);
NtStatus NtQuerySymbolicLinkObject(int64_t DirectoryHandle,
                                   struct NtUnicodeString *inout_TargetName,
                                   uint32_t *opt_out_ReturnLength);
NtStatus ZwAreMappedFilesTheSame(void *Address1, void *Address2);
NtStatus NtQueryVolumeInformationFile(int64_t FileHandle,
                                      struct NtIoStatusBlock *out_IoStatusBlock,
                                      void *out_FsInformation, uint32_t Length,
                                      uint32_t FsInformationClass);
NtStatus NtQuerySecurityObject(
    int64_t handle, int RequestedInformation,
    struct NtSecurityDescriptor *out_SecurityDescriptor,
    uint32_t SecurityDescriptorLength, uint32_t *out_ReturnLength);
NtStatus NtQueueApcThread(int64_t ThreadHandle, NtPkNormalRoutine ApcRoutine,
                          void *opt_ApcContext, void *opt_Argument1,
                          void *opt_Argument2);
NtStatus NtFlushInstructionCache(int64_t ProcessHandle, void *opt_BaseAddress,
                                 size_t FlushSize);
NtStatus NtQueryAttributesFile(const struct NtObjectAttributes *object,
                               struct NtFileBasicInformation *file_information);
NtStatus NtQueryDirectoryFile(
    int64_t FileHandle, void *opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    void *out_FileInformation, uint32_t FileInformationLength,
    uint32_t FileInformationClass, int32_t ReturnSingleEntry,
    struct NtUnicodeString *opt_FileName, int32_t RestartScan);
NtStatus NtFlushVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                              uint32_t **inout_FlushSize,
                              struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtQueryInformationJobObject(void *JobHandle, int JobInformationClass,
                                     void *out_JobInformation,
                                     uint32_t JobInformationLength,
                                     uint32_t *opt_out_ReturnLength);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » runtime library        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

NtStatus RtlInitializeCriticalSection(struct NtCriticalSection *out_crit);
NtStatus RtlDeleteCriticalSection(struct NtCriticalSection *crit);
NtStatus RtlEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlLeaveCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlTryEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlInitUnicodeString(struct NtUnicodeString *inout_DestinationString,
                              const char16_t *SourceString);
void RtlFreeUnicodeString(struct NtUnicodeString **string);
NtStatus RtlQueryEnvironmentVariable_U(char16_t *Environment,
                                       struct NtUnicodeString *Name,
                                       struct NtUnicodeString *Value);
NtStatus RtlConvertSidToUnicodeString(struct NtUnicodeString *out_UnicodeString,
                                      void *Sid,
                                      int32_t AllocateDestinationString);
void *RtlCreateHeap(uint32_t flags, void *base, size_t reserve_sz,
                    size_t commit_sz, void *lock, void *params);
NtStatus RtlDestroyHeap(void *base);
void *RtlAllocateHeap(int64_t heap, uint32_t flags, size_t size);
void *RtlReAllocateHeap(int64_t heap, uint32_t flags, void *ptr, size_t size);
NtStatus RtlFreeHeap(int64_t heap, uint32_t flags, void *ptr);
size_t RtlSizeHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlValidateHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlLockHeap(int64_t heap);
NtStatus RtlUnlockHeap(int64_t heap);
NtStatus RtlGetProcessHeaps(uint32_t count, void **out_Heaps);
NtStatus RtlWalkHeap(int64_t heap, void *out_Info);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntdll.inc */

#define NtYieldExecution(...) __imp_NtYieldExecution(__VA_ARGS__)

extern typeof(NtYieldExecution) *const __imp_NtYieldExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdllimport.h */

/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8     -*-│
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8                                 :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney                              │
│                                                                              │
│ Permission to use, copy, modify, and/or distribute this software for         │
│ any purpose with or without fee is hereby granted, provided that the         │
│ above copyright notice and this permission notice appear in all copies.      │
│                                                                              │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             │
│ PERFORMANCE OF THIS SOFTWARE.                                                │
╚─────────────────────────────────────────────────────────────────────────────*/
#define COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_
#ifdef __ASSEMBLER__
/* clang-format off */

.macro	.ntimp	fn:req name:req
#ifdef __x86_64__
	.yoink	_init_ntdll
	.initbss 202,_init_ntdll.\fn
__imp_\fn:
	.quad	0
	.endobj	__imp_\fn,globl,hidden
	.previous
	.initro 202,_init_ntdll.2.\fn
	.quad	RVA(.L\fn)
	.previous
	.section .rodata.str1.1,"aSM",@progbits,1
.L\fn:
	.asciz	"\fn"
	.previous
#elif defined(__aarch64__)
	.section .data.nt.\fn,"aw",@progbits
	.globl	__imp_\fn
	.balign	8
__imp_\fn:
	.quad	\name
	.weak	\name
#endif
.endm

/* clang-format on */
#endif /* __ASSEMBLER__ */


/*!BEGIN libc/nt/paint.h */

#define COSMOPOLITAN_LIBC_NT_PAINT_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » cpu graphics                             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t BeginPaint(int64_t hWnd, struct NtPaintStruct *lpPaint);
int32_t EndPaint(int64_t hWnd, const struct NtPaintStruct *lpPaint);
int32_t BitBlt(int64_t hdc, int x, int y, int cx, int cy, int64_t hdcSrc,
               int x1, int y1, uint32_t rop);
int32_t GetClientRect(int64_t hWnd, struct NtRect *lpRect);
int32_t GetWindowRect(int64_t hWnd, struct NtRect *lpRect);
int32_t SetBkMode(int64_t hdc, int mode);
uint32_t SetTextColor(int64_t hdc, uint32_t color);
uint32_t SetTextAlign(int64_t hdc, uint32_t align);
int32_t SetTextJustification(int64_t hdc, int extra, int count);
int32_t DrawText(int64_t hdc, const char16_t *lpchText, int cchText,
                 struct NtRect *lprc, uint32_t format);
int32_t DrawTextEx(int64_t hdc, char16_t *lpchText, int cchText,
                   struct NtRect *lprc, uint32_t format,
                   struct NtDrawTextParams *lpdtp);
int32_t FillRect(int64_t hDC, const struct NtRect *lpRC, int64_t hBrush);
uint32_t GetPixel(int64_t hdc, int x, int y);
uint32_t SetPixel(int64_t hdc, int x, int y, uint32_t color);
bool32 RedrawWindow(int64_t hWnd, const struct NtRect *opt_lprcUpdate,
                    int64_t opt_hrgnUpdate, uint32_t rdwFlags);
int64_t CreateCompatibleDC(int64_t hdc);
int64_t CreateCompatibleBitmap(int64_t hdc, int cx, int cy);
int64_t SelectObject(int64_t hdc, int64_t h);
bool32 DeleteObject(int64_t ho);
bool32 DeleteDC(int64_t hdc);
int SaveDC(int64_t hdc);
bool32 RestoreDC(int64_t hdc, int nSavedDC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/paint.inc */

#define SetPixel(...) __imp_SetPixel(__VA_ARGS__)
#define GetPixel(...) __imp_GetPixel(__VA_ARGS__)

extern typeof(SetPixel) *const __imp_SetPixel __msabi;
extern typeof(GetPixel) *const __imp_GetPixel __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/pdh.h */

#define COSMOPOLITAN_LIBC_NT_PDH_H_

/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » performance counters                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int PdhOpenQuery(const char16_t *opt_szDataSource, uint32_t *dwUserData,
                 int64_t *out_phQuery);

int PdhAddEnglishCounter(int64_t hQuery, const char16_t *szFullCounterPath,
                         uint32_t *dwUserData, int64_t *out_phCounter);

int PdhCollectQueryDataEx(int64_t hQuery, uint32_t dwIntervalTime,
                          int64_t hNewDataEvent);

int PdhGetFormattedCounterValue(int64_t hCounter, uint32_t dwFormat,
                                uint32_t *out_opt_lpdwType,
                                struct NtPdhFmtCountervalue *out_pValue);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/privilege.h */

#define COSMOPOLITAN_LIBC_NT_PRIVILEGE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » check your privilege                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtSePrivilegeEnabledByDefault 0x00000001u
#define kNtSePrivilegeEnabled          0x00000002u
#define kNtSePrivilegeRemoved          0x00000004u
#define kNtSePrivilegeUsedForAccess    0x80000000u

COSMOPOLITAN_C_START_

bool32 LookupPrivilegeValue(const char16_t *opt_lpSystemName,
                            const char16_t *lpName, struct NtLuid *out_lpLuid);

bool32 AdjustTokenPrivileges(int64_t TokenHandle, bool32 DisableAllPrivileges,
                             const struct NtTokenPrivileges *opt_NewState,
                             uint32_t BufferLength,
                             struct NtTokenPrivileges *opt_out_PreviousState,
                             uint32_t *opt_out_ReturnLength);

bool32 ImpersonateSelf(int kNtSecurityImpersonationLevel);
bool32 RevertToSelf(void);

bool32 OpenThreadToken(intptr_t ThreadHandle, uint32_t DesiredAccess,
                       bool32 OpenAsSelf, intptr_t *TokenHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_PROCESS_H_


/*!BEGIN libc/nt/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_NTSTARTUPINFO_H_
COSMOPOLITAN_C_START_

#define kNtProcThreadAttributeParentProcess 0x00020000
#define kNtProcThreadAttributeHandleList    0x00020002

void GetStartupInfo(struct NtStartupInfo *lpStartupInfo);

bool32 InitializeProcThreadAttributeList(
    struct NtProcThreadAttributeList *opt_inout_lpAttributeList,
    uint32_t dwAttributeCount, uint32_t reserved_dwFlags, size_t *inout_lpSize);
bool32 UpdateProcThreadAttribute(
    struct NtProcThreadAttributeList *inout_lpAttributeList, uint32_t dwFlags,
    uint64_t Attribute, const void *lpValue, size_t cbSize,
    void *reserved_lpPreviousValue, size_t *reserved_lpReturnSize);
void DeleteProcThreadAttributeList(
    struct NtProcThreadAttributeList *inout_lpAttributeList);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/startupinfo.inc */

#define GetStartupInfo(...) __imp_GetStartupInfoW(__VA_ARGS__)

extern typeof(GetStartupInfo) *const __imp_GetStartupInfoW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » processes                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 CreateProcess(const char16_t *opt_lpApplicationName,
                     char16_t *lpCommandLine,
                     const struct NtSecurityAttributes *opt_lpProcessAttributes,
                     const struct NtSecurityAttributes *opt_lpThreadAttributes,
                     bool32 bInheritHandles, uint32_t dwCreationFlags,
                     void *opt_lpEnvironment,
                     const char16_t *opt_lpCurrentDirectory,
                     const struct NtStartupInfo *lpStartupInfo,
                     struct NtProcessInformation *opt_out_lpProcessInformation)
    paramsnonnull((9));

uint32_t GetThreadId(int64_t hThread);   /* cf. NT_TID */
uint32_t GetProcessId(int64_t hProcess); /* cf. NT_PID */
void SetLastError(uint32_t dwErrCode);
uint32_t FormatMessage(uint32_t dwFlags, const void *lpSource,
                       uint32_t dwMessageId, uint32_t dwLanguageId,
                       char16_t *lpBuffer, uint32_t nSize, va_list *Arguments);
uint32_t FormatMessageA(uint32_t dwFlags, const void *lpSource,
                        uint32_t dwMessageId, uint32_t dwLanguageId,
                        char *lpBuffer, uint32_t nSize, va_list *Arguments);
int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                    uint32_t dwProcessId);
uint32_t GetCurrentProcessId(void); /* %gs:0x40 */
uint32_t GetEnvironmentVariable(const char16_t *lpName, char16_t *lpBuffer,
                                uint32_t nSize);
uint32_t SetEnvironmentVariable(const char16_t *lpName,
                                const char16_t *lpValue);
int32_t SetEnvironmentStrings(char16_t *NewEnvironment);
bool32 GetProcessAffinityMask(int64_t hProcess, uint64_t *lpProcessAffinityMask,
                              uint64_t *lpSystemAffinityMask);
uint64_t /*bool32*/ SetProcessAffinityMask(int64_t hProcess,
                                           uint64_t dwProcessAffinityMask);

/* e.g. kNtAboveNormalPriorityClass, kNtHighPriorityClass */
uint32_t GetPriorityClass(int64_t hProcess);
bool32 SetPriorityClass(int64_t hProcess, uint32_t dwPriorityClass);
bool32 SetProcessPriorityBoost(int64_t hProcess, bool32 bDisablePriorityBoost);
bool32 GetProcessPriorityBoost(int64_t hProcess, bool32 *pDisablePriorityBoost);

bool32 GetProcessMemoryInfo(
    int64_t hProcess, struct NtProcessMemoryCountersEx *out_ppsmemCounters,
    uint32_t cb);

int64_t CreateToolhelp32Snapshot(uint32_t dwFlags, uint32_t th32ProcessID);
bool32 Process32First(int64_t hSnapshot, struct NtProcessEntry32 *in_out_lppe);
bool32 Process32Next(int64_t hSnapshot, struct NtProcessEntry32 *out_lppe);

bool32 EnumProcesses(uint32_t *out_lpidProcess, uint32_t cb,
                     uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModules(int64_t hProcess, int64_t *out_lphModule, uint32_t cb,
                          uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModulesEx(int64_t hProcess, int64_t *out_lphModule,
                            uint32_t cb, uint32_t *out_lpcbNeeded,
                            uint32_t dwFilterFlag) paramsnonnull();
uint32_t GetModuleBaseName(int64_t hProcess, int64_t opt_hModule,
                           char16_t *out_lpBaseName, uint32_t nSize)
    paramsnonnull();

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/process.inc */

#define GetEnvironmentVariable(...) __imp_GetEnvironmentVariableW(__VA_ARGS__)
extern typeof(GetEnvironmentVariable) *const __imp_GetEnvironmentVariableW
    __msabi;

#define SetEnvironmentVariable(...) __imp_SetEnvironmentVariableW(__VA_ARGS__)
extern typeof(SetEnvironmentVariable) *const __imp_SetEnvironmentVariableW
    __msabi;

#define GetPriorityClass(...) __imp_GetPriorityClass(__VA_ARGS__)
extern typeof(GetPriorityClass) *const __imp_GetPriorityClass __msabi;

#define SetPriorityClass(...) __imp_SetPriorityClass(__VA_ARGS__)
extern typeof(SetPriorityClass) *const __imp_SetPriorityClass __msabi;

#define GetCurrentProcessId(...) __imp_GetCurrentProcessId(__VA_ARGS__)
extern typeof(GetCurrentProcessId) *const __imp_GetCurrentProcessId __msabi;

extern typeof(FormatMessage) *const __imp_FormatMessageW __msabi;
extern typeof(SetLastError) *const __imp_SetLastError __msabi;
extern typeof(FormatMessage) *const __imp_FormatMessage __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/registry.h */

#define COSMOPOLITAN_LIBC_NT_REGISTRY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » registry                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtMaxKeyNameChars   255
#define kNtMaxValueNameChars 16383
#define kNtMaxValueBytes     0x100000

#define kNtHkeyClassesRoot              0x80000000l
#define kNtHkeyCurrentUser              0x80000001l
#define kNtHkeyLocalMachine             0x80000002l
#define kNtHkeyUsers                    0x80000003l
#define kNtHkeyPerformanceData          0x80000004l
#define kNtHkeyPerformanceText          0x80000050l
#define kNtHkeyPerformanceNlstext       0x80000060l
#define kNtHkeyCurrentConfig            0x80000005l
#define kNtHkeyDynData                  0x80000006l
#define kNtHkeyCurrentUserLocalSettings 0x80000007l

COSMOPOLITAN_C_START_

int RegOpenKey(int64_t hKey, const char16_t *opt_lpSubKey,
               int64_t *out_phkResult) paramsnonnull((3));
int RegOpenKeyEx(int64_t hKey, const char16_t *opt_lpSubKey,
                 uint32_t opt_ulOptions, int samDesired, int64_t *out_phkResult)
    paramsnonnull((5));
int RegCloseKey(int64_t hKey);

int RegGetValue(int64_t hkey, const char16_t *opt_lpSubKey,
                const char16_t *opt_lpValue, unsigned dwFlags, int *opt_pdwType,
                void *opt_out_pvData, uint32_t *opt_inout_pcbDataBytes);
int RegSetValue(int64_t hKey, const char16_t *lpSubKey, int dwType,
                const char16_t *lpData, uint32_t cbData);
int RegSetValueEx(int64_t hKey, const char16_t *lpValueName, uint32_t Reserved,
                  int dwType, const unsigned char *lpData, uint32_t cbData);

int RegQueryInfoKey(int64_t hKey, char16_t *opt_out_lpClass,
                    uint32_t *opt_inout_lpClassLen, uint32_t *lpReserved,
                    uint32_t *opt_out_lpcSubKeys,
                    uint32_t *opt_out_lpcbMaxSubKeyBytes,
                    uint32_t *opt_out_lpcbMaxClassBytes,
                    uint32_t *opt_out_lpcValues,
                    uint32_t *opt_out_lpcbMaxValueNameBytes,
                    uint32_t *opt_out_lpcbMaxValueBytes,
                    uint32_t *opt_out_lpcbSecurityDescriptorBytes,
                    struct NtFileTime *opt_out_lpftLastWriteTime);
int RegEnumKey(int64_t hKey, uint32_t dwIndex, char16_t *opt_lpName,
               uint32_t NameLen);
int RegEnumKeyEx(int64_t hKey, uint32_t dwIndex, char16_t *out_lpName,
                 uint32_t *inout_lpcchName, uint32_t *lpReserved,
                 char16_t *opt_out_lpClass, uint32_t *opt_inout_lpcchClassLen,
                 struct NtFileTime *opt_out_lpftLastWriteTime);

int RegEnumValue(int64_t hKey, uint32_t dwIndex, char16_t *lpValueName,
                 uint32_t *lpValueNameLen, uint32_t *lpReserved,
                 int *opt_out_lpType, unsigned char *opt_out_lpData,
                 uint32_t *opt_inout_lpcbDataBytes);
int RegQueryValue(int64_t hKey, const char16_t *opt_lpSubKey,
                  char16_t *opt_out_lpData, int32_t *opt_inout_lpcbDataBytes);
int RegQueryValueEx(int64_t hKey, const char16_t *opt_lpValueName,
                    uint32_t *lpReserved, int *opt_out_lpType,
                    unsigned char *opt_out_lpData,
                    uint32_t *opt_inout_lpcbDataBytes);

int RegOverridePredefKey(int64_t hKey, int64_t hNewHKey);
int RegOpenUserClassesRoot(void *hToken, uint32_t dwOptions, int samDesired,
                           int64_t *phkResult);
int RegOpenCurrentUser(int samDesired, int64_t *phkResult);
int RegDisablePredefinedCache();
int RegConnectRegistry(const char16_t *lpMachineName, int64_t hKey,
                       int64_t *phkResult);
int RegConnectRegistryEx(const char16_t *lpMachineName, int64_t hKey,
                         uint32_t Flags, int64_t *phkResult);
int RegCreateKey(int64_t hKey, const char16_t *lpSubKey, int64_t *phkResult);
int RegCreateKeyEx(int64_t hKey, const char16_t *lpSubKey, uint32_t Reserved,
                   int16_t *lpClass, uint32_t dwOptions, int samDesired,
                   const struct NtSecurityAttributes *lpSecurityAttributes,
                   int64_t *phkResult, uint32_t *lpdwDisposition);
int RegDeleteKey(int64_t hKey, const char16_t *lpSubKey);
int RegDeleteKeyEx(int64_t hKey, const char16_t *lpSubKey, int samDesired,
                   uint32_t Reserved);
int RegDeleteTree(int64_t hKey, const char16_t *opt_lpSubKey);
int RegDisableReflectionKey(int64_t hBase);
int RegEnableReflectionKey(int64_t hBase);
int RegQueryReflectionKey(int64_t hBase, bool32 *bIsReflectionDisabled);
int RegDeleteValue(int64_t hKey, const char16_t *lpValueName);
int RegFlushKey(int64_t hKey);
int RegGetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor,
                      uint32_t *lpcbSecurityDescriptorBytes);
int RegLoadKey(int64_t hKey, const char16_t *lpSubKey, const char16_t *lpFile);
int RegNotifyChangeKeyValue(int64_t hKey, bool32 bWatchSubtree,
                            uint32_t dwNotifyFilter, void *hEvent,
                            int fAsynchronous);
int RegQueryMultipleValues(int64_t hKey, struct NtValent *inout_val_list,
                           uint32_t num_vals, int16_t *out_lpValueBuf,
                           uint32_t *inout_ldwTotsize) paramsnonnull();
int RegReplaceKey(int64_t hKey, const char16_t *lpSubKey,
                  const char16_t *lpNewFile, const char16_t *lpOldFile);
int RegRestoreKey(int64_t hKey, const char16_t *lpFile, uint32_t dwFlags);
int RegSaveKey(int64_t hKey, const char16_t *lpFile,
               const struct NtSecurityAttributes *lpSecurityAttributes);
int RegSetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor);
int RegUnLoadKey(int64_t hKey, const char16_t *lpSubKey);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/runtime.h */

#define COSMOPOLITAN_LIBC_NT_RUNTIME_H_

/**
 * @fileoverview NT Obligatory Runtime Functions.
 *
 * These functions are placed in their own file because they're (a)
 * abstracted by the Cosmopolitan runtime; and (b) it helps GCC avoid
 * bloating binaries with debug information the user doesn't need.
 */

#define kNtCpUtf8             65001
#define kNtInvalidHandleValue -1L
#define kNtStdInputHandle     -10u
#define kNtStdOutputHandle    -11u
#define kNtStdErrorHandle     -12u

#define GetCurrentProcess() -1

COSMOPOLITAN_C_START_

char16_t *GetCommandLine(void) nosideeffect;
char16_t *GetEnvironmentStrings(void) __wur;
bool32 FreeEnvironmentStrings(char16_t *) paramsnonnull();
bool32 ReadFile(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                uint32_t *lpNumberOfBytesRead,
                struct NtOverlapped *opt_lpOverlapped);
bool32 WriteFile(int64_t hFile, const void *lpBuffer,
                 uint32_t nNumberOfBytesToWrite,
                 uint32_t *lpNumberOfBytesWritten,
                 struct NtOverlapped *opt_lpOverlapped);
bool32 TerminateProcess(int64_t hProcess, uint32_t uExitCode);
void TerminateThisProcess(uint32_t dwWaitStatus) wontreturn;
void ExitProcess(uint32_t uExitCode) wontreturn;
uint32_t GetLastError(void) nosideeffect;
bool32 CloseHandle(int64_t hObject) dontthrow dontcallback;
intptr_t GetStdHandle(uint32_t nStdHandle) nosideeffect;
bool32 SetStdHandle(uint32_t nStdHandle, int64_t hHandle);
bool32 SetDefaultDllDirectories(unsigned dirflags);
bool32 ProcessPrng(void *RandomBuffer, uint32_t RandomBufferLength);
uint32_t GetModuleFileName(int64_t hModule, char16_t *lpFilename,
                           uint32_t nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/runtime.inc */

#define FreeEnvironmentStrings(...) __imp_FreeEnvironmentStringsW(__VA_ARGS__)
extern typeof(FreeEnvironmentStrings) *const __imp_FreeEnvironmentStringsW
    __msabi;

#define GetCommandLine(...) __imp_GetCommandLineW(__VA_ARGS__)
extern typeof(GetCommandLine) *const __imp_GetCommandLineW __msabi;

#define GetEnvironmentStrings(...) __imp_GetEnvironmentStringsW(__VA_ARGS__)
extern typeof(GetEnvironmentStrings) *const __imp_GetEnvironmentStringsW
    __msabi;

#define GetStdHandle(...) __imp_GetStdHandle(__VA_ARGS__)
extern typeof(GetStdHandle) *const __imp_GetStdHandle __msabi;

#define SetStdHandle(...) __imp_SetStdHandle(__VA_ARGS__)
extern typeof(SetStdHandle) *const __imp_SetStdHandle __msabi;

#define ReadFile(...) __imp_ReadFile(__VA_ARGS__)
extern typeof(ReadFile) *const __imp_ReadFile __msabi;

#define WriteFile(...) __imp_WriteFile(__VA_ARGS__)
extern typeof(WriteFile) *const __imp_WriteFile __msabi;

#define SetDefaultDllDirectories(...) \
  __imp_SetDefaultDllDirectories(__VA_ARGS__)
extern typeof(SetDefaultDllDirectories) *const __imp_SetDefaultDllDirectories
    __msabi;

#define GetModuleFileName(...) __imp_GetModuleFileNameW(__VA_ARGS__)
extern typeof(GetModuleFileName) *const __imp_GetModuleFileNameW __msabi;

extern typeof(GetLastError) *const __imp_GetLastError __msabi;
extern typeof(ExitProcess) *const __imp_ExitProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/signals.h */

#define COSMOPOLITAN_LIBC_NT_EXCEPTIONS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » signals                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

typedef int (*NtTopLevelExceptionFilter)(const struct NtExceptionPointers *);
typedef int32_t (*NtVectoredExceptionHandler)(struct NtExceptionPointers *);

int SetErrorMode(int uMode);

int64_t AddVectoredExceptionHandler(uint32_t First,
                                    NtVectoredExceptionHandler pHandler);
int64_t AddVectoredContinueHandler(uint32_t First,
                                   NtVectoredExceptionHandler pHandler);

uint32_t RemoveVectoredExceptionHandler(int64_t hHandle);
uint32_t RemoveVectoredContinueHandler(int64_t hHandle);

NtTopLevelExceptionFilter SetUnhandledExceptionFilter(
    NtTopLevelExceptionFilter opt_lpTopLevelExceptionFilter);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/signals.inc */

#define SetErrorMode(...) __imp_SetErrorMode(__VA_ARGS__)
#define AddVectoredExceptionHandler(...) \
  __imp_AddVectoredExceptionHandler(__VA_ARGS__)
#define AddVectoredContinueHandler(...) \
  __imp_AddVectoredContinueHandler(__VA_ARGS__)
#define RemoveVectoredExceptionHandler(...) \
  __imp_RemoveVectoredExceptionHandler(__VA_ARGS__)
#define RemoveVectoredContinueHandler(...) \
  __imp_RemoveVectoredContinueHandler(__VA_ARGS__)
#define SetUnhandledExceptionFilter(...) \
  __imp_SetUnhandledExceptionFilter(__VA_ARGS__)

extern typeof(SetErrorMode) *const __imp_SetErrorMode __msabi;
extern typeof(AddVectoredExceptionHandler) *const
    __imp_AddVectoredExceptionHandler __msabi;
extern typeof(AddVectoredContinueHandler) *const
    __imp_AddVectoredContinueHandler __msabi;
extern typeof(RemoveVectoredExceptionHandler) *const
    __imp_RemoveVectoredExceptionHandler __msabi;
extern typeof(RemoveVectoredContinueHandler) *const
    __imp_RemoveVectoredContinueHandler __msabi;
extern typeof(SetUnhandledExceptionFilter) *const
    __imp_SetUnhandledExceptionFilter __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/synchronization.h */

#define COSMOPOLITAN_LIBC_NT_SYNCHRONIZATION_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » synchronization                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

static inline int32_t InterlockedAdd(int32_t volatile *p, int32_t x) {
  return atomic_fetch_add((_Atomic(int32_t) *)p, x) + x;
}

static inline int32_t InterlockedExchange(int32_t volatile *p, int32_t x) {
  return atomic_exchange((_Atomic(int32_t) *)p, x);
}

typedef void (*NtTimerapcroutine)(void *lpArgToCompletionRoutine,
                                  uint32_t dwTimerLowValue,
                                  uint32_t dwTimerHighValue);
typedef void (*NtWaitOrTimerCallback)(void *lpParameter,
                                      bool32 TimerOrWaitFired);

void WakeByAddressAll(void *Address);
void WakeByAddressSingle(void *Address);
bool32 WaitOnAddress(const volatile void *Address, void *CompareAddress,
                     size_t AddressSize, uint32_t opt_dwMilliseconds);

void Sleep(uint32_t dwMilliseconds);
uint32_t SleepEx(uint32_t dwMilliseconds, bool32 bAlertable);

void GetSystemTime(struct NtSystemTime *lpSystemTime);
bool32 SystemTimeToFileTime(const struct NtSystemTime *lpSystemTime,
                            struct NtFileTime *lpFileTime);
void GetSystemTimeAsFileTime(struct NtFileTime *);
void GetSystemTimePreciseAsFileTime(struct NtFileTime *); /* win8+ */

uint32_t WaitForSingleObject(int64_t hHandle, uint32_t dwMilliseconds);
uint32_t WaitForMultipleObjects(uint32_t nCount, const int64_t *lpHandles,
                                bool32 bWaitAll, uint32_t dwMilliseconds);
uint32_t WaitForSingleObjectEx(int64_t hHandle, uint32_t dwMilliseconds,
                               bool32 bAlertable);
uint32_t WaitForMultipleObjectsEx(unsigned int nCount, const int64_t *lpHandles,
                                  bool32 bWaitAll, uint32_t dwMilliseconds,
                                  bool32 bAlertable);
bool32 RegisterWaitForSingleObject(int64_t *phNewWaitObject, int64_t hObject,
                                   NtWaitOrTimerCallback Callback,
                                   void *Context, uint32_t dwMilliseconds,
                                   uint32_t dwFlags);

int64_t CreateWaitableTimer(
    const struct NtSecurityAttributes *lpTimerAttributes, bool32 bManualReset,
    const char16_t *lpTimerName);
bool32 SetWaitableTimer(int64_t hTimer, const int64_t *lpDueTimeAsFtOrNegRela,
                        int32_t opt_lPeriodMs, NtTimerapcroutine opt_callback,
                        void *lpArgToCallback, bool32 fUnsleepSystem);

int64_t CreateSemaphore(
    const struct NtSecurityAttributes *opt_lpSemaphoreAttributes,
    uint32_t lInitialCount, uint32_t lMaximumCount, const char16_t *opt_lpName);

int32_t ReleaseMutex(int64_t hMutex);
int32_t ReleaseSemaphore(int64_t hSemaphore, int32_t lReleaseCount,
                         int *lpPreviousCount);

void InitializeCriticalSection(struct NtCriticalSection *lpCriticalSection);
void EnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void LeaveCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t TryEnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void DeleteCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t InitializeCriticalSectionAndSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);
uint32_t SetCriticalSectionSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);

void InitializeSRWLock(intptr_t *);
void AcquireSRWLockExclusive(intptr_t *);
void AcquireSRWLockShared(intptr_t *);
void ReleaseSRWLockExclusive(intptr_t *);
void ReleaseSRWLockShared(intptr_t *);
void TryAcquireSRWLockExclusive(intptr_t *);
void TryAcquireSRWLockShared(intptr_t *);

uint64_t GetTickCount64(void);

bool32 QueryPerformanceFrequency(uint64_t *lpFrequency);
bool32 QueryPerformanceCounter(uint64_t *lpPerformanceCount);
bool32 GetSystemTimeAdjustment(uint32_t *lpTimeAdjustment,
                               uint32_t *lpTimeIncrement,
                               bool32 *lpTimeAdjustmentDisabled);

void GetCurrentProcessorNumberEx(struct NtProcessorNumber *out_ProcNumber);

bool32 GetNumaProcessorNodeEx(const struct NtProcessorNumber *Processor,
                              unsigned short *out_NodeNumber);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/synchronization.inc */

extern typeof(SleepEx) *const __imp_SleepEx __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/system.h */

#define COSMOPOLITAN_LIBC_NT_SYSTEM_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » system control                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

bool32 SetSuspendState(bool32 bHibernate, bool32 bForce,
                       bool32 bWakeupEventsDisabled);

uint32_t InitiateShutdown(const char16_t *lpMachineName,
                          const char16_t *lpMessage, uint32_t dwGracePeriod,
                          uint32_t dwShutdownFlags, uint32_t dwReason);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_INFO_H_
COSMOPOLITAN_C_START_

void GetSystemInfo(struct NtSystemInfo *lpSystemInfo);
uint32_t GetSystemDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetSystemDirectoryA(char *lpBuffer, uint32_t uSize);
uint32_t GetWindowsDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetTempPath(uint32_t uSize, char16_t *lpBuffer);

bool32 GetComputerNameEx(/* enum/computernameformat.h */ int NameType,
                         char16_t *opt_lpBuffer, uint32_t *nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/systeminfo.inc */

#define GetSystemInfo(...) __imp_GetSystemInfo(__VA_ARGS__)
#define GetTempPath(...) __imp_GetTempPathW(__VA_ARGS__)

extern typeof(GetSystemInfo) *const __imp_GetSystemInfo __msabi;
extern typeof(GetTempPath) *const __imp_GetTempPathW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_THREADS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » threads                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t CreateThread(const struct NtSecurityAttributes *lpThreadAttributes,
                     size_t dwStackSize, void *lpStartAddress,
                     void *lpParameter, uint32_t dwCreationFlags,
                     uint32_t *opt_lpThreadId) paramsnonnull((3));

void ExitThread(uint32_t dwExitCode) wontreturn;
int64_t GetCurrentThread(void);
uint32_t GetCurrentThreadId(void);
uint64_t SetThreadAffinityMask(int64_t hThread, uintptr_t dwThreadAffinityMask);
int64_t OpenThread(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                   uint32_t dwThreadId);
bool32 TerminateThread(int64_t hThread, uint32_t dwExitCode);
bool32 GetExitCodeThread(int64_t hThread, uint32_t *lpExitCode);

/* e.g. kNtThreadPriorityAboveNormal, -1u on error */
uint32_t GetThreadPriority(int64_t hThread);
bool32 SetThreadPriority(int64_t hThread, int32_t nPriority);
bool32 SetThreadPriorityBoost(int64_t hThread, bool32 bDisablePriorityBoost);
bool32 GetThreadPriorityBoost(int64_t hThread, bool32 *pDisablePriorityBoost);
bool32 GetThreadIOPendingFlag(int64_t hThread, bool32 *lpIOIsPending);

bool32 CancelSynchronousIo(int64_t hThread);
bool32 CancelIo(int64_t hFile);
bool32 CancelIoEx(int64_t hFile, struct NtOverlapped *opt_lpOverlapped);

uint32_t TlsAlloc(void);
bool32 TlsFree(uint32_t);
bool32 TlsSetValue(uint32_t, void *);
void *TlsGetValue(uint32_t);

uint32_t SuspendThread(int64_t hThread);
uint32_t ResumeThread(int64_t hThread);
bool32 GetThreadContext(int64_t hThread, struct NtContext *in_out_lpContext);
bool32 SetThreadContext(int64_t hThread, const struct NtContext *lpContext);

void *SetThreadDescription(int64_t hThread,
                           const char16_t *lpThreadDescription);
void *GetThreadDescription(int64_t hThread,
                           char16_t *out_ppszThreadDescription);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/thread.inc */

#define GetCurrentThread(...)  __imp_GetCurrentThread(__VA_ARGS__)
#define GetThreadPriority(...) __imp_GetThreadPriority(__VA_ARGS__)
#define SetThreadPriority(...) __imp_SetThreadPriority(__VA_ARGS__)

extern typeof(GetCurrentThread) *const __imp_GetCurrentThread __msabi;
extern typeof(GetThreadPriority) *const __imp_GetThreadPriority __msabi;
extern typeof(SetThreadPriority) *const __imp_SetThreadPriority __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_TIME_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » time                                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetTimeZoneInformation(
    struct NtTimeZoneInformation *out_lpTimeZoneInformation);
uint32_t GetDynamicTimeZoneInformation(
    struct NtDynamicTimeZoneInformation *out_lpTimeZoneInformation);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/version.h */

#define COSMOPOLITAN_LIBC_NT_VERSION_H_
COSMOPOLITAN_C_START_

bool32 IsAtLeastWindows10(void) pureconst;
bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
#define GetNtMajorVersion()        \
  __extension__({                  \
    uintptr_t __x;                 \
    __asm__("mov\t%%gs:96,%q0\r\n" \
            "mov\t280(%q0),%b0"    \
            : "=q"(__x));          \
    (unsigned char)__x;            \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/windows.h */

#define COSMOPOLITAN_LIBC_NT_WINDOWS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » windows                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

int64_t CreateWindowEx(uint32_t dwExStyle, const char16_t *lpClassName,
                       const char16_t *lpWindowName, uint32_t dwStyle, int X,
                       int Y, int nWidth, int nHeight, int64_t hWndParent,
                       int64_t hMenu, int64_t hInstance, int64_t lpParam);

uint16_t RegisterClass(const struct NtWndClass *lpWndClass);

int64_t DefWindowProc(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                      int64_t lParam);

int32_t CloseWindow(int64_t hWnd);
int32_t DestroyWindow(int64_t hWnd);
int32_t ShowWindow(int64_t hWnd, int sw);
int32_t ShowCaret(bool32 bShow);
int32_t AnimateWindow(int64_t hWnd, uint32_t dwTime, uint32_t dwFlags);
int64_t LoadIcon(int64_t hInstance, const char16_t *lpIconName);
int32_t MoveWindow(int64_t hWnd, int X, int Y, int nWidth, int nHeight,
                   bool32 bRepaint);
int32_t BringWindowToTop(int64_t hWnd);
int32_t IsWindowVisible(int64_t hWnd);
int32_t SetWindowText(int64_t hWnd, const char16_t *lpString);
int32_t GetWindowText(int64_t hWnd, char16_t *lpString, int nMaxCount);
int32_t SetWindowPos(int64_t hWnd, int64_t hWndInsertAfter, int X, int Y,
                     int cx, int cy, uint32_t uFlags);
bool32 GetWindowPlacement(int64_t hWnd, struct NtWindowPlacement *lpwndpl);
bool32 SetWindowPlacement(int64_t hWnd,
                          const struct NtWindowPlacement *lpwndpl);

int64_t GetCursor(void);
int64_t SetCursor(int64_t hCursor);
int32_t ShowCursor(bool32 bShow);
int64_t LoadCursor(int64_t opt_hInstance, const char16_t *lpCursorNameOrIdc);

bool32 IsWindow(int64_t hWnd);
bool32 IsMenu(int64_t hMenu);
bool32 IsChild(int64_t hWndParent, int64_t hWnd);
bool32 IsZoomed(int64_t hWnd);
bool32 IsIconic(int64_t hWnd);

uintptr_t SetTimer(int64_t opt_hWnd, uintptr_t nIDEvent, uint32_t uElapseMs,
                   NtTimerProc lpTimerFunc);
int32_t KillTimer(int64_t hWnd, uintptr_t uIDEvent);

int64_t SetCapture(int64_t hWnd);
bool32 ReleaseCapture(void);
int16_t GetKeyState(int32_t nVirtKey);

int64_t CreateMenu(void);
int64_t CreatePopupMenu(void);
int64_t GetMenu(int64_t hWnd);
bool32 DestroyMenu(int64_t hMenu);
int64_t GetSystemMenu(int64_t hWnd, bool32 bRevert);
bool32 AppendMenu(int64_t hMenu, uint32_t mfFlags, uintptr_t uIDNewItem,
                  const char16_t *lpNewItem);
bool32 InsertMenu(int64_t hMenu, uint32_t uPosition, uint32_t uFlags,
                  uintptr_t uIDNewItem, const char16_t *lpNewItem);
bool32 TrackPopupMenu(int64_t hMenu, uint32_t uFlags, int32_t x, int32_t y,
                      int32_t nReserved, int64_t hWnd,
                      const struct NtRect *prcRect);

int WideCharToMultiByte(unsigned int CodePage, uint32_t dwFlags,
                        uint16_t *lpWideCharStr, int cchWideChar,
                        char *lpMultiByteStr, int cbMultiByte,
                        uint16_t *lpDefaultChar, int *lpUsedDefaultChar);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/clktck.h */

#define COSMOPOLITAN_LIBC_RUNTIME_CLKTCK_H_
COSMOPOLITAN_C_START_

#define CLK_TCK (__clk_tck())

int __clk_tck(void) pureconst;

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/fenv.h */

#define COSMOPOLITAN_LIBC_RUNTIME_FENV_H_

#ifdef __x86_64__
#define FE_INVALID    1
#define __FE_DENORM   2
#define FE_DIVBYZERO  4
#define FE_OVERFLOW   8
#define FE_UNDERFLOW  16
#define FE_INEXACT    32
#define FE_ALL_EXCEPT 63
#define FE_TONEAREST  0x0000
#define FE_DOWNWARD   0x0400
#define FE_UPWARD     0x0800
#define FE_TOWARDZERO 0x0c00
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint16_t fexcept_t;

#elif defined(__aarch64__)
#define FE_INVALID    1
#define FE_DIVBYZERO  2
#define FE_OVERFLOW   4
#define FE_UNDERFLOW  8
#define FE_INEXACT    16
#define FE_ALL_EXCEPT 31
#define FE_TONEAREST  0
#define FE_DOWNWARD   0x800000
#define FE_UPWARD     0x400000
#define FE_TOWARDZERO 0xc00000
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint32_t fexcept_t;

#elif defined(__powerpc64__)
#define FE_TONEAREST                  0
#define FE_TOWARDZERO                 1
#define FE_UPWARD                     2
#define FE_DOWNWARD                   3
#define FE_INEXACT                    0x02000000
#define FE_DIVBYZERO                  0x04000000
#define FE_UNDERFLOW                  0x08000000
#define FE_OVERFLOW                   0x10000000
#define FE_INVALID                    0x20000000
#define FE_ALL_EXCEPT                 0x3e000000
#define FE_INVALID_SNAN               0x01000000
#define FE_INVALID_ISI                0x00800000
#define FE_INVALID_IDI                0x00400000
#define FE_INVALID_ZDZ                0x00200000
#define FE_INVALID_IMZ                0x00100000
#define FE_INVALID_COMPARE            0x00080000
#define FE_INVALID_SOFTWARE           0x00000400
#define FE_INVALID_SQRT               0x00000200
#define FE_INVALID_INTEGER_CONVERSION 0x00000100
#define FE_ALL_INVALID                0x01f80700
#define FE_DFL_ENV                    ((const fenv_t *)-1)
typedef unsigned fexcept_t;
typedef double fenv_t;

#endif /* __x86_64__ */

#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD_TS_18661_3__
#elif defined(__FLT_EVAL_METHOD__)
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#else
#define FLT_EVAL_METHOD 0
#endif

COSMOPOLITAN_C_START_

#define FLT_ROUNDS (__flt_rounds())

int feclearexcept(int);
int fegetenv(fenv_t *);
int fegetexceptflag(fexcept_t *, int);
int fegetround(void);
int feholdexcept(fenv_t *);
int feraiseexcept(int);
int fesetenv(const fenv_t *);
int fesetexceptflag(const fexcept_t *, int);
int fesetround(int);
int fetestexcept(int);
int feenableexcept(int);
int fedisableexcept(int);
int feupdateenv(const fenv_t *);
int __flt_rounds(void);
int __fesetround(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/pathconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_PATHCONF_H_

#define _PC_LINK_MAX           0
#define _PC_MAX_CANON          1
#define _PC_MAX_INPUT          2
#define _PC_NAME_MAX           3
#define _PC_PATH_MAX           4
#define _PC_PIPE_BUF           5
#define _PC_CHOWN_RESTRICTED   6
#define _PC_NO_TRUNC           7
#define _PC_VDISABLE           8
#define _PC_SYNC_IO            9
#define _PC_ASYNC_IO           10
#define _PC_PRIO_IO            11
#define _PC_SOCK_MAXBUF        12
#define _PC_FILESIZEBITS       13
#define _PC_REC_INCR_XFER_SIZE 14
#define _PC_REC_MAX_XFER_SIZE  15
#define _PC_REC_MIN_XFER_SIZE  16
#define _PC_REC_XFER_ALIGN     17
#define _PC_ALLOC_SIZE_MIN     18
#define _PC_SYMLINK_MAX        19
#define _PC_2_SYMLINKS         20

COSMOPOLITAN_C_START_

long fpathconf(int, int);
long pathconf(const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/runtime.h */

#define COSMOPOLITAN_LIBC_RUNTIME_RUNTIME_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § runtime                                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#ifdef __x86_64__
typedef long jmp_buf[8];
typedef long sigjmp_buf[11];
#elif defined(__aarch64__)
typedef long jmp_buf[22];
typedef long sigjmp_buf[25];
#elif defined(__powerpc64__)
typedef unsigned __int128 jmp_buf[32];
#elif defined(__s390x__)
typedef unsigned long jmp_buf[18];
#elif defined(__riscv)
typedef unsigned long jmp_buf[26];
#endif

void mcount(void);
int daemon(int, int);
unsigned long getauxval(unsigned long);
int setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
int _setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
void siglongjmp(sigjmp_buf, int) libcesque wontreturn paramsnonnull();
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
void exit(int) wontreturn;
void _exit(int) libcesque wontreturn;
void _Exit(int) libcesque wontreturn;
void quick_exit(int) wontreturn;
void abort(void) wontreturn;
int atexit(void (*)(void)) paramsnonnull() libcesque;
char *getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
int putenv(char *);
int setenv(const char *, const char *, int);
int unsetenv(const char *);
int clearenv(void);
void fpreset(void);
void *mmap(void *, uint64_t, int32_t, int32_t, int32_t, int64_t);
int munmap(void *, uint64_t);
int mprotect(void *, uint64_t, int);
int msync(void *, size_t, int);
int mlock(const void *, size_t);
int munlock(const void *, size_t);
long gethostid(void);
int sethostid(long);
char *getlogin(void);
int getlogin_r(char *, size_t);
int login_tty(int);
int getpagesize(void);
int syncfs(int) dontthrow;
int vhangup(void);
int getdtablesize(void);
int sethostname(const char *, size_t);
int acct(const char *);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
extern char **environ;
char *secure_getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
#endif

#ifdef _COSMO_SOURCE
extern int __argc;
extern char **__argv;
extern char **__envp;
extern unsigned long *__auxv;
extern intptr_t __oldstack;
extern char *__program_executable_name;
extern uint64_t __nosync;
extern int __strace;
extern int __ftrace;
extern uint64_t __syscount;
extern uint64_t kStartTsc;
extern const char kNtSystemDirectory[];
extern const char kNtWindowsDirectory[];
extern size_t __virtualmax;
extern size_t __stackmax;
extern bool32 __isworker;
/* utilities */
void _intsort(int *, size_t);
void _longsort(long *, size_t);
/* diagnostics */
void ShowCrashReports(void);
int ftrace_install(void);
int ftrace_enabled(int);
int strace_enabled(int);
void __print_maps(void);
void __printargs(const char *);
/* builtin sh-like system/popen dsl */
int _cocmd(int, char **, char **);
/* executable program */
char *GetProgramExecutableName(void);
char *GetInterpreterExecutableName(char *, size_t);
int __open_executable(void);
/* execution control */
int verynice(void);
void __warn_if_powersave(void);
void _Exit1(int) libcesque wontreturn;
void __paginate(int, const char *);
void __paginate_file(int, const char *);
/* memory management */
void _weakfree(void *);
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
void CheckForMemoryLeaks(void);
void CheckForFileLeaks(void);
bool32 _isheap(const void *);
void __enable_threads(void);
void __oom_hook(size_t);
/* code morphing */
void __morph_begin(void);
void __morph_end(void);
void __jit_begin(void);
void __jit_end(void);
void __clear_cache(void *, void *);
/* portability */
int NtGetVersion(void) pureconst;
bool32 IsGenuineBlink(void);
bool32 IsCygwin(void);
const char *GetCpuidOs(void);
const char *GetCpuidEmulator(void);
void GetCpuidBrand(char[13], uint32_t);
long __get_rlimit(int);
const char *__describe_os(void);
long __get_sysctl(int, int);
int __get_arg_max(void) pureconst;
int __get_cpu_count(void) pureconst;
long __get_avphys_pages(void) pureconst;
long __get_phys_pages(void) pureconst;
long __get_minsigstksz(void) pureconst;
void __get_main_stack(void **, size_t *, int *);
long __get_safe_size(long, long);
char *__get_tmpdir(void);
forceinline int __trace_disabled(int x) {
  return 0;
}
#ifndef FTRACE
#define ftrace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#ifndef SYSDEBUG
#define strace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/stack.h */

#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_

/**
 * Returns preferred size and alignment of thread stack.
 */
#define GetStackSize() 262144

/**
 * Returns preferred stack guard size.
 *
 * This is the max cpu page size of supported architectures.
 */
#define GetGuardSize() 16384

/**
 * Align APE main thread stack at startup.
 *
 * You need this in your main program module:
 *
 *     STATIC_STACK_ALIGN(GetStackSize());
 *
 * If you want to use GetStackAddr() and HaveStackMemory() safely on
 * your main thread in your process. It causes crt.S to waste a tiny
 * amount of memory to ensure those macros go extremely fast.
 */
#define STATIC_STACK_ALIGN(BYTES) \
  _STACK_SYMBOL("ape_stack_align", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Makes program stack executable if declared, e.g.
 *
 *     STATIC_EXEC_STACK();
 *     int main() {
 *       char code[16] = {
 *           0x55,                          // push %rbp
 *           0xb8, 0007, 0x00, 0x00, 0x00,  // mov  $7,%eax
 *           0x5d,                          // push %rbp
 *           0xc3,                          // ret
 *       };
 *       int (*func)(void) = (void *)code;
 *       printf("result %d should be 7\n", func());
 *     }
 */
#define STATIC_EXEC_STACK() _STACK_SYMBOL("ape_stack_pf", "7")

#define _STACK_STRINGIFY(ADDR) #ADDR
#define _STACK_SYMBOL(NAME, VALUE)       \
  __asm__(".equ\t" NAME "," VALUE "\n\t" \
          ".globl\t" NAME)

#ifdef __SANITIZE_ADDRESS__
#define _STACK_EXTRA "*2"
#else
#define _STACK_EXTRA ""
#endif

#if defined(__GNUC__) && defined(__ELF__)
COSMOPOLITAN_C_START_

extern char ape_stack_prot[] __attribute__((__weak__));
extern char ape_stack_memsz[] __attribute__((__weak__));
extern char ape_stack_align[] __attribute__((__weak__));

/**
 * Returns address of bottom of current stack.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants.
 */
#define GetStackAddr() ((GetStackPointer() - 1) & -GetStackSize())

#define GetStaticStackSize() ((uintptr_t)ape_stack_memsz)

/**
 * Returns true if at least `n` bytes of stack are available.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants,
 * which make this check exceedingly fast.
 */
#define HaveStackMemory(n) \
  (GetStackPointer() >= GetStackAddr() + GetGuardSize() + (n))

/**
 * Extends stack memory by poking large allocations.
 *
 * This can be particularly useful depending on how your system
 * implements guard pages. For example, Windows can make stacks
 * that aren't fully committed, in which case there's only 4096
 * bytes of grows-down guard pages made by portable executable.
 * If you alloca() more memory than that, you should call this,
 * since it'll not only ensure stack overflows are detected, it
 * will also trigger the stack to grow down safely.
 */
forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
  for (; n > 0; n -= 4096) {
    ((char *)p)[n - 1] = 0;
  }
}

void *NewCosmoStack(void) vallocesque;
int FreeCosmoStack(void *) libcesque;

/**
 * Tunes stack size of main thread on Windows.
 *
 * On UNIX systems use `RLIMIT_STACK` to tune the main thread size.
 */
#define STATIC_STACK_SIZE(BYTES) \
  _STACK_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Tunes main thread stack address on Windows.
 */
#define STATIC_STACK_ADDR(ADDR) \
  _STACK_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))

#ifdef __x86_64__
/**
 * Returns preferred bottom address of main thread stack.
 *
 * On UNIX systems we favor the system provided stack, so this only
 * really applies to Windows. It's configurable at link time. It is
 * needed because polyfilling fork requires that we know, precicely
 * where the stack memory begins and ends.
 */
#define GetStaticStackAddr(ADDEND)          \
  ({                                        \
    intptr_t vAddr;                         \
    __asm__(".weak\tape_stack_vaddr\n\t"    \
            "movabs\t%1+ape_stack_vaddr,%0" \
            : "=r"(vAddr)                   \
            : "i"(ADDEND));                 \
    vAddr;                                  \
  })
#else
#define GetStaticStackAddr(ADDEND) (GetStackAddr() + ADDEND)
#endif

#define GetStackPointer()           \
  ({                                \
    uintptr_t __sp;                 \
    __asm__(__mov_sp : "=r"(__sp)); \
    __sp;                           \
  })

#ifdef __x86_64__
#define __mov_sp "mov\t%%rsp,%0"
#elif defined(__aarch64__)
#define __mov_sp "mov\t%0,sp"
#endif

COSMOPOLITAN_C_END_
#endif /* GNU ELF */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_STACK_H_ */


/*!BEGIN libc/runtime/sysconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_SYSCONF_H_

#define _SC_ARG_MAX                      0
#define _SC_CHILD_MAX                    1
#define _SC_CLK_TCK                      2
#define _SC_NGROUPS_MAX                  3
#define _SC_OPEN_MAX                     4
#define _SC_STREAM_MAX                   5
#define _SC_TZNAME_MAX                   6
#define _SC_JOB_CONTROL                  7
#define _SC_SAVED_IDS                    8
#define _SC_REALTIME_SIGNALS             9
#define _SC_PRIORITY_SCHEDULING          10
#define _SC_TIMERS                       11
#define _SC_ASYNCHRONOUS_IO              12
#define _SC_PRIORITIZED_IO               13
#define _SC_SYNCHRONIZED_IO              14
#define _SC_FSYNC                        15
#define _SC_MAPPED_FILES                 16
#define _SC_MEMLOCK                      17
#define _SC_MEMLOCK_RANGE                18
#define _SC_MEMORY_PROTECTION            19
#define _SC_MESSAGE_PASSING              20
#define _SC_SEMAPHORES                   21
#define _SC_SHARED_MEMORY_OBJECTS        22
#define _SC_AIO_LISTIO_MAX               23
#define _SC_AIO_MAX                      24
#define _SC_AIO_PRIO_DELTA_MAX           25
#define _SC_DELAYTIMER_MAX               26
#define _SC_MQ_OPEN_MAX                  27
#define _SC_MQ_PRIO_MAX                  28
#define _SC_VERSION                      29
#define _SC_PAGE_SIZE                    30
#define _SC_PAGESIZE                     30 /* !! */
#define _SC_RTSIG_MAX                    31
#define _SC_SEM_NSEMS_MAX                32
#define _SC_SEM_VALUE_MAX                33
#define _SC_SIGQUEUE_MAX                 34
#define _SC_TIMER_MAX                    35
#define _SC_BC_BASE_MAX                  36
#define _SC_BC_DIM_MAX                   37
#define _SC_BC_SCALE_MAX                 38
#define _SC_BC_STRING_MAX                39
#define _SC_COLL_WEIGHTS_MAX             40
#define _SC_EXPR_NEST_MAX                42
#define _SC_LINE_MAX                     43
#define _SC_RE_DUP_MAX                   44
#define _SC_2_VERSION                    46
#define _SC_2_C_BIND                     47
#define _SC_2_C_DEV                      48
#define _SC_2_FORT_DEV                   49
#define _SC_2_FORT_RUN                   50
#define _SC_2_SW_DEV                     51
#define _SC_2_LOCALEDEF                  52
#define _SC_UIO_MAXIOV                   60 /* !! */
#define _SC_IOV_MAX                      60
#define _SC_THREADS                      67
#define _SC_THREAD_SAFE_FUNCTIONS        68
#define _SC_GETGR_R_SIZE_MAX             69
#define _SC_GETPW_R_SIZE_MAX             70
#define _SC_LOGIN_NAME_MAX               71
#define _SC_TTY_NAME_MAX                 72
#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73
#define _SC_THREAD_KEYS_MAX              74
#define _SC_THREAD_STACK_MIN             75
#define _SC_THREAD_THREADS_MAX           76
#define _SC_THREAD_ATTR_STACKADDR        77
#define _SC_THREAD_ATTR_STACKSIZE        78
#define _SC_THREAD_PRIORITY_SCHEDULING   79
#define _SC_THREAD_PRIO_INHERIT          80
#define _SC_THREAD_PRIO_PROTECT          81
#define _SC_THREAD_PROCESS_SHARED        82
#define _SC_NPROCESSORS_CONF             83
#define _SC_NPROCESSORS_ONLN             84
#define _SC_PHYS_PAGES                   85
#define _SC_AVPHYS_PAGES                 86
#define _SC_ATEXIT_MAX                   87
#define _SC_PASS_MAX                     88
#define _SC_XOPEN_VERSION                89
#define _SC_XOPEN_XCU_VERSION            90
#define _SC_XOPEN_UNIX                   91
#define _SC_XOPEN_CRYPT                  92
#define _SC_XOPEN_ENH_I18N               93
#define _SC_XOPEN_SHM                    94
#define _SC_2_CHAR_TERM                  95
#define _SC_2_UPE                        97
#define _SC_XOPEN_XPG2                   98
#define _SC_XOPEN_XPG3                   99
#define _SC_XOPEN_XPG4                   100
#define _SC_NZERO                        109
#define _SC_XBS5_ILP32_OFF32             125
#define _SC_XBS5_ILP32_OFFBIG            126
#define _SC_XBS5_LP64_OFF64              127
#define _SC_XBS5_LPBIG_OFFBIG            128
#define _SC_XOPEN_LEGACY                 129
#define _SC_XOPEN_REALTIME               130
#define _SC_XOPEN_REALTIME_THREADS       131
#define _SC_ADVISORY_INFO                132
#define _SC_BARRIERS                     133
#define _SC_CLOCK_SELECTION              137
#define _SC_CPUTIME                      138
#define _SC_THREAD_CPUTIME               139
#define _SC_MONOTONIC_CLOCK              149
#define _SC_READER_WRITER_LOCKS          153
#define _SC_SPIN_LOCKS                   154
#define _SC_REGEXP                       155
#define _SC_SHELL                        157
#define _SC_SPAWN                        159
#define _SC_SPORADIC_SERVER              160
#define _SC_THREAD_SPORADIC_SERVER       161
#define _SC_TIMEOUTS                     164
#define _SC_TYPED_MEMORY_OBJECTS         165
#define _SC_2_PBS                        168
#define _SC_2_PBS_ACCOUNTING             169
#define _SC_2_PBS_LOCATE                 170
#define _SC_2_PBS_MESSAGE                171
#define _SC_2_PBS_TRACK                  172
#define _SC_SYMLOOP_MAX                  173
#define _SC_STREAMS                      174
#define _SC_2_PBS_CHECKPOINT             175
#define _SC_V6_ILP32_OFF32               176
#define _SC_V6_ILP32_OFFBIG              177
#define _SC_V6_LP64_OFF64                178
#define _SC_V6_LPBIG_OFFBIG              179
#define _SC_HOST_NAME_MAX                180
#define _SC_TRACE                        181
#define _SC_TRACE_EVENT_FILTER           182
#define _SC_TRACE_INHERIT                183
#define _SC_TRACE_LOG                    184
#define _SC_IPV6                         235
#define _SC_RAW_SOCKETS                  236
#define _SC_V7_ILP32_OFF32               237
#define _SC_V7_ILP32_OFFBIG              238
#define _SC_V7_LP64_OFF64                239
#define _SC_V7_LPBIG_OFFBIG              240
#define _SC_SS_REPL_MAX                  241
#define _SC_TRACE_EVENT_NAME_MAX         242
#define _SC_TRACE_NAME_MAX               243
#define _SC_TRACE_SYS_MAX                244
#define _SC_TRACE_USER_EVENT_MAX         245
#define _SC_XOPEN_STREAMS                246
#define _SC_THREAD_ROBUST_PRIO_INHERIT   247
#define _SC_THREAD_ROBUST_PRIO_PROTECT   248
#define _SC_SIGSTKSZ                     249
#define _SC_MINSIGSTKSZ                  250

COSMOPOLITAN_C_START_

long sysconf(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/utmp.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMP_H_


/*!BEGIN libc/runtime/utmpx.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMPX_H_
COSMOPOLITAN_C_START_

struct utmpx {
  short ut_type;
  pid_t ut_pid;
  char ut_line[32];
  char ut_id[4];
  char ut_user[32];
  char ut_host[256];
  struct {
    short __e_termination;
    short __e_exit;
  } ut_exit;
  long ut_session;
  struct timeval ut_tv;
  unsigned ut_addr_v6[4];
  char __unused[20];
};

void endutxent(void);
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *);
struct utmpx *getutxline(const struct utmpx *);
struct utmpx *pututxline(const struct utmpx *);
void setutxent(void);

#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define e_exit        __e_exit
#define e_termination __e_termination
void updwtmpx(const char *, const struct utmpx *);
int utmpxname(const char *);
#endif

#define EMPTY         0
#define RUN_LVL       1
#define BOOT_TIME     2
#define NEW_TIME      3
#define OLD_TIME      4
#define INIT_PROCESS  5
#define LOGIN_PROCESS 6
#define USER_PROCESS  7
#define DEAD_PROCESS  8

COSMOPOLITAN_C_END_

#define ACCOUNTING  9
#define UT_NAMESIZE 32
#define UT_HOSTSIZE 256
#define UT_LINESIZE 32

COSMOPOLITAN_C_START_

struct lastlog {
  time_t ll_time;
  char ll_line[UT_LINESIZE];
  char ll_host[UT_HOSTSIZE];
};

#define ut_time       ut_tv.tv_sec
#define ut_name       ut_user
#define ut_addr       ut_addr_v6[0]
#define utmp          utmpx
#define e_exit        __e_exit
#define e_termination __e_termination

int login_tty(int);
int utmpname(const char *);
struct utmp *getutent(void);
struct utmp *getutid(const struct utmp *);
struct utmp *getutline(const struct utmp *);
struct utmp *pututline(const struct utmp *);
void endutent(void);
void setutent(void);
void updwtmp(const char *, const struct utmp *);

#define _PATH_UTMP "/dev/null/utmp"
#define _PATH_WTMP "/dev/null/wtmp"

#define UTMP_FILE     _PATH_UTMP
#define WTMP_FILE     _PATH_WTMP
#define UTMP_FILENAME _PATH_UTMP
#define WTMP_FILENAME _PATH_WTMP

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/alg.h */

#define COSMOPOLITAN_LIBC_SOCK_ALG_H_
COSMOPOLITAN_C_START_

struct sockaddr_alg {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[64];
};

struct sockaddr_alg_new {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[]; /* Linux v4.12+ */
};

struct af_alg_iv {
  uint32_t ivlen;
  uint8_t iv[0];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/epoll.h */

#define COSMOPOLITAN_LIBC_SOCK_WEPOLL_H_
COSMOPOLITAN_C_START_

typedef union epoll_data {
  void *ptr;
  int fd;
  uint32_t u32;
  uint64_t u64;
} epoll_data_t;

struct thatispacked epoll_event {
  uint32_t events;
  epoll_data_t data;
};

int epoll_create(int) libcesque;
int epoll_create1(int) libcesque;
int epoll_ctl(int, int, int, struct epoll_event *) libcesque;
int epoll_wait(int, struct epoll_event *, int, int) libcesque;
int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/ifaddrs.h */

#define COSMOPOLITAN_LIBC_SOCK_IFADDRS_H_
COSMOPOLITAN_C_START_

struct ifaddrs {
  struct ifaddrs *ifa_next;
  char *ifa_name;
  unsigned ifa_flags;
  struct sockaddr *ifa_addr;
  struct sockaddr *ifa_netmask;
  union {
    struct sockaddr *ifa_broadaddr;
    struct sockaddr *ifa_dstaddr;
  };
  void *ifa_data;
};

void freeifaddrs(struct ifaddrs *) libcesque;
int getifaddrs(struct ifaddrs **) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/in.h */

#define COSMOPOLITAN_LIBC_SOCK_IN_H_

#define IN_CLASSA(a)       ((((in_addr_t)(a)) & 0x80000000) == 0)
#define IN_CLASSA_NET      0xff000000
#define IN_CLASSA_NSHIFT   24
#define IN_CLASSA_HOST     (0xffffffff & ~IN_CLASSA_NET)
#define IN_CLASSA_MAX      128
#define IN_CLASSB(a)       ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET      0xffff0000
#define IN_CLASSB_NSHIFT   16
#define IN_CLASSB_HOST     (0xffffffff & ~IN_CLASSB_NET)
#define IN_CLASSB_MAX      65536
#define IN_CLASSC(a)       ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET      0xffffff00
#define IN_CLASSC_NSHIFT   8
#define IN_CLASSC_HOST     (0xffffffff & ~IN_CLASSC_NET)
#define IN_CLASSD(a)       ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
#define IN_MULTICAST(a)    IN_CLASSD(a)
#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
#define IN_BADCLASS(a)     ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)

#define IN6_IS_ADDR_UNSPECIFIED(a)                           \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint32_t *)(a))[3] == 0)

#define IN6_IS_ADDR_LOOPBACK(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[12] == 0 && \
   ((uint8_t *)(a))[13] == 0 && ((uint8_t *)(a))[14] == 0 && \
   ((uint8_t *)(a))[15] == 1)

#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *)(a))[0] == 0xff)

#define IN6_IS_ADDR_LINKLOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0x80)

#define IN6_IS_ADDR_SITELOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0xc0)

#define IN6_IS_ADDR_V4MAPPED(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint8_t *)(a))[8] == 0 && ((uint8_t *)(a))[9] == 0 &&   \
   ((uint8_t *)(a))[10] == 0xff && ((uint8_t *)(a))[11] == 0xff)

#define IN6_IS_ADDR_V4COMPAT(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[15] > 1)

#define IN6_IS_ADDR_MC_NODELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x1))

#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x2))

#define IN6_IS_ADDR_MC_SITELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x5))

#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x8))

#define IN6_IS_ADDR_MC_GLOBAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0xe))

#define __ARE_4_EQUAL(a, b) \
  (!((0 [a] - 0 [b]) | (1 [a] - 1 [b]) | (2 [a] - 2 [b]) | (3 [a] - 3 [b])))
#define IN6_ARE_ADDR_EQUAL(a, b) \
  __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))



/*!BEGIN libc/sock/select.h */

#define COSMOPOLITAN_LIBC_SOCK_SELECT_H_

#define FD_SETSIZE 1024 /* it's 64 on windows */

COSMOPOLITAN_C_START_

typedef struct fd_set {
  unsigned long fds_bits[FD_SETSIZE / (sizeof(long) * 8)];
} fd_set;

#define FD_ISSET(FD, SET) (((SET)->fds_bits[(FD) >> 6] >> ((FD)&63)) & 1)
#define FD_SET(FD, SET)   ((SET)->fds_bits[(FD) >> 6] |= 1ull << ((FD)&63))
#define FD_CLR(FD, SET)   ((SET)->fds_bits[(FD) >> 6] &= ~(1ull << ((FD)&63)))
#define FD_ZERO(SET)      bzero((SET)->fds_bits, sizeof((SET)->fds_bits))
#define FD_SIZE(bits)     (((bits) + (sizeof(long) * 8) - 1) / sizeof(long))

int select(int, fd_set *, fd_set *, fd_set *, struct timeval *) libcesque;
int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
            const sigset_t *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/syslog.h */

#define COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_
COSMOPOLITAN_C_START_

int setlogmask(int) libcesque;
void openlog(const char *, int, int) libcesque;
void syslog(int, const char *, ...) libcesque;
void closelog(void) libcesque;
void vsyslog(int, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arphdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPHDR_H_
COSMOPOLITAN_C_START_

struct arphdr {
  uint16_t ar_hrd;
  uint16_t ar_pro;
  uint8_t ar_hln;
  uint8_t ar_pln;
  uint16_t ar_op;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arpreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPREQ_H_
COSMOPOLITAN_C_START_

struct arpreq {
  struct sockaddr arp_pa;
  struct sockaddr arp_ha;
  int arp_flags;
  struct sockaddr arp_netmask;
  char arp_dev[16];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/cmsghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_H_
COSMOPOLITAN_C_START_

#define CMSG_DATA(cmsg) ((unsigned char *)(((struct cmsghdr *)(cmsg)) + 1))

#define CMSG_FIRSTHDR(mhdr)                                 \
  ((size_t)(mhdr)->msg_controllen >= sizeof(struct cmsghdr) \
       ? (struct cmsghdr *)(mhdr)->msg_control              \
       : (struct cmsghdr *)0)

#define CMSG_NXTHDR(mhdr, cmsg)                           \
  ((cmsg)->cmsg_len < sizeof(struct cmsghdr) ||           \
           __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >=   \
               __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
       ? 0                                                \
       : (struct cmsghdr *)__CMSG_NEXT(cmsg))

#define CMSG_ALIGN(len) \
  (((len) + sizeof(size_t) - 1) & (size_t) ~(sizeof(size_t) - 1))

#define CMSG_SPACE(len) (CMSG_ALIGN(len) + CMSG_ALIGN(sizeof(struct cmsghdr)))

#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))

#define __CMSG_LEN(cmsg) \
  (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
#define __MHDR_END(mhdr) \
  ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)

struct cmsghdr { /* linux abi */
  uint32_t cmsg_len;
  uint32_t __pad1;
  int32_t cmsg_level;
  int32_t cmsg_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ether_header.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ETHER_HEADER_H_

#define ETH_ALEN 6

COSMOPOLITAN_C_START_

struct ether_addr {
  uint8_t ether_addr_octet[ETH_ALEN];
};

struct ether_header {
  uint8_t ether_dhost[ETH_ALEN];
  uint8_t ether_shost[ETH_ALEN];
  uint16_t ether_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ifconf.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFCONF_H_


/*!BEGIN libc/sock/struct/ifreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFREQ_H_
COSMOPOLITAN_C_START_

#define IF_NAMESIZE 16
#define IFNAMSIZ    IF_NAMESIZE

struct ifreq {
  union {
    char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0".  */
  } ifr_ifrn;
  union {
    struct sockaddr ifru_addr;      /* SIOCGIFADDR */
    struct sockaddr ifru_dstaddr;   /* SIOCGIFDSTADDR */
    struct sockaddr ifru_netmask;   /* SIOCGIFNETMASK */
    struct sockaddr ifru_broadaddr; /* SIOCGIFBRDADDR */
    short ifru_flags;               /* SIOCGIFFLAGS */
    int ifru_ivalue;                /* todo(jart) */
    char ifru_pad[24];              /* ifru_map is the largest, just pad */
  } ifr_ifru;
};

#define ifr_name      ifr_ifrn.ifrn_name      /* interface name */
#define ifr_addr      ifr_ifru.ifru_addr      /* address */
#define ifr_netmask   ifr_ifru.ifru_netmask   /* netmask */
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
#define ifr_dstaddr   ifr_ifru.ifru_dstaddr   /* destination address */
#define ifr_flags     ifr_ifru.ifru_flags     /* flags */
#define ifr_ifindex   ifr_ifru.ifru_ivalue

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/*
 * Structure used in SIOCGIFCONF request.
 * Used to retrieve interface configuration
 * for machine (useful for programs which
 * must know all networks accessible).
 */
struct ifconf {
  int32_t ifc_len; /* size of buffer */
  int32_t padding;
  union {
    char *ifcu_buf;
    struct ifreq *ifcu_req;
  } ifc_ifcu;
};

/* Shortcuts to the ifconf buffer or ifreq array */
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address   */
#define ifc_req ifc_ifcu.ifcu_req /* array of structures  */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in6_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN6_PKTINFO_H_


/*!BEGIN libc/sock/struct/sockaddr6.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SOCKADDR6_H_

struct in6_addr {
  union {
    uint8_t s6_addr[16];
    uint16_t s6_addr16[8];
    uint32_t s6_addr32[4];
  };
};

struct sockaddr_in6 { /* Linux+NT ABI */
  uint16_t sin6_family;
  uint16_t sin6_port;
  uint32_t sin6_flowinfo;
  struct in6_addr sin6_addr;
  uint32_t sin6_scope_id; /* rfc2553 */
};

extern const struct in6_addr in6addr_any;
extern const struct in6_addr in6addr_loopback;

COSMOPOLITAN_C_START_

struct in6_pktinfo {
  struct in6_addr ipi6_addr;
  unsigned ipi6_ifindex;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN_PKTINFO_H_
COSMOPOLITAN_C_START_

struct in_pktinfo {
  int ipi_ifindex;
  struct in_addr ipi_spec_dst;
  struct in_addr ipi_addr;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ip_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IP_MREQ_H_
COSMOPOLITAN_C_START_

struct ip_mreq {
  struct in_addr imr_multiaddr; /* IP multicast address of group */
  struct in_addr imr_interface; /* local IP address of interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ipv6_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IPV6_MREQ_H_
COSMOPOLITAN_C_START_

struct ipv6_mreq {
  struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address of group */
  unsigned ipv6mr_interface;        /* local interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/linger.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger {     /* Linux+XNU+BSD ABI */
  int32_t l_onoff;  /* on/off */
  int32_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/msghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_H_
COSMOPOLITAN_C_START_

struct msghdr {            /* Linux+NT ABI */
  void *msg_name;          /* optional address */
  uint32_t msg_namelen;    /* size of msg_name */
  struct iovec *msg_iov;   /* scatter/gather array */
  uint64_t msg_iovlen;     /* # elements in msg_iov */
  void *msg_control;       /* ancillary data c. cmsghdr */
  uint64_t msg_controllen; /* ancillary data buffer len */
  uint32_t msg_flags;      /* MSG_XXX */
};

ssize_t recvmsg(int, struct msghdr *, int);
ssize_t sendmsg(int, const struct msghdr *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_
COSMOPOLITAN_C_START_

struct pollfd {
  int32_t fd;
  int16_t events;
  int16_t revents;
};

int poll(struct pollfd *, uint64_t, int32_t);
int ppoll(struct pollfd *, uint64_t, const struct timespec *, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/append.h */

#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_

#define APPEND_COOKIE 21578

#define appendz   __appendz
#define appendr   __appendr
#define appendd   __appendd
#define appendw   __appendw
#define appends   __appends
#define appendf   __appendf
#define vappendf  __vappendf
#define kappendf  __kappendf
#define kvappendf __kvappendf

COSMOPOLITAN_C_START_

struct appendz {
  size_t i;
  size_t n;
};

struct appendz appendz(char *) libcesque;
ssize_t appendr(char **, size_t) libcesque;
ssize_t appendd(char **, const void *, size_t) libcesque;
ssize_t appendw(char **, uint64_t) libcesque;
ssize_t appends(char **, const char *) libcesque;
ssize_t appendf(char **, const char *, ...) libcesque;
ssize_t vappendf(char **, const char *, va_list) libcesque;
ssize_t kappendf(char **, const char *, ...) libcesque;
ssize_t kvappendf(char **, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_STDIO_APPEND_H_ */


/*!BEGIN libc/stdio/dprintf.h */

#define COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_
COSMOPOLITAN_C_START_

libcesque int dprintf(int, const char *, ...) paramsnonnull((2));
libcesque int vdprintf(int, const char *, va_list) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/ftw.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_FTW_H_
COSMOPOLITAN_C_START_

/**
 * Type for file.
 */
#define FTW_F 1

/**
 * Type for directory.
 */
#define FTW_D 2

/**
 * Type for directory that cannot be read.
 */
#define FTW_DNR 3

/**
 * Type for stat() failed and not a symbolic link.
 */
#define FTW_NS 4

/**
 * Type for symbolic link when `FTW_PHYS` is in flags.
 */
#define FTW_SL 5

/**
 * Directory and `FTW_DEPTH` in flags.
 */
#define FTW_DP 6

/**
 * Type for broken symbolic link when `FTW_PHYS` is not in flags.
 */
#define FTW_SLN 7

/**
 * Flag to prevent following symbolic links (recommended).
 * @see nftw() flags
 */
#define FTW_PHYS 1

/**
 * Flag to prevent crossing mount points.
 * @see nftw() flags
 */
#define FTW_MOUNT 2

/**
 * Unsupported.
 * @see nftw() flags
 */
#define FTW_CHDIR 4

/**
 * Flag for post-order traversal.
 *
 * 1. Will use `FTW_DP` instead of `FTW_D` as type.
 * 2. Directory callback happens *after* rather than before.
 *
 * @see nftw() flags
 */
#define FTW_DEPTH 8

struct FTW {

  /**
   * Byte offset of basename component in `fpath` passed to callback.
   */
  int base;

  /**
   * Depth relative to `dirpath` whose level is zero.
   */
  int level;
};

int ftw(const char *, int (*)(const char *, const struct stat *, int),
        int) dontthrow;

int nftw(const char *,
         int (*)(const char *, const struct stat *, int, struct FTW *), int,
         int) dontthrow;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/iconv.h */

#define COSMOPOLITAN_LIBC_STDIO_ICONV_H_
COSMOPOLITAN_C_START_

typedef void *iconv_t;

iconv_t iconv_open(const char *, const char *);
size_t iconv(iconv_t, char **, size_t *, char **, size_t *);
int iconv_close(iconv_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/rand.h */

#define COSMOPOLITAN_LIBC_RAND_RAND_H_
#define RAND_MAX __INT_MAX__
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § random                                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int rand(void) libcesque;
void srand(unsigned) libcesque;
char *strfry(char *) libcesque;
int getentropy(void *, size_t) libcesque;
ssize_t getrandom(void *, size_t, unsigned) libcesque;
char *initstate(unsigned, char *, size_t) libcesque;
char *setstate(char *) libcesque;
long random(void) libcesque;
void srandom(unsigned) libcesque;

#ifdef _COSMO_SOURCE
#define vigna   __vigna
#define vigna_r __vigna_r
#define rngset  __rngset
#define rdrand  __rdrand
#define rdseed  __rdseed
double poz(double) libcesque;
double pochisq(double, int) libcesque;
uint64_t lemur64(void) libcesque;
uint64_t _rand64(void) libcesque;
uint64_t vigna(void) libcesque;
uint64_t vigna_r(uint64_t[hasatleast 1]) libcesque;
void svigna(uint64_t) libcesque;
uint64_t rdrand(void) libcesque;
uint64_t rdseed(void) libcesque;
void _smt19937(uint64_t) libcesque;
void _Smt19937(uint64_t[], size_t) libcesque;
uint64_t _mt19937(void) libcesque;
double _real1(uint64_t) libcesque;
double _real2(uint64_t) libcesque;
double _real3(uint64_t) libcesque;
double MeasureEntropy(const char *, size_t) libcesque;
void *rngset(void *, size_t, uint64_t (*)(void), size_t) libcesque;
void rt_init(int) libcesque;
void rt_add(void *, int) libcesque;
void rt_end(double *, double *, double *, double *, double *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/readpassphrase.h */

#define COSMOPOLITAN_LIBC_STDIO_READPASSPHRASE_H_

#define RPP_ECHO_OFF    0x00
#define RPP_ECHO_ON     0x01
#define RPP_REQUIRE_TTY 0x02
#define RPP_FORCELOWER  0x04
#define RPP_FORCEUPPER  0x08
#define RPP_SEVENBIT    0x10
#define RPP_STDIN       0x20

COSMOPOLITAN_C_START_

char *readpassphrase(const char *, char *, size_t, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/stdio_ext.h */

#define COSMOPOLITAN_LIBC_STDIO_STDIO_EXT_H_

#define FSETLOCKING_QUERY    0
#define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_BYCALLER 2

COSMOPOLITAN_C_START_

size_t __fbufsize(FILE *) libcesque;
size_t __fpending(FILE *) libcesque;
int __flbf(FILE *) libcesque;
int __freadable(FILE *) libcesque;
int __fwritable(FILE *) libcesque;
int __freading(FILE *) libcesque;
int __fwriting(FILE *) libcesque;
int __fsetlocking(FILE *, int) libcesque;
void _flushlbf(void) libcesque;
void __fpurge(FILE *) libcesque;
void __fseterr(FILE *) libcesque;
const char *__freadptr(FILE *, size_t *) libcesque;
size_t __freadahead(FILE *) libcesque;
void __freadptrinc(FILE *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/syscall.h */

#define COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_
COSMOPOLITAN_C_START_

#define SYS_gettid    1
#define SYS_getrandom 2
#define SYS_getcpu    3

long syscall(long, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/sysparam.h */

#define COSMOPOLITAN_LIBC_SYSPARAM_H_

#define MAXSYMLINKS    20
#define MAXHOSTNAMELEN 64
#define MAXNAMLEN      255
#define MAXPATHLEN     PATH_MAX
#define NBBY           8
#define NGROUPS        32
#define CANBSIZ        255
#define NOFILE         256
#define NCARGS         131072
#define DEV_BSIZE      512
#define NOGROUP        (-1)

COSMOPOLITAN_C_START_

#define __bitop(x, i, o) ((x)[(i) / 8] o(1 << (i) % 8))
#define setbit(x, i)     __bitop(x, i, |=)
#define clrbit(x, i)     __bitop(x, i, &= ~)
#define isset(x, i)      __bitop(x, i, &)
#define isclr(x, i)      !isset(x, i)

#undef roundup
#define roundup(n, d) (howmany(n, d) * (d))
#define powerof2(n)   !(((n)-1) & (n))
#define howmany(n, d) (((n) + ((d)-1)) / (d))

#ifdef MIN
#undef MIN
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

#ifdef MAX
#undef MAX
#endif
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/ntspawn.h */

#define COSMOPOLITAN_NTSPAWN_H_
COSMOPOLITAN_C_START_

struct NtSpawnArgs {
  int64_t dirhand;
  const char *prog;
  char *const *argv;
  char *const *envp;
  char *const *extravars;
  uint32_t dwCreationFlags;
  const char16_t *opt_lpCurrentDirectory;
  int64_t opt_hParentProcess;
  int64_t *opt_lpExplicitHandleList;
  uint32_t dwExplicitHandleCount;
  const struct NtStartupInfo *lpStartupInfo;
  struct NtProcessInformation *opt_out_lpProcessInformation;
};

int mkntenvblock(char16_t[32767], char *const[], char *const[], char[32767]);
int ntspawn(struct NtSpawnArgs *);
size_t mkntcmdline(char16_t *, char *const[], size_t);
void mungentpath(char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/posix_spawn.h */

#define COSMOPOLITAN_LIBC_STDIO_SPAWN_H_

#define POSIX_SPAWN_USEVFORK      0
#define POSIX_SPAWN_RESETIDS      1
#define POSIX_SPAWN_SETPGROUP     2
#define POSIX_SPAWN_SETSIGDEF     4
#define POSIX_SPAWN_SETSIGMASK    8
#define POSIX_SPAWN_SETSCHEDPARAM 16
#define POSIX_SPAWN_SETSCHEDULER  32
#define POSIX_SPAWN_SETSID        128
#define POSIX_SPAWN_SETRLIMIT     256

COSMOPOLITAN_C_START_

typedef struct _posix_spawna *posix_spawnattr_t;
typedef struct _posix_faction *posix_spawn_file_actions_t;

int posix_spawn(int *, const char *, const posix_spawn_file_actions_t *,
                const posix_spawnattr_t *, char *const[], char *const[]);
int posix_spawnp(int *, const char *, const posix_spawn_file_actions_t *,
                 const posix_spawnattr_t *, char *const[], char *const[]);

int posix_spawn_file_actions_init(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *,
                                      int) libcesque;
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int,
                                     int) libcesque;
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *, int,
                                     const char *, int, unsigned) libcesque;
int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *,
                                         const char *) libcesque;
int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
                                          int) libcesque;

int posix_spawnattr_init(posix_spawnattr_t *) libcesque;
int posix_spawnattr_destroy(posix_spawnattr_t *) libcesque;
int posix_spawnattr_getflags(const posix_spawnattr_t *, short *) libcesque;
int posix_spawnattr_setflags(posix_spawnattr_t *, short) libcesque;
int posix_spawnattr_getpgroup(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setpgroup(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedparam(const posix_spawnattr_t *,
                                  struct sched_param *) libcesque;
int posix_spawnattr_setschedparam(posix_spawnattr_t *,
                                  const struct sched_param *) libcesque;
int posix_spawnattr_getsigmask(const posix_spawnattr_t *, sigset_t *) libcesque;
int posix_spawnattr_setsigmask(posix_spawnattr_t *, const sigset_t *) libcesque;
int posix_spawnattr_getsigdefault(const posix_spawnattr_t *,
                                  sigset_t *) libcesque;
int posix_spawnattr_setsigdefault(posix_spawnattr_t *,
                                  const sigset_t *) libcesque;
int posix_spawnattr_getrlimit(const posix_spawnattr_t *, int,
                              struct rlimit *) libcesque;
int posix_spawnattr_setrlimit(posix_spawnattr_t *, int,
                              const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/atomic.h */

#define NSYNC_ATOMIC_H_
COSMOPOLITAN_C_START_

#define nsync_atomic_uint32_ atomic_uint

#define NSYNC_ATOMIC_UINT32_INIT_        0
#define NSYNC_ATOMIC_UINT32_LOAD_(p)     (*(p))
#define NSYNC_ATOMIC_UINT32_STORE_(p, v) (*(p) = (v))
#define NSYNC_ATOMIC_UINT32_PTR_(p)      (p)

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/counter.h */

#define NSYNC_COUNTER_H_


/*!BEGIN third_party/nsync/time.h */

#define NSYNC_TIME_H_
COSMOPOLITAN_C_START_

#define NSYNC_TIME_SEC(t)  ((t).tv_sec)
#define NSYNC_TIME_NSEC(t) ((t).tv_nsec)
#define NSYNC_TIME_STATIC_INIT(t, ns) \
  { (t), (ns) }

/* The type nsync_time represents the interval elapsed between two
   moments in time. Often the first such moment is an address-space-wide
   epoch, such as the Unix epoch, but clients should not rely on the
   epoch in one address space being the same as that in another.
   Intervals relative to the epoch are known as absolute times. */
typedef struct timespec nsync_time;

/* A deadline infinitely far in the future. */
#define nsync_time_no_deadline timespec_max

/* The zero delay, or an expired deadline. */
#define nsync_time_zero timespec_zero

/* Return the current time since the epoch.  */
#define nsync_time_now() timespec_real()

/* Sleep for the specified delay. Returns the unslept time which may be
   non-zero if the call was interrupted. */
#define nsync_time_sleep(a) timespec_sleep(a)

/* Sleep until the specified time.  Returns 0 on success, and EINTR
   if the call was interrupted. */
#define nsync_time_sleep_until(a) timespec_sleep_until(a)

/* Return a+b */
#define nsync_time_add(a, b) timespec_add(a, b)

/* Return a-b */
#define nsync_time_sub(a, b) timespec_sub(a, b)

/* Return +ve, 0, or -ve according to whether a>b, a==b, or a<b. */
#define nsync_time_cmp(a, b) timespec_cmp(a, b)

/* Return the specified number of milliseconds as a time. */
#define nsync_time_ms(a) timespec_frommillis(a)

/* Return the specified number of microseconds as a time. */
#define nsync_time_us(a) timespec_frommicros(a)

/* Return the specified number of nanoseconds as a time. */
#define nsync_time_ns(a) timespec_fromnanos(a)

/* Return an nsync_time constructed from second and nanosecond
   components */
#define nsync_time_s_ns(s, ns) ((nsync_time){(int64_t)(s), (unsigned)(ns)})

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/* An nsync_counter represents an unsigned integer that can count up and down,
   and wake waiters when zero.  */
typedef struct nsync_counter_s_ *nsync_counter;

/* Return a freshly allocated nsync_counter with the specified value,
   of NULL if an nsync_counter cannot be created.

   Any non-NULL returned value should be passed to nsync_counter_free() when no
   longer needed.  */
nsync_counter nsync_counter_new(uint32_t value);

/* Free resources associated with c.  Requires that c was allocated by
   nsync_counter_new(), and no concurrent or future operations are applied to
   c.  */
void nsync_counter_free(nsync_counter c);

/* Add delta to c, and return its new value.  It is a checkable runtime error
   to decrement c below 0, or to increment c (i.e., apply a delta > 0) after a
   waiter has waited.  */
uint32_t nsync_counter_add(nsync_counter c, int32_t delta);

/* Return the current value of c.  */
uint32_t nsync_counter_value(nsync_counter c);

/* Wait until c has value 0, or until abs_deadline, then return
   the value of c.  It is a checkable runtime error to increment c after
   a waiter may have been woken due to the counter reaching zero.
   If abs_deadline==nsync_time_no_deadline, the deadline
   is far in the future. */
uint32_t nsync_counter_wait(nsync_counter c, nsync_time abs_deadline);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/cv.h */

#define NSYNC_CV_H_


/*!BEGIN third_party/nsync/mu.h */

#define NSYNC_MU_H_
COSMOPOLITAN_C_START_

/* An nsync_mu is a lock. If initialized to zero, it's valid and unlocked.

   An nsync_mu can be "free", held by a single thread (aka fiber,
   goroutine) in "write" (exclusive) mode, or by many threads in "read"
   (shared) mode. A thread that acquires it should eventually release
   it. It is illegal to acquire an nsync_mu in one thread and release it
   in another. It is illegal for a thread to reacquire an nsync_mu while
   holding it (even a second share of a "read" lock).

   Example usage:

       static struct foo {
         nsync_mu mu; // protects invariant a+b==0 on fields below.
         int a;
         int b;
       } p = { NSYNC_MU_INIT, 0, 0 };
       // ....
       nsync_mu_lock (&p.mu);
       // The current thread now has exclusive access to p.a and p.b;
       // invariant assumed true.
       p.a++;
       p.b--; // restore invariant p.a+p.b==0 before releasing p.mu
       nsync_mu_unlock (&p.mu)

   Mutexes can be used with condition variables; see nsync_cv.h.

   nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. See nsync_mu_wait.h for more details. Example
   use of nsync_mu_wait() to wait for p.a==0, using definition above:

        int a_is_zero (const void *condition_arg) {
                return (((const struct foo *)condition_arg)->a == 0);
        }
        ...
        nsync_mu_lock (&p.mu);
        nsync_mu_wait (&p.mu, &a_is_zero, &p, NULL);
        // The current thread now has exclusive access to
        // p.a and p.b, and p.a==0.
        ...
        nsync_mu_unlock (&p.mu);

*/
typedef struct nsync_mu_s_ {
  nsync_atomic_uint32_ word; /* internal use only */
  int _zero;                 /* c pthread_mutex_t */
  struct Dll *waiters;       /* internal use only */
} nsync_mu;

/* An nsync_mu should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_MU_INIT, or by setting
   the entire structure to all zeroes, or using nsync_mu_init(). */
#define NSYNC_MU_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }
void nsync_mu_init(nsync_mu *mu);

/* Block until *mu is free and then acquire it in writer mode. Requires
   that the calling thread not already hold *mu in any mode. */
void nsync_mu_lock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in write mode by the
   calling thread, and wake waiters, if appropriate. */
void nsync_mu_unlock(nsync_mu *mu);

/* Attempt to acquire *mu in writer mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. */
int nsync_mu_trylock(nsync_mu *mu);

/* Block until *mu can be acquired in reader mode and then acquire it.
   Requires that the calling thread not already hold *mu in any mode. */
void nsync_mu_rlock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in read mode by the calling
   thread, and wake waiters, if appropriate. */
void nsync_mu_runlock(nsync_mu *mu);

/* Attempt to acquire *mu in reader mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. Perhaps fail to acquire if a writer is waiting, to
   avoid starvation. */
int nsync_mu_rtrylock(nsync_mu *mu);

/* May abort if *mu is not held in write mode by the calling thread. */
void nsync_mu_assert_held(const nsync_mu *mu);

/* May abort if *mu is not held in read or write mode
   by the calling thread.  */
void nsync_mu_rassert_held(const nsync_mu *mu);

/* Return whether *mu is held in read mode.
   Requires that the calling thread holds *mu in some mode. */
int nsync_mu_is_reader(const nsync_mu *mu);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

#define NSYNC_CV_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }

struct nsync_note_s_;

/* An nsync_cv is a condition variable in the style of Mesa, Java,
   POSIX, and Go's sync.Cond. It allows a thread to wait for a condition
   on state protected by a mutex, and to proceed with the mutex held and
   the condition true.

   See also nsync_mu_wait() and nsync_mu_wait_with_deadline(), which
   implement conditional critical sections. In many cases, they are
   easier to use than condition variables.

   Usage

   After making the desired predicate true, call:

       nsync_cv_signal (&cv);    // If at most one thread can make use
                                 // of the predicate becoming true.

   or

       nsync_cv_broadcast (&cv); // If multiple threads can make use
                                 // of the predicate becoming true.

   To wait for a predicate with no deadline (assuming
   nsync_cv_broadcast() or nsync_cv_signal() is called whenever the
   predicate becomes true):

       nsync_mu_lock (&mu;)
       while (!some_predicate_protected_by_mu) { // while-loop required
         nsync_cv_wait (&cv, &mu);
       }
       // predicate is now true
       nsync_mu_unlock (&mu);

   To wait for a predicate with a deadline (assuming nsync_cv_broadcast() or
   nsync_cv_signal() is called whenever the predicate becomes true):

       nsync_mu_lock (&mu);
       while (!some_predicate_protected_by_mu &&
         nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                      cancel_note) == 0) {
       }
       if (some_predicate_protected_by_mu) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   or, if the predicate is complex and you wish to write it just once
   and inline, you could use the following instead of the for-loop
   above:

       nsync_mu_lock (&mu);
       int pred_is_true = 0;
       int outcome = 0;
       while (!(pred_is_true = some_predicate_protected_by_mu) &&
              outcome == 0) {
         outcome = nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                                cancel_note);
       }
       if (pred_is_true) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   As the examples show, Mesa-style condition variables require that
   waits use a loop that tests the predicate anew after each wait. It
   may be surprising that these are preferred over the precise wakeups
   offered by the condition variables in Hoare monitors. Imprecise
   wakeups make more efficient use of the critical section, because
   threads can enter it while a woken thread is still emerging from the
   scheduler, which may take thousands of cycles. Further, they make the
   programme easier to read and debug by making the predicate explicit
   locally at the wait, where the predicate is about to be assumed; the
   reader does not have to infer the predicate by examining all the
   places where wakeups may occur. */
typedef struct nsync_cv_s_ {
  /* see bits below */
  nsync_atomic_uint32_ word;
  /* points to tail of list of waiters; under mu. */
  struct Dll *waiters;
} nsync_cv;

/* An nsync_cv should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_CV_INIT, or by setting
   the entire struct to 0, or using nsync_cv_init(). */
void nsync_cv_init(nsync_cv *cv);

/* Wake at least one thread if any are currently blocked on *cv. If the
   chosen thread is a reader on an nsync_mu, wake all readers and, if
   possible, a writer. */
void nsync_cv_signal(nsync_cv *cv);

/* Wake all threads currently blocked on *cv. */
void nsync_cv_broadcast(nsync_cv *cv);

/* Atomically release "mu" (which must be held on entry) and block the
   caller on *cv. Wait until awakened by a call to nsync_cv_signal() or
   nsync_cv_broadcast(), or a spurious wakeup; then reacquire "mu", and
   return. Equivalent to a call to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL. Callers
   should use nsync_cv_wait() in a loop, as with all standard Mesa-style
   condition variables. See examples above. Returns 0 normally, otherwise
   ECANCELED may be returned if calling POSIX thread is cancelled only when
   the PTHREAD_CANCEL_MASKED mode is in play. */
int nsync_cv_wait(nsync_cv *cv, nsync_mu *mu);

/* Atomically release "mu" (which must be held on entry) and block the
   calling thread on *cv. It then waits until awakened by a call to
   nsync_cv_signal() or nsync_cv_broadcast() (or a spurious wakeup), or
   by the time reaching abs_deadline, or by cancel_note being notified.
   In all cases, it reacquires "mu", and returns the reason for the call
   returned (0, ETIMEDOUT, or ECANCELED). Use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no nsync cancellations (however POSIX thread
   cancellations may still happen, and ECANCELED could still be returned
   when the calling thread is cancelled only if PTHREAD_CANCEL_MASKED is
   in play). wait_with_deadline() should be used in a loop, as with all
   Mesa-style condition variables. See examples above.

   There are two reasons for using an absolute deadline, rather than a
   relative timeout---these are why pthread_cond_timedwait() also uses
   an absolute deadline. First, condition variable waits have to be used
   in a loop; with an absolute times, the deadline does not have to be
   recomputed on each iteration. Second, in most real programmes, some
   activity (such as an RPC to a server, or when guaranteeing response
   time in a UI), there is a deadline imposed by the specification or
   the caller/user; relative delays can shift arbitrarily with
   scheduling delays, and so after multiple waits might extend beyond
   the expected deadline. Relative delays tend to be more convenient
   mostly in tests and trivial examples than they are in real
   programmes. */
int nsync_cv_wait_with_deadline(nsync_cv *cv, nsync_mu *mu,
                                nsync_time abs_deadline,
                                struct nsync_note_s_ *cancel_note);

/* Like nsync_cv_wait_with_deadline(), but allow an arbitrary lock *v to be
   used, given its (*lock)(mu) and (*unlock)(mu) routines.  */
int nsync_cv_wait_with_deadline_generic(nsync_cv *cv, void *mu,
                                        void (*lock)(void *),
                                        void (*unlock)(void *),
                                        nsync_time abs_deadline,
                                        struct nsync_note_s_ *cancel_note);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/debug.h */

#define NSYNC_DEBUG_H_
COSMOPOLITAN_C_START_

/* Debugging operations for mutexes and condition variables.

   These operations should not be relied upon for normal functionality.
   The implementation may be slow, output formats may change, and the
   implementation is free to yield the empty string. */

/* Place in buf[0,..,n-1] a nul-terminated, human readable string
   indicative of some of the internal state of the mutex or condition
   variable, and return buf. If n>=4, buffer overflow is indicated by
   placing the characters "..." at the end of the string.

   The *_and_waiters() variants attempt to output the waiter lists in
   addition to the basic state. These variants may acquire internal
   locks and follow internal pointers. Thus, they are riskier if invoked
   in an address space whose overall health is uncertain. */
char *nsync_mu_debug_state(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state(nsync_cv *cv, char *buf, int n);
char *nsync_mu_debug_state_and_waiters(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state_and_waiters(nsync_cv *cv, char *buf, int n);

/* Like nsync_*_debug_state_and_waiters(), but ignoring all locking and
   safety considerations, and using an internal, possibly static buffer
   that may be overwritten by subsequent or concurrent calls to these
   routines. These variants should be used only from an interactive
   debugger, when all other threads are stopped; the debugger is
   expected to recover from errors. */
char *nsync_mu_debugger(nsync_mu *mu);
char *nsync_cv_debugger(nsync_cv *cv);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_semaphore.h */

#define NSYNC_SEM_H_
COSMOPOLITAN_C_START_

typedef struct nsync_semaphore_s_ {
  void *sem_space[3];
} nsync_semaphore;

/* Initialize *s; the initial value is 0. */
void nsync_mu_semaphore_init(nsync_semaphore *s);

/* Wait until the count of *s exceeds 0, and decrement it. */
errno_t nsync_mu_semaphore_p(nsync_semaphore *s);

/* Wait until one of: the count of *s is non-zero, in which case
   decrement *s and return 0; or abs_deadline expires, in which case
   return ETIMEDOUT. */
errno_t nsync_mu_semaphore_p_with_deadline(nsync_semaphore *s,
                                           nsync_time abs_deadline);

/* Ensure that the count of *s is at least 1. */
void nsync_mu_semaphore_v(nsync_semaphore *s);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_wait.h */

#define NSYNC_MU_WAIT_H_
COSMOPOLITAN_C_START_

/* nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. In many straightforward situations they are
   of equivalent performance and are somewhat easier to use, because
   unlike condition variables, they do not require that the waits be
   placed in a loop, and they do not require explicit wakeup calls.
   Example:

   Definitions:

       static nsync_mu mu = NSYNC_MU_INIT;
       static int i = 0;  // protected by mu
       // Condition for use with nsync_mu_wait().
       static int int_is_zero (const void *v) {
         return (*(const int *)v == 0);
       }

   Waiter:

       nsync_mu_lock (&mu);
       // Wait until i is zero.
       nsync_mu_wait (&mu, &int_is_zero, &i, NULL);
       // i is known to be zero here.
       // ...
       nsync_mu_unlock (&mu);

   Thread potentially making i zero:

       nsync_mu_lock (&mu);
       i--;
       // No need to signal that i may have become zero.  The unlock call
       // below will evaluate waiters' conditions to decide which to wake.
       nsync_mu_unlock (&mu);

   It is legal to use conditional critical sections and condition
   variables on the same mutex.

                              --------------

   The implementation benefits from determining whether waiters are
   waiting for the same condition; it may then evaluate a condition once
   on behalf of several waiters. Two waiters have equal condition if
   their "condition" pointers are equal, and either:

     - their "condition_arg" pointers are equal, or

     - "condition_arg_eq" is non-null and (*condition_arg_eq)
       (condition_arg0, condition_arg1) returns non-zero.

   *condition_arg_eq will not be invoked unless the "condition" pointers
   are equal, and the "condition_arg" pointers are unequal.

   If many waiters wait for distinct conditions simultaneously,
   condition variables may be faster.
 */

struct nsync_note_s_; /* forward declaration for an nsync_note */

/* Return when (*condition) (condition_arg) is true. Perhaps unlock and
   relock *mu while blocked waiting for the condition to become true.
   nsync_mu_wait() is equivalent to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL.

   Requires that *mu be held on entry. See nsync_mu_wait_with_deadline()
   for more details on *condition and *condition_arg_eq. */
void nsync_mu_wait(nsync_mu *mu, int (*condition)(const void *condition_arg),
                   const void *condition_arg,
                   int (*condition_arg_eq)(const void *a, const void *b));

/* Return when at least one of: (*condition) (condition_arg) is true,
   the deadline expires, or *cancel_note is notified. Perhaps unlock and
   relock *mu while blocked waiting for one of these events, but always
   return with *mu held. Return 0 iff the (*condition) (condition_arg)
   is true on return, and otherwise either ETIMEDOUT or ECANCELED,
   depending on why the call returned early. Callers should use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no cancellation.

   Requires that *mu be held on entry.

   The implementation may call *condition from any thread using the
   mutex, and while holding *mu in either read or write mode; it
   guarantees that any thread calling *condition will hold *mu in some
   mode. Requires that (*condition) (condition_arg) neither modify state
   protected by *mu, nor return a value dependent on state not protected
   by *mu. To depend on time, use the abs_deadline parameter.
   (Conventional use of condition variables have the same restrictions
   on the conditions tested by the while-loop.) If non-null,
   condition_arg_eq should return whether two condition_arg calls with
   the same "condition" pointer are considered equivalent; it should
   have no side-effects. */
int nsync_mu_wait_with_deadline(
    nsync_mu *mu, int (*condition)(const void *condition_arg),
    const void *condition_arg,
    int (*condition_arg_eq)(const void *a, const void *b),
    nsync_time abs_deadline, struct nsync_note_s_ *cancel_note);

/* Unlock *mu, which must be held in write mode, and wake waiters, if
   appropriate. Unlike nsync_mu_unlock(), this call is not required to
   wake nsync_mu_wait/nsync_mu_wait_with_deadline calls on conditions
   that were false before this thread acquired the lock. This call
   should be used only at the end of critical sections for which:
   - nsync_mu_wait and/or nsync_mu_wait_with_deadline are in use on the same
     mutex,
   - this critical section cannot make the condition true for any of those
     nsync_mu_wait/nsync_mu_wait_with_deadline waits, and
   - when performance is significantly improved by using this call. */
void nsync_mu_unlock_without_wakeup(nsync_mu *mu);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/note.h */

#define NSYNC_NOTE_H_
COSMOPOLITAN_C_START_

/* An nsync_note represents a single bit that can transition from 0 to 1
   at most once. When 1, the note is said to be notified. There are
   operations to wait for the transition, which can be triggered either
   by an explicit call, or timer expiry. Notes can have parent notes; a
   note becomes notified if its parent becomes notified. */
typedef struct nsync_note_s_ *nsync_note;

/* Return a freshly allocated nsync_note, or NULL if an nsync_note
   cannot be created.

   If parent!=NULL, the allocated nsync_note's parent will be parent.
   The newaly allocated note will be automatically notified at
   abs_deadline, and is notified at initialization if
   abs_deadline==nsync_zero_time.

   nsync_notes should be passed to nsync_note_free() when no longer needed. */
nsync_note nsync_note_new(nsync_note parent, nsync_time abs_deadline);

/* Free resources associated with n. Requires that n was allocated by
   nsync_note_new(), and no concurrent or future operations are applied
   to n directly.

   It is legal to call nsync_note_free() on a node even if it has a
   parent or children that are in use; if n has both a parent and
   children, n's parent adopts its children. */
void nsync_note_free(nsync_note n);

/* Notify n and all its descendants. */
void nsync_note_notify(nsync_note n);

/* Return whether n has been notified.  */
int nsync_note_is_notified(nsync_note n);

/* Wait until n has been notified or abs_deadline is reached, and return
   whether n has been notified. If abs_deadline==nsync_time_no_deadline,
   the deadline is far in the future. */
int nsync_note_wait(nsync_note n, nsync_time abs_deadline);

/* Return the expiry time associated with n. This is the minimum of the
   abs_deadline passed on creation and that of any of its ancestors. */
nsync_time nsync_note_expiry(nsync_note n);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/once.h */

#define NSYNC_ONCE_H_
COSMOPOLITAN_C_START_

/* An nsync_once allows a function to be called exactly once, when first
   referenced. */
typedef nsync_atomic_uint32_ nsync_once;

/* An initializer for nsync_once; it is guaranteed to be all zeroes. */
#define NSYNC_ONCE_INIT NSYNC_ATOMIC_UINT32_INIT_

/* The first time nsync_run_once() or nsync_run_once_arg() is applied to
   *once, the supplied function is run (with argument, in the case of
   nsync_run_once_arg()). Other callers will wait until the run of the
   function is complete, and then return without running the function
   again. */
void nsync_run_once(nsync_once *once, void (*f)(void));
void nsync_run_once_arg(nsync_once *once, void (*farg)(void *arg), void *arg);

/* Same as nsync_run_once()/nsync_run_once_arg() but uses a spinloop.
   Can be used on the same nsync_once as
   nsync_run_once/nsync_run_once_arg().

   These *_spin variants should be used only in contexts where normal
   blocking is disallowed, such as within user-space schedulers, when
   the runtime is not fully initialized, etc. They provide no
   significant performance benefit, and they should be avoided in normal
   code. */
void nsync_run_once_spin(nsync_once *once, void (*f)(void));
void nsync_run_once_arg_spin(nsync_once *once, void (*farg)(void *arg),
                             void *arg);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/waiter.h */

#define NSYNC_WAITER_H_
COSMOPOLITAN_C_START_

/* nsync_wait_n() allows the client to wait on multiple objects
   (condition variables, nsync_notes, nsync_counters, etc.) until at
   least one of them becomes ready, or a deadline expires.

   It can be thought of as rather like Unix's select() or poll(), except
   the the objects being waited for are synchronization data structures,
   rather than file descriptors.

   The client can construct new objects that can be waited for by
   implementing three routines.

   Examples:

   To wait on two nsync_notes n0, n1, and a nsync_counter c0, with a
   deadline of abs_deadline:

       // Form an array of struct nsync_waitable_s, identifying the
       // objects and the corresponding descriptors. (Static
       // initialization syntax is used for brevity.)
       static struct nsync_waitable_s w[] = {
         { &n0, &nsync_note_waitable_funcs },
         { &n1, &nsync_note_waitable_funcs },
         { &c0, &nsync_counter_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1], &w[2] };
       int n = sizeof (w) / sizeof (w[0]);

       // Wait. The mu, lock, and unlock arguments are NULL because no
       // condition variables are invovled.
       int i = nsync_wait_n (NULL, NULL, NULL, abs_deadline, n, pw);
       if (i == n) {
         // timeout
       } else {
         // w[i].v became ready.
       }

    To wait on multiple condition variables, the mu/lock/unlock
    parameters are used. Imagine cv0 and cv1 are signalled when
    predicates pred0() (under lock mu0) and pred1() (under lock mu1)
    become true respectively. Assume that mu0 is acquired before mu1.

       static void lock2 (void *v) {  // lock two mutexes in order
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_lock (mu[0]);
         nsync_mu_lock (mu[1]);
       }
       static void unlock2 (void *v) { // unlock two mutexes.
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_unlock (mu[1]);
         nsync_mu_unlock (mu[0]);
       }

       // Describe the condition variables and the locks.
       static struct nsync_waitable_s w[] = {
         { &cv0, &nsync_cv_waitable_funcs },
         { &cv1, &nsync_cv_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1] };
       nsync_mu *lock_list[] = { &mu0, &mu1 };
       int n = sizeof (w) / sizeof (w[0]);

       lock2 (list_list);
       while (!pred0 () && !pred1 ()) {
         // Wait for one of the condition variables to be signalled,
         // with no timeout.
         nsync_wait_n (lock_list, &lock2, &unlock2,
                       nsync_time_no_deadline, n, pw);
       }
       if (pred0 ()) { ... }
       if (pred1 ()) { ... }
       unlock2 (list_list);

   */

/* forward declaration of struct that contains type dependent wait
   operations */
struct nsync_waitable_funcs_s;

/* Clients wait on objects by forming an array of struct
   nsync_waitable_s. Each each element points to one object and its
   type-dependent functions. */
struct nsync_waitable_s {
  /* pointer to object */
  void *v;
  /* pointer to type-dependent functions. Use
     &nsync_note_waitable_funcs for an nsync_note,
     &nsync_counternote_waitable_funcs for an nsync_counter,
     &nsync_cv_waitable_funcs for an nsync_cv. */
  const struct nsync_waitable_funcs_s *funcs;
};

/* Wait until at least one of *waitable[0,..,count-1] is has been
   notified, or abs_deadline is reached. Return the index of the
   notified element of waitable[], or count if no such element exists.
   If mu!=NULL, (*unlock)(mu) is called after the thread is queued on
   the various waiters, and (*lock)(mu) is called before return;
   mu/lock/unlock are used to acquire and release the relevant locks
   whan waiting on condition variables. */
int nsync_wait_n(void *mu, void (*lock)(void *), void (*unlock)(void *),
                 nsync_time abs_deadline, int count,
                 struct nsync_waitable_s *waitable[]);

/* A "struct nsync_waitable_s" implementation must implement these
   functions. Clients should ignore the internals. */
struct nsync_waiter_s;
struct nsync_waitable_funcs_s {

  /* Return the time when *v will be ready (max time if unknown), or 0
     if it is already ready. The parameter nw may be passed as NULL, in
     which case the result should indicate whether the thread would
     block if it were to wait on *v. All calls with the same *v must
     report the same result until the object becomes ready, from which
     point calls must report 0. */
  nsync_time (*ready_time)(void *v, struct nsync_waiter_s *nw);

  /* If *v is ready, return zero; otherwise enqueue *nw on *v and return
     non-zero. */
  int (*enqueue)(void *v, struct nsync_waiter_s *nw);

  /* If nw has been previously dequeued, return zero; otherwise dequeue
   *nw from *v and return non-zero.  */
  int (*dequeue)(void *v, struct nsync_waiter_s *nw);
};

/* The "struct nsync_waitable_s" for nsync_note, nsync_counter, and nsync_cv. */
extern const struct nsync_waitable_funcs_s nsync_note_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_counter_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_cv_waitable_funcs;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/avx512.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
COSMOPOLITAN_C_START_

union XedAvx512Payload1 {
  struct {
    unsigned map : 4;
    unsigned rr_inv : 1;
    unsigned b_inv : 1;
    unsigned x_inv : 1;
    unsigned r_inv : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload2 {
  struct {
    unsigned pp : 2;
    unsigned ubit : 1;
    unsigned vexdest210 : 3;
    unsigned vexdest3 : 1;
    unsigned rexw : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload3 {
  struct {
    unsigned mask : 3;
    unsigned vexdest4p : 1;
    unsigned bcrc : 1;
    unsigned llrc : 2;
    unsigned z : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/private.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_PRIVATE_H_


/*!BEGIN third_party/xed/x86.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86_H_
/*           ▓▓▓▓▓▓▓▓▓▓▓▓▓                      ▄▄▄▄
             ▓▓▓▓▓▓▓▓▓▓▓▓▓     ▄▓▓▓▓▓▓▄      ▄▓▓▓▓▓▓▓▓            ▄▓▓▓▀
             ▓▓▓▓    ▓▓▓▓▓    ▓     ▓▓▓▓    ▓▓       ▓▓▓      ▄▓▓▓▓
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▬▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▬▬▬▬▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓     ▓▓▓▄     ▓▓▓   ▓▓▓▓             │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▀▓▓▓▓▄▄▄▓▓▓▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓▓▓▄   ▄▄▓▓▓▓▓▓▓▓▓  ▓▓▓▓      ▓▓▓▄    │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▄▄▓▓▀  ▀▀▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬║▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▓▓▓ ▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬║▬▬▬
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▓▓▓▓▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
■■■■■■■■║■■■■▓▓▓▓    ▓▓▓▓▓■■■▓▓▓▄▄▄▓▓▓▓■■■■▬▓▓▓▓▄▄▄▄▓▓▓■■■■▬▓▓▓▓▄▄▄▓▓▓▓▀■■■■║■■■
■■■■■■■■■■■■■▓▓▓▓▓▓▓▓▓▓▓▓▓■■■■■▀▓▓▓■■■■■■■■■■■■■■▀▀■■■■■■■■■■■■▀▓▓▀■■■■■■■■■■■■■
        ║▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓║
╔───────╨───────────────────────────────────────────────────────────────────╨──╗
│ cosmopolitan § virtual machine » byte code language                          │
╚─────────────────────────────────────────────────────────────────────────────*/

#define XED_MAX_INSTRUCTION_BYTES 15

#define XED_MODE_REAL   0
#define XED_MODE_LEGACY 1
#define XED_MODE_LONG   2

#define XED_HINT_NTAKEN 2
#define XED_HINT_TAKEN  4
#define XED_HINT_ALTER  6

#define XED_SEG_ES 1
#define XED_SEG_CS 2
#define XED_SEG_SS 3
#define XED_SEG_DS 4
#define XED_SEG_FS 5
#define XED_SEG_GS 6

#define xed_modrm_mod(M)           (((M)&0xff) >> 6)
#define xed_modrm_reg(M)           (((M)&0b00111000) >> 3)
#define xed_modrm_rm(M)            ((M)&7)
#define xed_sib_base(M)            ((M)&7)
#define xed_sib_index(M)           (((M)&0b00111000) >> 3)
#define xed_sib_scale(M)           (((M)&0xff) >> 6)
#define xed_get_modrm_reg_field(M) (((M)&0x38) >> 3)

COSMOPOLITAN_C_START_

#define XED_MACHINE_MODE_REAL           XED_MODE_REAL
#define XED_MACHINE_MODE_LEGACY_32      XED_MODE_LEGACY
#define XED_MACHINE_MODE_LONG_64        XED_MODE_LONG
#define XED_MACHINE_MODE_UNREAL         (1 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LEGACY_16      (2 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_16 (3 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_32 (4 << 2 | XED_MODE_LEGACY)
#define XED_MACHINE_MODE_LAST           (XED_MACHINE_MODE_LONG_COMPAT_32 + 1)

#define XED_ERROR_NONE                         0
#define XED_ERROR_BUFFER_TOO_SHORT             1
#define XED_ERROR_GENERAL_ERROR                2
#define XED_ERROR_INVALID_FOR_CHIP             3
#define XED_ERROR_BAD_REGISTER                 4
#define XED_ERROR_BAD_LOCK_PREFIX              5
#define XED_ERROR_BAD_REP_PREFIX               6
#define XED_ERROR_BAD_LEGACY_PREFIX            7
#define XED_ERROR_BAD_REX_PREFIX               8
#define XED_ERROR_BAD_EVEX_UBIT                9
#define XED_ERROR_BAD_MAP                      10
#define XED_ERROR_BAD_EVEX_V_PRIME             11
#define XED_ERROR_BAD_EVEX_Z_NO_MASKING        12
#define XED_ERROR_NO_OUTPUT_POINTER            13
#define XED_ERROR_NO_AGEN_CALL_BACK_REGISTERED 14
#define XED_ERROR_BAD_MEMOP_INDEX              15
#define XED_ERROR_CALLBACK_PROBLEM             16
#define XED_ERROR_GATHER_REGS                  17
#define XED_ERROR_INSTR_TOO_LONG               18
#define XED_ERROR_INVALID_MODE                 19
#define XED_ERROR_BAD_EVEX_LL                  20
#define XED_ERROR_UNIMPLEMENTED                21
#define XED_ERROR_LAST                         22

#define XED_ADDRESS_WIDTH_INVALID 0
#define XED_ADDRESS_WIDTH_16b     2
#define XED_ADDRESS_WIDTH_32b     4
#define XED_ADDRESS_WIDTH_64b     8
#define XED_ADDRESS_WIDTH_LAST    9

#define XED_ILD_MAP0        0 /* 8086+  ... */
#define XED_ILD_MAP1        1 /* 286+   0x0F,... */
#define XED_ILD_MAP2        2 /* Core2+ 0x0F,0x38,... */
#define XED_ILD_MAP3        3 /* Core2+ 0x0F,0x3A,... */
#define XED_ILD_MAP4        4
#define XED_ILD_MAP5        5
#define XED_ILD_MAP6        6
#define XED_ILD_MAPAMD      7
#define XED_ILD_MAP_XOP8    8
#define XED_ILD_MAP_XOP9    9
#define XED_ILD_MAP_XOPA    10
#define XED_ILD_MAP_LAST    11
#define XED_ILD_MAP_INVALID 12

struct XedOperands { /*
  ┌rep
  │ ┌log₂𝑏
  │ │ ┌mode
  │ │ │ ┌eamode
  │ │ │ │ ┌mod
  │ │ │ │ │
  │ │ │ │ │  ┌sego
  │ │ │ │ │  │
  │ │ │ │ │  │   ┌rex         REGISTER
  │ │ │ │ │  │   │┌rexb       DISPATCH
  │ │ │ │ │  │   ││┌srm       ENCODING
  │ │ │ │ │  │   │││  ┌rex
  │ │ │ │ │  │   │││  │┌rexb
  │ │ │ │ │  │   │││  ││┌rm
  │ │ │ │ │  │   │││  │││  ┌rexw
  │ │ │ │ │  │   │││  │││  │┌osz
  │ │ │ │ │  │   │││  │││  ││┌rex
  │ │ │ │ │  │   │││  │││  │││┌rexr
  │ │ │ │ │  │   │││  │││  ││││┌reg
  │3│2│2│2│2 │   │││  │││  │││││
  │0│8│6│4│2 │18 │││12│││ 7│││││ 0
  ├┐├┐├┐├┐├┐ ├─┐ ││├─┐││├─┐││││├─┐
  00000000000000000000000000000000*/
  uint32_t rde;
  union {
    struct {
      union {
        uint8_t opcode;
        uint8_t srm : 3;
      };
      uint8_t map : 4;
    };
    uint16_t dispatch;
  };
  union {
    uint8_t sib;
    struct {
      uint8_t base : 3;
      uint8_t index : 3;
      uint8_t scale : 2;
    };
  };
  bool osz : 1;   /* operand size override prefix */
  bool rexw : 1;  /* rex.w or rex.wb or etc. 64-bit override */
  bool rexb : 1;  /* rex.b or rex.wb or etc. see modrm table */
  bool rexr : 1;  /* rex.r or rex.wr or etc. see modrm table */
  bool rex : 1;   /* any rex prefix including rex */
  bool rexx : 1;  /* rex.x or rex.wx or etc. see sib table */
  bool rexrr : 1; /* evex */
  bool asz : 1;   /* address size override */
  int64_t disp;   /* displacement(%xxx) mostly sign-extended */
  uint64_t uimm0; /* $immediate mostly sign-extended */
  bool out_of_bytes : 1;
  bool is_intel_specific : 1;
  bool ild_f2 : 1;
  bool ild_f3 : 1;
  bool has_sib : 1;
  bool realmode : 1;
  bool amd3dnow : 1;
  bool lock : 1;
  union {
    uint8_t modrm; /* selects address register */
    struct {
      uint8_t rm : 3;
      uint8_t reg : 3;
      uint8_t mod : 2;
    };
  };
  uint8_t max_bytes;
  uint8_t rep : 2; /* 0, 2 (0xf2 repnz), 3 (0xf3 rep/repe) */
  uint8_t has_modrm : 2;
  bool imm_signed : 1;       /* internal */
  bool disp_unsigned : 1;    /* internal */
  uint8_t seg_ovd : 3;       /* XED_SEG_xx */
  uint8_t error : 5;         /* enum XedError */
  uint8_t mode : 2;          /* real,legacy,long */
  uint8_t hint : 3;          /* static branch prediction */
  uint8_t uimm1;             /* enter $x,$y */
  uint8_t disp_width;        /* in bits */
  uint8_t imm_width;         /* in bits */
  uint8_t mode_first_prefix; /* see xed_set_chip_modes() */
  uint8_t nrexes;
  uint8_t nprefixes;
  uint8_t nseg_prefixes;
  uint8_t ubit;       /* vex */
  uint8_t vexvalid;   /* vex */
  uint8_t vexdest3;   /* vex */
  uint8_t vexdest4;   /* vex */
  uint8_t vexdest210; /* vex */
  uint8_t vex_prefix; /* vex */
  uint8_t zeroing;    /* evex */
  uint8_t bcrc;       /* evex */
  uint8_t llrc;       /* evex */
  uint8_t vl;         /* evex */
  uint8_t mask;       /* evex */
  uint8_t imm1_bytes; /* evex */
  uint8_t pos_disp;
  uint8_t pos_imm;
  uint8_t pos_imm1;
  uint8_t pos_modrm;
  uint8_t pos_opcode;
  uint8_t pos_sib;
};

struct XedDecodedInst {
  unsigned char length;
  uint8_t bytes[15];
  struct XedOperands op;
};

#define xed_operands_set_mode(p, machine_mode) \
  do {                                         \
    struct XedOperands *__p = p;               \
    __p->realmode = false;                     \
    switch (machine_mode) {                    \
      default:                                 \
      case XED_MACHINE_MODE_LONG_64:           \
        __p->mode = XED_MODE_LONG;             \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_32:         \
      case XED_MACHINE_MODE_LONG_COMPAT_32:    \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_REAL:              \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
      case XED_MACHINE_MODE_UNREAL:            \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_16:         \
      case XED_MACHINE_MODE_LONG_COMPAT_16:    \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
    }                                          \
  } while (0)

extern const char kXedErrorNames[];
extern const uint8_t kXedEamode[2][3];

struct XedDecodedInst *xed_decoded_inst_zero_set_mode(struct XedDecodedInst *,
                                                      int);
int xed_instruction_length_decode(struct XedDecodedInst *, const void *,
                                  size_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef int xed_int_t;
typedef unsigned int xed_uint_t;
typedef unsigned int xed_uint_t;
typedef unsigned char xed_bits_t;
typedef intptr_t xed_addr_t;
typedef bool xed_bool_t;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/x86isa.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_
COSMOPOLITAN_C_START_

#define XED_CHIP_INVALID           1
#define XED_CHIP_I86               2
#define XED_CHIP_I86FP             3
#define XED_CHIP_I186              4
#define XED_CHIP_I186FP            5
#define XED_CHIP_I286REAL          6
#define XED_CHIP_I286              7
#define XED_CHIP_I2186FP           8
#define XED_CHIP_I386REAL          9
#define XED_CHIP_I386              10
#define XED_CHIP_I386FP            11
#define XED_CHIP_I486REAL          12
#define XED_CHIP_I486              13
#define XED_CHIP_PENTIUMREAL       14
#define XED_CHIP_PENTIUM           15
#define XED_CHIP_QUARK             16
#define XED_CHIP_PENTIUMMMXREAL    17
#define XED_CHIP_PENTIUMMMX        18
#define XED_CHIP_ALLREAL           19
#define XED_CHIP_PENTIUMPRO        20
#define XED_CHIP_PENTIUM2          21
#define XED_CHIP_PENTIUM3          22
#define XED_CHIP_PENTIUM4          23
#define XED_CHIP_P4PRESCOTT        24
#define XED_CHIP_P4PRESCOTT_NOLAHF 25
#define XED_CHIP_P4PRESCOTT_VTX    26
#define XED_CHIP_CORE2             27
#define XED_CHIP_PENRYN            28
#define XED_CHIP_PENRYN_E          29
#define XED_CHIP_NEHALEM           30
#define XED_CHIP_WESTMERE          31
#define XED_CHIP_BONNELL           32
#define XED_CHIP_SALTWELL          33
#define XED_CHIP_SILVERMONT        34
#define XED_CHIP_AMD               35
#define XED_CHIP_GOLDMONT          36
#define XED_CHIP_GOLDMONT_PLUS     37
#define XED_CHIP_TREMONT           38
#define XED_CHIP_SANDYBRIDGE       39
#define XED_CHIP_IVYBRIDGE         40
#define XED_CHIP_HASWELL           41
#define XED_CHIP_BROADWELL         42
#define XED_CHIP_SKYLAKE           43
#define XED_CHIP_SKYLAKE_SERVER    44
#define XED_CHIP_CASCADE_LAKE      45
#define XED_CHIP_KNL               46
#define XED_CHIP_KNM               47
#define XED_CHIP_CANNONLAKE        48
#define XED_CHIP_ICELAKE           49
#define XED_CHIP_ICELAKE_SERVER    50
#define XED_CHIP_FUTURE            51
#define XED_CHIP_ALL               52
#define XED_CHIP_LAST              53

#define XED_ISA_SET_INVALID               0
#define XED_ISA_SET_3DNOW                 1
#define XED_ISA_SET_ADOX_ADCX             2
#define XED_ISA_SET_AES                   3
#define XED_ISA_SET_AMD                   4
#define XED_ISA_SET_AVX                   5
#define XED_ISA_SET_AVX2                  6
#define XED_ISA_SET_AVX2GATHER            7
#define XED_ISA_SET_AVX512BW_128          8
#define XED_ISA_SET_AVX512BW_128N         9
#define XED_ISA_SET_AVX512BW_256          10
#define XED_ISA_SET_AVX512BW_512          11
#define XED_ISA_SET_AVX512BW_KOP          12
#define XED_ISA_SET_AVX512CD_128          13
#define XED_ISA_SET_AVX512CD_256          14
#define XED_ISA_SET_AVX512CD_512          15
#define XED_ISA_SET_AVX512DQ_128          16
#define XED_ISA_SET_AVX512DQ_128N         17
#define XED_ISA_SET_AVX512DQ_256          18
#define XED_ISA_SET_AVX512DQ_512          19
#define XED_ISA_SET_AVX512DQ_KOP          20
#define XED_ISA_SET_AVX512DQ_SCALAR       21
#define XED_ISA_SET_AVX512ER_512          22
#define XED_ISA_SET_AVX512ER_SCALAR       23
#define XED_ISA_SET_AVX512F_128           24
#define XED_ISA_SET_AVX512F_128N          25
#define XED_ISA_SET_AVX512F_256           26
#define XED_ISA_SET_AVX512F_512           27
#define XED_ISA_SET_AVX512F_KOP           28
#define XED_ISA_SET_AVX512F_SCALAR        29
#define XED_ISA_SET_AVX512PF_512          30
#define XED_ISA_SET_AVX512_4FMAPS_512     31
#define XED_ISA_SET_AVX512_4FMAPS_SCALAR  32
#define XED_ISA_SET_AVX512_4VNNIW_512     33
#define XED_ISA_SET_AVX512_BITALG_128     34
#define XED_ISA_SET_AVX512_BITALG_256     35
#define XED_ISA_SET_AVX512_BITALG_512     36
#define XED_ISA_SET_AVX512_GFNI_128       37
#define XED_ISA_SET_AVX512_GFNI_256       38
#define XED_ISA_SET_AVX512_GFNI_512       39
#define XED_ISA_SET_AVX512_IFMA_128       40
#define XED_ISA_SET_AVX512_IFMA_256       41
#define XED_ISA_SET_AVX512_IFMA_512       42
#define XED_ISA_SET_AVX512_VAES_128       43
#define XED_ISA_SET_AVX512_VAES_256       44
#define XED_ISA_SET_AVX512_VAES_512       45
#define XED_ISA_SET_AVX512_VBMI2_128      46
#define XED_ISA_SET_AVX512_VBMI2_256      47
#define XED_ISA_SET_AVX512_VBMI2_512      48
#define XED_ISA_SET_AVX512_VBMI_128       49
#define XED_ISA_SET_AVX512_VBMI_256       50
#define XED_ISA_SET_AVX512_VBMI_512       51
#define XED_ISA_SET_AVX512_VNNI_128       52
#define XED_ISA_SET_AVX512_VNNI_256       53
#define XED_ISA_SET_AVX512_VNNI_512       54
#define XED_ISA_SET_AVX512_VPCLMULQDQ_128 55
#define XED_ISA_SET_AVX512_VPCLMULQDQ_256 56
#define XED_ISA_SET_AVX512_VPCLMULQDQ_512 57
#define XED_ISA_SET_AVX512_VPOPCNTDQ_128  58
#define XED_ISA_SET_AVX512_VPOPCNTDQ_256  59
#define XED_ISA_SET_AVX512_VPOPCNTDQ_512  60
#define XED_ISA_SET_AVXAES                61
#define XED_ISA_SET_AVX_GFNI              62
#define XED_ISA_SET_BMI1                  63
#define XED_ISA_SET_BMI2                  64
#define XED_ISA_SET_CET                   65
#define XED_ISA_SET_CLDEMOTE              66
#define XED_ISA_SET_CLFLUSHOPT            67
#define XED_ISA_SET_CLFSH                 68
#define XED_ISA_SET_CLWB                  69
#define XED_ISA_SET_CLZERO                70
#define XED_ISA_SET_CMOV                  71
#define XED_ISA_SET_CMPXCHG16B            72
#define XED_ISA_SET_F16C                  73
#define XED_ISA_SET_FAT_NOP               74
#define XED_ISA_SET_FCMOV                 75
#define XED_ISA_SET_FMA                   76
#define XED_ISA_SET_FMA4                  77
#define XED_ISA_SET_FXSAVE                78
#define XED_ISA_SET_FXSAVE64              79
#define XED_ISA_SET_GFNI                  80
#define XED_ISA_SET_I186                  81
#define XED_ISA_SET_I286PROTECTED         82
#define XED_ISA_SET_I286REAL              83
#define XED_ISA_SET_I386                  84
#define XED_ISA_SET_I486                  85
#define XED_ISA_SET_I486REAL              86
#define XED_ISA_SET_I86                   87
#define XED_ISA_SET_INVPCID               88
#define XED_ISA_SET_LAHF                  89
#define XED_ISA_SET_LONGMODE              90
#define XED_ISA_SET_LZCNT                 91
#define XED_ISA_SET_MONITOR               92
#define XED_ISA_SET_MONITORX              93
#define XED_ISA_SET_MOVBE                 94
#define XED_ISA_SET_MOVDIR                95
#define XED_ISA_SET_MPX                   96
#define XED_ISA_SET_PAUSE                 97
#define XED_ISA_SET_PCLMULQDQ             98
#define XED_ISA_SET_PCONFIG               99
#define XED_ISA_SET_PENTIUMMMX            100
#define XED_ISA_SET_PENTIUMREAL           101
#define XED_ISA_SET_PKU                   102
#define XED_ISA_SET_POPCNT                103
#define XED_ISA_SET_PPRO                  104
#define XED_ISA_SET_PREFETCHW             105
#define XED_ISA_SET_PREFETCHWT1           106
#define XED_ISA_SET_PREFETCH_NOP          107
#define XED_ISA_SET_PT                    108
#define XED_ISA_SET_RDPID                 109
#define XED_ISA_SET_RDPMC                 110
#define XED_ISA_SET_RDRAND                111
#define XED_ISA_SET_RDSEED                112
#define XED_ISA_SET_RDTSCP                113
#define XED_ISA_SET_RDWRFSGS              114
#define XED_ISA_SET_RTM                   115
#define XED_ISA_SET_SGX                   116
#define XED_ISA_SET_SGX_ENCLV             117
#define XED_ISA_SET_SHA                   118
#define XED_ISA_SET_SMAP                  119
#define XED_ISA_SET_SMX                   120
#define XED_ISA_SET_SSE                   121
#define XED_ISA_SET_SSE2                  122
#define XED_ISA_SET_SSE2MMX               123
#define XED_ISA_SET_SSE3                  124
#define XED_ISA_SET_SSE3X87               125
#define XED_ISA_SET_SSE4                  126
#define XED_ISA_SET_SSE42                 127
#define XED_ISA_SET_SSE4A                 128
#define XED_ISA_SET_SSEMXCSR              129
#define XED_ISA_SET_SSE_PREFETCH          130
#define XED_ISA_SET_SSSE3                 131
#define XED_ISA_SET_SSSE3MMX              132
#define XED_ISA_SET_SVM                   133
#define XED_ISA_SET_TBM                   134
#define XED_ISA_SET_VAES                  135
#define XED_ISA_SET_VMFUNC                136
#define XED_ISA_SET_VPCLMULQDQ            137
#define XED_ISA_SET_VTX                   138
#define XED_ISA_SET_WAITPKG               139
#define XED_ISA_SET_WBNOINVD              140
#define XED_ISA_SET_X87                   141
#define XED_ISA_SET_XOP                   142
#define XED_ISA_SET_XSAVE                 143
#define XED_ISA_SET_XSAVEC                144
#define XED_ISA_SET_XSAVEOPT              145
#define XED_ISA_SET_XSAVES                146
#define XED_ISA_SET_LAST                  147

struct XedChipFeatures {
  uint64_t f[3];
};

#define xed_set_chip_modes(d, chip)    \
  do {                                 \
    struct XedDecodedInst *__d = d;    \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
        break;                         \
      case XED_CHIP_I86:               \
      case XED_CHIP_I86FP:             \
      case XED_CHIP_I186:              \
      case XED_CHIP_I186FP:            \
      case XED_CHIP_I286REAL:          \
      case XED_CHIP_I286:              \
      case XED_CHIP_I2186FP:           \
      case XED_CHIP_I386REAL:          \
      case XED_CHIP_I386:              \
      case XED_CHIP_I386FP:            \
      case XED_CHIP_I486REAL:          \
      case XED_CHIP_I486:              \
      case XED_CHIP_QUARK:             \
      case XED_CHIP_PENTIUM:           \
      case XED_CHIP_PENTIUMREAL:       \
      case XED_CHIP_PENTIUMMMX:        \
      case XED_CHIP_PENTIUMMMXREAL:    \
        __d->op.mode_first_prefix = 1; \
        break;                         \
      default:                         \
        break;                         \
    }                                  \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
      case XED_CHIP_ALL:               \
      case XED_CHIP_AMD:               \
        break;                         \
      default:                         \
        __d->op.is_intel_specific = 1; \
        break;                         \
    }                                  \
  } while (0)

extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];

bool xed_test_chip_features(struct XedChipFeatures *, int);
void xed_get_chip_features(struct XedChipFeatures *, int);
bool xed_isa_set_is_valid_for_chip(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/blake2.h */

#define COSMOPOLITAN_LIBC_STR_BLAKE2_H_

#define BLAKE2B256_DIGEST_LENGTH 32
#define BLAKE2B_CBLOCK           128

#define BLAKE2B256_Init    __BLAKE2B256_Init
#define BLAKE2B256_Update  __BLAKE2B256_Update
#define BLAKE2B256_Process __BLAKE2B256_Process
#define BLAKE2B256_Final   __BLAKE2B256_Final
#define BLAKE2B256         __BLAKE2B256

COSMOPOLITAN_C_START_

struct Blake2b {
  uint64_t h[8];
  uint64_t t_low;
  uint64_t t_high;
  union {
    uint8_t bytes[BLAKE2B_CBLOCK];
    uint64_t words[16];
  } block;
  size_t block_used;
};

int BLAKE2B256_Init(struct Blake2b *);
int BLAKE2B256_Update(struct Blake2b *, const void *, size_t);
int BLAKE2B256_Process(struct Blake2b *, const uint64_t[BLAKE2B_CBLOCK / 8]);
int BLAKE2B256_Final(struct Blake2b *, uint8_t[BLAKE2B256_DIGEST_LENGTH]);
int BLAKE2B256(const void *, size_t, uint8_t[BLAKE2B256_DIGEST_LENGTH]);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/highwayhash64.h */

#define COSMOPOLITAN_LIBC_STR_HIGHWAYHASH64_H_
COSMOPOLITAN_C_START_

uint64_t HighwayHash64(const void *, size_t, const uint64_t[4]) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/langinfo.h */

#define COSMOPOLITAN_LIBC_STR_LANGINFO_H_
COSMOPOLITAN_C_START_

#define ABDAY_1 0x20000
#define ABDAY_2 0x20001
#define ABDAY_3 0x20002
#define ABDAY_4 0x20003
#define ABDAY_5 0x20004
#define ABDAY_6 0x20005
#define ABDAY_7 0x20006

#define DAY_1 0x20007
#define DAY_2 0x20008
#define DAY_3 0x20009
#define DAY_4 0x2000A
#define DAY_5 0x2000B
#define DAY_6 0x2000C
#define DAY_7 0x2000D

#define ABMON_1  0x2000E
#define ABMON_2  0x2000F
#define ABMON_3  0x20010
#define ABMON_4  0x20011
#define ABMON_5  0x20012
#define ABMON_6  0x20013
#define ABMON_7  0x20014
#define ABMON_8  0x20015
#define ABMON_9  0x20016
#define ABMON_10 0x20017
#define ABMON_11 0x20018
#define ABMON_12 0x20019

#define MON_1  0x2001A
#define MON_2  0x2001B
#define MON_3  0x2001C
#define MON_4  0x2001D
#define MON_5  0x2001E
#define MON_6  0x2001F
#define MON_7  0x20020
#define MON_8  0x20021
#define MON_9  0x20022
#define MON_10 0x20023
#define MON_11 0x20024
#define MON_12 0x20025

#define AM_STR 0x20026
#define PM_STR 0x20027

#define D_T_FMT    0x20028
#define D_FMT      0x20029
#define T_FMT      0x2002A
#define T_FMT_AMPM 0x2002B

#define ERA         0x2002C
#define ERA_D_FMT   0x2002E
#define ALT_DIGITS  0x2002F
#define ERA_D_T_FMT 0x20030
#define ERA_T_FMT   0x20031

#define CODESET 14

#define CRNCYSTR 0x4000F

#define RADIXCHAR 0x10000
#define THOUSEP   0x10001
#define YESEXPR   0x50000
#define NOEXPR    0x50001

#define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff)

#if defined(_GNU_SOURCE)
#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat)
#endif

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define YESSTR 0x50002
#define NOSTR  0x50003
#endif

char *nl_langinfo(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/locale.h */

#define COSMOPOLITAN_LIBC_STR_LOCALE_H_

#define LC_CTYPE         0
#define LC_NUMERIC       1
#define LC_CTYPE_MASK    1
#define LC_TIME          2
#define LC_NUMERIC_MASK  2
#define LC_COLLATE       3
#define LC_MONETARY      4
#define LC_TIME_MASK     4
#define LC_MESSAGES      5
#define LC_ALL           6
#define LC_COLLATE_MASK  8
#define LC_MONETARY_MASK 16
#define LC_MESSAGES_MASK 32
#define LC_ALL_MASK      0x1fbf
#define LOCALE_NAME_MAX  23

COSMOPOLITAN_C_START_

#define LC_GLOBAL_LOCALE ((locale_t) - 1)

struct __locale_map {
  const void *map;
  size_t map_size;
  char name[LOCALE_NAME_MAX + 1];
  const struct __locale_map *next;
};

struct __locale_struct {
  const struct __locale_map *cat[6];
};

typedef struct __locale_struct *locale_t;

extern const struct __locale_map __c_dot_utf8;
extern const struct __locale_struct __c_locale;
extern const struct __locale_struct __c_dot_utf8_locale;

char *nl_langinfo_l(int, locale_t) libcesque;
char *setlocale(int, const char *) libcesque;
double strtod_l(const char *, char **, locale_t) libcesque;
double wcstod_l(const wchar_t *, wchar_t **, locale_t) libcesque;
float strtof_l(const char *, char **, locale_t) libcesque;
float wcstof_l(const wchar_t *, wchar_t **, locale_t) libcesque;
int isdigit_l(int, locale_t) libcesque;
int islower_l(int, locale_t) libcesque;
int isupper_l(int, locale_t) libcesque;
int iswalpha_l(wint_t, locale_t) libcesque;
int iswblank_l(wint_t, locale_t) libcesque;
int iswcntrl_l(wint_t, locale_t) libcesque;
int iswdigit_l(wint_t, locale_t) libcesque;
int iswlower_l(wint_t, locale_t) libcesque;
int iswprint_l(wint_t, locale_t) libcesque;
int iswpunct_l(wint_t, locale_t) libcesque;
int iswspace_l(wint_t, locale_t) libcesque;
int iswupper_l(wint_t, locale_t) libcesque;
int iswxdigit_l(wint_t, locale_t) libcesque;
int isxdigit_l(int, locale_t) libcesque;
int strcoll_l(const char *, const char *, locale_t) libcesque;
int tolower_l(int, locale_t) libcesque;
int toupper_l(int, locale_t) libcesque;
int wcscoll_l(const wchar_t *, const wchar_t *, locale_t) libcesque;
locale_t duplocale(locale_t) libcesque;
locale_t newlocale(int, const char *, locale_t) libcesque;
locale_t uselocale(locale_t) libcesque;
long double strtold_l(const char *, char **, locale_t) libcesque;
long double wcstold_l(const wchar_t *, wchar_t **, locale_t) libcesque;
long long strtoll_l(const char *, char **, int, locale_t) libcesque;
long long wcstoll_l(const wchar_t *, wchar_t **, int, locale_t) libcesque;
size_t strftime_l(char *, size_t, char const *, struct tm const *, locale_t);
size_t strxfrm_l(char *, const char *, size_t, locale_t) libcesque;
size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t) libcesque;
unsigned long long strtoull_l(const char *, char **, int, locale_t) libcesque;
unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t);
void freelocale(locale_t) libcesque;
wint_t towlower_l(wint_t, locale_t) libcesque;
wint_t towupper_l(wint_t, locale_t) libcesque;
int strcasecmp_l(const char *, const char *, locale_t) libcesque;
int strncasecmp_l(const char *, const char *, size_t, locale_t) libcesque;
ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/nltypes.h */

#define COSMOPOLITAN_LIBC_STR_NLTYPES_H_

#define NL_SETD       1
#define NL_CAT_LOCALE 1

COSMOPOLITAN_C_START_

typedef int nl_item;
typedef void *nl_catd;

nl_catd catopen(const char *, int);
char *catgets(nl_catd, int, int, const char *);
int catclose(nl_catd);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/slice.h */

#define COSMOPOLITAN_LIBC_STR_SLICE_H_
COSMOPOLITAN_C_START_

#define SlicesEqual(a, n, b, m)       \
  ({                                  \
    size_t __n = (n);                 \
    __n == (m) && !memcmp(a, b, __n); \
  })

#define SlicesEqualCase(a, n, b, m)       \
  ({                                      \
    size_t __n = (n);                     \
    __n == (m) && !memcasecmp(a, b, __n); \
  })

int CompareSlices(const char *, size_t, const char *, size_t) libcesque;
int CompareSlicesCase(const char *, size_t, const char *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/strwidth.h */

#define COSMOPOLITAN_LIBC_STR_STRWIDTH_H_
COSMOPOLITAN_C_START_

int strwidth(const char *, size_t) strlenesque;
int strnwidth(const char *, size_t, size_t) strlenesque;
int strwidth16(const char16_t *, size_t) strlenesque;
int strnwidth16(const char16_t *, size_t, size_t) strlenesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/thompike.h */

#define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_

#define ThomPikeCont(x)     (0200 == (0300 & (x)))
#define ThomPikeByte(x)     ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
#define ThomPikeLen(x)      (7 - ThomPikeMsb(x))
#define ThomPikeMsb(x)      ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1)
#define ThomPikeMerge(x, y) ((x) << 6 | (077 & (y)))



/*!BEGIN libc/str/unicode.h */

#define COSMOPOLITAN_LIBC_STR_UNICODE_H_
COSMOPOLITAN_C_START_

struct lconv {
  char *decimal_point;
  char *thousands_sep;
  char *grouping;
  char *int_curr_symbol;
  char *currency_symbol;
  char *mon_decimal_point;
  char *mon_thousands_sep;
  char *mon_grouping;
  char *positive_sign;
  char *negative_sign;
  char int_frac_digits;
  char frac_digits;
  char p_cs_precedes;
  char p_sep_by_space;
  char n_cs_precedes;
  char n_sep_by_space;
  char p_sign_posn;
  char n_sign_posn;
  char int_p_cs_precedes;
  char int_n_cs_precedes;
  char int_p_sep_by_space;
  char int_n_sep_by_space;
  char int_p_sign_posn;
  char int_n_sign_posn;
};

pureconst int wcwidth(wchar_t) libcesque;
int wcswidth(const wchar_t *, size_t) strlenesque;
struct lconv *localeconv(void) libcesque;

#ifdef _COSMO_SOURCE
int wcsnwidth(const wchar_t *, size_t, size_t) strlenesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/utf16.h */

#define COSMOPOLITAN_LIBC_STR_UTF16_H_

#define UTF16_MASK 0xfc00
#define UTF16_MOAR 0xd800 /* 0xD800..0xDBFF */
#define UTF16_CONT 0xdc00 /* 0xDC00..0xDFFF */

COSMOPOLITAN_C_START_

#define IsSurrogate(wc)     ((0xf800 & (wc)) == 0xd800)
#define IsHighSurrogate(wc) ((UTF16_MASK & (wc)) == UTF16_MOAR)
#define IsLowSurrogate(wc)  ((UTF16_MASK & (wc)) == UTF16_CONT)
#define IsUcs2(wc)          (((65535 & (wc)) >> 11) != 27)
#define IsUtf16Cont(wc)     IsLowSurrogate(wc) /* TODO: DELETE */
#define MergeUtf16(hi, lo)  ((((hi)-0xD800) << 10) + ((lo)-0xDC00) + 0x10000)
#define EncodeUtf16(wc)                                       \
  (LIKELY((0x0000 <= (wc) && (wc) <= 0xFFFF) ||               \
          (0xE000 <= (wc) && (wc) <= 0xFFFF))                 \
       ? (wc)                                                 \
   : 0x10000 <= (wc) && (wc) <= 0x10FFFF                      \
       ? (((((wc)-0x10000) >> 10) + 0xD800) |                 \
          (unsigned)((((wc)-0x10000) & 1023) + 0xDC00) << 16) \
       : 0xFFFD)

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/errfuns.h */

#define COSMOPOLITAN_LIBC_SYSV_ERRFUNS_H_

/**
 * @fileoverview Optimized error return paths.
 *
 * Saying this:
 *
 *     return einval();
 *
 * Instead of this:
 *
 *     errno = EINVAL;
 *     return -1;
 *
 * Allows the compiler to generate 11 fewer bytes of code each time.
 *
 * @return always -1
 * @see libc/sysv/errfuns.inc (for implementation)
 */

libcesque intptr_t einval(void) relegated;
libcesque intptr_t eperm(void) relegated;
libcesque intptr_t enoent(void) relegated;
libcesque intptr_t esrch(void) relegated;
libcesque intptr_t eintr(void) relegated;
libcesque intptr_t eio(void) relegated;
libcesque intptr_t enxio(void) relegated;
libcesque intptr_t e2big(void) relegated;
libcesque intptr_t enoexec(void) relegated;
libcesque intptr_t ebadf(void) relegated;
libcesque intptr_t echild(void) relegated;
libcesque intptr_t eagain(void) relegated;
libcesque intptr_t enomem(void) relegated;
libcesque intptr_t eacces(void) relegated;
libcesque intptr_t efault(void) relegated;
libcesque intptr_t enotblk(void) relegated;
libcesque intptr_t ebusy(void) relegated;
libcesque intptr_t eexist(void) relegated;
libcesque intptr_t exdev(void) relegated;
libcesque intptr_t enodev(void) relegated;
libcesque intptr_t enotdir(void) relegated;
libcesque intptr_t eisdir(void) relegated;
libcesque intptr_t enfile(void) relegated;
libcesque intptr_t emfile(void) relegated;
libcesque intptr_t enotty(void) relegated;
libcesque intptr_t enotsup(void) relegated;
libcesque intptr_t etxtbsy(void) relegated;
libcesque intptr_t efbig(void) relegated;
libcesque intptr_t enospc(void) relegated;
libcesque intptr_t espipe(void) relegated;
libcesque intptr_t erofs(void) relegated;
libcesque intptr_t emlink(void) relegated;
libcesque intptr_t epipe(void) relegated;
libcesque intptr_t edom(void) relegated;
libcesque intptr_t erange(void) relegated;
libcesque intptr_t edeadlk(void) relegated;
libcesque intptr_t enametoolong(void) relegated;
libcesque intptr_t enolck(void) relegated;
libcesque intptr_t enosys(void) relegated;
libcesque intptr_t enotempty(void) relegated;
libcesque intptr_t eloop(void) relegated;
libcesque intptr_t enomsg(void) relegated;
libcesque intptr_t eidrm(void) relegated;
libcesque intptr_t echrng(void) relegated;
libcesque intptr_t el2nsync(void) relegated;
libcesque intptr_t el3hlt(void) relegated;
libcesque intptr_t el3rst(void) relegated;
libcesque intptr_t elnrng(void) relegated;
libcesque intptr_t eunatch(void) relegated;
libcesque intptr_t enocsi(void) relegated;
libcesque intptr_t el2hlt(void) relegated;
libcesque intptr_t ebade(void) relegated;
libcesque intptr_t ebadr(void) relegated;
libcesque intptr_t exfull(void) relegated;
libcesque intptr_t enoano(void) relegated;
libcesque intptr_t ebadrqc(void) relegated;
libcesque intptr_t ebadslt(void) relegated;
libcesque intptr_t enostr(void) relegated;
libcesque intptr_t enodata(void) relegated;
libcesque intptr_t etime(void) relegated;
libcesque intptr_t enosr(void) relegated;
libcesque intptr_t enonet(void) relegated;
libcesque intptr_t enopkg(void) relegated;
libcesque intptr_t eremote(void) relegated;
libcesque intptr_t enolink(void) relegated;
libcesque intptr_t eadv(void) relegated;
libcesque intptr_t esrmnt(void) relegated;
libcesque intptr_t ecomm(void) relegated;
libcesque intptr_t eproto(void) relegated;
libcesque intptr_t emultihop(void) relegated;
libcesque intptr_t edotdot(void) relegated;
libcesque intptr_t ebadmsg(void) relegated;
libcesque intptr_t eoverflow(void) relegated;
libcesque intptr_t enotuniq(void) relegated;
libcesque intptr_t ebadfd(void) relegated;
libcesque intptr_t eremchg(void) relegated;
libcesque intptr_t elibacc(void) relegated;
libcesque intptr_t elibbad(void) relegated;
libcesque intptr_t elibscn(void) relegated;
libcesque intptr_t elibmax(void) relegated;
libcesque intptr_t elibexec(void) relegated;
libcesque intptr_t eilseq(void) relegated;
libcesque intptr_t erestart(void) relegated;
libcesque intptr_t estrpipe(void) relegated;
libcesque intptr_t eusers(void) relegated;
libcesque intptr_t enotsock(void) relegated;
libcesque intptr_t edestaddrreq(void) relegated;
libcesque intptr_t emsgsize(void) relegated;
libcesque intptr_t eprototype(void) relegated;
libcesque intptr_t enoprotoopt(void) relegated;
libcesque intptr_t eprotonosupport(void) relegated;
libcesque intptr_t esocktnosupport(void) relegated;
libcesque intptr_t eopnotsupp(void) relegated;
libcesque intptr_t epfnosupport(void) relegated;
libcesque intptr_t eafnosupport(void) relegated;
libcesque intptr_t eaddrinuse(void) relegated;
libcesque intptr_t eaddrnotavail(void) relegated;
libcesque intptr_t enetdown(void) relegated;
libcesque intptr_t enetunreach(void) relegated;
libcesque intptr_t enetreset(void) relegated;
libcesque intptr_t econnaborted(void) relegated;
libcesque intptr_t econnreset(void) relegated;
libcesque intptr_t enobufs(void) relegated;
libcesque intptr_t eisconn(void) relegated;
libcesque intptr_t enotconn(void) relegated;
libcesque intptr_t eshutdown(void) relegated;
libcesque intptr_t etoomanyrefs(void) relegated;
libcesque intptr_t etimedout(void) relegated;
libcesque intptr_t econnrefused(void) relegated;
libcesque intptr_t ehostdown(void) relegated;
libcesque intptr_t ehostunreach(void) relegated;
libcesque intptr_t ealready(void) relegated;
libcesque intptr_t einprogress(void) relegated;
libcesque intptr_t estale(void) relegated;
libcesque intptr_t euclean(void) relegated;
libcesque intptr_t enotnam(void) relegated;
libcesque intptr_t enavail(void) relegated;
libcesque intptr_t eisnam(void) relegated;
libcesque intptr_t eremoteio(void) relegated;
libcesque intptr_t edquot(void) relegated;
libcesque intptr_t enomedium(void) relegated;
libcesque intptr_t emediumtype(void) relegated;
libcesque intptr_t ecanceled(void) relegated;
libcesque intptr_t enokey(void) relegated;
libcesque intptr_t ekeyexpired(void) relegated;
libcesque intptr_t ekeyrevoked(void) relegated;
libcesque intptr_t ekeyrejected(void) relegated;
libcesque intptr_t eownerdead(void) relegated;
libcesque intptr_t enotrecoverable(void) relegated;
libcesque intptr_t erfkill(void) relegated;
libcesque intptr_t ehwpoison(void) relegated;

#if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __ERRFUN(FUNC)               \
  ({                                 \
    intptr_t NegOne;                 \
    asm volatile("call\t" FUNC       \
                 : "=a"(NegOne)      \
                 : /* no outputs */  \
                 : "rcx", "memory"); \
    NegOne;                          \
  })
#define einval()          __ERRFUN("einval")
#define eperm()           __ERRFUN("eperm")
#define enoent()          __ERRFUN("enoent")
#define esrch()           __ERRFUN("esrch")
#define eintr()           __ERRFUN("eintr")
#define eio()             __ERRFUN("eio")
#define enxio()           __ERRFUN("enxio")
#define e2big()           __ERRFUN("e2big")
#define enoexec()         __ERRFUN("enoexec")
#define ebadf()           __ERRFUN("ebadf")
#define echild()          __ERRFUN("echild")
#define eagain()          __ERRFUN("eagain")
#define enomem()          __ERRFUN("enomem")
#define eacces()          __ERRFUN("eacces")
#define efault()          __ERRFUN("efault")
#define enotblk()         __ERRFUN("enotblk")
#define ebusy()           __ERRFUN("ebusy")
#define eexist()          __ERRFUN("eexist")
#define exdev()           __ERRFUN("exdev")
#define enodev()          __ERRFUN("enodev")
#define enotdir()         __ERRFUN("enotdir")
#define eisdir()          __ERRFUN("eisdir")
#define enfile()          __ERRFUN("enfile")
#define emfile()          __ERRFUN("emfile")
#define enotty()          __ERRFUN("enotty")
#define enotsup()         __ERRFUN("enotsup")
#define etxtbsy()         __ERRFUN("etxtbsy")
#define efbig()           __ERRFUN("efbig")
#define enospc()          __ERRFUN("enospc")
#define espipe()          __ERRFUN("espipe")
#define erofs()           __ERRFUN("erofs")
#define emlink()          __ERRFUN("emlink")
#define epipe()           __ERRFUN("epipe")
#define edom()            __ERRFUN("edom")
#define erange()          __ERRFUN("erange")
#define edeadlk()         __ERRFUN("edeadlk")
#define enametoolong()    __ERRFUN("enametoolong")
#define enolck()          __ERRFUN("enolck")
#define enosys()          __ERRFUN("enosys")
#define enotempty()       __ERRFUN("enotempty")
#define eloop()           __ERRFUN("eloop")
#define enomsg()          __ERRFUN("enomsg")
#define eidrm()           __ERRFUN("eidrm")
#define echrng()          __ERRFUN("echrng")
#define el2nsync()        __ERRFUN("el2nsync")
#define el3hlt()          __ERRFUN("el3hlt")
#define el3rst()          __ERRFUN("el3rst")
#define elnrng()          __ERRFUN("elnrng")
#define eunatch()         __ERRFUN("eunatch")
#define enocsi()          __ERRFUN("enocsi")
#define el2hlt()          __ERRFUN("el2hlt")
#define ebade()           __ERRFUN("ebade")
#define ebadr()           __ERRFUN("ebadr")
#define exfull()          __ERRFUN("exfull")
#define enoano()          __ERRFUN("enoano")
#define ebadrqc()         __ERRFUN("ebadrqc")
#define ebadslt()         __ERRFUN("ebadslt")
#define enostr()          __ERRFUN("enostr")
#define enodata()         __ERRFUN("enodata")
#define etime()           __ERRFUN("etime")
#define enosr()           __ERRFUN("enosr")
#define enonet()          __ERRFUN("enonet")
#define enopkg()          __ERRFUN("enopkg")
#define eremote()         __ERRFUN("eremote")
#define enolink()         __ERRFUN("enolink")
#define eadv()            __ERRFUN("eadv")
#define esrmnt()          __ERRFUN("esrmnt")
#define ecomm()           __ERRFUN("ecomm")
#define eproto()          __ERRFUN("eproto")
#define emultihop()       __ERRFUN("emultihop")
#define edotdot()         __ERRFUN("edotdot")
#define ebadmsg()         __ERRFUN("ebadmsg")
#define eoverflow()       __ERRFUN("eoverflow")
#define enotuniq()        __ERRFUN("enotuniq")
#define ebadfd()          __ERRFUN("ebadfd")
#define eremchg()         __ERRFUN("eremchg")
#define elibacc()         __ERRFUN("elibacc")
#define elibbad()         __ERRFUN("elibbad")
#define elibscn()         __ERRFUN("elibscn")
#define elibmax()         __ERRFUN("elibmax")
#define elibexec()        __ERRFUN("elibexec")
#define eilseq()          __ERRFUN("eilseq")
#define erestart()        __ERRFUN("erestart")
#define estrpipe()        __ERRFUN("estrpipe")
#define eusers()          __ERRFUN("eusers")
#define enotsock()        __ERRFUN("enotsock")
#define edestaddrreq()    __ERRFUN("edestaddrreq")
#define emsgsize()        __ERRFUN("emsgsize")
#define eprototype()      __ERRFUN("eprototype")
#define enoprotoopt()     __ERRFUN("enoprotoopt")
#define eprotonosupport() __ERRFUN("eprotonosupport")
#define esocktnosupport() __ERRFUN("esocktnosupport")
#define eopnotsupp()      __ERRFUN("eopnotsupp")
#define epfnosupport()    __ERRFUN("epfnosupport")
#define eafnosupport()    __ERRFUN("eafnosupport")
#define eaddrinuse()      __ERRFUN("eaddrinuse")
#define eaddrnotavail()   __ERRFUN("eaddrnotavail")
#define enetdown()        __ERRFUN("enetdown")
#define enetunreach()     __ERRFUN("enetunreach")
#define enetreset()       __ERRFUN("enetreset")
#define econnaborted()    __ERRFUN("econnaborted")
#define econnreset()      __ERRFUN("econnreset")
#define enobufs()         __ERRFUN("enobufs")
#define eisconn()         __ERRFUN("eisconn")
#define enotconn()        __ERRFUN("enotconn")
#define eshutdown()       __ERRFUN("eshutdown")
#define etoomanyrefs()    __ERRFUN("etoomanyrefs")
#define etimedout()       __ERRFUN("etimedout")
#define econnrefused()    __ERRFUN("econnrefused")
#define ehostdown()       __ERRFUN("ehostdown")
#define ehostunreach()    __ERRFUN("ehostunreach")
#define ealready()        __ERRFUN("ealready")
#define einprogress()     __ERRFUN("einprogress")
#define estale()          __ERRFUN("estale")
#define euclean()         __ERRFUN("euclean")
#define enotnam()         __ERRFUN("enotnam")
#define enavail()         __ERRFUN("enavail")
#define eisnam()          __ERRFUN("eisnam")
#define eremoteio()       __ERRFUN("eremoteio")
#define edquot()          __ERRFUN("edquot")
#define enomedium()       __ERRFUN("enomedium")
#define emediumtype()     __ERRFUN("emediumtype")
#define ecanceled()       __ERRFUN("ecanceled")
#define enokey()          __ERRFUN("enokey")
#define ekeyexpired()     __ERRFUN("ekeyexpired")
#define ekeyrevoked()     __ERRFUN("ekeyrevoked")
#define ekeyrejected()    __ERRFUN("ekeyrejected")
#define eownerdead()      __ERRFUN("eownerdead")
#define enotrecoverable() __ERRFUN("enotrecoverable")
#define erfkill()         __ERRFUN("erfkill")
#define ehwpoison()       __ERRFUN("ehwpoison")
#endif



/*!BEGIN libc/sysv/consts/_posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS__POSIX_H_

/* The Open Group Base Specifications Issue 7, 2018 edition */
/* IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)  */

#define _POSIX_AIO_LISTIO_MAX               2
#define _POSIX_CLOCKRES_MIN                 20000000
#define _POSIX_AIO_MAX                      1
#define _POSIX_ARG_MAX                      4096
#define _POSIX_CHILD_MAX                    25
#define _POSIX_DELAYTIMER_MAX               32
#define _POSIX_HOST_NAME_MAX                255
#define _POSIX_LINK_MAX                     8
#define _POSIX_LOGIN_NAME_MAX               9
#define _POSIX_MAX_CANON                    255
#define _POSIX_MAX_INPUT                    255
#define _POSIX_MQ_OPEN_MAX                  8
#define _POSIX_MQ_PRIO_MAX                  32
#define _POSIX_NAME_MAX                     14
#define _POSIX_NGROUPS_MAX                  8
#define _POSIX_OPEN_MAX                     20
#define _POSIX_PATH_MAX                     256
#define _POSIX_PIPE_BUF                     512
#define _POSIX_RE_DUP_MAX                   255
#define _POSIX_RTSIG_MAX                    8
#define _POSIX_SEM_NSEMS_MAX                256
#define _POSIX_SEM_VALUE_MAX                32767
#define _POSIX_SIGQUEUE_MAX                 32
#define _POSIX_SSIZE_MAX                    32767
#define _POSIX_SS_REPL_MAX                  4
#define _POSIX_STREAM_MAX                   8
#define _POSIX_SYMLINK_MAX                  255
#define _POSIX_SYMLOOP_MAX                  8
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
#define _POSIX_THREAD_KEYS_MAX              128
#define _POSIX_THREAD_THREADS_MAX           64
#define _POSIX_TIMER_MAX                    32
#define _POSIX_TRACE_EVENT_NAME_MAX         30
#define _POSIX_TRACE_NAME_MAX               8
#define _POSIX_TRACE_SYS_MAX                8
#define _POSIX_TRACE_USER_EVENT_MAX         32
#define _POSIX_TTY_NAME_MAX                 9
#define _POSIX_TZNAME_MAX                   6

#define _POSIX2_BC_BASE_MAX        99
#define _POSIX2_BC_DIM_MAX         2048
#define _POSIX2_BC_SCALE_MAX       99
#define _POSIX2_BC_STRING_MAX      1000
#define _POSIX2_CHARCLASS_NAME_MAX 14
#define _POSIX2_COLL_WEIGHTS_MAX   2
#define _POSIX2_EXPR_NEST_MAX      32
#define _POSIX2_LINE_MAX           2048
#define _POSIX2_RE_DUP_MAX         255



/*!BEGIN libc/sysv/consts/af.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AF_H_
COSMOPOLITAN_C_START_

extern const int AF_ALG;
extern const int AF_APPLETALK;
extern const int AF_ASH;
extern const int AF_ATMPVC;
extern const int AF_ATMSVC;
extern const int AF_AX25;
extern const int AF_BLUETOOTH;
extern const int AF_BRIDGE;
extern const int AF_CAIF;
extern const int AF_CAN;
extern const int AF_ECONET;
extern const int AF_FILE;
extern const int AF_IB;
extern const int AF_IEEE802154;
extern const int AF_INET6;
extern const int AF_INET;
extern const int AF_IPX;
extern const int AF_IRDA;
extern const int AF_ISDN;
extern const int AF_IUCV;
extern const int AF_KCM;
extern const int AF_KEY;
extern const int AF_LINK;
extern const int AF_LLC;
extern const int AF_LOCAL;
extern const int AF_MAX;
extern const int AF_MPLS;
extern const int AF_NETBEUI;
extern const int AF_NETLINK;
extern const int AF_NETROM;
extern const int AF_NFC;
extern const int AF_PACKET;
extern const int AF_PHONET;
extern const int AF_PPPOX;
extern const int AF_ROSE;
extern const int AF_ROUTE;
extern const int AF_RXRPC;
extern const int AF_SECURITY;
extern const int AF_SNA;
extern const int AF_TIPC;
extern const int AF_UNIX;
extern const int AF_UNSPEC;
extern const int AF_VSOCK;
extern const int AF_WANPIPE;
extern const int AF_X25;

#define AF_ALG        AF_ALG
#define AF_LINK       AF_LINK
#define AF_APPLETALK  AF_APPLETALK
#define AF_ASH        AF_ASH
#define AF_ATMPVC     AF_ATMPVC
#define AF_ATMSVC     AF_ATMSVC
#define AF_AX25       AF_AX25
#define AF_BLUETOOTH  AF_BLUETOOTH
#define AF_BRIDGE     AF_BRIDGE
#define AF_CAIF       AF_CAIF
#define AF_CAN        AF_CAN
#define AF_ECONET     AF_ECONET
#define AF_FILE       AF_FILE
#define AF_IB         AF_IB
#define AF_IEEE802154 AF_IEEE802154
#define AF_INET       2
#define AF_INET6      AF_INET6
#define AF_IPX        AF_IPX
#define AF_IRDA       AF_IRDA
#define AF_ISDN       AF_ISDN
#define AF_IUCV       AF_IUCV
#define AF_KCM        AF_KCM
#define AF_KEY        AF_KEY
#define AF_LLC        AF_LLC
#define AF_LOCAL      AF_LOCAL
#define AF_MAX        AF_MAX
#define AF_MPLS       AF_MPLS
#define AF_NETBEUI    AF_NETBEUI
#define AF_NETLINK    AF_NETLINK
#define AF_NETROM     AF_NETROM
#define AF_NFC        AF_NFC
#define AF_PACKET     AF_PACKET
#define AF_PHONET     AF_PHONET
#define AF_PPPOX      AF_PPPOX
#define AF_ROSE       AF_ROSE
#define AF_ROUTE      AF_ROUTE
#define AF_RXRPC      AF_RXRPC
#define AF_SECURITY   AF_SECURITY
#define AF_SNA        AF_SNA
#define AF_TIPC       AF_TIPC
#define AF_UNIX       1
#define AF_UNSPEC     0
#define AF_VSOCK      AF_VSOCK
#define AF_WANPIPE    AF_WANPIPE
#define AF_X25        AF_X25

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/arch.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARCH_H_

#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004



/*!BEGIN libc/sysv/consts/arp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARP_H_

#define ARPHRD_ETHER 1



/*!BEGIN libc/sysv/consts/at.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AT_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview AT_xxx constants for fcntl(), fopenat(), etc..
 * @see libc/sysv/consts/auxv.h for getauxval() constants
 */

extern const int AT_FDCWD;
extern const int AT_SYMLINK_FOLLOW;
extern const int AT_SYMLINK_NOFOLLOW;
extern const int AT_REMOVEDIR;
extern const int AT_EACCESS;
extern const int AT_EMPTY_PATH;

COSMOPOLITAN_C_END_

#define AT_FDCWD            AT_FDCWD
#define AT_SYMLINK_FOLLOW   AT_SYMLINK_FOLLOW
#define AT_SYMLINK_NOFOLLOW AT_SYMLINK_NOFOLLOW
#define AT_REMOVEDIR        AT_REMOVEDIR
#define AT_EACCESS          AT_EACCESS



/*!BEGIN libc/sysv/consts/audit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AUDIT_H_

#define __AUDIT_ARCH_64BIT                 0x80000000
#define __AUDIT_ARCH_LE                    0x40000000
#define __AUDIT_ARCH_CONVENTION_MASK       0x30000000
#define __AUDIT_ARCH_CONVENTION_MIPS64_N32 0x20000000

#define AUDIT_ARCH_X86_64  (EM_X86_64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_I386    (EM_386 | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_AARCH64 (EM_AARCH64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_PPC64LE (EM_PPC64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_RISCV64 (EM_RISCV | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_S390X   (EM_S390 | __AUDIT_ARCH_64BIT)



/*!BEGIN libc/sysv/consts/auxv.h */

#define COSMOPOLITAN_LIBC_CALLS_AUXV_H_

/*
 * integral getauxval() keys
 */
#define AT_PHDR                     3
#define AT_PHENT                    4
#define AT_PHNUM                    5
#define AT_PAGESZ                   6
#define AT_BASE                     7
#define AT_FLAGS                    8
#define AT_FLAGS_PRESERVE_ARGV0_BIT 0
#define AT_FLAGS_PRESERVE_ARGV0     (1 << AT_FLAGS_PRESERVE_ARGV0_BIT)
#define AT_ENTRY                    9

COSMOPOLITAN_C_START_

/*
 * portable getauxval() keys
 */
extern const unsigned long AT_EXECFN;
extern const unsigned long AT_SECURE;
extern const unsigned long AT_RANDOM;
extern const unsigned long AT_HWCAP;
extern const unsigned long AT_HWCAP2;
extern const unsigned long AT_UID;
extern const unsigned long AT_EUID;
extern const unsigned long AT_GID;
extern const unsigned long AT_EGID;
#define AT_EXECFN AT_EXECFN
#define AT_SECURE AT_SECURE
#define AT_RANDOM AT_RANDOM
#define AT_HWCAP  AT_HWCAP
#define AT_HWCAP2 AT_HWCAP2
#define AT_UID    AT_UID
#define AT_EUID   AT_EUID
#define AT_GID    AT_GID
#define AT_EGID   AT_EGID

/*
 * platform-specific getauxval() keys
 */
extern const unsigned long AT_BASE_PLATFORM;
extern const unsigned long AT_CANARY;
extern const unsigned long AT_CANARYLEN;
extern const unsigned long AT_CLKTCK;
extern const unsigned long AT_DCACHEBSIZE;
extern const unsigned long AT_EHDRFLAGS;
extern const unsigned long AT_EXECFD;
extern const unsigned long AT_EXECPATH;
extern const unsigned long AT_ICACHEBSIZE;
extern const unsigned long AT_MINSIGSTKSZ;
extern const unsigned long AT_NCPUS;
extern const unsigned long AT_NOTELF;
extern const unsigned long AT_NO_AUTOMOUNT;
extern const unsigned long AT_OSRELDATE;
extern const unsigned long AT_PAGESIZES;
extern const unsigned long AT_PAGESIZESLEN;
extern const unsigned long AT_PLATFORM;
extern const unsigned long AT_STACKBASE;
extern const unsigned long AT_STACKPROT;
extern const unsigned long AT_SYSINFO_EHDR;
extern const unsigned long AT_TIMEKEEP;
extern const unsigned long AT_UCACHEBSIZE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/c.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CPIO_H_

#define MAGIC "070707"

#define C_IRUSR 000400
#define C_IWUSR 000200
#define C_IXUSR 000100
#define C_IRGRP 000040
#define C_IWGRP 000020
#define C_IXGRP 000010
#define C_IROTH 000004
#define C_IWOTH 000002
#define C_IXOTH 000001

#define C_ISUID 004000
#define C_ISGID 002000
#define C_ISVTX 001000

#define C_ISBLK  060000
#define C_ISCHR  020000
#define C_ISDIR  040000
#define C_ISFIFO 010000
#define C_ISSOCK 0140000
#define C_ISLNK  0120000
#define C_ISCTG  0110000
#define C_ISREG  0100000



/*!BEGIN libc/sysv/consts/cap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CAP_H_

#define CAP_CHOWN              0
#define CAP_DAC_OVERRIDE       1
#define CAP_DAC_READ_SEARCH    2
#define CAP_FOWNER             3
#define CAP_FSETID             4
#define CAP_KILL               5
#define CAP_SETGID             6
#define CAP_SETUID             7
#define CAP_SETPCAP            8
#define CAP_LINUX_IMMUTABLE    9
#define CAP_NET_BIND_SERVICE   10
#define CAP_NET_BROADCAST      11
#define CAP_NET_ADMIN          12
#define CAP_NET_RAW            13
#define CAP_IPC_LOCK           14
#define CAP_IPC_OWNER          15
#define CAP_SYS_MODULE         16
#define CAP_SYS_RAWIO          17
#define CAP_SYS_CHROOT         18
#define CAP_SYS_PTRACE         19
#define CAP_SYS_PACCT          20
#define CAP_SYS_ADMIN          21
#define CAP_SYS_BOOT           22
#define CAP_SYS_NICE           23
#define CAP_SYS_RESOURCE       24
#define CAP_SYS_TIME           25
#define CAP_SYS_TTY_CONFIG     26
#define CAP_MKNOD              27
#define CAP_LEASE              28
#define CAP_AUDIT_WRITE        29
#define CAP_AUDIT_CONTROL      30
#define CAP_SETFCAP            31
#define CAP_MAC_OVERRIDE       32
#define CAP_MAC_ADMIN          33
#define CAP_SYSLOG             34
#define CAP_WAKE_ALARM         35
#define CAP_BLOCK_SUSPEND      36
#define CAP_AUDIT_READ         37
#define CAP_PERFMON            38
#define CAP_BPF                39
#define CAP_CHECKPOINT_RESTORE 40
#define CAP_LAST_CAP           CAP_CHECKPOINT_RESTORE



/*!BEGIN libc/sysv/consts/clock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOCK_H_
COSMOPOLITAN_C_START_

extern const int CLOCK_BOOTTIME;
extern const int CLOCK_BOOTTIME_ALARM;
extern const int CLOCK_MONOTONIC;
extern const int CLOCK_MONOTONIC_COARSE;
extern const int CLOCK_MONOTONIC_FAST;
extern const int CLOCK_MONOTONIC_PRECISE;
extern const int CLOCK_MONOTONIC_RAW;
extern const int CLOCK_PROCESS_CPUTIME_ID;
extern const int CLOCK_PROF;
extern const int CLOCK_REALTIME_ALARM;
extern const int CLOCK_REALTIME_COARSE;
extern const int CLOCK_REALTIME_FAST;
extern const int CLOCK_REALTIME_PRECISE;
extern const int CLOCK_SECOND;
extern const int CLOCK_TAI;
extern const int CLOCK_THREAD_CPUTIME_ID;
extern const int CLOCK_UPTIME;
extern const int CLOCK_UPTIME_FAST;
extern const int CLOCK_UPTIME_PRECISE;

COSMOPOLITAN_C_END_

#define CLOCK_REALTIME  0
#define CLOCK_MONOTONIC CLOCK_MONOTONIC



/*!BEGIN libc/sysv/consts/clone.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLONE_H_
#ifdef _COSMO_SOURCE

#define CSIGNAL              0x000000ff
#define CLONE_VM             0x00000100
#define CLONE_FS             0x00000200
#define CLONE_FILES          0x00000400
#define CLONE_SIGHAND        0x00000800
#define CLONE_PIDFD          0x00001000
#define CLONE_PTRACE         0x00002000
#define CLONE_VFORK          0x00004000
#define CLONE_PARENT         0x00008000
#define CLONE_THREAD         0x00010000
#define CLONE_NEWNS          0x00020000
#define CLONE_SYSVSEM        0x00040000
#define CLONE_SETTLS         0x00080000
#define CLONE_PARENT_SETTID  0x00100000
#define CLONE_CHILD_CLEARTID 0x00200000
#define CLONE_DETACHED       0x00400000
#define CLONE_UNTRACED       0x00800000
#define CLONE_CHILD_SETTID   0x01000000
#define CLONE_NEWCGROUP      0x02000000
#define CLONE_NEWUTS         0x04000000
#define CLONE_NEWIPC         0x08000000
#define CLONE_NEWUSER        0x10000000
#define CLONE_NEWPID         0x20000000
#define CLONE_NEWNET         0x40000000
#define CLONE_IO             0x80000000

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/close.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOSE_H_
COSMOPOLITAN_C_START_

extern const unsigned int CLOSE_RANGE_UNSHARE;
extern const unsigned int CLOSE_RANGE_CLOEXEC;

COSMOPOLITAN_C_END_

#define CLOSE_RANGE_UNSHARE CLOSE_RANGE_UNSHARE
#define CLOSE_RANGE_CLOEXEC CLOSE_RANGE_CLOEXEC



/*!BEGIN libc/sysv/consts/dn.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DN_H_

#define DN_ACCESS    0x00000001 /* file accessed */
#define DN_MODIFY    0x00000002 /* file modified */
#define DN_CREATE    0x00000004 /* file created */
#define DN_DELETE    0x00000008 /* file removed */
#define DN_RENAME    0x00000010 /* file renamed */
#define DN_ATTRIB    0x00000020 /* file changed attibutes */
#define DN_MULTISHOT 0x80000000 /* don't remove notifier */



/*!BEGIN libc/sysv/consts/dt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DT_H_

#define DT_UNKNOWN 0
#define DT_FIFO    1
#define DT_CHR     2
#define DT_DIR     4
#define DT_BLK     6
#define DT_REG     8
#define DT_LNK     10
#define DT_SOCK    12



/*!BEGIN libc/sysv/consts/endian.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ENDIAN_H_

#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define __BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define __PDP_ENDIAN    __ORDER_PDP_ENDIAN__
#define __BYTE_ORDER    __BYTE_ORDER__



/*!BEGIN libc/sysv/consts/epoll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EPOLL_H_


/*!BEGIN libc/sysv/consts/o.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_

#define O_RDONLY  0
#define O_WRONLY  1
#define O_RDWR    2
#define O_ACCMODE 3

COSMOPOLITAN_C_START_

extern const unsigned O_APPEND;
extern const unsigned O_ASYNC;
extern const unsigned O_CLOEXEC;
extern const unsigned O_COMPRESSED;
extern const unsigned O_CREAT;
extern const unsigned O_DIRECT;
extern const unsigned O_DIRECTORY;
extern const unsigned O_DSYNC;
extern const unsigned O_EXCL;
extern const unsigned O_EXEC;
extern const unsigned O_EXLOCK;
extern const unsigned O_INDEXED;
extern const unsigned O_LARGEFILE;
extern const unsigned O_NOATIME;
extern const unsigned O_NOCTTY;
extern const unsigned O_NOFOLLOW;
extern const unsigned O_NOFOLLOW_ANY;
extern const unsigned O_NONBLOCK;
extern const unsigned O_PATH;
extern const unsigned O_RANDOM;
extern const unsigned O_RSYNC;
extern const unsigned O_SEARCH;
extern const unsigned O_SEQUENTIAL;
extern const unsigned O_SHLOCK;
extern const unsigned O_SYNC;
extern const unsigned O_TMPFILE; /* use tmpfd() or tmpfile() */
extern const unsigned O_TRUNC;
extern const unsigned O_TTY_INIT;
extern const unsigned O_UNLINK;
extern const unsigned O_VERIFY;

#define O_APPEND     O_APPEND
#define O_ASYNC      O_ASYNC
#define O_CLOEXEC    O_CLOEXEC
#define O_COMPRESSED O_COMPRESSED
#define O_CREAT      O_CREAT
#define O_DIRECTORY  O_DIRECTORY
#define O_EXCL       O_EXCL
#define O_EXEC       O_EXEC
#define O_INDEXED    O_INDEXED
#define O_LARGEFILE  O_LARGEFILE
#define O_NDELAY     O_NONBLOCK
#define O_NOATIME    O_NOATIME
#define O_NOCTTY     O_NOCTTY
#define O_NOFOLLOW   O_NOFOLLOW
#define O_NONBLOCK   O_NONBLOCK
#define O_RANDOM     O_RANDOM
#define O_SEQUENTIAL O_SEQUENTIAL
#define O_SYNC       O_SYNC
#define O_TRUNC      O_TRUNC
#define O_UNLINK     O_UNLINK

COSMOPOLITAN_C_END_

#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_DEL 2
#define EPOLL_CTL_MOD 3

#define EPOLLIN        1
#define EPOLLPRI       2
#define EPOLLOUT       4
#define EPOLLERR       8
#define EPOLLHUP       0x10
#define EPOLLRDNORM    0x40
#define EPOLLRDBAND    0x80
#define EPOLLWRNORM    0x0100
#define EPOLLWRBAND    0x0200
#define EPOLLMSG       0x0400
#define EPOLLRDHUP     0x2000
#define EPOLLEXCLUSIVE 0x10000000
#define EPOLLWAKEUP    0x20000000
#define EPOLLONESHOT   0x40000000
#define EPOLLET        0x80000000

COSMOPOLITAN_C_START_

extern const int EPOLL_CLOEXEC;
#define EPOLL_CLOEXEC O_CLOEXEC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ethernet.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ETHERNET_H_

#define ETHERTYPE_PUP      0x0200
#define ETHERTYPE_SPRITE   0x0500
#define ETHERTYPE_IP       0x0800
#define ETHERTYPE_ARP      0x0806
#define ETHERTYPE_REVARP   0x8035
#define ETHERTYPE_AT       0x809B
#define ETHERTYPE_AARP     0x80F3
#define ETHERTYPE_VLAN     0x8100
#define ETHERTYPE_IPX      0x8137
#define ETHERTYPE_IPV6     0x86dd
#define ETHERTYPE_LOOPBACK 0x9000

#define ETHER_ADDR_LEN ETH_ALEN
#define ETHER_TYPE_LEN 2
#define ETHER_CRC_LEN  4
#define ETHER_HDR_LEN  ETH_HLEN
#define ETHER_MIN_LEN  (ETH_ZLEN + ETHER_CRC_LEN)
#define ETHER_MAX_LEN  (ETH_FRAME_LEN + ETHER_CRC_LEN)

#define ETHER_IS_VALID_LEN(foo) \
  ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)

#define ETHERTYPE_TRAIL    0x1000
#define ETHERTYPE_NTRAILER 16

#define ETHERMTU ETH_DATA_LEN
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)



/*!BEGIN libc/sysv/consts/ex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EX_H_

/**
 * @fileoverview Eric Allman's exit() codes
 *
 * - Broadly supported style guideline;
 * - Dating back to 1980 in 4.0BSD;
 * - That won't be standardized.
 *
 */

#define EX_CANTCREAT   73
#define EX_CONFIG      78
#define EX_DATAERR     65
#define EX_IOERR       74
#define EX_NOHOST      68
#define EX_NOINPUT     66
#define EX_NOPERM      77
#define EX_NOUSER      67
#define EX_OK          0
#define EX_OSERR       71
#define EX_OSFILE      72
#define EX_PROTOCOL    76
#define EX_SOFTWARE    70
#define EX_TEMPFAIL    75
#define EX_UNAVAILABLE 69
#define EX_USAGE       64
#define EX__BASE       64
#define EX__MAX        78



/*!BEGIN libc/sysv/consts/exit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EXIT_H_

#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0



/*!BEGIN libc/sysv/consts/f.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_F_H_
COSMOPOLITAN_C_START_

/*
 * full set of fcntl() commands
 * many are only provided by a single platform
 * will be equal to -1 when not available on host
 */
extern const int F_BARRIERFSYNC;
extern const int F_DUPFD;
extern const int F_DUPFD_CLOEXEC;
extern const int F_FULLFSYNC;
extern const int F_GETFD;
extern const int F_GETFL;
extern const int F_GETLEASE;
extern const int F_GETLK;
extern const int F_GETNOSIGPIPE;
extern const int F_GETOWN;
extern const int F_GETPATH;
extern const int F_GETPIPE_SZ;
extern const int F_GETSIG;
extern const int F_MAXFD;
extern const int F_NOCACHE;
extern const int F_NOTIFY;
extern const int F_OFD_GETLK;
extern const int F_OFD_SETLK;
extern const int F_OFD_SETLKW;
extern const int F_RDLCK;
extern const int F_SETFD;
extern const int F_SETFL;
extern const int F_SETLEASE;
extern const int F_SETLK;
extern const int F_SETLKW;
extern const int F_SETNOSIGPIPE;
extern const int F_SETOWN;
extern const int F_SETPIPE_SZ;
extern const int F_SETSIG;
extern const int F_UNLCK;
extern const int F_WRLCK;

COSMOPOLITAN_C_END_

/*
 * portable fcntl() commands
 */
#define F_DUPFD         0
#define F_GETFD         1
#define F_SETFD         2
#define F_GETFL         3
#define F_SETFL         4
#define F_DUPFD_CLOEXEC F_DUPFD_CLOEXEC

/*
 * posix advisory locks
 * polyfilled poorly on windows
 */
#define F_SETLK  F_SETLK
#define F_SETLKW F_SETLKW
#define F_GETLK  F_GETLK
#define F_RDLCK  F_RDLCK
#define F_UNLCK  F_UNLCK
#define F_WRLCK  F_WRLCK



/*!BEGIN libc/sysv/consts/falloc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FALLOC_H_
COSMOPOLITAN_C_START_

extern const int FALLOC_FL_KEEP_SIZE;
extern const int FALLOC_FL_PUNCH_HOLE;
extern const int FALLOC_FL_NO_HIDE_STALE;
extern const int FALLOC_FL_COLLAPSE_RANGE;
extern const int FALLOC_FL_ZERO_RANGE;
extern const int FALLOC_FL_INSERT_RANGE;
extern const int FALLOC_FL_UNSHARE_RANGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fan.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FAN_H_

#define FAN_CLASS_NOTIF              0
#define FAN_ACCESS                   1
#define FAN_ACCESS_PERM              0x020000
#define FAN_ALLOW                    1
#define FAN_ALL_CLASS_BITS           12
#define FAN_ALL_EVENTS               59
#define FAN_ALL_INIT_FLAGS           63
#define FAN_ALL_MARK_FLAGS           255
#define FAN_ALL_OUTGOING_EVENTS      0x03403b
#define FAN_ALL_PERM_EVENTS          0x030000
#define FAN_CLASS_CONTENT            4
#define FAN_CLASS_PRE_CONTENT        8
#define FAN_CLOEXEC                  1
#define FAN_CLOSE                    24
#define FAN_CLOSE_NOWRITE            0x10
#define FAN_CLOSE_WRITE              8
#define FAN_DENY                     2
#define FAN_EVENT_METADATA_LEN       24
#define FAN_EVENT_ON_CHILD           0x08000000
#define FAN_MARK_ADD                 1
#define FAN_MARK_DONT_FOLLOW         4
#define FAN_MARK_FLUSH               0x80
#define FAN_MARK_IGNORED_MASK        0x20
#define FAN_MARK_IGNORED_SURV_MODIFY 0x40
#define FAN_MARK_MOUNT               0x10
#define FAN_MARK_ONLYDIR             8
#define FAN_MARK_REMOVE              2
#define FAN_MODIFY                   2
#define FAN_NOFD                     -1
#define FAN_NONBLOCK                 2
#define FAN_ONDIR                    0x40000000
#define FAN_OPEN                     0x20
#define FAN_OPEN_PERM                0x010000
#define FAN_Q_OVERFLOW               0x4000
#define FAN_UNLIMITED_MARKS          0x20
#define FAN_UNLIMITED_QUEUE          0x10



/*!BEGIN libc/sysv/consts/fbio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FB_H_
COSMOPOLITAN_C_START_

extern const uint64_t FBIOGET_VSCREENINFO;
extern const uint64_t FBIOPUT_VSCREENINFO;
extern const uint64_t FBIOGET_FSCREENINFO;
extern const uint64_t FBIOGETCMAP;
extern const uint64_t FBIOPUTCMAP;
extern const uint64_t FBIOPAN_DISPLAY;
extern const uint64_t FBIO_WAITFORVSYNC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FD_H_
COSMOPOLITAN_C_START_

extern const int FD_CLOEXEC;

#define FD_CLOEXEC 1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fileno.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FILENO_H_

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2



/*!BEGIN libc/sysv/consts/fio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FIO_H_
COSMOPOLITAN_C_START_

extern const uint32_t FIONREAD; /* one of the few encouraged ioctls */
extern const uint32_t FIONBIO;  /* use fcntl(fd, F_SETFL, O_NONBLOCK) */
extern const uint32_t FIOCLEX;  /* use fcntl(fd, F_SETFD, FD_CLOEXEC) */
extern const uint32_t FIONCLEX; /* use fcntl(fd, F_SETFD, 0) */
extern const uint32_t FIOASYNC; /* todo: fcntl(fd, F_SETOWN, pid) */

#define FIONREAD FIONREAD

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fs.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FS_H_

#define FS_IOC_GETFLAGS   0x80086601
#define FS_IOC_SETFLAGS   0x40086602
#define FS_IOC_GETVERSION 0x80087601
#define FS_IOC_SETVERSION 0x40087602
#define FS_IOC_FIEMAP     0xc020660b
#define FS_IOC_FSGETXATTR 0x801c581f
#define FS_IOC_FSSETXATTR 0x401c5820
#define FS_IOC_GETFSLABEL 0x81009431
#define FS_IOC_SETFSLABEL 0x41009432

#define FS_FL_USER_VISIBLE    0x0003DFFF /* user visible flags */
#define FS_FL_USER_MODIFIABLE 0x000380FF /* user modifiable flags */
#define FS_SECRM_FL           0x00000001 /* secure deletion */
#define FS_UNRM_FL            0x00000002 /* undelete */
#define FS_COMPR_FL           0x00000004 /* compress */
#define FS_SYNC_FL            0x00000008 /* synchronous */
#define FS_IMMUTABLE_FL       0x00000010
#define FS_APPEND_FL          0x00000020 /* append-only */
#define FS_NODUMP_FL          0x00000040
#define FS_NOATIME_FL         0x00000080
#define FS_DIRTY_FL           0x00000100
#define FS_COMPRBLK_FL        0x00000200
#define FS_NOCOMP_FL          0x00000400
#define FS_ENCRYPT_FL         0x00000800 /* encrypted file */
#define FS_BTREE_FL           0x00001000
#define FS_INDEX_FL           0x00001000 /* hash-indexed directory */
#define FS_IMAGIC_FL          0x00002000
#define FS_JOURNAL_DATA_FL    0x00004000
#define FS_NOTAIL_FL          0x00008000
#define FS_DIRSYNC_FL         0x00010000
#define FS_TOPDIR_FL          0x00020000
#define FS_HUGE_FILE_FL       0x00040000
#define FS_EXTENT_FL          0x00080000



/*!BEGIN libc/sysv/consts/futex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FUTEX_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_

extern const int FUTEX_WAIT;
extern const int FUTEX_WAKE;
extern const int FUTEX_REQUEUE;

#define FUTEX_WAIT         FUTEX_WAIT
#define FUTEX_WAKE         FUTEX_WAKE
#define FUTEX_REQUEUE      FUTEX_REQUEUE
#define FUTEX_PRIVATE_FLAG 128

#define FUTEX_WAIT_PRIVATE    (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAKE_PRIVATE    (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)

#define FUTEX_WAIT_BITSET      9
#define FUTEX_CLOCK_REALTIME   256
#define FUTEX_BITSET_MATCH_ANY 0xffffffff

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/grnd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_GRND_H_

#define GRND_NONBLOCK 1
#define GRND_RANDOM   2



/*!BEGIN libc/sysv/consts/hwcap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_HWCAP_H_
#ifdef __aarch64__

// Feature bits for getauxval(AT_HWCAP) on AARCH64 GNU/SystemD.

#define HWCAP_FP       (1 << 0)
#define HWCAP_ASIMD    (1 << 1)
#define HWCAP_EVTSTRM  (1 << 2)
#define HWCAP_AES      (1 << 3)
#define HWCAP_PMULL    (1 << 4)
#define HWCAP_SHA1     (1 << 5)
#define HWCAP_SHA2     (1 << 6)
#define HWCAP_CRC32    (1 << 7)
#define HWCAP_ATOMICS  (1 << 8)
#define HWCAP_FPHP     (1 << 9)
#define HWCAP_ASIMDHP  (1 << 10)
#define HWCAP_CPUID    (1 << 11)
#define HWCAP_ASIMDRDM (1 << 12)
#define HWCAP_JSCVT    (1 << 13)
#define HWCAP_FCMA     (1 << 14)
#define HWCAP_LRCPC    (1 << 15)
#define HWCAP_DCPOP    (1 << 16)
#define HWCAP_SHA3     (1 << 17)
#define HWCAP_SM3      (1 << 18)
#define HWCAP_SM4      (1 << 19)
#define HWCAP_ASIMDDP  (1 << 20)
#define HWCAP_SHA512   (1 << 21)
#define HWCAP_SVE      (1 << 22)
#define HWCAP_ASIMDFHM (1 << 23)
#define HWCAP_DIT      (1 << 24)
#define HWCAP_USCAT    (1 << 25)
#define HWCAP_ILRCPC   (1 << 26)
#define HWCAP_FLAGM    (1 << 27)
#define HWCAP_SSBS     (1 << 28)
#define HWCAP_SB       (1 << 29)
#define HWCAP_PACA     (1 << 30)
#define HWCAP_PACG     (1UL << 31)

#define HWCAP2_DCPODP     (1 << 0)
#define HWCAP2_SVE2       (1 << 1)
#define HWCAP2_SVEAES     (1 << 2)
#define HWCAP2_SVEPMULL   (1 << 3)
#define HWCAP2_SVEBITPERM (1 << 4)
#define HWCAP2_SVESHA3    (1 << 5)
#define HWCAP2_SVESM4     (1 << 6)
#define HWCAP2_FLAGM2     (1 << 7)
#define HWCAP2_FRINT      (1 << 8)
#define HWCAP2_SVEI8MM    (1 << 9)
#define HWCAP2_SVEF32MM   (1 << 10)
#define HWCAP2_SVEF64MM   (1 << 11)
#define HWCAP2_SVEBF16    (1 << 12)
#define HWCAP2_I8MM       (1 << 13)
#define HWCAP2_BF16       (1 << 14)
#define HWCAP2_DGH        (1 << 15)
#define HWCAP2_RNG        (1 << 16)
#define HWCAP2_BTI        (1 << 17)
#define HWCAP2_MTE        (1 << 18)

#endif /* __aarch64__ */


/*!BEGIN libc/sysv/consts/icmp6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ICMP6_H_

#define ICMP6_DST_UNREACH ICMP6_DST_UNREACH
#define ICMP6_DST_UNREACH_ADDR ICMP6_DST_UNREACH_ADDR
#define ICMP6_DST_UNREACH_ADMIN ICMP6_DST_UNREACH_ADMIN
#define ICMP6_DST_UNREACH_BEYONDSCOPE ICMP6_DST_UNREACH_BEYONDSCOPE
#define ICMP6_DST_UNREACH_NOPORT ICMP6_DST_UNREACH_NOPORT
#define ICMP6_DST_UNREACH_NOROUTE ICMP6_DST_UNREACH_NOROUTE
#define ICMP6_ECHO_REPLY ICMP6_ECHO_REPLY
#define ICMP6_ECHO_REQUEST ICMP6_ECHO_REQUEST
#define ICMP6_FILTER ICMP6_FILTER
#define ICMP6_INFOMSG_MASK ICMP6_INFOMSG_MASK
#define ICMP6_PACKET_TOO_BIG ICMP6_PACKET_TOO_BIG
#define ICMP6_PARAMPROB_HEADER ICMP6_PARAMPROB_HEADER
#define ICMP6_PARAMPROB_NEXTHEADER ICMP6_PARAMPROB_NEXTHEADER
#define ICMP6_PARAMPROB_OPTION ICMP6_PARAMPROB_OPTION
#define ICMP6_PARAM_PROB ICMP6_PARAM_PROB
#define ICMP6_ROUTER_RENUMBERING ICMP6_ROUTER_RENUMBERING
#define ICMP6_RR_FLAGS_FORCEAPPLY ICMP6_RR_FLAGS_FORCEAPPLY
#define ICMP6_RR_FLAGS_PREVDONE ICMP6_RR_FLAGS_PREVDONE
#define ICMP6_RR_FLAGS_REQRESULT ICMP6_RR_FLAGS_REQRESULT
#define ICMP6_RR_FLAGS_SPECSITE ICMP6_RR_FLAGS_SPECSITE
#define ICMP6_RR_FLAGS_TEST ICMP6_RR_FLAGS_TEST
#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO ICMP6_RR_PCOUSE_RAFLAGS_AUTO
#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN \
  ICMP6_RR_RESULT_FLAGS_FORBIDDEN
#define ICMP6_RR_RESULT_FLAGS_OOB ICMP6_RR_RESULT_FLAGS_OOB
#define ICMP6_TIME_EXCEEDED ICMP6_TIME_EXCEEDED
#define ICMP6_TIME_EXCEED_REASSEMBLY ICMP6_TIME_EXCEED_REASSEMBLY
#define ICMP6_TIME_EXCEED_TRANSIT ICMP6_TIME_EXCEED_TRANSIT

COSMOPOLITAN_C_START_

extern const uint8_t ICMP6_DST_UNREACH;
extern const uint8_t ICMP6_DST_UNREACH_ADDR;
extern const uint8_t ICMP6_DST_UNREACH_ADMIN;
extern const uint8_t ICMP6_DST_UNREACH_BEYONDSCOPE;
extern const uint8_t ICMP6_DST_UNREACH_NOPORT;
extern const uint8_t ICMP6_DST_UNREACH_NOROUTE;
extern const uint8_t ICMP6_ECHO_REPLY;
extern const uint8_t ICMP6_ECHO_REQUEST;
extern const uint8_t ICMP6_FILTER;
extern const uint8_t ICMP6_INFOMSG_MASK;
extern const uint8_t ICMP6_PACKET_TOO_BIG;
extern const uint8_t ICMP6_PARAMPROB_HEADER;
extern const uint8_t ICMP6_PARAMPROB_NEXTHEADER;
extern const uint8_t ICMP6_PARAMPROB_OPTION;
extern const uint8_t ICMP6_PARAM_PROB;
extern const uint8_t ICMP6_ROUTER_RENUMBERING;
extern const uint8_t ICMP6_RR_FLAGS_FORCEAPPLY;
extern const uint8_t ICMP6_RR_FLAGS_PREVDONE;
extern const uint8_t ICMP6_RR_FLAGS_REQRESULT;
extern const uint8_t ICMP6_RR_FLAGS_SPECSITE;
extern const uint8_t ICMP6_RR_FLAGS_TEST;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_AUTO;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_ONLINK;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_FORBIDDEN;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_OOB;
extern const uint8_t ICMP6_TIME_EXCEEDED;
extern const uint8_t ICMP6_TIME_EXCEED_REASSEMBLY;
extern const uint8_t ICMP6_TIME_EXCEED_TRANSIT;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/iff.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IFF_H_
COSMOPOLITAN_C_START_

extern const int IFF_UP;
extern const int IFF_ALLMULTI;
extern const int IFF_AUTOMEDIA;
extern const int IFF_BROADCAST;
extern const int IFF_DEBUG;
extern const int IFF_DYNAMIC;
extern const int IFF_LOOPBACK;
extern const int IFF_MASTER;
extern const int IFF_MULTICAST;
extern const int IFF_NOARP;
extern const int IFF_NOTRAILERS;
extern const int IFF_POINTOPOINT;
extern const int IFF_PORTSEL;
extern const int IFF_PROMISC;
extern const int IFF_RUNNING;
extern const int IFF_SLAVE;

COSMOPOLITAN_C_END_

#define IFF_UP          1
#define IFF_BROADCAST   2
#define IFF_DEBUG       4
#define IFF_LOOPBACK    8
#define IFF_ALLMULTI    IFF_ALLMULTI
#define IFF_AUTOMEDIA   IFF_AUTOMEDIA
#define IFF_DYNAMIC     IFF_DYNAMIC
#define IFF_MASTER      IFF_MASTER
#define IFF_MULTICAST   IFF_MULTICAST
#define IFF_NOARP       IFF_NOARP
#define IFF_NOTRAILERS  IFF_NOTRAILERS
#define IFF_POINTOPOINT IFF_POINTOPOINT
#define IFF_PORTSEL     IFF_PORTSEL
#define IFF_PROMISC     IFF_PROMISC
#define IFF_RUNNING     IFF_RUNNING
#define IFF_SLAVE       IFF_SLAVE




/*!BEGIN libc/sysv/consts/in.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IN_H_

#define IN_ACCESS        1
#define IN_ALL_EVENTS    0x0fff
#define IN_ATTRIB        4
#define IN_CLOEXEC       0x080000
#define IN_CLOSE         24
#define IN_CLOSE_NOWRITE 0x10
#define IN_CLOSE_WRITE   8
#define IN_CREATE        0x0100
#define IN_DELETE        0x0200
#define IN_DELETE_SELF   0x0400
#define IN_DONT_FOLLOW   0x02000000
#define IN_EXCL_UNLINK   0x04000000
#define IN_IGNORED       0x8000
#define IN_ISDIR         0x40000000
#define IN_MASK_ADD      0x20000000
#define IN_MODIFY        2
#define IN_MOVE          192
#define IN_MOVED_FROM    0x40
#define IN_MOVED_TO      0x80
#define IN_MOVE_SELF     0x0800
#define IN_NONBLOCK      0x0800
#define IN_ONESHOT       0x80000000
#define IN_ONLYDIR       0x01000000
#define IN_OPEN          0x20
#define IN_Q_OVERFLOW    0x4000
#define IN_UNMOUNT       0x2000
#define IN_CLASSA_NSHIFT 24



/*!BEGIN libc/sysv/consts/inaddr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INADDR_H_

/**
 * @fileoverview Well-known Internet addresses.
 * These need to be hard-coded as little-endian, so htonl() is needed.
 */

#define INADDR_ANY       0x00000000u /* 0.0.0.0 */
#define INADDR_BROADCAST 0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_NONE      0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_LOOPBACK  0x7F000001u /* 127.0.0.1 */
#define INADDR_TESTNET1  0xC0000200u /* 192.0.2.0/24 (RFC5737§3) */
#define INADDR_TESTNET2  0xC6336400u /* 198.51.100.0/24 */
#define INADDR_TESTNET3  0xCB007100u /* 203.0.113.0/24 */

#define INADDR_ALLHOSTS_GROUP  0xE0000001u
#define INADDR_ALLRTRS_GROUP   0xE0000002u
#define INADDR_MAX_LOCAL_GROUP 0xE00000FFu
#define INADDR_UNSPEC_GROUP    0xE0000000u

#define IN_LOOPBACKNET 127

/* clang-format off */
#define IN6ADDR_ANY_INIT      { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
/* clang-format on */



/*!BEGIN libc/sysv/consts/inet6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INET6_H_

#define INET6_ADDRSTRLEN 48



/*!BEGIN libc/sysv/consts/io.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IO_H_
COSMOPOLITAN_C_START_

#define _IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16))
#define _IOC_NONE        0U
#define _IOC_WRITE       1U
#define _IOC_READ        2U

#define _IO(a, b)      _IOC(_IOC_NONE, (a), (b), 0)
#define _IOW(a, b, c)  _IOC(_IOC_WRITE, (a), (b), sizeof(c))
#define _IOR(a, b, c)  _IOC(_IOC_READ, (a), (b), sizeof(c))
#define _IOWR(a, b, c) _IOC(_IOC_READ | _IOC_WRITE, (a), (b), sizeof(c))

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ioprio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOPRIO_H_
#ifdef _COSMO_SOURCE

#define IOPRIO_WHO_PROCESS 1
#define IOPRIO_WHO_PGRP    2
#define IOPRIO_WHO_USER    3

#define IOPRIO_CLASS_SHIFT 13
#define IOPRIO_CLASS_MASK  0x07
#define IOPRIO_PRIO_MASK   ((1UL << IOPRIO_CLASS_SHIFT) - 1)

#define IOPRIO_PRIO_CLASS(ioprio) \
  (((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)
#define IOPRIO_PRIO_DATA(ioprio) ((ioprio)&IOPRIO_PRIO_MASK)
#define IOPRIO_PRIO_VALUE(class, data)                     \
  ((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \
   ((data)&IOPRIO_PRIO_MASK))

#define IOPRIO_CLASS_NONE 0
#define IOPRIO_CLASS_RT   1
#define IOPRIO_CLASS_BE   2
#define IOPRIO_CLASS_IDLE 3

#define IOPRIO_NR_LEVELS 8
#define IOPRIO_BE_NR     IOPRIO_NR_LEVELS

#define IOPRIO_NORM    4
#define IOPRIO_BE_NORM IOPRIO_NORM

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/iov.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOV_H_
COSMOPOLITAN_C_START_

extern const int IOV_MAX;

COSMOPOLITAN_C_END_

#define IOV_MAX IOV_MAX



/*!BEGIN libc/sysv/consts/ip.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IP_H_
COSMOPOLITAN_C_START_

extern const int IP_ADD_MEMBERSHIP;
extern const int IP_ADD_SOURCE_MEMBERSHIP;
extern const int IP_BIND_ADDRESS_NO_PORT;
extern const int IP_BLOCK_SOURCE;
extern const int IP_CHECKSUM;
extern const int IP_DEFAULT_MULTICAST_LOOP;
extern const int IP_DEFAULT_MULTICAST_TTL;
extern const int IP_DROP_MEMBERSHIP;
extern const int IP_DROP_SOURCE_MEMBERSHIP;
extern const int IP_FREEBIND;
extern const int IP_HDRINCL;
extern const int IP_IPSEC_POLICY;
extern const int IP_MAX_MEMBERSHIPS;
extern const int IP_MINTTL;
extern const int IP_MSFILTER;
extern const int IP_MTU;
extern const int IP_MTU_DISCOVER;
extern const int IP_MULTICAST_ALL;
extern const int IP_MULTICAST_IF;
extern const int IP_MULTICAST_LOOP;
extern const int IP_MULTICAST_TTL;
extern const int IP_NODEFRAG;
extern const int IP_OPTIONS;
extern const int IP_ORIGDSTADDR;
extern const int IP_PASSSEC;
extern const int IP_PKTINFO;
extern const int IP_PKTOPTIONS;
extern const int IP_PMTUDISC;
extern const int IP_PMTUDISC_DO;
extern const int IP_PMTUDISC_DONT;
extern const int IP_PMTUDISC_INTERFACE;
extern const int IP_PMTUDISC_OMIT;
extern const int IP_PMTUDISC_PROBE;
extern const int IP_PMTUDISC_WANT;
extern const int IP_RECVDSTADDR;
extern const int IP_RECVERR;
extern const int IP_RECVOPTS;
extern const int IP_RECVORIGDSTADDR;
extern const int IP_RECVRETOPTS;
extern const int IP_RECVTOS;
extern const int IP_RECVTTL;
extern const int IP_RETOPTS;
extern const int IP_ROUTER_ALERT;
extern const int IP_TOS;
extern const int IP_TRANSPARENT;
extern const int IP_TTL;
extern const int IP_UNBLOCK_SOURCE;
extern const int IP_UNICAST_IF;
extern const int IP_XFRM_POLICY;

#define IP_ADD_MEMBERSHIP         IP_ADD_MEMBERSHIP
#define IP_ADD_SOURCE_MEMBERSHIP  IP_ADD_SOURCE_MEMBERSHIP
#define IP_BIND_ADDRESS_NO_PORT   IP_BIND_ADDRESS_NO_PORT
#define IP_BLOCK_SOURCE           IP_BLOCK_SOURCE
#define IP_CHECKSUM               IP_CHECKSUM
#define IP_DEFAULT_MULTICAST_LOOP IP_DEFAULT_MULTICAST_LOOP
#define IP_DEFAULT_MULTICAST_TTL  IP_DEFAULT_MULTICAST_TTL
#define IP_DROP_MEMBERSHIP        IP_DROP_MEMBERSHIP
#define IP_DROP_SOURCE_MEMBERSHIP IP_DROP_SOURCE_MEMBERSHIP
#define IP_FREEBIND               IP_FREEBIND
#define IP_HDRINCL                IP_HDRINCL
#define IP_IPSEC_POLICY           IP_IPSEC_POLICY
#define IP_MAX_MEMBERSHIPS        IP_MAX_MEMBERSHIPS
#define IP_MINTTL                 IP_MINTTL
#define IP_MSFILTER               IP_MSFILTER
#define IP_MTU                    IP_MTU
#define IP_MTU_DISCOVER           IP_MTU_DISCOVER
#define IP_MULTICAST_ALL          IP_MULTICAST_ALL
#define IP_MULTICAST_IF           IP_MULTICAST_IF
#define IP_MULTICAST_LOOP         IP_MULTICAST_LOOP
#define IP_MULTICAST_TTL          IP_MULTICAST_TTL
#define IP_NODEFRAG               IP_NODEFRAG
#define IP_OPTIONS                IP_OPTIONS
#define IP_ORIGDSTADDR            IP_ORIGDSTADDR
#define IP_PASSSEC                IP_PASSSEC
#define IP_PKTINFO                IP_PKTINFO
#define IP_PKTOPTIONS             IP_PKTOPTIONS
#define IP_PMTUDISC               IP_PMTUDISC
#define IP_PMTUDISC_DO            IP_PMTUDISC_DO
#define IP_PMTUDISC_DONT          IP_PMTUDISC_DONT
#define IP_PMTUDISC_INTERFACE     IP_PMTUDISC_INTERFACE
#define IP_PMTUDISC_OMIT          IP_PMTUDISC_OMIT
#define IP_PMTUDISC_PROBE         IP_PMTUDISC_PROBE
#define IP_PMTUDISC_WANT          IP_PMTUDISC_WANT
#define IP_RECVDSTADDR            IP_RECVDSTADDR
#define IP_RECVERR                IP_RECVERR
#define IP_RECVOPTS               IP_RECVOPTS
#define IP_RECVORIGDSTADDR        IP_RECVORIGDSTADDR
#define IP_RECVRETOPTS            IP_RECVRETOPTS
#define IP_RECVTOS                IP_RECVTOS
#define IP_RECVTTL                IP_RECVTTL
#define IP_RETOPTS                IP_RETOPTS
#define IP_ROUTER_ALERT           IP_ROUTER_ALERT
#define IP_TOS                    IP_TOS
#define IP_TRANSPARENT            IP_TRANSPARENT
#define IP_TTL                    IP_TTL
#define IP_UNBLOCK_SOURCE         IP_UNBLOCK_SOURCE
#define IP_UNICAST_IF             IP_UNICAST_IF
#define IP_XFRM_POLICY            IP_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipport.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPORT_H_

/**
 * ARPA network ports.
 */
#define IPPORT_ECHO         7
#define IPPORT_DISCARD      9
#define IPPORT_SYSTAT       11
#define IPPORT_DAYTIME      13
#define IPPORT_NETSTAT      15
#define IPPORT_FTP          21
#define IPPORT_TELNET       23
#define IPPORT_SMTP         25
#define IPPORT_TIMESERVER   37
#define IPPORT_NAMESERVER   42
#define IPPORT_WHOIS        43
#define IPPORT_MTP          57
#define IPPORT_TFTP         69
#define IPPORT_RJE          77
#define IPPORT_FINGER       79
#define IPPORT_TTYLINK      87
#define IPPORT_SUPDUP       95
#define IPPORT_EXECSERVER   512
#define IPPORT_LOGINSERVER  513
#define IPPORT_CMDSERVER    514
#define IPPORT_EFSSERVER    520
#define IPPORT_BIFFUDP      512
#define IPPORT_WHOSERVER    513
#define IPPORT_ROUTESERVER  520
#define IPPORT_RESERVED     1024
#define IPPORT_USERRESERVED IPPORT_USERRESERVED

/**
 * Modern network ports.
 */
#define IPPORT_SSH         22
#define IPPORT_DOMAIN      53
#define IPPORT_HTTP        80
#define IPPORT_POP3        110
#define IPPORT_SFTP        115
#define IPPORT_NTP         123
#define IPPORT_IMAP2       143
#define IPPORT_NETBIOS_NS  137
#define IPPORT_NETBIOS_DGM 138
#define IPPORT_NETBIOS_SSN 139
#define IPPORT_BGP         179
#define IPPORT_IRC         194
#define IPPORT_HTTPS       443
#define IPPORT_PRINTER     515
#define IPPORT_NFS         2049
#define IPPORT_DISTCC      3632
#define IPPORT_SIP         5060
#define IPPORT_POSTGRESQL  5432
#define IPPORT_X11         6000
#define IPPORT_GIT         9418
#define IPPORT_IRCD        6667
#define IPPORT_IMAPS       993
#define IPPORT_POP3S       995

COSMOPOLITAN_C_START_

extern const int IPPORT_USERRESERVED;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipproto.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPROTO_H_

#define IPPROTO_IP     0
#define IPPROTO_ICMP   1
#define IPPROTO_TCP    6
#define IPPROTO_UDP    17
#define IPPROTO_IPV6   41
#define IPPROTO_ICMPV6 58
#define IPPROTO_RAW    255
#define IPPROTO_MAX    263 /* xxx */



/*!BEGIN libc/sysv/consts/ipv6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPV6_H_
COSMOPOLITAN_C_START_

extern const int IPV6_2292DSTOPTS;
extern const int IPV6_2292HOPLIMIT;
extern const int IPV6_2292HOPOPTS;
extern const int IPV6_2292PKTINFO;
extern const int IPV6_2292PKTOPTIONS;
extern const int IPV6_2292RTHDR;
extern const int IPV6_ADDRFORM;
extern const int IPV6_ADD_MEMBERSHIP;
extern const int IPV6_AUTHHDR;
extern const int IPV6_AUTOFLOWLABEL;
extern const int IPV6_CHECKSUM;
extern const int IPV6_DONTFRAG;
extern const int IPV6_DROP_MEMBERSHIP;
extern const int IPV6_DSTOPTS;
extern const int IPV6_HDRINCL;
extern const int IPV6_HOPLIMIT;
extern const int IPV6_HOPOPTS;
extern const int IPV6_IPSEC_POLICY;
extern const int IPV6_JOIN_ANYCAST;
extern const int IPV6_JOIN_GROUP;
extern const int IPV6_LEAVE_ANYCAST;
extern const int IPV6_LEAVE_GROUP;
extern const int IPV6_MINHOPCOUNT;
extern const int IPV6_MTU;
extern const int IPV6_MTU_DISCOVER;
extern const int IPV6_MULTICAST_HOPS;
extern const int IPV6_MULTICAST_IF;
extern const int IPV6_MULTICAST_LOOP;
extern const int IPV6_NEXTHOP;
extern const int IPV6_ORIGDSTADDR;
extern const int IPV6_PATHMTU;
extern const int IPV6_PKTINFO;
extern const int IPV6_PMTUDISC_DO;
extern const int IPV6_PMTUDISC_DONT;
extern const int IPV6_PMTUDISC_INTERFACE;
extern const int IPV6_PMTUDISC_OMIT;
extern const int IPV6_PMTUDISC_PROBE;
extern const int IPV6_PMTUDISC_WANT;
extern const int IPV6_RECVDSTOPTS;
extern const int IPV6_RECVERR;
extern const int IPV6_RECVHOPLIMIT;
extern const int IPV6_RECVHOPOPTS;
extern const int IPV6_RECVORIGDSTADDR;
extern const int IPV6_RECVPATHMTU;
extern const int IPV6_RECVPKTINFO;
extern const int IPV6_RECVRTHDR;
extern const int IPV6_RECVTCLASS;
extern const int IPV6_ROUTER_ALERT;
extern const int IPV6_RTHDR;
extern const int IPV6_RTHDRDSTOPTS;
extern const int IPV6_RTHDR_LOOSE;
extern const int IPV6_RTHDR_STRICT;
extern const int IPV6_RTHDR_TYPE_0;
extern const int IPV6_RXDSTOPTS;
extern const int IPV6_RXHOPOPTS;
extern const int IPV6_TCLASS;
extern const int IPV6_UNICAST_HOPS;
extern const int IPV6_V6ONLY;
extern const int IPV6_XFRM_POLICY;

#define IPV6_2292DSTOPTS        IPV6_2292DSTOPTS
#define IPV6_2292HOPLIMIT       IPV6_2292HOPLIMIT
#define IPV6_2292HOPOPTS        IPV6_2292HOPOPTS
#define IPV6_2292PKTINFO        IPV6_2292PKTINFO
#define IPV6_2292PKTOPTIONS     IPV6_2292PKTOPTIONS
#define IPV6_2292RTHDR          IPV6_2292RTHDR
#define IPV6_ADDRFORM           IPV6_ADDRFORM
#define IPV6_ADD_MEMBERSHIP     IPV6_ADD_MEMBERSHIP
#define IPV6_AUTHHDR            IPV6_AUTHHDR
#define IPV6_AUTOFLOWLABEL      IPV6_AUTOFLOWLABEL
#define IPV6_CHECKSUM           IPV6_CHECKSUM
#define IPV6_DONTFRAG           IPV6_DONTFRAG
#define IPV6_DROP_MEMBERSHIP    IPV6_DROP_MEMBERSHIP
#define IPV6_DSTOPTS            IPV6_DSTOPTS
#define IPV6_HDRINCL            IPV6_HDRINCL
#define IPV6_HOPLIMIT           IPV6_HOPLIMIT
#define IPV6_HOPOPTS            IPV6_HOPOPTS
#define IPV6_IPSEC_POLICY       IPV6_IPSEC_POLICY
#define IPV6_JOIN_ANYCAST       IPV6_JOIN_ANYCAST
#define IPV6_JOIN_GROUP         IPV6_JOIN_GROUP
#define IPV6_LEAVE_ANYCAST      IPV6_LEAVE_ANYCAST
#define IPV6_LEAVE_GROUP        IPV6_LEAVE_GROUP
#define IPV6_MINHOPCOUNT        IPV6_MINHOPCOUNT
#define IPV6_MTU                IPV6_MTU
#define IPV6_MTU_DISCOVER       IPV6_MTU_DISCOVER
#define IPV6_MULTICAST_HOPS     IPV6_MULTICAST_HOPS
#define IPV6_MULTICAST_IF       IPV6_MULTICAST_IF
#define IPV6_MULTICAST_LOOP     IPV6_MULTICAST_LOOP
#define IPV6_NEXTHOP            IPV6_NEXTHOP
#define IPV6_ORIGDSTADDR        IPV6_ORIGDSTADDR
#define IPV6_PATHMTU            IPV6_PATHMTU
#define IPV6_PKTINFO            IPV6_PKTINFO
#define IPV6_PMTUDISC_DO        IPV6_PMTUDISC_DO
#define IPV6_PMTUDISC_DONT      IPV6_PMTUDISC_DONT
#define IPV6_PMTUDISC_INTERFACE IPV6_PMTUDISC_INTERFACE
#define IPV6_PMTUDISC_OMIT      IPV6_PMTUDISC_OMIT
#define IPV6_PMTUDISC_PROBE     IPV6_PMTUDISC_PROBE
#define IPV6_PMTUDISC_WANT      IPV6_PMTUDISC_WANT
#define IPV6_RECVDSTOPTS        IPV6_RECVDSTOPTS
#define IPV6_RECVERR            IPV6_RECVERR
#define IPV6_RECVHOPLIMIT       IPV6_RECVHOPLIMIT
#define IPV6_RECVHOPOPTS        IPV6_RECVHOPOPTS
#define IPV6_RECVORIGDSTADDR    IPV6_RECVORIGDSTADDR
#define IPV6_RECVPATHMTU        IPV6_RECVPATHMTU
#define IPV6_RECVPKTINFO        IPV6_RECVPKTINFO
#define IPV6_RECVRTHDR          IPV6_RECVRTHDR
#define IPV6_RECVTCLASS         IPV6_RECVTCLASS
#define IPV6_ROUTER_ALERT       IPV6_ROUTER_ALERT
#define IPV6_RTHDR              IPV6_RTHDR
#define IPV6_RTHDRDSTOPTS       IPV6_RTHDRDSTOPTS
#define IPV6_RTHDR_LOOSE        IPV6_RTHDR_LOOSE
#define IPV6_RTHDR_STRICT       IPV6_RTHDR_STRICT
#define IPV6_RTHDR_TYPE_0       IPV6_RTHDR_TYPE_0
#define IPV6_RXDSTOPTS          IPV6_RXDSTOPTS
#define IPV6_RXHOPOPTS          IPV6_RXHOPOPTS
#define IPV6_TCLASS             IPV6_TCLASS
#define IPV6_UNICAST_HOPS       IPV6_UNICAST_HOPS
#define IPV6_V6ONLY             IPV6_V6ONLY
#define IPV6_XFRM_POLICY        IPV6_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/itimer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ITIMER_H_

#define ITIMER_REAL    0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF    2



/*!BEGIN libc/sysv/consts/kd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KD_H_
COSMOPOLITAN_C_START_

extern const uint64_t GIO_FONT;
extern const uint64_t PIO_FONT;
extern const uint64_t GIO_FONTX;
extern const uint64_t PIO_FONTX;
extern const uint64_t PIO_FONT8x8;
extern const uint64_t PIO_FONT8x14;
extern const uint64_t PIO_FONT8x16;
extern const uint64_t PIO_VFONT;
extern const uint64_t PIO_FONTRESET;
extern const uint64_t KDFONTOP;

COSMOPOLITAN_C_END_

#define GIO_FONT      GIO_FONT
#define PIO_FONT      PIO_FONT
#define GIO_FONTX     GIO_FONTX
#define PIO_FONTX     PIO_FONTX
#define PIO_FONT8x8   PIO_FONT8x8
#define PIO_FONT8x14  PIO_FONT8x14
#define PIO_FONT8x16  PIO_FONT8x14
#define PIO_VFONT     PIO_VFONT
#define PIO_FONTRESET PIO_FONTRESET
#define KDFONTOP      KDFONTOP

#ifdef _BSD_SOURCE
#define PIO_VFONT_DEFAULT PIO_FONTRESET
#endif



/*!BEGIN libc/sysv/consts/kern.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KERN_H_
COSMOPOLITAN_C_START_

#define KERN_SOH       "\001"
#define KERN_SOH_ASCII '\001'
#define KERN_EMERG     KERN_SOH "0"
#define KERN_ALERT     KERN_SOH "1"
#define KERN_CRIT      KERN_SOH "2"
#define KERN_ERR       KERN_SOH "3"
#define KERN_WARNING   KERN_SOH "4"
#define KERN_NOTICE    KERN_SOH "5"
#define KERN_INFO      KERN_SOH "6"
#define KERN_DEBUG     KERN_SOH "7"
#define KERN_DEFAULT   ""
#define KERN_CONT      KERN_SOH "c"

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/l.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_L_H_

#define L_SET  SEEK_SET
#define L_INCR SEEK_CUR
#define L_XTND SEEK_END



/*!BEGIN libc/sysv/consts/limits.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIMITS_H_
COSMOPOLITAN_C_START_

extern const int NGROUPS_MAX;
extern const int PIPE_BUF;
extern const int SOMAXCONN;
extern const int _ARG_MAX;
extern const int _NAME_MAX;
extern const int _NSIG;
extern const int _PATH_MAX;
extern const int LINK_MAX;
extern const int MAX_CANON;
extern const int MAX_INPUT;

#define NGROUPS_MAX NGROUPS_MAX
#define PIPE_BUF    PIPE_BUF
#define SOMAXCONN   SOMAXCONN
#define _ARG_MAX    _ARG_MAX
#define _NAME_MAX   _NAME_MAX
#define _NSIG       _NSIG
#define _PATH_MAX   _PATH_MAX
#define LINK_MAX    LINK_MAX
#define MAX_CANON   MAX_CANON
#define MAX_INPUT   MAX_INPUT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIO_H_

#define LIO_NOP LIO_NOP
#define LIO_NOWAIT LIO_NOWAIT
#define LIO_READ LIO_READ
#define LIO_WAIT LIO_WAIT
#define LIO_WRITE LIO_WRITE

COSMOPOLITAN_C_START_

extern const int LIO_NOP;
extern const int LIO_NOWAIT;
extern const int LIO_READ;
extern const int LIO_WAIT;
extern const int LIO_WRITE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOCK_H_
COSMOPOLITAN_C_START_

extern const int LOCK_EX;
extern const int LOCK_NB;
extern const int LOCK_SH;
extern const int LOCK_UN;
extern const int LOCK_UNLOCK_CACHE;

COSMOPOLITAN_C_END_

#define LOCK_EX 2
#define LOCK_NB LOCK_NB
#define LOCK_SH LOCK_SH
#define LOCK_UN LOCK_UN




/*!BEGIN libc/sysv/consts/log.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOG_H_

#define LOG_MASK(pri) (1 << (pri))
#define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)

#define LOG_EMERG   0
#define LOG_ALERT   1
#define LOG_CRIT    2
#define LOG_ERR     3
#define LOG_WARNING 4
#define LOG_NOTICE  5
#define LOG_INFO    6
#define LOG_DEBUG   7

#define LOG_KERN     0000
#define LOG_USER     0010
#define LOG_MAIL     0020
#define LOG_DAEMON   0030
#define LOG_AUTH     0040
#define LOG_SYSLOG   0050
#define LOG_LPR      0060
#define LOG_NEWS     0070
#define LOG_UUCP     0100
#define LOG_CRON     0110
#define LOG_AUTHPRIV 0120
#define LOG_FTP      0130

#define LOG_PID    1
#define LOG_CONS   2
#define LOG_ODELAY 4
#define LOG_NDELAY 8
#define LOG_NOWAIT 16
#define LOG_PERROR 32

#define LOG_LOCAL0 128
#define LOG_LOCAL1 136
#define LOG_LOCAL2 144
#define LOG_LOCAL3 152
#define LOG_LOCAL4 160
#define LOG_LOCAL5 168
#define LOG_LOCAL6 176
#define LOG_LOCAL7 184

#define LOG_NFACILITIES 24
#define LOG_FACMASK     0x03f8
#define LOG_FAC(p)      ((LOG_FACMASK & (p)) >> 3)

#define LOG_PRIMASK       7
#define LOG_PRI(p)        (LOG_PRIMASK & (p))
#define LOG_MAKEPRI(f, p) (((f) << 3) | (p))



/*!BEGIN libc/sysv/consts/loglevel.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOGLEVEL_H_
COSMOPOLITAN_C_START_

#define LOGLEVEL_SCHED   -2
#define LOGLEVEL_DEFAULT -1
#define LOGLEVEL_EMERG   0
#define LOGLEVEL_ALERT   1
#define LOGLEVEL_CRIT    2
#define LOGLEVEL_ERR     3
#define LOGLEVEL_WARNING 4
#define LOGLEVEL_NOTICE  5
#define LOGLEVEL_INFO    6
#define LOGLEVEL_DEBUG   7

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/madv.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MADV_H_
COSMOPOLITAN_C_START_

extern const unsigned MADV_DODUMP;
extern const unsigned MADV_DOFORK;
extern const unsigned MADV_DONTDUMP;
extern const unsigned MADV_DONTFORK;
extern const unsigned MADV_DONTNEED;
extern const unsigned MADV_FREE;
extern const unsigned MADV_HUGEPAGE;
extern const unsigned MADV_HWPOISON;
extern const unsigned MADV_MERGEABLE;
extern const unsigned MADV_NOHUGEPAGE;
extern const unsigned MADV_NORMAL;
extern const unsigned MADV_RANDOM;
extern const unsigned MADV_REMOVE;
extern const unsigned MADV_SEQUENTIAL;
extern const unsigned MADV_UNMERGEABLE;
extern const unsigned MADV_WILLNEED;
extern const unsigned MADV_SOFT_OFFLINE;
extern const unsigned MADV_WIPEONFORK;
extern const unsigned MADV_KEEPONFORK;
extern const unsigned MADV_COLD;
extern const unsigned MADV_PAGEOUT;
extern const unsigned MADV_POPULATE_READ;
extern const unsigned MADV_POPULATE_WRITE;
extern const unsigned MADV_DONTNEED_LOCKED;
extern const unsigned MADV_COLLAPSE;

#define MADV_NORMAL     0
#define MADV_RANDOM     1
#define MADV_SEQUENTIAL 2
#define MADV_WILLNEED   3

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/map.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MAP_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int MAP_32BIT;
extern const int MAP_ANON;
extern const int MAP_ANONYMOUS;
extern const int MAP_CONCEAL;
extern const int MAP_DENYWRITE;
extern const int MAP_EXECUTABLE;
extern const int MAP_FILE;
extern const int MAP_FIXED;
extern const int MAP_FIXED_NOREPLACE;
extern const int MAP_HASSEMAPHORE;
extern const int MAP_HUGETLB;
extern const int MAP_INHERIT;
extern const int MAP_JIT;
extern const int MAP_LOCKED;
extern const int MAP_NOCACHE;
extern const int MAP_NOEXTEND;
extern const int MAP_NONBLOCK;
extern const int MAP_NORESERVE;
extern const int MAP_NOSYNC;
extern const int MAP_POPULATE;
extern const int MAP_PRIVATE;
extern const int MAP_SHARED;
extern const int MAP_SHARED_VALIDATE;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define MAP_FILE    0
#define MAP_SHARED  1
#define MAP_PRIVATE 2
#define MAP_STACK   6
#define MAP_TYPE    15
#define MAP_FIXED   16

#define MAP_ANONYMOUS       MAP_ANONYMOUS
#define MAP_CONCEAL         MAP_CONCEAL
#define MAP_EXECUTABLE      MAP_EXECUTABLE
#define MAP_FIXED_NOREPLACE MAP_FIXED_NOREPLACE
#define MAP_HASSEMAPHORE    MAP_HASSEMAPHORE
#define MAP_POPULATE        MAP_POPULATE
#define MAP_NORESERVE       MAP_NORESERVE

#define MAP_ANON   MAP_ANONYMOUS
#define MAP_NOCORE MAP_CONCEAL



/*!BEGIN libc/sysv/consts/mcast.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MCAST_H_

#define MCAST_BLOCK_SOURCE MCAST_BLOCK_SOURCE
#define MCAST_EXCLUDE MCAST_EXCLUDE
#define MCAST_INCLUDE MCAST_INCLUDE
#define MCAST_JOIN_GROUP MCAST_JOIN_GROUP
#define MCAST_JOIN_SOURCE_GROUP MCAST_JOIN_SOURCE_GROUP
#define MCAST_LEAVE_GROUP MCAST_LEAVE_GROUP
#define MCAST_LEAVE_SOURCE_GROUP MCAST_LEAVE_SOURCE_GROUP
#define MCAST_MSFILTER MCAST_MSFILTER
#define MCAST_UNBLOCK_SOURCE MCAST_UNBLOCK_SOURCE

COSMOPOLITAN_C_START_

extern const int MCAST_BLOCK_SOURCE;
extern const int MCAST_EXCLUDE;
extern const int MCAST_INCLUDE;
extern const int MCAST_JOIN_GROUP;
extern const int MCAST_JOIN_SOURCE_GROUP;
extern const int MCAST_LEAVE_GROUP;
extern const int MCAST_LEAVE_SOURCE_GROUP;
extern const int MCAST_MSFILTER;
extern const int MCAST_UNBLOCK_SOURCE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mfd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MFD_H_

#define MFD_CLOEXEC       1
#define MFD_ALLOW_SEALING 2



/*!BEGIN libc/sysv/consts/mlock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MLOCK_H_
COSMOPOLITAN_C_START_

extern const int MCL_CURRENT;
extern const int MCL_FUTURE;
extern const int MCL_ONFAULT;

COSMOPOLITAN_C_END_

#define MCL_CURRENT 1
#define MCL_FUTURE  2
#define MCL_ONFAULT MCL_ONFAULT



/*!BEGIN libc/sysv/consts/modem.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MODEM_H_
COSMOPOLITAN_C_START_

extern const uint64_t TIOCMGET;
extern const uint64_t TIOCMSET;
extern const uint64_t TIOCMBIC;
extern const uint64_t TIOCMBIS;

extern const int TIOCM_CAR;
extern const int TIOCM_CD;
extern const int TIOCM_CTS;
extern const int TIOCM_DSR;
extern const int TIOCM_DTR;
extern const int TIOCM_LE;
extern const int TIOCM_RI;
extern const int TIOCM_RNG;
extern const int TIOCM_RTS;
extern const int TIOCM_SR;
extern const int TIOCM_ST;

#define TIOCM_LE  0x01
#define TIOCM_DTR 0x02
#define TIOCM_RTS 0x04
#define TIOCM_ST  0x08
#define TIOCM_SR  0x10
#define TIOCM_CTS 0x20
#define TIOCM_CAR 0x40
#define TIOCM_CD  0x40
#define TIOCM_RI  0x80
#define TIOCM_RNG 0x80
#define TIOCM_DSR 0x0100

#define TIOCMGET TIOCMGET
#define TIOCMSET TIOCMSET
#define TIOCMBIC TIOCMBIC
#define TIOCMBIS TIOCMBIS


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const unsigned long MS_RDONLY;
extern const int MNT_RDONLY;
extern const unsigned long MS_NOSUID;
extern const int MNT_NOSUID;
extern const unsigned long MS_NODEV;
extern const int MNT_NODEV;
extern const unsigned long MS_NOEXEC;
extern const int MNT_NOEXEC;
extern const unsigned long MS_SYNCHRONOUS;
extern const int MNT_SYNCHRONOUS;
extern const unsigned long MS_REMOUNT;
extern const int MNT_UPDATE;
extern const unsigned long MS_MANDLOCK;
extern const unsigned long MS_DIRSYNC;
extern const unsigned long MS_NOATIME;
extern const int MNT_NOATIME;
extern const unsigned long MS_NODIRATIME;
extern const unsigned long MS_BIND;
extern const unsigned long MS_MOVE;
extern const unsigned long MS_REC;
extern const unsigned long MS_SILENT;
extern const unsigned long MS_POSIXACL;
extern const unsigned long MS_UNBINDABLE;
extern const unsigned long MS_PRIVATE;
extern const unsigned long MS_SLAVE;
extern const unsigned long MS_SHARED;
extern const unsigned long MS_RELATIME;
extern const int MNT_RELATIME;
extern const unsigned long MS_KERNMOUNT;
extern const unsigned long MS_I_VERSION;
extern const unsigned long MS_STRICTATIME;
extern const int MNT_STRICTATIME;
extern const unsigned long MS_LAZYTIME;
extern const unsigned long MS_ACTIVE;
extern const unsigned long MS_NOUSER;
extern const unsigned long MS_RMT_MASK;
extern const unsigned long MS_MGC_VAL;
extern const unsigned long MS_MGC_MSK;
extern const int MNT_ASYNC;
extern const int MNT_RELOAD;
extern const int MNT_SUIDDIR;
extern const int MNT_NOCLUSTERR;
extern const int MNT_NOCLUSTERW;
extern const int MNT_SNAPSHOT;

#define MS_RDONLY       0x00000001
#define MNT_RDONLY      0x00000001
#define MS_NOSUID       MS_NOSUID
#define MNT_NOSUID      MNT_NOSUID
#define MS_NODEV        MS_NODEV
#define MNT_NODEV       MNT_NODEV
#define MS_NOEXEC       MS_NOEXEC
#define MNT_NOEXEC      MNT_NOEXEC
#define MS_SYNCHRONOUS  MS_SYNCHRONOUS
#define MNT_SYNCHRONOUS MNT_SYNCHRONOUS
#define MS_REMOUNT      MS_REMOUNT
#define MNT_UPDATE      MNT_UPDATE
#define MS_MANDLOCK     MS_MANDLOCK
#define MS_DIRSYNC      MS_DIRSYNC
#define MS_NOATIME      MS_NOATIME
#define MNT_NOATIME     MNT_NOATIME
#define MS_NODIRATIME   MS_NODIRATIME
#define MS_BIND         MS_BIND
#define MS_MOVE         MS_MOVE
#define MS_REC          MS_REC
#define MS_SILENT       MS_SILENT
#define MS_POSIXACL     MS_POSIXACL
#define MS_UNBINDABLE   MS_UNBINDABLE
#define MS_PRIVATE      MS_PRIVATE
#define MS_SLAVE        MS_SLAVE
#define MS_SHARED       MS_SHARED
#define MS_RELATIME     MS_RELATIME
#define MNT_RELATIME    MNT_RELATIME
#define MS_KERNMOUNT    MS_KERNMOUNT
#define MS_I_VERSION    MS_I_VERSION
#define MS_STRICTATIME  MS_STRICTATIME
#define MNT_STRICTATIME MNT_STRICTATIME
#define MS_LAZYTIME     MS_LAZYTIME
#define MS_ACTIVE       MS_ACTIVE
#define MS_NOUSER       MS_NOUSER
#define MS_RMT_MASK     MS_RMT_MASK
#define MS_MGC_VAL      MS_MGC_VAL
#define MS_MGC_MSK      MS_MGC_MSK
#define MNT_ASYNC       MNT_ASYNC
#define MNT_RELOAD      MNT_RELOAD
#define MNT_SUIDDIR     MNT_SUIDDIR
#define MNT_NOCLUSTERR  MNT_NOCLUSTERR
#define MNT_NOCLUSTERW  MNT_NOCLUSTERW
#define MNT_SNAPSHOT    MNT_SNAPSHOT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mremap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MREMAP_H_

#define MREMAP_MAYMOVE 1
#define MREMAP_FIXED   2



/*!BEGIN libc/sysv/consts/msg.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSG_H_
COSMOPOLITAN_C_START_

extern const int MSG_BATCH;
extern const int MSG_BCAST;
extern const int MSG_CMSG_CLOEXEC;
extern const int MSG_CONFIRM;
extern const int MSG_CTRUNC;
extern const int MSG_DONTROUTE;
extern const int MSG_DONTWAIT;
extern const int MSG_EOF;
extern const int MSG_EOR;
extern const int MSG_ERRQUEUE;
extern const int MSG_EXCEPT;
extern const int MSG_FASTOPEN;
extern const int MSG_FIN;
extern const int MSG_INFO;
extern const int MSG_MCAST;
extern const int MSG_MORE;
extern const int MSG_NOERROR;
extern const int MSG_NOSIGNAL;
extern const int MSG_NOTIFICATION;
extern const int MSG_OOB;
extern const int MSG_PARITY_ERROR;
extern const int MSG_PEEK;
extern const int MSG_PROXY;
extern const int MSG_RST;
extern const int MSG_STAT;
extern const int MSG_SYN;
extern const int MSG_TRUNC;
extern const int MSG_WAITALL;
extern const int MSG_WAITFORONE;

#define MSG_OOB       1
#define MSG_PEEK      2
#define MSG_DONTROUTE 4
#define MSG_DONTWAIT  MSG_DONTWAIT
#define MSG_FASTOPEN  MSG_FASTOPEN
#define MSG_WAITALL   MSG_WAITALL
#define MSG_TRUNC     MSG_TRUNC
#define MSG_CTRUNC    MSG_CTRUNC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/msync.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSYNC_H_
COSMOPOLITAN_C_START_

extern const int MS_SYNC;
extern const int MS_ASYNC;
extern const int MS_INVALIDATE;

#define MS_SYNC       MS_SYNC
#define MS_ASYNC      MS_ASYNC
#define MS_INVALIDATE MS_INVALIDATE

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/nrlinux.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NRLINUX_H_
#ifdef _COSMO_SOURCE

#ifdef __x86_64__

#define __NR_linux_exit                    0x003c
#define __NR_linux_exit_group              0x00e7
#define __NR_linux_read                    0x0000
#define __NR_linux_write                   0x0001
#define __NR_linux_open                    0x0002
#define __NR_linux_close                   0x0003
#define __NR_linux_stat                    0x0004
#define __NR_linux_fstat                   0x0005
#define __NR_linux_lstat                   0x0006
#define __NR_linux_poll                    0x0007
#define __NR_linux_ppoll                   0x010f
#define __NR_linux_brk                     0x000c
#define __NR_linux_sigreturn               0x000f
#define __NR_linux_lseek                   0x0008
#define __NR_linux_mmap                    0x0009
#define __NR_linux_msync                   0x001a
#define __NR_linux_mprotect                0x000a
#define __NR_linux_munmap                  0x000b
#define __NR_linux_sigaction               0x000d
#define __NR_linux_sigprocmask             0x000e
#define __NR_linux_ioctl                   0x0010
#define __NR_linux_pread                   0x0011
#define __NR_linux_pwrite                  0x0012
#define __NR_linux_readv                   0x0013
#define __NR_linux_writev                  0x0014
#define __NR_linux_access                  0x0015
#define __NR_linux_pipe                    0x0016
#define __NR_linux_select                  0x0017
#define __NR_linux_pselect6                0x010e
#define __NR_linux_sched_yield             0x0018
#define __NR_linux_mremap                  0x0019
#define __NR_linux_mincore                 0x001b
#define __NR_linux_madvise                 0x001c
#define __NR_linux_shmget                  0x001d
#define __NR_linux_shmat                   0x001e
#define __NR_linux_shmctl                  0x001f
#define __NR_linux_dup                     0x0020
#define __NR_linux_dup2                    0x0021
#define __NR_linux_pause                   0x0022
#define __NR_linux_nanosleep               0x0023
#define __NR_linux_getitimer               0x0024
#define __NR_linux_setitimer               0x0026
#define __NR_linux_alarm                   0x0025
#define __NR_linux_getpid                  0x0027
#define __NR_linux_sendfile                0x0028
#define __NR_linux_socket                  0x0029
#define __NR_linux_connect                 0x002a
#define __NR_linux_accept                  0x002b
#define __NR_linux_sendto                  0x002c
#define __NR_linux_recvfrom                0x002d
#define __NR_linux_sendmsg                 0x002e
#define __NR_linux_recvmsg                 0x002f
#define __NR_linux_shutdown                0x0030
#define __NR_linux_bind                    0x0031
#define __NR_linux_listen                  0x0032
#define __NR_linux_getsockname             0x0033
#define __NR_linux_getpeername             0x0034
#define __NR_linux_socketpair              0x0035
#define __NR_linux_setsockopt              0x0036
#define __NR_linux_getsockopt              0x0037
#define __NR_linux_fork                    0x0039
#define __NR_linux_vfork                   0x003a
#define __NR_linux_execve                  0x003b
#define __NR_linux_wait4                   0x003d
#define __NR_linux_kill                    0x003e
#define __NR_linux_clone                   0x0038
#define __NR_linux_tkill                   0x00c8
#define __NR_linux_futex                   0x00ca
#define __NR_linux_set_robust_list         0x0111
#define __NR_linux_get_robust_list         0x0112
#define __NR_linux_uname                   0x003f
#define __NR_linux_semget                  0x0040
#define __NR_linux_semop                   0x0041
#define __NR_linux_semctl                  0x0042
#define __NR_linux_shmdt                   0x0043
#define __NR_linux_msgget                  0x0044
#define __NR_linux_msgsnd                  0x0045
#define __NR_linux_msgrcv                  0x0046
#define __NR_linux_msgctl                  0x0047
#define __NR_linux_fcntl                   0x0048
#define __NR_linux_flock                   0x0049
#define __NR_linux_fsync                   0x004a
#define __NR_linux_fdatasync               0x004b
#define __NR_linux_truncate                0x004c
#define __NR_linux_ftruncate               0x004d
#define __NR_linux_getcwd                  0x004f
#define __NR_linux_chdir                   0x0050
#define __NR_linux_fchdir                  0x0051
#define __NR_linux_rename                  0x0052
#define __NR_linux_mkdir                   0x0053
#define __NR_linux_rmdir                   0x0054
#define __NR_linux_creat                   0x0055
#define __NR_linux_link                    0x0056
#define __NR_linux_unlink                  0x0057
#define __NR_linux_symlink                 0x0058
#define __NR_linux_readlink                0x0059
#define __NR_linux_chmod                   0x005a
#define __NR_linux_fchmod                  0x005b
#define __NR_linux_chown                   0x005c
#define __NR_linux_fchown                  0x005d
#define __NR_linux_lchown                  0x005e
#define __NR_linux_umask                   0x005f
#define __NR_linux_gettimeofday            0x0060
#define __NR_linux_getrlimit               0x0061
#define __NR_linux_getrusage               0x0062
#define __NR_linux_sysinfo                 0x0063
#define __NR_linux_times                   0x0064
#define __NR_linux_ptrace                  0x0065
#define __NR_linux_syslog                  0x0067
#define __NR_linux_getuid                  0x0066
#define __NR_linux_getgid                  0x0068
#define __NR_linux_getppid                 0x006e
#define __NR_linux_getpgrp                 0x006f
#define __NR_linux_setsid                  0x0070
#define __NR_linux_getsid                  0x007c
#define __NR_linux_getpgid                 0x0079
#define __NR_linux_setpgid                 0x006d
#define __NR_linux_geteuid                 0x006b
#define __NR_linux_getegid                 0x006c
#define __NR_linux_getgroups               0x0073
#define __NR_linux_setgroups               0x0074
#define __NR_linux_setreuid                0x0071
#define __NR_linux_setregid                0x0072
#define __NR_linux_setuid                  0x0069
#define __NR_linux_setgid                  0x006a
#define __NR_linux_setresuid               0x0075
#define __NR_linux_setresgid               0x0077
#define __NR_linux_getresuid               0x0076
#define __NR_linux_getresgid               0x0078
#define __NR_linux_sigpending              0x007f
#define __NR_linux_sigsuspend              0x0082
#define __NR_linux_sigaltstack             0x0083
#define __NR_linux_mknod                   0x0085
#define __NR_linux_mknodat                 0x0103
#define __NR_linux_statfs                  0x0089
#define __NR_linux_fstatfs                 0x008a
#define __NR_linux_getpriority             0x008c
#define __NR_linux_setpriority             0x008d
#define __NR_linux_mlock                   0x0095
#define __NR_linux_munlock                 0x0096
#define __NR_linux_mlockall                0x0097
#define __NR_linux_munlockall              0x0098
#define __NR_linux_setrlimit               0x00a0
#define __NR_linux_chroot                  0x00a1
#define __NR_linux_sync                    0x00a2
#define __NR_linux_acct                    0x00a3
#define __NR_linux_settimeofday            0x00a4
#define __NR_linux_mount                   0x00a5
#define __NR_linux_reboot                  0x00a9
#define __NR_linux_quotactl                0x00b3
#define __NR_linux_setfsuid                0x007a
#define __NR_linux_setfsgid                0x007b
#define __NR_linux_capget                  0x007d
#define __NR_linux_capset                  0x007e
#define __NR_linux_sigtimedwait            0x0080
#define __NR_linux_sigqueueinfo            0x0081
#define __NR_linux_personality             0x0087
#define __NR_linux_ustat                   0x0088
#define __NR_linux_sysfs                   0x008b
#define __NR_linux_sched_setparam          0x008e
#define __NR_linux_sched_getparam          0x008f
#define __NR_linux_sched_setscheduler      0x0090
#define __NR_linux_sched_getscheduler      0x0091
#define __NR_linux_sched_get_priority_max  0x0092
#define __NR_linux_sched_get_priority_min  0x0093
#define __NR_linux_sched_rr_get_interval   0x0094
#define __NR_linux_vhangup                 0x0099
#define __NR_linux_modify_ldt              0x009a
#define __NR_linux_pivot_root              0x009b
#define __NR_linux__sysctl                 0x009c
#define __NR_linux_prctl                   0x009d
#define __NR_linux_arch_prctl              0x009e
#define __NR_linux_adjtimex                0x009f
#define __NR_linux_umount2                 0x00a6
#define __NR_linux_swapon                  0x00a7
#define __NR_linux_swapoff                 0x00a8
#define __NR_linux_sethostname             0x00aa
#define __NR_linux_setdomainname           0x00ab
#define __NR_linux_iopl                    0x00ac
#define __NR_linux_ioperm                  0x00ad
#define __NR_linux_init_module             0x00af
#define __NR_linux_delete_module           0x00b0
#define __NR_linux_gettid                  0x00ba
#define __NR_linux_readahead               0x00bb
#define __NR_linux_setxattr                0x00bc
#define __NR_linux_fsetxattr               0x00be
#define __NR_linux_getxattr                0x00bf
#define __NR_linux_fgetxattr               0x00c1
#define __NR_linux_listxattr               0x00c2
#define __NR_linux_flistxattr              0x00c4
#define __NR_linux_removexattr             0x00c5
#define __NR_linux_fremovexattr            0x00c7
#define __NR_linux_lsetxattr               0x00bd
#define __NR_linux_lgetxattr               0x00c0
#define __NR_linux_llistxattr              0x00c3
#define __NR_linux_lremovexattr            0x00c6
#define __NR_linux_sched_setaffinity       0x00cb
#define __NR_linux_sched_getaffinity       0x00cc
#define __NR_linux_io_setup                0x00ce
#define __NR_linux_io_destroy              0x00cf
#define __NR_linux_io_getevents            0x00d0
#define __NR_linux_io_submit               0x00d1
#define __NR_linux_io_cancel               0x00d2
#define __NR_linux_lookup_dcookie          0x00d4
#define __NR_linux_epoll_create            0x00d5
#define __NR_linux_epoll_wait              0x00e8
#define __NR_linux_epoll_ctl               0x00e9
#define __NR_linux_getdents                0x00d9
#define __NR_linux_oldgetdents             0x004e
#define __NR_linux_set_tid_address         0x00da
#define __NR_linux_restart_syscall         0x00db
#define __NR_linux_semtimedop              0x00dc
#define __NR_linux_fadvise                 0x00dd
#define __NR_linux_timer_create            0x00de
#define __NR_linux_timer_settime           0x00df
#define __NR_linux_timer_gettime           0x00e0
#define __NR_linux_timer_getoverrun        0x00e1
#define __NR_linux_timer_delete            0x00e2
#define __NR_linux_clock_settime           0x00e3
#define __NR_linux_clock_gettime           0x00e4
#define __NR_linux_clock_getres            0x00e5
#define __NR_linux_clock_nanosleep         0x00e6
#define __NR_linux_tgkill                  0x00ea
#define __NR_linux_mbind                   0x00ed
#define __NR_linux_set_mempolicy           0x00ee
#define __NR_linux_get_mempolicy           0x00ef
#define __NR_linux_mq_open                 0x00f0
#define __NR_linux_mq_unlink               0x00f1
#define __NR_linux_mq_timedsend            0x00f2
#define __NR_linux_mq_timedreceive         0x00f3
#define __NR_linux_mq_notify               0x00f4
#define __NR_linux_mq_getsetattr           0x00f5
#define __NR_linux_kexec_load              0x00f6
#define __NR_linux_waitid                  0x00f7
#define __NR_linux_add_key                 0x00f8
#define __NR_linux_request_key             0x00f9
#define __NR_linux_keyctl                  0x00fa
#define __NR_linux_ioprio_set              0x00fb
#define __NR_linux_ioprio_get              0x00fc
#define __NR_linux_inotify_init            0x00fd
#define __NR_linux_inotify_add_watch       0x00fe
#define __NR_linux_inotify_rm_watch        0x00ff
#define __NR_linux_openat                  0x0101
#define __NR_linux_mkdirat                 0x0102
#define __NR_linux_fchownat                0x0104
#define __NR_linux_utime                   0x0084
#define __NR_linux_utimes                  0x00eb
#define __NR_linux_futimesat               0x0105
#define __NR_linux_fstatat                 0x0106
#define __NR_linux_unlinkat                0x0107
#define __NR_linux_renameat                0x0108
#define __NR_linux_linkat                  0x0109
#define __NR_linux_symlinkat               0x010a
#define __NR_linux_readlinkat              0x010b
#define __NR_linux_fchmodat                0x010c
#define __NR_linux_faccessat               0x010d
#define __NR_linux_unshare                 0x0110
#define __NR_linux_splice                  0x0113
#define __NR_linux_tee                     0x0114
#define __NR_linux_sync_file_range         0x0115
#define __NR_linux_vmsplice                0x0116
#define __NR_linux_migrate_pages           0x0100
#define __NR_linux_move_pages              0x0117
#define __NR_linux_preadv                  0x0127
#define __NR_linux_pwritev                 0x0128
#define __NR_linux_utimensat               0x0118
#define __NR_linux_fallocate               0x011d
#define __NR_linux_accept4                 0x0120
#define __NR_linux_dup3                    0x0124
#define __NR_linux_pipe2                   0x0125
#define __NR_linux_epoll_pwait             0x0119
#define __NR_linux_epoll_create1           0x0123
#define __NR_linux_perf_event_open         0x012a
#define __NR_linux_inotify_init1           0x0126
#define __NR_linux_tgsigqueueinfo          0x0129
#define __NR_linux_signalfd                0x011a
#define __NR_linux_signalfd4               0x0121
#define __NR_linux_eventfd                 0x011c
#define __NR_linux_eventfd2                0x0122
#define __NR_linux_timerfd_create          0x011b
#define __NR_linux_timerfd_settime         0x011e
#define __NR_linux_timerfd_gettime         0x011f
#define __NR_linux_recvmmsg                0x012b
#define __NR_linux_fanotify_init           0x012c
#define __NR_linux_fanotify_mark           0x012d
#define __NR_linux_prlimit                 0x012e
#define __NR_linux_name_to_handle_at       0x012f
#define __NR_linux_open_by_handle_at       0x0130
#define __NR_linux_clock_adjtime           0x0131
#define __NR_linux_syncfs                  0x0132
#define __NR_linux_sendmmsg                0x0133
#define __NR_linux_setns                   0x0134
#define __NR_linux_getcpu                  0x0135
#define __NR_linux_process_vm_readv        0x0136
#define __NR_linux_process_vm_writev       0x0137
#define __NR_linux_kcmp                    0x0138
#define __NR_linux_finit_module            0x0139
#define __NR_linux_sched_setattr           0x013a
#define __NR_linux_sched_getattr           0x013b
#define __NR_linux_renameat2               0x013c
#define __NR_linux_seccomp                 0x013d
#define __NR_linux_getrandom               0x013e
#define __NR_linux_memfd_create            0x013f
#define __NR_linux_kexec_file_load         0x0140
#define __NR_linux_bpf                     0x0141
#define __NR_linux_execveat                0x0142
#define __NR_linux_userfaultfd             0x0143
#define __NR_linux_membarrier              0x0144
#define __NR_linux_mlock2                  0x0145
#define __NR_linux_copy_file_range         0x0146
#define __NR_linux_preadv2                 0x0147
#define __NR_linux_pwritev2                0x0148
#define __NR_linux_pkey_mprotect           0x0149
#define __NR_linux_pkey_alloc              0x014a
#define __NR_linux_pkey_free               0x014b
#define __NR_linux_statx                   0x014c
#define __NR_linux_io_pgetevents           0x014d
#define __NR_linux_rseq                    0x014e
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_quotactl_fd             0x01bb
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be
#define __NR_linux_memfd_secret            0x01bf
#define __NR_linux_process_mrelease        0x01c0
#define __NR_linux_futex_waitv             0x01c1
#define __NR_linux_set_mempolicy_home_node 0x01c2

#elif defined(__aarch64__)

#define __NR_linux_exit                    0x005d
#define __NR_linux_exit_group              0x005e
#define __NR_linux_read                    0x003f
#define __NR_linux_write                   0x0040
#define __NR_linux_open                    0x00b4
#define __NR_linux_close                   0x0039
#define __NR_linux_stat                    0x004f
#define __NR_linux_fstat                   0x0050
#define __NR_linux_ppoll                   0x0049
#define __NR_linux_brk                     0x00d6
#define __NR_linux_sigreturn               0x008b
#define __NR_linux_lseek                   0x003e
#define __NR_linux_mmap                    0x00de
#define __NR_linux_msync                   0x00e3
#define __NR_linux_mprotect                0x00e2
#define __NR_linux_munmap                  0x00d7
#define __NR_linux_sigaction               0x0086
#define __NR_linux_sigprocmask             0x0087
#define __NR_linux_ioctl                   0x001d
#define __NR_linux_pread                   0x0043
#define __NR_linux_pwrite                  0x0044
#define __NR_linux_readv                   0x0041
#define __NR_linux_writev                  0x0042
#define __NR_linux_pselect6                0x0048
#define __NR_linux_sched_yield             0x007c
#define __NR_linux_mremap                  0x00d8
#define __NR_linux_mincore                 0x00e8
#define __NR_linux_madvise                 0x00e9
#define __NR_linux_shmget                  0x00c2
#define __NR_linux_shmat                   0x00c4
#define __NR_linux_shmctl                  0x00c3
#define __NR_linux_dup                     0x0017
#define __NR_linux_nanosleep               0x0065
#define __NR_linux_getitimer               0x0066
#define __NR_linux_setitimer               0x0067
#define __NR_linux_getpid                  0x00ac
#define __NR_linux_sendfile                0x0047
#define __NR_linux_socket                  0x00c6
#define __NR_linux_connect                 0x00cb
#define __NR_linux_accept                  0x00ca
#define __NR_linux_sendto                  0x00ce
#define __NR_linux_recvfrom                0x00cf
#define __NR_linux_sendmsg                 0x00d3
#define __NR_linux_recvmsg                 0x00d4
#define __NR_linux_shutdown                0x00d2
#define __NR_linux_bind                    0x00c8
#define __NR_linux_listen                  0x00c9
#define __NR_linux_getsockname             0x00cc
#define __NR_linux_getpeername             0x00cd
#define __NR_linux_socketpair              0x00c7
#define __NR_linux_setsockopt              0x00d0
#define __NR_linux_getsockopt              0x00d1
#define __NR_linux_execve                  0x00dd
#define __NR_linux_wait4                   0x0104
#define __NR_linux_kill                    0x0081
#define __NR_linux_clone                   0x00dc
#define __NR_linux_tkill                   0x0082
#define __NR_linux_futex                   0x0062
#define __NR_linux_set_robust_list         0x0063
#define __NR_linux_get_robust_list         0x0064
#define __NR_linux_uname                   0x00a0
#define __NR_linux_semget                  0x00be
#define __NR_linux_semop                   0x00c1
#define __NR_linux_semctl                  0x00bf
#define __NR_linux_shmdt                   0x00c5
#define __NR_linux_msgget                  0x00ba
#define __NR_linux_msgsnd                  0x00bd
#define __NR_linux_msgrcv                  0x00bc
#define __NR_linux_msgctl                  0x00bb
#define __NR_linux_fcntl                   0x0019
#define __NR_linux_flock                   0x0020
#define __NR_linux_fsync                   0x0052
#define __NR_linux_fdatasync               0x0053
#define __NR_linux_truncate                0x002d
#define __NR_linux_ftruncate               0x002e
#define __NR_linux_getcwd                  0x0011
#define __NR_linux_chdir                   0x0031
#define __NR_linux_fchdir                  0x0032
#define __NR_linux_unlink                  0x00b5
#define __NR_linux_fchmod                  0x0034
#define __NR_linux_fchown                  0x0037
#define __NR_linux_umask                   0x00a6
#define __NR_linux_gettimeofday            0x00a9
#define __NR_linux_getrlimit               0x00a3
#define __NR_linux_getrusage               0x00a5
#define __NR_linux_sysinfo                 0x00b3
#define __NR_linux_times                   0x0099
#define __NR_linux_ptrace                  0x0075
#define __NR_linux_syslog                  0x0074
#define __NR_linux_getuid                  0x00ae
#define __NR_linux_getgid                  0x00b0
#define __NR_linux_getppid                 0x00ad
#define __NR_linux_setsid                  0x009d
#define __NR_linux_getsid                  0x009c
#define __NR_linux_getpgid                 0x009b
#define __NR_linux_setpgid                 0x009a
#define __NR_linux_geteuid                 0x00af
#define __NR_linux_getegid                 0x00b1
#define __NR_linux_getgroups               0x009e
#define __NR_linux_setgroups               0x009f
#define __NR_linux_setreuid                0x0091
#define __NR_linux_setregid                0x008f
#define __NR_linux_setuid                  0x0092
#define __NR_linux_setgid                  0x0090
#define __NR_linux_setresuid               0x0093
#define __NR_linux_setresgid               0x0095
#define __NR_linux_getresuid               0x0094
#define __NR_linux_getresgid               0x0096
#define __NR_linux_sigpending              0x0088
#define __NR_linux_sigsuspend              0x0085
#define __NR_linux_sigaltstack             0x0084
#define __NR_linux_mknodat                 0x0021
#define __NR_linux_statfs                  0x002b
#define __NR_linux_fstatfs                 0x002c
#define __NR_linux_getpriority             0x008d
#define __NR_linux_setpriority             0x008c
#define __NR_linux_mlock                   0x00e4
#define __NR_linux_munlock                 0x00e5
#define __NR_linux_mlockall                0x00e6
#define __NR_linux_munlockall              0x00e7
#define __NR_linux_setrlimit               0x00a4
#define __NR_linux_chroot                  0x0033
#define __NR_linux_sync                    0x0051
#define __NR_linux_acct                    0x0059
#define __NR_linux_settimeofday            0x00aa
#define __NR_linux_mount                   0x0028
#define __NR_linux_reboot                  0x008e
#define __NR_linux_quotactl                0x003c
#define __NR_linux_setfsuid                0x0097
#define __NR_linux_setfsgid                0x0098
#define __NR_linux_capget                  0x005a
#define __NR_linux_capset                  0x005b
#define __NR_linux_sigtimedwait            0x0089
#define __NR_linux_sigqueueinfo            0x008a
#define __NR_linux_personality             0x005c
#define __NR_linux_sched_setparam          0x0076
#define __NR_linux_sched_getparam          0x0079
#define __NR_linux_sched_setscheduler      0x0077
#define __NR_linux_sched_getscheduler      0x0078
#define __NR_linux_sched_get_priority_max  0x007d
#define __NR_linux_sched_get_priority_min  0x007e
#define __NR_linux_sched_rr_get_interval   0x007f
#define __NR_linux_vhangup                 0x003a
#define __NR_linux_pivot_root              0x0029
#define __NR_linux_prctl                   0x00a7
#define __NR_linux_adjtimex                0x00ab
#define __NR_linux_umount2                 0x0027
#define __NR_linux_swapon                  0x00e0
#define __NR_linux_swapoff                 0x00e1
#define __NR_linux_sethostname             0x00a1
#define __NR_linux_setdomainname           0x00a2
#define __NR_linux_init_module             0x0069
#define __NR_linux_delete_module           0x006a
#define __NR_linux_gettid                  0x00b2
#define __NR_linux_readahead               0x00d5
#define __NR_linux_setxattr                0x0005
#define __NR_linux_fsetxattr               0x0007
#define __NR_linux_getxattr                0x0008
#define __NR_linux_fgetxattr               0x000a
#define __NR_linux_listxattr               0x000b
#define __NR_linux_flistxattr              0x000d
#define __NR_linux_removexattr             0x000e
#define __NR_linux_fremovexattr            0x0010
#define __NR_linux_lsetxattr               0x0006
#define __NR_linux_lgetxattr               0x0009
#define __NR_linux_llistxattr              0x000c
#define __NR_linux_lremovexattr            0x000f
#define __NR_linux_sched_setaffinity       0x007a
#define __NR_linux_sched_getaffinity       0x007b
#define __NR_linux_io_setup                0x0000
#define __NR_linux_io_destroy              0x0001
#define __NR_linux_io_getevents            0x0004
#define __NR_linux_io_submit               0x0002
#define __NR_linux_io_cancel               0x0003
#define __NR_linux_lookup_dcookie          0x0012
#define __NR_linux_epoll_ctl               0x0015
#define __NR_linux_getdents                0x003d
#define __NR_linux_set_tid_address         0x0060
#define __NR_linux_restart_syscall         0x0080
#define __NR_linux_semtimedop              0x00c0
#define __NR_linux_fadvise                 0x00df
#define __NR_linux_timer_create            0x006b
#define __NR_linux_timer_settime           0x006e
#define __NR_linux_timer_gettime           0x006c
#define __NR_linux_timer_getoverrun        0x006d
#define __NR_linux_timer_delete            0x006f
#define __NR_linux_clock_settime           0x0070
#define __NR_linux_clock_gettime           0x0071
#define __NR_linux_clock_getres            0x0072
#define __NR_linux_clock_nanosleep         0x0073
#define __NR_linux_tgkill                  0x0083
#define __NR_linux_mbind                   0x00eb
#define __NR_linux_set_mempolicy           0x00ed
#define __NR_linux_get_mempolicy           0x00ec
#define __NR_linux_mq_open                 0x00b4
#define __NR_linux_mq_unlink               0x00b5
#define __NR_linux_mq_timedsend            0x00b6
#define __NR_linux_mq_timedreceive         0x00b7
#define __NR_linux_mq_notify               0x00b8
#define __NR_linux_mq_getsetattr           0x00b9
#define __NR_linux_kexec_load              0x0068
#define __NR_linux_waitid                  0x005f
#define __NR_linux_add_key                 0x00d9
#define __NR_linux_request_key             0x00da
#define __NR_linux_keyctl                  0x00db
#define __NR_linux_ioprio_set              0x001e
#define __NR_linux_ioprio_get              0x001f
#define __NR_linux_openat                  0x0038
#define __NR_linux_mkdirat                 0x0022
#define __NR_linux_fchownat                0x0036
#define __NR_linux_utime                   0x0062
#define __NR_linux_utimes                  0x0058
#define __NR_linux_fstatat                 0x004f
#define __NR_linux_unlinkat                0x0023
#define __NR_linux_renameat                0x0026
#define __NR_linux_linkat                  0x0025
#define __NR_linux_symlinkat               0x0024
#define __NR_linux_readlinkat              0x004e
#define __NR_linux_fchmodat                0x0035
#define __NR_linux_faccessat               0x0030
#define __NR_linux_unshare                 0x0061
#define __NR_linux_splice                  0x004c
#define __NR_linux_tee                     0x004d
#define __NR_linux_sync_file_range         0x0054
#define __NR_linux_vmsplice                0x004b
#define __NR_linux_migrate_pages           0x00ee
#define __NR_linux_move_pages              0x00ef
#define __NR_linux_preadv                  0x0045
#define __NR_linux_pwritev                 0x0046
#define __NR_linux_utimensat               0x0058
#define __NR_linux_fallocate               0x002f
#define __NR_linux_accept4                 0x00f2
#define __NR_linux_dup3                    0x0018
#define __NR_linux_pipe2                   0x003b
#define __NR_linux_epoll_pwait             0x0016
#define __NR_linux_epoll_create1           0x0014
#define __NR_linux_perf_event_open         0x00f1
#define __NR_linux_inotify_init1           0x001a
#define __NR_linux_tgsigqueueinfo          0x00f0
#define __NR_linux_signalfd4               0x004a
#define __NR_linux_eventfd2                0x0013
#define __NR_linux_timerfd_create          0x0055
#define __NR_linux_timerfd_settime         0x0056
#define __NR_linux_timerfd_gettime         0x0057
#define __NR_linux_recvmmsg                0x00f3
#define __NR_linux_fanotify_init           0x0106
#define __NR_linux_fanotify_mark           0x0107
#define __NR_linux_prlimit                 0x0105
#define __NR_linux_name_to_handle_at       0x0108
#define __NR_linux_open_by_handle_at       0x0109
#define __NR_linux_clock_adjtime           0x010a
#define __NR_linux_syncfs                  0x010b
#define __NR_linux_sendmmsg                0x010d
#define __NR_linux_setns                   0x010c
#define __NR_linux_getcpu                  0x00a8
#define __NR_linux_process_vm_readv        0x010e
#define __NR_linux_process_vm_writev       0x010f
#define __NR_linux_kcmp                    0x0110
#define __NR_linux_finit_module            0x0111
#define __NR_linux_sched_setattr           0x0112
#define __NR_linux_sched_getattr           0x0113
#define __NR_linux_renameat2               0x0114
#define __NR_linux_seccomp                 0x0115
#define __NR_linux_getrandom               0x0116
#define __NR_linux_memfd_create            0x0117
#define __NR_linux_bpf                     0x0118
#define __NR_linux_execveat                0x0119
#define __NR_linux_userfaultfd             0x011a
#define __NR_linux_membarrier              0x011b
#define __NR_linux_mlock2                  0x011c
#define __NR_linux_copy_file_range         0x011d
#define __NR_linux_preadv2                 0x011e
#define __NR_linux_pwritev2                0x011f
#define __NR_linux_pkey_mprotect           0x0120
#define __NR_linux_pkey_alloc              0x0121
#define __NR_linux_pkey_free               0x0122
#define __NR_linux_statx                   0x0123
#define __NR_linux_io_pgetevents           0x0124
#define __NR_linux_rseq                    0x0125
#define __NR_linux_kexec_file_load         0x0126
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be

#endif /* __x86_64__ */

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/ok.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_OK_H_

#define F_OK 0
#define X_OK X_OK
#define W_OK W_OK
#define R_OK R_OK

COSMOPOLITAN_C_START_

extern const int X_OK;
extern const int W_OK;
extern const unsigned R_OK; /* warning: is sign bit on windows */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/personality.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PERSONALITY_H_

#define ADDR_COMPAT_LAYOUT 0x0200000
#define READ_IMPLIES_EXEC  0x0400000
#define ADDR_LIMIT_3GB     0x8000000
#define FDPIC_FUNCPTRS     0x0080000
#define STICKY_TIMEOUTS    0x4000000
#define MMAP_PAGE_ZERO     0x0100000
#define ADDR_LIMIT_32BIT   0x0800000
#define WHOLE_SECONDS      0x2000000
#define ADDR_NO_RANDOMIZE  0x0040000
#define SHORT_INODE        0x1000000
#define UNAME26            0x0020000



/*!BEGIN libc/sysv/consts/pf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PF_H_
COSMOPOLITAN_C_START_

extern const int PF_ALG;
extern const int PF_APPLETALK;
extern const int PF_ASH;
extern const int PF_ATMPVC;
extern const int PF_ATMSVC;
extern const int PF_AX25;
extern const int PF_BLUETOOTH;
extern const int PF_BRIDGE;
extern const int PF_CAIF;
extern const int PF_CAN;
extern const int PF_ECONET;
extern const int PF_FILE;
extern const int PF_IB;
extern const int PF_IEEE802154;
extern const int PF_INET6;
extern const int PF_INET;
extern const int PF_IPX;
extern const int PF_IRDA;
extern const int PF_ISDN;
extern const int PF_IUCV;
extern const int PF_KCM;
extern const int PF_KEY;
extern const int PF_LLC;
extern const int PF_LOCAL;
extern const int PF_MAX;
extern const int PF_MPLS;
extern const int PF_NETBEUI;
extern const int PF_NETLINK;
extern const int PF_NETROM;
extern const int PF_NFC;
extern const int PF_PACKET;
extern const int PF_PHONET;
extern const int PF_PPPOX;
extern const int PF_RDS;
extern const int PF_ROSE;
extern const int PF_ROUTE;
extern const int PF_RXRPC;
extern const int PF_SECURITY;
extern const int PF_SNA;
extern const int PF_TIPC;
extern const int PF_UNIX;
extern const int PF_UNSPEC;
extern const int PF_VSOCK;
extern const int PF_WANPIPE;
extern const int PF_X25;

#define PF_ALG        PF_ALG
#define PF_APPLETALK  PF_APPLETALK
#define PF_ASH        PF_ASH
#define PF_ATMPVC     PF_ATMPVC
#define PF_ATMSVC     PF_ATMSVC
#define PF_AX25       PF_AX25
#define PF_BLUETOOTH  PF_BLUETOOTH
#define PF_BRIDGE     PF_BRIDGE
#define PF_CAIF       PF_CAIF
#define PF_CAN        PF_CAN
#define PF_ECONET     PF_ECONET
#define PF_FILE       PF_FILE
#define PF_IB         PF_IB
#define PF_IEEE802154 PF_IEEE802154
#define PF_INET       PF_INET
#define PF_INET6      PF_INET6
#define PF_IPX        PF_IPX
#define PF_IRDA       PF_IRDA
#define PF_ISDN       PF_ISDN
#define PF_IUCV       PF_IUCV
#define PF_KCM        PF_KCM
#define PF_KEY        PF_KEY
#define PF_LLC        PF_LLC
#define PF_LOCAL      PF_LOCAL
#define PF_MAX        PF_MAX
#define PF_MPLS       PF_MPLS
#define PF_NETBEUI    PF_NETBEUI
#define PF_NETLINK    PF_NETLINK
#define PF_NETROM     PF_NETROM
#define PF_NFC        PF_NFC
#define PF_PACKET     PF_PACKET
#define PF_PHONET     PF_PHONET
#define PF_PPPOX      PF_PPPOX
#define PF_RDS        PF_RDS
#define PF_ROSE       PF_ROSE
#define PF_ROUTE      PF_ROUTE
#define PF_RXRPC      PF_RXRPC
#define PF_SECURITY   PF_SECURITY
#define PF_SNA        PF_SNA
#define PF_TIPC       PF_TIPC
#define PF_UNIX       PF_UNIX
#define PF_UNSPEC     PF_UNSPEC
#define PF_VSOCK      PF_VSOCK
#define PF_WANPIPE    PF_WANPIPE
#define PF_X25        PF_X25


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/poll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POLL_H_
COSMOPOLITAN_C_START_

extern const int16_t POLLERR;
extern const int16_t POLLHUP;
extern const int16_t POLLIN;
extern const int16_t POLLNVAL;
extern const int16_t POLLOUT;
extern const int16_t POLLPRI;
extern const int16_t POLLRDBAND;
extern const int16_t POLLRDHUP;
extern const int16_t POLLRDNORM;
extern const int16_t POLLWRBAND;
extern const int16_t POLLWRNORM;

#define INFTIM     (-1)
#define POLLERR    POLLERR
#define POLLHUP    POLLHUP
#define POLLIN     POLLIN
#define POLLNVAL   POLLNVAL
#define POLLOUT    POLLOUT
#define POLLPRI    POLLPRI
#define POLLRDBAND POLLRDBAND
#define POLLRDHUP  POLLRDHUP
#define POLLRDNORM POLLRDNORM
#define POLLWRBAND POLLWRBAND
#define POLLWRNORM POLLWRNORM


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_
COSMOPOLITAN_C_START_

extern const int POSIX_FADV_DONTNEED;
extern const int POSIX_FADV_NOREUSE;
extern const int POSIX_MADV_DONTNEED;
extern const int POSIX_MADV_DONTNEED;

#define POSIX_FADV_NORMAL     0
#define POSIX_FADV_RANDOM     1
#define POSIX_FADV_SEQUENTIAL 2
#define POSIX_FADV_WILLNEED   3

#define POSIX_FADV_DONTNEED POSIX_FADV_DONTNEED
#define POSIX_FADV_NOREUSE  POSIX_FADV_NOREUSE

#define POSIX_MADV_NORMAL     0
#define POSIX_MADV_RANDOM     1
#define POSIX_MADV_SEQUENTIAL 2
#define POSIX_MADV_WILLNEED   3

#define POSIX_MADV_DONTNEED POSIX_MADV_DONTNEED


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/pr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PR_H_

#define PR_GET_SECCOMP        21
#define PR_SET_SECCOMP        22
#define SECCOMP_MODE_DISABLED 0
#define SECCOMP_MODE_STRICT   1
#define SECCOMP_MODE_FILTER   2

#define PR_CAPBSET_READ 23
#define PR_CAPBSET_DROP 24

#define PR_SET_NO_NEW_PRIVS 38
#define PR_GET_NO_NEW_PRIVS 39

#define PR_SET_NAME 15
#define PR_GET_NAME 16

#define PR_GET_TSC     25
#define PR_SET_TSC     26
#define PR_TSC_ENABLE  1
#define PR_TSC_SIGSEGV 2

#define PR_GET_FPEXC        11
#define PR_SET_FPEXC        12
#define PR_FP_EXC_SW_ENABLE 0x80
#define PR_FP_EXC_DIV       0x010000
#define PR_FP_EXC_OVF       0x020000
#define PR_FP_EXC_UND       0x040000
#define PR_FP_EXC_RES       0x080000
#define PR_FP_EXC_INV       0x100000
#define PR_FP_EXC_DISABLED  0
#define PR_FP_EXC_NONRECOV  1
#define PR_FP_EXC_ASYNC     2
#define PR_FP_EXC_PRECISE   3

#define PR_MCE_KILL_CLEAR           0
#define PR_MCE_KILL_LATE            0
#define PR_SPEC_NOT_AFFECTED        0
#define PR_SPEC_STORE_BYPASS        0
#define PR_CAP_AMBIENT_IS_SET       1
#define PR_FPEMU_NOPRINT            1
#define PR_MCE_KILL_EARLY           1
#define PR_MCE_KILL_SET             1
#define PR_SET_MM_START_CODE        1
#define PR_SET_PDEATHSIG            1
#define PR_SPEC_PRCTL               1
#define PR_CAP_AMBIENT_RAISE        2
#define PR_FPEMU_SIGFPE             2
#define PR_GET_PDEATHSIG            2
#define PR_MCE_KILL_DEFAULT         2
#define PR_SET_MM_END_CODE          2
#define PR_SPEC_ENABLE              2
#define PR_CAP_AMBIENT_LOWER        3
#define PR_GET_DUMPABLE             3
#define PR_SET_MM_START_DATA        3
#define PR_CAP_AMBIENT_CLEAR_ALL    4
#define PR_SET_DUMPABLE             4
#define PR_SET_MM_END_DATA          4
#define PR_SPEC_DISABLE             4
#define PR_SET_MM_START_STACK       5
#define PR_SET_MM_START_BRK         6
#define PR_GET_KEEPCAPS             7
#define PR_SET_MM_BRK               7
#define PR_SET_KEEPCAPS             8
#define PR_SET_MM_ARG_START         8
#define PR_SPEC_FORCE_DISABLE       8
#define PR_GET_FPEMU                9
#define PR_SET_MM_ARG_END           9
#define PR_SET_FPEMU                10
#define PR_SET_MM_ENV_START         10
#define PR_GET_FPEXC                11
#define PR_SET_MM_ENV_END           11
#define PR_SET_FPEXC                12
#define PR_SET_MM_AUXV              12
#define PR_SET_MM_EXE_FILE          13
#define PR_SET_MM_MAP               14
#define PR_SET_MM_MAP_SIZE          15
#define PR_GET_TSC                  25
#define PR_SET_TSC                  26
#define PR_GET_SECUREBITS           27
#define PR_SET_SECUREBITS           28
#define PR_SET_TIMERSLACK           29
#define PR_GET_TIMERSLACK           30
#define PR_TASK_PERF_EVENTS_DISABLE 31
#define PR_TASK_PERF_EVENTS_ENABLE  0x20
#define PR_MCE_KILL                 33
#define PR_MCE_KILL_GET             34
#define PR_SET_MM                   35
#define PR_SET_CHILD_SUBREAPER      36
#define PR_GET_CHILD_SUBREAPER      37
#define PR_GET_TID_ADDRESS          40
#define PR_SET_THP_DISABLE          41
#define PR_GET_THP_DISABLE          42
#define PR_MPX_ENABLE_MANAGEMENT    43
#define PR_MPX_DISABLE_MANAGEMENT   44
#define PR_CAP_AMBIENT              47
#define PR_GET_SPECULATION_CTRL     52
#define PR_SET_SPECULATION_CTRL     53
#define PR_SET_TAGGED_ADDR_CTRL     55
#define PR_GET_TAGGED_ADDR_CTRL     56
#define PR_SET_IO_FLUSHER           57
#define PR_GET_IO_FLUSHER           58
#define PR_SET_PTRACER              0x59616d61
#define PR_SET_PTRACER_ANY          -1
#define PR_SET_VMA                  0x53564d41
#define PR_SET_VMA_ANON_NAME        0



/*!BEGIN libc/sysv/consts/prio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PRIO_H_
COSMOPOLITAN_C_START_

extern const int PRIO_MAX;
extern const int PRIO_MIN;
extern const int PRIO_PGRP;
extern const int PRIO_PROCESS;
extern const int PRIO_USER;

#define PRIO_PROCESS 0
#define PRIO_PGRP    1
#define PRIO_USER    2
#define PRIO_MIN     -20
#define PRIO_MAX     20

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/prot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PROT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int PROT_NONE;
extern const int PROT_READ;
extern const int PROT_WRITE;
extern const int PROT_EXEC;
extern const int PROT_GROWSDOWN;
extern const int PROT_GROWSUP;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define PROT_NONE  0
#define PROT_READ  1
#define PROT_WRITE 2
#define PROT_EXEC  4



/*!BEGIN libc/sysv/consts/pt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PT_H_


/*!BEGIN libc/sysv/consts/ptrace.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTRACE_H_
COSMOPOLITAN_C_START_

extern const int PTRACE_TRACEME;
extern const int PTRACE_PEEKTEXT;
extern const int PTRACE_PEEKDATA;
extern const int PTRACE_PEEKUSER;
extern const int PTRACE_POKETEXT;
extern const int PTRACE_POKEDATA;
extern const int PTRACE_POKEUSER;
extern const int PTRACE_CONT;
extern const int PTRACE_KILL;
extern const int PTRACE_SINGLESTEP;
extern const int PTRACE_GETREGS;
extern const int PTRACE_SETREGS;
extern const int PTRACE_GETFPREGS;
extern const int PTRACE_SETFPREGS;
extern const int PTRACE_ATTACH;
extern const int PTRACE_DETACH;
extern const int PTRACE_GETFPXREGS;
extern const int PTRACE_SETFPXREGS;
extern const int PTRACE_SYSCALL;
extern const int PTRACE_GETEVENTMSG;
extern const int PTRACE_GETSIGINFO;
extern const int PTRACE_SETOPTIONS;
extern const int PTRACE_SETSIGINFO;
extern const int PTRACE_GETREGSET;
extern const int PTRACE_GETSIGMASK;
extern const int PTRACE_INTERRUPT;
extern const int PTRACE_LISTEN;
extern const int PTRACE_PEEKSIGINFO;
extern const int PTRACE_SECCOMP_GET_FILTER;
extern const int PTRACE_SECCOMP_GET_METADATA;
extern const int PTRACE_SEIZE;
extern const int PTRACE_SETREGSET;
extern const int PTRACE_SETSIGMASK;
extern const int PTRACE_O_TRACESYSGOOD;
extern const int PTRACE_O_TRACEFORK;
extern const int PTRACE_O_TRACEVFORK;
extern const int PTRACE_O_TRACECLONE;
extern const int PTRACE_O_TRACEEXEC;
extern const int PTRACE_O_TRACEVFORKDONE;
extern const int PTRACE_O_TRACEEXIT;
extern const int PTRACE_O_TRACESECCOMP;
extern const int PTRACE_O_MASK;
extern const int PTRACE_EVENT_FORK;
extern const int PTRACE_EVENT_VFORK;
extern const int PTRACE_EVENT_CLONE;
extern const int PTRACE_EVENT_EXEC;
extern const int PTRACE_EVENT_VFORK_DONE;
extern const int PTRACE_EVENT_EXIT;
extern const int PTRACE_EVENT_STOP;
extern const int PTRACE_EVENT_SECCOMP;

COSMOPOLITAN_C_END_

#define PTRACE_TRACEME              PTRACE_TRACEME
#define PTRACE_PEEKTEXT             PTRACE_PEEKTEXT
#define PTRACE_PEEKDATA             PTRACE_PEEKDATA
#define PTRACE_PEEKUSER             PTRACE_PEEKUSER
#define PTRACE_POKETEXT             PTRACE_POKETEXT
#define PTRACE_POKEDATA             PTRACE_POKEDATA
#define PTRACE_POKEUSER             PTRACE_POKEUSER
#define PTRACE_CONT                 PTRACE_CONT
#define PTRACE_KILL                 PTRACE_KILL
#define PTRACE_SINGLESTEP           PTRACE_SINGLESTEP
#define PTRACE_GETREGS              PTRACE_GETREGS
#define PTRACE_SETREGS              PTRACE_SETREGS
#define PTRACE_GETFPREGS            PTRACE_GETFPREGS
#define PTRACE_SETFPREGS            PTRACE_SETFPREGS
#define PTRACE_ATTACH               PTRACE_ATTACH
#define PTRACE_DETACH               PTRACE_DETACH
#define PTRACE_GETFPXREGS           PTRACE_GETFPXREGS
#define PTRACE_SETFPXREGS           PTRACE_SETFPXREGS
#define PTRACE_SYSCALL              PTRACE_SYSCALL
#define PTRACE_GETEVENTMSG          PTRACE_GETEVENTMSG
#define PTRACE_GETSIGINFO           PTRACE_GETSIGINFO
#define PTRACE_SETOPTIONS           PTRACE_SETOPTIONS
#define PTRACE_SETSIGINFO           PTRACE_SETSIGINFO
#define PTRACE_GETREGSET            PTRACE_GETREGSET
#define PTRACE_GETSIGMASK           PTRACE_GETSIGMASK
#define PTRACE_INTERRUPT            PTRACE_INTERRUPT
#define PTRACE_LISTEN               PTRACE_LISTEN
#define PTRACE_PEEKSIGINFO          PTRACE_PEEKSIGINFO
#define PTRACE_SECCOMP_GET_FILTER   PTRACE_SECCOMP_GET_FILTER
#define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
#define PTRACE_SEIZE                PTRACE_SEIZE
#define PTRACE_SETREGSET            PTRACE_SETREGSET
#define PTRACE_SETSIGMASK           PTRACE_SETSIGMASK
#define PTRACE_O_TRACESYSGOOD       PTRACE_O_TRACESYSGOOD
#define PTRACE_O_TRACEFORK          PTRACE_O_TRACEFORK
#define PTRACE_O_TRACEVFORK         PTRACE_O_TRACEVFORK
#define PTRACE_O_TRACECLONE         PTRACE_O_TRACECLONE
#define PTRACE_O_TRACEEXEC          PTRACE_O_TRACEEXEC
#define PTRACE_O_TRACEVFORKDONE     PTRACE_O_TRACEVFORKDONE
#define PTRACE_O_TRACEEXIT          PTRACE_O_TRACEEXIT
#define PTRACE_O_TRACESECCOMP       PTRACE_O_TRACESECCOMP
#define PTRACE_O_MASK               PTRACE_O_MASK
#define PTRACE_EVENT_FORK           PTRACE_EVENT_FORK
#define PTRACE_EVENT_VFORK          PTRACE_EVENT_VFORK
#define PTRACE_EVENT_CLONE          PTRACE_EVENT_CLONE
#define PTRACE_EVENT_EXEC           PTRACE_EVENT_EXEC
#define PTRACE_EVENT_VFORK_DONE     PTRACE_EVENT_VFORK_DONE
#define PTRACE_EVENT_EXIT           PTRACE_EVENT_EXIT
#define PTRACE_EVENT_STOP           PTRACE_EVENT_STOP
#define PTRACE_EVENT_SECCOMP        PTRACE_EVENT_SECCOMP


#define PT_ATTACH      PTRACE_ATTACH
#define PT_CONTINUE    PTRACE_CONT
#define PT_DETACH      PTRACE_DETACH
#define PT_GETEVENTMSG PTRACE_GETEVENTMSG
#define PT_GETFPREGS   PTRACE_GETFPREGS
#define PT_GETFPXREGS  PTRACE_GETFPXREGS
#define PT_GETREGS     PTRACE_GETREGS
#define PT_GETSIGINFO  PTRACE_GETSIGINFO
#define PT_KILL        PTRACE_KILL
#define PT_READ_D      PTRACE_PEEKDATA
#define PT_READ_I      PTRACE_PEEKTEXT
#define PT_READ_U      PTRACE_PEEKUSER
#define PT_SETFPREGS   PTRACE_SETFPREGS
#define PT_SETFPXREGS  PTRACE_SETFPXREGS
#define PT_SETOPTIONS  PTRACE_SETOPTIONS
#define PT_SETREGS     PTRACE_SETREGS
#define PT_SETSIGINFO  PTRACE_SETSIGINFO
#define PT_STEP        PTRACE_SINGLESTEP
#define PT_SYSCALL     PTRACE_SYSCALL
#define PT_WRITE_D     PTRACE_POKEDATA
#define PT_WRITE_I     PTRACE_POKETEXT
#define PT_WRITE_U     PTRACE_POKEUSER



/*!BEGIN libc/sysv/consts/pty.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTY_H_
COSMOPOLITAN_C_START_

extern const int TIOCPKT;
extern const int TIOCPKT_DATA;
extern const int TIOCPKT_DOSTOP;
extern const int TIOCPKT_FLUSHREAD;
extern const int TIOCPKT_FLUSHWRITE;
extern const int TIOCPKT_IOCTL;
extern const int TIOCPKT_NOSTOP;
extern const int TIOCPKT_START;
extern const int TIOCPKT_STOP;

#define TIOCPKT_DATA       0x00
#define TIOCPKT_DOSTOP     0x01
#define TIOCPKT_FLUSHREAD  0x02
#define TIOCPKT_FLUSHWRITE 0x04
#define TIOCPKT_IOCTL      0x08
#define TIOCPKT_NOSTOP     0x10
#define TIOCPKT_START      0x20
#define TIOCPKT_STOP       0x40

#define TIOCPKT TIOCPKT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/read.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_READ_H_

#define READ_10 READ_10
#define READ_12 READ_12
#define READ_6 READ_6
#define READ_BLOCK_LIMITS READ_BLOCK_LIMITS
#define READ_BUFFER READ_BUFFER
#define READ_CAPACITY READ_CAPACITY
#define READ_DEFECT_DATA READ_DEFECT_DATA
#define READ_ELEMENT_STATUS READ_ELEMENT_STATUS
#define READ_LONG READ_LONG
#define READ_POSITION READ_POSITION
#define READ_REVERSE READ_REVERSE
#define READ_TOC READ_TOC

COSMOPOLITAN_C_START_

extern const long READ_10;
extern const long READ_12;
extern const long READ_6;
extern const long READ_BLOCK_LIMITS;
extern const long READ_BUFFER;
extern const long READ_CAPACITY;
extern const long READ_DEFECT_DATA;
extern const long READ_ELEMENT_STATUS;
extern const long READ_LONG;
extern const long READ_POSITION;
extern const long READ_REVERSE;
extern const long READ_TOC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/reboot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_REBOOT_H_
COSMOPOLITAN_C_START_

extern const unsigned RB_AUTOBOOT;
extern const unsigned RB_POWER_OFF;
extern const unsigned RB_POWERDOWN;
extern const unsigned RB_POWEROFF;
extern const unsigned RB_HALT_SYSTEM;
extern const unsigned RB_HALT;
extern const unsigned RB_SW_SUSPEND;
extern const unsigned RB_KEXEC;
extern const unsigned RB_ENABLE_CAD;
extern const unsigned RB_DISABLE_CAD;
extern const unsigned RB_NOSYNC;

#define RB_AUTOBOOT    RB_AUTOBOOT
#define RB_POWER_OFF   RB_POWER_OFF
#define RB_POWERDOWN   RB_POWERDOWN
#define RB_POWEROFF    RB_POWEROFF
#define RB_HALT_SYSTEM RB_HALT_SYSTEM
#define RB_HALT        RB_HALT
#define RB_SW_SUSPEND  RB_SW_SUSPEND
#define RB_KEXEC       RB_KEXEC
#define RB_ENABLE_CAD  RB_ENABLE_CAD
#define RB_DISABLE_CAD RB_DISABLE_CAD
#define RB_NOSYNC      RB_NOSYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlim.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIM_H_
COSMOPOLITAN_C_START_

extern const uint64_t RLIM_INFINITY;
extern const uint64_t RLIM_NLIMITS;
extern const uint64_t RLIM_SAVED_CUR;
extern const uint64_t RLIM_SAVED_MAX;

#define RLIM_INFINITY  RLIM_INFINITY
#define RLIM_NLIMITS   RLIM_NLIMITS
#define RLIM_SAVED_CUR RLIM_SAVED_CUR
#define RLIM_SAVED_MAX RLIM_SAVED_MAX


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlimit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIMIT_H_
COSMOPOLITAN_C_START_

extern const unsigned RLIMIT_AS;
extern const unsigned RLIMIT_CORE;
extern const unsigned RLIMIT_CPU;
extern const unsigned RLIMIT_DATA;
extern const unsigned RLIMIT_FSIZE;
extern const unsigned RLIMIT_LOCKS;
extern const unsigned RLIMIT_MEMLOCK;
extern const unsigned RLIMIT_MSGQUEUE;
extern const unsigned RLIMIT_NICE;
extern const unsigned RLIMIT_NOFILE;
extern const unsigned RLIMIT_NPROC;
extern const unsigned RLIMIT_NPTS;
extern const unsigned RLIMIT_RSS;
extern const unsigned RLIMIT_RTPRIO;
extern const unsigned RLIMIT_RTTIME;
extern const unsigned RLIMIT_SBSIZE;
extern const unsigned RLIMIT_SIGPENDING;
extern const unsigned RLIMIT_STACK;
extern const unsigned RLIMIT_SWAP;
extern const unsigned RLIMIT_VMEM;

#define RLIMIT_AS         RLIMIT_AS
#define RLIMIT_CORE       RLIMIT_CORE
#define RLIMIT_CPU        RLIMIT_CPU
#define RLIMIT_DATA       RLIMIT_DATA
#define RLIMIT_FSIZE      RLIMIT_FSIZE
#define RLIMIT_LOCKS      RLIMIT_LOCKS
#define RLIMIT_MEMLOCK    RLIMIT_MEMLOCK
#define RLIMIT_MSGQUEUE   RLIMIT_MSGQUEUE
#define RLIMIT_NICE       RLIMIT_NICE
#define RLIMIT_NOFILE     RLIMIT_NOFILE
#define RLIMIT_NPROC      RLIMIT_NPROC
#define RLIMIT_NPTS       RLIMIT_NPTS
#define RLIMIT_RSS        RLIMIT_RSS
#define RLIMIT_RTPRIO     RLIMIT_RTPRIO
#define RLIMIT_RTTIME     RLIMIT_RTTIME
#define RLIMIT_SBSIZE     RLIMIT_SBSIZE
#define RLIMIT_SIGPENDING RLIMIT_SIGPENDING
#define RLIMIT_STACK      RLIMIT_STACK
#define RLIMIT_SWAP       RLIMIT_SWAP
#define RLIMIT_VMEM       RLIMIT_VMEM

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rusage.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RUSAGE_H_
COSMOPOLITAN_C_START_

extern const int RUSAGE_THREAD;
extern const int RUSAGE_CHILDREN;
extern const int RUSAGE_BOTH;

#define RUSAGE_SELF     0
#define RUSAGE_CHILDREN RUSAGE_CHILDREN

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/s.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_S_H_

#define S_IFIFO  0010000 /* pipe */
#define S_IFCHR  0020000 /* character device */
#define S_IFDIR  0040000 /* directory */
#define S_IFBLK  0060000 /* block device */
#define S_IFREG  0100000 /* regular file */
#define S_IFLNK  0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
#define S_IFMT   0170000 /* mask of file types above */

#define S_ISVTX  0001000 /* THE STICKY BIT */
#define S_ISGID  0002000 /* the setgid bit */
#define S_ISUID  0004000 /* the setuid bit */
#define S_IXUSR  0000100 /* user  --x; just use octal */
#define S_IWUSR  0000200 /* user  -w-; just use octal */
#define S_IRUSR  0000400 /* user  r--; just use octal */
#define S_IRWXU  0000700 /* user  rwx; just use octal */
#define S_IXGRP  0000010 /* group --x; just use octal */
#define S_IWGRP  0000020 /* group -w-; just use octal */
#define S_IRGRP  0000040 /* group r--; just use octal */
#define S_IRWXG  0000070 /* group rwx; just use octal */
#define S_IXOTH  0000001 /* other --x; just use octal */
#define S_IWOTH  0000002 /* other -w-; just use octal */
#define S_IROTH  0000004 /* other r--; just use octal */
#define S_IRWXO  0000007 /* other rwx; just use octal */
#define S_IREAD  0000400 /* just use octal */
#define S_IEXEC  0000100 /* just use octal */
#define S_IWRITE 0000200 /* just use octal */
#define S_ISTXT  0001000 /* just use octal */

#define S_ISDIR(mode)  (((mode)&S_IFMT) == S_IFDIR)
#define S_ISCHR(mode)  (((mode)&S_IFMT) == S_IFCHR)
#define S_ISBLK(mode)  (((mode)&S_IFMT) == S_IFBLK)
#define S_ISREG(mode)  (((mode)&S_IFMT) == S_IFREG)
#define S_ISFIFO(mode) (((mode)&S_IFMT) == S_IFIFO)
#define S_ISLNK(mode)  (((mode)&S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)

#define S_BLKSIZE   512
#define ALLPERMS    (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO)
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)



/*!BEGIN libc/sysv/consts/sa.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SA_H_
COSMOPOLITAN_C_START_

extern const uint64_t SA_NOCLDSTOP;
extern const uint64_t SA_NOCLDWAIT;
extern const uint64_t SA_NODEFER;
extern const uint64_t SA_NOMASK;
extern const uint64_t SA_ONESHOT;
extern const uint64_t SA_ONSTACK;
extern const uint64_t SA_RESETHAND;
extern const uint64_t SA_RESTART;
extern const uint64_t SA_SIGINFO;

#define SA_NOCLDSTOP SA_NOCLDSTOP
#define SA_NOCLDWAIT SA_NOCLDWAIT
#define SA_NODEFER   SA_NODEFER
#define SA_NOMASK    SA_NOMASK
#define SA_ONESHOT   SA_ONESHOT
#define SA_ONSTACK   SA_ONSTACK
#define SA_RESETHAND SA_RESETHAND
#define SA_RESTART   SA_RESTART
#define SA_SIGINFO   SA_SIGINFO


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sched.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCHED_H_
COSMOPOLITAN_C_START_

extern const int SCHED_BATCH;
extern const int SCHED_DEADLINE;
extern const int SCHED_FIFO;
extern const int SCHED_IDLE;
extern const int SCHED_OTHER;
extern const int SCHED_RESET_ON_FORK;
extern const int SCHED_RR;

#define SCHED_BATCH         SCHED_BATCH
#define SCHED_DEADLINE      SCHED_DEADLINE
#define SCHED_FIFO          SCHED_FIFO
#define SCHED_IDLE          SCHED_IDLE
#define SCHED_NORMAL        SCHED_OTHER
#define SCHED_OTHER         SCHED_OTHER
#define SCHED_RESET_ON_FORK SCHED_RESET_ON_FORK
#define SCHED_RR            SCHED_RR


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/scm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCM_H_
COSMOPOLITAN_C_START_

extern const int SCM_TIMESTAMP;
extern const int SCM_CREDENTIALS;
extern const int SCM_TIMESTAMPING;
extern const int SCM_TIMESTAMPNS;
extern const int SCM_WIFI_STATUS;

COSMOPOLITAN_C_END_

#define SCM_RIGHTS       1
#define SCM_TIMESTAMP    SCM_TIMESTAMP
#define SCM_CREDENTIALS  SCM_CREDENTIALS
#define SCM_TIMESTAMPING SCM_TIMESTAMPING
#define SCM_TIMESTAMPNS  SCM_TIMESTAMPNS
#define SCM_WIFI_STATUS  SCM_WIFI_STATUS




/*!BEGIN libc/sysv/consts/seek.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SEEK_H_
COSMOPOLITAN_C_START_

extern const int SEEK_DATA;
extern const int SEEK_HOLE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SF_H_
COSMOPOLITAN_C_START_

struct sf_hdtr {
  struct iovec *headers;
  int hdr_cnt;
  struct iovec *trailers;
  int trl_cnt;
};

extern const int SF_MNOWAIT;
extern const int SF_NODISKIO;
extern const int SF_SYNC;

#define SF_MNOWAIT  SF_MNOWAIT
#define SF_NODISKIO SF_NODISKIO
#define SF_SYNC     SF_SYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHM_H_

#define SHM_ANON      SHM_ANON
#define SHM_DEST      SHM_DEST
#define SHM_EXEC      SHM_EXEC
#define SHM_HUGETLB   SHM_HUGETLB
#define SHM_INFO      SHM_INFO
#define SHM_LOCK      SHM_LOCK
#define SHM_LOCKED    SHM_LOCKED
#define SHM_NORESERVE SHM_NORESERVE
#define SHM_R         SHM_R
#define SHM_RDONLY    SHM_RDONLY
#define SHM_REMAP     SHM_REMAP
#define SHM_RND       SHM_RND
#define SHM_STAT      SHM_STAT
#define SHM_UNLOCK    SHM_UNLOCK
#define SHM_W         SHM_W

COSMOPOLITAN_C_START_

extern const char *SHM_ANON;
extern const int SHM_DEST;
extern const int SHM_EXEC;
extern const int SHM_HUGETLB;
extern const int SHM_INFO;
extern const int SHM_LOCK;
extern const int SHM_LOCKED;
extern const int SHM_NORESERVE;
extern const int SHM_R;
extern const int SHM_RDONLY;
extern const int SHM_REMAP;
extern const int SHM_RND;
extern const int SHM_STAT;
extern const int SHM_UNLOCK;
extern const int SHM_W;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shut.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHUT_H_
COSMOPOLITAN_C_START_

extern const int SHUT_RD;
extern const int SHUT_RDWR;
extern const int SHUT_WR;

#define SHUT_RD   0
#define SHUT_RDWR 2
#define SHUT_WR   1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sicode.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SICODE_H_
COSMOPOLITAN_C_START_

extern const int32_t SI_USER;
extern const int32_t SI_QUEUE;
extern const int32_t SI_TIMER;
extern const int32_t SI_MESGQ;
extern const int32_t SI_ASYNCIO;
extern const int32_t SI_TKILL;
extern const int32_t SI_ASYNCNL;
extern const int32_t SI_KERNEL;
extern const int32_t SI_NOINFO;
extern const int32_t CLD_EXITED;
extern const int32_t CLD_KILLED;
extern const int32_t CLD_DUMPED;
extern const int32_t CLD_TRAPPED;
extern const int32_t CLD_STOPPED;
extern const int32_t CLD_CONTINUED;
extern const int32_t TRAP_BRKPT;
extern const int32_t TRAP_TRACE;
extern const int32_t SEGV_MAPERR;
extern const int32_t SEGV_ACCERR;
extern const int32_t SEGV_PKUERR;
extern const int32_t FPE_INTDIV;
extern const int32_t FPE_INTOVF;
extern const int32_t FPE_FLTDIV;
extern const int32_t FPE_FLTOVF;
extern const int32_t FPE_FLTUND;
extern const int32_t FPE_FLTRES;
extern const int32_t FPE_FLTINV;
extern const int32_t FPE_FLTSUB;
extern const int32_t ILL_ILLOPC;
extern const int32_t ILL_ILLOPN;
extern const int32_t ILL_ILLADR;
extern const int32_t ILL_ILLTRP;
extern const int32_t ILL_PRVOPC;
extern const int32_t ILL_PRVREG;
extern const int32_t ILL_COPROC;
extern const int32_t ILL_BADSTK;
extern const int32_t BUS_ADRALN;
extern const int32_t BUS_ADRERR;
extern const int32_t BUS_OBJERR;
extern const int32_t BUS_MCEERR_AR;
extern const int32_t BUS_MCEERR_AO;
extern const int32_t BUS_OOMERR;
extern const int32_t POLL_IN;
extern const int32_t POLL_OUT;
extern const int32_t POLL_MSG;
extern const int32_t POLL_ERR;
extern const int32_t POLL_PRI;
extern const int32_t POLL_HUP;
extern const int32_t SYS_SECCOMP;
extern const int32_t SYS_USER_DISPATCH;

#define CLD_EXITED    1
#define CLD_KILLED    2
#define CLD_DUMPED    3
#define CLD_TRAPPED   4
#define CLD_STOPPED   5
#define CLD_CONTINUED 6
#define TRAP_BRKPT    1
#define TRAP_TRACE    2
#define SEGV_MAPERR   1
#define SEGV_ACCERR   2
#define ILL_ILLOPC    1
#define ILL_PRVREG    6
#define ILL_COPROC    7
#define ILL_BADSTK    8
#define BUS_ADRALN    1
#define BUS_ADRERR    2
#define BUS_OBJERR    3
#define POLL_IN       1
#define POLL_OUT      2
#define POLL_MSG      3
#define POLL_ERR      4
#define POLL_PRI      5
#define POLL_HUP      6

#define SI_USER           SI_USER
#define SI_QUEUE          SI_QUEUE
#define SI_TIMER          SI_TIMER
#define SI_MESGQ          SI_MESGQ
#define SI_ASYNCIO        SI_ASYNCIO
#define SI_TKILL          SI_TKILL
#define SI_ASYNCNL        SI_ASYNCNL
#define SI_KERNEL         SI_KERNEL
#define SI_NOINFO         SI_NOINFO
#define SEGV_PKUERR       SEGV_PKUERR
#define FPE_INTDIV        FPE_INTDIV
#define FPE_INTOVF        FPE_INTOVF
#define FPE_FLTDIV        FPE_FLTDIV
#define FPE_FLTOVF        FPE_FLTOVF
#define FPE_FLTUND        FPE_FLTUND
#define FPE_FLTRES        FPE_FLTRES
#define FPE_FLTINV        FPE_FLTINV
#define FPE_FLTSUB        FPE_FLTSUB
#define ILL_ILLOPN        ILL_ILLOPN
#define ILL_ILLADR        ILL_ILLADR
#define ILL_ILLTRP        ILL_ILLTRP
#define ILL_PRVOPC        ILL_PRVOPC
#define BUS_OOMERR        BUS_OOMERR
#define BUS_MCEERR_AR     BUS_MCEERR_AR
#define BUS_MCEERR_AO     BUS_MCEERR_AO
#define SYS_SECCOMP       SYS_SECCOMP
#define SYS_USER_DISPATCH SYS_USER_DISPATCH


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sig.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIG_H_
COSMOPOLITAN_C_START_

extern const int SIGABRT;
extern const int SIGALRM;
extern const int SIGBUS;
extern const int SIGTHR;
extern const int SIGCHLD;
extern const int SIGCONT;
extern const int SIGEMT;
extern const int SIGFPE;
extern const int SIGHUP;
extern const int SIGILL;
extern const int SIGINFO;
extern const int SIGINT;
extern const int SIGIO;
extern const int SIGIOT;
extern const int SIGKILL;
extern const int SIGPIPE;
extern const int SIGPOLL;
extern const int SIGPROF;
extern const int SIGPWR;
extern const int SIGQUIT;
extern const int SIGRTMAX;
extern const int SIGRTMIN;
extern const int SIGSEGV;
extern const int SIGSTKFLT;
extern const int SIGSTOP;
extern const int SIGSYS;
extern const int SIGTERM;
extern const int SIGTRAP;
extern const int SIGTSTP;
extern const int SIGTTIN;
extern const int SIGTTOU;
extern const int SIGUNUSED;
extern const int SIGURG;
extern const int SIGUSR1;
extern const int SIGUSR2;
extern const int SIGVTALRM;
extern const int SIGWINCH;
extern const int SIGXCPU;
extern const int SIGXFSZ;

extern const int SIG_BLOCK;
extern const int SIG_SETMASK;
extern const int SIG_UNBLOCK;

COSMOPOLITAN_C_END_

#define SIGABRT   6
#define SIGALRM   14
#define SIGFPE    8
#define SIGHUP    1
#define SIGILL    4
#define SIGINT    2
#define SIGIOT    6
#define SIGKILL   9
#define SIGPIPE   13
#define SIGPROF   27
#define SIGQUIT   3
#define SIGSEGV   11
#define SIGTERM   15
#define SIGTRAP   5
#define SIGTTIN   21
#define SIGTTOU   22
#define SIGVTALRM 26
#define SIGWINCH  28
#define SIGXCPU   24
#define SIGXFSZ   25

/*
 * - No macro is define for SIGIO and SIGPOLL in order to persuade
 *   ./configure scripts to favor using poll() or select() instead of
 *   interrupt-based i/o.
 *
 * - No macros are defined for SIGRTMIN and SIGRTMAX because the project
 *   hasn't fleshed them out yet.
 *
 * - SIGTHR doesn't have a macro since it's internal to posix threads.
 *
 * - SIGSTKFLT is Linux-only so no macro is defined.
 */

#define SIGBUS  SIGBUS
#define SIGCHLD SIGCHLD
#define SIGCONT SIGCONT
#define SIGEMT  SIGEMT
#define SIGINFO SIGINFO
#define SIGPWR  SIGPWR
#define SIGSTOP SIGSTOP
#define SIGSYS  SIGSYS
#define SIGTSTP SIGTSTP
#define SIGURG  SIGURG
#define SIGUSR1 SIGUSR1
#define SIGUSR2 SIGUSR2

#define SIG_BLOCK   SIG_BLOCK
#define SIG_SETMASK SIG_SETMASK
#define SIG_UNBLOCK SIG_UNBLOCK



/*!BEGIN libc/sysv/consts/sio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIO_H_
COSMOPOLITAN_C_START_

extern const unsigned long SIOCADDDLCI;
extern const unsigned long SIOCADDMULTI;
extern const unsigned long SIOCADDRT;
extern const unsigned long SIOCDARP;
extern const unsigned long SIOCDELDLCI;
extern const unsigned long SIOCDELMULTI;
extern const unsigned long SIOCDELRT;
extern const unsigned long SIOCDEVPRIVATE;
extern const unsigned long SIOCDIFADDR;
extern const unsigned long SIOCDRARP;
extern const unsigned long SIOCGARP;
extern const unsigned long SIOCGIFADDR;
extern const unsigned long SIOCGIFBR;
extern const unsigned long SIOCGIFBRDADDR;
extern const unsigned long SIOCGIFCONF;
extern const unsigned long SIOCGIFCOUNT;
extern const unsigned long SIOCGIFDSTADDR;
extern const unsigned long SIOCGIFENCAP;
extern const unsigned long SIOCGIFFLAGS;
extern const unsigned long SIOCGIFHWADDR;
extern const unsigned long SIOCGIFINDEX;
extern const unsigned long SIOCGIFMAP;
extern const unsigned long SIOCGIFMEM;
extern const unsigned long SIOCGIFMETRIC;
extern const unsigned long SIOCGIFMTU;
extern const unsigned long SIOCGIFNAME;
extern const unsigned long SIOCGIFNETMASK;
extern const unsigned long SIOCGIFPFLAGS;
extern const unsigned long SIOCGIFSLAVE;
extern const unsigned long SIOCGIFTXQLEN;
extern const unsigned long SIOCGPGRP;
extern const unsigned long SIOCGRARP;
extern const unsigned long SIOCGSTAMP;
extern const unsigned long SIOCGSTAMPNS;
extern const unsigned long SIOCPROTOPRIVATE;
extern const unsigned long SIOCRTMSG;
extern const unsigned long SIOCSARP;
extern const unsigned long SIOCSIFADDR;
extern const unsigned long SIOCSIFBR;
extern const unsigned long SIOCSIFBRDADDR;
extern const unsigned long SIOCSIFDSTADDR;
extern const unsigned long SIOCSIFENCAP;
extern const unsigned long SIOCSIFFLAGS;
extern const unsigned long SIOCSIFHWADDR;
extern const unsigned long SIOCSIFHWBROADCAST;
extern const unsigned long SIOCSIFLINK;
extern const unsigned long SIOCSIFMAP;
extern const unsigned long SIOCSIFMEM;
extern const unsigned long SIOCSIFMETRIC;
extern const unsigned long SIOCSIFMTU;
extern const unsigned long SIOCSIFNAME;
extern const unsigned long SIOCSIFNETMASK;
extern const unsigned long SIOCSIFPFLAGS;
extern const unsigned long SIOCSIFSLAVE;
extern const unsigned long SIOCSIFTXQLEN;
extern const unsigned long SIOCSPGRP;
extern const unsigned long SIOCSRARP;
extern const unsigned long SIOGIFINDEX;

#define SIOCGIFCONF    SIOCGIFCONF
#define SIOCGIFADDR    SIOCGIFADDR
#define SIOCSIFADDR    SIOCSIFADDR
#define SIOCDIFADDR    SIOCDIFADDR
#define SIOCGIFBRDADDR SIOCGIFBRDADDR
#define SIOCGIFNETMASK SIOCGIFNETMASK
#define SIOCGIFFLAGS   SIOCGIFFLAGS
#define SIOCSIFFLAGS   SIOCSIFFLAGS
#define SIOCGIFMETRIC  SIOCGIFMETRIC
#define SIOCSIFMETRIC  SIOCSIFMETRIC
#define SIOCSIFBRDADDR SIOCSIFBRDADDR
#define SIOCSIFNETMASK SIOCSIFNETMASK
#define SIOCGIFDSTADDR SIOCGIFDSTADDR
#define SIOCSIFDSTADDR SIOCSIFDSTADDR
#define SIOCGIFMTU     SIOCGIFMTU
#define SIOCSIFMTU     SIOCSIFMTU

#define SIOCGPGRP SIOCGPGRP
#define SIOCSPGRP SIOCSPGRP

#define SIOCADDMULTI SIOCADDMULTI
#define SIOCDELMULTI SIOCDELMULTI

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/so.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SO_H_

#define SO_DEBUG 1

COSMOPOLITAN_C_START_

extern const int SO_TYPE;
extern const int SO_ERROR;
extern const int SO_ACCEPTCONN;
extern const int SO_REUSEADDR;
extern const int SO_KEEPALIVE;
extern const int SO_DONTROUTE;
extern const int SO_BROADCAST;
extern const int SO_USELOOPBACK;
extern const int SO_LINGER;
extern const int SO_OOBINLINE;
extern const int SO_SNDBUF;
extern const int SO_RCVBUF;
extern const int SO_RCVTIMEO;
extern const int SO_SNDTIMEO;
extern const int SO_RCVLOWAT;
extern const int SO_SNDLOWAT;

#define SO_TYPE        SO_TYPE
#define SO_ERROR       SO_ERROR
#define SO_ACCEPTCONN  SO_ACCEPTCONN
#define SO_REUSEADDR   SO_REUSEADDR
#define SO_KEEPALIVE   SO_KEEPALIVE
#define SO_DONTROUTE   SO_DONTROUTE
#define SO_BROADCAST   SO_BROADCAST
#define SO_USELOOPBACK SO_USELOOPBACK
#define SO_LINGER      SO_LINGER
#define SO_OOBINLINE   SO_OOBINLINE
#define SO_SNDBUF      SO_SNDBUF
#define SO_RCVBUF      SO_RCVBUF
#define SO_RCVTIMEO    SO_RCVTIMEO
#define SO_SNDTIMEO    SO_SNDTIMEO
#define SO_RCVLOWAT    SO_RCVLOWAT
#define SO_SNDLOWAT    SO_SNDLOWAT

/*
 * this isn't available on windows, but it should be fine to use anyway,
 * setsockopt will return ENOPROTOOPT which is perfectly fine to ignore.
 */
extern const int SO_REUSEPORT;
#define SO_REUSEPORT SO_REUSEPORT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOCK_H_
COSMOPOLITAN_C_START_

extern const int SOCK_CLOEXEC;
extern const int SOCK_DCCP;
extern const int SOCK_DGRAM;
extern const int SOCK_NONBLOCK;
extern const int SOCK_PACKET;
extern const int SOCK_RAW;
extern const int SOCK_RDM;
extern const int SOCK_SEQPACKET;
extern const int SOCK_STREAM;

#define SOCK_STREAM    1
#define SOCK_DGRAM     2
#define SOCK_RAW       3
#define SOCK_RDM       4
#define SOCK_SEQPACKET 5
#define SOCK_CLOEXEC   SOCK_CLOEXEC
#define SOCK_NONBLOCK  SOCK_NONBLOCK

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sol.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOL_H_

#define SOL_IP     0
#define SOL_ICMP   1
#define SOL_TCP    6
#define SOL_UDP    17
#define SOL_IPV6   41
#define SOL_ICMPV6 58
#define SOL_RAW    255

COSMOPOLITAN_C_START_

extern const int SOL_SOCKET;
#define SOL_SOCKET SOL_SOCKET

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/splice.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SPLICE_H_
COSMOPOLITAN_C_START_

extern const unsigned int SPLICE_F_GIFT;
extern const unsigned int SPLICE_F_MORE;
extern const unsigned int SPLICE_F_MOVE;
extern const unsigned int SPLICE_F_NONBLOCK;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ss.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SS_H_
COSMOPOLITAN_C_START_

extern const int SS_DISABLE;
extern const int _SIGSTKSZ;
extern const int _MINSIGSTKSZ;

COSMOPOLITAN_C_END_

#define SIGSTKSZ    32768
#define MINSIGSTKSZ 32768 /* xnu defines the highest minimum */
#define SS_ONSTACK  1
#define SS_DISABLE  SS_DISABLE



/*!BEGIN libc/sysv/consts/st.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ST_H_
COSMOPOLITAN_C_START_

extern const int ST_APPEND;
extern const int ST_IMMUTABLE;
extern const int ST_MANDLOCK;
extern const int ST_NOATIME;
extern const int ST_NODEV;
extern const int ST_NODIRATIME;
extern const int ST_NOEXEC;
extern const int ST_NOSUID;
extern const int ST_RDONLY;
extern const int ST_RELATIME;
extern const int ST_SYNCHRONOUS;
extern const int ST_WRITE;

#define ST_APPEND      ST_APPEND
#define ST_IMMUTABLE   ST_IMMUTABLE
#define ST_MANDLOCK    ST_MANDLOCK
#define ST_NOATIME     ST_NOATIME
#define ST_NODEV       ST_NODEV
#define ST_NODIRATIME  ST_NODIRATIME
#define ST_NOEXEC      ST_NOEXEC
#define ST_NOSUID      ST_NOSUID
#define ST_RDONLY      ST_RDONLY
#define ST_RELATIME    ST_RELATIME
#define ST_SYNCHRONOUS ST_SYNCHRONOUS
#define ST_WRITE       ST_WRITE


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCP_H_
COSMOPOLITAN_C_START_

extern const int TCP_CC_INFO;
extern const int TCP_CONGESTION;
extern const int TCP_COOKIE_TRANSACTIONS;
extern const int TCP_CORK;
extern const int TCP_DEFER_ACCEPT;
extern const int TCP_FASTOPEN;
extern const int TCP_FASTOPEN_CONNECT;
extern const int TCP_INFO;
extern const int TCP_KEEPCNT;
extern const int TCP_KEEPIDLE;
extern const int TCP_KEEPINTVL;
extern const int TCP_LINGER2;
extern const int TCP_MAXSEG;
extern const int TCP_MD5SIG;
extern const int TCP_MD5SIG_MAXKEYLEN;
extern const int TCP_NODELAY;
extern const int TCP_NOTSENT_LOWAT;
extern const int TCP_QUEUE_SEQ;
extern const int TCP_QUICKACK;
extern const int TCP_REPAIR;
extern const int TCP_REPAIR_OPTIONS;
extern const int TCP_REPAIR_QUEUE;
extern const int TCP_SAVED_SYN;
extern const int TCP_SAVE_SYN;
extern const int TCP_SYNCNT;
extern const int TCP_THIN_DUPACK;
extern const int TCP_THIN_LINEAR_TIMEOUTS;
extern const int TCP_TIMESTAMP;
extern const int TCP_ULP;
extern const int TCP_USER_TIMEOUT;
extern const int TCP_WINDOW_CLAMP;

#define TCP_NODELAY              1
#define TCP_CC_INFO              TCP_CC_INFO
#define TCP_CONGESTION           TCP_CONGESTION
#define TCP_COOKIE_TRANSACTIONS  TCP_COOKIE_TRANSACTIONS
#define TCP_CORK                 TCP_CORK
#define TCP_DEFER_ACCEPT         TCP_DEFER_ACCEPT
#define TCP_FASTOPEN             TCP_FASTOPEN
#define TCP_FASTOPEN_CONNECT     TCP_FASTOPEN_CONNECT
#define TCP_INFO                 TCP_INFO
#define TCP_KEEPCNT              TCP_KEEPCNT
#define TCP_KEEPIDLE             TCP_KEEPIDLE
#define TCP_KEEPINTVL            TCP_KEEPINTVL
#define TCP_LINGER2              TCP_LINGER2
#define TCP_MAXSEG               TCP_MAXSEG
#define TCP_MD5SIG               TCP_MD5SIG
#define TCP_MD5SIG_MAXKEYLEN     TCP_MD5SIG_MAXKEYLEN
#define TCP_NOTSENT_LOWAT        TCP_NOTSENT_LOWAT
#define TCP_QUEUE_SEQ            TCP_QUEUE_SEQ
#define TCP_QUICKACK             TCP_QUICKACK
#define TCP_REPAIR               TCP_REPAIR
#define TCP_REPAIR_OPTIONS       TCP_REPAIR_OPTIONS
#define TCP_REPAIR_QUEUE         TCP_REPAIR_QUEUE
#define TCP_SAVED_SYN            TCP_SAVED_SYN
#define TCP_SAVE_SYN             TCP_SAVE_SYN
#define TCP_SYNCNT               TCP_SYNCNT
#define TCP_THIN_DUPACK          TCP_THIN_DUPACK
#define TCP_THIN_LINEAR_TIMEOUTS TCP_THIN_LINEAR_TIMEOUTS
#define TCP_TIMESTAMP            TCP_TIMESTAMP
#define TCP_ULP                  TCP_ULP
#define TCP_USER_TIMEOUT         TCP_USER_TIMEOUT
#define TCP_WINDOW_CLAMP         TCP_WINDOW_CLAMP


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcpopt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCPOPT_H_

#define TCPOPT_EOL            0
#define TCPOPT_NOP            1
#define TCPOPT_MAXSEG         2
#define TCPOPT_WINDOW         3
#define TCPOPT_SACK_PERMITTED 4
#define TCPOPT_SACK           5
#define TCPOPT_TIMESTAMP      8

#define TCPOLEN_SACK_PERMITTED 2
#define TCPOLEN_WINDOW         3
#define TCPOLEN_MAXSEG         4
#define TCPOLEN_TIMESTAMP      10



/*!BEGIN libc/sysv/consts/th.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TH_H_

#define TH_FIN  1
#define TH_SYN  2
#define TH_RST  4
#define TH_PUSH 8
#define TH_URG  32
#define TH_ACK  16



/*!BEGIN libc/sysv/consts/timer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TIMER_H_

#define TIMER_ABSTIME 1



/*!BEGIN libc/sysv/consts/uc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UC_H_
COSMOPOLITAN_C_START_

#define UC_FP_XSTATE         1
#define UC_SIGCONTEXT_SS     2
#define UC_STRICT_RESTORE_SS 4

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/unmount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const int MNT_FORCE;
extern const int MNT_DETACH;
extern const int MNT_EXPIRE;
extern const int UMOUNT_NOFOLLOW;
extern const int MNT_BYFSID;

COSMOPOLITAN_C_END_

#define MNT_FORCE       MNT_FORCE
#define MNT_DETACH      MNT_DETACH
#define MNT_EXPIRE      MNT_EXPIRE
#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW
#define MNT_BYFSID      MNT_BYFSID



/*!BEGIN libc/sysv/consts/utime.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UTIME_H_
COSMOPOLITAN_C_START_

extern const int UTIME_NOW;
extern const int UTIME_OMIT;

COSMOPOLITAN_C_END_

#define UTIME_NOW  UTIME_NOW
#define UTIME_OMIT UTIME_OMIT




/*!BEGIN libc/sysv/consts/waitid.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_WAITID_H_
COSMOPOLITAN_C_START_

extern const int WEXITED;
extern const int WSTOPPED;
extern const int WNOWAIT;

#define WEXITED  WEXITED
#define WSTOPPED WSTOPPED
#define WNOWAIT  WNOWAIT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/xopen.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_XOPEN_H_

#define _XOPEN_IOV_MAX  16
#define _XOPEN_ENH_I18N 1
#define _XOPEN_UNIX     1
#define _XOPEN_NAME_MAX 63
#define _XOPEN_PATH_MAX 1024
#define _XOPEN_SOURCE   700



/*!BEGIN libc/thread/semaphore.h */

#define COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
COSMOPOLITAN_C_START_

#define SEM_FAILED        ((sem_t *)0)
#define SEM_MAGIC_NAMED   0xDEADBEEFu
#define SEM_MAGIC_UNNAMED 0xFEEDABEEu
#define SEM_MAGIC_KERNEL  0xCAFEBABEu

typedef struct {
  union {
    struct {
      _Atomic(int) sem_value;
      _Atomic(int) sem_waiters;
      _Atomic(int) sem_prefs; /* named only */
      unsigned sem_magic;
      int64_t sem_dev;     /* named only */
      int64_t sem_ino;     /* named only */
      int sem_pid;         /* unnamed only */
      char sem_lazydelete; /* named only */
      char sem_pshared;
      int *sem_kernel;
    };
    void *sem_space[32];
  };
} sem_t;

int sem_init(sem_t *, int, unsigned) libcesque;
int sem_destroy(sem_t *) libcesque;
int sem_post(sem_t *) libcesque;
int sem_wait(sem_t *) libcesque;
int sem_trywait(sem_t *) libcesque;
int sem_timedwait(sem_t *, const struct timespec *) libcesque;
int sem_getvalue(sem_t *, int *) libcesque;
sem_t *sem_open(const char *, int, ...) libcesque;
int sem_close(sem_t *) libcesque;
int sem_unlink(const char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/thread.h */

#define COSMOPOLITAN_LIBC_THREAD_THREAD_H_

#define PTHREAD_KEYS_MAX              128
#define PTHREAD_STACK_MIN             65536
#define PTHREAD_DESTRUCTOR_ITERATIONS 4

#define PTHREAD_BARRIER_SERIAL_THREAD 31337

#define PTHREAD_MUTEX_DEFAULT    0
#define PTHREAD_MUTEX_NORMAL     0
#define PTHREAD_MUTEX_RECURSIVE  1
#define PTHREAD_MUTEX_ERRORCHECK 2
#define PTHREAD_MUTEX_STALLED    0
#define PTHREAD_MUTEX_ROBUST     1

#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED  1

#define PTHREAD_CREATE_JOINABLE 0
#define PTHREAD_CREATE_DETACHED 1

#define PTHREAD_INHERIT_SCHED  0
#define PTHREAD_EXPLICIT_SCHED 1

#define PTHREAD_CANCELED ((void *)-1)

#define PTHREAD_CANCEL_ENABLE  0
#define PTHREAD_CANCEL_DISABLE 1
#define PTHREAD_CANCEL_MASKED  2

#define PTHREAD_CANCEL_DEFERRED     0
#define PTHREAD_CANCEL_ASYNCHRONOUS 1

#define PTHREAD_SCOPE_SYSTEM  0
#define PTHREAD_SCOPE_PROCESS 1

#define PTHREAD_ATTR_NO_SIGMASK_NP -1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

#define PTHREAD_ONCE_INIT          _PTHREAD_INIT
#define PTHREAD_COND_INITIALIZER   _PTHREAD_INIT
#define PTHREAD_RWLOCK_INITIALIZER _PTHREAD_INIT
#define PTHREAD_MUTEX_INITIALIZER  _PTHREAD_INIT
#define _PTHREAD_INIT \
  { 0 }

typedef uintptr_t pthread_t;
typedef int pthread_id_np_t;
typedef char pthread_condattr_t;
typedef char pthread_rwlockattr_t;
typedef char pthread_barrierattr_t;
typedef unsigned pthread_key_t;
typedef void (*pthread_key_dtor)(void *);

typedef struct pthread_once_s {
  _Atomic(uint32_t) _lock;
} pthread_once_t;

typedef struct pthread_spinlock_s {
  _Atomic(int) _lock;
} pthread_spinlock_t;

typedef struct pthread_mutex_s {
  _Atomic(int32_t) _lock;
  unsigned _type : 2;
  unsigned _pshared : 1;
  unsigned _depth : 6;
  unsigned _owner : 23;
  long _pid;
} pthread_mutex_t;

typedef struct pthread_mutexattr_s {
  char _type;
  char _pshared;
} pthread_mutexattr_t;

typedef struct pthread_cond_s {
  void *_nsync[2];
} pthread_cond_t;

typedef struct pthread_rwlock_s {
  void *_nsync[2];
  char _iswrite;
} pthread_rwlock_t;

typedef struct pthread_barrier_s {
  void *_nsync;
} pthread_barrier_t;

typedef struct pthread_attr_s {
  char __detachstate;
  char __inheritsched;
  char __havesigmask;
  int __schedparam;
  int __schedpolicy;
  int __contentionscope;
  int __guardsize;
  size_t __stacksize;
  uint64_t __sigmask;
  void *__stackaddr;
} pthread_attr_t;

struct _pthread_cleanup_buffer {
  void (*__routine)(void *);
  void *__arg;
  int __canceltype;
  struct _pthread_cleanup_buffer *__prev;
};

/* clang-format off */

int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) dontthrow;
int pthread_attr_destroy(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_getdetachstate(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getguardsize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_getinheritsched(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getschedpolicy(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getscope(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getstack(const pthread_attr_t *, void **, size_t *) libcesque paramsnonnull();
int pthread_attr_getstacksize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_init(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_setdetachstate(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setguardsize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_attr_setinheritsched(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setschedpolicy(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setscope(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setstack(pthread_attr_t *, void *, size_t) libcesque paramsnonnull((1));
int pthread_attr_setstacksize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_barrier_destroy(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned) libcesque paramsnonnull((1));
int pthread_barrier_wait(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrierattr_destroy(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *) libcesque paramsnonnull();
int pthread_barrierattr_init(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int) libcesque paramsnonnull();
int pthread_cancel(pthread_t) libcesque;
int pthread_cond_broadcast(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_destroy(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *) libcesque paramsnonnull((1));
int pthread_cond_signal(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *) libcesque paramsnonnull();
int pthread_condattr_destroy(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_getpshared(const pthread_condattr_t *, int *) libcesque paramsnonnull();
int pthread_condattr_init(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_setpshared(pthread_condattr_t *, int) libcesque paramsnonnull();
int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *) dontthrow paramsnonnull((1));
int pthread_detach(pthread_t) libcesque;
int pthread_equal(pthread_t, pthread_t) libcesque;
int pthread_getattr_np(pthread_t, pthread_attr_t *) libcesque paramsnonnull();
int pthread_getname_np(pthread_t, char *, size_t) libcesque paramsnonnull();
int pthread_getunique_np(pthread_t, pthread_id_np_t *) libcesque paramsnonnull();
int pthread_join(pthread_t, void **) libcesque;
int pthread_key_create(pthread_key_t *, pthread_key_dtor) libcesque paramsnonnull((1));
int pthread_key_delete(pthread_key_t) libcesque;
int pthread_kill(pthread_t, int) libcesque;
int pthread_mutex_consistent(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_destroy(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *) libcesque paramsnonnull((1));
int pthread_mutex_lock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_trylock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_unlock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutexattr_destroy(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_init(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_mutexattr_settype(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_once(pthread_once_t *, void (*)(void)) paramsnonnull();
int pthread_orphan_np(void) libcesque;
int pthread_rwlock_destroy(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *) libcesque paramsnonnull((1));
int pthread_rwlock_rdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_tryrdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_trywrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_unlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_wrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, int *) libcesque paramsnonnull();
int pthread_rwlockattr_init(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int) libcesque paramsnonnull();
int pthread_setcancelstate(int, int *) libcesque;
int pthread_setcanceltype(int, int *) libcesque;
int pthread_setname_np(pthread_t, const char *) libcesque paramsnonnull();
int pthread_setschedprio(pthread_t, int) libcesque;
int pthread_setspecific(pthread_key_t, const void *) libcesque;
int pthread_spin_destroy(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_init(pthread_spinlock_t *, int) libcesque paramsnonnull();
int pthread_spin_lock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_trylock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_unlock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_testcancel_np(void) libcesque;
int pthread_tryjoin_np(pthread_t, void **) libcesque;
int pthread_yield_np(void) libcesque;
int pthread_yield(void) libcesque;
pthread_id_np_t pthread_getthreadid_np(void) libcesque;
pthread_t pthread_self(void) libcesque pureconst;
void *pthread_getspecific(pthread_key_t) libcesque;
void pthread_cleanup_pop(struct _pthread_cleanup_buffer *, int) libcesque paramsnonnull();
void pthread_cleanup_push(struct _pthread_cleanup_buffer *, void (*)(void *), void *) libcesque paramsnonnull((1));
void pthread_exit(void *) libcesque wontreturn;
void pthread_testcancel(void) libcesque;
void pthread_pause_np(void) libcesque;

/* clang-format on */

#define pthread_cleanup_push(routine, arg)  \
  {                                         \
    struct _pthread_cleanup_buffer _buffer; \
    pthread_cleanup_push(&_buffer, (routine), (arg));

#define pthread_cleanup_pop(execute)        \
  pthread_cleanup_pop(&_buffer, (execute)); \
  }

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/thread/thread2.h */

#define COSMOPOLITAN_LIBC_INTRIN_PTHREAD2_H_
COSMOPOLITAN_C_START_
/* clang-format off */

int pthread_attr_getschedparam(const pthread_attr_t *, struct sched_param *) libcesque paramsnonnull();
int pthread_attr_getsigmask_np(const pthread_attr_t *, sigset_t *) libcesque paramsnonnull((1));
int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *) libcesque paramsnonnull();
int pthread_attr_setsigmask_np(pthread_attr_t *, const sigset_t *) libcesque paramsnonnull((1));
int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *) libcesque paramsnonnull((1, 2));
int pthread_getaffinity_np(pthread_t, size_t, cpu_set_t *) libcesque paramsnonnull();
int pthread_getschedparam(pthread_t, int *, struct sched_param *) libcesque paramsnonnull();
int pthread_setaffinity_np(pthread_t, size_t, const cpu_set_t *) libcesque paramsnonnull();
int pthread_setschedparam(pthread_t, int, const struct sched_param *) libcesque paramsnonnull();
int pthread_timedjoin_np(pthread_t, void **, struct timespec *) libcesque;

/* clang-format off */
COSMOPOLITAN_C_END_
/* clang-format on */


/*!BEGIN libc/thread/threads.h */

#define COSMOPOLITAN_LIBC_THREAD_THREADS_H_
COSMOPOLITAN_C_START_

#if !defined(__cplusplus) &&                   \
    (!(defined(__GNUC__) && __GNUC__ >= 13) || \
     !(defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L))
#define thread_local _Thread_local
#endif

#define TSS_DTOR_ITERATIONS 4

enum {
  thrd_success = 0,
  thrd_busy = 1,
  thrd_error = 2,
  thrd_nomem = 3,
  thrd_timedout = 4,
};

enum {
  mtx_plain = 0,
  mtx_recursive = 1,
  mtx_timed = 2,
};

typedef uintptr_t thrd_t;
typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *);
typedef _Atomic(uint32_t) once_flag;

void call_once(once_flag *, void (*)(void));
int thrd_create(thrd_t *, thrd_start_t, void *);
void thrd_exit(int) wontreturn;
int thrd_join(thrd_t, int *);
int thrd_detach(thrd_t);
int thrd_equal(thrd_t, thrd_t);
thrd_t thrd_current(void);
void thrd_yield(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/tls.h */

#define COSMOPOLITAN_LIBC_THREAD_TLS_H_

#define TLS_ALIGNMENT 64

#define TIB_FLAG_VFORKED 1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct CosmoFtrace {   /* 16 */
  char ft_once;        /*  0 */
  char ft_noreentry;   /*  1 */
  int ft_skew;         /*  4 */
  int64_t ft_lastaddr; /*  8 */
};

/* NOTE: update aarch64 libc/errno.h if sizeof changes */
/* NOTE: update aarch64 libc/proc/vfork.S if sizeof changes */
/* NOTE: update aarch64 libc/nexgen32e/gc.S if sizeof changes */
struct CosmoTib {
  struct CosmoTib *tib_self;      /* 0x00 */
  struct CosmoFtrace tib_ftracer; /* 0x08 */
  void *tib_garbages;             /* 0x18 */
  intptr_t tib_locale;            /* 0x20 */
  intptr_t tib_pthread;           /* 0x28 */
  struct CosmoTib *tib_self2;     /* 0x30 */
  _Atomic(int32_t) tib_tid;       /* 0x38 transitions -1 → tid → 0 */
  int32_t tib_errno;              /* 0x3c */
  uint64_t tib_flags;             /* 0x40 */
  int tib_ftrace;                 /* inherited */
  int tib_strace;                 /* inherited */
  _Atomic(uint64_t) tib_sigmask;  /* inherited */
  _Atomic(uint64_t) tib_sigpending;
  _Atomic(uint64_t) tib_syshand; /* win32=kThread, xnusilicon=pthread_t */
  char *tib_sigstack_addr;
  uint32_t tib_sigstack_size;
  uint32_t tib_sigstack_flags;
  void **tib_keys;
  void *tib_nsync;
  void *tib_todo[7];
} __attribute__((__aligned__(64)));

extern int __threaded;
extern char __tls_morphed;
extern unsigned __tls_index;

char *_mktls(struct CosmoTib **) libcesque;
void __bootstrap_tls(struct CosmoTib *, char *) libcesque;

#ifdef __x86_64__
extern char __tls_enabled;
#define __tls_enabled_set(x) __tls_enabled = x
#elif defined(__aarch64__)
#define __tls_enabled        true
#define __tls_enabled_set(x) (void)0
#else
#error "unsupported architecture"
#endif

void __set_tls(struct CosmoTib *) libcesque;

/**
 * Returns location of thread information block.
 *
 * This can't be used in privileged functions.
 */
forceinline pureconst struct CosmoTib *__get_tls(void) {
#ifdef __chibicc__
  return 0;
#elif __x86_64__
  struct CosmoTib *__tib;
  __asm__("mov\t%%gs:0x30,%0" : "=r"(__tib));
  return __tib;
#elif defined(__aarch64__)
  register struct CosmoTib *__tls __asm__("x28");
  return __tls - 1;
#endif
}

#ifdef __x86_64__
#define __adj_tls(tib) (tib)
#elif defined(__aarch64__)
#define __adj_tls(tib) ((struct CosmoTib *)(tib) + 1)
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/tinymath/emod.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMOD_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmod()
 */
#define emod(x, y)                            \
  ({                                          \
    double __x = x;                           \
    double __y = y;                           \
    __x - fabs(__y) * floor(__x / fabs(__y)); \
  })



/*!BEGIN libc/tinymath/emodl.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmodl()
 */
#define emodl(x, y)                              \
  ({                                             \
    long double __x = x;                         \
    long double __y = y;                         \
    __x - fabsl(__y) * floorl(__x / fabsl(__y)); \
  })



/*!BEGIN libc/tinymath/magicu.h */

#define COSMOPOLITAN_LIBC_TINYMATH_MAGICU_H_
COSMOPOLITAN_C_START_

struct magicu {
  uint32_t M;
  uint32_t s;
};

struct magicu __magicu_get(uint32_t);

/**
 * Performs fast division using precomputed magic for constant divisor.
 *
 * @param x is unsigned integer that shall be divided
 * @param d should be `__magicu_get(y)` if computing `x / y`
 * @return result of unsigned integer division
 */
forceinline uint32_t __magicu_div(uint32_t x, struct magicu d) {
  return ((((uint64_t)x * d.M) >> 32) + ((d.s & 64) ? x : 0)) >> (d.s & 63);
}

/**
 * Checks if 𝑑 contains a valid initialized divisor.
 */
static inline bool32 __magicu_valid(struct magicu d) {
  if (!d.M && !d.s) return false;     /* uninitialized */
  if (d.s & ~(64 | 63)) return false; /* corrupted */
  return true;
}

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/x.h */

#ifndef COSMOPOLITAN_LIBC_X_H_
#define COSMOPOLITAN_LIBC_X_H_

#define xwrite        __xwrite
#define xdie          __xdie
#define xmalloc       __xmalloc
#define xrealloc      __xrealloc
#define xcalloc       __xcalloc
#define xvalloc       __xvalloc
#define xmemalign     __xmemalign
#define xmemalignzero __xmemalignzero
#define xstrdup       __xstrdup
#define xstrndup      __xstrndup
#define xstrmul       __xstrmul
#define xinet_ntop    __xinet_ntop
#define xunbinga      __xunbinga
#define xunbing       __xunbing
#define utf8to16      __utf8to16
#define utf16to8      __utf16to8
#define utf8to32      __utf8to32
#define utf16to32     __utf16to32
#define utf32to8      __utf32to8
#define xhomedir      __xhomedir
#define xstripext     __xstripext
#define xstripexts    __xstripexts
#define xload         __xload
#define rmrf          __rmrf
#define xbasename     __xbasename
#define xdirname      __xdirname
#define xjoinpaths    __xjoinpaths
#define xfixpath      __xfixpath
#define xslurp        __xslurp
#define xbarf         __xbarf

COSMOPOLITAN_C_START_

int xwrite(int, const void *, uint64_t);
void xdie(void) wontreturn;
char *xdtoa(double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoaf(float)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoal(long double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmalloc(size_t) attributeallocsize((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xrealloc(void *, size_t)
    attributeallocsize((2)) dontthrow dontcallback __wur;
void *xcalloc(size_t, size_t) attributeallocsize((1, 2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xvalloc(size_t) attributeallocsize((1)) returnsaligned((65536))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalign(size_t, size_t) attributeallocalign((1)) attributeallocsize((2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalignzero(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2))
        returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrdup(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrndup(const char *, size_t) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrcat(const char *, ...) paramsnonnull((1)) nullterminated()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
#define xstrcat(...) (xstrcat)(__VA_ARGS__, NULL)
char *xstrmul(const char *, size_t) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xinet_ntop(int, const void *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xunbinga(size_t, const char16_t *)
    attributeallocalign((1)) returnspointerwithnoaliases dontthrow dontcallback
    __wur returnsnonnull dontthrow dontcallback __wur returnsnonnull;
void *xunbing(const char16_t *)
    returnspointerwithnoaliases dontthrow dontcallback __wur
    returnsnonnull dontthrow dontcallback __wur returnsnonnull;
char16_t *utf8to16(const char *, size_t, size_t *) __wur;
char *utf16to8(const char16_t *, size_t, size_t *) __wur;
wchar_t *utf8to32(const char *, size_t, size_t *) __wur;
wchar_t *utf16to32(const char16_t *, size_t, size_t *) __wur;
char *utf32to8(const wchar_t *, size_t, size_t *) __wur;
char *xhomedir(void) __wur;
char *xstripext(const char *) __wur;
char *xstripexts(const char *) __wur;
void *xload(_Atomic(void *) *, const void *, size_t, size_t);
int rmrf(const char *);
char *xbasename(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdirname(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xjoinpaths(const char *, const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void xfixpath(void);
void *xslurp(const char *, size_t *)
    paramsnonnull((1)) returnspointerwithnoaliases returnsaligned((4096)) __wur;
int xbarf(const char *, const void *, size_t);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_X_H_ */


/*!BEGIN libc/x/xasprintf.h */

#define COSMOPOLITAN_LIBC_X_XASPRINTF_H_
COSMOPOLITAN_C_START_

char *xasprintf(const char *, ...) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xvasprintf(const char *, va_list) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xgetline.h */

#define COSMOPOLITAN_LIBC_X_XGETLINE_H_
COSMOPOLITAN_C_START_

char *xgetline(FILE *) paramsnonnull() mallocesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xsigaction.h */

#define COSMOPOLITAN_LIBC_X_XSIGACTION_H_
COSMOPOLITAN_C_START_

int xsigaction(int, void *, uint64_t, uint64_t, struct sigaction *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xspawn.h */

#define COSMOPOLITAN_LIBC_X_XSPAWN_H_
COSMOPOLITAN_C_START_

int xspawn(struct rusage *);
int xvspawn(void (*)(void *), void *, struct rusage *) returnstwice;

COSMOPOLITAN_C_END_


/*!BEGIN net/http/csscolor.h */

#define COSMOPOLITAN_NET_HTTP_CSSCOLOR_H_

#define ALICEBLUE            0xFFFFF8F0u
#define ANTIQUEWHITE         0xFFD7EBFAu
#define ANTIQUEWHITE1        0xFFDBEFFFu
#define ANTIQUEWHITE2        0xFFCCDFEEu
#define ANTIQUEWHITE3        0xFFB0C0CDu
#define ANTIQUEWHITE4        0xFF78838Bu
#define AQUAMARINE           0xFFD4FF7Fu
#define AQUAMARINE1          0xFFD4FF7Fu
#define AQUAMARINE2          0xFFC6EE76u
#define AQUAMARINE3          0xFFAACD66u
#define AQUAMARINE4          0xFF748B45u
#define AZURE                0xFFFFFFF0u
#define AZURE1               0xFFFFFFF0u
#define AZURE2               0xFFEEEEE0u
#define AZURE3               0xFFCDCDC1u
#define AZURE4               0xFF8B8B83u
#define BEIGE                0xFFDCF5F5u
#define BISQUE               0xFFC4E4FFu
#define BISQUE1              0xFFC4E4FFu
#define BISQUE2              0xFFB7D5EEu
#define BISQUE3              0xFF9EB7CDu
#define BISQUE4              0xFF6B7D8Bu
#define BLACK                0xFF000000u
#define BLANCHEDALMOND       0xFFCDEBFFu
#define BLUE                 0xFFFF0000u
#define BLUE1                0xFFFF0000u
#define BLUE2                0xFFEE0000u
#define BLUE3                0xFFCD0000u
#define BLUE4                0xFF8B0000u
#define BLUEVIOLET           0xFFE22B8Au
#define BROWN                0xFF2A2AA5u
#define BROWN1               0xFF4040FFu
#define BROWN2               0xFF3B3BEEu
#define BROWN3               0xFF3333CDu
#define BROWN4               0xFF23238Bu
#define BURLYWOOD            0xFF87B8DEu
#define BURLYWOOD1           0xFF9BD3FFu
#define BURLYWOOD2           0xFF91C5EEu
#define BURLYWOOD3           0xFF7DAACDu
#define BURLYWOOD4           0xFF55738Bu
#define CADETBLUE            0xFFA09E5Fu
#define CADETBLUE1           0xFFFFF598u
#define CADETBLUE2           0xFFEEE58Eu
#define CADETBLUE3           0xFFCDC57Au
#define CADETBLUE4           0xFF8B8653u
#define CHARTREUSE           0xFF00FF7Fu
#define CHARTREUSE1          0xFF00FF7Fu
#define CHARTREUSE2          0xFF00EE76u
#define CHARTREUSE3          0xFF00CD66u
#define CHARTREUSE4          0xFF008B45u
#define CHOCOLATE            0xFF1E69D2u
#define CHOCOLATE1           0xFF247FFFu
#define CHOCOLATE2           0xFF2176EEu
#define CHOCOLATE3           0xFF1D66CDu
#define CHOCOLATE4           0xFF13458Bu
#define CORAL                0xFF507FFFu
#define CORAL1               0xFF5672FFu
#define CORAL2               0xFF506AEEu
#define CORAL3               0xFF455BCDu
#define CORAL4               0xFF2F3E8Bu
#define CORNFLOWERBLUE       0xFFED9564u
#define CORNSILK             0xFFDCF8FFu
#define CORNSILK1            0xFFDCF8FFu
#define CORNSILK2            0xFFCDE8EEu
#define CORNSILK3            0xFFB1C8CDu
#define CORNSILK4            0xFF78888Bu
#define CYAN                 0xFFFFFF00u
#define CYAN1                0xFFFFFF00u
#define CYAN2                0xFFEEEE00u
#define CYAN3                0xFFCDCD00u
#define CYAN4                0xFF8B8B00u
#define DARKBLUE             0xFF8B0000u
#define DARKCYAN             0xFF8B8B00u
#define DARKGOLDENROD        0xFF0B86B8u
#define DARKGOLDENROD1       0xFF0FB9FFu
#define DARKGOLDENROD2       0xFF0EADEEu
#define DARKGOLDENROD3       0xFF0C95CDu
#define DARKGOLDENROD4       0xFF08658Bu
#define DARKGRAY             0xFFA9A9A9u
#define DARKGREEN            0xFF006400u
#define DARKGREY             0xFFA9A9A9u
#define DARKKHAKI            0xFF6BB7BDu
#define DARKMAGENTA          0xFF8B008Bu
#define DARKOLIVEGREEN       0xFF2F6B55u
#define DARKOLIVEGREEN1      0xFF70FFCAu
#define DARKOLIVEGREEN2      0xFF68EEBCu
#define DARKOLIVEGREEN3      0xFF5ACDA2u
#define DARKOLIVEGREEN4      0xFF3D8B6Eu
#define DARKORANGE           0xFF008CFFu
#define DARKORANGE1          0xFF007FFFu
#define DARKORANGE2          0xFF0076EEu
#define DARKORANGE3          0xFF0066CDu
#define DARKORANGE4          0xFF00458Bu
#define DARKORCHID           0xFFCC3299u
#define DARKORCHID1          0xFFFF3EBFu
#define DARKORCHID2          0xFFEE3AB2u
#define DARKORCHID3          0xFFCD329Au
#define DARKORCHID4          0xFF8B2268u
#define DARKRED              0xFF00008Bu
#define DARKSALMON           0xFF7A96E9u
#define DARKSEAGREEN         0xFF8FBC8Fu
#define DARKSEAGREEN1        0xFFC1FFC1u
#define DARKSEAGREEN2        0xFFB4EEB4u
#define DARKSEAGREEN3        0xFF9BCD9Bu
#define DARKSEAGREEN4        0xFF698B69u
#define DARKSLATEBLUE        0xFF8B3D48u
#define DARKSLATEGRAY        0xFF4F4F2Fu
#define DARKSLATEGRAY1       0xFFFFFF97u
#define DARKSLATEGRAY2       0xFFEEEE8Du
#define DARKSLATEGRAY3       0xFFCDCD79u
#define DARKSLATEGRAY4       0xFF8B8B52u
#define DARKSLATEGREY        0xFF4F4F2Fu
#define DARKTURQUOISE        0xFFD1CE00u
#define DARKVIOLET           0xFFD30094u
#define DEEPPINK             0xFF9314FFu
#define DEEPPINK1            0xFF9314FFu
#define DEEPPINK2            0xFF8912EEu
#define DEEPPINK3            0xFF7610CDu
#define DEEPPINK4            0xFF500A8Bu
#define DEEPSKYBLUE          0xFFFFBF00u
#define DEEPSKYBLUE1         0xFFFFBF00u
#define DEEPSKYBLUE2         0xFFEEB200u
#define DEEPSKYBLUE3         0xFFCD9A00u
#define DEEPSKYBLUE4         0xFF8B6800u
#define DIMGRAY              0xFF696969u
#define DIMGREY              0xFF696969u
#define DODGERBLUE           0xFFFF901Eu
#define DODGERBLUE1          0xFFFF901Eu
#define DODGERBLUE2          0xFFEE861Cu
#define DODGERBLUE3          0xFFCD7418u
#define DODGERBLUE4          0xFF8B4E10u
#define FIREBRICK            0xFF2222B2u
#define FIREBRICK1           0xFF3030FFu
#define FIREBRICK2           0xFF2C2CEEu
#define FIREBRICK3           0xFF2626CDu
#define FIREBRICK4           0xFF1A1A8Bu
#define FLORALWHITE          0xFFF0FAFFu
#define FORESTGREEN          0xFF228B22u
#define GAINSBORO            0xFFDCDCDCu
#define GHOSTWHITE           0xFFFFF8F8u
#define GOLD                 0xFF00D7FFu
#define GOLD1                0xFF00D7FFu
#define GOLD2                0xFF00C9EEu
#define GOLD3                0xFF00ADCDu
#define GOLD4                0xFF00758Bu
#define GOLDENROD            0xFF20A5DAu
#define GOLDENROD1           0xFF25C1FFu
#define GOLDENROD2           0xFF22B4EEu
#define GOLDENROD3           0xFF1D9BCDu
#define GOLDENROD4           0xFF14698Bu
#define GRAY                 0xFFBEBEBEu
#define GRAY0                0xFF000000u
#define GRAY1                0xFF030303u
#define GRAY10               0xFF1A1A1Au
#define GRAY100              0xFFFFFFFFu
#define GRAY11               0xFF1C1C1Cu
#define GRAY12               0xFF1F1F1Fu
#define GRAY13               0xFF212121u
#define GRAY14               0xFF242424u
#define GRAY15               0xFF262626u
#define GRAY16               0xFF292929u
#define GRAY17               0xFF2B2B2Bu
#define GRAY18               0xFF2E2E2Eu
#define GRAY19               0xFF303030u
#define GRAY2                0xFF050505u
#define GRAY20               0xFF333333u
#define GRAY21               0xFF363636u
#define GRAY22               0xFF383838u
#define GRAY23               0xFF3B3B3Bu
#define GRAY24               0xFF3D3D3Du
#define GRAY25               0xFF404040u
#define GRAY26               0xFF424242u
#define GRAY27               0xFF454545u
#define GRAY28               0xFF474747u
#define GRAY29               0xFF4A4A4Au
#define GRAY3                0xFF080808u
#define GRAY30               0xFF4D4D4Du
#define GRAY31               0xFF4F4F4Fu
#define GRAY32               0xFF525252u
#define GRAY33               0xFF545454u
#define GRAY34               0xFF575757u
#define GRAY35               0xFF595959u
#define GRAY36               0xFF5C5C5Cu
#define GRAY37               0xFF5E5E5Eu
#define GRAY38               0xFF616161u
#define GRAY39               0xFF636363u
#define GRAY4                0xFF0A0A0Au
#define GRAY40               0xFF666666u
#define GRAY41               0xFF696969u
#define GRAY42               0xFF6B6B6Bu
#define GRAY43               0xFF6E6E6Eu
#define GRAY44               0xFF707070u
#define GRAY45               0xFF737373u
#define GRAY46               0xFF757575u
#define GRAY47               0xFF787878u
#define GRAY48               0xFF7A7A7Au
#define GRAY49               0xFF7D7D7Du
#define GRAY5                0xFF0D0D0Du
#define GRAY50               0xFF7F7F7Fu
#define GRAY51               0xFF828282u
#define GRAY52               0xFF858585u
#define GRAY53               0xFF878787u
#define GRAY54               0xFF8A8A8Au
#define GRAY55               0xFF8C8C8Cu
#define GRAY56               0xFF8F8F8Fu
#define GRAY57               0xFF919191u
#define GRAY58               0xFF949494u
#define GRAY59               0xFF969696u
#define GRAY6                0xFF0F0F0Fu
#define GRAY60               0xFF999999u
#define GRAY61               0xFF9C9C9Cu
#define GRAY62               0xFF9E9E9Eu
#define GRAY63               0xFFA1A1A1u
#define GRAY64               0xFFA3A3A3u
#define GRAY65               0xFFA6A6A6u
#define GRAY66               0xFFA8A8A8u
#define GRAY67               0xFFABABABu
#define GRAY68               0xFFADADADu
#define GRAY69               0xFFB0B0B0u
#define GRAY7                0xFF121212u
#define GRAY70               0xFFB3B3B3u
#define GRAY71               0xFFB5B5B5u
#define GRAY72               0xFFB8B8B8u
#define GRAY73               0xFFBABABAu
#define GRAY74               0xFFBDBDBDu
#define GRAY75               0xFFBFBFBFu
#define GRAY76               0xFFC2C2C2u
#define GRAY77               0xFFC4C4C4u
#define GRAY78               0xFFC7C7C7u
#define GRAY79               0xFFC9C9C9u
#define GRAY8                0xFF141414u
#define GRAY80               0xFFCCCCCCu
#define GRAY81               0xFFCFCFCFu
#define GRAY82               0xFFD1D1D1u
#define GRAY83               0xFFD4D4D4u
#define GRAY84               0xFFD6D6D6u
#define GRAY85               0xFFD9D9D9u
#define GRAY86               0xFFDBDBDBu
#define GRAY87               0xFFDEDEDEu
#define GRAY88               0xFFE0E0E0u
#define GRAY89               0xFFE3E3E3u
#define GRAY9                0xFF171717u
#define GRAY90               0xFFE5E5E5u
#define GRAY91               0xFFE8E8E8u
#define GRAY92               0xFFEBEBEBu
#define GRAY93               0xFFEDEDEDu
#define GRAY94               0xFFF0F0F0u
#define GRAY95               0xFFF2F2F2u
#define GRAY96               0xFFF5F5F5u
#define GRAY97               0xFFF7F7F7u
#define GRAY98               0xFFFAFAFAu
#define GRAY99               0xFFFCFCFCu
#define GREEN                0xFF00FF00u
#define GREEN1               0xFF00FF00u
#define GREEN2               0xFF00EE00u
#define GREEN3               0xFF00CD00u
#define GREEN4               0xFF008B00u
#define GREENYELLOW          0xFF2FFFADu
#define GREY                 0xFFBEBEBEu
#define GREY0                0xFF000000u
#define GREY1                0xFF030303u
#define GREY10               0xFF1A1A1Au
#define GREY100              0xFFFFFFFFu
#define GREY11               0xFF1C1C1Cu
#define GREY12               0xFF1F1F1Fu
#define GREY13               0xFF212121u
#define GREY14               0xFF242424u
#define GREY15               0xFF262626u
#define GREY16               0xFF292929u
#define GREY17               0xFF2B2B2Bu
#define GREY18               0xFF2E2E2Eu
#define GREY19               0xFF303030u
#define GREY2                0xFF050505u
#define GREY20               0xFF333333u
#define GREY21               0xFF363636u
#define GREY22               0xFF383838u
#define GREY23               0xFF3B3B3Bu
#define GREY24               0xFF3D3D3Du
#define GREY25               0xFF404040u
#define GREY26               0xFF424242u
#define GREY27               0xFF454545u
#define GREY28               0xFF474747u
#define GREY29               0xFF4A4A4Au
#define GREY3                0xFF080808u
#define GREY30               0xFF4D4D4Du
#define GREY31               0xFF4F4F4Fu
#define GREY32               0xFF525252u
#define GREY33               0xFF545454u
#define GREY34               0xFF575757u
#define GREY35               0xFF595959u
#define GREY36               0xFF5C5C5Cu
#define GREY37               0xFF5E5E5Eu
#define GREY38               0xFF616161u
#define GREY39               0xFF636363u
#define GREY4                0xFF0A0A0Au
#define GREY40               0xFF666666u
#define GREY41               0xFF696969u
#define GREY42               0xFF6B6B6Bu
#define GREY43               0xFF6E6E6Eu
#define GREY44               0xFF707070u
#define GREY45               0xFF737373u
#define GREY46               0xFF757575u
#define GREY47               0xFF787878u
#define GREY48               0xFF7A7A7Au
#define GREY49               0xFF7D7D7Du
#define GREY5                0xFF0D0D0Du
#define GREY50               0xFF7F7F7Fu
#define GREY51               0xFF828282u
#define GREY52               0xFF858585u
#define GREY53               0xFF878787u
#define GREY54               0xFF8A8A8Au
#define GREY55               0xFF8C8C8Cu
#define GREY56               0xFF8F8F8Fu
#define GREY57               0xFF919191u
#define GREY58               0xFF949494u
#define GREY59               0xFF969696u
#define GREY6                0xFF0F0F0Fu
#define GREY60               0xFF999999u
#define GREY61               0xFF9C9C9Cu
#define GREY62               0xFF9E9E9Eu
#define GREY63               0xFFA1A1A1u
#define GREY64               0xFFA3A3A3u
#define GREY65               0xFFA6A6A6u
#define GREY66               0xFFA8A8A8u
#define GREY67               0xFFABABABu
#define GREY68               0xFFADADADu
#define GREY69               0xFFB0B0B0u
#define GREY7                0xFF121212u
#define GREY70               0xFFB3B3B3u
#define GREY71               0xFFB5B5B5u
#define GREY72               0xFFB8B8B8u
#define GREY73               0xFFBABABAu
#define GREY74               0xFFBDBDBDu
#define GREY75               0xFFBFBFBFu
#define GREY76               0xFFC2C2C2u
#define GREY77               0xFFC4C4C4u
#define GREY78               0xFFC7C7C7u
#define GREY79               0xFFC9C9C9u
#define GREY8                0xFF141414u
#define GREY80               0xFFCCCCCCu
#define GREY81               0xFFCFCFCFu
#define GREY82               0xFFD1D1D1u
#define GREY83               0xFFD4D4D4u
#define GREY84               0xFFD6D6D6u
#define GREY85               0xFFD9D9D9u
#define GREY86               0xFFDBDBDBu
#define GREY87               0xFFDEDEDEu
#define GREY88               0xFFE0E0E0u
#define GREY89               0xFFE3E3E3u
#define GREY9                0xFF171717u
#define GREY90               0xFFE5E5E5u
#define GREY91               0xFFE8E8E8u
#define GREY92               0xFFEBEBEBu
#define GREY93               0xFFEDEDEDu
#define GREY94               0xFFF0F0F0u
#define GREY95               0xFFF2F2F2u
#define GREY96               0xFFF5F5F5u
#define GREY97               0xFFF7F7F7u
#define GREY98               0xFFFAFAFAu
#define GREY99               0xFFFCFCFCu
#define HONEYDEW             0xFFF0FFF0u
#define HONEYDEW1            0xFFF0FFF0u
#define HONEYDEW2            0xFFE0EEE0u
#define HONEYDEW3            0xFFC1CDC1u
#define HONEYDEW4            0xFF838B83u
#define HOTPINK              0xFFB469FFu
#define HOTPINK1             0xFFB46EFFu
#define HOTPINK2             0xFFA76AEEu
#define HOTPINK3             0xFF9060CDu
#define HOTPINK4             0xFF623A8Bu
#define INDIANRED            0xFF5C5CCDu
#define INDIANRED1           0xFF6A6AFFu
#define INDIANRED2           0xFF6363EEu
#define INDIANRED3           0xFF5555CDu
#define INDIANRED4           0xFF3A3A8Bu
#define IVORY                0xFFF0FFFFu
#define IVORY1               0xFFF0FFFFu
#define IVORY2               0xFFE0EEEEu
#define IVORY3               0xFFC1CDCDu
#define IVORY4               0xFF838B8Bu
#define KHAKI                0xFF8CE6F0u
#define KHAKI1               0xFF8FF6FFu
#define KHAKI2               0xFF85E6EEu
#define KHAKI3               0xFF73C6CDu
#define KHAKI4               0xFF4E868Bu
#define LAVENDER             0xFFFAE6E6u
#define LAVENDERBLUSH        0xFFF5F0FFu
#define LAVENDERBLUSH1       0xFFF5F0FFu
#define LAVENDERBLUSH2       0xFFE5E0EEu
#define LAVENDERBLUSH3       0xFFC5C1CDu
#define LAVENDERBLUSH4       0xFF86838Bu
#define LAWNGREEN            0xFF00FC7Cu
#define LEMONCHIFFON         0xFFCDFAFFu
#define LEMONCHIFFON1        0xFFCDFAFFu
#define LEMONCHIFFON2        0xFFBFE9EEu
#define LEMONCHIFFON3        0xFFA5C9CDu
#define LEMONCHIFFON4        0xFF70898Bu
#define LIGHTBLUE            0xFFE6D8ADu
#define LIGHTBLUE1           0xFFFFEFBFu
#define LIGHTBLUE2           0xFFEEDFB2u
#define LIGHTBLUE3           0xFFCDC09Au
#define LIGHTBLUE4           0xFF8B8368u
#define LIGHTCORAL           0xFF8080F0u
#define LIGHTCYAN            0xFFFFFFE0u
#define LIGHTCYAN1           0xFFFFFFE0u
#define LIGHTCYAN2           0xFFEEEED1u
#define LIGHTCYAN3           0xFFCDCDB4u
#define LIGHTCYAN4           0xFF8B8B7Au
#define LIGHTGOLDENROD       0xFF82DDEEu
#define LIGHTGOLDENROD1      0xFF8BECFFu
#define LIGHTGOLDENROD2      0xFF82DCEEu
#define LIGHTGOLDENROD3      0xFF70BECDu
#define LIGHTGOLDENROD4      0xFF4C818Bu
#define LIGHTGOLDENRODYELLOW 0xFFD2FAFAu
#define LIGHTGRAY            0xFFD3D3D3u
#define LIGHTGREEN           0xFF90EE90u
#define LIGHTGREY            0xFFD3D3D3u
#define LIGHTPINK            0xFFC1B6FFu
#define LIGHTPINK1           0xFFB9AEFFu
#define LIGHTPINK2           0xFFADA2EEu
#define LIGHTPINK3           0xFF958CCDu
#define LIGHTPINK4           0xFF655F8Bu
#define LIGHTSALMON          0xFF7AA0FFu
#define LIGHTSALMON1         0xFF7AA0FFu
#define LIGHTSALMON2         0xFF7295EEu
#define LIGHTSALMON3         0xFF6281CDu
#define LIGHTSALMON4         0xFF42578Bu
#define LIGHTSEAGREEN        0xFFAAB220u
#define LIGHTSKYBLUE         0xFFFACE87u
#define LIGHTSKYBLUE1        0xFFFFE2B0u
#define LIGHTSKYBLUE2        0xFFEED3A4u
#define LIGHTSKYBLUE3        0xFFCDB68Du
#define LIGHTSKYBLUE4        0xFF8B7B60u
#define LIGHTSLATEBLUE       0xFFFF7084u
#define LIGHTSLATEGRAY       0xFF998877u
#define LIGHTSLATEGREY       0xFF998877u
#define LIGHTSTEELBLUE       0xFFDEC4B0u
#define LIGHTSTEELBLUE1      0xFFFFE1CAu
#define LIGHTSTEELBLUE2      0xFFEED2BCu
#define LIGHTSTEELBLUE3      0xFFCDB5A2u
#define LIGHTSTEELBLUE4      0xFF8B7B6Eu
#define LIGHTYELLOW          0xFFE0FFFFu
#define LIGHTYELLOW1         0xFFE0FFFFu
#define LIGHTYELLOW2         0xFFD1EEEEu
#define LIGHTYELLOW3         0xFFB4CDCDu
#define LIGHTYELLOW4         0xFF7A8B8Bu
#define LIMEGREEN            0xFF32CD32u
#define LINEN                0xFFE6F0FAu
#define MAGENTA              0xFFFF00FFu
#define MAGENTA1             0xFFFF00FFu
#define MAGENTA2             0xFFEE00EEu
#define MAGENTA3             0xFFCD00CDu
#define MAGENTA4             0xFF8B008Bu
#define MAROON               0xFF6030B0u
#define MAROON1              0xFFB334FFu
#define MAROON2              0xFFA730EEu
#define MAROON3              0xFF9029CDu
#define MAROON4              0xFF621C8Bu
#define MEDIUMAQUAMARINE     0xFFAACD66u
#define MEDIUMBLUE           0xFFCD0000u
#define MEDIUMORCHID         0xFFD355BAu
#define MEDIUMORCHID1        0xFFFF66E0u
#define MEDIUMORCHID2        0xFFEE5FD1u
#define MEDIUMORCHID3        0xFFCD52B4u
#define MEDIUMORCHID4        0xFF8B377Au
#define MEDIUMPURPLE         0xFFDB7093u
#define MEDIUMPURPLE1        0xFFFF82ABu
#define MEDIUMPURPLE2        0xFFEE799Fu
#define MEDIUMPURPLE3        0xFFCD6889u
#define MEDIUMPURPLE4        0xFF8B475Du
#define MEDIUMSEAGREEN       0xFF71B33Cu
#define MEDIUMSLATEBLUE      0xFFEE687Bu
#define MEDIUMSPRINGGREEN    0xFF9AFA00u
#define MEDIUMTURQUOISE      0xFFCCD148u
#define MEDIUMVIOLETRED      0xFF8515C7u
#define MIDNIGHTBLUE         0xFF701919u
#define MINTCREAM            0xFFFAFFF5u
#define MISTYROSE            0xFFE1E4FFu
#define MISTYROSE1           0xFFE1E4FFu
#define MISTYROSE2           0xFFD2D5EEu
#define MISTYROSE3           0xFFB5B7CDu
#define MISTYROSE4           0xFF7B7D8Bu
#define MOCCASIN             0xFFB5E4FFu
#define NAVAJOWHITE          0xFFADDEFFu
#define NAVAJOWHITE1         0xFFADDEFFu
#define NAVAJOWHITE2         0xFFA1CFEEu
#define NAVAJOWHITE3         0xFF8BB3CDu
#define NAVAJOWHITE4         0xFF5E798Bu
#define NAVY                 0xFF800000u
#define NAVYBLUE             0xFF800000u
#define OLDLACE              0xFFE6F5FDu
#define OLIVEDRAB            0xFF238E6Bu
#define OLIVEDRAB1           0xFF3EFFC0u
#define OLIVEDRAB2           0xFF3AEEB3u
#define OLIVEDRAB3           0xFF32CD9Au
#define OLIVEDRAB4           0xFF228B69u
#define ORANGE               0xFF00A5FFu
#define ORANGE1              0xFF00A5FFu
#define ORANGE2              0xFF009AEEu
#define ORANGE3              0xFF0085CDu
#define ORANGE4              0xFF005A8Bu
#define ORANGERED            0xFF0045FFu
#define ORANGERED1           0xFF0045FFu
#define ORANGERED2           0xFF0040EEu
#define ORANGERED3           0xFF0037CDu
#define ORANGERED4           0xFF00258Bu
#define ORCHID               0xFFD670DAu
#define ORCHID1              0xFFFA83FFu
#define ORCHID2              0xFFE97AEEu
#define ORCHID3              0xFFC969CDu
#define ORCHID4              0xFF89478Bu
#define PALEGOLDENROD        0xFFAAE8EEu
#define PALEGREEN            0xFF98FB98u
#define PALEGREEN1           0xFF9AFF9Au
#define PALEGREEN2           0xFF90EE90u
#define PALEGREEN3           0xFF7CCD7Cu
#define PALEGREEN4           0xFF548B54u
#define PALETURQUOISE        0xFFEEEEAFu
#define PALETURQUOISE1       0xFFFFFFBBu
#define PALETURQUOISE2       0xFFEEEEAEu
#define PALETURQUOISE3       0xFFCDCD96u
#define PALETURQUOISE4       0xFF8B8B66u
#define PALEVIOLETRED        0xFF9370DBu
#define PALEVIOLETRED1       0xFFAB82FFu
#define PALEVIOLETRED2       0xFF9F79EEu
#define PALEVIOLETRED3       0xFF8968CDu
#define PALEVIOLETRED4       0xFF5D478Bu
#define PAPAYAWHIP           0xFFD5EFFFu
#define PEACHPUFF            0xFFB9DAFFu
#define PEACHPUFF1           0xFFB9DAFFu
#define PEACHPUFF2           0xFFADCBEEu
#define PEACHPUFF3           0xFF95AFCDu
#define PEACHPUFF4           0xFF65778Bu
#define PERU                 0xFF3F85CDu
#define PINK                 0xFFCBC0FFu
#define PINK1                0xFFC5B5FFu
#define PINK2                0xFFB8A9EEu
#define PINK3                0xFF9E91CDu
#define PINK4                0xFF6C638Bu
#define PLUM                 0xFFDDA0DDu
#define PLUM1                0xFFFFBBFFu
#define PLUM2                0xFFEEAEEEu
#define PLUM3                0xFFCD96CDu
#define PLUM4                0xFF8B668Bu
#define POWDERBLUE           0xFFE6E0B0u
#define PURPLE               0xFFF020A0u
#define PURPLE1              0xFFFF309Bu
#define PURPLE2              0xFFEE2C91u
#define PURPLE3              0xFFCD267Du
#define PURPLE4              0xFF8B1A55u
#define RED                  0xFF0000FFu
#define RED1                 0xFF0000FFu
#define RED2                 0xFF0000EEu
#define RED3                 0xFF0000CDu
#define RED4                 0xFF00008Bu
#define ROSYBROWN            0xFF8F8FBCu
#define ROSYBROWN1           0xFFC1C1FFu
#define ROSYBROWN2           0xFFB4B4EEu
#define ROSYBROWN3           0xFF9B9BCDu
#define ROSYBROWN4           0xFF69698Bu
#define ROYALBLUE            0xFFE16941u
#define ROYALBLUE1           0xFFFF7648u
#define ROYALBLUE2           0xFFEE6E43u
#define ROYALBLUE3           0xFFCD5F3Au
#define ROYALBLUE4           0xFF8B4027u
#define SADDLEBROWN          0xFF13458Bu
#define SALMON               0xFF7280FAu
#define SALMON1              0xFF698CFFu
#define SALMON2              0xFF6282EEu
#define SALMON3              0xFF5470CDu
#define SALMON4              0xFF394C8Bu
#define SANDYBROWN           0xFF60A4F4u
#define SEAGREEN             0xFF578B2Eu
#define SEAGREEN1            0xFF9FFF54u
#define SEAGREEN2            0xFF94EE4Eu
#define SEAGREEN3            0xFF80CD43u
#define SEAGREEN4            0xFF578B2Eu
#define SEASHELL             0xFFEEF5FFu
#define SEASHELL1            0xFFEEF5FFu
#define SEASHELL2            0xFFDEE5EEu
#define SEASHELL3            0xFFBFC5CDu
#define SEASHELL4            0xFF82868Bu
#define SIENNA               0xFF2D52A0u
#define SIENNA1              0xFF4782FFu
#define SIENNA2              0xFF4279EEu
#define SIENNA3              0xFF3968CDu
#define SIENNA4              0xFF26478Bu
#define SKYBLUE              0xFFEBCE87u
#define SKYBLUE1             0xFFFFCE87u
#define SKYBLUE2             0xFFEEC07Eu
#define SKYBLUE3             0xFFCDA66Cu
#define SKYBLUE4             0xFF8B704Au
#define SLATEBLUE            0xFFCD5A6Au
#define SLATEBLUE1           0xFFFF6F83u
#define SLATEBLUE2           0xFFEE677Au
#define SLATEBLUE3           0xFFCD5969u
#define SLATEBLUE4           0xFF8B3C47u
#define SLATEGRAY            0xFF908070u
#define SLATEGRAY1           0xFFFFE2C6u
#define SLATEGRAY2           0xFFEED3B9u
#define SLATEGRAY3           0xFFCDB69Fu
#define SLATEGRAY4           0xFF8B7B6Cu
#define SLATEGREY            0xFF908070u
#define SNOW                 0xFFFAFAFFu
#define SNOW1                0xFFFAFAFFu
#define SNOW2                0xFFE9E9EEu
#define SNOW3                0xFFC9C9CDu
#define SNOW4                0xFF89898Bu
#define SPRINGGREEN          0xFF7FFF00u
#define SPRINGGREEN1         0xFF7FFF00u
#define SPRINGGREEN2         0xFF76EE00u
#define SPRINGGREEN3         0xFF66CD00u
#define SPRINGGREEN4         0xFF458B00u
#define STEELBLUE            0xFFB48246u
#define STEELBLUE1           0xFFFFB863u
#define STEELBLUE2           0xFFEEAC5Cu
#define STEELBLUE3           0xFFCD944Fu
#define STEELBLUE4           0xFF8B6436u
#define TAN                  0xFF8CB4D2u
#define TAN1                 0xFF4FA5FFu
#define TAN2                 0xFF499AEEu
#define TAN3                 0xFF3F85CDu
#define TAN4                 0xFF2B5A8Bu
#define THISTLE              0xFFD8BFD8u
#define THISTLE1             0xFFFFE1FFu
#define THISTLE2             0xFFEED2EEu
#define THISTLE3             0xFFCDB5CDu
#define THISTLE4             0xFF8B7B8Bu
#define TOMATO               0xFF4763FFu
#define TOMATO1              0xFF4763FFu
#define TOMATO2              0xFF425CEEu
#define TOMATO3              0xFF394FCDu
#define TOMATO4              0xFF26368Bu
#define TURQUOISE            0xFFD0E040u
#define TURQUOISE1           0xFFFFF500u
#define TURQUOISE2           0xFFEEE500u
#define TURQUOISE3           0xFFCDC500u
#define TURQUOISE4           0xFF8B8600u
#define VIOLET               0xFFEE82EEu
#define VIOLETRED            0xFF9020D0u
#define VIOLETRED1           0xFF963EFFu
#define VIOLETRED2           0xFF8C3AEEu
#define VIOLETRED3           0xFF7832CDu
#define VIOLETRED4           0xFF52228Bu
#define WHEAT                0xFFB3DEF5u
#define WHEAT1               0xFFBAE7FFu
#define WHEAT2               0xFFAED8EEu
#define WHEAT3               0xFF96BACDu
#define WHEAT4               0xFF667E8Bu
#define WHITE                0xFFFFFFFFu
#define WHITESMOKE           0xFFF5F5F5u
#define YELLOW               0xFF00FFFFu
#define YELLOW1              0xFF00FFFFu
#define YELLOW2              0xFF00EEEEu
#define YELLOW3              0xFF00CDCDu
#define YELLOW4              0xFF008B8Bu
#define YELLOWGREEN          0xFF32CD9Au



/*!BEGIN net/http/escape.h */

#define COSMOPOLITAN_NET_HTTP_ESCAPE_H_

#define kControlWs 1
#define kControlC0 2
#define kControlC1 4

COSMOPOLITAN_C_START_

extern const char kEscapeAuthority[256];
extern const char kEscapeIp[256];
extern const char kEscapePath[256];
extern const char kEscapeSegment[256];
extern const char kEscapeParam[256];
extern const char kEscapeFragment[256];

char *EscapeHtml(const char *, size_t, size_t *);
char *EscapeUrl(const char *, size_t, size_t *, const char[256]);
char *EscapeUser(const char *, size_t, size_t *);
char *EscapePass(const char *, size_t, size_t *);
char *EscapeIp(const char *, size_t, size_t *);
char *EscapeHost(const char *, size_t, size_t *);
char *EscapePath(const char *, size_t, size_t *);
char *EscapeParam(const char *, size_t, size_t *);
char *EscapeFragment(const char *, size_t, size_t *);
char *EscapeSegment(const char *, size_t, size_t *);
char *EscapeJsStringLiteral(char **, size_t *, const char *, size_t, size_t *);

ssize_t HasControlCodes(const char *, size_t, int);
char *Underlong(const char *, size_t, size_t *);
char *DecodeLatin1(const char *, size_t, size_t *);
char *EncodeLatin1(const char *, size_t, size_t *, int);
char *EncodeHttpHeaderValue(const char *, size_t, size_t *);
char *VisualizeControlCodes(const char *, size_t, size_t *);
char *IndentLines(const char *, size_t, size_t *, size_t);
char *EncodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *DecodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *EncodeBase64(const char *, size_t, size_t *);
char *DecodeBase64(const char *, size_t, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/http.h */

#define COSMOPOLITAN_LIBC_HTTP_HTTP_H_

#define kHttpRequest  0
#define kHttpResponse 1

#define kHttpGet     READ32LE("GET")
#define kHttpHead    READ32LE("HEAD")
#define kHttpPost    READ32LE("POST")
#define kHttpPut     READ32LE("PUT")
#define kHttpDelete  READ64LE("DELETE\0")
#define kHttpOptions READ64LE("OPTIONS")
#define kHttpConnect READ64LE("CONNECT")
#define kHttpTrace   READ64LE("TRACE\0\0")

#define kHttpStateStart   0
#define kHttpStateMethod  1
#define kHttpStateUri     2
#define kHttpStateVersion 3
#define kHttpStateStatus  4
#define kHttpStateMessage 5
#define kHttpStateName    6
#define kHttpStateColon   7
#define kHttpStateValue   8
#define kHttpStateCr      9
#define kHttpStateLf1     10
#define kHttpStateLf2     11

#define kHttpClientStateHeaders      0
#define kHttpClientStateBody         1
#define kHttpClientStateBodyChunked  2
#define kHttpClientStateBodyLengthed 3

#define kHttpStateChunkStart   0
#define kHttpStateChunkSize    1
#define kHttpStateChunkExt     2
#define kHttpStateChunkLf1     3
#define kHttpStateChunk        4
#define kHttpStateChunkCr2     5
#define kHttpStateChunkLf2     6
#define kHttpStateTrailerStart 7
#define kHttpStateTrailer      8
#define kHttpStateTrailerLf1   9
#define kHttpStateTrailerLf2   10

#define kHttpHost                          0
#define kHttpCacheControl                  1
#define kHttpConnection                    2
#define kHttpAccept                        3
#define kHttpAcceptLanguage                4
#define kHttpAcceptEncoding                5
#define kHttpUserAgent                     6
#define kHttpReferer                       7
#define kHttpXForwardedFor                 8
#define kHttpOrigin                        9
#define kHttpUpgradeInsecureRequests       10
#define kHttpPragma                        11
#define kHttpCookie                        12
#define kHttpDnt                           13
#define kHttpSecGpc                        14
#define kHttpFrom                          15
#define kHttpIfModifiedSince               16
#define kHttpXRequestedWith                17
#define kHttpXForwardedHost                18
#define kHttpXForwardedProto               19
#define kHttpXCsrfToken                    20
#define kHttpSaveData                      21
#define kHttpRange                         22
#define kHttpContentLength                 23
#define kHttpContentType                   24
#define kHttpVary                          25
#define kHttpDate                          26
#define kHttpServer                        27
#define kHttpExpires                       28
#define kHttpContentEncoding               29
#define kHttpLastModified                  30
#define kHttpEtag                          31
#define kHttpAllow                         32
#define kHttpContentRange                  33
#define kHttpAcceptCharset                 34
#define kHttpAccessControlAllowCredentials 35
#define kHttpAccessControlAllowHeaders     36
#define kHttpAccessControlAllowMethods     37
#define kHttpAccessControlAllowOrigin      38
#define kHttpAccessControlMaxAge           39
#define kHttpAccessControlMethod           40
#define kHttpAccessControlRequestHeaders   41
#define kHttpAccessControlRequestMethod    42
#define kHttpAccessControlRequestMethods   43
#define kHttpAge                           44
#define kHttpAuthorization                 45
#define kHttpContentBase                   46
#define kHttpContentDescription            47
#define kHttpContentDisposition            48
#define kHttpContentLanguage               49
#define kHttpContentLocation               50
#define kHttpContentMd5                    51
#define kHttpExpect                        52
#define kHttpIfMatch                       53
#define kHttpIfNoneMatch                   54
#define kHttpIfRange                       55
#define kHttpIfUnmodifiedSince             56
#define kHttpKeepAlive                     57
#define kHttpLink                          58
#define kHttpLocation                      59
#define kHttpMaxForwards                   60
#define kHttpProxyAuthenticate             61
#define kHttpProxyAuthorization            62
#define kHttpProxyConnection               63
#define kHttpPublic                        64
#define kHttpRetryAfter                    65
#define kHttpTe                            66
#define kHttpTrailer                       67
#define kHttpTransferEncoding              68
#define kHttpUpgrade                       69
#define kHttpWarning                       70
#define kHttpWwwAuthenticate               71
#define kHttpVia                           72
#define kHttpStrictTransportSecurity       73
#define kHttpXFrameOptions                 74
#define kHttpXContentTypeOptions           75
#define kHttpAltSvc                        76
#define kHttpReferrerPolicy                77
#define kHttpXXssProtection                78
#define kHttpAcceptRanges                  79
#define kHttpSetCookie                     80
#define kHttpSecChUa                       81
#define kHttpSecChUaMobile                 82
#define kHttpSecFetchSite                  83
#define kHttpSecFetchMode                  84
#define kHttpSecFetchUser                  85
#define kHttpSecFetchDest                  86
#define kHttpCfRay                         87
#define kHttpCfVisitor                     88
#define kHttpCfConnectingIp                89
#define kHttpCfIpcountry                   90
#define kHttpSecChUaPlatform               91
#define kHttpCdnLoop                       92
#define kHttpHeadersMax                    93

COSMOPOLITAN_C_START_

struct HttpSlice {
  short a, b;
};

struct HttpHeader {
  struct HttpSlice k;
  struct HttpSlice v;
};

struct HttpHeaders {
  unsigned n, c;
  struct HttpHeader *p;
};

struct HttpMessage {
  int i, a, status;
  unsigned char t;
  unsigned char type;
  unsigned char version;
  uint64_t method;
  struct HttpSlice k;
  struct HttpSlice uri;
  struct HttpSlice scratch;
  struct HttpSlice message;
  struct HttpSlice headers[kHttpHeadersMax];
  struct HttpHeaders xheaders;
};

struct HttpUnchunker {
  int t;
  size_t i;
  size_t j;
  ssize_t m;
};

extern const char kHttpToken[256];
extern const bool kHttpRepeatable[kHttpHeadersMax];

const char *GetHttpReason(int);
const char *GetHttpHeaderName(int);
int GetHttpHeader(const char *, size_t);
void InitHttpMessage(struct HttpMessage *, int);
void DestroyHttpMessage(struct HttpMessage *);
int ParseHttpMessage(struct HttpMessage *, const char *, size_t);
bool HeaderHas(struct HttpMessage *, const char *, int, const char *, size_t);
int64_t ParseContentLength(const char *, size_t);
char *FormatHttpDateTime(char[hasatleast 30], struct tm *);
bool ParseHttpRange(const char *, size_t, long, long *, long *);
int64_t ParseHttpDateTime(const char *, size_t);
uint64_t ParseHttpMethod(const char *, size_t);
bool IsValidHttpToken(const char *, size_t);
bool IsValidCookieValue(const char *, size_t);
bool IsAcceptablePath(const char *, size_t);
bool IsAcceptableHost(const char *, size_t);
bool IsAcceptablePort(const char *, size_t);
bool IsReasonablePath(const char *, size_t);
int ParseForwarded(const char *, size_t, uint32_t *, uint16_t *);
bool IsMimeType(const char *, size_t, const char *);
ssize_t Unchunk(struct HttpUnchunker *, char *, size_t, size_t *);
const char *FindContentType(const char *, size_t);
bool IsNoCompressExt(const char *, size_t);
char *FoldHeader(struct HttpMessage *, const char *, int, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/ip.h */

#define COSMOPOLITAN_NET_HTTP_IP_H_

#define kIpUnknown    0
#define kIpMulticast  1
#define kIpLoopback   2
#define kIpPrivate    3
#define kIpTestnet    4
#define kIpAfrinic    5
#define kIpLacnic     6
#define kIpApnic      7
#define kIpArin       8
#define kIpRipe       9
#define kIpDod        10
#define kIpAtt        11
#define kIpApple      12
#define kIpFord       13
#define kIpCogent     14
#define kIpPrudential 15
#define kIpUsps       16
#define kIpComcast    17
#define kIpFuture     18
#define kIpAnonymous  19

COSMOPOLITAN_C_START_

struct Cidr {
  int64_t addr;
  int cidr;
};

int64_t ParseIp(const char *, size_t);
struct Cidr ParseCidr(const char *, size_t);
bool IsDodIp(uint32_t);
bool IsArinIp(uint32_t);
bool IsRipeIp(uint32_t);
bool IsApnicIp(uint32_t);
bool IsLacnicIp(uint32_t);
bool IsPublicIp(uint32_t);
bool IsPrivateIp(uint32_t);
bool IsAfrinicIp(uint32_t);
bool IsTestnetIp(uint32_t);
bool IsLoopbackIp(uint32_t);
bool IsMulticastIp(uint32_t);
bool IsAnonymousIp(uint32_t);
int CategorizeIp(uint32_t);
const char *GetIpCategoryName(int);
bool IsCloudflareIp(uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/tokenbucket.h */

#define COSMOPOLITAN_NET_HTTP_TOKENBUCKET_H_
COSMOPOLITAN_C_START_

void ReplenishTokens(atomic_uint_fast64_t *, size_t);
int AcquireToken(atomic_schar *, uint32_t, int);
int CountTokens(atomic_schar *, uint32_t, int);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/url.h */

#define COSMOPOLITAN_NET_HTTP_URL_H_

#define kUrlPlus   1
#define kUrlLatin1 2
#define kUrlOpaque 4

COSMOPOLITAN_C_START_

struct UrlView {
  size_t n;
  char *p;
};

struct UrlParams {
  size_t n;
  struct UrlParam {
    struct UrlView key;
    struct UrlView val;
  } * p;
};

struct Url {
  struct UrlView scheme; /* must be [A-Za-z][-+.0-9A-Za-z]* or empty */
  struct UrlView user;   /* depends on host non-absence */
  struct UrlView pass;   /* depends on user non-absence */
  struct UrlView host;   /* or reg_name */
  struct UrlView port;   /* depends on host non-absence */
  struct UrlView path;   /* or opaque_part */
  struct UrlParams params;
  struct UrlView fragment;
};

char *EncodeUrl(struct Url *, size_t *);
char *ParseUrl(const char *, size_t, struct Url *, int);
char *ParseParams(const char *, size_t, struct UrlParams *);
char *ParseHost(const char *, size_t, struct Url *);
char *EscapeUrlView(char *, struct UrlView *, const char[256]);

COSMOPOLITAN_C_END_


/*!BEGIN tool/args/args.h */

#define COSMOPOLITAN_TOOL_ARGS_ARGS_H_
COSMOPOLITAN_C_START_

int LoadZipArgs(int *, char ***);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/dlmalloc/dlmalloc.h */

#define COSMOPOLITAN_THIRD_PARTY_DLMALLOC_DLMALLOC_H_

#define dlbulk_free                  __dlbulk_free
#define dlcalloc                     __dlcalloc
#define dlfree                       __dlfree
#define dlindependent_calloc         __dlindependent_calloc
#define dlindependent_comalloc       __dlindependent_comalloc
#define dlmallinfo                   __dlmallinfo
#define dlmalloc                     __dlmalloc
#define dlmalloc_abort               __dlmalloc_abort
#define dlmalloc_atfork              __dlmalloc_atfork
#define dlmalloc_footprint           __dlmalloc_footprint
#define dlmalloc_footprint_limit     __dlmalloc_footprint_limit
#define dlmalloc_inspect_all         __dlmalloc_inspect_all
#define dlmalloc_max_footprint       __dlmalloc_max_footprint
#define dlmalloc_set_footprint_limit __dlmalloc_set_footprint_limit
#define dlmalloc_stats               __dlmalloc_stats
#define dlmalloc_trim                __dlmalloc_trim
#define dlmalloc_usable_size         __dlmalloc_usable_size
#define dlmallopt                    __dlmallopt
#define dlmallopt                    __dlmallopt
#define dlmemalign                   __dlmemalign
#define dlrealloc                    __dlrealloc
#define dlrealloc_in_place           __dlrealloc_in_place
#define dlrealloc_in_place           __dlrealloc_in_place

COSMOPOLITAN_C_START_

/*
  malloc(size_t n)
  Returns a pointer to a newly allocated chunk of at least n bytes, or
  null if no space is available, in which case errno is set to ENOMEM
  on ANSI C systems.

  If n is zero, malloc returns a minimum-sized chunk. (The minimum
  size is 16 bytes on most 32bit systems, and 32 bytes on 64bit
  systems.)  Note that size_t is an unsigned type, so calls with
  arguments that would be negative if signed are interpreted as
  requests for huge amounts of space, which will often fail. The
  maximum supported value of n differs across systems, but is in all
  cases less than the maximum representable value of a size_t.
*/
void* dlmalloc(size_t);

/*
  free(void* p)
  Releases the chunk of memory pointed to by p, that had been previously
  allocated using malloc or a related routine such as realloc.
  It has no effect if p is null. If p was not malloced or already
  freed, free(p) will by default cuase the current program to abort.
*/
void dlfree(void*);

/*
  calloc(size_t n_elements, size_t element_size);
  Returns a pointer to n_elements * element_size bytes, with all locations
  set to zero.
*/
void* dlcalloc(size_t, size_t);

/*
  realloc(void* p, size_t n)
  Returns a pointer to a chunk of size n that contains the same data
  as does chunk p up to the minimum of (n, p's size) bytes, or null
  if no space is available.

  The returned pointer may or may not be the same as p. The algorithm
  prefers extending p in most cases when possible, otherwise it
  employs the equivalent of a malloc-copy-free sequence.

  If p is null, realloc is equivalent to malloc.

  If space is not available, realloc returns null, errno is set (if on
  ANSI) and p is NOT freed.

  if n is for fewer bytes than already held by p, the newly unused
  space is lopped off and freed if possible.  realloc with a size
  argument of zero (re)allocates a minimum-sized chunk.

  The old unix realloc convention of allowing the last-free'd chunk
  to be used as an argument to realloc is not supported.
*/
void* dlrealloc(void*, size_t);

/*
  realloc_in_place(void* p, size_t n)
  Resizes the space allocated for p to size n, only if this can be
  done without moving p (i.e., only if there is adjacent space
  available if n is greater than p's current allocated size, or n is
  less than or equal to p's size). This may be used instead of plain
  realloc if an alternative allocation strategy is needed upon failure
  to expand space; for example, reallocation of a buffer that must be
  memory-aligned or cleared. You can use realloc_in_place to trigger
  these alternatives only when needed.

  Returns p if successful; otherwise null.
*/
void* dlrealloc_in_place(void*, size_t);

/*
  memalign(size_t alignment, size_t n);
  Returns a pointer to a newly allocated chunk of n bytes, aligned
  in accord with the alignment argument.

  The alignment argument should be a power of two. If the argument is
  not a power of two, the nearest greater power is used.
  8-byte alignment is guaranteed by normal malloc calls, so don't
  bother calling memalign with an argument of 8 or less.

  Overreliance on memalign is a sure way to fragment space.
*/
void* dlmemalign(size_t, size_t);

/*
  mallopt(int parameter_number, int parameter_value)
  Sets tunable parameters The format is to provide a
  (parameter-number, parameter-value) pair.  mallopt then sets the
  corresponding parameter to the argument value if it can (i.e., so
  long as the value is meaningful), and returns 1 if successful else
  0.  SVID/XPG/ANSI defines four standard param numbers for mallopt,
  normally defined in malloc.h.  None of these are use in this malloc,
  so setting them has no effect. But this malloc also supports other
  options in mallopt:

  Symbol            param #  default    allowed param values
  M_TRIM_THRESHOLD     -1   2*1024*1024   any   (-1U disables trimming)
  M_GRANULARITY        -2     page size   any power of 2 >= page size
  M_MMAP_THRESHOLD     -3      256*1024   any   (or 0 if no MMAP support)
*/
int dlmallopt(int, int);

/*
  malloc_footprint();
  Returns the number of bytes obtained from the system.  The total
  number of bytes allocated by malloc, realloc etc., is less than this
  value. Unlike mallinfo, this function returns only a precomputed
  result, so can be called frequently to monitor memory consumption.
  Even if locks are otherwise defined, this function does not use them,
  so results might not be up to date.
*/
size_t dlmalloc_footprint(void);

/*
  malloc_max_footprint();
  Returns the maximum number of bytes obtained from the system. This
  value will be greater than current footprint if deallocated space
  has been reclaimed by the system. The peak number of bytes allocated
  by malloc, realloc etc., is less than this value. Unlike mallinfo,
  this function returns only a precomputed result, so can be called
  frequently to monitor memory consumption.  Even if locks are
  otherwise defined, this function does not use them, so results might
  not be up to date.
*/
size_t dlmalloc_max_footprint(void);

/*
  malloc_footprint_limit();
  Returns the number of bytes that the heap is allowed to obtain from
  the system, returning the last value returned by
  malloc_set_footprint_limit, or the maximum size_t value if
  never set. The returned value reflects a permission. There is no
  guarantee that this number of bytes can actually be obtained from
  the system.
*/
size_t dlmalloc_footprint_limit(void);

/*
  malloc_set_footprint_limit();
  Sets the maximum number of bytes to obtain from the system, causing
  failure returns from malloc and related functions upon attempts to
  exceed this value. The argument value may be subject to page
  rounding to an enforceable limit; this actual value is returned.
  Using an argument of the maximum possible size_t effectively
  disables checks. If the argument is less than or equal to the
  current malloc_footprint, then all future allocations that require
  additional system memory will fail. However, invocation cannot
  retroactively deallocate existing used memory.
*/
size_t dlmalloc_set_footprint_limit(size_t bytes);

/*
  malloc_inspect_all(void(*handler)(void *start,
                                    void *end,
                                    size_t used_bytes,
                                    void* callback_arg),
                      void* arg);
  Traverses the heap and calls the given handler for each managed
  region, skipping all bytes that are (or may be) used for bookkeeping
  purposes.  Traversal does not include include chunks that have been
  directly memory mapped. Each reported region begins at the start
  address, and continues up to but not including the end address.  The
  first used_bytes of the region contain allocated data. If
  used_bytes is zero, the region is unallocated. The handler is
  invoked with the given callback argument. If locks are defined, they
  are held during the entire traversal. It is a bad idea to invoke
  other malloc functions from within the handler.

  For example, to count the number of in-use chunks with size greater
  than 1000, you could write:
  static int count = 0;
  void count_chunks(void* start, void* end, size_t used, void* arg) {
    if (used >= 1000) ++count;
  }
  then:
    malloc_inspect_all(count_chunks, NULL);

  malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined.
*/
void dlmalloc_inspect_all(void (*handler)(void*, void*, size_t, void*),
                          void* arg);

/*
  mallinfo()
  Returns (by copy) a struct containing various summary statistics:

  arena:     current total non-mmapped bytes allocated from system
  ordblks:   the number of free chunks
  smblks:    always zero.
  hblks:     current number of mmapped regions
  hblkhd:    total bytes held in mmapped regions
  usmblks:   the maximum total allocated space. This will be greater
                than current total if trimming has occurred.
  fsmblks:   always zero
  uordblks:  current total allocated space (normal or mmapped)
  fordblks:  total free space
  keepcost:  the maximum number of bytes that could ideally be released
               back to system via malloc_trim. ("ideally" means that
               it ignores page restrictions etc.)

  Because these fields are ints, but internal bookkeeping may
  be kept as longs, the reported values may wrap around zero and
  thus be inaccurate.
*/

struct mallinfo dlmallinfo(void);

/*
  independent_calloc(size_t n_elements, size_t element_size, void* chunks[]);

  independent_calloc is similar to calloc, but instead of returning a
  single cleared space, it returns an array of pointers to n_elements
  independent elements that can hold contents of size elem_size, each
  of which starts out cleared, and can be independently freed,
  realloc'ed etc. The elements are guaranteed to be adjacently
  allocated (this is not guaranteed to occur with multiple callocs or
  mallocs), which may also improve cache locality in some
  applications.

  The "chunks" argument is optional (i.e., may be null, which is
  probably the most typical usage). If it is null, the returned array
  is itself dynamically allocated and should also be freed when it is
  no longer needed. Otherwise, the chunks array must be of at least
  n_elements in length. It is filled in with the pointers to the
  chunks.

  In either case, independent_calloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and "chunks"
  is null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_calloc simplifies and speeds up implementations of many
  kinds of pools.  It may also be useful when constructing large data
  structures that initially have a fixed number of fixed-sized nodes,
  but the number is not known at compile time, and some of the nodes
  may later need to be freed. For example:

  struct Node { int item; struct Node* next; };

  struct Node* build_list() {
    struct Node** pool;
    int n = read_number_of_nodes_needed();
    if (n <= 0) return 0;
    pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
    if (pool == 0) die();
    // organize into a linked list...
    struct Node* first = pool[0];
    for (i = 0; i < n-1; ++i)
      pool[i]->next = pool[i+1];
    free(pool);     // Can now free the array (or not, if it is needed later)
    return first;
  }
*/
void** dlindependent_calloc(size_t, size_t, void**);

/*
  independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);

  independent_comalloc allocates, all at once, a set of n_elements
  chunks with sizes indicated in the "sizes" array.    It returns
  an array of pointers to these elements, each of which can be
  independently freed, realloc'ed etc. The elements are guaranteed to
  be adjacently allocated (this is not guaranteed to occur with
  multiple callocs or mallocs), which may also improve cache locality
  in some applications.

  The "chunks" argument is optional (i.e., may be null). If it is null
  the returned array is itself dynamically allocated and should also
  be freed when it is no longer needed. Otherwise, the chunks array
  must be of at least n_elements in length. It is filled in with the
  pointers to the chunks.

  In either case, independent_comalloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and chunks is
  null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_comallac differs from independent_calloc in that each
  element may have a different size, and also that it does not
  automatically clear elements.

  independent_comalloc can be used to speed up allocation in cases
  where several structs or objects must always be allocated at the
  same time.  For example:

  struct Head { ... }
  struct Foot { ... }

  void send_message(char* msg) {
    int msglen = strlen(msg);
    size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
    void* chunks[3];
    if (independent_comalloc(3, sizes, chunks) == 0)
      die();
    struct Head* head = (struct Head*)(chunks[0]);
    char*        body = (char*)(chunks[1]);
    struct Foot* foot = (struct Foot*)(chunks[2]);
    // ...
  }

  In general though, independent_comalloc is worth using only for
  larger values of n_elements. For small values, you probably won't
  detect enough difference from series of malloc calls to bother.

  Overuse of independent_comalloc can increase overall memory usage,
  since it cannot reuse existing noncontiguous small chunks that
  might be available for some of the elements.
*/
void** dlindependent_comalloc(size_t, size_t*, void**);

/*
  bulk_free(void* array[], size_t n_elements)
  Frees and clears (sets to null) each non-null pointer in the given
  array.  This is likely to be faster than freeing them one-by-one.
  If footers are used, pointers that have been allocated in different
  mspaces are not freed or cleared, and the count of all such pointers
  is returned.  For large arrays of pointers with poor locality, it
  may be worthwhile to sort this array before calling bulk_free.
*/
size_t dlbulk_free(void**, size_t n_elements);

/*
  malloc_trim(size_t pad);

  If possible, gives memory back to the system (via negative arguments
  to sbrk) if there is unused memory at the `high' end of the malloc
  pool or in unused MMAP segments. You can call this after freeing
  large blocks of memory to potentially reduce the system-level memory
  requirements of a program. However, it cannot guarantee to reduce
  memory. Under some allocation patterns, some large free blocks of
  memory will be locked between two used chunks, so they cannot be
  given back to the system.

  The `pad' argument to malloc_trim represents the amount of free
  trailing space to leave untrimmed. If this argument is zero, only
  the minimum amount of memory to maintain internal data structures
  will be left. Non-zero arguments can be supplied to maintain enough
  trailing space to service future expected allocations without having
  to re-obtain memory from the system.

  Malloc_trim returns 1 if it actually released any memory, else 0.
*/
int dlmalloc_trim(size_t);

/*
  malloc_stats();
  Prints on stderr the amount of space obtained from the system (both
  via sbrk and mmap), the maximum amount (which may be more than
  current if malloc_trim and/or munmap got called), and the current
  number of bytes allocated via malloc (or realloc, etc) but not yet
  freed. Note that this is the number of bytes allocated, not the
  number requested. It will be larger than the number requested
  because of alignment and bookkeeping overhead. Because it includes
  alignment wastage as being in use, this figure may be greater than
  zero even when no user-level chunks are allocated.

  The reported current and maximum system memory can be inaccurate if
  a program makes other calls to system memory allocation functions
  (normally sbrk) outside of malloc.

  malloc_stats prints only the most commonly interesting statistics.
  More information can be obtained by calling mallinfo.

  malloc_stats is not compiled if NO_MALLOC_STATS is defined.
*/
void dlmalloc_stats(void);

/*
  malloc_usable_size(void* p);

  Returns the number of bytes you can actually use in
  an allocated chunk, which may be more than you requested (although
  often not) due to alignment and minimum size constraints.
  You can use this many bytes without worrying about
  overwriting other allocated objects. This is not a particularly great
  programming practice. malloc_usable_size can be more useful in
  debugging and assertions, for example:

  p = malloc(n);
  assert(malloc_usable_size(p) >= 256);
*/
size_t dlmalloc_usable_size(void*);

/*
  mspace is an opaque type representing an independent
  region of space that supports mspace_malloc, etc.
*/
typedef void* mspace;

/*
  create_mspace creates and returns a new independent space with the
  given initial capacity, or, if 0, the default granularity size.  It
  returns null if there is no system memory available to create the
  space.  If argument locked is non-zero, the space uses a separate
  lock to control access. The capacity of the space will grow
  dynamically as needed to service mspace_malloc requests.  You can
  control the sizes of incremental increases of this space by
  compiling with a different DEFAULT_GRANULARITY or dynamically
  setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
  destroy_mspace destroys the given space, and attempts to return all
  of its memory back to the system, returning the total number of
  bytes freed. After destruction, the results of access to all memory
  used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

/*
  create_mspace_with_base uses the memory supplied as the initial base
  of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this
  space is used for bookkeeping, so the capacity must be at least this
  large. (Otherwise 0 is returned.) When this initial space is
  exhausted, additional memory will be obtained from the system.
  Destroying this space will deallocate all additionally allocated
  space (if possible) but not the initial base.
*/
mspace create_mspace_with_base(void* base, size_t capacity, int locked);

/*
  mspace_track_large_chunks controls whether requests for large chunks
  are allocated in their own untracked mmapped regions, separate from
  others in this mspace. By default large chunks are not tracked,
  which reduces fragmentation. However, such chunks are not
  necessarily released to the system upon destroy_mspace.  Enabling
  tracking by setting to true may increase fragmentation, but avoids
  leakage when relying on destroy_mspace to release all memory
  allocated using this space.  The function returns the previous
  setting.
*/
int mspace_track_large_chunks(mspace msp, int enable);

/*
  mspace_mallinfo behaves as mallinfo, but reports properties of
  the given space.
*/
struct mallinfo mspace_mallinfo(mspace msp);

/*
  An alias for mallopt.
*/
int mspace_mallopt(int, int);

/*
  The following operate identically to their malloc counterparts
  but operate only for the given mspace argument
*/
void* mspace_malloc(mspace msp, size_t bytes);
void mspace_free(mspace msp, void* mem);
void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
void* mspace_realloc(mspace msp, void* mem, size_t newsize);
void* mspace_realloc_in_place(mspace msp, void* mem, size_t newsize);
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
void** mspace_independent_calloc(mspace msp, size_t n_elements,
                                 size_t elem_size, void* chunks[]);
void** mspace_independent_comalloc(mspace msp, size_t n_elements,
                                   size_t sizes[], void* chunks[]);
size_t mspace_bulk_free(mspace msp, void**, size_t n_elements);
size_t mspace_usable_size(const void* mem);
void mspace_malloc_stats(mspace msp);
int mspace_trim(mspace msp, size_t pad);
size_t mspace_footprint(mspace msp);
size_t mspace_max_footprint(mspace msp);
size_t mspace_footprint_limit(mspace msp);
size_t mspace_set_footprint_limit(mspace msp, size_t bytes);
void mspace_inspect_all(mspace msp,
                        void (*handler)(void*, void*, size_t, void*),
                        void* arg);

void dlmalloc_atfork(void);
void dlmalloc_abort(void) relegated wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/gdtoa/gdtoa.h */

#define COSMOPOLITAN_THIRD_PARTY_GDTOA_GDTOA_H_
COSMOPOLITAN_C_START_

#define dtoa      __dtoa
#define gdtoa     __gdtoa
#define strtodg   __strtodg
#define freedtoa  __freedtoa
#define g_ddfmt   __g_ddfmt
#define g_ddfmt_p __g_ddfmt_p
#define g_dfmt    __g_dfmt
#define g_dfmt_p  __g_dfmt_p
#define g_ffmt    __g_ffmt
#define g_ffmt_p  __g_ffmt_p
#define g_Qfmt    __g_Qfmt
#define g_Qfmt_p  __g_Qfmt_p
#define g_xfmt    __g_xfmt
#define g_xfmt_p  __g_xfmt_p
#define g_xLfmt   __g_xLfmt
#define g_xLfmt_p __g_xLfmt_p
#define strtoId   __strtoId
#define strtoIdd  __strtoIdd
#define strtoIf   __strtoIf
#define strtoIQ   __strtoIQ
#define strtoIx   __strtoIx
#define strtoIxL  __strtoIxL
#define strtord   __strtord
#define strtordd  __strtordd
#define strtorf   __strtorf
#define strtorQ   __strtorQ
#define strtorx   __strtorx
#define strtorxL  __strtorxL
#define strtodI   __strtodI
#define strtopd   __strtopd
#define strtopdd  __strtopdd
#define strtopf   __strtopf
#define strtopQ   __strtopQ
#define strtopx   __strtopx
#define strtopxL  __strtopxL

/**
 * Configures g_*fmt()
 *
 * @param ic
 * 	0 ==> Infinity or NaN
 * 	1 ==> infinity or nan
 * 	2 ==> INFINITY or NAN
 * 	3 ==> Inf or NaN
 * 	4 ==> inf or nan
 * 	5 ==> INF or NAN
 * @param ic determines if NaNs are rendered as NaN(...)
 * 	0 ==> no
 * 	1 ==> yes
 * 	2 ==> no for default NaN values; yes otherwise
 * @param ns determines sign of NaN values reported
 * 	0 ==> distinguish NaN and -NaN
 * 	1 ==> report both as NaN
 */
#define NIK(ic, nb, ns) (ic + 6 * (nb + 3 * ns))

enum {
  /* return values from strtodg */
  STRTOG_Zero = 0,
  STRTOG_Normal = 1,
  STRTOG_Denormal = 2,
  STRTOG_Infinite = 3,
  STRTOG_NaN = 4,
  STRTOG_NaNbits = 5,
  STRTOG_NoNumber = 6,
  STRTOG_Retmask = 7,
  /* The following may be or-ed into one of the above values. */
  STRTOG_Neg = 0x08,    /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
  STRTOG_Inexlo = 0x10, /* returned result rounded toward zero */
  STRTOG_Inexhi = 0x20, /* returned result rounded away from zero */
  STRTOG_Inexact = 0x30,
  STRTOG_Underflow = 0x40,
  STRTOG_Overflow = 0x80
};

typedef struct FPI {
  int nbits;
  int emin;
  int emax;
  int rounding;
  int sudden_underflow;
  int int_max;
} FPI;

enum {
  /* FPI.rounding values: same as FLT_ROUNDS */
  FPI_Round_zero = 0,
  FPI_Round_near = 1,
  FPI_Round_up = 2,
  FPI_Round_down = 3
};

char *dtoa(double, int, int, int *, int *, char **);
char *gdtoa(const FPI *, int, unsigned *, int *, int, int, int *, char **);
int strtodg(const char *, char **, const FPI *, int *, unsigned *);
void freedtoa(char *);

char *g_ddfmt(char *, double *, int, size_t);
char *g_ddfmt_p(char *, double *, int, size_t, int);
char *g_dfmt(char *, double *, int, size_t);
char *g_dfmt_p(char *, double *, int, size_t, int);
char *g_ffmt(char *, float *, int, size_t);
char *g_ffmt_p(char *, float *, int, size_t, int);
char *g_Qfmt(char *, void *, int, size_t);
char *g_Qfmt_p(char *, void *, int, size_t, int);
char *g_xfmt(char *, void *, int, size_t);
char *g_xfmt_p(char *, void *, int, size_t, int);
char *g_xLfmt(char *, void *, int, size_t);
char *g_xLfmt_p(char *, void *, int, size_t, int);

int strtoId(const char *, char **, double *, double *);
int strtoIdd(const char *, char **, double *, double *);
int strtoIf(const char *, char **, float *, float *);
int strtoIQ(const char *, char **, void *, void *);
int strtoIx(const char *, char **, void *, void *);
int strtoIxL(const char *, char **, void *, void *);
int strtord(const char *, char **, int, double *);
int strtordd(const char *, char **, int, double *);
int strtorf(const char *, char **, int, float *);
int strtorQ(const char *, char **, int, void *);
int strtorx(const char *, char **, int, void *);
int strtorxL(const char *, char **, int, void *);

int strtodI(const char *, char **, double *);
int strtopd(const char *, char **, double *);
int strtopdd(const char *, char **, double *);
int strtopf(const char *, char **, float *);
int strtopQ(const char *, char **, void *);
int strtopx(const char *, char **, void *);
int strtopxL(const char *, char **, void *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long1.h */

#define _GETOPT_CORE_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif
COSMOPOLITAN_C_START_

extern char *optarg;
extern int optind, opterr, optopt, optreset;

int getopt(int, char *const *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long2.h */

#define _GETOPT_EXT_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif

#define no_argument       0
#define required_argument 1
#define optional_argument 2

COSMOPOLITAN_C_START_

struct option {
  const char *name;
  int has_arg;
  int *flag;
  int val;
};

int getopt_long(int, char *const *, const char *, const struct option *, int *);
int getopt_long_only(int, char *const *, const char *, const struct option *,
                     int *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/crypt.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_CRYPT_H_
COSMOPOLITAN_C_START_

struct crypt_data {
  int initialized;
  char __buf[256];
};

char *crypt(const char *, const char *) libcesque;
char *crypt_r(const char *, const char *, struct crypt_data *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/fnmatch.h */

#define COSMOPOLITAN_THIRD_PARTY_REGEX_FNMATCH_H_
COSMOPOLITAN_C_START_

#define FNM_PATHNAME    0x1
#define FNM_NOESCAPE    0x2
#define FNM_PERIOD      0x4
#define FNM_LEADING_DIR 0x8
#define FNM_CASEFOLD    0x10
#define FNM_FILE_NAME   FNM_PATHNAME

#define FNM_NOMATCH 1
#define FNM_NOSYS   (-1)

int fnmatch(const char *, const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/glob.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_GLOB_H_
COSMOPOLITAN_C_START_

#define GLOB_ERR      0x01
#define GLOB_MARK     0x02
#define GLOB_NOSORT   0x04
#define GLOB_DOOFFS   0x08 /* reserves null slots at start of gl_pathv */
#define GLOB_NOCHECK  0x10 /* just yield pattern if GLOB_NOMATCH happens */
#define GLOB_APPEND   0x20 /* enables us to call glob() multiple times */
#define GLOB_NOESCAPE 0x40 /* don't allow things like \*\?\[\] escaping */
#define GLOB_PERIOD   0x80

#define GLOB_TILDE       0x1000
#define GLOB_TILDE_CHECK 0x4000

#define GLOB_NOSPACE 1
#define GLOB_ABORTED 2
#define GLOB_NOMATCH 3
#define GLOB_NOSYS   4

typedef struct {
  size_t gl_pathc;
  char **gl_pathv;
  size_t gl_offs;
  int __dummy1;
  void *__dummy2[5];
} glob_t;

int glob(const char *, int, int (*)(const char *, int), glob_t *);
void globfree(glob_t *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/lockf.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_LOCKF_H_

#define F_ULOCK 0
#define F_LOCK  1
#define F_TLOCK 2
#define F_TEST  3

COSMOPOLITAN_C_START_

int lockf(int, int, int64_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/mntent.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_MNTENT_H_
COSMOPOLITAN_C_START_

#define MOUNTED "/etc/mtab"

#define MNTTYPE_IGNORE  "ignore"
#define MNTTYPE_NFS     "nfs"
#define MNTTYPE_SWAP    "swap"
#define MNTOPT_DEFAULTS "defaults"
#define MNTOPT_RO       "ro"
#define MNTOPT_RW       "rw"
#define MNTOPT_SUID     "suid"
#define MNTOPT_NOSUID   "nosuid"
#define MNTOPT_NOAUTO   "noauto"

struct mntent {
  char *mnt_fsname;
  char *mnt_dir;
  char *mnt_type;
  char *mnt_opts;
  int mnt_freq;
  int mnt_passno;
};

FILE *setmntent(const char *, const char *);
int endmntent(FILE *);
struct mntent *getmntent(FILE *);
struct mntent *getmntent_r(FILE *, struct mntent *, char *, int);
int addmntent(FILE *, const struct mntent *);
char *hasmntopt(const struct mntent *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/nameser.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NAMESER_H_
COSMOPOLITAN_C_START_

#define __NAMESER	19991006
#define NS_PACKETSZ	512
#define NS_MAXDNAME	1025
#define NS_MAXMSG	65535
#define NS_MAXCDNAME	255
#define NS_MAXLABEL	63
#define NS_HFIXEDSZ	12
#define NS_QFIXEDSZ	4
#define NS_RRFIXEDSZ	10
#define NS_INT32SZ	4
#define NS_INT16SZ	2
#define NS_INT8SZ	1
#define NS_INADDRSZ	4
#define NS_IN6ADDRSZ	16
#define NS_CMPRSFLGS	0xc0
#define NS_DEFAULTPORT	53

typedef enum __ns_sect {
	ns_s_qd = 0,
	ns_s_zn = 0,
	ns_s_an = 1,
	ns_s_pr = 1,
	ns_s_ns = 2,
	ns_s_ud = 2,
	ns_s_ar = 3,
	ns_s_max = 4
} ns_sect;

typedef struct __ns_msg {
	const unsigned char *_msg, *_eom;
	uint16_t _id, _flags, _counts[ns_s_max];
	const unsigned char *_sections[ns_s_max];
	ns_sect _sect;
	int _rrnum;
	const unsigned char *_msg_ptr;
} ns_msg;

struct _ns_flagdata {  int mask, shift;  };
extern const struct _ns_flagdata _ns_flagdata[];

#define ns_msg_id(handle) ((handle)._id + 0)
#define ns_msg_base(handle) ((handle)._msg + 0)
#define ns_msg_end(handle) ((handle)._eom + 0)
#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
#define ns_msg_getflag(handle, flag) \
	(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)

typedef	struct __ns_rr {
	char		name[NS_MAXDNAME];
	uint16_t	type;
	uint16_t	rr_class;
	uint32_t	ttl;
	uint16_t	rdlength;
	const unsigned char *rdata;
} ns_rr;

#define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
#define ns_rr_type(rr)	((ns_type)((rr).type + 0))
#define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0))
#define ns_rr_ttl(rr)	((rr).ttl + 0)
#define ns_rr_rdlen(rr)	((rr).rdlength + 0)
#define ns_rr_rdata(rr)	((rr).rdata + 0)

typedef enum __ns_flag {
	ns_f_qr,
	ns_f_opcode,
	ns_f_aa,
	ns_f_tc,
	ns_f_rd,
	ns_f_ra,
	ns_f_z,
	ns_f_ad,
	ns_f_cd,
	ns_f_rcode,
	ns_f_max
} ns_flag;

typedef enum __ns_opcode {
	ns_o_query = 0,
	ns_o_iquery = 1,
	ns_o_status = 2,
	ns_o_notify = 4,
	ns_o_update = 5,
	ns_o_max = 6
} ns_opcode;

typedef	enum __ns_rcode {
	ns_r_noerror = 0,
	ns_r_formerr = 1,
	ns_r_servfail = 2,
	ns_r_nxdomain = 3,
	ns_r_notimpl = 4,
	ns_r_refused = 5,
	ns_r_yxdomain = 6,
	ns_r_yxrrset = 7,
	ns_r_nxrrset = 8,
	ns_r_notauth = 9,
	ns_r_notzone = 10,
	ns_r_max = 11,
	ns_r_badvers = 16,
	ns_r_badsig = 16,
	ns_r_badkey = 17,
	ns_r_badtime = 18
} ns_rcode;

typedef enum __ns_update_operation {
	ns_uop_delete = 0,
	ns_uop_add = 1,
	ns_uop_max = 2
} ns_update_operation;

struct ns_tsig_key {
        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
        unsigned char *data;
        int len;
};
typedef struct ns_tsig_key ns_tsig_key;

struct ns_tcp_tsig_state {
	int counter;
	struct dst_key *key;
	void *ctx;
	unsigned char sig[NS_PACKETSZ];
	int siglen;
};
typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;

#define NS_TSIG_FUDGE 300
#define NS_TSIG_TCP_COUNT 100
#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"

#define NS_TSIG_ERROR_NO_TSIG -10
#define NS_TSIG_ERROR_NO_SPACE -11
#define NS_TSIG_ERROR_FORMERR -12

typedef enum __ns_type {
	ns_t_invalid = 0,
	ns_t_a = 1,
	ns_t_ns = 2,
	ns_t_md = 3,
	ns_t_mf = 4,
	ns_t_cname = 5,
	ns_t_soa = 6,
	ns_t_mb = 7,
	ns_t_mg = 8,
	ns_t_mr = 9,
	ns_t_null = 10,
	ns_t_wks = 11,
	ns_t_ptr = 12,
	ns_t_hinfo = 13,
	ns_t_minfo = 14,
	ns_t_mx = 15,
	ns_t_txt = 16,
	ns_t_rp = 17,
	ns_t_afsdb = 18,
	ns_t_x25 = 19,
	ns_t_isdn = 20,
	ns_t_rt = 21,
	ns_t_nsap = 22,
	ns_t_nsap_ptr = 23,
	ns_t_sig = 24,
	ns_t_key = 25,
	ns_t_px = 26,
	ns_t_gpos = 27,
	ns_t_aaaa = 28,
	ns_t_loc = 29,
	ns_t_nxt = 30,
	ns_t_eid = 31,
	ns_t_nimloc = 32,
	ns_t_srv = 33,
	ns_t_atma = 34,
	ns_t_naptr = 35,
	ns_t_kx = 36,
	ns_t_cert = 37,
	ns_t_a6 = 38,
	ns_t_dname = 39,
	ns_t_sink = 40,
	ns_t_opt = 41,
	ns_t_apl = 42,
	ns_t_tkey = 249,
	ns_t_tsig = 250,
	ns_t_ixfr = 251,
	ns_t_axfr = 252,
	ns_t_mailb = 253,
	ns_t_maila = 254,
	ns_t_any = 255,
	ns_t_zxfr = 256,
	ns_t_max = 65536
} ns_type;

#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
		      (t) == ns_t_mailb || (t) == ns_t_maila)
#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
		       (t) == ns_t_zxfr)

typedef enum __ns_class {
	ns_c_invalid = 0,
	ns_c_in = 1,
	ns_c_2 = 2,
	ns_c_chaos = 3,
	ns_c_hs = 4,
	ns_c_none = 254,
	ns_c_any = 255,
	ns_c_max = 65536
} ns_class;

typedef enum __ns_key_types {
	ns_kt_rsa = 1,
	ns_kt_dh  = 2,
	ns_kt_dsa = 3,
	ns_kt_private = 254
} ns_key_types;

typedef enum __ns_cert_types {
	cert_t_pkix = 1,
	cert_t_spki = 2,
	cert_t_pgp  = 3,
	cert_t_url  = 253,
	cert_t_oid  = 254
} ns_cert_types;

#define	NS_KEY_TYPEMASK		0xC000
#define	NS_KEY_TYPE_AUTH_CONF	0x0000
#define	NS_KEY_TYPE_CONF_ONLY	0x8000
#define	NS_KEY_TYPE_AUTH_ONLY	0x4000
#define	NS_KEY_TYPE_NO_KEY	0xC000
#define	NS_KEY_NO_AUTH		0x8000
#define	NS_KEY_NO_CONF		0x4000
#define	NS_KEY_RESERVED2	0x2000
#define	NS_KEY_EXTENDED_FLAGS	0x1000
#define	NS_KEY_RESERVED4	0x0800
#define	NS_KEY_RESERVED5	0x0400
#define	NS_KEY_NAME_TYPE	0x0300
#define	NS_KEY_NAME_USER	0x0000
#define	NS_KEY_NAME_ENTITY	0x0200
#define	NS_KEY_NAME_ZONE	0x0100
#define	NS_KEY_NAME_RESERVED	0x0300
#define	NS_KEY_RESERVED8	0x0080
#define	NS_KEY_RESERVED9	0x0040
#define	NS_KEY_RESERVED10	0x0020
#define	NS_KEY_RESERVED11	0x0010
#define	NS_KEY_SIGNATORYMASK	0x000F
#define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
				  NS_KEY_RESERVED4 | \
				  NS_KEY_RESERVED5 | \
				  NS_KEY_RESERVED8 | \
				  NS_KEY_RESERVED9 | \
				  NS_KEY_RESERVED10 | \
				  NS_KEY_RESERVED11 )
#define NS_KEY_RESERVED_BITMASK2 0xFFFF
#define	NS_ALG_MD5RSA		1
#define	NS_ALG_DH               2
#define	NS_ALG_DSA              3
#define	NS_ALG_DSS              NS_ALG_DSA
#define	NS_ALG_EXPIRE_ONLY	253
#define	NS_ALG_PRIVATE_OID	254

#define NS_KEY_PROT_TLS         1
#define NS_KEY_PROT_EMAIL       2
#define NS_KEY_PROT_DNSSEC      3
#define NS_KEY_PROT_IPSEC       4
#define NS_KEY_PROT_ANY		255

#define	NS_MD5RSA_MIN_BITS	 512
#define	NS_MD5RSA_MAX_BITS	4096
#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
#define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
#define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
#define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)

#define NS_DSA_SIG_SIZE         41
#define NS_DSA_MIN_SIZE         213
#define NS_DSA_MAX_BYTES        405

#define	NS_SIG_TYPE	0
#define	NS_SIG_ALG	2
#define	NS_SIG_LABELS	3
#define	NS_SIG_OTTL	4
#define	NS_SIG_EXPIR	8
#define	NS_SIG_SIGNED	12
#define	NS_SIG_FOOT	16
#define	NS_SIG_SIGNER	18
#define	NS_NXT_BITS 8
#define	NS_NXT_BIT_SET(  n,p) (p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
#define NS_NXT_MAX 127

#define NS_OPT_DNSSEC_OK        0x8000U
#define NS_OPT_NSID		3

#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2))
#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4))
#define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2)
#define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4)

unsigned ns_get16(const unsigned char *);
unsigned long ns_get32(const unsigned char *);
void ns_put16(unsigned, unsigned char *);
void ns_put32(unsigned long, unsigned char *);

int ns_initparse(const unsigned char *, int, ns_msg *);
int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int);
int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t);


#define	__BIND		19950621

typedef struct {
	unsigned	id :16;
#if __BYTE_ORDER == __BIG_ENDIAN
	unsigned	qr: 1;
	unsigned	opcode: 4;
	unsigned	aa: 1;
	unsigned	tc: 1;
	unsigned	rd: 1;
	unsigned	ra: 1;
	unsigned	unused :1;
	unsigned	ad: 1;
	unsigned	cd: 1;
	unsigned	rcode :4;
#else
	unsigned	rd :1;
	unsigned	tc :1;
	unsigned	aa :1;
	unsigned	opcode :4;
	unsigned	qr :1;
	unsigned	rcode :4;
	unsigned	cd: 1;
	unsigned	ad: 1;
	unsigned	unused :1;
	unsigned	ra :1;
#endif
	unsigned	qdcount :16;
	unsigned	ancount :16;
	unsigned	nscount :16;
	unsigned	arcount :16;
} HEADER;

#define PACKETSZ	NS_PACKETSZ
#define MAXDNAME	NS_MAXDNAME
#define MAXCDNAME	NS_MAXCDNAME
#define MAXLABEL	NS_MAXLABEL
#define	HFIXEDSZ	NS_HFIXEDSZ
#define QFIXEDSZ	NS_QFIXEDSZ
#define RRFIXEDSZ	NS_RRFIXEDSZ
#define	INT32SZ		NS_INT32SZ
#define	INT16SZ		NS_INT16SZ
#define INT8SZ		NS_INT8SZ
#define	INADDRSZ	NS_INADDRSZ
#define	IN6ADDRSZ	NS_IN6ADDRSZ
#define	INDIR_MASK	NS_CMPRSFLGS
#define NAMESERVER_PORT	NS_DEFAULTPORT

#define S_ZONE		ns_s_zn
#define S_PREREQ	ns_s_pr
#define S_UPDATE	ns_s_ud
#define S_ADDT		ns_s_ar

#define QUERY		ns_o_query
#define IQUERY		ns_o_iquery
#define STATUS		ns_o_status
#define	NS_NOTIFY_OP	ns_o_notify
#define	NS_UPDATE_OP	ns_o_update

#define NOERROR		ns_r_noerror
#define FORMERR		ns_r_formerr
#define SERVFAIL	ns_r_servfail
#define NXDOMAIN	ns_r_nxdomain
#define NOTIMP		ns_r_notimpl
#define REFUSED		ns_r_refused
#define YXDOMAIN	ns_r_yxdomain
#define YXRRSET		ns_r_yxrrset
#define NXRRSET		ns_r_nxrrset
#define NOTAUTH		ns_r_notauth
#define NOTZONE		ns_r_notzone

#define DELETE		ns_uop_delete
#define ADD		ns_uop_add

#define T_A		ns_t_a
#define T_NS		ns_t_ns
#define T_MD		ns_t_md
#define T_MF		ns_t_mf
#define T_CNAME		ns_t_cname
#define T_SOA		ns_t_soa
#define T_MB		ns_t_mb
#define T_MG		ns_t_mg
#define T_MR		ns_t_mr
#define T_NULL		ns_t_null
#define T_WKS		ns_t_wks
#define T_PTR		ns_t_ptr
#define T_HINFO		ns_t_hinfo
#define T_MINFO		ns_t_minfo
#define T_MX		ns_t_mx
#define T_TXT		ns_t_txt
#define	T_RP		ns_t_rp
#define T_AFSDB		ns_t_afsdb
#define T_X25		ns_t_x25
#define T_ISDN		ns_t_isdn
#define T_RT		ns_t_rt
#define T_NSAP		ns_t_nsap
#define T_NSAP_PTR	ns_t_nsap_ptr
#define	T_SIG		ns_t_sig
#define	T_KEY		ns_t_key
#define	T_PX		ns_t_px
#define	T_GPOS		ns_t_gpos
#define	T_AAAA		ns_t_aaaa
#define	T_LOC		ns_t_loc
#define	T_NXT		ns_t_nxt
#define	T_EID		ns_t_eid
#define	T_NIMLOC	ns_t_nimloc
#define	T_SRV		ns_t_srv
#define T_ATMA		ns_t_atma
#define T_NAPTR		ns_t_naptr
#define T_A6		ns_t_a6
#define T_DNAME		ns_t_dname
#define	T_TSIG		ns_t_tsig
#define	T_IXFR		ns_t_ixfr
#define T_AXFR		ns_t_axfr
#define T_MAILB		ns_t_mailb
#define T_MAILA		ns_t_maila
#define T_ANY		ns_t_any

#define C_IN		ns_c_in
#define C_CHAOS		ns_c_chaos
#define C_HS		ns_c_hs
#define C_NONE		ns_c_none
#define C_ANY		ns_c_any

#define	GETSHORT		NS_GET16
#define	GETLONG			NS_GET32
#define	PUTSHORT		NS_PUT16
#define	PUTLONG			NS_PUT32

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/netdb.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NETDB_H_
COSMOPOLITAN_C_START_

struct addrinfo {
	int ai_flags;
	int ai_family;
	int ai_socktype;
	int ai_protocol;
	uint32_t ai_addrlen;
	struct sockaddr *ai_addr;
	char *ai_canonname;
	struct addrinfo *ai_next;
};

#define AI_PASSIVE      0x01
#define AI_CANONNAME    0x02
#define AI_NUMERICHOST  0x04
#define AI_V4MAPPED     0x08
#define AI_ALL          0x10
#define AI_ADDRCONFIG   0x20
#define AI_NUMERICSERV  0x400

#define NI_NUMERICHOST  0x01
#define NI_NUMERICSERV  0x02
#define NI_NOFQDN       0x04
#define NI_NAMEREQD     0x08
#define NI_DGRAM        0x10
#define NI_NUMERICSCOPE 0x100

#define EAI_BADFLAGS   -1
#define EAI_NONAME     -2
#define EAI_AGAIN      -3
#define EAI_FAIL       -4
#define EAI_FAMILY     -6
#define EAI_SOCKTYPE   -7
#define EAI_SERVICE    -8
#define EAI_MEMORY     -10
#define EAI_SYSTEM     -11
#define EAI_OVERFLOW   -12

int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
void freeaddrinfo (struct addrinfo *);
int getnameinfo (const struct sockaddr *, uint32_t, char *, uint32_t, char *, uint32_t, int);
const char *gai_strerror(int);


/* Legacy functions follow (marked OBsolete in SUS) */

struct netent {
	char *n_name;
	char **n_aliases;
	int n_addrtype;
	uint32_t n_net;
};

struct hostent {
	char *h_name;
	char **h_aliases;
	int h_addrtype;
	int h_length;
	char **h_addr_list;
};
#define h_addr h_addr_list[0]

struct servent {
	char *s_name;
	char **s_aliases;
	int s_port;
	char *s_proto;
};

struct protoent {
	char *p_name;
	char **p_aliases;
	int p_proto;
};

void sethostent (int);
void endhostent (void);
struct hostent *gethostent (void);

void setnetent (int);
void endnetent (void);
struct netent *getnetent (void);
struct netent *getnetbyaddr (uint32_t, int);
struct netent *getnetbyname (const char *);

void setservent (int);
void endservent (void);
struct servent *getservent (void);
struct servent *getservbyname (const char *, const char *);
struct servent *getservbyport (int, const char *);

void setprotoent (int);
void endprotoent (void);
struct protoent *getprotoent (void);
struct protoent *getprotobyname (const char *);
struct protoent *getprotobynumber (int);

#define NI_MAXHOST 255
#define NI_MAXSERV 32

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
struct hostent *gethostbyname (const char *);
struct hostent *gethostbyaddr (const void *, uint32_t, int);
errno_t *__h_errno_location(void) dontthrow pureconst;
#define h_errno (*__h_errno_location())
#define HOST_NOT_FOUND 1
#define TRY_AGAIN      2
#define NO_RECOVERY    3
#define NO_DATA        4
#define NO_ADDRESS     NO_DATA
#endif

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
void herror(const char *);
const char *hstrerror(int);
int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
struct hostent *gethostbyname2(const char *, int);
int gethostbyaddr_r(const void *, uint32_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
#define EAI_NODATA     -5
#define EAI_ADDRFAMILY -9
#define EAI_INPROGRESS -100
#define EAI_CANCELED   -101
#define EAI_NOTCANCELED -102
#define EAI_ALLDONE    -103
#define EAI_INTR       -104
#define EAI_IDN_ENCODE -105
#endif

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/passwd.h */

#define COSMOPOLITAN_LIBC_PASSWD_H_
COSMOPOLITAN_C_START_

struct passwd {
  char *pw_name;
  char *pw_passwd;
  uid_t pw_uid;
  gid_t pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};

void setpwent(void);
void endpwent(void);
struct passwd *getpwent(void);
struct passwd *getpwuid(uid_t);
struct passwd *getpwnam(const char *);
int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
struct passwd *fgetpwent(FILE *);
int putpwent(const struct passwd *, FILE *);

struct group {
  char *gr_name;
  char *gr_passwd;
  gid_t gr_gid;
  char **gr_mem;
};

struct group *getgrgid(gid_t);
struct group *getgrnam(const char *);
int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
struct group *getgrent(void);
void endgrent(void);
void setgrent(void);
struct group *fgetgrent(FILE *);
int putgrent(const struct group *, FILE *);
int getgrouplist(const char *, gid_t, gid_t *, int *);
int initgroups(const char *, gid_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/rand48.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RAND48_H_
COSMOPOLITAN_C_START_

double drand48(void);
double erand48(unsigned short[3]);
long int lrand48(void);
long int nrand48(unsigned short[3]);
long mrand48(void);
long jrand48(unsigned short[3]);
void srand48(long);
unsigned short *seed48(unsigned short[3]);
void lcong48(unsigned short[7]);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/resolv.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RESOLV_H_
COSMOPOLITAN_C_START_

#define MAXNS			3
#define MAXDFLSRCH		3
#define MAXDNSRCH		6
#define LOCALDOMAINPARTS	2

#define RES_TIMEOUT		5
#define MAXRESOLVSORT		10
#define RES_MAXNDOTS		15
#define RES_MAXRETRANS		30
#define RES_MAXRETRY		5
#define RES_DFLRETRY		2
#define RES_MAXTIME		65535

/* unused; purely for broken apps */
typedef struct __res_state {
	int retrans;
	int retry;
	unsigned long options;
	int nscount;
	struct sockaddr_in nsaddr_list[MAXNS];
# define nsaddr	nsaddr_list[0]
	unsigned short id;
	char *dnsrch[MAXDNSRCH+1];
	char defdname[256];
	unsigned long pfcode;
	unsigned ndots:4;
	unsigned nsort:4;
	unsigned ipv6_unavail:1;
	unsigned unused:23;
	struct {
		struct in_addr addr;
		uint32_t mask;
	} sort_list[MAXRESOLVSORT];
	void *qhook;
	void *rhook;
	int res_h_errno;
	int _vcsock;
	unsigned _flags;
	union {
		char pad[52];
		struct {
			uint16_t		nscount;
			uint16_t		nsmap[MAXNS];
			int			nssocks[MAXNS];
			uint16_t		nscount6;
			uint16_t		nsinit;
			struct sockaddr_in6	*nsaddrs[MAXNS];
			unsigned int		_initstamp[2];
		} _ext;
	} _u;
} *res_state;

#define	__RES	19960801

#ifndef _PATH_RESCONF
#define _PATH_RESCONF        "/etc/resolv.conf"
#endif

struct res_sym {
	int number;
	char *name;
	char *humanname;
};

#define	RES_F_VC	0x00000001
#define	RES_F_CONN	0x00000002
#define RES_F_EDNS0ERR	0x00000004

#define	RES_EXHAUSTIVE	0x00000001

#define RES_INIT	0x00000001
#define RES_DEBUG	0x00000002
#define RES_AAONLY	0x00000004
#define RES_USEVC	0x00000008
#define RES_PRIMARY	0x00000010
#define RES_IGNTC	0x00000020
#define RES_RECURSE	0x00000040
#define RES_DEFNAMES	0x00000080
#define RES_STAYOPEN	0x00000100
#define RES_DNSRCH	0x00000200
#define	RES_INSECURE1	0x00000400
#define	RES_INSECURE2	0x00000800
#define	RES_NOALIASES	0x00001000
#define	RES_USE_INET6	0x00002000
#define RES_ROTATE	0x00004000
#define	RES_NOCHECKNAME	0x00008000
#define	RES_KEEPTSIG	0x00010000
#define	RES_BLAST	0x00020000
#define RES_USEBSTRING	0x00040000
#define RES_NOIP6DOTINT	0x00080000
#define RES_USE_EDNS0	0x00100000
#define RES_SNGLKUP	0x00200000
#define RES_SNGLKUPREOP	0x00400000
#define RES_USE_DNSSEC	0x00800000

#define RES_DEFAULT	(RES_RECURSE|RES_DEFNAMES|RES_DNSRCH|RES_NOIP6DOTINT)

#define RES_PRF_STATS	0x00000001
#define RES_PRF_UPDATE	0x00000002
#define RES_PRF_CLASS   0x00000004
#define RES_PRF_CMD	0x00000008
#define RES_PRF_QUES	0x00000010
#define RES_PRF_ANS	0x00000020
#define RES_PRF_AUTH	0x00000040
#define RES_PRF_ADD	0x00000080
#define RES_PRF_HEAD1	0x00000100
#define RES_PRF_HEAD2	0x00000200
#define RES_PRF_TTLID	0x00000400
#define RES_PRF_HEADX	0x00000800
#define RES_PRF_QUERY	0x00001000
#define RES_PRF_REPLY	0x00002000
#define RES_PRF_INIT	0x00004000

struct __res_state *__res_state(void);
#define _res (*__res_state())

int res_init(void);
int res_query(const char *, int, int, unsigned char *, int);
int res_querydomain(const char *, const char *, int, int, unsigned char *, int);
int res_search(const char *, int, int, unsigned char *, int);
int res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
int res_send(const unsigned char *, int, unsigned char *, int);
int dn_comp(const char *, unsigned char *, int, unsigned char **, unsigned char **);
int dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
int dn_skipname(const unsigned char *, const unsigned char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/search.h */

#define COSMOPOLITAN_THIRDPARTY_MUSL_SEARCH_H

typedef enum { FIND, ENTER } ACTION;
typedef enum { preorder, postorder, endorder, leaf } VISIT;

typedef struct entry {
	char *key;
	void *data;
} ENTRY;

int hcreate(size_t);
void hdestroy(void);
ENTRY *hsearch(ENTRY, ACTION);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct hsearch_data {
	struct __tab *__tab;
	unsigned int __unused1;
	unsigned int __unused2;
};

int hcreate_r(size_t, struct hsearch_data *);
void hdestroy_r(struct hsearch_data *);
int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *);
#endif

void insque(void *, void *);
void remque(void *);

void *lsearch(const void *, void *, size_t *, size_t,
	int (*)(const void *, const void *));
void *lfind(const void *, const void *, size_t *, size_t,
	int (*)(const void *, const void *));

void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *));
void *tfind(const void *, void *const *, int(*)(const void *, const void *));
void *tsearch(const void *, void **, int (*)(const void *, const void *));
void twalk(const void *, void (*)(const void *, VISIT, int));

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct qelem {
	struct qelem *q_forw, *q_back;
	char q_data[1];
};

void tdestroy(void *, void (*)(void *));
#endif



/*!BEGIN third_party/musl/shadow.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_SHADOW_H_
COSMOPOLITAN_C_START_

#define	SHADOW "/etc/shadow"

struct spwd {
	char *sp_namp;
	char *sp_pwdp;
	long sp_lstchg;
	long sp_min;
	long sp_max;
	long sp_warn;
	long sp_inact;
	long sp_expire;
	unsigned long sp_flag;
};

void setspent(void);
void endspent(void);
struct spwd *getspent(void);
struct spwd *fgetspent(FILE *);
struct spwd *sgetspent(const char *);
int putspent(const struct spwd *, FILE *);

struct spwd *getspnam(const char *);
int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **);

int lckpwdf(void);
int ulckpwdf(void);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/tempnam.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_TEMPNAM_H_
COSMOPOLITAN_C_START_

char *tempnam(const char *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/zlib/zconf.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZCONF_H_

#define STDC
#define STDC99
#define MAX_MEM_LEVEL 9
#define DEF_MEM_LEVEL 8
#define MAX_WBITS     15 /* 32K LZ77 window */

#ifdef MODE_DBG
#define ZLIB_DEBUG
#endif

#define z_const const

#define Z_COSMO_PREFIX_SET

#define Bytef                    _Cz_Bytef
#define _dist_code               _Cz__dist_code
#define _length_code             _Cz__length_code
#define _tr_align                _Cz__tr_align
#define _tr_flush_bits           _Cz__tr_flush_bits
#define _tr_flush_block          _Cz__tr_flush_block
#define _tr_init                 _Cz__tr_init
#define _tr_stored_block         _Cz__tr_stored_block
#define _tr_tally                _Cz__tr_tally
#define adler32                  _Cz_adler32
#define adler32_combine          _Cz_adler32_combine
#define adler32_combine64        _Cz_adler32_combine64
#define adler32_simd_            _Cz_adler32_simd_
#define adler32_z                _Cz_adler32_z
#define alloc_func               _Cz_alloc_func
#define arm_check_features       _Cz_arm_check_features
#define arm_cpu_enable_crc32     _Cz_arm_cpu_enable_crc32
#define arm_cpu_enable_pmull     _Cz_arm_cpu_enable_pmull
#define armv8_crc32_little       _Cz_armv8_crc32_little
#define armv8_crc32_pmull_little _Cz_armv8_crc32_pmull_little
#define charf                    _Cz_charf
#define compress                 _Cz_compress
#define compress2                _Cz_compress2
#define compressBound            _Cz_compressBound
#define copy_with_crc            _Cz_copy_with_crc
#define cpu_check_features       _Cz_cpu_check_features
#define crc32                    _Cz_crc32
#define crc32_combine            _Cz_crc32_combine
#define crc32_combine64          _Cz_crc32_combine64
#define crc32_combine_gen        _Cz_crc32_combine_gen
#define crc32_combine_gen64      _Cz_crc32_combine_gen64
#define crc32_combine_op         _Cz_crc32_combine_op
#define crc32_sse42_simd_        _Cz_crc32_sse42_simd_
#define crc32_z                  _Cz_crc32_z
#define crc_finalize             _Cz_crc_finalize
#define crc_fold_512to32         _Cz_crc_fold_512to32
#define crc_fold_copy            _Cz_crc_fold_copy
#define crc_fold_init            _Cz_crc_fold_init
#define crc_reset                _Cz_crc_reset
#define deflate                  _Cz_deflate
#define deflateBound             _Cz_deflateBound
#define deflateCopy              _Cz_deflateCopy
#define deflateEnd               _Cz_deflateEnd
#define deflateGetDictionary     _Cz_deflateGetDictionary
#define deflateInit              _Cz_deflateInit
#define deflateInit2             _Cz_deflateInit2
#define deflateParams            _Cz_deflateParams
#define deflatePending           _Cz_deflatePending
#define deflatePrime             _Cz_deflatePrime
#define deflateReset             _Cz_deflateReset
#define deflateResetKeep         _Cz_deflateResetKeep
#define deflateSetDictionary     _Cz_deflateSetDictionary
#define deflateSetHeader         _Cz_deflateSetHeader
#define deflateTune              _Cz_deflateTune
#define deflate_copyright        _Cz_deflate_copyright
#define deflate_read_buf         _Cz_deflate_read_buf
#define fill_window_sse          _Cz_fill_window_sse
#define free_func                _Cz_free_func
#define get_crc_table            _Cz_get_crc_table
#define gzFile                   _Cz_gzFile
#define gz_error                 _Cz_gz_error
#define gz_header                _Cz_gz_header
#define gz_header_s              _Cz_gz_header_s
#define gz_headerp               _Cz_gz_headerp
#define gz_intmax                _Cz_gz_intmax
#define gz_strwinerror           _Cz_gz_strwinerror
#define gzbuffer                 _Cz_gzbuffer
#define gzclearerr               _Cz_gzclearerr
#define gzclose                  _Cz_gzclose
#define gzclose_r                _Cz_gzclose_r
#define gzclose_w                _Cz_gzclose_w
#define gzdirect                 _Cz_gzdirect
#define gzdopen                  _Cz_gzdopen
#define gzeof                    _Cz_gzeof
#define gzerror                  _Cz_gzerror
#define gzflush                  _Cz_gzflush
#define gzfread                  _Cz_gzfread
#define gzfwrite                 _Cz_gzfwrite
#define gzgetc                   _Cz_gzgetc
#define gzgetc_                  _Cz_gzgetc_
#define gzgets                   _Cz_gzgets
#define gzoffset                 _Cz_gzoffset
#define gzoffset64               _Cz_gzoffset64
#define gzopen                   _Cz_gzopen
#define gzopen64                 _Cz_gzopen64
#define gzopen_w                 _Cz_gzopen_w
#define gzprintf                 _Cz_gzprintf
#define gzputc                   _Cz_gzputc
#define gzputs                   _Cz_gzputs
#define gzread                   _Cz_gzread
#define gzrewind                 _Cz_gzrewind
#define gzseek                   _Cz_gzseek
#define gzseek64                 _Cz_gzseek64
#define gzsetparams              _Cz_gzsetparams
#define gztell                   _Cz_gztell
#define gztell64                 _Cz_gztell64
#define gzungetc                 _Cz_gzungetc
#define gzvprintf                _Cz_gzvprintf
#define gzwrite                  _Cz_gzwrite
#define in_func                  _Cz_in_func
#define inflate                  _Cz_inflate
#define inflateBack              _Cz_inflateBack
#define inflateBackEnd           _Cz_inflateBackEnd
#define inflateBackInit_         _Cz_inflateBackInit_
#define inflateCodesUsed         _Cz_inflateCodesUsed
#define inflateCopy              _Cz_inflateCopy
#define inflateEnd               _Cz_inflateEnd
#define inflateGetDictionary     _Cz_inflateGetDictionary
#define inflateGetHeader         _Cz_inflateGetHeader
#define inflateInit              _Cz_inflateInit
#define inflateInit2             _Cz_inflateInit2
#define inflateMark              _Cz_inflateMark
#define inflatePrime             _Cz_inflatePrime
#define inflateReset             _Cz_inflateReset
#define inflateReset2            _Cz_inflateReset2
#define inflateResetKeep         _Cz_inflateResetKeep
#define inflateSetDictionary     _Cz_inflateSetDictionary
#define inflateSync              _Cz_inflateSync
#define inflateSyncPoint         _Cz_inflateSyncPoint
#define inflateUndermine         _Cz_inflateUndermine
#define inflateValidate          _Cz_inflateValidate
#define inflate_copyright        _Cz_inflate_copyright
#define inflate_fast             _Cz_inflate_fast
#define inflate_fast_chunk_      _Cz_inflate_fast_chunk_
#define inflate_table            _Cz_inflate_table
#define intf                     _Cz_intf
#define out_func                 _Cz_out_func
#define uInt                     _Cz_uInt
#define uIntf                    _Cz_uIntf
#define uLong                    _Cz_uLong
#define uLongf                   _Cz_uLongf
#define uncompress               _Cz_uncompress
#define uncompress2              _Cz_uncompress2
#define voidp                    _Cz_voidp
#define voidpc                   _Cz_voidpc
#define voidpf                   _Cz_voidpf
#define x86_check_features       _Cz_x86_check_features
#define x86_cpu_enable_simd      _Cz_x86_cpu_enable_simd
#define x86_cpu_enable_sse2      _Cz_x86_cpu_enable_sse2
#define x86_cpu_enable_ssse3     _Cz_x86_cpu_enable_ssse3
#define zError                   _Cz_zError
#define z_errmsg                 _Cz_z_errmsg
#define zcalloc                  _Cz_zcalloc
#define zcfree                   _Cz_zcfree
#define zlibCompileFlags         _Cz_zlibCompileFlags
#define zlibVersion              _Cz_zlibVersion


typedef unsigned char Byte;
typedef unsigned int uInt;   /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef Byte Bytef;
typedef char charf;
typedef int intf;
typedef uInt uIntf;
typedef uLong uLongf;
typedef void const *voidpc;
typedef void *voidpf;
typedef void *voidp;
typedef uint32_t z_crc_t;
typedef int64_t z_off64_t;
typedef size_t z_size_t;



/*!BEGIN third_party/zlib/zlib.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZLIB_H_

/**
 * @fileoverview zlib
 *
 * The 'zlib' compression library provides in-memory
 * compression and decompression functions, including integrity checks
 * of the uncompressed data. This version of the library supports only
 * one compression method (deflation) but other algorithms will be added
 * later and will have the same stream interface.
 *
 * Compression can be done in a single step if the buffers are large enough,
 * or can be done by repeated calls of the compression function.  In the latter
 * case, the application must provide more input and/or consume the output
 * (providing more output space) before each call.
 *
 * The compressed data format used by default by the in-memory functions is
 * the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
 * around a deflate stream, which is itself documented in RFC 1951.
 *
 * The library also supports reading and writing files in gzip (.gz) format
 * with an interface similar to that of stdio using the functions that start
 * with "gz".  The gzip format is different from the zlib format.  gzip is a
 * gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
 *
 * This library can optionally read and write gzip and raw deflate streams in
 * memory as well.
 *
 * The zlib format was designed to be compact and fast for use in memory
 * and on communications channels.  The gzip format was designed for single-
 * file compression on file systems, has a larger header than zlib to maintain
 * directory information, and uses a different, slower check method than zlib.
 *
 * The library does not install any signal handler.  The decoder checks
 * the consistency of the compressed data, so the library should never crash
 * even in the case of corrupted input.
 */

#define ZLIB_VERSION         "1.2.11"
#define ZLIB_VERNUM          0x12b0
#define ZLIB_VER_MAJOR       1
#define ZLIB_VER_MINOR       2
#define ZLIB_VER_REVISION    11
#define ZLIB_VER_SUBREVISION 0

/**
 * The application must update next_in and avail_in when avail_in has
 * dropped to zero. It must update next_out and avail_out when avail_out
 * has dropped to zero. The application must initialize zalloc, zfree
 * and opaque before calling the init function. All other fields are set
 * by the compression library and must not be updated by the
 * application.
 *
 * The opaque value provided by the application will be passed as the
 * first parameter for calls of zalloc and zfree. This can be useful for
 * custom memory management. The compression library attaches no meaning
 * to the opaque value.
 *
 * zalloc must return Z_NULL if there is not enough memory for the
 * object. If zlib is used in a multi-threaded application, zalloc and
 * zfree must be thread safe. In that case, zlib is thread-safe. When
 * zalloc and zfree are Z_NULL on entry to the initialization function,
 * they are set to internal routines that use the standard library
 * functions malloc() and free().
 *
 * On 16-bit systems, the functions zalloc and zfree must be able to
 * allocate exactly 65536 bytes, but will not be required to allocate
 * more than this if the symbol MAXSEG_64K is defined (see zconf.h).
 * WARNING: On MSDOS, pointers returned by zalloc for objects of exactly
 * 65536 bytes *must* have their offset normalized to zero. The default
 * allocation function provided by this library ensures this (see
 * zutil.c). To reduce memory requirements and avoid any allocation of
 * 64K objects, at the expense of compression ratio, compile the library
 * with -DMAX_WBITS=14 (see zconf.h).
 *
 * The fields total_in and total_out can be used for statistics or
 * progress reports. After compression, total_in holds the total size of
 * the uncompressed data and may be saved for use by the decompressor
 * (particularly if the decompressor wants to decompress everything in a
 * single step).
 */
#define Z_NO_FLUSH      0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH    2
#define Z_FULL_FLUSH    3
#define Z_FINISH        4
#define Z_BLOCK         5
#define Z_TREES         6

/**
 * Allowed flush values; see deflate() and inflate() below for details.
 */
#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO         (-1)
#define Z_STREAM_ERROR  (-2)
#define Z_DATA_ERROR    (-3)
#define Z_MEM_ERROR     (-4)
#define Z_BUF_ERROR     (-5)
#define Z_VERSION_ERROR (-6)

/**
 * Return codes for the compression/decompression functions. Negative
 * values are errors, positive values are used for special but normal
 * events.
 */
#define Z_NO_COMPRESSION      0
#define Z_BEST_SPEED          1
#define Z_BEST_COMPRESSION    9
#define Z_DEFAULT_COMPRESSION (-1)

/**
 * Compression levels.
 */
#define Z_FILTERED         1
#define Z_HUFFMAN_ONLY     2
#define Z_RLE              3
#define Z_FIXED            4
#define Z_DEFAULT_STRATEGY 0

/**
 * Compression strategy; see deflateInit2() below for details
 */
#define Z_BINARY  0
#define Z_TEXT    1
#define Z_ASCII   Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN 2

/**
 * Possible values of the data_type field for deflate()
 */
#define Z_DEFLATED 8

/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */

COSMOPOLITAN_C_START_

typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
typedef void (*free_func)(voidpf opaque, voidpf address);

struct internal_state;

typedef struct z_stream_s {
  const Bytef *next_in;         /* next input byte */
  uInt avail_in;                /* number of bytes available at next_in */
  uLong total_in;               /* total number of input bytes read so far */
  Bytef *next_out;              /* next output byte will go here */
  uInt avail_out;               /* remaining free space at next_out */
  uLong total_out;              /* total number of bytes output so far */
  const char *msg;              /* last error message, NULL if no error */
  struct internal_state *state; /* not visible by applications */
  alloc_func zalloc;            /* used to allocate the internal state */
  free_func zfree;              /* used to free the internal state */
  voidpf opaque;  /* private data object passed to zalloc and zfree */
  int data_type;  /* best guess about the data type: binary or text
                     for deflate, or the decoding state for inflate */
  uLong adler;    /* Adler-32 or CRC-32 value of the uncompressed data */
  uLong reserved; /* reserved for future use */
} z_stream;

typedef z_stream *z_streamp;

/**
 * gzip header information passed to and from zlib routines. See RFC
 * 1952 for more details on the meanings of these fields.
 */
typedef struct gz_header_s {
  int text;       /* true if compressed data believed to be text */
  uLong time_;    /* modification time */
  int xflags;     /* extra flags (not used when writing a gzip file) */
  int os;         /* operating system */
  Bytef *extra;   /* pointer to extra field or Z_NULL if none */
  uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  uInt extra_max; /* space at extra (only when reading header) */
  Bytef *name;    /* pointer to zero-terminated file name or Z_NULL */
  uInt name_max;  /* space at name (only when reading header) */
  Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  uInt comm_max;  /* space at comment (only when reading header) */
  int hcrc;       /* true if there was or will be a header crc */
  int done;       /* true when done reading gzip header (not used
                     when writing a gzip file) */
} gz_header;

typedef gz_header *gz_headerp;

#define zlib_version zlibVersion()

/**
 * The application can compare zlibVersion and ZLIB_VERSION for consistency.
 * If the first character differs, the library code actually used is not
 * compatible with the zlib.h header file used by the application.  This check
 * is automatically made by deflateInit and inflateInit.
 */
const char *zlibVersion(void);

/**
 * Initializes the internal stream state for compression.  The fields
 * zalloc, zfree and opaque must be initialized before by the caller.  If
 * zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
 * allocation functions.
 *
 * The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
 * 1 gives best speed, 9 gives best compression, 0 gives no compression at all
 * (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION
 * requests a default compromise between speed and compression (currently
 * equivalent to level 6).
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if level is not a valid compression level. msg
 *     is set to null if there is no error message. deflateInit does not
 *     perform any compression: this will be done by deflate().
 */
int deflateInit(z_streamp strm, int level);

/**
 * deflate compresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full. It may
 * introduce some output latency (reading input without producing any
 * output) except when forced to flush.
 *
 * The detailed semantics are as follows. deflate performs one or both
 * of the following actions:
 *
 * - Compress more input starting at next_in and update next_in and
 *  avail_in accordingly. If not all input can be processed (because
 *  there is not enough room in the output buffer), next_in and avail_in
 *  are updated and processing will resume at this point for the next
 *  call of deflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *  avail_out accordingly. This action is forced if the parameter flush
 *  is non zero. Forcing flush frequently degrades the compression
 *  ratio, so this parameter should be set only when necessary. Some
 *  output may be provided even if flush is zero.
 *
 * Before the call of deflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating avail_in or avail_out
 * accordingly; avail_out should never be zero before the call. The
 * application can consume the compressed output when it wants, for
 * example when the output buffer is full (avail_out == 0), or after
 * each call of deflate(). If deflate returns Z_OK and with zero
 * avail_out, it must be called again after making room in the output
 * buffer because there might be more output pending. See
 * deflatePending(), which can be used if desired to determine whether
 * or not there is more ouput in that case.
 *
 * Normally the parameter flush is set to Z_NO_FLUSH, which allows
 * deflate to decide how much data to accumulate before producing
 * output, in order to maximize compression.
 *
 * If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
 * flushed to the output buffer and the output is aligned on a byte
 * boundary, so that the decompressor can get all input data available
 * so far. (In particular avail_in is zero after the call if enough
 * output space has been provided before the call.) Flushing may degrade
 * compression for some compression algorithms and so it should be used
 * only when necessary. This completes the current deflate block and
 * follows it with an empty stored block that is three bits plus filler
 * bits to the next byte, followed by four bytes (00 00 ff ff).
 *
 * If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to
 * the output buffer, but the output is not aligned to a byte boundary.
 * All of the input data so far will be available to the decompressor,
 * as for Z_SYNC_FLUSH. This completes the current deflate block and
 * follows it with an empty fixed codes block that is 10 bits long. This
 * assures that enough bytes are output in order for the decompressor to
 * finish the block before the empty fixed codes block.
 *
 * If flush is set to Z_BLOCK, a deflate block is completed and emitted,
 * as for Z_SYNC_FLUSH, but the output is not aligned on a byte
 * boundary, and up to seven bits of the current block are held to be
 * written as the next byte after the next deflate block is completed.
 * In this case, the decompressor may not be provided enough bits at
 * this point in order to complete decompression of the data provided so
 * far to the compressor. It may need to wait for the next block to be
 * emitted. This is for advanced applications that need to control the
 * emission of deflate blocks.
 *
 * If flush is set to Z_FULL_FLUSH, all output is flushed as with
 * Z_SYNC_FLUSH, and the compression state is reset so that
 * decompression can restart from this point if previous compressed data
 * has been damaged or if random access is desired. Using Z_FULL_FLUSH
 * too often can seriously degrade compression.
 *
 * If deflate returns with avail_out == 0, this function must be called
 * again with the same value of the flush parameter and more output
 * space (updated avail_out), until the flush is complete (deflate
 * returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or
 * Z_SYNC_FLUSH, make sure that avail_out is greater than six to avoid
 * repeated flush markers due to avail_out == 0 on return.
 *
 * If the parameter flush is set to Z_FINISH, pending input is
 * processed, pending output is flushed and deflate returns with
 * Z_STREAM_END if there was enough output space. If deflate returns
 * with Z_OK or Z_BUF_ERROR, this function must be called again with
 * Z_FINISH and more output space (updated avail_out) but no more input
 * data, until it returns with Z_STREAM_END or an error. After deflate
 * has returned Z_STREAM_END, the only possible operations on the stream
 * are deflateReset or deflateEnd.
 *
 * Z_FINISH can be used in the first deflate call after deflateInit if
 * all the compression is to be done in a single step. In order to
 * complete in one call, avail_out must be at least the value returned
 * by deflateBound (see below). Then deflate is guaranteed to return
 * Z_STREAM_END. If not enough output space is provided, deflate will
 * not return Z_STREAM_END, and it must be called again as described
 * above.
 *
 * deflate() sets strm->adler to the Adler-32 checksum of all input read
 * so far (that is, total_in bytes). If a gzip stream is being
 * generated, then strm->adler will be the CRC-32 checksum of the input
 * read so far. (See deflateInit2 below.)
 *
 * deflate() may update strm->data_type if it can make a good guess about
 * the input data type (Z_BINARY or Z_TEXT).  If in doubt, the data is
 * considered binary.  This field is only for information purposes and does not
 * affect the compression algorithm in any manner.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if all input has been
 *     consumed and all output has been produced (only when flush is set
 *     to Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent
 *     (for example if next_in or next_out was Z_NULL or the state was
 *     inadvertently written over by the application), or Z_BUF_ERROR if
 *     no progress is possible (for example avail_in or avail_out was
 *     zero). Note that Z_BUF_ERROR is not fatal, and deflate() can be
 *     called again with more input and more output space to continue
 *     compressing.
 */
int deflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the stream state was
 *     inconsistent, Z_DATA_ERROR if the stream was freed prematurely
 *     (some input or output was discarded). In the error case, msg may
 *     be set but then points to a static string (which must not be
 *     deallocated).
 */
int deflateEnd(z_streamp strm);

/**
 * Initializes the internal stream state for decompression. The fields
 * next_in, avail_in, zalloc, zfree and opaque must be initialized
 * before by the caller. In the current version of inflate, the provided
 * input is not read or consumed. The allocation of a sliding window
 * will be deferred to the first call of inflate (if the decompression
 * does not complete on the first call). If zalloc and zfree are set to
 * Z_NULL, inflateInit updates them to use default allocation functions.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit does not perform any decompression. Actual
 *     decompression will be done by inflate(). So next_in, and
 *     avail_in, next_out, and avail_out are unused and unchanged. The
 *     current implementation of inflateInit() does not process any
 *     header information -- that is deferred until inflate() is called.
 */
int inflateInit(z_streamp strm);

/**
 * inflate decompresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full.  It may introduce
 * some output latency (reading input without producing any output) except when
 * forced to flush.
 *
 * The detailed semantics are as follows.  inflate performs one or both of the
 * following actions:
 *
 * - Decompress more input starting at next_in and update next_in and
 *   avail_in accordingly. If not all input can be processed (because
 *   there is not enough room in the output buffer), then next_in and
 *   avail_in are updated accordingly, and processing will resume at
 *   this point for the next call of inflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *   avail_out accordingly. inflate() provides as much output as
 *   possible, until there is no more input data or no more space in the
 *   output buffer (see below about the flush parameter).
 *
 * Before the call of inflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating the next_* and avail_* values
 * accordingly. If the caller of inflate() does not provide both
 * available input and available output space, it is possible that there
 * will be no progress made. The application can consume the
 * uncompressed output when it wants, for example when the output buffer
 * is full (avail_out == 0), or after each call of inflate(). If inflate
 * returns Z_OK and with zero avail_out, it must be called again after
 * making room in the output buffer because there might be more output
 * pending.
 *
 * The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
 * Z_FINISH, Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate()
 * flush as much output as possible to the output buffer. Z_BLOCK
 * requests that inflate() stop if and when it gets to the next deflate
 * block boundary. When decoding the zlib or gzip format, this will
 * cause inflate() to return immediately after the header and before the
 * first block. When doing a raw inflate, inflate() will go ahead and
 * process the first block, and will return when it gets to the end of
 * that block, or when it runs out of data.
 *
 * The Z_BLOCK option assists in appending to or combining deflate
 * streams. To assist in this, on return inflate() always sets
 * strm->data_type to the number of unused bits in the last byte taken
 * from strm->next_in, plus 64 if inflate() is currently decoding the
 * last block in the deflate stream, plus 128 if inflate() returned
 * immediately after decoding an end-of-block code or decoding the
 * complete header up to just before the first byte of the deflate
 * stream. The end-of-block will not be indicated until all of the
 * uncompressed data from that block has been written to strm->next_out.
 * The number of unused bits may in general be greater than seven,
 * except when bit 7 of data_type is set, in which case the number of
 * unused bits will be less than eight. data_type is set as noted here
 * every time inflate() returns for all flush options, and so can be
 * used to determine the amount of currently consumed input in bits.
 *
 * The Z_TREES option behaves as Z_BLOCK does, but it also returns when
 * the end of each deflate block header is reached, before any actual
 * data in that block is decoded. This allows the caller to determine
 * the length of the deflate block header for later use in random access
 * within a deflate block. 256 is added to the value of strm->data_type
 * when inflate() returns immediately after reaching the end of the
 * deflate block header.
 *
 * inflate() should normally be called until it returns Z_STREAM_END or
 * an error. However if all decompression is to be performed in a single
 * step (a single call of inflate), the parameter flush should be set to
 * Z_FINISH. In this case all pending input is processed and all pending
 * output is flushed; avail_out must be large enough to hold all of the
 * uncompressed data for the operation to complete. (The size of the
 * uncompressed data may have been saved by the compressor for this
 * purpose.) The use of Z_FINISH is not required to perform an inflation
 * in one step. However it may be used to inform inflate that a faster
 * approach can be used for the single inflate() call. Z_FINISH also
 * informs inflate to not maintain a sliding window if the stream
 * completes, which reduces inflate's memory footprint. If the stream
 * does not complete, either because not all of the stream is provided
 * or not enough output space is provided, then a sliding window will be
 * allocated and inflate() can be called again to continue the operation
 * as if Z_NO_FLUSH had been used.
 *
 * In this implementation, inflate() always flushes as much output as
 * possible to the output buffer, and always uses the faster approach on
 * the first call. So the effects of the flush parameter in this
 * implementation are on the return value of inflate() as noted below,
 * when inflate() returns early when Z_BLOCK or Z_TREES is used, and
 * when inflate() avoids the allocation of memory for a sliding window
 * when Z_FINISH is used.
 *
 * If a preset dictionary is needed after this call (see
 * inflateSetDictionary below), inflate sets strm->adler to the Adler-32
 * checksum of the dictionary chosen by the compressor and returns
 * Z_NEED_DICT; otherwise it sets strm->adler to the Adler-32 checksum
 * of all output produced so far (that is, total_out bytes) and returns
 * Z_OK, Z_STREAM_END or an error code as described below. At the end of
 * the stream, inflate() checks that its computed Adler-32 checksum is
 * equal to that saved by the compressor and returns Z_STREAM_END only
 * if the checksum is correct.
 *
 * inflate() can decompress and check either zlib-wrapped or
 * gzip-wrapped deflate data. The header type is detected automatically,
 * if requested when initializing with inflateInit2(). Any information
 * contained in the gzip header is not retained unless
 * inflateGetHeader() is used. When processing gzip-wrapped deflate
 * data, strm->adler32 is set to the CRC-32 of the output produced so
 * far. The CRC-32 is checked against the gzip trailer, as is the
 * uncompressed length, modulo 2^32.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if the end of the compressed
 *     data has been reached and all uncompressed output has been
 *     produced, Z_NEED_DICT if a preset dictionary is needed at this
 *     point, Z_DATA_ERROR if the input data was corrupted (input stream
 *     not conforming to the zlib format or incorrect check value, in
 *     which case strm->msg points to a string with a more specific
 *     error), Z_STREAM_ERROR if the stream structure was inconsistent
 *     (for example next_in or next_out was Z_NULL, or the state was
 *     inadvertently written over by the application), Z_MEM_ERROR if
 *     there was not enough memory, Z_BUF_ERROR if no progress was
 *     possible or if there was not enough room in the output buffer
 *     when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
 *     inflate() can be called again with more input and more output
 *     space to continue decompressing. If Z_DATA_ERROR is returned, the
 *     application may then call inflateSync() to look for a good
 *     compression block if a partial recovery of the data is to be
 *     attempted.
 */
int inflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK or Z_STREAM_ERROR if stream state inconsistent
 */
int inflateEnd(z_streamp strm);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » special functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  the following functions are needed only in some special applications */

/**
 * This is another version of deflateInit with more compression options.
 * The fields next_in, zalloc, zfree and opaque must be initialized
 * before by the caller.
 *
 * The method parameter is the compression method. It must be Z_DEFLATED
 * in this version of the library.
 *
 * The windowBits parameter is the base two logarithm of the window size
 * (the size of the history buffer). It should be in the range 8..15 for
 * this version of the library. Larger values of this parameter result
 * in better compression at the expense of memory usage. The default
 * value is 15 if deflateInit is used instead.
 *
 * For the current implementation of deflate(), a windowBits value of 8
 * (a window size of 256 bytes) is not supported. As a result, a request
 * for 8 will result in 9 (a 512-byte window). In that case, providing 8
 * to inflateInit2() will result in an error when the zlib header with 9
 * is checked against the initialization of inflate(). The remedy is to
 * not use 8 with deflateInit2() with this initialization, or at least
 * in that case use 9 with inflateInit2().
 *
 * windowBits can also be -8..-15 for raw deflate. In this case,
 * -windowBits determines the window size. deflate() will then generate
 * raw deflate data with no zlib header or trailer, and will not compute
 * a check value.
 *
 * windowBits can also be greater than 15 for optional gzip encoding.
 * Add 16 to windowBits to write a simple gzip header and trailer around
 * the compressed data instead of a zlib wrapper. The gzip header will
 * have no file name, no extra data, no comment, no modification time
 * (set to zero), no header crc, and the operating system will be set to
 * the appropriate value, if the operating system was determined at
 * compile time. If a gzip stream is being written, strm->adler is a
 * CRC-32 instead of an Adler-32.
 *
 * For raw deflate or gzip encoding, a request for a 256-byte window is
 * rejected as invalid, since only the zlib header provides a means of
 * transmitting the window size to the decompressor.
 *
 * The memLevel parameter specifies how much memory should be allocated
 * for the internal compression state. memLevel=1 uses minimum memory
 * but is slow and reduces compression ratio; memLevel=9 uses maximum
 * memory for optimal speed. The default value is 8. See zconf.h for
 * total memory usage as a function of windowBits and memLevel.
 *
 * The strategy parameter is used to tune the compression algorithm. Use
 * the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
 * produced by a filter (or predictor), Z_HUFFMAN_ONLY to force Huffman
 * encoding only (no string match), or Z_RLE to limit match distances to
 * one (run-length encoding). Filtered data consists mostly of small
 * values with a somewhat random distribution. In this case, the
 * compression algorithm is tuned to compress them better. The effect of
 * Z_FILTERED is to force more Huffman coding and less string matching;
 * it is somewhat intermediate between Z_DEFAULT_STRATEGY and
 * Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
 * Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
 * strategy parameter only affects the compression ratio but not the
 * correctness of the compressed output even if it is not set
 * appropriately. Z_FIXED prevents the use of dynamic Huffman codes,
 * allowing for a simpler decoder for special applications.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if any parameter is invalid (such as an invalid
 *     method). msg is set to null if there is no error message.
 *     deflateInit2 does not perform any compression: this will be done
 *     by deflate().
 */
int deflateInit2(z_streamp strm, int level, int method, int windowBits,
                 int memLevel, int strategy);

/**
 * Initializes the compression dictionary from the given byte sequence
 * without producing any compressed output. When using the zlib format,
 * this function must be called immediately after deflateInit,
 * deflateInit2 or deflateReset, and before any call of deflate. When
 * doing raw deflate, this function must be called either before any
 * call of deflate, or immediately after the completion of a deflate
 * block, i.e. after all input has been consumed and all output has been
 * delivered when using any of the flush options Z_BLOCK,
 * Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The compressor and
 * decompressor must use exactly the same dictionary (see
 * inflateSetDictionary).
 *
 * The dictionary should consist of strings (byte sequences) that are
 * likely to be encountered later in the data to be compressed, with the
 * most commonly used strings preferably put towards the end of the
 * dictionary. Using a dictionary is most useful when the data to be
 * compressed is short and can be predicted with good accuracy; the data
 * can then be compressed better than with the default empty dictionary.
 *
 * Depending on the size of the compression data structures selected by
 * deflateInit or deflateInit2, a part of the dictionary may in effect
 * be discarded, for example if the dictionary is larger than the window
 * size provided in deflateInit or deflateInit2. Thus the strings most
 * likely to be useful should be put at the end of the dictionary, not
 * at the front. In addition, the current implementation of deflate will
 * use at most the window size minus 262 bytes of the provided
 * dictionary.
 *
 * Upon return of this function, strm->adler is set to the Adler-32
 * value of the dictionary; the decompressor may later use this value to
 * determine which dictionary has been used by the compressor. (The
 * Adler-32 value applies to the whole dictionary even if only a subset
 * of the dictionary is actually used by the compressor.) If a raw
 * deflate was requested, then the Adler-32 value is not computed and
 * strm->adler is not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent (for example if deflate has already been called for
 *     this stream or if not at a block boundary for raw deflate).
 *     deflateSetDictionary does not perform any compression: this will
 *     be done by deflate().
 */
int deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by deflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If deflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * deflateGetDictionary() may return a length less than the window size, even
 * when more than the window size in input has been provided. It may return up
 * to 258 bytes less in that case, due to how zlib's implementation of deflate
 * manages the sliding window and lookahead for matches, where matches can be
 * up to 258 bytes long. If the application needs the last window-size bytes of
 * input, then that would need to be saved by the application outside of zlib.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int deflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Sets destination stream as a complete copy of the source stream.
 *
 * This function can be useful when several compression strategies will be
 * tried, for example when there are several ways of pre-processing the input
 * data with a filter.  The streams that will be discarded should then be freed
 * by calling deflateEnd.  Note that deflateCopy duplicates the internal
 * compression state which can be quite large, so this strategy is slow and can
 * consume lots of memory.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int deflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to deflateEnd followed by deflateInit, but
 * does not free and reallocate the internal compression state.  The stream
 * will leave the compression level and any other attributes that may have been
 * set unchanged.
 *
 * deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 * stream state was inconsistent (such as zalloc or state being Z_NULL).
 */
int deflateReset(z_streamp strm);

/**
 * Dynamically update the compression level and compression strategy.  The
 * interpretation of level and strategy is as in deflateInit2().  This can be
 * used to switch between compression and straight copy of the input data, or
 * to switch to a different kind of input data requiring a different strategy.
 * If the compression approach (which is a function of the level) or the
 * strategy is changed, and if any input has been consumed in a previous
 * deflate() call, then the input available so far is compressed with the old
 * level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
 * for the compression levels 0, 1..3, and 4..9 respectively.  The new level
 * and strategy will take effect at the next call of deflate().
 *
 * If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
 * not have enough output space to complete, then the parameter change will not
 * take effect.  In this case, deflateParams() can be called again with the
 * same parameters and more output space to try again.
 *
 * In order to assure a change in the parameters on the first try, the
 * deflate stream should be flushed using deflate() with Z_BLOCK or other flush
 * request until strm.avail_out is not zero, before calling deflateParams().
 * Then no more input data should be provided before the deflateParams() call.
 * If this is done, the old level and strategy will be applied to the data
 * compressed before deflateParams(), and the new level and strategy will be
 * applied to the the data compressed after deflateParams().
 *
 * deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
 * state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
 * there was not enough output space to complete the compression of the
 * available input data before a change in the strategy or approach.  Note that
 * in the case of a Z_BUF_ERROR, the parameters are not changed.  A return
 * value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
 * retried with more output space.
 */
int deflateParams(z_streamp strm, int level, int strategy);

/**
 * Fine tune deflate's internal compression parameters. This should only
 * be used by someone who understands the algorithm used by zlib's
 * deflate for searching for the best matching string, and even then
 * only by the most fanatic optimizer trying to squeeze out the last
 * compressed bit for their specific input data. Read the deflate.c
 * source code for the meaning of the max_lazy, good_length,
 * nice_length, and max_chain parameters.
 *
 * deflateTune() can be called after deflateInit() or deflateInit2(), and
 * returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
 */
int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
                int max_chain);

/**
 * deflateBound() returns an upper bound on the compressed size after
 * deflation of sourceLen bytes. It must be called after deflateInit()
 * or deflateInit2(), and after deflateSetHeader(), if used. This would
 * be used to allocate an output buffer for deflation in a single pass,
 * and so would be called before deflate(). If that first deflate() call
 * is provided the sourceLen input bytes, an output buffer allocated to
 * the size returned by deflateBound(), and the flush value Z_FINISH,
 * then deflate() is guaranteed to return Z_STREAM_END. Note that it is
 * possible for the compressed size to be larger than the value returned
 * by deflateBound() if flush options other than Z_FINISH or Z_NO_FLUSH
 * are used.
 */
uLong deflateBound(z_streamp strm, uLong sourceLen);

/**
 * deflatePending() returns the number of bytes and bits of output that
 * have been generated, but not yet provided in the available output.
 * The bytes not provided would be due to the available output space
 * having being consumed. The number of bits of output not provided are
 * between 0 and 7, where they await more bits to join them in order to
 * fill out a full byte. If pending or bits are Z_NULL, then those
 * values are not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int deflatePending(z_streamp strm, unsigned *pending, int *bits);

/**
 * deflatePrime() inserts bits in the deflate output stream.  The intent
 * is that this function is used to start off the deflate output with the bits
 * leftover from a previous deflate stream when appending to it.  As such, this
 * function can only be used for raw deflate, and must be used before the first
 * deflate() call after a deflateInit2() or deflateReset().  bits must be less
 * than or equal to 16, and that many of the least significant bits of value
 * will be inserted in the output.
 *
 * @return Z_OK if success, Z_BUF_ERROR if there was not enough room in
 *     the internal buffer to insert the bits, or Z_STREAM_ERROR if the
 *     source stream state was inconsistent.
 */
int deflatePrime(z_streamp strm, int bits, int value);

/**
 * Provides gzip header information for when a gzip stream is requested
 * by deflateInit2(). deflateSetHeader() may be called after
 * deflateInit2() or deflateReset() and before the first call of
 * deflate(). The text, time, os, extra field, name, and comment
 * information in the provided gz_header structure are written to the
 * gzip header (xflag is ignored -- the extra flags are set according to
 * the compression level). The caller must assure that, if not Z_NULL,
 * name and comment are terminated with a zero byte, and that if extra
 * is not Z_NULL, that extra_len bytes are available there. If hcrc is
 * true, a gzip header crc is included. Note that the current versions
 * of the command-line version of gzip (up through version 1.3.x) do not
 * support header crc's, and will report that it is a "multi-part gzip
 * file" and give up.
 *
 * If deflateSetHeader is not used, the default gzip header has text
 * false, the time set to zero, and os set to 255, with no extra, name,
 * or comment fields. The gzip header is returned to the default state
 * by deflateReset().
 *
 * deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the
 * source stream state was inconsistent.
 */
int deflateSetHeader(z_streamp strm, gz_headerp head);

/**
 * This is another version of inflateInit with an extra parameter. The
 * fields next_in, avail_in, zalloc, zfree and opaque must be
 * initialized before by the caller.
 *
 * The windowBits parameter is the base two logarithm of the maximum
 * window size (the size of the history buffer). It should be in the
 * range 8..15 for this version of the library. The default value is 15
 * if inflateInit is used instead. windowBits must be greater than or
 * equal to the windowBits value provided to deflateInit2() while
 * compressing, or it must be equal to 15 if deflateInit2() was not
 * used. If a compressed stream with a larger window size is given as
 * input, inflate() will return with the error code Z_DATA_ERROR instead
 * of trying to allocate a larger window.
 *
 * windowBits can also be zero to request that inflate use the window
 * size in the zlib header of the compressed stream.
 *
 * windowBits can also be -8..-15 for raw inflate. In this case,
 * -windowBits determines the window size. inflate() will then process
 * raw deflate data, not looking for a zlib or gzip header, not
 * generating a check value, and not looking for any check values for
 * comparison at the end of the stream. This is for use with other
 * formats that use the deflate compressed data format such as zip.
 * Those formats provide their own check values. If a custom format is
 * developed using the raw deflate format for compressed data, it is
 * recommended that a check value such as an Adler-32 or a CRC-32 be
 * applied to the uncompressed data as is done in the zlib, gzip, and
 * zip formats. For most applications, the zlib format should be used as
 * is. Note that comments above on the use in deflateInit2() applies to
 * the magnitude of windowBits.
 *
 * windowBits can also be greater than 15 for optional gzip decoding.
 * Add 32 to windowBits to enable zlib and gzip decoding with automatic
 * header detection, or add 16 to decode only the gzip format (the zlib
 * format will return a Z_DATA_ERROR). If a gzip stream is being
 * decoded, strm->adler is a CRC-32 instead of an Adler-32. Unlike the
 * gunzip utility and gzread() (see below), inflate() will not
 * automatically decode concatenated gzip streams. inflate() will return
 * Z_STREAM_END at the end of the gzip stream. The state would need to
 * be reset to continue decoding a subsequent gzip stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit2 does not perform any decompression apart
 *     from possibly reading the zlib header if present: actual
 *     decompression will be done by inflate(). (So next_in and avail_in
 *     may be modified, but next_out and avail_out are unused and
 *     unchanged.) The current implementation of inflateInit2() does not
 *     process any header information -- that is deferred until
 *     inflate() is called.
 */
int inflateInit2(z_streamp strm, int windowBits);

/**
 * Initializes the decompression dictionary from the given uncompressed
 * byte sequence. This function must be called immediately after a call
 * of inflate, if that call returned Z_NEED_DICT. The dictionary chosen
 * by the compressor can be determined from the Adler-32 value returned
 * by that call of inflate. The compressor and decompressor must use
 * exactly the same dictionary (see deflateSetDictionary). For raw
 * inflate, this function can be called at any time to set the
 * dictionary. If the provided dictionary is smaller than the window and
 * there is already data in the window, then the provided dictionary
 * will amend what's there. The application must insure that the
 * dictionary that was used for compression is provided.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent, Z_DATA_ERROR if the given dictionary doesn't match
 *     the expected one (incorrect Adler-32 value). inflateSetDictionary
 *     does not perform any decompression: this will be done by
 *     subsequent calls of inflate().
 */
int inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by inflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If inflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Skips invalid compressed data until a possible full flush point (see
 * above for the description of deflate with Z_FULL_FLUSH) can be found,
 * or until all available input is skipped. No output is provided.
 *
 * inflateSync searches for a 00 00 FF FF pattern in the compressed
 * data. All full flush points have this pattern, but not all
 * occurrences of this pattern are full flush points.
 *
 * @return Z_OK if a possible full flush point has been found,
 *     Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no
 *     flush point has been found, or Z_STREAM_ERROR if the stream
 *     structure was inconsistent. In the success case, the application
 *     may save the current current value of total_in which indicates
 *     where valid compressed data was found. In the error case, the
 *     application may repeatedly call inflateSync, providing more input
 *     each time, until success or end of the input data.
 */
int inflateSync(z_streamp strm);

/**
 * Sets the destination stream as a complete copy of the source stream.
 *
 * This function can be useful when randomly accessing a large stream.
 * The first pass through the stream can periodically record the inflate
 * state, allowing restarting inflate at those points when randomly
 * accessing the stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int inflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to inflateEnd followed by inflateInit,
 * but does not free and reallocate the internal decompression state.  The
 * stream will keep attributes that may have been set by inflateInit2.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL).
 */
int inflateReset(z_streamp strm);

/**
 * This function is the same as inflateReset, but it also permits changing
 * the wrap and window size requests.  The windowBits parameter is interpreted
 * the same as it is for inflateInit2.  If the window size is changed, then the
 * memory allocated for the window is freed, and the window will be reallocated
 * by inflate() if needed.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL), or if
 *     the windowBits parameter is invalid.
 */
int inflateReset2(z_streamp strm, int windowBits);

/**
 * This function inserts bits in the inflate input stream.  The intent is
 * that this function is used to start inflating at a bit position in the
 * middle of a byte.  The provided bits will be used before any bytes are used
 * from next_in.  This function should only be used with raw inflate, and
 * should be used before the first inflate() call after inflateInit2() or
 * inflateReset().  bits must be less than or equal to 16, and that many of the
 * least significant bits of value will be inserted in the input.
 *
 * If bits is negative, then the input stream bit buffer is emptied.  Then
 * inflatePrime() can be called again to put bits in the buffer.  This is used
 * to clear out bits leftover after feeding inflate a block description prior
 * to feeding inflate codes.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflatePrime(z_streamp strm, int bits, int value);

/**
 * Returns two values, one in the lower 16 bits of the return value, and
 * the other in the remaining upper bits, obtained by shifting the
 * return value down 16 bits. If the upper value is -1 and the lower
 * value is zero, then inflate() is currently decoding information
 * outside of a block. If the upper value is -1 and the lower value is
 * non-zero, then inflate is in the middle of a stored block, with the
 * lower value equaling the number of bytes from the input remaining to
 * copy. If the upper value is not -1, then it is the number of bits
 * back from the current bit position in the input of the code (literal
 * or length/distance pair) currently being processed. In that case the
 * lower value is the number of bytes already emitted for that code.
 *
 * A code is being processed if inflate is waiting for more input to
 * complete decoding of the code, or if it has completed decoding but is
 * waiting for more output space to write the literal or match data.
 *
 * inflateMark() is used to mark locations in the input data for random
 * access, which may be at bit positions, and to note those cases where
 * the output of a code may span boundaries of random access blocks. The
 * current location in the input stream can be determined from avail_in
 * and data_type as noted in the description for the Z_BLOCK flush
 * parameter for inflate.
 *
 * @return the value noted above, or -65536 if the provided source
 *     stream state was inconsistent.
 */
long inflateMark(z_streamp strm);

/**
 * inflateGetHeader() requests that gzip header information be stored in
 * the provided gz_header structure. inflateGetHeader() may be called
 * after inflateInit2() or inflateReset(), and before the first call of
 * inflate(). As inflate() processes the gzip stream, head->done is zero
 * until the header is completed, at which time head->done is set to
 * one. If a zlib stream is being decoded, then head->done is set to -1
 * to indicate that there will be no gzip header information
 * forthcoming. Note that Z_BLOCK or Z_TREES can be used to force
 * inflate() to return immediately after header processing is complete
 * and before any actual data is decompressed.
 *
 * The text, time, xflags, and os fields are filled in with the gzip
 * header contents. hcrc is set to true if there is a header CRC. (The
 * header CRC was valid if done is set to one.) If extra is not Z_NULL,
 * then extra_max contains the maximum number of bytes to write to
 * extra. Once done is true, extra_len contains the actual extra field
 * length, and extra contains the extra field, or that field truncated
 * if extra_max is less than extra_len. If name is not Z_NULL, then up
 * to name_max characters are written there, terminated with a zero
 * unless the length is greater than name_max. If comment is not Z_NULL,
 * then up to comm_max characters are written there, terminated with a
 * zero unless the length is greater than comm_max. When any of extra,
 * name, or comment are not Z_NULL and the respective field is not
 * present in the header, then that field is set to Z_NULL to signal its
 * absence. This allows the use of deflateSetHeader() with the returned
 * structure to duplicate the header. However if those fields are set to
 * allocated memory, then the application will need to save those
 * pointers elsewhere so that they can be eventually freed.
 *
 * If inflateGetHeader is not used, then the header information is
 * simply discarded. The header is always checked for validity,
 * including the header CRC if present. inflateReset() will reset the
 * process to discard the header information. The application would need
 * to call inflateGetHeader() again to retrieve the header from the next
 * gzip stream.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflateGetHeader(z_streamp strm, gz_headerp head);

/**
 * Initialize internal stream state for decompression using
 * inflateBack() calls. The fields zalloc, zfree and opaque in strm must
 * be initialized before the call. If zalloc and zfree are Z_NULL, then
 * the default library- derived memory allocation routines are used.
 * windowBits is the base two logarithm of the window size, in the range
 * 8..15. window is a caller supplied buffer of that size. Except for
 * special applications where it is assured that deflate was used with
 * small window sizes, windowBits must be 15 and a 32K byte window must
 * be supplied to be able to decompress general deflate streams.
 *
 * See inflateBack() for the usage of these routines.
 *
 * @return Z_OK on success, Z_STREAM_ERROR if any of the parameters are
 *     invalid, or Z_MEM_ERROR if the internal state could not be
 *     allocated.
 */
int inflateBackInit(z_streamp strm, int windowBits, unsigned char *window);

typedef unsigned (*in_func)(void *, const unsigned char **);
typedef int (*out_func)(void *, unsigned char *, unsigned);

/**
 * inflateBack() does a raw inflate with a single call using a call-back
 * interface for input and output. This is potentially more efficient
 * than inflate() for file i/o applications, in that it avoids copying
 * between the output and the sliding window by simply making the window
 * itself the output buffer. inflate() can be faster on modern CPUs when
 * used with large buffers. inflateBack() trusts the application to not
 * change the output buffer passed by the output function, at least
 * until inflateBack() returns.
 *
 * inflateBackInit() must be called first to allocate the internal state
 * and to initialize the state with the user-provided window buffer.
 * inflateBack() may then be used multiple times to inflate a complete,
 * raw deflate stream with each call. inflateBackEnd() is then called to
 * free the allocated state.
 *
 * A raw deflate stream is one with no zlib or gzip header or trailer.
 * This routine would normally be used in a utility that reads zip or
 * gzip files and writes out uncompressed files. The utility would
 * decode the header and process the trailer on its own, hence this
 * routine expects only the raw deflate stream to decompress. This is
 * different from the default behavior of inflate(), which expects a
 * zlib header and trailer around the deflate stream.
 *
 * inflateBack() uses two subroutines supplied by the caller that are
 * then called by inflateBack() for input and output. inflateBack()
 * calls those routines until it reads a complete deflate stream and
 * writes out all of the uncompressed data, or until it encounters an
 * error. The function's parameters and return types are defined above
 * in the in_func and out_func typedefs. inflateBack() will call
 * in(in_desc, &buf) which should return the number of bytes of provided
 * input, and a pointer to that input in buf. If there is no input
 * available, in() must return zero -- buf is ignored in that case --
 * and inflateBack() will return a buffer error. inflateBack() will call
 * out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
 * out() should return zero on success, or non-zero on failure. If out()
 * returns non-zero, inflateBack() will return with an error. Neither
 * in() nor out() are permitted to change the contents of the window
 * provided to inflateBackInit(), which is also the buffer that out()
 * uses to write from. The length written by out() will be at most the
 * window size. Any non-zero amount of input may be provided by in().
 *
 * For convenience, inflateBack() can be provided input on the first
 * call by setting strm->next_in and strm->avail_in. If that input is
 * exhausted, then in() will be called. Therefore strm->next_in must be
 * initialized before calling inflateBack(). If strm->next_in is Z_NULL,
 * then in() will be called immediately for input. If strm->next_in is
 * not Z_NULL, then strm->avail_in must also be initialized, and then if
 * strm->avail_in is not zero, input will initially be taken from
 * strm->next_in[0 .. strm->avail_in - 1].
 *
 * The in_desc and out_desc parameters of inflateBack() is passed as the
 * first parameter of in() and out() respectively when they are called.
 * These descriptors can be optionally used to pass any information that
 * the caller- supplied in() and out() functions need to do their job.
 *
 * On return, inflateBack() will set strm->next_in and strm->avail_in to
 * pass back any unused input that was provided by the last in() call.
 * The return values of inflateBack() can be Z_STREAM_END on success,
 * Z_BUF_ERROR if in() or out() returned an error, Z_DATA_ERROR if there
 * was a format error in the deflate stream (in which case strm->msg is
 * set to indicate the nature of the error), or Z_STREAM_ERROR if the
 * stream was not properly initialized. In the case of Z_BUF_ERROR, an
 * input or output error can be distinguished using strm->next_in which
 * will be Z_NULL only if in() returned an error. If strm->next_in is
 * not Z_NULL, then the Z_BUF_ERROR was due to out() returning non-zero.
 * (in() will always be called before out(), so strm->next_in is assured
 * to be defined if out() returns non-zero.) Note that inflateBack()
 * cannot return Z_OK.
 */
int inflateBack(z_streamp strm, in_func in, void *in_desc, out_func out,
                void *out_desc);

/**
 * All memory allocated by inflateBackInit() is freed.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state was
 *     inconsistent.
 */
int inflateBackEnd(z_streamp strm);

/*
 * Return flags indicating compile-time options.
 *
 * Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
 *   1.0: size of uInt
 *   3.2: size of uLong
 *   5.4: size of voidpf (pointer)
 *   7.6: size of off_t
 *
 * Compiler, assembler, and debug options:
 *   8: ZLIB_DEBUG
 *   9: ASMV or ASMINF -- use ASM code
 *   10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
 *   11: 0 (reserved)
 *
 * One-time table building (smaller code, but not thread-safe if true):
 *   12: BUILDFIXED -- build static block decoding tables when needed
 *   13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
 *   14,15: 0 (reserved)
 *
 * Library content (indicates missing functionality):
 *
 *   16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
 *   deflate code when not needed)
 *
 *   17: NO_GZIP -- deflate can't write gzip streams, and inflate can't
 *   detect and decode gzip streams (to avoid linking crc code)
 *
 *   18-19: 0 (reserved)
 *
 * Operation variations (changes in library functionality):
 *   20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
 *   21: FASTEST -- deflate algorithm with only one, lowest compression level
 *   22,23: 0 (reserved)
 *
 * The sprintf variant used by gzprintf (zero is best):
 *   24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
 *   25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
 *   26: 0 = returns value, 1 = void -- 1 means inferred string length returned
 *
 * Remainder is:
 *   27-31: 0 (reserved)
 */
uLong zlibCompileFlags(void);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » utility functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  The following utility functions are implemented on top of the basic
  stream-oriented functions. To simplify the interface, some default
  options are assumed (compression level and memory usage, standard
  memory allocation functions). The source code of these utility
  functions can be modified if you need special options. */

/**
 * Compresses source buffer into the destination buffer. sourceLen is
 * the byte length of the source buffer. Upon entry, destLen is the
 * total size of the destination buffer, which must be at least the
 * value returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data. compress() is equivalent to
 * compress2() with a level parameter of Z_DEFAULT_COMPRESSION.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer.
 */
int compress(Bytef *dest, uLongf *destLen, const Bytef *source,
             uLong sourceLen);

/**
 * Compresses source buffer into the destination buffer. The level
 * parameter has the same meaning as in deflateInit. sourceLen is the
 * byte length of the source buffer. Upon entry, destLen is the total
 * size of the destination buffer, which must be at least the value
 * returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer,
 *     Z_STREAM_ERROR if the level parameter is invalid.
 */
int compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
              uLong sourceLen, int level);

/**
 * Returns an upper bound on the compressed size after compress() or
 * compress2() on sourceLen bytes. It would be used before a compress()
 * or compress2() call to allocate the destination buffer.
 */
uLong compressBound(uLong sourceLen);

/**
 * Decompresses the source buffer into the destination buffer.  sourceLen is
 * the byte length of the source buffer.  Upon entry, destLen is the total size
 * of the destination buffer, which must be large enough to hold the entire
 * uncompressed data.  (The size of the uncompressed data must have been saved
 * previously by the compressor and transmitted to the decompressor by some
 * mechanism outside the scope of this compression library.) Upon exit, destLen
 * is the actual size of the uncompressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer, or
 *     Z_DATA_ERROR if the input data was corrupted or incomplete. In
 *     the case where there is not enough room, uncompress() will fill
 *     the output buffer with the uncompressed data up to that point.
 */
int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
               uLong sourceLen);

/**
 * Same as uncompress, except that sourceLen is a pointer, where the
 * length of the source is *sourceLen.  On return, *sourceLen is the number of
 * source bytes consumed.
 */
int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
                uLong *sourceLen);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » gzip                                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  This library supports reading and writing files in gzip (.gz) format
  with an interface similar to that of stdio, using the functions that
  start with "gz". The gzip format is different from the zlib format.
  gzip is a gzip wrapper, documented in RFC 1952, wrapped around a
  deflate stream. */

typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */

/**
 * Opens a gzip (.gz) file for reading or writing.
 *
 * The mode parameter is as in fopen ("rb" or "wb") but can also include
 * a compression level ("wb9") or a strategy: 'f' for filtered data as
 * in "wb6f", 'h' for Huffman-only compression as in "wb1h", 'R' for
 * run-length encoding as in "wb1R", or 'F' for fixed code compression
 * as in "wb9F". (See the description of deflateInit2 for more
 * information about the strategy parameter.) 'T' will request
 * transparent writing or appending with no compression and not using
 * the gzip format.
 *
 * "a" can be used instead of "w" to request that the gzip stream that
 * will be written be appended to the file. "+" will result in an error,
 * since reading and writing to the same gzip file is not supported. The
 * addition of "x" when writing will create the file exclusively, which
 * fails if the file already exists. On systems that support it, the
 * addition of "e" when reading or writing will set the flag to close
 * the file on an execve() call.
 *
 * These functions, as well as gzip, will read and decode a sequence of
 * gzip streams in a file. The append function of gzopen() can be used
 * to create such a file. (Also see gzflush() for another way to do
 * this.) When appending, gzopen does not test whether the file begins
 * with a gzip stream, nor does it look for the end of the gzip streams
 * to begin appending. gzopen will simply append a gzip stream to the
 * existing file.
 *
 * gzopen can be used to read a file which is not in gzip format; in
 * this case gzread will directly read from the file without
 * decompression. When reading, this will be detected automatically by
 * looking for the magic two- byte gzip header.
 *
 * @return Z_OK if the file could not be opened, if there was insufficient
 *     memory to allocate the gzFile state, or if an invalid mode was
 *     specified (an 'r', 'w', or 'a' was not provided, or '+' was
 *     provided). errno can be checked to determine if the reason gzopen
 *     failed was that the file could not be opened.
 */
gzFile gzopen(const char *path, const char *mode);

/**
 * Associates gzFile with the file descriptor.
 *
 * File descriptors are obtained from calls like open, dup, creat, pipe
 * or fileno (if the file has been previously opened with fopen). The
 * mode parameter is as in gzopen.
 *
 * The next call of gzclose on the returned gzFile will also close the file
 * descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
 * fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
 * mode);.  The duplicated descriptor should be saved to avoid a leak, since
 * gzdopen does not close fd if it fails.  If you are using fileno() to get the
 * file descriptor from a FILE *, then you will have to use dup() to avoid
 * double-close()ing the file descriptor.  Both gzclose() and fclose() will
 * close the associated file descriptor, so they need to have different file
 * descriptors.
 *
 * @return Z_OK if there was insufficient memory to allocate the gzFile
 *     state, if an invalid mode was specified (an 'r', 'w', or 'a' was
 *     not provided, or '+' was provided), or if fd is -1. The file
 *     descriptor is not used until the next gz* read, write, seek, or
 *     close operation, so gzdopen will not detect if fd is invalid
 *     (unless fd is -1).
 */
gzFile gzdopen(int fd, const char *mode);

/**
 * Sets internal buffer size used by this library's functions. The
 * default buffer size is 8192 bytes. This function must be called after
 * gzopen() or gzdopen(), and before any other calls that read or write
 * the file. The buffer memory allocation is always deferred to the
 * first read or write. Three times that size in buffer space is
 * allocated. A larger buffer size of, for example, 64K or 128K bytes
 * will noticeably increase the speed of decompression (reading).
 *
 * The new buffer size also affects the maximum length for gzprintf().
 *
 * @return Z_OK on success, or -1 on failure, such as being called too
 *     late.
 */
int gzbuffer(gzFile file, unsigned size);

/**
 * Dynamically update the compression level or strategy.  See the description
 * of deflateInit2 for the meaning of these parameters.  Previously provided
 * data is flushed before the parameter change.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the file was not opened for
 *     writing, Z_ERRNO if there is an error writing the flushed data,
 *     or Z_MEM_ERROR if there is a memory allocation error.
 */
int gzsetparams(gzFile file, int level, int strategy);

/**
 * Reads given number of uncompressed bytes from the compressed file. If
 * the input file is not in gzip format, gzread copies the given number
 * of bytes into the buffer directly from the file.
 *
 * After reaching the end of a gzip stream in the input, gzread will continue
 * to read, looking for another gzip stream.  Any number of gzip streams may be
 * concatenated in the input file, and will all be decompressed by gzread().
 * If something other than a gzip stream is encountered after a gzip stream,
 * that remaining trailing garbage is ignored (and no error is returned).
 *
 * gzread can be used to read a gzip file that is being concurrently written.
 * Upon reaching the end of the input, gzread will return with the available
 * data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
 * gzclearerr can be used to clear the end of file indicator in order to permit
 * gzread to be tried again.  Z_OK indicates that a gzip stream was completed
 * on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
 * middle of a gzip stream.  Note that gzread does not return -1 in the event
 * of an incomplete gzip stream.  This error is deferred until gzclose(), which
 * will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
 * stream.  Alternatively, gzerror can be used before gzclose to detect this
 * case.
 *
 * @return Z_OK number of uncompressed bytes actually read, less than
 *     len for end of file, or -1 for error. If len is too large to fit
 *     in an int, then nothing is read, -1 is returned, and the error
 *     state is set to Z_STREAM_ERROR.
 */
int gzread(gzFile file, voidp buf, unsigned len);

/**
 * Read up to nitems items of size size from file to buf, otherwise operating
 * as gzread() does.  This duplicates the interface of stdio's fread(), with
 * size_t request and return types.  If the library defines size_t, then
 * size_t is identical to size_t.  If not, then size_t is an unsigned
 * integer type that can contain a pointer.
 *
 * gzfread() returns the number of full items read of size size, or zero if
 * the end of the file was reached and a full item could not be read, or if
 * there was an error.  gzerror() must be consulted if zero is returned in
 * order to determine if there was an error.  If the multiplication of size and
 * nitems overflows, i.e. the product does not fit in a size_t, then nothing
 * is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
 *
 * In the event that the end of file is reached and only a partial item is
 * available at the end, i.e. the remaining uncompressed data length is not a
 * multiple of size, then the final partial item is nevetheless read into buf
 * and the end-of-file flag is set.  The length of the partial item read is not
 * provided, but could be inferred from the result of gztell().  This behavior
 * is the same as the behavior of fread() implementations in common libraries,
 * but it prevents the direct use of gzfread() to read a concurrently written
 * file, reseting and retrying on end-of-file, when size is not 1.
 */
size_t gzfread(voidp buf, size_t size, size_t nitems, gzFile file);

/**
 * Writes given number of uncompressed bytes into the compressed file.
 * gzwrite returns the number of uncompressed bytes written or 0 in case
 * of error.
 */
int gzwrite(gzFile file, voidpc buf, unsigned len);

/**
 * Writes nitems items of size size from buf to file, duplicating the
 * interface of stdio's fwrite(), with size_t request and return types.
 * If the library defines size_t, then size_t is identical to size_t. If
 * not, then size_t is an unsigned integer type that can contain a
 * pointer.
 *
 * gzfwrite() returns the number of full items written of size size, or zero
 * if there was an error.  If the multiplication of size and nitems overflows,
 * i.e. the product does not fit in a size_t, then nothing is written, zero
 * is returned, and the error state is set to Z_STREAM_ERROR.
 */
size_t gzfwrite(voidpc buf, size_t size, size_t nitems, gzFile file);

/**
 * Converts, formats, and writes the arguments to the compressed file
 * under control of the format string, as in fprintf. gzprintf returns
 * the number of uncompressed bytes actually written, or a negative zlib
 * error code in case of error. The number of uncompressed bytes written
 * is limited to 8191, or one less than the buffer size given to
 * gzbuffer(). The caller should assure that this limit is not exceeded.
 * If it is exceeded, then gzprintf() will return an error (0) with
 * nothing written. In this case, there may also be a buffer overflow
 * with unpredictable consequences, which is possible only if zlib was
 * compiled with the insecure functions sprintf() or vsprintf() because
 * the secure snprintf() or vsnprintf() functions were not available.
 * This can be determined using zlibCompileFlags().
 */
int gzprintf(gzFile file, const char *format, ...);

/**
 * Writes the given null-terminated string to the compressed file, excluding
 * the terminating null character.
 *
 * @return Z_OK number of characters written, or -1 in case of error.
 */
int gzputs(gzFile file, const char *s);

/**
 * Reads bytes from the compressed file until len-1 characters are read,
 * or a newline character is read and transferred to buf, or an
 * end-of-file condition is encountered. If any characters are read or
 * if len == 1, the string is terminated with a null character. If no
 * characters are read due to an end-of-file or len < 1, then the buffer
 * is left untouched.
 *
 * @return buf which is a null-terminated string, or it returns NULL for
 *     end-of-file or in case of error. If there was an error, the
 *     contents at buf are indeterminate.
 */
char *gzgets(gzFile file, char *buf, int len);

/**
 * Writes character converted to an unsigned char into compressed file.
 * @return value that was written, or -1 on error
 */
int gzputc(gzFile file, int c);

/**
 * Reads one byte from the compressed file. gzgetc returns this byte or
 * -1 in case of end of file or error. This is implemented as a macro
 * for speed. As such, it does not do all of the checking the other
 * functions do. I.e. it does not check to see if file is NULL, nor
 * whether the structure file points to has been clobbered or not.
 */
int gzgetc(gzFile file);

/**
 * Pushes one character back onto the stream to be read as the first
 * character on the next read. At least one character of push-back is
 * allowed. gzungetc() returns the character pushed, or -1 on failure.
 * gzungetc() will fail if c is -1, and may fail if a character has been
 * pushed but not read yet. If gzungetc is used immediately after gzopen
 * or gzdopen, at least the output buffer size of pushed characters is
 * allowed. (See gzbuffer above.) The pushed character will be discarded
 * if the stream is repositioned with gzseek() or gzrewind().
 */
int gzungetc(int c, gzFile file);

/**
 * Flushes all pending output into the compressed file. The parameter
 * flush is as in the deflate() function. The return value is the zlib
 * error number (see function gzerror below). gzflush is only permitted
 * when writing.
 *
 * If the flush parameter is Z_FINISH, the remaining data is written and
 * the gzip stream is completed in the output. If gzwrite() is called
 * again, a new gzip stream will be started in the output. gzread() is
 * able to read such concatenated gzip streams.
 *
 * gzflush should be called only when strictly necessary because it will
 * degrade compression if called too often.
 */
int gzflush(gzFile file, int flush);

/**
 * Sets starting position for the next gzread or gzwrite on the given
 * compressed file. The offset represents a number of bytes in the
 * uncompressed data stream. The whence parameter is defined as in
 * lseek(2); the value SEEK_END is not supported.
 *
 * If the file is opened for reading, this function is emulated but can be
 * extremely slow.  If the file is opened for writing, only forward seeks are
 * supported; gzseek then compresses a sequence of zeroes up to the new
 * starting position.
 *
 * @return resulting offset location as measured in bytes from the
 *     beginning of the uncompressed stream, or -1 in case of error, in
 *     particular if the file is opened for writing and the new starting
 *     position would be before the current position.
 */
ssize_t gzseek(gzFile file, int64_t offset, int whence);

/**
 * Rewinds file.
 *
 * This function is supported only for reading.
 *
 * @note gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
 */
int gzrewind(gzFile file);

/**
 * Returns starting position for the next gzread or gzwrite on the given
 * compressed file. This position represents a number of bytes in the
 * uncompressed data stream, and is zero when starting, even if
 * appending or reading a gzip stream from the middle of a file using
 * gzdopen().
 *
 * @note gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 */
ssize_t gztell(gzFile file);

/**
 * Returns current offset in the file being read or written. This offset
 * includes the count of bytes that precede the gzip stream, for example
 * when appending or when using gzdopen() for reading. When reading, the
 * offset does not include as yet unused buffered input. This
 * information can be used for a progress indicator. On error,
 * gzoffset() returns -1.
 */
ssize_t gzoffset(gzFile file);

/**
 * Returns true (1) if the end-of-file indicator has been set while
 * reading, false (0) otherwise. Note that the end-of-file indicator is
 * set only if the read tried to go past the end of the input, but came
 * up short. Therefore, just like feof(), gzeof() may return false even
 * if there is no more data to read, in the event that the last read
 * request was for the exact number of bytes remaining in the input
 * file. This will happen if the input file size is an exact multiple of
 * the buffer size.
 *
 * If gzeof() returns true, then the read functions will return no more
 * data, unless the end-of-file indicator is reset by gzclearerr() and
 * the input file has grown since the previous end of file was detected.
 */
int gzeof(gzFile file);

/**
 * Returns true (1) if file is being copied directly while reading, or
 * false (0) if file is a gzip stream being decompressed.
 *
 * If the input file is empty, gzdirect() will return true, since the
 * input does not contain a gzip stream.
 *
 * If gzdirect() is used immediately after gzopen() or gzdopen() it will
 * cause buffers to be allocated to allow reading the file to determine
 * if it is a gzip file. Therefore if gzbuffer() is used, it should be
 * called before gzdirect().
 *
 * When writing, gzdirect() returns true (1) if transparent writing was
 * requested ("wT" for the gzopen() mode), or false (0) otherwise.
 * (Note: gzdirect() is not needed when writing. Transparent writing
 * must be explicitly requested, so the application already knows the
 * answer. When linking statically, using gzdirect() will include all of
 * the zlib code for gzip file reading and decompression, which may not
 * be desired.)
 */
int gzdirect(gzFile file);

/**
 * Flushes all pending output if necessary, closes the compressed file
 * and deallocates the (de)compression state. Note that once file is
 * closed, you cannot call gzerror with file, since its structures have
 * been deallocated. gzclose must not be called more than once on the
 * same file, just as free must not be called more than once on the same
 * allocation.
 *
 * @return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a file
 *     operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
 *     last read ended in the middle of a gzip stream, or Z_OK on
 *     success.
 */
int gzclose(gzFile file);

/**
 * Same as gzclose(), but gzclose_r() is only for use when reading, and
 * gzclose_w() is only for use when writing or appending. The advantage
 * to using these instead of gzclose() is that they avoid linking in
 * zlib compression or decompression code that is not used when only
 * reading or only writing respectively. If gzclose() is used, then both
 * compression and decompression code will be included the application
 * when linking to a static zlib library.
 */
int gzclose_r(gzFile file);
int gzclose_w(gzFile file);

/**
 * Returns the error message for the last error which occurred on the given
 * compressed file.  errnum is set to zlib error number.  If an error occurred
 * in the file system and not in the compression library, errnum is set to
 * Z_ERRNO and the application may consult errno to get the exact error code.
 *
 * The application must not modify the returned string.  Future calls to
 * this function may invalidate the previously returned string.  If file is
 * closed, then the string previously returned by gzerror will no longer be
 * available.
 *
 * gzerror() should be used to distinguish errors from end-of-file for those
 * functions above that do not distinguish those cases in their return values.
 */
const char *gzerror(gzFile file, int *errnum);

/**
 * Clears the error and end-of-file flags for file.  This is analogous to the
 * clearerr() function in stdio.  This is useful for continuing to read a gzip
 * file that is being written concurrently.
 */
void gzclearerr(gzFile file);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » checksums                                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/**
 * Updates running Adler-32 checksum with the bytes buf[0..len-1] and
 * return the updated checksum. If buf is Z_NULL, this function returns
 * the required initial value for the checksum.
 */
uLong adler32(uLong adler, const Bytef *buf, uInt len);

/**
 * Same as adler32(), but with a size_t length.
 */
uLong adler32_z(uLong adler, const Bytef *buf, size_t len);

/**
 * Combine two Adler-32 checksums into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were
 * calculated for each, adler1 and adler2. adler32_combine() returns the
 * Adler-32 checksum of seq1 and seq2 concatenated, requiring only
 * adler1, adler2, and len2. Note that the off_t type (like off_t) is a
 * signed integer. If len2 is negative, the result has no meaning or
 * utility.
 */
uLong adler32_combine(uLong adler1, uLong adler2, int64_t len2);

/**
 * Update a running CRC-32 with the bytes buf[0..len-1] and return the
 * updated CRC-32.  If buf is Z_NULL, this function returns the required
 * initial value for the crc.  Pre- and post-conditioning (one's complement) is
 * performed within this function so it shouldn't be done by the application.
 *
 * Usage example:
 *
 *     uLong crc = crc32(0L, Z_NULL, 0);
 *     while (read_buffer(buffer, length) != EOF) {
 *       crc = crc32(crc, buffer, length);
 *     }
 *     if (crc != original_crc) error();
 */
uLong crc32(uLong crc, const Bytef *buf, uInt len);

/**
 * Same as crc32(), but with a size_t length.
 */
uint32_t crc32_z(uint32_t crc, const void *buf, size_t len);

/**
 * Combine two CRC-32 check values into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
 * calculated for each, crc1 and crc2. crc32_combine() returns the
 * CRC-32 check value of seq1 and seq2 concatenated, requiring only
 * crc1, crc2, and len2.
 */
uLong crc32_combine(uLong crc1, uLong crc2, int64_t len2);

/**
 * gzgetc() macro and its supporting function and exposed data
 * structure. Note that the real internal state is much larger than the
 * exposed structure. This abbreviated structure exposes just enough for
 * the gzgetc() macro. The user should not mess with these exposed
 * elements, since their names or behavior could change in the future,
 * perhaps even capriciously. They can only be used by the gzgetc()
 * macro. You have been warned.
 */
struct gzFile_s {
  unsigned have;
  unsigned char *next;
  int64_t pos;
};

int gzgetc_(gzFile file); /* backward compatibility */
#ifdef Z_PREFIX_SET
#undef z_gzgetc
#define z_gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#elif defined(Z_COSMO_PREFIX_SET)
#undef gzgetc
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (__gzgetc)(g))
#else
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#endif

/* undocumented functions */
const char *zError(int);
int inflateSyncPoint(z_streamp);
int inflateUndermine(z_streamp, int);
int inflateValidate(z_streamp, int);
unsigned long inflateCodesUsed(z_streamp);
int inflateResetKeep(z_streamp);
int deflateResetKeep(z_streamp);
int gzvprintf(gzFile file, const char *format, va_list va);
void inflate_fast_chunk(z_streamp strm, unsigned start);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/regex/regex.h */

#define COSMOPOLITAN_LIBC_REGEX_REGEX_H_
COSMOPOLITAN_C_START_

#if 0
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § regular expressions                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
#endif

#define REG_EXTENDED 1
#define REG_ICASE    2
#define REG_NEWLINE  4
#define REG_NOSUB    8

#define REG_NOTBOL 1 /* ^ should not match beginning of string */
#define REG_NOTEOL 2 /* $ should not match end of string */

#define REG_OK       0
#define REG_NOMATCH  1
#define REG_BADPAT   2
#define REG_ECOLLATE 3
#define REG_ECTYPE   4
#define REG_EESCAPE  5
#define REG_ESUBREG  6
#define REG_EBRACK   7
#define REG_EPAREN   8
#define REG_EBRACE   9
#define REG_BADBR    10
#define REG_ERANGE   11
#define REG_ESPACE   12
#define REG_BADRPT   13

#define REG_ENOSYS -1

typedef long regoff_t;

struct PosixRegex {
  size_t re_nsub;
  void *__opaque, *__padding[4];
  size_t __nsub2;
  char __padding2;
};

struct PosixRegexMatch {
  regoff_t rm_so;
  regoff_t rm_eo;
};

typedef struct PosixRegex regex_t;
typedef struct PosixRegexMatch regmatch_t;

int regcomp(regex_t *, const char *, int);
int regexec(const regex_t *, const char *, size_t, regmatch_t *, int);
size_t regerror(int, const regex_t *, char *, size_t);
void regfree(regex_t *);

COSMOPOLITAN_C_END_

#endif /* COSMOPOLITAN_H_ */
#ifndef COSMOPOLITAN_H_
#define COSMOPOLITAN_H_


/*!BEGIN libc/integral/normalize.inc */

#ifdef __COSMOPOLITAN__
#undef __COSMOPOLITAN__
#endif

#define __COSMOPOLITAN_MAJOR__ 3
#define __COSMOPOLITAN_MINOR__ 3
#define __COSMOPOLITAN_PATCH__ 10
#define __COSMOPOLITAN__                                                   \
  (100000000 * __COSMOPOLITAN_MAJOR__ + 1000000 * __COSMOPOLITAN_MINOR__ + \
   __COSMOPOLITAN_PATCH__)

#ifndef __COUNTER__
#define __COUNTER__ __LINE__
#endif

#if __GNUC__ + 0 < 2
#undef __GNUC__
#elif defined(__GNUC__) && defined(SWIG) /* lool */
#undef __GNUC__
#elif defined(__GNUC__) && defined(__NVCC__) /* lool */
#undef __GNUC__
#elif !defined(__GNUC__) && defined(__APPLE__) /* modesty */
#define __GNUC__            4
#define __GNUC_MINOR__      2
#define __GNUC_PATCHLEVEL__ 1
#elif !defined(__GNUC__) && defined(__TINYC__)
#define __GNUC__            2
#define __GNUC_MINOR__      0
#define __GNUC_PATCHLEVEL__ 0
#endif

#if !defined(__x86_64__) && \
    (defined(__amd64__) || (defined(_M_AMD64) && defined(_M_X64)))
#define __x86_64__ 1
#elif !defined(__i386__) && ((defined(__i486__) || defined(__i586__) ||  \
                              defined(__i686__) || defined(__i786__)) || \
                             _M_IX86 + 0 >= 400)
#define __i386__ 1
#elif !defined(__ia16__) && (defined(__MSDOS__) || defined(__BCC__))
#define __ia16__ 1
#endif
#if __ia16__ + __i386__ + __x86_64__ + 0
#define __x86__ 1
#endif

#ifdef _MSC_VER
#define __STRICT_ANSI__
#ifndef __STDC__
#define __STDC__
#endif
#endif

#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
#ifndef __has_builtin
#define __has_builtin(x) 0
#endif
#ifndef __has_cpp_attribute
#define __has_cpp_attribute(x) 0
#endif
#ifndef __has_extension
#define __has_extension(x) 0
#endif

#ifdef unix
#undef unix
#endif

#ifdef linux
#undef linux
#endif

#ifdef __linux
#undef __linux
#endif

#ifdef __linux__
#undef __linux__
#endif

#ifndef __BIGGEST_ALIGNMENT__
#define __BIGGEST_ALIGNMENT__ 16
#endif

#ifdef _COSMO_SOURCE
#define FRAMESIZE 65536
#define _PAGESIZE 4096
#endif

#if defined(__LP64__) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/lp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xfffffffffffffffful
#define __SIZE_MAX__    0xfffffffffffffffful
#define __INTPTR_MAX__  0x7fffffffffffffffl
#define __UINTPTR_MAX__ 0xfffffffffffffffful
#define __WINT_MAX__    0xffffffffu
#define __UINTMAX_MAX__ 0xffffffffffffffffUL
#define __INTMAX_MAX__  0x7fffffffffffffffL

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        8
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      8
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __INT16_TYPE__   short int
#define __INT32_TYPE__   int
#define __INT64_TYPE__   long int
#define __INT8_TYPE__    signed char
#define __INTMAX_TYPE__  long int
#define __INTPTR_TYPE__  long int
#define __PTRDIFF_TYPE__ long int
#define __SIZE_TYPE__    long unsigned int
#define __UINT16_TYPE__  short unsigned int
#define __UINT32_TYPE__  unsigned int
#define __UINT64_TYPE__  long unsigned int
#define __UINT8_TYPE__   unsigned char
#define __UINTMAX_TYPE__ long unsigned int
#define __UINTPTR_TYPE__ long unsigned int
#define __WCHAR_TYPE__   int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#elif defined(_MSC_VER) && !defined(__INT64_TYPE__)


/*!BEGIN libc/integral/llp64.inc */

#define __INT8_MAX__    0x7f
#define __UINT8_MAX__   0xff
#define __INT16_MAX__   0x7fff
#define __UINT16_MAX__  0xffff
#define __SHRT_MAX__    0x7fff
#define __INT_MAX__     0x7fffffff
#define __INT32_MAX__   0x7fffffff
#define __UINT32_MAX__  0xffffffffu
#define __INT64_MAX__   0x7fffffffffffffffl
#define __UINT64_MAX__  0xffffffffffffffffull
#define __SIZE_MAX__    0xffffffffffffffffull
#define __INTPTR_MAX__  0x7fffffffffffffffll
#define __UINTPTR_MAX__ 0xffffffffffffffffull
#define __WINT_MAX__    0xffffffffu

#define __SIZEOF_SHORT__       2
#define __SIZEOF_INT__         4
#define __SIZEOF_LONG__        4
#define __SIZEOF_LONG_LONG__   8
#define __SIZEOF_POINTER__     8
#define __SIZEOF_PTRDIFF_T__   8
#define __SIZEOF_SIZE_T__      4
#define __SIZEOF_WCHAR_T__     4
#define __SIZEOF_WINT_T__      4
#define __SIZEOF_FLOAT__       4
#define __SIZEOF_FLOAT128__    16
#define __SIZEOF_DOUBLE__      8
#define __SIZEOF_FLOAT80__     16
#define __SIZEOF_LONG_DOUBLE__ 16

#define __INT8_C(c)   c
#define __UINT8_C(c)  c
#define __INT16_C(c)  c
#define __UINT16_C(c) c
#define __INT32_C(c)  c
#define __UINT32_C(c) c##U
#define __INT64_C(c)  c##LL
#define __UINT64_C(c) c##ULL

#if !(__ASSEMBLER__ + __LINKER__ + 0)

#define __INT8_TYPE__    signed char
#define __UINT8_TYPE__   unsigned char
#define __INT16_TYPE__   short int
#define __UINT16_TYPE__  short unsigned int
#define __INT32_TYPE__   int
#define __UINT32_TYPE__  unsigned int
#define __INT64_TYPE__   long long int
#define __UINT64_TYPE__  long long unsigned int
#define __INTPTR_TYPE__  long long int
#define __UINTPTR_TYPE__ long long unsigned int
#define __PTRDIFF_TYPE__ long long int
#define __SIZE_TYPE__    unsigned int
#define __WCHAR_TYPE__   int
#define __CHAR16_TYPE__  short unsigned int
#define __CHAR32_TYPE__  unsigned int
#define __WINT_TYPE__    unsigned int

#define __INT_LEAST8_TYPE__   __INT8_TYPE__
#define __UINT_LEAST8_TYPE__  __UINT8_TYPE__
#define __INT_LEAST16_TYPE__  __INT32_TYPE__
#define __UINT_LEAST16_TYPE__ __UINT16_TYPE__
#define __INT_LEAST32_TYPE__  __INT16_TYPE__
#define __UINT_LEAST32_TYPE__ __UINT32_TYPE__
#define __INT_LEAST64_TYPE__  __INT64_TYPE__
#define __UINT_LEAST64_TYPE__ __UINT64_TYPE__
#define __INT_FAST8_TYPE__    __INT8_TYPE__
#define __UINT_FAST8_TYPE__   __UINT8_TYPE__
#define __INT_FAST16_TYPE__   __INT32_TYPE__
#define __UINT_FAST16_TYPE__  __UINT32_TYPE__
#define __INT_FAST32_TYPE__   __INT32_TYPE__
#define __UINT_FAST32_TYPE__  __UINT32_TYPE__
#define __INT_FAST64_TYPE__   __INT64_TYPE__
#define __UINT_FAST64_TYPE__  __UINT64_TYPE__

#endif
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
#ifdef __STDC__


/*!BEGIN libc/integral/c.inc */

#if __GNUC__ + 0 < 2
#define __attribute__(x)
#endif

#ifndef __cplusplus
#define COSMOPOLITAN_C_START_
#define COSMOPOLITAN_C_END_
#define COSMOPOLITAN_CXX_START_
#define COSMOPOLITAN_CXX_END_
#define COSMOPOLITAN_CXX_USING_
#endif

#ifndef __ia16__
#define __far
#endif

#if !defined(__GNUC__) && __cplusplus + 0 >= 201103L
#define typeof(x) decltype(x)
#elif !defined(__GNUC__) && __STDC_VERSION__ + 0 < 201112
#define typeof(x) __typeof(x)
#endif

#ifdef __cplusplus
#if __cplusplus >= 201103L
#define _Alignof(x) alignof(x)
#endif /* C++11 */
#else  /* __cplusplus */
#if __STDC_VERSION__ + 0 < 201112
#if __GNUC__ + _MSC_VER + 0
#define _Alignof(x) __alignof(x)
#else
#define _Alignof(x) /* basically all it ever did lool */ sizeof(x)
#endif /* GNU/MSVC/!ANSI */
#endif /* C11 */
#endif /* __cplusplus */

#if !defined(__cplusplus) && !defined(inline) && __STDC_VERSION__ + 0 < 199901
#if defined(__GNUC__) || defined(_MSC_VER)
#define inline __inline
#else
#define inline
#define __inline
#endif
#endif

#ifdef __chibicc__
#define __extension__
#endif

#if __STDC_VERSION__ + 0 < 201112
#ifdef __GNUC__
#define _Alignas(x) __attribute__((__aligned__(x)))
#elif defined(_MSC_VER)
#define _Alignas(x) __declspec(align(x))
#endif
#endif

#ifdef _MSC_VER
#define __builtin_unreachable() __assume(false)
#elif !((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405 || \
        defined(__clang__) || defined(__INTEL_COMPILER) ||    \
        __has_builtin(__builtin_unreachable))
#define __builtin_unreachable() \
  for (;;) {                    \
  }
#endif

#if (!defined(__llvm__) && !__has_builtin(__builtin_assume))
#define __builtin_assume(x)    \
  do {                         \
    if (!(x))                  \
      __builtin_unreachable(); \
  } while (0)
#endif

#if __STDC_VERSION__ + 0 < 201112
#define _Atomic(TYPE) TYPE volatile
#endif

#ifdef __llvm__
#define __gnu_printf__ __printf__
#define __gnu_scanf__  __scanf__
#endif

#if __cplusplus + 0 >= 201103L
#define NULL nullptr
#elif !defined(__cplusplus)
#define NULL ((void *)0)
#else
#define NULL 0
#endif

#ifndef __cplusplus
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC push_options
#pragma GCC diagnostic ignored "-Wc++-compat"
#endif
typedef __WCHAR_TYPE__ wchar_t;
typedef __CHAR16_TYPE__ char16_t;
typedef __CHAR32_TYPE__ char32_t;
#if defined(__GNUC__) && !defined(__llvm__)
#pragma GCC pop_options
#endif
#endif /* __cplusplus */

#ifndef __COSMOCC__


/*!BEGIN libc/stdbool.h */

#define COSMOPOLITAN_LIBC_STDBOOL_H_

#ifndef __cplusplus

#define bool _Bool
#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L
#define true  ((_Bool) + 1u)
#define false ((_Bool) + 0u)
#else
#define true  1
#define false 0
#endif

#else /* __cplusplus */

#define _Bool bool

#endif /* __cplusplus */

#define __bool_true_false_are_defined 1

#endif

#define _LIBCPP_STDINT_H

typedef int errno_t;
typedef __SIZE_TYPE__ size_t;
typedef __PTRDIFF_TYPE__ ssize_t;
typedef __INTPTR_TYPE__ intptr_t;
typedef __UINTPTR_TYPE__ uintptr_t;
typedef __PTRDIFF_TYPE__ ptrdiff_t;
typedef __WINT_TYPE__ wint_t; /* uint32_t on linux but int32_t on xnu */
typedef __INT8_TYPE__ int8_t;
typedef __UINT8_TYPE__ uint8_t;
typedef __INT16_TYPE__ int16_t;
typedef __UINT16_TYPE__ uint16_t;
typedef __INT32_TYPE__ bool32;
typedef __INT32_TYPE__ int32_t;
typedef __UINT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t;
typedef __UINT64_TYPE__ uint64_t;
typedef __INTMAX_TYPE__ intmax_t;
typedef __UINTMAX_TYPE__ uintmax_t;

#define __DEFINED_max_align_t
typedef long double max_align_t;

#ifdef _COSMO_SOURCE
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406 || defined(__llvm__)
typedef signed __int128 int128_t;
typedef unsigned __int128 uint128_t;
#endif
#endif /* _COSMO_SOURCE */

#ifndef __AXDX_T
#define __AXDX_T
typedef struct {
  intptr_t ax, dx;
} axdx_t;
#endif

#ifndef __chibicc__
#define va_list            __builtin_va_list
#define va_arg(ap, type)   __builtin_va_arg(ap, type)
#define va_copy(dest, src) __builtin_va_copy(dest, src)
#define va_end(ap)         __builtin_va_end(ap)
#define va_start(ap, last) __builtin_va_start(ap, last)
#else


/*!BEGIN libc/integral/lp64arg.inc */

/* variadic arguments for chibicc */

/* <sync libc/runtime/valist.c> */
struct __va_list {
  uint32_t gp_offset;
  uint32_t fp_offset;
  void *overflow_arg_area;
  void *reg_save_area;
};
/* </sync libc/runtime/valist.c> */

void *__va_arg(struct __va_list *, size_t, unsigned, unsigned);

#define __GNUC_VA_LIST 1
#define __gnuc_va_list va_list

#define va_end(AP)
#define va_copy(DST, SRC) ((DST)[0] = (SRC)[0])
#define va_start(AP, LAST)                    \
  do {                                        \
    *(AP) = *(struct __va_list *)__va_area__; \
  } while (0)

#define va_arg(AP, TYPE)                               \
  (*(TYPE *)__va_arg(AP, sizeof(TYPE), _Alignof(TYPE), \
                     __builtin_reg_class(TYPE)))

typedef struct __va_list va_list[1];
#endif

#define libcesque   dontthrow dontcallback
#define memcpyesque libcesque
#define strlenesque libcesque nosideeffect paramsnonnull()
#define vallocesque \
  libcesque __wur returnsaligned((65536)) returnspointerwithnoaliases
#define reallocesque libcesque returnsaligned((16))
#define mallocesque  reallocesque returnspointerwithnoaliases
#define interruptfn  nocallersavedregisters forcealignargpointer

#ifndef pureconst
#define pureconst __attribute__((__const__))
#endif

#ifndef forcealign
#define forcealign(bytes) __attribute__((__aligned__(bytes)))
#endif
#define thatispacked __attribute__((__packed__))

#define printfesque(n)   __attribute__((__format__(__gnu_printf__, n, n + 1)))
#define scanfesque(n)    __attribute__((__format__(__gnu_scanf__, n, n + 1)))
#define strftimeesque(n) __attribute__((__format__(__strftime__, n, 0)))

#ifndef privileged
#define privileged \
  _Section(".privileged") dontinline dontinstrument dontubsan dontasan
#endif

#ifndef wontreturn
#if (__has_attribute(__noreturn__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 208)
#define wontreturn __attribute__((__noreturn__))
#else
#define wontreturn
#endif
#endif

#ifndef nosideeffect
#if (__has_attribute(__pure__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 296)
#define nosideeffect __attribute__((__pure__))
#else
#define nosideeffect
#endif
#endif

#ifndef dontinline
#ifdef _MSC_VER
#define dontinline __declspec(noinline)
#elif (__has_attribute(__noinline__) || \
       (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301)
#define dontinline __attribute__((__noinline__))
#else
#define dontinline
#endif
#endif

#ifndef dontclone
#if (__has_attribute(__noclone__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 405)
#define dontclone __attribute__((__noclone__))
#else
#define dontclone
#endif
#endif

#ifndef forceinline
#ifdef __cplusplus
#define forceinline inline
#else
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 302
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
    !defined(__cplusplus) ||                              \
    (defined(__clang__) &&                                \
     (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__)))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define forceinline                                                 \
  static __inline __attribute__((__always_inline__, __gnu_inline__, \
                                 __no_instrument_function__, __unused__))
#else
#define forceinline                                 \
  static __inline __attribute__((__always_inline__, \
                                 __no_instrument_function__, __unused__))
#endif /* __GNUC_STDC_INLINE__ */
#endif /* GCC >= 4.3 */
#elif defined(_MSC_VER)
#define forceinline __forceinline
#else
#define forceinline static inline
#endif /* !ANSI && GCC >= 3.2 */
#endif /* __cplusplus */
#endif /* forceinline */

#ifndef __wur
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 304 || \
     __has_attribute(__warn_unused_result__))
#define __wur __attribute__((__warn_unused_result__))
#else
#define __wur
#endif
#endif

#ifndef nullterminated
#if __has_attribute(__sentinel__) || __GNUC__ + 0 >= 4
#define nullterminated(x) __attribute__((__sentinel__ x))
#else
#define nullterminated(x)
#endif
#endif

#ifndef flattenout
#if __has_attribute(__flatten__) || \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401 && !defined(__llvm__))
#define flattenout __attribute__((__flatten__))
#else
#define flattenout
#endif
#endif

#ifndef externinline
#if (!defined(__cplusplus) ||                              \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403 || \
     (defined(__clang__) &&                                \
      (defined(__GNUC_STDC_INLINE__) || defined(__GNUC_GNU_INLINE__))))
#if defined(__GNUC_STDC_INLINE__) || defined(__cplusplus)
#define externinline extern __inline __attribute__((__gnu_inline__))
#else
#define externinline extern __inline __attribute__((__always_inline__))
#endif
#else
#define externinline inline
#endif
#endif

#ifndef relegated
#if (__has_attribute(__cold__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define relegated __attribute__((__cold__))
#else
#define relegated
#endif
#endif

#if (__has_attribute(__warning__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define warnifused(s) __attribute__((__warning__(s)))
#else
#define warnifused(s)
#endif

#ifndef firstclass
#if (__has_attribute(__hot__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define firstclass __attribute__((__hot__))
#else
#define firstclass
#endif
#endif

#ifndef paramsnonnull
#if (__has_attribute(__nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 403)
#define paramsnonnull(opt_1idxs) __attribute__((__nonnull__ opt_1idxs))
#else
#define paramsnonnull(opt_1idxs)
#endif
#endif

#if __STDC_VERSION__ + 0 >= 199901L
#define hasatleast static
#else
#define hasatleast
#endif

#if __STDC_VERSION__ + 0 < 199901L && !defined(restrict)
#if !defined(__cplusplus) && \
    ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 301 || defined(_MSC_VER))
#define restrict __restrict__
#else
#define restrict
#define __restrict
#endif
#endif

#ifndef dontcallback
#if (__has_attribute(__leaf__) || \
     (!defined(__llvm__) &&       \
      (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 406))
#define dontcallback __attribute__((__leaf__))
#else
#define dontcallback
#endif
#endif

#ifndef dontthrow
#if defined(__cplusplus) &&        \
    (__has_attribute(dontthrow) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define dontthrow __attribute__((__nothrow__))
#elif defined(_MSC_VER)
#define dontthrow __declspec(nothrow)
#else
#define dontthrow
#endif
#endif

#ifndef returnstwice
#if (__has_attribute(__returns_twice__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 402)
#define returnstwice __attribute__((__returns_twice__))
#else
#define returnstwice
#endif
#endif

#ifndef nodebuginfo
#if __has_attribute(__nodebug__) || defined(__llvm__)
#define nodebuginfo __attribute__((__nodebug__))
#else
#define nodebuginfo
#endif
#endif

#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
    __has_attribute(__force_align_arg_pointer__)
#define forcealignargpointer __attribute__((__force_align_arg_pointer__))
#else
#define forcealignargpointer "need modern compiler"
#endif

#ifndef returnsnonnull
#if (__has_attribute(__returns_nonnull__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsnonnull __attribute__((__returns_nonnull__))
#else
#define returnsnonnull
#endif
#endif

#if (__has_attribute(__assume_aligned__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnsaligned(x) __attribute__((__assume_aligned__ x))
#else
#define returnsaligned(x)
#endif

#ifndef returnspointerwithnoaliases
#if (__has_attribute(__malloc__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define returnspointerwithnoaliases __attribute__((__malloc__))
#elif defined(_MSC_VER)
#define returnspointerwithnoaliases __declspec(allocator)
#else
#define returnspointerwithnoaliases
#endif
#endif

#ifndef attributeallocsize
#if (__has_attribute(__alloc_size__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocsize(x) __attribute__((__alloc_size__ x))
#else
#define attributeallocsize(x)
#endif
#endif

#ifndef attributeallocalign
#if (__has_attribute(__alloc_align__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409)
#define attributeallocalign(x) __attribute__((__alloc_align__ x))
#else
#define attributeallocalign(x)
#endif
#endif

#if __cplusplus + 0 >= 201103L
#define autotype(x) auto
#elif ((__has_builtin(__auto_type) || defined(__llvm__) ||     \
        (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 409) && \
       !defined(__chibicc__))
#define autotype(x) __auto_type
#else
#define autotype(x) typeof(x)
#endif

#define offsetof(type, member) __builtin_offsetof(type, member)

#ifdef _COSMO_SOURCE

#ifndef dontinstrument
#if (__has_attribute(__no_instrument_function__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 204)
#if ((__GNUC__ + 0) >= 7 && !defined(__chibicc__)) || \
    __has_attribute(__patchable_function_entry__)
#define dontinstrument                       \
  __attribute__((__no_instrument_function__, \
                 __patchable_function_entry__(0, 0)))
#else
#define dontinstrument __attribute__((__no_instrument_function__))
#endif
#else
#define dontinstrument
#endif
#endif

#ifndef mayalias
#if (__has_attribute(__may_alias__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 303)
#define mayalias __attribute__((__may_alias__))
#else
#define mayalias
#endif
#endif

#ifndef dontoptimize
#if defined(__llvm__) || __has_attribute(__optnone__)
#define dontoptimize __attribute__((__optnone__))
#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define dontoptimize __attribute__((__optimize__(0)))
#endif
#endif

#ifndef optimizesize
#if (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
    __has_attribute(__optimize__)
#define optimizesize __attribute__((__optimize__("s")))
#elif defined(__llvm__) || __has_attribute(__optnone__)
#define optimizesize __attribute__((__optnone__))
#endif
#endif

#ifndef optimizespeed
/* warning: corrupts frame pointer; only use on leaf functions */
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define optimizespeed __attribute__((__optimize__(3)))
#else
#define optimizespeed
#endif
#endif

#ifndef unrollloops
#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407 || \
     __has_attribute(__optimize__))
#define unrollloops __attribute__((__optimize__("unroll-loops")))
#else
#define unrollloops
#endif
#endif

#ifndef _Microarchitecture
#if (__has_attribute(__target__) || \
     (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 404)
#define _Microarchitecture(march) __attribute__((__target__(march)))
#else
#define _Microarchitecture(march)
#endif
#endif

#ifdef __x86_64__
#if __GNUC__ >= 7 || __has_attribute(__no_caller_saved_registers__)
#define nocallersavedregisters __attribute__((__no_caller_saved_registers__))
#else
#define nocallersavedregisters "need modern compiler"
#endif
#else
#define nocallersavedregisters
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_address__))
#define dontasan __attribute__((__no_sanitize_address__))
#else
#define dontasan
#endif

#if ((__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 408 || \
     __has_attribute(__no_sanitize_undefined__))
#define dontubsan __attribute__((__no_sanitize_undefined__))
#else
#define dontubsan
#endif

#ifdef __x86_64__
#define notpossible          \
  do {                       \
    __asm__("nop\n\t"        \
            "ud2\n\t"        \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#elif defined(__aarch64__)
#define notpossible          \
  do {                       \
    __asm__("udf\t#0\n\t"    \
            "nop");          \
    __builtin_unreachable(); \
  } while (0)
#else
#define notpossible __builtin_trap()
#endif

#define donothing \
  do {            \
  } while (0)

#define textstartup _Section(".text.startup")
#define textexit    _Section(".text.exit")
#define textreal    _Section(".text.real")
#define texthead    _Section(".text.head")
#define textwindows _Section(".text.windows")
#define antiquity   _Section(".text.antiquity")

#ifdef __llvm__
#define __builtin_ia32_movntdq(x, y) (*(x) = (y))
#endif

#ifndef _Section
#define _Section(s) __attribute__((__section__(s)))
#endif

#ifndef __llvm__
#pragma GCC diagnostic ignored "-Wformat=0" /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wbuiltin-declaration-mismatch"
#pragma GCC diagnostic warning "-Wunknown-pragmas"
#else
#pragma GCC diagnostic ignored "-Wformat"
#pragma GCC diagnostic ignored "-Wconstant-logical-operand" /* what */
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wstring-plus-int"       /* features 4 losers */
#pragma GCC diagnostic ignored "-Wkeyword-compat"        /* c++ upgrade */
#pragma GCC diagnostic ignored "-Wuser-defined-literals" /* reserved for me */
#endif

#pragma GCC diagnostic ignored "-Wformat-extra-args"     /* todo: patch gcc */
#pragma GCC diagnostic ignored "-Wunused-function"       /* contradicts dce */
#pragma GCC diagnostic ignored "-Wunused-const-variable" /* sooo ridiculous */
#ifndef __cplusplus
#pragma GCC diagnostic ignored "-Wold-style-definition" /* orwellian bullsh */
#endif

#ifdef __x86_64__
#define DebugBreak() __asm__("int3")
#elif defined(__aarch64__)
#define DebugBreak() __asm__("brk\t#0x666")
#else
#define DebugBreak() __builtin_trap()
#endif

#ifdef __aarch64__
/* raise sigill (not sigtrap) like x86 does */
#define __builtin_trap()     \
  do {                       \
    __asm__("udf\t#0x666");  \
    __builtin_unreachable(); \
  } while (0)
#endif

#endif /* _COSMO_SOURCE */

#define __veil(CONSTRAINT, EXPRESSION)                               \
  __extension__({                                                    \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                 \
    __asm__("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                     \
  })

#define __conceal(CONSTRAINT, EXPRESSION)                                     \
  __extension__({                                                             \
    autotype(EXPRESSION) VeiledValue = (EXPRESSION);                          \
    __asm__ volatile("" : "=" CONSTRAINT ""(VeiledValue) : "0"(VeiledValue)); \
    VeiledValue;                                                              \
  })

#define __expropriate(EXPRESSION)                      \
  __extension__({                                      \
    __asm__ volatile("" ::"g"(EXPRESSION) : "memory"); \
    0;                                                 \
  })

#if !defined(__APPLE__) && defined(__x86_64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tnopl\t%0\n\t.previous" : : "m"(SYMBOL))
#elif defined(__aarch64__)
#define __yoink(SYMBOL) \
  __asm__(".section .yoink\n\tb\t%0\n\t.previous" : : "m"(SYMBOL))
#else
#define __yoink(SYMBOL) (void)0
#endif

#if !defined(__APPLE__) && defined(__x86_64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
#elif defined(__aarch64__)
#define __static_yoink(SYMBOLSTR) \
  __asm__(".section .yoink\n\tb\t\"" SYMBOLSTR "\"\n\t.previous")
#else
#define __static_yoink(SYMBOLSTR)
#endif

#if !defined(IM_FEELING_NAUGHTY)
#define __static_yoink_source(PATH) __static_yoink(PATH)
#else
#define __static_yoink_source(PATH)
#endif

#define __weak_reference(sym, alias) __weak_reference_impl(sym, alias)
#define __weak_reference_impl(sym, alias)  \
  __asm__(".weak\t" #alias "\n\t"          \
          ".equ\t" #alias ", " #sym "\n\t" \
          ".type\t" #alias ",@notype")

#ifndef __chibicc__
#define __strong_reference(sym, alias) \
  extern __typeof(sym) alias __attribute__((__alias__(#sym)))
#else
#define __strong_reference(sym, alias) __weak_reference(sym, alias)
#endif

#if defined(__GNUC__) || defined(__llvm__)
#define __funline \
  extern __inline \
      __attribute__((__gnu_inline__, __always_inline__, __artificial__))
#else
#define __funline static inline
#endif

#if defined(__x86_64__) && (defined(__GNUC__) || defined(__llvm__)) && \
    !defined(__chibicc__) && defined(__OPTIMIZE__)
#define __target_clones(x) __attribute__((__target_clones__(x ",default")))
#else
#define __target_clones(x)
#endif

#if !defined(TINY) && !defined(__AVX__)
#define __vex __target_clones("avx")
#else
#define __vex
#endif

#define __notice(sym, str)                                                   \
  __attribute__((__section__(".notice"), __aligned__(1))) const char sym[] = \
      "\n\n" str

#define MACHINE_CODE_ANALYSIS_BEGIN_
#define MACHINE_CODE_ANALYSIS_END_
#else
#define const
#define volatile
#endif
#ifdef __cplusplus


/*!BEGIN libc/integral/cxx.inc */

#define COSMOPOLITAN_CXX_START_ namespace cosmo {
#define COSMOPOLITAN_CXX_END_   }
#define COSMOPOLITAN_CXX_USING_ using namespace cosmo;
#define COSMOPOLITAN_C_START_   extern "C" {
#define COSMOPOLITAN_C_END_     }

#if !defined(__builtin_types_compatible_p) && !__has_builtin(types_compatible_p)
#if 0 /* todo jart whyyyy */


/*!BEGIN libc/integral/cxxtypescompat.inc */

#define NAME __cxx_types_compatible
#define QUALIFIED(Q1, Q2)       \
  template <class _T, class _U> \
  struct NAME<_T Q1, _U Q2> : NAME<_T, _U> {}

template <class, class>
struct NAME {
  enum { _value = 0 };
};

template <class _T>
struct NAME<_T, _T> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[], _T[N]> {
  enum { _value = 1 };
};

template <class _T, size_t N>
struct NAME<_T[N], _T[]> {
  enum { _value = 1 };
};

QUALIFIED(const volatile, );
QUALIFIED(const volatile, const);
QUALIFIED(const, const volatile);
QUALIFIED(volatile, const volatile);
QUALIFIED(const volatile, volatile);
QUALIFIED(const, volatile);
QUALIFIED(volatile, const);
QUALIFIED(, const);
QUALIFIED(const, );
QUALIFIED(, volatile);
QUALIFIED(volatile, );

#undef QUALIFIED
#undef NAME
#define __builtin_types_compatible_p(A, B) \
  (__cxx_types_compatible<A, B>::_value)
#else
#define __builtin_types_compatible_p(A, B) 0
#endif
#endif

#if !defined(__builtin_choose_expr) && !__has_builtin(choose_expr)
#if 1
template <bool _P, typename _T, typename _U>
struct __cxx_choose_expr {
  __cxx_choose_expr(_T _a, _U _b) : _value(_a) {
  }
  const _T _value;
};
template <typename _T, typename _U>
struct __cxx_choose_expr<false, _T, _U> {
  __cxx_choose_expr(_T _a, _U _b) : _value(_b) {
  }
  const _U _value;
};
#define __builtin_choose_expr(X, A, B) \
  (__cxx_choose_expr<X, typeof(A), typeof(B)>(A, B)._value)
#else
#define __builtin_choose_expr(X, A, B) ((X) ? (A) : (B))
#endif
#endif

#ifdef __aarch64__
/* todo jart whyyyy */
#define _Float16 __fp16
#endif
#endif
#endif


/*!BEGIN ape/ape.h */

#define COSMOPOLITAN_APE_APE_H_

#define APE_VERSION_MAJOR 1
#define APE_VERSION_MINOR 10
#define APE_VERSION_STR   APE_VERSION_STR_(APE_VERSION_MAJOR, APE_VERSION_MINOR)
#define APE_VERSION_NOTE  APE_VERSION_NOTE_(APE_VERSION_MAJOR, APE_VERSION_MINOR)

#define APE_VERSION_STR__(x, y) #x "." #y
#define APE_VERSION_STR_(x, y)  APE_VERSION_STR__(x, y)
#define APE_VERSION_NOTE_(x, y) (100000000 * (x) + 1000000 * (y))



/*!BEGIN ape/relocations.h */

#define COSMOPOLITAN_APE_RELOCATIONS_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ αcτµαlly pδrταblε εxεcµταblε § relocations                                   │
╚──────────────────────────────────────────────────────────────────────────────╝
  One of the things αcτµαlly pδrταblε εxεcµταblε does a good job
  abstracting, is how a program needs to exist at three addresses
  simultaneously during the early stages of the loading process.

  By default, the linker calculates all symbols using virtual addresses.
  In some cases it's necessary to use addend macros that change virtual
  addresses into the other two types: physical and real. */

#define IMAGE_BASE_REAL 0x2000

#ifndef IMAGE_BASE_VIRTUAL
#define IMAGE_BASE_VIRTUAL 0x400000
#endif

#ifndef IMAGE_BASE_PHYSICAL
#define IMAGE_BASE_PHYSICAL 0x100000
#endif

/**
 * Returns Relative Virtual Address.
 */
#define RVA(x) ((x) - (IMAGE_BASE_VIRTUAL))

/**
 * Adjusts virtual address so it's relative to load address.
 */
#define PHYSICAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_PHYSICAL))

/**
 * Makes high-entropy read-only addresses relocatable in real mode.
 */
#define REAL(x) ((x) - (IMAGE_BASE_VIRTUAL - IMAGE_BASE_REAL))

#if IMAGE_BASE_VIRTUAL % 0x1000 != 0
#error "IMAGE_BASE_VIRTUAL must be 4kb aligned"
#endif
#if IMAGE_BASE_PHYSICAL % 0x1000 != 0
#error "IMAGE_BASE_PHYSICAL must be 4kb aligned"
#endif
#if IMAGE_BASE_REAL % 0x1000 != 0
#error "IMAGE_BASE_REAL must be 4kb aligned"
#endif



/*!BEGIN libc/ar.h */

#define COSMOPOLITAN_LIBC_AR_H_
COSMOPOLITAN_C_START_

#define ARMAG  "!<arch>\n"
#define SARMAG 8
#define ARFMAG "`\n"

struct ar_hdr {
  char ar_name[16];
  char ar_date[12];
  char ar_uid[6];
  char ar_gid[6];
  char ar_mode[8];
  char ar_size[10];
  char ar_fmag[2];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/assert.h */

#undef _ASSERT_H
#undef assert
#ifdef _COSMO_SOURCE
#undef unassert
#undef npassert
#ifndef NDEBUG
#undef __assert_macro
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

#define _ASSERT_H
COSMOPOLITAN_C_START_

void __assert_fail(const char *, const char *, int) libcesque;
void unassert(const char *, const char *, int) libcesque;

#ifdef NDEBUG
#define assert(x) ((void)0)
#else
#define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__), 0)))
#endif

#if __STDC_VERSION__ >= 201112L && !defined(__cplusplus)
#undef static_assert
#define static_assert _Static_assert
#endif

#ifdef _COSMO_SOURCE
#ifndef NDEBUG
#define unassert(x) __assert_macro(x, #x)
#define npassert(x) __assert_macro(x, #x)
#define __assert_macro(x, s)             \
  ({                                     \
    if (__builtin_expect(!(x), 0)) {     \
      (unassert)(s, __FILE__, __LINE__); \
      __asm__("nop");                    \
      __builtin_unreachable();           \
    }                                    \
    (void)0;                             \
  })
#else
#define npassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_trap();              \
    }                                \
    (void)0;                         \
  })
#define unassert(x)                  \
  ({                                 \
    if (__builtin_expect(!(x), 0)) { \
      __builtin_unreachable();       \
    }                                \
    (void)0;                         \
  })
#endif /* NDEBUG */
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/atomic.h */

#define COSMOPOLITAN_LIBC_ATOMIC_H_

#define atomic_bool           _Atomic(_Bool)
#define atomic_bool32         _Atomic(__INT32_TYPE__)
#define atomic_char           _Atomic(char)
#define atomic_schar          _Atomic(signed char)
#define atomic_uchar          _Atomic(unsigned char)
#define atomic_short          _Atomic(short)
#define atomic_ushort         _Atomic(unsigned short)
#define atomic_int            _Atomic(int)
#define atomic_uint           _Atomic(unsigned int)
#define atomic_long           _Atomic(long)
#define atomic_ulong          _Atomic(unsigned long)
#define atomic_llong          _Atomic(long long)
#define atomic_ullong         _Atomic(unsigned long long)
#define atomic_char16_t       _Atomic(__CHAR16_TYPE__)
#define atomic_char32_t       _Atomic(__CHAR32_TYPE__)
#define atomic_wchar_t        _Atomic(__WCHAR_TYPE__)
#define atomic_intptr_t       _Atomic(__INTPTR_TYPE__)
#define atomic_uintptr_t      _Atomic(__UINTPTR_TYPE__)
#define atomic_size_t         _Atomic(__SIZE_TYPE__)
#define atomic_ptrdiff_t      _Atomic(__PTRDIFF_TYPE__)
#define atomic_int_fast8_t    _Atomic(__INT_FAST8_TYPE__)
#define atomic_uint_fast8_t   _Atomic(__UINT_FAST8_TYPE__)
#define atomic_int_fast16_t   _Atomic(__INT_FAST16_TYPE__)
#define atomic_uint_fast16_t  _Atomic(__UINT_FAST16_TYPE__)
#define atomic_int_fast32_t   _Atomic(__INT_FAST32_TYPE__)
#define atomic_uint_fast32_t  _Atomic(__UINT_FAST32_TYPE__)
#define atomic_int_fast64_t   _Atomic(__INT_FAST64_TYPE__)
#define atomic_uint_fast64_t  _Atomic(__UINT_FAST64_TYPE__)
#define atomic_int_least8_t   _Atomic(__INT_LEAST8_TYPE__)
#define atomic_uint_least8_t  _Atomic(__UINT_LEAST8_TYPE__)
#define atomic_int_least16_t  _Atomic(__INT_LEAST16_TYPE__)
#define atomic_uint_least16_t _Atomic(__UINT_LEAST16_TYPE__)
#define atomic_int_least32_t  _Atomic(__INT_LEAST32_TYPE__)
#define atomic_uint_least32_t _Atomic(__UINT_LEAST32_TYPE__)
#define atomic_int_least64_t  _Atomic(__INT_LEAST64_TYPE__)
#define atomic_uint_least64_t _Atomic(__UINT_LEAST64_TYPE__)

#ifdef __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_BOOL_LOCK_FREE     __CLANG_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __CLANG_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __CLANG_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __CLANG_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __CLANG_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __CLANG_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __CLANG_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __CLANG_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __CLANG_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __CLANG_ATOMIC_POINTER_LOCK_FREE
#else
#define ATOMIC_BOOL_LOCK_FREE     __GCC_ATOMIC_BOOL_LOCK_FREE
#define ATOMIC_CHAR_LOCK_FREE     __GCC_ATOMIC_CHAR_LOCK_FREE
#define ATOMIC_CHAR16_T_LOCK_FREE __GCC_ATOMIC_CHAR16_T_LOCK_FREE
#define ATOMIC_CHAR32_T_LOCK_FREE __GCC_ATOMIC_CHAR32_T_LOCK_FREE
#define ATOMIC_WCHAR_T_LOCK_FREE  __GCC_ATOMIC_WCHAR_T_LOCK_FREE
#define ATOMIC_SHORT_LOCK_FREE    __GCC_ATOMIC_SHORT_LOCK_FREE
#define ATOMIC_INT_LOCK_FREE      __GCC_ATOMIC_INT_LOCK_FREE
#define ATOMIC_LONG_LOCK_FREE     __GCC_ATOMIC_LONG_LOCK_FREE
#define ATOMIC_LLONG_LOCK_FREE    __GCC_ATOMIC_LLONG_LOCK_FREE
#define ATOMIC_POINTER_LOCK_FREE  __GCC_ATOMIC_POINTER_LOCK_FREE
#endif



/*!BEGIN libc/complex.h */

#define COSMOPOLITAN_LIBC_COMPLEX_H_
COSMOPOLITAN_C_START_
#if __STDC_VERSION__ + 0 >= 201112 && !defined(__STDC_NO_COMPLEX__)

#define complex   _Complex
#define imaginary _Imaginary

double cabs(complex double) libcesque;
double carg(complex double) libcesque;
double cimag(complex double) libcesque;
double creal(complex double) libcesque;

float cabsf(complex float) libcesque;
float cargf(complex float) libcesque;
float cimagf(complex float) libcesque;
float crealf(complex float) libcesque;

long double cabsl(complex long double) libcesque;
long double cargl(complex long double) libcesque;
long double cimagl(complex long double) libcesque;
long double creall(complex long double) libcesque;

complex double cacos(complex double) libcesque;
complex double cacosh(complex double) libcesque;
complex double casin(complex double) libcesque;
complex double casinh(complex double) libcesque;
complex double catan(complex double) libcesque;
complex double catanh(complex double) libcesque;
complex double ccos(complex double) libcesque;
complex double ccosh(complex double) libcesque;
complex double cexp(complex double) libcesque;
complex double cexp2(complex double) libcesque;
complex double clog(complex double) libcesque;
complex double conj(complex double) libcesque;
complex double cpow(complex double, complex double) libcesque;
complex double cproj(complex double) libcesque;
complex double csin(complex double) libcesque;
complex double csinh(complex double) libcesque;
complex double csqrt(complex double) libcesque;
complex double ctan(complex double) libcesque;
complex double ctanh(complex double) libcesque;

complex float cacosf(complex float) libcesque;
complex float cacoshf(complex float) libcesque;
complex float casinf(complex float) libcesque;
complex float casinhf(complex float) libcesque;
complex float catanf(complex float) libcesque;
complex float catanhf(complex float) libcesque;
complex float ccosf(complex float) libcesque;
complex float ccoshf(complex float) libcesque;
complex float cexpf(complex float) libcesque;
complex float cexp2f(complex float) libcesque;
complex float clogf(complex float) libcesque;
complex float conjf(complex float) libcesque;
complex float cpowf(complex float, complex float) libcesque;
complex float cprojf(complex float) libcesque;
complex float csinf(complex float) libcesque;
complex float csinhf(complex float) libcesque;
complex float csqrtf(complex float) libcesque;
complex float ctanf(complex float) libcesque;
complex float ctanhf(complex float) libcesque;

complex long double cprojl(complex long double) libcesque;
complex long double csinhl(complex long double) libcesque;
complex long double csinl(complex long double) libcesque;
complex long double csqrtl(complex long double) libcesque;
complex long double ctanhl(complex long double) libcesque;
complex long double ctanl(complex long double) libcesque;
complex long double cacoshl(complex long double) libcesque;
complex long double cacosl(complex long double) libcesque;
complex long double casinhl(complex long double) libcesque;
complex long double casinl(complex long double) libcesque;
complex long double catanhl(complex long double) libcesque;
complex long double catanl(complex long double) libcesque;
complex long double ccoshl(complex long double) libcesque;
complex long double ccosl(complex long double) libcesque;
complex long double cexpl(complex long double) libcesque;
complex long double cexp2l(complex long double) libcesque;
complex long double clogl(complex long double) libcesque;
complex long double conjl(complex long double) libcesque;
complex long double cpowl(complex long double, complex long double) libcesque;

#ifndef __cplusplus
#define __CIMAG(x, t)   \
  (+(union {            \
      _Complex t __z;   \
      t __xy[2];        \
    }){(_Complex t)(x)} \
        .__xy[1])
#define creal(x)  ((double)(x))
#define crealf(x) ((float)(x))
#define creall(x) ((long double)(x))
#define cimag(x)  __CIMAG(x, double)
#define cimagf(x) __CIMAG(x, float)
#define cimagl(x) __CIMAG(x, long double)
#endif

#ifdef __GNUC__
#define _Complex_I (__extension__(0.0f + 1.0fi))
#else
#define _Complex_I (0.0f + 1.0fi)
#endif

#ifdef _Imaginary_I
#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I * (t)(y))
#elif defined(__clang__)
#define __CMPLX(x, y, t) (+(_Complex t){(t)(x), (t)(y)})
#else
#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y)))
#endif

#define CMPLX(x, y)  __CMPLX(x, y, double)
#define CMPLXF(x, y) __CMPLX(x, y, float)
#define CMPLXL(x, y) __CMPLX(x, y, long double)

#endif /* C11 */
COSMOPOLITAN_C_END_


/*!BEGIN libc/cosmo.h */

#define COSMOPOLITAN_LIBC_COSMO_H_
COSMOPOLITAN_C_START_

errno_t cosmo_once(_Atomic(uint32_t) *, void (*)(void));
int systemvpe(const char *, char *const[], char *const[]) libcesque;
char *GetProgramExecutableName(void);
void unleaf(void);
int __demangle(char *, const char *, size_t);
int __is_mangled(const char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/cxxabi.h */

#define _CXXABI_H
COSMOPOLITAN_C_START_

#ifdef __cplusplus
namespace __cxxabiv1 {
#endif /* __cplusplus */

char *__cxa_demangle(const char *, char *, size_t *, int *);
int __cxa_atexit(void (*)(void *), void *, void *) paramsnonnull((1)) dontthrow;
int __cxa_thread_atexit(void (*)(void *), void *, void *) dontthrow;
void __cxa_finalize(void *);

#ifdef __cplusplus
} /* namespace __cxxabiv1 */
#endif /* __cplusplus */

COSMOPOLITAN_C_END_


/*!BEGIN libc/dce.h */

#ifndef COSMOPOLITAN_LIBC_DCE_H_
#define COSMOPOLITAN_LIBC_DCE_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § autotune » dead code elimination                              │
╚─────────────────────────────────────────────────────────────────────────────*/

#ifndef SUPPORT_VECTOR
#ifdef __x86_64__
/**
 * Supported Platforms Tuning Knob (Runtime & Compile-Time)
 * Tuning this bitmask will remove platform polyfills at compile-time.
 */
#define SUPPORT_VECTOR 255
#else
#define SUPPORT_VECTOR (_HOSTLINUX | _HOSTXNU | _HOSTFREEBSD)
#endif
#endif

#define _HOSTLINUX   1
#define _HOSTMETAL   2
#define _HOSTWINDOWS 4
#define _HOSTXNU     8
#define _HOSTOPENBSD 16
#define _HOSTFREEBSD 32
#define _HOSTNETBSD  64

#ifdef NDEBUG
#define NoDebug() 1
#else
#define NoDebug() 0
#endif

#ifdef MODE_DBG
#define IsModeDbg() 1
#else
#define IsModeDbg() 0
#endif

#ifdef TRUSTWORTHY
#define IsTrustworthy() 1
#else
#define IsTrustworthy() 0
#endif

#ifdef TINY
#define IsTiny() 1
#else
#define IsTiny() 0
#endif

#ifdef __OPTIMIZE__
#define IsOptimized() 1
#else
#define IsOptimized() 0
#endif

#ifdef __SANITIZE_ADDRESS__
#define IsAsan() 1
#else
#define IsAsan() 0
#endif

#ifdef __aarch64__
#define IsAarch64()    1
#define IsXnuSilicon() IsXnu()
#else
#define IsAarch64()    0
#define IsXnuSilicon() 0
#endif

#if defined(__x86_64__)
#define _ARCH_NAME "amd64"
#elif defined(__aarch64__)
#define _ARCH_NAME "arm64"
#elif defined(__powerpc64__)
#define _ARCH_NAME "ppc64"
#elif defined(__s390x__)
#define _ARCH_NAME "s390x"
#elif defined(__riscv)
#define _ARCH_NAME "riscv"
#endif

#define SupportsLinux()   ((SUPPORT_VECTOR & _HOSTLINUX) == _HOSTLINUX)
#define SupportsMetal()   ((SUPPORT_VECTOR & _HOSTMETAL) == _HOSTMETAL)
#define SupportsWindows() ((SUPPORT_VECTOR & _HOSTWINDOWS) == _HOSTWINDOWS)
#define SupportsXnu()     ((SUPPORT_VECTOR & _HOSTXNU) == _HOSTXNU)
#define SupportsFreebsd() ((SUPPORT_VECTOR & _HOSTFREEBSD) == _HOSTFREEBSD)
#define SupportsOpenbsd() ((SUPPORT_VECTOR & _HOSTOPENBSD) == _HOSTOPENBSD)
#define SupportsNetbsd()  ((SUPPORT_VECTOR & _HOSTNETBSD) == _HOSTNETBSD)
#define SupportsBsd() \
  (!!(SUPPORT_VECTOR & (_HOSTXNU | _HOSTFREEBSD | _HOSTOPENBSD | _HOSTNETBSD)))
#define SupportsSystemv() \
  (!!(SUPPORT_VECTOR &    \
      (_HOSTLINUX | _HOSTXNU | _HOSTOPENBSD | _HOSTFREEBSD | _HOSTNETBSD)))

#ifndef __ASSEMBLER__
#define IsLinux()   (SupportsLinux() && (__hostos & _HOSTLINUX))
#define IsMetal()   (SupportsMetal() && (__hostos & _HOSTMETAL))
#define IsWindows() (SupportsWindows() && (__hostos & _HOSTWINDOWS))
#define IsXnu()     (SupportsXnu() && (__hostos & _HOSTXNU))
#define IsFreebsd() (SupportsFreebsd() && (__hostos & _HOSTFREEBSD))
#define IsOpenbsd() (SupportsOpenbsd() && (__hostos & _HOSTOPENBSD))
#define IsNetbsd()  (SupportsNetbsd() && (__hostos & _HOSTNETBSD))
#define IsBsd()     (IsXnu() || IsFreebsd() || IsOpenbsd() || IsNetbsd())
#else
/* clang-format off */
#define IsLinux() $_HOSTLINUX,__hostos(%rip)
#define IsMetal() $_HOSTMETAL,__hostos(%rip)
#define IsWindows() $_HOSTWINDOWS,__hostos(%rip)
#define IsBsd() $_HOSTXNU|_HOSTFREEBSD|_HOSTOPENBSD|_HOSTNETBSD,__hostos(%rip)
#define IsXnu() $_HOSTXNU,__hostos(%rip)
#define IsFreebsd() $_HOSTFREEBSD,__hostos(%rip)
#define IsOpenbsd() $_HOSTOPENBSD,__hostos(%rip)
#define IsNetbsd() $_HOSTNETBSD,__hostos(%rip)
/* clang-format on */
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __hostos;

int IsQemuUser(void);

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_DCE_H_ */


/*!BEGIN libc/errno.h */

#define COSMOPOLITAN_LIBC_ERRNO_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview System Five error codes.
 *
 * This file defines the `errno` global variable. When system calls
 * (e.g. read(), write(), etc.) fail they return -1 to indicate the
 * failure, and that is *the only* error return value. System calls
 * also update `errno` too whenever -1 is returned (otherwise errno
 * isn't changed) to be a non-zero value holding one of the numbers
 * below, in order to indicate why the system call failed.
 *
 * There is only one exception to the above rule; some system calls
 * are documented with the `@returnserrno` tag, which means they'll
 * return the error number rather than stuffing it in a global. You
 * can usually spot these system calls easily since most of them'll
 * have names like `posix_foo()` or `pthread_bar()`.
 *
 * @see libc/sysv/consts.sh for assigned numbers
 * @see libc/sysv/dos2errno.sh for multimapped numbers
 */

#if defined(__GNUC__) && defined(__aarch64__) && !defined(__cplusplus)
/* this header is included by 700+ files; therefore we */
/* hand-roll &__get_tls()->tib_errno to avoid #include */
/* cosmopolitan uses x28 as the tls register b/c apple */
#define errno                                      \
  (*__extension__({                                \
    errno_t *__ep;                                 \
    __asm__("sub\t%0,x28,#192-0x3c" : "=r"(__ep)); \
    __ep;                                          \
  }))
#else
#define errno (*__errno_location())
#endif

/**
 * System call unavailable.
 * @note kNtErrorInvalidFunction on NT
 */
extern const errno_t ENOSYS;

/**
 * Operation not permitted.
 * @note kNtErrorInvalidAccess on NT
 */
extern const errno_t EPERM;

/**
 * No such file or directory.
 */
extern const errno_t ENOENT;

/**
 * No such process.
 */
extern const errno_t ESRCH;

/**
 * The greatest of all errnos.
 */
extern const errno_t EINTR;

/**
 * Unix consensus.
 */
extern const errno_t EIO;

/**
 * No such device or address.
 */
extern const errno_t ENXIO;

/**
 * Argument list too long.
 */
extern const errno_t E2BIG;

/**
 * Exec format error.
 */
extern const errno_t ENOEXEC;

/**
 * Bad file descriptor.
 */
extern const errno_t EBADF;

/**
 * No child process.
 */
extern const errno_t ECHILD;

/**
 * Resource temporarily unavailable (e.g. SO_RCVTIMEO expired, too many
 * processes, too much memory locked, read or write with O_NONBLOCK needs
 * polling, etc.).
 */
extern const errno_t EAGAIN;

/**
 * We require more vespene gas.
 */
extern const errno_t ENOMEM;

/**
 * Permission denied.
 */
extern const errno_t EACCES;

/**
 * Pointer passed to system call that would otherwise segfault.
 */
extern const errno_t EFAULT;

/**
 * Block device required.
 */
extern const errno_t ENOTBLK;

/**
 * Device or resource busy.
 */
extern const errno_t EBUSY;

/**
 * File exists.
 */
extern const errno_t EEXIST;

/**
 * Improper link.
 */
extern const errno_t EXDEV;

/**
 * No such device.
 */
extern const errno_t ENODEV;

/**
 * Not a directory.
 */
extern const errno_t ENOTDIR;

/**
 * Is a a directory.
 */
extern const errno_t EISDIR;

/**
 * Invalid argument.
 */
extern const errno_t EINVAL;

/**
 * Too many open files in system.
 */
extern const errno_t ENFILE;

/**
 * Too many open files.
 */
extern const errno_t EMFILE;

/**
 * Inappropriate i/o control operation.
 */
extern const errno_t ENOTTY;

/**
 * Won't open executable that's executing in write mode.
 */
extern const errno_t ETXTBSY;

/**
 * File too large.
 */
extern const errno_t EFBIG;

/**
 * No space left on device.
 */
extern const errno_t ENOSPC;

/**
 * Disk quota exceeded.
 */
extern const errno_t EDQUOT;

/**
 * Invalid seek.
 */
extern const errno_t ESPIPE;

/**
 * Read-only filesystem.
 */
extern const errno_t EROFS;

/**
 * Too many links.
 */
extern const errno_t EMLINK;

/**
 * Broken pipe.
 */
extern const errno_t EPIPE;

/**
 * Mathematics argument out of domain of function.
 */
extern const errno_t EDOM;

/**
 * Result too large.
 */
extern const errno_t ERANGE;

/**
 * Resource deadlock avoided.
 */
extern const errno_t EDEADLK;

/**
 * Filename too long.
 */
extern const errno_t ENAMETOOLONG;

/**
 * No locks available.
 */
extern const errno_t ENOLCK;

/**
 * Directory not empty.
 */
extern const errno_t ENOTEMPTY;

/**
 * Too many levels of symbolic links.
 */
extern const errno_t ELOOP;

/**
 * No message error.
 */
extern const errno_t ENOMSG;

/**
 * Identifier removed.
 */
extern const errno_t EIDRM;

/**
 * Timer expired.
 */
extern const errno_t ETIME;

/**
 * Protocol error.
 */
extern const errno_t EPROTO;

/**
 * Overflow error.
 */
extern const errno_t EOVERFLOW;

/**
 * Unicode decoding error.
 */
extern const errno_t EILSEQ;

/**
 * Too many users.
 */
extern const errno_t EUSERS;

/**
 * Not a socket.
 */
extern const errno_t ENOTSOCK;

/**
 * Destination address required.
 */
extern const errno_t EDESTADDRREQ;

/**
 * Message too long.
 */
extern const errno_t EMSGSIZE;

/**
 * Protocol wrong type for socket.
 */
extern const errno_t EPROTOTYPE;

/**
 * Protocol not available.
 */
extern const errno_t ENOPROTOOPT;

/**
 * Protocol not supported.
 */
extern const errno_t EPROTONOSUPPORT;

/**
 * Socket type not supported.
 */
extern const errno_t ESOCKTNOSUPPORT;

/**
 * Operation not supported.
 */
extern const errno_t ENOTSUP;

/**
 * Socket operation not supported.
 */
extern const errno_t EOPNOTSUPP;

/**
 * Protocol family not supported.
 */
extern const errno_t EPFNOSUPPORT;

/**
 * Address family not supported.
 */
extern const errno_t EAFNOSUPPORT;

/**
 * Address already in use.
 */
extern const errno_t EADDRINUSE;

/**
 * Address not available.
 */
extern const errno_t EADDRNOTAVAIL;

/**
 * Network is down.
 */
extern const errno_t ENETDOWN;

/**
 * Host is unreachable.
 */
extern const errno_t ENETUNREACH;

/**
 * Connection reset by network.
 */
extern const errno_t ENETRESET;

/**
 * Connection reset before accept.
 */
extern const errno_t ECONNABORTED;

/**
 * Connection reset by client.
 */
extern const errno_t ECONNRESET;

/**
 * No buffer space available.
 */
extern const errno_t ENOBUFS;

/**
 * Socket is connected.
 */
extern const errno_t EISCONN;

/**
 * Socket is not connected.
 */
extern const errno_t ENOTCONN;

/**
 * Cannot send after transport endpoint shutdown.
 */
extern const errno_t ESHUTDOWN;

/**
 * Too many references: cannot splice.
 */
extern const errno_t ETOOMANYREFS;

/**
 * Connection timed out.
 */
extern const errno_t ETIMEDOUT;

/**
 * Connection refused error.
 */
extern const errno_t ECONNREFUSED;

/**
 * Host down error.
 */
extern const errno_t EHOSTDOWN;

/**
 * Host unreachable error.
 */
extern const errno_t EHOSTUNREACH;

/**
 * Connection already in progress.
 */
extern const errno_t EALREADY;

/**
 * Operation already in progress.
 */
extern const errno_t EINPROGRESS;

/**
 * Stale error.
 */
extern const errno_t ESTALE;

/**
 * Remote error.
 */
extern const errno_t EREMOTE;

/**
 * Bad message.
 */
extern const errno_t EBADMSG;

/**
 * Operation canceled.
 */
extern const errno_t ECANCELED;

/**
 * Owner died.
 */
extern const errno_t EOWNERDEAD;

/**
 * State not recoverable.
 */
extern const errno_t ENOTRECOVERABLE;

/**
 * No network.
 */
extern const errno_t ENONET;

/**
 * Please restart syscall.
 */
extern const errno_t ERESTART;

/**
 * Out of streams resources.
 */
extern const errno_t ENOSR;

/**
 * No string.
 */
extern const errno_t ENOSTR;

/**
 * No data.
 */
extern const errno_t ENODATA;

/**
 * Multihop attempted.
 */
extern const errno_t EMULTIHOP;

/**
 * Link severed.
 */
extern const errno_t ENOLINK;

/**
 * No medium found.
 */
extern const errno_t ENOMEDIUM;

/**
 * Wrong medium type.
 */
extern const errno_t EMEDIUMTYPE;

/**
 * Inappropriate file type or format.
 */
extern const errno_t EFTYPE;

extern const errno_t EAUTH;
extern const errno_t EBADARCH;
extern const errno_t EBADEXEC;
extern const errno_t EBADMACHO;
extern const errno_t EBADRPC;
extern const errno_t EDEVERR;
extern const errno_t ENEEDAUTH;
extern const errno_t ENOATTR;
extern const errno_t ENOPOLICY;
extern const errno_t EPROCLIM;
extern const errno_t EPROCUNAVAIL;
extern const errno_t EPROGMISMATCH;
extern const errno_t EPROGUNAVAIL;
extern const errno_t EPWROFF;
extern const errno_t ERPCMISMATCH;
extern const errno_t ESHLIBVERS;
extern const errno_t EADV;
extern const errno_t EBADE;
extern const errno_t EBADFD;
extern const errno_t EBADR;
extern const errno_t EBADRQC;
extern const errno_t EBADSLT;
extern const errno_t ECHRNG;
extern const errno_t ECOMM;
extern const errno_t EDOTDOT;
extern const errno_t EHWPOISON;
extern const errno_t EISNAM;
extern const errno_t EKEYEXPIRED;
extern const errno_t EKEYREJECTED;
extern const errno_t EKEYREVOKED;
extern const errno_t EL2HLT;
extern const errno_t EL2NSYNC;
extern const errno_t EL3HLT;
extern const errno_t EL3RST;
extern const errno_t ELIBACC;
extern const errno_t ELIBBAD;
extern const errno_t ELIBEXEC;
extern const errno_t ELIBMAX;
extern const errno_t ELIBSCN;
extern const errno_t ELNRNG;
extern const errno_t ENAVAIL;
extern const errno_t ENOANO;
extern const errno_t ENOCSI;
extern const errno_t ENOKEY;
extern const errno_t ENOPKG;
extern const errno_t ENOTNAM;
extern const errno_t ENOTUNIQ;
extern const errno_t EREMCHG;
extern const errno_t EREMOTEIO;
extern const errno_t ERFKILL;
extern const errno_t ESRMNT;
extern const errno_t ESTRPIPE;
extern const errno_t EUCLEAN;
extern const errno_t EUNATCH;
extern const errno_t EXFULL;

#define E2BIG           E2BIG
#define EACCES          EACCES
#define EADDRINUSE      EADDRINUSE
#define EADDRNOTAVAIL   EADDRNOTAVAIL
#define EAFNOSUPPORT    EAFNOSUPPORT
#define EAGAIN          EAGAIN
#define EALREADY        EALREADY
#define EBADF           EBADF
#define EBADMSG         EBADMSG
#define EBUSY           EBUSY
#define ECANCELED       ECANCELED
#define ECHILD          ECHILD
#define ECONNABORTED    ECONNABORTED
#define ECONNREFUSED    ECONNREFUSED
#define ECONNRESET      ECONNRESET
#define EDEADLK         EDEADLK
#define EDESTADDRREQ    EDESTADDRREQ
#define EDOM            EDOM
#define EDQUOT          EDQUOT
#define EEXIST          EEXIST
#define EFAULT          EFAULT
#define EFBIG           EFBIG
#define EFTYPE          EFTYPE
#define EHOSTDOWN       EHOSTDOWN
#define EHOSTUNREACH    EHOSTUNREACH
#define EIDRM           EIDRM
#define EILSEQ          EILSEQ
#define EINPROGRESS     EINPROGRESS
#define EINTR           EINTR
#define EINVAL          EINVAL
#define EIO             EIO
#define EISCONN         EISCONN
#define EISDIR          EISDIR
#define ELOOP           ELOOP
#define EMEDIUMTYPE     EMEDIUMTYPE
#define EMFILE          EMFILE
#define EMLINK          EMLINK
#define EMSGSIZE        EMSGSIZE
#define EMULTIHOP       EMULTIHOP
#define ENAMETOOLONG    ENAMETOOLONG
#define ENETDOWN        ENETDOWN
#define ENETRESET       ENETRESET
#define ENETUNREACH     ENETUNREACH
#define ENFILE          ENFILE
#define ENOBUFS         ENOBUFS
#define ENODATA         ENODATA
#define ENODEV          ENODEV
#define ENOENT          ENOENT
#define ENOEXEC         ENOEXEC
#define ENOLCK          ENOLCK
#define ENOLINK         ENOLINK
#define ENOMEDIUM       ENOMEDIUM
#define ENOMEM          ENOMEM
#define ENOMSG          ENOMSG
#define ENONET          ENONET
#define ENOPROTOOPT     ENOPROTOOPT
#define ENOSPC          ENOSPC
#define ENOSR           ENOSR
#define ENOSTR          ENOSTR
#define ENOSYS          ENOSYS
#define ENOTBLK         ENOTBLK
#define ENOTCONN        ENOTCONN
#define ENOTDIR         ENOTDIR
#define ENOTEMPTY       ENOTEMPTY
#define ENOTRECOVERABLE ENOTRECOVERABLE
#define ENOTSOCK        ENOTSOCK
#define ENOTSUP         ENOTSUP
#define ENOTTY          ENOTTY
#define ENXIO           ENXIO
#define EOPNOTSUPP      EOPNOTSUPP
#define EOVERFLOW       EOVERFLOW
#define EOWNERDEAD      EOWNERDEAD
#define EPERM           EPERM
#define EPFNOSUPPORT    EPFNOSUPPORT
#define EPIPE           EPIPE
#define EPROTO          EPROTO
#define EPROTONOSUPPORT EPROTONOSUPPORT
#define EPROTOTYPE      EPROTOTYPE
#define ERANGE          ERANGE
#define EREMOTE         EREMOTE
#define ERESTART        ERESTART
#define EROFS           EROFS
#define ESHUTDOWN       ESHUTDOWN
#define ESOCKTNOSUPPORT ESOCKTNOSUPPORT
#define ESPIPE          ESPIPE
#define ESRCH           ESRCH
#define ESTALE          ESTALE
#define ETIME           ETIME
#define ETIMEDOUT       ETIMEDOUT
#define ETOOMANYREFS    ETOOMANYREFS
#define ETXTBSY         ETXTBSY
#define EUSERS          EUSERS
#define EWOULDBLOCK     EAGAIN
#define EXDEV           EXDEV

extern errno_t __errno;
errno_t *__errno_location(void) dontthrow pureconst;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
extern char *program_invocation_short_name;
extern char *program_invocation_name;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/inttypes.h */

#define COSMOPOLITAN_LIBC_INTTYPES_H_

typedef __INT_LEAST8_TYPE__ int_least8_t;
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
typedef __INT_LEAST16_TYPE__ int_least16_t;
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
typedef __INT_LEAST32_TYPE__ int_least32_t;
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
typedef __INT_LEAST64_TYPE__ int_least64_t;
typedef __UINT_LEAST64_TYPE__ uint_least64_t;

typedef __INT_FAST8_TYPE__ int_fast8_t;
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
typedef __INT_FAST16_TYPE__ int_fast16_t;
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
typedef __INT_FAST32_TYPE__ int_fast32_t;
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
typedef __INT_FAST64_TYPE__ int_fast64_t;
typedef __UINT_FAST64_TYPE__ uint_fast64_t;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define __PRI8 "hh"

#if __SIZEOF_INT__ == 2
#define __PRI16 ""
#elif __SIZEOF_SHORT__ == 2
#define __PRI16 "h"
#elif __SIZEOF_LONG__ == 2
#define __PRI16 "l"
#endif

#if __SIZEOF_INT__ == 4
#define __PRI32 ""
#elif __SIZEOF_LONG__ == 4
#define __PRI32 "l"
#elif __SIZEOF_LONG_LONG__ == 4
#define __PRI32 "ll"
#endif

#if __SIZEOF_INT__ == 8
#define __PRI64 ""
#elif __SIZEOF_LONG__ == 8
#define __PRI64 "l"
#elif __SIZEOF_LONG_LONG__ == 8
#define __PRI64 "ll"
#endif

#if __SIZEOF_INT__ == 16
#define __PRI128 ""
#elif __SIZEOF_LONG__ == 16
#define __PRI128 "l"
#elif __SIZEOF_LONG_LONG__ == 16
#define __PRI128 "ll"
#elif __SIZEOF_INTMAX__ == 16
#define __PRI128 "j"
#else
#define __PRI128 "jj"
#endif

#if __SIZEOF_POINTER__ == __SIZEOF_INT__
#define __PRIPTR ""
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG__
#define __PRIPTR "l"
#elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__
#define __PRIPTR "ll"
#endif

#if __INT_FAST16_WIDTH__ == 16
#define __PRIFAST16 "h"
#elif __INT_FAST16_WIDTH__ == 32
#define __PRIFAST16 ""
#else
#define __PRIFAST16 "l"
#endif

#if __INT_FAST32_WIDTH__ == 32
#define __PRIFAST32 ""
#else
#define __PRIFAST32 "l"
#endif

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » decimal                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRId8   __PRI8 "d"
#define PRId16  __PRI16 "d"
#define PRId32  __PRI32 "d"
#define PRId64  __PRI64 "d"
#define PRId128 __PRI128 "d"

#define PRIdLEAST8   __PRI8 "d"
#define PRIdLEAST16  __PRI16 "d"
#define PRIdLEAST32  __PRI32 "d"
#define PRIdLEAST64  __PRI64 "d"
#define PRIdLEAST128 __PRI128 "d"

#define PRIdFAST8   __PRI8 "d"
#define PRIdFAST16  __PRIFAST16 "d"
#define PRIdFAST32  __PRIFAST32 "d"
#define PRIdFAST64  __PRI64 "d"
#define PRIdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » unsigned decimal        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIu8   __PRI8 "u"
#define PRIu16  __PRI16 "u"
#define PRIu32  __PRI32 "u"
#define PRIu64  __PRI64 "u"
#define PRIu128 __PRI128 "u"

#define PRIuLEAST8   __PRI8 "u"
#define PRIuLEAST16  __PRI16 "u"
#define PRIuLEAST32  __PRI32 "u"
#define PRIuLEAST64  __PRI64 "u"
#define PRIuLEAST128 __PRI128 "u"

#define PRIuFAST8   __PRI8 "u"
#define PRIuFAST16  __PRIFAST16 "u"
#define PRIuFAST32  __PRIFAST32 "u"
#define PRIuFAST64  __PRI64 "u"
#define PRIuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » wut                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIi8   __PRI8 "i"
#define PRIi16  __PRI16 "i"
#define PRIi32  __PRI32 "i"
#define PRIi64  __PRI64 "i"
#define PRIi128 __PRI128 "i"

#define PRIiLEAST8   __PRI8 "i"
#define PRIiLEAST16  __PRI16 "i"
#define PRIiLEAST32  __PRI32 "i"
#define PRIiLEAST64  __PRI64 "i"
#define PRIiLEAST128 __PRI128 "i"

#define PRIiFAST8   __PRI8 "i"
#define PRIiFAST16  __PRIFAST16 "i"
#define PRIiFAST32  __PRIFAST32 "i"
#define PRIiFAST64  __PRI64 "i"
#define PRIiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » octal                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIo8   __PRI8 "o"
#define PRIo16  __PRI16 "o"
#define PRIo32  __PRI32 "o"
#define PRIo64  __PRI64 "o"
#define PRIo128 __PRI128 "o"

#define PRIoLEAST8   __PRI8 "o"
#define PRIoLEAST16  __PRI16 "o"
#define PRIoLEAST32  __PRI32 "o"
#define PRIoLEAST64  __PRI64 "o"
#define PRIoLEAST128 __PRI128 "o"

#define PRIoFAST8   __PRI8 "o"
#define PRIoFAST16  __PRIFAST16 "o"
#define PRIoFAST32  __PRIFAST32 "o"
#define PRIoFAST64  __PRI64 "o"
#define PRIoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » hexadecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIx8   __PRI8 "x"
#define PRIx16  __PRI16 "x"
#define PRIx32  __PRI32 "x"
#define PRIx64  __PRI64 "x"
#define PRIx128 __PRI128 "x"

#define PRIxLEAST8   __PRI8 "x"
#define PRIxLEAST16  __PRI16 "x"
#define PRIxLEAST32  __PRI32 "x"
#define PRIxLEAST64  __PRI64 "x"
#define PRIxLEAST128 __PRI128 "x"

#define PRIxFAST8   __PRI8 "x"
#define PRIxFAST16  __PRIFAST16 "x"
#define PRIxFAST32  __PRIFAST32 "x"
#define PRIxFAST64  __PRI64 "x"
#define PRIxFAST128 __PRI128 "x"

#define PRIX8   __PRI8 "X"
#define PRIX16  __PRI16 "X"
#define PRIX32  __PRI32 "X"
#define PRIX64  __PRI64 "X"
#define PRIX128 __PRI128 "X"

#define PRIXLEAST8   __PRI8 "X"
#define PRIXLEAST16  __PRI16 "X"
#define PRIXLEAST32  __PRI32 "X"
#define PRIXLEAST64  __PRI64 "X"
#define PRIXLEAST128 __PRI128 "X"

#define PRIXFAST8   __PRI8 "X"
#define PRIXFAST16  __PRIFAST16 "X"
#define PRIXFAST32  __PRIFAST32 "X"
#define PRIXFAST64  __PRI64 "X"
#define PRIXFAST128 __PRI128 "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » binary                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIb8   __PRI8 "b"
#define PRIb16  __PRI16 "b"
#define PRIb32  __PRI32 "b"
#define PRIb64  __PRI64 "b"
#define PRIb128 __PRI128 "b"

#define PRIbLEAST8   __PRI8 "b"
#define PRIbLEAST16  __PRI16 "b"
#define PRIbLEAST32  __PRI32 "b"
#define PRIbLEAST64  __PRI64 "b"
#define PRIbLEAST128 __PRI128 "b"

#define PRIbFAST8   __PRI8 "b"
#define PRIbFAST16  __PRIFAST16 "b"
#define PRIbFAST32  __PRIFAST32 "b"
#define PRIbFAST64  __PRI64 "b"
#define PRIbFAST128 __PRI128 "b"

#define PRIB8   __PRI8 "B"
#define PRIB16  __PRI16 "B"
#define PRIB32  __PRI32 "B"
#define PRIB64  __PRI64 "B"
#define PRIB128 __PRI128 "B"

#define PRIBLEAST8   __PRI8 "B"
#define PRIBLEAST16  __PRI16 "B"
#define PRIBLEAST32  __PRI32 "B"
#define PRIBLEAST64  __PRI64 "B"
#define PRIBLEAST128 __PRI128 "B"

#define PRIBFAST8   __PRI8 "B"
#define PRIBFAST16  __PRIFAST16 "B"
#define PRIBFAST32  __PRIFAST32 "B"
#define PRIBFAST64  __PRI64 "B"
#define PRIBFAST128 __PRI128 "B"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » printf » miscellaneous           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define PRIdMAX "jd"
#define PRIiMAX "ji"
#define PRIoMAX "jo"
#define PRIuMAX "ju"
#define PRIxMAX "jx"
#define PRIXMAX "jX"

#define PRIdPTR __PRIPTR "d"
#define PRIiPTR __PRIPTR "i"
#define PRIoPTR __PRIPTR "o"
#define PRIuPTR __PRIPTR "u"
#define PRIxPTR __PRIPTR "x"
#define PRIXPTR __PRIPTR "X"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » decimal                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNd8   __PRI8 "d"
#define SCNd16  __PRI16 "d"
#define SCNd32  __PRI32 "d"
#define SCNd64  __PRI64 "d"
#define SCNd128 __PRI128 "d"

#define SCNdLEAST8   __PRI8 "d"
#define SCNdLEAST16  __PRI16 "d"
#define SCNdLEAST32  __PRI32 "d"
#define SCNdLEAST64  __PRI64 "d"
#define SCNdLEAST128 __PRI128 "d"

#define SCNdFAST8   __PRI8 "d"
#define SCNdFAST16  __PRIFAST16 "d"
#define SCNdFAST32  __PRIFAST32 "d"
#define SCNdFAST64  __PRI64 "d"
#define SCNdFAST128 __PRI128 "d"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » flexidecimal             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNi8   __PRI8 "i"
#define SCNi16  __PRI16 "i"
#define SCNi32  __PRI32 "i"
#define SCNi64  __PRI64 "i"
#define SCNi128 __PRI128 "i"

#define SCNiLEAST8   __PRI8 "i"
#define SCNiLEAST16  __PRI16 "i"
#define SCNiLEAST32  __PRI32 "i"
#define SCNiLEAST64  __PRI64 "i"
#define SCNiLEAST128 __PRI128 "i"

#define SCNiFAST8   __PRI8 "i"
#define SCNiFAST16  __PRIFAST16 "i"
#define SCNiFAST32  __PRIFAST32 "i"
#define SCNiFAST64  __PRI64 "i"
#define SCNiFAST128 __PRI128 "i"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » unsigned decimal         ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNu8   __PRI8 "u"
#define SCNu16  __PRI16 "u"
#define SCNu32  __PRI32 "u"
#define SCNu64  __PRI64 "u"
#define SCNu128 __PRI128 "u"

#define SCNuLEAST8   __PRI8 "u"
#define SCNuLEAST16  __PRI16 "u"
#define SCNuLEAST32  __PRI32 "u"
#define SCNuLEAST64  __PRI64 "u"
#define SCNuLEAST128 __PRI128 "u"

#define SCNuFAST8   __PRI8 "u"
#define SCNuFAST16  __PRIFAST16 "u"
#define SCNuFAST32  __PRIFAST32 "u"
#define SCNuFAST64  __PRI64 "u"
#define SCNuFAST128 __PRI128 "u"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » octal                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNo8   __PRI8 "o"
#define SCNo16  __PRI16 "o"
#define SCNo32  __PRI32 "o"
#define SCNo64  __PRI64 "o"
#define SCNo128 __PRI128 "o"

#define SCNoLEAST8   __PRI8 "o"
#define SCNoLEAST16  __PRI16 "o"
#define SCNoLEAST32  __PRI32 "o"
#define SCNoLEAST64  __PRI64 "o"
#define SCNoLEAST128 __PRI128 "o"

#define SCNoFAST8   __PRI8 "o"
#define SCNoFAST16  __PRIFAST16 "o"
#define SCNoFAST32  __PRIFAST32 "o"
#define SCNoFAST64  __PRI64 "o"
#define SCNoFAST128 __PRI128 "o"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » hexadecimal              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNx8   __PRI8 "x"
#define SCNx16  __PRI16 "x"
#define SCNx32  __PRI32 "x"
#define SCNx64  __PRI64 "x"
#define SCNx128 __PRI128 "x"

#define SCNxLEAST8   __PRI8 "x"
#define SCNxLEAST16  __PRI16 "x"
#define SCNxLEAST32  __PRI32 "x"
#define SCNxLEAST64  __PRI64 "x"
#define SCNxLEAST128 __PRI128 "x"

#define SCNxFAST8   __PRI8 "x"
#define SCNxFAST16  __PRIFAST16 "x"
#define SCNxFAST32  __PRIFAST32 "x"
#define SCNxFAST64  __PRI64 "x"
#define SCNxFAST128 __PRI128 "x"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » binary                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNb8   __PRI8 "b"
#define SCNb16  __PRI16 "b"
#define SCNb32  __PRI32 "b"
#define SCNb64  __PRI64 "b"
#define SCNb128 __PRI128 "b"

#define SCNbLEAST8   __PRI8 "b"
#define SCNbLEAST16  __PRI16 "b"
#define SCNbLEAST32  __PRI32 "b"
#define SCNbLEAST64  __PRI64 "b"
#define SCNbLEAST128 __PRI128 "b"

#define SCNbFAST8   __PRI8 "b"
#define SCNbFAST16  __PRIFAST16 "b"
#define SCNbFAST32  __PRIFAST32 "b"
#define SCNbFAST64  __PRI64 "b"
#define SCNbFAST128 __PRI128 "b"

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dismal format notation » scanf » miscellaneous            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define SCNdMAX "jd"
#define SCNiMAX "ji"
#define SCNoMAX "jo"
#define SCNuMAX "ju"
#define SCNxMAX "jx"

#define SCNdPTR __PRIPTR "d"
#define SCNiPTR __PRIPTR "i"
#define SCNoPTR __PRIPTR "o"
#define SCNuPTR __PRIPTR "u"
#define SCNxPTR __PRIPTR "x"



/*!BEGIN libc/limits.h */

#define COSMOPOLITAN_LIBC_LIMITS_H_
#define __STDC_LIMIT_MACROS

#define CHAR_BIT 8
#define PATH_MAX 1024
#define NAME_MAX 255
#define ARG_MAX  131074

#define UCHAR_MIN 0
#define UCHAR_MAX 255

#if '\200' < 0
#define CHAR_MIN '\200'
#define CHAR_MAX '\177'
#else
#define CHAR_MIN '\0'
#define CHAR_MAX '\377'
#endif

#define SCHAR_MAX     __SCHAR_MAX__
#define SHRT_MAX      __SHRT_MAX__
#define INT_MAX       __INT_MAX__
#define LONG_MAX      __LONG_MAX__
#define LLONG_MAX     LONG_LONG_MAX
#define LONG_LONG_MAX __LONG_LONG_MAX__
#define SIZE_MAX      __SIZE_MAX__
#define INT8_MAX      __INT8_MAX__
#define INT16_MAX     __INT16_MAX__
#define INT32_MAX     __INT32_MAX__
#define INT64_MAX     __INT64_MAX__
#define WINT_MAX      __WINT_MAX__
#define WCHAR_MAX     __WCHAR_MAX__
#define INTPTR_MAX    __INTPTR_MAX__
#define PTRDIFF_MAX   __PTRDIFF_MAX__
#define UINTPTR_MAX   __UINTPTR_MAX__
#define UINT8_MAX     __UINT8_MAX__
#define UINT16_MAX    __UINT16_MAX__
#define UINT32_MAX    __UINT32_MAX__
#define UINT64_MAX    __UINT64_MAX__
#define INTMAX_MAX    __INTMAX_MAX__
#define UINTMAX_MAX   __UINTMAX_MAX__
#define SSIZE_MAX     __INT64_MAX__

#define SCHAR_MIN     (-SCHAR_MAX - 1)
#define SHRT_MIN      (-SHRT_MAX - 1)
#define INT_MIN       (-INT_MAX - 1)
#define LONG_MIN      (-LONG_MAX - 1)
#define LLONG_MIN     (-LLONG_MAX - 1)
#define LONG_LONG_MIN (-LONG_LONG_MAX - 1)
#define SIZE_MIN      (-SIZE_MAX - 1)
#define INT8_MIN      (-INT8_MAX - 1)
#define INT16_MIN     (-INT16_MAX - 1)
#define INT32_MIN     (-INT32_MAX - 1)
#define INT64_MIN     (-INT64_MAX - 1)
#define INTMAX_MIN    (-INTMAX_MAX - 1)
#define INTPTR_MIN    (-INTPTR_MAX - 1)
#define WINT_MIN      __WINT_MIN__
#define WCHAR_MIN     (-WCHAR_MAX - 1)
#define PTRDIFF_MIN   (-PTRDIFF_MAX - 1)

#define USHRT_MAX 65535
#define UINT_MAX  0xffffffffu
#if __SIZEOF_LONG__ == 8
#define ULONG_MAX 0xfffffffffffffffful
#else
#define ULONG_MAX 0xfffffffful
#endif
#define ULLONG_MAX     0xffffffffffffffffull
#define ULONG_LONG_MAX 0xffffffffffffffffull

#define USHRT_MIN      0
#define UINT_MIN       0u
#define ULONG_MIN      0ul
#define ULLONG_MIN     0ull
#define ULONG_LONG_MIN 0ull
#define UINT8_MIN      0
#define UINT16_MIN     0
#define UINT32_MIN     0u
#define UINT64_MIN     0ull
#define UINTPTR_MIN    0ull
#define UINTMAX_MIN    ((uintmax_t)0)

#define MB_CUR_MAX 4
#define MB_LEN_MAX 4

#ifdef _COSMO_SOURCE
#if __GNUC__ * 100 + __GNUC_MINOR__ >= 406 || defined(__llvm__)
#define INT128_MIN  (-INT128_MAX - 1)
#define UINT128_MIN ((uint128_t)0)
#define INT128_MAX \
  ((int128_t)0x7fffffffffffffff << 64 | (int128_t)0xffffffffffffffff)
#define UINT128_MAX \
  ((uint128_t)0xffffffffffffffff << 64 | (uint128_t)0xffffffffffffffff)
#endif /* GCC 4.6+ */
#endif /* _COSMO_SOURCE */

#define SIG_ATOMIC_MIN INT32_MIN
#define SIG_ATOMIC_MAX INT32_MAX

#define FILESIZEBITS   64
#define SYMLOOP_MAX    40
#define TTY_NAME_MAX   32
#define HOST_NAME_MAX  255
#define TZNAME_MAX     6
#define WORD_BIT       32
#define SEM_VALUE_MAX  0x7fffffff
#define SEM_NSEMS_MAX  256
#define DELAYTIMER_MAX 0x7fffffff
#define MQ_PRIO_MAX    32768
#define LOGIN_NAME_MAX 256

#define NL_ARGMAX  9
#define NL_MSGMAX  32767
#define NL_SETMAX  255
#define NL_TEXTMAX 2048

#define INT_FAST8_MIN    (-__INT_FAST8_MAX__ - 1)
#define INT_FAST16_MIN   (-__INT_FAST16_MAX__ - 1)
#define INT_FAST32_MIN   (-__INT_FAST32_MAX__ - 1)
#define INT_FAST64_MIN   (-__INT_FAST64_MAX__ - 1)
#define INT_LEAST8_MIN   (-__INT_LEAST8_MAX__ - 1)
#define INT_LEAST16_MIN  (-__INT_LEAST16_MAX__ - 1)
#define INT_LEAST32_MIN  (-__INT_LEAST32_MAX__ - 1)
#define INT_LEAST64_MIN  (-__INT_LEAST64_MAX__ - 1)
#define INT_FAST8_MAX    __INT_FAST8_MAX__
#define INT_FAST16_MAX   __INT_FAST16_MAX__
#define INT_FAST32_MAX   __INT_FAST32_MAX__
#define INT_FAST64_MAX   __INT_FAST64_MAX__
#define INT_LEAST8_MAX   __INT_LEAST8_MAX__
#define INT_LEAST16_MAX  __INT_LEAST16_MAX__
#define INT_LEAST32_MAX  __INT_LEAST32_MAX__
#define INT_LEAST64_MAX  __INT_LEAST64_MAX__
#define UINT_FAST8_MAX   __UINT_FAST8_MAX__
#define UINT_FAST16_MAX  __UINT_FAST16_MAX__
#define UINT_FAST32_MAX  __UINT_FAST32_MAX__
#define UINT_FAST64_MAX  __UINT_FAST64_MAX__
#define UINT_LEAST8_MAX  __UINT_LEAST8_MAX__
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__

#define BC_BASE_MAX        99
#define BC_DIM_MAX         2048
#define BC_SCALE_MAX       99
#define BC_STRING_MAX      1000
#define CHARCLASS_NAME_MAX 14
#define COLL_WEIGHTS_MAX   2
#define EXPR_NEST_MAX      32
#define LINE_MAX           4096
#define RE_DUP_MAX         255
#define LONG_BIT           64
#define NZERO              20
#define NL_LANGMAX         32



/*!BEGIN libc/literal.h */

#define COSMOPOLITAN_LIBC_LITERAL_H_
#define __STDC_CONSTANT_MACROS

#ifdef __INT8_C
#define INT8_C(c)   __INT8_C(c)
#define UINT8_C(c)  __UINT8_C(c)
#define INT16_C(c)  __INT16_C(c)
#define UINT16_C(c) __UINT16_C(c)
#define INT32_C(c)  __INT32_C(c)
#define UINT32_C(c) __UINT32_C(c)
#define INT64_C(c)  __INT64_C(c)
#define UINT64_C(c) __UINT64_C(c)
#else
#define INT8_C(c)   c
#define UINT8_C(c)  c
#define INT16_C(c)  c
#define UINT16_C(c) c
#define INT32_C(c)  c
#define UINT32_C(c) c##U
#define INT64_C(c)  c##L
#define UINT64_C(c) c##UL
#endif

#if UINTPTR_MAX == UINT64_MAX
#define INTMAX_C(c)  c##L
#define UINTMAX_C(c) c##UL
#else
#define INTMAX_C(c)  c##LL
#define UINTMAX_C(c) c##ULL
#endif



/*!BEGIN libc/math.h */

#define COSMOPOLITAN_LIBC_MATH_H_
/*─────────────────────────────────────────────────────────────────────────────╗
│ cosmopolitan § mathematics                                                   │
╚─────────────────────────────────────────────────────────────────────────────*/

#define M_E        2.7182818284590452354  /* 𝑒 */
#define M_LOG2E    1.4426950408889634074  /* log₂𝑒 */
#define M_LOG10E   0.43429448190325182765 /* log₁₀𝑒 */
#define M_LN2      0.69314718055994530942 /* logₑ2 */
#define M_LN10     2.30258509299404568402 /* logₑ10 */
#define M_PI       3.14159265358979323846 /* 𝜋 */
#define M_PI_2     1.57079632679489661923 /* 𝜋/2 */
#define M_PI_4     0.78539816339744830962 /* 𝜋/4 */
#define M_1_PI     0.31830988618379067154 /* 1/𝜋 */
#define M_2_PI     0.63661977236758134308 /* 2/𝜋 */
#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(𝜋) */
#define M_SQRT2    1.41421356237309504880 /* sqrt(2) */
#define M_SQRT1_2  0.70710678118654752440 /* 1/sqrt(2) */

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_Ef        2.7182818284590452354f  /* 𝑒 */
#define M_LOG2Ef    1.4426950408889634074f  /* log₂𝑒 */
#define M_LOG10Ef   0.43429448190325182765f /* log₁₀𝑒 */
#define M_LN2f      0.69314718055994530942f /* logₑ2 */
#define M_LN10f     2.30258509299404568402f /* logₑ10 */
#define M_PIf       3.14159265358979323846f /* 𝜋 */
#define M_PI_2f     1.57079632679489661923f /* 𝜋/2 */
#define M_PI_4f     0.78539816339744830962f /* 𝜋/4 */
#define M_1_PIf     0.31830988618379067154f /* 1/𝜋 */
#define M_2_PIf     0.63661977236758134308f /* 2/𝜋 */
#define M_2_SQRTPIf 1.12837916709551257390f /* 2/sqrt(𝜋) */
#define M_SQRT2f    1.41421356237309504880f /* sqrt(2) */
#define M_SQRT1_2f  0.70710678118654752440f /* 1/sqrt(2) */
#endif

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define M_El        2.718281828459045235360287471352662498L /* 𝑒 */
#define M_LOG2El    1.442695040888963407359924681001892137L /* log₂𝑒 */
#define M_LOG10El   0.434294481903251827651128918916605082L /* log₁₀𝑒 */
#define M_LN2l      0.693147180559945309417232121458176568L /* logₑ2 */
#define M_LN10l     2.302585092994045684017991454684364208L /* logₑ10 */
#define M_PIl       3.141592653589793238462643383279502884L /* 𝜋 */
#define M_PI_2l     1.570796326794896619231321691639751442L /* 𝜋/2 */
#define M_PI_4l     0.785398163397448309615660845819875721L /* 𝜋/4 */
#define M_1_PIl     0.318309886183790671537767526745028724L /* 1/𝜋 */
#define M_2_PIl     0.636619772367581343075535053490057448L /* 2/𝜋 */
#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(𝜋) */
#define M_SQRT2l    1.414213562373095048801688724209698079L /* sqrt(2) */
#define M_SQRT1_2l  0.707106781186547524400844362104849039L /* 1/sqrt(2) */
#endif

#define DBL_DECIMAL_DIG   __DBL_DECIMAL_DIG__
#define DBL_DIG           __DBL_DIG__
#define DBL_EPSILON       __DBL_EPSILON__
#define DBL_HAS_SUBNORM   __DBL_HAS_DENORM__
#define DBL_IS_IEC_60559  __DBL_IS_IEC_60559__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MANT_DIG      __DBL_MANT_DIG__
#define DBL_MAX           __DBL_MAX__
#define DBL_MAX_10_EXP    __DBL_MAX_10_EXP__
#define DBL_MAX_EXP       __DBL_MAX_EXP__
#define DBL_MIN           __DBL_MIN__ /* 2.23e–308 ↔ 1.79e308 */
#define DBL_MIN_10_EXP    __DBL_MIN_10_EXP__
#define DBL_MIN_EXP       __DBL_MIN_EXP__
#define DBL_NORM_MAX      __DBL_NORM_MAX__
#define DBL_TRUE_MIN      __DBL_DENORM_MIN__
#define DECIMAL_DIG       __LDBL_DECIMAL_DIG__
#define FLT_DECIMAL_DIG   __FLT_DECIMAL_DIG__
#define FLT_DIG           __FLT_DIG__
#define FLT_EPSILON       __FLT_EPSILON__
#define FLT_HAS_SUBNORM   __FLT_HAS_DENORM__
#define FLT_IS_IEC_60559  __FLT_IS_IEC_60559__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MANT_DIG      __FLT_MANT_DIG__
#define FLT_MAX           __FLT_MAX__
#define FLT_MAX_10_EXP    __FLT_MAX_10_EXP__
#define FLT_MAX_EXP       __FLT_MAX_EXP__
#define FLT_MIN           __FLT_MIN__ /* 1.18e–38 ↔ 3.40e38 */
#define FLT_MIN_10_EXP    __FLT_MIN_10_EXP__
#define FLT_MIN_EXP       __FLT_MIN_EXP__
#define FLT_NORM_MAX      __FLT_NORM_MAX__
#define FLT_RADIX         __FLT_RADIX__
#define FLT_TRUE_MIN      __FLT_DENORM_MIN__
#define HLF_MAX           6.50e4f
#define HLF_MIN           3.10e-5f
#define LDBL_DECIMAL_DIG  __LDBL_DECIMAL_DIG__
#define LDBL_DIG          __LDBL_DIG__
#define LDBL_EPSILON      __LDBL_EPSILON__
#define LDBL_HAS_SUBNORM  __LDBL_HAS_DENORM__
#define LDBL_IS_IEC_60559 __LDBL_IS_IEC_60559__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MANT_DIG     __LDBL_MANT_DIG__
#define LDBL_MAX          __LDBL_MAX__
#define LDBL_MAX_10_EXP   __LDBL_MAX_10_EXP__
#define LDBL_MAX_EXP      __LDBL_MAX_EXP__
#define LDBL_MIN          __LDBL_MIN__ /* 3.37e–4932 ↔ 1.18e4932 */
#define LDBL_MIN_10_EXP   __LDBL_MIN_10_EXP__
#define LDBL_MIN_EXP      __LDBL_MIN_EXP__
#define LDBL_NORM_MAX     __LDBL_NORM_MAX__
#define LDBL_TRUE_MIN     __LDBL_DENORM_MIN__

#define FP_NAN       0
#define FP_INFINITE  1
#define FP_ZERO      2
#define FP_SUBNORMAL 3
#define FP_NORMAL    4
#define FP_ILOGB0    (-2147483647 - 1)
#define FP_ILOGBNAN  (-2147483647 - 1)

#define MATH_ERRNO     1
#define MATH_ERREXCEPT 2

#ifdef __FAST_MATH__
#define math_errhandling 0
#elif defined(__NO_MATH_ERRNO__)
#define math_errhandling (MATH_ERREXCEPT)
#else
#define math_errhandling (MATH_ERRNO | MATH_ERREXCEPT)
#endif

#ifdef __FP_FAST_FMA
#define FP_FAST_FMA 1
#endif
#ifdef __FP_FAST_FMAF
#define FP_FAST_FMAF 1
#endif
#ifdef __FP_FAST_FMAL
#define FP_FAST_FMAL 1
#endif

COSMOPOLITAN_C_START_

#define NAN       __builtin_nanf("")
#define INFINITY  __builtin_inff()
#define HUGE_VAL  __builtin_inf()
#define HUGE_VALF __builtin_inff()
#define HUGE_VALL __builtin_infl()

#if __FLT_EVAL_METHOD__ + 0 == 2
typedef long double float_t;
typedef long double double_t;
#else
typedef float float_t;
typedef double double_t;
#endif

#define isinf(x)             __builtin_isinf(x)
#define isnan(x)             __builtin_isnan(x)
#define isfinite(x)          __builtin_isfinite(x)
#define isnormal(x)          __builtin_isnormal(x)
#define isgreater(x, y)      __builtin_isgreater(x, y)
#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
#define isless(x, y)         __builtin_isless(x, y)
#define islessequal(x, y)    __builtin_islessequal(x, y)
#define islessgreater(x, y)  __builtin_islessgreater(x, y)
#define isunordered(x, y)    __builtin_isunordered(x, y)

#define fpclassify(x) \
  __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)

#define signbit(x)                                          \
  (sizeof(x) == sizeof(long double) ? __builtin_signbitl(x) \
   : sizeof(x) == sizeof(float)     ? __builtin_signbitf(x) \
                                    : __builtin_signbit(x))

extern int signgam;

double acos(double) libcesque;
double acosh(double) libcesque;
double asin(double) libcesque;
double asinh(double) libcesque;
double atan(double) libcesque;
double atan2(double, double) libcesque;
double atanh(double) libcesque;
double cbrt(double) libcesque;
double ceil(double) libcesque;
double copysign(double, double) libcesque;
double cos(double) libcesque;
double cosh(double) libcesque;
double drem(double, double) libcesque;
double erf(double) libcesque;
double erfc(double) libcesque;
double exp(double) libcesque;
double exp10(double) libcesque;
double exp2(double) libcesque;
double expm1(double) libcesque;
double fabs(double) libcesque;
double fdim(double, double) libcesque;
double floor(double) libcesque;
double fma(double, double, double) libcesque;
double fmax(double, double) libcesque;
double fmin(double, double) libcesque;
double fmod(double, double) libcesque;
double hypot(double, double) libcesque;
double ldexp(double, int) libcesque;
double log(double) libcesque;
double log10(double) libcesque;
double log1p(double) libcesque;
double log2(double) libcesque;
double logb(double) libcesque;
double nearbyint(double) libcesque;
double nextafter(double, double) libcesque;
double nexttoward(double, long double) libcesque;
double pow(double, double) libcesque;
double pow10(double) libcesque;
double powi(double, int) libcesque;
double remainder(double, double) libcesque;
double rint(double) libcesque;
double round(double) libcesque;
double scalb(double, double) libcesque;
double scalbln(double, long int) libcesque;
double scalbn(double, int) libcesque;
double significand(double) libcesque;
double sin(double) libcesque;
double sinh(double) libcesque;
double sqrt(double) libcesque;
double tan(double) libcesque;
double tanh(double) libcesque;
double trunc(double) libcesque;
double tgamma(double) libcesque;
double lgamma(double) libcesque;
double lgamma_r(double, int *) libcesque;
int finite(double) libcesque;

float acosf(float) libcesque;
float acoshf(float) libcesque;
float asinf(float) libcesque;
float asinhf(float) libcesque;
float atan2f(float, float) libcesque;
float atanf(float) libcesque;
float atanhf(float) libcesque;
float cbrtf(float) libcesque;
float ceilf(float) libcesque;
float copysignf(float, float) libcesque;
float cosf(float) libcesque;
float coshf(float) libcesque;
float dremf(float, float) libcesque;
float erfcf(float) libcesque;
float erff(float) libcesque;
float exp10f(float) libcesque;
float exp2f(float) libcesque;
float expf(float) libcesque;
float expm1f(float) libcesque;
float fabsf(float) libcesque;
float fdimf(float, float) libcesque;
float floorf(float) libcesque;
float fmaf(float, float, float) libcesque;
float fmaxf(float, float) libcesque;
float fminf(float, float) libcesque;
float fmodf(float, float) libcesque;
float hypotf(float, float) libcesque;
float ldexpf(float, int) libcesque;
float lgammaf(float) libcesque;
float lgammaf_r(float, int *) libcesque;
float log10f(float) libcesque;
float log1pf(float) libcesque;
float log2f(float) libcesque;
float logbf(float) libcesque;
float logf(float) libcesque;
float nearbyintf(float) libcesque;
float nextafterf(float, float) libcesque;
float nexttowardf(float, long double) libcesque;
float pow10f(float) libcesque;
float powf(float, float) libcesque;
float powif(float, int) libcesque;
float remainderf(float, float) libcesque;
float rintf(float) libcesque;
float roundf(float) libcesque;
float scalbf(float, float) libcesque;
float scalblnf(float, long int) libcesque;
float scalbnf(float, int) libcesque;
float significandf(float) libcesque;
float sinf(float) libcesque;
float sinhf(float) libcesque;
float sqrtf(float) libcesque;
float tanf(float) libcesque;
float tanhf(float) libcesque;
float tgammaf(float) libcesque;
float truncf(float) libcesque;
int finitef(float) libcesque;

int finitel(long double) libcesque;
long double acoshl(long double) libcesque;
long double acosl(long double) libcesque;
long double asinhl(long double) libcesque;
long double asinl(long double) libcesque;
long double atan2l(long double, long double) libcesque;
long double atanhl(long double) libcesque;
long double atanl(long double) libcesque;
long double cbrtl(long double) libcesque;
long double ceill(long double) libcesque;
long double copysignl(long double, long double) libcesque;
long double coshl(long double) libcesque;
long double cosl(long double) libcesque;
long double dreml(long double, long double) libcesque;
long double erfcl(long double) libcesque;
long double erfl(long double) libcesque;
long double exp10l(long double) libcesque;
long double exp2l(long double) libcesque;
long double expl(long double) libcesque;
long double expm1l(long double) libcesque;
long double fabsl(long double) libcesque;
long double fdiml(long double, long double) libcesque;
long double floorl(long double) libcesque;
long double fmal(long double, long double, long double) libcesque;
long double fmaxl(long double, long double) libcesque;
long double fminl(long double, long double) libcesque;
long double fmodl(long double, long double) libcesque;
long double hypotl(long double, long double) libcesque;
long double ldexpl(long double, int) libcesque;
long double lgammal(long double) libcesque;
long double lgammal_r(long double, int *) libcesque;
long double log10l(long double) libcesque;
long double log1pl(long double) libcesque;
long double log2l(long double) libcesque;
long double logbl(long double) libcesque;
long double logl(long double) libcesque;
long double nearbyintl(long double) libcesque;
long double nextafterl(long double, long double) libcesque;
long double nexttowardl(long double, long double) libcesque;
long double pow10l(long double) libcesque;
long double powl(long double, long double) libcesque;
long double remainderl(long double, long double) libcesque;
long double rintl(long double) libcesque;
long double roundl(long double) libcesque;
long double scalbl(long double, long double) libcesque;
long double scalblnl(long double, long int) libcesque;
long double scalbnl(long double, int) libcesque;
long double significandl(long double) libcesque;
long double sinhl(long double) libcesque;
long double sinl(long double) libcesque;
long double sqrtl(long double) libcesque;
long double tanhl(long double) libcesque;
long double tanl(long double) libcesque;
long double tgammal(long double) libcesque;
long double truncl(long double) libcesque;

long lrint(double) libcesque;
long lrintf(float) libcesque;
long lrintl(long double) libcesque;
long lround(double) libcesque;
long lroundf(float) libcesque;
long lroundl(long double) libcesque;

int ilogbf(float) libcesque;
int ilogb(double) libcesque;
int ilogbl(long double) libcesque;

long long llrint(double) libcesque;
long long llrintf(float) libcesque;
long long llrintl(long double) libcesque;
long long llround(double) libcesque;
long long llroundf(float) libcesque;
long long llroundl(long double) libcesque;

double frexp(double, int *) libcesque;
double modf(double, double *) libcesque;
double nan(const char *) libcesque;
double remquo(double, double, int *) libcesque;
float frexpf(float, int *) libcesque;
float modff(float, float *) libcesque;
float nanf(const char *) libcesque;
float remquof(float, float, int *) libcesque;
long double frexpl(long double, int *) libcesque;
long double modfl(long double, long double *) libcesque;
long double nanl(const char *) libcesque;
long double remquol(long double, long double, int *) libcesque;
void sincos(double, double *, double *) libcesque;
void sincosf(float, float *, float *) libcesque;
void sincosl(long double, long double *, long double *) libcesque;

double fsumf(const float *, size_t) libcesque;
double fsum(const double *, size_t) libcesque;

double j0(double) libcesque;
double j1(double) libcesque;
double jn(int, double) libcesque;
float j0f(float) libcesque;
float j1f(float) libcesque;
float jnf(int, float) libcesque;

double y0(double) libcesque;
double y1(double) libcesque;
double yn(int, double) libcesque;
float y0f(float) libcesque;
float y1f(float) libcesque;
float ynf(int, float) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/paths.h */

#define COSMOPOLITAN_LIBC_PATHS_H_

#define _PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin"
#define _PATH_STDPATH "/bin:/usr/bin:/sbin:/usr/sbin"

#define _PATH_BSHELL   "/bin/sh"
#define _PATH_CONSOLE  "/dev/console"
#define _PATH_DEVNULL  "/dev/null"
#define _PATH_KLOG     "/proc/kmsg"
#define _PATH_LASTLOG  "/var/log/lastlog"
#define _PATH_MAILDIR  "/var/mail"
#define _PATH_MAN      "/usr/share/man"
#define _PATH_MNTTAB   "/etc/fstab"
#define _PATH_MOUNTED  "/etc/mtab"
#define _PATH_NOLOGIN  "/etc/nologin"
#define _PATH_SENDMAIL "/usr/sbin/sendmail"
#define _PATH_SHADOW   "/etc/shadow"
#define _PATH_SHELLS   "/etc/shells"
#define _PATH_TTY      "/dev/tty"
#define _PATH_UTMP     "/dev/null/utmp"
#define _PATH_VI       "/usr/bin/vi"
#define _PATH_WTMP     "/dev/null/wtmp"

#define _PATH_DEV    "/dev/"
#define _PATH_TMP    "/tmp/"
#define _PATH_VARDB  "/var/lib/misc/"
#define _PATH_VARRUN "/var/run/"
#define _PATH_VARTMP "/var/tmp/"



/*!BEGIN libc/serialize.h */

#define COSMOPOLITAN_SERIALIZE_H_
#ifdef _COSMO_SOURCE

#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define __SWAPBE16(x) (x)
#define __SWAPBE32(x) (x)
#define __SWAPBE64(x) (x)
#else
#define __SWAPBE16(x) __builtin_bswap16(x)
#define __SWAPBE32(x) __builtin_bswap32(x)
#define __SWAPBE64(x) __builtin_bswap64(x)
#endif

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define __SWAPLE16(x) (x)
#define __SWAPLE32(x) (x)
#define __SWAPLE64(x) (x)
#else
#define __SWAPLE16(x) __builtin_bswap16(x)
#define __SWAPLE32(x) __builtin_bswap32(x)
#define __SWAPLE64(x) __builtin_bswap64(x)
#endif

#define READ16LE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPLE16(__x);                   \
  }))

#define READ16BE(P)                    \
  (__extension__({                     \
    uint16_t __x;                      \
    __builtin_memcpy(&__x, P, 16 / 8); \
    __SWAPBE16(__x);                   \
  }))

#define READ32LE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ32BE(P)                    \
  (__extension__({                     \
    uint32_t __x;                      \
    __builtin_memcpy(&__x, P, 32 / 8); \
    __SWAPBE32(__x);                   \
  }))

#define READ64LE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPLE32(__x);                   \
  }))

#define READ64BE(P)                    \
  (__extension__({                     \
    uint64_t __x;                      \
    __builtin_memcpy(&__x, P, 64 / 8); \
    __SWAPBE64(__x);                   \
  }))

#define WRITE16LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPLE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE16BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint16_t __x = __SWAPBE16(X);        \
    __builtin_memcpy(__p, &__x, 16 / 8); \
    __p + 16 / 8;                        \
  }))

#define WRITE32LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPLE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE32BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint32_t __x = __SWAPBE32(X);        \
    __builtin_memcpy(__p, &__x, 32 / 8); \
    __p + 32 / 8;                        \
  }))

#define WRITE64LE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPLE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#define WRITE64BE(P, X)                  \
  (__extension__({                       \
    __typeof__(&(P)[0]) __p = (P);       \
    uint64_t __x = __SWAPBE64(X);        \
    __builtin_memcpy(__p, &__x, 64 / 8); \
    __p + 64 / 8;                        \
  }))

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/stdckdint.h */

#define COSMOPOLITAN_LIBC_STDCKDINT_H_
/* clang-format off */

/**
 * @fileoverview C23 Checked Arithmetic
 *
 * This header defines three type generic functions:
 *
 *   - `bool ckd_add(res, a, b)`
 *   - `bool ckd_sub(res, a, b)`
 *   - `bool ckd_mul(res, a, b)`
 *
 * Which allow integer arithmetic errors to be detected. There are many
 * kinds of integer errors, e.g. overflow, truncation, etc. These funcs
 * catch them all. Here's an example of how it works:
 *
 *     uint32_t c;
 *     int32_t a = 0x7fffffff;
 *     int32_t b = 2;
 *     assert(!ckd_add(&c, a, b));
 *     assert(c == 0x80000001u);
 *
 * Experienced C / C++ users should find this example counter-intuitive
 * because the expression `0x7fffffff + 2` not only overflows it's also
 * undefined behavior. However here we see it's specified, and does not
 * result in an error. That's because C23 checked arithmetic is not the
 * arithmetic you're used to. The new standard changes the mathematics.
 *
 * C23 checked arithmetic is defined as performing the arithmetic using
 * infinite precision and then checking if the resulting value will fit
 * in the output type. Our example above did not result in an error due
 * to `0x80000001` being a legal value for `uint32_t`.
 *
 * This implementation will use the GNU compiler builtins, when they're
 * available, only if you don't use build flags like `-std=c11` because
 * they define `__STRICT_ANSI__` and GCC extensions aren't really ANSI.
 * Instead, you'll get a pretty good pure C11 and C++11 implementation.
 *
 * @see https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3096.pdf
 * @version 0.1 (2023-07-22)
 */

#define __STDC_VERSION_STDCKDINT_H__ 202311L

#if ((defined(__llvm__) ||                                              \
      (defined(__GNUC__) && __GNUC__ * 100 + __GNUC_MINOR__ >= 406)) && \
     !defined(__STRICT_ANSI__))
#define __ckd_have_int128
#define __ckd_intmax __int128
#elif ((defined(__cplusplus) && __cplusplus >= 201103L) ||              \
       (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L))
#define __ckd_intmax long long
#else
#define __ckd_intmax long
#endif

typedef signed __ckd_intmax __ckd_intmax_t;
typedef unsigned __ckd_intmax __ckd_uintmax_t;

#if (!defined(__STRICT_ANSI__) &&                       \
     ((defined(__GNUC__) && __GNUC__ >= 5 &&            \
       !defined(__chibicc__) && !defined(__ICC)) ||     \
      (__has_builtin(__builtin_add_overflow) &&         \
       __has_builtin(__builtin_sub_overflow) &&         \
       __has_builtin(__builtin_mul_overflow))))
#define ckd_add(res, x, y) __builtin_add_overflow((x), (y), (res))
#define ckd_sub(res, x, y) __builtin_sub_overflow((x), (y), (res))
#define ckd_mul(res, x, y) __builtin_mul_overflow((x), (y), (res))

#elif defined(__cplusplus) && __cplusplus >= 201103L

template <typename __T, typename __U, typename __V>
inline bool ckd_add(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x + __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u + u
      return __truncated | (__z < __x);
    case 1:  // u = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 2:  // u = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    case 3:  // u = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z | __x) &  __y) |
                                       ((__z & __x) & ~__y)) < 0);
    case 4:  // s = u + u
      return __truncated | (__z < __x) | (static_cast<__ckd_intmax_t>(__z) < 0);
    case 5:  // s = u + s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __y);
    case 6:  // s = s + u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x + __y < __x);
    case 7:  // s = s + s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__z ^ __x) &
                                       (__z ^ __y)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_sub(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  __ckd_uintmax_t __z = __x - __y;
  *__res = __z;
  if (sizeof(__z) > sizeof(__U) && sizeof(__z) > sizeof(__V)) {
    if (sizeof(__z) > sizeof(__T) || std::is_signed<__T>::value) {
      return static_cast<__ckd_intmax_t>(__z) != static_cast<__T>(__z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  bool __truncated = false;
  if (sizeof(__T) < sizeof(__ckd_intmax_t)) {
    __truncated = __z != static_cast<__ckd_uintmax_t>(static_cast<__T>(__z));
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0:  // u = u - u
      return __truncated | (__x < __y);
    case 1:  // u = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    case 2:  // u = s - u
      return __truncated | (__y > __x) | (static_cast<__ckd_intmax_t>(__x) < 0);
    case 3:  // u = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>(((__z & __x) &  __y) |
                                       ((__z | __x) & ~__y)) < 0);
    case 4:  // s = u - u
      return __truncated |
          ((__x < __y) ^ (static_cast<__ckd_intmax_t>(__z) < 0));
    case 5:  // s = u - s
      __y ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x >= __y);
    case 6:  // s = s - u
      __x ^= std::numeric_limits<__ckd_intmax_t>::min();
      return __truncated | (__x < __y);
    case 7:  // s = s - s
      return __truncated |
          (static_cast<__ckd_intmax_t>((__x ^ __y) &
                                       (__z ^ __x)) < 0);
    default:
      for (;;) (void)0;
  }
}

template <typename __T, typename __U, typename __V>
inline bool ckd_mul(__T *__res, __U __a, __V __b) {
  static_assert(std::is_integral<__T>::value &&
                std::is_integral<__U>::value &&
                std::is_integral<__V>::value,
                "non-integral types not allowed");
  static_assert(!std::is_same<__T, bool>::value &&
                !std::is_same<__U, bool>::value &&
                !std::is_same<__V, bool>::value,
                "checked booleans not supported");
  static_assert(!std::is_same<__T, char>::value &&
                !std::is_same<__U, char>::value &&
                !std::is_same<__V, char>::value,
                "unqualified char type is ambiguous");
  __ckd_uintmax_t __x = __a;
  __ckd_uintmax_t __y = __b;
  if ((sizeof(__U) * 8 - std::is_signed<__U>::value) +
      (sizeof(__V) * 8 - std::is_signed<__V>::value) <=
      (sizeof(__T) * 8 - std::is_signed<__T>::value)) {
    if (sizeof(__ckd_uintmax_t) > sizeof(__T) || std::is_signed<__T>::value) {
      __ckd_intmax_t __z = __x * __y;
      return __z != (*__res = __z);
    } else if (!std::is_same<__T, __ckd_uintmax_t>::value) {
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return (__z != static_cast<__T>(__z) ||
              ((std::is_signed<__U>::value ||
                std::is_signed<__V>::value) &&
               static_cast<__ckd_intmax_t>(__z) < 0));
    }
  }
  switch (std::is_signed<__T>::value << 2 |  //
          std::is_signed<__U>::value << 1 |  //
          std::is_signed<__V>::value) {
    case 0: {  // u = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 1: {  // u = u * s
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__y) < 0) & !!__x) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 2: {  // u = s * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | ((static_cast<__ckd_intmax_t>(__x) < 0) & !!__y) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 3: { // u = s * s
      int __o = false;
      if (static_cast<__ckd_intmax_t>(__x & __y) < 0) {
        __x = -__x;
        __y = -__y;
      } else if (static_cast<__ckd_intmax_t>(__x ^ __y) < 0) {
        __o = __x && __y;
      }
      __ckd_uintmax_t __z = __x * __y;
      __o |= __x && __z / __x != __y;
      *__res = __z;
      return __o | (sizeof(__T) < sizeof(__z) &&
                    __z != static_cast<__ckd_uintmax_t>(*__res));
    }
    case 4: {  // s = u * u
      __ckd_uintmax_t __z = __x * __y;
      int __o = __x && __z / __x != __y;
      *__res = __z;
      return (__o | (static_cast<__ckd_intmax_t>(__z) < 0) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 5: {  // s = u * s
      __ckd_uintmax_t __t = -__y;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __y : __t;
      __ckd_uintmax_t __p = __t * __x;
      int __o = __t && __p / __t != __x;
      int __n = static_cast<__ckd_intmax_t>(__y) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 6: {  // s = s * u
      __ckd_uintmax_t __t = -__x;
      __t = static_cast<__ckd_intmax_t>(__t) < 0 ? __x : __t;
      __ckd_uintmax_t __p = __t * __y;
      int __o = __t && __p / __t != __y;
      int __n = static_cast<__ckd_intmax_t>(__x) < 0;
      __ckd_uintmax_t __z = __n ? -__p : __p;
      *__res = __z;
      __ckd_uintmax_t __m = std::numeric_limits<__ckd_intmax_t>::max();
      return (__o | (__p > __m + __n) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    case 7: {  // s = s * s
      __ckd_uintmax_t __z = __x * __y;
      *__res = __z;
      return ((((static_cast<__ckd_intmax_t>(__y) < 0) &&
                (static_cast<__ckd_intmax_t>(__x) ==
                 std::numeric_limits<__ckd_intmax_t>::min())) ||
               (__y && ((static_cast<__ckd_intmax_t>(__z) /
                         static_cast<__ckd_intmax_t>(__y)) !=
                        static_cast<__ckd_intmax_t>(__x)))) |
              (sizeof(__T) < sizeof(__z) &&
               __z != static_cast<__ckd_uintmax_t>(*__res)));
    }
    default:
      for (;;) (void)0;
  }
}

#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L

#define ckd_add(res, a, b) __ckd_expr(add, (res), (a), (b))
#define ckd_sub(res, a, b) __ckd_expr(sub, (res), (a), (b))
#define ckd_mul(res, a, b) __ckd_expr(mul, (res), (a), (b))

#if defined(__GNUC__) || defined(__llvm__)
#define __ckd_inline                                    \
  extern __inline __attribute__((__gnu_inline__,        \
                                 __always_inline__,     \
                                 __artificial__))
#else
#define __ckd_inline static inline
#endif

#ifdef __ckd_have_int128
#define __ckd_generic_int128(x, y) , signed __int128: x, unsigned __int128: y
#else
#define __ckd_generic_int128(x, y)
#endif

#define __ckd_sign(T)                           \
  ((T)1 << (sizeof(T) * 8 - 1))

#define __ckd_is_signed(x)                      \
  _Generic(x,                                   \
           signed char: 1,                      \
           unsigned char: 0,                    \
           signed short: 1,                     \
           unsigned short: 0,                   \
           signed int: 1,                       \
           unsigned int: 0,                     \
           signed long: 1,                      \
           unsigned long: 0,                    \
           signed long long: 1,                 \
           unsigned long long: 0                \
           __ckd_generic_int128(1, 0))

#define __ckd_expr(op, res, a, b)                       \
  (_Generic(*res,                                       \
            signed char: __ckd_##op##_schar,            \
            unsigned char: __ckd_##op##_uchar,          \
            signed short: __ckd_##op##_sshort,          \
            unsigned short: __ckd_##op##_ushort,        \
            signed int: __ckd_##op##_sint,              \
            unsigned int: __ckd_##op##_uint,            \
            signed long: __ckd_##op##_slong,            \
            unsigned long: __ckd_##op##_ulong,          \
            signed long long: __ckd_##op##_slonger,     \
            unsigned long long: __ckd_##op##_ulonger    \
            __ckd_generic_int128(                       \
                __ckd_##op##_sint128,                   \
                __ckd_##op##_uint128))(                 \
                    res, a, b,                          \
                    __ckd_is_signed(a),                 \
                    __ckd_is_signed(b)))

#define __ckd_declare_add(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x + __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u + u */                                          \
        return __truncated | (__z < __x);                               \
      case 1:  /* u = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 2:  /* u = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      case 3:  /* u = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z | __x) &  __y) |                    \
                              ((__z & __x) & ~__y)) < 0);               \
      case 4:  /* s = u + u */                                          \
        return __truncated | (__z < __x) | ((__ckd_intmax_t)__z < 0);   \
      case 5:  /* s = u + s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __y);                         \
      case 6:  /* s = s + u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x + __y < __x);                         \
      case 7:  /* s = s + s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__z ^ __x) &                             \
                              (__z ^ __y)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_add(__ckd_add_schar, signed char)
__ckd_declare_add(__ckd_add_uchar, unsigned char)
__ckd_declare_add(__ckd_add_sshort, signed short)
__ckd_declare_add(__ckd_add_ushort, unsigned short)
__ckd_declare_add(__ckd_add_sint, signed int)
__ckd_declare_add(__ckd_add_uint, unsigned int)
__ckd_declare_add(__ckd_add_slong, signed long)
__ckd_declare_add(__ckd_add_ulong, unsigned long)
__ckd_declare_add(__ckd_add_slonger, signed long long)
__ckd_declare_add(__ckd_add_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_add(__ckd_add_sint128, signed __int128)
__ckd_declare_add(__ckd_add_uint128, unsigned __int128)
#endif

#define __ckd_declare_sub(S, T)                                         \
  __ckd_inline char S(void *__res,                                      \
                      __ckd_uintmax_t __x,                              \
                      __ckd_uintmax_t __y,                              \
                      char __a_signed,                                  \
                      char __b_signed) {                                \
    __ckd_uintmax_t __z = __x - __y;                                    \
    *(T *)__res = __z;                                                  \
    char __truncated = 0;                                               \
    if (sizeof(T) < sizeof(__ckd_intmax_t)) {                           \
      __truncated = __z != (__ckd_uintmax_t)(T)__z;                     \
    }                                                                   \
    switch (__ckd_is_signed((T)0) << 2 |                                \
            __a_signed << 1 | __b_signed) {                             \
      case 0:  /* u = u - u */                                          \
        return __truncated | (__x < __y);                               \
      case 1:  /* u = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      case 2:  /* u = s - u */                                          \
        return __truncated | (__y > __x) | ((__ckd_intmax_t)__x < 0);   \
      case 3:  /* u = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)(((__z & __x) &  __y) |                    \
                              ((__z | __x) & ~__y)) < 0);               \
      case 4:  /* s = u - u */                                          \
        return __truncated | ((__x < __y) ^ ((__ckd_intmax_t)__z < 0)); \
      case 5:  /* s = u - s */                                          \
        __y ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x >= __y);                              \
      case 6:  /* s = s - u */                                          \
        __x ^= __ckd_sign(__ckd_uintmax_t);                             \
        return __truncated | (__x < __y);                               \
      case 7:  /* s = s - s */                                          \
        return __truncated |                                            \
            ((__ckd_intmax_t)((__x ^ __y) &                             \
                              (__z ^ __x)) < 0);                        \
      default:                                                          \
        for (;;) (void)0;                                               \
    }                                                                   \
  }

__ckd_declare_sub(__ckd_sub_schar, signed char)
__ckd_declare_sub(__ckd_sub_uchar, unsigned char)
__ckd_declare_sub(__ckd_sub_sshort, signed short)
__ckd_declare_sub(__ckd_sub_ushort, unsigned short)
__ckd_declare_sub(__ckd_sub_sint, signed int)
__ckd_declare_sub(__ckd_sub_uint, unsigned int)
__ckd_declare_sub(__ckd_sub_slong, signed long)
__ckd_declare_sub(__ckd_sub_ulong, unsigned long)
__ckd_declare_sub(__ckd_sub_slonger, signed long long)
__ckd_declare_sub(__ckd_sub_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_sub(__ckd_sub_sint128, signed __int128)
__ckd_declare_sub(__ckd_sub_uint128, unsigned __int128)
#endif

#define __ckd_declare_mul(S, T)                                 \
  __ckd_inline char S(void *__res,                              \
                      __ckd_uintmax_t __x,                      \
                      __ckd_uintmax_t __y,                      \
                      char __a_signed,                          \
                      char __b_signed) {                        \
    switch (__ckd_is_signed((T)0) << 2 |                        \
            __a_signed << 1 | __b_signed) {                     \
      case 0: {  /* u = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 1: {  /* u = u * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__y < 0) & !!__x) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 2: {  /* u = s * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | (((__ckd_intmax_t)__x < 0) & !!__y) |     \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 3: {  /* u = s * s */                                \
        int __o = 0;                                            \
        if ((__ckd_intmax_t)(__x & __y) < 0) {                  \
          __x = -__x;                                           \
          __y = -__y;                                           \
        } else if ((__ckd_intmax_t)(__x ^ __y) < 0) {           \
          __o = __x && __y;                                     \
        }                                                       \
        __ckd_uintmax_t __z = __x * __y;                        \
        __o |= __x && __z / __x != __y;                         \
        *(T *)__res = __z;                                      \
        return __o | (sizeof(T) < sizeof(__z) &&                \
                      __z != (__ckd_uintmax_t)*(T *)__res);     \
      }                                                         \
      case 4: {  /* s = u * u */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        int __o = __x && __z / __x != __y;                      \
        *(T *)__res = __z;                                      \
        return (__o | ((__ckd_intmax_t)(__z) < 0) |             \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 5: {  /* s = u * s */                                \
        __ckd_uintmax_t __t = -__y;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __y : __t;            \
        __ckd_uintmax_t __p = __t * __x;                        \
        int __o = __t && __p / __t != __x;                      \
        int __n = (__ckd_intmax_t)__y < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 6: {  /* s = s * u */                                \
        __ckd_uintmax_t __t = -__x;                             \
        __t = (__ckd_intmax_t)(__t) < 0 ? __x : __t;            \
        __ckd_uintmax_t __p = __t * __y;                        \
        int __o = __t && __p / __t != __y;                      \
        int __n = (__ckd_intmax_t)__x < 0;                      \
        __ckd_uintmax_t __z = __n ? -__p : __p;                 \
        *(T *)__res = __z;                                      \
        __ckd_uintmax_t __m = __ckd_sign(__ckd_uintmax_t) - 1;  \
        return (__o | (__p > __m + __n) |                       \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      case 7: {  /* s = s * s */                                \
        __ckd_uintmax_t __z = __x * __y;                        \
        *(T *)__res = __z;                                      \
        return (((((__ckd_intmax_t)__y < 0) &&                  \
                  (__x == __ckd_sign(__ckd_uintmax_t))) ||      \
                 (__y && (((__ckd_intmax_t)__z /                \
                           (__ckd_intmax_t)__y) !=              \
                          (__ckd_intmax_t)__x))) |              \
                (sizeof(T) < sizeof(__z) &&                     \
                 __z != (__ckd_uintmax_t)*(T *)__res));         \
      }                                                         \
      default:                                                  \
        for (;;) (void)0;                                       \
    }                                                           \
  }

__ckd_declare_mul(__ckd_mul_schar, signed char)
__ckd_declare_mul(__ckd_mul_uchar, unsigned char)
__ckd_declare_mul(__ckd_mul_sshort, signed short)
__ckd_declare_mul(__ckd_mul_ushort, unsigned short)
__ckd_declare_mul(__ckd_mul_sint, signed int)
__ckd_declare_mul(__ckd_mul_uint, unsigned int)
__ckd_declare_mul(__ckd_mul_slong, signed long)
__ckd_declare_mul(__ckd_mul_ulong, unsigned long)
__ckd_declare_mul(__ckd_mul_slonger, signed long long)
__ckd_declare_mul(__ckd_mul_ulonger, unsigned long long)
#ifdef __ckd_have_int128
__ckd_declare_mul(__ckd_mul_sint128, signed __int128)
__ckd_declare_mul(__ckd_mul_uint128, unsigned __int128)
#endif

#else
#pragma message "checked integer arithmetic unsupported in this environment"

#define ckd_add(res, x, y) (*(res) = (x) + (y), 0)
#define ckd_sub(res, x, y) (*(res) = (x) - (y), 0)
#define ckd_mul(res, x, y) (*(res) = (x) * (y), 0)

#endif /* GNU */
/* clang-format on */


/*!BEGIN libc/stdlib.h */

#define COSMOPOLITAN_LIBC_STDLIB_H_
COSMOPOLITAN_C_START_

char *fcvt(double, int, int *, int *) libcesque;
char *ecvt(double, int, int *, int *) libcesque;
char *gcvt(double, int, char *) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void setkey(const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/temp.h */

#define COSMOPOLITAN_LIBC_TEMP_H_
COSMOPOLITAN_C_START_

char *mktemp(char *) libcesque returnsnonnull paramsnonnull();
char *mkdtemp(char *) libcesque paramsnonnull() __wur;
int mkstemp(char *) libcesque paramsnonnull() __wur;
int mkstemps(char *, int) libcesque paramsnonnull() __wur;

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
int mkostemp(char *, unsigned) libcesque paramsnonnull() __wur;
int mkostemps(char *, int, unsigned) libcesque paramsnonnull() __wur;
#endif

#ifdef _COSMO_SOURCE
int openatemp(int, char *, int, int, int) libcesque paramsnonnull() __wur;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/time.h */

#define COSMOPOLITAN_LIBC_TIME_H_

#define TIME_UTC 1

COSMOPOLITAN_C_START_

struct tm {
  int32_t tm_sec;
  int32_t tm_min;
  int32_t tm_hour;
  int32_t tm_mday; /* 1-indexed */
  int32_t tm_mon;  /* 0-indexed */
  int32_t tm_year; /* minus 1900 */
  int32_t tm_wday;
  int32_t tm_yday;
  int32_t tm_isdst;
  int64_t tm_gmtoff;
  const char *tm_zone;
};

struct timezone {
  int32_t tz_minuteswest;
  int32_t tz_dsttime;
};

extern char *tzname[2];
extern long timezone;
extern int daylight;

void tzset(void) libcesque;
char *asctime(const struct tm *) libcesque;
char *asctime_r(const struct tm *, char *) libcesque;
char *strptime(const char *, const char *, struct tm *) libcesque;
int64_t mktime(struct tm *) libcesque;
int64_t timegm(struct tm *) libcesque;
int64_t timelocal(struct tm *) libcesque;
int64_t timeoff(struct tm *, long) libcesque;
size_t strftime(char *, size_t, const char *, const struct tm *) libcesque
    strftimeesque(3) libcesque;
size_t wcsftime(wchar_t *, size_t, const wchar_t *,
                const struct tm *) libcesque;
struct tm *gmtime(const int64_t *) libcesque;
struct tm *gmtime_r(const int64_t *, struct tm *) libcesque;
struct tm *localtime(const int64_t *) libcesque;
struct tm *localtime_r(const int64_t *, struct tm *) libcesque;

char *ctime(const int64_t *) libcesque;
char *ctime_r(const int64_t *, char *) libcesque;
double difftime(int64_t, int64_t)
pureconst libcesque;
int stime(const int64_t *) libcesque;
void tzset(void) libcesque;

#ifdef _COSMO_SOURCE
extern const char kWeekdayNameShort[7][4];
extern const char kWeekdayName[7][10];
extern const char kMonthNameShort[12][4];
extern const char kMonthName[12][10];
extern const unsigned short kMonthYearDay[2][12];
#define iso8601 __iso8601
char *iso8601(char[hasatleast 20], struct tm *) libcesque;
#define iso8601us __iso8601us
char *iso8601us(char[hasatleast 27], struct tm *, long) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/type2str.h */

#define COSMOPOLITAN_LIBC_TYPE2STR_H_
#if __STDC_VERSION__ + 0 >= 201112
/* clang-format off */

#define _TYPE2STR(X)                          \
  _Generic(X,                                 \
    _Bool:              "_Bool",              \
    signed char:        "signed char",        \
    unsigned char:      "unsigned char",      \
    char:               "char",               \
    short:              "short",              \
    unsigned short:     "unsigned short",     \
    int:                "int",                \
    unsigned:           "unsigned",           \
    long:               "long",               \
    unsigned long:      "unsigned long",      \
    long long:          "long long",          \
    unsigned long long: "unsigned long long", \
    __int128:           "__int128",           \
    unsigned __int128:  "unsigned __int128",  \
    float:              "float",              \
    double:             "double",             \
    long double:        "long double")

#define _PRINTF_GENERIC(X, D, U) \
  _Generic(X,                    \
    _Bool:              "hhh" U, \
    signed char:        "hh" D,  \
    unsigned char:      "hh" U,  \
    char:               "hh" D,  \
    short:              "h" D,   \
    unsigned short:     "h" U,   \
    int:                D,       \
    unsigned:           U,       \
    long:               "l" D,   \
    unsigned long:      "l" U,   \
    long long:          "ll" D,  \
    unsigned long long: "ll" U,  \
    float:              "f",     \
    double:             "f",     \
    long double:        "Lf")

/* clang-format on */
#endif /* C11 */


/*!BEGIN libc/unistd.h */

#define COSMOPOLITAN_LIBC_UNISTD_H_
COSMOPOLITAN_C_START_

#define _CS_PATH 0

size_t confstr(int, char *, size_t) libcesque;

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_COSMO_SOURCE)
void encrypt(char *, int) libcesque;
char *crypt(const char *, const char *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/utime.h */

#define COSMOPOLITAN_LIBC_UTIME_H_
COSMOPOLITAN_C_START_

struct utimbuf {
  int64_t actime;  /* access time */
  int64_t modtime; /* modified time */
};

int utime(const char *, const struct utimbuf *) libcesque;

#ifdef _COSMO_SOURCE
int sys_utime(const char *, const struct utimbuf *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/typedef/u.h */

#define COSMOPOLITAN_LIBC_CALLS_TYPEDEF_U_H_
COSMOPOLITAN_C_START_

typedef unsigned char u_int8_t;
typedef unsigned short u_int16_t;
typedef unsigned u_int32_t;
typedef char *caddr_t;
typedef unsigned char u_char;
typedef unsigned short u_short, ushort;
typedef unsigned u_int, uint;
typedef unsigned long u_long, ulong;
typedef long long quad_t;
typedef unsigned long long u_quad_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/cpuset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_CPUSET_H_

#define CPU_SETSIZE 1024

COSMOPOLITAN_C_START_

typedef struct cpu_set_t {
  uint64_t __bits[16];
} cpu_set_t;

int sched_getcpu(void) libcesque;
int sched_getaffinity(int, size_t, cpu_set_t *) libcesque;
int sched_setaffinity(int, size_t, const cpu_set_t *) libcesque;

#define CPU_SET(i, s)   ((s)->__bits[(i) / 64] |= 1ull << ((i) % 64))
#define CPU_CLR(i, s)   ((s)->__bits[(i) / 64] &= ~(1ull << ((i) % 64)))
#define CPU_ISSET(i, s) (!!((s)->__bits[(i) / 64] & (1ull << ((i) % 64))))

void CPU_ZERO(cpu_set_t *) libcesque;
#define CPU_ZERO(x) CPU_ZERO(x)

int CPU_COUNT(cpu_set_t *) libcesque;
#define CPU_COUNT(x) CPU_COUNT(x)

int CPU_EQUAL(cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_EQUAL(x, y) CPU_EQUAL(x, y)

void CPU_AND(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_AND(x, y, z) CPU_AND(x, y, z)

void CPU_OR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_OR(x, y, z) CPU_OR(x, y, z)

void CPU_XOR(cpu_set_t *, cpu_set_t *, cpu_set_t *) libcesque;
#define CPU_XOR(x, y, z) CPU_XOR(x, y, z)

int CPU_COUNT_S(size_t, const cpu_set_t *) libcesque;
#define CPU_COUNT_S(x, y) CPU_COUNT_S(x, y)

#define CPU_ALLOC_SIZE(n) \
  ((((n) + (8 * sizeof(long) - 1)) & -(8 * sizeof(long))) / sizeof(long))

#define CPU_ALLOC(n)                  ((cpu_set_t *)calloc(1, CPU_ALLOC_SIZE(n)))
#define CPU_FREE(set)                 free(set)
#define CPU_ZERO_S(size, set)         memset(set, 0, size)
#define CPU_EQUAL_S(size, set1, set2) (!memcmp(set1, set2, size))
#define _CPU_S(i, size, set, op)                                              \
  ((i) / 8U >= (size) ? 0                                                     \
                      : (((unsigned long *)(set))[(i) / 8 / sizeof(long)] op( \
                            1UL << ((i) % (8 * sizeof(long))))))
#define CPU_SET_S(i, size, set)   _CPU_S(i, size, set, |=)
#define CPU_CLR_S(i, size, set)   _CPU_S(i, size, set, &= ~)
#define CPU_ISSET_S(i, size, set) _CPU_S(i, size, set, &)

typedef cpu_set_t cpuset_t; /* for freebsd compatibility */

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/dirent.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_DIRENT_H_
COSMOPOLITAN_C_START_

struct dirent {      /* linux getdents64 abi */
  uint64_t d_ino;    /* inode number */
  int64_t d_off;     /* implementation-dependent location number */
  uint16_t d_reclen; /* byte length of this whole struct and string */
  uint8_t d_type;    /* DT_REG, DT_DIR, DT_UNKNOWN, DT_BLK, etc. */
  char d_name[256];  /* NUL-terminated basename */
};

struct dirstream;
typedef struct dirstream DIR;

DIR *fdopendir(int) libcesque __wur;
DIR *opendir(const char *) libcesque __wur;
int closedir(DIR *) libcesque;
int dirfd(DIR *) libcesque;
long telldir(DIR *) libcesque;
struct dirent *readdir(DIR *) libcesque;
int readdir_r(DIR *, struct dirent *, struct dirent **) libcesque;
void rewinddir(DIR *) libcesque;
void seekdir(DIR *, long) libcesque;
int alphasort(const struct dirent **, const struct dirent **) libcesque;
int versionsort(const struct dirent **, const struct dirent **) libcesque;
int scandir(const char *, struct dirent ***, int (*)(const struct dirent *),
            int (*)(const struct dirent **, const struct dirent **)) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/flock.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FLOCK_H_
COSMOPOLITAN_C_START_

struct flock {      /* cosmopolitan abi */
  int16_t l_type;   /* F_RDLCK, F_WRLCK, F_UNLCK */
  int16_t l_whence; /* SEEK_SET, SEEK_CUR, SEEK_END */
  int64_t l_start;  /* starting offset */
  int64_t l_len;    /* no. bytes (0 means to end of file) */
  int32_t l_pid;    /* lock owner */
  int32_t l_sysid;  /* remote system id or zero for local (freebsd) */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/framebuffercolormap.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERCOLORMAP_H_

struct FrameBufferColorMap {
  uint32_t start;
  uint32_t len;
  uint16_t *red;
  uint16_t *green;
  uint16_t *blue;
  uint16_t *transp;
};



/*!BEGIN libc/calls/struct/framebufferfixedscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERFIXEDSCREENINFO_H_

struct FrameBufferFixedScreenInfo {
  char id[16];
  uint64_t smem_start;
  uint32_t smem_len;
  uint32_t type;
  uint32_t type_aux;
  uint32_t visual;
  uint16_t xpanstep;
  uint16_t ypanstep;
  uint16_t ywrapstep;
  uint32_t line_length;
  uint64_t mmio_start;
  uint32_t mmio_len;
  uint32_t accel;
  uint16_t capabilities;
  uint16_t reserved[2];
};



/*!BEGIN libc/calls/struct/framebuffervirtualscreeninfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FRAMEBUFFERVIRTUALSCREENINFO_H_

struct FrameBufferBitField {
  uint32_t offset;
  uint32_t length;
  uint32_t msb_right;
};

struct FrameBufferVirtualScreenInfo {
  uint32_t xres;
  uint32_t yres;
  uint32_t xres_virtual;
  uint32_t yres_virtual;
  uint32_t xoffset;
  uint32_t yoffset;
  uint32_t bits_per_pixel;
  uint32_t grayscale;
  struct FrameBufferBitField red;
  struct FrameBufferBitField green;
  struct FrameBufferBitField blue;
  struct FrameBufferBitField transp;
  uint32_t nonstd;
  uint32_t activate;
  uint32_t height;
  uint32_t width;
  uint32_t accel_flags;
  uint32_t pixclock;
  uint32_t left_margin;
  uint32_t right_margin;
  uint32_t upper_margin;
  uint32_t lower_margin;
  uint32_t hsync_len;
  uint32_t vsync_len;
  uint32_t sync;
  uint32_t vmode;
  uint32_t rotate;
  uint32_t colorspace;
  uint32_t reserved[4];
};



/*!BEGIN libc/calls/struct/fsid.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_FSID_H_
COSMOPOLITAN_C_START_

typedef struct fsid_t {
  uint32_t __val[2];
} fsid_t;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/iovec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct iovec {
  void *iov_base;
  size_t iov_len;
};

ssize_t preadv(int, struct iovec *, int, int64_t) libcesque;
ssize_t pwritev(int, const struct iovec *, int, int64_t) libcesque;
ssize_t readv(int, const struct iovec *, int) libcesque;
ssize_t vmsplice(int, const struct iovec *, int64_t, uint32_t) libcesque;
ssize_t writev(int, const struct iovec *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/itimerval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_ITIMERVAL_H_


/*!BEGIN libc/calls/struct/timeval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMEVAL_H_


/*!BEGIN libc/calls/struct/timespec.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TIMESPEC_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct timespec {
  int64_t tv_sec;
  int64_t tv_nsec; /* nanoseconds */
};

int clock_getres(int, struct timespec *) libcesque;
int clock_gettime(int, struct timespec *) libcesque;
int clock_settime(int, const struct timespec *) libcesque;
int clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int futimens(int, const struct timespec[2]) libcesque;
int nanosleep(const struct timespec *, struct timespec *) libcesque;
int utimensat(int, const char *, const struct timespec[2], int) libcesque;
int timespec_getres(struct timespec *, int) libcesque;
int timespec_get(struct timespec *, int) libcesque;

#ifdef _COSMO_SOURCE
int sys_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
int cosmo_clock_nanosleep(int, int, const struct timespec *, struct timespec *);
#define timespec_zero ((struct timespec){0})
#define timespec_max  ((struct timespec){0x7fffffffffffffff, 999999999})
libcesque int timespec_cmp(struct timespec, struct timespec) pureconst;
libcesque int64_t timespec_tomicros(struct timespec) pureconst;
libcesque int64_t timespec_tomillis(struct timespec) pureconst;
libcesque int64_t timespec_tonanos(struct timespec) pureconst;
libcesque struct timespec timespec_add(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_fromnanos(int64_t) pureconst;
libcesque struct timespec timespec_frommicros(int64_t) pureconst;
libcesque struct timespec timespec_frommillis(int64_t) pureconst;
libcesque struct timespec timespec_real(void) libcesque;
libcesque struct timespec timespec_mono(void) libcesque;
libcesque struct timespec timespec_sleep(struct timespec) libcesque;
libcesque int timespec_sleep_until(struct timespec) libcesque;
libcesque struct timespec timespec_sub(struct timespec,
                                       struct timespec) pureconst;
libcesque struct timespec timespec_subz(struct timespec,
                                        struct timespec) pureconst;
int sys_futex(int *, int, int, const struct timespec *, int *);
static inline struct timespec timespec_fromseconds(int64_t __x) {
  return (struct timespec){__x};
}
static inline int timespec_iszero(struct timespec __ts) {
  return !(__ts.tv_sec | __ts.tv_nsec);
}
static inline int timespec_isvalid(struct timespec __ts) {
  return __ts.tv_sec >= 0 && __ts.tv_nsec + 0ull < 1000000000ull;
}
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

struct timeval {
  int64_t tv_sec;
  int64_t tv_usec; /* microseconds */
};

int futimes(int, const struct timeval[2]);
int futimesat(int, const char *, const struct timeval[2]);
int gettimeofday(struct timeval *, struct timezone *);
int settimeofday(const struct timeval *, const struct timezone *);
int lutimes(const char *, const struct timeval[2]);
int utimes(const char *, const struct timeval[2]);

#ifdef _COSMO_SOURCE
/* cosmopolitan libc's non-posix timevals library
   removed by default due to emacs codebase clash */
#define timeval_zero ((struct timeval){0})
#define timeval_max  ((struct timeval){0x7fffffffffffffff, 999999})
int timeval_cmp(struct timeval, struct timeval) pureconst;
struct timeval timeval_real(void);
struct timeval timeval_frommicros(int64_t) pureconst;
struct timeval timeval_frommillis(int64_t) pureconst;
struct timeval timeval_add(struct timeval, struct timeval) pureconst;
struct timeval timeval_sub(struct timeval, struct timeval) pureconst;
struct timeval timeval_subz(struct timeval, struct timeval) pureconst;
int64_t timeval_toseconds(struct timeval);
int64_t timeval_tomicros(struct timeval);
int64_t timeval_tomillis(struct timeval);
struct timeval timespec_totimeval(struct timespec) pureconst;
static inline struct timeval timeval_fromseconds(int64_t __x) {
  return (struct timeval){__x};
}
static inline struct timespec timeval_totimespec(struct timeval __tv) {
  return (struct timespec){__tv.tv_sec, __tv.tv_usec * 1000};
}
static inline int timeval_iszero(struct timeval __tv) {
  return !(__tv.tv_sec | __tv.tv_usec);
}
static inline int timeval_isvalid(struct timeval __tv) {
  return __tv.tv_sec >= 0 && __tv.tv_usec + 0ull < 1000000ull;
}
#endif /* _COSMO_SOURCE */

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
#define timercmp(s, t, op)                                  \
  ((s)->tv_sec == (t)->tv_sec ? (s)->tv_usec op(t)->tv_usec \
                              : (s)->tv_sec op(t)->tv_sec)
#define timeradd(s, t, a)                                           \
  (void)((a)->tv_sec = (s)->tv_sec + (t)->tv_sec,                   \
         ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
             ((a)->tv_usec -= 1000000, (a)->tv_sec++))
#define timersub(s, t, a)                                    \
  (void)((a)->tv_sec = (s)->tv_sec - (t)->tv_sec,            \
         ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
             ((a)->tv_usec += 1000000, (a)->tv_sec--))
#endif

#ifdef _GNU_SOURCE
#define TIMEVAL_TO_TIMESPEC(tv, ts) \
  ((ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0)
#define TIMESPEC_TO_TIMEVAL(tv, ts) \
  ((tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0)
#endif

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct itimerval {
  struct timeval it_interval; /* {0,0} means singleshot */
  struct timeval it_value;    /* {0,0} means disarm */
};

int getitimer(int, struct itimerval *);
int setitimer(int, const struct itimerval *, struct itimerval *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/metasigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_METASIGALTSTACK_H_


/*!BEGIN libc/calls/struct/sigaltstack.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGALTSTACK_H_
COSMOPOLITAN_C_START_

struct sigaltstack {
  void *ss_sp;
  int ss_flags;
  size_t ss_size;
};

typedef struct sigaltstack stack_t;

int sigaltstack(const struct sigaltstack *, struct sigaltstack *) libcesque;

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct sigaltstack_bsd {
  void *ss_sp;
  uint64_t ss_size;
  int32_t ss_flags;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rlimit.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RLIMIT_H_
COSMOPOLITAN_C_START_

struct rlimit {
  uint64_t rlim_cur; /* current (soft) limit in bytes */
  uint64_t rlim_max; /* maximum limit in bytes */
};

int getrlimit(int, struct rlimit *) libcesque;
int setrlimit(int, const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/rusage.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_RUSAGE_H_
COSMOPOLITAN_C_START_

struct rusage {
  struct timeval ru_utime; /* user CPU time used */
  struct timeval ru_stime; /* system CPU time used */
  int64_t ru_maxrss;       /* maximum resident set size in (kb) */
  int64_t ru_ixrss;        /* shared memory size (integral kb CLK_TCK) */
  int64_t ru_idrss;        /* unshared data size (integral kb CLK_TCK) */
  int64_t ru_isrss;        /* unshared stack size (integral kb CLK_TCK) */
  int64_t ru_minflt;       /* page reclaims */
  int64_t ru_majflt;       /* page faults */
  int64_t ru_nswap;        /* swaps */
  int64_t ru_inblock;      /* block input operations */
  int64_t ru_oublock;      /* block output operations */
  int64_t ru_msgsnd;       /* IPC messages sent */
  int64_t ru_msgrcv;       /* IPC messages received */
  int64_t ru_nsignals;     /* signals received */
  int64_t ru_nvcsw;        /* voluntary context switches */
  int64_t ru_nivcsw;       /* involuntary context switches */
};

int getrusage(int, struct rusage *) libcesque;
int wait3(int *, int, struct rusage *) libcesque;
int wait4(int, int *, int, struct rusage *) libcesque;
void rusage_add(struct rusage *, const struct rusage *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sched_param.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SCHED_PARAM_H_
COSMOPOLITAN_C_START_

struct sched_param {
  int32_t sched_priority;
};

int sched_get_priority_max(int) libcesque;
int sched_get_priority_min(int) libcesque;
int sched_getparam(int, struct sched_param *) libcesque;
int sched_getscheduler(int) libcesque;
int sched_rr_get_interval(int, struct timespec *) libcesque;
int sched_setparam(int, const struct sched_param *) libcesque;
int sched_setscheduler(int, int, const struct sched_param *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigaction.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGACTION_H_


/*!BEGIN libc/calls/struct/siginfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGINFO_H_


/*!BEGIN libc/calls/struct/sigval.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGVAL_H_
COSMOPOLITAN_C_START_

union sigval {
  int32_t sival_int;
  void *sival_ptr;
};

int sigqueue(int, int, const union sigval);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct siginfo {
  int32_t si_signo;
  int32_t si_errno;
  int32_t si_code; /* {SICODE,SEGV,ILL,FPE,POLL}_xxx */
  union {
    struct {
      union {
        struct {
          /* signals sent by kill() and sigqueue() set these */
          int32_t si_pid;
          uint32_t si_uid;
        };
        struct {
          /* SIGALRM sets these */
          int32_t si_timerid;
          int32_t si_overrun;
        };
      };
      union {
        union sigval si_value; /* provided by third arg of sigqueue(2) */
        struct {
          int32_t si_status;
          int64_t si_utime;
          int64_t si_stime;
        };
      };
    };
    struct {
      void *si_addr;
      int16_t si_addr_lsb;
      union {
        struct {
          void *si_lower;
          void *si_upper;
        };
        uint32_t si_pkey;
      };
    };
    struct {
      int64_t si_band; /* SIGPOLL */
      int32_t si_fd;
    };
    struct {
      void *si_call_addr;
      int32_t si_syscall;
      uint32_t si_arch;
    };
    char __ignoreme[128 - 2 * sizeof(int32_t) - sizeof(int64_t)];
  };
};

typedef struct siginfo siginfo_t;

#ifdef _COSMO_SOURCE
void __minicrash(int, siginfo_t *, void *) libcesque;
char __is_stack_overflow(siginfo_t *, void *) libcesque;
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sigset.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SIGSET_H_
COSMOPOLITAN_C_START_

typedef uint64_t sigset_t;

int sigaddset(sigset_t *, int) paramsnonnull();
int sigdelset(sigset_t *, int) paramsnonnull();
int sigemptyset(sigset_t *) paramsnonnull();
int sigfillset(sigset_t *) paramsnonnull();
int sigandset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigorset(sigset_t *, const sigset_t *, const sigset_t *) paramsnonnull();
int sigisemptyset(const sigset_t *) paramsnonnull() nosideeffect;
int sigismember(const sigset_t *, int) paramsnonnull() nosideeffect;
int sigcountset(const sigset_t *) paramsnonnull() nosideeffect;
int sigprocmask(int, const sigset_t *, sigset_t *);
int sigsuspend(const sigset_t *);
int sigpending(sigset_t *);
int pthread_sigmask(int, const sigset_t *, sigset_t *);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef void (*sighandler_t)(int);
typedef void (*sigaction_f)(int, struct siginfo *, void *);

struct sigaction {
  union {
    sighandler_t sa_handler;
    sigaction_f sa_sigaction;
  };
  uint64_t sa_flags;
  void (*sa_restorer)(void);
  sigset_t sa_mask;
};

sighandler_t signal(int, sighandler_t) libcesque;
int sigaction(int, const struct sigaction *, struct sigaction *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_H_
COSMOPOLITAN_C_START_

struct stat {              /* cosmo abi */
  uint64_t st_dev;         /* 0: id of device with file */
  uint64_t st_ino;         /* 8: inode number in disk b-tree */
  uint64_t st_nlink;       /* 16: hard link count */
  uint32_t st_mode;        /* 24: octal file mask thing */
  uint32_t st_uid;         /* 28: user id of owner */
  uint32_t st_gid;         /* group id of owning group */
  uint32_t st_flags;       /* nt/xnu/bsd-only */
  uint64_t st_rdev;        /* id of device if a special file */
  int64_t st_size;         /* bytes in file */
  int64_t st_blksize;      /* preferred chunking for underlying filesystem */
  int64_t st_blocks;       /* number of 512-byte pages allocated to file */
  struct timespec st_atim; /* access time */
  struct timespec st_mtim; /* modified time */
  struct timespec st_ctim; /* complicated time */
  struct timespec st_birthtim;
  uint64_t st_gen; /* xnu/bsd only */
};

int stat(const char *, struct stat *);
int lstat(const char *, struct stat *);
int fstat(int, struct stat *);
int fstatat(int, const char *, struct stat *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/stat.macros.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STAT_MACROS_H_

#define STAT_HAVE_NSEC 1

#define st_atime st_atim.tv_sec
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec

#define st_atime_nsec st_atim.tv_nsec
#define st_mtime_nsec st_mtim.tv_nsec
#define st_ctime_nsec st_ctim.tv_nsec

#define st_atimensec st_atim.tv_nsec
#define st_mtimensec st_mtim.tv_nsec
#define st_ctimensec st_ctim.tv_nsec
#define st_birthtime st_birthtim.tv_sec

#define st_file_attributes st_flags

#define INIT_STRUCT_STAT_PADDING(st) (void)st



/*!BEGIN libc/calls/struct/statfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATFS_H_
COSMOPOLITAN_C_START_

struct statfs {       /* cosmo abi */
  int64_t f_type;     /* type of filesystem */
  int64_t f_bsize;    /* optimal transfer block size */
  int64_t f_blocks;   /* total data blocks in filesystem */
  int64_t f_bfree;    /* free blocks in filesystem */
  int64_t f_bavail;   /* free blocks available to unprivileged users */
  int64_t f_files;    /* total file nodes in filesystem */
  int64_t f_ffree;    /* free file nodes in filesystem */
  fsid_t f_fsid;      /* filesystem id */
  int64_t f_namelen;  /* maximum length of filenames */
  int64_t f_frsize;   /* fragment size */
  int64_t f_flags;    /* mount flags of filesystem 2.6.36 */
  int64_t f_spare[4]; /* end of linux abi */
  uint32_t f_owner;
  char f_fstypename[16];
};

int statfs(const char *, struct statfs *) libcesque;
int fstatfs(int, struct statfs *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/statvfs.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_STATVFS_H_
COSMOPOLITAN_C_START_

struct statvfs {
  unsigned long f_bsize;   /* Filesystem block size */
  unsigned long f_frsize;  /* Fragment size */
  uint64_t f_blocks;       /* Size of fs in f_frsize units */
  uint64_t f_bfree;        /* Number of free blocks */
  uint64_t f_bavail;       /* Number of free blocks for unprivileged users */
  uint64_t f_files;        /* Number of inodes */
  uint64_t f_ffree;        /* Number of free inodes */
  uint64_t f_favail;       /* Number of free inodes for unprivileged users */
  unsigned long f_fsid;    /* Filesystem ID */
  unsigned long f_flag;    /* Mount flags */
  unsigned long f_namemax; /* Maximum filename length */
};

int statvfs(const char *, struct statvfs *);
int fstatvfs(int, struct statvfs *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/sysinfo.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SYSINFO_H_
COSMOPOLITAN_C_START_

struct sysinfo {
  int64_t uptime;     /* seconds since boot */
  uint64_t loads[3];  /* 1-5-15 min active process averages */
  uint64_t totalram;  /* system physical memory */
  uint64_t freeram;   /* amount of ram currently going to waste */
  uint64_t sharedram; /* bytes w/ pages mapped into multiple progs */
  uint64_t bufferram; /* lingering disk pages; see fadvise */
  uint64_t totalswap; /* size of emergency memory */
  uint64_t freeswap;  /* hopefully equal to totalswap */
  uint16_t procs;     /* number of processes */
  int16_t __ignore1;  /* padding */
  int32_t __ignore2;  /* padding */
  uint64_t totalhigh; /* wut */
  uint64_t freehigh;  /* wut */
  uint32_t mem_unit;  /* ram stuff above is multiples of this */
};

int sysinfo(struct sysinfo *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TERMIOS_H_

#define NCCS 20

COSMOPOLITAN_C_START_

struct termios {      /* cosmo abi */
  uint32_t c_iflag;   /* input modes */
  uint32_t c_oflag;   /* output modes */
  uint32_t c_cflag;   /* control modes */
  uint32_t c_lflag;   /* local modes */
  uint8_t c_cc[NCCS]; /* code mappings */
  uint32_t _c_ispeed; /* use cfgetispeed() and cfsetispeed() */
  uint32_t _c_ospeed; /* use cfgetospeed() and cfsetospeed() */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/tms.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_TMS_H_
COSMOPOLITAN_C_START_

struct tms {
  int64_t tms_utime;  /* userspace time */
  int64_t tms_stime;  /* kernelspace time */
  int64_t tms_cutime; /* children userspace time */
  int64_t tms_cstime; /* children kernelspace time */
};

long times(struct tms *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/user_regs_struct.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_USER_REGS_STRUCT_H_
COSMOPOLITAN_C_START_

/**
 * Linux Kernel user registers.
 *
 * @note superset of struct pt_regs
 * @see ptrace() w/ PTRACE_SYSCALL
 */
struct user_regs_struct {
  uint64_t r15;
  uint64_t r14;
  uint64_t r13;
  uint64_t r12;
  uint64_t rbp;
  uint64_t rbx;
  uint64_t r11;
  uint64_t r10;
  uint64_t r9;
  uint64_t r8;
  uint64_t rax;
  uint64_t rcx;
  uint64_t rdx;
  uint64_t rsi;
  uint64_t rdi;
  uint64_t orig_rax;
  uint64_t rip;
  uint64_t cs;
  uint64_t eflags;
  uint64_t rsp;
  uint64_t ss;
  uint64_t fs_base;
  uint64_t gs_base;
  uint64_t ds;
  uint64_t es;
  uint64_t fs;
  uint64_t gs;
};

struct useregs_struct_freebsd {
  int64_t r15;
  int64_t r14;
  int64_t r13;
  int64_t r12;
  int64_t r11;
  int64_t r10;
  int64_t r9;
  int64_t r8;
  int64_t rdi;
  int64_t rsi;
  int64_t rbp;
  int64_t rbx;
  int64_t rdx;
  int64_t rcx;
  int64_t rax;
  uint32_t trapno;
  uint16_t fs;
  uint16_t gs;
  uint32_t err;
  uint16_t es;
  uint16_t ds;
  int64_t rip;
  int64_t cs;
  int64_t rflags;
  int64_t rsp;
  int64_t ss;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/utsname.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_UTSNAME_H_

#define SYS_NMLN 150

COSMOPOLITAN_C_START_

struct utsname {             /* cosmo abi */
  char sysname[SYS_NMLN];    /* name of os */
  char nodename[SYS_NMLN];   /* name of network node */
  char release[SYS_NMLN];    /* release level */
  char version[SYS_NMLN];    /* version level */
  char machine[SYS_NMLN];    /* hardware type */
  char domainname[SYS_NMLN]; /* domain name */
};

int uname(struct utsname *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/struct/winsize.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_WINSIZE_H_
COSMOPOLITAN_C_START_

struct winsize {
  uint16_t ws_row;
  uint16_t ws_col;
  uint16_t ws_xpixel;
  uint16_t ws_ypixel;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/cachestat.h */

#define COSMOPOLITAN_LIBC_CALLS_CACHESTAT_H_

COSMOPOLITAN_C_START_

struct cachestat_range {
  uint64_t off;
  uint64_t len;
};

struct cachestat {
  /** Number of cached pages. */
  uint64_t nr_cache;
  /** Number of dirty pages */
  uint64_t nr_dirty;
  /** Number of pages marked for writeback. */
  uint64_t nr_writeback;
  /** Number of pages evicted from the cache. */
  uint64_t nr_evicted;
  /**
   * Number of recently evicted pages.
   * A page is recently evicted if its last eviction was recent enough that its
   * reentry to the cache would indicate that it is actively being used by the
   * system, and that there is memory pressure on the system.
   */
  uint64_t nr_recently_evicted;
};

int cachestat(int, struct cachestat_range *, struct cachestat *, uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/calls.h */

#define COSMOPOLITAN_LIBC_CALLS_SYSCALLS_H_

#define _POSIX_VERSION  200809L
#define _POSIX2_VERSION _POSIX_VERSION
#define _XOPEN_VERSION  700

#define _POSIX_MAPPED_FILES               _POSIX_VERSION
#define _POSIX_FSYNC                      _POSIX_VERSION
#define _POSIX_IPV6                       _POSIX_VERSION
#define _POSIX_THREADS                    _POSIX_VERSION
#define _POSIX_THREAD_PROCESS_SHARED      _POSIX_VERSION
#define _POSIX_THREAD_SAFE_FUNCTIONS      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKADDR      _POSIX_VERSION
#define _POSIX_THREAD_ATTR_STACKSIZE      _POSIX_VERSION
#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
#define _POSIX_THREAD_CPUTIME             _POSIX_VERSION
#define _POSIX_TIMEOUTS                   _POSIX_VERSION
#define _POSIX_MONOTONIC_CLOCK            _POSIX_VERSION
#define _POSIX_CPUTIME                    _POSIX_VERSION
#define _POSIX_BARRIERS                   _POSIX_VERSION
#define _POSIX_SPIN_LOCKS                 _POSIX_VERSION
#define _POSIX_READER_WRITER_LOCKS        _POSIX_VERSION
#define _POSIX_SEMAPHORES                 _POSIX_VERSION
#define _POSIX_SHARED_MEMORY_OBJECTS      _POSIX_VERSION
#define _POSIX_MEMLOCK_RANGE              _POSIX_VERSION
#define _POSIX_SPAWN                      _POSIX_VERSION

#define NSIG 64

#define SEEK_SET 0          /* relative to beginning */
#define SEEK_CUR 1          /* relative to current position */
#define SEEK_END 2          /* relative to end */
#define __WALL   0x40000000 /* Wait on all children, regardless of type */
#define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */

#define SIG_ERR ((void (*)(int))(-1))
#define SIG_DFL ((void (*)(int))0)
#define SIG_IGN ((void (*)(int))1)

#define CLOCKS_PER_SEC 1000000L

#define MAP_FAILED ((void *)-1)

#define WTERMSIG(x)     (127 & (x))
#define WCOREDUMP(x)    (128 & (x))
#define WIFEXITED(x)    (!WTERMSIG(x))
#define WEXITSTATUS(x)  ((x) >> 8)
#define WSTOPSIG(x)     ((0xff00 & (x)) >> 8)
#define WIFSTOPPED(x)   __wifstopped(x)
#define WIFSIGNALED(x)  __wifsignaled(x)
#define WIFCONTINUED(x) __wifcontinued(x)
#define W_STOPCODE(x)   ((x) << 8 | 0177)

#ifdef _COSMO_SOURCE
#define clone         __clone
#define commandv      __commandv
#define fileexists    __fileexists
#define ischardev     __ischardev
#define isdirectory   __isdirectory
#define isexecutable  __isexecutable
#define isregularfile __isregularfile
#define issymlink     __issymlink
#define makedirs      __makedirs
#define tmpfd         __tmpfd
#endif

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § system calls                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

typedef int sig_atomic_t;

bool32 isatty(int) libcesque;
char *getcwd(char *, size_t) dontthrow;
char *realpath(const char *, char *) libcesque __wur;
char *ttyname(int) libcesque;
int access(const char *, int) libcesque;
int chdir(const char *) libcesque;
int chmod(const char *, unsigned) libcesque;
int chown(const char *, unsigned, unsigned) libcesque;
int chroot(const char *) libcesque;
int close(int) libcesque;
int close_range(unsigned, unsigned, unsigned) libcesque;
int closefrom(int) libcesque;
int creat(const char *, unsigned) libcesque;
int dup(int) libcesque;
int dup2(int, int) libcesque;
int dup3(int, int, int) libcesque;
int execl(const char *, const char *, ...) nullterminated() libcesque;
int execle(const char *, const char *, ...) nullterminated((1)) libcesque;
int execlp(const char *, const char *, ...) nullterminated() libcesque;
int execv(const char *, char *const[]) libcesque;
int execve(const char *, char *const[], char *const[]) libcesque;
int execvp(const char *, char *const[]) libcesque;
int faccessat(int, const char *, int, int) libcesque;
int fchdir(int) libcesque;
int fchmod(int, unsigned) libcesque;
int fchmodat(int, const char *, unsigned, int) libcesque;
int fchown(int, unsigned, unsigned) libcesque;
int fchownat(int, const char *, unsigned, unsigned, int) libcesque;
int fcntl(int, int, ...) libcesque;
int fdatasync(int) libcesque;
int fexecve(int, char *const[], char *const[]) libcesque;
int flock(int, int) libcesque;
int fork(void) libcesque;
int fsync(int) libcesque;
int ftruncate(int, int64_t) libcesque;
int getdomainname(char *, size_t) libcesque;
int getgroups(int, unsigned[]) libcesque;
int gethostname(char *, size_t) libcesque;
int getloadavg(double *, int) libcesque;
int getpgid(int) libcesque;
int getpgrp(void) libcesque nosideeffect;
int getpid(void) libcesque nosideeffect;
int getppid(void) libcesque;
int getpriority(int, unsigned) libcesque;
int getsid(int) nosideeffect libcesque;
int ioctl(int, unsigned long, ...) libcesque;
int issetugid(void) libcesque;
int kill(int, int) libcesque;
int killpg(int, int) libcesque;
int lchmod(const char *, unsigned) libcesque;
int lchown(const char *, unsigned, unsigned) libcesque;
int link(const char *, const char *) libcesque;
int linkat(int, const char *, int, const char *, int) libcesque;
int mincore(void *, size_t, unsigned char *) libcesque;
int mkdir(const char *, unsigned) libcesque;
int mkdirat(int, const char *, unsigned) libcesque;
int mknod(const char *, unsigned, uint64_t) libcesque;
int nice(int) libcesque;
int open(const char *, int, ...) libcesque;
int openat(int, const char *, int, ...) libcesque;
int pause(void) libcesque;
int pipe(int[hasatleast 2]) libcesque;
int pipe2(int[hasatleast 2], int) libcesque;
int posix_fadvise(int, int64_t, int64_t, int) libcesque;
int posix_madvise(void *, uint64_t, int) libcesque;
int raise(int) libcesque;
int reboot(int) libcesque;
int remove(const char *) libcesque;
int rename(const char *, const char *) libcesque;
int renameat(int, const char *, int, const char *) libcesque;
int rmdir(const char *) libcesque;
int sched_yield(void) libcesque;
int setegid(unsigned) libcesque;
int seteuid(unsigned) libcesque;
int setfsgid(unsigned) libcesque;
int setfsuid(unsigned) libcesque;
int setgid(unsigned) libcesque;
int setgroups(size_t, const unsigned[]) libcesque;
int setpgid(int, int) libcesque;
int setpgrp(void) libcesque;
int setpriority(int, unsigned, int) libcesque;
int setregid(unsigned, unsigned) libcesque;
int setreuid(unsigned, unsigned) libcesque;
int setsid(void) libcesque;
int setuid(unsigned) libcesque;
int shm_open(const char *, int, unsigned) libcesque;
int shm_unlink(const char *) libcesque;
int sigignore(int) libcesque;
int siginterrupt(int, int) libcesque;
int symlink(const char *, const char *) libcesque;
int symlinkat(const char *, int, const char *) libcesque;
int tcgetpgrp(int) libcesque;
int tcsetpgrp(int, int) libcesque;
int truncate(const char *, int64_t) libcesque;
int ttyname_r(int, char *, size_t) libcesque;
int unlink(const char *) libcesque;
int unlinkat(int, const char *, int) libcesque;
int usleep(uint64_t) libcesque;
int vfork(void) libcesque returnstwice;
int wait(int *) libcesque;
int waitpid(int, int *, int) libcesque;
int64_t clock(void) libcesque;
int64_t time(int64_t *) libcesque;
ssize_t copy_file_range(int, long *, int, long *, size_t, unsigned) libcesque;
ssize_t lseek(int, int64_t, int) libcesque;
ssize_t pread(int, void *, size_t, int64_t) libcesque;
ssize_t pwrite(int, const void *, size_t, int64_t) libcesque;
ssize_t read(int, void *, size_t) libcesque;
ssize_t readlink(const char *, char *, size_t) libcesque;
ssize_t readlinkat(int, const char *, char *, size_t) libcesque;
ssize_t write(int, const void *, size_t) libcesque;
unsigned alarm(unsigned) libcesque;
unsigned getegid(void) libcesque nosideeffect;
unsigned geteuid(void) libcesque nosideeffect;
unsigned getgid(void) libcesque nosideeffect;
unsigned getuid(void) libcesque;
unsigned sleep(unsigned) libcesque;
unsigned ualarm(unsigned, unsigned) libcesque;
unsigned umask(unsigned) libcesque;
void sync(void) libcesque;

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE)
int syncfs(int) libcesque;
int prctl(int, ...) libcesque;
int gettid(void) libcesque;
int setresgid(unsigned, unsigned, unsigned) libcesque;
int setresuid(unsigned, unsigned, unsigned) libcesque;
int getresgid(unsigned *, unsigned *, unsigned *) libcesque;
int getresuid(unsigned *, unsigned *, unsigned *) libcesque;
char *get_current_dir_name(void) libcesque __wur;
ssize_t splice(int, int64_t *, int, int64_t *, size_t, unsigned) libcesque;
int memfd_create(const char *, unsigned int) libcesque;
int execvpe(const char *, char *const[], char *const[]) libcesque;
int euidaccess(const char *, int) libcesque;
int eaccess(const char *, int) libcesque;
int madvise(void *, uint64_t, int) libcesque;
int getcpu(unsigned *, unsigned *) libcesque;
#endif

#ifdef _COSMO_SOURCE
bool32 fdexists(int) libcesque;
bool32 fileexists(const char *) libcesque;
bool32 ischardev(int) libcesque;
bool32 isdirectory(const char *) libcesque;
bool32 isexecutable(const char *) libcesque;
bool32 isregularfile(const char *) libcesque;
bool32 issymlink(const char *) libcesque;
char *commandv(const char *, char *, size_t) libcesque;
int __getcwd(char *, size_t) libcesque;
int clone(void *, void *, size_t, int, void *, void *, void *, void *);
int fadvise(int, uint64_t, uint64_t, int) libcesque;
int makedirs(const char *, unsigned) libcesque;
int pivot_root(const char *, const char *) libcesque;
int pledge(const char *, const char *) libcesque;
int seccomp(unsigned, unsigned, void *) libcesque;
int sys_iopl(int) libcesque;
int sys_ioprio_get(int, int) libcesque;
int sys_ioprio_set(int, int, int) libcesque;
int sys_mlock(const void *, size_t) libcesque;
int sys_mlock2(const void *, size_t, int) libcesque;
int sys_mlockall(int) libcesque;
int sys_munlock(const void *, size_t) libcesque;
int sys_munlockall(void) libcesque;
int sys_personality(uint64_t) libcesque;
int sys_ptrace(int, ...) libcesque;
int sysctl(int *, unsigned, void *, size_t *, void *, size_t) libcesque;
int sysctlbyname(const char *, void *, size_t *, void *, size_t) libcesque;
int sysctlnametomib(const char *, int *, size_t *) libcesque;
int tmpfd(void) libcesque;
int touch(const char *, unsigned) libcesque;
int unveil(const char *, const char *) libcesque;
long ptrace(int, ...) libcesque;
ssize_t copyfd(int, int, size_t) libcesque;
ssize_t readansi(int, char *, size_t) libcesque;
ssize_t tinyprint(int, const char *, ...) libcesque nullterminated();
void shm_path_np(const char *, char[hasatleast 78]) libcesque;
#endif /* _COSMO_SOURCE */

int system(const char *) libcesque;

int __wifstopped(int) libcesque pureconst;
int __wifcontinued(int) libcesque pureconst;
int __wifsignaled(int) libcesque pureconst;

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define lseek64     lseek
#define pread64     pread
#define pwrite64    pwrite
#define truncate64  truncate
#define ftruncate64 ftruncate
#define lockf64     lockf
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ipc.h */

#define COSMOPOLITAN_LIBC_CALLS_IPC_H_

#define IPC_PRIVATE 0
#define IPC_RMID    0
#define IPC_SET     1
#define IPC_STAT    2
#define IPC_INFO    3
#define IPC_CREAT   01000
#define IPC_EXCL    02000
#define IPC_NOWAIT  04000

COSMOPOLITAN_C_START_

int ftok(const char *, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/landlock.h */

#define COSMOPOLITAN_LIBC_CALLS_LANDLOCK_H_

#define LANDLOCK_CREATE_RULESET_VERSION 0x0001ul

#define LANDLOCK_ACCESS_FS_EXECUTE     0x0001ul
#define LANDLOCK_ACCESS_FS_WRITE_FILE  0x0002ul
#define LANDLOCK_ACCESS_FS_READ_FILE   0x0004ul
#define LANDLOCK_ACCESS_FS_READ_DIR    0x0008ul
#define LANDLOCK_ACCESS_FS_REMOVE_DIR  0x0010ul
#define LANDLOCK_ACCESS_FS_REMOVE_FILE 0x0020ul
#define LANDLOCK_ACCESS_FS_MAKE_CHAR   0x0040ul
#define LANDLOCK_ACCESS_FS_MAKE_DIR    0x0080ul
#define LANDLOCK_ACCESS_FS_MAKE_REG    0x0100ul
#define LANDLOCK_ACCESS_FS_MAKE_SOCK   0x0200ul
#define LANDLOCK_ACCESS_FS_MAKE_FIFO   0x0400ul
#define LANDLOCK_ACCESS_FS_MAKE_BLOCK  0x0800ul
#define LANDLOCK_ACCESS_FS_MAKE_SYM    0x1000ul

/**
 * Allow renaming or linking file to a different directory.
 *
 * @see https://lore.kernel.org/r/20220329125117.1393824-8-mic@digikod.net
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 2+
 */
#define LANDLOCK_ACCESS_FS_REFER 0x2000ul

/**
 * Control file truncation.
 *
 * @see
 * https://lore.kernel.org/all/20221018182216.301684-1-gnoack3000@gmail.com/
 * @see https://docs.kernel.org/userspace-api/landlock.html
 * @note ABI 3+
 */
#define LANDLOCK_ACCESS_FS_TRUNCATE 0x4000ul

COSMOPOLITAN_C_START_

enum landlock_rule_type {
  LANDLOCK_RULE_PATH_BENEATH = 1,
};

struct landlock_ruleset_attr {
  uint64_t handled_access_fs;
};

struct thatispacked landlock_path_beneath_attr {
  uint64_t allowed_access;
  int32_t parent_fd;
};

int landlock_restrict_self(int, uint32_t);
int landlock_add_rule(int, enum landlock_rule_type, const void *, uint32_t);
int landlock_create_ruleset(const struct landlock_ruleset_attr *, size_t,
                            uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/makedev.h */

#define COSMOPOLITAN_LIBC_CALLS_MAKEDEV_H_

uint64_t makedev(uint32_t, uint32_t) libcesque;
uint32_t major(uint64_t) libcesque;
uint32_t minor(uint64_t) libcesque;

#define major(x)      major(x)
#define minor(x)      minor(x)
#define makedev(x, y) makedev(x, y)



/*!BEGIN libc/calls/mount.h */

#define COSMOPOLITAN_LIBC_CALLS_MOUNT_H_
COSMOPOLITAN_C_START_

int mount(const char *, const char *, const char *, unsigned long,
          const void *);
int unmount(const char *, int);

#ifdef _GNU_SOURCE
int umount(const char *);
int umount2(const char *, int);
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/pledge.h */

#define COSMOPOLITAN_LIBC_CALLS_PLEDGE_H_

#define PLEDGE_PENALTY_KILL_THREAD  0x0000
#define PLEDGE_PENALTY_KILL_PROCESS 0x0001
#define PLEDGE_PENALTY_RETURN_EPERM 0x0002
#define PLEDGE_PENALTY_MASK         0x000f
#define PLEDGE_STDERR_LOGGING       0x0010

COSMOPOLITAN_C_START_

extern int __pledge_mode;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/sigtimedwait.h */

#define COSMOPOLITAN_LIBC_CALLS_SIGTIMEDWAIT_H_
COSMOPOLITAN_C_START_

int sigwait(const sigset_t *, int *);
int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *);
int sigwaitinfo(const sigset_t *, siginfo_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/termios.h */

#define COSMOPOLITAN_LIBC_CALLS_TERMIOS_H_
COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § teletypewriter control                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int tcgetattr(int, struct termios *) libcesque;
int tcsetattr(int, int, const struct termios *) libcesque;

int openpty(int *, int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2));
int forkpty(int *, char *, const struct termios *,
            const struct winsize *) libcesque paramsnonnull((1, 2)) __wur;
char *ptsname(int) libcesque;
errno_t ptsname_r(int, char *, size_t) libcesque;

int grantpt(int) libcesque;
int unlockpt(int) libcesque;
int posix_openpt(int) libcesque __wur;

int tcdrain(int) libcesque;
int tcgetsid(int) libcesque;
int tcflow(int, int) libcesque;
int tcflush(int, int) libcesque;
int tcsetsid(int, int) libcesque;
int tcsendbreak(int, int) libcesque;
void cfmakeraw(struct termios *) libcesque;
int cfsetspeed(struct termios *, uint32_t) libcesque;
int cfsetospeed(struct termios *, uint32_t) libcesque;
int cfsetispeed(struct termios *, uint32_t) libcesque;
uint32_t cfgetospeed(const struct termios *) libcesque;
uint32_t cfgetispeed(const struct termios *) libcesque;
int tcsetwinsize(int, const struct winsize *) libcesque;
int tcgetwinsize(int, struct winsize *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/ttydefaults.h */

#define COSMOPOLITAN_LIBC_CALLS_TTYDEFAULTS_H_


/*!BEGIN libc/sysv/consts/termios.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TERMIOS_H_
COSMOPOLITAN_C_START_

#define EXTA B19200
#define EXTB B38400

extern const int _POSIX_VDISABLE;
extern const uint32_t BRKINT;
extern const uint32_t BS1;
extern const uint32_t BS2;
extern const uint32_t BSDLY;
extern const uint32_t CLOCAL;
extern const uint32_t CMSPAR;
extern const uint32_t CR1;
extern const uint32_t CR2;
extern const uint32_t CR3;
extern const uint32_t CRDLY;
extern const uint32_t CREAD;
extern const uint32_t CS5;
extern const uint32_t CS6;
extern const uint32_t CS7;
extern const uint32_t CS8;
extern const uint32_t CSIZE;
extern const uint32_t CSTOPB;
extern const uint32_t ECHOCTL;
extern const uint32_t ECHOE;
extern const uint32_t ECHOK;
extern const uint32_t ECHOKE;
extern const uint32_t ECHONL;
extern const uint32_t ECHOPRT;
extern const long EXTPROC;
extern const uint32_t FF1;
extern const uint32_t FF2;
extern const uint32_t FFDLY;
extern const uint32_t FLUSHO;
extern const uint32_t HUPCL;
extern const uint32_t ICANON;
extern const uint32_t ICRNL;
extern const uint32_t IEXTEN;
extern const uint32_t IGNBRK;
extern const uint32_t IGNCR;
extern const uint32_t IGNPAR;
extern const uint32_t IMAXBEL;
extern const uint32_t INLCR;
extern const uint32_t INPCK;
extern const uint32_t ISIG;
extern const uint32_t ISTRIP;
extern const uint32_t IUCLC;
extern const uint32_t IUTF8;
extern const uint32_t IXANY;
extern const uint32_t IXOFF;
extern const uint32_t IXON;
extern const uint32_t NL1;
extern const uint32_t NL2;
extern const uint32_t NL3;
extern const uint32_t NLDLY;
extern const uint32_t NOFLSH;
extern const uint32_t OCRNL;
extern const uint32_t OFDEL;
extern const uint32_t OFILL;
extern const uint32_t OLCUC;
extern const uint32_t ONLCR;
extern const uint32_t ONLRET;
extern const uint32_t ONOCR;
extern const uint32_t OPOST;
extern const uint32_t PARENB;
extern const uint32_t PARMRK;
extern const uint32_t PARODD;
extern const uint32_t PENDIN;
extern const uint32_t TAB1;
extern const uint32_t TAB2;
extern const uint32_t TAB3;
extern const uint32_t TABDLY;
extern const uint64_t TIOCCONS;
extern const uint64_t TIOCGETD;
extern const uint64_t TIOCGWINSZ;
extern const uint64_t TIOCNOTTY;
extern const uint64_t TIOCNXCL;
extern const uint64_t TIOCOUTQ;
extern const uint64_t TIOCSCTTY;
extern const uint64_t TIOCSETD;
extern const uint64_t TIOCSIG;
extern const uint64_t TIOCSPGRP;
extern const uint64_t TIOCSTI;
extern const uint64_t TIOCSWINSZ;
extern const long TOSTOP;
extern const uint8_t VDISCARD;
extern const uint8_t VEOF;
extern const uint8_t VEOL2;
extern const uint8_t VEOL;
extern const uint8_t VERASE;
extern const uint8_t VINTR;
extern const uint8_t VKILL;
extern const uint8_t VLNEXT;
extern const uint8_t VMIN;
extern const uint8_t VQUIT;
extern const uint8_t VREPRINT;
extern const uint8_t VSTART;
extern const uint8_t VSTOP;
extern const uint8_t VSUSP;
extern const uint8_t VSWTC;
extern const uint32_t VT1;
extern const uint32_t VT2;
extern const uint32_t VTDLY;
extern const uint8_t VTIME;
extern const uint8_t VWERASE;
extern const uint32_t XCASE;
extern const uint32_t XTABS;
extern const uint32_t CRTSCTS;

#define BRKINT  0x02
#define ICRNL   0x0100
#define IGNBRK  0x01
#define IGNCR   0x80
#define IGNPAR  0x04
#define IMAXBEL 0x2000
#define INLCR   0x40
#define INPCK   0x10
#define ISTRIP  0x20
#define IXANY   0x0800
#define OPOST   0x01
#define PARMRK  0x08

#define _POSIX_VDISABLE _POSIX_VDISABLE

#define NLDLY   NLDLY
#define NL0     0
#define NL1     NL1
#define NL2     NL2
#define NL3     NL3
#define CRDLY   CRDLY
#define CR0     0
#define CR1     CR1
#define CR2     CR2
#define CR3     CR3
#define TABDLY  TABDLY
#define TAB0    0
#define TAB1    TAB1
#define TAB2    TAB2
#define TAB3    TAB3
#define XTABS   XTABS
#define CRTSCTS CRTSCTS
#define BSDLY   BSDLY
#define BS0     0
#define BS1     BS1
#define BS2     BS2
#define VTDLY   VTDLY
#define VT0     0
#define VT1     VT1
#define VT2     VT2
#define FFDLY   FFDLY
#define FF0     0
#define FF1     FF1
#define FF2     FF2

#define CLOCAL   CLOCAL
#define CREAD    CREAD
#define CS5      CS5
#define CS6      CS6
#define CS7      CS7
#define CS8      CS8
#define CSIZE    CSIZE
#define CSTOPB   CSTOPB
#define ECHO     8
#define ECHOCTL  ECHOCTL
#define ECHOE    ECHOE
#define ECHOK    ECHOK
#define ECHOKE   ECHOKE
#define ECHONL   ECHONL
#define ECHOPRT  ECHOPRT
#define EXTPROC  EXTPROC
#define FLUSHO   FLUSHO
#define HUPCL    HUPCL
#define ICANON   ICANON
#define IEXTEN   IEXTEN
#define ISIG     ISIG
#define IUCLC    IUCLC
#define IUTF8    IUTF8
#define IXOFF    IXOFF
#define IXON     IXON
#define NOFLSH   NOFLSH
#define OCRNL    OCRNL
#define OFDEL    OFDEL
#define OFILL    OFILL
#define OLCUC    OLCUC
#define ONLCR    ONLCR
#define ONLRET   ONLRET
#define ONOCR    ONOCR
#define PARENB   PARENB
#define PARODD   PARODD
#define PENDIN   PENDIN
#define TOSTOP   TOSTOP
#define VDISCARD VDISCARD
#define VEOF     VEOF
#define VEOL     VEOL
#define VEOL2    VEOL2
#define VERASE   VERASE
#define VINTR    VINTR
#define VKILL    VKILL
#define VLNEXT   VLNEXT
#define VMIN     VMIN
#define VQUIT    VQUIT
#define VREPRINT VREPRINT
#define VSTART   VSTART
#define VSTOP    VSTOP
#define VSUSP    VSUSP
#define VSWTC    VSWTC
#define VTIME    VTIME
#define VWERASE  VWERASE
#define XCASE    XCASE

/* terminal ioctls */
#define TIOCGWINSZ TIOCGWINSZ /* get tty dimensions */
#define TIOCSWINSZ TIOCSWINSZ /* set tty dimensions */
#define TIOCCONS   TIOCCONS   /* redirect terminal */
#define TIOCGETD   TIOCGETD   /* get line discipline */
#define TIOCSETD   TIOCSETD   /* set line discipline */
#define TIOCNOTTY  TIOCNOTTY  /* give up terminal */
#define TIOCNXCL   TIOCNXCL   /* disable exclusive mode */
#define TIOCOUTQ   TIOCOUTQ   /* bytes in output buffer */
#define TIOCSCTTY  TIOCSCTTY  /* make controlling terminal */
#define TIOCSIG    TIOCSIG    /* generate pty signal */
#define TIOCSTI    TIOCSTI    /* insert fake tty input */

/* tcsetattr() */
#define TCSANOW   0
#define TCSAFLUSH 2
#define TCSADRAIN 1
extern const unsigned long TCGETS; /* use tcgetattr() */
extern const unsigned long TCSETS; /* use tcsetattr() */

/* tcflush() */
extern const int TCIFLUSH;
extern const int TCOFLUSH;
extern const int TCIOFLUSH;
#define TCIFLUSH  TCIFLUSH
#define TCOFLUSH  TCOFLUSH
#define TCIOFLUSH TCIOFLUSH

/* tcflow() */
#define TCOOFF 0
#define TCOON  1
#define TCIOFF 2
#define TCION  3

COSMOPOLITAN_C_END_

#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS)
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE | ECHOKE | ECHOCTL)
#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
#define TTYDEF_SPEED (B9600)

#define CTRL(x)  ((x) ^ 0100)
#define CEOF     CTRL('D')
#define CERASE   CTRL('?')
#define CINTR    CTRL('C')
#define CKILL    CTRL('U')
#define CQUIT    CTRL('\\')
#define CSUSP    CTRL('Z')
#define CDSUSP   CTRL('Y')
#define CSTART   CTRL('Q')
#define CSTOP    CTRL('S')
#define CLNEXT   CTRL('V')
#define CDISCARD CTRL('O')
#define CWERASE  CTRL('W')
#define CREPRINT CTRL('R')
#define CEOT     CEOF
#define CBRK     CEOL
#define CRPRNT   CREPRINT
#define CFLUSH   CDISCARD
#define CEOL     255
#define CMIN     1
#define CTIME    0



/*!BEGIN libc/calls/ucontext.h */

#define COSMOPOLITAN_LIBC_CALLS_UCONTEXT_H_
COSMOPOLITAN_C_START_

#ifdef __x86_64__

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
#define REG_R8      0
#define REG_R9      1
#define REG_R10     2
#define REG_R11     3
#define REG_R12     4
#define REG_R13     5
#define REG_R14     6
#define REG_R15     7
#define REG_RDI     8
#define REG_RSI     9
#define REG_RBP     10
#define REG_RBX     11
#define REG_RDX     12
#define REG_RAX     13
#define REG_RCX     14
#define REG_RSP     15
#define REG_RIP     16
#define REG_EFL     17
#define REG_CSGSFS  18
#define REG_ERR     19
#define REG_TRAPNO  20
#define REG_OLDMASK 21
#define REG_CR2     22
#endif

struct XmmRegister {
  uint64_t u64[2];
};

struct FpuStackEntry {
  uint16_t significand[4];
  uint16_t exponent;
  uint16_t padding[3];
};

struct thatispacked FpuState {

  /* 8087 FPU Control Word
      IM: Invalid Operation ───────────────┐
      DM: Denormal Operand ───────────────┐│
      ZM: Zero Divide ───────────────────┐││
      OM: Overflow ─────────────────────┐│││
      UM: Underflow ───────────────────┐││││
      PM: Precision ──────────────────┐│││││
      PC: Precision Control ───────┐  ││││││
       {float,∅,double,long double}│  ││││││
      RC: Rounding Control ──────┐ │  ││││││
       {even, →-∞, →+∞, →0}      │┌┤  ││││││
                                ┌┤││  ││││││
                               d││││rr││││││
                          0b0000001001111111 */
  uint16_t cwd;

  /* 8087 FPU Status Word */
  uint16_t swd;

  uint16_t ftw;
  uint16_t fop;
  uint64_t rip;
  uint64_t rdp;

  /* SSE CONTROL AND STATUS REGISTER
     IE: Invalid Operation Flag ──────────────┐
     DE: Denormal Flag ──────────────────────┐│
     ZE: Divide-by-Zero Flag ───────────────┐││
     OE: Overflow Flag ────────────────────┐│││
     UE: Underflow Flag ──────────────────┐││││
     PE: Precision Flag ─────────────────┐│││││
     DAZ: Denormals Are Zeros ──────────┐││││││
     IM: Invalid Operation Mask ───────┐│││││││
     DM: Denormal Operation Mask ─────┐││││││││
     ZM: Divide-by-Zero Mask ────────┐│││││││││
     OM: Overflow Mask ─────────────┐││││││││││
     UM: Underflow Mask ───────────┐│││││││││││
     PM: Precision Mask ──────────┐││││││││││││
     RC: Rounding Control ───────┐│││││││││││││
       {even, →-∞, →+∞, →0}      ││││││││││││││
     FTZ: Flush To Zero ───────┐ ││││││││││││││
                               │┌┤│││││││││││││
               ┌──────────────┐││││││││││││││││
               │   reserved   │││││││││││││││││
             0b00000000000000000001111110000000 */
  uint32_t mxcsr;
  uint32_t mxcr_mask;

  struct FpuStackEntry st[8];
  struct XmmRegister xmm[16];
  uint32_t __padding[24];
};

typedef long long greg_t;
typedef greg_t gregset_t[23];
typedef struct FpuState *fpregset_t;

#endif /* __x86_64__ */

struct sigcontext {
#ifdef __x86_64__
  union {
    struct {
      uint64_t r8;     /* 40 */
      uint64_t r9;     /* 48 */
      uint64_t r10;    /* 56 */
      uint64_t r11;    /* 64 */
      uint64_t r12;    /* 72 */
      uint64_t r13;    /* 80 */
      uint64_t r14;    /* 88 */
      uint64_t r15;    /* 96 */
      uint64_t rdi;    /* 104 */
      uint64_t rsi;    /* 112 */
      uint64_t rbp;    /* 120 */
      uint64_t rbx;    /* 128 */
      uint64_t rdx;    /* 136 */
      uint64_t rax;    /* 144 */
      uint64_t rcx;    /* 152 */
      uint64_t rsp;    /* 160 */
      uint64_t rip;    /* 168 */
      uint64_t eflags; /* 176 */
      uint16_t cs;
      uint16_t gs;
      uint16_t fs;
      uint16_t __pad0;
      uint64_t err;
      uint64_t trapno;
      uint64_t oldmask;
      uint64_t cr2;
    };
    gregset_t gregs;
  };
  struct FpuState *fpregs; /* zero when no fpu context */
  uint64_t __pad1[8];
#elif defined(__aarch64__)
  uint64_t fault_address;
  uint64_t regs[31];
  uint64_t sp;
  uint64_t pc;
  uint64_t pstate;
  uint8_t __reserved[4096] __attribute__((__aligned__(16)));
#endif /* __x86_64__ */
};

typedef struct sigcontext mcontext_t;

struct ucontext {
  uint64_t uc_flags; /* don't use this */
  struct ucontext *uc_link;
  stack_t uc_stack;
#ifdef __x86_64__
  struct sigcontext uc_mcontext;
  sigset_t uc_sigmask;
  uint64_t __pad[2];
  struct FpuState __fpustate; /* for cosmo on non-linux */
#elif defined(__aarch64__)
  sigset_t uc_sigmask;
  uint8_t __unused[1024 / 8];
  struct sigcontext uc_mcontext;
#endif
} forcealign(16);

typedef struct ucontext ucontext_t;

int getcontext(ucontext_t *) dontthrow;
int setcontext(const ucontext_t *) dontthrow;
int swapcontext(ucontext_t *, const ucontext_t *) dontthrow returnstwice;
void makecontext(ucontext_t *, void *, int, ...) dontthrow dontcallback;
void __sig_restore(const ucontext_t *) wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN libc/calls/weirdtypes.h */

#define COSMOPOLITAN_LIBC_CALLS_WEIRDTYPES_H_

/**
 * @fileoverview Types we'd prefer hadn't been invented.
 */

typedef int64_t blkcnt_t;
typedef uint8_t cc_t;
typedef int64_t clock_t; /* uint64_t on xnu */
typedef uint64_t dev_t;  /* int32_t on xnu */
typedef uint64_t fsblkcnt_t;
typedef int64_t fsfilcnt_t; /* uint32_t on xnu */
typedef uint32_t gid_t;
typedef int32_t id_t; /* int32_t on linux/freebsd/etc. */
typedef uint32_t in_addr_t;
typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
typedef uint64_t ino_t;
typedef int32_t key_t;
typedef int64_t loff_t;
typedef uint32_t mode_t; /* uint16_t on xnu */
typedef uint64_t nfds_t;
typedef int64_t off_t;
typedef int32_t pid_t;
typedef int64_t register_t;
typedef uint16_t sa_family_t; /* bsd:uint8_t */
typedef uint32_t socklen_t;
typedef uint32_t speed_t;
typedef uint32_t suseconds_t;
typedef uint64_t useconds_t;   /* uint32_t on xnu */
typedef int64_t syscall_arg_t; /* uint64_t on xnu */
typedef uint32_t tcflag_t;
typedef int64_t time_t;
typedef void *timer_t;
typedef uint32_t uid_t;
typedef uint64_t rlim_t; /* int64_t on bsd */
typedef int32_t clockid_t;

#ifdef __x86_64__
typedef int64_t blksize_t; /* int32_t on xnu */
typedef uint64_t nlink_t;
#elif defined(__aarch64__)
typedef int32_t blksize_t;
typedef uint32_t nlink_t; /* uint16_t on xnu */
#endif

#define TIME_T_MAX __INT64_MAX__
#define TIME_T_MIN (-TIME_T_MAX - 1)

#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define F_GETLK64         F_GETLK
#define F_SETLK64         F_SETLK
#define F_SETLKW64        F_SETLKW
#define RLIM64_INFINITY   RLIM_INFINITY
#define RLIM64_SAVED_CUR  RLIM_SAVED_CUR
#define RLIM64_SAVED_MAX  RLIM_SAVED_MAX
#define alphasort64       alphasort
#define blkcnt64_t        blkcnt_t
#define dirent64          dirent
#define flock64           flock
#define fsfilcnt64_t      fsfilcnt_t
#define fstat64           fstat
#define fstatat64         fstatat
#define fstatfs64         fstatfs
#define fstatvfs64        fstatvfs
#define getrlimit64       getrlimit
#define ino64_t           ino_t
#define lockf64           lockf
#define lstat64           lstat
#define mmap64            mmap
#define off64_t           off_t
#define open64            open
#define openat64          openat
#define posix_fadvise64   posix_fadvise
#define posix_fallocate64 posix_fallocate
#define readdir64         readdir
#define readdir64_r       readdir_r
#define rlim64_t          rlim_t
#define rlimit64          rlimit
#define scandir64         scandir
#define sendfile64        sendfile
#define setrlimit64       setrlimit
#define stat64            stat
#define statfs64          statfs
#define statvfs64         statvfs
#define versionsort64     versionsort
#endif



/*!BEGIN libc/elf/def.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DEF_H_

/**
 * @fileoverview Executable and Linkable Format Definitions.
 */

#define EI_NIDENT 16

#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3

#define ELFMAG  "\177ELF"
#define ELFMAG0 0x7f
#define ELFMAG1 'E'
#define ELFMAG2 'L'
#define ELFMAG3 'F'
#define SELFMAG 4

#define EI_CLASS     4
#define ELFCLASSNONE 0
#define ELFCLASS32   1
#define ELFCLASS64   2
#define ELFCLASSNUM  3

#define EI_DATA     5
#define ELFDATANONE 0
#define ELFDATA2LSB 1
#define ELFDATA2MSB 2
#define ELFDATANUM  3

#define EI_VERSION 6

#define EI_OSABI            7
#define ELFOSABI_NONE       0
#define ELFOSABI_SYSV       0
#define ELFOSABI_HPUX       1
#define ELFOSABI_NETBSD     2
#define ELFOSABI_LINUX      3
#define ELFOSABI_GNU        3
#define ELFOSABI_SOLARIS    6
#define ELFOSABI_AIX        7
#define ELFOSABI_IRIX       8
#define ELFOSABI_FREEBSD    9
#define ELFOSABI_TRU64      10
#define ELFOSABI_MODESTO    11
#define ELFOSABI_OPENBSD    12
#define ELFOSABI_ARM        97
#define ELFOSABI_STANDALONE 255

#define EI_ABIVERSION 8

#define EI_PAD 9

#define ET_NONE   0
#define ET_REL    1
#define ET_EXEC   2
#define ET_DYN    3
#define ET_CORE   4
#define ET_NUM    5
#define ET_LOOS   0xfe00
#define ET_HIOS   0xfeff
#define ET_LOPROC 0xff00
#define ET_HIPROC 0xffff

#define EM_NONE      0
#define EM_M32       1
#define EM_386       3
#define EM_PPC64     21
#define EM_S390      22
#define EM_ARM       40
#define EM_NEXGEN32E 62
#define EM_X86_64    EM_NEXGEN32E
#define EM_IA32E     EM_NEXGEN32E
#define EM_AMD64     EM_NEXGEN32E
#define EM_PDP11     65
#define EM_CRAYNV2   172
#define EM_L10M      180
#define EM_K10M      181
#define EM_AARCH64   183
#define EM_CUDA      190
#define EM_Z80       220
#define EM_RISCV     243
#define EM_BPF       247

/* the ape flag, "lol cat 5" */
#define EF_APE_MODERN      0x101ca75
#define EF_APE_MODERN_MASK 0x1ffffff

#define GRP_COMDAT 1
#define STN_UNDEF  0

#define EV_NONE    0
#define EV_CURRENT 1
#define EV_NUM     2

#define SYMINFO_NONE          0
#define SYMINFO_CURRENT       1
#define SYMINFO_NUM           2
#define SYMINFO_BT_SELF       0xffff
#define SYMINFO_BT_PARENT     0xfffe
#define SYMINFO_BT_LOWRESERVE 0xff00
#define SYMINFO_FLG_DIRECT    0x0001
#define SYMINFO_FLG_PASSTHRU  0x0002
#define SYMINFO_FLG_COPY      0x0004
#define SYMINFO_FLG_LAZYLOAD  0x0008

#define PT_NULL         0
#define PT_LOAD         1
#define PT_DYNAMIC      2
#define PT_INTERP       3
#define PT_NOTE         4
#define PT_SHLIB        5
#define PT_PHDR         6
#define PT_TLS          7
#define PT_NUM          8
#define PT_LOOS         0x60000000
#define PT_GNU_EH_FRAME 0x6474e550
#define PT_GNU_STACK    0x6474e551
#define PT_GNU_RELRO    0x6474e552
#define PT_LOSUNW       0x6ffffffa
#define PT_SUNWBSS      0x6ffffffa
#define PT_SUNWSTACK    0x6ffffffb
#define PT_HISUNW       0x6fffffff
#define PT_HIOS         0x6fffffff
#define PT_LOPROC       0x70000000
#define PT_HIPROC       0x7fffffff

#define PN_XNUM 0xffff

#define PF_X        1
#define PF_W        2
#define PF_R        4
#define PF_MASKOS   0x0ff00000
#define PF_MASKPROC 0xf0000000

#define R_X86_64_NONE            0
#define R_X86_64_64              1
#define R_X86_64_PC32            2
#define R_X86_64_GOT32           3
#define R_X86_64_PLT32           4
#define R_X86_64_COPY            5
#define R_X86_64_GLOB_DAT        6
#define R_X86_64_JUMP_SLOT       7
#define R_X86_64_RELATIVE        8
#define R_X86_64_GOTPCREL        9
#define R_X86_64_32              10
#define R_X86_64_32S             11
#define R_X86_64_16              12
#define R_X86_64_PC16            13
#define R_X86_64_8               14
#define R_X86_64_PC8             15
#define R_X86_64_DTPMOD64        16
#define R_X86_64_DTPOFF64        17
#define R_X86_64_TPOFF64         18
#define R_X86_64_TLSGD           19
#define R_X86_64_TLSLD           20
#define R_X86_64_DTPOFF32        21
#define R_X86_64_GOTTPOFF        22
#define R_X86_64_TPOFF32         23
#define R_X86_64_PC64            24
#define R_X86_64_GOTOFF64        25
#define R_X86_64_GOTPC32         26
#define R_X86_64_GOT64           27
#define R_X86_64_GOTPCREL64      28
#define R_X86_64_GOTPC64         29
#define R_X86_64_GOTPLT64        30
#define R_X86_64_PLTOFF64        31
#define R_X86_64_SIZE32          32
#define R_X86_64_SIZE64          33
#define R_X86_64_GOTPC32_TLSDESC 34
#define R_X86_64_TLSDESC_CALL    35
#define R_X86_64_TLSDESC         36
#define R_X86_64_IRELATIVE       37
#define R_X86_64_RELATIVE64      38
#define R_X86_64_GOTPCRELX       41 /* 6 bytes */
#define R_X86_64_REX_GOTPCRELX   42 /* 7 bytes */
#define R_X86_64_NUM             43

#define R_AARCH64_NONE   0
#define R_AARCH64_ABS64  257
#define R_AARCH64_ABS32  258
#define R_AARCH64_ABS16  259
#define R_AARCH64_PREL64 260
#define R_AARCH64_PREL32 261
#define R_AARCH64_PREL16 262

#define R_PPC_NONE   0
#define R_PPC_ADDR32 1
#define R_PPC_ADDR24 2
#define R_PPC_ADDR16 3
#define R_PPC_REL32  26

#define R_PPC64_NONE   R_PPC_NONE
#define R_PPC64_ADDR32 R_PPC_ADDR32
#define R_PPC64_ADDR24 R_PPC_ADDR24
#define R_PPC64_ADDR16 R_PPC_ADDR16
#define R_PPC64_REL32  R_PPC_REL32

#define R_RISCV_NONE     0
#define R_RISCV_32       1
#define R_RISCV_64       2
#define R_RISCV_RELATIVE 3

#define R_390_NONE 0
#define R_390_8    1
#define R_390_12   2
#define R_390_16   3
#define R_390_32   4
#define R_390_PC32 5

#define STB_LOCAL      0
#define STB_GLOBAL     1
#define STB_WEAK       2
#define STB_NUM        3
#define STB_LOOS       10
#define STB_GNU_UNIQUE 10
#define STB_HIOS       12
#define STB_LOPROC     13
#define STB_HIPROC     15

#define STT_NOTYPE    0
#define STT_OBJECT    1
#define STT_FUNC      2
#define STT_SECTION   3
#define STT_FILE      4
#define STT_COMMON    5
#define STT_TLS       6
#define STT_NUM       7
#define STT_LOOS      10
#define STT_GNU_IFUNC 10
#define STT_HIOS      12
#define STT_LOPROC    13
#define STT_HIPROC    15

#define STV_DEFAULT   0
#define STV_INTERNAL  1
#define STV_HIDDEN    2
#define STV_PROTECTED 3

#define SHN_UNDEF     0
#define SHN_LORESERVE 0xff00
#define SHN_LOPROC    0xff00
#define SHN_BEFORE    0xff00
#define SHN_AFTER     0xff01
#define SHN_HIPROC    0xff1f
#define SHN_LOOS      0xff20
#define SHN_HIOS      0xff3f
#define SHN_ABS       0xfff1
#define SHN_COMMON    0xfff2
#define SHN_XINDEX    0xffff
#define SHN_HIRESERVE 0xffff

#define SHF_WRITE            (1 << 0)
#define SHF_ALLOC            (1 << 1)
#define SHF_EXECINSTR        (1 << 2)
#define SHF_MERGE            (1 << 4)
#define SHF_STRINGS          (1 << 5)
#define SHF_INFO_LINK        (1 << 6)
#define SHF_LINK_ORDER       (1 << 7)
#define SHF_OS_NONCONFORMING (1 << 8)
#define SHF_GROUP            (1 << 9)
#define SHF_TLS              (1 << 10)
#define SHF_COMPRESSED       (1 << 11)
#define SHF_MASKOS           0x0ff00000
#define SHF_MASKPROC         0xf0000000
#define SHF_ORDERED          (1 << 30)
#define SHF_EXCLUDE          (1U << 31)

#define ELFCOMPRESS_ZLIB   1
#define ELFCOMPRESS_LOOS   0x60000000
#define ELFCOMPRESS_HIOS   0x6fffffff
#define ELFCOMPRESS_LOPROC 0x70000000
#define ELFCOMPRESS_HIPROC 0x7fffffff

#define SHT_NULL           0
#define SHT_PROGBITS       1
#define SHT_SYMTAB         2
#define SHT_STRTAB         3
#define SHT_RELA           4
#define SHT_HASH           5
#define SHT_DYNAMIC        6
#define SHT_NOTE           7
#define SHT_NOBITS         8
#define SHT_REL            9
#define SHT_SHLIB          10
#define SHT_DYNSYM         11
#define SHT_INIT_ARRAY     14
#define SHT_FINI_ARRAY     15
#define SHT_PREINIT_ARRAY  16
#define SHT_GROUP          17
#define SHT_SYMTAB_SHNDX   18
#define SHT_NUM            19
#define SHT_LOOS           0x60000000
#define SHT_GNU_ATTRIBUTES 0x6ffffff5
#define SHT_GNU_HASH       0x6ffffff6
#define SHT_GNU_LIBLIST    0x6ffffff7
#define SHT_CHECKSUM       0x6ffffff8
#define SHT_LOSUNW         0x6ffffffa
#define SHT_SUNW_move      0x6ffffffa
#define SHT_SUNW_COMDAT    0x6ffffffb
#define SHT_SUNW_syminfo   0x6ffffffc
#define SHT_GNU_verdef     0x6ffffffd
#define SHT_GNU_verneed    0x6ffffffe
#define SHT_GNU_versym     0x6fffffff
#define SHT_HISUNW         0x6fffffff
#define SHT_HIOS           0x6fffffff
#define SHT_LOPROC         0x70000000
#define SHT_HIPROC         0x7fffffff
#define SHT_LOUSER         0x80000000
#define SHT_HIUSER         0x8fffffff

#define DT_NULL               0
#define DT_NEEDED             1
#define DT_PLTRELSZ           2
#define DT_PLTGOT             3
#define DT_HASH               4
#define DT_STRTAB             5
#define DT_SYMTAB             6
#define DT_RELA               7
#define DT_RELASZ             8
#define DT_RELAENT            9
#define DT_STRSZ              10
#define DT_SYMENT             11
#define DT_INIT               12
#define DT_FINI               13
#define DT_SONAME             14
#define DT_RPATH              15
#define DT_SYMBOLIC           16
#define DT_REL                17
#define DT_RELSZ              18
#define DT_RELENT             19
#define DT_PLTREL             20
#define DT_DEBUG              21
#define DT_TEXTREL            22
#define DT_JMPREL             23
#define DT_BIND_NOW           24
#define DT_INIT_ARRAY         25
#define DT_FINI_ARRAY         26
#define DT_INIT_ARRAYSZ       27
#define DT_FINI_ARRAYSZ       28
#define DT_RUNPATH            29
#define DT_FLAGS              30
#define DT_ENCODING           32
#define DT_PREINIT_ARRAY      32
#define DT_PREINIT_ARRAYSZ    33
#define DT_SYMTAB_SHNDX       34
#define DT_NUM                35
#define DT_LOOS               0x6000000d
#define DT_HIOS               0x6ffff000
#define DT_LOPROC             0x70000000
#define DT_HIPROC             0x7fffffff
#define DT_VALRNGLO           0x6ffffd00
#define DT_GNU_PRELINKED      0x6ffffdf5
#define DT_GNU_CONFLICTSZ     0x6ffffdf6
#define DT_GNU_LIBLISTSZ      0x6ffffdf7
#define DT_CHECKSUM           0x6ffffdf8
#define DT_PLTPADSZ           0x6ffffdf9
#define DT_MOVEENT            0x6ffffdfa
#define DT_MOVESZ             0x6ffffdfb
#define DT_FEATURE_1          0x6ffffdfc
#define DT_POSFLAG_1          0x6ffffdfd
#define DT_SYMINSZ            0x6ffffdfe
#define DT_SYMINENT           0x6ffffdff
#define DT_VALRNGHI           0x6ffffdff
#define DT_VALTAGIDX(tag)     (DT_VALRNGHI - (tag))
#define DT_VALNUM             12
#define DT_ADDRRNGLO          0x6ffffe00
#define DT_GNU_HASH           0x6ffffef5
#define DT_TLSDESC_PLT        0x6ffffef6
#define DT_TLSDESC_GOT        0x6ffffef7
#define DT_GNU_CONFLICT       0x6ffffef8
#define DT_GNU_LIBLIST        0x6ffffef9
#define DT_CONFIG             0x6ffffefa
#define DT_DEPAUDIT           0x6ffffefb
#define DT_AUDIT              0x6ffffefc
#define DT_PLTPAD             0x6ffffefd
#define DT_MOVETAB            0x6ffffefe
#define DT_SYMINFO            0x6ffffeff
#define DT_ADDRRNGHI          0x6ffffeff
#define DT_ADDRTAGIDX(tag)    (DT_ADDRRNGHI - (tag))
#define DT_ADDRNUM            11
#define DT_VERSYM             0x6ffffff0
#define DT_RELACOUNT          0x6ffffff9
#define DT_RELCOUNT           0x6ffffffa
#define DT_FLAGS_1            0x6ffffffb
#define DT_VERDEF             0x6ffffffc
#define DT_VERDEFNUM          0x6ffffffd
#define DT_VERNEED            0x6ffffffe
#define DT_VERNEEDNUM         0x6fffffff
#define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag))
#define DT_VERSIONTAGNUM      16
#define DT_AUXILIARY          0x7ffffffd
#define DT_FILTER             0x7fffffff
#define DT_EXTRATAGIDX(tag)   ((Elf32_Word) - ((Elf32_Sword)(tag) << 1 >> 1) - 1)
#define DT_EXTRANUM           3

#define VER_NEED_NONE    0
#define VER_NEED_CURRENT 1
#define VER_NEED_NUM     2
#define VER_FLG_WEAK     0x2

#define ELF_NOTE_SOLARIS       "SUNW Solaris"
#define ELF_NOTE_GNU           "GNU"
#define ELF_NOTE_PAGESIZE_HINT 1
#define ELF_NOTE_ABI           NT_GNU_ABI_TAG
#define ELF_NOTE_OS_LINUX      0
#define ELF_NOTE_OS_GNU        1
#define ELF_NOTE_OS_SOLARIS2   2
#define ELF_NOTE_OS_FREEBSD    3

#define NT_GNU_ABI_TAG      1
#define NT_GNU_BUILD_ID     3
#define NT_GNU_GOLD_VERSION 4

#define EF_CPU32 0x00810000

#define DF_ORIGIN       0x00000001
#define DF_SYMBOLIC     0x00000002
#define DF_TEXTREL      0x00000004
#define DF_BIND_NOW     0x00000008
#define DF_STATIC_TLS   0x00000010
#define DF_1_NOW        0x00000001
#define DF_1_GLOBAL     0x00000002
#define DF_1_GROUP      0x00000004
#define DF_1_NODELETE   0x00000008
#define DF_1_LOADFLTR   0x00000010
#define DF_1_INITFIRST  0x00000020
#define DF_1_NOOPEN     0x00000040
#define DF_1_ORIGIN     0x00000080
#define DF_1_DIRECT     0x00000100
#define DF_1_TRANS      0x00000200
#define DF_1_INTERPOSE  0x00000400
#define DF_1_NODEFLIB   0x00000800
#define DF_1_NODUMP     0x00001000
#define DF_1_CONFALT    0x00002000
#define DF_1_ENDFILTEE  0x00004000
#define DF_1_DISPRELDNE 0x00008000
#define DF_1_DISPRELPND 0x00010000
#define DF_1_NODIRECT   0x00020000
#define DF_1_IGNMULDEF  0x00040000
#define DF_1_NOKSYMS    0x00080000
#define DF_1_NOHDR      0x00100000
#define DF_1_EDITED     0x00200000
#define DF_1_NORELOC    0x00400000
#define DF_1_SYMINTPOSE 0x00800000
#define DF_1_GLOBAUDIT  0x01000000
#define DF_1_SINGLETON  0x02000000
#define DF_1_STUB       0x04000000
#define DF_1_PIE        0x08000000
#define DTF_1_PARINIT   0x00000001
#define DTF_1_CONFEXP   0x00000002
#define DF_P1_LAZYLOAD  0x00000001
#define DF_P1_GROUPPERM 0x00000002

#define ELF64_ST_BIND(val)        (((unsigned char)(val)) >> 4)
#define ELF64_ST_TYPE(val)        ((val)&0xf)
#define ELF64_ST_INFO(bind, type) (((bind) << 4) + ((type)&0xf))
#define ELF64_ST_VISIBILITY(o)    ((o)&0x03)

#define ELF64_R_SYM(i)          ((i) >> 32)
#define ELF64_R_TYPE(i)         ((i)&0xffffffff)
#define ELF64_R_INFO(sym, type) ((((Elf64_Xword)(sym)) << 32) + (type))

#define ELF64_M_SYM(info)       ((info) >> 8)
#define ELF64_M_SIZE(info)      ((unsigned char)(info))
#define ELF64_M_INFO(sym, size) (((sym) << 8) + (unsigned char)(size))

#define NT_PRSTATUS         1
#define NT_PRFPREG          2
#define NT_FPREGSET         2
#define NT_PRPSINFO         3
#define NT_PRXREG           4
#define NT_TASKSTRUCT       4
#define NT_PLATFORM         5
#define NT_AUXV             6
#define NT_GWINDOWS         7
#define NT_ASRS             8
#define NT_PSTATUS          10
#define NT_PSINFO           13
#define NT_PRCRED           14
#define NT_UTSNAME          15
#define NT_LWPSTATUS        16
#define NT_LWPSINFO         17
#define NT_PRFPXREG         20
#define NT_SIGINFO          0x53494749
#define NT_FILE             0x46494c45
#define NT_PRXFPREG         0x46e62b7f
#define NT_PPC_VMX          0x100
#define NT_PPC_SPE          0x101
#define NT_PPC_VSX          0x102
#define NT_PPC_TAR          0x103
#define NT_PPC_PPR          0x104
#define NT_PPC_DSCR         0x105
#define NT_PPC_EBB          0x106
#define NT_PPC_PMU          0x107
#define NT_PPC_TM_CGPR      0x108
#define NT_PPC_TM_CFPR      0x109
#define NT_PPC_TM_CVMX      0x10a
#define NT_PPC_TM_CVSX      0x10b
#define NT_PPC_TM_SPR       0x10c
#define NT_PPC_TM_CTAR      0x10d
#define NT_PPC_TM_CPPR      0x10e
#define NT_PPC_TM_CDSCR     0x10f
#define NT_X86_XSTATE       0x202
#define NT_S390_HIGH_GPRS   0x300
#define NT_S390_TIMER       0x301
#define NT_S390_TODCMP      0x302
#define NT_S390_TODPREG     0x303
#define NT_S390_CTRS        0x304
#define NT_S390_PREFIX      0x305
#define NT_S390_LAST_BREAK  0x306
#define NT_S390_SYSTEM_CALL 0x307
#define NT_S390_TDB         0x308
#define NT_S390_VXRS_LOW    0x309
#define NT_S390_VXRS_HIGH   0x30a
#define NT_S390_GS_CB       0x30b
#define NT_S390_GS_BC       0x30c
#define NT_S390_RI_CB       0x30d
#define NT_ARM_VFP          0x400
#define NT_ARM_TLS          0x401
#define NT_ARM_HW_BREAK     0x402
#define NT_ARM_HW_WATCH     0x403
#define NT_ARM_SYSTEM_CALL  0x404
#define NT_ARM_SVE          0x405
#define NT_ARM_PAC_MASK     0x406
#define NT_METAG_CBUF       0x500
#define NT_METAG_RPIPE      0x501
#define NT_METAG_TLS        0x502
#define NT_ARC_V2           0x600
#define NT_VMCOREDD         0x700
#define NT_VERSION          1

#define VER_DEF_NONE      0
#define VER_DEF_CURRENT   1
#define VER_DEF_NUM       2
#define VER_FLG_BASE      0x1
#define VER_FLG_WEAK      0x2
#define VER_NDX_LOCAL     0
#define VER_NDX_GLOBAL    1
#define VER_NDX_LORESERVE 0xff00
#define VER_NDX_ELIMINATE 0xff01

#define LL_NONE           0
#define LL_EXACT_MATCH    (1 << 0)
#define LL_IGNORE_INT_VER (1 << 1)
#define LL_REQUIRE_MINOR  (1 << 2)
#define LL_EXPORTS        (1 << 3)
#define LL_DELAY_LOAD     (1 << 4)
#define LL_DELTA          (1 << 5)

#define R_BPF_NONE   0
#define R_BPF_MAP_FD 1



/*!BEGIN libc/elf/elf.h */

#define COSMOPOLITAN_LIBC_ELF_H_


/*!BEGIN libc/elf/struct/ehdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_EHDR_H_


/*!BEGIN libc/elf/scalar.h */

#define COSMOPOLITAN_LIBC_ELF_SCALAR_H_

#define Elf64_Addr    uint64_t
#define Elf64_Half    uint16_t
#define Elf64_Off     uint64_t
#define Elf64_Section uint16_t
#define Elf64_Sword   int32_t
#define Elf64_Sxword  int64_t
#define Elf64_Versym  Elf64_Half
#define Elf64_Word    uint32_t
#define Elf64_Xword   uint64_t
#define Elf_Symndx    uint32_t


/*
 * ELF header.
 */
typedef struct Elf64_Ehdr {

  /*
   * Leading bytes of ELF header.
   *
   * - `e_ident[0]` is always `127`
   * - `e_ident[1]` is always `'E'`
   * - `e_ident[2]` is always `'L'`
   * - `e_ident[3]` is always `'F'`
   *
   * - `e_ident[EI_CLASS]` is mandatory and should be:
   *
   *   - `ELFCLASSNONE64` if it's an Elf64 image
   *   - `ELFCLASSNONE32` if it's an Elf32 image
   *   - Otherwise we assume it's an Elf64 image
   *
   * - `e_ident[EI_DATA]` is advisory and could be:
   *
   *   - `ELFDATANONE` isn't strictly valid
   *   - `ELFDATA2LSB` for little-endian
   *   - `ELFDATA2MSB` for big-endian
   *
   * - `e_ident[EI_VERSION]` is advisory and should be:
   *
   *   - `EV_NONE` if it's zero or unspecified
   *   - `EV_CURRENT` for current ELF version (which is 1)
   *
   * - `e_ident[EI_OSABI]` is mandatory and could be:
   *
   *   - `ELFOSABI_NONE` is zero
   *   - `ELFOSABI_GNU` is for GNU
   *   - `ELFOSABI_SYSV` used by GNU
   *   - `ELFOSABI_LINUX` doesn't care
   *   - `ELFOSABI_FREEBSD` does care (recommended)
   *   - `ELFOSABI_NETBSD` doesn't care (see `PT_NOTE`)
   *   - `ELFOSABI_OPENBSD` doesn't care (see `PT_NOTE`)
   *
   * - `e_ident[EI_ABIVERSION]` is advisory
   *
   */
  unsigned char e_ident[16];

  /*
   * ELF image type.
   *
   * This field is mandatory and should be one of:
   *
   * - `ET_REL` for `.o` object files
   * - `ET_DYN` for `.so` files and `-pie` executables
   * - `ET_EXEC` for statically-linked executables
   *
   */
  Elf64_Half e_type;

  /*
   * ELF machine type.
   *
   * This field is mandatory and could be one of:
   *
   * - `EM_M32` for Bellmac
   * - `EM_X86_64` for Amd64
   * - `EM_AARCH64` for Arm64
   * - `EM_PPC64` for Raptors
   * - `EM_RISCV` for Berkeley
   * - `EM_S390` for System/360
   *
   */
  Elf64_Half e_machine;

  /*
   * ELF version.
   *
   * This field is advisory and could be:
   *
   * - `EV_NONE` if it's zero or unspecified
   * - `EV_CURRENT` for current ELF version (which is 1)
   *
   * @see `e_ident[EI_VERSION]`
   */
  Elf64_Word e_version;

  /*
   * ELF executable entrypoint.
   *
   * Static executables should use this field to store the virtual
   * address of the _start() function. This field may be zero, for
   * unspecified.
   */
  Elf64_Addr e_entry;

  /*
   * `Elf64_Phdr` file offset.
   *
   * This field is mandatory. Object files should set it to zero.
   */
  Elf64_Off e_phoff;

  /*
   * `Elf64_Shdr` file offset.
   *
   * This field is advisory.
   */
  Elf64_Off e_shoff;

  /*
   * ELF flags.
   *
   * This field is advisory.
   */
  Elf64_Word e_flags;

  /*
   * `Elf64_Ehdr` size.
   *
   * This field is advisory and should be 64.
   */
  Elf64_Half e_ehsize;

  /*
   * `Elf64_Phdr` element size.
   *
   * This field *is* cared about and should be set to 56. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_phentsize;

  /*
   * `Elf64_Phdr` array count.
   */
  Elf64_Half e_phnum;

  /*
   * `Elf64_Shdr` element size.
   *
   * This field is advisory and should be set to 64. Cosmopolitan
   * permits larger values for the pleasure of it.
   */
  Elf64_Half e_shentsize;

  /*
   * `Elf64_Shdr` count.
   *
   * This field is advisory.
   */
  Elf64_Half e_shnum;

  /*
   * Section header index of section name string table.
   */
  Elf64_Half e_shstrndx;

} Elf64_Ehdr;



/*!BEGIN libc/elf/struct/phdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_PHDR_H_

typedef struct Elf64_Phdr {
  Elf64_Word p_type;
  Elf64_Word p_flags;
  Elf64_Off p_offset;
  Elf64_Addr p_vaddr;
  Elf64_Addr p_paddr;
  Elf64_Xword p_filesz;
  Elf64_Xword p_memsz;
  Elf64_Xword p_align;
} Elf64_Phdr;



/*!BEGIN libc/elf/struct/shdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SHDR_H_

/**
 * Section header.
 * @see https://docs.oracle.com/cd/E19683-01/816-1386/chapter6-94076/index.html
 */
typedef struct Elf64_Shdr {

  Elf64_Word sh_name;

  Elf64_Word sh_type; /* SHT_{PROGBITS,NOBITS,STRTAB,SYMTAB,RELA,...} */

  Elf64_Xword sh_flags; /* SHF_{WRITE,ALLOC,EXECINSTR,TLS,MERGE,STRINGS,,...} */

  Elf64_Addr sh_addr;

  Elf64_Off sh_offset;

  Elf64_Xword sh_size;

  /*
   * Index of linked section header.
   *
   * If `sh_type` is `SHT_RELA` then `sh_link` holds the section header
   * index of the associated symbol table.
   *
   * If `sh_type` is `SHT_SYMTAB` then `sh_link` holds the section
   * header index of the associated string table.
   */
  Elf64_Word sh_link;

  /*
   * If `sh_type` is `SHT_RELA` then `sh_info` contains the index of the
   * section to which relocations apply.
   *
   * If `sh_type` is `SHT_SYMTAB` or `SHT_DYNSYM` then `sh_info`
   * contains an index that's one greater than symbol table index of
   * last `STB_LOCAL` symbol.
   */
  Elf64_Word sh_info;

  Elf64_Xword sh_addralign;

  Elf64_Xword sh_entsize;

} Elf64_Shdr;



/*!BEGIN libc/elf/struct/sym.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYM_H_

typedef struct Elf64_Sym {

  /*
   * Symbol name.
   *
   * This value is a byte offset into the `.strtab` section. If this
   * value is zero, then the symbol has no name.
   */
  Elf64_Word st_name;

  /*
   * Symbol type and binding.
   *
   * This value may be created using:
   *
   *     sym.st_info = ELF64_ST_INFO(bind, type);
   *
   * This value may be read using:
   *
   *     int bind = ELF64_ST_BIND(sym.st_info);
   *     int type = ELF64_ST_TYPE(sym.st_info);
   *
   * Where `bind` is typically:
   *
   * - `STB_LOCAL`
   * - `STB_GLOBAL`
   * - `STB_WEAK`
   *
   * Where `type` is typically:
   *
   * - `STT_NOTYPE`
   * - `STT_OBJECT`
   * - `STT_FUNC`
   * - `STT_SECTION`
   * - `STT_FILE`
   * - `STT_COMMON`
   * - `STT_TLS`
   */
  uint8_t st_info;

  /*
   * Symbol visibility.
   *
   * This value should be accessed using:
   *
   *     int visibility = ELF64_ST_VISIBILITY(sym.st_other);
   *
   * Where `visibility` is typically:
   *
   * - `STV_DEFAULT`
   * - `STV_INTERNAL`
   * - `STV_HIDDEN`
   * - `STV_PROTECTED`
   */
  uint8_t st_other;

  /*
   * Symbol section.
   *
   * If `st_shndx` is within `(SHN_UNDEF,SHN_LORESERVE)` then it holds
   * an index into the section header table.
   *
   * Otherwise `st_shndx` is usually one of the following magic numbers:
   *
   * - `SHN_UNDEF` means symbol is undefined
   * - `SHN_ABS` means symbol is a linker integer
   * - `SHN_COMMON` means symbol is defined traditionally
   */
  Elf64_Section st_shndx;

  /*
   * Symbol value.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is `SHN_COMMON`, then
   * `st_value` holds the required symbol alignment, or ≤ 1 if no
   * alignment is required.
   *
   * If `e_type` is `ET_REL` and `st_shndx` is a section index, then
   * `st_value` holds a byte offset into the section memory.
   *
   * If `e_type` isn't `ET_REL` then `st_value` holds a virtual address.
   */
  Elf64_Addr st_value;

  /* byte length optionally set by .size directive */
  Elf64_Xword st_size;

} Elf64_Sym;

#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § executable linkable format                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
/* clang-format off */

bool32 IsElfSymbolContent(const Elf64_Sym *);
bool32 IsElf64Binary(const Elf64_Ehdr *, size_t);
char *GetElfStringTable(const Elf64_Ehdr *, size_t, const char *);
Elf64_Sym *GetElfSymbols(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Shdr *GetElfSymbolTable(const Elf64_Ehdr *, size_t, int, Elf64_Xword *);
Elf64_Phdr *GetElfProgramHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *GetElfSectionHeaderAddress(const Elf64_Ehdr *, size_t, Elf64_Half);
Elf64_Shdr *FindElfSectionByName(const Elf64_Ehdr *, size_t, char *, const char *);
char *GetElfString(const Elf64_Ehdr *, size_t, const char *, Elf64_Word);
void *GetElfSectionAddress(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
void *GetElfSegmentAddress(const Elf64_Ehdr *, size_t, const Elf64_Phdr *);
char *GetElfSectionName(const Elf64_Ehdr *, size_t, const Elf64_Shdr *);
char *GetElfSectionNameStringTable(const Elf64_Ehdr *, size_t);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */
/* clang-format on */


/*!BEGIN libc/elf/link.h */

#define COSMOPOLITAN_ELF_LINK_H_


/*!BEGIN libc/elf/struct/dyn.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_DYN_H_

typedef struct Elf64_Dyn {
  Elf64_Sxword d_tag;
  union {
    Elf64_Xword d_val;
    Elf64_Addr d_ptr;
  } d_un;
} Elf64_Dyn;

COSMOPOLITAN_C_START_

#define ElfW(type) Elf64_##type

struct dl_phdr_info {
  Elf64_Addr dlpi_addr;
  const char *dlpi_name;
  const Elf64_Phdr *dlpi_phdr;
  Elf64_Half dlpi_phnum;
  unsigned long long int dlpi_adds;
  unsigned long long int dlpi_subs;
  size_t dlpi_tls_modid;
  void *dlpi_tls_data;
};

struct link_map {
  Elf64_Addr l_addr;
  char *l_name;
  Elf64_Dyn *l_ld;
  struct link_map *l_next;
  struct link_map *l_prev;
};

struct r_debug {
  int r_version;
  struct link_map *r_map;
  Elf64_Addr r_brk;
  enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state;
  Elf64_Addr r_ldbase;
};

int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/elf/struct/auxv.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_AUXV_H_

typedef struct Elf64_auxv_t {
  uint64_t a_type;
  union {
    uint64_t a_val;
  } a_un;
} Elf64_auxv_t;



/*!BEGIN libc/elf/struct/chdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_CHDR_H_

typedef struct Elf64_Chdr {
  Elf64_Word ch_type;
  Elf64_Word ch_reserved;
  Elf64_Xword ch_size;
  Elf64_Xword ch_addralign;
} Elf64_Chdr;



/*!BEGIN libc/elf/struct/lib.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_LIB_H_

typedef struct Elf64_Lib {
  Elf64_Word l_name;
  Elf64_Word l_time_stamp;
  Elf64_Word l_checksum;
  Elf64_Word l_version;
  Elf64_Word l_flags;
} Elf64_Lib;



/*!BEGIN libc/elf/struct/move.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_MOVE_H_

typedef struct Elf64_Move {
  Elf64_Xword m_value;
  Elf64_Xword m_info;
  Elf64_Xword m_poffset;
  Elf64_Half m_repeat;
  Elf64_Half m_stride;
} Elf64_Move;



/*!BEGIN libc/elf/struct/nhdr.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_NHDR_H_

typedef struct Elf64_Nhdr {
  Elf64_Word n_namesz;
  Elf64_Word n_descsz;
  Elf64_Word n_type;
} Elf64_Nhdr;



/*!BEGIN libc/elf/struct/rel.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_REL_H_

/*
 * ELF relocation.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_REL`.
 *
 * @see Elf64_Rela
 */
typedef struct Elf64_Rel {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` might be:
   *
   * - `R_X86_64_64`
   * - `R_X86_64_PC32`
   * - `R_X86_64_GOTPCRELX`
   * - `R_AARCH64_ABS64`
   *
   * Each relocation type specifies a mathematical formula that's used
   * to compute the appropriate value for the fixed-up object code. If
   * it needs an addend, then this struct doesn't have one, but it can
   * still be embedded by the compiler in the location to be modified.
   */
  Elf64_Xword r_info;

} Elf64_Rel;



/*!BEGIN libc/elf/struct/rela.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_RELA_H_

/*
 * ELF relocation w/ explicit addend.
 *
 * Relocations let us easily apply fixups to compiled object code. This
 * data structure represents the contents of an `sh_type` w/ `SHT_RELA`
 *
 * @see Elf64_Rel
 */
typedef struct Elf64_Rela {

  /*
   * Location to be modified.
   *
   * If `e_type` is `ET_REL` then this is a section data byte offset.
   *
   * If `e_type` isn't `ET_REL` then this is a virtual address.
   */
  Elf64_Addr r_offset;

  /*
   * Relocation type and symbol.
   *
   * This value may be created using:
   *
   *     r_info = ELF64_R_INFO(sym, type);
   *
   * This value may be read using:
   *
   *     Elf64_Word sym = ELF64_R_SYM(r_info);
   *     Elf64_Word type = ELF64_R_TYPE(r_info);
   *
   * Where `sym` is a symbol index, and `type` will likely be:
   *
   * - `R_X86_64_PC32`
   * - `R_X86_64_PLT32`
   * - `R_X86_64_32`
   * - `R_X86_64_64`
   * - `R_X86_64_32S`
   * - `R_X86_64_8`
   * - `R_X86_64_16`
   * - `R_X86_64_DTPOFF32`
   * - `R_X86_64_GOTPCREL`
   * - `R_X86_64_PC16`
   * - `R_X86_64_REX_GOTPCRELX`
   * - `R_X86_64_TPOFF32`
   *
   */
  Elf64_Xword r_info;

  /*
   * Relocation parameter.
   *
   * Each relocation type has its own mathematical formula, which should
   * incorporate this value in its own unique way.
   */
  Elf64_Sxword r_addend;

} Elf64_Rela;



/*!BEGIN libc/elf/struct/syminfo.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_SYMINFO_H_

typedef struct Elf64_Syminfo {
  Elf64_Half si_boundto;
  Elf64_Half si_flags;
} Elf64_Syminfo;



/*!BEGIN libc/elf/struct/verdaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDAUX_H_

typedef struct Elf64_Verdaux {
  Elf64_Word vda_name;
  Elf64_Word vda_next;
} Elf64_Verdaux;



/*!BEGIN libc/elf/struct/verdef.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERDEF_H_

typedef struct Elf64_Verdef {
  Elf64_Half vd_version;
  Elf64_Half vd_flags;
  Elf64_Half vd_ndx;
  Elf64_Half vd_cnt;
  Elf64_Word vd_hash;
  Elf64_Word vd_aux;
  Elf64_Word vd_next;
} Elf64_Verdef;



/*!BEGIN libc/elf/struct/vernaux.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNAUX_H_

typedef struct Elf64_Vernaux {
  Elf64_Word vna_hash;
  Elf64_Half vna_flags;
  Elf64_Half vna_other;
  Elf64_Word vna_name;
  Elf64_Word vna_next;
} Elf64_Vernaux;



/*!BEGIN libc/elf/struct/verneed.h */

#define COSMOPOLITAN_LIBC_ELF_STRUCT_VERNEED_H_

typedef struct Elf64_Verneed {
  Elf64_Half vn_version;
  Elf64_Half vn_cnt;
  Elf64_Word vn_file;
  Elf64_Word vn_aux;
  Elf64_Word vn_next;
} Elf64_Verneed;



/*!BEGIN libc/fmt/conv.h */

#define COSMOPOLITAN_LIBC_FMT_CONV_H_
COSMOPOLITAN_C_START_

int abs(int) libcesque pureconst;
long labs(long) libcesque pureconst;
long long llabs(long long) libcesque pureconst;
libcesque intmax_t imaxabs(intmax_t) pureconst;
int atoi(const char *) paramsnonnull() libcesque;
long atol(const char *) paramsnonnull() libcesque;
long long atoll(const char *) paramsnonnull() libcesque;
unsigned long strtoul(const char *, char **, int) libcesque paramsnonnull((1));
long long strtoll(const char *, char **, int) libcesque paramsnonnull((1));
unsigned long long strtoull(const char *, char **, int) paramsnonnull((1));
intmax_t strtoimax(const char *, char **, int) libcesque paramsnonnull((1));
uintmax_t strtoumax(const char *, char **, int) libcesque paramsnonnull((1));
intmax_t wcstoimax(const wchar_t *, wchar_t **, int) libcesque;
uintmax_t wcstoumax(const wchar_t *, wchar_t **, int) libcesque;
long wcstol(const wchar_t *, wchar_t **, int) libcesque;
unsigned long wcstoul(const wchar_t *, wchar_t **, int) libcesque;
long strtol(const char *, char **, int) paramsnonnull((1)) libcesque;
long sizetol(const char *, long) paramsnonnull() libcesque;
char *sizefmt(char *, uint64_t, uint64_t) libcesque;
long long wcstoll(const wchar_t *, wchar_t **, int) libcesque;
unsigned long long wcstoull(const wchar_t *, wchar_t **, int) libcesque;
int wcscoll(const wchar_t *, const wchar_t *) libcesque;
size_t wcsxfrm(wchar_t *, const wchar_t *, size_t) libcesque;

double atof(const char *) libcesque;
float strtof(const char *, char **) libcesque;
double strtod(const char *, char **) libcesque;
long double strtold(const char *, char **) libcesque;
float wcstof(const wchar_t *, wchar_t **) libcesque;
double wcstod(const wchar_t *, wchar_t **) libcesque;
long double wcstold(const wchar_t *, wchar_t **) libcesque;

#ifdef _COSMO_SOURCE
char *stripext(char *) libcesque;
char *stripexts(char *) libcesque;
#endif /* _COSMO_SOURCE */

typedef struct {
  int quot;
  int rem;
} div_t;

typedef struct {
  long int quot;
  long int rem;
} ldiv_t;

typedef struct {
  long long int quot;
  long long int rem;
} lldiv_t;

typedef struct {
  intmax_t quot;
  intmax_t rem;
} imaxdiv_t;

libcesque div_t div(int, int) pureconst;
libcesque ldiv_t ldiv(long, long) pureconst;
libcesque lldiv_t lldiv(long long, long long) pureconst;
libcesque imaxdiv_t imaxdiv(intmax_t, intmax_t) pureconst;

#if __STDC_VERSION__ + 0 >= 199901L
#define div(num, den)   ((div_t){(num) / (den), (num) % (den)})
#define ldiv(num, den)  ((ldiv_t){(num) / (den), (num) % (den)})
#define lldiv(num, den) ((lldiv_t){(num) / (den), (num) % (den)})
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/fmt/itoa.h */

#ifndef COSMOPOLITAN_LIBC_FMT_ITOA_H_
#define COSMOPOLITAN_LIBC_FMT_ITOA_H_
COSMOPOLITAN_C_START_

#define LengthInt64           __LengthInt64
#define LengthUint64          __LengthUint64
#define LengthInt64Thousands  __LengthInt64Thousands
#define LengthUint64Thousands __LengthUint64Thousands
#define FormatInt32           __FormatInt32
#define FormatUint32          __FormatUint32
#define FormatInt64           __FormatInt64
#define FormatUint64          __FormatUint64
#define FormatInt64Thousands  __FormatInt64Thousands
#define FormatUint64Thousands __FormatUint64Thousands
#define FormatOctal32         __FormatOctal32
#define FormatOctal64         __FormatOctal64
#define FormatBinary64        __FormatBinary64
#define FormatHex64           __FormatHex64
#define FormatFlex64          __FormatFlex64
#define uint64toarray_radix16 __uint64toarray_radix16
#define uint64toarray_fixed16 __uint64toarray_fixed16
#define uint64toarray_radix8  __uint64toarray_radix8

libcesque unsigned LengthInt64(int64_t) pureconst;
libcesque unsigned LengthUint64(uint64_t) pureconst;
libcesque unsigned LengthInt64Thousands(int64_t) pureconst;
libcesque unsigned LengthUint64Thousands(uint64_t) pureconst;
libcesque char *FormatInt32(char[hasatleast 12], int32_t);
libcesque char *FormatUint32(char[hasatleast 12], uint32_t);
libcesque char *FormatInt64(char[hasatleast 21], int64_t);
libcesque char *FormatUint64(char[hasatleast 21], uint64_t);
libcesque char *FormatInt64Thousands(char[hasatleast 27], int64_t);
libcesque char *FormatUint64Thousands(char[hasatleast 27], uint64_t);
libcesque char *FormatOctal32(char[hasatleast 13], uint32_t, bool32);
libcesque char *FormatOctal64(char[hasatleast 24], uint64_t, bool32);
libcesque char *FormatBinary64(char[hasatleast 67], uint64_t, char);
libcesque char *FormatHex64(char[hasatleast 19], uint64_t, char);
libcesque char *FormatFlex64(char[hasatleast 24], int64_t, char);
libcesque size_t uint64toarray_radix16(uint64_t, char[hasatleast 17]);
libcesque size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
libcesque size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_ITOA_H_ */


/*!BEGIN libc/fmt/leb128.h */

#ifndef COSMOPOLITAN_LIBC_FMT_LEB128_H_
#define COSMOPOLITAN_LIBC_FMT_LEB128_H_
COSMOPOLITAN_C_START_

#define sleb64   __sleb64
#define zleb64   __zleb64
#define uleb64   __uleb64
#define unzleb64 __unzleb64
#define unuleb64 __unuleb64

char *sleb64(char *, int64_t) libcesque;
char *zleb64(char[hasatleast 10], int64_t) libcesque;
char *uleb64(char[hasatleast 10], uint64_t) libcesque;
int unzleb64(const char *, size_t, int64_t *) libcesque;
int unuleb64(const char *, size_t, uint64_t *) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_FMT_LEB128_H_ */


/*!BEGIN libc/fmt/libgen.h */

#define COSMOPOLITAN_LIBC_FMT_LIBGEN_H_
COSMOPOLITAN_C_START_

char *dirname(char *) libcesque;
char *basename(char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/dlopen/dlfcn.h */

#define COSMOPOLITAN_LIBC_DLFCN_H_

#define RTLD_LOCAL  0
#define RTLD_LAZY   1
#define RTLD_NOW    2
#define RTLD_GLOBAL 256

COSMOPOLITAN_C_START_

#define RTLD_NEXT    ((void *)-1)
#define RTLD_DEFAULT ((void *)0)

char *dlerror(void) libcesque;
void *dlopen(const char *, int) libcesque;
void *dlsym(void *, const char *) libcesque;
int dlclose(void *) libcesque;

char *cosmo_dlerror(void) libcesque;
void *cosmo_dlopen(const char *, int) libcesque;
void *cosmo_dlsym(void *, const char *) libcesque;
void *cosmo_dltramp(void *) libcesque;
int cosmo_dlclose(void *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/asancodes.h */

#define COSMOPOLITAN_LIBC_INTRIN_ASANCODES_H_

#define kAsanScale           3
#define kAsanMagic           0x7fff8000
#define kAsanNullPage        -1  /* ∅ 0xff */
#define kAsanProtected       -2  /* P 0xfe */
#define kAsanHeapFree        -3  /* F 0xfd */
#define kAsanHeapRelocated   -4  /* R 0xfc */
#define kAsanAllocaOverrun   -5  /* 𝑂 0xfb */
#define kAsanHeapUnderrun    -6  /* U 0xfa */
#define kAsanHeapOverrun     -7  /* O 0xf9 */
#define kAsanStackUnscoped   -8  /* s 0xf8 */
#define kAsanStackOverflow   -9  /* ! 0xf7 */
#define kAsanGlobalOrder     -10 /* I 0xf6 */
#define kAsanStackFree       -11 /* r 0xf5 */
#define kAsanStackPartial    -12 /* p 0xf4 */
#define kAsanStackOverrun    -13 /* o 0xf3 */
#define kAsanStackMiddle     -14 /* m 0xf2 */
#define kAsanStackUnderrun   -15 /* u 0xf1 */
#define kAsanAllocaUnderrun  -16 /* 𝑈 0xf0 */
#define kAsanUnmapped        -17 /* M 0xef */
#define kAsanGlobalRedzone   -18 /* G 0xee */
#define kAsanGlobalGone      -19 /* 𝐺 0xed */
#define kAsanGlobalUnderrun  -20 /* μ 0xec */
#define kAsanGlobalOverrun   -21 /* Ω 0xeb */
#define kAsanMmapSizeOverrun -22 /* Z 0xea */



/*!BEGIN libc/intrin/asmflag.h */

#define COSMOPOLITAN_LIBC_BITS_ASMFLAG_H_

/*
 * Constraints for virtual machine flags.
 * @note we beseech clang devs for flag constraints
 */
#ifdef __GCC_ASM_FLAG_OUTPUTS__ /* GCC6+ CLANG10+ */
#define CFLAG_CONSTRAINT  "=@ccc"
#define CFLAG_ASM(OP)     OP
#define ZFLAG_CONSTRAINT  "=@ccz"
#define ZFLAG_ASM(OP)     OP
#define OFLAG_CONSTRAINT  "=@cco"
#define OFLAG_ASM(OP)     OP
#define SFLAG_CONSTRAINT  "=@ccs"
#define SFLAG_ASM(SP)     SP
#define ABOVE_CONSTRAINT  "=@cca" /* i.e. !ZF && !CF */
#define ABOVEFLAG_ASM(OP) OP
#else
#define CFLAG_CONSTRAINT  "=q"
#define CFLAG_ASM(OP)     OP "\n\tsetc\t%b0"
#define ZFLAG_CONSTRAINT  "=q"
#define ZFLAG_ASM(OP)     OP "\n\tsetz\t%b0"
#define OFLAG_CONSTRAINT  "=q"
#define OFLAG_ASM(OP)     OP "\n\tseto\t%b0"
#define SFLAG_CONSTRAINT  "=q"
#define SFLAG_ASM(SP)     OP "\n\tsets\t%b0"
#define ABOVE_CONSTRAINT  "=@cca"
#define ABOVEFLAG_ASM(OP) OP "\n\tseta\t%b0"
#endif



/*!BEGIN libc/intrin/atomic.h */

#define COSMOPOLITAN_LIBC_BITS_ATOMIC_H_

/**
 * @fileoverview Cosmopolitan C11 Atomics Library
 *
 * - Forty-two different ways to say MOV.
 * - Fourteen different ways to say XCHG.
 * - Twenty different ways to say LOCK CMPXCHG.
 *
 * @see libc/atomic.h
 */

typedef int memory_order;

enum {
  memory_order_relaxed,
  memory_order_consume,
  memory_order_acquire,
  memory_order_release,
  memory_order_acq_rel,
  memory_order_seq_cst,
};

#define ATOMIC_VAR_INIT(...)     __VA_ARGS__
#define atomic_is_lock_free(obj) ((void)(obj), sizeof(obj) <= sizeof(void *))

#define atomic_flag      atomic_bool
#define ATOMIC_FLAG_INIT ATOMIC_VAR_INIT(0)
#define atomic_flag_test_and_set_explicit(x, order) \
  atomic_exchange_explicit(x, 1, order)
#define atomic_flag_clear_explicit(x, order) atomic_store_explicit(x, 0, order)

#define atomic_compare_exchange_strong(pObject, pExpected, desired) \
  atomic_compare_exchange_strong_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_compare_exchange_weak(pObject, pExpected, desired) \
  atomic_compare_exchange_weak_explicit(                          \
      pObject, pExpected, desired, memory_order_seq_cst, memory_order_seq_cst)
#define atomic_exchange(pObject, desired) \
  atomic_exchange_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_fetch_add(pObject, operand) \
  atomic_fetch_add_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_and(pObject, operand) \
  atomic_fetch_and_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_or(pObject, operand) \
  atomic_fetch_or_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_sub(pObject, operand) \
  atomic_fetch_sub_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_fetch_xor(pObject, operand) \
  atomic_fetch_xor_explicit(pObject, operand, memory_order_seq_cst)
#define atomic_load(pObject) atomic_load_explicit(pObject, memory_order_seq_cst)
#define atomic_store(pObject, desired) \
  atomic_store_explicit(pObject, desired, memory_order_seq_cst)
#define atomic_flag_test_and_set(x) \
  atomic_flag_test_and_set_explicit(x, memory_order_seq_cst)
#define atomic_flag_clear(x) atomic_flag_clear_explicit(x, memory_order_seq_cst)

#if defined(__CLANG_ATOMIC_BOOL_LOCK_FREE)

#define atomic_init(obj, value)    __c11_atomic_init(obj, value)
#define atomic_thread_fence(order) __c11_atomic_thread_fence(order)
#define atomic_signal_fence(order) __c11_atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(object, expected, desired, \
                                                success, failure)          \
  __c11_atomic_compare_exchange_strong(object, expected, desired, success, \
                                       failure)
#define atomic_compare_exchange_weak_explicit(object, expected, desired, \
                                              success, failure)          \
  __c11_atomic_compare_exchange_weak(object, expected, desired, success, \
                                     failure)
#define atomic_exchange_explicit(object, desired, order) \
  __c11_atomic_exchange(object, desired, order)
#define atomic_fetch_add_explicit(object, operand, order) \
  __c11_atomic_fetch_add(object, operand, order)
#define atomic_fetch_and_explicit(object, operand, order) \
  __c11_atomic_fetch_and(object, operand, order)
#define atomic_fetch_or_explicit(object, operand, order) \
  __c11_atomic_fetch_or(object, operand, order)
#define atomic_fetch_sub_explicit(object, operand, order) \
  __c11_atomic_fetch_sub(object, operand, order)
#define atomic_fetch_xor_explicit(object, operand, order) \
  __c11_atomic_fetch_xor(object, operand, order)
#define atomic_load_explicit(object, order) __c11_atomic_load(object, order)
#define atomic_store_explicit(object, desired, order) \
  __c11_atomic_store(object, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 407

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __atomic_thread_fence(order)
#define atomic_signal_fence(order) __atomic_signal_fence(order)
#define atomic_compare_exchange_strong_explicit(pObject, pExpected, desired, \
                                                success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 0, success, failure)
#define atomic_compare_exchange_weak_explicit(pObject, pExpected, desired, \
                                              success, failure)            \
  __atomic_compare_exchange_n(pObject, pExpected, desired, 1, success, failure)
#define atomic_exchange_explicit(pObject, desired, order) \
  __atomic_exchange_n(pObject, desired, order)
#define atomic_fetch_add_explicit(pObject, operand, order) \
  __atomic_fetch_add(pObject, operand, order)
#define atomic_fetch_and_explicit(pObject, operand, order) \
  __atomic_fetch_and(pObject, operand, order)
#define atomic_fetch_or_explicit(pObject, operand, order) \
  __atomic_fetch_or(pObject, operand, order)
#define atomic_fetch_sub_explicit(pObject, operand, order) \
  __atomic_fetch_sub(pObject, operand, order)
#define atomic_fetch_xor_explicit(pObject, operand, order) \
  __atomic_fetch_xor(pObject, operand, order)
#define atomic_load_explicit(pObject, order) __atomic_load_n(pObject, order)
#define atomic_store_explicit(pObject, desired, order) \
  __atomic_store_n(pObject, desired, order)

#elif (__GNUC__ + 0) * 100 + (__GNUC_MINOR__ + 0) >= 401

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __sync_synchronize()
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define __atomic_apply_stride(object, operand) \
  (((__typeof__(*(object)))0) + (operand))
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    __typeof__(expected) __ep = (expected);                                   \
    __typeof__(*__ep) __e = *__ep;                                            \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    (*__ep = __sync_val_compare_and_swap(object, __e, desired)) == __e;       \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#if __has_builtin(__sync_swap)
#define atomic_exchange_explicit(object, desired, order) \
  ((void)(order), __sync_swap(object, desired))
#else
#define atomic_exchange_explicit(object, desired, order) \
  __extension__({                                        \
    __typeof__(object) __o = (object);                   \
    __typeof__(desired) __d = (desired);                 \
    (void)(order);                                       \
    __sync_synchronize();                                \
    __sync_lock_test_and_set(__o, __d);                  \
  })
#endif
#define atomic_fetch_add_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_add(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_and_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_and(object, operand))
#define atomic_fetch_or_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_or(object, operand))
#define atomic_fetch_sub_explicit(object, operand, order) \
  ((void)(order),                                         \
   __sync_fetch_and_sub(object, __atomic_apply_stride(object, operand)))
#define atomic_fetch_xor_explicit(object, operand, order) \
  ((void)(order), __sync_fetch_and_xor(object, operand))
#define atomic_load_explicit(object, order) \
  ((void)(order), __sync_fetch_and_add(object, 0))
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#elif defined(__GNUC__) && defined(__x86__) /* x86 with gcc 4.0 and earlier */

#define atomic_init(obj, value)    ((void)(*(obj) = (value)))
#define atomic_thread_fence(order) __asm__ volatile("mfence" ::: "memory")
#define atomic_signal_fence(order) __asm__ volatile("" ::: "memory")
#define atomic_compare_exchange_strong_explicit(object, expected, desired,    \
                                                success_order, failure_order) \
  __extension__({                                                             \
    char DidIt;                                                               \
    __typeof__(object) IfThing = (object);                                    \
    __typeof__(IfThing) IsEqualToMe = (expected);                             \
    __typeof__(*IfThing) ReplaceItWithMe = (desired), ax;                     \
    (void)(success_order);                                                    \
    (void)(failure_order);                                                    \
    __asm__ volatile("lock cmpxchg\t%3,(%1)\n\t"                              \
                     "setz\t%b0"                                              \
                     : "=q"(DidIt), "=r"(IfThing), "+a"(ax)                   \
                     : "r"(ReplaceItWithMe), "2"(*IsEqualToMe)                \
                     : "memory", "cc");                                       \
    *IsEqualToMe = ax;                                                        \
    DidIt;                                                                    \
  })
#define atomic_compare_exchange_weak_explicit(object, expected, desired,    \
                                              success_order, failure_order) \
  atomic_compare_exchange_strong_explicit(object, expected, desired,        \
                                          success_order, failure_order)
#define atomic_exchange_explicit(object, desired, order)                \
  __extension__({                                                       \
    __typeof__(object) __o = (object);                                  \
    __typeof__(*__o) __d = (desired);                                   \
    (void)(order);                                                      \
    __asm__ volatile("xchg\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                \
  })
#define atomic_fetch_add_explicit(object, operand, order)                    \
  __extension__({                                                            \
    __typeof__(object) __o = (object);                                       \
    __typeof__(*__o) __d = (desired);                                        \
    (void)(order);                                                           \
    __asm__ volatile("lock xadd\t%0,%1" : "=r"(__d), "+m"(*__o) : "0"(__d)); \
    __d;                                                                     \
  })
#define atomic_fetch_sub_explicit(object, operand, order) \
  atomic_fetch_add_explicit(object, -(operand), order)
#define atomic_load_explicit(object, order) \
  atomic_fetch_add_explicit(object, 0, order)
#define atomic_store_explicit(object, desired, order) \
  ((void)atomic_exchange_explicit(object, desired, order))

#else /* non-gcc or old gcc w/o x86 */
#error "atomic operations not supported with this compiler and/or architecture"
#endif



/*!BEGIN libc/intrin/bsf.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
COSMOPOLITAN_C_START_

libcesque int bsf(int) pureconst;
libcesque int bsfl(long) pureconst;
libcesque int bsfll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsf(x)   __builtin_ctz(x)
#define bsfl(x)  __builtin_ctzl(x)
#define bsfll(x) __builtin_ctzll(x)
#endif

/* deprecated */
#define _bsf(x)   bsf(x)
#define _bsfl(x)  bsfl(x)
#define _bsfll(x) bsfll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */


/*!BEGIN libc/intrin/bsr.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
COSMOPOLITAN_C_START_

libcesque int bsr(int) pureconst;
libcesque int bsrl(long) pureconst;
libcesque int bsrll(long long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bsr(x)   (__builtin_clz(x) ^ (sizeof(int) * 8 - 1))
#define bsrl(x)  (__builtin_clzl(x) ^ (sizeof(long) * 8 - 1))
#define bsrll(x) (__builtin_clzll(x) ^ (sizeof(long long) * 8 - 1))
#endif

/* deprecated */
#define _bsr(x)   bsr(x)
#define _bsrl(x)  bsrl(x)
#define _bsrll(x) bsrll(x)

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */


/*!BEGIN libc/intrin/bswap.h */

#define COSMOPOLITAN_LIBC_BITS_BSWAP_H_
COSMOPOLITAN_C_START_

libcesque uint16_t bswap_16(uint16_t) pureconst;
libcesque uint32_t bswap_32(uint32_t) pureconst;
libcesque uint64_t bswap_64(uint64_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define bswap_16(x) __builtin_bswap16(x)
#define bswap_32(x) __builtin_bswap32(x)
#define bswap_64(x) __builtin_bswap64(x)
#endif /* defined(__GNUC__) && !defined(__STRICT_ANSI__) */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/cmpxchg.h */

#define COSMOPOLITAN_LIBC_INTRIN_CMPXCHG_H_
COSMOPOLITAN_C_START_

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86__)
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME)                       \
  ({                                                                          \
    bool32 DidIt;                                                             \
    autotype(IFTHING) IfThing = (IFTHING);                                    \
    typeof(*IfThing) IsEqualToMe = (ISEQUALTOME);                             \
    typeof(*IfThing) ReplaceItWithMe = (REPLACEITWITHME);                     \
    asm volatile(ZFLAG_ASM("cmpxchg\t%3,%1")                                  \
                 : ZFLAG_CONSTRAINT(DidIt), "+m"(*IfThing), "+a"(IsEqualToMe) \
                 : "r"(ReplaceItWithMe)                                       \
                 : "cc");                                                     \
    DidIt;                                                                    \
  })
#else
#define _cmpxchg(IFTHING, ISEQUALTOME, REPLACEITWITHME) \
  (*(IFTHING) == (ISEQUALTOME) ? (*(IFTHING) = (REPLACEITWITHME), 1) : 0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/dll.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_
#define dll_make_first   __dll_make_first
#define dll_make_last    __dll_make_last
#define dll_remove       __dll_remove
#define dll_splice_after __dll_splice_after
COSMOPOLITAN_C_START_

#define DLL_CONTAINER(t, f, p) ((t *)(((char *)(p)) - offsetof(t, f)))

struct Dll {
  struct Dll *next;
  struct Dll *prev;
};

static inline void dll_init(struct Dll *e) {
  e->next = e;
  e->prev = e;
}

static inline int dll_is_alone(struct Dll *e) {
  return e->next == e && e->prev == e;
}

static inline int dll_is_empty(struct Dll *list) {
  return !list;
}

static inline struct Dll *dll_last(struct Dll *list) {
  return list;
}

static inline struct Dll *dll_first(struct Dll *list) {
  struct Dll *first = 0;
  if (list) first = list->next;
  return first;
}

static inline struct Dll *dll_next(struct Dll *list, struct Dll *e) {
  struct Dll *next = 0;
  if (e != list) next = e->next;
  return next;
}

static inline struct Dll *dll_prev(struct Dll *list, struct Dll *e) {
  struct Dll *prev = 0;
  if (e != list->next) prev = e->prev;
  return prev;
}

void dll_remove(struct Dll **, struct Dll *) paramsnonnull() libcesque;
void dll_make_last(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_make_first(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque;
void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */


/*!BEGIN libc/intrin/hilbert.h */

#define COSMOPOLITAN_LIBC_BITS_HILBERT_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_
#define hilbert   __hilbert
#define unhilbert __unhilbert

libcesque long hilbert(long, long, long) pureconst;
libcesque axdx_t unhilbert(long, long) pureconst;

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/kprintf.h */

#ifndef COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_
#define COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_

#define klog         __klog
#define kprintf      __kprintf
#define ksnprintf    __ksnprintf
#define kvprintf     __kvprintf
#define kvsnprintf   __kvsnprintf
#define kloghandle   __kloghandle
#define kisdangerous __kisdangerous
#define uprintf      __uprintf
#define uvprintf     __uvprintf

#if !(__ASSEMBLER__ + __LINKER__ + 0)

COSMOPOLITAN_C_START_

void kprintf(const char *, ...) libcesque;
size_t ksnprintf(char *, size_t, const char *, ...) libcesque;
void kvprintf(const char *, va_list) libcesque;
size_t kvsnprintf(char *, size_t, const char *, va_list) libcesque;

bool32 kisdangerous(const void *) libcesque;

void klog(const char *, size_t) libcesque;
void _klog_serial(const char *, size_t) libcesque;
long kloghandle(void) libcesque;

void uprintf(const char *, ...) libcesque;
void uvprintf(const char *, va_list) libcesque;

#ifndef TINY
#define KINFOF(FMT, ...)                                         \
  do {                                                           \
    uprintf("\r\e[35m%s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                      \
  } while (0)
#define KWARNF(FMT, ...)                                                  \
  do {                                                                    \
    uprintf("\r\e[94;49mwarn: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                               \
  } while (0)
#else
#define KINFOF(FMT, ...) ((void)0)
#define KWARNF(FMT, ...) ((void)0)
#endif
#define KDIEF(FMT, ...)                                                     \
  do {                                                                      \
    kprintf("\r\e[30;101mfatal: %s:%d: " FMT "\e[0m\n", __FILE__, __LINE__, \
            ##__VA_ARGS__);                                                 \
    for (;;) asm volatile("cli\n\thlt");                                    \
  } while (0)

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* COSMOPOLITAN_LIBC_INTRIN_KPRINTF_H_ */


/*!BEGIN libc/intrin/likely.h */

#define COSMOPOLITAN_LIBC_BITS_LIKELY_H_
#ifdef _COSMO_SOURCE

#define LIKELY(x)   __builtin_expect(!!(x), 1)
#define UNLIKELY(x) __builtin_expect(!!(x), 0)

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_LIKELY(x) __builtin_expect_with_probability(!!(x), 1, 0.999)
#else
#define VERY_LIKELY(x) LIKELY(x)
#endif

#if __GNUC__ + 0 >= 9 && !defined(__chibicc__)
#define VERY_UNLIKELY(x) __builtin_expect_with_probability(!!(x), 0, 0.999)
#else
#define VERY_UNLIKELY(x) UNLIKELY(x)
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/macros.h */

#define COSMOPOLITAN_LIBC_INTRIN_MACROS_H_


/*!BEGIN libc/nexgen32e/x86feature.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86FEATURE_H_
#ifdef __x86_64__


/*!BEGIN libc/nexgen32e/kcpuids.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_KCPUIDS_H_

#define KCPUIDS_0H        0
#define KCPUIDS_1H        1
#define KCPUIDS_2H        2
#define KCPUIDS_7H        3
#define KCPUIDS_80000001H 4
#define KCPUIDS_80000007H 5
#define KCPUIDS_16H       6
#define KCPUIDS_7H_1H     7
#define KCPUIDS_LEN       8
#define KCPUIDS_6H        -1 /* TBD: Thermal and Power Management */
#define KCPUIDS_DH        -1 /* TBD: Extended state features */
#define KCPUIDS_80000008H -1 /* TBD: AMD Miscellaneous */
#define KCPUIDS_8000000AH -1 /* TBD: AMD SVM */

#define KCPUIDS_EAX 0
#define KCPUIDS_EBX 1
#define KCPUIDS_ECX 2
#define KCPUIDS_EDX 3

#define KCPUIDS(LEAF, REG) _KCPUIDS(LEAF, REG)
#ifdef __ASSEMBLER__
#define _KCPUIDS(LEAF, REG) KCPUIDS_##LEAF * 16 + KCPUIDS_##REG * 4
#else
#define _KCPUIDS(LEAF, REG) kCpuids[KCPUIDS_##LEAF][KCPUIDS_##REG]
#endif

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const unsigned kCpuids[KCPUIDS_LEN][4];

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nexgen32e/x86compiler.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86COMPILER_H_
#ifdef __x86_64__

/**
 * @fileoverview x86 cpu feature compile-time requirement detection.
 * @see -march=native, -mavx2, etc.
 */

#ifdef __AES__
#define _X86_CC_AES 1
#else
#define _X86_CC_AES 0
#endif

#ifdef __AVX__
#define _X86_CC_AVX 1
#else
#define _X86_CC_AVX 0
#endif

#ifdef __AVX2__
#define _X86_CC_AVX2 1
#else
#define _X86_CC_AVX2 0
#endif

#ifdef __F16C__
#define _X86_CC_F16C 1
#else
#define _X86_CC_F16C 0
#endif

#ifdef __AVXVNNI__
#define _X86_CC_AVXVNNI 1
#else
#define _X86_CC_AVXVNNI 0
#endif

#ifdef __AVXVNNIINT8__
#define _X86_CC_AVXVNNIINT8 1
#else
#define _X86_CC_AVXVNNIINT8 0
#endif

#ifdef __AVXVNNIINT16__
#define _X86_CC_AVXVNNIINT16 1
#else
#define _X86_CC_AVXVNNIINT16 0
#endif

#ifdef __AVX512F__
#define _X86_CC_AVX512F 1
#else
#define _X86_CC_AVX512F 0
#endif

#ifdef __AVX512BF16__
#define _X86_CC_AVX512BF16 1
#else
#define _X86_CC_AVX512BF16 0
#endif

#ifdef __AVX512FP16__
#define _X86_CC_AVX512FP16 1
#else
#define _X86_CC_AVX512FP16 0
#endif

#ifdef __AVX512VBMI__
#define _X86_CC_AVX512VBMI 1
#else
#define _X86_CC_AVX512VBMI 0
#endif

#ifdef __AVX512VNNI__
#define _X86_CC_AVX512VNNI 1
#else
#define _X86_CC_AVX512VNNI 0
#endif

#ifdef __AVX5124VNNIW__
#define _X86_CC_AVX5124VNNIW 1
#else
#define _X86_CC_AVX5124VNNIW 0
#endif

#ifdef __ABM__
#define _X86_CC_ABM 1
#else
#define _X86_CC_ABM 0
#endif

#ifdef __BMI__
#define _X86_CC_BMI 1
#else
#define _X86_CC_BMI 0
#endif

#ifdef __BMI2__
#define _X86_CC_BMI2 1
#else
#define _X86_CC_BMI2 0
#endif

#ifdef __FMA__
#define _X86_CC_FMA 1
#else
#define _X86_CC_FMA 0
#endif

#ifdef __ADX__
#define _X86_CC_ADX 1
#else
#define _X86_CC_ADX 0
#endif

#ifdef __PCLMUL__
#define _X86_CC_PCLMUL 1
#else
#define _X86_CC_PCLMUL 0
#endif

#ifdef __POPCNT__
#define _X86_CC_POPCNT 1
#else
#define _X86_CC_POPCNT 0
#endif

#ifdef __RDRND__
#define _X86_CC_RDRND 1
#else
#define _X86_CC_RDRND 0
#endif

#ifdef __RDSEED__
#define _X86_CC_RDSEED 1
#else
#define _X86_CC_RDSEED 0
#endif

#ifdef __SHA__
#define _X86_CC_SHA 1
#else
#define _X86_CC_SHA 0
#endif

#ifdef __SSSE3__
#define _X86_CC_SSSE3 1
#else
#define _X86_CC_SSSE3 0
#endif

#ifdef __SSE__
#define _X86_CC_SSE 1
#else
#define _X86_CC_SSE 0
#endif

#ifdef __SSE2__
#define _X86_CC_SSE2 1
#else
#define _X86_CC_SSE2 0
#endif

#ifdef __SSE3__
#define _X86_CC_SSE3 1
#else
#define _X86_CC_SSE3 0
#endif

#ifdef __SSE4_1__
#define _X86_CC_SSE4_1 1
#else
#define _X86_CC_SSE4_1 0
#endif

#ifdef __SSE4_2__
#define _X86_CC_SSE4_2 1
#else
#define _X86_CC_SSE4_2 0
#endif

#ifdef __XSAVE__
#define _X86_CC_XSAVE 1
#else
#define _X86_CC_XSAVE 0
#endif

#ifdef __CLFLUSHOPT__
#define _X86_CC_CLFLUSHOPT 1
#else
#define _X86_CC_CLFLUSHOPT 0
#endif

#ifdef __RDPID__
#define _X86_CC_RDPID 1
#else
#define _X86_CC_RDPID 0
#endif

#endif /* __x86_64__ */

/* Returns true if x86 FEATURE is present.
   This performs a runtime check in normal portable builds.
   It's usually dead code eliminated for -march=native builds. */
#define X86_HAVE(FEATURE) _X86_HAVE(X86_##FEATURE)

/* Returns true if x86 FEATURE is present.
   This will *always* perform a runtime check.
   It's useful for checking compile-time cpu features are present. */
#define X86_CHECK(FEATURE) _X86_CHECK(X86_##FEATURE)

/* Returns true if x86 FEATURE is mandatory at build time.
   This will never perform runtime checks; it's always constant. */
#define X86_NEED(FEATURE) _X86_NEED(X86_##FEATURE)

/* clang-format off */
/*      --- FEATURE              LEAF       REG BIT  COMPILE-TIME-DEFINE */
#define X86_ACC                  1H,        EDX, 29, 0
#define X86_ACPI                 1H,        EDX, 22, 0
#define X86_ADX                  7H,        EBX, 19, _X86_CC_ADX              /* broadwell c. 2014 */
#define X86_AES                  1H,        ECX, 25, _X86_CC_AES              /* westmere c. 2010 */
#define X86_APIC                 1H,        EDX,  9, 0
#define X86_ARCH_CAPABILITIES    7H,        EDX, 29, 0
#define X86_AVX                  1H,        ECX, 28, _X86_CC_AVX              /* sandybridge c. 2012 */
#define X86_AVX2                 7H,        EBX,  5, _X86_CC_AVX2             /* haswell c. 2013 */
#define X86_AVXVNNI              7H_1H,     EAX,  4, _X86_CC_AVXVNNI
#define X86_AVXVNNIINT8          7H_1H,     EDX,  4, _X86_CC_AVXVNNIINT8
#define X86_AVXVNNIINT16         7H_1H,     EDX, 10, _X86_CC_AVXVNNIINT16
#define X86_AVX512BW             7H,        EBX, 30, 0
#define X86_AVX512CD             7H,        EBX, 28, 0
#define X86_AVX512DQ             7H,        EBX, 17, 0
#define X86_AVX512ER             7H,        EBX, 27, 0
#define X86_AVX512F              7H,        EBX, 16, _X86_CC_AVX512F
#define X86_AVX512IFMA           7H,        EBX, 21, 0
#define X86_AVX512PF             7H,        EBX, 26, 0
#define X86_AVX512VBMI           7H,        ECX,  1, _X86_CC_AVX512VBMI
#define X86_AVX512VL             7H,        EBX, 31, 0
#define X86_AVX512_4FMAPS        7H,        EDX,  3, 0
#define X86_AVX512_4VNNIW        7H,        EDX,  2, _X86_CC_AVX5124VNNIW
#define X86_AVX512_FP16          7H,        EDX, 23, _X86_CC_AVX512FP16
#define X86_AVX512_BF16          7H_1H,     EAX,  5, _X86_CC_AVX512BF16
#define X86_AVX512_BITALG        7H,        ECX, 12, 0
#define X86_AVX512_VBMI2         7H,        ECX,  6, 0
#define X86_AVX512_VNNI          7H,        ECX, 11, _X86_CC_AVX512VNNI
#define X86_AVX512_VP2INTERSECT  7H,        EDX,  8, 0
#define X86_AVX512_VPOPCNTDQ     7H,        ECX, 14, 0
#define X86_BMI                  7H,        EBX,  3, _X86_CC_BMI              /* haswell c. 2013 */
#define X86_BMI2                 7H,        EBX,  8, _X86_CC_BMI2             /* haswell c. 2013 */
#define X86_CID                  1H,        ECX, 10, 0
#define X86_CLDEMOTE             7H,        ECX, 25, 0
#define X86_CLFLUSH              1H,        EDX, 19, _X86_CC_SSE2
#define X86_CLFLUSHOPT           7H,        EBX, 23, _X86_CC_CLFLUSHOPT       /* skylake/zen  */
#define X86_CLWB                 7H,        EBX, 24, 0                        /* skylake/zen2 */
#define X86_CMOV                 1H,        EDX, 15, 0
#define X86_CQM                  7H,        EBX, 12, 0
#define X86_CX16                 1H,        ECX, 13, 0
#define X86_CX8                  1H,        EDX,  8, 0
#define X86_DCA                  1H,        ECX, 18, 0
#define X86_DE                   1H,        EDX,  2, 0
#define X86_DS                   1H,        EDX, 21, 0
#define X86_DSCPL                1H,        ECX,  4, 0
#define X86_DTES64               1H,        ECX,  2, 0
#define X86_ERMS                 7H,        EBX,  9, 0                        /* broaadwell c. 2014 */
#define X86_EST                  1H,        ECX,  7, 0
#define X86_F16C                 1H,        ECX, 29, _X86_CC_F16C
#define X86_FDP_EXCPTN_ONLY      7H,        EBX,  6, 0
#define X86_FLUSH_L1D            7H,        EDX, 28, 0
#define X86_FMA                  1H,        ECX, 12, _X86_CC_FMA              /* haswell c. 2013 */
#define X86_FPU                  1H,        EDX,  0, 0
#define X86_FSGSBASE             7H,        EBX,  0, 0
#define X86_FXSR                 1H,        EDX, 24, 0
#define X86_GBPAGES              80000001H, EDX, 26, 0
#define X86_GFNI                 7H,        ECX,  8, 0
#define X86_HLE                  7H,        EBX,  4, 0
#define X86_HT                   1H,        EDX, 28, 0
#define X86_HYPERVISOR           1H,        ECX, 31, 0
#define X86_IA64                 1H,        EDX, 30, 0
#define X86_INTEL_PT             7H,        EBX, 25, 0
#define X86_INTEL_STIBP          7H,        EDX, 27, 0
#define X86_INVPCID              1H,        EBX, 10, 0
#define X86_INVTSC               80000007H, EDX,  8, _X86_CC_POPCNT           /* i.e. not a K8 */
#define X86_LA57                 7H,        ECX, 16, 0
#define X86_LAHF_LM              80000001H, ECX,  0, 0
#define X86_LM                   80000001H, EDX, 29, 0
#define X86_MCA                  1H,        EDX, 14, 0
#define X86_MCE                  1H,        EDX,  7, 0
#define X86_MD_CLEAR             7H,        EDX, 10, 0
#define X86_MMX                  1H,        EDX, 23, 0
#define X86_MOVBE                1H,        ECX, 22, 0
#define X86_MOVDIR64B            7H,        ECX, 28, 0
#define X86_MOVDIRI              7H,        ECX, 27, 0
#define X86_MP                   80000001H, EDX, 19, 0
#define X86_MPX                  7H,        EBX, 14, 0
#define X86_MSR                  1H,        EDX,  5, 0
#define X86_MTRR                 1H,        EDX, 12, 0
#define X86_MWAIT                1H,        ECX,  3, 0
#define X86_NX                   80000001H, EDX, 20, 0
#define X86_OSPKE                7H,        ECX,  4, 0
#define X86_OSXSAVE              1H,        ECX, 27, 0
#define X86_PAE                  1H,        EDX,  6, 0
#define X86_PAT                  1H,        EDX, 16, 0
#define X86_PBE                  1H,        EDX, 31, 0
#define X86_PCID                 1H,        ECX, 17, 0
#define X86_PCLMUL               1H,        ECX,  1, _X86_CC_PCLMUL           /* westmere c. 2010 */
#define X86_PCONFIG              7H,        EDX, 18, 0
#define X86_PDCM                 1H,        ECX, 15, 0
#define X86_PGE                  1H,        EDX, 13, 0
#define X86_PKU                  7H,        ECX,  3, 0
#define X86_PN                   1H,        EDX, 18, 0
#define X86_POPCNT               1H,        ECX, 23, _X86_CC_POPCNT           /* nehalem c. 2008 */
#define X86_PSE                  1H,        EDX,  3, 0
#define X86_PSE36                1H,        EDX, 17, 0
#define X86_RDPID                7H,        ECX, 22, _X86_CC_RDPID            /* cannonlake c. 2018 */
#define X86_RDRND                1H,        ECX, 30, _X86_CC_RDRND            /* ivybridge c. 2012 */
#define X86_RDSEED               7H,        EBX, 18, _X86_CC_RDSEED           /* broadwell c. 2014 */
#define X86_RDTSCP               80000001H, EDX, 27, 0
#define X86_RDT_A                7H,        EBX, 15, 0
#define X86_RTM                  7H,        EBX, 11, 0
#define X86_SDBG                 1H,        ECX, 11, 0
#define X86_SELFSNOOP            1H,        EDX, 27, 0
#define X86_SEP                  1H,        EDX, 11, 0
#define X86_SHA                  7H,        EBX, 29, _X86_CC_SHA              /* goldmont (2016) */
#define X86_SMAP                 7H,        EBX, 20, 0
#define X86_SMEP                 7H,        EBX,  7, 0
#define X86_SMX                  1H,        ECX,  6, 0
#define X86_SPEC_CTRL            7H,        EDX, 26, 0
#define X86_SPEC_CTRL_SSBD       7H,        EDX, 31, 0
#define X86_SSE                  1H,        EDX, 25, _X86_CC_SSE              /* pentium c. 1999 */
#define X86_SSE2                 1H,        EDX, 26, _X86_CC_SSE2             /* pentium c. 2001 */
#define X86_SSE3                 1H,        ECX,  0, _X86_CC_SSE3             /* k8 c. 2005 */
#define X86_SSE4_1               1H,        ECX, 19, _X86_CC_SSE4_1           /* core c. 2006 */
#define X86_SSE4_2               1H,        ECX, 20, _X86_CC_SSE4_2           /* nehalem c. 2008 */
#define X86_SSSE3                1H,        ECX,  9, _X86_CC_SSSE3            /* westmere c. 2010 */
#define X86_SYSCALL              80000001H, EDX, 11, 0
#define X86_TM2                  1H,        ECX,  8, 0
#define X86_TME                  7H,        ECX, 13, 0
#define X86_TSC                  1H,        EDX,  4, 0
#define X86_TSC_ADJUST           7H,        EBX,  1, 0
#define X86_TSC_DEADLINE_TIMER   1H,        ECX, 24, 0
#define X86_TSX_FORCE_ABORT      7H,        EDX, 13, 0
#define X86_UMIP                 7H,        ECX,  2, 0
#define X86_VAES                 7H,        ECX,  9, 0
#define X86_VME                  1H,        EDX,  1, 0
#define X86_VMX                  1H,        ECX,  5, 0
#define X86_VPCLMULQDQ           7H,        ECX, 10, 0
#define X86_WAITPKG              7H,        ECX,  5, 0
#define X86_X2APIC               1H,        ECX, 21, 0
#define X86_XSAVE                1H,        ECX, 26, _X86_CC_XSAVE            /* sandybridge c. 2012 */
#define X86_XTPR                 1H,        ECX, 14, 0
#define X86_ZERO_FCS_FDS         7H,        EBX, 13, 0
#define X86_JIT                  80000001H, ECX, 31, 0                        /* IsGenuineBlink() */
#define X86_HYBRID_CPU           7H,        EDX, 15, 0                        /* Has performance and efficiency cores */
/* clang-format on */

/* AMD specific features */
#define X86_ABM            80000001H, ECX, 5, _X86_CC_ABM
#define X86_3DNOW          80000001H, EDX, 31, 0
#define X86_3DNOWEXT       80000001H, EDX, 30, 0
#define X86_3DNOWPREFETCH  80000001H, ECX, 8, 0
#define X86_BPEXT          80000001H, ECX, 26, 0
#define X86_CMP_LEGACY     80000001H, ECX, 1, 0
#define X86_CR8_LEGACY     80000001H, ECX, 4, 0
#define X86_EXTAPIC        80000001H, ECX, 3, 0
#define X86_FMA4           80000001H, ECX, 16, 0
#define X86_FXSR_OPT       80000001H, EDX, 25, 0
#define X86_IBS            80000001H, ECX, 10, 0
#define X86_LWP            80000001H, ECX, 15, 0
#define X86_MISALIGNSSE    80000001H, ECX, 7, 0
#define X86_MMXEXT         80000001H, EDX, 22, 0
#define X86_MWAITX         80000001H, ECX, 29, 0
#define X86_NODEID_MSR     80000001H, ECX, 19, 0
#define X86_OSVW           80000001H, ECX, 9, 0
#define X86_OVERFLOW_RECOV 80000007H, EBX, 0, 0
#define X86_PERFCTR_CORE   80000001H, ECX, 23, 0
#define X86_PERFCTR_LLC    80000001H, ECX, 28, 0
#define X86_PERFCTR_NB     80000001H, ECX, 24, 0
#define X86_PTSC           80000001H, ECX, 27, 0
#define X86_SKINIT         80000001H, ECX, 12, 0
#define X86_SMCA           80000007H, EBX, 3, 0
#define X86_SSE4A          80000001H, ECX, 6, 0
#define X86_SUCCOR         80000007H, EBX, 1, 0
#define X86_SVM            80000001H, ECX, 2, 0
#define X86_TBM            80000001H, ECX, 21, 0
#define X86_TCE            80000001H, ECX, 17, 0
#define X86_TOPOEXT        80000001H, ECX, 22, 0
#define X86_WDT            80000001H, ECX, 13, 0
#define X86_XOP            80000001H, ECX, 11, 0

/* Defined but not loaded by kCpuids.S */
#define X86_ARAT            6H, EAX, 2, 0
#define X86_AVIC            8000000AH, EDX, 13, 0
#define X86_CLZERO          80000008H, EBX, 0, 0
#define X86_DECODEASSISTS   8000000AH, EDX, 7, 0
#define X86_DTHERM          6H, EAX, 0, 0
#define X86_FLUSHBYASID     8000000AH, EDX, 6, 0
#define X86_HWP             6H, EAX, 7, 0
#define X86_HWP_ACT_WINDOW  6H, EAX, 9, 0
#define X86_HWP_EPP         6H, EAX, 10, 0
#define X86_HWP_NOTIFY      6H, EAX, 8, 0
#define X86_HWP_PKG_REQ     6H, EAX, 11, 0
#define X86_IBPB            80000008H, EBX, 12, 0
#define X86_IBRS            80000008H, EBX, 14, 0
#define X86_IDA             6H, EAX, 1, 0
#define X86_IRPERF          80000008H, EBX, 1, 0
#define X86_LBRV            8000000AH, EDX, 1, 0
#define X86_NPT             8000000AH, EDX, 0, 0
#define X86_NRIPS           8000000AH, EDX, 3, 0
#define X86_PAUSEFILTER     8000000AH, EDX, 10, 0
#define X86_PFTHRESHOLD     8000000AH, EDX, 12, 0
#define X86_PLN             6H, EAX, 4, 0
#define X86_PTS             6H, EAX, 6, 0
#define X86_SSBD            80000008H, EBX, 24, 0
#define X86_SSB_NO          80000008H, EBX, 26, 0
#define X86_STIBP           80000008H, EBX, 15, 0
#define X86_STIBP_ALWAYS_ON 80000008H, EBX, 17, 0
#define X86_SVML            8000000AH, EDX, 2, 0
#define X86_TSCRATEMSR      8000000AH, EDX, 4, 0
#define X86_VGIF            8000000AH, EDX, 16, 0
#define X86_VIRT_SSBD       80000008H, EBX, 25, 0
#define X86_VMCBCLEAN       8000000AH, EDX, 5, 0
#define X86_V_VMSAVE_VMLOAD 8000000AH, EDX, 15, 0
#define X86_WBNOINVD        80000008H, EBX, 9, 0
#define X86_XGETBV1         DH, EAX, 2, 0
#define X86_XSAVEC          DH, EAX, 1, 0
#define X86_XSAVEERPTR      80000008H, EBX, 2, 0
#define X86_XSAVEOPT        DH, EAX, 0, 0
#define X86_XSAVES          DH, EAX, 3, 0

#define X86_WORD(FEATURE) _X86_WORD(X86_##FEATURE)
#define X86_LEAF(FEATURE) _X86_LEAF(X86_##FEATURE)
#define X86_REG(FEATURE)  _X86_REG(X86_##FEATURE)
#define X86_BIT(FEATURE)  _X86_BIT(X86_##FEATURE)

#define _X86_CHECK(FEATURE) __X86_CHECK(FEATURE)
#define _X86_HAVE(FEATURE)  __X86_HAVE(FEATURE)
#define _X86_NEED(FEATURE)  __X86_NEED(FEATURE)
#define _X86_WORD(FEATURE)  __X86_WORD(FEATURE)
#define _X86_LEAF(FEATURE)  __X86_LEAF(FEATURE)
#define _X86_REG(FEATURE)   __X86_REG(FEATURE)
#define _X86_BIT(FEATURE)   __X86_BIT(FEATURE)

#define __X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  ___X86_CHECK(LEAF, REG, BIT, MANDATORY)
#define __X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  ___X86_HAVE(LEAF, REG, BIT, MANDATORY)
#define __X86_NEED(LEAF, REG, BIT, MANDATORY) MANDATORY
#define __X86_WORD(LEAF, REG, BIT, MANDATORY) KCPUIDS(LEAF, REG)
#define __X86_LEAF(LEAF, REG, BIT, MANDATORY) LEAF
#define __X86_REG(LEAF, REG, BIT, MANDATORY)  REG
#define __X86_BIT(LEAF, REG, BIT, MANDATORY)  BIT

#define ___X86_CHECK(LEAF, REG, BIT, MANDATORY) \
  !!(KCPUIDS(LEAF, REG) & (1u << BIT))

#ifndef __ASSEMBLER__
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  !!(MANDATORY || KCPUIDS(LEAF, REG) & (1u << BIT))
#else
#define ___X86_HAVE(LEAF, REG, BIT, MANDATORY) \
  $1 << (BIT % 8), BIT / 8 + KCPUIDS(LEAF, REG)
#endif

#else
#define X86_HAVE(FEATURE)  0
#define X86_NEED(FEATURE)  0
#define X86_CHECK(FEATURE) 0
#endif /* __x86_64__ */

#define INTRIN_COMMUTATIVE "%"
#define INTRIN_NONCOMMUTATIVE

#if defined(__x86_64__) && !defined(__STRICT_ANSI__)

typedef char __intrin_xmm_t
    __attribute__((__vector_size__(16), __aligned__(16), __may_alias__));

#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C)                    \
  do {                                                                         \
    if (X86_HAVE(ISA)) {                                                       \
      __intrin_xmm_t *Xmm0 = (void *)(A);                                      \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);                \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(C);                \
      if (!X86_NEED(AVX)) {                                                    \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm2), "0"(*Xmm1));        \
      } else {                                                                 \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : FLAGS "x"(*Xmm1), "x"(*Xmm2)); \
      }                                                                        \
    } else {                                                                   \
      PURE(A, B, C);                                                           \
    }                                                                          \
  } while (0)

#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)                 \
  do {                                                               \
    if (X86_HAVE(ISA)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I));     \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)                 \
  do {                                                          \
    if (X86_HAVE(ISA)) {                                        \
      __intrin_xmm_t *Xmm0 = (void *)(A);                       \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B); \
      if (!X86_NEED(AVX)) {                                     \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "0"(*Xmm1));           \
      } else {                                                  \
        asm("v" OP "\t%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1));       \
      }                                                         \
    } else {                                                    \
      PURE(A, B);                                               \
    }                                                           \
  } while (0)

#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)                   \
  do {                                                               \
    if (!IsModeDbg() && X86_HAVE(ISA)) {                             \
      __intrin_xmm_t *Xmm0 = (void *)(A);                            \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);      \
      if (!X86_NEED(AVX)) {                                          \
        asm(OP "\t%1,%0" : "=x"(*Xmm0) : "i"(I), "0"(*Xmm1));        \
      } else {                                                       \
        asm("v" OP "\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \
      }                                                              \
    } else {                                                         \
      PURE(A, B, I);                                                 \
    }                                                                \
  } while (0)

#else
#define INTRIN_SSEVEX_X_X_X_(PURE, ISA, OP, FLAGS, A, B, C) PURE(A, B, C)
#define INTRIN_SSEVEX_X_X_I_(PURE, ISA, OP, A, B, I)        PURE(A, B, I)
#define INTRIN_SSEVEX_X_I_(PURE, ISA, OP, A, B, I)          PURE(A, B, I)
#define INTRIN_SSEVEX_X_X_(PURE, ISA, OP, A, B)             PURE(A, B)
#endif /* X86 && !ANSI */



/*!BEGIN libc/intrin/newbie.h */

#define COSMOPOLITAN_LIBC_BITS_NEWBIE_H_

#define BYTE_ORDER    __BYTE_ORDER__
#define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define PDP_ENDIAN    __ORDER_PDP_ENDIAN__

#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define htobe16(x) bswap_16(x)
#define be16toh(x) bswap_16(x)
#define betoh16(x) bswap_16(x)
#define htobe32(x) bswap_32(x)
#define be32toh(x) bswap_32(x)
#define betoh32(x) bswap_32(x)
#define htobe64(x) bswap_64(x)
#define be64toh(x) bswap_64(x)
#define betoh64(x) bswap_64(x)
#define htole16(x) (uint16_t)(x)
#define le16toh(x) (uint16_t)(x)
#define letoh16(x) (uint16_t)(x)
#define htole32(x) (uint32_t)(x)
#define le32toh(x) (uint32_t)(x)
#define letoh32(x) (uint32_t)(x)
#define htole64(x) (uint64_t)(x)
#define le64toh(x) (uint64_t)(x)
#define letoh64(x) (uint64_t)(x)
#else
#define htobe16(x) (uint16_t)(x)
#define be16toh(x) (uint16_t)(x)
#define betoh16(x) (uint16_t)(x)
#define htobe32(x) (uint32_t)(x)
#define be32toh(x) (uint32_t)(x)
#define betoh32(x) (uint32_t)(x)
#define htobe64(x) (uint64_t)(x)
#define be64toh(x) (uint64_t)(x)
#define betoh64(x) (uint64_t)(x)
#define htole16(x) bswap_16(x)
#define le16toh(x) bswap_16(x)
#define letoh16(x) bswap_16(x)
#define htole32(x) bswap_32(x)
#define le32toh(x) bswap_32(x)
#define letoh32(x) bswap_32(x)
#define htole64(x) bswap_64(x)
#define le64toh(x) bswap_64(x)
#define letoh64(x) bswap_64(x)
#endif



/*!BEGIN libc/intrin/packsswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKSSWB_H_
COSMOPOLITAN_C_START_

void packsswb(int8_t[16], const int16_t[8], const int16_t[8]);

#define packsswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packsswb, SSE2, "packsswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/packuswb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PACKUSWB_H_
COSMOPOLITAN_C_START_

void packuswb(uint8_t[16], const int16_t[8], const int16_t[8]);

#define packuswb(A, B, C)                                                    \
  INTRIN_SSEVEX_X_X_X_(packuswb, SSE2, "packuswb", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/paddw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PADDW_H_
COSMOPOLITAN_C_START_

void paddw(int16_t[8], const int16_t[8], const int16_t[8]);

#define paddw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(paddw, SSE2, "paddw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/palignr.h */

#define COSMOPOLITAN_LIBC_INTRIN_PALIGNR_H_


/*!BEGIN libc/str/str.h */

#define COSMOPOLITAN_LIBC_STR_STR_H_

#define INVALID_CODEPOINT 0xfffd

#define _tolower(u) (0040 | (u))
#define _toupper(u) (0137 & (u))

#ifdef _COSMO_SOURCE
#define chomp         _chomp
#define chomp16       _chomp16
#define wchomp        _wchomp
#define tpenc         _tpenc
#define isutf8        _isutf8
#define istext        _istext
#define startswith    _startswith
#define startswithi   _startswithi
#define endswith      _endswith
#define wcsendswith   _wcsendswith
#define wcsstartswith _wcsstartswith
#endif /* _COSMO_SOURCE */

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

int isascii(int) libcesque;
int isspace(int) libcesque;
int isalpha(int) libcesque;
int isdigit(int) libcesque;
int isalnum(int) libcesque;
int isxdigit(int) libcesque;
int isprint(int) libcesque;
int islower(int) libcesque;
int isupper(int) libcesque;
int isblank(int) libcesque;
int iscntrl(int) libcesque;
int isgraph(int) libcesque;
int tolower(int) libcesque;
int ispunct(int) libcesque;
int toupper(int) libcesque;
int toascii(int) libcesque;

int iswalnum(wint_t) libcesque;
int iswalpha(wint_t) libcesque;
int iswblank(wint_t) libcesque;
int iswcntrl(wint_t) libcesque;
int iswdigit(wint_t) libcesque;
int iswgraph(wint_t) libcesque;
int iswlower(wint_t) libcesque;
int iswspace(wint_t) libcesque;
int iswupper(wint_t) libcesque;
int iswxdigit(wint_t) libcesque;
int iswpunct(wint_t) libcesque;
int iswprint(wint_t) libcesque;
int iswseparator(wint_t) libcesque;
wint_t towlower(wint_t) libcesque;
wint_t towupper(wint_t) libcesque;

void *memset(void *, int, size_t) memcpyesque;
void *memmove(void *, const void *, size_t) memcpyesque;
void *memcpy(void *restrict, const void *restrict, size_t) memcpyesque;
void *mempcpy(void *restrict, const void *restrict, size_t) memcpyesque;
char *hexpcpy(char *restrict, const void *restrict, size_t) memcpyesque;
void *memccpy(void *restrict, const void *restrict, int, size_t) memcpyesque;
void explicit_bzero(void *, size_t);

int memcmp(const void *, const void *, size_t) strlenesque;
int timingsafe_bcmp(const void *, const void *, size_t) libcesque;
int timingsafe_memcmp(const void *, const void *, size_t) libcesque;

size_t strlen(const char *) strlenesque;
size_t strnlen(const char *, size_t) strlenesque;
size_t strnlen_s(const char *, size_t) libcesque;
char *strchr(const char *, int) strlenesque;
void *memchr(const void *, int, size_t) strlenesque;
char *strchrnul(const char *, int) strlenesque returnsnonnull;
void *rawmemchr(const void *, int) strlenesque returnsnonnull;
size_t wcslen(const wchar_t *) strlenesque;
size_t wcsnlen(const wchar_t *, size_t) strlenesque;
size_t wcsnlen_s(const wchar_t *, size_t) libcesque;
wchar_t *wcschr(const wchar_t *, wchar_t) strlenesque;
wchar_t *wmemchr(const wchar_t *, wchar_t, size_t) strlenesque;
wchar_t *wcschrnul(const wchar_t *, wchar_t)
strlenesque returnsnonnull;
char *strstr(const char *, const char *) strlenesque;
char *strcasestr(const char *, const char *) strlenesque;
wchar_t *wcsstr(const wchar_t *, const wchar_t *) strlenesque;
int strcmp(const char *, const char *) strlenesque;
int strncmp(const char *, const char *, size_t) strlenesque;
int wcscmp(const wchar_t *, const wchar_t *) strlenesque;
int wcsncmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int wmemcmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
int strcasecmp(const char *, const char *) strlenesque;
int memcasecmp(const void *, const void *, size_t) strlenesque;
int wcscasecmp(const wchar_t *, const wchar_t *) strlenesque;
int strncasecmp(const char *, const char *, size_t) strlenesque;
int wcsncasecmp(const wchar_t *, const wchar_t *, size_t) strlenesque;
char *strrchr(const char *, int) strlenesque;
void *memrchr(const void *, int, size_t) strlenesque;
wchar_t *wcsrchr(const wchar_t *, wchar_t) strlenesque;
void *wmemrchr(const wchar_t *, wchar_t, size_t) strlenesque;
char *strpbrk(const char *, const char *) strlenesque;
wchar_t *wcspbrk(const wchar_t *, const wchar_t *) strlenesque;
size_t strspn(const char *, const char *) strlenesque;
size_t wcsspn(const wchar_t *, const wchar_t *) strlenesque;
size_t strcspn(const char *, const char *) strlenesque;
size_t wcscspn(const wchar_t *, const wchar_t *) strlenesque;
void *memfrob(void *, size_t) memcpyesque;
int strcoll(const char *, const char *) strlenesque;
char *strsep(char **, const char *) libcesque paramsnonnull();
char *stpcpy(char *, const char *) memcpyesque;
char *stpncpy(char *, const char *, size_t) memcpyesque;
char *strcat(char *, const char *) memcpyesque;
wchar_t *wcscat(wchar_t *, const wchar_t *) memcpyesque;
size_t strlcpy(char *, const char *, size_t) libcesque;
size_t strlcat(char *, const char *, size_t) libcesque;
size_t strxfrm(char *, const char *, size_t) libcesque;
char *strcpy(char *, const char *) memcpyesque;
wchar_t *wcscpy(wchar_t *, const wchar_t *) memcpyesque;
char *strncat(char *, const char *, size_t) memcpyesque;
wchar_t *wcsncat(wchar_t *, const wchar_t *, size_t) memcpyesque;
char *strncpy(char *, const char *, size_t) memcpyesque;
char *strtok(char *, const char *) paramsnonnull((2)) libcesque;
char *strtok_r(char *, const char *, char **) paramsnonnull((2, 3));
wchar_t *wcstok(wchar_t *, const wchar_t *, wchar_t **) paramsnonnull((2, 3));
int strverscmp(const char *, const char *) libcesque;
wchar_t *wmemset(wchar_t *, wchar_t, size_t) memcpyesque;
wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmempcpy(wchar_t *, const wchar_t *, size_t) memcpyesque;
wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t) memcpyesque;
void *memmem(const void *, size_t, const void *, size_t)
libcesque nosideeffect;
ssize_t strfmon(char *, size_t, const char *, ...) libcesque;
long a64l(const char *) libcesque;
char *l64a(long) libcesque;

typedef unsigned mbstate_t;

wchar_t *wcsncpy(wchar_t *, const wchar_t *, size_t) libcesque;
int mbtowc(wchar_t *, const char *, size_t) libcesque;
size_t mbrtowc(wchar_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbsrtowcs(wchar_t *, const char **, size_t, mbstate_t *) libcesque;
size_t mbstowcs(wchar_t *, const char *, size_t) libcesque;
size_t wcrtomb(char *, wchar_t, mbstate_t *) libcesque;
size_t c32rtomb(char *, char32_t, mbstate_t *) libcesque;
size_t mbrtoc32(char32_t *, const char *, size_t, mbstate_t *) libcesque;
size_t c16rtomb(char *, char16_t, mbstate_t *) libcesque;
size_t mbrtoc16(char16_t *, const char *, size_t, mbstate_t *) libcesque;
size_t mbrlen(const char *, size_t, mbstate_t *) libcesque;
size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *);
size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *);
size_t wcsrtombs(char *, const wchar_t **, size_t, mbstate_t *) libcesque;
size_t wcstombs(char *, const wchar_t *, size_t) libcesque;
int mbsinit(const mbstate_t *) libcesque;
int mblen(const char *, size_t) libcesque;
int wctomb(char *, wchar_t) libcesque;
int wctob(wint_t) libcesque;
wint_t btowc(int) libcesque;

typedef unsigned wctype_t;
wctype_t wctype(const char *) strlenesque;
pureconst int iswctype(wint_t, wctype_t) libcesque;

typedef const int *wctrans_t;
wctrans_t wctrans(const char *) libcesque;
wint_t towctrans(wint_t, wctrans_t) libcesque;

int getsubopt(char **, char *const *, char **) libcesque paramsnonnull();
char *strsignal(int) returnsnonnull libcesque;
char *strerror(int) returnsnonnull dontthrow dontcallback;
errno_t strerror_r(int, char *, size_t) libcesque;
char *__xpg_strerror_r(int, char *, size_t) libcesque;

#ifdef _COSMO_SOURCE
pureconst uint64_t tpenc(uint32_t) libcesque;
char *chomp(char *) libcesque;
wchar_t *wchomp(wchar_t *) libcesque;
uint64_t __fnv(const void *, size_t) strlenesque;
bool32 startswith(const char *, const char *) strlenesque;
bool32 startswithi(const char *, const char *) strlenesque;
bool32 endswith(const char *, const char *) strlenesque;
bool32 istext(const void *, size_t) libcesque;
bool32 isutf8(const void *, size_t) libcesque;
const char *strsignal_r(int, char[21]) returnsnonnull libcesque __wur;
char16_t *chomp16(char16_t *) libcesque;
size_t strlen16(const char16_t *) strlenesque;
size_t strnlen16(const char16_t *, size_t) strlenesque;
char16_t *strchr16(const char16_t *, int) strlenesque;
void *memchr16(const void *, int, size_t) strlenesque;
char16_t *strchrnul16(const char16_t *, int) strlenesque returnsnonnull;
void *rawmemchr16(const void *, int) strlenesque returnsnonnull;
char16_t *strstr16(const char16_t *, const char16_t *) strlenesque;
int strcmp16(const char16_t *, const char16_t *) strlenesque;
int strncmp16(const char16_t *, const char16_t *, size_t) strlenesque;
int strcasecmp16(const char16_t *, const char16_t *) strlenesque;
int strncasecmp16(const char16_t *, const char16_t *, size_t) strlenesque;
char16_t *strrchr16(const char16_t *, int) strlenesque;
void *memrchr16(const void *, int, size_t) strlenesque;
char16_t *strpbrk16(const char16_t *, const char16_t *) strlenesque;
size_t strspn16(const char16_t *, const char16_t *) strlenesque;
size_t strcspn16(const char16_t *, const char16_t *) strlenesque;
char16_t *strcat16(char16_t *, const char16_t *) memcpyesque;
char16_t *strcpy16(char16_t *, const char16_t *) memcpyesque;
char16_t *strncat16(char16_t *, const char16_t *, size_t) memcpyesque;
char16_t *memset16(char16_t *, char16_t, size_t) memcpyesque;
bool32 startswith16(const char16_t *, const char16_t *) strlenesque;
bool32 endswith16(const char16_t *, const char16_t *) strlenesque;
axdx_t tprecode8to16(char16_t *, size_t, const char *) libcesque;
axdx_t tprecode16to8(char *, size_t, const char16_t *) libcesque;
bool32 wcsstartswith(const wchar_t *, const wchar_t *) strlenesque;
bool32 wcsendswith(const wchar_t *, const wchar_t *) strlenesque;
char *__join_paths(char *, size_t, const char *, const char *) libcesque __wur;
int __mkntpathat(int, const char *, int, char16_t[hasatleast 1024]);
#endif /* _COSMO_SOURCE */

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || \
    defined(_POSIX_SOURCE) ||                                                 \
    (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE + 0 < 200809L) ||            \
    (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE + 0 < 700)
int bcmp(const void *, const void *, size_t) strlenesque;
void bcopy(const void *, void *, size_t) memcpyesque;
void bzero(void *, size_t) memcpyesque;
char *index(const char *, int) strlenesque;
char *rindex(const char *, int) strlenesque;
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
COSMOPOLITAN_C_START_

void palignr(void *, const void *, const void *, unsigned long);

#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) && defined(__x86_64__)
__intrin_xmm_t __palignrs(__intrin_xmm_t, __intrin_xmm_t);
#define palignr(C, B, A, I)                                                \
  do {                                                                     \
    if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSSE3), \
                         1)) {                                             \
      __intrin_xmm_t *Xmm0 = (void *)(C);                                  \
      const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B);            \
      const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(A);            \
      if (__builtin_constant_p(I)) {                                       \
        if (!X86_NEED(AVX)) {                                              \
          asm("palignr\t%2,%1,%0"                                          \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm2), "i"(I), "0"(*Xmm1));                           \
        } else {                                                           \
          asm("vpalignr\t%3,%2,%1,%0"                                      \
              : "=x"(*Xmm0)                                                \
              : "x"(*Xmm1), "x"(*Xmm2), "i"(I));                           \
        }                                                                  \
      } else {                                                             \
        unsigned long Vimm = (I);                                          \
        typeof(__palignrs) *Fn;                                            \
        if (__builtin_expect(Vimm < 32, 1)) {                              \
          Fn = (typeof(__palignrs) *)((uintptr_t)&__palignrs + Vimm * 8);  \
          *Xmm0 = Fn(*Xmm1, *Xmm2);                                        \
        } else {                                                           \
          memset(Xmm0, 0, 16);                                             \
        }                                                                  \
      }                                                                    \
    } else {                                                               \
      palignr(C, B, A, I);                                                 \
    }                                                                      \
  } while (0)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pandn.h */

#define COSMOPOLITAN_LIBC_INTRIN_PANDN_H_
COSMOPOLITAN_C_START_

void pandn(uint64_t[2], const uint64_t[2], const uint64_t[2]);

#define pandn(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pandn, SSE2, "pandn", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTB_H_
COSMOPOLITAN_C_START_

void pcmpgtb(int8_t[16], const int8_t[16], const int8_t[16]);

#define pcmpgtb(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtb, SSE2, "pcmpgtb", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pcmpgtw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTW_H_
COSMOPOLITAN_C_START_

void pcmpgtw(int16_t[8], const int16_t[8], const int16_t[8]);

#define pcmpgtw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pcmpgtw, SSE2, "pcmpgtw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmaddubsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMADDUBSW_H_
COSMOPOLITAN_C_START_

void pmaddubsw(int16_t[8], const uint8_t[16], const int8_t[16]);

#define pmaddubsw(W, B, C)                                                   \
  INTRIN_SSEVEX_X_X_X_(pmaddubsw, SSSE3, "pmaddubsw", INTRIN_NONCOMMUTATIVE, \
                       W, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmovmskb.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMOVMSKB_H_
COSMOPOLITAN_C_START_

uint32_t pmovmskb(const uint8_t[16]);

#if defined(__x86_64__) && defined(__GNUC__)
#define pmovmskb(A)                                            \
  ({                                                           \
    uint32_t Mask;                                             \
    if (!IsModeDbg() && X86_HAVE(SSE2)) {                      \
      const __intrin_xmm_t *Xmm = (const __intrin_xmm_t *)(A); \
      if (!X86_NEED(AVX)) {                                    \
        asm("pmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));       \
      } else {                                                 \
        asm("vpmovmskb\t%1,%0" : "=r"(Mask) : "x"(*Xmm));      \
      }                                                        \
    } else {                                                   \
      Mask = pmovmskb(A);                                      \
    }                                                          \
    Mask;                                                      \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/pmulhrsw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PMULHRSW_H_
COSMOPOLITAN_C_START_

void pmulhrsw(int16_t a[8], const int16_t b[8], const int16_t c[8]);

#define pmulhrsw(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(pmulhrsw, SSSE3, "pmulhrsw", INTRIN_COMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/popcnt.h */

#define COSMOPOLITAN_LIBC_BITS_POPCNT_H_
COSMOPOLITAN_C_START_

libcesque size_t _countbits(const void *, size_t);
libcesque unsigned long popcnt(unsigned long) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define popcnt(X)                                                \
  (__builtin_constant_p(X) ? __builtin_popcountll(X) : ({        \
    unsigned long PoP = (X);                                     \
    if (X86_HAVE(POPCNT)) {                                      \
      asm("popcnt\t%0,%0" : "+r"(PoP) : /* no inputs */ : "cc"); \
    } else {                                                     \
      PoP = (popcnt)(PoP);                                       \
    }                                                            \
    PoP;                                                         \
  }))
#else
#define popcnt(x) __builtin_popcountll(x)
#endif /* GNUC && !ANSI */

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/psraw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PSRAW_H_
COSMOPOLITAN_C_START_

void psraw(int16_t[8], const int16_t[8], unsigned char) libcesque;
void psrawv(int16_t[8], const int16_t[8], const uint64_t[2]) libcesque;

#define psraw(A, B, I) INTRIN_SSEVEX_X_I_(psraw, SSE2, "psraw", A, B, I)
#define psrawv(A, B, C) \
  INTRIN_SSEVEX_X_X_X_(psrawv, SSE2, "psraw", INTRIN_NONCOMMUTATIVE, A, B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHBW_H_
COSMOPOLITAN_C_START_

void punpckhbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpckhbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhbw, SSE2, "punpckhbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpckhwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHWD_H_
COSMOPOLITAN_C_START_

void punpckhwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpckhwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpckhwd, SSE2, "punpckhwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklbw.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLBW_H_
COSMOPOLITAN_C_START_

void punpcklbw(uint8_t[16], const uint8_t[16], const uint8_t[16]);

#define punpcklbw(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklbw, SSE2, "punpcklbw", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/punpcklwd.h */

#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLWD_H_
COSMOPOLITAN_C_START_

void punpcklwd(uint16_t[8], const uint16_t[8], const uint16_t[8]);

#define punpcklwd(A, B, C)                                                     \
  INTRIN_SSEVEX_X_X_X_(punpcklwd, SSE2, "punpcklwd", INTRIN_NONCOMMUTATIVE, A, \
                       B, C)

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/repmovsb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPMOVSB_H_
#ifdef _COSMO_SOURCE

forceinline void repmovsb(void **dest, const void **src, size_t cx) {
  char *di = (char *)*dest;
  const char *si = (const char *)*src;
  while (cx) *di++ = *si++, cx--;
  *dest = di, *src = si;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repmovsb(DI, SI, CX)                                       \
  ({                                                               \
    void *Di = *(DI);                                              \
    const void *Si = *(SI);                                        \
    size_t Cx = (CX);                                              \
    asm("rep movsb"                                                \
        : "=D"(Di), "=S"(Si), "=c"(Cx), "=m"(*(char(*)[Cx])Di)     \
        : "0"(Di), "1"(Si), "2"(Cx), "m"(*(const char(*)[Cx])Si)); \
    *(DI) = Di, *(SI) = Si;                                        \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/repstosb.h */

#define COSMOPOLITAN_LIBC_INTRIN_REPSTOSB_H_
#ifdef _COSMO_SOURCE

forceinline void *repstosb(void *dest, unsigned char al, size_t cx) {
  unsigned char *di = (unsigned char *)dest;
  while (cx) *di++ = al, cx--;
  return di;
}

#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
#define repstosb(DI, AL, CX)                         \
  ({                                                 \
    void *Di = (DI);                                 \
    size_t Cx = (CX);                                \
    unsigned char Al = (AL);                         \
    asm("rep stosb %b5,(%0)"                         \
        : "=D"(Di), "=c"(Cx), "=m"(*(char(*)[Cx])Di) \
        : "0"(Di), "1"(Cx), "a"(Al));                \
    Di;                                              \
  })
#endif

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/intrin/ubsan.h */

#define COSMOPOLITAN_LIBC_INTRIN_UBSAN_H_
COSMOPOLITAN_C_START_

extern bool32 __ubsan_strict;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/ulock.h */

#define COSMOPOLITAN_ULOCK_H_
COSMOPOLITAN_C_START_

/* both wake and wait take one of these */
#define UL_COMPARE_AND_WAIT          1 /* multi-thread */
#define UL_UNFAIR_LOCK               2
#define UL_COMPARE_AND_WAIT_SHARED   3 /* multi-thread/process */
#define UL_UNFAIR_LOCK64_SHARED      4
#define UL_COMPARE_AND_WAIT64        5
#define UL_COMPARE_AND_WAIT64_SHARED 6

#define ULF_WAKE_ALL             0x00000100
#define ULF_WAKE_THREAD          0x00000200 /* takes wake_value */
#define ULF_WAKE_ALLOW_NON_OWNER 0x00000400

#define ULF_WAIT_WORKQ_DATA_CONTENTION 0x00010000
#define ULF_WAIT_CANCEL_POINT          0x00020000 /* raises eintr */
#define ULF_WAIT_ADAPTIVE_SPIN         0x00040000

int ulock_wake(uint32_t, void *, uint64_t) libcesque;
int ulock_wait(uint32_t, void *, uint64_t, uint32_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/intrin/weaken.h */

#define COSMOPOLITAN_LIBC_BITS_WEAKEN_H_

#ifndef __chibicc__
#define _weaken(symbol)                                         \
  __extension__({                                               \
    extern __typeof__(symbol) symbol __attribute__((__weak__)); \
    &symbol;                                                    \
  })
#else
#define _weaken(symbol) (&(symbol))
#endif



/*!BEGIN libc/intrin/x86.h */

#define COSMOPOLITAN_LIBC_INTRIN_X86_H_
COSMOPOLITAN_C_START_

enum VendorSignatures {
  SIG_INTEL = 0x756e6547, /* Genu */
  SIG_AMD = 0x68747541,   /* Auth */
};

enum ProcessorVendors {
  VENDOR_INTEL = 1,
  VENDOR_AMD,
  VENDOR_OTHER,
  VENDOR_MAX
};

enum ProcessorTypes {
  INTEL_BONNELL = 1,
  INTEL_CORE2,
  INTEL_COREI7,
  AMDFAM10H,
  AMDFAM15H,
  INTEL_SILVERMONT,
  INTEL_KNL,
  AMD_BTVER1,
  AMD_BTVER2,
  AMDFAM17H,
  INTEL_KNM,
  INTEL_GOLDMONT,
  INTEL_GOLDMONT_PLUS,
  INTEL_TREMONT,
  AMDFAM19H,
  ZHAOXIN_FAM7H,
  INTEL_SIERRAFOREST,
  INTEL_GRANDRIDGE,
  INTEL_CLEARWATERFOREST,
  CPU_TYPE_MAX
};

enum ProcessorSubtypes {
  INTEL_COREI7_NEHALEM = 1,
  INTEL_COREI7_WESTMERE,
  INTEL_COREI7_SANDYBRIDGE,
  AMDFAM10H_BARCELONA,
  AMDFAM10H_SHANGHAI,
  AMDFAM10H_ISTANBUL,
  AMDFAM15H_BDVER1,
  AMDFAM15H_BDVER2,
  AMDFAM15H_BDVER3,
  AMDFAM15H_BDVER4,
  AMDFAM17H_ZNVER1,
  INTEL_COREI7_IVYBRIDGE,
  INTEL_COREI7_HASWELL,
  INTEL_COREI7_BROADWELL,
  INTEL_COREI7_SKYLAKE,
  INTEL_COREI7_SKYLAKE_AVX512,
  INTEL_COREI7_CANNONLAKE,
  INTEL_COREI7_ICELAKE_CLIENT,
  INTEL_COREI7_ICELAKE_SERVER,
  AMDFAM17H_ZNVER2,
  INTEL_COREI7_CASCADELAKE,
  INTEL_COREI7_TIGERLAKE,
  INTEL_COREI7_COOPERLAKE,
  INTEL_COREI7_SAPPHIRERAPIDS,
  INTEL_COREI7_ALDERLAKE,
  AMDFAM19H_ZNVER3,
  INTEL_COREI7_ROCKETLAKE,
  ZHAOXIN_FAM7H_LUJIAZUI,
  AMDFAM19H_ZNVER4,
  INTEL_COREI7_GRANITERAPIDS,
  INTEL_COREI7_GRANITERAPIDS_D,
  INTEL_COREI7_ARROWLAKE,
  INTEL_COREI7_ARROWLAKE_S,
  INTEL_COREI7_PANTHERLAKE,
  CPU_SUBTYPE_MAX
};

enum ProcessorFeatures {
  FEATURE_CMOV = 0,
  FEATURE_MMX,
  FEATURE_POPCNT,
  FEATURE_SSE,
  FEATURE_SSE2,
  FEATURE_SSE3,
  FEATURE_SSSE3,
  FEATURE_SSE4_1,
  FEATURE_SSE4_2,
  FEATURE_AVX,
  FEATURE_AVX2,
  FEATURE_SSE4_A,
  FEATURE_FMA4,
  FEATURE_XOP,
  FEATURE_FMA,
  FEATURE_AVX512F,
  FEATURE_BMI,
  FEATURE_BMI2,
  FEATURE_AES,
  FEATURE_PCLMUL,
  FEATURE_AVX512VL,
  FEATURE_AVX512BW,
  FEATURE_AVX512DQ,
  FEATURE_AVX512CD,
  FEATURE_AVX512ER,
  FEATURE_AVX512PF,
  FEATURE_AVX512VBMI,
  FEATURE_AVX512IFMA,
  FEATURE_AVX5124VNNIW,
  FEATURE_AVX5124FMAPS,
  FEATURE_AVX512VPOPCNTDQ,
  FEATURE_AVX512VBMI2,
  FEATURE_GFNI,
  FEATURE_VPCLMULQDQ,
  FEATURE_AVX512VNNI,
  FEATURE_AVX512BITALG,
  FEATURE_AVX512BF16,
  FEATURE_AVX512VP2INTERSECT,

  FEATURE_CMPXCHG16B = 46,
  FEATURE_F16C = 49,
  FEATURE_LAHF_LM = 54,
  FEATURE_LM,
  FEATURE_WP,
  FEATURE_LZCNT,
  FEATURE_MOVBE,

  FEATURE_AVX512FP16 = 94,
  FEATURE_X86_64_BASELINE,
  FEATURE_X86_64_V2,
  FEATURE_X86_64_V3,
  FEATURE_X86_64_V4,
  CPU_FEATURE_MAX
};

struct __processor_model {
  unsigned __cpu_vendor;
  unsigned __cpu_type;
  unsigned __cpu_subtype;
  unsigned __cpu_features[1];
  const char *__cpu_march;
};

extern struct __processor_model __cpu_model;

const char *__cpu_march(unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/bsd.h */

#define COSMOPOLITAN_LIBC_LOG_BSD_H_
COSMOPOLITAN_C_START_

void err(int, const char *, ...) wontreturn;
void verr(int, const char *, va_list) wontreturn;
void errc(int, int, const char *, ...) wontreturn;
void verrc(int, int, const char *, va_list) wontreturn;
void errx(int, const char *, ...) wontreturn;
void verrx(int, const char *, va_list) wontreturn;
void warn(const char *, ...);
void vwarn(const char *, va_list);
void warnc(int, const char *, ...);
void vwarnc(int, const char *, va_list);
void warnx(const char *, ...);
void vwarnx(const char *, va_list);
void err_set_exit(void (*)(int));

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/check.h */

#define COSMOPOLITAN_LIBC_LOG_CHECK_H_
COSMOPOLITAN_C_START_

#define CHECK(X, ...)         __CHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define CHECK_EQ(Y, X, ...)   __CHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NE(Y, X, ...)   __CHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LE(Y, X, ...)   __CHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_LT(Y, X, ...)   __CHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GE(Y, X, ...)   __CHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_GT(Y, X, ...)   __CHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define CHECK_NOTNULL(X, ...) __CHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define DCHECK(X, ...)       __DCHK(ne, !=, false, "false", !!(X), #X, "" __VA_ARGS__)
#define DCHECK_EQ(Y, X, ...) __DCHK(eq, ==, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NE(Y, X, ...) __DCHK(ne, !=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LE(Y, X, ...) __DCHK(le, <=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_LT(Y, X, ...) __DCHK(lt, <, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GE(Y, X, ...) __DCHK(ge, >=, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_GT(Y, X, ...) __DCHK(gt, >, Y, #Y, X, #X, "" __VA_ARGS__)
#define DCHECK_NOTNULL(X, ...) \
  __DCHK(ne, !=, NULL, "NULL", X, #X, "" __VA_ARGS__)

#define CHECK_ALIGNED(BYTES, VAR, ...)                                \
  do {                                                                \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                            \
      __check_fail_aligned(BYTES, (uintptr_t)VAR, __FILE__, __LINE__, \
                           "" __VA_ARGS__);                           \
      __builtin_unreachable();                                        \
    }                                                                 \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES);          \
  } while (0)

#define DCHECK_ALIGNED(BYTES, VAR, ...)                      \
  do {                                                       \
    if (((uintptr_t)VAR & ((BYTES)-1u))) {                   \
      __DCHK_ALIGNED(BYTES, (uintptr_t)VAR, "" __VA_ARGS__); \
      __builtin_unreachable();                               \
    }                                                        \
    VAR = (typeof(VAR))__builtin_assume_aligned(VAR, BYTES); \
  } while (0)

#define __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...)                   \
  do {                                                                       \
    autotype(GOT) Got = (GOT);                                               \
    autotype(WANT) Want = (WANT);                                            \
    if (!(Want OP Got)) {                                                    \
      if (!NoDebug()) {                                                      \
        __check_fail(#SUFFIX, #OP, (uint64_t)Want, (WANTSTR), (uint64_t)Got, \
                     (GOTSTR), __FILE__, __LINE__, __VA_ARGS__);             \
      } else {                                                               \
        __check_fail_##SUFFIX((uint64_t)Want, (uint64_t)Got, __FILE__,       \
                              __LINE__, 0, __VA_ARGS__);                     \
      }                                                                      \
      __builtin_unreachable();                                               \
    }                                                                        \
  } while (0)

#ifdef NDEBUG
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, ...) \
  do {                                              \
    autotype(GOT) Got = (GOT);                      \
    autotype(WANT) Want = (WANT);                   \
    if (!(Want OP Got)) {                           \
      __builtin_unreachable();                      \
    }                                               \
  } while (0)
#else
#define __DCHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, ...) \
  __CHK(SUFFIX, OP, WANT, WANTSTR, GOT, GOTSTR, __VA_ARGS__)
#endif /* NDEBUG */

#ifdef NDEBUG
#define __DCHK_ALIGNED(BYTES, VAR, ...)
#else
#define __DCHK_ALIGNED(BYTES, VAR, ...) \
  __check_fail_aligned(BYTES, VAR, __FILE__, __LINE__, __VA_ARGS__)
#endif

void __check_fail(const char *, const char *, uint64_t, const char *, uint64_t,
                  const char *, const char *, int, const char *,
                  ...) relegated wontreturn;

void __check_fail_eq(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ne(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_le(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_lt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_ge(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_gt(uint64_t, uint64_t, const char *, int, const char *,
                     const char *, ...) relegated wontreturn;
void __check_fail_aligned(unsigned, uint64_t, const char *, int, const char *,
                          ...) relegated wontreturn;

#ifdef __VSCODE_INTELLISENSE__
#undef __CHK
#define __CHK(...)
#undef __DCHK
#define __DCHK(...)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countbranch.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTBRANCH_H_
COSMOPOLITAN_C_START_

#define COUNTBRANCH(x) COUNTBRANCH_(x, #x, STRINGIFY(__FILE__), __LINE__)
#define COUNTBRANCH_(x, xs, file, line) \
  COUNTBRANCH__(x, STRINGIFY(xs), STRINGIFY(xs), file, line)
#define COUNTBRANCH__(x, xs, xss, file, line)                   \
  ({                                                            \
    bool Cond;                                                  \
    struct countbranch *Info;                                   \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31338:\t"                                              \
        ".asciz\t" xs "\n"                                      \
        "31339:\t"                                              \
        ".asciz\t" xss "\n"                                     \
        "31340:\t"                                              \
        ".asciz\t" file "\n\t"                                  \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountbranch_data(%%rip)\n\t"                     \
        ".previous\n\t"                                         \
        ".section .sort.data.countbranch.2,\"a\",@progbits\n\t" \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t0\n\t"                                          \
        ".quad\t0\n\t"                                          \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31339b\n\t"                                     \
        ".quad\t31340b\n\t"                                     \
        ".quad\t" #line "\n\t"                                  \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(Info));                                          \
    Cond = (x);                                                 \
    ++Info->total;                                              \
    if (Cond) ++Info->taken;                                    \
    Cond;                                                       \
  })

struct countbranch {
  long total;
  long taken;
  const char *code;
  const char *xcode;
  const char *file;
  long line;
};

extern struct countbranch countbranch_data[];

void countbranch_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/countexpr.h */

#define COSMOPOLITAN_LIBC_LOG_COUNTEXPR_H_


/*!BEGIN libc/nexgen32e/bench.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_BENCH_H_


/*!BEGIN libc/nexgen32e/rdtsc.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSC_H_
COSMOPOLITAN_C_START_

/**
 * Reads CPU timestamp counter.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(INVTSC)
 */
#define rdtsc() __RDTSC("rdtsc")

/**
 * Reads CPU timestamp counter w/ full serialization.
 *
 * This macro inhibits CPU magic.
 * This macro inhibits compiler magic.
 *
 * The clock isn't read until:
 *
 *   1. previous instructions finish executing; and
 *   2. previous loads are globally visible; and
 *   3. previous stores are globally visible.
 *
 * Later instructions won't dispatch until RDTSC completes.
 *
 * @see X86_HAVE(INVTSC)
 */
#define mfence_lfence_rdtsc_lfence() \
  __RDTSC("mfence\n\tlfence\n\trdtsc\n\tlfence")

#ifdef __x86__
#define __RDTSC(ASM)                                                       \
  ({                                                                       \
    uint64_t Rax, Rdx;                                                     \
    asm volatile(ASM : "=a"(Rax), "=d"(Rdx) : /* no inputs */ : "memory"); \
    Rdx << 32 | Rax;                                                       \
  })
#elif defined(__aarch64__)
#define __RDTSC(ASM)                                \
  ({                                                \
    uint64_t _Ts;                                   \
    asm volatile("mrs\t%0,cntvct_el0" : "=r"(_Ts)); \
    _Ts * 48; /* the fudge factor */                \
  })
#elif defined(__powerpc64__)
#define __RDTSC(ASM)                           \
  ({                                           \
    uint64_t _Ts;                              \
    asm volatile("mfspr\t%0,268" : "=r"(_Ts)); \
    _Ts;                                       \
  })
#elif defined(__riscv)
#define __RDTSC(ASM)                         \
  ({                                         \
    uint64_t _Ts;                            \
    asm volatile("rdcycle\t%0" : "=r"(_Ts)); \
    _Ts;                                     \
  })
#endif

COSMOPOLITAN_C_END_

/**
 * @fileoverview NexGen32e Microbenchmarking.
 *
 * @see X86_HAVE(INVTSC)
 * @see libc/testlib/bench.h
 */

#ifdef __x86__
#define __startbench()                            \
  ({                                              \
    uint64_t Ticks;                               \
    asm volatile("lfence\n\t"                     \
                 "push\t%%rbx\n\t"                \
                 "cpuid\n\t"                      \
                 "pop\t%%rbx\n\t"                 \
                 "rdtsc\n\t"                      \
                 "shl\t%2,%%rdx\n\t"              \
                 "or\t%%rdx,%0"                   \
                 : "=a"(Ticks)                    \
                 : "0"(0), "J"(32)                \
                 : "rcx", "rdx", "memory", "cc"); \
    Ticks;                                        \
  })
#define __endbench()                                     \
  ({                                                     \
    uint64_t Ticks;                                      \
    asm volatile("rdtscp\n\t"                            \
                 "shl\t%1,%%rdx\n\t"                     \
                 "or\t%%rdx,%%rax\n\t"                   \
                 "mov\t%%rax,%0\n\t"                     \
                 "xor\t%%eax,%%eax\n\t"                  \
                 "push\t%%rbx\n\t"                       \
                 "cpuid\n\t"                             \
                 "pop\t%%rbx"                            \
                 : "=r"(Ticks)                           \
                 : "J"(32)                               \
                 : "rax", "rcx", "rdx", "memory", "cc"); \
    Ticks;                                               \
  })
#else
#define __startbench()                \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#define __endbench()                  \
  ({                                  \
    uint64_t _ts;                     \
    asm volatile("isb" ::: "memory"); \
    _ts = rdtsc();                    \
    asm volatile("isb" ::: "memory"); \
    _ts;                              \
  })
#endif

#define __startbench_m() mfence_lfence_rdtsc_lfence()
#define __endbench_m()   __startbench_m()
#define __marker()       asm("nop")
#define __ordered()      asm volatile("" ::: "memory")
#define __fakeread(X)    asm volatile("" : /* no outputs */ : "g"(X))
#define __fakereadwrite(X)                 \
  ({                                       \
    autotype(X) Res = (X);                 \
    asm volatile("" : "=g"(Res) : "0"(X)); \
    Res;                                   \
  })

COSMOPOLITAN_C_START_

/**
 * Shows nanosecond timings histogram for expr at exit().
 */
#define COUNTEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, rdtsc, rdtsc, \
             "COUNTEXPR")

/**
 * Like COUNTEXPR() but can be used on function calls that return void.
 */
#define COUNTSTMT(stmt)                                                    \
  (void)COUNTEXPR_((stmt, 0), #stmt, STRINGIFY(__FILE__), __LINE__, rdtsc, \
                   rdtsc, "COUNTSTMT")

/**
 * Same as COUNTEXPR() but uses Intel's expensive measurement technique.
 */
#define BENCHEXPR(expr)                                                \
  COUNTEXPR_(expr, #expr, STRINGIFY(__FILE__), __LINE__, __startbench, \
             __endbench, "BENCHEXPR")

#define COUNTEXPR_(expr, code, file, line, start, stop, macro) \
  COUNTEXPR__(expr, STRINGIFY(code), file, line, start, stop, STRINGIFY(macro))

#define COUNTEXPR__(expr, code, file, line, start, stop, macro) \
  ({                                                            \
    struct countexpr *InfO;                                     \
    uint64_t t1_, t2_, TiCkS, NaNoS;                            \
    t1_ = start();                                              \
    asm volatile("" ::: "memory");                              \
    autotype(expr) ReS = (expr);                                \
    asm volatile("" ::: "memory");                              \
    t2_ = stop();                                               \
    TiCkS = t2_ >= t1_ ? t2_ - t1_ : ~t1_ + t2_ + 1;            \
    asm(".section .rodata.str1.1,\"aMS\",@progbits,1\n\t"       \
        ".balign\t1\n"                                          \
        "31340:\t.asciz\t" file "\n\t"                          \
        "31338:\t.asciz\t" code "\n"                            \
        "31332:\t.asciz\t" macro "\n"                           \
        ".previous\n\t"                                         \
        ".section .yoink\n\t"                                   \
        "nopl\tcountexpr_data(%%rip)\n\t"                       \
        ".previous\n\t"                                         \
        ".section .sort.data.countexpr.2,\"a\",@progbits\n\t"   \
        ".balign\t8\n31337:\t"                                  \
        ".quad\t" #line "\n\t"                                  \
        ".quad\t31340b\n\t"                                     \
        ".quad\t31338b\n\t"                                     \
        ".quad\t31332b\n\t"                                     \
        ".rept\t65\n\t"                                         \
        ".quad\t0\n\t"                                          \
        ".endr\n\t"                                             \
        ".previous\n\t"                                         \
        "lea\t31337b(%%rip),%0"                                 \
        : "=r"(InfO));                                          \
    /* approximation of round(x*.323018) which is usually */    \
    /* the ratio, between x86 rdtsc ticks and nanoseconds */    \
    NaNoS = (TiCkS * 338709) >> 20;                             \
    ++InfO->logos[NaNoS ? bsrl(NaNoS) + 1 : 0];                 \
    ReS;                                                        \
  })

struct countexpr {
  long line; /* zero for last entry */
  const char *file;
  const char *code;
  const char *macro;
  long logos[65];
};

extern struct countexpr countexpr_data[];

void countexpr_report(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/gdb.h */

#define COSMOPOLITAN_LIBC_LOG_GDB_H_


/*!BEGIN libc/sysv/consts/nr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NR_H_
#ifdef _COSMO_SOURCE
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int __NR_exit;
extern const int __NR_exit_group;
extern const int __NR_read;
extern const int __NR_write;
extern const int __NR_open;
extern const int __NR_close;
extern const int __NR_stat;
extern const int __NR_fstat;
extern const int __NR_lstat;
extern const int __NR_poll;
extern const int __NR_ppoll;
extern const int __NR_lseek;
extern const int __NR_mmap;
extern const int __NR_msync;
extern const int __NR_mprotect;
extern const int __NR_munmap;
extern const int __NR_sigaction;
extern const int __NR_sigprocmask;
extern const int __NR_ioctl;
extern const int __NR_pread;
extern const int __NR_pwrite;
extern const int __NR_readv;
extern const int __NR_writev;
extern const int __NR_access;
extern const int __NR_pipe;
extern const int __NR_select;
extern const int __NR_pselect;
extern const int __NR_pselect6;
extern const int __NR_sched_yield;
extern const int __NR_mremap;
extern const int __NR_mincore;
extern const int __NR_madvise;
extern const int __NR_shmget;
extern const int __NR_shmat;
extern const int __NR_shmctl;
extern const int __NR_dup;
extern const int __NR_dup2;
extern const int __NR_pause;
extern const int __NR_nanosleep;
extern const int __NR_getitimer;
extern const int __NR_setitimer;
extern const int __NR_alarm;
extern const int __NR_getpid;
extern const int __NR_sendfile;
extern const int __NR_socket;
extern const int __NR_connect;
extern const int __NR_accept;
extern const int __NR_sendto;
extern const int __NR_recvfrom;
extern const int __NR_sendmsg;
extern const int __NR_recvmsg;
extern const int __NR_shutdown;
extern const int __NR_bind;
extern const int __NR_listen;
extern const int __NR_getsockname;
extern const int __NR_getpeername;
extern const int __NR_socketpair;
extern const int __NR_setsockopt;
extern const int __NR_getsockopt;
extern const int __NR_fork;
extern const int __NR_vfork;
extern const int __NR_posix_spawn;
extern const int __NR_execve;
extern const int __NR_wait4;
extern const int __NR_kill;
extern const int __NR_killpg;
extern const int __NR_clone;
extern const int __NR_tkill;
extern const int __NR_futex;
extern const int __NR_set_robust_list;
extern const int __NR_get_robust_list;
extern const int __NR_uname;
extern const int __NR_semget;
extern const int __NR_semop;
extern const int __NR_semctl;
extern const int __NR_shmdt;
extern const int __NR_msgget;
extern const int __NR_msgsnd;
extern const int __NR_msgrcv;
extern const int __NR_msgctl;
extern const int __NR_fcntl;
extern const int __NR_flock;
extern const int __NR_fsync;
extern const int __NR_fdatasync;
extern const int __NR_truncate;
extern const int __NR_ftruncate;
extern const int __NR_getcwd;
extern const int __NR_chdir;
extern const int __NR_fchdir;
extern const int __NR_rename;
extern const int __NR_mkdir;
extern const int __NR_rmdir;
extern const int __NR_creat;
extern const int __NR_link;
extern const int __NR_unlink;
extern const int __NR_symlink;
extern const int __NR_readlink;
extern const int __NR_chmod;
extern const int __NR_fchmod;
extern const int __NR_chown;
extern const int __NR_fchown;
extern const int __NR_lchown;
extern const int __NR_umask;
extern const int __NR_gettimeofday;
extern const int __NR_getrlimit;
extern const int __NR_getrusage;
extern const int __NR_sysinfo;
extern const int __NR_times;
extern const int __NR_ptrace;
extern const int __NR_syslog;
extern const int __NR_getuid;
extern const int __NR_getgid;
extern const int __NR_getppid;
extern const int __NR_getpgrp;
extern const int __NR_setsid;
extern const int __NR_getsid;
extern const int __NR_getpgid;
extern const int __NR_setpgid;
extern const int __NR_geteuid;
extern const int __NR_getegid;
extern const int __NR_getgroups;
extern const int __NR_setgroups;
extern const int __NR_setreuid;
extern const int __NR_setregid;
extern const int __NR_setuid;
extern const int __NR_setgid;
extern const int __NR_setresuid;
extern const int __NR_setresgid;
extern const int __NR_getresuid;
extern const int __NR_getresgid;
extern const int __NR_sigpending;
extern const int __NR_sigsuspend;
extern const int __NR_sigaltstack;
extern const int __NR_mknod;
extern const int __NR_mknodat;
extern const int __NR_mkfifo;
extern const int __NR_mkfifoat;
extern const int __NR_statfs;
extern const int __NR_fstatfs;
extern const int __NR_getpriority;
extern const int __NR_setpriority;
extern const int __NR_mlock;
extern const int __NR_munlock;
extern const int __NR_mlockall;
extern const int __NR_munlockall;
extern const int __NR_setrlimit;
extern const int __NR_chroot;
extern const int __NR_sync;
extern const int __NR_acct;
extern const int __NR_settimeofday;
extern const int __NR_mount;
extern const int __NR_reboot;
extern const int __NR_quotactl;
extern const int __NR_setfsuid;
extern const int __NR_setfsgid;
extern const int __NR_capget;
extern const int __NR_capset;
extern const int __NR_sigtimedwait;
extern const int __NR_sigqueueinfo;
extern const int __NR_personality;
extern const int __NR_ustat;
extern const int __NR_sysfs;
extern const int __NR_sched_setparam;
extern const int __NR_sched_getparam;
extern const int __NR_sched_setscheduler;
extern const int __NR_sched_getscheduler;
extern const int __NR_sched_get_priority_max;
extern const int __NR_sched_get_priority_min;
extern const int __NR_sched_rr_get_interval;
extern const int __NR_vhangup;
extern const int __NR_modify_ldt;
extern const int __NR_pivot_root;
extern const int __NR__sysctl;
extern const int __NR_prctl;
extern const int __NR_arch_prctl;
extern const int __NR_adjtimex;
extern const int __NR_umount2;
extern const int __NR_swapon;
extern const int __NR_swapoff;
extern const int __NR_sethostname;
extern const int __NR_setdomainname;
extern const int __NR_iopl;
extern const int __NR_ioperm;
extern const int __NR_init_module;
extern const int __NR_delete_module;
extern const int __NR_gettid;
extern const int __NR_readahead;
extern const int __NR_setxattr;
extern const int __NR_fsetxattr;
extern const int __NR_getxattr;
extern const int __NR_fgetxattr;
extern const int __NR_listxattr;
extern const int __NR_flistxattr;
extern const int __NR_removexattr;
extern const int __NR_fremovexattr;
extern const int __NR_lsetxattr;
extern const int __NR_lgetxattr;
extern const int __NR_llistxattr;
extern const int __NR_lremovexattr;
extern const int __NR_sched_setaffinity;
extern const int __NR_sched_getaffinity;
extern const int __NR_cpuset_getaffinity;
extern const int __NR_cpuset_setaffinity;
extern const int __NR_io_setup;
extern const int __NR_io_destroy;
extern const int __NR_io_getevents;
extern const int __NR_io_submit;
extern const int __NR_io_cancel;
extern const int __NR_lookup_dcookie;
extern const int __NR_epoll_create;
extern const int __NR_epoll_wait;
extern const int __NR_epoll_ctl;
extern const int __NR_getdents;
extern const int __NR_set_tid_address;
extern const int __NR_restart_syscall;
extern const int __NR_semtimedop;
extern const int __NR_fadvise;
extern const int __NR_timer_create;
extern const int __NR_timer_settime;
extern const int __NR_timer_gettime;
extern const int __NR_timer_getoverrun;
extern const int __NR_timer_delete;
extern const int __NR_clock_settime;
extern const int __NR_clock_gettime;
extern const int __NR_clock_getres;
extern const int __NR_clock_nanosleep;
extern const int __NR_tgkill;
extern const int __NR_mbind;
extern const int __NR_set_mempolicy;
extern const int __NR_get_mempolicy;
extern const int __NR_mq_open;
extern const int __NR_mq_unlink;
extern const int __NR_mq_timedsend;
extern const int __NR_mq_timedreceive;
extern const int __NR_mq_notify;
extern const int __NR_mq_getsetattr;
extern const int __NR_kexec_load;
extern const int __NR_waitid;
extern const int __NR_add_key;
extern const int __NR_request_key;
extern const int __NR_keyctl;
extern const int __NR_ioprio_set;
extern const int __NR_ioprio_get;
extern const int __NR_inotify_init;
extern const int __NR_inotify_add_watch;
extern const int __NR_inotify_rm_watch;
extern const int __NR_openat;
extern const int __NR_mkdirat;
extern const int __NR_fchownat;
extern const int __NR_utime;
extern const int __NR_utimes;
extern const int __NR_futimesat;
extern const int __NR_futimes;
extern const int __NR_futimens;
extern const int __NR_fstatat;
extern const int __NR_unlinkat;
extern const int __NR_renameat;
extern const int __NR_linkat;
extern const int __NR_symlinkat;
extern const int __NR_readlinkat;
extern const int __NR_fchmodat;
extern const int __NR_faccessat;
extern const int __NR_unshare;
extern const int __NR_splice;
extern const int __NR_tee;
extern const int __NR_vmsplice;
extern const int __NR_migrate_pages;
extern const int __NR_move_pages;
extern const int __NR_preadv;
extern const int __NR_pwritev;
extern const int __NR_utimensat;
extern const int __NR_fallocate;
extern const int __NR_posix_fallocate;
extern const int __NR_accept4;
extern const int __NR_dup3;
extern const int __NR_pipe2;
extern const int __NR_epoll_pwait;
extern const int __NR_epoll_create1;
extern const int __NR_perf_event_open;
extern const int __NR_inotify_init1;
extern const int __NR_tgsigqueueinfo;
extern const int __NR_signalfd;
extern const int __NR_signalfd4;
extern const int __NR_eventfd;
extern const int __NR_eventfd2;
extern const int __NR_timerfd_create;
extern const int __NR_timerfd_settime;
extern const int __NR_timerfd_gettime;
extern const int __NR_recvmmsg;
extern const int __NR_fanotify_init;
extern const int __NR_fanotify_mark;
extern const int __NR_prlimit;
extern const int __NR_name_to_handle_at;
extern const int __NR_open_by_handle_at;
extern const int __NR_clock_adjtime;
extern const int __NR_syncfs;
extern const int __NR_sendmmsg;
extern const int __NR_setns;
extern const int __NR_getcpu;
extern const int __NR_process_vm_readv;
extern const int __NR_process_vm_writev;
extern const int __NR_kcmp;
extern const int __NR_finit_module;
extern const int __NR_sched_setattr;
extern const int __NR_sched_getattr;
extern const int __NR_renameat2;
extern const int __NR_seccomp;
extern const int __NR_getrandom;
extern const int __NR_memfd_create;
extern const int __NR_kexec_file_load;
extern const int __NR_bpf;
extern const int __NR_execveat;
extern const int __NR_userfaultfd;
extern const int __NR_membarrier;
extern const int __NR_mlock2;
extern const int __NR_copy_file_range;
extern const int __NR_preadv2;
extern const int __NR_pwritev2;
extern const int __NR_pkey_mprotect;
extern const int __NR_pkey_alloc;
extern const int __NR_pkey_free;
extern const int __NR_statx;
extern const int __NR_io_pgetevents;
extern const int __NR_rseq;
extern const int __NR_pidfd_send_signal;
extern const int __NR_io_uring_setup;
extern const int __NR_io_uring_enter;
extern const int __NR_io_uring_register;
extern const int __NR_pledge;
extern const int __NR_msyscall;
extern const int __NR_ktrace;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/w.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_W_H_
COSMOPOLITAN_C_START_

extern const int WNOHANG;
extern const int WUNTRACED;
extern const int WCONTINUED;

#define WNOHANG    1
#define WUNTRACED  WUNTRACED
#define WCONTINUED WCONTINUED


COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/**
 * @fileoverview GDB Attach Support Code.
 *
 * The goal of these macros is to make the backtrace into the failing
 * code as short as possible. It also helps avoid GDB getting confused
 * about how we don't use its readability destroying unwind directives.
 */

extern volatile int g_gdbsync;

int gdbexec(const char *);
int AttachDebugger(intptr_t);

#define AttachDebugger(CONTINUE_TO_ADDR) /* shorten backtraces */ \
  SYNCHRONIZE_DEBUGGER((AttachDebugger)(CONTINUE_TO_ADDR))

#define SYNCHRONIZE_DEBUGGER(PID)                                    \
  ({                                                                 \
    int Rc, Pid = (PID);                                             \
    if (Pid != -1) {                                                 \
      while ((Rc = __inline_wait4(Pid, NULL, WNOHANG, NULL)) == 0) { \
        if (g_gdbsync) {                                             \
          g_gdbsync = 0;                                             \
          if (Rc > 0) Pid = 0;                                       \
          break;                                                     \
        } else {                                                     \
          sched_yield();                                             \
        }                                                            \
      }                                                              \
    }                                                                \
    Pid;                                                             \
  })

#ifdef __x86_64__
#define __inline_wait4(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE)     \
  ({                                                                      \
    int64_t WaAx;                                                         \
    if (!IsWindows()) {                                                   \
      asm volatile("mov\t%5,%%r10\n\t"                                    \
                   "syscall"                                              \
                   : "=a"(WaAx)                                           \
                   : "0"(__NR_wait4), "D"(PID), "S"(OPT_OUT_WSTATUS),     \
                     "d"(OPTIONS), "g"(OPT_OUT_RUSAGE)                    \
                   : "rcx", "r8", "r9", "r10", "r11", "memory", "cc");    \
    } else {                                                              \
      WaAx = sys_wait4_nt(PID, OPT_OUT_WSTATUS, OPTIONS, OPT_OUT_RUSAGE); \
    }                                                                     \
    WaAx;                                                                 \
  })
#else
#define __inline_wait4 wait4
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/log/log.h */

#ifndef COSMOPOLITAN_LIBC_LOG_LOG_H_
#define COSMOPOLITAN_LIBC_LOG_LOG_H_


/*!BEGIN libc/stdio/stdio.h */

#define COSMOPOLITAN_LIBC_STDIO_H_

#define EOF    -1  /* end of file */
#define WEOF   -1u /* end of file (multibyte) */
#define _IOFBF 0   /* fully buffered */
#define _IOLBF 1   /* line buffered */
#define _IONBF 2   /* no buffering */

#define L_tmpnam     20
#define L_ctermid    20
#define P_tmpdir     "/tmp"
#define FILENAME_MAX 1024
#define FOPEN_MAX    1000
#define TMP_MAX      10000
#define BUFSIZ       4096

COSMOPOLITAN_C_START_

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct FILE;
typedef struct FILE FILE;

extern FILE *stdin;
extern FILE *stdout;
extern FILE *stderr;

errno_t ferror(FILE *) libcesque paramsnonnull();
void clearerr(FILE *) libcesque paramsnonnull();
int feof(FILE *) libcesque paramsnonnull();
int getc(FILE *) libcesque paramsnonnull();
int putc(int, FILE *) libcesque paramsnonnull();
int fflush(FILE *) libcesque;
int fpurge(FILE *) libcesque;
int fgetc(FILE *) libcesque paramsnonnull();
char *fgetln(FILE *, size_t *) libcesque paramsnonnull((1));
int ungetc(int, FILE *) libcesque paramsnonnull();
int fileno(FILE *) libcesque paramsnonnull() nosideeffect;
int fputc(int, FILE *) libcesque paramsnonnull();
int fputs(const char *, FILE *) libcesque paramsnonnull();
int fputws(const wchar_t *, FILE *) libcesque paramsnonnull();
void flockfile(FILE *) libcesque paramsnonnull();
void funlockfile(FILE *) libcesque paramsnonnull();
int ftrylockfile(FILE *) libcesque paramsnonnull();
char *fgets(char *, int, FILE *) libcesque paramsnonnull();
wchar_t *fgetws(wchar_t *, int, FILE *) libcesque paramsnonnull();
wint_t putwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t fputwc(wchar_t, FILE *) libcesque paramsnonnull();
wint_t putwchar(wchar_t) libcesque;
wint_t getwchar(void) libcesque;
wint_t getwc(FILE *) libcesque paramsnonnull();
wint_t fgetwc(FILE *) libcesque paramsnonnull();
wint_t ungetwc(wint_t, FILE *) libcesque paramsnonnull();
int getchar(void) libcesque;
int putchar(int) libcesque;
int puts(const char *) libcesque;
ssize_t getline(char **, size_t *, FILE *) libcesque paramsnonnull();
ssize_t getdelim(char **, size_t *, int, FILE *) libcesque paramsnonnull();
FILE *fopen(const char *, const char *) libcesque paramsnonnull((2)) __wur;
FILE *fdopen(int, const char *) libcesque paramsnonnull() __wur;
FILE *fmemopen(void *, size_t, const char *) libcesque paramsnonnull((3)) __wur;
FILE *freopen(const char *, const char *, FILE *) paramsnonnull((2, 3));
size_t fread(void *, size_t, size_t, FILE *) libcesque paramsnonnull((4));
size_t fwrite(const void *, size_t, size_t, FILE *) paramsnonnull((4));
int fclose(FILE *) libcesque;
int fseek(FILE *, long, int) libcesque paramsnonnull();
long ftell(FILE *) libcesque paramsnonnull();
int fseeko(FILE *, int64_t, int) libcesque paramsnonnull();
int64_t ftello(FILE *) libcesque paramsnonnull();
void rewind(FILE *) libcesque paramsnonnull();
int fopenflags(const char *) libcesque paramsnonnull();
void setlinebuf(FILE *) libcesque;
void setbuf(FILE *, char *) libcesque;
void setbuffer(FILE *, char *, size_t) libcesque;
int setvbuf(FILE *, char *, int, size_t) libcesque;
int pclose(FILE *) libcesque;
char *ctermid(char *) libcesque;
void perror(const char *) libcesque relegated;

typedef uint64_t fpos_t;
char *gets(char *) libcesque paramsnonnull();
int fgetpos(FILE *, fpos_t *) libcesque paramsnonnull();
int fsetpos(FILE *, const fpos_t *) libcesque paramsnonnull();

FILE *tmpfile(void) libcesque __wur;
char *tmpnam(char *) libcesque __wur;
char *tmpnam_r(char *) libcesque __wur;

FILE *popen(const char *, const char *) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » formatting                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int printf(const char *, ...) printfesque(1) paramsnonnull((1)) libcesque;
int vprintf(const char *, va_list) paramsnonnull() libcesque;
int fprintf(FILE *, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vfprintf(FILE *, const char *, va_list) paramsnonnull() libcesque;
int scanf(const char *, ...) libcesque scanfesque(1);
int vscanf(const char *, va_list) libcesque;
int fscanf(FILE *, const char *, ...) libcesque scanfesque(2);
int vfscanf(FILE *, const char *, va_list) libcesque;

int snprintf(char *, size_t, const char *, ...) printfesque(3) libcesque;
int vsnprintf(char *, size_t, const char *, va_list) libcesque;
int sprintf(char *, const char *, ...) libcesque;
int vsprintf(char *, const char *, va_list) libcesque;

int fwprintf(FILE *, const wchar_t *, ...) libcesque;
int fwscanf(FILE *, const wchar_t *, ...) libcesque;
int swprintf(wchar_t *, size_t, const wchar_t *, ...) libcesque;
int swscanf(const wchar_t *, const wchar_t *, ...) libcesque;
int vfwprintf(FILE *, const wchar_t *, va_list) libcesque;
int vfwscanf(FILE *, const wchar_t *, va_list) libcesque;
int vswprintf(wchar_t *, size_t, const wchar_t *, va_list) libcesque;
int vswscanf(const wchar_t *, const wchar_t *, va_list) libcesque;
int vwprintf(const wchar_t *, va_list) libcesque;
int vwscanf(const wchar_t *, va_list) libcesque;
int wprintf(const wchar_t *, ...) libcesque;
int wscanf(const wchar_t *, ...) libcesque;
int fwide(FILE *, int) libcesque;

int sscanf(const char *, const char *, ...) libcesque scanfesque(2);
int vsscanf(const char *, const char *, va_list) libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » allocating                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int asprintf(char **, const char *, ...) printfesque(2)
    paramsnonnull((1, 2)) libcesque;
int vasprintf(char **, const char *, va_list) paramsnonnull() libcesque;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § standard i/o » without mutexes                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int getc_unlocked(FILE *) libcesque paramsnonnull();
int puts_unlocked(const char *) libcesque;
int getchar_unlocked(void) libcesque;
int putc_unlocked(int, FILE *) libcesque paramsnonnull();
int putchar_unlocked(int) libcesque;
void clearerr_unlocked(FILE *) libcesque;
int feof_unlocked(FILE *) libcesque;
int ferror_unlocked(FILE *) libcesque;
int fileno_unlocked(FILE *) libcesque;
int fflush_unlocked(FILE *) libcesque;
int fgetc_unlocked(FILE *) libcesque;
int fputc_unlocked(int, FILE *) libcesque;
size_t fread_unlocked(void *, size_t, size_t, FILE *) libcesque;
size_t fwrite_unlocked(const void *, size_t, size_t, FILE *) libcesque;
char *fgets_unlocked(char *, int, FILE *) libcesque;
int fputs_unlocked(const char *, FILE *) libcesque;
wint_t getwc_unlocked(FILE *) libcesque;
wint_t getwchar_unlocked(void) libcesque;
wint_t fgetwc_unlocked(FILE *) libcesque;
wint_t fputwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwc_unlocked(wchar_t, FILE *) libcesque;
wint_t putwchar_unlocked(wchar_t) libcesque;
wchar_t *fgetws_unlocked(wchar_t *, int, FILE *) libcesque;
int fputws_unlocked(const wchar_t *, FILE *) libcesque;
wint_t ungetwc_unlocked(wint_t, FILE *) libcesque paramsnonnull();
int ungetc_unlocked(int, FILE *) libcesque paramsnonnull();
int fseek_unlocked(FILE *, int64_t, int) libcesque paramsnonnull();
ssize_t getdelim_unlocked(char **, size_t *, int, FILE *) paramsnonnull();
int fprintf_unlocked(FILE *, const char *, ...) printfesque(2) libcesque;
int vfprintf_unlocked(FILE *, const char *, va_list) paramsnonnull() libcesque;

COSMOPOLITAN_C_END_

#define kLogFatal   0
#define kLogError   1
#define kLogWarn    2
#define kLogInfo    3
#define kLogVerbose 4
#define kLogDebug   5
#define kLogNoise   6

/**
 * Log level for compile-time DCE.
 */
#ifndef LOGGABLELEVEL
#ifndef TINY
#define LOGGABLELEVEL kLogNoise
/* #elif IsTiny() */
/* #define LOGGABLELEVEL kLogInfo */
#else
#define LOGGABLELEVEL kLogVerbose
#endif
#endif

#ifdef TINY
#define _LOG_TINY 1
#else
#define _LOG_TINY 0
#endif

COSMOPOLITAN_C_START_

extern FILE *__log_file;

int __watch(void *, size_t);
void __die(void) relegated wontreturn; /* print backtrace and abort() */
void _meminfo(int);                    /* shows malloc statistics &c. */
void _memsummary(int);                 /* light version of same thing */
const char *commandvenv(const char *, const char *);
const char *GetAddr2linePath(void);
const char *GetGdbPath(void);
bool32 IsDebuggerPresent(bool32);
bool32 IsRunningUnderMake(void);
char *GetSymbolByAddr(int64_t);
void PrintGarbage(void);
void PrintGarbageNumeric(FILE *);
void PrintWindowsMemory(const char *, size_t);

#ifndef __STRICT_ANSI__

#define _LOG_UNLIKELY(x) __builtin_expect(!!(x), 0)

extern unsigned __log_level; /* log level for runtime check */

#define LOGGABLE(LEVEL)                                          \
  ((!__builtin_constant_p(LEVEL) || (LEVEL) <= LOGGABLELEVEL) && \
   (LEVEL) <= __log_level)

// log a message with the specified log level (not checking if LOGGABLE)
#define LOGF(LEVEL, FMT, ...)                                   \
  do {                                                          \
    if (!_LOG_TINY) _log_untrace();                             \
    flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    if (!_LOG_TINY) _log_retrace();                             \
  } while (0)

// report an error without backtrace and debugger invocation
#define FATALF(FMT, ...)                                            \
  do {                                                              \
    if (!_LOG_TINY) _log_untrace();                                 \
    flogf(kLogError, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                   \
  } while (0)

#define DIEF(FMT, ...)                                                \
  do {                                                                \
    if (!_LOG_TINY) _log_untrace();                                   \
    ffatalf(kLogFatal, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
    __builtin_unreachable();                                          \
  } while (0)

#define ERRORF(FMT, ...)                   \
  do {                                     \
    if (LOGGABLE(kLogError)) {             \
      LOGF(kLogError, FMT, ##__VA_ARGS__); \
    }                                      \
  } while (0)

#define WARNF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogWarn)) {             \
      LOGF(kLogWarn, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define INFOF(FMT, ...)                   \
  do {                                    \
    if (LOGGABLE(kLogInfo)) {             \
      LOGF(kLogInfo, FMT, ##__VA_ARGS__); \
    }                                     \
  } while (0)

#define VERBOSEF(FMT, ...)                                                  \
  do {                                                                      \
    if (LOGGABLE(kLogVerbose)) {                                            \
      if (!_LOG_TINY) _log_untrace();                                       \
      fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                       \
    }                                                                       \
  } while (0)

#define DEBUGF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fdebugf(kLogDebug, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define NOISEF(FMT, ...)                                                \
  do {                                                                  \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                           \
      if (!_LOG_TINY) _log_untrace();                                   \
      fnoisef(kLogNoise, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                   \
    }                                                                   \
  } while (0)

#define FLOGF(F, FMT, ...)                                        \
  do {                                                            \
    if (LOGGABLE(kLogInfo)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogInfo, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FWARNF(F, FMT, ...)                                       \
  do {                                                            \
    if (LOGGABLE(kLogWarn)) {                                     \
      if (!_LOG_TINY) _log_untrace();                             \
      flogf(kLogWarn, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                             \
    }                                                             \
  } while (0)

#define FFATALF(F, FMT, ...)                                     \
  do {                                                           \
    if (!_LOG_TINY) _log_untrace();                              \
    flogf(kLogError, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
    _log_exit(1);                                                \
  } while (0)

#define FDEBUGF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogDebug))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fdebugf(kLogDebug, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define FNOISEF(F, FMT, ...)                                         \
  do {                                                               \
    if (_LOG_UNLIKELY(LOGGABLE(kLogNoise))) {                        \
      if (!_LOG_TINY) _log_untrace();                                \
      fnoisef(kLogNoise, __FILE__, __LINE__, F, FMT, ##__VA_ARGS__); \
      if (!_LOG_TINY) _log_retrace();                                \
    }                                                                \
  } while (0)

#define LOGIFNEG1(FORM)                                                \
  ({                                                                   \
    int e = _log_get_errno();                                          \
    autotype(FORM) Ax = (FORM);                                        \
    if (_LOG_UNLIKELY(Ax == (typeof(Ax))(-1)) && LOGGABLE(kLogWarn)) { \
      if (!_LOG_TINY) _log_untrace();                                  \
      _log_errno(__FILE__, __LINE__, #FORM);                           \
      if (!_LOG_TINY) _log_retrace();                                  \
      _log_set_errno(e);                                               \
    }                                                                  \
    Ax;                                                                \
  })

#define LOGIFNULL(FORM)                      \
  ({                                         \
    int e = _log_get_errno();                \
    autotype(FORM) Ax = (FORM);              \
    if (Ax == NULL && LOGGABLE(kLogWarn)) {  \
      if (!_LOG_TINY) _log_untrace();        \
      _log_errno(__FILE__, __LINE__, #FORM); \
      if (!_LOG_TINY) _log_retrace();        \
      _log_set_errno(e);                     \
    }                                        \
    Ax;                                      \
  })

void _log_errno(const char *, int, const char *) relegated;
int _log_get_errno(void);
void _log_set_errno(int);
void _log_untrace(void);
void _log_retrace(void);
void _log_exit(int) wontreturn;

#define ARGS  unsigned, const char *, int, FILE *, const char *
#define ATTR  paramsnonnull((5)) printfesque(5)
#define ATTRV paramsnonnull((5))
void flogf(ARGS, ...) ATTR libcesque;
void vflogf(ARGS, va_list) ATTRV libcesque;
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfverbosef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fdebugf(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfdebugf(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fnoisef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfnoisef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void ffatalf(ARGS, ...) asm("flogf") ATTR relegated wontreturn libcesque;
void vffatalf(ARGS, va_list) asm("vflogf") ATTRV relegated wontreturn libcesque;
#undef ARGS
#undef ATTR
#undef ATTRV

#endif /* __STRICT_ANSI__ */
COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_LOG_LOG_H_ */


/*!BEGIN libc/log/traceme.h */

#define COSMOPOLITAN_LIBC_LOG_TRACEME_H_
COSMOPOLITAN_C_START_

extern int traceme;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alg.h */

#define COSMOPOLITAN_LIBC_ALG_ALG_H_
COSMOPOLITAN_C_START_

void *bsearch(const void *, const void *, size_t, size_t,
              int (*)(const void *, const void *)) paramsnonnull() nosideeffect;
void *bsearch_r(const void *, const void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 2, 5)) nosideeffect;
void djbsort(int32_t *, size_t) libcesque;
void qsort3(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort(void *, size_t, size_t, int (*)(const void *, const void *))
    paramsnonnull();
void qsort_r(void *, size_t, size_t,
             int (*)(const void *, const void *, void *), void *)
    paramsnonnull((1, 4));
void smoothsort(void *, size_t, size_t, int (*)(const void *, const void *));
void smoothsort_r(void *, size_t, size_t,
                  int (*)(const void *, const void *, void *), void *);
int heapsort(void *, size_t, size_t, int (*)(const void *, const void *));
int heapsort_r(void *, size_t, size_t,
               int (*)(const void *, const void *, void *), void *);
int mergesort(void *, size_t, size_t, int (*)(const void *, const void *));
int mergesort_r(void *, size_t, size_t,
                int (*)(const void *, const void *, void *), void *);

int radix_sort_int32(int32_t *, size_t) libcesque;
int radix_sort_int64(int64_t *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/alloca.h */

#define COSMOPOLITAN_LIBC_MEM_ALLOCA_H_

#define alloca(size) __builtin_alloca(size)



/*!BEGIN libc/mem/critbit0.h */

#define COSMOPOLITAN_LIBC_ALG_CRITBIT0_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § data structures » critical bit tree (for c strings)       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

struct critbit0 {
  void *root;
  size_t count;
};

bool critbit0_contains(struct critbit0 *, const char *) libcesque nosideeffect
    paramsnonnull();
int critbit0_insert(struct critbit0 *, const char *) paramsnonnull();
bool critbit0_delete(struct critbit0 *, const char *) libcesque paramsnonnull();
void critbit0_clear(struct critbit0 *) libcesque paramsnonnull();
char *critbit0_get(struct critbit0 *, const char *);
intptr_t critbit0_allprefixed(struct critbit0 *, const char *,
                              intptr_t (*)(const char *, void *), void *)
    paramsnonnull((1, 2, 3)) libcesque;
int critbit0_emplace(struct critbit0 *, const void *, size_t) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/mem/gc.h */

#ifndef COSMOPOLITAN_LIBC_MEM_GC_H_
#define COSMOPOLITAN_LIBC_MEM_GC_H_
COSMOPOLITAN_C_START_

libcesque void _gc_free(void *);
libcesque void __defer(void *, void *, void *);
libcesque void gclongjmp(void *, int) wontreturn;
#define gc(THING)  defer((void *)_gc_free, (void *)(THING))
#define _gc(THING) defer((void *)_gc_free, (void *)(THING))
#define defer(FN, ARG)                             \
  ({                                               \
    autotype(ARG) Arg = (ARG);                     \
    /* prevent weird opts like tail call */        \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    __defer(__builtin_frame_address(0), FN, Arg);  \
    __asm__ volatile("" : "+g"(Arg) : : "memory"); \
    Arg;                                           \
  })

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_MEM_GC_H_ */


/*!BEGIN libc/mem/mem.h */

#define COSMOPOLITAN_LIBC_MEM_MEM_H_

#define M_TRIM_THRESHOLD (-1)
#define M_GRANULARITY    (-2)
#define M_MMAP_THRESHOLD (-3)

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § dynamic memory                                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

void free(void *) libcesque;
void *malloc(size_t) attributeallocsize((1)) mallocesque;
void *calloc(size_t, size_t) attributeallocsize((1, 2)) mallocesque;
void *memalign(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
void *realloc(void *, size_t) reallocesque;
void *realloc_in_place(void *, size_t) reallocesque;
void *reallocarray(void *, size_t, size_t) __wur;
void *valloc(size_t) attributeallocsize((1)) vallocesque;
void *pvalloc(size_t) vallocesque;
char *strdup(const char *) paramsnonnull() mallocesque;
char *strndup(const char *, size_t) paramsnonnull() mallocesque;
void *aligned_alloc(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2)) returnspointerwithnoaliases libcesque __wur;
int posix_memalign(void **, size_t, size_t) libcesque;

int mallopt(int, int) libcesque;
int malloc_trim(size_t) libcesque;
size_t bulk_free(void **, size_t) libcesque;
size_t malloc_usable_size(void *) libcesque;
void **independent_calloc(size_t, size_t, void **) libcesque;
void **independent_comalloc(size_t, size_t *, void **) libcesque;

wchar_t *wcsdup(const wchar_t *) strlenesque __wur;

struct mallinfo {
  size_t arena;    /* non-mmapped space allocated from system */
  size_t ordblks;  /* number of free chunks */
  size_t smblks;   /* always 0 */
  size_t hblks;    /* always 0 */
  size_t hblkhd;   /* space in mmapped regions */
  size_t usmblks;  /* maximum total allocated space */
  size_t fsmblks;  /* always 0 */
  size_t uordblks; /* total allocated space */
  size_t fordblks; /* total free space */
  size_t keepcost; /* releasable (via malloc_trim) space */
};

struct mallinfo mallinfo(void) libcesque;

size_t malloc_footprint(void) libcesque;
size_t malloc_max_footprint(void) libcesque;
size_t malloc_footprint_limit(void) libcesque;
size_t malloc_set_footprint_limit(size_t) libcesque;
void malloc_inspect_all(void (*)(void *, void *, size_t, void *), void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/cachesize.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CACHESIZE_H_

#define kCpuCacheTypeData        1
#define kCpuCacheTypeInstruction 2
#define kCpuCacheTypeUnified     3

COSMOPOLITAN_C_START_

unsigned _getcachesize(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/crc32.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_CRC32_H_
COSMOPOLITAN_C_START_

extern const uint32_t kCrc32cTab[256];

void crc32init(uint32_t[hasatleast 256], uint32_t);
uint32_t crc32c(uint32_t, const void *, size_t) nosideeffect;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/ffs.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_FFS_H_
COSMOPOLITAN_C_START_

int ffs(int) pureconst;
int ffsl(long) pureconst;
int ffsll(long long) pureconst;

#ifdef __GNUC__
#define ffs(u)   __builtin_ffs(u)
#define ffsl(u)  __builtin_ffsl(u)
#define ffsll(u) __builtin_ffsll(u)
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/kompressor.h */

#define COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
#ifdef _COSMO_SOURCE

#define rldecode  __rldecode
#define rldecode2 __rldecode2
#define lz4check  __lz4check
#define lz4cpy    __lz4cpy
#define lz4len    __lz4len
#define lz4decode __lz4decode

COSMOPOLITAN_C_START_

struct RlDecode {
  uint8_t repititions;
  uint8_t byte;
};

void rldecode(void *dest, const struct RlDecode *);
void rldecode2(void *dest, const struct RlDecode *);
const uint8_t *lz4check(const void *data);
void *lz4cpy(void *dest, const void *blockdata, size_t blocksize);
size_t lz4len(const void *blockdata, size_t blocksize);
void *lz4decode(void *dest, const void *src);

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/nexgen32e/lz4.h */

#define COSMOPOLITAN_LIBC_LZ4_H_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4                                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  LZ4 is a brilliant framing format for REP MOVSB designed by Yann Collet.

  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md
  @see https://github.com/lz4/lz4/blob/master/doc/lz4_Block_format.md
  @see http://ticki.github.io/blog/how-lz4-works/ */

#define LZ4_EOF                0
#define LZ4_VERSION            1
#define LZ4_MAGICNUMBER        0x184D2204
#define LZ4_SKIPPABLE0         0x184D2A50
#define LZ4_SKIPPABLEMASK      0xFFFFFFF0
#define LZ4_MAXHEADERSIZE      (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1)
#define LZ4_BLOCKMAXSIZE_64KB  4
#define LZ4_BLOCKMAXSIZE_256KB 5
#define LZ4_BLOCKMAXSIZE_1MB   6
#define LZ4_BLOCKMAXSIZE_4MB   7

COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » frames                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_MAGIC(FRAME)                      READ32LE(FRAME)
#define LZ4_FRAME_VERSION(FRAME)              ((_LZ4_FRAME_FLG(FRAME) >> 6) & 3)
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME)    ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
#define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1)
#define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \
  ((_LZ4_FRAME_FLG(FRAME) >> 2) & 1)
#define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1)
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME)     ((_LZ4_FRAME_BD(FRAME) >> 4) & 7)
#define LZ4_FRAME_RESERVED1(FRAME)        ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
#define LZ4_FRAME_RESERVED2(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
#define LZ4_FRAME_RESERVED3(FRAME)        ((_LZ4_FRAME_BD(FRAME) >> 0) & 15)
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
  (LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? READ64LE((FRAME) + 4 + 1 + 1) : 0)
#define LZ4_FRAME_DICTIONARYID(FRAME)                          \
  (LZ4_FRAME_DICTIONARYIDFLAG(FRAME)                           \
       ? READ32LE(((FRAME) + 4 + 1 + 1 +                       \
                   8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME))) \
       : 0)
#define LZ4_FRAME_HEADERCHECKSUM(FRAME)                                \
  (*((FRAME) + 4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
     4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME)))
#define LZ4_FRAME_HEADERSIZE(FRAME)                        \
  (4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
   4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME) + 1)
#define _LZ4_FRAME_FLG(FRAME) (*((FRAME) + 4))
#define _LZ4_FRAME_BD(FRAME)  (*((FRAME) + 5))

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § lz4 » blocks                                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define LZ4_BLOCK_DATA(block)         (block + sizeof(uint32_t))
#define LZ4_BLOCK_DATASIZE(block)     (READ32LE(block) & 0x7fffffff)
#define LZ4_BLOCK_ISEOF(block)        (READ32LE(block) == LZ4_EOF)
#define LZ4_BLOCK_ISCOMPRESSED(block) ((READ32LE(block) & 0x80000000) == 0)
#define LZ4_BLOCK_SIZE(frame, block)              \
  (sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \
   (LZ4_FRAME_BLOCKCHECKSUMFLAG(frame) ? sizeof(uint8_t) : 0))

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nexgen32e.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NEXGEN32E_H_
COSMOPOLITAN_C_START_

extern long kHalfCache3;
extern const uint64_t kTens[20];
extern const uint32_t kSha256[64];
extern const uint64_t kSha512[80];
extern const unsigned char kTensIndex[64];

void CheckStackIsAligned(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/nt2sysv.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_NT2SYSV_H_


/*!BEGIN libc/nexgen32e/trampoline.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_

#define TRAMPOLINE(FUNCTION, THUNK)   \
  ({                                  \
    typeof(FUNCTION) *Tramp;          \
    asm(".section .text.trampoline\n" \
        "183:\n\t"                    \
        "mov\t%1,%%eax\n\t"           \
        "jmp\t" #THUNK "\n\t"         \
        ".previous\n\t"               \
        "mov\t$183b,%k0"              \
        : "=r"(Tramp)                 \
        : "i"(FUNCTION));             \
    Tramp;                            \
  })


/**
 * Creates function to thunk FUNCTION from MSX64 to System V ABI.
 *
 * This macro should be used when specifying callbacks in the WIN32 API.
 */
#define NT2SYSV(FUNCTION) TRAMPOLINE(FUNCTION, __nt2sysv)



/*!BEGIN libc/nexgen32e/rdtscp.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_RDTSCP_H_
COSMOPOLITAN_C_START_

#define TSC_AUX_CORE(MSR) ((MSR) & 0xfff)
#define TSC_AUX_NODE(MSR) (((MSR) >> 12) & 0xfff)

/**
 * Reads CPU timestamp counter and IA32_TSC_AUX.
 *
 * This macro inhibits compiler magic.
 * This macro does not inhibit CPU magic.
 *
 * @see X86_HAVE(RDTSCP)
 */
#define rdtscp(OPT_OUT_IA32_TSC_AUX)               \
  ({                                               \
    uint64_t Rax, Rdx;                             \
    uint32_t Ecx, *EcxOut;                         \
    asm volatile("rdtscp"                          \
                 : "=a"(Rax), "=c"(Ecx), "=d"(Rdx) \
                 : /* no inputs */                 \
                 : "memory");                      \
    EcxOut = (OPT_OUT_IA32_TSC_AUX);               \
    if (EcxOut) *EcxOut = Ecx;                     \
    Rdx << 32 | Rax;                               \
  })

/**
 * Reads timestamp counter auxiliary model specific register value.
 */
#define rdpid()                                                           \
  ({                                                                      \
    long Msr;                                                             \
    bool32 Ok;                                                            \
    Ok = false;                                                           \
    if (X86_HAVE(RDPID)) {                                                \
      asm volatile("rdpid\t%0" : "=r"(Msr) : /* no inputs */ : "memory"); \
      Ok = true;                                                          \
    } else if (IsLinux()) {                                               \
      char *p = (char *)0x7b;                                             \
      asm volatile(ZFLAG_ASM("lsl\t%2,%1")                                \
                   : ZFLAG_CONSTRAINT(Ok), "=r"(Msr)                      \
                   : "r"(p)                                               \
                   : "memory");                                           \
    }                                                                     \
    if (!Ok && X86_HAVE(RDTSCP)) {                                        \
      asm volatile("rdtscp"                                               \
                   : "=c"(Msr)                                            \
                   : /* no inputs */                                      \
                   : "eax", "edx", "memory");                             \
      Ok = true;                                                          \
    }                                                                     \
    if (!Ok) {                                                            \
      Msr = -1;                                                           \
    }                                                                     \
    Msr;                                                                  \
  })

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/sha.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_SHA_H_
COSMOPOLITAN_C_START_

void sha1_transform_avx2(uint32_t[hasatleast 5], const void *, unsigned);
void sha1_transform_ni(uint32_t[hasatleast 5], const void *, unsigned);
void sha256_transform_rorx(uint32_t[hasatleast 8], const void *, unsigned);
void sha256_transform_ni(uint32_t[hasatleast 8], const void *, unsigned);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nexgen32e/stackframe.h */

#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
#define COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_
COSMOPOLITAN_C_START_

struct StackFrame {
  struct StackFrame *next;
  intptr_t addr;
};

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_STACKFRAME_H_ */


/*!BEGIN libc/nexgen32e/x86info.h */

#define COSMOPOLITAN_LIBC_NEXGEN32E_X86INFO_H_

#define kX86CpuStepping    ((KCPUIDS(1H, EAX) >> 0) & 15)
#define kX86CpuModelid     ((KCPUIDS(1H, EAX) >> 4) & 15)
#define kX86CpuFamilyid    ((KCPUIDS(1H, EAX) >> 8) & 15)
#define kX86CpuType        ((KCPUIDS(1H, EAX) >> 12) & 3)
#define kX86CpuExtmodelid  ((KCPUIDS(1H, EAX) >> 16) & 15)
#define kX86CpuExtfamilyid ((KCPUIDS(1H, EAX) >> 20) & 255)

#define kX86CpuFamily \
  (kX86CpuFamilyid + (kX86CpuFamilyid == 15 ? kX86CpuExtfamilyid : 0))

#define kX86CpuModel                                                       \
  (kX86CpuModelid |                                                        \
   (kX86CpuFamilyid == 6 || kX86CpuFamilyid == 15 ? kX86CpuExtmodelid : 0) \
       << 4)

#define kX86ProcessorModelKey                                                 \
  (kX86CpuExtfamilyid << 12 | kX86CpuFamilyid << 8 | kX86CpuExtmodelid << 4 | \
   kX86CpuModelid)

#define X86_MARCH_UNKNOWN        0
#define X86_MARCH_CORE2          1
#define X86_MARCH_NEHALEM        2
#define X86_MARCH_WESTMERE       3
#define X86_MARCH_SANDYBRIDGE    4
#define X86_MARCH_IVYBRIDGE      5
#define X86_MARCH_HASWELL        6
#define X86_MARCH_BROADWELL      7
#define X86_MARCH_SKYLAKE        8
#define X86_MARCH_KABYLAKE       9
#define X86_MARCH_CANNONLAKE     10
#define X86_MARCH_ICELAKE        11
#define X86_MARCH_TIGERLAKE      12
#define X86_MARCH_BONNELL        13
#define X86_MARCH_SALTWELL       14
#define X86_MARCH_SILVERMONT     15
#define X86_MARCH_AIRMONT        16
#define X86_MARCH_GOLDMONT       17
#define X86_MARCH_GOLDMONTPLUS   18
#define X86_MARCH_TREMONT        19
#define X86_MARCH_KNIGHTSLANDING 20
#define X86_MARCH_KNIGHTSMILL    21
#define X86_MARCH_SAPPHIRERAPIDS 22
#define X86_MARCH_ALDERLAKE      23
#define X86_MARCH_COMETLAKE      24
#define X86_MARCH_RAPTORLAKE     25
#define X86_MARCH_ROCKETLAKE     26

#define X86_GRADE_UNKNOWN   0
#define X86_GRADE_APPLIANCE 1
#define X86_GRADE_MOBILE    2
#define X86_GRADE_TABLET    3
#define X86_GRADE_DESKTOP   4
#define X86_GRADE_CLIENT    5
#define X86_GRADE_DENSITY   6
#define X86_GRADE_SERVER    7
#define X86_GRADE_SCIENCE   8

struct X86ProcessorModel {
  short key;
  unsigned char march;
  unsigned char grade;
};

extern const size_t kX86ProcessorModelCount;
extern const struct X86ProcessorModel kX86ProcessorModels[];

const struct X86ProcessorModel *getx86processormodel(short) nosideeffect;



/*!BEGIN libc/nt/enum/accessmask.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ACCESSMASK_H_

#define kNtGenericRead            0x80000000u
#define kNtGenericWrite           0x40000000u
#define kNtGenericExecute         0x20000000u
#define kNtGenericAll             0x10000000u
#define kNtDelete                 0x00010000u
#define kNtReadControl            0x00020000u
#define kNtWriteDac               0x00040000u
#define kNtWriteOwner             0x00080000u
#define kNtSynchronize            0x00100000u
#define kNtStandardRightsRequired 0x000F0000u
#define kNtStandardRightsRead     kNtReadControl
#define kNtStandardRightsWrite    kNtReadControl
#define kNtStandardRightsExecute  kNtReadControl
#define kNtStandardRightsAll      0x001F0000u
#define kNtSpecificRightsAll      0x0000FFFFu
#define kNtAccessSystemSecurity   0x01000000u
#define kNtMaximumAllowed         0x02000000u
#define kNtFileReadData           0x0001u
#define kNtFileListDirectory      0x0001u
#define kNtFileWriteData          0x0002u
#define kNtFileAddFile            0x0002u
#define kNtFileAppendData         0x0004u
#define kNtFileAddSubdirectory    0x0004u
#define kNtFileCreatePipeInstance 0x0004u
#define kNtFileReadEa             0x0008u
#define kNtFileWriteEa            0x0010u
#define kNtFileExecute            0x0020u
#define kNtFileTraverse           0x0020u
#define kNtFileDeleteChild        0x0040u
#define kNtFileReadAttributes     0x0080u
#define kNtFileWriteAttributes    0x0100u
#define kNtFileAllAccess          (kNtStandardRightsRequired | kNtSynchronize | 0x1FFu)
#define kNtFileGenericRead                                           \
  (kNtStandardRightsRead | kNtFileReadData | kNtFileReadAttributes | \
   kNtFileReadEa | kNtSynchronize)
#define kNtFileGenericWrite                                             \
  (kNtStandardRightsWrite | kNtFileWriteData | kNtFileWriteAttributes | \
   kNtFileWriteEa | kNtFileAppendData | kNtSynchronize)
#define kNtFileGenericExecute                                          \
  (kNtStandardRightsExecute | kNtFileReadAttributes | kNtFileExecute | \
   kNtSynchronize)
#define kNtTokenAssignPrimary    0x0001u
#define kNtTokenDuplicate        0x0002u
#define kNtTokenImpersonate      0x0004u
#define kNtTokenQuery            0x0008u
#define kNtTokenQuerySource      0x0010u
#define kNtTokenAdjustPrivileges 0x0020u
#define kNtTokenAdjustGroups     0x0040u
#define kNtTokenAdjustDefault    0x0080u
#define kNtTokenAdjustSessionid  0x0100u
#define kNtTokenAllAccessP                                                 \
  (kNtStandardRightsRequired | kNtTokenAssignPrimary | kNtTokenDuplicate | \
   kNtTokenImpersonate | kNtTokenQuery | kNtTokenQuerySource |             \
   kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | kNtTokenAdjustDefault)
#define kNtTokenAllAccess kNtTokenAllAccessP | kNtTokenAdjustSessionid
#define kNtTokenRead      kNtStandardRightsRead | kNtTokenQuery
#define kNtTokenWrite                                                         \
  (kNtStandardRightsWrite | kNtTokenAdjustPrivileges | kNtTokenAdjustGroups | \
   kNtTokenAdjustDefault)
#define kNtTokenExecute kNtStandardRightsExecute
#define kNtTokenTrustConstraintMask \
  (kNtStandardRightsRead | kNtTokenQuery | kNtTokenQuerySource)
#define kNtTokenAccessPseudoHandleWin8 kNtTokenQuery | kNtTokenQuerySource
#define kNtTokenAccessPseudoHandle     kNtTokenAccessPseudoHandleWin8



/*!BEGIN libc/nt/enum/afd.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_AFD_H_

#define kNtAfdPollReceive          0x0001
#define kNtAfdPollReceiveExpedited 0x0002
#define kNtAfdPollSend             0x0004
#define kNtAfdPollDisconnect       0x0008
#define kNtAfdPollAbort            0x0010
#define kNtAfdPollLocalClose       0x0020
#define kNtAfdPollAccept           0x0080
#define kNtAfdPollConnectFail      0x0100



/*!BEGIN libc/nt/enum/bitblt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_BITBLT_H_

#define kNtSrccopy     0x00CC0020u /* src */
#define kNtSrcpaint    0x00EE0086u /* src | dst */
#define kNtSrcand      0x008800C6u /* src & dst */
#define kNtSrcinvert   0x00660046u /* src ^ dst */
#define kNtSrcerase    0x00440328u /* src & ~dst */
#define kNtNotsrccopy  0x00330008u /* ~src */
#define kNtNotsrcerase 0x001100A6u /* ~src & ~dst */
#define kNtMergecopy   0x00C000CAu /* (src & pattern) */
#define kNtMergepaint  0x00BB0226u /* ~src | dst */
#define kNtPatcopy     0x00F00021u /* pat */
#define kNtPatpaint    0x00FB0A09u /* wut */
#define kNtPatinvert   0x005A0049u /* pat ^ dst */
#define kNtDstinvert   0x00550009u /* ~dst */
#define kNtBlackness   0x00000042u /* black */
#define kNtWhiteness   0x00FF0062u /* white */



/*!BEGIN libc/nt/enum/callback.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CALLBACK_H_

#define kNtCallbackChunkFinished 0
#define kNtCallbackStreamSwitch  1



/*!BEGIN libc/nt/enum/color.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COLOR_H_

#define kNtColorScrollbar               0
#define kNtColorBackground              1
#define kNtColorActivecaption           2
#define kNtColorInactivecaption         3
#define kNtColorMenu                    4
#define kNtColorWindow                  5
#define kNtColorWindowframe             6
#define kNtColorMenutext                7
#define kNtColorWindowtext              8
#define kNtColorCaptiontext             9
#define kNtColorActiveborder            10
#define kNtColorInactiveborder          11
#define kNtColorAppworkspace            12
#define kNtColorHighlight               13
#define kNtColorHighlighttext           14
#define kNtColorBtnface                 15
#define kNtColorBtnshadow               16
#define kNtColorGraytext                17
#define kNtColorBtntext                 18
#define kNtColorInactivecaptiontext     19
#define kNtColorBtnhighlight            20
#define kNtColor3ddkshadow              21
#define kNtColor3dlight                 22
#define kNtColorInfotext                23
#define kNtColorInfobk                  24
#define kNtColorHotlight                26
#define kNtColorGradientactivecaption   27
#define kNtColorGradientinactivecaption 28
#define kNtColorMenuhilight             29
#define kNtColorMenubar                 30



/*!BEGIN libc/nt/enum/computernameformat.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COMPUTERNAMEFORMAT_H_

#define kNtComputerNameNetBios                   0
#define kNtComputerNameDnsHostname               1
#define kNtComputerNameDnsDomain                 2
#define kNtComputerNameDnsFullyQualified         3
#define kNtComputerNamePhysicalNetBios           4
#define kNtComputerNamePhysicalDnsHostname       5
#define kNtComputerNamePhysicalDnsDomain         6
#define kNtComputerNamePhysicalDnsFullyQualified 7
#define kNtComputerName_MAX                      8



/*!BEGIN libc/nt/enum/consolemodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLEMODEFLAGS_H_

/* input mode */
#define kNtEnableProcessedInput 0x0001u
#define kNtEnableLineInput 0x0002u
#define kNtEnableEchoInput 0x0004u
#define kNtEnableWindowInput 0x0008u
#define kNtEnableMouseInput 0x0010u
#define kNtEnableInsertMode 0x0020u
#define kNtEnableQuickEditMode 0x0040u
#define kNtEnableExtendedFlags 0x0080u
#define kNtEnableAutoPosition 0x0100u
#define kNtEnableVirtualTerminalInput 0x0200u

/* output mode */
#define kNtEnableProcessedOutput 0x0001u
#define kNtEnableWrapAtEolOutput 0x0002u
#define kNtEnableVirtualTerminalProcessing 0x0004u
#define kNtDisableNewlineAutoReturn 0x0008u
#define kNtEnableLvbGridWorldwide 0x0010u



/*!BEGIN libc/nt/enum/consoleselectionflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONSOLESELECTIONFLAGS_H_

#define kNtConsoleNoSelection 0x0000u
#define kNtConsoleSelectionInProgress 0x0001u
#define kNtConsoleSelectionNotEmpty 0x0002u
#define kNtConsoleMouseSelection 0x0004u
#define kNtConsoleMouseDown 0x0008u



/*!BEGIN libc/nt/enum/context.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CONTEXT_H_

#define kNtContextAmd64 0x00100000

#define kNtContextControl        (kNtContextAmd64 | 0x00000001)
#define kNtContextInteger        (kNtContextAmd64 | 0x00000002)
#define kNtContextSegments       (kNtContextAmd64 | 0x00000004)
#define kNtContextFloatingPoint  (kNtContextAmd64 | 0x00000008)
#define kNtContextDebugRegisters (kNtContextAmd64 | 0x00000010)

#define kNtContextFull \
  (kNtContextControl | kNtContextInteger | kNtContextFloatingPoint)

#define kNtContextAll                                           \
  (kNtContextControl | kNtContextInteger | kNtContextSegments | \
   kNtContextFloatingPoint | kNtContextDebugRegisters)

#define kNtContextXstate (kNtContextAmd64 | 0x00000040)



/*!BEGIN libc/nt/enum/copyfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COPYFILE_H_

#define kNtCopyFileFailIfExists              0x00000001
#define kNtCopyFileRestartable               0x00000002
#define kNtCopyFileOpenSourceForWrite        0x00000004
#define kNtCopyFileAllowDecryptedDestination 0x00000008
#define kNtCopyFileCopySymlink               0x00000800
#define kNtCopyFileNoBuffering               0x00001000
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileResumeFromPause           0x00004000 /* Win8+ */
#define kNtCopyFileRequestSecurityPrivileges 0x00002000 /* Win8+ */
#define kNtCopyFileNoOffload                 0x00040000 /* Win8+ */
#define kNtCopyFileIgnoreEdpBlock            0x00400000 /* Win10+ */
#define kNtCopyFileIgnoreSourceEncryption    0x00800000 /* Win10+ */



/*!BEGIN libc/nt/enum/creationdisposition.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CREATIONDISPOSITION_H_

#define kNtCreateNew 1
#define kNtCreateAlways 2
#define kNtOpenExisting 3
#define kNtOpenAlways 4
#define kNtTruncateExisting 5



/*!BEGIN libc/nt/enum/cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CS_H_

#define kNtCsVredraw         0x00000001
#define kNtCsHredraw         0x00000002
#define kNtCsDblclks         0x00000008
#define kNtCsOwndc           0x00000020
#define kNtCsClassdc         0x00000040
#define kNtCsParentdc        0x00000080
#define kNtCsNoclose         0x00000200
#define kNtCsSavebits        0x00000800
#define kNtCsBytealignclient 0x00001000
#define kNtCsBytealignwindow 0x00002000
#define kNtCsGlobalclass     0x00004000
#define kNtCsIme             0x00010000
#define kNtCsDropshadow      0x00020000



/*!BEGIN libc/nt/enum/ctrlevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CTRLEVENT_H_

#define kNtCtrlCEvent 0      /* SIGINT */
#define kNtCtrlBreakEvent 1  /* SIGQUIT */
#define kNtCtrlCloseEvent 2  /* SIGHUP */
#define kNtCtrlLogoffEvent 5 /* SIGTERM */
#define kNtCtrlShutdownEvent 6



/*!BEGIN libc/nt/enum/cw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_CW_H_

#define kNtCwUsedefault ((int)0x80000000)



/*!BEGIN libc/nt/enum/dialogresult.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_DIALOGRESULT_H_

#define kNtIdok       1
#define kNtIdcancel   2
#define kNtIdabort    3
#define kNtIdretry    4
#define kNtIdignore   5
#define kNtIdyes      6
#define kNtIdno       7
#define kNtIdclose    8
#define kNtIdhelp     9
#define kNtIdtryagain 10
#define kNtIdcontinue 11



/*!BEGIN libc/nt/enum/errormodeflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_ERRORMODEFLAGS_H_

#define kNtErrorModeDefault      0x0
#define kNtSemFailcriticalerrors 0x1
#define kNtSemNogpfaulterrorbox  0x2
#define kNtSemNoopenfileerrorbox 0x8000



/*!BEGIN libc/nt/enum/event.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENT_H_

#define kNtEventSystemSound            0x0001
#define kNtEventSystemAlert            0x0002
#define kNtEventSystemForeground       0x0003
#define kNtEventSystemMenustart        0x0004
#define kNtEventSystemMenuend          0x0005
#define kNtEventSystemMenupopupstart   0x0006
#define kNtEventSystemMenupopupend     0x0007
#define kNtEventSystemCapturestart     0x0008
#define kNtEventSystemCaptureend       0x0009
#define kNtEventSystemMovesizestart    0x000A
#define kNtEventSystemMovesizeend      0x000B
#define kNtEventSystemContexthelpstart 0x000C
#define kNtEventSystemContexthelpend   0x000D
#define kNtEventSystemDragdropstart    0x000E
#define kNtEventSystemDragdropend      0x000F
#define kNtEventSystemDialogstart      0x0010
#define kNtEventSystemDialogend        0x0011
#define kNtEventSystemScrollingstart   0x0012
#define kNtEventSystemScrollingend     0x0013
#define kNtEventSystemSwitchstart      0x0014
#define kNtEventSystemSwitchend        0x0015
#define kNtEventSystemMinimizestart    0x0016
#define kNtEventSystemMinimizeend      0x0017

#define kNtEventConsoleCaret            0x4001
#define kNtEventConsoleUpdateRegion     0x4002
#define kNtEventConsoleUpdateSimple     0x4003
#define kNtEventConsoleUpdateScroll     0x4004
#define kNtEventConsoleLayout           0x4005
#define kNtEventConsoleStartApplication 0x4006
#define kNtEventConsoleEndApplication   0x4007

#define kNtEventObjectCreate            0x8000
#define kNtEventObjectDestroy           0x8001
#define kNtEventObjectShow              0x8002
#define kNtEventObjectHide              0x8003
#define kNtEventObjectReorder           0x8004
#define kNtEventObjectFocus             0x8005
#define kNtEventObjectSelection         0x8006
#define kNtEventObjectSelectionadd      0x8007
#define kNtEventObjectSelectionremove   0x8008
#define kNtEventObjectSelectionwithin   0x8009
#define kNtEventObjectStatechange       0x800A
#define kNtEventObjectLocationchange    0x800B
#define kNtEventObjectNamechange        0x800C
#define kNtEventObjectDescriptionchange 0x800D
#define kNtEventObjectValuechange       0x800E
#define kNtEventObjectParentchange      0x800F
#define kNtEventObjectHelpchange        0x8010
#define kNtEventObjectDefactionchange   0x8011
#define kNtEventObjectAcceleratorchange 0x8012



/*!BEGIN libc/nt/enum/eventtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EVENTTYPE_H_

#define kNtNotificationEvent    0
#define kNtSynchronizationEvent 1



/*!BEGIN libc/nt/enum/exceptionhandleractions.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_EXCEPTIONHANDLERACTIONS_H_

#define kNtExceptionExecuteHandler 0x1u
#define kNtExceptionContinueExecution 0xffffffffu
#define kNtExceptionContinueSearch 0x0u



/*!BEGIN libc/nt/enum/fileflagandattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEFLAGANDATTRIBUTES_H_

/**
 * MS-DOS File Attributes.
 *
 * @see GetFileInformationByHandle()
 * @see libc/sysv/consts.sh
 */
#define kNtFileAttributeReadonly    0x00000001u
#define kNtFileAttributeHidden      0x00000002u
#define kNtFileAttributeSystem      0x00000004u
#define kNtFileAttributeVolumelabel 0x00000008u
#define kNtFileAttributeDirectory   0x00000010u
#define kNtFileAttributeArchive     0x00000020u

/**
 * NT File Attributes.
 */
#define kNtFileAttributeDevice            0x00000040u
#define kNtFileAttributeNormal            0x00000080u
#define kNtFileAttributeTemporary         0x00000100u
#define kNtFileAttributeSparseFile        0x00000200u
#define kNtFileAttributeReparsePoint      0x00000400u
#define kNtFileAttributeCompressed        0x00000800u
#define kNtFileAttributeOffline           0x00001000u
#define kNtFileAttributeNotContentIndexed 0x00002000u
#define kNtFileAttributeEncrypted         0x00004000u

/**
 * NT File Flags.
 */
#define kNtFileFlagWriteThrough      0x80000000u
#define kNtFileFlagOverlapped        0x40000000u
#define kNtFileFlagNoBuffering       0x20000000u
#define kNtFileFlagRandomAccess      0x10000000u
#define kNtFileFlagSequentialScan    0x08000000u
#define kNtFileFlagDeleteOnClose     0x04000000u
#define kNtFileFlagBackupSemantics   0x02000000u
#define kNtFileFlagPosixSemantics    0x01000000u
#define kNtFileFlagOpenReparsePoint  0x00200000u
#define kNtFileFlagOpenNoRecall      0x00100000u
#define kNtFileFlagFirstPipeInstance 0x00080000u



/*!BEGIN libc/nt/enum/fileinfobyhandleclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFOBYHANDLECLASS_H_

#define kNtFileBasicInfo                  0 /* struct NtFileBasicInformation */
#define kNtFileStandardInfo               1 /* struct NtFileStandardInformation */
#define kNtFileNameInfo                   2 /* struct NtFileNameInformation */
#define kNtFileStreamInfo                 7 /* struct NtFileStreamInformation */
#define kNtFileCompressionInfo            8 /* struct NtFileCompressionInfo */
#define kNtFileAttributeTagInfo           9 /* struct NtFileAttributeTagInformation */
#define kNtFileIdBothDirectoryInfo        10
#define kNtFileIdBothDirectoryRestartInfo 11
#define kNtFileRemoteProtocolInfo         13
#define kNtFileFullDirectoryInfo          14 /* NtFileFullDirectoryInformation */
#define kNtFileFullDirectoryRestartInfo   15
#define kNtFileStorageInfo                16 /* win8+ */
#define kNtFileAlignmentInfo              17 /* win8+ */
#define kNtFileIdInfo                     18 /* win8+ */
#define kNtFileIdExtdDirectoryInfo        19 /* win8+ */
#define kNtFileIdExtdDirectoryRestartInfo 20 /* win8+ */

#define kNtFileRenameInfo         4
#define kNtFileDispositionInfo    5
#define kNtFileAllocationInfo     6
#define kNtFileEndOfFileInfo      7
#define kNtFileIoPriorityHintInfo 13
#define kNtFileDispositionInfoEx  22 /* win10+ */
#define kNtFileRenameInfoEx       23 /* win10+ */



/*!BEGIN libc/nt/enum/fileinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEINFORMATIONCLASS_H_

#define kNtFileDirectoryInformation 1 /*→ struct NtFileDirectoryInformation */
#define kNtFileFullDirectoryInformation 2 /*→ etc. */
#define kNtFileBothDirectoryInformation 3
#define kNtFileBasicInformation 4
#define kNtFileStandardInformation 5
#define kNtFileInternalInformation 6
#define kNtFileEaInformation 7
#define kNtFileAccessInformation 8
#define kNtFileNameInformation 9
#define kNtFileRenameInformation 10
#define kNtFileLinkInformation 11
#define kNtFileNamesInformation 12
#define kNtFileDispositionInformation 13
#define kNtFilePositionInformation 14
#define kNtFileFullEaInformation 15
#define kNtFileModeInformation 16
#define kNtFileAlignmentInformation 17
#define kNtFileAllInformation 18
#define kNtFileAllocationInformation 19
#define kNtFileEndOfFileInformation 20
#define kNtFileAlternateNameInformation 21
#define kNtFileStreamInformation 22
#define kNtFilePipeInformation 23
#define kNtFilePipeLocalInformation 24
#define kNtFilePipeRemoteInformation 25
#define kNtFileMailslotQueryInformation 26
#define kNtFileMailslotSetInformation 27
#define kNtFileCompressionInformation 28
#define kNtFileObjectIdInformation 29
#define kNtFileCompletionInformation 30
#define kNtFileMoveClusterInformation 31
#define kNtFileQuotaInformation 32
#define kNtFileReparsePointInformation 33
#define kNtFileNetworkOpenInformation 34
#define kNtFileAttributeTagInformation 35
#define kNtFileTrackingInformation 36
#define kNtFileIdBothDirectoryInformation 37
#define kNtFileIdFullDirectoryInformation 38
#define kNtFileValidDataLengthInformation 39
#define kNtFileShortNameInformation 40
#define kNtFileInformation_MAX 40



/*!BEGIN libc/nt/enum/filelockflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILELOCKFLAGS_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/filemapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMAPFLAGS_H_

#define kNtFileMapCopy           0x00000001u
#define kNtFileMapWrite          0x00000002u
#define kNtFileMapRead           0x00000004u
#define kNtFileMapExecute        0x00000020u
#define kNtFileMapReserve        0x80000000u
#define kNtFileMapTargetsInvalid 0x40000000u
#define kNtFileMapLargePages     0x20000000u



/*!BEGIN libc/nt/enum/filemovemethod.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILEMOVEMETHOD_H_

#define kNtFileBegin   0
#define kNtFileCurrent 1
#define kNtFileEnd     2



/*!BEGIN libc/nt/enum/filesharemode.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILESHAREFLAGS_H_

#define kNtFileShareExclusive 0x00000000u
#define kNtFileShareRead 0x00000001u
#define kNtFileShareWrite 0x00000002u
#define kNtFileShareDelete 0x00000004u



/*!BEGIN libc/nt/enum/filetype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FILETYPE_H_

#define kNtFileTypeUnknown 0x0000
#define kNtFileTypeDisk    0x0001 /* @see S_ISBLK() */
#define kNtFileTypeChar    0x0002 /* @see S_ISCHR() */
#define kNtFileTypePipe    0x0003 /* @see S_ISFIFO() */
#define kNtFileTypeRemote  0x8000 /* unused -MSDN */



/*!BEGIN libc/nt/enum/fillattribute.h */

#define COSMOPOLITAN_LIBC_NT_NTFILLATTRIBUTE_H_

#define kNtForegroundBlue 0x0001
#define kNtForegroundGreen 0x0002
#define kNtForegroundRed 0x0004
#define kNtForegroundIntensity 0x0008
#define kNtBackgroundBlue 0x0010
#define kNtBackgroundGreen 0x0020
#define kNtBackgroundRed 0x0040
#define kNtBackgroundIntensity 0x0080



/*!BEGIN libc/nt/enum/findexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXINFOLEVELS_H_

#define kNtFindExInfoStandard     0
#define kNtFindExInfoBasic        1
#define kNtFindExInfoMaxInfoLevel 2



/*!BEGIN libc/nt/enum/findexsearchops.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FINDEXSEARCHOPS_H_

#define kNtFindExSearchNameMatch          0
#define kNtFindExSearchLimitToDirectories 1
#define kNtFindExSearchLimitToDevices     2
#define kNtFindExSearchMaxSearchOp        3



/*!BEGIN libc/nt/enum/formatmessageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FORMATMESSAGEFLAGS_H_

#define kNtFormatMessageAllocateBuffer 0x100
#define kNtFormatMessageIgnoreInserts  0x200
#define kNtFormatMessageFromString     0x400
#define kNtFormatMessageFromHmodule    0x800
#define kNtFormatMessageFromSystem     0x1000
#define kNtFormatMessageArgumentArray  0x2000
#define kNtFormatMessageMaxWidthMask   0xff



/*!BEGIN libc/nt/enum/fsctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSCTL_H_

#define kNtFsctlDisableLocalBuffering   0x000902B8u
#define kNtFsctlFilePrefetch            0x00090120u
#define kNtFsctlFilesystemGetStatistics 0x00090060u
#define kNtFsctlGetCompression          0x0009003Cu
#define kNtFsctlGetNtfsFileRecord       0x00090068u
#define kNtFsctlGetNtfsVolumeData       0x00090064u
#define kNtFsctlQueryAllocatedRanges    0x000940CFu
#define kNtFsctlScrubData               0x000902B0u
#define kNtFsctlSetCompression          0x0009C040u
#define kNtFsctlSetSparse               0x000900C4u
#define kNtFsctlSetZeroData             0x000980C8u
#define kNtFsctlGetReparsePoint         0x000900a8u
#define kNtFsctlSetReparsePoint         0x000900a4u



/*!BEGIN libc/nt/enum/fsinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_FSINFORMATIONCLASS_H_

#define kNtFileFsVolumeInformation 1
#define kNtFileFsLabelInformation 2
#define kNtFileFsSizeInformation 3
#define kNtFileFsDeviceInformation 4
#define kNtFileFsAttributeInformation 5
#define kNtFileFsControlInformation 6
#define kNtFileFsFullSizeInformation 7
#define kNtFileFsObjectIdInformation 8
#define kNtFileFsDriverPathInformation 9
#define kNtFileFsInformation_MAX 10



/*!BEGIN libc/nt/enum/getfileexinfolevels.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_GETFILEEXINFOLEVELS_H_

#define kNtGetFileExInfoStandard 0



/*!BEGIN libc/nt/enum/heap.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HEAP_H_

#define kNtHeapNoSerialize        1
#define kNtHeapGenerateExceptions 4
#define kNtHeapZeroMemory         8
#define kNtHeapReallocInPlaceOnly 16



/*!BEGIN libc/nt/enum/ht.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_HT_H_

#define kNtHterror       -2
#define kNtHttransparent -1
#define kNtHtnowhere     0
#define kNtHtclient      1
#define kNtHtcaption     2
#define kNtHtsysmenu     3
#define kNtHtgrowbox     4
#define kNtHtsize        kNtHtgrowbox
#define kNtHtmenu        5
#define kNtHthscroll     6
#define kNtHtvscroll     7
#define kNtHtminbutton   8
#define kNtHtmaxbutton   9
#define kNtHtleft        10
#define kNtHtright       11
#define kNtHttop         12
#define kNtHttopleft     13
#define kNtHttopright    14
#define kNtHtbottom      15
#define kNtHtbottomleft  16
#define kNtHtbottomright 17
#define kNtHtborder      18
#define kNtHtreduce      kNtHtminbutton
#define kNtHtzoom        kNtHtmaxbutton
#define kNtHtsizefirst   kNtHtleft
#define kNtHtsizelast    kNtHtbottomright
#define kNtHtobject      19
#define kNtHtclose       20
#define kNtHthelp        21



/*!BEGIN libc/nt/enum/idc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IDC_H_
COSMOPOLITAN_C_START_

#define kNtIdcArrow    ((const char16_t *)32512)
#define kNtIdcIbeam    ((const char16_t *)32513)
#define kNtIdcWait     ((const char16_t *)32514)
#define kNtIdcCross    ((const char16_t *)32515)
#define kNtIdcUparrow  ((const char16_t *)32516)
#define kNtIdcSizenwse ((const char16_t *)32642)
#define kNtIdcSizenesw ((const char16_t *)32643)
#define kNtIdcSizewe   ((const char16_t *)32644)
#define kNtIdcSizens   ((const char16_t *)32645)
#define kNtIdcSizeall  ((const char16_t *)32646)
#define kNtIdcNo       ((const char16_t *)32648)
#define kNtIdcHand     ((const char16_t *)32649)
#define kNtIdcHelp     ((const char16_t *)32651)
#define kNtIdcPin      ((const char16_t *)32671)
#define kNtIdcPerson   ((const char16_t *)32672)

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/imageauxsymboltype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMAGEAUXSYMBOLTYPE_H_

#define kNtImageAuxSymbolTypeTokenDef 1



/*!BEGIN libc/nt/enum/importobjectnametype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTNAMETYPE_H_

enum NtImportObjectNameType {
  IMPORT_OBJECT_ORDINAL,
  IMPORT_OBJECT_NAME,
  IMPORT_OBJECT_NAME_NO_PREFIX,
  IMPORT_OBJECT_NAME_UNDECORATE,
  IMPORT_OBJECT_NAME_EXPORTAS
};



/*!BEGIN libc/nt/enum/importobjecttype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IMPORTOBJECTTYPE_H_

enum NtImportObjectType {
  IMPORT_OBJECT_CODE,
  IMPORT_OBJECT_DATA,
  IMPORT_OBJECT_CONST
};



/*!BEGIN libc/nt/enum/io.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IO_H_

#define kNtIoReparseTagSymlink    0xa000000c
#define kNtIoReparseTagMountPoint 0xa0000003



/*!BEGIN libc/nt/enum/ioctl.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_IOCTL_H_

#define kNtIoctlDiskGetDriveGeometry 0x00070000u
#define kNtIoctlAfdPoll              0x00012024u



/*!BEGIN libc/nt/enum/jobobjectinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_JOBOBJECTINFOCLASS_H_

#define kNtJobObjectBasicAccountingInformation         1
#define kNtJobObjectBasicLimitInformation              2
#define kNtJobObjectBasicProcessIdList                 3
#define kNtJobObjectBasicUIRestrictions                4
#define kNtJobObjectSecurityLimitInformation           5
#define kNtJobObjectEndOfJobTimeInformation            6
#define kNtJobObjectAssociateCompletionPortInformation 7
#define kNtJobObjectBasicAndIoAccountingInformation    8
#define kNtJobObjectExtendedLimitInformation           9
#define kNtJobObjectJobSetInformation                  10



/*!BEGIN libc/nt/enum/keyaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYACCESS_H_

#define kNtKeyRead      0x00020019
#define kNtKeyWrite     0x00020006
#define kNtKeyExecute   0x00020019
#define kNtKeyAllAccess 0x000f003f



/*!BEGIN libc/nt/enum/keyedevent.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYEDEVENT_H_

#define kNtKeyedeventWait 0x00000001u
#define kNtKeyedeventWake 0x00000002u
#define kNtKeyedeventAllAccess \
  (kNtStandardRightsRequired | kNtKeyedeventWait | kNtKeyedeventWake)



/*!BEGIN libc/nt/enum/keyinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KEYINFORMATIONCLASS_H_

#define kNtKeyBasicInformation 0
#define kNtKeyNodeInformation  1
#define kNtKeyFullInformation  2
#define kNtKeyNameInformation  3



/*!BEGIN libc/nt/enum/kwaitreason.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_KWAITREASON_H_

#define kNtExecutive 0
#define kNtFreePage 1
#define kNtPageIn 2
#define kNtPoolAllocation 3
#define kNtDelayExecution 4
#define kNtSuspended 5
#define kNtUserRequest 6
#define kNtWrExecutive 7
#define kNtWrFreePage 8
#define kNtWrPageIn 9
#define kNtWrPoolAllocation 10
#define kNtWrDelayExecution 11
#define kNtWrSuspended 12
#define kNtWrUserRequest 13
#define kNtWrEventPair 14
#define kNtWrQueue 15
#define kNtWrLpcReceive 16
#define kNtWrLpcReply 17
#define kNtWrVirtualMemory 18
#define kNtWrPageOut 19
#define kNtWrRendezvous 20
#define kNtSpare2 21
#define kNtSpare3 22
#define kNtSpare4 23
#define kNtSpare5 24
#define kNtSpare6 25
#define kNtWrKernel 26
#define kNtMaximumWaitReason 27



/*!BEGIN libc/nt/enum/lang.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LANG_H_

#define MAKELANGID(p, s) ((((uint16_t)(s)) << 10) | (uint16_t)(p))

#define kNtLangNeutral            0x00
#define kNtLangInvariant          0x7f
#define kNtLangAfrikaans          0x36
#define kNtLangAlbanian           0x1c
#define kNtLangAlsatian           0x84
#define kNtLangAmharic            0x5e
#define kNtLangArabic             0x01
#define kNtLangArmenian           0x2b
#define kNtLangAssamese           0x4d
#define kNtLangAzeri              0x2c
#define kNtLangAzerbaijani        0x2c
#define kNtLangBangla             0x45
#define kNtLangBashkir            0x6d
#define kNtLangBasque             0x2d
#define kNtLangBelarusian         0x23
#define kNtLangBengali            0x45
#define kNtLangBreton             0x7e
#define kNtLangBosnian            0x1a
#define kNtLangBosnianNeutral     0x781a
#define kNtLangBulgarian          0x02
#define kNtLangCatalan            0x03
#define kNtLangCentralKurdish     0x92
#define kNtLangCherokee           0x5c
#define kNtLangChinese            0x04
#define kNtLangChineseSimplified  0x04
#define kNtLangChineseTraditional 0x7c04
#define kNtLangCorsican           0x83
#define kNtLangCroatian           0x1a
#define kNtLangCzech              0x05
#define kNtLangDanish             0x06
#define kNtLangDari               0x8c
#define kNtLangDivehi             0x65
#define kNtLangDutch              0x13
#define kNtLangEnglish            0x09
#define kNtLangEstonian           0x25
#define kNtLangFaeroese           0x38
#define kNtLangFarsi              0x29
#define kNtLangFilipino           0x64
#define kNtLangFinnish            0x0b
#define kNtLangFrench             0x0c
#define kNtLangFrisian            0x62
#define kNtLangFulah              0x67
#define kNtLangGalician           0x56
#define kNtLangGeorgian           0x37
#define kNtLangGerman             0x07
#define kNtLangGreek              0x08
#define kNtLangGreenlandic        0x6f
#define kNtLangGujarati           0x47
#define kNtLangHausa              0x68
#define kNtLangHawaiian           0x75
#define kNtLangHebrew             0x0d
#define kNtLangHindi              0x39
#define kNtLangHungarian          0x0e
#define kNtLangIcelandic          0x0f
#define kNtLangIgbo               0x70
#define kNtLangIndonesian         0x21
#define kNtLangInuktitut          0x5d
#define kNtLangIrish              0x3c
#define kNtLangItalian            0x10
#define kNtLangJapanese           0x11
#define kNtLangKannada            0x4b
#define kNtLangKashmiri           0x60
#define kNtLangKazak              0x3f
#define kNtLangKhmer              0x53
#define kNtLangKiche              0x86
#define kNtLangKinyarwanda        0x87
#define kNtLangKonkani            0x57
#define kNtLangKorean             0x12
#define kNtLangKyrgyz             0x40
#define kNtLangLao                0x54
#define kNtLangLatvian            0x26
#define kNtLangLithuanian         0x27
#define kNtLangLowerSorbian       0x2e
#define kNtLangLuxembourgish      0x6e
#define kNtLangMacedonian         0x2f
#define kNtLangMalay              0x3e
#define kNtLangMalayalam          0x4c
#define kNtLangMaltese            0x3a
#define kNtLangManipuri           0x58
#define kNtLangMaori              0x81
#define kNtLangMapudungun         0x7a
#define kNtLangMarathi            0x4e
#define kNtLangMohawk             0x7c
#define kNtLangMongolian          0x50
#define kNtLangNepali             0x61
#define kNtLangNorwegian          0x14
#define kNtLangOccitan            0x82
#define kNtLangOdia               0x48
#define kNtLangOriya              0x48
#define kNtLangPashto             0x63
#define kNtLangPersian            0x29
#define kNtLangPolish             0x15
#define kNtLangPortuguese         0x16
#define kNtLangPular              0x67
#define kNtLangPunjabi            0x46
#define kNtLangQuechua            0x6b
#define kNtLangRomanian           0x18
#define kNtLangRomansh            0x17
#define kNtLangRussian            0x19
#define kNtLangSakha              0x85
#define kNtLangSami               0x3b
#define kNtLangSanskrit           0x4f
#define kNtLangScottishGaelic     0x91
#define kNtLangSerbian            0x1a
#define kNtLangSerbianNeutral     0x7c1a
#define kNtLangSindhi             0x59
#define kNtLangSinhalese          0x5b
#define kNtLangSlovak             0x1b
#define kNtLangSlovenian          0x24
#define kNtLangSotho              0x6c
#define kNtLangSpanish            0x0a
#define kNtLangSwahili            0x41
#define kNtLangSwedish            0x1d
#define kNtLangSyriac             0x5a
#define kNtLangTajik              0x28
#define kNtLangTamazight          0x5f
#define kNtLangTamil              0x49
#define kNtLangTatar              0x44
#define kNtLangTelugu             0x4a
#define kNtLangThai               0x1e
#define kNtLangTibetan            0x51
#define kNtLangTigrigna           0x73
#define kNtLangTigrinya           0x73
#define kNtLangTswana             0x32
#define kNtLangTurkish            0x1f
#define kNtLangTurkmen            0x42
#define kNtLangUighur             0x80
#define kNtLangUkrainian          0x22
#define kNtLangUpperSorbian       0x2e
#define kNtLangUrdu               0x20
#define kNtLangUzbek              0x43
#define kNtLangValencian          0x03
#define kNtLangVietnamese         0x2a
#define kNtLangWelsh              0x52
#define kNtLangWolof              0x88
#define kNtLangXhosa              0x34
#define kNtLangYakut              0x85
#define kNtLangYi                 0x78
#define kNtLangYoruba             0x6a
#define kNtLangZulu               0x35

#define kNtSublangNeutral                          0x00
#define kNtSublangDefault                          0x01
#define kNtSublangSysDefault                       0x02
#define kNtSublangCustomDefault                    0x03
#define kNtSublangCustomUnspecified                0x04
#define kNtSublangUiCustomDefault                  0x05
#define kNtSublangAfrikaansSouthAfrica             0x01
#define kNtSublangAlbanianAlbania                  0x01
#define kNtSublangAlsatianFrance                   0x01
#define kNtSublangAmharicEthiopia                  0x01
#define kNtSublangArabicSaudiArabia                0x01
#define kNtSublangArabicIraq                       0x02
#define kNtSublangArabicEgypt                      0x03
#define kNtSublangArabicLibya                      0x04
#define kNtSublangArabicAlgeria                    0x05
#define kNtSublangArabicMorocco                    0x06
#define kNtSublangArabicTunisia                    0x07
#define kNtSublangArabicOman                       0x08
#define kNtSublangArabicYemen                      0x09
#define kNtSublangArabicSyria                      0x0a
#define kNtSublangArabicJordan                     0x0b
#define kNtSublangArabicLebanon                    0x0c
#define kNtSublangArabicKuwait                     0x0d
#define kNtSublangArabicUae                        0x0e
#define kNtSublangArabicBahrain                    0x0f
#define kNtSublangArabicQatar                      0x10
#define kNtSublangArmenianArmenia                  0x01
#define kNtSublangAssameseIndia                    0x01
#define kNtSublangAzeriLatin                       0x01
#define kNtSublangAzeriCyrillic                    0x02
#define kNtSublangAzerbaijaniAzerbaijanLatin       0x01
#define kNtSublangAzerbaijaniAzerbaijanCyrillic    0x02
#define kNtSublangBanglaIndia                      0x01
#define kNtSublangBanglaBangladesh                 0x02
#define kNtSublangBashkirRussia                    0x01
#define kNtSublangBasqueBasque                     0x01
#define kNtSublangBelarusianBelarus                0x01
#define kNtSublangBengaliIndia                     0x01
#define kNtSublangBengaliBangladesh                0x02
#define kNtSublangBosnianBosniaHerzegovinaLatin    0x05
#define kNtSublangBosnianBosniaHerzegovinaCyrillic 0x08
#define kNtSublangBretonFrance                     0x01
#define kNtSublangBulgarianBulgaria                0x01
#define kNtSublangCatalanCatalan                   0x01
#define kNtSublangCentralKurdishIraq               0x01
#define kNtSublangCherokeeCherokee                 0x01
#define kNtSublangChineseTraditional               0x01
#define kNtSublangChineseSimplified                0x02
#define kNtSublangChineseHongkong                  0x03
#define kNtSublangChineseSingapore                 0x04
#define kNtSublangChineseMacau                     0x05
#define kNtSublangCorsicanFrance                   0x01
#define kNtSublangCzechCzechRepublic               0x01
#define kNtSublangCroatianCroatia                  0x01
#define kNtSublangCroatianBosniaHerzegovinaLatin   0x04
#define kNtSublangDanishDenmark                    0x01
#define kNtSublangDariAfghanistan                  0x01
#define kNtSublangDivehiMaldives                   0x01
#define kNtSublangDutch                            0x01
#define kNtSublangDutchBelgian                     0x02
#define kNtSublangEnglishUs                        0x01
#define kNtSublangEnglishUk                        0x02
#define kNtSublangEnglishAus                       0x03
#define kNtSublangEnglishCan                       0x04
#define kNtSublangEnglishNz                        0x05
#define kNtSublangEnglishEire                      0x06
#define kNtSublangEnglishSouthAfrica               0x07
#define kNtSublangEnglishJamaica                   0x08
#define kNtSublangEnglishCaribbean                 0x09
#define kNtSublangEnglishBelize                    0x0a
#define kNtSublangEnglishTrinidad                  0x0b
#define kNtSublangEnglishZimbabwe                  0x0c
#define kNtSublangEnglishPhilippines               0x0d
#define kNtSublangEnglishIndia                     0x10
#define kNtSublangEnglishMalaysia                  0x11
#define kNtSublangEnglishSingapore                 0x12
#define kNtSublangEstonianEstonia                  0x01
#define kNtSublangFaeroeseFaroeIslands             0x01
#define kNtSublangFilipinoPhilippines              0x01
#define kNtSublangFinnishFinland                   0x01
#define kNtSublangFrench                           0x01
#define kNtSublangFrenchBelgian                    0x02
#define kNtSublangFrenchCanadian                   0x03
#define kNtSublangFrenchSwiss                      0x04
#define kNtSublangFrenchLuxembourg                 0x05
#define kNtSublangFrenchMonaco                     0x06
#define kNtSublangFrisianNetherlands               0x01
#define kNtSublangFulahSenegal                     0x02
#define kNtSublangGalicianGalician                 0x01
#define kNtSublangGeorgianGeorgia                  0x01
#define kNtSublangGerman                           0x01
#define kNtSublangGermanSwiss                      0x02
#define kNtSublangGermanAustrian                   0x03
#define kNtSublangGermanLuxembourg                 0x04
#define kNtSublangGermanLiechtenstein              0x05
#define kNtSublangGreekGreece                      0x01
#define kNtSublangGreenlandicGreenland             0x01
#define kNtSublangGujaratiIndia                    0x01
#define kNtSublangHausaNigeriaLatin                0x01
#define kNtSublangHawaiianUs                       0x01
#define kNtSublangHebrewIsrael                     0x01
#define kNtSublangHindiIndia                       0x01
#define kNtSublangHungarianHungary                 0x01
#define kNtSublangIcelandicIceland                 0x01
#define kNtSublangIgboNigeria                      0x01
#define kNtSublangIndonesianIndonesia              0x01
#define kNtSublangInuktitutCanada                  0x01
#define kNtSublangInuktitutCanadaLatin             0x02
#define kNtSublangIrishIreland                     0x02
#define kNtSublangItalian                          0x01
#define kNtSublangItalianSwiss                     0x02
#define kNtSublangJapaneseJapan                    0x01
#define kNtSublangKannadaIndia                     0x01
#define kNtSublangKashmiriSasia                    0x02
#define kNtSublangKashmiriIndia                    0x02
#define kNtSublangKazakKazakhstan                  0x01
#define kNtSublangKhmerCambodia                    0x01
#define kNtSublangKicheGuatemala                   0x01
#define kNtSublangKinyarwandaRwanda                0x01
#define kNtSublangKonkaniIndia                     0x01
#define kNtSublangKorean                           0x01
#define kNtSublangKyrgyzKyrgyzstan                 0x01
#define kNtSublangLaoLao                           0x01
#define kNtSublangLatvianLatvia                    0x01
#define kNtSublangLithuanian                       0x01
#define kNtSublangLowerSorbianGermany              0x02
#define kNtSublangLuxembourgishLuxembourg          0x01
#define kNtSublangMacedonianMacedonia              0x01
#define kNtSublangMalayMalaysia                    0x01
#define kNtSublangMalayBruneiDarussalam            0x02
#define kNtSublangMalayalamIndia                   0x01
#define kNtSublangMalteseMalta                     0x01
#define kNtSublangMaoriNewZealand                  0x01
#define kNtSublangMapudungunChile                  0x01
#define kNtSublangMarathiIndia                     0x01
#define kNtSublangMohawkMohawk                     0x01
#define kNtSublangMongolianCyrillicMongolia        0x01
#define kNtSublangMongolianPrc                     0x02
#define kNtSublangNepaliIndia                      0x02
#define kNtSublangNepaliNepal                      0x01
#define kNtSublangNorwegianBokmal                  0x01
#define kNtSublangNorwegianNynorsk                 0x02
#define kNtSublangOccitanFrance                    0x01
#define kNtSublangOdiaIndia                        0x01
#define kNtSublangOriyaIndia                       0x01
#define kNtSublangPashtoAfghanistan                0x01
#define kNtSublangPersianIran                      0x01
#define kNtSublangPolishPoland                     0x01
#define kNtSublangPortuguese                       0x02
#define kNtSublangPortugueseBrazilian              0x01
#define kNtSublangPularSenegal                     0x02
#define kNtSublangPunjabiIndia                     0x01
#define kNtSublangPunjabiPakistan                  0x02
#define kNtSublangQuechuaBolivia                   0x01
#define kNtSublangQuechuaEcuador                   0x02
#define kNtSublangQuechuaPeru                      0x03
#define kNtSublangRomanianRomania                  0x01
#define kNtSublangRomanshSwitzerland               0x01
#define kNtSublangRussianRussia                    0x01
#define kNtSublangSakhaRussia                      0x01
#define kNtSublangSamiNorthernNorway               0x01
#define kNtSublangSamiNorthernSweden               0x02
#define kNtSublangSamiNorthernFinland              0x03
#define kNtSublangSamiLuleNorway                   0x04
#define kNtSublangSamiLuleSweden                   0x05
#define kNtSublangSamiSouthernNorway               0x06
#define kNtSublangSamiSouthernSweden               0x07
#define kNtSublangSamiSkoltFinland                 0x08
#define kNtSublangSamiInariFinland                 0x09
#define kNtSublangSanskritIndia                    0x01
#define kNtSublangScottishGaelic                   0x01
#define kNtSublangSerbianBosniaHerzegovinaLatin    0x06
#define kNtSublangSerbianBosniaHerzegovinaCyrillic 0x07
#define kNtSublangSerbianMontenegroLatin           0x0b
#define kNtSublangSerbianMontenegroCyrillic        0x0c
#define kNtSublangSerbianSerbiaLatin               0x09
#define kNtSublangSerbianSerbiaCyrillic            0x0a
#define kNtSublangSerbianCroatia                   0x01
#define kNtSublangSerbianLatin                     0x02
#define kNtSublangSerbianCyrillic                  0x03
#define kNtSublangSindhiIndia                      0x01
#define kNtSublangSindhiPakistan                   0x02
#define kNtSublangSindhiAfghanistan                0x02
#define kNtSublangSinhaleseSriLanka                0x01
#define kNtSublangSothoNorthernSouthAfrica         0x01
#define kNtSublangSlovakSlovakia                   0x01
#define kNtSublangSlovenianSlovenia                0x01
#define kNtSublangSpanish                          0x01
#define kNtSublangSpanishMexican                   0x02
#define kNtSublangSpanishModern                    0x03
#define kNtSublangSpanishGuatemala                 0x04
#define kNtSublangSpanishCostaRica                 0x05
#define kNtSublangSpanishPanama                    0x06
#define kNtSublangSpanishDominicanRepublic         0x07
#define kNtSublangSpanishVenezuela                 0x08
#define kNtSublangSpanishColombia                  0x09
#define kNtSublangSpanishPeru                      0x0a
#define kNtSublangSpanishArgentina                 0x0b
#define kNtSublangSpanishEcuador                   0x0c
#define kNtSublangSpanishChile                     0x0d
#define kNtSublangSpanishUruguay                   0x0e
#define kNtSublangSpanishParaguay                  0x0f
#define kNtSublangSpanishBolivia                   0x10
#define kNtSublangSpanishElSalvador                0x11
#define kNtSublangSpanishHonduras                  0x12
#define kNtSublangSpanishNicaragua                 0x13
#define kNtSublangSpanishPuertoRico                0x14
#define kNtSublangSpanishUs                        0x15
#define kNtSublangSwahiliKenya                     0x01
#define kNtSublangSwedish                          0x01
#define kNtSublangSwedishFinland                   0x02
#define kNtSublangSyriacSyria                      0x01
#define kNtSublangTajikTajikistan                  0x01
#define kNtSublangTamazightAlgeriaLatin            0x02
#define kNtSublangTamazightMoroccoTifinagh         0x04
#define kNtSublangTamilIndia                       0x01
#define kNtSublangTamilSriLanka                    0x02
#define kNtSublangTatarRussia                      0x01
#define kNtSublangTeluguIndia                      0x01
#define kNtSublangThaiThailand                     0x01
#define kNtSublangTibetanPrc                       0x01
#define kNtSublangTigrignaEritrea                  0x02
#define kNtSublangTigrinyaEritrea                  0x02
#define kNtSublangTigrinyaEthiopia                 0x01
#define kNtSublangTswanaBotswana                   0x02
#define kNtSublangTswanaSouthAfrica                0x01
#define kNtSublangTurkishTurkey                    0x01
#define kNtSublangTurkmenTurkmenistan              0x01
#define kNtSublangUighurPrc                        0x01
#define kNtSublangUkrainianUkraine                 0x01
#define kNtSublangUpperSorbianGermany              0x01
#define kNtSublangUrduPakistan                     0x01
#define kNtSublangUrduIndia                        0x02
#define kNtSublangUzbekLatin                       0x01
#define kNtSublangUzbekCyrillic                    0x02
#define kNtSublangValencianValencia                0x02
#define kNtSublangVietnameseVietnam                0x01
#define kNtSublangWelshUnitedKingdom               0x01
#define kNtSublangWolofSenegal                     0x01
#define kNtSublangXhosaSouthAfrica                 0x01
#define kNtSublangYakutRussia                      0x01
#define kNtSublangYiPrc                            0x01
#define kNtSublangYorubaNigeria                    0x01
#define kNtSublangZuluSouthAfrica                  0x01



/*!BEGIN libc/nt/enum/loadlibrarysearch.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOADLIBRARYSEARCH_H_

#define kNtLoadLibrarySearchApplicationDir 0x00000200u
#define kNtLoadLibrarySearchSearchSystem32 0x00000800u
#define kNtLoadLibrarySearchUserDirs       0x00000400u
#define kNtLoadLibrarySearchDefaultDirs    0x00001000u



/*!BEGIN libc/nt/enum/lockfile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_LOCKFILE_H_

#define kNtLockfileFailImmediately 1
#define kNtLockfileExclusiveLock   2



/*!BEGIN libc/nt/enum/mb.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MB_H_

#define kNtMbOk                      0x00000000
#define kNtMbOkcancel                0x00000001
#define kNtMbAbortretryignore        0x00000002
#define kNtMbYesnocancel             0x00000003
#define kNtMbYesno                   0x00000004
#define kNtMbRetrycancel             0x00000005
#define kNtMbCanceltrycontinue       0x00000006
#define kNtMbIconhand                0x00000010
#define kNtMbIconquestion            0x00000020
#define kNtMbIconexclamation         0x00000030
#define kNtMbIconasterisk            0x00000040
#define kNtMbUsericon                0x00000080
#define kNtMbIconwarning             kNtMbIconexclamation
#define kNtMbIconerror               kNtMbIconhand
#define kNtMbIconinformation         kNtMbIconasterisk
#define kNtMbIconstop                kNtMbIconhand
#define kNtMbDefbutton1              0x00000000
#define kNtMbDefbutton2              0x00000100
#define kNtMbDefbutton3              0x00000200
#define kNtMbDefbutton4              0x00000300
#define kNtMbApplmodal               0x00000000
#define kNtMbSystemmodal             0x00001000
#define kNtMbTaskmodal               0x00002000
#define kNtMbHelp                    0x00004000
#define kNtMbNofocus                 0x00008000
#define kNtMbSetforeground           0x00010000
#define kNtMbDefaultDesktopOnly      0x00020000
#define kNtMbTopmost                 0x00040000
#define kNtMbRight                   0x00080000
#define kNtMbRtlreading              0x00100000
#define kNtMbServiceNotification     0x00200000
#define kNtMbServiceNotificationNt3x 0x00040000
#define kNtMbTypemask                0x0000000F
#define kNtMbIconmask                0x000000F0
#define kNtMbDefmask                 0x00000F00
#define kNtMbModemask                0x00003000
#define kNtMbMiscmask                0x0000C000



/*!BEGIN libc/nt/enum/memflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMFLAGS_H_

#define kNtMemCommit     0x1000 /* perform physical memory reservation step */
#define kNtMemReserve    0x2000 /* perform virtual memory reservation step */
#define kNtMemDecommit   0x4000
#define kNtMemRelease    0x8000
#define kNtMemFree       0x10000
#define kNtMemPrivate    0x20000
#define kNtMemMapped     0x40000
#define kNtMemReset      0x80000
#define kNtMemTopDown    0x100000
#define kNtMemWriteWatch 0x200000
#define kNtMemPhysical   0x400000
#define kNtMemImage      0x1000000
#define kNtMemLargePages 0x20000000
#define kNtMem4mbPages   0x80000000

#define kNtMemReplacePlaceholder 0x00004000



/*!BEGIN libc/nt/enum/memoryinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MEMORYINFORMATIONCLASS_H_

#define kNtMemoryBasicInformation    0
#define kNtMemoryWorkingSetList      1
#define kNtMemorySectionName         2
#define kNtMemoryBasicVlmInformation 3



/*!BEGIN libc/nt/enum/mf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MF_H_

#define kNtMfInsert          0x00000000
#define kNtMfChange          0x00000080
#define kNtMfAppend          0x00000100
#define kNtMfDelete          0x00000200
#define kNtMfRemove          0x00001000
#define kNtMfBycommand       0x00000000
#define kNtMfByposition      0x00000400
#define kNtMfSeparator       0x00000800
#define kNtMfEnabled         0x00000000
#define kNtMfGrayed          0x00000001
#define kNtMfDisabled        0x00000002
#define kNtMfUnchecked       0x00000000
#define kNtMfChecked         0x00000008
#define kNtMfUsecheckbitmaps 0x00000200
#define kNtMfString          0x00000000
#define kNtMfBitmap          0x00000004
#define kNtMfOwnerdraw       0x00000100
#define kNtMfPopup           0x00000010
#define kNtMfMenubarbreak    0x00000020
#define kNtMfMenubreak       0x00000040
#define kNtMfUnhilite        0x00000000
#define kNtMfHilite          0x00000080
#define kNtMfDefault         0x00001000
#define kNtMfSysmenu         0x00002000
#define kNtMfHelp            0x00004000
#define kNtMfRightjustify    0x00004000
#define kNtMfMouseselect     0x00008000



/*!BEGIN libc/nt/enum/mk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MK_H_

#define kNtMkLbutton  0x0001
#define kNtMkRbutton  0x0002
#define kNtMkShift    0x0004
#define kNtMkControl  0x0008
#define kNtMkMbutton  0x0010
#define kNtMkXbutton1 0x0020
#define kNtMkXbutton2 0x0040



/*!BEGIN libc/nt/enum/movefileexflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_MOVEFILEEXFLAGS_H_

#define kNtMovefileReplaceExisting    1
#define kNtMovefileCopyAllowed        2
#define kNtMovefileDelayUntilReboot   4
#define kNtMovefileWriteThrough       8
#define kNtMovefileCreateHardlink     16
#define kNtMovefileFailIfNotTrackable 32



/*!BEGIN libc/nt/enum/objectinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OBJECTINFORMATIONCLASS_H_

#define kNtObjectBasicInformation 0 /*→ struct NtObjectBasicInformation */
#define kNtObjectNameInformation  1 /*→ etc. */
#define kNtObjectTypeInformation  2
#define kNtObjectAllInformation   3
#define kNtObjectDataInformation  4



/*!BEGIN libc/nt/enum/offerpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFFERPRIORITY_H_

/* TODO(jart): Are these values correct? */
#define kNtVmOfferPriorityVeryLow     1 /* 0x00001000? */
#define kNtVmOfferPriorityLow         2 /* 0x00002000? */
#define kNtVmOfferPriorityBelowNormal 3 /* 0x00002000? */
#define kNtVmOfferPriorityNormal      4 /* 0x00002000? */



/*!BEGIN libc/nt/enum/ofn.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_OFN_H_

#define kNtOfnReadonly             0x00000001
#define kNtOfnOverwriteprompt      0x00000002
#define kNtOfnHidereadonly         0x00000004
#define kNtOfnNochangedir          0x00000008
#define kNtOfnShowhelp             0x00000010
#define kNtOfnEnablehook           0x00000020
#define kNtOfnEnabletemplate       0x00000040
#define kNtOfnEnabletemplatehandle 0x00000080
#define kNtOfnNovalidate           0x00000100
#define kNtOfnAllowmultiselect     0x00000200
#define kNtOfnExtensiondifferent   0x00000400
#define kNtOfnPathmustexist        0x00000800
#define kNtOfnFilemustexist        0x00001000
#define kNtOfnCreateprompt         0x00002000
#define kNtOfnShareaware           0x00004000
#define kNtOfnNoreadonlyreturn     0x00008000
#define kNtOfnNotestfilecreate     0x00010000
#define kNtOfnNonetworkbutton      0x00020000
#define kNtOfnNolongnames          0x00040000
#define kNtOfnExplorer             0x00080000
#define kNtOfnNodereferencelinks   0x00100000
#define kNtOfnLongnames            0x00200000
#define kNtOfnEnableincludenotify  0x00400000
#define kNtOfnEnablesizing         0x00800000
#define kNtOfnDontaddtorecent      0x02000000
#define kNtOfnForceshowhidden      0x10000000



/*!BEGIN libc/nt/enum/pageflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PAGEFLAGS_H_

/* Pick One */
#define kNtPageNoaccess         0x001
#define kNtPageReadonly         0x002
#define kNtPageReadwrite        0x004
#define kNtPageWritecopy        0x008
#define kNtPageExecute          0x010
#define kNtPageExecuteRead      0x020
#define kNtPageExecuteReadwrite 0x040
#define kNtPageExecuteWritecopy 0x080
#define kNtPageGuard            0x100
#define kNtPageNocache          0x200
#define kNtPageWritecombine     0x400

/* These may be OR'd */
#define kNtSecReserve        0x04000000
#define kNtSecCommit         0x08000000 /* default */
#define kNtSecImageNoExecute 0x11000000
#define kNtSecImage          0x01000000
#define kNtSecNocache        0x10000000
#define kNtSecLargePages     0x80000000
#define kNtSecWritecombine   0x40000000



/*!BEGIN libc/nt/enum/pdh.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PDH_H_

#define kNtPdhFmtRaw          0x00000010u
#define kNtPdhFmtAnsi         0x00000020u
#define kNtPdhFmtUnicode      0x00000040u
#define kNtPdhFmtLong         0x00000100u
#define kNtPdhFmtDouble       0x00000200u
#define kNtPdhFmtLarge        0x00000400u
#define kNtPdhFmtNoscale      0x00001000u
#define kNtPdhFmt1000         0x00002000u
#define kNtPdhFmtNodata       0x00004000u
#define kNtPdhFmtNocap100     0x00008000u
#define kNtPerfDetailCostly   0x00010000u
#define kNtPerfDetailStandard 0x0000FFFFu



/*!BEGIN libc/nt/enum/processaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSACCESS_H_

#define kNtProcessCreateProcess 0x0080u
#define kNtProcessCreateThread 0x0002u
#define kNtProcessDupHandle 0x0040u
#define kNtProcessQueryInformation 0x0400u
#define kNtProcessQueryLimitedInformation 0x1000u
#define kNtProcessSetInformation 0x0200u
#define kNtProcessSetQuota 0x0100u
#define kNtProcessSuspendResume 0x0800u
#define kNtProcessTerminate 0x0001u
#define kNtProcessVmOperation 0x0008u
#define kNtProcessVmRead 0x0010u
#define kNtProcessVmWrite 0x0020u
#define kNtProcessSynchronize kNtSynchronize
#define kNtProcessAllAccess \
  (kNtStandardRightsRequired | kNtSynchronize | 0xffffu)



/*!BEGIN libc/nt/enum/processcreationflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSCREATIONFLAGS_H_

#define kNtIdlePriorityClass        0x00000040u
#define kNtBelowNormalPriorityClass 0x00004000u
#define kNtNormalPriorityClass      0x00000020u
#define kNtAboveNormalPriorityClass 0x00008000u
#define kNtHighPriorityClass        0x00000080u
#define kNtRealtimePriorityClass    0x00000100u

#define kNtDebugProcess                 0x00000001u
#define kNtDebugOnlyThisProcess         0x00000002u
#define kNtCreateSuspended              0x00000004u
#define kNtDetachedProcess              0x00000008u
#define kNtCreateNewConsole             0x00000010u
#define kNtCreateNewProcessGroup        0x00000200u
#define kNtCreateUnicodeEnvironment     0x00000400u
#define kNtCreateSeparateWowVdm         0x00000800u
#define kNtCreateSharedWowVdm           0x00001000u
#define kNtCreateForcedos               0x00002000u
#define kNtInheritParentAffinity        0x00010000u
#define kNtCreateProtectedProcess       0x00040000u
#define kNtExtendedStartupinfoPresent   0x00080000u
#define kNtProcessModeBackgroundBegin   0x00100000u
#define kNtProcessModeBackgroundEnd     0x00200000u
#define kNtCreateSecureProcess          0x00400000u
#define kNtCreateBreakawayFromJob       0x01000000u
#define kNtCreatePreserveCodeAuthzLevel 0x02000000u
#define kNtCreateDefaultErrorMode       0x04000000u
#define kNtCreateNoWindow               0x08000000u
#define kNtProfileUser                  0x10000000u
#define kNtProfileKernel                0x20000000u
#define kNtProfileServer                0x40000000u
#define kNtCreateIgnoreSystemDefault    0x80000000u

#define kNtStackSizeParamIsAReservation 0x00010000



/*!BEGIN libc/nt/enum/processinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCESSINFOCLASS_H_

#define kNtProcessBasicInformation 0
#define kNtProcessQuotaLimits      1
#define kNtProcessIoCounters       2
#define kNtProcessVmCounters       3
#define kNtProcessTimes            4
#define kNtProcessBasePriority     5
#define kNtProcessRaisePriority    6
#define kNtProcessDebugPort        7
#define kNtProcessExceptionPort    8
#define kNtProcessAccessToken      9
#define kNtProcessWow64Information 26
#define kNtProcessImageFileName    27



/*!BEGIN libc/nt/enum/procthreadattributes.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROCTHREADATTRIBUTES_H_

#define kNtProcThreadAttributeReplaceValue 1
#define kNtProcThreadAttributeHandleList 0x00020002



/*!BEGIN libc/nt/enum/progress.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PROGRESS_H_

#define kNtProgressContinue 0
#define kNtProgressCancel   1
#define kNtProgressStop     2
#define kNtProgressQuiet    3



/*!BEGIN libc/nt/enum/pseudoconsole.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PSEUDOCONSOLE_H_

#define kNtPseudoconsoleInheritCursor 1



/*!BEGIN libc/nt/enum/pwr.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_PWR_H_

#define kNtPwrOk             1
#define kNtPwrFail           (-1)
#define kNtPwrSuspendrequest 1
#define kNtPwrSuspendresume  2
#define kNtPwrCriticalresume 3



/*!BEGIN libc/nt/enum/rdw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_RDW_H_

#define kNtRdwInvalidate      0x0001
#define kNtRdwInternalpaint   0x0002
#define kNtRdwErase           0x0004
#define kNtRdwValidate        0x0008
#define kNtRdwNointernalpaint 0x0010
#define kNtRdwNoerase         0x0020
#define kNtRdwNochildren      0x0040
#define kNtRdwAllchildren     0x0080
#define kNtRdwUpdatenow       0x0100
#define kNtRdwErasenow        0x0200
#define kNtRdwFrame           0x0400
#define kNtRdwNoframe         0x0800



/*!BEGIN libc/nt/enum/reggetvalueflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGGETVALUEFLAGS_H_

#define kNtRrfRtRegNone        0x00000001
#define kNtRrfRtRegSz          0x00000002
#define kNtRrfRtRegExpandSz    0x00000004
#define kNtRrfRtRegBinary      0x00000008
#define kNtRrfRtRegDword       0x00000010
#define kNtRrfRtRegMultiSz     0x00000020
#define kNtRrfRtRegQword       0x00000040
#define kNtRrfRtDword          (kNtRrfRtRegBinary | kNtRrfRtRegDword)
#define kNtRrfRtQword          (kNtRrfRtRegBinary | kNtRrfRtRegQword)
#define kNtRrfRtAny            0x0000ffff
#define kNtRrfSubkeyWow6464key 0x00010000
#define kNtRrfSubkeyWow6432key 0x00020000
#define kNtRrfWow64Mask        0x00030000
#define kNtRrfNoexpand         0x10000000
#define kNtRrfZeroonfailure    0x20000000



/*!BEGIN libc/nt/enum/regtype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REGTYPE_H_

#define kNtRegNone                     0
#define kNtRegSz                       1 /* UTF-16 string */
#define kNtRegExpandSz                 2 /* UTF-16 string w/ env vars refs */
#define kNtRegBinary                   3
#define kNtRegDword                    4
#define kNtRegDwordBigEndian           5
#define kNtRegLink                     6
#define kNtRegMultiSz                  7 /* UTF-16 double-nul-terminated */
#define kNtRegResourceList             8
#define kNtRegFullResourceDescriptor   9
#define kNtRegResourceRequirementsList 10
#define kNtRegQword                    11



/*!BEGIN libc/nt/enum/replacefile.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_REPLACEFILE_H_

#define kNtReplacefileWriteThrough      1
#define kNtReplacefileIgnoreMergeErrors 2
#define kNtReplacefileIgnoreAclErrors   4



/*!BEGIN libc/nt/enum/sc.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SC_H_

#define kNtScSize         0xF000
#define kNtScMove         0xF010
#define kNtScMinimize     0xF020
#define kNtScMaximize     0xF030
#define kNtScNextwindow   0xF040
#define kNtScPrevwindow   0xF050
#define kNtScClose        0xF060
#define kNtScVscroll      0xF070
#define kNtScHscroll      0xF080
#define kNtScMousemenu    0xF090
#define kNtScKeymenu      0xF100
#define kNtScArrange      0xF110
#define kNtScRestore      0xF120
#define kNtScTasklist     0xF130
#define kNtScScreensave   0xF140
#define kNtScHotkey       0xF150
#define kNtScDefault      0xF160
#define kNtScMonitorpower 0xF170
#define kNtScContexthelp  0xF180
#define kNtScSeparator    0xF00F



/*!BEGIN libc/nt/enum/sectioninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINFORMATIONCLASS_H_

#define kNtSectionBasicInformation 0
#define kNtSectionImageInformation 1



/*!BEGIN libc/nt/enum/sectioninherit.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONINHERIT_H_

enum NtSectionInherit { kNtViewShare = 1, kNtViewUnmap = 2 };



/*!BEGIN libc/nt/enum/sectionmapflags.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECTIONMAPFLAGS_H_

#define kNtSectionQuery              0x0001
#define kNtSectionMapWrite           0x0002
#define kNtSectionMapRead            0x0004
#define kNtSectionMapExecute         0x0008
#define kNtSectionExtendSize         0x0010
#define kNtSectionMapExecuteExplicit 0x0020



/*!BEGIN libc/nt/enum/securityimpersonationlevel.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYIMPERSONATIONLEVEL_H_

#define kNtSecurityAnonymous      0
#define kNtSecurityIdentification 1
#define kNtSecurityImpersonation  2
#define kNtSecurityDelegation     3



/*!BEGIN libc/nt/enum/securityinformation.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SECURITYINFORMATION_H_

#define kNtOwnerSecurityInformation 0x00000001
#define kNtGroupSecurityInformation 0x00000002
#define kNtDaclSecurityInformation 0x00000004
#define kNtSaclSecurityInformation 0x00000008
#define kNtLabelSecurityInformation 0x00000010
#define kNtAttributeSecurityInformation 0x00000020
#define kNtScopeSecurityInformation 0x00000040
#define kNtProcessTrustLabelSecurityInformation 0x00000080
#define kNtAccessFilterSecurityInformation 0x00000100
#define kNtBackupSecurityInformation 0x00010000
#define kNtProtectedDaclSecurityInformation 0x80000000
#define kNtProtectedSaclSecurityInformation 0x40000000
#define kNtUnprotectedDaclSecurityInformation 0x20000000
#define kNtUnprotectedSaclSecurityInformation 0x10000000



/*!BEGIN libc/nt/enum/signal.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIGNAL_H_

#define kNtSignalBreakpoint          0x80000003u
#define kNtSignalIllegalInstruction  0xC000001Du
#define kNtSignalPrivInstruction     0xC0000096u
#define kNtSignalGuardPage           0x80000001u
#define kNtSignalAccessViolation     0xC0000005u
#define kNtSignalInPageError         0xC0000006u
#define kNtSignalInvalidHandle       0xC0000008u
#define kNtSignalInvalidParameter    0xC000000du
#define kNtSignalFltDenormalOperand  0xC000008Du
#define kNtSignalFltDivideByZero     0xC000008Eu
#define kNtSignalFltInexactResult    0xC000008Fu
#define kNtSignalFltInvalidOperation 0xC0000090u
#define kNtSignalFltOverflow         0xC0000091u
#define kNtSignalFltStackCheck       0xC0000092u
#define kNtSignalFltUnderflow        0xC0000093u
#define kNtSignalIntegerDivideByZero 0xC0000094u
#define kNtSignalDllNotFound         0xC0000135u
#define kNtSignalOrdinalNotFound     0xC0000138u
#define kNtSignalEntrypointNotFound  0xC0000139u
#define kNtSignalControlCExit        0xC000013Au
#define kNtSignalDllInitFailed       0xC0000142u
#define kNtSignalFloatMultipleFaults 0xC00002B4u
#define kNtSignalFloatMultipleTraps  0xC00002B5u
#define kNtSignalAssertionFailure    0xC0000420u



/*!BEGIN libc/nt/enum/sio.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIO_H_

#define kNtSioAbsorbRtralert                      0x98000005u
#define kNtSioAcquirePortReservation              0x98000064u
#define kNtSioAddressListChange                   0x28000017u
#define kNtSioAddressListQuery                    0x48000016u
#define kNtSioAddressListSort                     0xc8000019u
#define kNtSioApplyTransportSetting               0x98000013u
#define kNtSioAssociateHandle                     0x88000001u
#define kNtSioAssociatePortReservation            0x98000066u
#define kNtSioBaseHandle                          0x48000022u
#define kNtSioBspHandlePoll                       0x4800001Du
#define kNtSioDeletePeerTargetName                0x980000cbu
#define kNtSioEnableCircularQueueing              0x28000002u
#define kNtSioFindRoute                           0x48000003u
#define kNtSioFlush                               0x28000004u
#define kNtSioGetBroadcastAddress                 0x48000005u
#define kNtSioGetExtensionFunctionPointer         0xc8000006u
#define kNtSioGetGroupQos                         0xc8000008u
#define kNtSioGetInterfaceList                    0x4008747fu
#define kNtSioGetMultipleExtensionFunctionPointer 0xc8000024u
#define kNtSioGetQos                              0xc8000007u
#define kNtSioIndexAddMcast                       0x9800000au
#define kNtSioIndexBind                           0x98000008u
#define kNtSioIndexDelMcast                       0x9800000bu
#define kNtSioIndexMcastif                        0x98000009u
#define kNtSioKeepaliveVals                       0x98000004u
#define kNtSioLimitBroadcasts                     0x98000007u
#define kNtSioLoopbackFastPath                    0x98000010u
#define kNtSioMulticastScope                      0x8800000au
#define kNtSioMultipointLoopback                  0x88000009u
#define kNtSioQueryRssProcessorInfo               0x48000025u
#define kNtSioQueryRssScalabilityInfo             0x580000d2u
#define kNtSioQuerySecurity                       0xd80000c9u
#define kNtSioQueryTargetPnpHandle                0x48000018u
#define kNtSioQueryTransportSetting               0x98000014u
#define kNtSioQueryWfpAleEndpointHandle           0x580000cdu
#define kNtSioQueryWfpConnectionRedirectContext   0x980000ddu
#define kNtSioQueryWfpConnectionRedirectRecords   0x980000dcu
#define kNtSioRcvall                              0x98000001u
#define kNtSioRcvallIf                            0x9800000eu
#define kNtSioRcvallIgmpmcast                     0x98000003u
#define kNtSioRcvallMcast                         0x98000002u
#define kNtSioRcvallMcastIf                       0x9800000du
#define kNtSioReleasePortReservation              0x98000065u
#define kNtSioReserved1                           0x8800001au
#define kNtSioReserved2                           0x88000021u
#define kNtSioRoutingInterfaceChange              0x88000015u
#define kNtSioRoutingInterfaceQuery               0xc8000014u
#define kNtSioSetGroupQos                         0x8800000cu
#define kNtSioSetPeerTargetName                   0x980000cau
#define kNtSioSetPriorityHint                     0x98000018u
#define kNtSioSetQos                              0x8800000bu
#define kNtSioSetSecurity                         0x980000c8u
#define kNtSioSetWfpConnectionRedirectRecords     0x980000deu
#define kNtSioSocketCloseNotify                   0x9800000du
#define kNtSioSocketUsageNotification             0x980000ccu
#define kNtSioTcpInfo                             0xd8000027u
#define kNtSioTcpInitialRto                       0x98000011u
#define kNtSioTcpSetAckFrequency                  0x98000017u
#define kNtSioTcpSetIcw                           0x98000016u
#define kNtSioTranslateHandle                     0xc800000du
#define kNtSioUcastIf                             0x98000006u
#define kNtSioUdpConnreset                        0x9800000cu
#define kNtSioUdpNetreset                         0x9800000fu



/*!BEGIN libc/nt/enum/size.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SIZE_H_

#define kNtSizeRestored  0
#define kNtSizeMinimized 1
#define kNtSizeMaximized 2
#define kNtSizeMaxshow   3
#define kNtSizeMaxhide   4



/*!BEGIN libc/nt/enum/startf.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STARTF_H_

#define kNtStartfUseshowwindow 0x00000001 /* otherwise wShowWindow ignored */
#define kNtStartfUsesize 0x00000002       /* otherwise dwX / dwY ignored */
#define kNtStartfUseposition 0x00000004   /* otherwise dwX/YSize ignored */
#define kNtStartfUsecountchars 0x00000008 /* otherwise dwX/YCountChars ign. */
#define kNtStartfUsefillattribute 0x00000010 /* etc. */
#define kNtStartfRunfullscreen 0x00000020
#define kNtStartfForceonfeedback 0x00000040
#define kNtStartfForceofffeedback 0x00000080
#define kNtStartfUsestdhandles 0x00000100 /* otherwise hStd... ignored */
#define kNtStartfUsehotkey 0x00000200
#define kNtStartfTitleislinkname 0x00000800
#define kNtStartfTitleisappid 0x00001000
#define kNtStartfPreventpinning 0x00002000
#define kNtStartfUntrustedsource 0x00008000



/*!BEGIN libc/nt/enum/statfs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_STATFS_H_
COSMOPOLITAN_C_START_

#define kNtFileCasePreservedNames         0x00000002
#define kNtFileCaseSensitiveSearch        0x00000001
#define kNtFileFileCompression            0x00000010
#define kNtFileNamedStreams               0x00040000
#define kNtFilePersistentAcls             0x00000008
#define kNtFileReadOnlyVolume             0x00080000 /* ST_RDONLY */
#define kNtFileSequentialWriteOnce        0x00100000
#define kNtFileSupportsEncryption         0x00020000
#define kNtFileSupportsExtendedAttributes 0x00800000
#define kNtFileSupportsHardLinks          0x00400000
#define kNtFileSupportsObjectIds          0x00010000
#define kNtFileSupportsOpenByFileId       0x01000000
#define kNtFileSupportsReparsePoints      0x00000080
#define kNtFileSupportsSparseFiles        0x00000040
#define kNtFileSupportsTransactions       0x00200000
#define kNtFileSupportsUsnJournal         0x02000000
#define kNtFileUnicodeOnDisk              0x00000004
#define kNtFileVolumeIsCompressed         0x00008000
#define kNtFileVolumeQuotas               0x00000020
#define kNtFileSupportsBlockRefcounting   0x08000000

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/status.h */

#define COSMOPOLITAN_LIBC_NT_STATUS_H_

/* high two bits = {success,informational,warning,error} */
#define kNtStatusSuccess                  0x00000000 /* success statuses */
#define kNtStatusWait0                    0x00000000
#define kNtStatusAbandonedWait0           0x00000080
#define kNtStatusUserApc                  0x000000C0
#define kNtStatusTimeout                  0x00000102
#define kNtStatusPending                  0x00000103
#define kNtStatusGuardPageViolation       0x80000001 /* warning statuses */
#define kNtStatusDatatypeMisalignment     0x80000002
#define kNtStatusBreakpoint               0x80000003
#define kNtStatusSingleStep               0x80000004
#define kNtStatusLongjump                 0x80000026
#define kNtStatusUnwindConsolidate        0x80000029
#define kNtStatusAccessViolation          0xC0000005 /* error statuses */
#define kNtStatusInPageError              0xC0000006
#define kNtStatusInvalidHandle            0xC0000008
#define kNtStatusInvalidParameter         0xC000000D
#define kNtStatusNoMemory                 0xC0000017
#define kNtStatusIllegalInstruction       0xC000001D
#define kNtStatusNoncontinuableException  0xC0000025
#define kNtStatusInvalidDisposition       0xC0000026
#define kNtStatusArrayBoundsExceeded      0xC000008C
#define kNtStatusFloatDenormalOperand     0xC000008D
#define kNtStatusFloatDivideByZero        0xC000008E
#define kNtStatusFloatInexactResult       0xC000008F
#define kNtStatusFloatInvalidOperation    0xC0000090
#define kNtStatusFloatOverflow            0xC0000091
#define kNtStatusFloatStackCheck          0xC0000092
#define kNtStatusFloatUnderflow           0xC0000093
#define kNtStatusIntegerDivideBYZero      0xC0000094
#define kNtStatusIntegerOverflow          0xC0000095
#define kNtStatusPrivilegedInstruction    0xC0000096
#define kNtStatusStackOverflow            0xC00000FD
#define kNtStatusDllNotFound              0xC0000135
#define kNtStatusOrdinalNotFound          0xC0000138
#define kNtStatusEntrypointNotFound       0xC0000139
#define kNtStatusControlCExit             0xC000013A
#define kNtStatusDllInitFailed            0xC0000142
#define kNtStatusFloatMultipleFaults      0xC00002B4
#define kNtStatusFloatMultipleTraps       0xC00002B5
#define kNtStatusRegNatConsumption        0xC00002C9
#define kNtStatusHeapCorruption           0xC0000374
#define kNtStatusStackBufferOverrun       0xC0000409
#define kNtStatusInvalidCruntimeParameter 0xC0000417
#define kNtStatusAssertionFailure         0xC0000420
#define kNtStatusEnclaveViolation         0xC00004A2
#define kNtStatusSegmentNotification      0x40000005
#define kNtStatusFatalAppExit             0x40000015
#define kNtStatusNotFound                 0xC0000225
#define kNtStatusCancelled                0xC0000120

#define kNtDbgExceptionHandled    0x00010001
#define kNtDbgContinue            0x00010002
#define kNtDbgReplyLater          0x40010001
#define kNtDbgTerminateThread     0x40010003
#define kNtDbgTerminateProcess    0x40010004
#define kNtDbgControlC            0x40010005
#define kNtDbgPrintexceptionC     0x40010006
#define kNtDbgRipexception        0x40010007
#define kNtDbgControlBreak        0x40010008
#define kNtDbgCommandException    0x40010009
#define kNtDbgPrintexceptionWideC 0x4001000A
#define kNtDbgExceptionNotHandled 0x80010001
#define kNtStillActive            kNtStatusPending

#if !(__ASSEMBLER__ + __LINKER__ + 0)

typedef uint32_t NtStatus;

#define NtSuccess(s)      ((NtStatus)(s) >= 0)
#define NtInformation(s)  (NtSeverity(s) == 1)
#define NtWarning(s)      (NtSeverity(s) == 2)
#define NtError(s)        (NtSeverity(s) == 3)
#define NtCode(s)         ((NtStatus)(s)&0xffff)
#define NtSeverity(s)     ((NtStatus)(s) >> 30)
#define NtFacility(s)     (((NtStatus)(s) >> 16) & 0xfff)
#define NtFacilityCode(s) ((NtStatus)(s)&0x0FFFFFFF)

#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/nt/enum/sw.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SW_H_

#define kNtSwHide            0
#define kNtSwShownormal      1
#define kNtSwNormal          1
#define kNtSwShowminimized   2
#define kNtSwShowmaximized   3
#define kNtSwMaximize        3
#define kNtSwShownoactivate  4
#define kNtSwShow            5
#define kNtSwMinimize        6
#define kNtSwShowminnoactive 7
#define kNtSwShowna          8
#define kNtSwRestore         9
#define kNtSwShowdefault     10
#define kNtSwForceminimize   11



/*!BEGIN libc/nt/enum/symboliclink.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYMBOLICLINK_H_

#define kNtSymbolicLinkFlagDirectory               1
#define kNtSymbolicLinkFlagAllowUnprivilegedCreate 2



/*!BEGIN libc/nt/enum/systeminformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SYSTEMINFORMATIONCLASS_H_

#define kNtSystemBasicInformation 0
#define kNtSystemProcessorInformation 1
#define kNtSystemPerformanceInformation 2
#define kNtSystemTimeOfDayInformation 3
#define kNtSystemProcessInformation 5
#define kNtSystemProcessorTimes 8
#define kNtSystemGlobalFlag 9
#define kNtSystemModuleInformation 11
#define kNtSystemLockInformation 12
#define kNtSystemHandleInformation 16
#define kNtSystemObjectInformation 17
#define kNtSystemInterruptInformation 23
#define kNtSystemExceptionInformation 33
#define kNtSystemRegistryQuotaInformation 37
#define kNtSystemLookasideInformation 45



/*!BEGIN libc/nt/enum/th32cs.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TH32CS_H_

#define kNtTh32csInherit      0x80000000
#define kNtTh32csSnapheaplist 0x00000001
#define kNtTh32csSnapmodule   0x00000008
#define kNtTh32csSnapmodule32 0x00000010
#define kNtTh32csSnapprocess  0x00000002
#define kNtTh32csSnapthread   0x00000004



/*!BEGIN libc/nt/enum/threadaccess.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADACCESS_H_

#define kNtThreadTerminate 0x0001
#define kNtThreadSuspendResume 0x0002
#define kNtThreadGetContext 0x0008
#define kNtThreadSetContext 0x0010
#define kNtThreadQueryInformation 0x0040
#define kNtThreadSetInformation 0x0020
#define kNtThreadSetThreadToken 0x0080
#define kNtThreadImpersonate 0x0100
#define kNtThreadDirectImpersonation 0x0200
#define kNtThreadSetLimitedInformation 0x0400
#define kNtThreadQueryLimitedInformation 0x0800
#define kNtThreadResume 0x1000
#define kNtThreadAllAccess (kNtStandardRightsRequired | kNtSynchronize | 0xFFFF)



/*!BEGIN libc/nt/enum/threadinfoclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADINFOCLASS_H_

enum NtThreadInfoClass {
  kNtThreadBasicInformation,
  kNtThreadTimes,
  kNtThreadPriority,
  kNtThreadBasePriority,
  kNtThreadAffinityMask,
  kNtThreadImpersonationToken,
  kNtThreadDescriptorTableEntry,
  kNtThreadEnableAlignmentFaultFixup,
  kNtThreadEventPair_Reusable,
  kNtThreadQuerySetWin32StartAddress,
  kNtThreadZeroTlsCell,
  kNtThreadPerformanceCount,
  kNtThreadAmILastThread,
  kNtThreadIdealProcessor,
  kNtThreadPriorityBoost,
  kNtThreadSetTlsArrayAddress,
  kNtThreadIsIoPending,
  kNtThreadHideFromDebugger,
  kNtThreadInfoClass_MAX
};



/*!BEGIN libc/nt/enum/threadpriority.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADPRIORITY_H_

#define kNtThreadBasePriorityIdle  (-15)
#define kNtThreadBasePriorityMin   (-2)
#define kNtThreadBasePriorityMax   2
#define kNtThreadBasePriorityLowrt 15

#define kNtThreadPriorityIdle         kNtThreadBasePriorityIdle
#define kNtThreadPriorityLowest       kNtThreadBasePriorityMin
#define kNtThreadPriorityBelowNormal  (kNtThreadPriorityLowest + 1)
#define kNtThreadPriorityNormal       0
#define kNtThreadPriorityAboveNormal  (kNtThreadPriorityHighest - 1)
#define kNtThreadPriorityHighest      kNtThreadBasePriorityMax
#define kNtThreadPriorityTimeCritical kNtThreadBasePriorityLowrt



/*!BEGIN libc/nt/enum/threadstate.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_THREADSTATE_H_

#define kNtStateInitialized 0
#define kNtStateReady       1
#define kNtStateRunning     2
#define kNtStateStandby     3
#define kNtStateTerminated  4
#define kNtStateWait        5
#define kNtStateTransition  6
#define kNtStateUnknown     7



/*!BEGIN libc/nt/enum/timezoneid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TIMEZONEID_H_

#define kNtTimeZoneIdUnknown  0
#define kNtTimeZoneIdStandard 1
#define kNtTimeZoneIdDaylight 2



/*!BEGIN libc/nt/enum/tokeninformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENINFORMATIONCLASS_H_

#define kNtTokenUser 1
#define kNtTokenGroups 2
#define kNtTokenPrivileges 3
#define kNtTokenOwner 4
#define kNtTokenPrimaryGroup 5
#define kNtTokenDefaultDacl 6
#define kNtTokenSource 7
#define kNtTokenType 8
#define kNtTokenImpersonationLevel 9
#define kNtTokenStatistics 10
#define kNtTokenRestrictedSids 11
#define kNtTokenSessionId 12
#define kNtTokenGroupsAndPrivileges 13
#define kNtTokenSessionReference 14
#define kNtTokenSandBoxInert 15
#define kNtTokenAuditPolicy 16
#define kNtTokenOrigin 17
#define kNtTokenInfoClass_MAX 18



/*!BEGIN libc/nt/enum/tokentype.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TOKENTYPE_H_

#define kNtTokenPrimary       1
#define kNtTokenImpersonation 2



/*!BEGIN libc/nt/enum/tpm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_TPM_H_

#define kNtTpmLeftbutton      0x00000
#define kNtTpmRightbutton     0x00002
#define kNtTpmLeftalign       0x00000
#define kNtTpmCenteralign     0x00004
#define kNtTpmRightalign      0x00008
#define kNtTpmTopalign        0x00000
#define kNtTpmVcenteralign    0x00010
#define kNtTpmBottomalign     0x00020
#define kNtTpmHorizontal      0x00000
#define kNtTpmVertical        0x00040
#define kNtTpmNonotify        0x00080
#define kNtTpmReturncmd       0x00100
#define kNtTpmRecurse         0x00001
#define kNtTpmHorposanimation 0x00400
#define kNtTpmHorneganimation 0x00800
#define kNtTpmVerposanimation 0x01000
#define kNtTpmVerneganimation 0x02000
#define kNtTpmNoanimation     0x04000
#define kNtTpmLayoutrtl       0x08000
#define kNtTpmWorkarea        0x10000



/*!BEGIN libc/nt/enum/valueinformationclass.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VALUEINFORMATIONCLASS_H_

#define kNtKeyValueBasicInformation          0
#define kNtKeyValueFullInformation           1
#define kNtKeyValuePartialInformation        2
#define kNtKeyValueFullInformationAlign64    3
#define kNtKeyValuePartialInformationAlign64 4



/*!BEGIN libc/nt/enum/version.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VERSION_H_

/**
 * Known versions of the New Technology executive.
 * @see IsAtLeastWindows10()
 * @see NtGetVersion()
 */
#define kNtVersionWindows10    0x0a00
#define kNtVersionWindows81    0x0603
#define kNtVersionWindows8     0x0602
#define kNtVersionWindows7     0x0601
#define kNtVersionWindowsVista 0x0600 /* intended baseline */
#define kNtVersionWindowsXp64  0x0502 /* end of the road */
#define kNtVersionWindowsXp    0x0501 /* snowball's chance */
#define kNtVersionWindows2000  0x0500 /* the golden age */
#define kNtVersionFuture       0x0b00



/*!BEGIN libc/nt/enum/vk.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_VK_H_

#define kNtVkLbutton                      0x01
#define kNtVkRbutton                      0x02
#define kNtVkCancel                       0x03
#define kNtVkMbutton                      0x04
#define kNtVkXbutton1                     0x05
#define kNtVkXbutton2                     0x06
#define kNtVkBack                         0x08
#define kNtVkTab                          0x09
#define kNtVkClear                        0x0C
#define kNtVkReturn                       0x0D
#define kNtVkShift                        0x10
#define kNtVkControl                      0x11
#define kNtVkMenu                         0x12 /* alt? */
#define kNtVkPause                        0x13
#define kNtVkCapital                      0x14
#define kNtVkKana                         0x15
#define kNtVkHangul                       0x15
#define kNtVkJunja                        0x17
#define kNtVkFinal                        0x18
#define kNtVkHanja                        0x19
#define kNtVkKanji                        0x19
#define kNtVkEscape                       0x1B
#define kNtVkConvert                      0x1C
#define kNtVkNonconvert                   0x1D
#define kNtVkAccept                       0x1E
#define kNtVkModechange                   0x1F
#define kNtVkSpace                        0x20
#define kNtVkPrior                        0x21 /* page up */
#define kNtVkNext                         0x22 /* page down */
#define kNtVkEnd                          0x23
#define kNtVkHome                         0x24
#define kNtVkLeft                         0x25
#define kNtVkUp                           0x26
#define kNtVkRight                        0x27
#define kNtVkDown                         0x28
#define kNtVkSelect                       0x29
#define kNtVkPrint                        0x2A
#define kNtVkExecute                      0x2B
#define kNtVkSnapshot                     0x2C
#define kNtVkInsert                       0x2D
#define kNtVkDelete                       0x2E
#define kNtVkHelp                         0x2F
#define kNtVkLwin                         0x5B
#define kNtVkRwin                         0x5C
#define kNtVkApps                         0x5D
#define kNtVkSleep                        0x5F
#define kNtVkNumpad0                      0x60
#define kNtVkNumpad1                      0x61
#define kNtVkNumpad2                      0x62
#define kNtVkNumpad3                      0x63
#define kNtVkNumpad4                      0x64
#define kNtVkNumpad5                      0x65
#define kNtVkNumpad6                      0x66
#define kNtVkNumpad7                      0x67
#define kNtVkNumpad8                      0x68
#define kNtVkNumpad9                      0x69
#define kNtVkMultiply                     0x6A
#define kNtVkAdd                          0x6B
#define kNtVkSeparator                    0x6C
#define kNtVkSubtract                     0x6D
#define kNtVkDecimal                      0x6E
#define kNtVkDivide                       0x6F
#define kNtVkF1                           0x70
#define kNtVkF2                           0x71
#define kNtVkF3                           0x72
#define kNtVkF4                           0x73
#define kNtVkF5                           0x74
#define kNtVkF6                           0x75
#define kNtVkF7                           0x76
#define kNtVkF8                           0x77
#define kNtVkF9                           0x78
#define kNtVkF10                          0x79
#define kNtVkF11                          0x7A
#define kNtVkF12                          0x7B
#define kNtVkF13                          0x7C
#define kNtVkF14                          0x7D
#define kNtVkF15                          0x7E
#define kNtVkF16                          0x7F
#define kNtVkF17                          0x80
#define kNtVkF18                          0x81
#define kNtVkF19                          0x82
#define kNtVkF20                          0x83
#define kNtVkF21                          0x84
#define kNtVkF22                          0x85
#define kNtVkF23                          0x86
#define kNtVkF24                          0x87
#define kNtVkNumlock                      0x90
#define kNtVkScroll                       0x91
#define kNtVkLshift                       0xA0
#define kNtVkRshift                       0xA1
#define kNtVkLcontrol                     0xA2
#define kNtVkRcontrol                     0xA3
#define kNtVkLmenu                        0xA4
#define kNtVkRmenu                        0xA5
#define kNtVkBrowserBack                  0xA6
#define kNtVkBrowserForward               0xA7
#define kNtVkBrowserRefresh               0xA8
#define kNtVkBrowserStop                  0xA9
#define kNtVkBrowserSearch                0xAA
#define kNtVkBrowserFavorites             0xAB
#define kNtVkBrowserHome                  0xAC
#define kNtVkVolumeMute                   0xAD
#define kNtVkVolumeDown                   0xAE
#define kNtVkVolumeUp                     0xAF
#define kNtVkMediaNextTrack               0xB0
#define kNtVkMediaPrevTrack               0xB1
#define kNtVkMediaStop                    0xB2
#define kNtVkMediaPlayPause               0xB3
#define kNtVkLaunchMail                   0xB4
#define kNtVkLaunchMediaSelect            0xB5
#define kNtVkLaunchApp1                   0xB6
#define kNtVkLaunchApp2                   0xB7
#define kNtVkOem_1                        0xBA
#define kNtVkOemPlus                      0xBB
#define kNtVkOemComma                     0xBC
#define kNtVkOemMinus                     0xBD
#define kNtVkOemPeriod                    0xBE
#define kNtVkOem_2                        0xBF
#define kNtVkOem_3                        0xC0
#define kNtVkGamepadA                     0xC3
#define kNtVkGamepadB                     0xC4
#define kNtVkGamepadX                     0xC5
#define kNtVkGamepadY                     0xC6
#define kNtVkGamepadRightShoulder         0xC7
#define kNtVkGamepadLeftShoulder          0xC8
#define kNtVkGamepadLeftTrigger           0xC9
#define kNtVkGamepadRightTrigger          0xCA
#define kNtVkGamepadDpadUp                0xCB
#define kNtVkGamepadDpadDown              0xCC
#define kNtVkGamepadDpadLeft              0xCD
#define kNtVkGamepadDpadRight             0xCE
#define kNtVkGamepadMenu                  0xCF
#define kNtVkGamepadView                  0xD0
#define kNtVkGamepadLeftThumbstickButton  0xD1
#define kNtVkGamepadRightThumbstickButton 0xD2
#define kNtVkGamepadLeftThumbstickUp      0xD3
#define kNtVkGamepadLeftThumbstickDown    0xD4
#define kNtVkGamepadLeftThumbstickRight   0xD5
#define kNtVkGamepadLeftThumbstickLeft    0xD6
#define kNtVkGamepadRightThumbstickUp     0xD7
#define kNtVkGamepadRightThumbstickDown   0xD8
#define kNtVkGamepadRightThumbstickRight  0xD9
#define kNtVkGamepadRightThumbstickLeft   0xDA
#define kNtVkOem_4                        0xDB
#define kNtVkOem_5                        0xDC
#define kNtVkOem_6                        0xDD
#define kNtVkOem_7                        0xDE
#define kNtVkOem_8                        0xDF
#define kNtVkOemAx                        0xE1
#define kNtVkOem_102                      0xE2
#define kNtVkIcoHelp                      0xE3
#define kNtVkIco_00                       0xE4
#define kNtVkProcesskey                   0xE5
#define kNtVkIcoClear                     0xE6
#define kNtVkPacket                       0xE7
#define kNtVkOemReset                     0xE9
#define kNtVkOemJump                      0xEA
#define kNtVkOemPa1                       0xEB
#define kNtVkOemPa2                       0xEC
#define kNtVkOemPa3                       0xED
#define kNtVkOemWsctrl                    0xEE
#define kNtVkOemCusel                     0xEF
#define kNtVkOemAttn                      0xF0
#define kNtVkOemFinish                    0xF1
#define kNtVkOemCopy                      0xF2
#define kNtVkOemAuto                      0xF3
#define kNtVkOemEnlw                      0xF4
#define kNtVkOemBacktab                   0xF5
#define kNtVkAttn                         0xF6
#define kNtVkCrsel                        0xF7
#define kNtVkExsel                        0xF8
#define kNtVkEreof                        0xF9
#define kNtVkPlay                         0xFA
#define kNtVkZoom                         0xFB
#define kNtVkNoname                       0xFC
#define kNtVkPa1                          0xFD
#define kNtVkOemClear                     0xFE



/*!BEGIN libc/nt/enum/wa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WA_H_

#define kNtWaInactive    0
#define kNtWaActive      1
#define kNtWaClickactive 2



/*!BEGIN libc/nt/enum/wait.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WAIT_H_

#define kNtWaitFailed    0xffffffffu
#define kNtWaitTimeout   0x00000102u
#define kNtWaitAbandoned 0x00000080u



/*!BEGIN libc/nt/enum/wm.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WM_H_

#define kNtWmNull                   0x0000
#define kNtWmCreate                 0x0001
#define kNtWmDestroy                0x0002
#define kNtWmMove                   0x0003
#define kNtWmSize                   0x0005
#define kNtWmActivate               0x0006
#define kNtWmSetfocus               0x0007
#define kNtWmKillfocus              0x0008
#define kNtWmEnable                 0x000A
#define kNtWmSetredraw              0x000B
#define kNtWmSettext                0x000C
#define kNtWmGettext                0x000D
#define kNtWmGettextlength          0x000E
#define kNtWmPaint                  0x000F
#define kNtWmClose                  0x0010
#define kNtWmQueryendsession        0x0011
#define kNtWmQueryopen              0x0013
#define kNtWmEndsession             0x0016
#define kNtWmQuit                   0x0012
#define kNtWmErasebkgnd             0x0014
#define kNtWmSyscolorchange         0x0015
#define kNtWmShowwindow             0x0018
#define kNtWmWininichange           0x001A
#define kNtWmSettingchange          kNtWmWininichange
#define kNtWmDevmodechange          0x001B
#define kNtWmActivateapp            0x001C
#define kNtWmFontchange             0x001D
#define kNtWmTimechange             0x001E
#define kNtWmCancelmode             0x001F
#define kNtWmSetcursor              0x0020
#define kNtWmMouseactivate          0x0021
#define kNtWmChildactivate          0x0022
#define kNtWmQueuesync              0x0023
#define kNtWmGetminmaxinfo          0x0024
#define kNtWmPainticon              0x0026
#define kNtWmIconerasebkgnd         0x0027
#define kNtWmNextdlgctl             0x0028
#define kNtWmSpoolerstatus          0x002A
#define kNtWmDrawitem               0x002B
#define kNtWmMeasureitem            0x002C
#define kNtWmDeleteitem             0x002D
#define kNtWmVkeytoitem             0x002E
#define kNtWmChartoitem             0x002F
#define kNtWmSetfont                0x0030
#define kNtWmGetfont                0x0031
#define kNtWmSethotkey              0x0032
#define kNtWmGethotkey              0x0033
#define kNtWmQuerydragicon          0x0037
#define kNtWmCompareitem            0x0039
#define kNtWmGetobject              0x003D
#define kNtWmCompacting             0x0041
#define kNtWmWindowposchanging      0x0046
#define kNtWmWindowposchanged       0x0047
#define kNtWmPower                  0x0048
#define kNtWmCopydata               0x004A
#define kNtWmCanceljournal          0x004B
#define kNtWmNotify                 0x004E
#define kNtWmInputlangchangerequest 0x0050
#define kNtWmInputlangchange        0x0051
#define kNtWmTcard                  0x0052
#define kNtWmHelp                   0x0053
#define kNtWmUserchanged            0x0054
#define kNtWmNotifyformat           0x0055
#define kNtWmContextmenu            0x007B
#define kNtWmStylechanging          0x007C
#define kNtWmStylechanged           0x007D
#define kNtWmDisplaychange          0x007E
#define kNtWmGeticon                0x007F
#define kNtWmSeticon                0x0080
#define kNtWmNccreate               0x0081
#define kNtWmNcdestroy              0x0082
#define kNtWmNccalcsize             0x0083
#define kNtWmNchittest              0x0084
#define kNtWmNcpaint                0x0085
#define kNtWmNcactivate             0x0086
#define kNtWmGetdlgcode             0x0087
#define kNtWmNcmousemove            0x00A0
#define kNtWmNclbuttondown          0x00A1
#define kNtWmNclbuttonup            0x00A2
#define kNtWmNclbuttondblclk        0x00A3
#define kNtWmNcrbuttondown          0x00A4
#define kNtWmNcrbuttonup            0x00A5
#define kNtWmNcrbuttondblclk        0x00A6
#define kNtWmNcmbuttondown          0x00A7
#define kNtWmNcmbuttonup            0x00A8
#define kNtWmNcmbuttondblclk        0x00A9
#define kNtWmNcxbuttondown          0x00AB
#define kNtWmNcxbuttonup            0x00AC
#define kNtWmNcxbuttondblclk        0x00AD
#define kNtWmKeyfirst               0x0100
#define kNtWmKeydown                0x0100
#define kNtWmKeyup                  0x0101
#define kNtWmChar                   0x0102
#define kNtWmDeadchar               0x0103
#define kNtWmSyskeydown             0x0104
#define kNtWmSyskeyup               0x0105
#define kNtWmSyschar                0x0106
#define kNtWmSysdeadchar            0x0107
#define kNtWmUnichar                0x0109
#define kNtWmKeylast                0x0109
#define kNtWmInitdialog             0x0110
#define kNtWmCommand                0x0111
#define kNtWmSyscommand             0x0112
#define kNtWmTimer                  0x0113
#define kNtWmHscroll                0x0114
#define kNtWmVscroll                0x0115
#define kNtWmInitmenu               0x0116
#define kNtWmInitmenupopup          0x0117
#define kNtWmGesture                0x0119
#define kNtWmGesturenotify          0x011A
#define kNtWmMenuselect             0x011F
#define kNtWmMenuchar               0x0120
#define kNtWmEnteridle              0x0121
#define kNtWmMenurbuttonup          0x0122
#define kNtWmMenudrag               0x0123
#define kNtWmMenugetobject          0x0124
#define kNtWmUninitmenupopup        0x0125
#define kNtWmMenucommand            0x0126
#define kNtWmChangeuistate          0x0127
#define kNtWmUpdateuistate          0x0128
#define kNtWmQueryuistate           0x0129
#define kNtWmMousefirst             0x0200
#define kNtWmMousemove              0x0200
#define kNtWmLbuttondown            0x0201
#define kNtWmLbuttonup              0x0202
#define kNtWmLbuttondblclk          0x0203
#define kNtWmRbuttondown            0x0204
#define kNtWmRbuttonup              0x0205
#define kNtWmRbuttondblclk          0x0206
#define kNtWmMbuttondown            0x0207
#define kNtWmMbuttonup              0x0208
#define kNtWmMbuttondblclk          0x0209
#define kNtWmMousewheel             0x020A
#define kNtWmXbuttondown            0x020B
#define kNtWmXbuttonup              0x020C
#define kNtWmXbuttondblclk          0x020D
#define kNtWmMousehwheel            0x020E
#define kNtWmMouselast              0x020E
#define kNtWmParentnotify           0x0210
#define kNtWmEntermenuloop          0x0211
#define kNtWmExitmenuloop           0x0212
#define kNtWmNextmenu               0x0213
#define kNtWmSizing                 0x0214
#define kNtWmCapturechanged         0x0215
#define kNtWmMoving                 0x0216
#define kNtWmPowerbroadcast         0x0218
#define kNtWmMdicreate              0x0220
#define kNtWmMdidestroy             0x0221
#define kNtWmMdiactivate            0x0222
#define kNtWmMdirestore             0x0223
#define kNtWmMdinext                0x0224
#define kNtWmMdimaximize            0x0225
#define kNtWmMditile                0x0226
#define kNtWmMdicascade             0x0227
#define kNtWmMdiiconarrange         0x0228
#define kNtWmMdigetactive           0x0229
#define kNtWmMdisetmenu             0x0230
#define kNtWmEntersizemove          0x0231
#define kNtWmExitsizemove           0x0232
#define kNtWmDropfiles              0x0233
#define kNtWmMdirefreshmenu         0x0234
#define kNtWmCut                    0x0300
#define kNtWmCopy                   0x0301
#define kNtWmPaste                  0x0302
#define kNtWmClear                  0x0303
#define kNtWmUndo                   0x0304
#define kNtWmRenderformat           0x0305
#define kNtWmRenderallformats       0x0306
#define kNtWmDestroyclipboard       0x0307
#define kNtWmDrawclipboard          0x0308
#define kNtWmPaintclipboard         0x0309
#define kNtWmVscrollclipboard       0x030A
#define kNtWmSizeclipboard          0x030B
#define kNtWmAskcbformatname        0x030C
#define kNtWmChangecbchain          0x030D
#define kNtWmHscrollclipboard       0x030E
#define kNtWmQuerynewpalette        0x030F
#define kNtWmPaletteischanging      0x0310
#define kNtWmPalettechanged         0x0311
#define kNtWmHotkey                 0x0312



/*!BEGIN libc/nt/enum/ws.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WS_H_

#define kNtWsOverlapped   0x00000000
#define kNtWsPopup        0x80000000
#define kNtWsChild        0x40000000
#define kNtWsMinimize     0x20000000
#define kNtWsVisible      0x10000000
#define kNtWsDisabled     0x08000000
#define kNtWsClipsiblings 0x04000000
#define kNtWsClipchildren 0x02000000
#define kNtWsMaximize     0x01000000
#define kNtWsCaption      0x00C00000
#define kNtWsBorder       0x00800000
#define kNtWsDlgframe     0x00400000
#define kNtWsVscroll      0x00200000
#define kNtWsHscroll      0x00100000
#define kNtWsSysmenu      0x00080000
#define kNtWsThickframe   0x00040000
#define kNtWsGroup        0x00020000
#define kNtWsTabstop      0x00010000
#define kNtWsMinimizebox  0x00020000
#define kNtWsMaximizebox  0x00010000
#define kNtWsTiled        kNtWsOverlapped
#define kNtWsIconic       kNtWsMinimize
#define kNtWsSizebox      kNtWsThickframe
#define kNtWsTiledwindow  kNtWsOverlappedwindow
#define kNtWsOverlappedwindow                                        \
  (kNtWsOverlapped | kNtWsCaption | kNtWsSysmenu | kNtWsThickframe | \
   kNtWsMinimizebox | kNtWsMaximizebox)
#define kNtWsPopupwindow (kNtWsPopup | kNtWsBorder | kNtWsSysmenu)

#define kNtWsExDlgmodalframe       0x00000001
#define kNtWsExNoparentnotify      0x00000004
#define kNtWsExTopmost             0x00000008
#define kNtWsExAcceptfiles         0x00000010
#define kNtWsExTransparent         0x00000020
#define kNtWsExMdichild            0x00000040
#define kNtWsExToolwindow          0x00000080
#define kNtWsExWindowedge          0x00000100
#define kNtWsExClientedge          0x00000200
#define kNtWsExContexthelp         0x00000400
#define kNtWsExRight               0x00001000
#define kNtWsExLeft                0x00000000
#define kNtWsExRtlreading          0x00002000
#define kNtWsExLtrreading          0x00000000
#define kNtWsExLeftscrollbar       0x00004000
#define kNtWsExRightscrollbar      0x00000000
#define kNtWsExControlparent       0x00010000
#define kNtWsExStaticedge          0x00020000
#define kNtWsExAppwindow           0x00040000
#define kNtWsExNoinheritlayout     0x00100000
#define kNtWsExNoredirectionbitmap 0x00200000
#define kNtWsExLayoutrtl           0x00400000
#define kNtWsExComposited          0x02000000
#define kNtWsExNoactivate          0x08000000

#define kNtWsExOverlappedwindow (kNtWsExWindowedge | kNtWsExClientedge)
#define kNtWsExPalettewindow \
  (kNtWsExWindowedge | kNtWsExToolwindow | kNtWsExTopmost)



/*!BEGIN libc/nt/enum/wsa.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSA_H_


/*!BEGIN libc/nt/errors.h */

#define COSMOPOLITAN_NT_ERRORS_H_

#define kNtNoError 0

#define kNtErrorInsufficientBuffer 122

#define kNtErrorSuccess                                             0
#define kNtErrorInvalidFunction                                     1 /* ENOSYS */
#define kNtErrorFileNotFound                                        2 /* ENOENT */
#define kNtErrorPathNotFound                                        3 /* ENOTDIR */
#define kNtErrorTooManyOpenFiles                                    4 /* EMFILE */
#define kNtErrorAccessDenied                                        5 /* EACCES */
#define kNtErrorInvalidHandle                                       6 /* EBADF */
#define kNtErrorArenaTrashed                                        7
#define kNtErrorNotEnoughMemory                                     8
#define kNtErrorInvalidBlock                                        9
#define kNtErrorBadEnvironment                                      10
#define kNtErrorBadFormat                                           11
#define kNtErrorInvalidAccess                                       12 /* EPERM */
#define kNtErrorInvalidData                                         13
#define kNtErrorOutofmemory                                         14 /* ENOMEM */
#define kNtErrorInvalidDrive                                        15
#define kNtErrorCurrentDirectory                                    16
#define kNtErrorNotSameDevice                                       17
#define kNtErrorNoMoreFiles                                         18
#define kNtErrorWriteProtect                                        19
#define kNtErrorBadUnit                                             20
#define kNtErrorNotReady                                            21
#define kNtErrorBadCommand                                          22
#define kNtErrorCrc                                                 23
#define kNtErrorBadLength                                           24
#define kNtErrorSeek                                                25 /* ESPIPE */
#define kNtErrorNotDosDisk                                          26 /* ENOTBLK */
#define kNtErrorSectorNotFound                                      27
#define kNtErrorOutOfPaper                                          28
#define kNtErrorWriteFault                                          29
#define kNtErrorReadFault                                           30
#define kNtErrorGenFailure                                          31
#define kNtErrorSharingViolation                                    32
#define kNtErrorLockViolation                                       33
#define kNtErrorWrongDisk                                           34
#define kNtErrorSharingBufferExceeded                               36
#define kNtErrorHandleEof                                           38 /* w/ GetOverlappedResult() */
#define kNtErrorHandleDiskFull                                      39
#define kNtErrorNotSupported                                        50
#define kNtErrorRemNotList                                          51
#define kNtErrorDupName                                             52
#define kNtErrorBadNetpath                                          53
#define kNtErrorNetworkBusy                                         54
#define kNtErrorDevNotExist                                         55
#define kNtErrorTooManyCmds                                         56
#define kNtErrorAdapHdwErr                                          57
#define kNtErrorBadNetResp                                          58
#define kNtErrorUnexpNetErr                                         59
#define kNtErrorBadRemAdap                                          60
#define kNtErrorPrintqFull                                          61
#define kNtErrorNoSpoolSpace                                        62
#define kNtErrorPrintCancelled                                      63
#define kNtErrorNetnameDeleted                                      64
#define kNtErrorNetworkAccessDenied                                 65
#define kNtErrorBadDevType                                          66
#define kNtErrorBadNetName                                          67
#define kNtErrorTooManyNames                                        68
#define kNtErrorTooManySess                                         69
#define kNtErrorSharingPaused                                       70
#define kNtErrorReqNotAccep                                         71
#define kNtErrorRedirPaused                                         72
#define kNtErrorFileExists                                          80 /* EEXIST */
#define kNtErrorCannotMake                                          82
#define kNtErrorFailI24                                             83
#define kNtErrorOutOfStructures                                     84
#define kNtErrorAlreadyAssigned                                     85
#define kNtErrorInvalidPassword                                     86
#define kNtErrorInvalidParameter                                    87 /* EINVAL */
#define kNtErrorNetWriteFault                                       88
#define kNtErrorNoProcSlots                                         89
#define kNtErrorTooManySemaphores                                   100
#define kNtErrorExclSemAlreadyOwned                                 101
#define kNtErrorSemIsSet                                            102
#define kNtErrorTooManySemRequests                                  103
#define kNtErrorInvalidAtInterruptTime                              104
#define kNtErrorSemOwnerDied                                        105 /* EOWNERDEAD */
#define kNtErrorSemUserLimit                                        106
#define kNtErrorDiskChange                                          107
#define kNtErrorDriveLocked                                         108
#define kNtErrorBrokenPipe                                          109 /* EPIPE; happens on ReadFile() too */
#define kNtErrorOpenFailed                                          110
#define kNtErrorBufferOverflow                                      111
#define kNtErrorDiskFull                                            112 /* ENOSPC */
#define kNtErrorNoMoreSearchHandles                                 113
#define kNtErrorInvalidTargetHandle                                 114 /* EBADF */
#define kNtErrorInvalidCategory                                     117 /* ENOATTR */
#define kNtErrorInvalidVerifySwitch                                 118
#define kNtErrorBadDriverLevel                                      119
#define kNtErrorCallNotImplemented                                  120
#define kNtErrorSemTimeout                                          121
#define kNtErrorInsufficientBuffer                                  122
#define kNtErrorInvalidName                                         123
#define kNtErrorInvalidLevel                                        124
#define kNtErrorNoVolumeLabel                                       125
#define kNtErrorModNotFound                                         126
#define kNtErrorProcNotFound                                        127
#define kNtErrorWaitNoChildren                                      128 /* ECHILD */
#define kNtErrorChildNotComplete                                    129
#define kNtErrorDirectAccessHandle                                  130 /* EBADF */
#define kNtErrorNegativeSeek                                        131
#define kNtErrorSeekOnDevice                                        132
#define kNtErrorIsJoinTarget                                        133
#define kNtErrorIsJoined                                            134
#define kNtErrorIsSubsted                                           135
#define kNtErrorNotJoined                                           136
#define kNtErrorNotSubsted                                          137
#define kNtErrorJoinToJoin                                          138
#define kNtErrorSubstToSubst                                        139
#define kNtErrorJoinToSubst                                         140
#define kNtErrorSubstToJoin                                         141
#define kNtErrorBusyDrive                                           142
#define kNtErrorSameDrive                                           143
#define kNtErrorDirNotRoot                                          144
#define kNtErrorDirNotEmpty                                         145
#define kNtErrorIsSubstPath                                         146
#define kNtErrorIsJoinPath                                          147
#define kNtErrorPathBusy                                            148 /* ETXTBSY */
#define kNtErrorIsSubstTarget                                       149
#define kNtErrorSystemTrace                                         150
#define kNtErrorInvalidEventCount                                   151
#define kNtErrorTooManyMuxwaiters                                   152
#define kNtErrorInvalidListFormat                                   153
#define kNtErrorLabelTooLong                                        154
#define kNtErrorTooManyTcbs                                         155
#define kNtErrorSignalRefused                                       156
#define kNtErrorDiscarded                                           157
#define kNtErrorNotLocked                                           158 /* ENOLCK */
#define kNtErrorBadThreadidAddr                                     159
#define kNtErrorBadArguments                                        160
#define kNtErrorBadPathname                                         161
#define kNtErrorSignalPending                                       162
#define kNtErrorMaxThrdsReached                                     164
#define kNtErrorLockFailed                                          167
#define kNtErrorBusy                                                170 /* EBUSY */
#define kNtErrorDeviceSupportInProgress                             171
#define kNtErrorCancelViolation                                     173
#define kNtErrorAtomicLocksNotSupported                             174
#define kNtErrorInvalidSegmentNumber                                180
#define kNtErrorInvalidOrdinal                                      182
#define kNtErrorAlreadyExists                                       183 /* EEXIST */
#define kNtErrorInvalidFlagNumber                                   186
#define kNtErrorSemNotFound                                         187
#define kNtErrorInvalidStartingCodeseg                              188
#define kNtErrorInvalidStackseg                                     189
#define kNtErrorInvalidModuletype                                   190
#define kNtErrorInvalidExeSignature                                 191
#define kNtErrorExeMarkedInvalid                                    192 /* EBADEXEC */
#define kNtErrorBadExeFormat                                        193 /* ENOEXEC */
#define kNtErrorIteratedDataExceeds_64k                             194
#define kNtErrorInvalidMinallocsize                                 195
#define kNtErrorDynlinkFromInvalidRing                              196
#define kNtErrorIoplNotEnabled                                      197
#define kNtErrorInvalidSegdpl                                       198
#define kNtErrorAutodatasegExceeds_64k                              199
#define kNtErrorRing2segMustBeMovable                               200
#define kNtErrorRelocChainXeedsSeglim                               201
#define kNtErrorInfloopInRelocChain                                 202
#define kNtErrorEnvvarNotFound                                      203
#define kNtErrorNoSignalSent                                        205
#define kNtErrorFilenameExcedRange                                  206 /* ENAMETOOLONG */
#define kNtErrorRing2StackInUse                                     207
#define kNtErrorMetaExpansionTooLong                                208
#define kNtErrorInvalidSignalNumber                                 209
#define kNtErrorThread_1Inactive                                    210
#define kNtErrorLocked                                              212
#define kNtErrorTooManyModules                                      214
#define kNtErrorNestingNotAllowed                                   215
#define kNtErrorExeMachineTypeMismatch                              216 /* EBADARCH */
#define kNtErrorExeCannotModifySignedBinary                         217
#define kNtErrorExeCannotModifyStrongSignedBinary                   218
#define kNtErrorFileCheckedOut                                      220
#define kNtErrorCheckoutRequired                                    221
#define kNtErrorBadFileType                                         222 /* EFTYPE */
#define kNtErrorFileTooLarge                                        223 /* EFBIG */
#define kNtErrorFormsAuthRequired                                   224 /* ENEEDAUTH */
#define kNtErrorVirusInfected                                       225
#define kNtErrorVirusDeleted                                        226
#define kNtErrorPipeLocal                                           229
#define kNtErrorBadPipe                                             230
#define kNtErrorPipeBusy                                            231
#define kNtErrorNoData                                              232
#define kNtErrorPipeNotConnected                                    233
#define kNtErrorMoreData                                            234
#define kNtErrorNoWorkDone                                          235
#define kNtErrorVcDisconnected                                      240
#define kNtErrorInvalidEaName                                       254
#define kNtErrorEaListInconsistent                                  255
#define kNtErrorNoMoreItems                                         259
#define kNtErrorCannotCopy                                          266
#define kNtErrorDirectory                                           267 /* EISDIR */
#define kNtErrorEasDidntFit                                         275
#define kNtErrorEaFileCorrupt                                       276
#define kNtErrorEaTableFull                                         277
#define kNtErrorInvalidEaHandle                                     278
#define kNtErrorEasNotSupported                                     282
#define kNtErrorNotOwner                                            288
#define kNtErrorTooManyPosts                                        298
#define kNtErrorPartialCopy                                         299
#define kNtErrorOplockNotGranted                                    300
#define kNtErrorInvalidOplockProtocol                               301
#define kNtErrorDiskTooFragmented                                   302
#define kNtErrorDeletePending                                       303
#define kNtErrorIncompatibleWithGlobalShortNameRegistrySetting      304
#define kNtErrorShortNamesNotEnabledOnVolume                        305
#define kNtErrorSecurityStreamIsInconsistent                        306
#define kNtErrorInvalidLockRange                                    307
#define kNtErrorImageSubsystemNotPresent                            308
#define kNtErrorNotificationGuidAlreadyDefined                      309
#define kNtErrorInvalidExceptionHandler                             310
#define kNtErrorDuplicatePrivileges                                 311
#define kNtErrorNoRangesProcessed                                   312
#define kNtErrorNotAllowedOnSystemFile                              313
#define kNtErrorDiskResourcesExhausted                              314
#define kNtErrorInvalidToken                                        315
#define kNtErrorDeviceFeatureNotSupported                           316
#define kNtErrorMrMidNotFound                                       317
#define kNtErrorScopeNotFound                                       318
#define kNtErrorUndefinedScope                                      319
#define kNtErrorInvalidCap                                          320
#define kNtErrorDeviceUnreachable                                   321
#define kNtErrorDeviceNoResources                                   322
#define kNtErrorDataChecksumError                                   323
#define kNtErrorIntermixedKernelEaOperation                         324
#define kNtErrorFileLevelTrimNotSupported                           326
#define kNtErrorOffsetAlignmentViolation                            327
#define kNtErrorInvalidFieldInParameterList                         328
#define kNtErrorOperationInProgress                                 329 /* EPROGUNAVAIL */
#define kNtErrorBadDevicePath                                       330
#define kNtErrorTooManyDescriptors                                  331 /* ENFILE */
#define kNtErrorScrubDataDisabled                                   332
#define kNtErrorNotRedundantStorage                                 333
#define kNtErrorResidentFileNotSupported                            334
#define kNtErrorCompressedFileNotSupported                          335
#define kNtErrorDirectoryNotSupported                               336
#define kNtErrorNotReadFromCopy                                     337
#define kNtErrorFtWriteFailure                                      338
#define kNtErrorFtDiScanRequired                                    339
#define kNtErrorInvalidKernelInfoVersion                            340
#define kNtErrorInvalidPepInfoVersion                               341
#define kNtErrorObjectNotExternallyBacked                           342
#define kNtErrorExternalBackingProviderUnknown                      343
#define kNtErrorCompressionNotBeneficial                            344
#define kNtErrorStorageTopologyIdMismatch                           345
#define kNtErrorBlockedByParentalControls                           346
#define kNtErrorBlockTooManyReferences                              347
#define kNtErrorMarkedToDisallowWrites                              348
#define kNtErrorEnclaveFailure                                      349
#define kNtErrorFailNoactionReboot                                  350
#define kNtErrorFailShutdown                                        351
#define kNtErrorFailRestart                                         352
#define kNtErrorMaxSessionsReached                                  353
#define kNtErrorNetworkAccessDeniedEdp                              354
#define kNtErrorDeviceHintNameBufferTooSmall                        355
#define kNtErrorEdpPolicyDeniesOperation                            356
#define kNtErrorEdpDplPolicyCantBeSatisfied                         357
#define kNtErrorCloudFileSyncRootMetadataCorrupt                    358
#define kNtErrorDeviceInMaintenance                                 359
#define kNtErrorNotSupportedOnDax                                   360
#define kNtErrorDaxMappingExists                                    361
#define kNtErrorCloudFileProviderNotRunning                         362
#define kNtErrorCloudFileMetadataCorrupt                            363
#define kNtErrorCloudFileMetadataTooLarge                           364
#define kNtErrorCloudFilePropertyBlobTooLarge                       365
#define kNtErrorCloudFilePropertyBlobChecksumMismatch               366
#define kNtErrorChildProcessBlocked                                 367
#define kNtErrorStorageLostDataPersistence                          368
#define kNtErrorFileSystemVirtualizationUnavailable                 369
#define kNtErrorFileSystemVirtualizationMetadataCorrupt             370
#define kNtErrorFileSystemVirtualizationBusy                        371
#define kNtErrorFileSystemVirtualizationProviderUnknown             372
#define kNtErrorGdiHandleLeak                                       373
#define kNtErrorCloudFileTooManyPropertyBlobs                       374
#define kNtErrorCloudFilePropertyVersionNotSupported                375
#define kNtErrorNotACloudFile                                       376
#define kNtErrorCloudFileNotInSync                                  377
#define kNtErrorCloudFileAlreadyConnected                           378
#define kNtErrorCloudFileNotSupported                               379
#define kNtErrorCloudFileInvalidRequest                             380
#define kNtErrorCloudFileReadOnlyVolume                             381
#define kNtErrorCloudFileConnectedProviderOnly                      382
#define kNtErrorCloudFileValidationFailed                           383
#define kNtErrorSmb1NotAvailable                                    384
#define kNtErrorFileSystemVirtualizationInvalidOperation            385
#define kNtErrorCloudFileAuthenticationFailed                       386
#define kNtErrorCloudFileInsufficientResources                      387
#define kNtErrorCloudFileNetworkUnavailable                         388
#define kNtErrorCloudFileUnsuccessful                               389
#define kNtErrorCloudFileNotUnderSyncRoot                           390
#define kNtErrorCloudFileInUse                                      391
#define kNtErrorCloudFilePinned                                     392
#define kNtErrorCloudFileRequestAborted                             393
#define kNtErrorCloudFilePropertyCorrupt                            394
#define kNtErrorCloudFileAccessDenied                               395
#define kNtErrorCloudFileIncompatibleHardlinks                      396
#define kNtErrorCloudFilePropertyLockConflict                       397
#define kNtErrorCloudFileRequestCanceled                            398
#define kNtErrorExternalSyskeyNotSupported                          399
#define kNtErrorThreadModeAlreadyBackground                         400
#define kNtErrorThreadModeNotBackground                             401
#define kNtErrorProcessModeAlreadyBackground                        402
#define kNtErrorProcessModeNotBackground                            403
#define kNtErrorCloudFileProviderTerminated                         404
#define kNtErrorNotACloudSyncRoot                                   405
#define kNtErrorFileProtectedUnderDpl                               406
#define kNtErrorVolumeNotClusterAligned                             407
#define kNtErrorNoPhysicallyAlignedFreeSpaceFound                   408
#define kNtErrorAppxFileNotEncrypted                                409
#define kNtErrorRwrawEncryptedFileNotEncrypted                      410
#define kNtErrorRwrawEncryptedInvalidEdatainfoFileoffset            411
#define kNtErrorRwrawEncryptedInvalidEdatainfoFilerange             412
#define kNtErrorRwrawEncryptedInvalidEdatainfoParameter             413
#define kNtErrorLinuxSubsystemNotPresent                            414
#define kNtErrorCapauthzNotDevunlocked                              450
#define kNtErrorCapauthzChangeType                                  451
#define kNtErrorCapauthzNotProvisioned                              452
#define kNtErrorCapauthzNotAuthorized                               453
#define kNtErrorCapauthzNoPolicy                                    454
#define kNtErrorCapauthzDbCorrupted                                 455
#define kNtErrorCapauthzSccdInvalidCatalog                          456
#define kNtErrorCapauthzSccdNoAuthEntity                            457
#define kNtErrorCapauthzSccdParseError                              458
#define kNtErrorCapauthzSccdDevModeRequired                         459
#define kNtErrorCapauthzSccdNoCapabilityMatch                       460
#define kNtErrorPnpQueryRemoveDeviceTimeout                         480
#define kNtErrorPnpQueryRemoveRelatedDeviceTimeout                  481
#define kNtErrorPnpQueryRemoveUnrelatedDeviceTimeout                482
#define kNtErrorDeviceHardwareError                                 483 /* EDEVERR */
#define kNtErrorInvalidAddress                                      487 /* EFAULT */
#define kNtErrorVrfCfgEnabled                                       1183
#define kNtErrorPartitionTerminating                                1184
#define kNtErrorUserProfileLoad                                     500
#define kNtErrorArithmeticOverflow                                  534 /* EOVERFLOW */
#define kNtErrorPipeConnected                                       535
#define kNtErrorPipeListening                                       536
#define kNtErrorVerifierStop                                        537
#define kNtErrorAbiosError                                          538
#define kNtErrorWx86Warning                                         539
#define kNtErrorWx86Error                                           540
#define kNtErrorTimerNotCanceled                                    541
#define kNtErrorUnwind                                              542
#define kNtErrorBadStack                                            543
#define kNtErrorInvalidUnwindTarget                                 544
#define kNtErrorInvalidPortAttributes                               545
#define kNtErrorPortMessageTooLong                                  546
#define kNtErrorInvalidQuotaLower                                   547
#define kNtErrorDeviceAlreadyAttached                               548
#define kNtErrorInstructionMisalignment                             549
#define kNtErrorProfilingNotStarted                                 550
#define kNtErrorProfilingNotStopped                                 551
#define kNtErrorCouldNotInterpret                                   552
#define kNtErrorProfilingAtLimit                                    553
#define kNtErrorCantWait                                            554
#define kNtErrorCantTerminateSelf                                   555
#define kNtErrorUnexpectedMmCreateErr                               556
#define kNtErrorUnexpectedMmMapError                                557
#define kNtErrorUnexpectedMmExtendErr                               558
#define kNtErrorBadFunctionTable                                    559
#define kNtErrorNoGuidTranslation                                   560
#define kNtErrorInvalidLdtSize                                      561
#define kNtErrorInvalidLdtOffset                                    563
#define kNtErrorInvalidLdtDescriptor                                564
#define kNtErrorTooManyThreads                                      565
#define kNtErrorThreadNotInProcess                                  566 /* ESRCH */
#define kNtErrorPagefileQuotaExceeded                               567
#define kNtErrorLogonServerConflict                                 568
#define kNtErrorSynchronizationRequired                             569
#define kNtErrorNetOpenFailed                                       570
#define kNtErrorIoPrivilegeFailed                                   571
#define kNtErrorControlCExit                                        572
#define kNtErrorMissingSystemfile                                   573
#define kNtErrorUnhandledException                                  574
#define kNtErrorAppInitFailure                                      575
#define kNtErrorPagefileCreateFailed                                576
#define kNtErrorInvalidImageHash                                    577
#define kNtErrorNoPagefile                                          578
#define kNtErrorIllegalFloatContext                                 579
#define kNtErrorNoEventPair                                         580
#define kNtErrorDomainCtrlrConfigError                              581
#define kNtErrorIllegalCharacter                                    582 /* EILSEQ */
#define kNtErrorUndefinedCharacter                                  583
#define kNtErrorFloppyVolume                                        584
#define kNtErrorBiosFailedToConnectInterrupt                        585
#define kNtErrorBackupController                                    586
#define kNtErrorMutantLimitExceeded                                 587
#define kNtErrorFsDriverRequired                                    588
#define kNtErrorCannotLoadRegistryFile                              589
#define kNtErrorDebugAttachFailed                                   590
#define kNtErrorSystemProcessTerminated                             591
#define kNtErrorDataNotAccepted                                     592
#define kNtErrorVdmHardError                                        593
#define kNtErrorDriverCancelTimeout                                 594
#define kNtErrorReplyMessageMismatch                                595 /* EPROGMISMATCH */
#define kNtErrorLostWritebehindData                                 596
#define kNtErrorClientServerParametersInvalid                       597
#define kNtErrorNotTinyStream                                       598
#define kNtErrorStackOverflowRead                                   599
#define kNtErrorConvertToLarge                                      600
#define kNtErrorFoundOutOfScope                                     601
#define kNtErrorAllocateBucket                                      602
#define kNtErrorMarshallOverflow                                    603
#define kNtErrorInvalidVariant                                      604
#define kNtErrorBadCompressionBuffer                                605
#define kNtErrorAuditFailed                                         606
#define kNtErrorTimerResolutionNotSet                               607
#define kNtErrorInsufficientLogonInfo                               608
#define kNtErrorBadDllEntrypoint                                    609
#define kNtErrorBadServiceEntrypoint                                610
#define kNtErrorIpAddressConflict1                                  611
#define kNtErrorIpAddressConflict2                                  612
#define kNtErrorRegistryQuotaLimit                                  613
#define kNtErrorNoCallbackActive                                    614
#define kNtErrorPwdTooShort                                         615
#define kNtErrorPwdTooRecent                                        616
#define kNtErrorPwdHistoryConflict                                  617
#define kNtErrorUnsupportedCompression                              618
#define kNtErrorInvalidHwProfile                                    619
#define kNtErrorInvalidPlugplayDevicePath                           620
#define kNtErrorQuotaListInconsistent                               621
#define kNtErrorEvaluationExpiration                                622
#define kNtErrorIllegalDllRelocation                                623
#define kNtErrorDllInitFailedLogoff                                 624
#define kNtErrorValidateContinue                                    625
#define kNtErrorNoMoreMatches                                       626
#define kNtErrorRangeListConflict                                   627
#define kNtErrorServerSidMismatch                                   628
#define kNtErrorCantEnableDenyOnly                                  629
#define kNtErrorFloatMultipleFaults                                 630
#define kNtErrorFloatMultipleTraps                                  631
#define kNtErrorNointerface                                         632
#define kNtErrorDriverFailedSleep                                   633
#define kNtErrorCorruptSystemFile                                   634
#define kNtErrorCommitmentMinimum                                   635
#define kNtErrorPnpRestartEnumeration                               636
#define kNtErrorSystemImageBadSignature                             637
#define kNtErrorPnpRebootRequired                                   638
#define kNtErrorInsufficientPower                                   639 /* EPWROFF */
#define kNtErrorMultipleFaultViolation                              640
#define kNtErrorSystemShutdown                                      641
#define kNtErrorPortNotSet                                          642
#define kNtErrorDsVersionCheckFailure                               643
#define kNtErrorRangeNotFound                                       644
#define kNtErrorNotSafeModeDriver                                   646
#define kNtErrorFailedDriverEntry                                   647
#define kNtErrorDeviceEnumerationError                              648
#define kNtErrorMountPointNotResolved                               649
#define kNtErrorInvalidDeviceObjectParameter                        650
#define kNtErrorMcaOccured                                          651
#define kNtErrorDriverDatabaseError                                 652
#define kNtErrorSystemHiveTooLarge                                  653
#define kNtErrorDriverFailedPriorUnload                             654
#define kNtErrorVolsnapPrepareHibernate                             655
#define kNtErrorHibernationFailure                                  656
#define kNtErrorPwdTooLong                                          657
#define kNtErrorFileSystemLimitation                                665
#define kNtErrorAssertionFailure                                    668
#define kNtErrorAcpiError                                           669
#define kNtErrorWowAssertion                                        670
#define kNtErrorPnpBadMpsTable                                      671
#define kNtErrorPnpTranslationFailed                                672
#define kNtErrorPnpIrqTranslationFailed                             673
#define kNtErrorPnpInvalidId                                        674
#define kNtErrorWakeSystemDebugger                                  675
#define kNtErrorHandlesClosed                                       676
#define kNtErrorExtraneousInformation                               677
#define kNtErrorRxactCommitNecessary                                678
#define kNtErrorMediaCheck                                          679
#define kNtErrorGuidSubstitutionMade                                680
#define kNtErrorStoppedOnSymlink                                    681
#define kNtErrorLongjump                                            682
#define kNtErrorPlugplayQueryVetoed                                 683
#define kNtErrorUnwindConsolidate                                   684
#define kNtErrorRegistryHiveRecovered                               685
#define kNtErrorDllMightBeInsecure                                  686
#define kNtErrorDllMightBeIncompatible                              687
#define kNtErrorDbgExceptionNotHandled                              688
#define kNtErrorDbgReplyLater                                       689
#define kNtErrorDbgUnableToProvideHandle                            690
#define kNtErrorDbgTerminateThread                                  691
#define kNtErrorDbgTerminateProcess                                 692
#define kNtErrorDbgControlC                                         693
#define kNtErrorDbgPrintexceptionC                                  694
#define kNtErrorDbgRipexception                                     695
#define kNtErrorDbgControlBreak                                     696
#define kNtErrorDbgCommandException                                 697
#define kNtErrorObjectNameExists                                    698
#define kNtErrorThreadWasSuspended                                  699
#define kNtErrorImageNotAtBase                                      700
#define kNtErrorRxactStateCreated                                   701
#define kNtErrorSegmentNotification                                 702
#define kNtErrorBadCurrentDirectory                                 703
#define kNtErrorFtReadRecoveryFromBackup                            704
#define kNtErrorFtWriteRecovery                                     705
#define kNtErrorImageMachineTypeMismatch                            706
#define kNtErrorReceivePartial                                      707
#define kNtErrorReceiveExpedited                                    708
#define kNtErrorReceivePartialExpedited                             709
#define kNtErrorEventDone                                           710
#define kNtErrorEventPending                                        711
#define kNtErrorCheckingFileSystem                                  712
#define kNtErrorFatalAppExit                                        713
#define kNtErrorPredefinedHandle                                    714
#define kNtErrorWasUnlocked                                         715
#define kNtErrorServiceNotification                                 716
#define kNtErrorWasLocked                                           717
#define kNtErrorLogHardError                                        718
#define kNtErrorAlreadyWin32                                        719
#define kNtErrorImageMachineTypeMismatchExe                         720
#define kNtErrorNoYieldPerformed                                    721
#define kNtErrorTimerResumeIgnored                                  722
#define kNtErrorArbitrationUnhandled                                723
#define kNtErrorCardbusNotSupported                                 724
#define kNtErrorMpProcessorMismatch                                 725
#define kNtErrorHibernated                                          726
#define kNtErrorResumeHibernation                                   727
#define kNtErrorFirmwareUpdated                                     728
#define kNtErrorDriversLeakingLockedPages                           729
#define kNtErrorWakeSystem                                          730
#define kNtErrorWait_1                                              731
#define kNtErrorWait_2                                              732
#define kNtErrorWait_3                                              733
#define kNtErrorWait_63                                             734
#define kNtErrorAbandonedWait_0                                     735
#define kNtErrorAbandonedWait_63                                    736
#define kNtErrorUserApc                                             737
#define kNtErrorKernelApc                                           738
#define kNtErrorAlerted                                             739
#define kNtErrorElevationRequired                                   740
#define kNtErrorReparse                                             741
#define kNtErrorOplockBreakInProgress                               742
#define kNtErrorVolumeMounted                                       743
#define kNtErrorRxactCommitted                                      744
#define kNtErrorNotifyCleanup                                       745
#define kNtErrorPrimaryTransportConnectFailed                       746
#define kNtErrorPageFaultTransition                                 747
#define kNtErrorPageFaultDemandZero                                 748
#define kNtErrorPageFaultCopyOnWrite                                749
#define kNtErrorPageFaultGuardPage                                  750
#define kNtErrorPageFaultPagingFile                                 751
#define kNtErrorCachePageLocked                                     752
#define kNtErrorCrashDump                                           753
#define kNtErrorBufferAllZeros                                      754
#define kNtErrorReparseObject                                       755
#define kNtErrorResourceRequirementsChanged                         756
#define kNtErrorTranslationComplete                                 757
#define kNtErrorNothingToTerminate                                  758
#define kNtErrorProcessNotInJob                                     759
#define kNtErrorProcessInJob                                        760
#define kNtErrorVolsnapHibernateReady                               761
#define kNtErrorFsfilterOpCompletedSuccessfully                     762
#define kNtErrorInterruptVectorAlreadyConnected                     763
#define kNtErrorInterruptStillConnected                             764
#define kNtErrorWaitForOplock                                       765
#define kNtErrorDbgExceptionHandled                                 766
#define kNtErrorDbgContinue                                         767
#define kNtErrorCallbackPopStack                                    768
#define kNtErrorCompressionDisabled                                 769
#define kNtErrorCantfetchbackwards                                  770
#define kNtErrorCantscrollbackwards                                 771
#define kNtErrorRowsnotreleased                                     772
#define kNtErrorBadAccessorFlags                                    773
#define kNtErrorErrorsEncountered                                   774
#define kNtErrorNotCapable                                          775
#define kNtErrorRequestOutOfSequence                                776
#define kNtErrorVersionParseError                                   777
#define kNtErrorBadstartposition                                    778
#define kNtErrorMemoryHardware                                      779
#define kNtErrorDiskRepairDisabled                                  780
#define kNtErrorInsufficientResourceForSpecifiedSharedSectionSize   781
#define kNtErrorSystemPowerstateTransition                          782
#define kNtErrorSystemPowerstateComplexTransition                   783
#define kNtErrorMcaException                                        784
#define kNtErrorAccessAuditByPolicy                                 785
#define kNtErrorAccessDisabledNoSaferUiByPolicy                     786
#define kNtErrorAbandonHiberfile                                    787
#define kNtErrorLostWritebehindDataNetworkDisconnected              788
#define kNtErrorLostWritebehindDataNetworkServerError               789
#define kNtErrorLostWritebehindDataLocalDiskError                   790
#define kNtErrorBadMcfgTable                                        791
#define kNtErrorDiskRepairRedirected                                792
#define kNtErrorDiskRepairUnsuccessful                              793
#define kNtErrorCorruptLogOverfull                                  794
#define kNtErrorCorruptLogCorrupted                                 795
#define kNtErrorCorruptLogUnavailable                               796
#define kNtErrorCorruptLogDeletedFull                               797
#define kNtErrorCorruptLogCleared                                   798
#define kNtErrorOrphanNameExhausted                                 799
#define kNtErrorOplockSwitchedToNewHandle                           800
#define kNtErrorCannotGrantRequestedOplock                          801
#define kNtErrorCannotBreakOplock                                   802
#define kNtErrorOplockHandleClosed                                  803
#define kNtErrorNoAceCondition                                      804
#define kNtErrorInvalidAceCondition                                 805
#define kNtErrorFileHandleRevoked                                   806
#define kNtErrorImageAtDifferentBase                                807
#define kNtErrorEncryptedIoNotPossible                              808
#define kNtErrorFileMetadataOptimizationInProgress                  809
#define kNtErrorQuotaActivity                                       810
#define kNtErrorHandleRevoked                                       811
#define kNtErrorCallbackInvokeInline                                812
#define kNtErrorCpuSetInvalid                                       813
#define kNtErrorEnclaveNotTerminated                                814
#define kNtErrorEnclaveViolation                                    815
#define kNtErrorEaAccessDenied                                      994
#define kNtErrorOperationAborted                                    995
#define kNtErrorIoIncomplete                                        996
#define kNtErrorIoPending                                           997
#define kNtErrorNoaccess                                            998
#define kNtErrorSwaperror                                           999
#define kNtErrorStackOverflow                                       1001
#define kNtErrorInvalidMessage                                      1002
#define kNtErrorCanNotComplete                                      1003
#define kNtErrorInvalidFlags                                        1004
#define kNtErrorUnrecognizedVolume                                  1005
#define kNtErrorFileInvalid                                         1006
#define kNtErrorFullscreenMode                                      1007
#define kNtErrorNoToken                                             1008
#define kNtErrorBaddb                                               1009
#define kNtErrorBadkey                                              1010
#define kNtErrorCantopen                                            1011
#define kNtErrorCantread                                            1012
#define kNtErrorCantwrite                                           1013
#define kNtErrorRegistryRecovered                                   1014
#define kNtErrorRegistryCorrupt                                     1015
#define kNtErrorRegistryIoFailed                                    1016
#define kNtErrorNotRegistryFile                                     1017
#define kNtErrorKeyDeleted                                          1018
#define kNtErrorNoLogSpace                                          1019
#define kNtErrorKeyHasChildren                                      1020
#define kNtErrorChildMustBeVolatile                                 1021
#define kNtErrorNotifyEnumDir                                       1022
#define kNtErrorDependentServicesRunning                            1051
#define kNtErrorInvalidServiceControl                               1052
#define kNtErrorServiceRequestTimeout                               1053
#define kNtErrorServiceNoThread                                     1054
#define kNtErrorServiceDatabaseLocked                               1055
#define kNtErrorServiceAlreadyRunning                               1056
#define kNtErrorInvalidServiceAccount                               1057
#define kNtErrorServiceDisabled                                     1058
#define kNtErrorCircularDependency                                  1059
#define kNtErrorServiceDoesNotExist                                 1060
#define kNtErrorServiceCannotAcceptCtrl                             1061
#define kNtErrorServiceNotActive                                    1062
#define kNtErrorFailedServiceControllerConnect                      1063
#define kNtErrorExceptionInService                                  1064
#define kNtErrorDatabaseDoesNotExist                                1065
#define kNtErrorServiceSpecificError                                1066
#define kNtErrorProcessAborted                                      1067
#define kNtErrorServiceDependencyFail                               1068
#define kNtErrorServiceLogonFailed                                  1069
#define kNtErrorServiceStartHang                                    1070
#define kNtErrorInvalidServiceLock                                  1071
#define kNtErrorServiceMarkedForDelete                              1072
#define kNtErrorServiceExists                                       1073
#define kNtErrorAlreadyRunningLkg                                   1074
#define kNtErrorServiceDependencyDeleted                            1075
#define kNtErrorBootAlreadyAccepted                                 1076
#define kNtErrorServiceNeverStarted                                 1077
#define kNtErrorDuplicateServiceName                                1078
#define kNtErrorDifferentServiceAccount                             1079
#define kNtErrorCannotDetectDriverFailure                           1080
#define kNtErrorCannotDetectProcessAbort                            1081
#define kNtErrorNoRecoveryProgram                                   1082
#define kNtErrorServiceNotInExe                                     1083
#define kNtErrorNotSafebootService                                  1084
#define kNtErrorEndOfMedia                                          1100
#define kNtErrorFilemarkDetected                                    1101
#define kNtErrorBeginningOfMedia                                    1102
#define kNtErrorSetmarkDetected                                     1103
#define kNtErrorNoDataDetected                                      1104
#define kNtErrorPartitionFailure                                    1105
#define kNtErrorInvalidBlockLength                                  1106
#define kNtErrorDeviceNotPartitioned                                1107
#define kNtErrorUnableToLockMedia                                   1108
#define kNtErrorUnableToUnloadMedia                                 1109
#define kNtErrorMediaChanged                                        1110
#define kNtErrorBusReset                                            1111
#define kNtErrorNoMediaInDrive                                      1112 /* ENXIO */
#define kNtErrorNoUnicodeTranslation                                1113
#define kNtErrorDllInitFailed                                       1114
#define kNtErrorShutdownInProgress                                  1115
#define kNtErrorNoShutdownInProgress                                1116
#define kNtErrorIoDevice                                            1117 /* EIO */
#define kNtErrorSerialNoDevice                                      1118 /* ENOTTY */
#define kNtErrorIrqBusy                                             1119
#define kNtErrorMoreWrites                                          1120
#define kNtErrorCounterTimeout                                      1121
#define kNtErrorFloppyIdMarkNotFound                                1122
#define kNtErrorFloppyWrongCylinder                                 1123
#define kNtErrorFloppyUnknownError                                  1124
#define kNtErrorFloppyBadRegisters                                  1125
#define kNtErrorDiskRecalibrateFailed                               1126
#define kNtErrorDiskOperationFailed                                 1127
#define kNtErrorDiskResetFailed                                     1128
#define kNtErrorEomOverflow                                         1129
#define kNtErrorNotEnoughServerMemory                               1130
#define kNtErrorPossibleDeadlock                                    1131 /* EDEADLK */
#define kNtErrorMappedAlignment                                     1132
#define kNtErrorSetPowerStateVetoed                                 1140
#define kNtErrorSetPowerStateFailed                                 1141
#define kNtErrorTooManyLinks                                        1142
#define kNtErrorOldWinVersion                                       1150
#define kNtErrorAppWrongOs                                          1151
#define kNtErrorSingleInstanceApp                                   1152
#define kNtErrorRmodeApp                                            1153
#define kNtErrorInvalidDll                                          1154
#define kNtErrorNoAssociation                                       1155
#define kNtErrorDdeFail                                             1156
#define kNtErrorDllNotFound                                         1157
#define kNtErrorNoMoreUserHandles                                   1158
#define kNtErrorMessageSyncOnly                                     1159
#define kNtErrorSourceElementEmpty                                  1160
#define kNtErrorDestinationElementFull                              1161
#define kNtErrorIllegalElementAddress                               1162
#define kNtErrorMagazineNotPresent                                  1163
#define kNtErrorDeviceReinitializationNeeded                        1164
#define kNtErrorDeviceRequiresCleaning                              1165
#define kNtErrorDeviceDoorOpen                                      1166
#define kNtErrorDeviceNotConnected                                  1167
#define kNtErrorNotFound                                            1168
#define kNtErrorNoMatch                                             1169
#define kNtErrorSetNotFound                                         1170
#define kNtErrorPointNotFound                                       1171
#define kNtErrorNoTrackingService                                   1172
#define kNtErrorNoVolumeId                                          1173
#define kNtErrorUnableToRemoveReplaced                              1175
#define kNtErrorUnableToMoveReplacement                             1176
#define kNtErrorUnableToMoveReplacement_2                           1177
#define kNtErrorJournalDeleteInProgress                             1178
#define kNtErrorJournalNotActive                                    1179
#define kNtErrorPotentialFileFound                                  1180
#define kNtErrorJournalEntryDeleted                                 1181
#define kNtErrorShutdownIsScheduled                                 1190
#define kNtErrorShutdownUsersLoggedOn                               1191
#define kNtErrorBadDevice                                           1200 /* ENODEV */
#define kNtErrorConnectionUnavail                                   1201
#define kNtErrorDeviceAlreadyRemembered                             1202
#define kNtErrorNoNetOrBadPath                                      1203
#define kNtErrorBadProvider                                         1204
#define kNtErrorCannotOpenProfile                                   1205
#define kNtErrorBadProfile                                          1206
#define kNtErrorNotContainer                                        1207
#define kNtErrorExtendedError                                       1208
#define kNtErrorInvalidGroupname                                    1209
#define kNtErrorInvalidComputername                                 1210
#define kNtErrorInvalidEventname                                    1211
#define kNtErrorInvalidDomainname                                   1212
#define kNtErrorInvalidServicename                                  1213
#define kNtErrorInvalidNetname                                      1214
#define kNtErrorInvalidSharename                                    1215
#define kNtErrorInvalidPasswordname                                 1216
#define kNtErrorInvalidMessagename                                  1217
#define kNtErrorInvalidMessagedest                                  1218
#define kNtErrorSessionCredentialConflict                           1219
#define kNtErrorRemoteSessionLimitExceeded                          1220
#define kNtErrorDupDomainname                                       1221
#define kNtErrorNoNetwork                                           1222
#define kNtErrorCancelled                                           1223 /* ECANCELED */
#define kNtErrorUserMappedFile                                      1224
#define kNtErrorConnectionRefused                                   1225
#define kNtErrorGracefulDisconnect                                  1226
#define kNtErrorAddressAlreadyAssociated                            1227
#define kNtErrorAddressNotAssociated                                1228
#define kNtErrorConnectionInvalid                                   1229
#define kNtErrorConnectionActive                                    1230
#define kNtErrorNetworkUnreachable                                  1231
#define kNtErrorHostUnreachable                                     1232
#define kNtErrorProtocolUnreachable                                 1233 /* multimapped to ENETUNREACH */
#define kNtErrorPortUnreachable                                     1234
#define kNtErrorRequestAborted                                      1235
#define kNtErrorConnectionAborted                                   1236
#define kNtErrorRetry                                               1237
#define kNtErrorConnectionCountLimit                                1238
#define kNtErrorLoginTimeRestriction                                1239
#define kNtErrorLoginWkstaRestriction                               1240
#define kNtErrorIncorrectAddress                                    1241
#define kNtErrorAlreadyRegistered                                   1242
#define kNtErrorServiceNotFound                                     1243
#define kNtErrorNotAuthenticated                                    1244 /* EAUTH */
#define kNtErrorNotLoggedOn                                         1245
#define kNtErrorContinue                                            1246
#define kNtErrorAlreadyInitialized                                  1247
#define kNtErrorNoMoreDevices                                       1248
#define kNtErrorNoSuchSite                                          1249
#define kNtErrorDomainControllerExists                              1250
#define kNtErrorOnlyIfConnected                                     1251
#define kNtErrorOverrideNochanges                                   1252
#define kNtErrorBadUserProfile                                      1253
#define kNtErrorNotSupportedOnSbs                                   1254
#define kNtErrorServerShutdownInProgress                            1255
#define kNtErrorHostDown                                            1256
#define kNtErrorNonAccountSid                                       1257
#define kNtErrorNonDomainSid                                        1258
#define kNtErrorApphelpBlock                                        1259
#define kNtErrorAccessDisabledByPolicy                              1260
#define kNtErrorRegNatConsumption                                   1261
#define kNtErrorCscshareOffline                                     1262
#define kNtErrorPkinitFailure                                       1263
#define kNtErrorSmartcardSubsystemFailure                           1264
#define kNtErrorDowngradeDetected                                   1265
#define kNtErrorMachineLocked                                       1271
#define kNtErrorSmbGuestLogonBlocked                                1272
#define kNtErrorCallbackSuppliedInvalidData                         1273
#define kNtErrorSyncForegroundRefreshRequired                       1274
#define kNtErrorDriverBlocked                                       1275
#define kNtErrorInvalidImportOfNonDll                               1276
#define kNtErrorAccessDisabledWebblade                              1277
#define kNtErrorAccessDisabledWebbladeTamper                        1278
#define kNtErrorRecoveryFailure                                     1279
#define kNtErrorAlreadyFiber                                        1280
#define kNtErrorAlreadyThread                                       1281
#define kNtErrorStackBufferOverrun                                  1282
#define kNtErrorParameterQuotaExceeded                              1283
#define kNtErrorDebuggerInactive                                    1284
#define kNtErrorDelayLoadFailed                                     1285
#define kNtErrorVdmDisallowed                                       1286
#define kNtErrorUnidentifiedError                                   1287 /* EIDRM */
#define kNtErrorInvalidCruntimeParameter                            1288
#define kNtErrorBeyondVdl                                           1289
#define kNtErrorIncompatibleServiceSidType                          1290
#define kNtErrorDriverProcessTerminated                             1291
#define kNtErrorImplementationLimit                                 1292
#define kNtErrorProcessIsProtected                                  1293
#define kNtErrorServiceNotifyClientLagging                          1294
#define kNtErrorDiskQuotaExceeded                                   1295
#define kNtErrorContentBlocked                                      1296
#define kNtErrorIncompatibleServicePrivilege                        1297
#define kNtErrorAppHang                                             1298
#define kNtErrorInvalidLabel                                        1299
#define kNtErrorNotAllAssigned                                      1300
#define kNtErrorSomeNotMapped                                       1301
#define kNtErrorNoQuotasForAccount                                  1302
#define kNtErrorLocalUserSessionKey                                 1303
#define kNtErrorNullLmPassword                                      1304
#define kNtErrorUnknownRevision                                     1305
#define kNtErrorRevisionMismatch                                    1306
#define kNtErrorInvalidOwner                                        1307
#define kNtErrorInvalidPrimaryGroup                                 1308
#define kNtErrorNoImpersonationToken                                1309
#define kNtErrorCantDisableMandatory                                1310
#define kNtErrorNoLogonServers                                      1311
#define kNtErrorNoSuchLogonSession                                  1312
#define kNtErrorNoSuchPrivilege                                     1313
#define kNtErrorPrivilegeNotHeld                                    1314
#define kNtErrorInvalidAccountName                                  1315
#define kNtErrorUserExists                                          1316
#define kNtErrorNoSuchUser                                          1317
#define kNtErrorGroupExists                                         1318
#define kNtErrorNoSuchGroup                                         1319
#define kNtErrorMemberInGroup                                       1320
#define kNtErrorMemberNotInGroup                                    1321
#define kNtErrorLastAdmin                                           1322
#define kNtErrorWrongPassword                                       1323
#define kNtErrorIllFormedPassword                                   1324
#define kNtErrorPasswordRestriction                                 1325
#define kNtErrorLogonFailure                                        1326
#define kNtErrorAccountRestriction                                  1327
#define kNtErrorInvalidLogonHours                                   1328
#define kNtErrorInvalidWorkstation                                  1329
#define kNtErrorPasswordExpired                                     1330
#define kNtErrorAccountDisabled                                     1331
#define kNtErrorNoneMapped                                          1332
#define kNtErrorTooManyLuidsRequested                               1333
#define kNtErrorLuidsExhausted                                      1334
#define kNtErrorInvalidSubAuthority                                 1335
#define kNtErrorInvalidAcl                                          1336
#define kNtErrorInvalidSid                                          1337
#define kNtErrorInvalidSecurityDescr                                1338
#define kNtErrorBadInheritanceAcl                                   1340
#define kNtErrorServerDisabled                                      1341
#define kNtErrorServerNotDisabled                                   1342
#define kNtErrorInvalidIdAuthority                                  1343
#define kNtErrorAllottedSpaceExceeded                               1344
#define kNtErrorInvalidGroupAttributes                              1345
#define kNtErrorBadImpersonationLevel                               1346
#define kNtErrorCantOpenAnonymous                                   1347
#define kNtErrorBadValidationClass                                  1348
#define kNtErrorBadTokenType                                        1349
#define kNtErrorNoSecurityOnObject                                  1350
#define kNtErrorCantAccessDomainInfo                                1351
#define kNtErrorInvalidServerState                                  1352
#define kNtErrorInvalidDomainState                                  1353
#define kNtErrorInvalidDomainRole                                   1354
#define kNtErrorNoSuchDomain                                        1355
#define kNtErrorDomainExists                                        1356
#define kNtErrorDomainLimitExceeded                                 1357
#define kNtErrorInternalDbCorruption                                1358
#define kNtErrorInternalError                                       1359
#define kNtErrorGenericNotMapped                                    1360
#define kNtErrorBadDescriptorFormat                                 1361
#define kNtErrorNotLogonProcess                                     1362
#define kNtErrorLogonSessionExists                                  1363
#define kNtErrorNoSuchPackage                                       1364
#define kNtErrorBadLogonSessionState                                1365
#define kNtErrorLogonSessionCollision                               1366
#define kNtErrorInvalidLogonType                                    1367
#define kNtErrorCannotImpersonate                                   1368
#define kNtErrorRxactInvalidState                                   1369
#define kNtErrorRxactCommitFailure                                  1370
#define kNtErrorSpecialAccount                                      1371
#define kNtErrorSpecialGroup                                        1372
#define kNtErrorSpecialUser                                         1373
#define kNtErrorMembersPrimaryGroup                                 1374
#define kNtErrorTokenAlreadyInUse                                   1375
#define kNtErrorNoSuchAlias                                         1376
#define kNtErrorMemberNotInAlias                                    1377
#define kNtErrorMemberInAlias                                       1378
#define kNtErrorAliasExists                                         1379
#define kNtErrorLogonNotGranted                                     1380
#define kNtErrorTooManySecrets                                      1381
#define kNtErrorSecretTooLong                                       1382
#define kNtErrorInternalDbError                                     1383
#define kNtErrorTooManyContextIds                                   1384
#define kNtErrorLogonTypeNotGranted                                 1385
#define kNtErrorNtCrossEncryptionRequired                           1386
#define kNtErrorNoSuchMember                                        1387
#define kNtErrorInvalidMember                                       1388
#define kNtErrorTooManySids                                         1389
#define kNtErrorLmCrossEncryptionRequired                           1390
#define kNtErrorNoInheritance                                       1391
#define kNtErrorFileCorrupt                                         1392
#define kNtErrorDiskCorrupt                                         1393
#define kNtErrorNoUserSessionKey                                    1394
#define kNtErrorLicenseQuotaExceeded                                1395
#define kNtErrorWrongTargetName                                     1396
#define kNtErrorMutualAuthFailed                                    1397
#define kNtErrorTimeSkew                                            1398
#define kNtErrorCurrentDomainNotAllowed                             1399
#define kNtErrorInvalidWindowHandle                                 1400
#define kNtErrorInvalidMenuHandle                                   1401
#define kNtErrorInvalidCursorHandle                                 1402
#define kNtErrorInvalidAccelHandle                                  1403
#define kNtErrorInvalidHookHandle                                   1404
#define kNtErrorInvalidDwpHandle                                    1405
#define kNtErrorTlwWithWschild                                      1406
#define kNtErrorCannotFindWndClass                                  1407
#define kNtErrorWindowOfOtherThread                                 1408
#define kNtErrorHotkeyAlreadyRegistered                             1409
#define kNtErrorClassAlreadyExists                                  1410
#define kNtErrorClassDoesNotExist                                   1411
#define kNtErrorClassHasWindows                                     1412
#define kNtErrorInvalidIndex                                        1413
#define kNtErrorInvalidIconHandle                                   1414
#define kNtErrorPrivateDialogIndex                                  1415
#define kNtErrorListboxIdNotFound                                   1416
#define kNtErrorNoWildcardCharacters                                1417
#define kNtErrorClipboardNotOpen                                    1418
#define kNtErrorHotkeyNotRegistered                                 1419
#define kNtErrorWindowNotDialog                                     1420
#define kNtErrorControlIdNotFound                                   1421
#define kNtErrorInvalidComboboxMessage                              1422
#define kNtErrorWindowNotCombobox                                   1423
#define kNtErrorInvalidEditHeight                                   1424
#define kNtErrorDcNotFound                                          1425
#define kNtErrorInvalidHookFilter                                   1426
#define kNtErrorInvalidFilterProc                                   1427
#define kNtErrorHookNeedsHmod                                       1428
#define kNtErrorGlobalOnlyHook                                      1429
#define kNtErrorJournalHookSet                                      1430
#define kNtErrorHookNotInstalled                                    1431
#define kNtErrorInvalidLbMessage                                    1432
#define kNtErrorSetcountOnBadLb                                     1433
#define kNtErrorLbWithoutTabstops                                   1434
#define kNtErrorDestroyObjectOfOtherThread                          1435
#define kNtErrorChildWindowMenu                                     1436
#define kNtErrorNoSystemMenu                                        1437
#define kNtErrorInvalidMsgboxStyle                                  1438
#define kNtErrorInvalidSpiValue                                     1439
#define kNtErrorScreenAlreadyLocked                                 1440
#define kNtErrorHwndsHaveDiffParent                                 1441
#define kNtErrorNotChildWindow                                      1442
#define kNtErrorInvalidGwCommand                                    1443
#define kNtErrorInvalidThreadId                                     1444
#define kNtErrorNonMdichildWindow                                   1445
#define kNtErrorPopupAlreadyActive                                  1446
#define kNtErrorNoScrollbars                                        1447
#define kNtErrorInvalidScrollbarRange                               1448
#define kNtErrorInvalidShowwinCommand                               1449
#define kNtErrorNoSystemResources                                   1450
#define kNtErrorNonpagedSystemResources                             1451
#define kNtErrorPagedSystemResources                                1452
#define kNtErrorWorkingSetQuota                                     1453
#define kNtErrorPagefileQuota                                       1454
#define kNtErrorCommitmentLimit                                     1455
#define kNtErrorMenuItemNotFound                                    1456
#define kNtErrorInvalidKeyboardHandle                               1457
#define kNtErrorHookTypeNotAllowed                                  1458
#define kNtErrorRequiresInteractiveWindowstation                    1459
#define kNtErrorTimeout                                             1460 /* ETIMEDOUT */
#define kNtErrorInvalidMonitorHandle                                1461
#define kNtErrorIncorrectSize                                       1462
#define kNtErrorSymlinkClassDisabled                                1463
#define kNtErrorSymlinkNotSupported                                 1464
#define kNtErrorXmlParseError                                       1465
#define kNtErrorXmldsigError                                        1466
#define kNtErrorRestartApplication                                  1467
#define kNtErrorWrongCompartment                                    1468
#define kNtErrorAuthipFailure                                       1469
#define kNtErrorNoNvramResources                                    1470
#define kNtErrorNotGuiProcess                                       1471
#define kNtErrorEventlogFileCorrupt                                 1500
#define kNtErrorEventlogCantStart                                   1501
#define kNtErrorLogFileFull                                         1502
#define kNtErrorEventlogFileChanged                                 1503
#define kNtErrorContainerAssigned                                   1504
#define kNtErrorJobNoContainer                                      1505
#define kNtErrorInvalidTaskName                                     1550
#define kNtErrorInvalidTaskIndex                                    1551
#define kNtErrorThreadAlreadyInTask                                 1552
#define kNtErrorInstallServiceFailure                               1601
#define kNtErrorInstallUserexit                                     1602
#define kNtErrorInstallFailure                                      1603
#define kNtErrorInstallSuspend                                      1604
#define kNtErrorUnknownProduct                                      1605
#define kNtErrorUnknownFeature                                      1606
#define kNtErrorUnknownComponent                                    1607
#define kNtErrorUnknownProperty                                     1608
#define kNtErrorInvalidHandleState                                  1609
#define kNtErrorBadConfiguration                                    1610
#define kNtErrorIndexAbsent                                         1611
#define kNtErrorInstallSourceAbsent                                 1612
#define kNtErrorInstallPackageVersion                               1613
#define kNtErrorProductUninstalled                                  1614
#define kNtErrorBadQuerySyntax                                      1615
#define kNtErrorInvalidField                                        1616
#define kNtErrorDeviceRemoved                                       1617
#define kNtErrorInstallAlreadyRunning                               1618
#define kNtErrorInstallPackageOpenFailed                            1619
#define kNtErrorInstallPackageInvalid                               1620
#define kNtErrorInstallUiFailure                                    1621
#define kNtErrorInstallLogFailure                                   1622
#define kNtErrorInstallLanguageUnsupported                          1623
#define kNtErrorInstallTransformFailure                             1624
#define kNtErrorInstallPackageRejected                              1625
#define kNtErrorFunctionNotCalled                                   1626 /* EBADRPC */
#define kNtErrorFunctionFailed                                      1627 /* ERPCMISMATCH */
#define kNtErrorInvalidTable                                        1628
#define kNtErrorDatatypeMismatch                                    1629
#define kNtErrorUnsupportedType                                     1630
#define kNtErrorCreateFailed                                        1631
#define kNtErrorInstallTempUnwritable                               1632
#define kNtErrorInstallPlatformUnsupported                          1633
#define kNtErrorInstallNotused                                      1634
#define kNtErrorPatchPackageOpenFailed                              1635
#define kNtErrorPatchPackageInvalid                                 1636
#define kNtErrorPatchPackageUnsupported                             1637
#define kNtErrorProductVersion                                      1638
#define kNtErrorInvalidCommandLine                                  1639 /* E2BIG */
#define kNtErrorInstallRemoteDisallowed                             1640
#define kNtErrorSuccessRebootInitiated                              1641
#define kNtErrorPatchTargetNotFound                                 1642
#define kNtErrorPatchPackageRejected                                1643
#define kNtErrorInstallTransformRejected                            1644
#define kNtErrorInstallRemoteProhibited                             1645
#define kNtErrorPatchRemovalUnsupported                             1646
#define kNtErrorUnknownPatch                                        1647
#define kNtErrorPatchNoSequence                                     1648
#define kNtErrorPatchRemovalDisallowed                              1649
#define kNtErrorInvalidPatchXml                                     1650
#define kNtErrorPatchManagedAdvertisedProduct                       1651
#define kNtErrorInstallServiceSafeboot                              1652
#define kNtErrorFailFastException                                   1653
#define kNtErrorInstallRejected                                     1654
#define kNtErrorDynamicCodeBlocked                                  1655
#define kNtErrorNotSameObject                                       1656
#define kNtErrorStrictCfgViolation                                  1657
#define kNtErrorSetContextDenied                                    1660
#define kNtErrorCrossPartitionViolation                             1661
#define kNtErrorInvalidUserBuffer                                   1784
#define kNtErrorUnrecognizedMedia                                   1785
#define kNtErrorNoTrustLsaSecret                                    1786
#define kNtErrorNoTrustSamAccount                                   1787
#define kNtErrorTrustedDomainFailure                                1788
#define kNtErrorTrustedRelationshipFailure                          1789
#define kNtErrorTrustFailure                                        1790
#define kNtErrorNetlogonNotStarted                                  1792
#define kNtErrorAccountExpired                                      1793
#define kNtErrorRedirectorHasOpenHandles                            1794
#define kNtErrorPrinterDriverAlreadyInstalled                       1795
#define kNtErrorUnknownPort                                         1796
#define kNtErrorUnknownPrinterDriver                                1797
#define kNtErrorUnknownPrintprocessor                               1798
#define kNtErrorInvalidSeparatorFile                                1799
#define kNtErrorInvalidPriority                                     1800
#define kNtErrorInvalidPrinterName                                  1801
#define kNtErrorPrinterAlreadyExists                                1802
#define kNtErrorInvalidPrinterCommand                               1803
#define kNtErrorInvalidDatatype                                     1804
#define kNtErrorInvalidEnvironment                                  1805
#define kNtErrorNologonInterdomainTrustAccount                      1807
#define kNtErrorNologonWorkstationTrustAccount                      1808
#define kNtErrorNologonServerTrustAccount                           1809
#define kNtErrorDomainTrustInconsistent                             1810
#define kNtErrorServerHasOpenHandles                                1811
#define kNtErrorResourceDataNotFound                                1812
#define kNtErrorResourceTypeNotFound                                1813
#define kNtErrorResourceNameNotFound                                1814
#define kNtErrorResourceLangNotFound                                1815
#define kNtErrorNotEnoughQuota                                      1816 /* EDQUOT */
#define kNtErrorInvalidTime                                         1901
#define kNtErrorInvalidFormName                                     1902
#define kNtErrorInvalidFormSize                                     1903
#define kNtErrorAlreadyWaiting                                      1904
#define kNtErrorPrinterDeleted                                      1905
#define kNtErrorInvalidPrinterState                                 1906
#define kNtErrorPasswordMustChange                                  1907
#define kNtErrorDomainControllerNotFound                            1908
#define kNtErrorAccountLockedOut                                    1909
#define kNtErrorNoSitename                                          1919
#define kNtErrorCantAccessFile                                      1920
#define kNtErrorCantResolveFilename                                 1921
#define kNtErrorKmDriverBlocked                                     1930
#define kNtErrorContextExpired                                      1931
#define kNtErrorPerUserTrustQuotaExceeded                           1932
#define kNtErrorAllUserTrustQuotaExceeded                           1933
#define kNtErrorUserDeleteTrustQuotaExceeded                        1934
#define kNtErrorAuthenticationFirewallFailed                        1935
#define kNtErrorRemotePrintConnectionsBlocked                       1936
#define kNtErrorNtlmBlocked                                         1937
#define kNtErrorPasswordChangeRequired                              1938
#define kNtErrorLostModeLogonRestriction                            1939
#define kNtErrorInvalidPixelFormat                                  2000
#define kNtErrorBadDriver                                           2001
#define kNtErrorInvalidWindowStyle                                  2002
#define kNtErrorMetafileNotSupported                                2003
#define kNtErrorTransformNotSupported                               2004
#define kNtErrorClippingNotSupported                                2005
#define kNtErrorInvalidCmm                                          2010
#define kNtErrorInvalidProfile                                      2011
#define kNtErrorTagNotFound                                         2012
#define kNtErrorTagNotPresent                                       2013
#define kNtErrorDuplicateTag                                        2014
#define kNtErrorProfileNotAssociatedWithDevice                      2015
#define kNtErrorProfileNotFound                                     2016
#define kNtErrorInvalidColorspace                                   2017
#define kNtErrorIcmNotEnabled                                       2018
#define kNtErrorDeletingIcmXform                                    2019
#define kNtErrorInvalidTransform                                    2020
#define kNtErrorColorspaceMismatch                                  2021
#define kNtErrorInvalidColorindex                                   2022
#define kNtErrorProfileDoesNotMatchDevice                           2023
#define kNtErrorConnectedOtherPassword                              2108
#define kNtErrorConnectedOtherPasswordDefault                       2109
#define kNtErrorBadUsername                                         2202
#define kNtErrorNotConnected                                        2250
#define kNtErrorOpenFiles                                           2401
#define kNtErrorActiveConnections                                   2402
#define kNtErrorDeviceInUse                                         2404
#define kNtErrorUnknownPrintMonitor                                 3000
#define kNtErrorPrinterDriverInUse                                  3001
#define kNtErrorSpoolFileNotFound                                   3002
#define kNtErrorSplNoStartdoc                                       3003
#define kNtErrorSplNoAddjob                                         3004
#define kNtErrorPrintProcessorAlreadyInstalled                      3005
#define kNtErrorPrintMonitorAlreadyInstalled                        3006
#define kNtErrorInvalidPrintMonitor                                 3007
#define kNtErrorPrintMonitorInUse                                   3008
#define kNtErrorPrinterHasJobsQueued                                3009
#define kNtErrorSuccessRebootRequired                               3010
#define kNtErrorSuccessRestartRequired                              3011
#define kNtErrorPrinterNotFound                                     3012
#define kNtErrorPrinterDriverWarned                                 3013
#define kNtErrorPrinterDriverBlocked                                3014
#define kNtErrorPrinterDriverPackageInUse                           3015
#define kNtErrorCoreDriverPackageNotFound                           3016
#define kNtErrorFailRebootRequired                                  3017
#define kNtErrorFailRebootInitiated                                 3018
#define kNtErrorPrinterDriverDownloadNeeded                         3019
#define kNtErrorPrintJobRestartRequired                             3020
#define kNtErrorInvalidPrinterDriverManifest                        3021
#define kNtErrorPrinterNotShareable                                 3022
#define kNtErrorRequestPaused                                       3050
#define kNtErrorAppexecConditionNotSatisfied                        3060
#define kNtErrorAppexecHandleInvalidated                            3061
#define kNtErrorAppexecInvalidHostGeneration                        3062
#define kNtErrorAppexecUnexpectedProcessRegistration                3063
#define kNtErrorAppexecInvalidHostState                             3064
#define kNtErrorAppexecNoDonor                                      3065
#define kNtErrorAppexecHostIdMismatch                               3066
#define kNtErrorIoReissueAsCached                                   3950
#define kNtErrorWinsInternal                                        4000
#define kNtErrorCanNotDelLocalWins                                  4001
#define kNtErrorStaticInit                                          4002
#define kNtErrorIncBackup                                           4003
#define kNtErrorFullBackup                                          4004
#define kNtErrorRecNonExistent                                      4005
#define kNtErrorRplNotAllowed                                       4006
#define kNtErrorDhcpAddressConflict                                 4100
#define kNtErrorWmiGuidNotFound                                     4200
#define kNtErrorWmiInstanceNotFound                                 4201
#define kNtErrorWmiItemidNotFound                                   4202
#define kNtErrorWmiTryAgain                                         4203
#define kNtErrorWmiDpNotFound                                       4204
#define kNtErrorWmiUnresolvedInstanceRef                            4205
#define kNtErrorWmiAlreadyEnabled                                   4206
#define kNtErrorWmiGuidDisconnected                                 4207
#define kNtErrorWmiServerUnavailable                                4208
#define kNtErrorWmiDpFailed                                         4209
#define kNtErrorWmiInvalidMof                                       4210
#define kNtErrorWmiInvalidReginfo                                   4211
#define kNtErrorWmiAlreadyDisabled                                  4212
#define kNtErrorWmiReadOnly                                         4213
#define kNtErrorWmiSetFailure                                       4214
#define kNtErrorNotAppcontainer                                     4250
#define kNtErrorAppcontainerRequired                                4251
#define kNtErrorNotSupportedInAppcontainer                          4252
#define kNtErrorInvalidPackageSidLength                             4253
#define kNtErrorInvalidMedia                                        4300
#define kNtErrorInvalidLibrary                                      4301
#define kNtErrorInvalidMediaPool                                    4302
#define kNtErrorDriveMediaMismatch                                  4303
#define kNtErrorMediaOffline                                        4304
#define kNtErrorLibraryOffline                                      4305
#define kNtErrorEmpty                                               4306 /* ENOMSG */
#define kNtErrorNotEmpty                                            4307
#define kNtErrorMediaUnavailable                                    4308
#define kNtErrorResourceDisabled                                    4309
#define kNtErrorInvalidCleaner                                      4310
#define kNtErrorUnableToClean                                       4311
#define kNtErrorObjectNotFound                                      4312
#define kNtErrorDatabaseFailure                                     4313
#define kNtErrorDatabaseFull                                        4314
#define kNtErrorMediaIncompatible                                   4315
#define kNtErrorResourceNotPresent                                  4316
#define kNtErrorInvalidOperation                                    4317
#define kNtErrorMediaNotAvailable                                   4318
#define kNtErrorDeviceNotAvailable                                  4319
#define kNtErrorRequestRefused                                      4320
#define kNtErrorInvalidDriveObject                                  4321
#define kNtErrorLibraryFull                                         4322
#define kNtErrorMediumNotAccessible                                 4323
#define kNtErrorUnableToLoadMedium                                  4324
#define kNtErrorUnableToInventoryDrive                              4325
#define kNtErrorUnableToInventorySlot                               4326
#define kNtErrorUnableToInventoryTransport                          4327
#define kNtErrorTransportFull                                       4328
#define kNtErrorControllingIeport                                   4329
#define kNtErrorUnableToEjectMountedMedia                           4330
#define kNtErrorCleanerSlotSet                                      4331
#define kNtErrorCleanerSlotNotSet                                   4332
#define kNtErrorCleanerCartridgeSpent                               4333
#define kNtErrorUnexpectedOmid                                      4334
#define kNtErrorCantDeleteLastItem                                  4335
#define kNtErrorMessageExceedsMaxSize                               4336
#define kNtErrorVolumeContainsSysFiles                              4337
#define kNtErrorIndigenousType                                      4338
#define kNtErrorNoSupportingDrives                                  4339
#define kNtErrorCleanerCartridgeInstalled                           4340
#define kNtErrorIeportFull                                          4341
#define kNtErrorFileOffline                                         4350
#define kNtErrorRemoteStorageNotActive                              4351
#define kNtErrorRemoteStorageMediaError                             4352
#define kNtErrorNotAReparsePoint                                    4390
#define kNtErrorReparseAttributeConflict                            4391
#define kNtErrorInvalidReparseData                                  4392
#define kNtErrorReparseTagInvalid                                   4393
#define kNtErrorReparseTagMismatch                                  4394
#define kNtErrorReparsePointEncountered                             4395
#define kNtErrorAppDataNotFound                                     4400
#define kNtErrorAppDataExpired                                      4401
#define kNtErrorAppDataCorrupt                                      4402
#define kNtErrorAppDataLimitExceeded                                4403
#define kNtErrorAppDataRebootRequired                               4404
#define kNtErrorSecurebootRollbackDetected                          4420
#define kNtErrorSecurebootPolicyViolation                           4421
#define kNtErrorSecurebootInvalidPolicy                             4422
#define kNtErrorSecurebootPolicyPublisherNotFound                   4423
#define kNtErrorSecurebootPolicyNotSigned                           4424
#define kNtErrorSecurebootNotEnabled                                4425
#define kNtErrorSecurebootFileReplaced                              4426
#define kNtErrorSecurebootPolicyNotAuthorized                       4427
#define kNtErrorSecurebootPolicyUnknown                             4428
#define kNtErrorSecurebootPolicyMissingAntirollbackversion          4429
#define kNtErrorSecurebootPlatformIdMismatch                        4430
#define kNtErrorSecurebootPolicyRollbackDetected                    4431
#define kNtErrorSecurebootPolicyUpgradeMismatch                     4432
#define kNtErrorSecurebootRequiredPolicyFileMissing                 4433
#define kNtErrorSecurebootNotBasePolicy                             4434
#define kNtErrorSecurebootNotSupplementalPolicy                     4435
#define kNtErrorOffloadReadFltNotSupported                          4440
#define kNtErrorOffloadWriteFltNotSupported                         4441
#define kNtErrorOffloadReadFileNotSupported                         4442
#define kNtErrorOffloadWriteFileNotSupported                        4443
#define kNtErrorAlreadyHasStreamId                                  4444
#define kNtErrorSmrGarbageCollectionRequired                        4445
#define kNtErrorWofWimHeaderCorrupt                                 4446
#define kNtErrorWofWimResourceTableCorrupt                          4447
#define kNtErrorWofFileResourceTableCorrupt                         4448
#define kNtErrorVolumeNotSisEnabled                                 4500
#define kNtErrorSystemIntegrityRollbackDetected                     4550
#define kNtErrorSystemIntegrityPolicyViolation                      4551
#define kNtErrorSystemIntegrityInvalidPolicy                        4552
#define kNtErrorSystemIntegrityPolicyNotSigned                      4553
#define kNtErrorVsmNotInitialized                                   4560
#define kNtErrorVsmDmaProtectionNotInUse                            4561
#define kNtErrorPlatformManifestNotAuthorized                       4570
#define kNtErrorPlatformManifestInvalid                             4571
#define kNtErrorPlatformManifestFileNotAuthorized                   4572
#define kNtErrorPlatformManifestCatalogNotAuthorized                4573
#define kNtErrorPlatformManifestBinaryIdNotFound                    4574
#define kNtErrorPlatformManifestNotActive                           4575
#define kNtErrorPlatformManifestNotSigned                           4576
#define kNtErrorDependentResourceExists                             5001
#define kNtErrorDependencyNotFound                                  5002
#define kNtErrorDependencyAlreadyExists                             5003
#define kNtErrorResourceNotOnline                                   5004
#define kNtErrorHostNodeNotAvailable                                5005
#define kNtErrorResourceNotAvailable                                5006
#define kNtErrorResourceNotFound                                    5007
#define kNtErrorShutdownCluster                                     5008
#define kNtErrorCantEvictActiveNode                                 5009
#define kNtErrorObjectAlreadyExists                                 5010
#define kNtErrorObjectInList                                        5011
#define kNtErrorGroupNotAvailable                                   5012
#define kNtErrorGroupNotFound                                       5013
#define kNtErrorGroupNotOnline                                      5014
#define kNtErrorHostNodeNotResourceOwner                            5015
#define kNtErrorHostNodeNotGroupOwner                               5016
#define kNtErrorResmonCreateFailed                                  5017
#define kNtErrorResmonOnlineFailed                                  5018
#define kNtErrorResourceOnline                                      5019
#define kNtErrorQuorumResource                                      5020
#define kNtErrorNotQuorumCapable                                    5021
#define kNtErrorClusterShuttingDown                                 5022
#define kNtErrorInvalidState                                        5023
#define kNtErrorResourcePropertiesStored                            5024
#define kNtErrorNotQuorumClass                                      5025
#define kNtErrorCoreResource                                        5026
#define kNtErrorQuorumResourceOnlineFailed                          5027
#define kNtErrorQuorumlogOpenFailed                                 5028
#define kNtErrorClusterlogCorrupt                                   5029
#define kNtErrorClusterlogRecordExceedsMaxsize                      5030
#define kNtErrorClusterlogExceedsMaxsize                            5031
#define kNtErrorClusterlogChkpointNotFound                          5032
#define kNtErrorClusterlogNotEnoughSpace                            5033
#define kNtErrorQuorumOwnerAlive                                    5034
#define kNtErrorNetworkNotAvailable                                 5035
#define kNtErrorNodeNotAvailable                                    5036
#define kNtErrorAllNodesNotAvailable                                5037
#define kNtErrorResourceFailed                                      5038
#define kNtErrorClusterInvalidNode                                  5039
#define kNtErrorClusterNodeExists                                   5040
#define kNtErrorClusterJoinInProgress                               5041
#define kNtErrorClusterNodeNotFound                                 5042
#define kNtErrorClusterLocalNodeNotFound                            5043
#define kNtErrorClusterNetworkExists                                5044
#define kNtErrorClusterNetworkNotFound                              5045
#define kNtErrorClusterNetinterfaceExists                           5046
#define kNtErrorClusterNetinterfaceNotFound                         5047
#define kNtErrorClusterInvalidRequest                               5048
#define kNtErrorClusterInvalidNetworkProvider                       5049
#define kNtErrorClusterNodeDown                                     5050
#define kNtErrorClusterNodeUnreachable                              5051
#define kNtErrorClusterNodeNotMember                                5052
#define kNtErrorClusterJoinNotInProgress                            5053
#define kNtErrorClusterInvalidNetwork                               5054
#define kNtErrorClusterNodeUp                                       5056
#define kNtErrorClusterIpaddrInUse                                  5057
#define kNtErrorClusterNodeNotPaused                                5058
#define kNtErrorClusterNoSecurityContext                            5059
#define kNtErrorClusterNetworkNotInternal                           5060
#define kNtErrorClusterNodeAlreadyUp                                5061
#define kNtErrorClusterNodeAlreadyDown                              5062
#define kNtErrorClusterNetworkAlreadyOnline                         5063
#define kNtErrorClusterNetworkAlreadyOffline                        5064
#define kNtErrorClusterNodeAlreadyMember                            5065
#define kNtErrorClusterLastInternalNetwork                          5066
#define kNtErrorClusterNetworkHasDependents                         5067
#define kNtErrorInvalidOperationOnQuorum                            5068
#define kNtErrorDependencyNotAllowed                                5069
#define kNtErrorClusterNodePaused                                   5070
#define kNtErrorNodeCantHostResource                                5071
#define kNtErrorClusterNodeNotReady                                 5072
#define kNtErrorClusterNodeShuttingDown                             5073
#define kNtErrorClusterJoinAborted                                  5074
#define kNtErrorClusterIncompatibleVersions                         5075
#define kNtErrorClusterMaxnumOfResourcesExceeded                    5076
#define kNtErrorClusterSystemConfigChanged                          5077
#define kNtErrorClusterResourceTypeNotFound                         5078
#define kNtErrorClusterRestypeNotSupported                          5079
#define kNtErrorClusterResnameNotFound                              5080
#define kNtErrorClusterNoRpcPackagesRegistered                      5081
#define kNtErrorClusterOwnerNotInPreflist                           5082
#define kNtErrorClusterDatabaseSeqmismatch                          5083
#define kNtErrorResmonInvalidState                                  5084
#define kNtErrorClusterGumNotLocker                                 5085
#define kNtErrorQuorumDiskNotFound                                  5086
#define kNtErrorDatabaseBackupCorrupt                               5087
#define kNtErrorClusterNodeAlreadyHasDfsRoot                        5088
#define kNtErrorResourcePropertyUnchangeable                        5089
#define kNtErrorNoAdminAccessPoint                                  5090
#define kNtErrorClusterMembershipInvalidState                       5890
#define kNtErrorClusterQuorumlogNotFound                            5891
#define kNtErrorClusterMembershipHalt                               5892
#define kNtErrorClusterInstanceIdMismatch                           5893
#define kNtErrorClusterNetworkNotFoundForIp                         5894
#define kNtErrorClusterPropertyDataTypeMismatch                     5895
#define kNtErrorClusterEvictWithoutCleanup                          5896
#define kNtErrorClusterParameterMismatch                            5897
#define kNtErrorNodeCannotBeClustered                               5898
#define kNtErrorClusterWrongOsVersion                               5899
#define kNtErrorClusterCantCreateDupClusterName                     5900
#define kNtErrorCluscfgAlreadyCommitted                             5901
#define kNtErrorCluscfgRollbackFailed                               5902
#define kNtErrorCluscfgSystemDiskDriveLetterConflict                5903
#define kNtErrorClusterOldVersion                                   5904
#define kNtErrorClusterMismatchedComputerAcctName                   5905
#define kNtErrorClusterNoNetAdapters                                5906
#define kNtErrorClusterPoisoned                                     5907
#define kNtErrorClusterGroupMoving                                  5908
#define kNtErrorClusterResourceTypeBusy                             5909
#define kNtErrorResourceCallTimedOut                                5910
#define kNtErrorInvalidClusterIpv6Address                           5911
#define kNtErrorClusterInternalInvalidFunction                      5912
#define kNtErrorClusterParameterOutOfBounds                         5913
#define kNtErrorClusterPartialSend                                  5914
#define kNtErrorClusterRegistryInvalidFunction                      5915
#define kNtErrorClusterInvalidStringTermination                     5916
#define kNtErrorClusterInvalidStringFormat                          5917
#define kNtErrorClusterDatabaseTransactionInProgress                5918
#define kNtErrorClusterDatabaseTransactionNotInProgress             5919
#define kNtErrorClusterNullData                                     5920
#define kNtErrorClusterPartialRead                                  5921
#define kNtErrorClusterPartialWrite                                 5922
#define kNtErrorClusterCantDeserializeData                          5923
#define kNtErrorDependentResourcePropertyConflict                   5924
#define kNtErrorClusterNoQuorum                                     5925
#define kNtErrorClusterInvalidIpv6Network                           5926
#define kNtErrorClusterInvalidIpv6TunnelNetwork                     5927
#define kNtErrorQuorumNotAllowedInThisGroup                         5928
#define kNtErrorDependencyTreeTooComplex                            5929
#define kNtErrorExceptionInResourceCall                             5930
#define kNtErrorClusterRhsFailedInitialization                      5931
#define kNtErrorClusterNotInstalled                                 5932
#define kNtErrorClusterResourcesMustBeOnlineOnTheSameNode           5933
#define kNtErrorClusterMaxNodesInCluster                            5934
#define kNtErrorClusterTooManyNodes                                 5935
#define kNtErrorClusterObjectAlreadyUsed                            5936
#define kNtErrorNoncoreGroupsFound                                  5937
#define kNtErrorFileShareResourceConflict                           5938
#define kNtErrorClusterEvictInvalidRequest                          5939
#define kNtErrorClusterSingletonResource                            5940
#define kNtErrorClusterGroupSingletonResource                       5941
#define kNtErrorClusterResourceProviderFailed                       5942
#define kNtErrorClusterResourceConfigurationError                   5943
#define kNtErrorClusterGroupBusy                                    5944
#define kNtErrorClusterNotSharedVolume                              5945
#define kNtErrorClusterInvalidSecurityDescriptor                    5946
#define kNtErrorClusterSharedVolumesInUse                           5947
#define kNtErrorClusterUseSharedVolumesApi                          5948
#define kNtErrorClusterBackupInProgress                             5949
#define kNtErrorNonCsvPath                                          5950
#define kNtErrorCsvVolumeNotLocal                                   5951
#define kNtErrorClusterWatchdogTerminating                          5952
#define kNtErrorClusterResourceVetoedMoveIncompatibleNodes          5953
#define kNtErrorClusterInvalidNodeWeight                            5954
#define kNtErrorClusterResourceVetoedCall                           5955
#define kNtErrorResmonSystemResourcesLacking                        5956
#define kNtErrorClusterResourceVetoedMoveNotEnoughResourcesOnSource 5958
#define kNtErrorClusterGroupQueued                                  5959
#define kNtErrorClusterResourceLockedStatus                         5960
#define kNtErrorClusterSharedVolumeFailoverNotAllowed               5961
#define kNtErrorClusterNodeDrainInProgress                          5962
#define kNtErrorClusterDiskNotConnected                             5963
#define kNtErrorDiskNotCsvCapable                                   5964
#define kNtErrorResourceNotInAvailableStorage                       5965
#define kNtErrorClusterSharedVolumeRedirected                       5966
#define kNtErrorClusterSharedVolumeNotRedirected                    5967
#define kNtErrorClusterCannotReturnProperties                       5968
#define kNtErrorClusterResourceIsInMaintenanceMode                  5970
#define kNtErrorClusterAffinityConflict                             5971
#define kNtErrorClusterResourceIsReplicaVirtualMachine              5972
#define kNtErrorClusterUpgradeIncompatibleVersions                  5973
#define kNtErrorClusterUpgradeFixQuorumNotSupported                 5974
#define kNtErrorClusterUpgradeRestartRequired                       5975
#define kNtErrorClusterUpgradeInProgress                            5976
#define kNtErrorClusterUpgradeIncomplete                            5977
#define kNtErrorClusterNodeInGracePeriod                            5978
#define kNtErrorClusterCsvIoPauseTimeout                            5979
#define kNtErrorNodeNotActiveClusterMember                          5980
#define kNtErrorClusterResourceNotMonitored                         5981
#define kNtErrorClusterResourceDoesNotSupportUnmonitored            5982
#define kNtErrorClusterResourceIsReplicated                         5983
#define kNtErrorClusterNodeIsolated                                 5984
#define kNtErrorClusterNodeQuarantined                              5985
#define kNtErrorClusterDatabaseUpdateConditionFailed                5986
#define kNtErrorClusterSpaceDegraded                                5987
#define kNtErrorClusterTokenDelegationNotSupported                  5988
#define kNtErrorClusterCsvInvalidHandle                             5989
#define kNtErrorClusterCsvSupportedOnlyOnCoordinator                5990
#define kNtErrorGroupsetNotAvailable                                5991
#define kNtErrorGroupsetNotFound                                    5992
#define kNtErrorGroupsetCantProvide                                 5993
#define kNtErrorClusterFaultDomainParentNotFound                    5994
#define kNtErrorClusterFaultDomainInvalidHierarchy                  5995
#define kNtErrorClusterFaultDomainFailedS2dValidation               5996
#define kNtErrorClusterFaultDomainS2dConnectivityLoss               5997
#define kNtErrorClusterInvalidInfrastructureFileserverName          5998
#define kNtErrorClustersetManagementClusterUnreachable              5999
#define kNtErrorEncryptionFailed                                    6000
#define kNtErrorDecryptionFailed                                    6001
#define kNtErrorFileEncrypted                                       6002
#define kNtErrorNoRecoveryPolicy                                    6003
#define kNtErrorNoEfs                                               6004
#define kNtErrorWrongEfs                                            6005
#define kNtErrorNoUserKeys                                          6006
#define kNtErrorFileNotEncrypted                                    6007
#define kNtErrorNotExportFormat                                     6008
#define kNtErrorFileReadOnly                                        6009 /* EROFS */
#define kNtErrorDirEfsDisallowed                                    6010
#define kNtErrorEfsServerNotTrusted                                 6011
#define kNtErrorBadRecoveryPolicy                                   6012
#define kNtErrorEfsAlgBlobTooBig                                    6013
#define kNtErrorVolumeNotSupportEfs                                 6014
#define kNtErrorEfsDisabled                                         6015
#define kNtErrorEfsVersionNotSupport                                6016
#define kNtErrorCsEncryptionInvalidServerResponse                   6017
#define kNtErrorCsEncryptionUnsupportedServer                       6018
#define kNtErrorCsEncryptionExistingEncryptedFile                   6019
#define kNtErrorCsEncryptionNewEncryptedFile                        6020
#define kNtErrorCsEncryptionFileNotCse                              6021
#define kNtErrorEncryptionPolicyDeniesOperation                     6022
#define kNtErrorNoBrowserServersFound                               6118
#define kNtErrorLogSectorInvalid                                    6600
#define kNtErrorLogSectorParityInvalid                              6601
#define kNtErrorLogSectorRemapped                                   6602
#define kNtErrorLogBlockIncomplete                                  6603
#define kNtErrorLogInvalidRange                                     6604 /* ERANGE */
#define kNtErrorLogBlocksExhausted                                  6605
#define kNtErrorLogReadContextInvalid                               6606
#define kNtErrorLogRestartInvalid                                   6607
#define kNtErrorLogBlockVersion                                     6608
#define kNtErrorLogBlockInvalid                                     6609
#define kNtErrorLogReadModeInvalid                                  6610
#define kNtErrorLogNoRestart                                        6611
#define kNtErrorLogMetadataCorrupt                                  6612
#define kNtErrorLogMetadataInvalid                                  6613
#define kNtErrorLogMetadataInconsistent                             6614
#define kNtErrorLogReservationInvalid                               6615
#define kNtErrorLogCantDelete                                       6616
#define kNtErrorLogContainerLimitExceeded                           6617
#define kNtErrorLogStartOfLog                                       6618
#define kNtErrorLogPolicyAlreadyInstalled                           6619
#define kNtErrorLogPolicyNotInstalled                               6620
#define kNtErrorLogPolicyInvalid                                    6621
#define kNtErrorLogPolicyConflict                                   6622
#define kNtErrorLogPinnedArchiveTail                                6623
#define kNtErrorLogRecordNonexistent                                6624
#define kNtErrorLogRecordsReservedInvalid                           6625
#define kNtErrorLogSpaceReservedInvalid                             6626
#define kNtErrorLogTailInvalid                                      6627
#define kNtErrorLogFull                                             6628
#define kNtErrorCouldNotResizeLog                                   6629
#define kNtErrorLogMultiplexed                                      6630
#define kNtErrorLogDedicated                                        6631
#define kNtErrorLogArchiveNotInProgress                             6632
#define kNtErrorLogArchiveInProgress                                6633
#define kNtErrorLogEphemeral                                        6634
#define kNtErrorLogNotEnoughContainers                              6635
#define kNtErrorLogClientAlreadyRegistered                          6636
#define kNtErrorLogClientNotRegistered                              6637
#define kNtErrorLogFullHandlerInProgress                            6638
#define kNtErrorLogContainerReadFailed                              6639
#define kNtErrorLogContainerWriteFailed                             6640
#define kNtErrorLogContainerOpenFailed                              6641
#define kNtErrorLogContainerStateInvalid                            6642
#define kNtErrorLogStateInvalid                                     6643
#define kNtErrorLogPinned                                           6644
#define kNtErrorLogMetadataFlushFailed                              6645
#define kNtErrorLogInconsistentSecurity                             6646
#define kNtErrorLogAppendedFlushFailed                              6647
#define kNtErrorLogPinnedReservation                                6648
#define kNtErrorInvalidTransaction                                  6700
#define kNtErrorTransactionNotActive                                6701
#define kNtErrorTransactionRequestNotValid                          6702
#define kNtErrorTransactionNotRequested                             6703
#define kNtErrorTransactionAlreadyAborted                           6704
#define kNtErrorTransactionAlreadyCommitted                         6705
#define kNtErrorTmInitializationFailed                              6706
#define kNtErrorResourcemanagerReadOnly                             6707
#define kNtErrorTransactionNotJoined                                6708
#define kNtErrorTransactionSuperiorExists                           6709
#define kNtErrorCrmProtocolAlreadyExists                            6710
#define kNtErrorTransactionPropagationFailed                        6711
#define kNtErrorCrmProtocolNotFound                                 6712
#define kNtErrorTransactionInvalidMarshallBuffer                    6713
#define kNtErrorCurrentTransactionNotValid                          6714
#define kNtErrorTransactionNotFound                                 6715
#define kNtErrorResourcemanagerNotFound                             6716
#define kNtErrorEnlistmentNotFound                                  6717
#define kNtErrorTransactionmanagerNotFound                          6718
#define kNtErrorTransactionmanagerNotOnline                         6719
#define kNtErrorTransactionmanagerRecoveryNameCollision             6720
#define kNtErrorTransactionNotRoot                                  6721
#define kNtErrorTransactionObjectExpired                            6722
#define kNtErrorTransactionResponseNotEnlisted                      6723
#define kNtErrorTransactionRecordTooLong                            6724
#define kNtErrorImplicitTransactionNotSupported                     6725
#define kNtErrorTransactionIntegrityViolated                        6726
#define kNtErrorTransactionmanagerIdentityMismatch                  6727
#define kNtErrorRmCannotBeFrozenForSnapshot                         6728
#define kNtErrorTransactionMustWritethrough                         6729
#define kNtErrorTransactionNoSuperior                               6730
#define kNtErrorHeuristicDamagePossible                             6731
#define kNtErrorTransactionalConflict                               6800
#define kNtErrorRmNotActive                                         6801
#define kNtErrorRmMetadataCorrupt                                   6802
#define kNtErrorDirectoryNotRm                                      6803
#define kNtErrorTransactionsUnsupportedRemote                       6805
#define kNtErrorLogResizeInvalidSize                                6806
#define kNtErrorObjectNoLongerExists                                6807
#define kNtErrorStreamMiniversionNotFound                           6808
#define kNtErrorStreamMiniversionNotValid                           6809
#define kNtErrorMiniversionInaccessibleFromSpecifiedTransaction     6810
#define kNtErrorCantOpenMiniversionWithModifyIntent                 6811
#define kNtErrorCantCreateMoreStreamMiniversions                    6812
#define kNtErrorRemoteFileVersionMismatch                           6814
#define kNtErrorHandleNoLongerValid                                 6815
#define kNtErrorNoTxfMetadata                                       6816
#define kNtErrorLogCorruptionDetected                               6817
#define kNtErrorCantRecoverWithHandleOpen                           6818
#define kNtErrorRmDisconnected                                      6819
#define kNtErrorEnlistmentNotSuperior                               6820
#define kNtErrorRecoveryNotNeeded                                   6821
#define kNtErrorRmAlreadyStarted                                    6822
#define kNtErrorFileIdentityNotPersistent                           6823
#define kNtErrorCantBreakTransactionalDependency                    6824
#define kNtErrorCantCrossRmBoundary                                 6825
#define kNtErrorTxfDirNotEmpty                                      6826
#define kNtErrorIndoubtTransactionsExist                            6827
#define kNtErrorTmVolatile                                          6828
#define kNtErrorRollbackTimerExpired                                6829
#define kNtErrorTxfAttributeCorrupt                                 6830
#define kNtErrorEfsNotAllowedInTransaction                          6831
#define kNtErrorTransactionalOpenNotAllowed                         6832
#define kNtErrorLogGrowthFailed                                     6833
#define kNtErrorTransactedMappingUnsupportedRemote                  6834
#define kNtErrorTxfMetadataAlreadyPresent                           6835
#define kNtErrorTransactionScopeCallbacksNotSet                     6836
#define kNtErrorTransactionRequiredPromotion                        6837
#define kNtErrorCannotExecuteFileInTransaction                      6838
#define kNtErrorTransactionsNotFrozen                               6839
#define kNtErrorTransactionFreezeInProgress                         6840
#define kNtErrorNotSnapshotVolume                                   6841
#define kNtErrorNoSavepointWithOpenFiles                            6842
#define kNtErrorDataLostRepair                                      6843
#define kNtErrorSparseNotAllowedInTransaction                       6844
#define kNtErrorTmIdentityMismatch                                  6845
#define kNtErrorFloatedSection                                      6846
#define kNtErrorCannotAcceptTransactedWork                          6847
#define kNtErrorCannotAbortTransactions                             6848
#define kNtErrorBadClusters                                         6849
#define kNtErrorCompressionNotAllowedInTransaction                  6850
#define kNtErrorVolumeDirty                                         6851
#define kNtErrorNoLinkTrackingInTransaction                         6852
#define kNtErrorOperationNotSupportedInTransaction                  6853
#define kNtErrorExpiredHandle                                       6854
#define kNtErrorTransactionNotEnlisted                              6855
#define kNtErrorCtxWinstationNameInvalid                            7001
#define kNtErrorCtxInvalidPd                                        7002
#define kNtErrorCtxPdNotFound                                       7003
#define kNtErrorCtxWdNotFound                                       7004
#define kNtErrorCtxCannotMakeEventlogEntry                          7005
#define kNtErrorCtxServiceNameCollision                             7006
#define kNtErrorCtxClosePending                                     7007
#define kNtErrorCtxNoOutbuf                                         7008
#define kNtErrorCtxModemInfNotFound                                 7009
#define kNtErrorCtxInvalidModemname                                 7010
#define kNtErrorCtxModemResponseError                               7011
#define kNtErrorCtxModemResponseTimeout                             7012
#define kNtErrorCtxModemResponseNoCarrier                           7013
#define kNtErrorCtxModemResponseNoDialtone                          7014
#define kNtErrorCtxModemResponseBusy                                7015
#define kNtErrorCtxModemResponseVoice                               7016
#define kNtErrorCtxTdError                                          7017
#define kNtErrorCtxWinstationNotFound                               7022
#define kNtErrorCtxWinstationAlreadyExists                          7023
#define kNtErrorCtxWinstationBusy                                   7024
#define kNtErrorCtxBadVideoMode                                     7025
#define kNtErrorCtxGraphicsInvalid                                  7035
#define kNtErrorCtxLogonDisabled                                    7037
#define kNtErrorCtxNotConsole                                       7038
#define kNtErrorCtxClientQueryTimeout                               7040
#define kNtErrorCtxConsoleDisconnect                                7041
#define kNtErrorCtxConsoleConnect                                   7042
#define kNtErrorCtxShadowDenied                                     7044
#define kNtErrorCtxWinstationAccessDenied                           7045
#define kNtErrorCtxInvalidWd                                        7049
#define kNtErrorCtxShadowInvalid                                    7050
#define kNtErrorCtxShadowDisabled                                   7051
#define kNtErrorCtxClientLicenseInUse                               7052
#define kNtErrorCtxClientLicenseNotSet                              7053
#define kNtErrorCtxLicenseNotAvailable                              7054
#define kNtErrorCtxLicenseClientInvalid                             7055
#define kNtErrorCtxLicenseExpired                                   7056
#define kNtErrorCtxShadowNotRunning                                 7057
#define kNtErrorCtxShadowEndedByModeChange                          7058
#define kNtErrorActivationCountExceeded                             7059
#define kNtErrorCtxWinstationsDisabled                              7060
#define kNtErrorCtxEncryptionLevelRequired                          7061
#define kNtErrorCtxSessionInUse                                     7062
#define kNtErrorCtxNoForceLogoff                                    7063
#define kNtErrorCtxAccountRestriction                               7064
#define kNtErrorRdpProtocolError                                    7065 /* EPROTO */
#define kNtErrorCtxCdmConnect                                       7066
#define kNtErrorCtxCdmDisconnect                                    7067
#define kNtErrorCtxSecurityLayerError                               7068
#define kNtErrorTsIncompatibleSessions                              7069
#define kNtErrorTsVideoSubsystemError                               7070
#define kNtErrorDsNotInstalled                                      8200
#define kNtErrorDsMembershipEvaluatedLocally                        8201
#define kNtErrorDsNoAttributeOrValue                                8202
#define kNtErrorDsInvalidAttributeSyntax                            8203
#define kNtErrorDsAttributeTypeUndefined                            8204
#define kNtErrorDsAttributeOrValueExists                            8205
#define kNtErrorDsBusy                                              8206
#define kNtErrorDsUnavailable                                       8207
#define kNtErrorDsNoRidsAllocated                                   8208
#define kNtErrorDsNoMoreRids                                        8209
#define kNtErrorDsIncorrectRoleOwner                                8210
#define kNtErrorDsRidmgrInitError                                   8211
#define kNtErrorDsObjClassViolation                                 8212
#define kNtErrorDsCantOnNonLeaf                                     8213
#define kNtErrorDsCantOnRdn                                         8214
#define kNtErrorDsCantModObjClass                                   8215
#define kNtErrorDsCrossDomMoveError                                 8216
#define kNtErrorDsGcNotAvailable                                    8217
#define kNtErrorSharedPolicy                                        8218
#define kNtErrorPolicyObjectNotFound                                8219
#define kNtErrorPolicyOnlyInDs                                      8220
#define kNtErrorPromotionActive                                     8221
#define kNtErrorNoPromotionActive                                   8222
#define kNtErrorDsOperationsError                                   8224
#define kNtErrorDsProtocolError                                     8225
#define kNtErrorDsTimelimitExceeded                                 8226
#define kNtErrorDsSizelimitExceeded                                 8227
#define kNtErrorDsAdminLimitExceeded                                8228
#define kNtErrorDsCompareFalse                                      8229
#define kNtErrorDsCompareTrue                                       8230
#define kNtErrorDsAuthMethodNotSupported                            8231
#define kNtErrorDsStrongAuthRequired                                8232
#define kNtErrorDsInappropriateAuth                                 8233
#define kNtErrorDsAuthUnknown                                       8234
#define kNtErrorDsReferral                                          8235
#define kNtErrorDsUnavailableCritExtension                          8236
#define kNtErrorDsConfidentialityRequired                           8237
#define kNtErrorDsInappropriateMatching                             8238
#define kNtErrorDsConstraintViolation                               8239
#define kNtErrorDsNoSuchObject                                      8240
#define kNtErrorDsAliasProblem                                      8241
#define kNtErrorDsInvalidDnSyntax                                   8242
#define kNtErrorDsIsLeaf                                            8243
#define kNtErrorDsAliasDerefProblem                                 8244
#define kNtErrorDsUnwillingToPerform                                8245
#define kNtErrorDsLoopDetect                                        8246
#define kNtErrorDsNamingViolation                                   8247
#define kNtErrorDsObjectResultsTooLarge                             8248
#define kNtErrorDsAffectsMultipleDsas                               8249
#define kNtErrorDsServerDown                                        8250
#define kNtErrorDsLocalError                                        8251
#define kNtErrorDsEncodingError                                     8252
#define kNtErrorDsDecodingError                                     8253
#define kNtErrorDsFilterUnknown                                     8254
#define kNtErrorDsParamError                                        8255
#define kNtErrorDsNotSupported                                      8256
#define kNtErrorDsNoResultsReturned                                 8257
#define kNtErrorDsControlNotFound                                   8258
#define kNtErrorDsClientLoop                                        8259
#define kNtErrorDsReferralLimitExceeded                             8260
#define kNtErrorDsSortControlMissing                                8261
#define kNtErrorDsOffsetRangeError                                  8262
#define kNtErrorDsRidmgrDisabled                                    8263
#define kNtErrorDsRootMustBeNc                                      8301
#define kNtErrorDsAddReplicaInhibited                               8302
#define kNtErrorDsAttNotDefInSchema                                 8303
#define kNtErrorDsMaxObjSizeExceeded                                8304
#define kNtErrorDsObjStringNameExists                               8305
#define kNtErrorDsNoRdnDefinedInSchema                              8306
#define kNtErrorDsRdnDoesntMatchSchema                              8307
#define kNtErrorDsNoRequestedAttsFound                              8308
#define kNtErrorDsUserBufferToSmall                                 8309
#define kNtErrorDsAttIsNotOnObj                                     8310
#define kNtErrorDsIllegalModOperation                               8311
#define kNtErrorDsObjTooLarge                                       8312
#define kNtErrorDsBadInstanceType                                   8313
#define kNtErrorDsMasterdsaRequired                                 8314
#define kNtErrorDsObjectClassRequired                               8315
#define kNtErrorDsMissingRequiredAtt                                8316
#define kNtErrorDsAttNotDefForClass                                 8317
#define kNtErrorDsAttAlreadyExists                                  8318
#define kNtErrorDsCantAddAttValues                                  8320
#define kNtErrorDsSingleValueConstraint                             8321
#define kNtErrorDsRangeConstraint                                   8322
#define kNtErrorDsAttValAlreadyExists                               8323
#define kNtErrorDsCantRemMissingAtt                                 8324
#define kNtErrorDsCantRemMissingAttVal                              8325
#define kNtErrorDsRootCantBeSubref                                  8326
#define kNtErrorDsNoChaining                                        8327
#define kNtErrorDsNoChainedEval                                     8328
#define kNtErrorDsNoParentObject                                    8329
#define kNtErrorDsParentIsAnAlias                                   8330
#define kNtErrorDsCantMixMasterAndReps                              8331
#define kNtErrorDsChildrenExist                                     8332
#define kNtErrorDsObjNotFound                                       8333
#define kNtErrorDsAliasedObjMissing                                 8334
#define kNtErrorDsBadNameSyntax                                     8335
#define kNtErrorDsAliasPointsToAlias                                8336
#define kNtErrorDsCantDerefAlias                                    8337
#define kNtErrorDsOutOfScope                                        8338
#define kNtErrorDsObjectBeingRemoved                                8339
#define kNtErrorDsCantDeleteDsaObj                                  8340
#define kNtErrorDsGenericError                                      8341
#define kNtErrorDsDsaMustBeIntMaster                                8342
#define kNtErrorDsClassNotDsa                                       8343
#define kNtErrorDsInsuffAccessRights                                8344
#define kNtErrorDsIllegalSuperior                                   8345
#define kNtErrorDsAttributeOwnedBySam                               8346
#define kNtErrorDsNameTooManyParts                                  8347
#define kNtErrorDsNameTooLong                                       8348
#define kNtErrorDsNameValueTooLong                                  8349
#define kNtErrorDsNameUnparseable                                   8350
#define kNtErrorDsNameTypeUnknown                                   8351
#define kNtErrorDsNotAnObject                                       8352
#define kNtErrorDsSecDescTooShort                                   8353
#define kNtErrorDsSecDescInvalid                                    8354
#define kNtErrorDsNoDeletedName                                     8355
#define kNtErrorDsSubrefMustHaveParent                              8356
#define kNtErrorDsNcnameMustBeNc                                    8357
#define kNtErrorDsCantAddSystemOnly                                 8358
#define kNtErrorDsClassMustBeConcrete                               8359
#define kNtErrorDsInvalidDmd                                        8360
#define kNtErrorDsObjGuidExists                                     8361
#define kNtErrorDsNotOnBacklink                                     8362
#define kNtErrorDsNoCrossrefForNc                                   8363
#define kNtErrorDsShuttingDown                                      8364
#define kNtErrorDsUnknownOperation                                  8365
#define kNtErrorDsInvalidRoleOwner                                  8366
#define kNtErrorDsCouldntContactFsmo                                8367
#define kNtErrorDsCrossNcDnRename                                   8368
#define kNtErrorDsCantModSystemOnly                                 8369
#define kNtErrorDsReplicatorOnly                                    8370
#define kNtErrorDsObjClassNotDefined                                8371
#define kNtErrorDsObjClassNotSubclass                               8372
#define kNtErrorDsNameReferenceInvalid                              8373
#define kNtErrorDsCrossRefExists                                    8374
#define kNtErrorDsCantDelMasterCrossref                             8375
#define kNtErrorDsSubtreeNotifyNotNcHead                            8376
#define kNtErrorDsNotifyFilterTooComplex                            8377
#define kNtErrorDsDupRdn                                            8378
#define kNtErrorDsDupOid                                            8379
#define kNtErrorDsDupMapiId                                         8380
#define kNtErrorDsDupSchemaIdGuid                                   8381
#define kNtErrorDsDupLdapDisplayName                                8382
#define kNtErrorDsSemanticAttTest                                   8383
#define kNtErrorDsSyntaxMismatch                                    8384
#define kNtErrorDsExistsInMustHave                                  8385
#define kNtErrorDsExistsInMayHave                                   8386
#define kNtErrorDsNonexistentMayHave                                8387
#define kNtErrorDsNonexistentMustHave                               8388
#define kNtErrorDsAuxClsTestFail                                    8389
#define kNtErrorDsNonexistentPossSup                                8390
#define kNtErrorDsSubClsTestFail                                    8391
#define kNtErrorDsBadRdnAttIdSyntax                                 8392
#define kNtErrorDsExistsInAuxCls                                    8393
#define kNtErrorDsExistsInSubCls                                    8394
#define kNtErrorDsExistsInPossSup                                   8395
#define kNtErrorDsRecalcschemaFailed                                8396
#define kNtErrorDsTreeDeleteNotFinished                             8397
#define kNtErrorDsCantDelete                                        8398
#define kNtErrorDsAttSchemaReqId                                    8399
#define kNtErrorDsBadAttSchemaSyntax                                8400
#define kNtErrorDsCantCacheAtt                                      8401
#define kNtErrorDsCantCacheClass                                    8402
#define kNtErrorDsCantRemoveAttCache                                8403
#define kNtErrorDsCantRemoveClassCache                              8404
#define kNtErrorDsCantRetrieveDn                                    8405
#define kNtErrorDsMissingSupref                                     8406
#define kNtErrorDsCantRetrieveInstance                              8407
#define kNtErrorDsCodeInconsistency                                 8408
#define kNtErrorDsDatabaseError                                     8409
#define kNtErrorDsGovernsidMissing                                  8410
#define kNtErrorDsMissingExpectedAtt                                8411
#define kNtErrorDsNcnameMissingCrRef                                8412
#define kNtErrorDsSecurityCheckingError                             8413
#define kNtErrorDsSchemaNotLoaded                                   8414
#define kNtErrorDsSchemaAllocFailed                                 8415
#define kNtErrorDsAttSchemaReqSyntax                                8416
#define kNtErrorDsGcverifyError                                     8417
#define kNtErrorDsDraSchemaMismatch                                 8418
#define kNtErrorDsCantFindDsaObj                                    8419
#define kNtErrorDsCantFindExpectedNc                                8420
#define kNtErrorDsCantFindNcInCache                                 8421
#define kNtErrorDsCantRetrieveChild                                 8422
#define kNtErrorDsSecurityIllegalModify                             8423
#define kNtErrorDsCantReplaceHiddenRec                              8424
#define kNtErrorDsBadHierarchyFile                                  8425
#define kNtErrorDsBuildHierarchyTableFailed                         8426
#define kNtErrorDsConfigParamMissing                                8427
#define kNtErrorDsCountingAbIndicesFailed                           8428
#define kNtErrorDsHierarchyTableMallocFailed                        8429
#define kNtErrorDsInternalFailure                                   8430
#define kNtErrorDsUnknownError                                      8431
#define kNtErrorDsRootRequiresClassTop                              8432
#define kNtErrorDsRefusingFsmoRoles                                 8433
#define kNtErrorDsMissingFsmoSettings                               8434
#define kNtErrorDsUnableToSurrenderRoles                            8435
#define kNtErrorDsDraGeneric                                        8436
#define kNtErrorDsDraInvalidParameter                               8437
#define kNtErrorDsDraBusy                                           8438
#define kNtErrorDsDraBadDn                                          8439
#define kNtErrorDsDraBadNc                                          8440
#define kNtErrorDsDraDnExists                                       8441
#define kNtErrorDsDraInternalError                                  8442
#define kNtErrorDsDraInconsistentDit                                8443
#define kNtErrorDsDraConnectionFailed                               8444
#define kNtErrorDsDraBadInstanceType                                8445
#define kNtErrorDsDraOutOfMem                                       8446
#define kNtErrorDsDraMailProblem                                    8447
#define kNtErrorDsDraRefAlreadyExists                               8448
#define kNtErrorDsDraRefNotFound                                    8449
#define kNtErrorDsDraObjIsRepSource                                 8450
#define kNtErrorDsDraDbError                                        8451
#define kNtErrorDsDraNoReplica                                      8452
#define kNtErrorDsDraAccessDenied                                   8453
#define kNtErrorDsDraNotSupported                                   8454
#define kNtErrorDsDraRpcCancelled                                   8455
#define kNtErrorDsDraSourceDisabled                                 8456
#define kNtErrorDsDraSinkDisabled                                   8457
#define kNtErrorDsDraNameCollision                                  8458
#define kNtErrorDsDraSourceReinstalled                              8459
#define kNtErrorDsDraMissingParent                                  8460
#define kNtErrorDsDraPreempted                                      8461
#define kNtErrorDsDraAbandonSync                                    8462
#define kNtErrorDsDraShutdown                                       8463
#define kNtErrorDsDraIncompatiblePartialSet                         8464
#define kNtErrorDsDraSourceIsPartialReplica                         8465
#define kNtErrorDsDraExtnConnectionFailed                           8466
#define kNtErrorDsInstallSchemaMismatch                             8467
#define kNtErrorDsDupLinkId                                         8468
#define kNtErrorDsNameErrorResolving                                8469
#define kNtErrorDsNameErrorNotFound                                 8470
#define kNtErrorDsNameErrorNotUnique                                8471
#define kNtErrorDsNameErrorNoMapping                                8472
#define kNtErrorDsNameErrorDomainOnly                               8473
#define kNtErrorDsNameErrorNoSyntacticalMapping                     8474
#define kNtErrorDsConstructedAttMod                                 8475
#define kNtErrorDsWrongOmObjClass                                   8476
#define kNtErrorDsDraReplPending                                    8477
#define kNtErrorDsDsRequired                                        8478
#define kNtErrorDsInvalidLdapDisplayName                            8479
#define kNtErrorDsNonBaseSearch                                     8480
#define kNtErrorDsCantRetrieveAtts                                  8481
#define kNtErrorDsBacklinkWithoutLink                               8482
#define kNtErrorDsEpochMismatch                                     8483
#define kNtErrorDsSrcNameMismatch                                   8484
#define kNtErrorDsSrcAndDstNcIdentical                              8485
#define kNtErrorDsDstNcMismatch                                     8486
#define kNtErrorDsNotAuthoritiveForDstNc                            8487
#define kNtErrorDsSrcGuidMismatch                                   8488
#define kNtErrorDsCantMoveDeletedObject                             8489
#define kNtErrorDsPdcOperationInProgress                            8490
#define kNtErrorDsCrossDomainCleanupReqd                            8491
#define kNtErrorDsIllegalXdomMoveOperation                          8492
#define kNtErrorDsCantWithAcctGroupMembershps                       8493
#define kNtErrorDsNcMustHaveNcParent                                8494
#define kNtErrorDsCrImpossibleToValidate                            8495
#define kNtErrorDsDstDomainNotNative                                8496
#define kNtErrorDsMissingInfrastructureContainer                    8497
#define kNtErrorDsCantMoveAccountGroup                              8498
#define kNtErrorDsCantMoveResourceGroup                             8499
#define kNtErrorDsInvalidSearchFlag                                 8500
#define kNtErrorDsNoTreeDeleteAboveNc                               8501
#define kNtErrorDsCouldntLockTreeForDelete                          8502
#define kNtErrorDsCouldntIdentifyObjectsForTreeDelete               8503
#define kNtErrorDsSamInitFailure                                    8504
#define kNtErrorDsSensitiveGroupViolation                           8505
#define kNtErrorDsCantModPrimarygroupid                             8506
#define kNtErrorDsIllegalBaseSchemaMod                              8507
#define kNtErrorDsNonsafeSchemaChange                               8508
#define kNtErrorDsSchemaUpdateDisallowed                            8509
#define kNtErrorDsCantCreateUnderSchema                             8510
#define kNtErrorDsInstallNoSrcSchVersion                            8511
#define kNtErrorDsInstallNoSchVersionInInifile                      8512
#define kNtErrorDsInvalidGroupType                                  8513
#define kNtErrorDsNoNestGlobalgroupInMixeddomain                    8514
#define kNtErrorDsNoNestLocalgroupInMixeddomain                     8515
#define kNtErrorDsGlobalCantHaveLocalMember                         8516
#define kNtErrorDsGlobalCantHaveUniversalMember                     8517
#define kNtErrorDsUniversalCantHaveLocalMember                      8518
#define kNtErrorDsGlobalCantHaveCrossdomainMember                   8519
#define kNtErrorDsLocalCantHaveCrossdomainLocalMember               8520
#define kNtErrorDsHavePrimaryMembers                                8521
#define kNtErrorDsStringSdConversionFailed                          8522
#define kNtErrorDsNamingMasterGc                                    8523
#define kNtErrorDsDnsLookupFailure                                  8524
#define kNtErrorDsCouldntUpdateSpns                                 8525
#define kNtErrorDsCantRetrieveSd                                    8526
#define kNtErrorDsKeyNotUnique                                      8527
#define kNtErrorDsWrongLinkedAttSyntax                              8528
#define kNtErrorDsSamNeedBootkeyPassword                            8529
#define kNtErrorDsSamNeedBootkeyFloppy                              8530
#define kNtErrorDsCantStart                                         8531
#define kNtErrorDsInitFailure                                       8532
#define kNtErrorDsNoPktPrivacyOnConnection                          8533
#define kNtErrorDsSourceDomainInForest                              8534
#define kNtErrorDsDestinationDomainNotInForest                      8535
#define kNtErrorDsDestinationAuditingNotEnabled                     8536
#define kNtErrorDsCantFindDcForSrcDomain                            8537
#define kNtErrorDsSrcObjNotGroupOrUser                              8538
#define kNtErrorDsSrcSidExistsInForest                              8539
#define kNtErrorDsSrcAndDstObjectClassMismatch                      8540
#define kNtErrorSamInitFailure                                      8541
#define kNtErrorDsDraSchemaInfoShip                                 8542
#define kNtErrorDsDraSchemaConflict                                 8543
#define kNtErrorDsDraEarlierSchemaConflict                          8544
#define kNtErrorDsDraObjNcMismatch                                  8545
#define kNtErrorDsNcStillHasDsas                                    8546
#define kNtErrorDsGcRequired                                        8547
#define kNtErrorDsLocalMemberOfLocalOnly                            8548
#define kNtErrorDsNoFpoInUniversalGroups                            8549
#define kNtErrorDsCantAddToGc                                       8550
#define kNtErrorDsNoCheckpointWithPdc                               8551
#define kNtErrorDsSourceAuditingNotEnabled                          8552
#define kNtErrorDsCantCreateInNondomainNc                           8553
#define kNtErrorDsInvalidNameForSpn                                 8554
#define kNtErrorDsFilterUsesContructedAttrs                         8555
#define kNtErrorDsUnicodepwdNotInQuotes                             8556
#define kNtErrorDsMachineAccountQuotaExceeded                       8557
#define kNtErrorDsMustBeRunOnDstDc                                  8558
#define kNtErrorDsSrcDcMustBeSp4OrGreater                           8559
#define kNtErrorDsCantTreeDeleteCriticalObj                         8560
#define kNtErrorDsInitFailureConsole                                8561
#define kNtErrorDsSamInitFailureConsole                             8562
#define kNtErrorDsForestVersionTooHigh                              8563
#define kNtErrorDsDomainVersionTooHigh                              8564
#define kNtErrorDsForestVersionTooLow                               8565
#define kNtErrorDsDomainVersionTooLow                               8566
#define kNtErrorDsIncompatibleVersion                               8567
#define kNtErrorDsLowDsaVersion                                     8568
#define kNtErrorDsNoBehaviorVersionInMixeddomain                    8569
#define kNtErrorDsNotSupportedSortOrder                             8570
#define kNtErrorDsNameNotUnique                                     8571
#define kNtErrorDsMachineAccountCreatedPrent4                       8572
#define kNtErrorDsOutOfVersionStore                                 8573
#define kNtErrorDsIncompatibleControlsUsed                          8574
#define kNtErrorDsNoRefDomain                                       8575
#define kNtErrorDsReservedLinkId                                    8576
#define kNtErrorDsLinkIdNotAvailable                                8577
#define kNtErrorDsAgCantHaveUniversalMember                         8578
#define kNtErrorDsModifydnDisallowedByInstanceType                  8579
#define kNtErrorDsNoObjectMoveInSchemaNc                            8580
#define kNtErrorDsModifydnDisallowedByFlag                          8581
#define kNtErrorDsModifydnWrongGrandparent                          8582
#define kNtErrorDsNameErrorTrustReferral                            8583
#define kNtErrorNotSupportedOnStandardServer                        8584
#define kNtErrorDsCantAccessRemotePartOfAd                          8585
#define kNtErrorDsCrImpossibleToValidateV2                          8586
#define kNtErrorDsThreadLimitExceeded                               8587
#define kNtErrorDsNotClosest                                        8588
#define kNtErrorDsCantDeriveSpnWithoutServerRef                     8589
#define kNtErrorDsSingleUserModeFailed                              8590
#define kNtErrorDsNtdscriptSyntaxError                              8591
#define kNtErrorDsNtdscriptProcessError                             8592
#define kNtErrorDsDifferentReplEpochs                               8593
#define kNtErrorDsDrsExtensionsChanged                              8594
#define kNtErrorDsReplicaSetChangeNotAllowedOnDisabledCr            8595
#define kNtErrorDsNoMsdsIntid                                       8596
#define kNtErrorDsDupMsdsIntid                                      8597
#define kNtErrorDsExistsInRdnattid                                  8598
#define kNtErrorDsAuthorizationFailed                               8599
#define kNtErrorDsInvalidScript                                     8600
#define kNtErrorDsRemoteCrossrefOpFailed                            8601
#define kNtErrorDsCrossRefBusy                                      8602
#define kNtErrorDsCantDeriveSpnForDeletedDomain                     8603
#define kNtErrorDsCantDemoteWithWriteableNc                         8604
#define kNtErrorDsDuplicateIdFound                                  8605
#define kNtErrorDsInsufficientAttrToCreateObject                    8606
#define kNtErrorDsGroupConversionError                              8607
#define kNtErrorDsCantMoveAppBasicGroup                             8608
#define kNtErrorDsCantMoveAppQueryGroup                             8609
#define kNtErrorDsRoleNotVerified                                   8610
#define kNtErrorDsWkoContainerCannotBeSpecial                       8611
#define kNtErrorDsDomainRenameInProgress                            8612
#define kNtErrorDsExistingAdChildNc                                 8613
#define kNtErrorDsReplLifetimeExceeded                              8614
#define kNtErrorDsDisallowedInSystemContainer                       8615
#define kNtErrorDsLdapSendQueueFull                                 8616
#define kNtErrorDsDraOutScheduleWindow                              8617
#define kNtErrorDsPolicyNotKnown                                    8618
#define kNtErrorNoSiteSettingsObject                                8619
#define kNtErrorNoSecrets                                           8620
#define kNtErrorNoWritableDcFound                                   8621
#define kNtErrorDsNoServerObject                                    8622
#define kNtErrorDsNoNtdsaObject                                     8623
#define kNtErrorDsNonAsqSearch                                      8624
#define kNtErrorDsAuditFailure                                      8625
#define kNtErrorDsInvalidSearchFlagSubtree                          8626
#define kNtErrorDsInvalidSearchFlagTuple                            8627
#define kNtErrorDsHierarchyTableTooDeep                             8628
#define kNtErrorDsDraCorruptUtdVector                               8629
#define kNtErrorDsDraSecretsDenied                                  8630
#define kNtErrorDsReservedMapiId                                    8631
#define kNtErrorDsMapiIdNotAvailable                                8632
#define kNtErrorDsDraMissingKrbtgtSecret                            8633
#define kNtErrorDsDomainNameExistsInForest                          8634
#define kNtErrorDsFlatNameExistsInForest                            8635
#define kNtErrorInvalidUserPrincipalName                            8636
#define kNtErrorDsOidMappedGroupCantHaveMembers                     8637
#define kNtErrorDsOidNotFound                                       8638
#define kNtErrorDsDraRecycledTarget                                 8639
#define kNtErrorDsDisallowedNcRedirect                              8640
#define kNtErrorDsHighAdldsFfl                                      8641
#define kNtErrorDsHighDsaVersion                                    8642
#define kNtErrorDsLowAdldsFfl                                       8643
#define kNtErrorDomainSidSameAsLocalWorkstation                     8644
#define kNtErrorDsUndeleteSamValidationFailed                       8645
#define kNtErrorIncorrectAccountType                                8646
#define kNtErrorDsSpnValueNotUniqueInForest                         8647
#define kNtErrorDsUpnValueNotUniqueInForest                         8648
#define kNtErrorDsMissingForestTrust                                8649
#define kNtErrorDsValueKeyNotUnique                                 8650
#define kNtErrorIpsecQmPolicyExists                                 13000
#define kNtErrorIpsecQmPolicyNotFound                               13001
#define kNtErrorIpsecQmPolicyInUse                                  13002
#define kNtErrorIpsecMmPolicyExists                                 13003
#define kNtErrorIpsecMmPolicyNotFound                               13004
#define kNtErrorIpsecMmPolicyInUse                                  13005
#define kNtErrorIpsecMmFilterExists                                 13006
#define kNtErrorIpsecMmFilterNotFound                               13007
#define kNtErrorIpsecTransportFilterExists                          13008
#define kNtErrorIpsecTransportFilterNotFound                        13009
#define kNtErrorIpsecMmAuthExists                                   13010
#define kNtErrorIpsecMmAuthNotFound                                 13011
#define kNtErrorIpsecMmAuthInUse                                    13012
#define kNtErrorIpsecDefaultMmPolicyNotFound                        13013
#define kNtErrorIpsecDefaultMmAuthNotFound                          13014
#define kNtErrorIpsecDefaultQmPolicyNotFound                        13015
#define kNtErrorIpsecTunnelFilterExists                             13016
#define kNtErrorIpsecTunnelFilterNotFound                           13017
#define kNtErrorIpsecMmFilterPendingDeletion                        13018
#define kNtErrorIpsecTransportFilterPendingDeletion                 13019
#define kNtErrorIpsecTunnelFilterPendingDeletion                    13020
#define kNtErrorIpsecMmPolicyPendingDeletion                        13021
#define kNtErrorIpsecMmAuthPendingDeletion                          13022
#define kNtErrorIpsecQmPolicyPendingDeletion                        13023
#define kNtErrorIpsecIkeNegStatusBegin                              13800
#define kNtErrorIpsecIkeAuthFail                                    13801
#define kNtErrorIpsecIkeAttribFail                                  13802
#define kNtErrorIpsecIkeNegotiationPending                          13803
#define kNtErrorIpsecIkeGeneralProcessingError                      13804
#define kNtErrorIpsecIkeTimedOut                                    13805
#define kNtErrorIpsecIkeNoCert                                      13806
#define kNtErrorIpsecIkeSaDeleted                                   13807
#define kNtErrorIpsecIkeSaReaped                                    13808
#define kNtErrorIpsecIkeMmAcquireDrop                               13809
#define kNtErrorIpsecIkeQmAcquireDrop                               13810
#define kNtErrorIpsecIkeQueueDropMm                                 13811
#define kNtErrorIpsecIkeQueueDropNoMm                               13812
#define kNtErrorIpsecIkeDropNoResponse                              13813
#define kNtErrorIpsecIkeMmDelayDrop                                 13814
#define kNtErrorIpsecIkeQmDelayDrop                                 13815
#define kNtErrorIpsecIkeError                                       13816
#define kNtErrorIpsecIkeCrlFailed                                   13817
#define kNtErrorIpsecIkeInvalidKeyUsage                             13818
#define kNtErrorIpsecIkeInvalidCertType                             13819
#define kNtErrorIpsecIkeNoPrivateKey                                13820
#define kNtErrorIpsecIkeSimultaneousRekey                           13821
#define kNtErrorIpsecIkeDhFail                                      13822
#define kNtErrorIpsecIkeCriticalPayloadNotRecognized                13823
#define kNtErrorIpsecIkeInvalidHeader                               13824
#define kNtErrorIpsecIkeNoPolicy                                    13825
#define kNtErrorIpsecIkeInvalidSignature                            13826
#define kNtErrorIpsecIkeKerberosError                               13827
#define kNtErrorIpsecIkeNoPublicKey                                 13828
#define kNtErrorIpsecIkeProcessErr                                  13829
#define kNtErrorIpsecIkeProcessErrSa                                13830
#define kNtErrorIpsecIkeProcessErrProp                              13831
#define kNtErrorIpsecIkeProcessErrTrans                             13832
#define kNtErrorIpsecIkeProcessErrKe                                13833
#define kNtErrorIpsecIkeProcessErrId                                13834
#define kNtErrorIpsecIkeProcessErrCert                              13835
#define kNtErrorIpsecIkeProcessErrCertReq                           13836
#define kNtErrorIpsecIkeProcessErrHash                              13837
#define kNtErrorIpsecIkeProcessErrSig                               13838
#define kNtErrorIpsecIkeProcessErrNonce                             13839
#define kNtErrorIpsecIkeProcessErrNotify                            13840
#define kNtErrorIpsecIkeProcessErrDelete                            13841
#define kNtErrorIpsecIkeProcessErrVendor                            13842
#define kNtErrorIpsecIkeInvalidPayload                              13843
#define kNtErrorIpsecIkeLoadSoftSa                                  13844
#define kNtErrorIpsecIkeSoftSaTornDown                              13845
#define kNtErrorIpsecIkeInvalidCookie                               13846
#define kNtErrorIpsecIkeNoPeerCert                                  13847
#define kNtErrorIpsecIkePeerCrlFailed                               13848
#define kNtErrorIpsecIkePolicyChange                                13849
#define kNtErrorIpsecIkeNoMmPolicy                                  13850
#define kNtErrorIpsecIkeNotcbpriv                                   13851
#define kNtErrorIpsecIkeSecloadfail                                 13852
#define kNtErrorIpsecIkeFailsspinit                                 13853
#define kNtErrorIpsecIkeFailqueryssp                                13854
#define kNtErrorIpsecIkeSrvacqfail                                  13855
#define kNtErrorIpsecIkeSrvquerycred                                13856
#define kNtErrorIpsecIkeGetspifail                                  13857
#define kNtErrorIpsecIkeInvalidFilter                               13858
#define kNtErrorIpsecIkeOutOfMemory                                 13859
#define kNtErrorIpsecIkeAddUpdateKeyFailed                          13860
#define kNtErrorIpsecIkeInvalidPolicy                               13861
#define kNtErrorIpsecIkeUnknownDoi                                  13862
#define kNtErrorIpsecIkeInvalidSituation                            13863
#define kNtErrorIpsecIkeDhFailure                                   13864
#define kNtErrorIpsecIkeInvalidGroup                                13865
#define kNtErrorIpsecIkeEncrypt                                     13866
#define kNtErrorIpsecIkeDecrypt                                     13867
#define kNtErrorIpsecIkePolicyMatch                                 13868
#define kNtErrorIpsecIkeUnsupportedId                               13869
#define kNtErrorIpsecIkeInvalidHash                                 13870
#define kNtErrorIpsecIkeInvalidHashAlg                              13871
#define kNtErrorIpsecIkeInvalidHashSize                             13872
#define kNtErrorIpsecIkeInvalidEncryptAlg                           13873
#define kNtErrorIpsecIkeInvalidAuthAlg                              13874
#define kNtErrorIpsecIkeInvalidSig                                  13875
#define kNtErrorIpsecIkeLoadFailed                                  13876
#define kNtErrorIpsecIkeRpcDelete                                   13877
#define kNtErrorIpsecIkeBenignReinit                                13878
#define kNtErrorIpsecIkeInvalidResponderLifetimeNotify              13879
#define kNtErrorIpsecIkeInvalidMajorVersion                         13880
#define kNtErrorIpsecIkeInvalidCertKeylen                           13881
#define kNtErrorIpsecIkeMmLimit                                     13882
#define kNtErrorIpsecIkeNegotiationDisabled                         13883
#define kNtErrorIpsecIkeQmLimit                                     13884
#define kNtErrorIpsecIkeMmExpired                                   13885
#define kNtErrorIpsecIkePeerMmAssumedInvalid                        13886
#define kNtErrorIpsecIkeCertChainPolicyMismatch                     13887
#define kNtErrorIpsecIkeUnexpectedMessageId                         13888
#define kNtErrorIpsecIkeInvalidAuthPayload                          13889
#define kNtErrorIpsecIkeDosCookieSent                               13890
#define kNtErrorIpsecIkeShuttingDown                                13891
#define kNtErrorIpsecIkeCgaAuthFailed                               13892
#define kNtErrorIpsecIkeProcessErrNatoa                             13893
#define kNtErrorIpsecIkeInvalidMmForQm                              13894
#define kNtErrorIpsecIkeQmExpired                                   13895
#define kNtErrorIpsecIkeTooManyFilters                              13896
#define kNtErrorIpsecIkeNegStatusEnd                                13897
#define kNtErrorIpsecIkeKillDummyNapTunnel                          13898
#define kNtErrorIpsecIkeInnerIpAssignmentFailure                    13899
#define kNtErrorIpsecIkeRequireCpPayloadMissing                     13900
#define kNtErrorIpsecKeyModuleImpersonationNegotiationPending       13901
#define kNtErrorIpsecIkeCoexistenceSuppress                         13902
#define kNtErrorIpsecIkeRatelimitDrop                               13903
#define kNtErrorIpsecIkePeerDoesntSupportMobike                     13904
#define kNtErrorIpsecIkeAuthorizationFailure                        13905
#define kNtErrorIpsecIkeStrongCredAuthorizationFailure              13906
#define kNtErrorIpsecIkeAuthorizationFailureWithOptionalRetry       13907
#define kNtErrorIpsecIkeStrongCredAuthorizationAndCertmapFailure    13908
#define kNtErrorIpsecIkeNegStatusExtendedEnd                        13909
#define kNtErrorIpsecBadSpi                                         13910
#define kNtErrorIpsecSaLifetimeExpired                              13911
#define kNtErrorIpsecWrongSa                                        13912
#define kNtErrorIpsecReplayCheckFailed                              13913
#define kNtErrorIpsecInvalidPacket                                  13914
#define kNtErrorIpsecIntegrityCheckFailed                           13915
#define kNtErrorIpsecClearTextDrop                                  13916
#define kNtErrorIpsecAuthFirewallDrop                               13917
#define kNtErrorIpsecThrottleDrop                                   13918
#define kNtErrorIpsecDospBlock                                      13925
#define kNtErrorIpsecDospReceivedMulticast                          13926
#define kNtErrorIpsecDospInvalidPacket                              13927
#define kNtErrorIpsecDospStateLookupFailed                          13928
#define kNtErrorIpsecDospMaxEntries                                 13929
#define kNtErrorIpsecDospKeymodNotAllowed                           13930
#define kNtErrorIpsecDospNotInstalled                               13931
#define kNtErrorIpsecDospMaxPerIpRatelimitQueues                    13932
#define kNtErrorSxsSectionNotFound                                  14000
#define kNtErrorSxsCantGenActctx                                    14001
#define kNtErrorSxsInvalidActctxdataFormat                          14002
#define kNtErrorSxsAssemblyNotFound                                 14003
#define kNtErrorSxsManifestFormatError                              14004
#define kNtErrorSxsManifestParseError                               14005
#define kNtErrorSxsActivationContextDisabled                        14006
#define kNtErrorSxsKeyNotFound                                      14007
#define kNtErrorSxsVersionConflict                                  14008
#define kNtErrorSxsWrongSectionType                                 14009
#define kNtErrorSxsThreadQueriesDisabled                            14010
#define kNtErrorSxsProcessDefaultAlreadySet                         14011
#define kNtErrorSxsUnknownEncodingGroup                             14012
#define kNtErrorSxsUnknownEncoding                                  14013
#define kNtErrorSxsInvalidXmlNamespaceUri                           14014
#define kNtErrorSxsRootManifestDependencyNotInstalled               14015
#define kNtErrorSxsLeafManifestDependencyNotInstalled               14016
#define kNtErrorSxsInvalidAssemblyIdentityAttribute                 14017
#define kNtErrorSxsManifestMissingRequiredDefaultNamespace          14018
#define kNtErrorSxsManifestInvalidRequiredDefaultNamespace          14019
#define kNtErrorSxsPrivateManifestCrossPathWithReparsePoint         14020
#define kNtErrorSxsDuplicateDllName                                 14021
#define kNtErrorSxsDuplicateWindowclassName                         14022
#define kNtErrorSxsDuplicateClsid                                   14023
#define kNtErrorSxsDuplicateIid                                     14024
#define kNtErrorSxsDuplicateTlbid                                   14025
#define kNtErrorSxsDuplicateProgid                                  14026
#define kNtErrorSxsDuplicateAssemblyName                            14027
#define kNtErrorSxsFileHashMismatch                                 14028
#define kNtErrorSxsPolicyParseError                                 14029
#define kNtErrorSxsXmlEMissingquote                                 14030
#define kNtErrorSxsXmlECommentsyntax                                14031
#define kNtErrorSxsXmlEBadstartnamechar                             14032
#define kNtErrorSxsXmlEBadnamechar                                  14033
#define kNtErrorSxsXmlEBadcharinstring                              14034
#define kNtErrorSxsXmlEXmldeclsyntax                                14035
#define kNtErrorSxsXmlEBadchardata                                  14036
#define kNtErrorSxsXmlEMissingwhitespace                            14037
#define kNtErrorSxsXmlEExpectingtagend                              14038
#define kNtErrorSxsXmlEMissingsemicolon                             14039
#define kNtErrorSxsXmlEUnbalancedparen                              14040
#define kNtErrorSxsXmlEInternalerror                                14041
#define kNtErrorSxsXmlEUnexpectedWhitespace                         14042
#define kNtErrorSxsXmlEIncompleteEncoding                           14043
#define kNtErrorSxsXmlEMissingParen                                 14044
#define kNtErrorSxsXmlEExpectingclosequote                          14045
#define kNtErrorSxsXmlEMultipleColons                               14046
#define kNtErrorSxsXmlEInvalidDecimal                               14047
#define kNtErrorSxsXmlEInvalidHexidecimal                           14048
#define kNtErrorSxsXmlEInvalidUnicode                               14049
#define kNtErrorSxsXmlEWhitespaceorquestionmark                     14050
#define kNtErrorSxsXmlEUnexpectedendtag                             14051
#define kNtErrorSxsXmlEUnclosedtag                                  14052
#define kNtErrorSxsXmlEDuplicateattribute                           14053
#define kNtErrorSxsXmlEMultipleroots                                14054
#define kNtErrorSxsXmlEInvalidatrootlevel                           14055
#define kNtErrorSxsXmlEBadxmldecl                                   14056
#define kNtErrorSxsXmlEMissingroot                                  14057
#define kNtErrorSxsXmlEUnexpectedeof                                14058
#define kNtErrorSxsXmlEBadperefinsubset                             14059
#define kNtErrorSxsXmlEUnclosedstarttag                             14060
#define kNtErrorSxsXmlEUnclosedendtag                               14061
#define kNtErrorSxsXmlEUnclosedstring                               14062
#define kNtErrorSxsXmlEUnclosedcomment                              14063
#define kNtErrorSxsXmlEUncloseddecl                                 14064
#define kNtErrorSxsXmlEUnclosedcdata                                14065
#define kNtErrorSxsXmlEReservednamespace                            14066
#define kNtErrorSxsXmlEInvalidencoding                              14067
#define kNtErrorSxsXmlEInvalidswitch                                14068
#define kNtErrorSxsXmlEBadxmlcase                                   14069
#define kNtErrorSxsXmlEInvalidStandalone                            14070
#define kNtErrorSxsXmlEUnexpectedStandalone                         14071
#define kNtErrorSxsXmlEInvalidVersion                               14072
#define kNtErrorSxsXmlEMissingequals                                14073
#define kNtErrorSxsProtectionRecoveryFailed                         14074
#define kNtErrorSxsProtectionPublicKeyTooShort                      14075
#define kNtErrorSxsProtectionCatalogNotValid                        14076
#define kNtErrorSxsUntranslatableHresult                            14077
#define kNtErrorSxsProtectionCatalogFileMissing                     14078
#define kNtErrorSxsMissingAssemblyIdentityAttribute                 14079
#define kNtErrorSxsInvalidAssemblyIdentityAttributeName             14080
#define kNtErrorSxsAssemblyMissing                                  14081
#define kNtErrorSxsCorruptActivationStack                           14082
#define kNtErrorSxsCorruption                                       14083
#define kNtErrorSxsEarlyDeactivation                                14084
#define kNtErrorSxsInvalidDeactivation                              14085
#define kNtErrorSxsMultipleDeactivation                             14086
#define kNtErrorSxsProcessTerminationRequested                      14087
#define kNtErrorSxsReleaseActivationContext                         14088
#define kNtErrorSxsSystemDefaultActivationContextEmpty              14089
#define kNtErrorSxsInvalidIdentityAttributeValue                    14090
#define kNtErrorSxsInvalidIdentityAttributeName                     14091
#define kNtErrorSxsIdentityDuplicateAttribute                       14092
#define kNtErrorSxsIdentityParseError                               14093
#define kNtErrorMalformedSubstitutionString                         14094
#define kNtErrorSxsIncorrectPublicKeyToken                          14095
#define kNtErrorUnmappedSubstitutionString                          14096
#define kNtErrorSxsAssemblyNotLocked                                14097
#define kNtErrorSxsComponentStoreCorrupt                            14098
#define kNtErrorAdvancedInstallerFailed                             14099
#define kNtErrorXmlEncodingMismatch                                 14100
#define kNtErrorSxsManifestIdentitySameButContentsDifferent         14101
#define kNtErrorSxsIdentitiesDifferent                              14102
#define kNtErrorSxsAssemblyIsNotADeployment                         14103
#define kNtErrorSxsFileNotPartOfAssembly                            14104
#define kNtErrorSxsManifestTooBig                                   14105
#define kNtErrorSxsSettingNotRegistered                             14106
#define kNtErrorSxsTransactionClosureIncomplete                     14107
#define kNtErrorSmiPrimitiveInstallerFailed                         14108
#define kNtErrorGenericCommandFailed                                14109
#define kNtErrorSxsFileHashMissing                                  14110
#define kNtErrorEvtInvalidChannelPath                               15000
#define kNtErrorEvtInvalidQuery                                     15001
#define kNtErrorEvtPublisherMetadataNotFound                        15002
#define kNtErrorEvtEventTemplateNotFound                            15003
#define kNtErrorEvtInvalidPublisherName                             15004
#define kNtErrorEvtInvalidEventData                                 15005
#define kNtErrorEvtChannelNotFound                                  15007
#define kNtErrorEvtMalformedXmlText                                 15008
#define kNtErrorEvtSubscriptionToDirectChannel                      15009
#define kNtErrorEvtConfigurationError                               15010
#define kNtErrorEvtQueryResultStale                                 15011
#define kNtErrorEvtQueryResultInvalidPosition                       15012
#define kNtErrorEvtNonValidatingMsxml                               15013
#define kNtErrorEvtFilterAlreadyscoped                              15014
#define kNtErrorEvtFilterNoteltset                                  15015
#define kNtErrorEvtFilterInvarg                                     15016
#define kNtErrorEvtFilterInvtest                                    15017
#define kNtErrorEvtFilterInvtype                                    15018
#define kNtErrorEvtFilterParseerr                                   15019
#define kNtErrorEvtFilterUnsupportedop                              15020
#define kNtErrorEvtFilterUnexpectedtoken                            15021
#define kNtErrorEvtInvalidOperationOverEnabledDirectChannel         15022
#define kNtErrorEvtInvalidChannelPropertyValue                      15023
#define kNtErrorEvtInvalidPublisherPropertyValue                    15024
#define kNtErrorEvtChannelCannotActivate                            15025
#define kNtErrorEvtFilterTooComplex                                 15026
#define kNtErrorEvtMessageNotFound                                  15027
#define kNtErrorEvtMessageIdNotFound                                15028
#define kNtErrorEvtUnresolvedValueInsert                            15029
#define kNtErrorEvtUnresolvedParameterInsert                        15030
#define kNtErrorEvtMaxInsertsReached                                15031
#define kNtErrorEvtEventDefinitionNotFound                          15032
#define kNtErrorEvtMessageLocaleNotFound                            15033
#define kNtErrorEvtVersionTooOld                                    15034
#define kNtErrorEvtVersionTooNew                                    15035
#define kNtErrorEvtCannotOpenChannelOfQuery                         15036
#define kNtErrorEvtPublisherDisabled                                15037
#define kNtErrorEvtFilterOutOfRange                                 15038
#define kNtErrorEcSubscriptionCannotActivate                        15080
#define kNtErrorEcLogDisabled                                       15081
#define kNtErrorEcCircularForwarding                                15082
#define kNtErrorEcCredstoreFull                                     15083
#define kNtErrorEcCredNotFound                                      15084
#define kNtErrorEcNoActiveChannel                                   15085
#define kNtErrorMuiFileNotFound                                     15100
#define kNtErrorMuiInvalidFile                                      15101
#define kNtErrorMuiInvalidRcConfig                                  15102
#define kNtErrorMuiInvalidLocaleName                                15103
#define kNtErrorMuiInvalidUltimatefallbackName                      15104
#define kNtErrorMuiFileNotLoaded                                    15105
#define kNtErrorResourceEnumUserStop                                15106
#define kNtErrorMuiIntlsettingsUilangNotInstalled                   15107
#define kNtErrorMuiIntlsettingsInvalidLocaleName                    15108
#define kNtErrorMrmRuntimeNoDefaultOrNeutralResource                15110
#define kNtErrorMrmInvalidPriconfig                                 15111
#define kNtErrorMrmInvalidFileType                                  15112
#define kNtErrorMrmUnknownQualifier                                 15113
#define kNtErrorMrmInvalidQualifierValue                            15114
#define kNtErrorMrmNoCandidate                                      15115
#define kNtErrorMrmNoMatchOrDefaultCandidate                        15116
#define kNtErrorMrmResourceTypeMismatch                             15117
#define kNtErrorMrmDuplicateMapName                                 15118
#define kNtErrorMrmDuplicateEntry                                   15119
#define kNtErrorMrmInvalidResourceIdentifier                        15120
#define kNtErrorMrmFilepathTooLong                                  15121
#define kNtErrorMrmUnsupportedDirectoryType                         15122
#define kNtErrorMrmInvalidPriFile                                   15126
#define kNtErrorMrmNamedResourceNotFound                            15127
#define kNtErrorMrmMapNotFound                                      15135
#define kNtErrorMrmUnsupportedProfileType                           15136
#define kNtErrorMrmInvalidQualifierOperator                         15137
#define kNtErrorMrmIndeterminateQualifierValue                      15138
#define kNtErrorMrmAutomergeEnabled                                 15139
#define kNtErrorMrmTooManyResources                                 15140
#define kNtErrorMrmUnsupportedFileTypeForMerge                      15141
#define kNtErrorMrmUnsupportedFileTypeForLoadUnloadPriFile          15142
#define kNtErrorMrmNoCurrentViewOnThread                            15143
#define kNtErrorDifferentProfileResourceManagerExist                15144
#define kNtErrorOperationNotAllowedFromSystemComponent              15145
#define kNtErrorMrmDirectRefToNonDefaultResource                    15146
#define kNtErrorMrmGenerationCountMismatch                          15147
#define kNtErrorPriMergeVersionMismatch                             15148
#define kNtErrorPriMergeMissingSchema                               15149
#define kNtErrorPriMergeLoadFileFailed                              15150
#define kNtErrorPriMergeAddFileFailed                               15151
#define kNtErrorPriMergeWriteFileFailed                             15152
#define kNtErrorPriMergeMultiplePackageFamiliesNotAllowed           15153
#define kNtErrorPriMergeMultipleMainPackagesNotAllowed              15154
#define kNtErrorPriMergeBundlePackagesNotAllowed                    15155
#define kNtErrorPriMergeMainPackageRequired                         15156
#define kNtErrorPriMergeResourcePackageRequired                     15157
#define kNtErrorPriMergeInvalidFileName                             15158
#define kNtErrorMcaInvalidCapabilitiesString                        15200
#define kNtErrorMcaInvalidVcpVersion                                15201
#define kNtErrorMcaMonitorViolatesMccsSpecification                 15202
#define kNtErrorMcaMccsVersionMismatch                              15203
#define kNtErrorMcaUnsupportedMccsVersion                           15204
#define kNtErrorMcaInternalError                                    15205
#define kNtErrorMcaInvalidTechnologyTypeReturned                    15206
#define kNtErrorMcaUnsupportedColorTemperature                      15207
#define kNtErrorAmbiguousSystemDevice                               15250
#define kNtErrorSystemDeviceNotFound                                15299
#define kNtErrorHashNotSupported                                    15300
#define kNtErrorHashNotPresent                                      15301
#define kNtErrorSecondaryIcProviderNotRegistered                    15321
#define kNtErrorGpioClientInformationInvalid                        15322
#define kNtErrorGpioVersionNotSupported                             15323
#define kNtErrorGpioInvalidRegistrationPacket                       15324
#define kNtErrorGpioOperationDenied                                 15325
#define kNtErrorGpioIncompatibleConnectMode                         15326
#define kNtErrorGpioInterruptAlreadyUnmasked                        15327
#define kNtErrorCannotSwitchRunlevel                                15400
#define kNtErrorInvalidRunlevelSetting                              15401
#define kNtErrorRunlevelSwitchTimeout                               15402
#define kNtErrorRunlevelSwitchAgentTimeout                          15403
#define kNtErrorRunlevelSwitchInProgress                            15404
#define kNtErrorServicesFailedAutostart                             15405
#define kNtErrorComTaskStopPending                                  15501
#define kNtErrorInstallOpenPackageFailed                            15600
#define kNtErrorInstallPackageNotFound                              15601
#define kNtErrorInstallInvalidPackage                               15602
#define kNtErrorInstallResolveDependencyFailed                      15603
#define kNtErrorInstallOutOfDiskSpace                               15604
#define kNtErrorInstallNetworkFailure                               15605
#define kNtErrorInstallRegistrationFailure                          15606
#define kNtErrorInstallDeregistrationFailure                        15607
#define kNtErrorInstallCancel                                       15608
#define kNtErrorInstallFailed                                       15609
#define kNtErrorRemoveFailed                                        15610
#define kNtErrorPackageAlreadyExists                                15611
#define kNtErrorNeedsRemediation                                    15612
#define kNtErrorInstallPrerequisiteFailed                           15613
#define kNtErrorPackageRepositoryCorrupted                          15614
#define kNtErrorInstallPolicyFailure                                15615
#define kNtErrorPackageUpdating                                     15616
#define kNtErrorDeploymentBlockedByPolicy                           15617
#define kNtErrorPackagesInUse                                       15618
#define kNtErrorRecoveryFileCorrupt                                 15619
#define kNtErrorInvalidStagedSignature                              15620
#define kNtErrorDeletingExistingApplicationdataStoreFailed          15621
#define kNtErrorInstallPackageDowngrade                             15622
#define kNtErrorSystemNeedsRemediation                              15623
#define kNtErrorAppxIntegrityFailureClrNgen                         15624
#define kNtErrorResiliencyFileCorrupt                               15625
#define kNtErrorInstallFirewallServiceNotRunning                    15626
#define kNtErrorPackageMoveFailed                                   15627
#define kNtErrorInstallVolumeNotEmpty                               15628
#define kNtErrorInstallVolumeOffline                                15629
#define kNtErrorInstallVolumeCorrupt                                15630
#define kNtErrorNeedsRegistration                                   15631
#define kNtErrorInstallWrongProcessorArchitecture                   15632
#define kNtErrorDevSideloadLimitExceeded                            15633
#define kNtErrorInstallOptionalPackageRequiresMainPackage           15634
#define kNtErrorPackageNotSupportedOnFilesystem                     15635
#define kNtErrorPackageMoveBlockedByStreaming                       15636
#define kNtErrorInstallOptionalPackageApplicationidNotUnique        15637
#define kNtErrorPackageStagingOnhold                                15638
#define kNtErrorInstallInvalidRelatedSetUpdate                      15639
#define kNtErrorPackagesReputationCheckFailed                       15643
#define kNtErrorPackagesReputationCheckTimedout                     15644
#define kNtErrorStateLoadStoreFailed                                15800
#define kNtErrorStateGetVersionFailed                               15801
#define kNtErrorStateSetVersionFailed                               15802
#define kNtErrorStateStructuredResetFailed                          15803
#define kNtErrorStateOpenContainerFailed                            15804
#define kNtErrorStateCreateContainerFailed                          15805
#define kNtErrorStateDeleteContainerFailed                          15806
#define kNtErrorStateReadSettingFailed                              15807
#define kNtErrorStateWriteSettingFailed                             15808
#define kNtErrorStateDeleteSettingFailed                            15809
#define kNtErrorStateQuerySettingFailed                             15810
#define kNtErrorStateReadCompositeSettingFailed                     15811
#define kNtErrorStateWriteCompositeSettingFailed                    15812
#define kNtErrorStateEnumerateContainerFailed                       15813
#define kNtErrorStateEnumerateSettingsFailed                        15814
#define kNtErrorStateCompositeSettingValueSizeLimitExceeded         15815
#define kNtErrorStateSettingValueSizeLimitExceeded                  15816
#define kNtErrorStateSettingNameSizeLimitExceeded                   15817
#define kNtErrorStateContainerNameSizeLimitExceeded                 15818
#define kNtErrorApiUnavailable                                      15841 /* EPROCUNAVAIL */

#define kNtWaitIoCompletion 0xc0

/* WinSock Error Codes: 10000-11999 */
#define WSABASEERR                  10000
#define WSAEINTR                    10004
#define WSAEBADF                    10009
#define WSAEACCES                   10013
#define WSAEFAULT                   10014
#define WSAEINVAL                   10022
#define WSAEMFILE                   10024
#define WSAEWOULDBLOCK              10035
#define WSAEINPROGRESS              10036
#define WSAEALREADY                 10037
#define WSAENOTSOCK                 10038
#define WSAEDESTADDRREQ             10039
#define WSAEMSGSIZE                 10040
#define WSAEPROTOTYPE               10041
#define WSAENOPROTOOPT              10042
#define WSAEPROTONOSUPPORT          10043
#define WSAESOCKTNOSUPPORT          10044
#define WSAEOPNOTSUPP               10045
#define WSAEPFNOSUPPORT             10046
#define WSAEAFNOSUPPORT             10047
#define WSAEADDRINUSE               10048
#define WSAEADDRNOTAVAIL            10049
#define WSAENETDOWN                 10050
#define WSAENETUNREACH              10051
#define WSAENETRESET                10052
#define WSAECONNABORTED             10053
#define WSAECONNRESET               10054
#define WSAENOBUFS                  10055
#define WSAEISCONN                  10056
#define WSAENOTCONN                 10057
#define WSAESHUTDOWN                10058
#define WSAETOOMANYREFS             10059
#define WSAETIMEDOUT                10060
#define WSAECONNREFUSED             10061
#define WSAELOOP                    10062
#define WSAENAMETOOLONG             10063
#define WSAEHOSTDOWN                10064
#define WSAEHOSTUNREACH             10065
#define WSAENOTEMPTY                10066
#define WSAEPROCLIM                 10067
#define WSAEUSERS                   10068
#define WSAEDQUOT                   10069
#define WSAESTALE                   10070
#define WSAEREMOTE                  10071
#define WSASYSNOTREADY              10091
#define WSAVERNOTSUPPORTED          10092
#define WSANOTINITIALISED           10093
#define WSAEDISCON                  10101
#define WSAENOMORE                  10102
#define WSAECANCELLED               10103
#define WSAEINVALIDPROCTABLE        10104
#define WSAEINVALIDPROVIDER         10105
#define WSAEPROVIDERFAILEDINIT      10106
#define WSASYSCALLFAILURE           10107
#define WSASERVICE_NOT_FOUND        10108
#define WSATYPE_NOT_FOUND           10109
#define WSA_E_NO_MORE               10110
#define WSA_E_CANCELLED             10111
#define WSAEREFUSED                 10112
#define WSAHOST_NOT_FOUND           11001
#define WSATRY_AGAIN                11002
#define WSANO_RECOVERY              11003
#define WSANO_DATA                  11004
#define WSA_QOS_RECEIVERS           11005
#define WSA_QOS_SENDERS             11006
#define WSA_QOS_NO_SENDERS          11007
#define WSA_QOS_NO_RECEIVERS        11008
#define WSA_QOS_REQUEST_CONFIRMED   11009
#define WSA_QOS_ADMISSION_FAILURE   11010
#define WSA_QOS_POLICY_FAILURE      11011
#define WSA_QOS_BAD_STYLE           11012
#define WSA_QOS_BAD_OBJECT          11013
#define WSA_QOS_TRAFFIC_CTRL_ERROR  11014
#define WSA_QOS_GENERIC_ERROR       11015
#define WSA_QOS_ESERVICETYPE        11016
#define WSA_QOS_EFLOWSPEC           11017
#define WSA_QOS_EPROVSPECBUF        11018
#define WSA_QOS_EFILTERSTYLE        11019
#define WSA_QOS_EFILTERTYPE         11020
#define WSA_QOS_EFILTERCOUNT        11021
#define WSA_QOS_EOBJLENGTH          11022
#define WSA_QOS_EFLOWCOUNT          11023
#define WSA_QOS_EUNKOWNPSOBJ        11024
#define WSA_QOS_EPOLICYOBJ          11025
#define WSA_QOS_EFLOWDESC           11026
#define WSA_QOS_EPSFLOWSPEC         11027
#define WSA_QOS_EPSFILTERSPEC       11028
#define WSA_QOS_ESDMODEOBJ          11029
#define WSA_QOS_ESHAPERATEOBJ       11030
#define WSA_QOS_RESERVED_PETYPE     11031
#define WSA_SECURE_HOST_NOT_FOUND   11032
#define WSA_IPSEC_NAME_POLICY_ERROR 11033

#define WSA_WAIT_FAILED         -1u
#define WSA_WAIT_EVENT_0        0
#define WSA_WAIT_IO_COMPLETION  0xc0
#define WSA_WAIT_TIMEOUT        258
#define WSA_MAXIMUM_WAIT_EVENTS 64
#define WSA_IO_PENDING          997


#define kNtWsaInvalidHandle    kNtErrorInvalidHandle
#define kNtWsaNotEnoughMemory  kNtErrorNotEnoughMemory
#define kNtWsaInvalidParameter kNtErrorInvalidParameter
#define kNtWsaIoPending        kNtErrorIoPending
#define kNtWsaIoIncomplete     kNtErrorIoIncomplete
#define kNtWsaOperationAborted kNtErrorOperationAborted



/*!BEGIN libc/nt/enum/wsaid.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WSAID_H_
COSMOPOLITAN_C_START_

#define WSAID_WSAPOLL                                \
  {                                                  \
    0x18C76F85, 0xDC66, 0x4964, {                    \
      0x97, 0x2E, 0x23, 0xC2, 0x72, 0x38, 0x31, 0x2B \
    }                                                \
  }

#define WSAID_WSARECVMSG                             \
  {                                                  \
    0xf689d7c8, 0x6f1f, 0x436b, {                    \
      0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22 \
    }                                                \
  }

#define WSAID_WSASENDMSG                             \
  {                                                  \
    0xa441e712, 0x754f, 0x43ca, {                    \
      0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d \
    }                                                \
  }

#define WSAID_CONNECTEX                              \
  {                                                  \
    0x25a207b9, 0xddf3, 0x4660, {                    \
      0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e \
    }                                                \
  }

#define WSAID_ACCEPTEX                               \
  {                                                  \
    0xb5367df1, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_GETACCEPTEXSOCKADDRS                   \
  {                                                  \
    0xb5367df2, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITFILE                           \
  {                                                  \
    0xb5367df0, 0xcbac, 0x11cf, {                    \
      0x95, 0xca, 0x00, 0x80, 0x5f, 0x48, 0xa1, 0x92 \
    }                                                \
  }

#define WSAID_TRANSMITPACKETS                        \
  {                                                  \
    0xd9689da0, 0x1f90, 0x11d3, {                    \
      0x99, 0x71, 0x00, 0xc0, 0x4f, 0x68, 0xc8, 0x76 \
    }                                                \
  }

#define WSAID_DISCONNECTEX                           \
  {                                                  \
    0x7fda2e11, 0x8630, 0x436f, {                    \
      0xa0, 0x31, 0xf5, 0x36, 0xa6, 0xee, 0xc1, 0x57 \
    }                                                \
  }

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/enum/wt.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_WT_H_

#define kNtWtExecutedefault            0x00000000u
#define kNtWtExecuteonlyonce           0x00000008u
#define kNtWtExecuteintimerthread      0x00000020u
#define kNtWtExecuteinpersistentthread 0x00000080u
#define kNtWtExecutelongfunction       0x00000010u
#define kNtWtTransferImpersonation     0𝔵00000100𝔲



/*!BEGIN libc/nt/struct/acl.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ACL_H_

struct NtAcl {
  uint8_t AclRevision;
  uint8_t Sbz1;
  uint16_t AclSize;
  uint16_t AceCount;
  uint16_t Sbz2;
};



/*!BEGIN libc/nt/struct/afd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_AFD_H_
COSMOPOLITAN_C_START_

struct NtAfdPollHandleInfo {
  int64_t Handle;
  uint32_t Events;
  NtStatus Status;
};

struct NtAfdPollInfo {
  int64_t Timeout;
  uint32_t NumberOfHandles;
  uint32_t Exclusive;
  struct NtAfdPollHandleInfo Handles[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ansistring.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_ANSISTRING_H_

struct NtAnsiString {
  unsigned short Length;
  unsigned short MaximumLength;
  char *Buffer;
};



/*!BEGIN libc/nt/struct/byhandlefileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_BYHANDLEFILEINFORMATION_H_


/*!BEGIN libc/nt/struct/filetime.h */

#define COSMOPOLITAN_LIBC_NT_FILETIME_H_

struct NtFileTime {
  uint32_t dwLowDateTime;
  uint32_t dwHighDateTime;
};


struct NtByHandleFileInformation {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationFileTime;
  struct NtFileTime ftLastAccessFileTime;
  struct NtFileTime ftLastWriteFileTime;
  uint32_t dwVolumeSerialNumber;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t nNumberOfLinks;
  uint32_t nFileIndexHigh;
  uint32_t nFileIndexLow;
};



/*!BEGIN libc/nt/struct/charinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CHARINFO_H_

struct NtCharInfo {
  union {
    char16_t UnicodeChar;
    char AsciiChar;
  } Char;
  uint16_t Attributes;
};



/*!BEGIN libc/nt/struct/clientid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CLIENTID_H_

struct NtClientId {
  void *UniqueProcess;
  void *UniqueThread;
};



/*!BEGIN libc/nt/struct/consolecursorinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLECURSORINFO_H_

struct NtConsoleCursorInfo {
  uint32_t dwSize;
  bool32 bVisible;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFO_H_


/*!BEGIN libc/nt/struct/coord.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_COORD_H_

struct NtCoord {
  int16_t X;
  int16_t Y;
};



/*!BEGIN libc/nt/struct/smallrect.h */

#define COSMOPOLITAN_LIBC_NT_ENUM_SMALLRECT_H_

struct NtSmallRect {
  int16_t Left;
  int16_t Top;
  int16_t Right;
  int16_t Bottom;
};


struct NtConsoleScreenBufferInfo {
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes;
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
};



/*!BEGIN libc/nt/struct/consolescreenbufferinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESCREENBUFFERINFOEX_H_

struct NtConsoleScreenBufferInfoEx {
  uint32_t cbSize; /* sizeof(struct NtConsoleScreenBufferInfoEx) */
  struct NtCoord dwSize;
  struct NtCoord dwCursorPosition;
  uint16_t wAttributes; /* kNt{Foreground,Background}... */
  struct NtSmallRect srWindow;
  struct NtCoord dwMaximumWindowSize;
  uint16_t wPopupAttributes;
  bool32 bFullscreenSupported;
  uint32_t ColorTable[16]; /* 0x00BBGGRR */
};



/*!BEGIN libc/nt/struct/consoleselectioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONSOLESELECTIONINFO_H_

struct NtConsoleSelectionInfo {
  uint32_t dwFlags;
  struct NtCoord dwSelectionAnchor;
  struct NtSmallRect srSelection;
};



/*!BEGIN libc/nt/struct/context.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CONTEXT_H_

struct NtM128A {
  uint64_t Low;
  int64_t High;
};

struct NtXmmSaveArea32 { /* basically same as struct FpuState */
  uint16_t ControlWord;
  uint16_t StatusWord;
  uint8_t TagWord;
  uint8_t Reserved1;
  uint16_t ErrorOpcode;
  uint32_t ErrorOffset;
  uint16_t ErrorSelector;
  uint16_t Reserved2;
  uint32_t DataOffset;
  uint16_t DataSelector;
  uint16_t Reserved3;
  uint32_t MxCsr;
  uint32_t MxCsr_Mask;
  struct NtM128A FloatRegisters[8];
  struct NtM128A XmmRegisters[16];
  uint8_t Reserved4[96];
};

struct NtContext {
  uint64_t P1Home, P2Home, P3Home, P4Home, P5Home, P6Home;
  uint32_t ContextFlags;
  uint32_t MxCsr;
  uint16_t SegCs, SegDs, SegEs, SegFs, SegGs, SegSs;
  uint32_t EFlags;
  uint64_t Dr0, Dr1, Dr2, Dr3, Dr6, Dr7;
  uint64_t Rax, Rcx, Rdx, Rbx, Rsp, Rbp, Rsi, Rdi;
  uint64_t R8, R9, R10, R11, R12, R13, R14, R15;
  uint64_t Rip;
  union {
    struct NtXmmSaveArea32 FltSave;
    struct NtXmmSaveArea32 FloatSave;
    struct {
      struct NtM128A Header[2];
      struct NtM128A Legacy[8];
      struct NtM128A Xmm0, Xmm1, Xmm2, Xmm3, Xmm4, Xmm5, Xmm6, Xmm7;
      struct NtM128A Xmm8, Xmm9, Xmm10, Xmm11, Xmm12, Xmm13, Xmm14, Xmm15;
    };
  };
  struct NtM128A VectorRegister[26];
  uint64_t VectorControl;
  uint64_t DebugControl;
  uint64_t LastBranchToRip;
  uint64_t LastBranchFromRip;
  uint64_t LastExceptionToRip;
  uint64_t LastExceptionFromRip;
} forcealign(16);



/*!BEGIN libc/nt/struct/criticalsection.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTION_H_


/*!BEGIN libc/nt/struct/criticalsectiondebug.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_CRITICALSECTIONDEBUG_H_


/*!BEGIN libc/nt/struct/linkedlist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINKEDLIST_H_

/**
 * Dynamic linked list overlay.
 */
struct NtLinkedList {
  struct NtLinkedList *Next;
  struct NtLinkedList *Prev;
};


struct NtCriticalSectionDebug {
  uint16_t Type;
  uint16_t CreatorBackTraceIndex;
  struct NtCriticalSection *CriticalSection;
  struct NtLinkedList ProcessLocksList;
  uint32_t EntryCount;
  uint32_t ContentionCount;
  uint32_t Spare[2];
};


struct NtCriticalSection {
  struct NtCriticalSectionDebug *DebugInfo;
  int32_t LockCount;
  int32_t RecursionCount;
  void *OwningThread;
  void *LockSemaphore;
  uintptr_t SpinCount;
};



/*!BEGIN libc/nt/struct/drawtextparams.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DRAWTEXTPARAMS_H_
COSMOPOLITAN_C_START_

struct NtDrawTextParams {
  uint32_t cbSize;
  int32_t iTabLength;
  int32_t iLeftMargin;
  int32_t iRightMargin;
  uint32_t uiLengthDrawn;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/dynamictimezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_DYNAMICTIMEZONEINFORMATION_H_


/*!BEGIN libc/nt/struct/systemtime.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIME_H_

struct NtSystemTime {
  uint16_t wYear;
  uint16_t wMonth;
  uint16_t wDayOfWeek;
  uint16_t wDay;
  uint16_t wHour;
  uint16_t wMinute;
  uint16_t wSecond;
  uint16_t wMilliseconds;
};


struct NtDynamicTimeZoneInformation {
  int32_t Bias;
  char16_t StandardName[32];
  struct NtSystemTime StandardDate;
  int32_t StandardBias;
  char16_t DaylightName[32];
  struct NtSystemTime DaylightDate;
  int32_t DaylightBias;
  char16_t TimeZoneKeyName[128];
  bool32 DynamicDaylightTimeDisabled;
};



/*!BEGIN libc/nt/struct/editmenu.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EDITMENU_H_

struct NtEditMenu {
  int64_t hmenu;
  uint16_t idEdit;
  uint16_t idCut;
  uint16_t idCopy;
  uint16_t idPaste;
  uint16_t idClear;
  uint16_t idUndo;
};



/*!BEGIN libc/nt/struct/exceptionframe.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_EXCEPTIONFRAME_H_

struct NtExceptionFrame {
  struct NtExceptionFrame *Prev;
};



/*!BEGIN libc/nt/struct/fdset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FDSET_H_
COSMOPOLITAN_C_START_

struct NtFdSet {
  uint32_t fd_count;
  int64_t fd_array[64];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/fileaccessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEACCESSINFORMATION_H_

struct NtFileAccessInformation {
  uint32_t AccessFlags;
};



/*!BEGIN libc/nt/struct/filealignmentinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALIGNMENTINFORMATION_H_

struct NtFileAlignmentInformation {
  uint32_t AlignmentRequirement;
};



/*!BEGIN libc/nt/struct/fileallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLINFORMATION_H_


/*!BEGIN libc/nt/struct/filebasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFORMATION_H_

struct NtFileBasicInformation {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/fileeainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEEAINFORMATION_H_

struct NtFileEaInformation {
  uint32_t EaSize;
};



/*!BEGIN libc/nt/struct/fileinternalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEINTERNALINFORMATION_H_

struct NtFileInternalInformation {
  int64_t IndexNumber;
};



/*!BEGIN libc/nt/struct/filemodeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMODEINFORMATION_H_

struct NtFileModeInformation {
  uint32_t Mode;
};



/*!BEGIN libc/nt/struct/filenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMEINFORMATION_H_

struct NtFileNameInformation {
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filepositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPOSITIONINFORMATION_H_

struct NtFilePositionInformation {
  int64_t CurrentByteOffset;
};



/*!BEGIN libc/nt/struct/filestandardinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTANDARDINFORMATION_H_

struct NtFileStandardInformation {
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t NumberOfLinks;
  bool32 DeletePending;
  bool32 Directory;
};


struct NtFileAllInformation {
  struct NtFileBasicInformation BasicInformation;
  struct NtFileStandardInformation StandardInformation;
  struct NtFileInternalInformation InternalInformation;
  struct NtFileEaInformation EaInformation;
  struct NtFileAccessInformation AccessInformation;
  struct NtFilePositionInformation PositionInformation;
  struct NtFileModeInformation ModeInformation;
  struct NtFileAlignmentInformation AlignmentInformation;
  struct NtFileNameInformation NameInformation;
};



/*!BEGIN libc/nt/struct/fileallocationinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEALLOCATIONINFORMATION_H_

struct NtFileAllocationInformation {
  int64_t AllocationSize;
};



/*!BEGIN libc/nt/struct/fileattributetaginformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEATTRIBUTETAGINFORMATION_H_

struct NtFileAttributeTagInformation {
  uint32_t FileAttributes;
  uint32_t ReparseTag;
};



/*!BEGIN libc/nt/struct/filebasicinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBASICINFO_H_

struct NtFileBasicInfo {
  int64_t CreationTime;    /* in 100ns units */
  int64_t LastAccessTime;  /* in 100ns units */
  int64_t LastWriteTime;   /* in 100ns units */
  int64_t ChangeTime;      /* in 100ns units */
  uint32_t FileAttributes; /* kNtFileAttributeXXX */
};



/*!BEGIN libc/nt/struct/filebothdirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEBOTHDIRECTORYINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileBothDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  unsigned char ShortNameLength;
  char16_t ShortName[12];
  char16_t FileName[1];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filecompressioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILECOMPRESSIONINFO_H_

struct NtFileCompressionInfo {
  int64_t CompressedFileSize;
  uint16_t CompressionFormat;
  uint8_t CompressionUnitShift;
  uint8_t ChunkShift;
  uint8_t ClusterShift;
  uint8_t Reserved[3];
};



/*!BEGIN libc/nt/struct/filedirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDIRECTORYINFORMATION_H_

struct NtFileDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filedispositioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEDISPOSITIONINFORMATION_H_

struct NtFileDispositionInformation {
  bool32 DoDeleteFile;
};



/*!BEGIN libc/nt/struct/fileendoffileinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEENDOFFILEINFORMATION_H_

struct FileEndOfFileInformation {
  int64_t EndOfFile;
};



/*!BEGIN libc/nt/struct/filefsfullsizeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFSFULLSIZEINFORMATION_H_
COSMOPOLITAN_C_START_

struct NtFileFsFullSizeInformation {
  int64_t TotalAllocationUnits;
  int64_t CallerAvailableAllocationUnits;
  int64_t ActualAvailableAllocationUnits;
  uint32_t SectorsPerAllocationUnit;
  uint32_t BytesPerSector;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/filefulldirectoryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLDIRECTORYINFORMATION_H_

struct NtFileFullDirectoryInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t EndOfFile;
  int64_t AllocationSize;
  uint32_t FileAttributes;
  uint32_t FileNameLength;
  uint32_t EaSize;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filefulleainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEFULLEAINFORMATION_H_

struct NtFileFullEaInformation {
  uint32_t NextEntryOffset;
  uint8_t Flags;
  uint8_t EaNameLength;
  uint16_t EaValueLength;
  char EaName[1];
};



/*!BEGIN libc/nt/struct/filemailslotqueryinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTQUERYINFORMATION_H_

struct NtFileMailslotQueryInformation {
  uint32_t MaximumMessageSize;
  uint32_t MailslotQuota;
  uint32_t NextMessageSize;
  uint32_t MessagesAvailable;
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filemailslotsetinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEMAILSLOTSETINFORMATION_H_

struct NtFileMailslotSetInformation {
  int64_t ReadTimeout;
};



/*!BEGIN libc/nt/struct/filenamesinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENAMESINFORMATION_H_

struct NtFileNamesInformation {
  uint32_t NextEntryOffset;
  uint32_t FileIndex;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filenetworkopeninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILENETWORKOPENINFORMATION_H_

struct NtFileNetworkOpenInformation {
  int64_t CreationTime;
  int64_t LastAccessTime;
  int64_t LastWriteTime;
  int64_t ChangeTime;
  int64_t AllocationSize;
  int64_t EndOfFile;
  uint32_t FileAttributes;
};



/*!BEGIN libc/nt/struct/filepipelocalinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEPIPELOCALINFORMATION_H_

struct NtFilePipeLocalInformation {
  uint32_t NamedPipeType;
  uint32_t NamedPipeConfiguration;
  uint32_t MaximumInstances;
  uint32_t CurrentInstances;
  uint32_t InboundQuota;
  uint32_t ReadDataAvailable;
  uint32_t OutboundQuota;
  uint32_t WriteQuotaAvailable;
  uint32_t NamedPipeState;
  uint32_t NamedPipeEnd;
};



/*!BEGIN libc/nt/struct/filerenameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILERENAMEINFORMATION_H_

struct NtFileRenameInformation {
  bool32 Replace;
  void *RootDir;
  uint32_t FileNameLength;
  char16_t FileName[1];
};



/*!BEGIN libc/nt/struct/filesegmentelement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESEGMENTELEMENT_H_

union NtFileSegmentElement {
  void *Buffer;
  uint64_t Alignment;
};



/*!BEGIN libc/nt/struct/filestreaminformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILESTREAMINFORMATION_H_

struct NtFileStreamInformation {
  uint32_t NextEntryOffset;
  uint32_t StreamNameLength;
  int64_t StreamSize;
  int64_t StreamAllocationSize;
  char16_t StreamName[1];
};



/*!BEGIN libc/nt/struct/filezerodatainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FILEZERODATAINFORMATION_H_

struct NtFileZeroDataInformation {
  uint64_t FileOffset;
  uint64_t BeyondFinalZero;
};



/*!BEGIN libc/nt/struct/fpodata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_FPODATA_H_

struct NtFpoData {
  /* TODO(jart): No bitfields. */
  uint32_t ulOffStart;
  uint32_t cbProcSize;
  uint32_t cdwLocals;
  uint16_t cdwParams;
  uint16_t cbProlog : 8;
  uint16_t cbRegs : 3;
  uint16_t fHasSEH : 1;
  uint16_t fUseBP : 1;
  uint16_t reserved : 1;
  uint16_t cbFrame : 2;
};



/*!BEGIN libc/nt/struct/genericmapping.h */

#define COSMOPOLITAN_LIBC_NT_GENERICMAPPING_H_

struct NtGenericMapping {
  unsigned int GenericRead;
  unsigned int GenericWrite;
  unsigned int GenericExecute;
  unsigned int GenericAll;
};



/*!BEGIN libc/nt/struct/guid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_GUID_H_
COSMOPOLITAN_C_START_

struct NtGuid {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/inputrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_INPUTRECORD_H_

struct NtKeyEventRecord {
  bool32 bKeyDown;
  uint16_t wRepeatCount;
  uint16_t wVirtualKeyCode;
  uint16_t wVirtualScanCode;
  union {
    uint16_t UnicodeChar;
    char AsciiChar;
  } uChar;
  unsigned int dwControlKeyState;
#define kNtRightAltPressed  0x0001
#define kNtLeftAltPressed   0x0002
#define kNtRightCtrlPressed 0x0004
#define kNtLeftCtrlPressed  0x0008
#define kNtShiftPressed     0x0010
#define kNtNumlockOn        0x0020
#define kNtScrolllockOn     0x0040
#define kNtCapslockOn       0x0080
#define kNtEnhancedKey      0x0100
};

struct NtMouseEventRecord {
  struct NtCoord dwMousePosition;
  uint32_t dwButtonState;
#define kNtFromLeft1stButtonPressed 0x0001
#define kNtRightmostButtonPressed   0x0002
#define kNtFromLeft2ndButtonPressed 0x0004
#define kNtFromLeft3rdButtonPressed 0x0008
#define kNtFromLeft4thButtonPressed 0x0010
  uint32_t dwControlKeyState;
  uint32_t dwEventFlags;
#define kNtMouseMoved    0x0001
#define kNtDoubleClick   0x0002
#define kNtMouseWheeled  0x0004
#define kNtMouseHwheeled 0x0008
};

struct NtWindowBufferSizeRecord {
  struct NtCoord dwSize;
};

struct NtMenuEventRecord {
  uint32_t dwCommandId;
};

struct NtFocusEventRecord {
  bool32 bSetFocus;
};

struct NtInputRecord {
  uint16_t EventType;
#define kNtKeyEvent              0x0001
#define kNtMouseEvent            0x0002
#define kNtWindowBufferSizeEvent 0x0004
#define kNtMenuEvent             0x0008
#define kNtFocusEvent            0x0010
  union {
    struct NtKeyEventRecord KeyEvent;
    struct NtMouseEventRecord MouseEvent;
    struct NtWindowBufferSizeRecord WindowBufferSizeEvent;
    struct NtMenuEventRecord MenuEvent;
    struct NtFocusEventRecord FocusEvent;
  } Event;
};



/*!BEGIN libc/nt/struct/iocounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOCOUNTERS_H_

struct NtIoCounters {
  uint64_t ReadOperationCount;
  uint64_t WriteOperationCount;
  uint64_t OtherOperationCount;
  uint64_t ReadTransferCount;
  uint64_t WriteTransferCount;
  uint64_t OtherTransferCount;
};



/*!BEGIN libc/nt/struct/iostatusblock.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOSTATUSBLOCK_H_

struct NtIoStatusBlock {
  union {
    NtStatus Status;
    void *Pointer; /* reserved for internal use */
  };
  uint32_t *Information; /* request dependent */
};



/*!BEGIN libc/nt/struct/iovec.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IOVEC_H_
COSMOPOLITAN_C_START_

struct NtIovec {
  uint32_t len;
  char *buf;
};

void DescribeIovNt(const struct NtIovec *, uint32_t, ssize_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/ipadapteraddresses.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_IP_ADAPTER_ADDRESSES_H_


/*!BEGIN libc/nt/winsock.h */

#define COSMOPOLITAN_LIBC_NT_WINSOCK_H_


/*!BEGIN libc/nt/struct/overlapped.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPED_H_

struct NtOverlapped {
  uintptr_t Internal;
  uintptr_t InternalHigh;
  union {
    struct {
      uint32_t Offset;
      uint32_t OffsetHigh;
    };
    int64_t Pointer;
  };
  int64_t hEvent;
};



/*!BEGIN libc/nt/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POLLFD_H_

struct sys_pollfd_nt {
  int64_t handle;
  int16_t events;
  int16_t revents;
};



/*!BEGIN libc/nt/struct/timeval.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEVAL_H_
COSMOPOLITAN_C_START_

struct NtTimeval {
  int32_t tv_sec; /* [sic] */
  int32_t tv_usec;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thunk/msabi.h */

#define COSMOPOLITAN_LIBC_NT_THUNK_MSABI_H_
#ifdef __x86_64__

#if (__GNUC__ * 100 + __GNUC_MINOR__ >= 408 || \
     (__has_attribute(__ms_abi__) || defined(__llvm__)))
/**
 * Defines function as using Microsoft x64 calling convention.
 *
 * This can be used to define prototypes that allow modern compilers to
 * generate code that calls MS ABI functions directly, without needing
 * to jump through the assembly thunks.
 */
#define __msabi __attribute__((__ms_abi__))
#endif

/*
 * Returns true if header should provide MS-ABI overrides.
 */
#ifndef ShouldUseMsabiAttribute
#if defined(__msabi) && defined(NDEBUG) && !defined(__PG__) && !defined(FTRACE)
#define ShouldUseMsabiAttribute() 1
#else
#define ShouldUseMsabiAttribute() 0
#endif
#endif

#else
#define __msabi
#ifndef ShouldUseMsabiAttribute
#define ShouldUseMsabiAttribute() 0
#endif
#endif /* __x86_64__ */


/*!BEGIN libc/sock/sock.h */

#define COSMOPOLITAN_LIBC_SOCK_SOCK_H_
COSMOPOLITAN_C_START_

#define INET_ADDRSTRLEN 22
#define IFHWADDRLEN     6

libcesque uint16_t htons(uint16_t) pureconst;
libcesque uint16_t ntohs(uint16_t) pureconst;
libcesque uint32_t htonl(uint32_t) pureconst;
libcesque uint32_t ntohl(uint32_t) pureconst;

#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define htons(x) __builtin_bswap16(x)
#define ntohs(x) __builtin_bswap16(x)
#define htonl(x) __builtin_bswap32(x)
#define ntohl(x) __builtin_bswap32(x)
#endif

const char *inet_ntop(int, const void *, char *, uint32_t) libcesque;
int inet_pton(int, const char *, void *) libcesque;
uint32_t inet_addr(const char *) libcesque;
libcesque uint32_t *GetHostIps(void) __wur;

int socket(int, int, int) libcesque;
int listen(int, int) libcesque;
int shutdown(int, int) libcesque;
ssize_t send(int, const void *, size_t, int) libcesque;
ssize_t recv(int, void *, size_t, int) libcesque;
ssize_t sendfile(int, int, int64_t *, size_t) libcesque;
int getsockopt(int, int, int, void *, uint32_t *) libcesque;
int setsockopt(int, int, int, const void *, uint32_t) libcesque;
int socketpair(int, int, int, int[2]) libcesque;
int sockatmark(int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/sockaddr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_SOCKADDR_H_
COSMOPOLITAN_C_START_

struct sockaddr {     /* Linux+NT ABI */
  uint16_t sa_family; /* AF_XXX */
  char sa_data[14];
};

struct in_addr { /* ARPA ABI */
  /* e.g. 127|0<<8|0<<16|1<<24 or inet_pton(AF_INET, "127.0.0.1", &s_addr) */
  uint32_t s_addr;
};

struct sockaddr_in {   /* Linux+NT ABI */
  uint16_t sin_family; /* AF_XXX */
  uint16_t sin_port;   /* htons(XXX) i.e. big endian */
  struct in_addr sin_addr;
  uint8_t sin_zero[8];
};

struct sockaddr_un {
  uint16_t sun_family; /* AF_UNIX */
  char sun_path[108];  /* path */
};

struct sockaddr_storage {
  union {
    uint16_t ss_family;
    intptr_t __ss_align;
    char __ss_storage[128];
  };
};

int inet_aton(const char *, struct in_addr *);
char *inet_ntoa(struct in_addr);
int accept(int, struct sockaddr *, uint32_t *);
int accept4(int, struct sockaddr *, uint32_t *, int);
int bind(int, const struct sockaddr *, uint32_t);
int connect(int, const struct sockaddr *, uint32_t);
int getsockname(int, struct sockaddr *, uint32_t *);
int getpeername(int, struct sockaddr *, uint32_t *);
ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, uint32_t *);
ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
               uint32_t);

COSMOPOLITAN_C_END_
/* ░▓█████████████████████████████████████████████▓▒
   ░█▓░░░░░░░░░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒░
   ░█▓░ ░▒▒▒▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░ ░▓▓▓▒  ▓██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▓▒▒
   ░█▓░       ░▓██▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓██▓▒▒
   ░███████████████████████████████████████████████▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░                                          ▒█▓▒▒
   ░█▓░          ░▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒░             ▒█▓▒▒
   ░█▓░        ░▒░                 ▒█▓░          ▒█▓▒▒
   ░█▓░      ░░░░    ░░░░░░░░      ▒▓▓▓▒░        ▒█▓▒▒
   ░█▓░    ░░░░  ░░░░░▒▒▓███▓░░░░░░░░▒▓▓▓▓▒      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒████▓░░░░░░░░░░▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒  ░░░░░░░▒▒▓▓▓▓▓░░░░░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▒▒▒░░░░░ ░▒▒▒▒░░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓      ▒█▓▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░▒▒██▓   ░▓█▓▒▒▒▒
   ░█▓░   ░▒▒   ░░▒▓█▓░░░░░░░▒▓██▓░░░░░▒██▓   ░████▓▒░
   ░█▓░     ░░░░░░░░▒▒░░░░░░░░░▒▒░░░▒▒▓▓▒░░    ░░▓███▓▒░
   ░█▓░      ░░░░░░░░░░░░░░░░░░░░░░▒▓▓▓▒░        ▒████▓▒░░░░░░
   ░█▓░        ░░▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░░        ░▓▓▓▓██▒░░░░░░░░
   ░█▓░          ▒█████████████████▒  ▓█▓▒░      ▒█▓ ░█▓      ░▓▓░
   ░█▓░                              ░▓████▒░    ▒█▓▒░  ░░░░░░░  ▓█▓░
   ░█▓░                                ░▓████▒░  ░▒░  ░░░░░░░░░░░  ░█▓
   ░█▓                                    ▒███▓▒▒░  ░░░░░░░░░░░░░░░  ▒▓▓
   ░██████████████████████████████████████▓▒▓█▓░  ░░░░░░░░░░░░░░░░░░ ▒█▓
    ▒▒▒▒▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▒░ ░░░░░░░░░░░░░░░░░░░░▒█▓
         ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▒██▒▒▒░░░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░██▒▒▒▒▒░░░░░░░░░░░░░░░░░░░▒█▓
                                          ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░░░░░░▒▓█▓
                                            ░▓▓▓▒▒▒▒▒▒░░░░░░░░░░░▒▒▒▒▓▓▒
                                              ░██▓▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒  ░█▓
                                                 ▒█▓▒▒▒▒▒▒▒▒▒▒▒██▓▒░ ░█▓
                                                   ▒█████████████▓▒▒░  ░██▒
╔────────────────────────────────────────────────────────────────▀▀▀▀───▀▀▀▀─│─╗
│ cosmopolitan § new technology » winsock                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtWsaFlagOverlapped      0x01
#define kNtWsaFlagNoHandleInherit 0x80

#define kNtCompEqual   0
#define kNtCompNotless 1

#define kNtTfDisconnect       0x01
#define kNtTfReuseSocket      0x02
#define kNtTfWriteBehind      0x04
#define kNtTfUseDefaultWorker 0x00
#define kNtTfUseSystemThread  0x10
#define kNtTfUseKernelApc     0x20

#define kNtSoConnectTime          0x700C
#define kNtSoUpdateAcceptContext  0x700B
#define kNtSoUpdateConnectContext 0x7010

#define kNtNspNotifyImmediately 0
#define kNtNspNotifyHwnd        1
#define kNtNspNotifyEvent       2
#define kNtNspNotifyPort        3
#define kNtNspNotifyApc         4

COSMOPOLITAN_C_START_

struct NtMsgHdr {
  struct sockaddr *name;
  int32_t namelen;
  struct NtIovec *lpBuffers;
  uint32_t dwBufferCount;
  struct NtIovec Control;
  uint32_t dwFlags;
};

struct NtWsaData {
  uint16_t wVersion;
  uint16_t wHighVersion;
  uint16_t iMaxSockets;
  uint16_t iMaxUdpDg;
  char *lpVendorInfo;
  char szDescription[257];
  char szSystemStatus[129];
};

struct NtSocketAddress {
  struct sockaddr *lpSockaddr;
  int32_t iSockaddrLength;
};

struct NtSocketAddressList {
  int32_t iAddressCount;
  struct NtSocketAddress Address[1];
};

struct NtAddrInfoEx {  /* win8+ */
  int32_t ai_flags;    /* AI_PASSIVE, AI_CANONNAME, AI_NUMERICHOST */
  int32_t ai_family;   /* PF_XXX */
  int32_t ai_socktype; /* SOCK_XXX */
  int32_t ai_protocol;
  uint64_t ai_addrlen;
  char16_t *ai_canonname;
  struct sockaddr *ai_addr;
  void *ai_blob;
  uint64_t ai_bloblen;
  struct NtGuid *ai_provider;
  struct NtAddrInfoEx *ai_next;
  int32_t ai_version;          /* v2 */
  char16_t *ai_fqdn;           /* v2 */
  int32_t ai_interfaceindex;   /* v3 */
  int64_t ai_resolutionhandle; /* v4 */
};

struct NtWsaProtocolChain {
  int32_t ChainLen;
  uint32_t ChainEntries[7];
};

struct NtWsaProtocolInfo {
  uint32_t dwServiceFlags1;
  uint32_t dwServiceFlags2;
  uint32_t dwServiceFlags3;
  uint32_t dwServiceFlags4;
  uint32_t dwProviderFlags;
  struct NtGuid ProviderId;
  uint32_t dwCatalogEntryId;
  struct NtWsaProtocolChain ProtocolChain;
  int32_t iVersion;
  int32_t iAddressFamily;
  int32_t iMaxSockAddr;
  int32_t iMinSockAddr;
  int32_t iSocketType;
  int32_t iProtocol;
  int32_t iProtocolMaxOffset;
  int32_t iNetworkByteOrder;
  int32_t iSecurityScheme;
  uint32_t dwMessageSize;
  uint32_t dwProviderReserved;
  char16_t szProtocol[256];
};

struct NtFlowSpec {
  uint32_t TokenRate;          /* bytes/sec */
  uint32_t TokenBucketSize;    /* bytes */
  uint32_t PeakBandwidth;      /* bytes/sec */
  uint32_t Latency;            /* µs */
  uint32_t DelayVariation;     /* µs */
  uint32_t ServiceType;        /* kNtServicetypeXxx */
  uint32_t MaxSduSize;         /* bytes */
  uint32_t MinimumPolicedSize; /* bytes */
};

struct NtQos {
  struct NtFlowSpec SendingFlowspec;
  struct NtFlowSpec ReceivingFlowspec;
  struct NtIovec ProviderSpecific;
};

struct NtWsaVersion {
  uint32_t dwVersion;
  int ecHow;
};

struct NtAfProtocols {
  int32_t iAddressFamily;
  int32_t iProtocol;
};

struct NtBlob {
  uint32_t cbSize;
  uint8_t pBlobData;
};

struct NtCsAddrInfo {
  struct NtSocketAddress LocalAddr;
  struct NtSocketAddress RemoteAddr;
  int32_t iSocketType;
  int32_t iProtocol;
};

struct NtWsaQuerySet {
  uint32_t dwSize; /* of this */
  char16_t *lpszServiceInstanceName;
  struct NtGuid *lpServiceClassId;
  struct NtWsaVersion *lpVersion;
  char16_t *lpszComment;
  uint32_t dwNameSpace;
  struct NtGuid *lpNSProviderId;
  char16_t *lpszContext;
  uint32_t dwNumberOfProtocols;
  struct NtAfProtocols *lpafpProtocols /*[dwNumberOfProtocols]*/;
  char16_t *lpszQueryString;
  uint32_t dwNumberOfCsAddrs;
  struct NtCsAddrInfo *lpcsaBuffer /*[dwNumberOfCsAddrs]*/;
  uint32_t dwOutputFlags;
  struct NtBlob *lpBlob;
};

struct NtWsaNamespaceInfoEx {
  struct NtGuid NSProviderId;
  uint32_t dwNameSpace;
  bool32 fActive;
  uint32_t dwVersion;
  char16_t *lpszIdentifier;
  struct NtBlob *ProviderSpecific;
};

struct NtWsansClassInfo {
  char16_t *lpszName;
  uint32_t dwNameSpace;
  uint32_t dwValueType;
  uint32_t dwValueSize;
  void *lpValue;
};

struct NtWsaServiceClassInfo {
  struct NtGuid *lpServiceClassId;
  char16_t *lpszServiceClassName;
  uint32_t dwCount;
  struct NtWsansClassInfo *lpClassInfos;
};

struct NtWsaNetworkEvents {
  int32_t lNetworkEvents;
  int32_t iErrorCode[10];
};

struct NtTransmitFileBuffers {
  void *Head;
  uint32_t HeadLength;
  void *Tail;
  uint32_t TailLength;
};

typedef int (*NtConditionProc)(
    const struct NtIovec *lpCallerId, const struct NtIovec *lpCallerData,
    struct NtQos *inout_lpSQOS, struct NtQos *inout_lpGQOS,
    const struct NtIovec *lpCalleeId, const struct NtIovec *lpCalleeData,
    uint32_t *out_group, const uint32_t *dwCallbackData);

typedef void (*NtWsaOverlappedCompletionRoutine)(
    uint32_t dwError, uint32_t cbTransferred,
    const struct NtOverlapped *lpOverlapped, uint32_t dwFlags);

struct NtWsaCompletion {
  int Type;
  union {
    struct {
      int64_t hWnd;
      uint32_t uMsg;
      uintptr_t context;
    } WindowMessage;
    struct {
      struct NtOverlapped *lpOverlapped;
    } Event;
    struct {
      struct NtOverlapped *lpOverlapped;
      NtWsaOverlappedCompletionRoutine lpfnCompletionProc;
    } Apc;
    struct {
      struct NtOverlapped *lpOverlapped;
      int64_t hPort;
      uint32_t Key;
    } Port;
  } Parameters;
};

struct NtInterfaceInfo {
  uint64_t iiFlags;
  struct sockaddr_in iiAddress;
  struct sockaddr_in iiBroadcastAddress;
  struct sockaddr_in iiNetmask;
};

/**
 * Winsock2 prototypes.
 *
 * @note Some of the functions exported by WS2_32.DLL, e.g. bind(),
 *       overlap with the names used by System V. Prototypes for these
 *       functions are declared within their respective wrappers.
 */

int32_t WSAStartup(uint16_t wVersionRequested, struct NtWsaData *lpWSAData)
    paramsnonnull();

int WSACleanup(void);
int WSAGetLastError(void) nosideeffect;
void WSASetLastError(int);

int64_t __sys_socket_nt(int, int, int);
int __sys_bind_nt(uint64_t, const void *, int);
int __sys_closesocket_nt(uint64_t);
int __sys_getpeername_nt(uint64_t, void *, uint32_t *);
int __sys_getsockname_nt(uint64_t, void *, uint32_t *);
int __sys_getsockopt_nt(uint64_t, int, int, void *, uint32_t *);
int __sys_ioctlsocket_nt(uint64_t, int32_t, uint32_t *);
int __sys_listen_nt(uint64_t, int);
int __sys_setsockopt_nt(uint64_t, int, int, const void *, int);
int __sys_shutdown_nt(uint64_t, int);
int __sys_select_nt(int, struct NtFdSet *, struct NtFdSet *, struct NtFdSet *,
                    struct NtTimeval *);

uint64_t WSASocket(int af, int type, int protocol,
                   const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                   const uint32_t opt_group, uint32_t dwFlags) __wur;

int WSAConnect(uint64_t s, const struct sockaddr *name, const int namelen,
               const struct NtIovec *opt_lpCallerData,
               struct NtIovec *opt_out_lpCalleeData,
               const struct NtQos *opt_lpSQOS, const struct NtQos *opt_lpGQOS)
    paramsnonnull((2));

bool32 WSAConnectByName(uint64_t s, const char16_t *nodename,
                        const char16_t *servicename,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2, 3));

bool32 WSAConnectByList(uint64_t s,
                        const struct NtSocketAddressList *SocketAddress,
                        uint32_t *opt_inout_LocalAddressLength,
                        struct sockaddr *out_LocalAddress,
                        uint32_t *opt_inout_RemoteAddressLength,
                        struct sockaddr *out_RemoteAddress,
                        const struct NtTimeval *opt_timeout,
                        struct NtOverlapped *__Reserved) paramsnonnull((2));

int64_t WSAAccept(uint64_t s, struct sockaddr *out_addr,
                  int32_t *opt_inout_addrlen,
                  const NtConditionProc opt_lpfnCondition,
                  const uint32_t *opt_dwCallbackData) paramsnonnull((2)) __wur;

int WSASend(uint64_t s, const struct NtIovec *lpBuffers, uint32_t dwBufferCount,
            uint32_t *opt_out_lpNumberOfBytesSent, uint32_t dwFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendMsg(int64_t Handle, const struct NtMsgHdr *lpMsg, uint32_t dwFlags,
               uint32_t *opt_out_lpNumberOfBytesSent,
               struct NtOverlapped *opt_inout_lpOverlapped,
               const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSASendTo(uint64_t s, const struct NtIovec *lpBuffers,
              uint32_t dwBufferCount,
              uint32_t *opt_out_lpNumberOfBytesSent /* opt if !overlapped */,
              uint32_t dwFlags, const void *opt_tosockaddr,
              int32_t tosockaddrlen,
              struct NtOverlapped *opt_inout_lpOverlapped,
              const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2));

int WSAPoll(struct sys_pollfd_nt *inout_fdArray, uint32_t nfds,
            signed timeout_ms) paramsnonnull();

int WSARecv(uint64_t s, const struct NtIovec *inout_lpBuffers,
            uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
            uint32_t *inout_lpFlags,
            struct NtOverlapped *opt_inout_lpOverlapped,
            const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvFrom(uint64_t s, const struct NtIovec *inout_lpBuffers,
                uint32_t dwBufferCount, uint32_t *opt_out_lpNumberOfBytesRecvd,
                uint32_t *inout_lpFlags, void *out_fromsockaddr,
                uint32_t *opt_inout_fromsockaddrlen,
                struct NtOverlapped *opt_inout_lpOverlapped,
                const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((2, 5));

int WSARecvDisconnect(uint64_t s, struct NtIovec *out_InboundDisconnectData);
int WSASendDisconnect(int64_t s, struct NtIovec *opt_OutboundDisconnectData);

int WSADuplicateSocket(uint64_t s, uint32_t dwProcessId,
                       struct NtWsaProtocolInfo *out_lpProtocolInfo)
    paramsnonnull((3));

int WSAIoctl(uint64_t s, uint32_t dwIoControlCode, const void *lpvInBuffer,
             uint32_t cbInBuffer, void *out_lpvOutBuffer, uint32_t cbOutBuffer,
             uint32_t *out_lpcbBytesReturned,
             struct NtOverlapped *opt_inout_lpOverlapped,
             const NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((5, 7));

int WSANSPIoctl(int64_t hLookup, uint32_t dwControlCode,
                const void *lpvInBuffer, uint32_t cbInBuffer,
                void *out_lpvOutBuffer, uint32_t cbOutBuffer,
                uint32_t *out_lpcbBytesReturned,
                const struct NtWsaCompletion *opt_lpCompletion)
    paramsnonnull((3, 5, 7));

int64_t WSACreateEvent(void) __wur;
bool32 WSACloseEvent(const int64_t hEvent);
bool32 WSAResetEvent(const int64_t hEvent);
bool32 WSASetEvent(const int64_t hEvent);

int WSAEventSelect(uint64_t s, const int64_t opt_hEventObject,
                   long lNetworkEvents);

uint32_t WSAWaitForMultipleEvents(uint32_t cEvents, const int64_t *lphEvents,
                                  bool32 fWaitAll, uint32_t dwTimeout_ms,
                                  bool32 fAlertable) paramsnonnull();

int WSAEnumNetworkEvents(uint64_t s, const int64_t hEventObject,
                         struct NtWsaNetworkEvents *out_lpNetworkEvents)
    paramsnonnull();

bool32 WSAGetOverlappedResult(uint64_t s,
                              const struct NtOverlapped *lpOverlapped,
                              uint32_t *out_lpcbTransfer, bool32 fWait,
                              uint32_t *out_lpdwFlags) paramsnonnull();

int WSAEnumProtocols(const int32_t *opt_lpiProtocols,
                     struct NtWsaProtocolInfo *out_lpProtocolBuffer,
                     uint32_t *inout_lpdwBufferLength) paramsnonnull();

bool32 WSAGetQOSByName(uint64_t s, const struct NtIovec *lpQOSName,
                       struct NtQos *out_lpQOS) paramsnonnull();

uint64_t WSAJoinLeaf(uint64_t s, const struct sockaddr *name, const int namelen,
                     const struct NtIovec *opt_lpCallerData,
                     struct NtIovec *opt_out_lpCalleeData,
                     const struct NtQos *opt_lpSQOS,
                     const struct NtQos *opt_lpGQOS, uint32_t dwFlags)
    paramsnonnull((2, 4));

int WSALookupServiceBegin(const struct NtWsaQuerySet *lpqsRestrictions,
                          uint32_t dwControlFlags, int64_t *out_lphLookup)
    paramsnonnull();

int WSALookupServiceNext(const int64_t hLookup, uint32_t dwControlFlags,
                         uint32_t *inout_lpdwBufferLength,
                         struct NtWsaQuerySet *out_lpqsResults) paramsnonnull();

int WSALookupServiceEnd(int64_t hLookup);

int WSAAddressToString(const struct sockaddr *lpsaAddress,
                       uint32_t dwAddressLength,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       char16_t *out_lpszAddressString,
                       uint32_t *inout_lpdwAddressStringLength)
    paramsnonnull((1, 4, 5));

int WSAStringToAddress(const char16_t *AddressString, int AddressFamily,
                       const struct NtWsaProtocolInfo *opt_lpProtocolInfo,
                       struct sockaddr *out_lpAddress,
                       int *inout_lpAddressLength) paramsnonnull((1, 3, 4));

int WSAEnumNameSpaceProvidersEx(uint32_t *inout_lpdwBufferLength,
                                struct NtWsaNamespaceInfoEx *out_lpnspBuffer)
    paramsnonnull();

int WSAProviderConfigChange(
    int64_t *inout_lpNotificationHandle,
    struct NtOverlapped *opt_inout_lpOverlapped,
    NtWsaOverlappedCompletionRoutine opt_lpCompletionRoutine)
    paramsnonnull((1));

int WSAInstallServiceClass(
    const struct NtWsaServiceClassInfo *lpServiceClassInfo) paramsnonnull();

int WSARemoveServiceClass(const struct NtGuid *lpServiceClassId)
    paramsnonnull();

int WSAGetServiceClassInfo(const struct NtGuid *lpProviderId,
                           const struct NtGuid *lpServiceClassId,
                           uint32_t *inout_lpdwBufSize,
                           struct NtWsaServiceClassInfo *out_lpServiceClassInfo)
    paramsnonnull((1, 2, 3));

int WSASetService(const struct NtWsaQuerySet *lpqsRegInfo, int essoperation,
                  uint32_t dwControlFlags) paramsnonnull();

int /* success==0 */ WSAGetServiceClassNameByClassId(
    const struct NtGuid *lpServiceClassId, char16_t *out_lpszServiceClassName,
    uint32_t *inout_lpdwBufferLength) paramsnonnull();

void GetAcceptExSockaddrs(
    const void *lpOutputBuffer /*[recvsize+addrsize+addrlen]*/,
    uint32_t dwReceiveDataLength, uint32_t dwLocalAddressLength,
    uint32_t dwRemoteAddressLength,
    struct sockaddr **out_LocalSockaddr /*[*LocalSockaddrLength]*/,
    int *out_LocalSockaddrLength,
    struct sockaddr **out_RemoteSockaddr /*[*RemoteSockaddrLength]*/,
    int *out_RemoteSockaddrLength);

bool32 DisconnectEx(int64_t s, struct NtOverlapped *inout_opt_lpOverlapped,
                    uint32_t dwFlags, uint32_t dwReserved);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/winsock.inc */

extern typeof(WSAGetLastError) *const __imp_WSAGetLastError __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_

/* Constants ----------------------------------------------------------- */

#define kNtMaxAdapterAddressLength  8
#define kNtMaxDnsSuffixStringLength 256
#define kNtMaxDhcpv6DuidLength      130

/* Values for the 'Flags' parameter of GetAdaptersAddresses */
#define kNtGaaFlagSkipUnicast               0x0001
#define kNtGaaFlagSkipAnycast               0x0002
#define kNtGaaFlagSkipMulticast             0x0004
#define kNtGaaFlagSkipDnsServer             0x0008
#define kNtGaaFlagIncludePrefix             0x0010
#define kNtGaaFlagSkipFriendlyName          0x0020
#define kNtGaaFlagIncludeWinsInfo           0x0040
#define kNtGaaFlagIncludeGateways           0x0080
#define kNtGaaFlagIncludeAllInterfaces      0x0100
#define kNtGaaFlagIncludeAllCompartments    0x0200
#define kNtGaaFlagIncludeTunnelBindingorder 0x0400
#define kNtGaaFlagSkipDnsInfo               0x0800

/* Values for the IfType parameter
 * See:
 * https://docs.microsoft.com/en-us/windows/win32/api/iptypes/ns-iptypes-ip_adapter_addresses_lh
 */
#define kNtIfTypeOther             1
#define kNtIfTypeEthernetCsmacd    6
#define kNtIfTypeIso88025Tokenring 9
#define kNtIfTypePpp               23
#define kNtIfTypeSoftwareLoopback  24
#define kNtIfTypeAtm               37
#define kNtIfTypeIeee80211         71 /* wifi */
#define kNtIfTypeTunnel            131
#define kNtIfTypeIeee1394          144 /* firewire */

#define kNtIpAdapterDdnsEnabled             0x0001
#define kNtIpAdapterRegisterAdapterSuffix   0x0002
#define kNtIpAdapterDhcpv4Enabled           0x0004
#define kNtIpAdapterReceiveOnly             0x0008
#define kNtIpAdapterNoMulticast             0x0010
#define kNtIpAdapterIpv6OtherStatefulConfig 0x0020
#define kNtIpAdapterNetbiosOverTcpipEnabled 0x0040
#define kNtIpAdapterIpv4Enabled             0x0080
#define kNtIpAdapterIpv6Enabled             0x0100
#define kNtIpAdapterIpv6Managed             0x0200

#define kNtIpPrefixOriginOther               0
#define kNtIpPrefixOriginManual              1
#define kNtIpPrefixOriginWellKnown           2
#define kNtIpPrefixOriginDhcp                3
#define kNtIpPrefixOriginRouterAdvertisement 4
#define kNtIpPrefixOriginUnchanged           16

#define kNtIpSuffixOriginOther            0
#define kNtIpSuffixOriginManual           1
#define kNtIpSuffixOriginWellKnown        2
#define kNtIpSuffixOriginDhcp             3
#define kNtIpSuffixOriginLinkLayerAddress 4
#define kNtIpSuffixOriginRandom           5
#define kNtIpSuffixOriginUnchanged        16

#define kNtIpDadStateInvalid    0
#define kNtIpDadStateTentative  1
#define kNtIpDadStateDuplicate  2
#define kNtIpDadStateDeprecated 3
#define kNtIpDadStatePreferred  4

#define kNtIfOperStatusUp             1
#define kNtIfOperStatusDown           2
#define kNtIfOperStatusTesting        3
#define kNtIfOperStatusUnknown        4
#define kNtIfOperStatusDormant        5
#define kNtIfOperStatusNotPresent     6
#define kNtIfOperStatusLowerLayerDown 7

#define kNtNetIfConnectionDedicated 1
#define kNtNetIfConnectionPassive   2
#define kNtNetIfConnectionDemand    3
#define kNtNetIfConnectionMaximum   4

#define kNtTunnelTypeNone    0
#define kNtTunnelTypeOther   1
#define kNtTunnelTypeDirect  2
#define kNtTunnelType6to4    11
#define kNtTunnelTypeIsatap  13
#define kNtTunnelTypeTeredo  14
#define kNtTunnelTypeIphttps 15

COSMOPOLITAN_C_START_

/* Inner Types --------------------------------------------------------- */

struct NtIpAdapterUnicastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterUnicastAddress *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixOrigin; /* kNtIpPrefixOrigin... */
  uint32_t SuffixOrigin; /* kNtIpSuffixOrigin... */
  uint32_t DadState;     /* kNtIpDadState... */
  uint32_t ValidLifetime;
  uint32_t PreferredLifetime;
  uint32_t LeaseLifetime;
  uint8_t OnLinkPrefixLength;
};

struct NtIpAdapterAnycastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterAnycastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterMulticastAddress {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterMulticastAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterDnsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterPrefix {
  uint32_t Length;
  uint32_t Flags;
  struct NtIpAdapterPrefix *Next;
  struct NtSocketAddress Address;
  uint32_t PrefixLength;
};

struct NtIpAdapterWinsServerAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterWinsServerAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterGatewayAddress {
  uint32_t Length;
  uint32_t Reserved;
  struct NtIpAdapterGatewayAddress *Next;
  struct NtSocketAddress Address;
};

struct NtIpAdapterDnsSuffix {
  struct NtIpAdapterDnsSuffix *Next;
  uint16_t String[kNtMaxDnsSuffixStringLength];
};

/* Top level ----------------------------------------------------------- */

struct NtIpAdapterAddresses {
  uint32_t Length;
  uint32_t IfIndex;
  struct NtIpAdapterAddresses *Next;
  char *AdapterName;
  struct NtIpAdapterUnicastAddress *FirstUnicastAddress;
  struct NtIpAdapterAnycastAddress *FirstAnycastAddress;
  struct NtIpAdapterMulticastAddress *FirstMulticastAddress;
  struct NtIpAdapterDnsServerAddress *FirstDnsServerAddress;
  uint16_t *DnsSuffix;
  uint16_t *Description;
  uint16_t *FriendlyName;
  uint8_t PhysicalAddress[kNtMaxAdapterAddressLength];
  uint32_t PhysicalAddressLength;
  uint32_t Flags; /* kNtIpAdapter... */
  uint32_t Mtu;
  uint32_t IfType;     /* kNtIfType... */
  uint32_t OperStatus; /* kNtIfOperStatus... */
  uint32_t Ipv6IfIndex;
  uint32_t ZoneIndices[16];
  struct NtIpAdapterPrefix *FirstPrefix;
  uint64_t TransmitLinkSpeed;
  uint64_t ReceiveLinkSpeed;
  struct NtIpAdapterWinsServerAddress *FirstWinsServerAddress;
  struct NtIpAdapterGatewayAddress *FirstGatewayAddress;
  uint32_t Ipv4Metric;
  uint32_t Ipv6Metric;
  uint64_t Luid; /* reserved(24bits),NetLuidIndex(24b),IfType(16b) */
  struct NtSocketAddress Dhcpv4Server;
  uint32_t CompartmentId;
  struct NtGuid NetworkGuid;
  uint32_t ConnectionType; /* kNtNetIfConnection... */
  uint32_t TunnelType;     /* kNtTunnelType... */
  struct NtSocketAddress Dhcpv6Server;
  uint8_t Dhcpv6ClientDuid[kNtMaxDhcpv6DuidLength];
  uint32_t Dhcpv6ClientDuidLength;
  uint32_t Dhcpv6Iaid;
  struct NtIpAdapterDnsSuffix *FirstDnsSuffix;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/kernelusertimes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_KERNELUSERTIMES_H_

struct NtKernelUserTimes {
  uint64_t CreateFileTime;
  uint64_t ExitFileTime;
  int64_t KernelTime;
  int64_t UserTime;
};



/*!BEGIN libc/nt/struct/ldr.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDR_H_

struct NtLdr {
  uint32_t SizeOfThis;                       /* msdn:reserved */
  uint32_t IsInitialized;                    /* msdn:reserved */
  void *SsHandle;                            /* msdn:reserved */
  struct NtLinkedList InLoadOrderModuleList; /* msdn:reserved */
  struct NtLinkedList /*∩NtLdrDataTableEntry*/ InMemoryOrderModuleList;
  struct NtLinkedList InInitOrderModuleList; /* msdn:reserved */
};



/*!BEGIN libc/nt/struct/ldrdatatableentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LDRDATATABLEENTRY_H_


/*!BEGIN libc/nt/struct/unicodestring.h */

#define COSMOPOLITAN_LIBC_NT_UNICODE_H_

struct NtUnicodeString {
  uint16_t Length;
  uint16_t MaxLength;
  char16_t *Data;
};


struct NtLdrDataTableEntry {
  struct NtLinkedList InLoadOrderLinks; /* msdn:reserved */
  struct NtLinkedList InMemoryOrderLinks;
  struct NtLinkedList InInitOrderLinks; /* msdn:reserved */
  void *DllBase;
  void *EntryPoint;
  union {
    uint32_t SizeOfImage;
    unsigned char SizeOfImagePadding[__SIZEOF_POINTER__];
  };
  struct NtUnicodeString FullDllName;
  struct NtUnicodeString BaseDllName;
  uint32_t Flags;
  uint16_t Load_Count;
  uint16_t TlsIndex;
  union {
    struct NtLinkedList HashLinks;
    struct {
      void *SectionPointer;
      uint32_t CheckSum;
    };
  };
  union {
    void *LoadedImports;
    uint32_t TimeDateStamp;
  };
  void *EntryPointActivationContext;
  void *PatchInformation;
  struct NtLinkedList ForwarderLinks;
  struct NtLinkedList ServiceTagLinks;
  struct NtLinkedList StaticLinks;
  void *ContextInformation;
  uintptr_t OriginalBase;
  int64_t LoadTime;
};



/*!BEGIN libc/nt/struct/linger.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger_nt {
  uint16_t l_onoff;  /* on/off */
  uint16_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/luid.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUID_H_

struct NtLuid {
  uint32_t LowPart;
  int32_t HighPart;
};



/*!BEGIN libc/nt/struct/luidandattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_LUIDANDATTRIBUTES_H_

struct NtLuidAndAttributes {
  struct NtLuid Luid;
  uint32_t Attributes;
};



/*!BEGIN libc/nt/struct/memextendedparameter.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMEXTENDEDPARAMETER_H_

#define kNtMemExtendedParameterTypeBits 8

#define kNtMemExtendedParameterInvalidType         0
#define kNtMemExtendedParameterAddressRequirements 1
#define kNtMemExtendedParameterNumaNode            2
#define kNtMemExtendedParameterPartitionHandle     3
#define kNtMemExtendedParameterUserPhysicalHandle  4
#define kNtMemExtendedParameterAttributeFlags      5
#define kNtMemExtendedParameterMax                 6

#define kNtMemExtendedParameterGraphics          0x00000001
#define kNtMemExtendedParameterNonpaged          0x00000002
#define kNtMemExtendedParameterZeroPagesOptional 0x00000004
#define kNtMemExtendedParameterNonpagedLarge     0x00000008
#define kNtMemExtendedParameterNonpagedHuge      0x00000010

struct NtMemExtendedParameter {
  struct {
    uint64_t Type : kNtMemExtendedParameterTypeBits;
    uint64_t Reserved : 64 - kNtMemExtendedParameterTypeBits;
  } DUMMYSTRUCTNAME;
  union {
    uint64_t ULong64;
    void *Pointer;
    size_t Size;
    intptr_t Handle;
    unsigned ULong;
  } DUMMYUNIONNAME;
};



/*!BEGIN libc/nt/struct/memorybasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYBASICINFORMATION_H_

struct NtMemoryBasicInformation {
  void *BaseAddress;
  void *AllocationBase;
  uint32_t AllocationProtect;
  uint64_t RegionSize;
  uint32_t State;
  uint32_t Protect;
  uint32_t Type;
};



/*!BEGIN libc/nt/struct/memoryrangeentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYRANGEENTRY_H_

struct NtMemoryRangeEntry {
  void *VirtualAddress;
  size_t NumberOfBytes;
};



/*!BEGIN libc/nt/struct/memorystatusex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MEMORYSTATUSEX_H_

struct NtMemoryStatusEx {
  uint32_t dwLength;
  uint32_t dwMemoryLoad;
  uint64_t ullTotalPhys;
  uint64_t ullAvailPhys;
  uint64_t ullTotalPageFile;
  uint64_t ullAvailPageFile;
  uint64_t ullTotalVirtual;
  uint64_t ullAvailVirtual;
  uint64_t ullAvailExtendedVirtual;
};



/*!BEGIN libc/nt/struct/msg.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_MSG_H_


/*!BEGIN libc/nt/struct/point.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_POINT_H_

struct NtPoint {
  int32_t x;
  int32_t y;
};


struct NtMsg {
  int64_t hwnd;
  uint32_t dwMessage;
  uint64_t wParam;
  int64_t lParam;
  uint32_t dwTime;
  struct NtPoint pt;
};



/*!BEGIN libc/nt/struct/nonpageddebuginfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NONPAGEDDEBUGINFO_H_

struct NtNonPagedDebugInfo {
  uint16_t Signature;
  uint16_t Flags;
  uint32_t Size;
  uint16_t Machine;
  uint16_t Characteristics;
  uint32_t TimeDateStamp;
  uint32_t CheckSum;
  uint32_t SizeOfImage;
  uint64_t ImageBase;
};



/*!BEGIN libc/nt/struct/ntexceptionpointers.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONPOINTERS_H_


/*!BEGIN libc/nt/struct/ntexceptionrecord.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTEXCEPTIONRECORD_H_

#define kNtExceptionMaximumParameters 15
#define kNtExceptionNoncontinuable    1


struct NtExceptionRecord {
  uint32_t ExceptionCode;                    /* kNtException... */
  uint32_t ExceptionFlags;                   /* kNtExceptionNoncontinuable */
  struct NtExceptionRecord *ExceptionRecord; /* nested exceptions */
  void *ExceptionAddress;                    /* %rip */
  uint32_t NumberParameters;                 /* #ExceptionInformation */
  uint64_t ExceptionInformation[kNtExceptionMaximumParameters];
};


struct NtExceptionPointers {
  struct NtExceptionRecord *ExceptionRecord;
  struct NtContext *ContextRecord;
};



/*!BEGIN libc/nt/struct/objectallinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTALLINFORMATION_H_


/*!BEGIN libc/nt/struct/objecttypeinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTTYPEINFORMATION_H_

struct NtObjectTypeInformation {
  struct NtUnicodeString TypeName;
  uint32_t TotalNumberOfObjects;
  uint32_t TotalNumberOfHandles;
  uint32_t TotalPagedPoolUsage;
  uint32_t TotalNonPagedPoolUsage;
  uint32_t TotalNamePoolUsage;
  uint32_t TotalHandleTableUsage;
  uint32_t HighWaterNumberOfObjects;
  uint32_t HighWaterNumberOfHandles;
  uint32_t HighWaterPagedPoolUsage;
  uint32_t HighWaterNonPagedPoolUsage;
  uint32_t HighWaterNamePoolUsage;
  uint32_t HighWaterHandleTableUsage;
  uint32_t InvalidAttributes;
  struct NtGenericMapping GenericMapping;
  uint32_t ValidAccessMask;
  bool32 SecurityRequired;
  bool32 MaintainHandleCount;
  uint32_t PoolType;
  uint32_t DefaultPagedPoolCharge;
  uint32_t DefaultNonPagedPoolCharge;
};


struct NtObjectAllInformation {
  uint32_t NumberOfObjects;
  struct NtObjectTypeInformation ObjectTypeInformation[1];
};



/*!BEGIN libc/nt/struct/objectattributes.h */

#define COSMOPOLITAN_LIBC_NT_I_OBJECTATTRIBUTES_H_


/*!BEGIN libc/nt/struct/rtluserprocessparameters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSPARAMETERS_H_

struct NtRtlUserProcessParameters {
  uint32_t MaximumLength;
  uint32_t Length;
  uint32_t Flags;
  uint32_t DebugFlags;
  int64_t ConsoleHandle;
  uint32_t ConsoleFlags;
  int64_t StdInputHandle;
  int64_t StdOutputHandle;
  int64_t StdErrorHandle;
  struct NtUnicodeString *CurrentDirectoryPath;
  int64_t CurrentDirectoryHandle;
  struct NtUnicodeString *DllPath;
  struct NtUnicodeString *ImagePathName;
  struct NtUnicodeString *CommandLine;
  void *Environment;
  uint32_t StartingPositionLeft;
  uint32_t StartingPositionTop;
  uint32_t Width;
  uint32_t Height;
  uint32_t CharWidth;
  uint32_t CharHeight;
  uint32_t ConsoleTextAttributes;
  uint32_t WindowFlags;
  uint32_t ShowWindowFlags;
  struct NtUnicodeString *WindowTitle;
  struct NtUnicodeString *DesktopName;
  struct NtUnicodeString *ShellInfo;
  struct NtUnicodeString *RuntimeData;
};



/*!BEGIN libc/nt/struct/securityattributes.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYATTRIBUTES_H_


/*!BEGIN libc/nt/struct/securitydescriptor.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECURITYDESCRIPTOR_H_

struct NtSecurityDescriptor {
  uint8_t Revision;
  uint8_t Sbz1;
  uint16_t Control;
  void *Owner;
  void *Group;
  struct NtAcl *Sacl;
  struct NtAcl *Dacl;
};


struct NtSecurityAttributes {
  uint32_t nLength;
  struct NtSecurityDescriptor *lpSecurityDescriptor;
  bool32 bInheritHandle;
};

const char *DescribeNtSecurityAttributes(char[32],
                                         const struct NtSecurityAttributes *);
#define DescribeNtSecurityAttributes(x) \
  DescribeNtSecurityAttributes(alloca(32), x)


struct NtObjectAttributes {
  uint32_t Length;
  int64_t RootDirectory;
  const struct NtUnicodeString *ObjectName;
  uint32_t Attributes; /* OBJ_INHERIT, etc. */
  struct NtSecurityDescriptor *SecurityDescriptor;
  void *SecurityQualityOfService;
};



/*!BEGIN libc/nt/struct/objectbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTBASICINFORMATION_H_

struct NtObjectBasicInformation {
  uint32_t Attributes;
  uint32_t GrantedAccess;
  uint32_t HandleCount;
  uint32_t PointerCount;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t Reserved[3];
  uint32_t NameInformationLength;
  uint32_t TypeInformationLength;
  uint32_t SecurityDescriptorLength;
  int64_t CreateTime;
};



/*!BEGIN libc/nt/struct/objectnameinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OBJECTNAMEINFORMATION_H_

struct NtObjectNameInformation {
  struct NtUnicodeString Name;
};



/*!BEGIN libc/nt/struct/openfilename.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OPENFILENAME_H_

struct NtOpenFilename {
  uint32_t lStructSize;
  int64_t hwndOwner;
  int64_t hInstance;
  const char16_t *lpstrFilter;
  char16_t *lpstrCustomFilter;
  uint32_t nMaxCustFilter;
  uint32_t nFilterIndex;
  char16_t *lpstrFile;
  uint32_t nMaxFile;
  char16_t *lpstrFileTitle;
  uint32_t nMaxFileTitle;
  const char16_t *lpstrInitialDir;
  const char16_t *lpstrTitle;
  uint32_t Flags;
  uint16_t nFileOffset;
  uint16_t nFileExtension;
  const char16_t *lpstrDefExt;
  intptr_t lCustData;
  uint64_t (*lpfnHook)(int64_t, uint32_t, uint64_t, int64_t);
  const char16_t *lpTemplateName;
  void *pvReserved;
  uint32_t dwReserved;
  uint32_t FlagsEx;
};



/*!BEGIN libc/nt/struct/osversioninfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OSVERSIONINFO_H_
COSMOPOLITAN_C_START_

struct NtOsVersionInfo {
  uint32_t dwOSVersionInfoSize;
  uint32_t dwMajorVersion;
  uint32_t dwMinorVersion;
  uint32_t dwBuildNumber;
  uint32_t dwPlatformId;
  char16_t szCSDVersion[128];
  uint16_t wServicePackMajor;
  uint16_t wServicePackMinor;
  uint16_t wSuiteMask;
  uint8_t wProductType;
  uint8_t wReserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/overlappedentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_OVERLAPPEDENTRY_H_
COSMOPOLITAN_C_START_

struct NtOverlappedEntry {
  uint64_t lpCompletionKey;
  struct NtOverlapped *lpOverlapped;
  uint32_t *Internal;
  uint32_t dwNumberOfBytesTransferred;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/paintstruct.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PAINTSTRUCT_H_


/*!BEGIN libc/nt/struct/rect.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RECT_H_

struct NtRect {
  int32_t left;
  int32_t top;
  int32_t right;
  int32_t bottom;
};


struct NtPaintStruct {
  int64_t hdc;
  bool32 fErase;
  struct NtRect rcPaint;
  bool32 fRestore;
  bool32 fIncUpdate;
  uint8_t rgbReserved[32];
};



/*!BEGIN libc/nt/struct/pdhfmtcountervalue.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PDHFMTCOUNTERVALUE_H_
COSMOPOLITAN_C_START_

struct NtPdhFmtCountervalue {
  uint32_t CStatus;
  union {
    int32_t longValue;
    double doubleValue;
    int64_t largeValue;
    const char *AnsiStringValue;
    const char16_t *WideStringValue;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/peb.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PEB_H_

struct NtPeb {
  union {
    struct {
      unsigned char InheritedAddressSpace;
      unsigned char ReadImageFileExecOptions;
      unsigned char BeingDebugged;
      unsigned char __wut1;
    };
    uint64_t __wut2;
  };
  uint64_t Mutant;
  uint64_t ImageBaseAddress;
  struct NtLdr *Ldr;
  uint64_t ProcessParameters;
  uint64_t SubSystemData;
  uint64_t ProcessHeap;
  uint64_t FastPebLock;
  uint64_t __wut3;
  uint64_t __wut4;
  uint64_t __wut5;
  union {
    uint64_t KernelCallbackTable;
    uint64_t UserSharedInfoPtr;
  };
  uint32_t SystemReserved;
  uint32_t __wut6;
  uint64_t __wut7;
  uint64_t TlsExpansionCounter;
  uint64_t TlsBitmap;
  uint32_t TlsBitmapBits[2];
  uint64_t ReadOnlySharedMemoryBase;
  uint64_t __wut8;
  uint64_t ReadOnlyStaticServerData;
  uint64_t AnsiCodePageData;
  uint64_t OemCodePageData;
  uint64_t UnicodeCaseTableData;
  uint32_t NumberOfProcessors;
#ifdef __x86_64__
  uint32_t NtGlobalFlag;
#else
  uint64_t NtGlobalFlag;
#endif
  int64_t CriticalSectionTimeout;
  uint64_t HeapSegmentReserve;
  uint64_t HeapSegmentCommit;
  uint64_t HeapDeCommitTotalFreeThreshold;
  uint64_t HeapDeCommitFreeBlockThreshold;
  uint32_t NumberOfHeaps;
  uint32_t MaximumNumberOfHeaps;
  uint64_t ProcessHeaps;
  uint64_t GdiSharedHandleTable;
  uint64_t ProcessStarterHelper;
  uint64_t GdiDCAttributeList;
  uint64_t LoaderLock;
  union {
    struct {
      uint32_t OSMajorVersion;
      uint32_t OSMinorVersion;
    };
    uint64_t OSVersion;
  };
  uint16_t OSBuildNumber;
  uint16_t OSCSDVersion;
  uint32_t OSPlatformId;
  uint32_t ImageSubsystem;
  uint32_t ImageSubsystemMajorVersion;
  uint64_t ImageSubsystemMinorVersion;
  union {
    uint64_t ImageProcessAffinityMask;
    uint64_t ActiveProcessAffinityMask;
  };
  uint64_t GdiHandleBuffer[38 - __SIZEOF_POINTER__];
  uint64_t PostProcessInitRoutine;
  uint64_t TlsExpansionBitmap;
  uint32_t TlsExpansionBitmapBits[32];
  uint64_t SessionId;
  uint64_t AppCompatFlags;
  uint64_t AppCompatFlagsUser;
  uint64_t pShimData;
  uint64_t AppCompatInfo;
  struct NtUnicodeString CSDVersion;
  uint64_t ActivationContextData;
  uint64_t ProcessAssemblyStorageMap;
  uint64_t SystemDefaultActivationContextData;
  uint64_t SystemAssemblyStorageMap;
  uint64_t MinimumStackCommit;
};



/*!BEGIN libc/nt/struct/privilegeset.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PRIVILEGESET_H_

struct NtPrivilegeSet {
  uint32_t PrivilegeCount;
  uint32_t Control;
  struct NtLuidAndAttributes Privilege[1];
};



/*!BEGIN libc/nt/struct/processbasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSBASICINFORMATION_H_

struct NtProcessBasicInformation {
  int32_t ExitStatus;
  struct NtPeb *PebBaseAddress;
  uint32_t *AffinityMask;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
};



/*!BEGIN libc/nt/struct/processentry32.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSENTRY32_H_

struct NtProcessEntry32 {
  uint32_t dwSize;
  uint32_t cntUsage; /* unused */
  uint32_t th32ProcessID;
  uint64_t th32DefaultHeapID; /* unused */
  uint32_t th32ModuleID;      /* unused */
  uint32_t cntThreads;
  uint32_t th32ParentProcessID;
  int32_t cPriClassBase;
  uint32_t dwFlags; /* unused */
  char16_t szExeFile[260];
};



/*!BEGIN libc/nt/struct/processinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSINFORMATION_H_

struct NtProcessInformation {
  int64_t hProcess;
  int64_t hThread;
  uint32_t dwProcessId;
  uint32_t dwThreadId;
};



/*!BEGIN libc/nt/struct/processmemorycounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSMEMORYCOUNTERS_H_
COSMOPOLITAN_C_START_

struct NtProcessMemoryCountersEx {
  uint32_t cb; /* count bytes */
  uint32_t PageFaultCount;
  uint64_t PeakWorkingSetSize;
  uint64_t WorkingSetSize;
  uint64_t QuotaPeakPagedPoolUsage;
  uint64_t QuotaPagedPoolUsage;
  uint64_t QuotaPeakNonPagedPoolUsage;
  uint64_t QuotaNonPagedPoolUsage;
  uint64_t PagefileUsage;
  uint64_t PeakPagefileUsage;
  uint64_t PrivateUsage;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/processornumber.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSORNUMBER_H_
COSMOPOLITAN_C_START_

struct NtProcessorNumber {
  uint16_t Group;
  uint8_t Number;
  uint8_t Reserved;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/procthreadattributelist.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCTHREADATTRIBUTELIST_H_

struct NtProcThreadAttributeList;



/*!BEGIN libc/nt/struct/reparsedatabuffer.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_REPARSEDATABUFFER_H_
COSMOPOLITAN_C_START_

struct NtReparseDataBuffer {
  uint32_t ReparseTag;
  uint16_t ReparseDataLength;
  uint16_t Reserved;
  union {
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      uint32_t Flags;
      char16_t PathBuffer[1];
    } SymbolicLinkReparseBuffer;
    struct {
      uint16_t SubstituteNameOffset;
      uint16_t SubstituteNameLength;
      uint16_t PrintNameOffset;
      uint16_t PrintNameLength;
      char16_t PathBuffer[1];
    } MountPointReparseBuffer;
    struct {
      uint8_t DataBuffer[1];
    } GenericReparseBuffer;
  };
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/rtluserprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_RTLUSERPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/sectionimageinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SECTIONIMAGEINFORMATION_H_

struct NtSectionImageInformation {
  void *EntryPoint;
  uint32_t Unknown1;
  uint32_t StackReserve;
  uint32_t StackCommit;
  uint32_t Subsystem;
  uint16_t MinorSubsystemVersion;
  uint16_t MajorSubsystemVersion;
  uint32_t Unknown2;
  uint32_t Characteristics;
  uint16_t ImageNumber;
  uint32_t IsExecutable;
  uint8_t __wut1;
  uint32_t __wut2[3];
};


struct NtRtlUserProcessInformation {
  uint32_t SizeOfThis;
  int64_t ProcessHandle;
  int64_t ThreadHandle;
  struct NtClientId ClientId;
  struct NtSectionImageInformation ImageInformation;
};



/*!BEGIN libc/nt/struct/size.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SIZE_H_
COSMOPOLITAN_C_START_

struct NtSize {
  int32_t cx;
  int32_t cy;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFO_H_

struct NtStartupInfo {
  uint32_t cb /* = sizeof(struct NtStartupInfo) */;
  uint16_t *lpReserved;
  char16_t *lpDesktop;
  char16_t *lpTitle; /* title of *new* console window only */
  uint32_t dwX;      /* position of window on screen */
  uint32_t dwY;
  uint32_t dwXSize;
  uint32_t dwYSize;
  uint32_t dwXCountChars; /* used to dimension the dos terminal */
  uint32_t dwYCountChars;
  uint32_t dwFillAttribute;
  uint32_t dwFlags;
  uint16_t wShowWindow;
  uint16_t cbReserved2;
  uint8_t *lpReserved2;
  union {
    struct {
      int64_t hStdInput;
      int64_t hStdOutput;
      int64_t hStdError;
    };
    int64_t stdiofds[3];
  };
};



/*!BEGIN libc/nt/struct/startupinfoex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_STARTUPINFOEX_H_

struct NtStartupInfoEx {
  struct NtStartupInfo StartupInfo;
  struct NtProcThreadAttributeList *lpAttributeList;
};



/*!BEGIN libc/nt/struct/systembasicinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMBASICINFORMATION_H_

struct NtSystemBasicInformation {
  unsigned char Reserved1[4];
  uint32_t MaximumIncrement;
  uint32_t PhysicalPageSize;
  uint32_t NumberOfPhysicalPages;
  uint32_t LowestPhysicalPage;
  uint32_t HighestPhysicalPage;
  uint32_t AllocationGranularity;
  uint32_t LowestUserAddress;
  uint32_t HighestUserAddress;
  uint32_t ActiveProcessors;
  char NumberOfProcessors;
};



/*!BEGIN libc/nt/struct/systemexceptioninformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMEXCEPTIONINFORMATION_H_

struct NtSystemExceptionInformation {
  unsigned char Reserved1[16];
};



/*!BEGIN libc/nt/struct/systemhandleentry.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEENTRY_H_

struct NtSystemHandleEntry {
  uint32_t OwnerPid;
  unsigned char ObjectType;
  unsigned char HandleFlags;
  unsigned short HandleValue;
  void *ObjectPointer;
  uint32_t AccessMask;
};



/*!BEGIN libc/nt/struct/systemhandleinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMHANDLEINFORMATION_H_

struct NtSystemHandleInformation {
  uint32_t Count;
  struct NtSystemHandleEntry Handle[1];
};



/*!BEGIN libc/nt/struct/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINFO_H_

struct NtSystemInfo {
  union {
    uint32_t dwOemId;
    struct {
      uint16_t wProcessorArchitecture;
      uint16_t wReserved;
    };
  };
  uint32_t dwPageSize;
  void *lpMinimumApplicationAddress;
  void *lpMaximumApplicationAddress;
  uintptr_t dwActiveProcessorMask;
  uint32_t dwNumberOfProcessors;
  uint32_t dwProcessorType;
  uint32_t dwAllocationGranularity;
  uint16_t wProcessorLevel;
  uint16_t wProcessorRevision;
};



/*!BEGIN libc/nt/struct/systeminterruptinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMINTERRUPTINFORMATION_H_

struct NtSystemInterruptInformation {
  unsigned char Reserved1[24];
};



/*!BEGIN libc/nt/struct/systemlookasideinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMLOOKASIDEINFORMATION_H_

struct NtSystemLookasideInformation {
  unsigned char Reserved1[32];
};



/*!BEGIN libc/nt/struct/systemperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPERFORMANCEINFORMATION_H_

struct NtSystemPerformanceInformation {
  int64_t IdleTime;
  int64_t ReadTransferCount;
  int64_t WriteTransferCount;
  int64_t OtherTransferCount;
  uint32_t ReadOperationCount;
  uint32_t WriteOperationCount;
  uint32_t OtherOperationCount;
  uint32_t AvailablePages;
  uint32_t TotalCommittedPages;
  uint32_t TotalCommitLimit;
  uint32_t PeakCommitment;
  uint32_t PageFaults;
  uint32_t WriteCopyFaults;
  uint32_t TransitionFaults;
  uint32_t CacheTransitionFaults;
  uint32_t DemandZeroFaults;
  uint32_t PagesRead;
  uint32_t PageReadIos;
  uint32_t CacheReads;
  uint32_t CacheIos;
  uint32_t PagefilePagesWritten;
  uint32_t PagefilePageWriteIos;
  uint32_t MappedFilePagesWritten;
  uint32_t MappedFilePageWriteIos;
  uint32_t PagedPoolUsage;
  uint32_t NonPagedPoolUsage;
  uint32_t PagedPoolAllocs;
  uint32_t PagedPoolFrees;
  uint32_t NonPagedPoolAllocs;
  uint32_t NonPagedPoolFrees;
  uint32_t TotalFreeSystemPtes;
  uint32_t SystemCodePage;
  uint32_t TotalSystemDriverPages;
  uint32_t TotalSystemCodePages;
  uint32_t SmallNonPagedLookasideListAllocateHits;
  uint32_t SmallPagedLookasideListAllocateHits;
  uint32_t Reserved3;
  uint32_t MmSystemCachePage;
  uint32_t PagedPoolPage;
  uint32_t SystemDriverPage;
  uint32_t FastReadNoWait;
  uint32_t FastReadWait;
  uint32_t FastReadResourceMiss;
  uint32_t FastReadNotPossible;
  uint32_t FastMdlReadNoWait;
  uint32_t FastMdlReadWait;
  uint32_t FastMdlReadResourceMiss;
  uint32_t FastMdlReadNotPossible;
  uint32_t MapDataNoWait;
  uint32_t MapDataWait;
  uint32_t MapDataNoWaitMiss;
  uint32_t MapDataWaitMiss;
  uint32_t PinMappedDataCount;
  uint32_t PinReadNoWait;
  uint32_t PinReadWait;
  uint32_t PinReadNoWaitMiss;
  uint32_t PinReadWaitMiss;
  uint32_t CopyReadNoWait;
  uint32_t CopyReadWait;
  uint32_t CopyReadNoWaitMiss;
  uint32_t CopyReadWaitMiss;
  uint32_t MdlReadNoWait;
  uint32_t MdlReadWait;
  uint32_t MdlReadNoWaitMiss;
  uint32_t MdlReadWaitMiss;
  uint32_t ReadAheadIos;
  uint32_t LazyWriteIos;
  uint32_t LazyWritePages;
  uint32_t DataFlushes;
  uint32_t DataPages;
  uint32_t ContextSwitches;
  uint32_t FirstLevelTbFills;
  uint32_t SecondLevelTbFills;
  uint32_t SystemCalls;
};



/*!BEGIN libc/nt/struct/systemprocessinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSINFORMATION_H_


/*!BEGIN libc/nt/struct/vmcounters.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VMCOUNTERS_H_

struct NtVmCounters {
  size_t PeakVirtualSize;
  size_t VirtualSize;
  uint32_t PageFaultCount;
  size_t PeakWorkingSetSize;
  size_t WorkingSetSize;
  size_t QuotaPeakPagedPoolUsage;
  size_t QuotaPagedPoolUsage;
  size_t QuotaPeakNonPagedPoolUsage;
  size_t QuotaNonPagedPoolUsage;
  size_t PagefileUsage;
  size_t PeakPagefileUsage;
};


struct NtSystemProcessInformation {
  uint32_t NextEntryOffset;
  uint32_t NumberOfThreads;
  int64_t Reserved[3];
  int64_t CreateTime;
  int64_t UserTime;
  int64_t KernelTime;
  struct NtUnicodeString ImageName;
  int32_t BasePriority;
  int64_t UniqueProcessId;
  int64_t InheritedFromUniqueProcessId;
  uint32_t HandleCount;
  uint32_t SessionId;
  uint32_t PageDirectoryBase;
  struct NtVmCounters VirtualMemoryCounters;
  size_t PrivatePageCount;
  struct NtIoCounters IoCounters;
};



/*!BEGIN libc/nt/struct/systemprocessorinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORINFORMATION_H_

struct NtSystemProcessorInformation {
  unsigned short ProcessorArchitecture;
  unsigned short ProcessorLevel;
  unsigned short ProcessorRevision;
  unsigned short Unknown;
  uint32_t FeatureBits;
};



/*!BEGIN libc/nt/struct/systemprocessorperformanceinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMPROCESSORPERFORMANCEINFORMATION_H_

struct NtSystemProcessorPerformanceInformation {
  int64_t IdleTime;
  int64_t KernelTime;
  int64_t UserTime;
  int64_t Reserved1[2];
  uint32_t Reserved2;
};



/*!BEGIN libc/nt/struct/systemregistryquotainformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMREGISTRYQUOTAINFORMATION_H_

struct NtSystemRegistryQuotaInformation {
  uint32_t RegistryQuotaAllowed;
  uint32_t RegistryQuotaUsed;
  void *Reserved1;
};



/*!BEGIN libc/nt/struct/systemthreads.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTHREADS_H_

struct NtSystemThreads {
  int64_t KernelTime;
  int64_t UserTime;
  int64_t CreateTime;
  uint32_t WaitTime;
  void *StartAddress;
  struct NtClientId ClientId;
  int32_t Priority;
  int32_t BasePriority;
  uint32_t ContextSwitchCount;
  int State;
  uint32_t WaitReason;
};



/*!BEGIN libc/nt/struct/systemtimeofdayinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_SYSTEMTIMEOFDAYINFORMATION_H_

struct NtSystemTimeofdayInformation {
  int64_t BootTime;
  int64_t CurrentTime;
  int64_t TimeZoneBias;
  uint32_t CurrentTimeZoneId;
  unsigned char Reserved1[20];
};



/*!BEGIN libc/nt/struct/teb.h */

#define COSMOPOLITAN_LIBC_NT_TEB_H_
#ifdef __GNUC__

/*
 * These macros address directly into NT's TEB a.k.a. TIB
 * Any function that does this needs the `dontasan` keyword
 */
#define NtGetPeb()           ((__seg_gs struct NtPeb *)0x60)
#define NtGetTeb()           ((void *)*(__seg_gs uintptr_t *)0x30)
#define NtGetPid()           (*(__seg_gs uint32_t *)0x40)
#define NtGetTid()           (*(__seg_gs uint32_t *)0x48)
#define NtGetErr()           (*(__seg_gs int *)0x68)
#define _NtGetSeh()          ((void *)*(__seg_gs uintptr_t *)0x00)
#define _NtGetStackHigh()    ((void *)*(__seg_gs uintptr_t *)0x08)
#define _NtGetStackLow()     ((void *)*(__seg_gs uintptr_t *)0x10)
#define _NtGetSubsystemTib() ((void *)*(__seg_gs uintptr_t *)0x18)
#define _NtGetFib()          ((void *)*(__seg_gs uintptr_t *)0x20)
#define _NtGetEnv()          ((char16_t *)*(__seg_gs intptr_t *)0x38)
#define _NtGetRpc()          ((void *)*(__seg_gs uintptr_t *)0x50)
#define _NtGetTls()          ((void *)*(__seg_gs uintptr_t *)0x58)

#endif /* __GNUC__ */


/*!BEGIN libc/nt/struct/timezoneinformation.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TIMEZONEINFORMATION_H_

struct NtTimeZoneInformation {
  int Bias;                  /* in minutes e.g. +480 for -8:00 */
  char16_t StandardName[32]; /* e.g. "Pacific Standard Time" */
  struct NtSystemTime StandardDate;
  int StandardBias;
  char16_t DaylightName[32]; /* e.g. "Pacific Daylight Time" */
  struct NtSystemTime DaylightDate;
  int DaylightBias; /* e.g. -60 */
};



/*!BEGIN libc/nt/struct/tokenprivileges.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_TOKENPRIVILEGES_H_

struct NtTokenPrivileges {
  uint32_t PrivilegeCount;
  struct NtLuidAndAttributes Privileges[1];
};



/*!BEGIN libc/nt/struct/userstack.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_NTUSERSTACK_H_

struct NtUserStack {
  void *FixedStackBase;
  void *FixedStackLimit;
  void *ExpandableStackBase;
  void *ExpandableStackLimit;
  void *ExpandableStackBottom;
};



/*!BEGIN libc/nt/struct/valent.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_VALENT_H_

struct NtValent {
  char16_t *ve_valuename;
  uint32_t ve_valuelen;
  uintptr_t ve_valueptr;
  uint32_t ve_type;
};



/*!BEGIN libc/nt/struct/win32fileattributedata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FILEATTRIBUTEDATA_H_

struct NtWin32FileAttributeData {
  uint32_t dwFileAttributes; /* ←NtFileFlagAndAttributes */
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
};



/*!BEGIN libc/nt/struct/win32finddata.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WIN32FINDDATA_H_

struct NtWin32FindData {
  uint32_t dwFileAttributes;
  struct NtFileTime ftCreationTime;
  struct NtFileTime ftLastAccessTime;
  struct NtFileTime ftLastWriteTime;
  uint32_t nFileSizeHigh;
  uint32_t nFileSizeLow;
  uint32_t dwReserved0;
  uint32_t dwReserved1;
  char16_t cFileName[260];
  char16_t cAlternateFileName[14];
  uint32_t dwFileType;    /* obsolete */
  uint32_t dwCreatorType; /* obsolete */
  uint16_t wFinderFlags;  /* obsolete */
};



/*!BEGIN libc/nt/struct/windowplacement.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WINDOWPLACEMENT_H_

struct NtWindowPlacement {
  uint32_t length;
  uint32_t flags;
  uint32_t showCmd;
  struct NtPoint ptMinPosition;
  struct NtPoint ptMaxPosition;
  struct NtRect rcNormalPosition;
  struct NtRect rcDevice;
};



/*!BEGIN libc/nt/struct/wndclass.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASS_H_


/*!BEGIN libc/nt/typedef/wndproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDPROC_H_
COSMOPOLITAN_C_START_

typedef int64_t (*NtWndProc)(int64_t, uint32_t, uint64_t, int64_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

struct NtWndClass {
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/struct/wndclassex.h */

#define COSMOPOLITAN_LIBC_NT_STRUCT_WNDCLASSEX_H_
COSMOPOLITAN_C_START_

struct NtWndClassEx {
  uint32_t cbSize;
  uint32_t style;
  NtWndProc lpfnWndProc;
  int32_t cbClsExtra;
  int32_t cbWndExtra;
  int64_t hInstance;
  int64_t hIcon;
  int64_t hCursor;
  int64_t hbrBackground;
  const char16_t *lpszMenuName;
  const char16_t *lpszClassName;
  int64_t hIconSm;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/exceptionhandler.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_EXCEPTIONHANDLER_H_
COSMOPOLITAN_C_START_

typedef unsigned (*NtExceptionHandler)(struct NtExceptionRecord *,
                                       struct NtExceptionFrame *,
                                       struct NtContext *, void *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/handlerroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HANDLERROUTINE_H_

typedef bool32 (*NtHandlerRoutine)(uint32_t);



/*!BEGIN libc/nt/typedef/hookproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_HOOKPROC_H_

typedef intptr_t (*NtHookProc)(int code, uintptr_t wParam, intptr_t lParam);



/*!BEGIN libc/nt/typedef/imagetlscallback.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IMAGETLSCALLBACK_H_

typedef void (*NtImageTlsCallback)(void *DllHandle, uint32_t Reason,
                                   void *Reserved);



/*!BEGIN libc/nt/typedef/ioapcroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_IOAPCROUTINE_H_

typedef void (*NtIoApcRoutine)(void *ApcContext,
                               struct NtIoStatusBlock *IoStatusBlock,
                               uint32_t Reserved);



/*!BEGIN libc/nt/typedef/pknormalroutine.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_PKNORMALROUTINE_H_

typedef void (*NtPkNormalRoutine)(void *NormalContext, void *SystemArgument1,
                                  void *SystemArgument2);



/*!BEGIN libc/nt/typedef/timerproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_TIMERPROC_H_

typedef void (*NtTimerProc)(int64_t, uint32_t, uintptr_t, uint32_t);



/*!BEGIN libc/nt/typedef/wambda.h */

#define COSMOPOLITAN_LIBC_NT_WAMBDA_H_
COSMOPOLITAN_C_START_

typedef intptr_t (*wambda)();

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/typedef/wndenumproc.h */

#define COSMOPOLITAN_LIBC_NT_TYPEDEF_WNDENUMPROC_H_

typedef int (*NtWndEnumProc)(int64_t foo, intptr_t bar);



/*!BEGIN libc/nt/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » debugging              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtContinue(struct NtContext *Context, int32_t TestAlert);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/file.h */

#define COSMOPOLITAN_LIBC_NT_NT_FILE_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtClose(int64_t handle);

NtStatus NtCreateFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                      const struct NtObjectAttributes *ObjectAttributes,
                      struct NtIoStatusBlock *out_IoStatusBlock,
                      int64_t *opt_AllocationSize, uint32_t FileAttributes,
                      uint32_t ShareAccess, uint32_t CreateDisposition,
                      uint32_t CreateOptions, void *opt_EaBuffer,
                      uint32_t EaLength);

NtStatus NtReadFile(int64_t FileHandle, void *opt_Event,
                    NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                    struct NtIoStatusBlock *out_IoStatusBlock, void *out_Buffer,
                    uint32_t Length, int64_t *opt_ByteOffset,
                    uint32_t *opt_Key);

NtStatus NtWriteFile(int64_t FileHandle, void *opt_Event,
                     NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                     struct NtIoStatusBlock *out_IoStatusBlock,
                     const void *Buffer, uint32_t Length,
                     int64_t *opt_ByteOffset, uint32_t *opt_Key);

NtStatus NtDuplicateObject(int64_t SourceProcessHandle, void *SourceHandle,
                           void *TargetProcessHandle,
                           void **opt_out_TargetHandle, uint32_t DesiredAcess,
                           uint32_t Attributes, uint32_t options_t);

NtStatus NtQueryInformationFile(int64_t FileHandle,
                                struct NtIoStatusBlock *out_IoStatusBlock,
                                void *out_FileInformation,
                                uint32_t FileInformationLength,
                                uint32_t FileInformationClass);

NtStatus NtSetInformationFile(int64_t FileHandle,
                              struct NtIoStatusBlock *out_IoStatusBlock,
                              void *FileInformation,
                              uint32_t FileInformationLength,
                              uint32_t FileInformationClass);

NtStatus NtDeviceIoControlFile(
    int64_t FileHandle, int64_t opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    uint32_t IoControlCode, void *opt_InputBuffer, uint32_t InputBufferLength,
    void *opt_out_OutputBuffer, uint32_t OutputBufferLength);

NtStatus NtCancelIoFileEx(int64_t FileHandle,
                          struct NtIoStatusBlock *IoRequestToCancel,
                          struct NtIoStatusBlock *IoStatusBlock);

NtStatus RtlNtStatusToDosError(NtStatus Status);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntfile.inc */

#define NtQueryInformationFile(...) __imp_NtQueryInformationFile(__VA_ARGS__)

extern typeof(NtQueryInformationFile) *const
    __imp_NtQueryInformationFile __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_NT_IPC_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » ipc                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtIoStatusBlock;
struct NtObjectAttributes;

NtStatus NtCreateNamedPipeFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes,
                               struct NtIoStatusBlock *out_IoStatusBlock,
                               uint32_t ShareAccess, uint32_t CreateDisposition,
                               uint32_t CreateOptions, int32_t TypeMessage,
                               int32_t ReadmodeMessage, int32_t Nonblocking,
                               uint32_t MaxInstances, uint32_t InBufferSize,
                               uint32_t OutBufferSize,
                               int64_t *opt_DefaultTimeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/key.h */

#define COSMOPOLITAN_LIBC_NT_NT_EVENT_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » files                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtCreateKeyedEvent(int64_t *KeyedEventHandle, uint32_t DesiredAccess,
                            struct NtObjectAttributes *ObjectAttributes,
                            uint32_t Flags);

NtStatus NtReleaseKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

NtStatus NtWaitForKeyedEvent(int64_t KeyedEventHandle, void *KeyValue,
                             bool32 Alertable, int64_t *Timeout);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/loader.h */

#define COSMOPOLITAN_LIBC_NT_NT_LOADER_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » loader                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtAnsiString;
struct NtLdrDataTableEntry;
struct NtUnicodeString;

NtStatus LdrLoadDll(const char16_t *opt_PathToFile, uint32_t *opt_Flags,
                    struct NtUnicodeString *ModuleFileName,
                    void **out_ModuleHandle);
NtStatus LdrUnloadDll(void *ModuleHandle);
NtStatus LdrGetProcedureAddress(void *ModuleHandle,
                                struct NtAnsiString *opt_ProcedureName,
                                uint32_t opt_Ordinal,
                                wambda *out_ProcedureAddress);
NtStatus LdrGetDllHandle(const char16_t *opt_PathToFile, uint32_t opt_Unused,
                         struct NtUnicodeString *ModuleFileName,
                         void **out_ModuleHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_NT_MEMORY_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » memory                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtAllocateVirtualMemory(int64_t ProcessHandle,
                                 void **inout_BaseAddress, uint32_t dwZeroBits,
                                 uint32_t *inout_AllocationSize,
                                 uint32_t dwMemAllocationType,
                                 uint32_t dwPageProtect);
NtStatus NtFreeVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                             size_t *inout_FreeSize, uint32_t FreeType);
NtStatus NtQueryVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                              int MemoryInformationClass,
                              void *out_MemoryInformation,
                              size_t MemoryInformationLength,
                              size_t *opt_out_ReturnLength);
NtStatus NtProtectVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                                uint32_t *inout_ProtectSize,
                                uint32_t NewProtect, uint32_t *out_OldProtect);
NtStatus NtWriteVirtualMemory(int64_t ProcessHandle, void *BaseAddress,
                              const void *Buffer, size_t BufferLength,
                              size_t *opt_out_ReturnLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_NT_PROCESS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » processes              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtObjectAttributes;
struct NtRtlUserProcessInformation;
struct NtRtlUserProcessParameters;
struct NtSecurityDescriptor;
struct NtUnicodeString;

NtStatus NtCreateProcess(int64_t *out_ProcessHandle, uint32_t dwDesiredAccess,
                         struct NtObjectAttributes *opt_ObjectAttributes,
                         void *InheritFromProcessHandle, int32_t InheritHandles,
                         void *opt_SectionHandle, void *opt_DebugPort,
                         void *opt_ExceptionPort);
NtStatus NtTerminateProcess(int64_t opt_ProcessHandle, int32_t ExitStatus);

NtStatus NtQueryInformationProcess(int64_t ProcessHandle,
                                   int ProcessInformationClass,
                                   void *out_ProcessInformation,
                                   uint32_t ProcessInformationLength,
                                   uint32_t *opt_out_ReturnLength);
NtStatus NtOpenProcessToken(int64_t ProcessToken, uint32_t DesiredAccess,
                            int64_t *out_TokenHandle);
NtStatus NtOpenProcess(int64_t *out_ProcessHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       struct NtClientId *ClientId);

NtStatus RtlCreateProcessParameters(
    struct NtRtlUserProcessParameters **out_ProcessParameters,
    struct NtUnicodeString *ImageFile, struct NtUnicodeString *opt_DllPath,
    struct NtUnicodeString *opt_CurrentDirectory,
    struct NtUnicodeString *opt_CommandLine, uint32_t CreationFlags,
    struct NtUnicodeString *opt_WindowTitle,
    struct NtUnicodeString *opt_Desktop, struct NtUnicodeString *opt_Reserved,
    struct NtUnicodeString *opt_Reserved2);

NtStatus RtlDestroyProcessParameters(
    struct NtRtlUserProcessParameters *ProcessParameters);

NtStatus RtlCloneUserProcess(
    uint32_t ProcessFlags,
    struct NtSecurityDescriptor *opt_ProcessSecurityDescriptor,
    struct NtSecurityDescriptor *opt_ThreadSecurityDescriptor,
    void *opt_DebugPort,
    struct NtRtlUserProcessInformation *ProcessInformation);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/process.inc */

#define NtQueryInformationProcess(...) \
  __imp_NtQueryInformationProcess(__VA_ARGS__)

extern typeof(NtQueryInformationProcess) *const
    __imp_NtQueryInformationProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/sections.h */

#define COSMOPOLITAN_LIBC_NT_NT_SECTIONS_H_
COSMOPOLITAN_C_START_

NtStatus NtCreateSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                         struct NtObjectAttributes *ObjectAttributes,
                         int64_t *opt_SectionSize, uint32_t Protect,
                         uint32_t Attributes, int64_t FileHandle);
NtStatus NtOpenSection(int64_t *out_SectionHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes);
NtStatus NtMapViewOfSection(int64_t SectionHandle, int64_t ProcessHandle,
                            void **inout_BaseAddress, uint32_t *ZeroBits,
                            size_t CommitSize, int64_t *opt_inout_SectionOffset,
                            size_t *inout_ViewSize, int InheritDisposition,
                            uint32_t AllocationType, uint32_t Protect);
NtStatus NtUnmapViewOfSection(int64_t ProcessHandle, void *BaseAddress);
NtStatus NtQuerySection(int64_t SectionHandle, int SectionInformationClass,
                        void *out_SectionInformation,
                        uint32_t SectionInformationLength,
                        uint32_t *opt_out_ResultLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/signing.h */

#define COSMOPOLITAN_LIBC_NT_NT_SIGNING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » code signing           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus CsrClientCallServer(void *inout_Message, void *unknown,
                             uint32_t Opcode, uint32_t Size);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » threads                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

struct NtClientId;
struct NtContext;
struct NtObjectAttributes;
struct NtUserStack;

NtStatus NtCreateThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                        struct NtObjectAttributes *ObjectAttributes,
                        int64_t ProcessHandle, struct NtClientId *out_ClientId,
                        struct NtContext *ThreadContext,
                        struct NtUserStack *UserStack, int32_t CreateSuspended);

NtStatus NtTerminateThread(void *opt_ThreadHandle, int32_t ExitStatus);

NtStatus NtOpenThread(int64_t *out_ThreadHandle, uint32_t DesiredAccess,
                      struct NtObjectAttributes *ObjectAttributes,
                      struct NtClientId *ClientId);

NtStatus NtQueryInformationThread(int64_t ThreadHandle,
                                  enum NtThreadInfoClass ThreadInformationClass,
                                  void *out_ThreadInformation,
                                  uint32_t ThreadInformationLength,
                                  uint32_t *opt_out_ReturnLength);

NtStatus NtGetContextThread(int64_t ThreadHandle,
                            struct NtContext *out_Context);
NtStatus NtSetContextThread(int64_t ThreadHandle, struct NtContext *Context);
NtStatus NtSuspendThread(int64_t ThreadHandle,
                         uint32_t *opt_out_PreviousSuspendCount);
NtStatus NtResumeThread(int64_t ThreadHandle,
                        uint32_t *opt_out_PreviousSuspendCount);

NtStatus NtOpenThreadToken(int64_t ThreadHandle, uint32_t DesiredAccess,
                           int32_t OpenAsSelf, int64_t *out_TokenHandle);

NtStatus NtSetInformationThread(int64_t ThreadHandle,
                                enum NtThreadInfoClass ThreadInformationClass,
                                void *ThreadInformation,
                                uint32_t ThreadInformationLength);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_NT_THREAD_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale » time                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

NtStatus NtDelayExecution(bool32 alertable, int64_t *AbsCobolOrNegRelHectoNano);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/nt/thunk/time.inc */

#define NtDelayExecution(...) __imp_NtDelayExecution(__VA_ARGS__)

extern typeof(NtDelayExecution) *const __imp_NtDelayExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/accounting.h */

#define COSMOPOLITAN_LIBC_NT_ACCOUNTING_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » accounting                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetMaximumProcessorCount(uint16_t GroupNumber);
int GetUserName(char16_t (*buf)[257], uint32_t *in_out_size);
bool32 GlobalMemoryStatusEx(struct NtMemoryStatusEx *lpBuffer);
int32_t GetExitCodeProcess(int64_t hProcess, uint32_t *lpExitCode);
int32_t GetProcessHandleCount(int64_t hProcess, uint32_t *pdwHandleCount);
bool32 GetSystemTimes(struct NtFileTime *opt_out_lpIdleTime,
                      struct NtFileTime *opt_out_lpKernelTime,
                      struct NtFileTime *opt_out_lpUserTime);
bool32 GetProcessTimes(int64_t hProcess,
                       struct NtFileTime *out_lpCreationFileTime,
                       struct NtFileTime *out_lpExitFileTime,
                       struct NtFileTime *out_lpKernelFileTime,
                       struct NtFileTime *out_lpUserFileTime);
bool32 GetThreadTimes(int64_t hThread,
                      struct NtFileTime *out_lpCreationFileTime,
                      struct NtFileTime *out_lpExitFileTime,
                      struct NtFileTime *out_lpKernelFileTime,
                      struct NtFileTime *out_lpUserFileTime);
int32_t GetProcessIoCounters(int64_t hProcess,
                             struct NtIoCounters *lpIoCounters);
int32_t GetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t *lpMinimumWorkingSetSize,
                                 uint64_t *lpMaximumWorkingSetSize);
int32_t GetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t *lpMinimumWorkingSetSize,
                                   uint64_t *lpMaximumWorkingSetSize,
                                   uint32_t *Flags);
int32_t SetProcessWorkingSetSize(int64_t hProcess,
                                 uint64_t dwMinimumWorkingSetSize,
                                 uint64_t dwMaximumWorkingSetSize);
int32_t SetProcessWorkingSetSizeEx(int64_t hProcess,
                                   uint64_t dwMinimumWorkingSetSize,
                                   uint64_t dwMaximumWorkingSetSize,
                                   uint32_t Flags);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/accounting.inc */

#define GetProcessTimes(...) __imp_GetProcessTimes(__VA_ARGS__)
extern typeof(GetProcessTimes) *const __imp_GetProcessTimes __msabi;

#define GetThreadTimes(...) __imp_GetThreadTimes(__VA_ARGS__)
extern typeof(GetThreadTimes) *const __imp_GetThreadTimes __msabi;

#define GetUserName(...) __imp_GetUserNameW(__VA_ARGS__)
extern typeof(GetUserName) *const __imp_GetUserNameW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/automation.h */

#define COSMOPOLITAN_LIBC_NT_AUTOMATION_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » aol hacking                              ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int64_t GetShellWindow(void);
int64_t GetDesktopWindow(void);
int64_t GetParent(int64_t hWnd);
int64_t SetParent(int64_t hWndChild, int64_t hWndNewParent);
int32_t EnumChildWindows(int64_t hWndParent, NtWndEnumProc lpEnumFunc,
                         intptr_t lParam);
int64_t FindWindow(const char16_t *lpClassName, const char16_t *lpWindowName);
int64_t FindWindowEx(int64_t hWndParent, int64_t hWndChildAfter,
                     const char16_t *lpszClass, const char16_t *lpszWindow);
int64_t GetWindow(int64_t hWnd, uint32_t uCmd);
int64_t SetWindowsHook(int nFilterType, NtHookProc pfnFilterProc);
int32_t UnhookWindowsHook(int nCode, NtHookProc pfnFilterProc);
int64_t SetWindowsHookEx(int idHook, NtHookProc lpfn, int64_t hmod,
                         uint32_t dwThreadId);
int32_t UnhookWindowsHookEx(int64_t hhk);
intptr_t CallNextHookEx(int64_t hhk, int nCode, uintptr_t wParam,
                        intptr_t lParam);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/codegen.h */

#define COSMOPOLITAN_LIBC_NT_CODEGEN_H_


/*!BEGIN libc/nt/comdlg.h */

#define COSMOPOLITAN_LIBC_NT_COMDLG_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » common dialogs                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 GetOpenFileName(struct NtOpenFilename *arg);
bool32 GetSaveFileName(struct NtOpenFilename *arg);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/comms.h */

#define COSMOPOLITAN_LIBC_NT_COMMS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » communications                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

bool32 PurgeComm(int64_t hFile, uint32_t dwFlags);
bool32 TransmitCommChar(int64_t hFile, char cChar);
bool32 ClearCommBreak(int64_t hFile);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/console.h */

#define COSMOPOLITAN_LIBC_NT_CONSOLE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » console                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtAttachParentProcess -1u

COSMOPOLITAN_C_START_

bool32 WriteConsoleOutput(int64_t hConsoleOutput,
                          const struct NtCharInfo *lpBuffer,
                          struct NtCoord dwBufferSize,
                          struct NtCoord dwBufferCoord,
                          struct NtSmallRect *lpWriteRegion);
bool32 ReadConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 PeekConsoleInput(int64_t hConsoleInput, struct NtInputRecord *lpBuffer,
                        uint32_t nLength, uint32_t *lpNumberOfEventsRead);
bool32 GetNumberOfConsoleInputEvents(int64_t hConsoleInput,
                                     uint32_t *lpNumberOfEvents);
bool32 ReadConsoleOutput(int64_t hConsoleOutput, struct NtCharInfo *lpBuffer,
                         struct NtCoord dwBufferSize,
                         struct NtCoord dwBufferCoord,
                         struct NtSmallRect *lpReadRegion);
bool32 WriteConsoleInput(int64_t hConsoleInput,
                         const struct NtInputRecord *lpBuffer, uint32_t nLength,
                         uint32_t *lpNumberOfEventsWritten);
bool32 FlushConsoleInputBuffer(int64_t hConsoleInput);

int64_t GetConsoleWindow(void);
bool32 GetConsoleMode(int64_t hConsoleHandle, uint32_t *lpMode);
bool32 SetConsoleMode(int64_t hConsoleHandle, uint32_t dwMode);
int32_t AllocConsole(void);
int32_t FreeConsole(void);
int32_t AttachConsole(uint32_t dwProcessId);
uint32_t GetConsoleTitle(char16_t *lpConsoleTitle, uint32_t nSize);
int32_t SetConsoleTitle(const char16_t *lpConsoleTitle);
bool32 GetConsoleScreenBufferInfo(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfo *out_lpConsoleScreenBufferInfo);
bool32 GetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    struct NtConsoleScreenBufferInfoEx *in_out_lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferInfoEx(
    int64_t hConsoleOutput,
    const struct NtConsoleScreenBufferInfoEx *lpConsoleScreenBufferInfo);
bool32 SetConsoleScreenBufferSize(int64_t lpConsoleOutput,
                                  struct NtCoord dwSize);
struct NtCoord GetLargestConsoleWindowSize(int64_t hConsoleHandle);
int32_t ReadConsole(int64_t hConsoleInput, void *lpBuffer,
                    uint32_t nNumberOfCharsToRead,
                    uint32_t *lpNumberOfCharsRead, void *lpReserved);
int32_t WriteConsole(int64_t hConsoleOutput, const void *lpBuffer,
                     uint32_t nNumberOfCharsToWrite,
                     uint32_t *lpNumberOfCharsWritten, void *lpReserved)
    paramsnonnull((2, 4));
bool32 GetNumberOfConsoleMouseButtons(uint32_t *out_lpNumberOfMouseButtons)
    paramsnonnull();
bool32 GetConsoleSelectionInfo(
    struct NtConsoleSelectionInfo *out_lpConsoleSelectionInfo);
uint32_t WaitForInputIdle(int64_t hProcess, uint32_t dwMilliseconds);
uint32_t GetConsoleCP(void);
bool32 SetConsoleCP(uint32_t wCodePageID);
bool32 SetConsoleOutputCP(uint32_t wCodePageID);
uint32_t GetConsoleOutputCP(void);
bool32 SetConsoleCtrlHandler(NtHandlerRoutine opt_HandlerRoutine, bool32 Add);
bool32 GenerateConsoleCtrlEvent(uint32_t dwCtrlEvent,
                                uint32_t dwProcessGroupId);

bool32 GetConsoleCursorInfo(
    int64_t hConsoleOutput,
    struct NtConsoleCursorInfo *out_lpConsoleCursorInfo);
bool32 SetConsoleCursorInfo(
    int64_t hConsoleOutput,
    const struct NtConsoleCursorInfo *lpConsoleCursorInfo);

long CreatePseudoConsole(struct NtCoord size, int64_t hInput, int64_t hOutput,
                         uint32_t dwFlags, int64_t *out_phPC);
long ResizePseudoConsole(int64_t hPC, struct NtCoord size);
void ClosePseudoConsole(int64_t hPC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/console.inc */

#define GetConsoleMode(...) __imp_GetConsoleMode(__VA_ARGS__)
extern typeof(GetConsoleMode) *const __imp_GetConsoleMode __msabi;

#define SetConsoleCP(...) __imp_SetConsoleCP(__VA_ARGS__)
extern typeof(SetConsoleCP) *const __imp_SetConsoleCP __msabi;

#define GetConsoleCP(...) __imp_GetConsoleCP(__VA_ARGS__)
extern typeof(GetConsoleCP) *const __imp_GetConsoleCP __msabi;

#define SetConsoleCtrlHandler(...) __imp_SetConsoleCtrlHandler(__VA_ARGS__)
extern typeof(SetConsoleCtrlHandler) *const __imp_SetConsoleCtrlHandler __msabi;

#define SetConsoleMode(...) __imp_SetConsoleMode(__VA_ARGS__)
extern typeof(SetConsoleMode) *const __imp_SetConsoleMode __msabi;

#define SetConsoleOutputCP(...) __imp_SetConsoleOutputCP(__VA_ARGS__)
extern typeof(SetConsoleOutputCP) *const __imp_SetConsoleOutputCP __msabi;

#define GetConsoleOutputCP(...) __imp_GetConsoleOutputCP(__VA_ARGS__)
extern typeof(GetConsoleOutputCP) *const __imp_GetConsoleOutputCP __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/createfile.h */

#define COSMOPOLITAN_LIBC_NT_CREATEFILE_H_
COSMOPOLITAN_C_START_

int64_t CreateFile(
    const char16_t *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int64_t CreateFileA(
    const char *lpFileName, uint32_t dwDesiredAccess, uint32_t dwShareMode,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes,
    int dwCreationDisposition,
    uint32_t dwFlagsAndAttributes, /* libc/nt/enum/fileflagandattributes.h */
    int64_t opt_hTemplateFile) paramsnonnull((1));

int GetNtOpenFlags(int, int, uint32_t *, uint32_t *, uint32_t *, uint32_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/debug.h */

#define COSMOPOLITAN_LIBC_NT_DEBUG_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » debugging                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* Some of these APIs were moved to system.h and libc.h */
int32_t DebugBreakProcess(void *Process);
int32_t DebugActiveProcess(uint32_t dwProcessId);
int32_t DebugActiveProcessStop(uint32_t dwProcessId);
int32_t CheckRemoteDebuggerPresent(int64_t hProcess, int *pbDebuggerPresent);
int32_t ContinueDebugEvent(uint32_t dwProcessId, uint32_t dwThreadId,
                           uint32_t dwContinueStatus);
void FatalExit(int uExitCode);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/dll.h */

#define COSMOPOLITAN_LIBC_NT_DLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » dynamic link libraries                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t LoadLibrary(const char16_t *lpLibFileName);
int64_t LoadLibraryA(const char *lpLibFileName);
int64_t LoadLibraryEx(const char16_t *lpLibFileName, int64_t hFile,
                      uint32_t dwFlags);
uint32_t GetModuleFileNameA(int64_t hModule, char *lpFilename, uint32_t nSize);
intptr_t GetModuleHandle(const char *opt_lpModuleName);
intptr_t GetModuleHandleW(const char16_t *opt_lpModuleName);
void *GetProcAddress(int64_t hModule, const char *lpProcName);
int32_t FreeResource(int64_t hResData);
intptr_t LockResource(int64_t hResData);
int32_t FreeLibrary(int64_t hLibModule);
void *AddDllDirectory(const char16_t *NewDirectory);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/efi.h */

#define COSMOPOLITAN_LIBC_NT_EFI_H_
/*
    ▐██ ░█████████▓   ▐██▌     ██▓░   ▐█▌  ▐██  ░██░    ▓█▌  ▓██▒     ▓██
    ▐██     ░██░     ▒█▓██░    ████░  ▐█▌  ▐██  ░██░    ▓█▌  ▓███░   ▓███
    ▐██     ░██░     ██░▐█▓    ██▒▓█░ ▐█▌  ▐██  ░██░    ▓█▌  ▓█▌▓█░ ▓█▒██
    ▐██     ░██░    ▐█▌  ▓█▌   ██░░▓█░▐█▌  ▐██  ░██░    ▓█▌  ▓█▌░█▓▓█▒░██
    ▐██     ░██░   ▒██▓█████░  ██░ ░▓▓▓█▌  ▐██  ░██░    ██░  ▓█▌ ░██▌ ░██
    ▐██     ░██░   ▓█▌    ▓█▓  ██░  ░███▌  ▐██   ▐██▄▄▄▓█▓   ▓█▌      ░██
╔────────────────────────────────────────────────────────────────────────────│─╗
│ αcτµαlly pδrταblε εxεcµταblε § the unified extensible firmware interface ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define EFI_SUCCESS           0x8000000000000000
#define EFI_LOAD_ERROR        0x8000000000000001
#define EFI_INVALID_PARAMETER 0x8000000000000002
#define EFI_UNSUPPORTED       0x8000000000000003
#define EFI_BAD_BUFFER_SIZE   0x8000000000000004
#define EFI_BUFFER_TOO_SMALL  0x8000000000000005
#define EFI_NOT_READY         0x8000000000000006
#define EFI_DEVICE_ERROR      0x8000000000000007
#define EFI_WRITE_PROTECTED   0x8000000000000008
#define EFI_OUT_OF_RESOURCES  0x8000000000000009
#define EFI_VOLUME_CORRUPTED  0x800000000000000a
#define EFI_VOLUME_FULL       0x800000000000000b
#define EFI_NO_MEDIA          0x800000000000000c
#define EFI_MEDIA_CHANGED     0x800000000000000d
#define EFI_NOT_FOUND         0x800000000000000e
#define EFI_ACCESS_DENIED     0x800000000000000f
#define EFI_NO_RESPONSE       0x8000000000000010
#define EFI_NO_MAPPING        0x8000000000000011
#define EFI_TIMEOUT           0x8000000000000012
#define EFI_NOT_STARTED       0x8000000000000013
#define EFI_ALREADY_STARTED   0x8000000000000014
#define EFI_ABORTED           0x8000000000000015
#define EFI_ICMP_ERROR        0x8000000000000016
#define EFI_TFTP_ERROR        0x8000000000000017
#define EFI_PROTOCOL_ERROR    0x8000000000000018

#define EFI_VARIABLE_NON_VOLATILE                          0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS                    0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS                        0x00000004
#define EFI_VARIABLE_HARDWARE_ERROR_RECORD                 0x00000008
#define EFI_VARIABLE_AUTHENTICATED_WRITE_ACCESS            0x00000010
#define EFI_VARIABLE_TIME_BASED_AUTHENTICATED_WRITE_ACCESS 0x00000020
#define EFI_VARIABLE_APPEND_WRITE                          0x00000040

#define EFI_MEMORY_UC            0x0000000000000001U
#define EFI_MEMORY_WC            0x0000000000000002U
#define EFI_MEMORY_WT            0x0000000000000004U
#define EFI_MEMORY_WB            0x0000000000000008U
#define EFI_MEMORY_UCE           0x0000000000000010U
#define EFI_MEMORY_WP            0x0000000000001000U
#define EFI_MEMORY_RP            0x0000000000002000U
#define EFI_MEMORY_XP            0x0000000000004000U
#define EFI_MEMORY_RO            0x0000000000020000U
#define EFI_MEMORY_NV            0x0000000000008000U
#define EFI_MEMORY_MORE_RELIABLE 0x0000000000010000U
#define EFI_MEMORY_RUNTIME       0x8000000000000000U

#define EFI_OPTIONAL_PTR 0x00000001

#define EFI_SCAN_NULL      0x0000
#define EFI_SCAN_UP        0x0001
#define EFI_SCAN_DOWN      0x0002
#define EFI_SCAN_RIGHT     0x0003
#define EFI_SCAN_LEFT      0x0004
#define EFI_SCAN_HOME      0x0005
#define EFI_SCAN_END       0x0006
#define EFI_SCAN_INSERT    0x0007
#define EFI_SCAN_DELETE    0x0008
#define EFI_SCAN_PAGE_UP   0x0009
#define EFI_SCAN_PAGE_DOWN 0x000A
#define EFI_SCAN_F1        0x000B
#define EFI_SCAN_F2        0x000C
#define EFI_SCAN_F3        0x000D
#define EFI_SCAN_F4        0x000E
#define EFI_SCAN_F5        0x000F
#define EFI_SCAN_F6        0x0010
#define EFI_SCAN_F7        0x0011
#define EFI_SCAN_F8        0x0012
#define EFI_SCAN_F9        0x0013
#define EFI_SCAN_F10       0x0014
#define EFI_SCAN_ESC       0x0017

#define EFI_EVT_TIMER                         0x80000000
#define EFI_EVT_RUNTIME                       0x40000000
#define EFI_EVT_NOTIFY_WAIT                   0x00000100
#define EFI_EVT_NOTIFY_SIGNAL                 0x00000200
#define EFI_EVT_SIGNAL_EXIT_BOOT_SERVICES     0x00000201
#define EFI_EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE 0x60000202
#define EFI_EVT_RUNTIME_CONTEXT               0x20000000

#define LOADED_IMAGE_PROTOCOL                        \
  {                                                  \
    0x5B1B31A1, 0x9562, 0x11d2, {                    \
      0x8E, 0x3F, 0x00, 0xA0, 0xC9, 0x69, 0x72, 0x3B \
    }                                                \
  }
#define GRAPHICS_OUTPUT_PROTOCOL                     \
  {                                                  \
    0x9042A9DE, 0x23DC, 0x4A38, {                    \
      0x96, 0xFB, 0x7A, 0xDE, 0xD0, 0x80, 0x51, 0x6A \
    }                                                \
  }
#define ACPI_20_TABLE_GUID                           \
  {                                                  \
    0x8868E871, 0xE4F1, 0x11D3, {                    \
      0xBC, 0x22, 0x00, 0x80, 0xC7, 0x3C, 0x88, 0x81 \
    }                                                \
  }
#define ACPI_10_TABLE_GUID                           \
  {                                                  \
    0xEB9D2D30, 0x2D88, 0x11D3, {                    \
      0x9A, 0x16, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D \
    }                                                \
  }

COSMOPOLITAN_C_START_

#if defined(__GNUC__) && __GNUC__ >= 6 && !defined(__chibicc__) && \
    defined(__x86_64__)
#define EFIAPI __attribute__((__ms_abi__))
#else
#define EFIAPI /* TODO(jart): fix me */
#endif

#define EFI_STATUS uint64_t
#define EFI_EVENT  uintptr_t
#define EFI_HANDLE uintptr_t

typedef struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL EFI_SIMPLE_TEXT_INPUT_PROTOCOL;
typedef struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL;
typedef struct _EFI_GRAPHICS_OUTPUT_PROTOCOL EFI_GRAPHICS_OUTPUT_PROTOCOL;

typedef enum {
  EfiReservedMemoryType,
  EfiLoaderCode,
  EfiLoaderData,
  EfiBootServicesCode,
  EfiBootServicesData,
  EfiRuntimeServicesCode,
  EfiRuntimeServicesData,
  EfiConventionalMemory,
  EfiUnusableMemory,
  EfiACPIReclaimMemory,
  EfiACPIMemoryNVS,
  EfiMemoryMappedIO,
  EfiMemoryMappedIOPortSpace,
  EfiPalCode,
  EfiPersistentMemory,
  EfiMaxMemoryType
} EFI_MEMORY_TYPE;

typedef enum {
  EfiResetCold,
  EfiResetWarm,
  EfiResetShutdown,
  EfiResetPlatformSpecific
} EFI_RESET_TYPE;

typedef enum {
  AllocateAnyPages,
  AllocateMaxAddress,
  AllocateAddress,
  MaxAllocateType
} EFI_ALLOCATE_TYPE;

typedef enum {
  TimerCancel,
  TimerPeriodic,
  TimerRelative,
} EFI_TIMER_DELAY;

typedef struct {
  uint32_t Resolution;
  uint32_t Accuracy;
  bool32 SetsToZero;
} EFI_TIME_CAPABILITIES;

typedef struct {
  uint32_t Data1;
  uint16_t Data2;
  uint16_t Data3;
  uint8_t Data4[8];
} EFI_GUID;

typedef struct {
  uint16_t Year;
  uint8_t Month;
  uint8_t Day;
  uint8_t Hour;
  uint8_t Minute;
  uint8_t Second;
  uint8_t Pad1;
  uint32_t Nanosecond;
  int16_t TimeZone;
  uint8_t Daylight;
  uint8_t Pad2;
} EFI_TIME;

typedef struct {
  uint32_t Type;
  uint64_t PhysicalStart;
  uint64_t VirtualStart;
  uint64_t NumberOfPages;
  uint64_t Attribute;
} EFI_MEMORY_DESCRIPTOR;

typedef struct {
  EFI_GUID VendorGuid;
  void *VendorTable;
} EFI_CONFIGURATION_TABLE;

typedef struct {
  EFI_GUID CapsuleGuid;
  uint32_t HeaderSize;
  uint32_t Flags;
  uint32_t CapsuleImageSize;
} EFI_CAPSULE_HEADER;

typedef struct {
  uint16_t ScanCode;
  char16_t UnicodeChar;
} EFI_INPUT_KEY;

typedef struct {
  int32_t MaxMode;
  int32_t Mode;
  int32_t Attribute;
  int32_t CursorColumn;
  int32_t CursorRow;
  bool32 CursorVisible;
} EFI_SIMPLE_TEXT_OUTPUT_MODE;

typedef enum {
  PixelRedGreenBlueReserved8BitPerColor,
  PixelBlueGreenRedReserved8BitPerColor,
  PixelBitMask,
  PixelBltOnly,
  PixelFormatMax
} EFI_GRAPHICS_PIXEL_FORMAT;

typedef struct {
  uint32_t RedMask;
  uint32_t GreenMask;
  uint32_t BlueMask;
  uint32_t ReservedMask;
} EFI_PIXEL_BITMASK;

typedef struct {
  uint32_t Version;
  uint32_t HorizontalResolution;
  uint32_t VerticalResolution;
  EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
  EFI_PIXEL_BITMASK PixelInformation;
  uint32_t PixelsPerScanLine;
} EFI_GRAPHICS_OUTPUT_MODE_INFORMATION;

typedef struct {
  uint8_t Blue;
  uint8_t Green;
  uint8_t Red;
  uint8_t Reserved;
} EFI_GRAPHICS_OUTPUT_BLT_PIXEL;

typedef enum {
  EfiBltVideoFill,
  EfiBltVideoToBltBuffer,
  EfiBltBufferToVideo,
  EfiBltVideoToVideo,
  EfiGraphicsOutputBltOperationMax
} EFI_GRAPHICS_OUTPUT_BLT_OPERATION;

typedef struct {
  uint32_t MaxMode;
  uint32_t Mode;
  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
  uint32_t SizeOfInfo;
  uint64_t FrameBufferBase;
  uint32_t FrameBufferSize;
} EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE;

typedef struct {
  uint64_t Signature;
  uint32_t Revision;
  uint32_t HeaderSize;
  uint32_t CRC32;
  uint32_t Reserved;
} EFI_TABLE_HEADER;

typedef struct {
  uint8_t Type;
  uint8_t SubType;
  uint8_t Length[2];
} EFI_DEVICE_PATH_PROTOCOL;

typedef EFI_STATUS(EFIAPI *EFI_EXIT)(EFI_HANDLE ImageHandle,
                                     EFI_STATUS ExitStatus,
                                     uintptr_t ExitDataSize,
                                     char16_t *opt_ExitData);

typedef EFI_STATUS(EFIAPI *EFI_GET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t *outopt_Attributes,
                                             uintptr_t *inout_DataSize,
                                             void *outopt_Data);
typedef EFI_STATUS(EFIAPI *EFI_SET_VARIABLE)(char16_t *VariableName,
                                             EFI_GUID *VendorGuid,
                                             uint32_t Attributes,
                                             uintptr_t DataSize, void *Data);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME)(
    uintptr_t *inout_VariableNameSize, char16_t *inout_VariableName,
    EFI_GUID *inout_VendorGuid);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_VARIABLE_INFO)(
    uint32_t Attributes, uint64_t *out_MaximumVariableStorageSize,
    uint64_t *out_RemainingVariableStorageSize,
    uint64_t *out_MaximumVariableSize);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_PAGES)(EFI_ALLOCATE_TYPE Type,
                                               EFI_MEMORY_TYPE MemoryType,
                                               uintptr_t Pages,
                                               uint64_t *inout_Memory);
typedef EFI_STATUS(EFIAPI *EFI_FREE_PAGES)(uint64_t Memory, uintptr_t Pages);
typedef EFI_STATUS(EFIAPI *EFI_GET_MEMORY_MAP)(
    uintptr_t *inout_MemoryMapSize, EFI_MEMORY_DESCRIPTOR *inout_MemoryMap,
    uintptr_t *out_MapKey, uintptr_t *out_DescriptorSize,
    uint32_t *out_DescriptorVersion);

typedef EFI_STATUS(EFIAPI *EFI_ALLOCATE_POOL)(EFI_MEMORY_TYPE PoolType,
                                              uintptr_t Size, void *out_Buffer);
typedef EFI_STATUS(EFIAPI *EFI_FREE_POOL)(void *Buffer);
typedef void(EFIAPI *EFI_SET_MEM)(void *Buffer, uintptr_t Size, uint8_t Value);
typedef void(EFIAPI *EFI_COPY_MEM)(void *Destination, void *Source,
                                   uintptr_t Length);

typedef EFI_STATUS(EFIAPI *EFI_CHECK_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_CLOSE_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_SIGNAL_EVENT)(EFI_EVENT Event);
typedef EFI_STATUS(EFIAPI *EFI_WAIT_FOR_EVENT)(uintptr_t NumberOfEvents,
                                               EFI_EVENT *Events,
                                               uintptr_t *out_Index);
typedef EFI_STATUS(EFIAPI *EFI_SET_TIMER)(EFI_EVENT Event, EFI_TIMER_DELAY Type,
                                          uint64_t TriggerTime);
typedef void(EFIAPI *EFI_EVENT_NOTIFY)(EFI_EVENT Event, void *Context);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT)(uint32_t Type, uintptr_t NotifyTpl,
                                             EFI_EVENT_NOTIFY NotifyFunction,
                                             void *NotifyContext,
                                             EFI_EVENT *out_Event);
typedef EFI_STATUS(EFIAPI *EFI_CREATE_EVENT_EX)(
    uint32_t Type, uintptr_t NotifyTpl, EFI_EVENT_NOTIFY opt_NotifyFunction,
    const void *opt_NotifyContext, const EFI_GUID *opt_EventGroup,
    EFI_EVENT *out_Event);

typedef EFI_STATUS(EFIAPI *EFI_UPDATE_CAPSULE)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t opt_ScatterGatherList);
typedef EFI_STATUS(EFIAPI *EFI_QUERY_CAPSULE_CAPABILITIES)(
    EFI_CAPSULE_HEADER **CapsuleHeaderArray, uintptr_t CapsuleCount,
    uint64_t *out_MaximumCapsuleSize, EFI_RESET_TYPE *out_ResetType);
typedef EFI_STATUS(EFIAPI *EFI_GET_WAKEUP_TIME)(bool32 *out_Enabled,
                                                bool32 *out_Pending,
                                                EFI_TIME *out_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WAKEUP_TIME)(bool32 Enable,
                                                EFI_TIME *opt_Time);
typedef EFI_STATUS(EFIAPI *EFI_SET_WATCHDOG_TIMER)(uintptr_t Timeout,
                                                   uint64_t WatchdogCode,
                                                   uintptr_t DataSize,
                                                   char16_t *opt_WatchdogData);
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)(EFI_GUID *Protocol,
                                                void *Registration,
                                                void *Interface);

typedef EFI_STATUS(EFIAPI *EFI_SET_TIME)(EFI_TIME *Time);
typedef EFI_STATUS(EFIAPI *EFI_GET_TIME)(
    EFI_TIME *out_Time, EFI_TIME_CAPABILITIES *outopt_Capabilities);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT)(
    uint32_t *out_HighCount);
typedef EFI_STATUS(EFIAPI *EFI_STALL)(uintptr_t Microseconds);
typedef EFI_STATUS(EFIAPI *EFI_GET_NEXT_MONOTONIC_COUNT)(uint64_t *out_Count);

typedef EFI_STATUS(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP)(
    uintptr_t MemoryMapSize, uintptr_t DescriptorSize,
    uint32_t DescriptorVersion, EFI_MEMORY_DESCRIPTOR *VirtualMap);
typedef void(EFIAPI *EFI_RESET_SYSTEM)(EFI_RESET_TYPE ResetType,
                                       EFI_STATUS ResetStatus,
                                       uintptr_t DataSize, void *opt_ResetData);
typedef EFI_STATUS(EFIAPI *EFI_CONVERT_POINTER)(uintptr_t DebugDisposition,
                                                void **inout_Address);

typedef EFI_STATUS(EFIAPI *EFI_INPUT_RESET)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_INPUT_READ_KEY)(
    EFI_SIMPLE_TEXT_INPUT_PROTOCOL *This, EFI_INPUT_KEY *out_Key);

typedef EFI_STATUS(EFIAPI *EFI_TEXT_RESET)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 ExtendedVerification);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_TEST_STRING)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, char16_t *String);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_QUERY_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber,
    uint64_t *out_Columns, uint64_t *out_Rows);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_MODE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_ATTRIBUTE)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Attribute);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_CLEAR_SCREEN)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_SET_CURSOR_POSITION)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, uint64_t Column, uint64_t Row);
typedef EFI_STATUS(EFIAPI *EFI_TEXT_ENABLE_CURSOR)(
    EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *This, bool32 Visible);

typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber,
    uint32_t *SizeOfInfo, EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This, uint32_t ModeNumber);
typedef EFI_STATUS(EFIAPI *EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT)(
    EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
    EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer,
    EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, uint32_t SourceX,
    uint32_t SourceY, uint32_t DestinationX, uint32_t DestinationY,
    uint32_t Width, uint32_t Height, uint32_t Delta);

typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(EFI_HANDLE Handle,
                                                EFI_GUID *Protocol,
                                                void *out_Interface);

typedef EFI_STATUS(EFIAPI *EFI_IMAGE_LOAD)(bool32 BootPolicy,
                                           EFI_HANDLE ParentImageHandle,
                                           EFI_DEVICE_PATH_PROTOCOL *DevicePath,
                                           void *opt_SourceBuffer,
                                           uintptr_t SourceSize,
                                           EFI_HANDLE *out_ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_IMAGE_UNLOAD)(EFI_HANDLE ImageHandle);
typedef EFI_STATUS(EFIAPI *EFI_EXIT_BOOT_SERVICES)(EFI_HANDLE ImageHandle,
                                                   uintptr_t MapKey);

typedef struct {
  EFI_TABLE_HEADER Hdr;
  EFI_GET_TIME GetTime;
  EFI_SET_TIME SetTime;
  EFI_GET_WAKEUP_TIME GetWakeupTime;
  EFI_SET_WAKEUP_TIME SetWakeupTime;
  EFI_SET_VIRTUAL_ADDRESS_MAP SetVirtualAddressMap;
  EFI_CONVERT_POINTER ConvertPointer;
  EFI_GET_VARIABLE GetVariable;
  EFI_GET_NEXT_VARIABLE_NAME GetNextVariableName;
  EFI_SET_VARIABLE SetVariable;
  EFI_GET_NEXT_HIGH_MONO_COUNT GetNextHighMonotonicCount;
  EFI_RESET_SYSTEM ResetSystem;
  EFI_UPDATE_CAPSULE UpdateCapsule;
  EFI_QUERY_CAPSULE_CAPABILITIES QueryCapsuleCapabilities;
  EFI_QUERY_VARIABLE_INFO QueryVariableInfo;
} EFI_RUNTIME_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  void *RaiseTPL;
  void *RestoreTPL;
  EFI_ALLOCATE_PAGES AllocatePages;
  EFI_FREE_PAGES FreePages;
  EFI_GET_MEMORY_MAP GetMemoryMap;
  EFI_ALLOCATE_POOL AllocatePool;
  EFI_FREE_POOL FreePool;
  EFI_CREATE_EVENT CreateEvent;
  EFI_SET_TIMER SetTimer;
  EFI_WAIT_FOR_EVENT WaitForEvent;
  EFI_SIGNAL_EVENT SignalEvent;
  EFI_CLOSE_EVENT CloseEvent;
  EFI_CHECK_EVENT CheckEvent;
  void *InstallProtocolInterface;
  void *ReinstallProtocolInterface;
  void *UninstallProtocolInterface;
  EFI_HANDLE_PROTOCOL HandleProtocol;
  void *Reserved;
  void *RegisterProtocolNotify;
  void *LocateHandle;
  void *LocateDevicePath;
  void *InstallConfigurationTable;
  EFI_IMAGE_LOAD LoadImage;
  void *StartImage;
  EFI_EXIT Exit;
  EFI_IMAGE_UNLOAD UnloadImage;
  EFI_EXIT_BOOT_SERVICES ExitBootServices;
  EFI_GET_NEXT_MONOTONIC_COUNT GetNextMonotonicCount;
  EFI_STALL Stall;
  EFI_SET_WATCHDOG_TIMER SetWatchdogTimer;
  void *ConnectController;
  void *DisconnectController;
  void *OpenProtocol;
  void *CloseProtocol;
  void *OpenProtocolInformation;
  void *ProtocolsPerHandle;
  void *LocateHandleBuffer;
  EFI_LOCATE_PROTOCOL LocateProtocol;
  void *InstallMultipleProtocolInterfaces;
  void *UninstallMultipleProtocolInterfaces;
  void *CalculateCrc32;
  EFI_COPY_MEM CopyMem;
  EFI_SET_MEM SetMem;
  EFI_CREATE_EVENT_EX CreateEventEx;
} EFI_BOOT_SERVICES;

typedef struct {
  EFI_TABLE_HEADER Hdr;
  char16_t *FirmwareVendor;
  uint32_t FirmwareRevision;
  EFI_HANDLE ConsoleInHandle;
  EFI_SIMPLE_TEXT_INPUT_PROTOCOL *ConIn;
  EFI_HANDLE ConsoleOutHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *ConOut;
  EFI_HANDLE StandardErrorHandle;
  EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *StdErr;
  EFI_RUNTIME_SERVICES *RuntimeServices;
  EFI_BOOT_SERVICES *BootServices;
  uintptr_t NumberOfTableEntries;
  EFI_CONFIGURATION_TABLE *ConfigurationTable;
} EFI_SYSTEM_TABLE;

struct _EFI_SIMPLE_TEXT_INPUT_PROTOCOL {
  EFI_INPUT_RESET Reset;
  EFI_INPUT_READ_KEY ReadKeyStroke;
  EFI_EVENT WaitForKey;
};

struct _EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL {
  EFI_TEXT_RESET Reset;
  EFI_TEXT_STRING OutputString;
  EFI_TEXT_TEST_STRING TestString;
  EFI_TEXT_QUERY_MODE QueryMode;
  EFI_TEXT_SET_MODE SetMode;
  EFI_TEXT_SET_ATTRIBUTE SetAttribute;
  EFI_TEXT_CLEAR_SCREEN ClearScreen;
  EFI_TEXT_SET_CURSOR_POSITION SetCursorPosition;
  EFI_TEXT_ENABLE_CURSOR EnableCursor;
  EFI_SIMPLE_TEXT_OUTPUT_MODE *Mode;
};

struct _EFI_GRAPHICS_OUTPUT_PROTOCOL {
  EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT Blt;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *Mode;
};

typedef struct {
  uint32_t Revision;
  EFI_HANDLE ParentHandle;
  EFI_SYSTEM_TABLE *SystemTable;
  EFI_HANDLE DeviceHandle;
  EFI_DEVICE_PATH_PROTOCOL *FilePath;
  void *Reserved;
  uint32_t LoadOptionsSize;
  void *LoadOptions;
  void *ImageBase;
  uint64_t ImageSize;
  EFI_MEMORY_TYPE ImageCodeType;
  EFI_MEMORY_TYPE ImageDataType;
  EFI_IMAGE_UNLOAD Unload;
} EFI_LOADED_IMAGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/events.h */

#define COSMOPOLITAN_LIBC_NT_EVENTS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » events                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int32_t GetMessage(struct NtMsg *lpMsg, int64_t hWnd, uint32_t wMsgFilterMin,
                   uint32_t wMsgFilterMax);
int32_t TranslateMessage(const struct NtMsg *lpMsg);
intptr_t DispatchMessage(const struct NtMsg *lpMsg);
void PostQuitMessage(int nExitCode);
bool32 GetCursorPos(struct NtPoint *lpPoint);
int64_t SendMessage(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                    int64_t lParam);

#define EVENTLOG_SUCCESS          0x00000000
#define EVENTLOG_ERROR_TYPE       0x00000001
#define EVENTLOG_WARNING_TYPE     0x00000002
#define EVENTLOG_INFORMATION_TYPE 0x00000004
#define EVENTLOG_AUDIT_SUCCESS    0x00000008
#define EVENTLOG_AUDIT_FAILURE    0x00000010

int32_t ReportEventA(int64_t handle, uint16_t wType, uint16_t wCategory,
                     uint32_t dwEventID, const char *lpUserId,
                     uint16_t wNumStrings, uint32_t dwDataSize,
                     const char **lpStrings, void **lpRawData);
int64_t RegisterEventSource(const char16_t *lpUNCServerName,
                            const char16_t *lpSourceName);
int32_t DeregisterEventSource(uint64_t handle);

int64_t CreateEvent(const struct NtSecurityAttributes *opt_lpEventAttributes,
                    bool32 bManualReset, bool32 bInitialState,
                    const char16_t *opt_lpName);
int64_t CreateEventA(const struct NtSecurityAttributes *opt_lpEventAttributes,
                     bool32 bManualReset, bool32 bInitialState,
                     const char *opt_lpName);
int64_t CreateEventEx(const struct NtSecurityAttributes *lpEventAttributes,
                      const char16_t *lpName, uint32_t dwFlags,
                      uint32_t dwDesiredAccess);

int32_t SetEvent(int64_t hEvent);
int32_t ResetEvent(int64_t hEvent);
int32_t PulseEvent(int64_t hEvent);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/files.h */

#define COSMOPOLITAN_LIBC_NT_FILES_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » files                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtHandleFlagInherit          1 /* SetHandleInformation */
#define kNtHandleFlagProtectFromClose 2

#define kNtFindFirstExCaseSensitive 1
#define kNtFindFirstExLargeFetch    2

#define kNtDuplicateCloseSource 1
#define kNtDuplicateSameAccess  2

COSMOPOLITAN_C_START_

intptr_t LoadResource(int64_t hModule, int64_t hResInfo);
uint32_t SetHandleCount(uint32_t uNumber);
uint32_t GetLogicalDrives(void);
bool32 FlushFileBuffers(int64_t hFile);

int64_t ReOpenFile(int64_t hOriginalFile, uint32_t dwDesiredAccess,
                   uint32_t dwShareMode, uint32_t dwFlagsAndAttributes);

bool32 DeleteFile(const char16_t *lpFileName) paramsnonnull();

bool32 CopyFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName, bool32 bFailIfExists)
    paramsnonnull();

bool32 MoveFile(const char16_t *lpExistingFileName,
                const char16_t *lpNewFileName) paramsnonnull();
bool32 MoveFileEx(const char16_t *lpExistingFileName,
                  const char16_t *opt_lpNewFileName, int dwFlags)
    paramsnonnull((1));

bool32 SetCurrentDirectory(const char16_t *lpPathName);
uint32_t GetCurrentDirectory(uint32_t nBufferLength, char16_t *out_lpBuffer);

bool32 CreateDirectory(const char16_t *lpPathName,
                       const struct NtSecurityAttributes *lpSecurityAttributes);
bool32 RemoveDirectory(const char16_t *lpPathName);

bool32 DuplicateHandle(int64_t hSourceProcessHandle, int64_t hSourceHandle,
                       int64_t hTargetProcessHandle, int64_t *lpTargetHandle,
                       uint32_t dwDesiredAccess, bool32 bInheritHandle,
                       uint32_t dwOptions);

bool32 GetHandleInformation(int64_t hObject, uint32_t *out_lpdwFlags);
bool32 SetHandleInformation(int64_t hObject, uint32_t dwMask, uint32_t dwFlags);
int GetFileType(int64_t hFile);

bool32 GetFileInformationByHandleEx(int64_t hFile,
                                    uint32_t FileInformationClass,
                                    void *out_lpFileInformation,
                                    uint32_t dwBufferSize);

bool32 GetFileInformationByHandle(
    int64_t hFile, struct NtByHandleFileInformation *lpFileInformation);
bool32 SetFileInformationByHandle(int64_t hFile, int FileInformationClass,
                                  const void *lpFileInformation,
                                  uint32_t dwBufferSize);

uint32_t GetFileAttributes(const char16_t *lpFileName);
bool32 GetFileAttributesEx(
    const char16_t *lpFileName, int fInfoLevelId /* kNtGetFileExInfoStandard */,
    void *out_lpFileInformation /* → struct NtWin32FileAttributeData * */)
    paramsnonnull();

uint32_t GetCompressedFileSize(const char16_t *lpFileName,
                               uint32_t *lpFileSizeHigh);
bool32 SetFileAttributes(const char16_t *lpFileName, uint32_t dwFileAttributes);
bool32 GetFileTime(int64_t hFile, struct NtFileTime *opt_lpCreationFileTime,
                   struct NtFileTime *opt_lpLastAccessFileTime,
                   struct NtFileTime *opt_lpLastWriteFileTime);
bool32 SetFileTime(int64_t hFile,
                   const struct NtFileTime *opt_lpCreationFileTime,
                   const struct NtFileTime *opt_lpLastAccessFileTime,
                   const struct NtFileTime *opt_lpLastWriteFileTime);

bool32 DeviceIoControl(int64_t hDevice, uint32_t dwIoControlCode,
                       void *lpInBuffer, uint32_t nInBufferSize,
                       void *lpOutBuffer, uint32_t nOutBufferSize,
                       uint32_t *lpBytesReturned,
                       struct NtOverlapped *lpOverlapped);

bool32 LockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToLockLow,
                uint32_t nNumberOfBytesToLockHigh);
bool32 UnlockFile(int64_t hFile, uint32_t dwFileOffsetLow,
                  uint32_t dwFileOffsetHigh, uint32_t nNumberOfBytesToUnlockLow,
                  uint32_t nNumberOfBytesToUnlockHigh);
bool32 LockFileEx(int64_t hFile, uint32_t dwFlags, uint32_t dwReserved,
                  uint32_t nNumberOfBytesToLockLow,
                  uint32_t nNumberOfBytesToLockHigh,
                  struct NtOverlapped *lpOverlapped) paramsnonnull();
bool32 UnlockFileEx(int64_t hFile, uint32_t dwReserved,
                    uint32_t nNumberOfBytesToUnlockLow,
                    uint32_t nNumberOfBytesToUnlockHigh,
                    struct NtOverlapped *lpOverlapped) paramsnonnull();

bool32 CreateHardLink(const char16_t *lpFileName,
                      const char16_t *lpExistingFileName,
                      const struct NtSecurityAttributes *reserved)
    paramsnonnull((1, 2));
bool32 CreateSymbolicLink(const char16_t *lpSymlinkFileName,
                          const char16_t *lpTargetPathName, uint32_t dwFlags)
    paramsnonnull();

bool32 SetEndOfFile(int64_t hFile);
bool32 SetFileValidData(int64_t hFile, int64_t ValidDataLength);

bool32 GetFileSecurity(const char16_t *lpFileName,
                       uint32_t RequestedInformation,
                       struct NtSecurityDescriptor *pSecurityDescriptor,
                       uint32_t nLength, uint32_t *lpnLengthNeeded);

bool32 OpenProcessToken(int64_t hProcessHandle, uint32_t dwDesiredAccess,
                        int64_t *out_hTokenHandle);
bool32 DuplicateToken(int64_t hExistingTokenHandle, int dwImpersonationLevel,
                      int64_t *out_hDuplicateTokenHandle);
bool32 DuplicateTokenEx(int64_t hExistingToken, unsigned int dwDesiredAccess,
                        const struct NtSecurityAttributes *lpTokenAttributes,
                        int ImpersonationLevel, int TokenType,
                        int64_t *out_phNewToken);

bool32 AccessCheck(struct NtSecurityDescriptor *pSecurityDescriptor,
                   int64_t ClientToken, unsigned int DesiredAccess,
                   struct NtGenericMapping *lpGenericMapping,
                   struct NtPrivilegeSet *lpPrivilegeSet,
                   unsigned int *PrivilegeSetLength,
                   unsigned int *GrantedAccess, bool32 *AccessStatus);

void MapGenericMask(uint32_t *AccessMask,
                    struct NtGenericMapping *GenericMapping);

int64_t FindFirstFile(const char16_t *lpFileName,
                      struct NtWin32FindData *out_lpFindFileData);
int64_t FindFirstFileEx(const char16_t *lpFileName, int fInfoLevelId,
                        void *out_lpFindFileData, int fSearchOp,
                        void *reserved_lpSearchFilter,
                        uint32_t dwAdditionalFlags);
bool32 FindNextFile(int64_t hFindFile,
                    struct NtWin32FindData *out_lpFindFileData);
bool32 FindClose(int64_t hFindFile);

int64_t FindFirstVolume(char16_t *out_lpszVolumeName, uint32_t cchBufferLength);
bool32 FindNextVolume(int64_t inout_hFindVolume, char16_t *out_lpszVolumeName,
                      uint32_t cchBufferLength);
bool32 FindVolumeClose(int64_t hFindVolume);

bool32 ReadFileScatter(
    int64_t hFileOpenedWithOverlappedAndNoBuffering,
    const union NtFileSegmentElement
        aNullTerminatedPageAlignedSizedSegmentArray[],
    uint32_t nNumberOfBytesToReadThatsMultipleOfFileVolumeSectorSize,
    uint32_t *lpReserved, struct NtOverlapped *inout_lpOverlapped)
    paramsnonnull();

bool32 WriteFileGather(int64_t hFileOpenedWithOverlappedAndNoBuffering,
                       const union NtFileSegmentElement aSegmentArray[],
                       uint32_t nNumberOfBytesToWrite, uint32_t *lpReserved,
                       struct NtOverlapped inout_lpOverlapped) paramsnonnull();

#define kNtFileNameNormalized 0x0
#define kNtFileNameOpened     0x8
#define kNtVolumeNameDos      0x0 /* e.g. \\?\C:\Users\jart */
#define kNtVolumeNameGuid     0x1 /* e.g. \\?\Volume{ea38-etc.}\Users\jart */
#define kNtVolumeNameNt       0x2 /* e.g. \Device\HarddiskVolume4\Users\jart */
#define kNtVolumeNameNone     0x4 /* e.g. \Users\jart */
uint32_t GetFinalPathNameByHandle(int64_t hFile, char16_t *out_path,
                                  uint32_t arraylen, uint32_t flags);

uint32_t GetFullPathName(const char16_t *lpFileName, uint32_t nBufferLength,
                         char16_t *lpBuffer, char16_t **lpFilePart);

bool32 GetOverlappedResult(int64_t hFile, struct NtOverlapped *lpOverlapped,
                           uint32_t *lpNumberOfBytesTransferred, bool32 bWait);
bool32 GetOverlappedResultEx(int64_t hFile, struct NtOverlapped *lpOverlapped,
                             uint32_t *lpNumberOfBytesTransferred,
                             uint32_t dwMilliseconds, bool32 bAlertable);

bool32 GetVolumePathName(const char16_t *lpszFileName,
                         char16_t *lpszVolumePathName,
                         uint32_t cchBufferLength);

bool32 GetVolumeInformationByHandle(int64_t hFile,
                                    char16_t *opt_out_lpVolumeNameBuffer,
                                    uint32_t nVolumeNameSize,
                                    uint32_t *opt_out_lpVolumeSerialNumber,
                                    uint32_t *opt_out_lpMaximumComponentLength,
                                    uint32_t *opt_out_lpFileSystemFlags,
                                    char16_t *opt_out_lpFileSystemNameBuffer,
                                    uint32_t nFileSystemNameSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/files.inc */

#define CopyFile(...) __imp_CopyFileW(__VA_ARGS__)
extern typeof(CopyFile) *const __imp_CopyFileW __msabi;

#define GetFileType(...) __imp_GetFileType(__VA_ARGS__)
extern typeof(GetFileType) *const __imp_GetFileType __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iocp.h */

#define COSMOPOLITAN_LIBC_NT_IOCP_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » i/o completion ports                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtFileSkipCompletionPortOnSuccess 1
#define kNtFileSkipSetEventOnHandle        2

COSMOPOLITAN_C_START_

typedef void (*NtOverlappedCompletionRoutine)(
    uint32_t dwErrorCode, uint32_t dwNumberOfBytesTransfered,
    struct NtOverlapped *inout_lpOverlapped);

int64_t CreateIoCompletionPort(int64_t FileHandleOrNeg1,
                               int64_t opt_ExistingCompletionPortOrZero,
                               uint64_t CompletionKey,
                               uint32_t NumberOfConcurrentThreads);

bool32 GetQueuedCompletionStatus(int64_t CompletionPort,
                                 uint32_t *lpNumberOfBytesTransferred,
                                 uint64_t *out_lpCompletionKey,
                                 struct NtOverlapped **out_lpOverlapped,
                                 uint32_t dwMilliseconds);

bool32 GetQueuedCompletionStatusEx(
    int64_t CompletionPort,
    struct NtOverlappedEntry *out_lpCompletionPortEntries, uint32_t ulCount,
    uint32_t *out_ulNumEntriesRemoved, uint32_t dwMilliseconds,
    bool32 fAlertable);

bool32 PostQueuedCompletionStatus(int64_t CompletionPort,
                                  uint32_t dwNumberOfBytesTransferred,
                                  uint64_t dwCompletionKey,
                                  struct NtOverlapped *opt_lpOverlapped);

bool32 SetFileCompletionNotificationModes(int64_t FileHandle,
                                          unsigned char Flags);

bool32 ReadFileEx(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                  uint32_t *lpNumberOfBytesRead,
                  struct NtOverlapped *opt_lpOverlapped,
                  NtOverlappedCompletionRoutine lpCompletionRoutine);

bool32 WriteFileEx(int64_t hFile, const void *lpBuffer,
                   uint32_t nNumberOfBytesToWrite,
                   struct NtOverlapped *lpOverlapped,
                   NtOverlappedCompletionRoutine lpCompletionRoutine);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ipc.h */

#define COSMOPOLITAN_LIBC_NT_IPC_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ipc                                      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/* CreateNamedPipe:dwOpenMode */
#define kNtPipeAccessInbound  0x00000001
#define kNtPipeAccessOutbound 0x00000002
#define kNtPipeAccessDuplex   0x00000003

/* CreateNamedPipe::dwPipeMode */
#define kNtPipeWait                0x00000000
#define kNtPipeNowait              0x00000001
#define kNtPipeReadmodeByte        0x00000000
#define kNtPipeReadmodeMessage     0x00000002
#define kNtPipeTypeByte            0x00000000
#define kNtPipeTypeMessage         0x00000004
#define kNtPipeAcceptRemoteClients 0x00000000
#define kNtPipeRejectRemoteClients 0x00000008

/* CreateNamedPipe::nMaxInstances */
#define kNtPipeUnlimitedInstances 255

/* GetNamedPipeInfo */
#define kNtPipeClientEnd 0x00000000
#define kNtPipeServerEnd 0x00000001

COSMOPOLITAN_C_START_

bool32 CreatePipe(int64_t *out_hReadPipe, int64_t *out_hWritePipe,
                  const struct NtSecurityAttributes *opt_lpPipeAttributes,
                  uint32_t nSize) paramsnonnull((1, 2));

int64_t CreateNamedPipe(
    const char16_t *lpName, uint32_t dwOpenMode, uint32_t dwPipeMode,
    uint32_t nMaxInstances, uint32_t nOutBufferSize, uint32_t nInBufferSize,
    uint32_t nDefaultTimeOut,
    const struct NtSecurityAttributes *opt_lpSecurityAttributes)
    paramsnonnull((1));

bool32 CallNamedPipe(const char16_t *lpNamedPipeName, void *lpInBuffer,
                     uint32_t nInBufferSize, void *lpOutBuffer,
                     uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                     uint32_t nTimeOut);

bool32 ConnectNamedPipe(int64_t hNamedPipe, struct NtOverlapped *lpOverlapped);
bool32 WaitNamedPipe(const char16_t *lpNamedPipeName, uint32_t nTimeOut);
bool32 DisconnectNamedPipe(int64_t hNamedPipe);

bool32 SetNamedPipeHandleState(int64_t hNamedPipe, uint32_t *lpMode,
                               uint32_t *lpMaxCollectionCount,
                               uint32_t *lpCollectDataTimeout);

bool32 PeekNamedPipe(int64_t hNamedPipe, void *lpBuffer, uint32_t nBufferSize,
                     uint32_t *opt_lpBytesRead, uint32_t *opt_lpTotalBytesAvail,
                     uint32_t *opt_lpBytesLeftThisMessage);

bool32 TransactNamedPipe(int64_t hNamedPipe, void *lpInBuffer,
                         uint32_t nInBufferSize, void *lpOutBuffer,
                         uint32_t nOutBufferSize, uint32_t *lpBytesRead,
                         struct NtOverlapped *lpOverlapped);

bool32 GetNamedPipeInfo(int64_t hNamedPipe, uint32_t *opt_out_lpFlags,
                        uint32_t *opt_out_lpOutBufferSize,
                        uint32_t *opt_out_lpInBufferSize,
                        uint32_t *opt_out_lpMaxInstances);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/iphlpapi.h */

#define COSMOPOLITAN_LIBC_NT_IPHLPAPI_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » ip helper api                            ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetAdaptersAddresses(uint32_t Family, uint32_t Flags, void *Reserved,
                              struct NtIpAdapterAddresses *AdapterAddresses,
                              uint32_t *SizePointer);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/memory.h */

#define COSMOPOLITAN_LIBC_NT_MEMORY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » memory                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtNumaNoPreferredNode 0xffffffffu

COSMOPOLITAN_C_START_

void *LocalFree(void *hMem);

int64_t CreateFileMapping(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName);
int64_t CreateFileMappingNuma(
    int64_t opt_hFile,
    const struct NtSecurityAttributes *opt_lpFileMappingAttributes,
    uint32_t flProtect, uint32_t dwMaximumSizeHigh, uint32_t dwMaximumSizeLow,
    const char16_t *opt_lpName, uint32_t nndDesiredNumaNode);

void *MapViewOfFileEx(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                      uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                      size_t dwNumberOfBytesToMap,
                      void *opt_lpDesiredBaseAddress);
void *MapViewOfFileExNuma(int64_t hFileMappingObject, uint32_t dwDesiredAccess,
                          uint32_t dwFileOffsetHigh, uint32_t dwFileOffsetLow,
                          size_t dwNumberOfBytesToMap,
                          void *opt_lpDesiredBaseAddress,
                          uint32_t nndDesiredNumaNode);

bool32 UnmapViewOfFile(const void *lpBaseAddress);
bool32 FlushViewOfFile(const void *lpBaseAddress,
                       size_t dwNumberOfBytesToFlush);

void *VirtualAlloc(void *opt_lpAddress, uint64_t dwSize,
                   uint32_t flAllocationType, uint32_t flProtect);
bool32 VirtualFree(void *lpAddress, uint64_t dwSize, uint32_t dwFreeType);
bool32 VirtualProtect(void *lpAddress, uint64_t dwSize, uint32_t flNewProtect,
                      uint32_t *lpflOldProtect) paramsnonnull();
bool32 VirtualLock(const void *lpAddress, size_t dwSize);
bool32 VirtualUnlock(const void *lpAddress, size_t dwSize);
uint64_t VirtualQuery(const void *lpAddress,
                      struct NtMemoryBasicInformation *lpBuffer,
                      uint64_t dwLength);
void *VirtualAllocEx(int64_t hProcess, void *lpAddress, uint64_t dwSize,
                     uint32_t flAllocationType, uint32_t flProtect);

int64_t GetProcessHeap(void);
void *HeapAlloc(int64_t hHeap, uint32_t dwFlags, size_t dwBytes) __wur;
bool32 HeapFree(int64_t hHeap, uint32_t dwFlags, void *opt_lpMem);
void *HeapReAlloc(int64_t hHeap, uint32_t dwFlags, void *lpMem,
                  size_t dwBytes) __wur;

void *GlobalAlloc(uint32_t uFlags, uint64_t dwBytes) __wur;
void *GlobalFree(void *hMem);

/**
 * @param AllocationType
 *     - kNtMemReserve
 *     - kNtMemReplacePlaceholder
 *     - kNtMemLargePages
 */
void *MapViewOfFile3(
    intptr_t FileMapping, intptr_t Process, void *opt_BaseAddress,
    uint64_t Offset, size_t ViewSize, unsigned AllocationType,
    unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

void *VirtualAlloc2(
    intptr_t opt_Process, void *opt_BaseAddress, size_t Size,
    unsigned AllocationType, unsigned PageProtection,
    struct NtMemExtendedParameter *in_out_opt_ExtendedParameters,
    unsigned ParameterCount);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/memory.inc */

extern typeof(LocalFree) *const __imp_LocalFree __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/messagebox.h */

#define COSMOPOLITAN_LIBC_NT_MESSAGEBOX_H_
COSMOPOLITAN_C_START_

int MessageBox(int64_t hWnd, const char16_t *lpText, const char16_t *lpCaption,
               uint32_t mbType);
int MessageBoxEx(int64_t hWnd, const char16_t *lpText,
                 const char16_t *lpCaption, uint32_t mbType,
                 uint16_t wLanguageId);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdll.h */

#define COSMOPOLITAN_LIBC_NT_NTDLL_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » beyond the pale                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
    “The functions and structures in [for these APIs] are internal to
     the operating system and subject to change from one release of
     Windows to the next, and possibly even between service packs for
     each release.” ──Quoth MSDN */

#define __nt_system_call_dispatcher (wambda *)0x7ffe0308

extern const struct NtUnicodeString *const RtlNtdllName;

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » eponymous runtime      ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define NT_PROCESS_FLAGS_CREATE_SUSPENDED 0x00000001
#define NT_PROCESS_FLAGS_INHERIT_HANDLES  0x00000002
#define NT_PROCESS_FLAGS_NO_SYNCHRONIZE   0x00000004
#define NT_RTL_CLONE_PARENT               0
#define NT_RTL_CLONE_CHILD                297

NtStatus NtCallbackReturn(void *opt_Result, uint32_t ResultLength,
                          int32_t Status);
NtStatus NtTestAlert(void);

NtStatus NtOpenFile(int64_t *out_FileHandle, uint32_t DesiredAccess,
                    struct NtObjectAttributes *ObjectAttributes,
                    struct NtIoStatusBlock *out_IoStatusBlock,
                    uint32_t ShareAccess, uint32_t OpenOptions);

NtStatus NtQueryInformationToken(int64_t TokenHandle,
                                 uint32_t TokenInformationClass,
                                 void *out_TokenInformation,
                                 uint32_t TokenInformationLength,
                                 uint32_t *out_ReturnLength);
NtStatus NtYieldExecution(void);
NtStatus NtQuerySystemInformation(uint32_t info_class, void *out_info,
                                  uint32_t info_size,
                                  uint32_t *out_bytes_received);
NtStatus NtReadVirtualMemory(int64_t ProcessHandle, const void *BaseAddress,
                             void *out_Buffer, size_t BufferLength,
                             size_t *opt_out_ReturnLength);
NtStatus NtCreateTimer(void **out_TimerHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       uint32_t TimerType);
NtStatus NtSetTimer(void *TimerHandle, int64_t *DueTime, void *TimerApcRoutine,
                    void *TimerContext, int32_t Resume, int32_t Period,
                    int32_t *out_PreviousState);
NtStatus NtQueryObject(void *ObjectHandle, int ObjectInformationClass,
                       void *out_ObjectInformation,
                       uint32_t ObjectInformationLength,
                       uint32_t *opt_out_ReturnLength);
NtStatus NtQueryFullAttributesFile(
    struct NtObjectAttributes *attributes,
    struct NtFileNetworkOpenInformation *out_info);
NtStatus NtCreateKey(void **out_KeyHandle, uint32_t DesiredAccess,
                     struct NtObjectAttributes *ObjectAttributes,
                     uint32_t TitleIndex, struct NtUnicodeString *opt_Class,
                     uint32_t CreateOptions, uint32_t *opt_out_Disposition);
NtStatus NtOpenKey(void **out_KeyHandle, uint32_t DesiredAccess,
                   struct NtObjectAttributes *ObjectAttributes);
NtStatus NtSetValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                       uint32_t opt_TitleIndex, uint32_t Type, void *Data,
                       uint32_t DataSize);
NtStatus NtDeleteKey(void *KeyHandle);
NtStatus NtQueryValueKey(void *KeyHandle, struct NtUnicodeString *ValueName,
                         int KeyValueInformationClass,
                         void *out_KeyValueInformation, uint32_t Length,
                         uint32_t *out_ResultLength);
NtStatus NtFlushKey(void *KeyHandle);
NtStatus NtEnumerateKey(int64_t hkey, uint32_t index, int info_class,
                        void *out_key_info, uint32_t key_info_size,
                        uint32_t *out_bytes_received);
NtStatus NtEnumerateValueKey(int64_t hKey, uint32_t index, int info_class,
                             void *out_key_info, uint32_t key_info_size,
                             uint32_t *out_bytes_received);
NtStatus NtQuerySystemTime(int64_t *SystemTime);
NtStatus NtDeleteFile(struct NtObjectAttributes *ObjectAttributes);
NtStatus NtFlushBuffersFile(int64_t FileHandle,
                            struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateIoCompletion(void **out_IoCompletionHandle,
                              uint32_t DesiredAccess,
                              struct NtObjectAttributes *ObjectAttributes,
                              uint32_t NumberOfConcurrentThreads);
NtStatus NtRaiseHardError(int32_t ErrorStatus, uint32_t NumberOfArguments,
                          uint32_t UnicodeStringArgumentsMask, void *Arguments,
                          uint32_t MessageBoxType,
                          uint32_t *out_MessageBoxResult);
NtStatus NtRaiseException(struct NtExceptionRecord *ExceptionRecord,
                          struct NtContext *Context, int32_t SearchFrames);
NtStatus NtCreateEvent(void **out_EventHandle, uint32_t DesiredAccess,
                       struct NtObjectAttributes *ObjectAttributes,
                       int EventType, int32_t InitialState);
NtStatus NtWaitForSingleObject(void *ObjectHandle, int32_t Alertable,
                               int64_t *TimeOut);
NtStatus NtSetEvent(void *EventHandle, int32_t *opt_out_PreviousState);
NtStatus NtClearEvent(void *EventHandle);
NtStatus NtSignalAndWaitForSingleObject(void *ObjectToSignal,
                                        void *WaitableObject, int32_t Alertable,
                                        int64_t *opt_Time);
NtStatus NtQueryPerformanceCounter(int64_t *out_PerformanceCount,
                                   int64_t *opt_out_PerformanceFrequency);
NtStatus NtFsControlFile(int64_t FileHandle, void *opt_Event,
                         NtIoApcRoutine opt_ApcRoutine, void *opt_ApcContext,
                         struct NtIoStatusBlock *out_IoStatusBlock,
                         uint32_t FsControlCode, void *opt_InputBuffer,
                         uint32_t InputBufferLength, void *opt_out_OutputBuffer,
                         uint32_t OutputBufferLength);
NtStatus NtCancelIoFile(int64_t FileHandle,
                        struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtCreateProfile(void **out_ProfileHandle, int64_t ProcessHandle,
                         void *Base, uint32_t Size, uint32_t BucketShift,
                         uint32_t *Buffer, uint32_t BufferLength, int Source,
                         uint32_t ProcessorMask);
NtStatus NtSetIntervalProfile(uint32_t Interval, int Source);
NtStatus NtQueryIntervalProfile(int Source, uint32_t *out_Interval);
NtStatus NtStartProfile(void *ProfileHandle);
NtStatus NtStopProfile(void *ProfileHandle);
NtStatus NtCreateDirectoryObject(int64_t *out_DirectoryHandle,
                                 uint32_t DesiredAccess,
                                 struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenDirectoryObject(int64_t *out_DirectoryHandle,
                               uint32_t DesiredAccess,
                               struct NtObjectAttributes *ObjectAttributes);
NtStatus NtOpenSymbolicLinkObject(int64_t *out_DirectoryHandle,
                                  uint32_t DesiredAccess,
                                  struct NtObjectAttributes *ObjectAttributes);
NtStatus NtQuerySymbolicLinkObject(int64_t DirectoryHandle,
                                   struct NtUnicodeString *inout_TargetName,
                                   uint32_t *opt_out_ReturnLength);
NtStatus ZwAreMappedFilesTheSame(void *Address1, void *Address2);
NtStatus NtQueryVolumeInformationFile(int64_t FileHandle,
                                      struct NtIoStatusBlock *out_IoStatusBlock,
                                      void *out_FsInformation, uint32_t Length,
                                      uint32_t FsInformationClass);
NtStatus NtQuerySecurityObject(
    int64_t handle, int RequestedInformation,
    struct NtSecurityDescriptor *out_SecurityDescriptor,
    uint32_t SecurityDescriptorLength, uint32_t *out_ReturnLength);
NtStatus NtQueueApcThread(int64_t ThreadHandle, NtPkNormalRoutine ApcRoutine,
                          void *opt_ApcContext, void *opt_Argument1,
                          void *opt_Argument2);
NtStatus NtFlushInstructionCache(int64_t ProcessHandle, void *opt_BaseAddress,
                                 size_t FlushSize);
NtStatus NtQueryAttributesFile(const struct NtObjectAttributes *object,
                               struct NtFileBasicInformation *file_information);
NtStatus NtQueryDirectoryFile(
    int64_t FileHandle, void *opt_Event, NtIoApcRoutine opt_ApcRoutine,
    void *opt_ApcContext, struct NtIoStatusBlock *out_IoStatusBlock,
    void *out_FileInformation, uint32_t FileInformationLength,
    uint32_t FileInformationClass, int32_t ReturnSingleEntry,
    struct NtUnicodeString *opt_FileName, int32_t RestartScan);
NtStatus NtFlushVirtualMemory(int64_t ProcessHandle, void **inout_BaseAddress,
                              uint32_t **inout_FlushSize,
                              struct NtIoStatusBlock *out_IoStatusBlock);
NtStatus NtQueryInformationJobObject(void *JobHandle, int JobInformationClass,
                                     void *out_JobInformation,
                                     uint32_t JobInformationLength,
                                     uint32_t *opt_out_ReturnLength);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » beyond the pale » runtime library        ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

NtStatus RtlInitializeCriticalSection(struct NtCriticalSection *out_crit);
NtStatus RtlDeleteCriticalSection(struct NtCriticalSection *crit);
NtStatus RtlEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlLeaveCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlTryEnterCriticalSection(struct NtCriticalSection *inout_crit);
NtStatus RtlInitUnicodeString(struct NtUnicodeString *inout_DestinationString,
                              const char16_t *SourceString);
void RtlFreeUnicodeString(struct NtUnicodeString **string);
NtStatus RtlQueryEnvironmentVariable_U(char16_t *Environment,
                                       struct NtUnicodeString *Name,
                                       struct NtUnicodeString *Value);
NtStatus RtlConvertSidToUnicodeString(struct NtUnicodeString *out_UnicodeString,
                                      void *Sid,
                                      int32_t AllocateDestinationString);
void *RtlCreateHeap(uint32_t flags, void *base, size_t reserve_sz,
                    size_t commit_sz, void *lock, void *params);
NtStatus RtlDestroyHeap(void *base);
void *RtlAllocateHeap(int64_t heap, uint32_t flags, size_t size);
void *RtlReAllocateHeap(int64_t heap, uint32_t flags, void *ptr, size_t size);
NtStatus RtlFreeHeap(int64_t heap, uint32_t flags, void *ptr);
size_t RtlSizeHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlValidateHeap(int64_t heap, uint32_t flags, void *ptr);
NtStatus RtlLockHeap(int64_t heap);
NtStatus RtlUnlockHeap(int64_t heap);
NtStatus RtlGetProcessHeaps(uint32_t count, void **out_Heaps);
NtStatus RtlWalkHeap(int64_t heap, void *out_Info);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/ntdll.inc */

#define NtYieldExecution(...) __imp_NtYieldExecution(__VA_ARGS__)

extern typeof(NtYieldExecution) *const __imp_NtYieldExecution __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/ntdllimport.h */

/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8     -*-│
│ vi: set noet ft=asm ts=8 sw=8 fenc=utf-8                                 :vi │
╞══════════════════════════════════════════════════════════════════════════════╡
│ Copyright 2020 Justine Alexandra Roberts Tunney                              │
│                                                                              │
│ Permission to use, copy, modify, and/or distribute this software for         │
│ any purpose with or without fee is hereby granted, provided that the         │
│ above copyright notice and this permission notice appear in all copies.      │
│                                                                              │
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL                │
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED                │
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE             │
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL         │
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR        │
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER               │
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR             │
│ PERFORMANCE OF THIS SOFTWARE.                                                │
╚─────────────────────────────────────────────────────────────────────────────*/
#define COSMOPOLITAN_LIBC_NT_NTDLLIMPORT_H_
#ifdef __ASSEMBLER__
/* clang-format off */

.macro	.ntimp	fn:req name:req
#ifdef __x86_64__
	.yoink	_init_ntdll
	.initbss 202,_init_ntdll.\fn
__imp_\fn:
	.quad	0
	.endobj	__imp_\fn,globl,hidden
	.previous
	.initro 202,_init_ntdll.2.\fn
	.quad	RVA(.L\fn)
	.previous
	.section .rodata.str1.1,"aSM",@progbits,1
.L\fn:
	.asciz	"\fn"
	.previous
#elif defined(__aarch64__)
	.section .data.nt.\fn,"aw",@progbits
	.globl	__imp_\fn
	.balign	8
__imp_\fn:
	.quad	\name
	.weak	\name
#endif
.endm

/* clang-format on */
#endif /* __ASSEMBLER__ */


/*!BEGIN libc/nt/paint.h */

#define COSMOPOLITAN_LIBC_NT_PAINT_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § new technology » cpu graphics                             ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t BeginPaint(int64_t hWnd, struct NtPaintStruct *lpPaint);
int32_t EndPaint(int64_t hWnd, const struct NtPaintStruct *lpPaint);
int32_t BitBlt(int64_t hdc, int x, int y, int cx, int cy, int64_t hdcSrc,
               int x1, int y1, uint32_t rop);
int32_t GetClientRect(int64_t hWnd, struct NtRect *lpRect);
int32_t GetWindowRect(int64_t hWnd, struct NtRect *lpRect);
int32_t SetBkMode(int64_t hdc, int mode);
uint32_t SetTextColor(int64_t hdc, uint32_t color);
uint32_t SetTextAlign(int64_t hdc, uint32_t align);
int32_t SetTextJustification(int64_t hdc, int extra, int count);
int32_t DrawText(int64_t hdc, const char16_t *lpchText, int cchText,
                 struct NtRect *lprc, uint32_t format);
int32_t DrawTextEx(int64_t hdc, char16_t *lpchText, int cchText,
                   struct NtRect *lprc, uint32_t format,
                   struct NtDrawTextParams *lpdtp);
int32_t FillRect(int64_t hDC, const struct NtRect *lpRC, int64_t hBrush);
uint32_t GetPixel(int64_t hdc, int x, int y);
uint32_t SetPixel(int64_t hdc, int x, int y, uint32_t color);
bool32 RedrawWindow(int64_t hWnd, const struct NtRect *opt_lprcUpdate,
                    int64_t opt_hrgnUpdate, uint32_t rdwFlags);
int64_t CreateCompatibleDC(int64_t hdc);
int64_t CreateCompatibleBitmap(int64_t hdc, int cx, int cy);
int64_t SelectObject(int64_t hdc, int64_t h);
bool32 DeleteObject(int64_t ho);
bool32 DeleteDC(int64_t hdc);
int SaveDC(int64_t hdc);
bool32 RestoreDC(int64_t hdc, int nSavedDC);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/paint.inc */

#define SetPixel(...) __imp_SetPixel(__VA_ARGS__)
#define GetPixel(...) __imp_GetPixel(__VA_ARGS__)

extern typeof(SetPixel) *const __imp_SetPixel __msabi;
extern typeof(GetPixel) *const __imp_GetPixel __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/pdh.h */

#define COSMOPOLITAN_LIBC_NT_PDH_H_

/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » performance counters                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

int PdhOpenQuery(const char16_t *opt_szDataSource, uint32_t *dwUserData,
                 int64_t *out_phQuery);

int PdhAddEnglishCounter(int64_t hQuery, const char16_t *szFullCounterPath,
                         uint32_t *dwUserData, int64_t *out_phCounter);

int PdhCollectQueryDataEx(int64_t hQuery, uint32_t dwIntervalTime,
                          int64_t hNewDataEvent);

int PdhGetFormattedCounterValue(int64_t hCounter, uint32_t dwFormat,
                                uint32_t *out_opt_lpdwType,
                                struct NtPdhFmtCountervalue *out_pValue);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/privilege.h */

#define COSMOPOLITAN_LIBC_NT_PRIVILEGE_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » check your privilege                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtSePrivilegeEnabledByDefault 0x00000001u
#define kNtSePrivilegeEnabled          0x00000002u
#define kNtSePrivilegeRemoved          0x00000004u
#define kNtSePrivilegeUsedForAccess    0x80000000u

COSMOPOLITAN_C_START_

bool32 LookupPrivilegeValue(const char16_t *opt_lpSystemName,
                            const char16_t *lpName, struct NtLuid *out_lpLuid);

bool32 AdjustTokenPrivileges(int64_t TokenHandle, bool32 DisableAllPrivileges,
                             const struct NtTokenPrivileges *opt_NewState,
                             uint32_t BufferLength,
                             struct NtTokenPrivileges *opt_out_PreviousState,
                             uint32_t *opt_out_ReturnLength);

bool32 ImpersonateSelf(int kNtSecurityImpersonationLevel);
bool32 RevertToSelf(void);

bool32 OpenThreadToken(intptr_t ThreadHandle, uint32_t DesiredAccess,
                       bool32 OpenAsSelf, intptr_t *TokenHandle);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/process.h */

#define COSMOPOLITAN_LIBC_NT_PROCESS_H_


/*!BEGIN libc/nt/startupinfo.h */

#define COSMOPOLITAN_LIBC_NT_NTSTARTUPINFO_H_
COSMOPOLITAN_C_START_

#define kNtProcThreadAttributeParentProcess 0x00020000
#define kNtProcThreadAttributeHandleList    0x00020002

void GetStartupInfo(struct NtStartupInfo *lpStartupInfo);

bool32 InitializeProcThreadAttributeList(
    struct NtProcThreadAttributeList *opt_inout_lpAttributeList,
    uint32_t dwAttributeCount, uint32_t reserved_dwFlags, size_t *inout_lpSize);
bool32 UpdateProcThreadAttribute(
    struct NtProcThreadAttributeList *inout_lpAttributeList, uint32_t dwFlags,
    uint64_t Attribute, const void *lpValue, size_t cbSize,
    void *reserved_lpPreviousValue, size_t *reserved_lpReturnSize);
void DeleteProcThreadAttributeList(
    struct NtProcThreadAttributeList *inout_lpAttributeList);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/startupinfo.inc */

#define GetStartupInfo(...) __imp_GetStartupInfoW(__VA_ARGS__)

extern typeof(GetStartupInfo) *const __imp_GetStartupInfoW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » processes                                ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

bool32 CreateProcess(const char16_t *opt_lpApplicationName,
                     char16_t *lpCommandLine,
                     const struct NtSecurityAttributes *opt_lpProcessAttributes,
                     const struct NtSecurityAttributes *opt_lpThreadAttributes,
                     bool32 bInheritHandles, uint32_t dwCreationFlags,
                     void *opt_lpEnvironment,
                     const char16_t *opt_lpCurrentDirectory,
                     const struct NtStartupInfo *lpStartupInfo,
                     struct NtProcessInformation *opt_out_lpProcessInformation)
    paramsnonnull((9));

uint32_t GetThreadId(int64_t hThread);   /* cf. NT_TID */
uint32_t GetProcessId(int64_t hProcess); /* cf. NT_PID */
void SetLastError(uint32_t dwErrCode);
uint32_t FormatMessage(uint32_t dwFlags, const void *lpSource,
                       uint32_t dwMessageId, uint32_t dwLanguageId,
                       char16_t *lpBuffer, uint32_t nSize, va_list *Arguments);
uint32_t FormatMessageA(uint32_t dwFlags, const void *lpSource,
                        uint32_t dwMessageId, uint32_t dwLanguageId,
                        char *lpBuffer, uint32_t nSize, va_list *Arguments);
int64_t OpenProcess(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                    uint32_t dwProcessId);
uint32_t GetCurrentProcessId(void); /* %gs:0x40 */
uint32_t GetEnvironmentVariable(const char16_t *lpName, char16_t *lpBuffer,
                                uint32_t nSize);
uint32_t SetEnvironmentVariable(const char16_t *lpName,
                                const char16_t *lpValue);
int32_t SetEnvironmentStrings(char16_t *NewEnvironment);
bool32 GetProcessAffinityMask(int64_t hProcess, uint64_t *lpProcessAffinityMask,
                              uint64_t *lpSystemAffinityMask);
uint64_t /*bool32*/ SetProcessAffinityMask(int64_t hProcess,
                                           uint64_t dwProcessAffinityMask);

/* e.g. kNtAboveNormalPriorityClass, kNtHighPriorityClass */
uint32_t GetPriorityClass(int64_t hProcess);
bool32 SetPriorityClass(int64_t hProcess, uint32_t dwPriorityClass);
bool32 SetProcessPriorityBoost(int64_t hProcess, bool32 bDisablePriorityBoost);
bool32 GetProcessPriorityBoost(int64_t hProcess, bool32 *pDisablePriorityBoost);

bool32 GetProcessMemoryInfo(
    int64_t hProcess, struct NtProcessMemoryCountersEx *out_ppsmemCounters,
    uint32_t cb);

int64_t CreateToolhelp32Snapshot(uint32_t dwFlags, uint32_t th32ProcessID);
bool32 Process32First(int64_t hSnapshot, struct NtProcessEntry32 *in_out_lppe);
bool32 Process32Next(int64_t hSnapshot, struct NtProcessEntry32 *out_lppe);

bool32 EnumProcesses(uint32_t *out_lpidProcess, uint32_t cb,
                     uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModules(int64_t hProcess, int64_t *out_lphModule, uint32_t cb,
                          uint32_t *out_lpcbNeeded) paramsnonnull();
bool32 EnumProcessModulesEx(int64_t hProcess, int64_t *out_lphModule,
                            uint32_t cb, uint32_t *out_lpcbNeeded,
                            uint32_t dwFilterFlag) paramsnonnull();
uint32_t GetModuleBaseName(int64_t hProcess, int64_t opt_hModule,
                           char16_t *out_lpBaseName, uint32_t nSize)
    paramsnonnull();

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/process.inc */

#define GetEnvironmentVariable(...) __imp_GetEnvironmentVariableW(__VA_ARGS__)
extern typeof(GetEnvironmentVariable) *const __imp_GetEnvironmentVariableW
    __msabi;

#define SetEnvironmentVariable(...) __imp_SetEnvironmentVariableW(__VA_ARGS__)
extern typeof(SetEnvironmentVariable) *const __imp_SetEnvironmentVariableW
    __msabi;

#define GetPriorityClass(...) __imp_GetPriorityClass(__VA_ARGS__)
extern typeof(GetPriorityClass) *const __imp_GetPriorityClass __msabi;

#define SetPriorityClass(...) __imp_SetPriorityClass(__VA_ARGS__)
extern typeof(SetPriorityClass) *const __imp_SetPriorityClass __msabi;

#define GetCurrentProcessId(...) __imp_GetCurrentProcessId(__VA_ARGS__)
extern typeof(GetCurrentProcessId) *const __imp_GetCurrentProcessId __msabi;

extern typeof(FormatMessage) *const __imp_FormatMessageW __msabi;
extern typeof(SetLastError) *const __imp_SetLastError __msabi;
extern typeof(FormatMessage) *const __imp_FormatMessage __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/registry.h */

#define COSMOPOLITAN_LIBC_NT_REGISTRY_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » registry                                 ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#define kNtMaxKeyNameChars   255
#define kNtMaxValueNameChars 16383
#define kNtMaxValueBytes     0x100000

#define kNtHkeyClassesRoot              0x80000000l
#define kNtHkeyCurrentUser              0x80000001l
#define kNtHkeyLocalMachine             0x80000002l
#define kNtHkeyUsers                    0x80000003l
#define kNtHkeyPerformanceData          0x80000004l
#define kNtHkeyPerformanceText          0x80000050l
#define kNtHkeyPerformanceNlstext       0x80000060l
#define kNtHkeyCurrentConfig            0x80000005l
#define kNtHkeyDynData                  0x80000006l
#define kNtHkeyCurrentUserLocalSettings 0x80000007l

COSMOPOLITAN_C_START_

int RegOpenKey(int64_t hKey, const char16_t *opt_lpSubKey,
               int64_t *out_phkResult) paramsnonnull((3));
int RegOpenKeyEx(int64_t hKey, const char16_t *opt_lpSubKey,
                 uint32_t opt_ulOptions, int samDesired, int64_t *out_phkResult)
    paramsnonnull((5));
int RegCloseKey(int64_t hKey);

int RegGetValue(int64_t hkey, const char16_t *opt_lpSubKey,
                const char16_t *opt_lpValue, unsigned dwFlags, int *opt_pdwType,
                void *opt_out_pvData, uint32_t *opt_inout_pcbDataBytes);
int RegSetValue(int64_t hKey, const char16_t *lpSubKey, int dwType,
                const char16_t *lpData, uint32_t cbData);
int RegSetValueEx(int64_t hKey, const char16_t *lpValueName, uint32_t Reserved,
                  int dwType, const unsigned char *lpData, uint32_t cbData);

int RegQueryInfoKey(int64_t hKey, char16_t *opt_out_lpClass,
                    uint32_t *opt_inout_lpClassLen, uint32_t *lpReserved,
                    uint32_t *opt_out_lpcSubKeys,
                    uint32_t *opt_out_lpcbMaxSubKeyBytes,
                    uint32_t *opt_out_lpcbMaxClassBytes,
                    uint32_t *opt_out_lpcValues,
                    uint32_t *opt_out_lpcbMaxValueNameBytes,
                    uint32_t *opt_out_lpcbMaxValueBytes,
                    uint32_t *opt_out_lpcbSecurityDescriptorBytes,
                    struct NtFileTime *opt_out_lpftLastWriteTime);
int RegEnumKey(int64_t hKey, uint32_t dwIndex, char16_t *opt_lpName,
               uint32_t NameLen);
int RegEnumKeyEx(int64_t hKey, uint32_t dwIndex, char16_t *out_lpName,
                 uint32_t *inout_lpcchName, uint32_t *lpReserved,
                 char16_t *opt_out_lpClass, uint32_t *opt_inout_lpcchClassLen,
                 struct NtFileTime *opt_out_lpftLastWriteTime);

int RegEnumValue(int64_t hKey, uint32_t dwIndex, char16_t *lpValueName,
                 uint32_t *lpValueNameLen, uint32_t *lpReserved,
                 int *opt_out_lpType, unsigned char *opt_out_lpData,
                 uint32_t *opt_inout_lpcbDataBytes);
int RegQueryValue(int64_t hKey, const char16_t *opt_lpSubKey,
                  char16_t *opt_out_lpData, int32_t *opt_inout_lpcbDataBytes);
int RegQueryValueEx(int64_t hKey, const char16_t *opt_lpValueName,
                    uint32_t *lpReserved, int *opt_out_lpType,
                    unsigned char *opt_out_lpData,
                    uint32_t *opt_inout_lpcbDataBytes);

int RegOverridePredefKey(int64_t hKey, int64_t hNewHKey);
int RegOpenUserClassesRoot(void *hToken, uint32_t dwOptions, int samDesired,
                           int64_t *phkResult);
int RegOpenCurrentUser(int samDesired, int64_t *phkResult);
int RegDisablePredefinedCache();
int RegConnectRegistry(const char16_t *lpMachineName, int64_t hKey,
                       int64_t *phkResult);
int RegConnectRegistryEx(const char16_t *lpMachineName, int64_t hKey,
                         uint32_t Flags, int64_t *phkResult);
int RegCreateKey(int64_t hKey, const char16_t *lpSubKey, int64_t *phkResult);
int RegCreateKeyEx(int64_t hKey, const char16_t *lpSubKey, uint32_t Reserved,
                   int16_t *lpClass, uint32_t dwOptions, int samDesired,
                   const struct NtSecurityAttributes *lpSecurityAttributes,
                   int64_t *phkResult, uint32_t *lpdwDisposition);
int RegDeleteKey(int64_t hKey, const char16_t *lpSubKey);
int RegDeleteKeyEx(int64_t hKey, const char16_t *lpSubKey, int samDesired,
                   uint32_t Reserved);
int RegDeleteTree(int64_t hKey, const char16_t *opt_lpSubKey);
int RegDisableReflectionKey(int64_t hBase);
int RegEnableReflectionKey(int64_t hBase);
int RegQueryReflectionKey(int64_t hBase, bool32 *bIsReflectionDisabled);
int RegDeleteValue(int64_t hKey, const char16_t *lpValueName);
int RegFlushKey(int64_t hKey);
int RegGetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor,
                      uint32_t *lpcbSecurityDescriptorBytes);
int RegLoadKey(int64_t hKey, const char16_t *lpSubKey, const char16_t *lpFile);
int RegNotifyChangeKeyValue(int64_t hKey, bool32 bWatchSubtree,
                            uint32_t dwNotifyFilter, void *hEvent,
                            int fAsynchronous);
int RegQueryMultipleValues(int64_t hKey, struct NtValent *inout_val_list,
                           uint32_t num_vals, int16_t *out_lpValueBuf,
                           uint32_t *inout_ldwTotsize) paramsnonnull();
int RegReplaceKey(int64_t hKey, const char16_t *lpSubKey,
                  const char16_t *lpNewFile, const char16_t *lpOldFile);
int RegRestoreKey(int64_t hKey, const char16_t *lpFile, uint32_t dwFlags);
int RegSaveKey(int64_t hKey, const char16_t *lpFile,
               const struct NtSecurityAttributes *lpSecurityAttributes);
int RegSetKeySecurity(int64_t hKey, uint32_t SecurityInformation,
                      void *pSecurityDescriptor);
int RegUnLoadKey(int64_t hKey, const char16_t *lpSubKey);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/runtime.h */

#define COSMOPOLITAN_LIBC_NT_RUNTIME_H_

/**
 * @fileoverview NT Obligatory Runtime Functions.
 *
 * These functions are placed in their own file because they're (a)
 * abstracted by the Cosmopolitan runtime; and (b) it helps GCC avoid
 * bloating binaries with debug information the user doesn't need.
 */

#define kNtCpUtf8             65001
#define kNtInvalidHandleValue -1L
#define kNtStdInputHandle     -10u
#define kNtStdOutputHandle    -11u
#define kNtStdErrorHandle     -12u

#define GetCurrentProcess() -1

COSMOPOLITAN_C_START_

char16_t *GetCommandLine(void) nosideeffect;
char16_t *GetEnvironmentStrings(void) __wur;
bool32 FreeEnvironmentStrings(char16_t *) paramsnonnull();
bool32 ReadFile(int64_t hFile, void *lpBuffer, uint32_t nNumberOfBytesToRead,
                uint32_t *lpNumberOfBytesRead,
                struct NtOverlapped *opt_lpOverlapped);
bool32 WriteFile(int64_t hFile, const void *lpBuffer,
                 uint32_t nNumberOfBytesToWrite,
                 uint32_t *lpNumberOfBytesWritten,
                 struct NtOverlapped *opt_lpOverlapped);
bool32 TerminateProcess(int64_t hProcess, uint32_t uExitCode);
void TerminateThisProcess(uint32_t dwWaitStatus) wontreturn;
void ExitProcess(uint32_t uExitCode) wontreturn;
uint32_t GetLastError(void) nosideeffect;
bool32 CloseHandle(int64_t hObject) dontthrow dontcallback;
intptr_t GetStdHandle(uint32_t nStdHandle) nosideeffect;
bool32 SetStdHandle(uint32_t nStdHandle, int64_t hHandle);
bool32 SetDefaultDllDirectories(unsigned dirflags);
bool32 ProcessPrng(void *RandomBuffer, uint32_t RandomBufferLength);
uint32_t GetModuleFileName(int64_t hModule, char16_t *lpFilename,
                           uint32_t nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/runtime.inc */

#define FreeEnvironmentStrings(...) __imp_FreeEnvironmentStringsW(__VA_ARGS__)
extern typeof(FreeEnvironmentStrings) *const __imp_FreeEnvironmentStringsW
    __msabi;

#define GetCommandLine(...) __imp_GetCommandLineW(__VA_ARGS__)
extern typeof(GetCommandLine) *const __imp_GetCommandLineW __msabi;

#define GetEnvironmentStrings(...) __imp_GetEnvironmentStringsW(__VA_ARGS__)
extern typeof(GetEnvironmentStrings) *const __imp_GetEnvironmentStringsW
    __msabi;

#define GetStdHandle(...) __imp_GetStdHandle(__VA_ARGS__)
extern typeof(GetStdHandle) *const __imp_GetStdHandle __msabi;

#define SetStdHandle(...) __imp_SetStdHandle(__VA_ARGS__)
extern typeof(SetStdHandle) *const __imp_SetStdHandle __msabi;

#define ReadFile(...) __imp_ReadFile(__VA_ARGS__)
extern typeof(ReadFile) *const __imp_ReadFile __msabi;

#define WriteFile(...) __imp_WriteFile(__VA_ARGS__)
extern typeof(WriteFile) *const __imp_WriteFile __msabi;

#define SetDefaultDllDirectories(...) \
  __imp_SetDefaultDllDirectories(__VA_ARGS__)
extern typeof(SetDefaultDllDirectories) *const __imp_SetDefaultDllDirectories
    __msabi;

#define GetModuleFileName(...) __imp_GetModuleFileNameW(__VA_ARGS__)
extern typeof(GetModuleFileName) *const __imp_GetModuleFileNameW __msabi;

extern typeof(GetLastError) *const __imp_GetLastError __msabi;
extern typeof(ExitProcess) *const __imp_ExitProcess __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/signals.h */

#define COSMOPOLITAN_LIBC_NT_EXCEPTIONS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » signals                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

COSMOPOLITAN_C_START_

typedef int (*NtTopLevelExceptionFilter)(const struct NtExceptionPointers *);
typedef int32_t (*NtVectoredExceptionHandler)(struct NtExceptionPointers *);

int SetErrorMode(int uMode);

int64_t AddVectoredExceptionHandler(uint32_t First,
                                    NtVectoredExceptionHandler pHandler);
int64_t AddVectoredContinueHandler(uint32_t First,
                                   NtVectoredExceptionHandler pHandler);

uint32_t RemoveVectoredExceptionHandler(int64_t hHandle);
uint32_t RemoveVectoredContinueHandler(int64_t hHandle);

NtTopLevelExceptionFilter SetUnhandledExceptionFilter(
    NtTopLevelExceptionFilter opt_lpTopLevelExceptionFilter);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/signals.inc */

#define SetErrorMode(...) __imp_SetErrorMode(__VA_ARGS__)
#define AddVectoredExceptionHandler(...) \
  __imp_AddVectoredExceptionHandler(__VA_ARGS__)
#define AddVectoredContinueHandler(...) \
  __imp_AddVectoredContinueHandler(__VA_ARGS__)
#define RemoveVectoredExceptionHandler(...) \
  __imp_RemoveVectoredExceptionHandler(__VA_ARGS__)
#define RemoveVectoredContinueHandler(...) \
  __imp_RemoveVectoredContinueHandler(__VA_ARGS__)
#define SetUnhandledExceptionFilter(...) \
  __imp_SetUnhandledExceptionFilter(__VA_ARGS__)

extern typeof(SetErrorMode) *const __imp_SetErrorMode __msabi;
extern typeof(AddVectoredExceptionHandler) *const
    __imp_AddVectoredExceptionHandler __msabi;
extern typeof(AddVectoredContinueHandler) *const
    __imp_AddVectoredContinueHandler __msabi;
extern typeof(RemoveVectoredExceptionHandler) *const
    __imp_RemoveVectoredExceptionHandler __msabi;
extern typeof(RemoveVectoredContinueHandler) *const
    __imp_RemoveVectoredContinueHandler __msabi;
extern typeof(SetUnhandledExceptionFilter) *const
    __imp_SetUnhandledExceptionFilter __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/synchronization.h */

#define COSMOPOLITAN_LIBC_NT_SYNCHRONIZATION_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » synchronization                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

static inline int32_t InterlockedAdd(int32_t volatile *p, int32_t x) {
  return atomic_fetch_add((_Atomic(int32_t) *)p, x) + x;
}

static inline int32_t InterlockedExchange(int32_t volatile *p, int32_t x) {
  return atomic_exchange((_Atomic(int32_t) *)p, x);
}

typedef void (*NtTimerapcroutine)(void *lpArgToCompletionRoutine,
                                  uint32_t dwTimerLowValue,
                                  uint32_t dwTimerHighValue);
typedef void (*NtWaitOrTimerCallback)(void *lpParameter,
                                      bool32 TimerOrWaitFired);

void WakeByAddressAll(void *Address);
void WakeByAddressSingle(void *Address);
bool32 WaitOnAddress(const volatile void *Address, void *CompareAddress,
                     size_t AddressSize, uint32_t opt_dwMilliseconds);

void Sleep(uint32_t dwMilliseconds);
uint32_t SleepEx(uint32_t dwMilliseconds, bool32 bAlertable);

void GetSystemTime(struct NtSystemTime *lpSystemTime);
bool32 SystemTimeToFileTime(const struct NtSystemTime *lpSystemTime,
                            struct NtFileTime *lpFileTime);
void GetSystemTimeAsFileTime(struct NtFileTime *);
void GetSystemTimePreciseAsFileTime(struct NtFileTime *); /* win8+ */

uint32_t WaitForSingleObject(int64_t hHandle, uint32_t dwMilliseconds);
uint32_t WaitForMultipleObjects(uint32_t nCount, const int64_t *lpHandles,
                                bool32 bWaitAll, uint32_t dwMilliseconds);
uint32_t WaitForSingleObjectEx(int64_t hHandle, uint32_t dwMilliseconds,
                               bool32 bAlertable);
uint32_t WaitForMultipleObjectsEx(unsigned int nCount, const int64_t *lpHandles,
                                  bool32 bWaitAll, uint32_t dwMilliseconds,
                                  bool32 bAlertable);
bool32 RegisterWaitForSingleObject(int64_t *phNewWaitObject, int64_t hObject,
                                   NtWaitOrTimerCallback Callback,
                                   void *Context, uint32_t dwMilliseconds,
                                   uint32_t dwFlags);

int64_t CreateWaitableTimer(
    const struct NtSecurityAttributes *lpTimerAttributes, bool32 bManualReset,
    const char16_t *lpTimerName);
bool32 SetWaitableTimer(int64_t hTimer, const int64_t *lpDueTimeAsFtOrNegRela,
                        int32_t opt_lPeriodMs, NtTimerapcroutine opt_callback,
                        void *lpArgToCallback, bool32 fUnsleepSystem);

int64_t CreateSemaphore(
    const struct NtSecurityAttributes *opt_lpSemaphoreAttributes,
    uint32_t lInitialCount, uint32_t lMaximumCount, const char16_t *opt_lpName);

int32_t ReleaseMutex(int64_t hMutex);
int32_t ReleaseSemaphore(int64_t hSemaphore, int32_t lReleaseCount,
                         int *lpPreviousCount);

void InitializeCriticalSection(struct NtCriticalSection *lpCriticalSection);
void EnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void LeaveCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t TryEnterCriticalSection(struct NtCriticalSection *lpCriticalSection);
void DeleteCriticalSection(struct NtCriticalSection *lpCriticalSection);
int32_t InitializeCriticalSectionAndSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);
uint32_t SetCriticalSectionSpinCount(
    struct NtCriticalSection *lpCriticalSection, uint32_t dwSpinCount);

void InitializeSRWLock(intptr_t *);
void AcquireSRWLockExclusive(intptr_t *);
void AcquireSRWLockShared(intptr_t *);
void ReleaseSRWLockExclusive(intptr_t *);
void ReleaseSRWLockShared(intptr_t *);
void TryAcquireSRWLockExclusive(intptr_t *);
void TryAcquireSRWLockShared(intptr_t *);

uint64_t GetTickCount64(void);

bool32 QueryPerformanceFrequency(uint64_t *lpFrequency);
bool32 QueryPerformanceCounter(uint64_t *lpPerformanceCount);
bool32 GetSystemTimeAdjustment(uint32_t *lpTimeAdjustment,
                               uint32_t *lpTimeIncrement,
                               bool32 *lpTimeAdjustmentDisabled);

void GetCurrentProcessorNumberEx(struct NtProcessorNumber *out_ProcNumber);

bool32 GetNumaProcessorNodeEx(const struct NtProcessorNumber *Processor,
                              unsigned short *out_NodeNumber);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/synchronization.inc */

extern typeof(SleepEx) *const __imp_SleepEx __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/system.h */

#define COSMOPOLITAN_LIBC_NT_SYSTEM_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » system control                           ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

bool32 SetSuspendState(bool32 bHibernate, bool32 bForce,
                       bool32 bWakeupEventsDisabled);

uint32_t InitiateShutdown(const char16_t *lpMachineName,
                          const char16_t *lpMessage, uint32_t dwGracePeriod,
                          uint32_t dwShutdownFlags, uint32_t dwReason);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/systeminfo.h */

#define COSMOPOLITAN_LIBC_NT_INFO_H_
COSMOPOLITAN_C_START_

void GetSystemInfo(struct NtSystemInfo *lpSystemInfo);
uint32_t GetSystemDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetSystemDirectoryA(char *lpBuffer, uint32_t uSize);
uint32_t GetWindowsDirectory(char16_t *lpBuffer, uint32_t uSize);
uint32_t GetTempPath(uint32_t uSize, char16_t *lpBuffer);

bool32 GetComputerNameEx(/* enum/computernameformat.h */ int NameType,
                         char16_t *opt_lpBuffer, uint32_t *nSize);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/systeminfo.inc */

#define GetSystemInfo(...) __imp_GetSystemInfo(__VA_ARGS__)
#define GetTempPath(...) __imp_GetTempPathW(__VA_ARGS__)

extern typeof(GetSystemInfo) *const __imp_GetSystemInfo __msabi;
extern typeof(GetTempPath) *const __imp_GetTempPathW __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/thread.h */

#define COSMOPOLITAN_LIBC_NT_THREADS_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » threads                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int64_t CreateThread(const struct NtSecurityAttributes *lpThreadAttributes,
                     size_t dwStackSize, void *lpStartAddress,
                     void *lpParameter, uint32_t dwCreationFlags,
                     uint32_t *opt_lpThreadId) paramsnonnull((3));

void ExitThread(uint32_t dwExitCode) wontreturn;
int64_t GetCurrentThread(void);
uint32_t GetCurrentThreadId(void);
uint64_t SetThreadAffinityMask(int64_t hThread, uintptr_t dwThreadAffinityMask);
int64_t OpenThread(uint32_t dwDesiredAccess, bool32 bInheritHandle,
                   uint32_t dwThreadId);
bool32 TerminateThread(int64_t hThread, uint32_t dwExitCode);
bool32 GetExitCodeThread(int64_t hThread, uint32_t *lpExitCode);

/* e.g. kNtThreadPriorityAboveNormal, -1u on error */
uint32_t GetThreadPriority(int64_t hThread);
bool32 SetThreadPriority(int64_t hThread, int32_t nPriority);
bool32 SetThreadPriorityBoost(int64_t hThread, bool32 bDisablePriorityBoost);
bool32 GetThreadPriorityBoost(int64_t hThread, bool32 *pDisablePriorityBoost);
bool32 GetThreadIOPendingFlag(int64_t hThread, bool32 *lpIOIsPending);

bool32 CancelSynchronousIo(int64_t hThread);
bool32 CancelIo(int64_t hFile);
bool32 CancelIoEx(int64_t hFile, struct NtOverlapped *opt_lpOverlapped);

uint32_t TlsAlloc(void);
bool32 TlsFree(uint32_t);
bool32 TlsSetValue(uint32_t, void *);
void *TlsGetValue(uint32_t);

uint32_t SuspendThread(int64_t hThread);
uint32_t ResumeThread(int64_t hThread);
bool32 GetThreadContext(int64_t hThread, struct NtContext *in_out_lpContext);
bool32 SetThreadContext(int64_t hThread, const struct NtContext *lpContext);

void *SetThreadDescription(int64_t hThread,
                           const char16_t *lpThreadDescription);
void *GetThreadDescription(int64_t hThread,
                           char16_t *out_ppszThreadDescription);

#if ShouldUseMsabiAttribute()


/*!BEGIN libc/nt/thunk/thread.inc */

#define GetCurrentThread(...)  __imp_GetCurrentThread(__VA_ARGS__)
#define GetThreadPriority(...) __imp_GetThreadPriority(__VA_ARGS__)
#define SetThreadPriority(...) __imp_SetThreadPriority(__VA_ARGS__)

extern typeof(GetCurrentThread) *const __imp_GetCurrentThread __msabi;
extern typeof(GetThreadPriority) *const __imp_GetThreadPriority __msabi;
extern typeof(SetThreadPriority) *const __imp_SetThreadPriority __msabi;
#endif /* ShouldUseMsabiAttribute() */
COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/time.h */

#define COSMOPOLITAN_LIBC_NT_TIME_H_
COSMOPOLITAN_C_START_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » time                                     ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

uint32_t GetTimeZoneInformation(
    struct NtTimeZoneInformation *out_lpTimeZoneInformation);
uint32_t GetDynamicTimeZoneInformation(
    struct NtDynamicTimeZoneInformation *out_lpTimeZoneInformation);

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/version.h */

#define COSMOPOLITAN_LIBC_NT_VERSION_H_
COSMOPOLITAN_C_START_

bool32 IsAtLeastWindows10(void) pureconst;
bool32 GetVersionEx(struct NtOsVersionInfo *lpVersionInformation);

#if defined(__GNUC__) && !defined(__STRICT_ANSI__) && defined(__x86_64__)
#define IsAtLeastWindows10() (GetNtMajorVersion() >= 10)
#define GetNtMajorVersion()        \
  __extension__({                  \
    uintptr_t __x;                 \
    __asm__("mov\t%%gs:96,%q0\r\n" \
            "mov\t280(%q0),%b0"    \
            : "=q"(__x));          \
    (unsigned char)__x;            \
  })
#endif

COSMOPOLITAN_C_END_


/*!BEGIN libc/nt/windows.h */

#define COSMOPOLITAN_LIBC_NT_WINDOWS_H_
/*                            ░░░░
                       ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░
                      ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░
                     ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓░
                     ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   ▓▓▓▓▓▓▒        ▒▒▒▓▓█
                    ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                   ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓   █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                   ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░  ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
                  ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓  ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒
                  ▒▒▒▒▓▓      ▓▒▒▓▓▓▓   ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                                   ▒▓  ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓
                  ░░░░░░░░░░░▒▒▒▒      ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█
                ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓     ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓
               ░▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓░      ░▓███▓
               ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░  ▒▓▓▓▒▒▒         ░▒▒▒▓   ████████████
              ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓  ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░           ░███
              ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓            ███
             ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒            ▓██
             ▒░░░░░░░░░░░▒▒▒▒▒▓▓   ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓           ▓██
            ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒  ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒           ███
                            ░▒▓  ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓          ▓██
╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗
│ cosmopolitan § new technology » windows                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
COSMOPOLITAN_C_START_

int64_t CreateWindowEx(uint32_t dwExStyle, const char16_t *lpClassName,
                       const char16_t *lpWindowName, uint32_t dwStyle, int X,
                       int Y, int nWidth, int nHeight, int64_t hWndParent,
                       int64_t hMenu, int64_t hInstance, int64_t lpParam);

uint16_t RegisterClass(const struct NtWndClass *lpWndClass);

int64_t DefWindowProc(int64_t hWnd, uint32_t Msg, uint64_t wParam,
                      int64_t lParam);

int32_t CloseWindow(int64_t hWnd);
int32_t DestroyWindow(int64_t hWnd);
int32_t ShowWindow(int64_t hWnd, int sw);
int32_t ShowCaret(bool32 bShow);
int32_t AnimateWindow(int64_t hWnd, uint32_t dwTime, uint32_t dwFlags);
int64_t LoadIcon(int64_t hInstance, const char16_t *lpIconName);
int32_t MoveWindow(int64_t hWnd, int X, int Y, int nWidth, int nHeight,
                   bool32 bRepaint);
int32_t BringWindowToTop(int64_t hWnd);
int32_t IsWindowVisible(int64_t hWnd);
int32_t SetWindowText(int64_t hWnd, const char16_t *lpString);
int32_t GetWindowText(int64_t hWnd, char16_t *lpString, int nMaxCount);
int32_t SetWindowPos(int64_t hWnd, int64_t hWndInsertAfter, int X, int Y,
                     int cx, int cy, uint32_t uFlags);
bool32 GetWindowPlacement(int64_t hWnd, struct NtWindowPlacement *lpwndpl);
bool32 SetWindowPlacement(int64_t hWnd,
                          const struct NtWindowPlacement *lpwndpl);

int64_t GetCursor(void);
int64_t SetCursor(int64_t hCursor);
int32_t ShowCursor(bool32 bShow);
int64_t LoadCursor(int64_t opt_hInstance, const char16_t *lpCursorNameOrIdc);

bool32 IsWindow(int64_t hWnd);
bool32 IsMenu(int64_t hMenu);
bool32 IsChild(int64_t hWndParent, int64_t hWnd);
bool32 IsZoomed(int64_t hWnd);
bool32 IsIconic(int64_t hWnd);

uintptr_t SetTimer(int64_t opt_hWnd, uintptr_t nIDEvent, uint32_t uElapseMs,
                   NtTimerProc lpTimerFunc);
int32_t KillTimer(int64_t hWnd, uintptr_t uIDEvent);

int64_t SetCapture(int64_t hWnd);
bool32 ReleaseCapture(void);
int16_t GetKeyState(int32_t nVirtKey);

int64_t CreateMenu(void);
int64_t CreatePopupMenu(void);
int64_t GetMenu(int64_t hWnd);
bool32 DestroyMenu(int64_t hMenu);
int64_t GetSystemMenu(int64_t hWnd, bool32 bRevert);
bool32 AppendMenu(int64_t hMenu, uint32_t mfFlags, uintptr_t uIDNewItem,
                  const char16_t *lpNewItem);
bool32 InsertMenu(int64_t hMenu, uint32_t uPosition, uint32_t uFlags,
                  uintptr_t uIDNewItem, const char16_t *lpNewItem);
bool32 TrackPopupMenu(int64_t hMenu, uint32_t uFlags, int32_t x, int32_t y,
                      int32_t nReserved, int64_t hWnd,
                      const struct NtRect *prcRect);

int WideCharToMultiByte(unsigned int CodePage, uint32_t dwFlags,
                        uint16_t *lpWideCharStr, int cchWideChar,
                        char *lpMultiByteStr, int cbMultiByte,
                        uint16_t *lpDefaultChar, int *lpUsedDefaultChar);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/clktck.h */

#define COSMOPOLITAN_LIBC_RUNTIME_CLKTCK_H_
COSMOPOLITAN_C_START_

#define CLK_TCK (__clk_tck())

int __clk_tck(void) pureconst;

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/fenv.h */

#define COSMOPOLITAN_LIBC_RUNTIME_FENV_H_

#ifdef __x86_64__
#define FE_INVALID    1
#define __FE_DENORM   2
#define FE_DIVBYZERO  4
#define FE_OVERFLOW   8
#define FE_UNDERFLOW  16
#define FE_INEXACT    32
#define FE_ALL_EXCEPT 63
#define FE_TONEAREST  0x0000
#define FE_DOWNWARD   0x0400
#define FE_UPWARD     0x0800
#define FE_TOWARDZERO 0x0c00
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint16_t fexcept_t;

#elif defined(__aarch64__)
#define FE_INVALID    1
#define FE_DIVBYZERO  2
#define FE_OVERFLOW   4
#define FE_UNDERFLOW  8
#define FE_INEXACT    16
#define FE_ALL_EXCEPT 31
#define FE_TONEAREST  0
#define FE_DOWNWARD   0x800000
#define FE_UPWARD     0x400000
#define FE_TOWARDZERO 0xc00000
#define FE_DFL_ENV    ((const fenv_t *)-1)
typedef void *fenv_t;
typedef uint32_t fexcept_t;

#elif defined(__powerpc64__)
#define FE_TONEAREST                  0
#define FE_TOWARDZERO                 1
#define FE_UPWARD                     2
#define FE_DOWNWARD                   3
#define FE_INEXACT                    0x02000000
#define FE_DIVBYZERO                  0x04000000
#define FE_UNDERFLOW                  0x08000000
#define FE_OVERFLOW                   0x10000000
#define FE_INVALID                    0x20000000
#define FE_ALL_EXCEPT                 0x3e000000
#define FE_INVALID_SNAN               0x01000000
#define FE_INVALID_ISI                0x00800000
#define FE_INVALID_IDI                0x00400000
#define FE_INVALID_ZDZ                0x00200000
#define FE_INVALID_IMZ                0x00100000
#define FE_INVALID_COMPARE            0x00080000
#define FE_INVALID_SOFTWARE           0x00000400
#define FE_INVALID_SQRT               0x00000200
#define FE_INVALID_INTEGER_CONVERSION 0x00000100
#define FE_ALL_INVALID                0x01f80700
#define FE_DFL_ENV                    ((const fenv_t *)-1)
typedef unsigned fexcept_t;
typedef double fenv_t;

#endif /* __x86_64__ */

#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD_TS_18661_3__
#elif defined(__FLT_EVAL_METHOD__)
#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__
#else
#define FLT_EVAL_METHOD 0
#endif

COSMOPOLITAN_C_START_

#define FLT_ROUNDS (__flt_rounds())

int feclearexcept(int);
int fegetenv(fenv_t *);
int fegetexceptflag(fexcept_t *, int);
int fegetround(void);
int feholdexcept(fenv_t *);
int feraiseexcept(int);
int fesetenv(const fenv_t *);
int fesetexceptflag(const fexcept_t *, int);
int fesetround(int);
int fetestexcept(int);
int feenableexcept(int);
int fedisableexcept(int);
int feupdateenv(const fenv_t *);
int __flt_rounds(void);
int __fesetround(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/pathconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_PATHCONF_H_

#define _PC_LINK_MAX           0
#define _PC_MAX_CANON          1
#define _PC_MAX_INPUT          2
#define _PC_NAME_MAX           3
#define _PC_PATH_MAX           4
#define _PC_PIPE_BUF           5
#define _PC_CHOWN_RESTRICTED   6
#define _PC_NO_TRUNC           7
#define _PC_VDISABLE           8
#define _PC_SYNC_IO            9
#define _PC_ASYNC_IO           10
#define _PC_PRIO_IO            11
#define _PC_SOCK_MAXBUF        12
#define _PC_FILESIZEBITS       13
#define _PC_REC_INCR_XFER_SIZE 14
#define _PC_REC_MAX_XFER_SIZE  15
#define _PC_REC_MIN_XFER_SIZE  16
#define _PC_REC_XFER_ALIGN     17
#define _PC_ALLOC_SIZE_MIN     18
#define _PC_SYMLINK_MAX        19
#define _PC_2_SYMLINKS         20

COSMOPOLITAN_C_START_

long fpathconf(int, int);
long pathconf(const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/runtime.h */

#define COSMOPOLITAN_LIBC_RUNTIME_RUNTIME_H_
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § runtime                                                   ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

#ifdef __x86_64__
typedef long jmp_buf[8];
typedef long sigjmp_buf[11];
#elif defined(__aarch64__)
typedef long jmp_buf[22];
typedef long sigjmp_buf[25];
#elif defined(__powerpc64__)
typedef unsigned __int128 jmp_buf[32];
#elif defined(__s390x__)
typedef unsigned long jmp_buf[18];
#elif defined(__riscv)
typedef unsigned long jmp_buf[26];
#endif

void mcount(void);
int daemon(int, int);
unsigned long getauxval(unsigned long);
int setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
void longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
int _setjmp(jmp_buf)
libcesque returnstwice paramsnonnull();
int sigsetjmp(sigjmp_buf, int) libcesque returnstwice paramsnonnull();
void siglongjmp(sigjmp_buf, int) libcesque wontreturn paramsnonnull();
void _longjmp(jmp_buf, int) libcesque wontreturn paramsnonnull();
void exit(int) wontreturn;
void _exit(int) libcesque wontreturn;
void _Exit(int) libcesque wontreturn;
void quick_exit(int) wontreturn;
void abort(void) wontreturn;
int atexit(void (*)(void)) paramsnonnull() libcesque;
char *getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
int putenv(char *);
int setenv(const char *, const char *, int);
int unsetenv(const char *);
int clearenv(void);
void fpreset(void);
void *mmap(void *, uint64_t, int32_t, int32_t, int32_t, int64_t);
int munmap(void *, uint64_t);
int mprotect(void *, uint64_t, int);
int msync(void *, size_t, int);
int mlock(const void *, size_t);
int munlock(const void *, size_t);
long gethostid(void);
int sethostid(long);
char *getlogin(void);
int getlogin_r(char *, size_t);
int login_tty(int);
int getpagesize(void);
int syncfs(int) dontthrow;
int vhangup(void);
int getdtablesize(void);
int sethostname(const char *, size_t);
int acct(const char *);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
extern char **environ;
char *secure_getenv(const char *) paramsnonnull() __wur nosideeffect libcesque;
#endif

#ifdef _COSMO_SOURCE
extern int __argc;
extern char **__argv;
extern char **__envp;
extern unsigned long *__auxv;
extern intptr_t __oldstack;
extern char *__program_executable_name;
extern uint64_t __nosync;
extern int __strace;
extern int __ftrace;
extern uint64_t __syscount;
extern uint64_t kStartTsc;
extern const char kNtSystemDirectory[];
extern const char kNtWindowsDirectory[];
extern size_t __virtualmax;
extern size_t __stackmax;
extern bool32 __isworker;
/* utilities */
void _intsort(int *, size_t);
void _longsort(long *, size_t);
/* diagnostics */
void ShowCrashReports(void);
int ftrace_install(void);
int ftrace_enabled(int);
int strace_enabled(int);
void __print_maps(void);
void __printargs(const char *);
/* builtin sh-like system/popen dsl */
int _cocmd(int, char **, char **);
/* executable program */
char *GetProgramExecutableName(void);
char *GetInterpreterExecutableName(char *, size_t);
int __open_executable(void);
/* execution control */
int verynice(void);
void __warn_if_powersave(void);
void _Exit1(int) libcesque wontreturn;
void __paginate(int, const char *);
void __paginate_file(int, const char *);
/* memory management */
void _weakfree(void *);
void *_mapanon(size_t) attributeallocsize((1)) mallocesque;
void *_mapshared(size_t) attributeallocsize((1)) mallocesque;
void CheckForMemoryLeaks(void);
void CheckForFileLeaks(void);
bool32 _isheap(const void *);
void __enable_threads(void);
void __oom_hook(size_t);
/* code morphing */
void __morph_begin(void);
void __morph_end(void);
void __jit_begin(void);
void __jit_end(void);
void __clear_cache(void *, void *);
/* portability */
int NtGetVersion(void) pureconst;
bool32 IsGenuineBlink(void);
bool32 IsCygwin(void);
const char *GetCpuidOs(void);
const char *GetCpuidEmulator(void);
void GetCpuidBrand(char[13], uint32_t);
long __get_rlimit(int);
const char *__describe_os(void);
long __get_sysctl(int, int);
int __get_arg_max(void) pureconst;
int __get_cpu_count(void) pureconst;
long __get_avphys_pages(void) pureconst;
long __get_phys_pages(void) pureconst;
long __get_minsigstksz(void) pureconst;
void __get_main_stack(void **, size_t *, int *);
long __get_safe_size(long, long);
char *__get_tmpdir(void);
forceinline int __trace_disabled(int x) {
  return 0;
}
#ifndef FTRACE
#define ftrace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#ifndef SYSDEBUG
#define strace_enabled(...) __trace_disabled(__VA_ARGS__)
#endif
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/stack.h */

#ifndef COSMOPOLITAN_LIBC_RUNTIME_STACK_H_
#define COSMOPOLITAN_LIBC_RUNTIME_STACK_H_

/**
 * Returns preferred size and alignment of thread stack.
 */
#define GetStackSize() 262144

/**
 * Returns preferred stack guard size.
 *
 * This is the max cpu page size of supported architectures.
 */
#define GetGuardSize() 16384

/**
 * Align APE main thread stack at startup.
 *
 * You need this in your main program module:
 *
 *     STATIC_STACK_ALIGN(GetStackSize());
 *
 * If you want to use GetStackAddr() and HaveStackMemory() safely on
 * your main thread in your process. It causes crt.S to waste a tiny
 * amount of memory to ensure those macros go extremely fast.
 */
#define STATIC_STACK_ALIGN(BYTES) \
  _STACK_SYMBOL("ape_stack_align", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Makes program stack executable if declared, e.g.
 *
 *     STATIC_EXEC_STACK();
 *     int main() {
 *       char code[16] = {
 *           0x55,                          // push %rbp
 *           0xb8, 0007, 0x00, 0x00, 0x00,  // mov  $7,%eax
 *           0x5d,                          // push %rbp
 *           0xc3,                          // ret
 *       };
 *       int (*func)(void) = (void *)code;
 *       printf("result %d should be 7\n", func());
 *     }
 */
#define STATIC_EXEC_STACK() _STACK_SYMBOL("ape_stack_pf", "7")

#define _STACK_STRINGIFY(ADDR) #ADDR
#define _STACK_SYMBOL(NAME, VALUE)       \
  __asm__(".equ\t" NAME "," VALUE "\n\t" \
          ".globl\t" NAME)

#ifdef __SANITIZE_ADDRESS__
#define _STACK_EXTRA "*2"
#else
#define _STACK_EXTRA ""
#endif

#if defined(__GNUC__) && defined(__ELF__)
COSMOPOLITAN_C_START_

extern char ape_stack_prot[] __attribute__((__weak__));
extern char ape_stack_memsz[] __attribute__((__weak__));
extern char ape_stack_align[] __attribute__((__weak__));

/**
 * Returns address of bottom of current stack.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants.
 */
#define GetStackAddr() ((GetStackPointer() - 1) & -GetStackSize())

#define GetStaticStackSize() ((uintptr_t)ape_stack_memsz)

/**
 * Returns true if at least `n` bytes of stack are available.
 *
 * This always works on threads. If you want it to work on the main
 * process too, then you'll need STATIC_STACK_ALIGN(GetStackSize())
 * which will burn O(256kb) of memory to ensure thread invariants,
 * which make this check exceedingly fast.
 */
#define HaveStackMemory(n) \
  (GetStackPointer() >= GetStackAddr() + GetGuardSize() + (n))

/**
 * Extends stack memory by poking large allocations.
 *
 * This can be particularly useful depending on how your system
 * implements guard pages. For example, Windows can make stacks
 * that aren't fully committed, in which case there's only 4096
 * bytes of grows-down guard pages made by portable executable.
 * If you alloca() more memory than that, you should call this,
 * since it'll not only ensure stack overflows are detected, it
 * will also trigger the stack to grow down safely.
 */
forceinline void CheckLargeStackAllocation(void *p, ssize_t n) {
  for (; n > 0; n -= 4096) {
    ((char *)p)[n - 1] = 0;
  }
}

void *NewCosmoStack(void) vallocesque;
int FreeCosmoStack(void *) libcesque;

/**
 * Tunes stack size of main thread on Windows.
 *
 * On UNIX systems use `RLIMIT_STACK` to tune the main thread size.
 */
#define STATIC_STACK_SIZE(BYTES) \
  _STACK_SYMBOL("ape_stack_memsz", _STACK_STRINGIFY(BYTES) _STACK_EXTRA)

/**
 * Tunes main thread stack address on Windows.
 */
#define STATIC_STACK_ADDR(ADDR) \
  _STACK_SYMBOL("ape_stack_vaddr", _STACK_STRINGIFY(ADDR))

#ifdef __x86_64__
/**
 * Returns preferred bottom address of main thread stack.
 *
 * On UNIX systems we favor the system provided stack, so this only
 * really applies to Windows. It's configurable at link time. It is
 * needed because polyfilling fork requires that we know, precicely
 * where the stack memory begins and ends.
 */
#define GetStaticStackAddr(ADDEND)          \
  ({                                        \
    intptr_t vAddr;                         \
    __asm__(".weak\tape_stack_vaddr\n\t"    \
            "movabs\t%1+ape_stack_vaddr,%0" \
            : "=r"(vAddr)                   \
            : "i"(ADDEND));                 \
    vAddr;                                  \
  })
#else
#define GetStaticStackAddr(ADDEND) (GetStackAddr() + ADDEND)
#endif

#define GetStackPointer()           \
  ({                                \
    uintptr_t __sp;                 \
    __asm__(__mov_sp : "=r"(__sp)); \
    __sp;                           \
  })

#ifdef __x86_64__
#define __mov_sp "mov\t%%rsp,%0"
#elif defined(__aarch64__)
#define __mov_sp "mov\t%0,sp"
#endif

COSMOPOLITAN_C_END_
#endif /* GNU ELF */
#endif /* COSMOPOLITAN_LIBC_RUNTIME_STACK_H_ */


/*!BEGIN libc/runtime/sysconf.h */

#define COSMOPOLITAN_LIBC_RUNTIME_SYSCONF_H_

#define _SC_ARG_MAX                      0
#define _SC_CHILD_MAX                    1
#define _SC_CLK_TCK                      2
#define _SC_NGROUPS_MAX                  3
#define _SC_OPEN_MAX                     4
#define _SC_STREAM_MAX                   5
#define _SC_TZNAME_MAX                   6
#define _SC_JOB_CONTROL                  7
#define _SC_SAVED_IDS                    8
#define _SC_REALTIME_SIGNALS             9
#define _SC_PRIORITY_SCHEDULING          10
#define _SC_TIMERS                       11
#define _SC_ASYNCHRONOUS_IO              12
#define _SC_PRIORITIZED_IO               13
#define _SC_SYNCHRONIZED_IO              14
#define _SC_FSYNC                        15
#define _SC_MAPPED_FILES                 16
#define _SC_MEMLOCK                      17
#define _SC_MEMLOCK_RANGE                18
#define _SC_MEMORY_PROTECTION            19
#define _SC_MESSAGE_PASSING              20
#define _SC_SEMAPHORES                   21
#define _SC_SHARED_MEMORY_OBJECTS        22
#define _SC_AIO_LISTIO_MAX               23
#define _SC_AIO_MAX                      24
#define _SC_AIO_PRIO_DELTA_MAX           25
#define _SC_DELAYTIMER_MAX               26
#define _SC_MQ_OPEN_MAX                  27
#define _SC_MQ_PRIO_MAX                  28
#define _SC_VERSION                      29
#define _SC_PAGE_SIZE                    30
#define _SC_PAGESIZE                     30 /* !! */
#define _SC_RTSIG_MAX                    31
#define _SC_SEM_NSEMS_MAX                32
#define _SC_SEM_VALUE_MAX                33
#define _SC_SIGQUEUE_MAX                 34
#define _SC_TIMER_MAX                    35
#define _SC_BC_BASE_MAX                  36
#define _SC_BC_DIM_MAX                   37
#define _SC_BC_SCALE_MAX                 38
#define _SC_BC_STRING_MAX                39
#define _SC_COLL_WEIGHTS_MAX             40
#define _SC_EXPR_NEST_MAX                42
#define _SC_LINE_MAX                     43
#define _SC_RE_DUP_MAX                   44
#define _SC_2_VERSION                    46
#define _SC_2_C_BIND                     47
#define _SC_2_C_DEV                      48
#define _SC_2_FORT_DEV                   49
#define _SC_2_FORT_RUN                   50
#define _SC_2_SW_DEV                     51
#define _SC_2_LOCALEDEF                  52
#define _SC_UIO_MAXIOV                   60 /* !! */
#define _SC_IOV_MAX                      60
#define _SC_THREADS                      67
#define _SC_THREAD_SAFE_FUNCTIONS        68
#define _SC_GETGR_R_SIZE_MAX             69
#define _SC_GETPW_R_SIZE_MAX             70
#define _SC_LOGIN_NAME_MAX               71
#define _SC_TTY_NAME_MAX                 72
#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73
#define _SC_THREAD_KEYS_MAX              74
#define _SC_THREAD_STACK_MIN             75
#define _SC_THREAD_THREADS_MAX           76
#define _SC_THREAD_ATTR_STACKADDR        77
#define _SC_THREAD_ATTR_STACKSIZE        78
#define _SC_THREAD_PRIORITY_SCHEDULING   79
#define _SC_THREAD_PRIO_INHERIT          80
#define _SC_THREAD_PRIO_PROTECT          81
#define _SC_THREAD_PROCESS_SHARED        82
#define _SC_NPROCESSORS_CONF             83
#define _SC_NPROCESSORS_ONLN             84
#define _SC_PHYS_PAGES                   85
#define _SC_AVPHYS_PAGES                 86
#define _SC_ATEXIT_MAX                   87
#define _SC_PASS_MAX                     88
#define _SC_XOPEN_VERSION                89
#define _SC_XOPEN_XCU_VERSION            90
#define _SC_XOPEN_UNIX                   91
#define _SC_XOPEN_CRYPT                  92
#define _SC_XOPEN_ENH_I18N               93
#define _SC_XOPEN_SHM                    94
#define _SC_2_CHAR_TERM                  95
#define _SC_2_UPE                        97
#define _SC_XOPEN_XPG2                   98
#define _SC_XOPEN_XPG3                   99
#define _SC_XOPEN_XPG4                   100
#define _SC_NZERO                        109
#define _SC_XBS5_ILP32_OFF32             125
#define _SC_XBS5_ILP32_OFFBIG            126
#define _SC_XBS5_LP64_OFF64              127
#define _SC_XBS5_LPBIG_OFFBIG            128
#define _SC_XOPEN_LEGACY                 129
#define _SC_XOPEN_REALTIME               130
#define _SC_XOPEN_REALTIME_THREADS       131
#define _SC_ADVISORY_INFO                132
#define _SC_BARRIERS                     133
#define _SC_CLOCK_SELECTION              137
#define _SC_CPUTIME                      138
#define _SC_THREAD_CPUTIME               139
#define _SC_MONOTONIC_CLOCK              149
#define _SC_READER_WRITER_LOCKS          153
#define _SC_SPIN_LOCKS                   154
#define _SC_REGEXP                       155
#define _SC_SHELL                        157
#define _SC_SPAWN                        159
#define _SC_SPORADIC_SERVER              160
#define _SC_THREAD_SPORADIC_SERVER       161
#define _SC_TIMEOUTS                     164
#define _SC_TYPED_MEMORY_OBJECTS         165
#define _SC_2_PBS                        168
#define _SC_2_PBS_ACCOUNTING             169
#define _SC_2_PBS_LOCATE                 170
#define _SC_2_PBS_MESSAGE                171
#define _SC_2_PBS_TRACK                  172
#define _SC_SYMLOOP_MAX                  173
#define _SC_STREAMS                      174
#define _SC_2_PBS_CHECKPOINT             175
#define _SC_V6_ILP32_OFF32               176
#define _SC_V6_ILP32_OFFBIG              177
#define _SC_V6_LP64_OFF64                178
#define _SC_V6_LPBIG_OFFBIG              179
#define _SC_HOST_NAME_MAX                180
#define _SC_TRACE                        181
#define _SC_TRACE_EVENT_FILTER           182
#define _SC_TRACE_INHERIT                183
#define _SC_TRACE_LOG                    184
#define _SC_IPV6                         235
#define _SC_RAW_SOCKETS                  236
#define _SC_V7_ILP32_OFF32               237
#define _SC_V7_ILP32_OFFBIG              238
#define _SC_V7_LP64_OFF64                239
#define _SC_V7_LPBIG_OFFBIG              240
#define _SC_SS_REPL_MAX                  241
#define _SC_TRACE_EVENT_NAME_MAX         242
#define _SC_TRACE_NAME_MAX               243
#define _SC_TRACE_SYS_MAX                244
#define _SC_TRACE_USER_EVENT_MAX         245
#define _SC_XOPEN_STREAMS                246
#define _SC_THREAD_ROBUST_PRIO_INHERIT   247
#define _SC_THREAD_ROBUST_PRIO_PROTECT   248
#define _SC_SIGSTKSZ                     249
#define _SC_MINSIGSTKSZ                  250

COSMOPOLITAN_C_START_

long sysconf(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/runtime/utmp.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMP_H_


/*!BEGIN libc/runtime/utmpx.h */

#define COSMOPOLITAN_LIBC_RUNTIME_UTMPX_H_
COSMOPOLITAN_C_START_

struct utmpx {
  short ut_type;
  pid_t ut_pid;
  char ut_line[32];
  char ut_id[4];
  char ut_user[32];
  char ut_host[256];
  struct {
    short __e_termination;
    short __e_exit;
  } ut_exit;
  long ut_session;
  struct timeval ut_tv;
  unsigned ut_addr_v6[4];
  char __unused[20];
};

void endutxent(void);
struct utmpx *getutxent(void);
struct utmpx *getutxid(const struct utmpx *);
struct utmpx *getutxline(const struct utmpx *);
struct utmpx *pututxline(const struct utmpx *);
void setutxent(void);

#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define e_exit        __e_exit
#define e_termination __e_termination
void updwtmpx(const char *, const struct utmpx *);
int utmpxname(const char *);
#endif

#define EMPTY         0
#define RUN_LVL       1
#define BOOT_TIME     2
#define NEW_TIME      3
#define OLD_TIME      4
#define INIT_PROCESS  5
#define LOGIN_PROCESS 6
#define USER_PROCESS  7
#define DEAD_PROCESS  8

COSMOPOLITAN_C_END_

#define ACCOUNTING  9
#define UT_NAMESIZE 32
#define UT_HOSTSIZE 256
#define UT_LINESIZE 32

COSMOPOLITAN_C_START_

struct lastlog {
  time_t ll_time;
  char ll_line[UT_LINESIZE];
  char ll_host[UT_HOSTSIZE];
};

#define ut_time       ut_tv.tv_sec
#define ut_name       ut_user
#define ut_addr       ut_addr_v6[0]
#define utmp          utmpx
#define e_exit        __e_exit
#define e_termination __e_termination

int login_tty(int);
int utmpname(const char *);
struct utmp *getutent(void);
struct utmp *getutid(const struct utmp *);
struct utmp *getutline(const struct utmp *);
struct utmp *pututline(const struct utmp *);
void endutent(void);
void setutent(void);
void updwtmp(const char *, const struct utmp *);

#define _PATH_UTMP "/dev/null/utmp"
#define _PATH_WTMP "/dev/null/wtmp"

#define UTMP_FILE     _PATH_UTMP
#define WTMP_FILE     _PATH_WTMP
#define UTMP_FILENAME _PATH_UTMP
#define WTMP_FILENAME _PATH_WTMP

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/alg.h */

#define COSMOPOLITAN_LIBC_SOCK_ALG_H_
COSMOPOLITAN_C_START_

struct sockaddr_alg {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[64];
};

struct sockaddr_alg_new {
  uint16_t salg_family;
  uint8_t salg_type[14];
  uint32_t salg_feat;
  uint32_t salg_mask;
  uint8_t salg_name[]; /* Linux v4.12+ */
};

struct af_alg_iv {
  uint32_t ivlen;
  uint8_t iv[0];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/epoll.h */

#define COSMOPOLITAN_LIBC_SOCK_WEPOLL_H_
COSMOPOLITAN_C_START_

typedef union epoll_data {
  void *ptr;
  int fd;
  uint32_t u32;
  uint64_t u64;
} epoll_data_t;

struct thatispacked epoll_event {
  uint32_t events;
  epoll_data_t data;
};

int epoll_create(int) libcesque;
int epoll_create1(int) libcesque;
int epoll_ctl(int, int, int, struct epoll_event *) libcesque;
int epoll_wait(int, struct epoll_event *, int, int) libcesque;
int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/ifaddrs.h */

#define COSMOPOLITAN_LIBC_SOCK_IFADDRS_H_
COSMOPOLITAN_C_START_

struct ifaddrs {
  struct ifaddrs *ifa_next;
  char *ifa_name;
  unsigned ifa_flags;
  struct sockaddr *ifa_addr;
  struct sockaddr *ifa_netmask;
  union {
    struct sockaddr *ifa_broadaddr;
    struct sockaddr *ifa_dstaddr;
  };
  void *ifa_data;
};

void freeifaddrs(struct ifaddrs *) libcesque;
int getifaddrs(struct ifaddrs **) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/in.h */

#define COSMOPOLITAN_LIBC_SOCK_IN_H_

#define IN_CLASSA(a)       ((((in_addr_t)(a)) & 0x80000000) == 0)
#define IN_CLASSA_NET      0xff000000
#define IN_CLASSA_NSHIFT   24
#define IN_CLASSA_HOST     (0xffffffff & ~IN_CLASSA_NET)
#define IN_CLASSA_MAX      128
#define IN_CLASSB(a)       ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000)
#define IN_CLASSB_NET      0xffff0000
#define IN_CLASSB_NSHIFT   16
#define IN_CLASSB_HOST     (0xffffffff & ~IN_CLASSB_NET)
#define IN_CLASSB_MAX      65536
#define IN_CLASSC(a)       ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000)
#define IN_CLASSC_NET      0xffffff00
#define IN_CLASSC_NSHIFT   8
#define IN_CLASSC_HOST     (0xffffffff & ~IN_CLASSC_NET)
#define IN_CLASSD(a)       ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000)
#define IN_MULTICAST(a)    IN_CLASSD(a)
#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000)
#define IN_BADCLASS(a)     ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000)

#define IN6_IS_ADDR_UNSPECIFIED(a)                           \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint32_t *)(a))[3] == 0)

#define IN6_IS_ADDR_LOOPBACK(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[12] == 0 && \
   ((uint8_t *)(a))[13] == 0 && ((uint8_t *)(a))[14] == 0 && \
   ((uint8_t *)(a))[15] == 1)

#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *)(a))[0] == 0xff)

#define IN6_IS_ADDR_LINKLOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0x80)

#define IN6_IS_ADDR_SITELOCAL(a) \
  ((((uint8_t *)(a))[0]) == 0xfe && (((uint8_t *)(a))[1] & 0xc0) == 0xc0)

#define IN6_IS_ADDR_V4MAPPED(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint8_t *)(a))[8] == 0 && ((uint8_t *)(a))[9] == 0 &&   \
   ((uint8_t *)(a))[10] == 0xff && ((uint8_t *)(a))[11] == 0xff)

#define IN6_IS_ADDR_V4COMPAT(a)                              \
  (((uint32_t *)(a))[0] == 0 && ((uint32_t *)(a))[1] == 0 && \
   ((uint32_t *)(a))[2] == 0 && ((uint8_t *)(a))[15] > 1)

#define IN6_IS_ADDR_MC_NODELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x1))

#define IN6_IS_ADDR_MC_LINKLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x2))

#define IN6_IS_ADDR_MC_SITELOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x5))

#define IN6_IS_ADDR_MC_ORGLOCAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0x8))

#define IN6_IS_ADDR_MC_GLOBAL(a) \
  (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *)(a))[1] & 0xf) == 0xe))

#define __ARE_4_EQUAL(a, b) \
  (!((0 [a] - 0 [b]) | (1 [a] - 1 [b]) | (2 [a] - 2 [b]) | (3 [a] - 3 [b])))
#define IN6_ARE_ADDR_EQUAL(a, b) \
  __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b))



/*!BEGIN libc/sock/select.h */

#define COSMOPOLITAN_LIBC_SOCK_SELECT_H_

#define FD_SETSIZE 1024 /* it's 64 on windows */

COSMOPOLITAN_C_START_

typedef struct fd_set {
  unsigned long fds_bits[FD_SETSIZE / (sizeof(long) * 8)];
} fd_set;

#define FD_ISSET(FD, SET) (((SET)->fds_bits[(FD) >> 6] >> ((FD)&63)) & 1)
#define FD_SET(FD, SET)   ((SET)->fds_bits[(FD) >> 6] |= 1ull << ((FD)&63))
#define FD_CLR(FD, SET)   ((SET)->fds_bits[(FD) >> 6] &= ~(1ull << ((FD)&63)))
#define FD_ZERO(SET)      bzero((SET)->fds_bits, sizeof((SET)->fds_bits))
#define FD_SIZE(bits)     (((bits) + (sizeof(long) * 8) - 1) / sizeof(long))

int select(int, fd_set *, fd_set *, fd_set *, struct timeval *) libcesque;
int pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
            const sigset_t *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/syslog.h */

#define COSMOPOLITAN_LIBC_SOCK_SYSLOG_H_
COSMOPOLITAN_C_START_

int setlogmask(int) libcesque;
void openlog(const char *, int, int) libcesque;
void syslog(int, const char *, ...) libcesque;
void closelog(void) libcesque;
void vsyslog(int, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arphdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPHDR_H_
COSMOPOLITAN_C_START_

struct arphdr {
  uint16_t ar_hrd;
  uint16_t ar_pro;
  uint8_t ar_hln;
  uint8_t ar_pln;
  uint16_t ar_op;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/arpreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ARPREQ_H_
COSMOPOLITAN_C_START_

struct arpreq {
  struct sockaddr arp_pa;
  struct sockaddr arp_ha;
  int arp_flags;
  struct sockaddr arp_netmask;
  char arp_dev[16];
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/cmsghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_CMSGHDR_H_
COSMOPOLITAN_C_START_

#define CMSG_DATA(cmsg) ((unsigned char *)(((struct cmsghdr *)(cmsg)) + 1))

#define CMSG_FIRSTHDR(mhdr)                                 \
  ((size_t)(mhdr)->msg_controllen >= sizeof(struct cmsghdr) \
       ? (struct cmsghdr *)(mhdr)->msg_control              \
       : (struct cmsghdr *)0)

#define CMSG_NXTHDR(mhdr, cmsg)                           \
  ((cmsg)->cmsg_len < sizeof(struct cmsghdr) ||           \
           __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >=   \
               __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
       ? 0                                                \
       : (struct cmsghdr *)__CMSG_NEXT(cmsg))

#define CMSG_ALIGN(len) \
  (((len) + sizeof(size_t) - 1) & (size_t) ~(sizeof(size_t) - 1))

#define CMSG_SPACE(len) (CMSG_ALIGN(len) + CMSG_ALIGN(sizeof(struct cmsghdr)))

#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))

#define __CMSG_LEN(cmsg) \
  (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
#define __MHDR_END(mhdr) \
  ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)

struct cmsghdr { /* linux abi */
  uint32_t cmsg_len;
  uint32_t __pad1;
  int32_t cmsg_level;
  int32_t cmsg_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ether_header.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_ETHER_HEADER_H_

#define ETH_ALEN 6

COSMOPOLITAN_C_START_

struct ether_addr {
  uint8_t ether_addr_octet[ETH_ALEN];
};

struct ether_header {
  uint8_t ether_dhost[ETH_ALEN];
  uint8_t ether_shost[ETH_ALEN];
  uint16_t ether_type;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ifconf.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFCONF_H_


/*!BEGIN libc/sock/struct/ifreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IFREQ_H_
COSMOPOLITAN_C_START_

#define IF_NAMESIZE 16
#define IFNAMSIZ    IF_NAMESIZE

struct ifreq {
  union {
    char ifrn_name[IFNAMSIZ]; /* Interface name, e.g. "en0".  */
  } ifr_ifrn;
  union {
    struct sockaddr ifru_addr;      /* SIOCGIFADDR */
    struct sockaddr ifru_dstaddr;   /* SIOCGIFDSTADDR */
    struct sockaddr ifru_netmask;   /* SIOCGIFNETMASK */
    struct sockaddr ifru_broadaddr; /* SIOCGIFBRDADDR */
    short ifru_flags;               /* SIOCGIFFLAGS */
    int ifru_ivalue;                /* todo(jart) */
    char ifru_pad[24];              /* ifru_map is the largest, just pad */
  } ifr_ifru;
};

#define ifr_name      ifr_ifrn.ifrn_name      /* interface name */
#define ifr_addr      ifr_ifru.ifru_addr      /* address */
#define ifr_netmask   ifr_ifru.ifru_netmask   /* netmask */
#define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */
#define ifr_dstaddr   ifr_ifru.ifru_dstaddr   /* destination address */
#define ifr_flags     ifr_ifru.ifru_flags     /* flags */
#define ifr_ifindex   ifr_ifru.ifru_ivalue

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/*
 * Structure used in SIOCGIFCONF request.
 * Used to retrieve interface configuration
 * for machine (useful for programs which
 * must know all networks accessible).
 */
struct ifconf {
  int32_t ifc_len; /* size of buffer */
  int32_t padding;
  union {
    char *ifcu_buf;
    struct ifreq *ifcu_req;
  } ifc_ifcu;
};

/* Shortcuts to the ifconf buffer or ifreq array */
#define ifc_buf ifc_ifcu.ifcu_buf /* buffer address   */
#define ifc_req ifc_ifcu.ifcu_req /* array of structures  */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in6_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN6_PKTINFO_H_


/*!BEGIN libc/sock/struct/sockaddr6.h */

#define COSMOPOLITAN_LIBC_CALLS_STRUCT_SOCKADDR6_H_

struct in6_addr {
  union {
    uint8_t s6_addr[16];
    uint16_t s6_addr16[8];
    uint32_t s6_addr32[4];
  };
};

struct sockaddr_in6 { /* Linux+NT ABI */
  uint16_t sin6_family;
  uint16_t sin6_port;
  uint32_t sin6_flowinfo;
  struct in6_addr sin6_addr;
  uint32_t sin6_scope_id; /* rfc2553 */
};

extern const struct in6_addr in6addr_any;
extern const struct in6_addr in6addr_loopback;

COSMOPOLITAN_C_START_

struct in6_pktinfo {
  struct in6_addr ipi6_addr;
  unsigned ipi6_ifindex;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/in_pktinfo.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IN_PKTINFO_H_
COSMOPOLITAN_C_START_

struct in_pktinfo {
  int ipi_ifindex;
  struct in_addr ipi_spec_dst;
  struct in_addr ipi_addr;
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ip_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IP_MREQ_H_
COSMOPOLITAN_C_START_

struct ip_mreq {
  struct in_addr imr_multiaddr; /* IP multicast address of group */
  struct in_addr imr_interface; /* local IP address of interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/ipv6_mreq.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_IPV6_MREQ_H_
COSMOPOLITAN_C_START_

struct ipv6_mreq {
  struct in6_addr ipv6mr_multiaddr; /* IPv6 multicast address of group */
  unsigned ipv6mr_interface;        /* local interface */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/linger.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_LINGER_H_
COSMOPOLITAN_C_START_

struct linger {     /* Linux+XNU+BSD ABI */
  int32_t l_onoff;  /* on/off */
  int32_t l_linger; /* seconds */
};

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/msghdr.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_MSGHDR_H_
COSMOPOLITAN_C_START_

struct msghdr {            /* Linux+NT ABI */
  void *msg_name;          /* optional address */
  uint32_t msg_namelen;    /* size of msg_name */
  struct iovec *msg_iov;   /* scatter/gather array */
  uint64_t msg_iovlen;     /* # elements in msg_iov */
  void *msg_control;       /* ancillary data c. cmsghdr */
  uint64_t msg_controllen; /* ancillary data buffer len */
  uint32_t msg_flags;      /* MSG_XXX */
};

ssize_t recvmsg(int, struct msghdr *, int);
ssize_t sendmsg(int, const struct msghdr *, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/sock/struct/pollfd.h */

#define COSMOPOLITAN_LIBC_SOCK_STRUCT_POLLFD_H_
COSMOPOLITAN_C_START_

struct pollfd {
  int32_t fd;
  int16_t events;
  int16_t revents;
};

int poll(struct pollfd *, uint64_t, int32_t);
int ppoll(struct pollfd *, uint64_t, const struct timespec *, const sigset_t *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/append.h */

#ifndef COSMOPOLITAN_LIBC_STDIO_APPEND_H_
#define COSMOPOLITAN_LIBC_STDIO_APPEND_H_

#define APPEND_COOKIE 21578

#define appendz   __appendz
#define appendr   __appendr
#define appendd   __appendd
#define appendw   __appendw
#define appends   __appends
#define appendf   __appendf
#define vappendf  __vappendf
#define kappendf  __kappendf
#define kvappendf __kvappendf

COSMOPOLITAN_C_START_

struct appendz {
  size_t i;
  size_t n;
};

struct appendz appendz(char *) libcesque;
ssize_t appendr(char **, size_t) libcesque;
ssize_t appendd(char **, const void *, size_t) libcesque;
ssize_t appendw(char **, uint64_t) libcesque;
ssize_t appends(char **, const char *) libcesque;
ssize_t appendf(char **, const char *, ...) libcesque;
ssize_t vappendf(char **, const char *, va_list) libcesque;
ssize_t kappendf(char **, const char *, ...) libcesque;
ssize_t kvappendf(char **, const char *, va_list) libcesque;

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_STDIO_APPEND_H_ */


/*!BEGIN libc/stdio/dprintf.h */

#define COSMOPOLITAN_LIBC_CALLS_DPRINTF_H_
COSMOPOLITAN_C_START_

libcesque int dprintf(int, const char *, ...) paramsnonnull((2));
libcesque int vdprintf(int, const char *, va_list) paramsnonnull();

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/ftw.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_FTW_H_
COSMOPOLITAN_C_START_

/**
 * Type for file.
 */
#define FTW_F 1

/**
 * Type for directory.
 */
#define FTW_D 2

/**
 * Type for directory that cannot be read.
 */
#define FTW_DNR 3

/**
 * Type for stat() failed and not a symbolic link.
 */
#define FTW_NS 4

/**
 * Type for symbolic link when `FTW_PHYS` is in flags.
 */
#define FTW_SL 5

/**
 * Directory and `FTW_DEPTH` in flags.
 */
#define FTW_DP 6

/**
 * Type for broken symbolic link when `FTW_PHYS` is not in flags.
 */
#define FTW_SLN 7

/**
 * Flag to prevent following symbolic links (recommended).
 * @see nftw() flags
 */
#define FTW_PHYS 1

/**
 * Flag to prevent crossing mount points.
 * @see nftw() flags
 */
#define FTW_MOUNT 2

/**
 * Unsupported.
 * @see nftw() flags
 */
#define FTW_CHDIR 4

/**
 * Flag for post-order traversal.
 *
 * 1. Will use `FTW_DP` instead of `FTW_D` as type.
 * 2. Directory callback happens *after* rather than before.
 *
 * @see nftw() flags
 */
#define FTW_DEPTH 8

struct FTW {

  /**
   * Byte offset of basename component in `fpath` passed to callback.
   */
  int base;

  /**
   * Depth relative to `dirpath` whose level is zero.
   */
  int level;
};

int ftw(const char *, int (*)(const char *, const struct stat *, int),
        int) dontthrow;

int nftw(const char *,
         int (*)(const char *, const struct stat *, int, struct FTW *), int,
         int) dontthrow;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/iconv.h */

#define COSMOPOLITAN_LIBC_STDIO_ICONV_H_
COSMOPOLITAN_C_START_

typedef void *iconv_t;

iconv_t iconv_open(const char *, const char *);
size_t iconv(iconv_t, char **, size_t *, char **, size_t *);
int iconv_close(iconv_t);

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/rand.h */

#define COSMOPOLITAN_LIBC_RAND_RAND_H_
#define RAND_MAX __INT_MAX__
COSMOPOLITAN_C_START_
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § random                                                    ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

int rand(void) libcesque;
void srand(unsigned) libcesque;
char *strfry(char *) libcesque;
int getentropy(void *, size_t) libcesque;
ssize_t getrandom(void *, size_t, unsigned) libcesque;
char *initstate(unsigned, char *, size_t) libcesque;
char *setstate(char *) libcesque;
long random(void) libcesque;
void srandom(unsigned) libcesque;

#ifdef _COSMO_SOURCE
#define vigna   __vigna
#define vigna_r __vigna_r
#define rngset  __rngset
#define rdrand  __rdrand
#define rdseed  __rdseed
double poz(double) libcesque;
double pochisq(double, int) libcesque;
uint64_t lemur64(void) libcesque;
uint64_t _rand64(void) libcesque;
uint64_t vigna(void) libcesque;
uint64_t vigna_r(uint64_t[hasatleast 1]) libcesque;
void svigna(uint64_t) libcesque;
uint64_t rdrand(void) libcesque;
uint64_t rdseed(void) libcesque;
void _smt19937(uint64_t) libcesque;
void _Smt19937(uint64_t[], size_t) libcesque;
uint64_t _mt19937(void) libcesque;
double _real1(uint64_t) libcesque;
double _real2(uint64_t) libcesque;
double _real3(uint64_t) libcesque;
double MeasureEntropy(const char *, size_t) libcesque;
void *rngset(void *, size_t, uint64_t (*)(void), size_t) libcesque;
void rt_init(int) libcesque;
void rt_add(void *, int) libcesque;
void rt_end(double *, double *, double *, double *, double *) libcesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/readpassphrase.h */

#define COSMOPOLITAN_LIBC_STDIO_READPASSPHRASE_H_

#define RPP_ECHO_OFF    0x00
#define RPP_ECHO_ON     0x01
#define RPP_REQUIRE_TTY 0x02
#define RPP_FORCELOWER  0x04
#define RPP_FORCEUPPER  0x08
#define RPP_SEVENBIT    0x10
#define RPP_STDIN       0x20

COSMOPOLITAN_C_START_

char *readpassphrase(const char *, char *, size_t, int) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/stdio_ext.h */

#define COSMOPOLITAN_LIBC_STDIO_STDIO_EXT_H_

#define FSETLOCKING_QUERY    0
#define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_BYCALLER 2

COSMOPOLITAN_C_START_

size_t __fbufsize(FILE *) libcesque;
size_t __fpending(FILE *) libcesque;
int __flbf(FILE *) libcesque;
int __freadable(FILE *) libcesque;
int __fwritable(FILE *) libcesque;
int __freading(FILE *) libcesque;
int __fwriting(FILE *) libcesque;
int __fsetlocking(FILE *, int) libcesque;
void _flushlbf(void) libcesque;
void __fpurge(FILE *) libcesque;
void __fseterr(FILE *) libcesque;
const char *__freadptr(FILE *, size_t *) libcesque;
size_t __freadahead(FILE *) libcesque;
void __freadptrinc(FILE *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/syscall.h */

#define COSMOPOLITAN_LIBC_STDIO_SYSCALL_H_
COSMOPOLITAN_C_START_

#define SYS_gettid    1
#define SYS_getrandom 2
#define SYS_getcpu    3

long syscall(long, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/stdio/sysparam.h */

#define COSMOPOLITAN_LIBC_SYSPARAM_H_

#define MAXSYMLINKS    20
#define MAXHOSTNAMELEN 64
#define MAXNAMLEN      255
#define MAXPATHLEN     PATH_MAX
#define NBBY           8
#define NGROUPS        32
#define CANBSIZ        255
#define NOFILE         256
#define NCARGS         131072
#define DEV_BSIZE      512
#define NOGROUP        (-1)

COSMOPOLITAN_C_START_

#define __bitop(x, i, o) ((x)[(i) / 8] o(1 << (i) % 8))
#define setbit(x, i)     __bitop(x, i, |=)
#define clrbit(x, i)     __bitop(x, i, &= ~)
#define isset(x, i)      __bitop(x, i, &)
#define isclr(x, i)      !isset(x, i)

#undef roundup
#define roundup(n, d) (howmany(n, d) * (d))
#define powerof2(n)   !(((n)-1) & (n))
#define howmany(n, d) (((n) + ((d)-1)) / (d))

#ifdef MIN
#undef MIN
#endif
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

#ifdef MAX
#undef MAX
#endif
#define MAX(a, b) (((a) > (b)) ? (a) : (b))

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/ntspawn.h */

#define COSMOPOLITAN_NTSPAWN_H_
COSMOPOLITAN_C_START_

struct NtSpawnArgs {
  int64_t dirhand;
  const char *prog;
  char *const *argv;
  char *const *envp;
  char *const *extravars;
  uint32_t dwCreationFlags;
  const char16_t *opt_lpCurrentDirectory;
  int64_t opt_hParentProcess;
  int64_t *opt_lpExplicitHandleList;
  uint32_t dwExplicitHandleCount;
  const struct NtStartupInfo *lpStartupInfo;
  struct NtProcessInformation *opt_out_lpProcessInformation;
};

int mkntenvblock(char16_t[32767], char *const[], char *const[], char[32767]);
int ntspawn(struct NtSpawnArgs *);
size_t mkntcmdline(char16_t *, char *const[], size_t);
void mungentpath(char *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/proc/posix_spawn.h */

#define COSMOPOLITAN_LIBC_STDIO_SPAWN_H_

#define POSIX_SPAWN_USEVFORK      0
#define POSIX_SPAWN_RESETIDS      1
#define POSIX_SPAWN_SETPGROUP     2
#define POSIX_SPAWN_SETSIGDEF     4
#define POSIX_SPAWN_SETSIGMASK    8
#define POSIX_SPAWN_SETSCHEDPARAM 16
#define POSIX_SPAWN_SETSCHEDULER  32
#define POSIX_SPAWN_SETSID        128
#define POSIX_SPAWN_SETRLIMIT     256

COSMOPOLITAN_C_START_

typedef struct _posix_spawna *posix_spawnattr_t;
typedef struct _posix_faction *posix_spawn_file_actions_t;

int posix_spawn(int *, const char *, const posix_spawn_file_actions_t *,
                const posix_spawnattr_t *, char *const[], char *const[]);
int posix_spawnp(int *, const char *, const posix_spawn_file_actions_t *,
                 const posix_spawnattr_t *, char *const[], char *const[]);

int posix_spawn_file_actions_init(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *) libcesque;
int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *,
                                      int) libcesque;
int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int,
                                     int) libcesque;
int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *, int,
                                     const char *, int, unsigned) libcesque;
int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *,
                                         const char *) libcesque;
int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *,
                                          int) libcesque;

int posix_spawnattr_init(posix_spawnattr_t *) libcesque;
int posix_spawnattr_destroy(posix_spawnattr_t *) libcesque;
int posix_spawnattr_getflags(const posix_spawnattr_t *, short *) libcesque;
int posix_spawnattr_setflags(posix_spawnattr_t *, short) libcesque;
int posix_spawnattr_getpgroup(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setpgroup(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *, int *) libcesque;
int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int) libcesque;
int posix_spawnattr_getschedparam(const posix_spawnattr_t *,
                                  struct sched_param *) libcesque;
int posix_spawnattr_setschedparam(posix_spawnattr_t *,
                                  const struct sched_param *) libcesque;
int posix_spawnattr_getsigmask(const posix_spawnattr_t *, sigset_t *) libcesque;
int posix_spawnattr_setsigmask(posix_spawnattr_t *, const sigset_t *) libcesque;
int posix_spawnattr_getsigdefault(const posix_spawnattr_t *,
                                  sigset_t *) libcesque;
int posix_spawnattr_setsigdefault(posix_spawnattr_t *,
                                  const sigset_t *) libcesque;
int posix_spawnattr_getrlimit(const posix_spawnattr_t *, int,
                              struct rlimit *) libcesque;
int posix_spawnattr_setrlimit(posix_spawnattr_t *, int,
                              const struct rlimit *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/atomic.h */

#define NSYNC_ATOMIC_H_
COSMOPOLITAN_C_START_

#define nsync_atomic_uint32_ atomic_uint

#define NSYNC_ATOMIC_UINT32_INIT_        0
#define NSYNC_ATOMIC_UINT32_LOAD_(p)     (*(p))
#define NSYNC_ATOMIC_UINT32_STORE_(p, v) (*(p) = (v))
#define NSYNC_ATOMIC_UINT32_PTR_(p)      (p)

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/counter.h */

#define NSYNC_COUNTER_H_


/*!BEGIN third_party/nsync/time.h */

#define NSYNC_TIME_H_
COSMOPOLITAN_C_START_

#define NSYNC_TIME_SEC(t)  ((t).tv_sec)
#define NSYNC_TIME_NSEC(t) ((t).tv_nsec)
#define NSYNC_TIME_STATIC_INIT(t, ns) \
  { (t), (ns) }

/* The type nsync_time represents the interval elapsed between two
   moments in time. Often the first such moment is an address-space-wide
   epoch, such as the Unix epoch, but clients should not rely on the
   epoch in one address space being the same as that in another.
   Intervals relative to the epoch are known as absolute times. */
typedef struct timespec nsync_time;

/* A deadline infinitely far in the future. */
#define nsync_time_no_deadline timespec_max

/* The zero delay, or an expired deadline. */
#define nsync_time_zero timespec_zero

/* Return the current time since the epoch.  */
#define nsync_time_now() timespec_real()

/* Sleep for the specified delay. Returns the unslept time which may be
   non-zero if the call was interrupted. */
#define nsync_time_sleep(a) timespec_sleep(a)

/* Sleep until the specified time.  Returns 0 on success, and EINTR
   if the call was interrupted. */
#define nsync_time_sleep_until(a) timespec_sleep_until(a)

/* Return a+b */
#define nsync_time_add(a, b) timespec_add(a, b)

/* Return a-b */
#define nsync_time_sub(a, b) timespec_sub(a, b)

/* Return +ve, 0, or -ve according to whether a>b, a==b, or a<b. */
#define nsync_time_cmp(a, b) timespec_cmp(a, b)

/* Return the specified number of milliseconds as a time. */
#define nsync_time_ms(a) timespec_frommillis(a)

/* Return the specified number of microseconds as a time. */
#define nsync_time_us(a) timespec_frommicros(a)

/* Return the specified number of nanoseconds as a time. */
#define nsync_time_ns(a) timespec_fromnanos(a)

/* Return an nsync_time constructed from second and nanosecond
   components */
#define nsync_time_s_ns(s, ns) ((nsync_time){(int64_t)(s), (unsigned)(ns)})

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

/* An nsync_counter represents an unsigned integer that can count up and down,
   and wake waiters when zero.  */
typedef struct nsync_counter_s_ *nsync_counter;

/* Return a freshly allocated nsync_counter with the specified value,
   of NULL if an nsync_counter cannot be created.

   Any non-NULL returned value should be passed to nsync_counter_free() when no
   longer needed.  */
nsync_counter nsync_counter_new(uint32_t value);

/* Free resources associated with c.  Requires that c was allocated by
   nsync_counter_new(), and no concurrent or future operations are applied to
   c.  */
void nsync_counter_free(nsync_counter c);

/* Add delta to c, and return its new value.  It is a checkable runtime error
   to decrement c below 0, or to increment c (i.e., apply a delta > 0) after a
   waiter has waited.  */
uint32_t nsync_counter_add(nsync_counter c, int32_t delta);

/* Return the current value of c.  */
uint32_t nsync_counter_value(nsync_counter c);

/* Wait until c has value 0, or until abs_deadline, then return
   the value of c.  It is a checkable runtime error to increment c after
   a waiter may have been woken due to the counter reaching zero.
   If abs_deadline==nsync_time_no_deadline, the deadline
   is far in the future. */
uint32_t nsync_counter_wait(nsync_counter c, nsync_time abs_deadline);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/cv.h */

#define NSYNC_CV_H_


/*!BEGIN third_party/nsync/mu.h */

#define NSYNC_MU_H_
COSMOPOLITAN_C_START_

/* An nsync_mu is a lock. If initialized to zero, it's valid and unlocked.

   An nsync_mu can be "free", held by a single thread (aka fiber,
   goroutine) in "write" (exclusive) mode, or by many threads in "read"
   (shared) mode. A thread that acquires it should eventually release
   it. It is illegal to acquire an nsync_mu in one thread and release it
   in another. It is illegal for a thread to reacquire an nsync_mu while
   holding it (even a second share of a "read" lock).

   Example usage:

       static struct foo {
         nsync_mu mu; // protects invariant a+b==0 on fields below.
         int a;
         int b;
       } p = { NSYNC_MU_INIT, 0, 0 };
       // ....
       nsync_mu_lock (&p.mu);
       // The current thread now has exclusive access to p.a and p.b;
       // invariant assumed true.
       p.a++;
       p.b--; // restore invariant p.a+p.b==0 before releasing p.mu
       nsync_mu_unlock (&p.mu)

   Mutexes can be used with condition variables; see nsync_cv.h.

   nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. See nsync_mu_wait.h for more details. Example
   use of nsync_mu_wait() to wait for p.a==0, using definition above:

        int a_is_zero (const void *condition_arg) {
                return (((const struct foo *)condition_arg)->a == 0);
        }
        ...
        nsync_mu_lock (&p.mu);
        nsync_mu_wait (&p.mu, &a_is_zero, &p, NULL);
        // The current thread now has exclusive access to
        // p.a and p.b, and p.a==0.
        ...
        nsync_mu_unlock (&p.mu);

*/
typedef struct nsync_mu_s_ {
  nsync_atomic_uint32_ word; /* internal use only */
  int _zero;                 /* c pthread_mutex_t */
  struct Dll *waiters;       /* internal use only */
} nsync_mu;

/* An nsync_mu should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_MU_INIT, or by setting
   the entire structure to all zeroes, or using nsync_mu_init(). */
#define NSYNC_MU_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }
void nsync_mu_init(nsync_mu *mu);

/* Block until *mu is free and then acquire it in writer mode. Requires
   that the calling thread not already hold *mu in any mode. */
void nsync_mu_lock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in write mode by the
   calling thread, and wake waiters, if appropriate. */
void nsync_mu_unlock(nsync_mu *mu);

/* Attempt to acquire *mu in writer mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. */
int nsync_mu_trylock(nsync_mu *mu);

/* Block until *mu can be acquired in reader mode and then acquire it.
   Requires that the calling thread not already hold *mu in any mode. */
void nsync_mu_rlock(nsync_mu *mu);

/* Unlock *mu, which must have been acquired in read mode by the calling
   thread, and wake waiters, if appropriate. */
void nsync_mu_runlock(nsync_mu *mu);

/* Attempt to acquire *mu in reader mode without blocking, and return
   non-zero iff successful. Return non-zero with high probability if *mu
   was free on entry. Perhaps fail to acquire if a writer is waiting, to
   avoid starvation. */
int nsync_mu_rtrylock(nsync_mu *mu);

/* May abort if *mu is not held in write mode by the calling thread. */
void nsync_mu_assert_held(const nsync_mu *mu);

/* May abort if *mu is not held in read or write mode
   by the calling thread.  */
void nsync_mu_rassert_held(const nsync_mu *mu);

/* Return whether *mu is held in read mode.
   Requires that the calling thread holds *mu in some mode. */
int nsync_mu_is_reader(const nsync_mu *mu);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

#define NSYNC_CV_INIT \
  { NSYNC_ATOMIC_UINT32_INIT_, 0 }

struct nsync_note_s_;

/* An nsync_cv is a condition variable in the style of Mesa, Java,
   POSIX, and Go's sync.Cond. It allows a thread to wait for a condition
   on state protected by a mutex, and to proceed with the mutex held and
   the condition true.

   See also nsync_mu_wait() and nsync_mu_wait_with_deadline(), which
   implement conditional critical sections. In many cases, they are
   easier to use than condition variables.

   Usage

   After making the desired predicate true, call:

       nsync_cv_signal (&cv);    // If at most one thread can make use
                                 // of the predicate becoming true.

   or

       nsync_cv_broadcast (&cv); // If multiple threads can make use
                                 // of the predicate becoming true.

   To wait for a predicate with no deadline (assuming
   nsync_cv_broadcast() or nsync_cv_signal() is called whenever the
   predicate becomes true):

       nsync_mu_lock (&mu;)
       while (!some_predicate_protected_by_mu) { // while-loop required
         nsync_cv_wait (&cv, &mu);
       }
       // predicate is now true
       nsync_mu_unlock (&mu);

   To wait for a predicate with a deadline (assuming nsync_cv_broadcast() or
   nsync_cv_signal() is called whenever the predicate becomes true):

       nsync_mu_lock (&mu);
       while (!some_predicate_protected_by_mu &&
         nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                      cancel_note) == 0) {
       }
       if (some_predicate_protected_by_mu) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   or, if the predicate is complex and you wish to write it just once
   and inline, you could use the following instead of the for-loop
   above:

       nsync_mu_lock (&mu);
       int pred_is_true = 0;
       int outcome = 0;
       while (!(pred_is_true = some_predicate_protected_by_mu) &&
              outcome == 0) {
         outcome = nsync_cv_wait_with_deadline (&cv, &mu, abs_deadline,
                                                cancel_note);
       }
       if (pred_is_true) { // predicate is true
       } else {
         // predicate is false, and deadline expired, or
         // cancel_note was notified.
       }
       nsync_mu_unlock (&mu);

   As the examples show, Mesa-style condition variables require that
   waits use a loop that tests the predicate anew after each wait. It
   may be surprising that these are preferred over the precise wakeups
   offered by the condition variables in Hoare monitors. Imprecise
   wakeups make more efficient use of the critical section, because
   threads can enter it while a woken thread is still emerging from the
   scheduler, which may take thousands of cycles. Further, they make the
   programme easier to read and debug by making the predicate explicit
   locally at the wait, where the predicate is about to be assumed; the
   reader does not have to infer the predicate by examining all the
   places where wakeups may occur. */
typedef struct nsync_cv_s_ {
  /* see bits below */
  nsync_atomic_uint32_ word;
  /* points to tail of list of waiters; under mu. */
  struct Dll *waiters;
} nsync_cv;

/* An nsync_cv should be zeroed to initialize, which can be accomplished
   by initializing with static initializer NSYNC_CV_INIT, or by setting
   the entire struct to 0, or using nsync_cv_init(). */
void nsync_cv_init(nsync_cv *cv);

/* Wake at least one thread if any are currently blocked on *cv. If the
   chosen thread is a reader on an nsync_mu, wake all readers and, if
   possible, a writer. */
void nsync_cv_signal(nsync_cv *cv);

/* Wake all threads currently blocked on *cv. */
void nsync_cv_broadcast(nsync_cv *cv);

/* Atomically release "mu" (which must be held on entry) and block the
   caller on *cv. Wait until awakened by a call to nsync_cv_signal() or
   nsync_cv_broadcast(), or a spurious wakeup; then reacquire "mu", and
   return. Equivalent to a call to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL. Callers
   should use nsync_cv_wait() in a loop, as with all standard Mesa-style
   condition variables. See examples above. Returns 0 normally, otherwise
   ECANCELED may be returned if calling POSIX thread is cancelled only when
   the PTHREAD_CANCEL_MASKED mode is in play. */
int nsync_cv_wait(nsync_cv *cv, nsync_mu *mu);

/* Atomically release "mu" (which must be held on entry) and block the
   calling thread on *cv. It then waits until awakened by a call to
   nsync_cv_signal() or nsync_cv_broadcast() (or a spurious wakeup), or
   by the time reaching abs_deadline, or by cancel_note being notified.
   In all cases, it reacquires "mu", and returns the reason for the call
   returned (0, ETIMEDOUT, or ECANCELED). Use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no nsync cancellations (however POSIX thread
   cancellations may still happen, and ECANCELED could still be returned
   when the calling thread is cancelled only if PTHREAD_CANCEL_MASKED is
   in play). wait_with_deadline() should be used in a loop, as with all
   Mesa-style condition variables. See examples above.

   There are two reasons for using an absolute deadline, rather than a
   relative timeout---these are why pthread_cond_timedwait() also uses
   an absolute deadline. First, condition variable waits have to be used
   in a loop; with an absolute times, the deadline does not have to be
   recomputed on each iteration. Second, in most real programmes, some
   activity (such as an RPC to a server, or when guaranteeing response
   time in a UI), there is a deadline imposed by the specification or
   the caller/user; relative delays can shift arbitrarily with
   scheduling delays, and so after multiple waits might extend beyond
   the expected deadline. Relative delays tend to be more convenient
   mostly in tests and trivial examples than they are in real
   programmes. */
int nsync_cv_wait_with_deadline(nsync_cv *cv, nsync_mu *mu,
                                nsync_time abs_deadline,
                                struct nsync_note_s_ *cancel_note);

/* Like nsync_cv_wait_with_deadline(), but allow an arbitrary lock *v to be
   used, given its (*lock)(mu) and (*unlock)(mu) routines.  */
int nsync_cv_wait_with_deadline_generic(nsync_cv *cv, void *mu,
                                        void (*lock)(void *),
                                        void (*unlock)(void *),
                                        nsync_time abs_deadline,
                                        struct nsync_note_s_ *cancel_note);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/debug.h */

#define NSYNC_DEBUG_H_
COSMOPOLITAN_C_START_

/* Debugging operations for mutexes and condition variables.

   These operations should not be relied upon for normal functionality.
   The implementation may be slow, output formats may change, and the
   implementation is free to yield the empty string. */

/* Place in buf[0,..,n-1] a nul-terminated, human readable string
   indicative of some of the internal state of the mutex or condition
   variable, and return buf. If n>=4, buffer overflow is indicated by
   placing the characters "..." at the end of the string.

   The *_and_waiters() variants attempt to output the waiter lists in
   addition to the basic state. These variants may acquire internal
   locks and follow internal pointers. Thus, they are riskier if invoked
   in an address space whose overall health is uncertain. */
char *nsync_mu_debug_state(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state(nsync_cv *cv, char *buf, int n);
char *nsync_mu_debug_state_and_waiters(nsync_mu *mu, char *buf, int n);
char *nsync_cv_debug_state_and_waiters(nsync_cv *cv, char *buf, int n);

/* Like nsync_*_debug_state_and_waiters(), but ignoring all locking and
   safety considerations, and using an internal, possibly static buffer
   that may be overwritten by subsequent or concurrent calls to these
   routines. These variants should be used only from an interactive
   debugger, when all other threads are stopped; the debugger is
   expected to recover from errors. */
char *nsync_mu_debugger(nsync_mu *mu);
char *nsync_cv_debugger(nsync_cv *cv);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_semaphore.h */

#define NSYNC_SEM_H_
COSMOPOLITAN_C_START_

typedef struct nsync_semaphore_s_ {
  void *sem_space[3];
} nsync_semaphore;

/* Initialize *s; the initial value is 0. */
void nsync_mu_semaphore_init(nsync_semaphore *s);

/* Wait until the count of *s exceeds 0, and decrement it. */
errno_t nsync_mu_semaphore_p(nsync_semaphore *s);

/* Wait until one of: the count of *s is non-zero, in which case
   decrement *s and return 0; or abs_deadline expires, in which case
   return ETIMEDOUT. */
errno_t nsync_mu_semaphore_p_with_deadline(nsync_semaphore *s,
                                           nsync_time abs_deadline);

/* Ensure that the count of *s is at least 1. */
void nsync_mu_semaphore_v(nsync_semaphore *s);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/mu_wait.h */

#define NSYNC_MU_WAIT_H_
COSMOPOLITAN_C_START_

/* nsync_mu_wait() and nsync_mu_wait_with_deadline() can be used instead
   of condition variables. In many straightforward situations they are
   of equivalent performance and are somewhat easier to use, because
   unlike condition variables, they do not require that the waits be
   placed in a loop, and they do not require explicit wakeup calls.
   Example:

   Definitions:

       static nsync_mu mu = NSYNC_MU_INIT;
       static int i = 0;  // protected by mu
       // Condition for use with nsync_mu_wait().
       static int int_is_zero (const void *v) {
         return (*(const int *)v == 0);
       }

   Waiter:

       nsync_mu_lock (&mu);
       // Wait until i is zero.
       nsync_mu_wait (&mu, &int_is_zero, &i, NULL);
       // i is known to be zero here.
       // ...
       nsync_mu_unlock (&mu);

   Thread potentially making i zero:

       nsync_mu_lock (&mu);
       i--;
       // No need to signal that i may have become zero.  The unlock call
       // below will evaluate waiters' conditions to decide which to wake.
       nsync_mu_unlock (&mu);

   It is legal to use conditional critical sections and condition
   variables on the same mutex.

                              --------------

   The implementation benefits from determining whether waiters are
   waiting for the same condition; it may then evaluate a condition once
   on behalf of several waiters. Two waiters have equal condition if
   their "condition" pointers are equal, and either:

     - their "condition_arg" pointers are equal, or

     - "condition_arg_eq" is non-null and (*condition_arg_eq)
       (condition_arg0, condition_arg1) returns non-zero.

   *condition_arg_eq will not be invoked unless the "condition" pointers
   are equal, and the "condition_arg" pointers are unequal.

   If many waiters wait for distinct conditions simultaneously,
   condition variables may be faster.
 */

struct nsync_note_s_; /* forward declaration for an nsync_note */

/* Return when (*condition) (condition_arg) is true. Perhaps unlock and
   relock *mu while blocked waiting for the condition to become true.
   nsync_mu_wait() is equivalent to nsync_mu_wait_with_deadline() with
   abs_deadline==nsync_time_no_deadline, and cancel_note==NULL.

   Requires that *mu be held on entry. See nsync_mu_wait_with_deadline()
   for more details on *condition and *condition_arg_eq. */
void nsync_mu_wait(nsync_mu *mu, int (*condition)(const void *condition_arg),
                   const void *condition_arg,
                   int (*condition_arg_eq)(const void *a, const void *b));

/* Return when at least one of: (*condition) (condition_arg) is true,
   the deadline expires, or *cancel_note is notified. Perhaps unlock and
   relock *mu while blocked waiting for one of these events, but always
   return with *mu held. Return 0 iff the (*condition) (condition_arg)
   is true on return, and otherwise either ETIMEDOUT or ECANCELED,
   depending on why the call returned early. Callers should use
   abs_deadline==nsync_time_no_deadline for no deadline, and
   cancel_note==NULL for no cancellation.

   Requires that *mu be held on entry.

   The implementation may call *condition from any thread using the
   mutex, and while holding *mu in either read or write mode; it
   guarantees that any thread calling *condition will hold *mu in some
   mode. Requires that (*condition) (condition_arg) neither modify state
   protected by *mu, nor return a value dependent on state not protected
   by *mu. To depend on time, use the abs_deadline parameter.
   (Conventional use of condition variables have the same restrictions
   on the conditions tested by the while-loop.) If non-null,
   condition_arg_eq should return whether two condition_arg calls with
   the same "condition" pointer are considered equivalent; it should
   have no side-effects. */
int nsync_mu_wait_with_deadline(
    nsync_mu *mu, int (*condition)(const void *condition_arg),
    const void *condition_arg,
    int (*condition_arg_eq)(const void *a, const void *b),
    nsync_time abs_deadline, struct nsync_note_s_ *cancel_note);

/* Unlock *mu, which must be held in write mode, and wake waiters, if
   appropriate. Unlike nsync_mu_unlock(), this call is not required to
   wake nsync_mu_wait/nsync_mu_wait_with_deadline calls on conditions
   that were false before this thread acquired the lock. This call
   should be used only at the end of critical sections for which:
   - nsync_mu_wait and/or nsync_mu_wait_with_deadline are in use on the same
     mutex,
   - this critical section cannot make the condition true for any of those
     nsync_mu_wait/nsync_mu_wait_with_deadline waits, and
   - when performance is significantly improved by using this call. */
void nsync_mu_unlock_without_wakeup(nsync_mu *mu);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/note.h */

#define NSYNC_NOTE_H_
COSMOPOLITAN_C_START_

/* An nsync_note represents a single bit that can transition from 0 to 1
   at most once. When 1, the note is said to be notified. There are
   operations to wait for the transition, which can be triggered either
   by an explicit call, or timer expiry. Notes can have parent notes; a
   note becomes notified if its parent becomes notified. */
typedef struct nsync_note_s_ *nsync_note;

/* Return a freshly allocated nsync_note, or NULL if an nsync_note
   cannot be created.

   If parent!=NULL, the allocated nsync_note's parent will be parent.
   The newaly allocated note will be automatically notified at
   abs_deadline, and is notified at initialization if
   abs_deadline==nsync_zero_time.

   nsync_notes should be passed to nsync_note_free() when no longer needed. */
nsync_note nsync_note_new(nsync_note parent, nsync_time abs_deadline);

/* Free resources associated with n. Requires that n was allocated by
   nsync_note_new(), and no concurrent or future operations are applied
   to n directly.

   It is legal to call nsync_note_free() on a node even if it has a
   parent or children that are in use; if n has both a parent and
   children, n's parent adopts its children. */
void nsync_note_free(nsync_note n);

/* Notify n and all its descendants. */
void nsync_note_notify(nsync_note n);

/* Return whether n has been notified.  */
int nsync_note_is_notified(nsync_note n);

/* Wait until n has been notified or abs_deadline is reached, and return
   whether n has been notified. If abs_deadline==nsync_time_no_deadline,
   the deadline is far in the future. */
int nsync_note_wait(nsync_note n, nsync_time abs_deadline);

/* Return the expiry time associated with n. This is the minimum of the
   abs_deadline passed on creation and that of any of its ancestors. */
nsync_time nsync_note_expiry(nsync_note n);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/once.h */

#define NSYNC_ONCE_H_
COSMOPOLITAN_C_START_

/* An nsync_once allows a function to be called exactly once, when first
   referenced. */
typedef nsync_atomic_uint32_ nsync_once;

/* An initializer for nsync_once; it is guaranteed to be all zeroes. */
#define NSYNC_ONCE_INIT NSYNC_ATOMIC_UINT32_INIT_

/* The first time nsync_run_once() or nsync_run_once_arg() is applied to
   *once, the supplied function is run (with argument, in the case of
   nsync_run_once_arg()). Other callers will wait until the run of the
   function is complete, and then return without running the function
   again. */
void nsync_run_once(nsync_once *once, void (*f)(void));
void nsync_run_once_arg(nsync_once *once, void (*farg)(void *arg), void *arg);

/* Same as nsync_run_once()/nsync_run_once_arg() but uses a spinloop.
   Can be used on the same nsync_once as
   nsync_run_once/nsync_run_once_arg().

   These *_spin variants should be used only in contexts where normal
   blocking is disallowed, such as within user-space schedulers, when
   the runtime is not fully initialized, etc. They provide no
   significant performance benefit, and they should be avoided in normal
   code. */
void nsync_run_once_spin(nsync_once *once, void (*f)(void));
void nsync_run_once_arg_spin(nsync_once *once, void (*farg)(void *arg),
                             void *arg);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/nsync/waiter.h */

#define NSYNC_WAITER_H_
COSMOPOLITAN_C_START_

/* nsync_wait_n() allows the client to wait on multiple objects
   (condition variables, nsync_notes, nsync_counters, etc.) until at
   least one of them becomes ready, or a deadline expires.

   It can be thought of as rather like Unix's select() or poll(), except
   the the objects being waited for are synchronization data structures,
   rather than file descriptors.

   The client can construct new objects that can be waited for by
   implementing three routines.

   Examples:

   To wait on two nsync_notes n0, n1, and a nsync_counter c0, with a
   deadline of abs_deadline:

       // Form an array of struct nsync_waitable_s, identifying the
       // objects and the corresponding descriptors. (Static
       // initialization syntax is used for brevity.)
       static struct nsync_waitable_s w[] = {
         { &n0, &nsync_note_waitable_funcs },
         { &n1, &nsync_note_waitable_funcs },
         { &c0, &nsync_counter_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1], &w[2] };
       int n = sizeof (w) / sizeof (w[0]);

       // Wait. The mu, lock, and unlock arguments are NULL because no
       // condition variables are invovled.
       int i = nsync_wait_n (NULL, NULL, NULL, abs_deadline, n, pw);
       if (i == n) {
         // timeout
       } else {
         // w[i].v became ready.
       }

    To wait on multiple condition variables, the mu/lock/unlock
    parameters are used. Imagine cv0 and cv1 are signalled when
    predicates pred0() (under lock mu0) and pred1() (under lock mu1)
    become true respectively. Assume that mu0 is acquired before mu1.

       static void lock2 (void *v) {  // lock two mutexes in order
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_lock (mu[0]);
         nsync_mu_lock (mu[1]);
       }
       static void unlock2 (void *v) { // unlock two mutexes.
         nsync_mu **mu = (nsync_mu **) v;
         nsync_mu_unlock (mu[1]);
         nsync_mu_unlock (mu[0]);
       }

       // Describe the condition variables and the locks.
       static struct nsync_waitable_s w[] = {
         { &cv0, &nsync_cv_waitable_funcs },
         { &cv1, &nsync_cv_waitable_funcs }
       };
       static struct nsync_waitable_s *pw[] = { &w[0], &w[1] };
       nsync_mu *lock_list[] = { &mu0, &mu1 };
       int n = sizeof (w) / sizeof (w[0]);

       lock2 (list_list);
       while (!pred0 () && !pred1 ()) {
         // Wait for one of the condition variables to be signalled,
         // with no timeout.
         nsync_wait_n (lock_list, &lock2, &unlock2,
                       nsync_time_no_deadline, n, pw);
       }
       if (pred0 ()) { ... }
       if (pred1 ()) { ... }
       unlock2 (list_list);

   */

/* forward declaration of struct that contains type dependent wait
   operations */
struct nsync_waitable_funcs_s;

/* Clients wait on objects by forming an array of struct
   nsync_waitable_s. Each each element points to one object and its
   type-dependent functions. */
struct nsync_waitable_s {
  /* pointer to object */
  void *v;
  /* pointer to type-dependent functions. Use
     &nsync_note_waitable_funcs for an nsync_note,
     &nsync_counternote_waitable_funcs for an nsync_counter,
     &nsync_cv_waitable_funcs for an nsync_cv. */
  const struct nsync_waitable_funcs_s *funcs;
};

/* Wait until at least one of *waitable[0,..,count-1] is has been
   notified, or abs_deadline is reached. Return the index of the
   notified element of waitable[], or count if no such element exists.
   If mu!=NULL, (*unlock)(mu) is called after the thread is queued on
   the various waiters, and (*lock)(mu) is called before return;
   mu/lock/unlock are used to acquire and release the relevant locks
   whan waiting on condition variables. */
int nsync_wait_n(void *mu, void (*lock)(void *), void (*unlock)(void *),
                 nsync_time abs_deadline, int count,
                 struct nsync_waitable_s *waitable[]);

/* A "struct nsync_waitable_s" implementation must implement these
   functions. Clients should ignore the internals. */
struct nsync_waiter_s;
struct nsync_waitable_funcs_s {

  /* Return the time when *v will be ready (max time if unknown), or 0
     if it is already ready. The parameter nw may be passed as NULL, in
     which case the result should indicate whether the thread would
     block if it were to wait on *v. All calls with the same *v must
     report the same result until the object becomes ready, from which
     point calls must report 0. */
  nsync_time (*ready_time)(void *v, struct nsync_waiter_s *nw);

  /* If *v is ready, return zero; otherwise enqueue *nw on *v and return
     non-zero. */
  int (*enqueue)(void *v, struct nsync_waiter_s *nw);

  /* If nw has been previously dequeued, return zero; otherwise dequeue
   *nw from *v and return non-zero.  */
  int (*dequeue)(void *v, struct nsync_waiter_s *nw);
};

/* The "struct nsync_waitable_s" for nsync_note, nsync_counter, and nsync_cv. */
extern const struct nsync_waitable_funcs_s nsync_note_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_counter_waitable_funcs;
extern const struct nsync_waitable_funcs_s nsync_cv_waitable_funcs;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/avx512.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_AVX512_H_
COSMOPOLITAN_C_START_

union XedAvx512Payload1 {
  struct {
    unsigned map : 4;
    unsigned rr_inv : 1;
    unsigned b_inv : 1;
    unsigned x_inv : 1;
    unsigned r_inv : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload2 {
  struct {
    unsigned pp : 2;
    unsigned ubit : 1;
    unsigned vexdest210 : 3;
    unsigned vexdest3 : 1;
    unsigned rexw : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

union XedAvx512Payload3 {
  struct {
    unsigned mask : 3;
    unsigned vexdest4p : 1;
    unsigned bcrc : 1;
    unsigned llrc : 2;
    unsigned z : 1;
    unsigned pad : 24;
  } s;
  unsigned u32;
};

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/private.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_PRIVATE_H_


/*!BEGIN third_party/xed/x86.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86_H_
/*           ▓▓▓▓▓▓▓▓▓▓▓▓▓                      ▄▄▄▄
             ▓▓▓▓▓▓▓▓▓▓▓▓▓     ▄▓▓▓▓▓▓▄      ▄▓▓▓▓▓▓▓▓            ▄▓▓▓▀
             ▓▓▓▓    ▓▓▓▓▓    ▓     ▓▓▓▓    ▓▓       ▓▓▓      ▄▓▓▓▓
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▬▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▬▬▬▬▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓     ▓▓▓▄     ▓▓▓   ▓▓▓▓             │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▀▓▓▓▓▄▄▄▓▓▓▬▬▓▓▓▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬
        │    ▓▓▓▓    ▓▓▓▓▓          ▓▓▓▓▓▄   ▄▄▓▓▓▓▓▓▓▓▓  ▓▓▓▓      ▓▓▓▄    │
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▄▄▓▓▀  ▀▀▓▓▓▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
▬▬▬▬▬▬▬▬║▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▓▓▓▬▬▬▬▬▬▬▬▬▓▓▓ ▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▬▬▬║▬▬▬
▬▬▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓    ▓▓▓▓▓▬▬▬▬▬▬▬▬▬▬▬▓▓▓▓▬▬▓▓▓▬▬▬▬▬▬▬▬▓▓▓▬▓▓▓▓▬▬▬▬▬▬▬▓▓▓▬▬▬▬▬▬▬▬
■■■■■■■■║■■■■▓▓▓▓    ▓▓▓▓▓■■■▓▓▓▄▄▄▓▓▓▓■■■■▬▓▓▓▓▄▄▄▄▓▓▓■■■■▬▓▓▓▓▄▄▄▓▓▓▓▀■■■■║■■■
■■■■■■■■■■■■■▓▓▓▓▓▓▓▓▓▓▓▓▓■■■■■▀▓▓▓■■■■■■■■■■■■■■▀▀■■■■■■■■■■■■▀▓▓▀■■■■■■■■■■■■■
        ║▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓║
╔───────╨───────────────────────────────────────────────────────────────────╨──╗
│ cosmopolitan § virtual machine » byte code language                          │
╚─────────────────────────────────────────────────────────────────────────────*/

#define XED_MAX_INSTRUCTION_BYTES 15

#define XED_MODE_REAL   0
#define XED_MODE_LEGACY 1
#define XED_MODE_LONG   2

#define XED_HINT_NTAKEN 2
#define XED_HINT_TAKEN  4
#define XED_HINT_ALTER  6

#define XED_SEG_ES 1
#define XED_SEG_CS 2
#define XED_SEG_SS 3
#define XED_SEG_DS 4
#define XED_SEG_FS 5
#define XED_SEG_GS 6

#define xed_modrm_mod(M)           (((M)&0xff) >> 6)
#define xed_modrm_reg(M)           (((M)&0b00111000) >> 3)
#define xed_modrm_rm(M)            ((M)&7)
#define xed_sib_base(M)            ((M)&7)
#define xed_sib_index(M)           (((M)&0b00111000) >> 3)
#define xed_sib_scale(M)           (((M)&0xff) >> 6)
#define xed_get_modrm_reg_field(M) (((M)&0x38) >> 3)

COSMOPOLITAN_C_START_

#define XED_MACHINE_MODE_REAL           XED_MODE_REAL
#define XED_MACHINE_MODE_LEGACY_32      XED_MODE_LEGACY
#define XED_MACHINE_MODE_LONG_64        XED_MODE_LONG
#define XED_MACHINE_MODE_UNREAL         (1 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LEGACY_16      (2 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_16 (3 << 2 | XED_MODE_REAL)
#define XED_MACHINE_MODE_LONG_COMPAT_32 (4 << 2 | XED_MODE_LEGACY)
#define XED_MACHINE_MODE_LAST           (XED_MACHINE_MODE_LONG_COMPAT_32 + 1)

#define XED_ERROR_NONE                         0
#define XED_ERROR_BUFFER_TOO_SHORT             1
#define XED_ERROR_GENERAL_ERROR                2
#define XED_ERROR_INVALID_FOR_CHIP             3
#define XED_ERROR_BAD_REGISTER                 4
#define XED_ERROR_BAD_LOCK_PREFIX              5
#define XED_ERROR_BAD_REP_PREFIX               6
#define XED_ERROR_BAD_LEGACY_PREFIX            7
#define XED_ERROR_BAD_REX_PREFIX               8
#define XED_ERROR_BAD_EVEX_UBIT                9
#define XED_ERROR_BAD_MAP                      10
#define XED_ERROR_BAD_EVEX_V_PRIME             11
#define XED_ERROR_BAD_EVEX_Z_NO_MASKING        12
#define XED_ERROR_NO_OUTPUT_POINTER            13
#define XED_ERROR_NO_AGEN_CALL_BACK_REGISTERED 14
#define XED_ERROR_BAD_MEMOP_INDEX              15
#define XED_ERROR_CALLBACK_PROBLEM             16
#define XED_ERROR_GATHER_REGS                  17
#define XED_ERROR_INSTR_TOO_LONG               18
#define XED_ERROR_INVALID_MODE                 19
#define XED_ERROR_BAD_EVEX_LL                  20
#define XED_ERROR_UNIMPLEMENTED                21
#define XED_ERROR_LAST                         22

#define XED_ADDRESS_WIDTH_INVALID 0
#define XED_ADDRESS_WIDTH_16b     2
#define XED_ADDRESS_WIDTH_32b     4
#define XED_ADDRESS_WIDTH_64b     8
#define XED_ADDRESS_WIDTH_LAST    9

#define XED_ILD_MAP0        0 /* 8086+  ... */
#define XED_ILD_MAP1        1 /* 286+   0x0F,... */
#define XED_ILD_MAP2        2 /* Core2+ 0x0F,0x38,... */
#define XED_ILD_MAP3        3 /* Core2+ 0x0F,0x3A,... */
#define XED_ILD_MAP4        4
#define XED_ILD_MAP5        5
#define XED_ILD_MAP6        6
#define XED_ILD_MAPAMD      7
#define XED_ILD_MAP_XOP8    8
#define XED_ILD_MAP_XOP9    9
#define XED_ILD_MAP_XOPA    10
#define XED_ILD_MAP_LAST    11
#define XED_ILD_MAP_INVALID 12

struct XedOperands { /*
  ┌rep
  │ ┌log₂𝑏
  │ │ ┌mode
  │ │ │ ┌eamode
  │ │ │ │ ┌mod
  │ │ │ │ │
  │ │ │ │ │  ┌sego
  │ │ │ │ │  │
  │ │ │ │ │  │   ┌rex         REGISTER
  │ │ │ │ │  │   │┌rexb       DISPATCH
  │ │ │ │ │  │   ││┌srm       ENCODING
  │ │ │ │ │  │   │││  ┌rex
  │ │ │ │ │  │   │││  │┌rexb
  │ │ │ │ │  │   │││  ││┌rm
  │ │ │ │ │  │   │││  │││  ┌rexw
  │ │ │ │ │  │   │││  │││  │┌osz
  │ │ │ │ │  │   │││  │││  ││┌rex
  │ │ │ │ │  │   │││  │││  │││┌rexr
  │ │ │ │ │  │   │││  │││  ││││┌reg
  │3│2│2│2│2 │   │││  │││  │││││
  │0│8│6│4│2 │18 │││12│││ 7│││││ 0
  ├┐├┐├┐├┐├┐ ├─┐ ││├─┐││├─┐││││├─┐
  00000000000000000000000000000000*/
  uint32_t rde;
  union {
    struct {
      union {
        uint8_t opcode;
        uint8_t srm : 3;
      };
      uint8_t map : 4;
    };
    uint16_t dispatch;
  };
  union {
    uint8_t sib;
    struct {
      uint8_t base : 3;
      uint8_t index : 3;
      uint8_t scale : 2;
    };
  };
  bool osz : 1;   /* operand size override prefix */
  bool rexw : 1;  /* rex.w or rex.wb or etc. 64-bit override */
  bool rexb : 1;  /* rex.b or rex.wb or etc. see modrm table */
  bool rexr : 1;  /* rex.r or rex.wr or etc. see modrm table */
  bool rex : 1;   /* any rex prefix including rex */
  bool rexx : 1;  /* rex.x or rex.wx or etc. see sib table */
  bool rexrr : 1; /* evex */
  bool asz : 1;   /* address size override */
  int64_t disp;   /* displacement(%xxx) mostly sign-extended */
  uint64_t uimm0; /* $immediate mostly sign-extended */
  bool out_of_bytes : 1;
  bool is_intel_specific : 1;
  bool ild_f2 : 1;
  bool ild_f3 : 1;
  bool has_sib : 1;
  bool realmode : 1;
  bool amd3dnow : 1;
  bool lock : 1;
  union {
    uint8_t modrm; /* selects address register */
    struct {
      uint8_t rm : 3;
      uint8_t reg : 3;
      uint8_t mod : 2;
    };
  };
  uint8_t max_bytes;
  uint8_t rep : 2; /* 0, 2 (0xf2 repnz), 3 (0xf3 rep/repe) */
  uint8_t has_modrm : 2;
  bool imm_signed : 1;       /* internal */
  bool disp_unsigned : 1;    /* internal */
  uint8_t seg_ovd : 3;       /* XED_SEG_xx */
  uint8_t error : 5;         /* enum XedError */
  uint8_t mode : 2;          /* real,legacy,long */
  uint8_t hint : 3;          /* static branch prediction */
  uint8_t uimm1;             /* enter $x,$y */
  uint8_t disp_width;        /* in bits */
  uint8_t imm_width;         /* in bits */
  uint8_t mode_first_prefix; /* see xed_set_chip_modes() */
  uint8_t nrexes;
  uint8_t nprefixes;
  uint8_t nseg_prefixes;
  uint8_t ubit;       /* vex */
  uint8_t vexvalid;   /* vex */
  uint8_t vexdest3;   /* vex */
  uint8_t vexdest4;   /* vex */
  uint8_t vexdest210; /* vex */
  uint8_t vex_prefix; /* vex */
  uint8_t zeroing;    /* evex */
  uint8_t bcrc;       /* evex */
  uint8_t llrc;       /* evex */
  uint8_t vl;         /* evex */
  uint8_t mask;       /* evex */
  uint8_t imm1_bytes; /* evex */
  uint8_t pos_disp;
  uint8_t pos_imm;
  uint8_t pos_imm1;
  uint8_t pos_modrm;
  uint8_t pos_opcode;
  uint8_t pos_sib;
};

struct XedDecodedInst {
  unsigned char length;
  uint8_t bytes[15];
  struct XedOperands op;
};

#define xed_operands_set_mode(p, machine_mode) \
  do {                                         \
    struct XedOperands *__p = p;               \
    __p->realmode = false;                     \
    switch (machine_mode) {                    \
      default:                                 \
      case XED_MACHINE_MODE_LONG_64:           \
        __p->mode = XED_MODE_LONG;             \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_32:         \
      case XED_MACHINE_MODE_LONG_COMPAT_32:    \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_REAL:              \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
      case XED_MACHINE_MODE_UNREAL:            \
        __p->realmode = true;                  \
        __p->mode = XED_MODE_LEGACY;           \
        break;                                 \
      case XED_MACHINE_MODE_LEGACY_16:         \
      case XED_MACHINE_MODE_LONG_COMPAT_16:    \
        __p->mode = XED_MODE_REAL;             \
        break;                                 \
    }                                          \
  } while (0)

extern const char kXedErrorNames[];
extern const uint8_t kXedEamode[2][3];

struct XedDecodedInst *xed_decoded_inst_zero_set_mode(struct XedDecodedInst *,
                                                      int);
int xed_instruction_length_decode(struct XedDecodedInst *, const void *,
                                  size_t);

COSMOPOLITAN_C_END_
COSMOPOLITAN_C_START_

typedef int xed_int_t;
typedef unsigned int xed_uint_t;
typedef unsigned int xed_uint_t;
typedef unsigned char xed_bits_t;
typedef intptr_t xed_addr_t;
typedef bool xed_bool_t;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/xed/x86isa.h */

#define COSMOPOLITAN_THIRD_PARTY_XED_X86ISA_H_
COSMOPOLITAN_C_START_

#define XED_CHIP_INVALID           1
#define XED_CHIP_I86               2
#define XED_CHIP_I86FP             3
#define XED_CHIP_I186              4
#define XED_CHIP_I186FP            5
#define XED_CHIP_I286REAL          6
#define XED_CHIP_I286              7
#define XED_CHIP_I2186FP           8
#define XED_CHIP_I386REAL          9
#define XED_CHIP_I386              10
#define XED_CHIP_I386FP            11
#define XED_CHIP_I486REAL          12
#define XED_CHIP_I486              13
#define XED_CHIP_PENTIUMREAL       14
#define XED_CHIP_PENTIUM           15
#define XED_CHIP_QUARK             16
#define XED_CHIP_PENTIUMMMXREAL    17
#define XED_CHIP_PENTIUMMMX        18
#define XED_CHIP_ALLREAL           19
#define XED_CHIP_PENTIUMPRO        20
#define XED_CHIP_PENTIUM2          21
#define XED_CHIP_PENTIUM3          22
#define XED_CHIP_PENTIUM4          23
#define XED_CHIP_P4PRESCOTT        24
#define XED_CHIP_P4PRESCOTT_NOLAHF 25
#define XED_CHIP_P4PRESCOTT_VTX    26
#define XED_CHIP_CORE2             27
#define XED_CHIP_PENRYN            28
#define XED_CHIP_PENRYN_E          29
#define XED_CHIP_NEHALEM           30
#define XED_CHIP_WESTMERE          31
#define XED_CHIP_BONNELL           32
#define XED_CHIP_SALTWELL          33
#define XED_CHIP_SILVERMONT        34
#define XED_CHIP_AMD               35
#define XED_CHIP_GOLDMONT          36
#define XED_CHIP_GOLDMONT_PLUS     37
#define XED_CHIP_TREMONT           38
#define XED_CHIP_SANDYBRIDGE       39
#define XED_CHIP_IVYBRIDGE         40
#define XED_CHIP_HASWELL           41
#define XED_CHIP_BROADWELL         42
#define XED_CHIP_SKYLAKE           43
#define XED_CHIP_SKYLAKE_SERVER    44
#define XED_CHIP_CASCADE_LAKE      45
#define XED_CHIP_KNL               46
#define XED_CHIP_KNM               47
#define XED_CHIP_CANNONLAKE        48
#define XED_CHIP_ICELAKE           49
#define XED_CHIP_ICELAKE_SERVER    50
#define XED_CHIP_FUTURE            51
#define XED_CHIP_ALL               52
#define XED_CHIP_LAST              53

#define XED_ISA_SET_INVALID               0
#define XED_ISA_SET_3DNOW                 1
#define XED_ISA_SET_ADOX_ADCX             2
#define XED_ISA_SET_AES                   3
#define XED_ISA_SET_AMD                   4
#define XED_ISA_SET_AVX                   5
#define XED_ISA_SET_AVX2                  6
#define XED_ISA_SET_AVX2GATHER            7
#define XED_ISA_SET_AVX512BW_128          8
#define XED_ISA_SET_AVX512BW_128N         9
#define XED_ISA_SET_AVX512BW_256          10
#define XED_ISA_SET_AVX512BW_512          11
#define XED_ISA_SET_AVX512BW_KOP          12
#define XED_ISA_SET_AVX512CD_128          13
#define XED_ISA_SET_AVX512CD_256          14
#define XED_ISA_SET_AVX512CD_512          15
#define XED_ISA_SET_AVX512DQ_128          16
#define XED_ISA_SET_AVX512DQ_128N         17
#define XED_ISA_SET_AVX512DQ_256          18
#define XED_ISA_SET_AVX512DQ_512          19
#define XED_ISA_SET_AVX512DQ_KOP          20
#define XED_ISA_SET_AVX512DQ_SCALAR       21
#define XED_ISA_SET_AVX512ER_512          22
#define XED_ISA_SET_AVX512ER_SCALAR       23
#define XED_ISA_SET_AVX512F_128           24
#define XED_ISA_SET_AVX512F_128N          25
#define XED_ISA_SET_AVX512F_256           26
#define XED_ISA_SET_AVX512F_512           27
#define XED_ISA_SET_AVX512F_KOP           28
#define XED_ISA_SET_AVX512F_SCALAR        29
#define XED_ISA_SET_AVX512PF_512          30
#define XED_ISA_SET_AVX512_4FMAPS_512     31
#define XED_ISA_SET_AVX512_4FMAPS_SCALAR  32
#define XED_ISA_SET_AVX512_4VNNIW_512     33
#define XED_ISA_SET_AVX512_BITALG_128     34
#define XED_ISA_SET_AVX512_BITALG_256     35
#define XED_ISA_SET_AVX512_BITALG_512     36
#define XED_ISA_SET_AVX512_GFNI_128       37
#define XED_ISA_SET_AVX512_GFNI_256       38
#define XED_ISA_SET_AVX512_GFNI_512       39
#define XED_ISA_SET_AVX512_IFMA_128       40
#define XED_ISA_SET_AVX512_IFMA_256       41
#define XED_ISA_SET_AVX512_IFMA_512       42
#define XED_ISA_SET_AVX512_VAES_128       43
#define XED_ISA_SET_AVX512_VAES_256       44
#define XED_ISA_SET_AVX512_VAES_512       45
#define XED_ISA_SET_AVX512_VBMI2_128      46
#define XED_ISA_SET_AVX512_VBMI2_256      47
#define XED_ISA_SET_AVX512_VBMI2_512      48
#define XED_ISA_SET_AVX512_VBMI_128       49
#define XED_ISA_SET_AVX512_VBMI_256       50
#define XED_ISA_SET_AVX512_VBMI_512       51
#define XED_ISA_SET_AVX512_VNNI_128       52
#define XED_ISA_SET_AVX512_VNNI_256       53
#define XED_ISA_SET_AVX512_VNNI_512       54
#define XED_ISA_SET_AVX512_VPCLMULQDQ_128 55
#define XED_ISA_SET_AVX512_VPCLMULQDQ_256 56
#define XED_ISA_SET_AVX512_VPCLMULQDQ_512 57
#define XED_ISA_SET_AVX512_VPOPCNTDQ_128  58
#define XED_ISA_SET_AVX512_VPOPCNTDQ_256  59
#define XED_ISA_SET_AVX512_VPOPCNTDQ_512  60
#define XED_ISA_SET_AVXAES                61
#define XED_ISA_SET_AVX_GFNI              62
#define XED_ISA_SET_BMI1                  63
#define XED_ISA_SET_BMI2                  64
#define XED_ISA_SET_CET                   65
#define XED_ISA_SET_CLDEMOTE              66
#define XED_ISA_SET_CLFLUSHOPT            67
#define XED_ISA_SET_CLFSH                 68
#define XED_ISA_SET_CLWB                  69
#define XED_ISA_SET_CLZERO                70
#define XED_ISA_SET_CMOV                  71
#define XED_ISA_SET_CMPXCHG16B            72
#define XED_ISA_SET_F16C                  73
#define XED_ISA_SET_FAT_NOP               74
#define XED_ISA_SET_FCMOV                 75
#define XED_ISA_SET_FMA                   76
#define XED_ISA_SET_FMA4                  77
#define XED_ISA_SET_FXSAVE                78
#define XED_ISA_SET_FXSAVE64              79
#define XED_ISA_SET_GFNI                  80
#define XED_ISA_SET_I186                  81
#define XED_ISA_SET_I286PROTECTED         82
#define XED_ISA_SET_I286REAL              83
#define XED_ISA_SET_I386                  84
#define XED_ISA_SET_I486                  85
#define XED_ISA_SET_I486REAL              86
#define XED_ISA_SET_I86                   87
#define XED_ISA_SET_INVPCID               88
#define XED_ISA_SET_LAHF                  89
#define XED_ISA_SET_LONGMODE              90
#define XED_ISA_SET_LZCNT                 91
#define XED_ISA_SET_MONITOR               92
#define XED_ISA_SET_MONITORX              93
#define XED_ISA_SET_MOVBE                 94
#define XED_ISA_SET_MOVDIR                95
#define XED_ISA_SET_MPX                   96
#define XED_ISA_SET_PAUSE                 97
#define XED_ISA_SET_PCLMULQDQ             98
#define XED_ISA_SET_PCONFIG               99
#define XED_ISA_SET_PENTIUMMMX            100
#define XED_ISA_SET_PENTIUMREAL           101
#define XED_ISA_SET_PKU                   102
#define XED_ISA_SET_POPCNT                103
#define XED_ISA_SET_PPRO                  104
#define XED_ISA_SET_PREFETCHW             105
#define XED_ISA_SET_PREFETCHWT1           106
#define XED_ISA_SET_PREFETCH_NOP          107
#define XED_ISA_SET_PT                    108
#define XED_ISA_SET_RDPID                 109
#define XED_ISA_SET_RDPMC                 110
#define XED_ISA_SET_RDRAND                111
#define XED_ISA_SET_RDSEED                112
#define XED_ISA_SET_RDTSCP                113
#define XED_ISA_SET_RDWRFSGS              114
#define XED_ISA_SET_RTM                   115
#define XED_ISA_SET_SGX                   116
#define XED_ISA_SET_SGX_ENCLV             117
#define XED_ISA_SET_SHA                   118
#define XED_ISA_SET_SMAP                  119
#define XED_ISA_SET_SMX                   120
#define XED_ISA_SET_SSE                   121
#define XED_ISA_SET_SSE2                  122
#define XED_ISA_SET_SSE2MMX               123
#define XED_ISA_SET_SSE3                  124
#define XED_ISA_SET_SSE3X87               125
#define XED_ISA_SET_SSE4                  126
#define XED_ISA_SET_SSE42                 127
#define XED_ISA_SET_SSE4A                 128
#define XED_ISA_SET_SSEMXCSR              129
#define XED_ISA_SET_SSE_PREFETCH          130
#define XED_ISA_SET_SSSE3                 131
#define XED_ISA_SET_SSSE3MMX              132
#define XED_ISA_SET_SVM                   133
#define XED_ISA_SET_TBM                   134
#define XED_ISA_SET_VAES                  135
#define XED_ISA_SET_VMFUNC                136
#define XED_ISA_SET_VPCLMULQDQ            137
#define XED_ISA_SET_VTX                   138
#define XED_ISA_SET_WAITPKG               139
#define XED_ISA_SET_WBNOINVD              140
#define XED_ISA_SET_X87                   141
#define XED_ISA_SET_XOP                   142
#define XED_ISA_SET_XSAVE                 143
#define XED_ISA_SET_XSAVEC                144
#define XED_ISA_SET_XSAVEOPT              145
#define XED_ISA_SET_XSAVES                146
#define XED_ISA_SET_LAST                  147

struct XedChipFeatures {
  uint64_t f[3];
};

#define xed_set_chip_modes(d, chip)    \
  do {                                 \
    struct XedDecodedInst *__d = d;    \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
        break;                         \
      case XED_CHIP_I86:               \
      case XED_CHIP_I86FP:             \
      case XED_CHIP_I186:              \
      case XED_CHIP_I186FP:            \
      case XED_CHIP_I286REAL:          \
      case XED_CHIP_I286:              \
      case XED_CHIP_I2186FP:           \
      case XED_CHIP_I386REAL:          \
      case XED_CHIP_I386:              \
      case XED_CHIP_I386FP:            \
      case XED_CHIP_I486REAL:          \
      case XED_CHIP_I486:              \
      case XED_CHIP_QUARK:             \
      case XED_CHIP_PENTIUM:           \
      case XED_CHIP_PENTIUMREAL:       \
      case XED_CHIP_PENTIUMMMX:        \
      case XED_CHIP_PENTIUMMMXREAL:    \
        __d->op.mode_first_prefix = 1; \
        break;                         \
      default:                         \
        break;                         \
    }                                  \
    switch (chip) {                    \
      case XED_CHIP_INVALID:           \
      case XED_CHIP_ALL:               \
      case XED_CHIP_AMD:               \
        break;                         \
      default:                         \
        __d->op.is_intel_specific = 1; \
        break;                         \
    }                                  \
  } while (0)

extern const uint64_t kXedChipFeatures[XED_CHIP_LAST][3];

bool xed_test_chip_features(struct XedChipFeatures *, int);
void xed_get_chip_features(struct XedChipFeatures *, int);
bool xed_isa_set_is_valid_for_chip(int, int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/blake2.h */

#define COSMOPOLITAN_LIBC_STR_BLAKE2_H_

#define BLAKE2B256_DIGEST_LENGTH 32
#define BLAKE2B_CBLOCK           128

#define BLAKE2B256_Init    __BLAKE2B256_Init
#define BLAKE2B256_Update  __BLAKE2B256_Update
#define BLAKE2B256_Process __BLAKE2B256_Process
#define BLAKE2B256_Final   __BLAKE2B256_Final
#define BLAKE2B256         __BLAKE2B256

COSMOPOLITAN_C_START_

struct Blake2b {
  uint64_t h[8];
  uint64_t t_low;
  uint64_t t_high;
  union {
    uint8_t bytes[BLAKE2B_CBLOCK];
    uint64_t words[16];
  } block;
  size_t block_used;
};

int BLAKE2B256_Init(struct Blake2b *);
int BLAKE2B256_Update(struct Blake2b *, const void *, size_t);
int BLAKE2B256_Process(struct Blake2b *, const uint64_t[BLAKE2B_CBLOCK / 8]);
int BLAKE2B256_Final(struct Blake2b *, uint8_t[BLAKE2B256_DIGEST_LENGTH]);
int BLAKE2B256(const void *, size_t, uint8_t[BLAKE2B256_DIGEST_LENGTH]);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/highwayhash64.h */

#define COSMOPOLITAN_LIBC_STR_HIGHWAYHASH64_H_
COSMOPOLITAN_C_START_

uint64_t HighwayHash64(const void *, size_t, const uint64_t[4]) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/langinfo.h */

#define COSMOPOLITAN_LIBC_STR_LANGINFO_H_
COSMOPOLITAN_C_START_

#define ABDAY_1 0x20000
#define ABDAY_2 0x20001
#define ABDAY_3 0x20002
#define ABDAY_4 0x20003
#define ABDAY_5 0x20004
#define ABDAY_6 0x20005
#define ABDAY_7 0x20006

#define DAY_1 0x20007
#define DAY_2 0x20008
#define DAY_3 0x20009
#define DAY_4 0x2000A
#define DAY_5 0x2000B
#define DAY_6 0x2000C
#define DAY_7 0x2000D

#define ABMON_1  0x2000E
#define ABMON_2  0x2000F
#define ABMON_3  0x20010
#define ABMON_4  0x20011
#define ABMON_5  0x20012
#define ABMON_6  0x20013
#define ABMON_7  0x20014
#define ABMON_8  0x20015
#define ABMON_9  0x20016
#define ABMON_10 0x20017
#define ABMON_11 0x20018
#define ABMON_12 0x20019

#define MON_1  0x2001A
#define MON_2  0x2001B
#define MON_3  0x2001C
#define MON_4  0x2001D
#define MON_5  0x2001E
#define MON_6  0x2001F
#define MON_7  0x20020
#define MON_8  0x20021
#define MON_9  0x20022
#define MON_10 0x20023
#define MON_11 0x20024
#define MON_12 0x20025

#define AM_STR 0x20026
#define PM_STR 0x20027

#define D_T_FMT    0x20028
#define D_FMT      0x20029
#define T_FMT      0x2002A
#define T_FMT_AMPM 0x2002B

#define ERA         0x2002C
#define ERA_D_FMT   0x2002E
#define ALT_DIGITS  0x2002F
#define ERA_D_T_FMT 0x20030
#define ERA_T_FMT   0x20031

#define CODESET 14

#define CRNCYSTR 0x4000F

#define RADIXCHAR 0x10000
#define THOUSEP   0x10001
#define YESEXPR   0x50000
#define NOEXPR    0x50001

#define _NL_LOCALE_NAME(cat) (((cat) << 16) | 0xffff)

#if defined(_GNU_SOURCE)
#define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat)
#endif

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
#define YESSTR 0x50002
#define NOSTR  0x50003
#endif

char *nl_langinfo(int);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/locale.h */

#define COSMOPOLITAN_LIBC_STR_LOCALE_H_

#define LC_CTYPE         0
#define LC_NUMERIC       1
#define LC_CTYPE_MASK    1
#define LC_TIME          2
#define LC_NUMERIC_MASK  2
#define LC_COLLATE       3
#define LC_MONETARY      4
#define LC_TIME_MASK     4
#define LC_MESSAGES      5
#define LC_ALL           6
#define LC_COLLATE_MASK  8
#define LC_MONETARY_MASK 16
#define LC_MESSAGES_MASK 32
#define LC_ALL_MASK      0x1fbf
#define LOCALE_NAME_MAX  23

COSMOPOLITAN_C_START_

#define LC_GLOBAL_LOCALE ((locale_t) - 1)

struct __locale_map {
  const void *map;
  size_t map_size;
  char name[LOCALE_NAME_MAX + 1];
  const struct __locale_map *next;
};

struct __locale_struct {
  const struct __locale_map *cat[6];
};

typedef struct __locale_struct *locale_t;

extern const struct __locale_map __c_dot_utf8;
extern const struct __locale_struct __c_locale;
extern const struct __locale_struct __c_dot_utf8_locale;

char *nl_langinfo_l(int, locale_t) libcesque;
char *setlocale(int, const char *) libcesque;
double strtod_l(const char *, char **, locale_t) libcesque;
double wcstod_l(const wchar_t *, wchar_t **, locale_t) libcesque;
float strtof_l(const char *, char **, locale_t) libcesque;
float wcstof_l(const wchar_t *, wchar_t **, locale_t) libcesque;
int isdigit_l(int, locale_t) libcesque;
int islower_l(int, locale_t) libcesque;
int isupper_l(int, locale_t) libcesque;
int iswalpha_l(wint_t, locale_t) libcesque;
int iswblank_l(wint_t, locale_t) libcesque;
int iswcntrl_l(wint_t, locale_t) libcesque;
int iswdigit_l(wint_t, locale_t) libcesque;
int iswlower_l(wint_t, locale_t) libcesque;
int iswprint_l(wint_t, locale_t) libcesque;
int iswpunct_l(wint_t, locale_t) libcesque;
int iswspace_l(wint_t, locale_t) libcesque;
int iswupper_l(wint_t, locale_t) libcesque;
int iswxdigit_l(wint_t, locale_t) libcesque;
int isxdigit_l(int, locale_t) libcesque;
int strcoll_l(const char *, const char *, locale_t) libcesque;
int tolower_l(int, locale_t) libcesque;
int toupper_l(int, locale_t) libcesque;
int wcscoll_l(const wchar_t *, const wchar_t *, locale_t) libcesque;
locale_t duplocale(locale_t) libcesque;
locale_t newlocale(int, const char *, locale_t) libcesque;
locale_t uselocale(locale_t) libcesque;
long double strtold_l(const char *, char **, locale_t) libcesque;
long double wcstold_l(const wchar_t *, wchar_t **, locale_t) libcesque;
long long strtoll_l(const char *, char **, int, locale_t) libcesque;
long long wcstoll_l(const wchar_t *, wchar_t **, int, locale_t) libcesque;
size_t strftime_l(char *, size_t, char const *, struct tm const *, locale_t);
size_t strxfrm_l(char *, const char *, size_t, locale_t) libcesque;
size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t) libcesque;
unsigned long long strtoull_l(const char *, char **, int, locale_t) libcesque;
unsigned long long wcstoull_l(const wchar_t *, wchar_t **, int, locale_t);
void freelocale(locale_t) libcesque;
wint_t towlower_l(wint_t, locale_t) libcesque;
wint_t towupper_l(wint_t, locale_t) libcesque;
int strcasecmp_l(const char *, const char *, locale_t) libcesque;
int strncasecmp_l(const char *, const char *, size_t, locale_t) libcesque;
ssize_t strfmon_l(char *, size_t, locale_t, const char *, ...) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/nltypes.h */

#define COSMOPOLITAN_LIBC_STR_NLTYPES_H_

#define NL_SETD       1
#define NL_CAT_LOCALE 1

COSMOPOLITAN_C_START_

typedef int nl_item;
typedef void *nl_catd;

nl_catd catopen(const char *, int);
char *catgets(nl_catd, int, int, const char *);
int catclose(nl_catd);

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/slice.h */

#define COSMOPOLITAN_LIBC_STR_SLICE_H_
COSMOPOLITAN_C_START_

#define SlicesEqual(a, n, b, m)       \
  ({                                  \
    size_t __n = (n);                 \
    __n == (m) && !memcmp(a, b, __n); \
  })

#define SlicesEqualCase(a, n, b, m)       \
  ({                                      \
    size_t __n = (n);                     \
    __n == (m) && !memcasecmp(a, b, __n); \
  })

int CompareSlices(const char *, size_t, const char *, size_t) libcesque;
int CompareSlicesCase(const char *, size_t, const char *, size_t) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/strwidth.h */

#define COSMOPOLITAN_LIBC_STR_STRWIDTH_H_
COSMOPOLITAN_C_START_

int strwidth(const char *, size_t) strlenesque;
int strnwidth(const char *, size_t, size_t) strlenesque;
int strwidth16(const char16_t *, size_t) strlenesque;
int strnwidth16(const char16_t *, size_t, size_t) strlenesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/thompike.h */

#define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_

#define ThomPikeCont(x)     (0200 == (0300 & (x)))
#define ThomPikeByte(x)     ((x) & (((1 << ThomPikeMsb(x)) - 1) | 3))
#define ThomPikeLen(x)      (7 - ThomPikeMsb(x))
#define ThomPikeMsb(x)      ((255 & (x)) < 252 ? bsr(255 & ~(x)) : 1)
#define ThomPikeMerge(x, y) ((x) << 6 | (077 & (y)))



/*!BEGIN libc/str/unicode.h */

#define COSMOPOLITAN_LIBC_STR_UNICODE_H_
COSMOPOLITAN_C_START_

struct lconv {
  char *decimal_point;
  char *thousands_sep;
  char *grouping;
  char *int_curr_symbol;
  char *currency_symbol;
  char *mon_decimal_point;
  char *mon_thousands_sep;
  char *mon_grouping;
  char *positive_sign;
  char *negative_sign;
  char int_frac_digits;
  char frac_digits;
  char p_cs_precedes;
  char p_sep_by_space;
  char n_cs_precedes;
  char n_sep_by_space;
  char p_sign_posn;
  char n_sign_posn;
  char int_p_cs_precedes;
  char int_n_cs_precedes;
  char int_p_sep_by_space;
  char int_n_sep_by_space;
  char int_p_sign_posn;
  char int_n_sign_posn;
};

pureconst int wcwidth(wchar_t) libcesque;
int wcswidth(const wchar_t *, size_t) strlenesque;
struct lconv *localeconv(void) libcesque;

#ifdef _COSMO_SOURCE
int wcsnwidth(const wchar_t *, size_t, size_t) strlenesque;
#endif /* _COSMO_SOURCE */

COSMOPOLITAN_C_END_


/*!BEGIN libc/str/utf16.h */

#define COSMOPOLITAN_LIBC_STR_UTF16_H_

#define UTF16_MASK 0xfc00
#define UTF16_MOAR 0xd800 /* 0xD800..0xDBFF */
#define UTF16_CONT 0xdc00 /* 0xDC00..0xDFFF */

COSMOPOLITAN_C_START_

#define IsSurrogate(wc)     ((0xf800 & (wc)) == 0xd800)
#define IsHighSurrogate(wc) ((UTF16_MASK & (wc)) == UTF16_MOAR)
#define IsLowSurrogate(wc)  ((UTF16_MASK & (wc)) == UTF16_CONT)
#define IsUcs2(wc)          (((65535 & (wc)) >> 11) != 27)
#define IsUtf16Cont(wc)     IsLowSurrogate(wc) /* TODO: DELETE */
#define MergeUtf16(hi, lo)  ((((hi)-0xD800) << 10) + ((lo)-0xDC00) + 0x10000)
#define EncodeUtf16(wc)                                       \
  (LIKELY((0x0000 <= (wc) && (wc) <= 0xFFFF) ||               \
          (0xE000 <= (wc) && (wc) <= 0xFFFF))                 \
       ? (wc)                                                 \
   : 0x10000 <= (wc) && (wc) <= 0x10FFFF                      \
       ? (((((wc)-0x10000) >> 10) + 0xD800) |                 \
          (unsigned)((((wc)-0x10000) & 1023) + 0xDC00) << 16) \
       : 0xFFFD)

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/errfuns.h */

#define COSMOPOLITAN_LIBC_SYSV_ERRFUNS_H_

/**
 * @fileoverview Optimized error return paths.
 *
 * Saying this:
 *
 *     return einval();
 *
 * Instead of this:
 *
 *     errno = EINVAL;
 *     return -1;
 *
 * Allows the compiler to generate 11 fewer bytes of code each time.
 *
 * @return always -1
 * @see libc/sysv/errfuns.inc (for implementation)
 */

libcesque intptr_t einval(void) relegated;
libcesque intptr_t eperm(void) relegated;
libcesque intptr_t enoent(void) relegated;
libcesque intptr_t esrch(void) relegated;
libcesque intptr_t eintr(void) relegated;
libcesque intptr_t eio(void) relegated;
libcesque intptr_t enxio(void) relegated;
libcesque intptr_t e2big(void) relegated;
libcesque intptr_t enoexec(void) relegated;
libcesque intptr_t ebadf(void) relegated;
libcesque intptr_t echild(void) relegated;
libcesque intptr_t eagain(void) relegated;
libcesque intptr_t enomem(void) relegated;
libcesque intptr_t eacces(void) relegated;
libcesque intptr_t efault(void) relegated;
libcesque intptr_t enotblk(void) relegated;
libcesque intptr_t ebusy(void) relegated;
libcesque intptr_t eexist(void) relegated;
libcesque intptr_t exdev(void) relegated;
libcesque intptr_t enodev(void) relegated;
libcesque intptr_t enotdir(void) relegated;
libcesque intptr_t eisdir(void) relegated;
libcesque intptr_t enfile(void) relegated;
libcesque intptr_t emfile(void) relegated;
libcesque intptr_t enotty(void) relegated;
libcesque intptr_t enotsup(void) relegated;
libcesque intptr_t etxtbsy(void) relegated;
libcesque intptr_t efbig(void) relegated;
libcesque intptr_t enospc(void) relegated;
libcesque intptr_t espipe(void) relegated;
libcesque intptr_t erofs(void) relegated;
libcesque intptr_t emlink(void) relegated;
libcesque intptr_t epipe(void) relegated;
libcesque intptr_t edom(void) relegated;
libcesque intptr_t erange(void) relegated;
libcesque intptr_t edeadlk(void) relegated;
libcesque intptr_t enametoolong(void) relegated;
libcesque intptr_t enolck(void) relegated;
libcesque intptr_t enosys(void) relegated;
libcesque intptr_t enotempty(void) relegated;
libcesque intptr_t eloop(void) relegated;
libcesque intptr_t enomsg(void) relegated;
libcesque intptr_t eidrm(void) relegated;
libcesque intptr_t echrng(void) relegated;
libcesque intptr_t el2nsync(void) relegated;
libcesque intptr_t el3hlt(void) relegated;
libcesque intptr_t el3rst(void) relegated;
libcesque intptr_t elnrng(void) relegated;
libcesque intptr_t eunatch(void) relegated;
libcesque intptr_t enocsi(void) relegated;
libcesque intptr_t el2hlt(void) relegated;
libcesque intptr_t ebade(void) relegated;
libcesque intptr_t ebadr(void) relegated;
libcesque intptr_t exfull(void) relegated;
libcesque intptr_t enoano(void) relegated;
libcesque intptr_t ebadrqc(void) relegated;
libcesque intptr_t ebadslt(void) relegated;
libcesque intptr_t enostr(void) relegated;
libcesque intptr_t enodata(void) relegated;
libcesque intptr_t etime(void) relegated;
libcesque intptr_t enosr(void) relegated;
libcesque intptr_t enonet(void) relegated;
libcesque intptr_t enopkg(void) relegated;
libcesque intptr_t eremote(void) relegated;
libcesque intptr_t enolink(void) relegated;
libcesque intptr_t eadv(void) relegated;
libcesque intptr_t esrmnt(void) relegated;
libcesque intptr_t ecomm(void) relegated;
libcesque intptr_t eproto(void) relegated;
libcesque intptr_t emultihop(void) relegated;
libcesque intptr_t edotdot(void) relegated;
libcesque intptr_t ebadmsg(void) relegated;
libcesque intptr_t eoverflow(void) relegated;
libcesque intptr_t enotuniq(void) relegated;
libcesque intptr_t ebadfd(void) relegated;
libcesque intptr_t eremchg(void) relegated;
libcesque intptr_t elibacc(void) relegated;
libcesque intptr_t elibbad(void) relegated;
libcesque intptr_t elibscn(void) relegated;
libcesque intptr_t elibmax(void) relegated;
libcesque intptr_t elibexec(void) relegated;
libcesque intptr_t eilseq(void) relegated;
libcesque intptr_t erestart(void) relegated;
libcesque intptr_t estrpipe(void) relegated;
libcesque intptr_t eusers(void) relegated;
libcesque intptr_t enotsock(void) relegated;
libcesque intptr_t edestaddrreq(void) relegated;
libcesque intptr_t emsgsize(void) relegated;
libcesque intptr_t eprototype(void) relegated;
libcesque intptr_t enoprotoopt(void) relegated;
libcesque intptr_t eprotonosupport(void) relegated;
libcesque intptr_t esocktnosupport(void) relegated;
libcesque intptr_t eopnotsupp(void) relegated;
libcesque intptr_t epfnosupport(void) relegated;
libcesque intptr_t eafnosupport(void) relegated;
libcesque intptr_t eaddrinuse(void) relegated;
libcesque intptr_t eaddrnotavail(void) relegated;
libcesque intptr_t enetdown(void) relegated;
libcesque intptr_t enetunreach(void) relegated;
libcesque intptr_t enetreset(void) relegated;
libcesque intptr_t econnaborted(void) relegated;
libcesque intptr_t econnreset(void) relegated;
libcesque intptr_t enobufs(void) relegated;
libcesque intptr_t eisconn(void) relegated;
libcesque intptr_t enotconn(void) relegated;
libcesque intptr_t eshutdown(void) relegated;
libcesque intptr_t etoomanyrefs(void) relegated;
libcesque intptr_t etimedout(void) relegated;
libcesque intptr_t econnrefused(void) relegated;
libcesque intptr_t ehostdown(void) relegated;
libcesque intptr_t ehostunreach(void) relegated;
libcesque intptr_t ealready(void) relegated;
libcesque intptr_t einprogress(void) relegated;
libcesque intptr_t estale(void) relegated;
libcesque intptr_t euclean(void) relegated;
libcesque intptr_t enotnam(void) relegated;
libcesque intptr_t enavail(void) relegated;
libcesque intptr_t eisnam(void) relegated;
libcesque intptr_t eremoteio(void) relegated;
libcesque intptr_t edquot(void) relegated;
libcesque intptr_t enomedium(void) relegated;
libcesque intptr_t emediumtype(void) relegated;
libcesque intptr_t ecanceled(void) relegated;
libcesque intptr_t enokey(void) relegated;
libcesque intptr_t ekeyexpired(void) relegated;
libcesque intptr_t ekeyrevoked(void) relegated;
libcesque intptr_t ekeyrejected(void) relegated;
libcesque intptr_t eownerdead(void) relegated;
libcesque intptr_t enotrecoverable(void) relegated;
libcesque intptr_t erfkill(void) relegated;
libcesque intptr_t ehwpoison(void) relegated;

#if defined(__MNO_RED_ZONE__) && defined(__GNUC__) && !defined(__STRICT_ANSI__)
#define __ERRFUN(FUNC)               \
  ({                                 \
    intptr_t NegOne;                 \
    asm volatile("call\t" FUNC       \
                 : "=a"(NegOne)      \
                 : /* no outputs */  \
                 : "rcx", "memory"); \
    NegOne;                          \
  })
#define einval()          __ERRFUN("einval")
#define eperm()           __ERRFUN("eperm")
#define enoent()          __ERRFUN("enoent")
#define esrch()           __ERRFUN("esrch")
#define eintr()           __ERRFUN("eintr")
#define eio()             __ERRFUN("eio")
#define enxio()           __ERRFUN("enxio")
#define e2big()           __ERRFUN("e2big")
#define enoexec()         __ERRFUN("enoexec")
#define ebadf()           __ERRFUN("ebadf")
#define echild()          __ERRFUN("echild")
#define eagain()          __ERRFUN("eagain")
#define enomem()          __ERRFUN("enomem")
#define eacces()          __ERRFUN("eacces")
#define efault()          __ERRFUN("efault")
#define enotblk()         __ERRFUN("enotblk")
#define ebusy()           __ERRFUN("ebusy")
#define eexist()          __ERRFUN("eexist")
#define exdev()           __ERRFUN("exdev")
#define enodev()          __ERRFUN("enodev")
#define enotdir()         __ERRFUN("enotdir")
#define eisdir()          __ERRFUN("eisdir")
#define enfile()          __ERRFUN("enfile")
#define emfile()          __ERRFUN("emfile")
#define enotty()          __ERRFUN("enotty")
#define enotsup()         __ERRFUN("enotsup")
#define etxtbsy()         __ERRFUN("etxtbsy")
#define efbig()           __ERRFUN("efbig")
#define enospc()          __ERRFUN("enospc")
#define espipe()          __ERRFUN("espipe")
#define erofs()           __ERRFUN("erofs")
#define emlink()          __ERRFUN("emlink")
#define epipe()           __ERRFUN("epipe")
#define edom()            __ERRFUN("edom")
#define erange()          __ERRFUN("erange")
#define edeadlk()         __ERRFUN("edeadlk")
#define enametoolong()    __ERRFUN("enametoolong")
#define enolck()          __ERRFUN("enolck")
#define enosys()          __ERRFUN("enosys")
#define enotempty()       __ERRFUN("enotempty")
#define eloop()           __ERRFUN("eloop")
#define enomsg()          __ERRFUN("enomsg")
#define eidrm()           __ERRFUN("eidrm")
#define echrng()          __ERRFUN("echrng")
#define el2nsync()        __ERRFUN("el2nsync")
#define el3hlt()          __ERRFUN("el3hlt")
#define el3rst()          __ERRFUN("el3rst")
#define elnrng()          __ERRFUN("elnrng")
#define eunatch()         __ERRFUN("eunatch")
#define enocsi()          __ERRFUN("enocsi")
#define el2hlt()          __ERRFUN("el2hlt")
#define ebade()           __ERRFUN("ebade")
#define ebadr()           __ERRFUN("ebadr")
#define exfull()          __ERRFUN("exfull")
#define enoano()          __ERRFUN("enoano")
#define ebadrqc()         __ERRFUN("ebadrqc")
#define ebadslt()         __ERRFUN("ebadslt")
#define enostr()          __ERRFUN("enostr")
#define enodata()         __ERRFUN("enodata")
#define etime()           __ERRFUN("etime")
#define enosr()           __ERRFUN("enosr")
#define enonet()          __ERRFUN("enonet")
#define enopkg()          __ERRFUN("enopkg")
#define eremote()         __ERRFUN("eremote")
#define enolink()         __ERRFUN("enolink")
#define eadv()            __ERRFUN("eadv")
#define esrmnt()          __ERRFUN("esrmnt")
#define ecomm()           __ERRFUN("ecomm")
#define eproto()          __ERRFUN("eproto")
#define emultihop()       __ERRFUN("emultihop")
#define edotdot()         __ERRFUN("edotdot")
#define ebadmsg()         __ERRFUN("ebadmsg")
#define eoverflow()       __ERRFUN("eoverflow")
#define enotuniq()        __ERRFUN("enotuniq")
#define ebadfd()          __ERRFUN("ebadfd")
#define eremchg()         __ERRFUN("eremchg")
#define elibacc()         __ERRFUN("elibacc")
#define elibbad()         __ERRFUN("elibbad")
#define elibscn()         __ERRFUN("elibscn")
#define elibmax()         __ERRFUN("elibmax")
#define elibexec()        __ERRFUN("elibexec")
#define eilseq()          __ERRFUN("eilseq")
#define erestart()        __ERRFUN("erestart")
#define estrpipe()        __ERRFUN("estrpipe")
#define eusers()          __ERRFUN("eusers")
#define enotsock()        __ERRFUN("enotsock")
#define edestaddrreq()    __ERRFUN("edestaddrreq")
#define emsgsize()        __ERRFUN("emsgsize")
#define eprototype()      __ERRFUN("eprototype")
#define enoprotoopt()     __ERRFUN("enoprotoopt")
#define eprotonosupport() __ERRFUN("eprotonosupport")
#define esocktnosupport() __ERRFUN("esocktnosupport")
#define eopnotsupp()      __ERRFUN("eopnotsupp")
#define epfnosupport()    __ERRFUN("epfnosupport")
#define eafnosupport()    __ERRFUN("eafnosupport")
#define eaddrinuse()      __ERRFUN("eaddrinuse")
#define eaddrnotavail()   __ERRFUN("eaddrnotavail")
#define enetdown()        __ERRFUN("enetdown")
#define enetunreach()     __ERRFUN("enetunreach")
#define enetreset()       __ERRFUN("enetreset")
#define econnaborted()    __ERRFUN("econnaborted")
#define econnreset()      __ERRFUN("econnreset")
#define enobufs()         __ERRFUN("enobufs")
#define eisconn()         __ERRFUN("eisconn")
#define enotconn()        __ERRFUN("enotconn")
#define eshutdown()       __ERRFUN("eshutdown")
#define etoomanyrefs()    __ERRFUN("etoomanyrefs")
#define etimedout()       __ERRFUN("etimedout")
#define econnrefused()    __ERRFUN("econnrefused")
#define ehostdown()       __ERRFUN("ehostdown")
#define ehostunreach()    __ERRFUN("ehostunreach")
#define ealready()        __ERRFUN("ealready")
#define einprogress()     __ERRFUN("einprogress")
#define estale()          __ERRFUN("estale")
#define euclean()         __ERRFUN("euclean")
#define enotnam()         __ERRFUN("enotnam")
#define enavail()         __ERRFUN("enavail")
#define eisnam()          __ERRFUN("eisnam")
#define eremoteio()       __ERRFUN("eremoteio")
#define edquot()          __ERRFUN("edquot")
#define enomedium()       __ERRFUN("enomedium")
#define emediumtype()     __ERRFUN("emediumtype")
#define ecanceled()       __ERRFUN("ecanceled")
#define enokey()          __ERRFUN("enokey")
#define ekeyexpired()     __ERRFUN("ekeyexpired")
#define ekeyrevoked()     __ERRFUN("ekeyrevoked")
#define ekeyrejected()    __ERRFUN("ekeyrejected")
#define eownerdead()      __ERRFUN("eownerdead")
#define enotrecoverable() __ERRFUN("enotrecoverable")
#define erfkill()         __ERRFUN("erfkill")
#define ehwpoison()       __ERRFUN("ehwpoison")
#endif



/*!BEGIN libc/sysv/consts/_posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS__POSIX_H_

/* The Open Group Base Specifications Issue 7, 2018 edition */
/* IEEE Std 1003.1-2017 (Revision of IEEE Std 1003.1-2008)  */

#define _POSIX_AIO_LISTIO_MAX               2
#define _POSIX_CLOCKRES_MIN                 20000000
#define _POSIX_AIO_MAX                      1
#define _POSIX_ARG_MAX                      4096
#define _POSIX_CHILD_MAX                    25
#define _POSIX_DELAYTIMER_MAX               32
#define _POSIX_HOST_NAME_MAX                255
#define _POSIX_LINK_MAX                     8
#define _POSIX_LOGIN_NAME_MAX               9
#define _POSIX_MAX_CANON                    255
#define _POSIX_MAX_INPUT                    255
#define _POSIX_MQ_OPEN_MAX                  8
#define _POSIX_MQ_PRIO_MAX                  32
#define _POSIX_NAME_MAX                     14
#define _POSIX_NGROUPS_MAX                  8
#define _POSIX_OPEN_MAX                     20
#define _POSIX_PATH_MAX                     256
#define _POSIX_PIPE_BUF                     512
#define _POSIX_RE_DUP_MAX                   255
#define _POSIX_RTSIG_MAX                    8
#define _POSIX_SEM_NSEMS_MAX                256
#define _POSIX_SEM_VALUE_MAX                32767
#define _POSIX_SIGQUEUE_MAX                 32
#define _POSIX_SSIZE_MAX                    32767
#define _POSIX_SS_REPL_MAX                  4
#define _POSIX_STREAM_MAX                   8
#define _POSIX_SYMLINK_MAX                  255
#define _POSIX_SYMLOOP_MAX                  8
#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
#define _POSIX_THREAD_KEYS_MAX              128
#define _POSIX_THREAD_THREADS_MAX           64
#define _POSIX_TIMER_MAX                    32
#define _POSIX_TRACE_EVENT_NAME_MAX         30
#define _POSIX_TRACE_NAME_MAX               8
#define _POSIX_TRACE_SYS_MAX                8
#define _POSIX_TRACE_USER_EVENT_MAX         32
#define _POSIX_TTY_NAME_MAX                 9
#define _POSIX_TZNAME_MAX                   6

#define _POSIX2_BC_BASE_MAX        99
#define _POSIX2_BC_DIM_MAX         2048
#define _POSIX2_BC_SCALE_MAX       99
#define _POSIX2_BC_STRING_MAX      1000
#define _POSIX2_CHARCLASS_NAME_MAX 14
#define _POSIX2_COLL_WEIGHTS_MAX   2
#define _POSIX2_EXPR_NEST_MAX      32
#define _POSIX2_LINE_MAX           2048
#define _POSIX2_RE_DUP_MAX         255



/*!BEGIN libc/sysv/consts/af.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AF_H_
COSMOPOLITAN_C_START_

extern const int AF_ALG;
extern const int AF_APPLETALK;
extern const int AF_ASH;
extern const int AF_ATMPVC;
extern const int AF_ATMSVC;
extern const int AF_AX25;
extern const int AF_BLUETOOTH;
extern const int AF_BRIDGE;
extern const int AF_CAIF;
extern const int AF_CAN;
extern const int AF_ECONET;
extern const int AF_FILE;
extern const int AF_IB;
extern const int AF_IEEE802154;
extern const int AF_INET6;
extern const int AF_INET;
extern const int AF_IPX;
extern const int AF_IRDA;
extern const int AF_ISDN;
extern const int AF_IUCV;
extern const int AF_KCM;
extern const int AF_KEY;
extern const int AF_LINK;
extern const int AF_LLC;
extern const int AF_LOCAL;
extern const int AF_MAX;
extern const int AF_MPLS;
extern const int AF_NETBEUI;
extern const int AF_NETLINK;
extern const int AF_NETROM;
extern const int AF_NFC;
extern const int AF_PACKET;
extern const int AF_PHONET;
extern const int AF_PPPOX;
extern const int AF_ROSE;
extern const int AF_ROUTE;
extern const int AF_RXRPC;
extern const int AF_SECURITY;
extern const int AF_SNA;
extern const int AF_TIPC;
extern const int AF_UNIX;
extern const int AF_UNSPEC;
extern const int AF_VSOCK;
extern const int AF_WANPIPE;
extern const int AF_X25;

#define AF_ALG        AF_ALG
#define AF_LINK       AF_LINK
#define AF_APPLETALK  AF_APPLETALK
#define AF_ASH        AF_ASH
#define AF_ATMPVC     AF_ATMPVC
#define AF_ATMSVC     AF_ATMSVC
#define AF_AX25       AF_AX25
#define AF_BLUETOOTH  AF_BLUETOOTH
#define AF_BRIDGE     AF_BRIDGE
#define AF_CAIF       AF_CAIF
#define AF_CAN        AF_CAN
#define AF_ECONET     AF_ECONET
#define AF_FILE       AF_FILE
#define AF_IB         AF_IB
#define AF_IEEE802154 AF_IEEE802154
#define AF_INET       2
#define AF_INET6      AF_INET6
#define AF_IPX        AF_IPX
#define AF_IRDA       AF_IRDA
#define AF_ISDN       AF_ISDN
#define AF_IUCV       AF_IUCV
#define AF_KCM        AF_KCM
#define AF_KEY        AF_KEY
#define AF_LLC        AF_LLC
#define AF_LOCAL      AF_LOCAL
#define AF_MAX        AF_MAX
#define AF_MPLS       AF_MPLS
#define AF_NETBEUI    AF_NETBEUI
#define AF_NETLINK    AF_NETLINK
#define AF_NETROM     AF_NETROM
#define AF_NFC        AF_NFC
#define AF_PACKET     AF_PACKET
#define AF_PHONET     AF_PHONET
#define AF_PPPOX      AF_PPPOX
#define AF_ROSE       AF_ROSE
#define AF_ROUTE      AF_ROUTE
#define AF_RXRPC      AF_RXRPC
#define AF_SECURITY   AF_SECURITY
#define AF_SNA        AF_SNA
#define AF_TIPC       AF_TIPC
#define AF_UNIX       1
#define AF_UNSPEC     0
#define AF_VSOCK      AF_VSOCK
#define AF_WANPIPE    AF_WANPIPE
#define AF_X25        AF_X25

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/arch.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARCH_H_

#define ARCH_SET_GS 0x1001
#define ARCH_SET_FS 0x1002
#define ARCH_GET_FS 0x1003
#define ARCH_GET_GS 0x1004



/*!BEGIN libc/sysv/consts/arp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ARP_H_

#define ARPHRD_ETHER 1



/*!BEGIN libc/sysv/consts/at.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AT_H_
COSMOPOLITAN_C_START_

/**
 * @fileoverview AT_xxx constants for fcntl(), fopenat(), etc..
 * @see libc/sysv/consts/auxv.h for getauxval() constants
 */

extern const int AT_FDCWD;
extern const int AT_SYMLINK_FOLLOW;
extern const int AT_SYMLINK_NOFOLLOW;
extern const int AT_REMOVEDIR;
extern const int AT_EACCESS;
extern const int AT_EMPTY_PATH;

COSMOPOLITAN_C_END_

#define AT_FDCWD            AT_FDCWD
#define AT_SYMLINK_FOLLOW   AT_SYMLINK_FOLLOW
#define AT_SYMLINK_NOFOLLOW AT_SYMLINK_NOFOLLOW
#define AT_REMOVEDIR        AT_REMOVEDIR
#define AT_EACCESS          AT_EACCESS



/*!BEGIN libc/sysv/consts/audit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_AUDIT_H_

#define __AUDIT_ARCH_64BIT                 0x80000000
#define __AUDIT_ARCH_LE                    0x40000000
#define __AUDIT_ARCH_CONVENTION_MASK       0x30000000
#define __AUDIT_ARCH_CONVENTION_MIPS64_N32 0x20000000

#define AUDIT_ARCH_X86_64  (EM_X86_64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_I386    (EM_386 | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_AARCH64 (EM_AARCH64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_PPC64LE (EM_PPC64 | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_RISCV64 (EM_RISCV | __AUDIT_ARCH_64BIT | __AUDIT_ARCH_LE)
#define AUDIT_ARCH_S390X   (EM_S390 | __AUDIT_ARCH_64BIT)



/*!BEGIN libc/sysv/consts/auxv.h */

#define COSMOPOLITAN_LIBC_CALLS_AUXV_H_

/*
 * integral getauxval() keys
 */
#define AT_PHDR                     3
#define AT_PHENT                    4
#define AT_PHNUM                    5
#define AT_PAGESZ                   6
#define AT_BASE                     7
#define AT_FLAGS                    8
#define AT_FLAGS_PRESERVE_ARGV0_BIT 0
#define AT_FLAGS_PRESERVE_ARGV0     (1 << AT_FLAGS_PRESERVE_ARGV0_BIT)
#define AT_ENTRY                    9

COSMOPOLITAN_C_START_

/*
 * portable getauxval() keys
 */
extern const unsigned long AT_EXECFN;
extern const unsigned long AT_SECURE;
extern const unsigned long AT_RANDOM;
extern const unsigned long AT_HWCAP;
extern const unsigned long AT_HWCAP2;
extern const unsigned long AT_UID;
extern const unsigned long AT_EUID;
extern const unsigned long AT_GID;
extern const unsigned long AT_EGID;
#define AT_EXECFN AT_EXECFN
#define AT_SECURE AT_SECURE
#define AT_RANDOM AT_RANDOM
#define AT_HWCAP  AT_HWCAP
#define AT_HWCAP2 AT_HWCAP2
#define AT_UID    AT_UID
#define AT_EUID   AT_EUID
#define AT_GID    AT_GID
#define AT_EGID   AT_EGID

/*
 * platform-specific getauxval() keys
 */
extern const unsigned long AT_BASE_PLATFORM;
extern const unsigned long AT_CANARY;
extern const unsigned long AT_CANARYLEN;
extern const unsigned long AT_CLKTCK;
extern const unsigned long AT_DCACHEBSIZE;
extern const unsigned long AT_EHDRFLAGS;
extern const unsigned long AT_EXECFD;
extern const unsigned long AT_EXECPATH;
extern const unsigned long AT_ICACHEBSIZE;
extern const unsigned long AT_MINSIGSTKSZ;
extern const unsigned long AT_NCPUS;
extern const unsigned long AT_NOTELF;
extern const unsigned long AT_NO_AUTOMOUNT;
extern const unsigned long AT_OSRELDATE;
extern const unsigned long AT_PAGESIZES;
extern const unsigned long AT_PAGESIZESLEN;
extern const unsigned long AT_PLATFORM;
extern const unsigned long AT_STACKBASE;
extern const unsigned long AT_STACKPROT;
extern const unsigned long AT_SYSINFO_EHDR;
extern const unsigned long AT_TIMEKEEP;
extern const unsigned long AT_UCACHEBSIZE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/c.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CPIO_H_

#define MAGIC "070707"

#define C_IRUSR 000400
#define C_IWUSR 000200
#define C_IXUSR 000100
#define C_IRGRP 000040
#define C_IWGRP 000020
#define C_IXGRP 000010
#define C_IROTH 000004
#define C_IWOTH 000002
#define C_IXOTH 000001

#define C_ISUID 004000
#define C_ISGID 002000
#define C_ISVTX 001000

#define C_ISBLK  060000
#define C_ISCHR  020000
#define C_ISDIR  040000
#define C_ISFIFO 010000
#define C_ISSOCK 0140000
#define C_ISLNK  0120000
#define C_ISCTG  0110000
#define C_ISREG  0100000



/*!BEGIN libc/sysv/consts/cap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CAP_H_

#define CAP_CHOWN              0
#define CAP_DAC_OVERRIDE       1
#define CAP_DAC_READ_SEARCH    2
#define CAP_FOWNER             3
#define CAP_FSETID             4
#define CAP_KILL               5
#define CAP_SETGID             6
#define CAP_SETUID             7
#define CAP_SETPCAP            8
#define CAP_LINUX_IMMUTABLE    9
#define CAP_NET_BIND_SERVICE   10
#define CAP_NET_BROADCAST      11
#define CAP_NET_ADMIN          12
#define CAP_NET_RAW            13
#define CAP_IPC_LOCK           14
#define CAP_IPC_OWNER          15
#define CAP_SYS_MODULE         16
#define CAP_SYS_RAWIO          17
#define CAP_SYS_CHROOT         18
#define CAP_SYS_PTRACE         19
#define CAP_SYS_PACCT          20
#define CAP_SYS_ADMIN          21
#define CAP_SYS_BOOT           22
#define CAP_SYS_NICE           23
#define CAP_SYS_RESOURCE       24
#define CAP_SYS_TIME           25
#define CAP_SYS_TTY_CONFIG     26
#define CAP_MKNOD              27
#define CAP_LEASE              28
#define CAP_AUDIT_WRITE        29
#define CAP_AUDIT_CONTROL      30
#define CAP_SETFCAP            31
#define CAP_MAC_OVERRIDE       32
#define CAP_MAC_ADMIN          33
#define CAP_SYSLOG             34
#define CAP_WAKE_ALARM         35
#define CAP_BLOCK_SUSPEND      36
#define CAP_AUDIT_READ         37
#define CAP_PERFMON            38
#define CAP_BPF                39
#define CAP_CHECKPOINT_RESTORE 40
#define CAP_LAST_CAP           CAP_CHECKPOINT_RESTORE



/*!BEGIN libc/sysv/consts/clock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOCK_H_
COSMOPOLITAN_C_START_

extern const int CLOCK_BOOTTIME;
extern const int CLOCK_BOOTTIME_ALARM;
extern const int CLOCK_MONOTONIC;
extern const int CLOCK_MONOTONIC_COARSE;
extern const int CLOCK_MONOTONIC_FAST;
extern const int CLOCK_MONOTONIC_PRECISE;
extern const int CLOCK_MONOTONIC_RAW;
extern const int CLOCK_PROCESS_CPUTIME_ID;
extern const int CLOCK_PROF;
extern const int CLOCK_REALTIME_ALARM;
extern const int CLOCK_REALTIME_COARSE;
extern const int CLOCK_REALTIME_FAST;
extern const int CLOCK_REALTIME_PRECISE;
extern const int CLOCK_SECOND;
extern const int CLOCK_TAI;
extern const int CLOCK_THREAD_CPUTIME_ID;
extern const int CLOCK_UPTIME;
extern const int CLOCK_UPTIME_FAST;
extern const int CLOCK_UPTIME_PRECISE;

COSMOPOLITAN_C_END_

#define CLOCK_REALTIME  0
#define CLOCK_MONOTONIC CLOCK_MONOTONIC



/*!BEGIN libc/sysv/consts/clone.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLONE_H_
#ifdef _COSMO_SOURCE

#define CSIGNAL              0x000000ff
#define CLONE_VM             0x00000100
#define CLONE_FS             0x00000200
#define CLONE_FILES          0x00000400
#define CLONE_SIGHAND        0x00000800
#define CLONE_PIDFD          0x00001000
#define CLONE_PTRACE         0x00002000
#define CLONE_VFORK          0x00004000
#define CLONE_PARENT         0x00008000
#define CLONE_THREAD         0x00010000
#define CLONE_NEWNS          0x00020000
#define CLONE_SYSVSEM        0x00040000
#define CLONE_SETTLS         0x00080000
#define CLONE_PARENT_SETTID  0x00100000
#define CLONE_CHILD_CLEARTID 0x00200000
#define CLONE_DETACHED       0x00400000
#define CLONE_UNTRACED       0x00800000
#define CLONE_CHILD_SETTID   0x01000000
#define CLONE_NEWCGROUP      0x02000000
#define CLONE_NEWUTS         0x04000000
#define CLONE_NEWIPC         0x08000000
#define CLONE_NEWUSER        0x10000000
#define CLONE_NEWPID         0x20000000
#define CLONE_NEWNET         0x40000000
#define CLONE_IO             0x80000000

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/close.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_CLOSE_H_
COSMOPOLITAN_C_START_

extern const unsigned int CLOSE_RANGE_UNSHARE;
extern const unsigned int CLOSE_RANGE_CLOEXEC;

COSMOPOLITAN_C_END_

#define CLOSE_RANGE_UNSHARE CLOSE_RANGE_UNSHARE
#define CLOSE_RANGE_CLOEXEC CLOSE_RANGE_CLOEXEC



/*!BEGIN libc/sysv/consts/dn.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DN_H_

#define DN_ACCESS    0x00000001 /* file accessed */
#define DN_MODIFY    0x00000002 /* file modified */
#define DN_CREATE    0x00000004 /* file created */
#define DN_DELETE    0x00000008 /* file removed */
#define DN_RENAME    0x00000010 /* file renamed */
#define DN_ATTRIB    0x00000020 /* file changed attibutes */
#define DN_MULTISHOT 0x80000000 /* don't remove notifier */



/*!BEGIN libc/sysv/consts/dt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_DT_H_

#define DT_UNKNOWN 0
#define DT_FIFO    1
#define DT_CHR     2
#define DT_DIR     4
#define DT_BLK     6
#define DT_REG     8
#define DT_LNK     10
#define DT_SOCK    12



/*!BEGIN libc/sysv/consts/endian.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ENDIAN_H_

#define __LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
#define __BIG_ENDIAN    __ORDER_BIG_ENDIAN__
#define __PDP_ENDIAN    __ORDER_PDP_ENDIAN__
#define __BYTE_ORDER    __BYTE_ORDER__



/*!BEGIN libc/sysv/consts/epoll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EPOLL_H_


/*!BEGIN libc/sysv/consts/o.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_O_H_

#define O_RDONLY  0
#define O_WRONLY  1
#define O_RDWR    2
#define O_ACCMODE 3

COSMOPOLITAN_C_START_

extern const unsigned O_APPEND;
extern const unsigned O_ASYNC;
extern const unsigned O_CLOEXEC;
extern const unsigned O_COMPRESSED;
extern const unsigned O_CREAT;
extern const unsigned O_DIRECT;
extern const unsigned O_DIRECTORY;
extern const unsigned O_DSYNC;
extern const unsigned O_EXCL;
extern const unsigned O_EXEC;
extern const unsigned O_EXLOCK;
extern const unsigned O_INDEXED;
extern const unsigned O_LARGEFILE;
extern const unsigned O_NOATIME;
extern const unsigned O_NOCTTY;
extern const unsigned O_NOFOLLOW;
extern const unsigned O_NOFOLLOW_ANY;
extern const unsigned O_NONBLOCK;
extern const unsigned O_PATH;
extern const unsigned O_RANDOM;
extern const unsigned O_RSYNC;
extern const unsigned O_SEARCH;
extern const unsigned O_SEQUENTIAL;
extern const unsigned O_SHLOCK;
extern const unsigned O_SYNC;
extern const unsigned O_TMPFILE; /* use tmpfd() or tmpfile() */
extern const unsigned O_TRUNC;
extern const unsigned O_TTY_INIT;
extern const unsigned O_UNLINK;
extern const unsigned O_VERIFY;

#define O_APPEND     O_APPEND
#define O_ASYNC      O_ASYNC
#define O_CLOEXEC    O_CLOEXEC
#define O_COMPRESSED O_COMPRESSED
#define O_CREAT      O_CREAT
#define O_DIRECTORY  O_DIRECTORY
#define O_EXCL       O_EXCL
#define O_EXEC       O_EXEC
#define O_INDEXED    O_INDEXED
#define O_LARGEFILE  O_LARGEFILE
#define O_NDELAY     O_NONBLOCK
#define O_NOATIME    O_NOATIME
#define O_NOCTTY     O_NOCTTY
#define O_NOFOLLOW   O_NOFOLLOW
#define O_NONBLOCK   O_NONBLOCK
#define O_RANDOM     O_RANDOM
#define O_SEQUENTIAL O_SEQUENTIAL
#define O_SYNC       O_SYNC
#define O_TRUNC      O_TRUNC
#define O_UNLINK     O_UNLINK

COSMOPOLITAN_C_END_

#define EPOLL_CTL_ADD 1
#define EPOLL_CTL_DEL 2
#define EPOLL_CTL_MOD 3

#define EPOLLIN        1
#define EPOLLPRI       2
#define EPOLLOUT       4
#define EPOLLERR       8
#define EPOLLHUP       0x10
#define EPOLLRDNORM    0x40
#define EPOLLRDBAND    0x80
#define EPOLLWRNORM    0x0100
#define EPOLLWRBAND    0x0200
#define EPOLLMSG       0x0400
#define EPOLLRDHUP     0x2000
#define EPOLLEXCLUSIVE 0x10000000
#define EPOLLWAKEUP    0x20000000
#define EPOLLONESHOT   0x40000000
#define EPOLLET        0x80000000

COSMOPOLITAN_C_START_

extern const int EPOLL_CLOEXEC;
#define EPOLL_CLOEXEC O_CLOEXEC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ethernet.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ETHERNET_H_

#define ETHERTYPE_PUP      0x0200
#define ETHERTYPE_SPRITE   0x0500
#define ETHERTYPE_IP       0x0800
#define ETHERTYPE_ARP      0x0806
#define ETHERTYPE_REVARP   0x8035
#define ETHERTYPE_AT       0x809B
#define ETHERTYPE_AARP     0x80F3
#define ETHERTYPE_VLAN     0x8100
#define ETHERTYPE_IPX      0x8137
#define ETHERTYPE_IPV6     0x86dd
#define ETHERTYPE_LOOPBACK 0x9000

#define ETHER_ADDR_LEN ETH_ALEN
#define ETHER_TYPE_LEN 2
#define ETHER_CRC_LEN  4
#define ETHER_HDR_LEN  ETH_HLEN
#define ETHER_MIN_LEN  (ETH_ZLEN + ETHER_CRC_LEN)
#define ETHER_MAX_LEN  (ETH_FRAME_LEN + ETHER_CRC_LEN)

#define ETHER_IS_VALID_LEN(foo) \
  ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN)

#define ETHERTYPE_TRAIL    0x1000
#define ETHERTYPE_NTRAILER 16

#define ETHERMTU ETH_DATA_LEN
#define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN)



/*!BEGIN libc/sysv/consts/ex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EX_H_

/**
 * @fileoverview Eric Allman's exit() codes
 *
 * - Broadly supported style guideline;
 * - Dating back to 1980 in 4.0BSD;
 * - That won't be standardized.
 *
 */

#define EX_CANTCREAT   73
#define EX_CONFIG      78
#define EX_DATAERR     65
#define EX_IOERR       74
#define EX_NOHOST      68
#define EX_NOINPUT     66
#define EX_NOPERM      77
#define EX_NOUSER      67
#define EX_OK          0
#define EX_OSERR       71
#define EX_OSFILE      72
#define EX_PROTOCOL    76
#define EX_SOFTWARE    70
#define EX_TEMPFAIL    75
#define EX_UNAVAILABLE 69
#define EX_USAGE       64
#define EX__BASE       64
#define EX__MAX        78



/*!BEGIN libc/sysv/consts/exit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_EXIT_H_

#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0



/*!BEGIN libc/sysv/consts/f.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_F_H_
COSMOPOLITAN_C_START_

/*
 * full set of fcntl() commands
 * many are only provided by a single platform
 * will be equal to -1 when not available on host
 */
extern const int F_BARRIERFSYNC;
extern const int F_DUPFD;
extern const int F_DUPFD_CLOEXEC;
extern const int F_FULLFSYNC;
extern const int F_GETFD;
extern const int F_GETFL;
extern const int F_GETLEASE;
extern const int F_GETLK;
extern const int F_GETNOSIGPIPE;
extern const int F_GETOWN;
extern const int F_GETPATH;
extern const int F_GETPIPE_SZ;
extern const int F_GETSIG;
extern const int F_MAXFD;
extern const int F_NOCACHE;
extern const int F_NOTIFY;
extern const int F_OFD_GETLK;
extern const int F_OFD_SETLK;
extern const int F_OFD_SETLKW;
extern const int F_RDLCK;
extern const int F_SETFD;
extern const int F_SETFL;
extern const int F_SETLEASE;
extern const int F_SETLK;
extern const int F_SETLKW;
extern const int F_SETNOSIGPIPE;
extern const int F_SETOWN;
extern const int F_SETPIPE_SZ;
extern const int F_SETSIG;
extern const int F_UNLCK;
extern const int F_WRLCK;

COSMOPOLITAN_C_END_

/*
 * portable fcntl() commands
 */
#define F_DUPFD         0
#define F_GETFD         1
#define F_SETFD         2
#define F_GETFL         3
#define F_SETFL         4
#define F_DUPFD_CLOEXEC F_DUPFD_CLOEXEC

/*
 * posix advisory locks
 * polyfilled poorly on windows
 */
#define F_SETLK  F_SETLK
#define F_SETLKW F_SETLKW
#define F_GETLK  F_GETLK
#define F_RDLCK  F_RDLCK
#define F_UNLCK  F_UNLCK
#define F_WRLCK  F_WRLCK



/*!BEGIN libc/sysv/consts/falloc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FALLOC_H_
COSMOPOLITAN_C_START_

extern const int FALLOC_FL_KEEP_SIZE;
extern const int FALLOC_FL_PUNCH_HOLE;
extern const int FALLOC_FL_NO_HIDE_STALE;
extern const int FALLOC_FL_COLLAPSE_RANGE;
extern const int FALLOC_FL_ZERO_RANGE;
extern const int FALLOC_FL_INSERT_RANGE;
extern const int FALLOC_FL_UNSHARE_RANGE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fan.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FAN_H_

#define FAN_CLASS_NOTIF              0
#define FAN_ACCESS                   1
#define FAN_ACCESS_PERM              0x020000
#define FAN_ALLOW                    1
#define FAN_ALL_CLASS_BITS           12
#define FAN_ALL_EVENTS               59
#define FAN_ALL_INIT_FLAGS           63
#define FAN_ALL_MARK_FLAGS           255
#define FAN_ALL_OUTGOING_EVENTS      0x03403b
#define FAN_ALL_PERM_EVENTS          0x030000
#define FAN_CLASS_CONTENT            4
#define FAN_CLASS_PRE_CONTENT        8
#define FAN_CLOEXEC                  1
#define FAN_CLOSE                    24
#define FAN_CLOSE_NOWRITE            0x10
#define FAN_CLOSE_WRITE              8
#define FAN_DENY                     2
#define FAN_EVENT_METADATA_LEN       24
#define FAN_EVENT_ON_CHILD           0x08000000
#define FAN_MARK_ADD                 1
#define FAN_MARK_DONT_FOLLOW         4
#define FAN_MARK_FLUSH               0x80
#define FAN_MARK_IGNORED_MASK        0x20
#define FAN_MARK_IGNORED_SURV_MODIFY 0x40
#define FAN_MARK_MOUNT               0x10
#define FAN_MARK_ONLYDIR             8
#define FAN_MARK_REMOVE              2
#define FAN_MODIFY                   2
#define FAN_NOFD                     -1
#define FAN_NONBLOCK                 2
#define FAN_ONDIR                    0x40000000
#define FAN_OPEN                     0x20
#define FAN_OPEN_PERM                0x010000
#define FAN_Q_OVERFLOW               0x4000
#define FAN_UNLIMITED_MARKS          0x20
#define FAN_UNLIMITED_QUEUE          0x10



/*!BEGIN libc/sysv/consts/fbio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FB_H_
COSMOPOLITAN_C_START_

extern const uint64_t FBIOGET_VSCREENINFO;
extern const uint64_t FBIOPUT_VSCREENINFO;
extern const uint64_t FBIOGET_FSCREENINFO;
extern const uint64_t FBIOGETCMAP;
extern const uint64_t FBIOPUTCMAP;
extern const uint64_t FBIOPAN_DISPLAY;
extern const uint64_t FBIO_WAITFORVSYNC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FD_H_
COSMOPOLITAN_C_START_

extern const int FD_CLOEXEC;

#define FD_CLOEXEC 1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fileno.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FILENO_H_

#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2



/*!BEGIN libc/sysv/consts/fio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FIO_H_
COSMOPOLITAN_C_START_

extern const uint32_t FIONREAD; /* one of the few encouraged ioctls */
extern const uint32_t FIONBIO;  /* use fcntl(fd, F_SETFL, O_NONBLOCK) */
extern const uint32_t FIOCLEX;  /* use fcntl(fd, F_SETFD, FD_CLOEXEC) */
extern const uint32_t FIONCLEX; /* use fcntl(fd, F_SETFD, 0) */
extern const uint32_t FIOASYNC; /* todo: fcntl(fd, F_SETOWN, pid) */

#define FIONREAD FIONREAD

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/fs.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FS_H_

#define FS_IOC_GETFLAGS   0x80086601
#define FS_IOC_SETFLAGS   0x40086602
#define FS_IOC_GETVERSION 0x80087601
#define FS_IOC_SETVERSION 0x40087602
#define FS_IOC_FIEMAP     0xc020660b
#define FS_IOC_FSGETXATTR 0x801c581f
#define FS_IOC_FSSETXATTR 0x401c5820
#define FS_IOC_GETFSLABEL 0x81009431
#define FS_IOC_SETFSLABEL 0x41009432

#define FS_FL_USER_VISIBLE    0x0003DFFF /* user visible flags */
#define FS_FL_USER_MODIFIABLE 0x000380FF /* user modifiable flags */
#define FS_SECRM_FL           0x00000001 /* secure deletion */
#define FS_UNRM_FL            0x00000002 /* undelete */
#define FS_COMPR_FL           0x00000004 /* compress */
#define FS_SYNC_FL            0x00000008 /* synchronous */
#define FS_IMMUTABLE_FL       0x00000010
#define FS_APPEND_FL          0x00000020 /* append-only */
#define FS_NODUMP_FL          0x00000040
#define FS_NOATIME_FL         0x00000080
#define FS_DIRTY_FL           0x00000100
#define FS_COMPRBLK_FL        0x00000200
#define FS_NOCOMP_FL          0x00000400
#define FS_ENCRYPT_FL         0x00000800 /* encrypted file */
#define FS_BTREE_FL           0x00001000
#define FS_INDEX_FL           0x00001000 /* hash-indexed directory */
#define FS_IMAGIC_FL          0x00002000
#define FS_JOURNAL_DATA_FL    0x00004000
#define FS_NOTAIL_FL          0x00008000
#define FS_DIRSYNC_FL         0x00010000
#define FS_TOPDIR_FL          0x00020000
#define FS_HUGE_FILE_FL       0x00040000
#define FS_EXTENT_FL          0x00080000



/*!BEGIN libc/sysv/consts/futex.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_FUTEX_H_
#ifdef _COSMO_SOURCE
COSMOPOLITAN_C_START_

extern const int FUTEX_WAIT;
extern const int FUTEX_WAKE;
extern const int FUTEX_REQUEUE;

#define FUTEX_WAIT         FUTEX_WAIT
#define FUTEX_WAKE         FUTEX_WAKE
#define FUTEX_REQUEUE      FUTEX_REQUEUE
#define FUTEX_PRIVATE_FLAG 128

#define FUTEX_WAIT_PRIVATE    (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
#define FUTEX_WAKE_PRIVATE    (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)

#define FUTEX_WAIT_BITSET      9
#define FUTEX_CLOCK_REALTIME   256
#define FUTEX_BITSET_MATCH_ANY 0xffffffff

COSMOPOLITAN_C_END_
#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/grnd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_GRND_H_

#define GRND_NONBLOCK 1
#define GRND_RANDOM   2



/*!BEGIN libc/sysv/consts/hwcap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_HWCAP_H_
#ifdef __aarch64__

// Feature bits for getauxval(AT_HWCAP) on AARCH64 GNU/SystemD.

#define HWCAP_FP       (1 << 0)
#define HWCAP_ASIMD    (1 << 1)
#define HWCAP_EVTSTRM  (1 << 2)
#define HWCAP_AES      (1 << 3)
#define HWCAP_PMULL    (1 << 4)
#define HWCAP_SHA1     (1 << 5)
#define HWCAP_SHA2     (1 << 6)
#define HWCAP_CRC32    (1 << 7)
#define HWCAP_ATOMICS  (1 << 8)
#define HWCAP_FPHP     (1 << 9)
#define HWCAP_ASIMDHP  (1 << 10)
#define HWCAP_CPUID    (1 << 11)
#define HWCAP_ASIMDRDM (1 << 12)
#define HWCAP_JSCVT    (1 << 13)
#define HWCAP_FCMA     (1 << 14)
#define HWCAP_LRCPC    (1 << 15)
#define HWCAP_DCPOP    (1 << 16)
#define HWCAP_SHA3     (1 << 17)
#define HWCAP_SM3      (1 << 18)
#define HWCAP_SM4      (1 << 19)
#define HWCAP_ASIMDDP  (1 << 20)
#define HWCAP_SHA512   (1 << 21)
#define HWCAP_SVE      (1 << 22)
#define HWCAP_ASIMDFHM (1 << 23)
#define HWCAP_DIT      (1 << 24)
#define HWCAP_USCAT    (1 << 25)
#define HWCAP_ILRCPC   (1 << 26)
#define HWCAP_FLAGM    (1 << 27)
#define HWCAP_SSBS     (1 << 28)
#define HWCAP_SB       (1 << 29)
#define HWCAP_PACA     (1 << 30)
#define HWCAP_PACG     (1UL << 31)

#define HWCAP2_DCPODP     (1 << 0)
#define HWCAP2_SVE2       (1 << 1)
#define HWCAP2_SVEAES     (1 << 2)
#define HWCAP2_SVEPMULL   (1 << 3)
#define HWCAP2_SVEBITPERM (1 << 4)
#define HWCAP2_SVESHA3    (1 << 5)
#define HWCAP2_SVESM4     (1 << 6)
#define HWCAP2_FLAGM2     (1 << 7)
#define HWCAP2_FRINT      (1 << 8)
#define HWCAP2_SVEI8MM    (1 << 9)
#define HWCAP2_SVEF32MM   (1 << 10)
#define HWCAP2_SVEF64MM   (1 << 11)
#define HWCAP2_SVEBF16    (1 << 12)
#define HWCAP2_I8MM       (1 << 13)
#define HWCAP2_BF16       (1 << 14)
#define HWCAP2_DGH        (1 << 15)
#define HWCAP2_RNG        (1 << 16)
#define HWCAP2_BTI        (1 << 17)
#define HWCAP2_MTE        (1 << 18)

#endif /* __aarch64__ */


/*!BEGIN libc/sysv/consts/icmp6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ICMP6_H_

#define ICMP6_DST_UNREACH ICMP6_DST_UNREACH
#define ICMP6_DST_UNREACH_ADDR ICMP6_DST_UNREACH_ADDR
#define ICMP6_DST_UNREACH_ADMIN ICMP6_DST_UNREACH_ADMIN
#define ICMP6_DST_UNREACH_BEYONDSCOPE ICMP6_DST_UNREACH_BEYONDSCOPE
#define ICMP6_DST_UNREACH_NOPORT ICMP6_DST_UNREACH_NOPORT
#define ICMP6_DST_UNREACH_NOROUTE ICMP6_DST_UNREACH_NOROUTE
#define ICMP6_ECHO_REPLY ICMP6_ECHO_REPLY
#define ICMP6_ECHO_REQUEST ICMP6_ECHO_REQUEST
#define ICMP6_FILTER ICMP6_FILTER
#define ICMP6_INFOMSG_MASK ICMP6_INFOMSG_MASK
#define ICMP6_PACKET_TOO_BIG ICMP6_PACKET_TOO_BIG
#define ICMP6_PARAMPROB_HEADER ICMP6_PARAMPROB_HEADER
#define ICMP6_PARAMPROB_NEXTHEADER ICMP6_PARAMPROB_NEXTHEADER
#define ICMP6_PARAMPROB_OPTION ICMP6_PARAMPROB_OPTION
#define ICMP6_PARAM_PROB ICMP6_PARAM_PROB
#define ICMP6_ROUTER_RENUMBERING ICMP6_ROUTER_RENUMBERING
#define ICMP6_RR_FLAGS_FORCEAPPLY ICMP6_RR_FLAGS_FORCEAPPLY
#define ICMP6_RR_FLAGS_PREVDONE ICMP6_RR_FLAGS_PREVDONE
#define ICMP6_RR_FLAGS_REQRESULT ICMP6_RR_FLAGS_REQRESULT
#define ICMP6_RR_FLAGS_SPECSITE ICMP6_RR_FLAGS_SPECSITE
#define ICMP6_RR_FLAGS_TEST ICMP6_RR_FLAGS_TEST
#define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME
#define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME \
  ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME
#define ICMP6_RR_PCOUSE_RAFLAGS_AUTO ICMP6_RR_PCOUSE_RAFLAGS_AUTO
#define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK ICMP6_RR_PCOUSE_RAFLAGS_ONLINK
#define ICMP6_RR_RESULT_FLAGS_FORBIDDEN \
  ICMP6_RR_RESULT_FLAGS_FORBIDDEN
#define ICMP6_RR_RESULT_FLAGS_OOB ICMP6_RR_RESULT_FLAGS_OOB
#define ICMP6_TIME_EXCEEDED ICMP6_TIME_EXCEEDED
#define ICMP6_TIME_EXCEED_REASSEMBLY ICMP6_TIME_EXCEED_REASSEMBLY
#define ICMP6_TIME_EXCEED_TRANSIT ICMP6_TIME_EXCEED_TRANSIT

COSMOPOLITAN_C_START_

extern const uint8_t ICMP6_DST_UNREACH;
extern const uint8_t ICMP6_DST_UNREACH_ADDR;
extern const uint8_t ICMP6_DST_UNREACH_ADMIN;
extern const uint8_t ICMP6_DST_UNREACH_BEYONDSCOPE;
extern const uint8_t ICMP6_DST_UNREACH_NOPORT;
extern const uint8_t ICMP6_DST_UNREACH_NOROUTE;
extern const uint8_t ICMP6_ECHO_REPLY;
extern const uint8_t ICMP6_ECHO_REQUEST;
extern const uint8_t ICMP6_FILTER;
extern const uint8_t ICMP6_INFOMSG_MASK;
extern const uint8_t ICMP6_PACKET_TOO_BIG;
extern const uint8_t ICMP6_PARAMPROB_HEADER;
extern const uint8_t ICMP6_PARAMPROB_NEXTHEADER;
extern const uint8_t ICMP6_PARAMPROB_OPTION;
extern const uint8_t ICMP6_PARAM_PROB;
extern const uint8_t ICMP6_ROUTER_RENUMBERING;
extern const uint8_t ICMP6_RR_FLAGS_FORCEAPPLY;
extern const uint8_t ICMP6_RR_FLAGS_PREVDONE;
extern const uint8_t ICMP6_RR_FLAGS_REQRESULT;
extern const uint8_t ICMP6_RR_FLAGS_SPECSITE;
extern const uint8_t ICMP6_RR_FLAGS_TEST;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_AUTO;
extern const uint8_t ICMP6_RR_PCOUSE_RAFLAGS_ONLINK;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_FORBIDDEN;
extern const uint8_t ICMP6_RR_RESULT_FLAGS_OOB;
extern const uint8_t ICMP6_TIME_EXCEEDED;
extern const uint8_t ICMP6_TIME_EXCEED_REASSEMBLY;
extern const uint8_t ICMP6_TIME_EXCEED_TRANSIT;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/iff.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IFF_H_
COSMOPOLITAN_C_START_

extern const int IFF_UP;
extern const int IFF_ALLMULTI;
extern const int IFF_AUTOMEDIA;
extern const int IFF_BROADCAST;
extern const int IFF_DEBUG;
extern const int IFF_DYNAMIC;
extern const int IFF_LOOPBACK;
extern const int IFF_MASTER;
extern const int IFF_MULTICAST;
extern const int IFF_NOARP;
extern const int IFF_NOTRAILERS;
extern const int IFF_POINTOPOINT;
extern const int IFF_PORTSEL;
extern const int IFF_PROMISC;
extern const int IFF_RUNNING;
extern const int IFF_SLAVE;

COSMOPOLITAN_C_END_

#define IFF_UP          1
#define IFF_BROADCAST   2
#define IFF_DEBUG       4
#define IFF_LOOPBACK    8
#define IFF_ALLMULTI    IFF_ALLMULTI
#define IFF_AUTOMEDIA   IFF_AUTOMEDIA
#define IFF_DYNAMIC     IFF_DYNAMIC
#define IFF_MASTER      IFF_MASTER
#define IFF_MULTICAST   IFF_MULTICAST
#define IFF_NOARP       IFF_NOARP
#define IFF_NOTRAILERS  IFF_NOTRAILERS
#define IFF_POINTOPOINT IFF_POINTOPOINT
#define IFF_PORTSEL     IFF_PORTSEL
#define IFF_PROMISC     IFF_PROMISC
#define IFF_RUNNING     IFF_RUNNING
#define IFF_SLAVE       IFF_SLAVE




/*!BEGIN libc/sysv/consts/in.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IN_H_

#define IN_ACCESS        1
#define IN_ALL_EVENTS    0x0fff
#define IN_ATTRIB        4
#define IN_CLOEXEC       0x080000
#define IN_CLOSE         24
#define IN_CLOSE_NOWRITE 0x10
#define IN_CLOSE_WRITE   8
#define IN_CREATE        0x0100
#define IN_DELETE        0x0200
#define IN_DELETE_SELF   0x0400
#define IN_DONT_FOLLOW   0x02000000
#define IN_EXCL_UNLINK   0x04000000
#define IN_IGNORED       0x8000
#define IN_ISDIR         0x40000000
#define IN_MASK_ADD      0x20000000
#define IN_MODIFY        2
#define IN_MOVE          192
#define IN_MOVED_FROM    0x40
#define IN_MOVED_TO      0x80
#define IN_MOVE_SELF     0x0800
#define IN_NONBLOCK      0x0800
#define IN_ONESHOT       0x80000000
#define IN_ONLYDIR       0x01000000
#define IN_OPEN          0x20
#define IN_Q_OVERFLOW    0x4000
#define IN_UNMOUNT       0x2000
#define IN_CLASSA_NSHIFT 24



/*!BEGIN libc/sysv/consts/inaddr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INADDR_H_

/**
 * @fileoverview Well-known Internet addresses.
 * These need to be hard-coded as little-endian, so htonl() is needed.
 */

#define INADDR_ANY       0x00000000u /* 0.0.0.0 */
#define INADDR_BROADCAST 0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_NONE      0xFFFFFFFFu /* 255.255.255.255 */
#define INADDR_LOOPBACK  0x7F000001u /* 127.0.0.1 */
#define INADDR_TESTNET1  0xC0000200u /* 192.0.2.0/24 (RFC5737§3) */
#define INADDR_TESTNET2  0xC6336400u /* 198.51.100.0/24 */
#define INADDR_TESTNET3  0xCB007100u /* 203.0.113.0/24 */

#define INADDR_ALLHOSTS_GROUP  0xE0000001u
#define INADDR_ALLRTRS_GROUP   0xE0000002u
#define INADDR_MAX_LOCAL_GROUP 0xE00000FFu
#define INADDR_UNSPEC_GROUP    0xE0000000u

#define IN_LOOPBACKNET 127

/* clang-format off */
#define IN6ADDR_ANY_INIT      { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
/* clang-format on */



/*!BEGIN libc/sysv/consts/inet6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_INET6_H_

#define INET6_ADDRSTRLEN 48



/*!BEGIN libc/sysv/consts/io.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IO_H_
COSMOPOLITAN_C_START_

#define _IOC(a, b, c, d) (((a) << 30) | ((b) << 8) | (c) | ((d) << 16))
#define _IOC_NONE        0U
#define _IOC_WRITE       1U
#define _IOC_READ        2U

#define _IO(a, b)      _IOC(_IOC_NONE, (a), (b), 0)
#define _IOW(a, b, c)  _IOC(_IOC_WRITE, (a), (b), sizeof(c))
#define _IOR(a, b, c)  _IOC(_IOC_READ, (a), (b), sizeof(c))
#define _IOWR(a, b, c) _IOC(_IOC_READ | _IOC_WRITE, (a), (b), sizeof(c))

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ioprio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOPRIO_H_
#ifdef _COSMO_SOURCE

#define IOPRIO_WHO_PROCESS 1
#define IOPRIO_WHO_PGRP    2
#define IOPRIO_WHO_USER    3

#define IOPRIO_CLASS_SHIFT 13
#define IOPRIO_CLASS_MASK  0x07
#define IOPRIO_PRIO_MASK   ((1UL << IOPRIO_CLASS_SHIFT) - 1)

#define IOPRIO_PRIO_CLASS(ioprio) \
  (((ioprio) >> IOPRIO_CLASS_SHIFT) & IOPRIO_CLASS_MASK)
#define IOPRIO_PRIO_DATA(ioprio) ((ioprio)&IOPRIO_PRIO_MASK)
#define IOPRIO_PRIO_VALUE(class, data)                     \
  ((((class) & IOPRIO_CLASS_MASK) << IOPRIO_CLASS_SHIFT) | \
   ((data)&IOPRIO_PRIO_MASK))

#define IOPRIO_CLASS_NONE 0
#define IOPRIO_CLASS_RT   1
#define IOPRIO_CLASS_BE   2
#define IOPRIO_CLASS_IDLE 3

#define IOPRIO_NR_LEVELS 8
#define IOPRIO_BE_NR     IOPRIO_NR_LEVELS

#define IOPRIO_NORM    4
#define IOPRIO_BE_NORM IOPRIO_NORM

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/iov.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IOV_H_
COSMOPOLITAN_C_START_

extern const int IOV_MAX;

COSMOPOLITAN_C_END_

#define IOV_MAX IOV_MAX



/*!BEGIN libc/sysv/consts/ip.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IP_H_
COSMOPOLITAN_C_START_

extern const int IP_ADD_MEMBERSHIP;
extern const int IP_ADD_SOURCE_MEMBERSHIP;
extern const int IP_BIND_ADDRESS_NO_PORT;
extern const int IP_BLOCK_SOURCE;
extern const int IP_CHECKSUM;
extern const int IP_DEFAULT_MULTICAST_LOOP;
extern const int IP_DEFAULT_MULTICAST_TTL;
extern const int IP_DROP_MEMBERSHIP;
extern const int IP_DROP_SOURCE_MEMBERSHIP;
extern const int IP_FREEBIND;
extern const int IP_HDRINCL;
extern const int IP_IPSEC_POLICY;
extern const int IP_MAX_MEMBERSHIPS;
extern const int IP_MINTTL;
extern const int IP_MSFILTER;
extern const int IP_MTU;
extern const int IP_MTU_DISCOVER;
extern const int IP_MULTICAST_ALL;
extern const int IP_MULTICAST_IF;
extern const int IP_MULTICAST_LOOP;
extern const int IP_MULTICAST_TTL;
extern const int IP_NODEFRAG;
extern const int IP_OPTIONS;
extern const int IP_ORIGDSTADDR;
extern const int IP_PASSSEC;
extern const int IP_PKTINFO;
extern const int IP_PKTOPTIONS;
extern const int IP_PMTUDISC;
extern const int IP_PMTUDISC_DO;
extern const int IP_PMTUDISC_DONT;
extern const int IP_PMTUDISC_INTERFACE;
extern const int IP_PMTUDISC_OMIT;
extern const int IP_PMTUDISC_PROBE;
extern const int IP_PMTUDISC_WANT;
extern const int IP_RECVDSTADDR;
extern const int IP_RECVERR;
extern const int IP_RECVOPTS;
extern const int IP_RECVORIGDSTADDR;
extern const int IP_RECVRETOPTS;
extern const int IP_RECVTOS;
extern const int IP_RECVTTL;
extern const int IP_RETOPTS;
extern const int IP_ROUTER_ALERT;
extern const int IP_TOS;
extern const int IP_TRANSPARENT;
extern const int IP_TTL;
extern const int IP_UNBLOCK_SOURCE;
extern const int IP_UNICAST_IF;
extern const int IP_XFRM_POLICY;

#define IP_ADD_MEMBERSHIP         IP_ADD_MEMBERSHIP
#define IP_ADD_SOURCE_MEMBERSHIP  IP_ADD_SOURCE_MEMBERSHIP
#define IP_BIND_ADDRESS_NO_PORT   IP_BIND_ADDRESS_NO_PORT
#define IP_BLOCK_SOURCE           IP_BLOCK_SOURCE
#define IP_CHECKSUM               IP_CHECKSUM
#define IP_DEFAULT_MULTICAST_LOOP IP_DEFAULT_MULTICAST_LOOP
#define IP_DEFAULT_MULTICAST_TTL  IP_DEFAULT_MULTICAST_TTL
#define IP_DROP_MEMBERSHIP        IP_DROP_MEMBERSHIP
#define IP_DROP_SOURCE_MEMBERSHIP IP_DROP_SOURCE_MEMBERSHIP
#define IP_FREEBIND               IP_FREEBIND
#define IP_HDRINCL                IP_HDRINCL
#define IP_IPSEC_POLICY           IP_IPSEC_POLICY
#define IP_MAX_MEMBERSHIPS        IP_MAX_MEMBERSHIPS
#define IP_MINTTL                 IP_MINTTL
#define IP_MSFILTER               IP_MSFILTER
#define IP_MTU                    IP_MTU
#define IP_MTU_DISCOVER           IP_MTU_DISCOVER
#define IP_MULTICAST_ALL          IP_MULTICAST_ALL
#define IP_MULTICAST_IF           IP_MULTICAST_IF
#define IP_MULTICAST_LOOP         IP_MULTICAST_LOOP
#define IP_MULTICAST_TTL          IP_MULTICAST_TTL
#define IP_NODEFRAG               IP_NODEFRAG
#define IP_OPTIONS                IP_OPTIONS
#define IP_ORIGDSTADDR            IP_ORIGDSTADDR
#define IP_PASSSEC                IP_PASSSEC
#define IP_PKTINFO                IP_PKTINFO
#define IP_PKTOPTIONS             IP_PKTOPTIONS
#define IP_PMTUDISC               IP_PMTUDISC
#define IP_PMTUDISC_DO            IP_PMTUDISC_DO
#define IP_PMTUDISC_DONT          IP_PMTUDISC_DONT
#define IP_PMTUDISC_INTERFACE     IP_PMTUDISC_INTERFACE
#define IP_PMTUDISC_OMIT          IP_PMTUDISC_OMIT
#define IP_PMTUDISC_PROBE         IP_PMTUDISC_PROBE
#define IP_PMTUDISC_WANT          IP_PMTUDISC_WANT
#define IP_RECVDSTADDR            IP_RECVDSTADDR
#define IP_RECVERR                IP_RECVERR
#define IP_RECVOPTS               IP_RECVOPTS
#define IP_RECVORIGDSTADDR        IP_RECVORIGDSTADDR
#define IP_RECVRETOPTS            IP_RECVRETOPTS
#define IP_RECVTOS                IP_RECVTOS
#define IP_RECVTTL                IP_RECVTTL
#define IP_RETOPTS                IP_RETOPTS
#define IP_ROUTER_ALERT           IP_ROUTER_ALERT
#define IP_TOS                    IP_TOS
#define IP_TRANSPARENT            IP_TRANSPARENT
#define IP_TTL                    IP_TTL
#define IP_UNBLOCK_SOURCE         IP_UNBLOCK_SOURCE
#define IP_UNICAST_IF             IP_UNICAST_IF
#define IP_XFRM_POLICY            IP_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipport.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPORT_H_

/**
 * ARPA network ports.
 */
#define IPPORT_ECHO         7
#define IPPORT_DISCARD      9
#define IPPORT_SYSTAT       11
#define IPPORT_DAYTIME      13
#define IPPORT_NETSTAT      15
#define IPPORT_FTP          21
#define IPPORT_TELNET       23
#define IPPORT_SMTP         25
#define IPPORT_TIMESERVER   37
#define IPPORT_NAMESERVER   42
#define IPPORT_WHOIS        43
#define IPPORT_MTP          57
#define IPPORT_TFTP         69
#define IPPORT_RJE          77
#define IPPORT_FINGER       79
#define IPPORT_TTYLINK      87
#define IPPORT_SUPDUP       95
#define IPPORT_EXECSERVER   512
#define IPPORT_LOGINSERVER  513
#define IPPORT_CMDSERVER    514
#define IPPORT_EFSSERVER    520
#define IPPORT_BIFFUDP      512
#define IPPORT_WHOSERVER    513
#define IPPORT_ROUTESERVER  520
#define IPPORT_RESERVED     1024
#define IPPORT_USERRESERVED IPPORT_USERRESERVED

/**
 * Modern network ports.
 */
#define IPPORT_SSH         22
#define IPPORT_DOMAIN      53
#define IPPORT_HTTP        80
#define IPPORT_POP3        110
#define IPPORT_SFTP        115
#define IPPORT_NTP         123
#define IPPORT_IMAP2       143
#define IPPORT_NETBIOS_NS  137
#define IPPORT_NETBIOS_DGM 138
#define IPPORT_NETBIOS_SSN 139
#define IPPORT_BGP         179
#define IPPORT_IRC         194
#define IPPORT_HTTPS       443
#define IPPORT_PRINTER     515
#define IPPORT_NFS         2049
#define IPPORT_DISTCC      3632
#define IPPORT_SIP         5060
#define IPPORT_POSTGRESQL  5432
#define IPPORT_X11         6000
#define IPPORT_GIT         9418
#define IPPORT_IRCD        6667
#define IPPORT_IMAPS       993
#define IPPORT_POP3S       995

COSMOPOLITAN_C_START_

extern const int IPPORT_USERRESERVED;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ipproto.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPPROTO_H_

#define IPPROTO_IP     0
#define IPPROTO_ICMP   1
#define IPPROTO_TCP    6
#define IPPROTO_UDP    17
#define IPPROTO_IPV6   41
#define IPPROTO_ICMPV6 58
#define IPPROTO_RAW    255
#define IPPROTO_MAX    263 /* xxx */



/*!BEGIN libc/sysv/consts/ipv6.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_IPV6_H_
COSMOPOLITAN_C_START_

extern const int IPV6_2292DSTOPTS;
extern const int IPV6_2292HOPLIMIT;
extern const int IPV6_2292HOPOPTS;
extern const int IPV6_2292PKTINFO;
extern const int IPV6_2292PKTOPTIONS;
extern const int IPV6_2292RTHDR;
extern const int IPV6_ADDRFORM;
extern const int IPV6_ADD_MEMBERSHIP;
extern const int IPV6_AUTHHDR;
extern const int IPV6_AUTOFLOWLABEL;
extern const int IPV6_CHECKSUM;
extern const int IPV6_DONTFRAG;
extern const int IPV6_DROP_MEMBERSHIP;
extern const int IPV6_DSTOPTS;
extern const int IPV6_HDRINCL;
extern const int IPV6_HOPLIMIT;
extern const int IPV6_HOPOPTS;
extern const int IPV6_IPSEC_POLICY;
extern const int IPV6_JOIN_ANYCAST;
extern const int IPV6_JOIN_GROUP;
extern const int IPV6_LEAVE_ANYCAST;
extern const int IPV6_LEAVE_GROUP;
extern const int IPV6_MINHOPCOUNT;
extern const int IPV6_MTU;
extern const int IPV6_MTU_DISCOVER;
extern const int IPV6_MULTICAST_HOPS;
extern const int IPV6_MULTICAST_IF;
extern const int IPV6_MULTICAST_LOOP;
extern const int IPV6_NEXTHOP;
extern const int IPV6_ORIGDSTADDR;
extern const int IPV6_PATHMTU;
extern const int IPV6_PKTINFO;
extern const int IPV6_PMTUDISC_DO;
extern const int IPV6_PMTUDISC_DONT;
extern const int IPV6_PMTUDISC_INTERFACE;
extern const int IPV6_PMTUDISC_OMIT;
extern const int IPV6_PMTUDISC_PROBE;
extern const int IPV6_PMTUDISC_WANT;
extern const int IPV6_RECVDSTOPTS;
extern const int IPV6_RECVERR;
extern const int IPV6_RECVHOPLIMIT;
extern const int IPV6_RECVHOPOPTS;
extern const int IPV6_RECVORIGDSTADDR;
extern const int IPV6_RECVPATHMTU;
extern const int IPV6_RECVPKTINFO;
extern const int IPV6_RECVRTHDR;
extern const int IPV6_RECVTCLASS;
extern const int IPV6_ROUTER_ALERT;
extern const int IPV6_RTHDR;
extern const int IPV6_RTHDRDSTOPTS;
extern const int IPV6_RTHDR_LOOSE;
extern const int IPV6_RTHDR_STRICT;
extern const int IPV6_RTHDR_TYPE_0;
extern const int IPV6_RXDSTOPTS;
extern const int IPV6_RXHOPOPTS;
extern const int IPV6_TCLASS;
extern const int IPV6_UNICAST_HOPS;
extern const int IPV6_V6ONLY;
extern const int IPV6_XFRM_POLICY;

#define IPV6_2292DSTOPTS        IPV6_2292DSTOPTS
#define IPV6_2292HOPLIMIT       IPV6_2292HOPLIMIT
#define IPV6_2292HOPOPTS        IPV6_2292HOPOPTS
#define IPV6_2292PKTINFO        IPV6_2292PKTINFO
#define IPV6_2292PKTOPTIONS     IPV6_2292PKTOPTIONS
#define IPV6_2292RTHDR          IPV6_2292RTHDR
#define IPV6_ADDRFORM           IPV6_ADDRFORM
#define IPV6_ADD_MEMBERSHIP     IPV6_ADD_MEMBERSHIP
#define IPV6_AUTHHDR            IPV6_AUTHHDR
#define IPV6_AUTOFLOWLABEL      IPV6_AUTOFLOWLABEL
#define IPV6_CHECKSUM           IPV6_CHECKSUM
#define IPV6_DONTFRAG           IPV6_DONTFRAG
#define IPV6_DROP_MEMBERSHIP    IPV6_DROP_MEMBERSHIP
#define IPV6_DSTOPTS            IPV6_DSTOPTS
#define IPV6_HDRINCL            IPV6_HDRINCL
#define IPV6_HOPLIMIT           IPV6_HOPLIMIT
#define IPV6_HOPOPTS            IPV6_HOPOPTS
#define IPV6_IPSEC_POLICY       IPV6_IPSEC_POLICY
#define IPV6_JOIN_ANYCAST       IPV6_JOIN_ANYCAST
#define IPV6_JOIN_GROUP         IPV6_JOIN_GROUP
#define IPV6_LEAVE_ANYCAST      IPV6_LEAVE_ANYCAST
#define IPV6_LEAVE_GROUP        IPV6_LEAVE_GROUP
#define IPV6_MINHOPCOUNT        IPV6_MINHOPCOUNT
#define IPV6_MTU                IPV6_MTU
#define IPV6_MTU_DISCOVER       IPV6_MTU_DISCOVER
#define IPV6_MULTICAST_HOPS     IPV6_MULTICAST_HOPS
#define IPV6_MULTICAST_IF       IPV6_MULTICAST_IF
#define IPV6_MULTICAST_LOOP     IPV6_MULTICAST_LOOP
#define IPV6_NEXTHOP            IPV6_NEXTHOP
#define IPV6_ORIGDSTADDR        IPV6_ORIGDSTADDR
#define IPV6_PATHMTU            IPV6_PATHMTU
#define IPV6_PKTINFO            IPV6_PKTINFO
#define IPV6_PMTUDISC_DO        IPV6_PMTUDISC_DO
#define IPV6_PMTUDISC_DONT      IPV6_PMTUDISC_DONT
#define IPV6_PMTUDISC_INTERFACE IPV6_PMTUDISC_INTERFACE
#define IPV6_PMTUDISC_OMIT      IPV6_PMTUDISC_OMIT
#define IPV6_PMTUDISC_PROBE     IPV6_PMTUDISC_PROBE
#define IPV6_PMTUDISC_WANT      IPV6_PMTUDISC_WANT
#define IPV6_RECVDSTOPTS        IPV6_RECVDSTOPTS
#define IPV6_RECVERR            IPV6_RECVERR
#define IPV6_RECVHOPLIMIT       IPV6_RECVHOPLIMIT
#define IPV6_RECVHOPOPTS        IPV6_RECVHOPOPTS
#define IPV6_RECVORIGDSTADDR    IPV6_RECVORIGDSTADDR
#define IPV6_RECVPATHMTU        IPV6_RECVPATHMTU
#define IPV6_RECVPKTINFO        IPV6_RECVPKTINFO
#define IPV6_RECVRTHDR          IPV6_RECVRTHDR
#define IPV6_RECVTCLASS         IPV6_RECVTCLASS
#define IPV6_ROUTER_ALERT       IPV6_ROUTER_ALERT
#define IPV6_RTHDR              IPV6_RTHDR
#define IPV6_RTHDRDSTOPTS       IPV6_RTHDRDSTOPTS
#define IPV6_RTHDR_LOOSE        IPV6_RTHDR_LOOSE
#define IPV6_RTHDR_STRICT       IPV6_RTHDR_STRICT
#define IPV6_RTHDR_TYPE_0       IPV6_RTHDR_TYPE_0
#define IPV6_RXDSTOPTS          IPV6_RXDSTOPTS
#define IPV6_RXHOPOPTS          IPV6_RXHOPOPTS
#define IPV6_TCLASS             IPV6_TCLASS
#define IPV6_UNICAST_HOPS       IPV6_UNICAST_HOPS
#define IPV6_V6ONLY             IPV6_V6ONLY
#define IPV6_XFRM_POLICY        IPV6_XFRM_POLICY


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/itimer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ITIMER_H_

#define ITIMER_REAL    0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF    2



/*!BEGIN libc/sysv/consts/kd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KD_H_
COSMOPOLITAN_C_START_

extern const uint64_t GIO_FONT;
extern const uint64_t PIO_FONT;
extern const uint64_t GIO_FONTX;
extern const uint64_t PIO_FONTX;
extern const uint64_t PIO_FONT8x8;
extern const uint64_t PIO_FONT8x14;
extern const uint64_t PIO_FONT8x16;
extern const uint64_t PIO_VFONT;
extern const uint64_t PIO_FONTRESET;
extern const uint64_t KDFONTOP;

COSMOPOLITAN_C_END_

#define GIO_FONT      GIO_FONT
#define PIO_FONT      PIO_FONT
#define GIO_FONTX     GIO_FONTX
#define PIO_FONTX     PIO_FONTX
#define PIO_FONT8x8   PIO_FONT8x8
#define PIO_FONT8x14  PIO_FONT8x14
#define PIO_FONT8x16  PIO_FONT8x14
#define PIO_VFONT     PIO_VFONT
#define PIO_FONTRESET PIO_FONTRESET
#define KDFONTOP      KDFONTOP

#ifdef _BSD_SOURCE
#define PIO_VFONT_DEFAULT PIO_FONTRESET
#endif



/*!BEGIN libc/sysv/consts/kern.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_KERN_H_
COSMOPOLITAN_C_START_

#define KERN_SOH       "\001"
#define KERN_SOH_ASCII '\001'
#define KERN_EMERG     KERN_SOH "0"
#define KERN_ALERT     KERN_SOH "1"
#define KERN_CRIT      KERN_SOH "2"
#define KERN_ERR       KERN_SOH "3"
#define KERN_WARNING   KERN_SOH "4"
#define KERN_NOTICE    KERN_SOH "5"
#define KERN_INFO      KERN_SOH "6"
#define KERN_DEBUG     KERN_SOH "7"
#define KERN_DEFAULT   ""
#define KERN_CONT      KERN_SOH "c"

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/l.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_L_H_

#define L_SET  SEEK_SET
#define L_INCR SEEK_CUR
#define L_XTND SEEK_END



/*!BEGIN libc/sysv/consts/limits.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIMITS_H_
COSMOPOLITAN_C_START_

extern const int NGROUPS_MAX;
extern const int PIPE_BUF;
extern const int SOMAXCONN;
extern const int _ARG_MAX;
extern const int _NAME_MAX;
extern const int _NSIG;
extern const int _PATH_MAX;
extern const int LINK_MAX;
extern const int MAX_CANON;
extern const int MAX_INPUT;

#define NGROUPS_MAX NGROUPS_MAX
#define PIPE_BUF    PIPE_BUF
#define SOMAXCONN   SOMAXCONN
#define _ARG_MAX    _ARG_MAX
#define _NAME_MAX   _NAME_MAX
#define _NSIG       _NSIG
#define _PATH_MAX   _PATH_MAX
#define LINK_MAX    LINK_MAX
#define MAX_CANON   MAX_CANON
#define MAX_INPUT   MAX_INPUT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LIO_H_

#define LIO_NOP LIO_NOP
#define LIO_NOWAIT LIO_NOWAIT
#define LIO_READ LIO_READ
#define LIO_WAIT LIO_WAIT
#define LIO_WRITE LIO_WRITE

COSMOPOLITAN_C_START_

extern const int LIO_NOP;
extern const int LIO_NOWAIT;
extern const int LIO_READ;
extern const int LIO_WAIT;
extern const int LIO_WRITE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/lock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOCK_H_
COSMOPOLITAN_C_START_

extern const int LOCK_EX;
extern const int LOCK_NB;
extern const int LOCK_SH;
extern const int LOCK_UN;
extern const int LOCK_UNLOCK_CACHE;

COSMOPOLITAN_C_END_

#define LOCK_EX 2
#define LOCK_NB LOCK_NB
#define LOCK_SH LOCK_SH
#define LOCK_UN LOCK_UN




/*!BEGIN libc/sysv/consts/log.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOG_H_

#define LOG_MASK(pri) (1 << (pri))
#define LOG_UPTO(pri) ((1 << ((pri) + 1)) - 1)

#define LOG_EMERG   0
#define LOG_ALERT   1
#define LOG_CRIT    2
#define LOG_ERR     3
#define LOG_WARNING 4
#define LOG_NOTICE  5
#define LOG_INFO    6
#define LOG_DEBUG   7

#define LOG_KERN     0000
#define LOG_USER     0010
#define LOG_MAIL     0020
#define LOG_DAEMON   0030
#define LOG_AUTH     0040
#define LOG_SYSLOG   0050
#define LOG_LPR      0060
#define LOG_NEWS     0070
#define LOG_UUCP     0100
#define LOG_CRON     0110
#define LOG_AUTHPRIV 0120
#define LOG_FTP      0130

#define LOG_PID    1
#define LOG_CONS   2
#define LOG_ODELAY 4
#define LOG_NDELAY 8
#define LOG_NOWAIT 16
#define LOG_PERROR 32

#define LOG_LOCAL0 128
#define LOG_LOCAL1 136
#define LOG_LOCAL2 144
#define LOG_LOCAL3 152
#define LOG_LOCAL4 160
#define LOG_LOCAL5 168
#define LOG_LOCAL6 176
#define LOG_LOCAL7 184

#define LOG_NFACILITIES 24
#define LOG_FACMASK     0x03f8
#define LOG_FAC(p)      ((LOG_FACMASK & (p)) >> 3)

#define LOG_PRIMASK       7
#define LOG_PRI(p)        (LOG_PRIMASK & (p))
#define LOG_MAKEPRI(f, p) (((f) << 3) | (p))



/*!BEGIN libc/sysv/consts/loglevel.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_LOGLEVEL_H_
COSMOPOLITAN_C_START_

#define LOGLEVEL_SCHED   -2
#define LOGLEVEL_DEFAULT -1
#define LOGLEVEL_EMERG   0
#define LOGLEVEL_ALERT   1
#define LOGLEVEL_CRIT    2
#define LOGLEVEL_ERR     3
#define LOGLEVEL_WARNING 4
#define LOGLEVEL_NOTICE  5
#define LOGLEVEL_INFO    6
#define LOGLEVEL_DEBUG   7

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/madv.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MADV_H_
COSMOPOLITAN_C_START_

extern const unsigned MADV_DODUMP;
extern const unsigned MADV_DOFORK;
extern const unsigned MADV_DONTDUMP;
extern const unsigned MADV_DONTFORK;
extern const unsigned MADV_DONTNEED;
extern const unsigned MADV_FREE;
extern const unsigned MADV_HUGEPAGE;
extern const unsigned MADV_HWPOISON;
extern const unsigned MADV_MERGEABLE;
extern const unsigned MADV_NOHUGEPAGE;
extern const unsigned MADV_NORMAL;
extern const unsigned MADV_RANDOM;
extern const unsigned MADV_REMOVE;
extern const unsigned MADV_SEQUENTIAL;
extern const unsigned MADV_UNMERGEABLE;
extern const unsigned MADV_WILLNEED;
extern const unsigned MADV_SOFT_OFFLINE;
extern const unsigned MADV_WIPEONFORK;
extern const unsigned MADV_KEEPONFORK;
extern const unsigned MADV_COLD;
extern const unsigned MADV_PAGEOUT;
extern const unsigned MADV_POPULATE_READ;
extern const unsigned MADV_POPULATE_WRITE;
extern const unsigned MADV_DONTNEED_LOCKED;
extern const unsigned MADV_COLLAPSE;

#define MADV_NORMAL     0
#define MADV_RANDOM     1
#define MADV_SEQUENTIAL 2
#define MADV_WILLNEED   3

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/map.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MAP_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int MAP_32BIT;
extern const int MAP_ANON;
extern const int MAP_ANONYMOUS;
extern const int MAP_CONCEAL;
extern const int MAP_DENYWRITE;
extern const int MAP_EXECUTABLE;
extern const int MAP_FILE;
extern const int MAP_FIXED;
extern const int MAP_FIXED_NOREPLACE;
extern const int MAP_HASSEMAPHORE;
extern const int MAP_HUGETLB;
extern const int MAP_INHERIT;
extern const int MAP_JIT;
extern const int MAP_LOCKED;
extern const int MAP_NOCACHE;
extern const int MAP_NOEXTEND;
extern const int MAP_NONBLOCK;
extern const int MAP_NORESERVE;
extern const int MAP_NOSYNC;
extern const int MAP_POPULATE;
extern const int MAP_PRIVATE;
extern const int MAP_SHARED;
extern const int MAP_SHARED_VALIDATE;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define MAP_FILE    0
#define MAP_SHARED  1
#define MAP_PRIVATE 2
#define MAP_STACK   6
#define MAP_TYPE    15
#define MAP_FIXED   16

#define MAP_ANONYMOUS       MAP_ANONYMOUS
#define MAP_CONCEAL         MAP_CONCEAL
#define MAP_EXECUTABLE      MAP_EXECUTABLE
#define MAP_FIXED_NOREPLACE MAP_FIXED_NOREPLACE
#define MAP_HASSEMAPHORE    MAP_HASSEMAPHORE
#define MAP_POPULATE        MAP_POPULATE
#define MAP_NORESERVE       MAP_NORESERVE

#define MAP_ANON   MAP_ANONYMOUS
#define MAP_NOCORE MAP_CONCEAL



/*!BEGIN libc/sysv/consts/mcast.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MCAST_H_

#define MCAST_BLOCK_SOURCE MCAST_BLOCK_SOURCE
#define MCAST_EXCLUDE MCAST_EXCLUDE
#define MCAST_INCLUDE MCAST_INCLUDE
#define MCAST_JOIN_GROUP MCAST_JOIN_GROUP
#define MCAST_JOIN_SOURCE_GROUP MCAST_JOIN_SOURCE_GROUP
#define MCAST_LEAVE_GROUP MCAST_LEAVE_GROUP
#define MCAST_LEAVE_SOURCE_GROUP MCAST_LEAVE_SOURCE_GROUP
#define MCAST_MSFILTER MCAST_MSFILTER
#define MCAST_UNBLOCK_SOURCE MCAST_UNBLOCK_SOURCE

COSMOPOLITAN_C_START_

extern const int MCAST_BLOCK_SOURCE;
extern const int MCAST_EXCLUDE;
extern const int MCAST_INCLUDE;
extern const int MCAST_JOIN_GROUP;
extern const int MCAST_JOIN_SOURCE_GROUP;
extern const int MCAST_LEAVE_GROUP;
extern const int MCAST_LEAVE_SOURCE_GROUP;
extern const int MCAST_MSFILTER;
extern const int MCAST_UNBLOCK_SOURCE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mfd.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MFD_H_

#define MFD_CLOEXEC       1
#define MFD_ALLOW_SEALING 2



/*!BEGIN libc/sysv/consts/mlock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MLOCK_H_
COSMOPOLITAN_C_START_

extern const int MCL_CURRENT;
extern const int MCL_FUTURE;
extern const int MCL_ONFAULT;

COSMOPOLITAN_C_END_

#define MCL_CURRENT 1
#define MCL_FUTURE  2
#define MCL_ONFAULT MCL_ONFAULT



/*!BEGIN libc/sysv/consts/modem.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MODEM_H_
COSMOPOLITAN_C_START_

extern const uint64_t TIOCMGET;
extern const uint64_t TIOCMSET;
extern const uint64_t TIOCMBIC;
extern const uint64_t TIOCMBIS;

extern const int TIOCM_CAR;
extern const int TIOCM_CD;
extern const int TIOCM_CTS;
extern const int TIOCM_DSR;
extern const int TIOCM_DTR;
extern const int TIOCM_LE;
extern const int TIOCM_RI;
extern const int TIOCM_RNG;
extern const int TIOCM_RTS;
extern const int TIOCM_SR;
extern const int TIOCM_ST;

#define TIOCM_LE  0x01
#define TIOCM_DTR 0x02
#define TIOCM_RTS 0x04
#define TIOCM_ST  0x08
#define TIOCM_SR  0x10
#define TIOCM_CTS 0x20
#define TIOCM_CAR 0x40
#define TIOCM_CD  0x40
#define TIOCM_RI  0x80
#define TIOCM_RNG 0x80
#define TIOCM_DSR 0x0100

#define TIOCMGET TIOCMGET
#define TIOCMSET TIOCMSET
#define TIOCMBIC TIOCMBIC
#define TIOCMBIS TIOCMBIS


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const unsigned long MS_RDONLY;
extern const int MNT_RDONLY;
extern const unsigned long MS_NOSUID;
extern const int MNT_NOSUID;
extern const unsigned long MS_NODEV;
extern const int MNT_NODEV;
extern const unsigned long MS_NOEXEC;
extern const int MNT_NOEXEC;
extern const unsigned long MS_SYNCHRONOUS;
extern const int MNT_SYNCHRONOUS;
extern const unsigned long MS_REMOUNT;
extern const int MNT_UPDATE;
extern const unsigned long MS_MANDLOCK;
extern const unsigned long MS_DIRSYNC;
extern const unsigned long MS_NOATIME;
extern const int MNT_NOATIME;
extern const unsigned long MS_NODIRATIME;
extern const unsigned long MS_BIND;
extern const unsigned long MS_MOVE;
extern const unsigned long MS_REC;
extern const unsigned long MS_SILENT;
extern const unsigned long MS_POSIXACL;
extern const unsigned long MS_UNBINDABLE;
extern const unsigned long MS_PRIVATE;
extern const unsigned long MS_SLAVE;
extern const unsigned long MS_SHARED;
extern const unsigned long MS_RELATIME;
extern const int MNT_RELATIME;
extern const unsigned long MS_KERNMOUNT;
extern const unsigned long MS_I_VERSION;
extern const unsigned long MS_STRICTATIME;
extern const int MNT_STRICTATIME;
extern const unsigned long MS_LAZYTIME;
extern const unsigned long MS_ACTIVE;
extern const unsigned long MS_NOUSER;
extern const unsigned long MS_RMT_MASK;
extern const unsigned long MS_MGC_VAL;
extern const unsigned long MS_MGC_MSK;
extern const int MNT_ASYNC;
extern const int MNT_RELOAD;
extern const int MNT_SUIDDIR;
extern const int MNT_NOCLUSTERR;
extern const int MNT_NOCLUSTERW;
extern const int MNT_SNAPSHOT;

#define MS_RDONLY       0x00000001
#define MNT_RDONLY      0x00000001
#define MS_NOSUID       MS_NOSUID
#define MNT_NOSUID      MNT_NOSUID
#define MS_NODEV        MS_NODEV
#define MNT_NODEV       MNT_NODEV
#define MS_NOEXEC       MS_NOEXEC
#define MNT_NOEXEC      MNT_NOEXEC
#define MS_SYNCHRONOUS  MS_SYNCHRONOUS
#define MNT_SYNCHRONOUS MNT_SYNCHRONOUS
#define MS_REMOUNT      MS_REMOUNT
#define MNT_UPDATE      MNT_UPDATE
#define MS_MANDLOCK     MS_MANDLOCK
#define MS_DIRSYNC      MS_DIRSYNC
#define MS_NOATIME      MS_NOATIME
#define MNT_NOATIME     MNT_NOATIME
#define MS_NODIRATIME   MS_NODIRATIME
#define MS_BIND         MS_BIND
#define MS_MOVE         MS_MOVE
#define MS_REC          MS_REC
#define MS_SILENT       MS_SILENT
#define MS_POSIXACL     MS_POSIXACL
#define MS_UNBINDABLE   MS_UNBINDABLE
#define MS_PRIVATE      MS_PRIVATE
#define MS_SLAVE        MS_SLAVE
#define MS_SHARED       MS_SHARED
#define MS_RELATIME     MS_RELATIME
#define MNT_RELATIME    MNT_RELATIME
#define MS_KERNMOUNT    MS_KERNMOUNT
#define MS_I_VERSION    MS_I_VERSION
#define MS_STRICTATIME  MS_STRICTATIME
#define MNT_STRICTATIME MNT_STRICTATIME
#define MS_LAZYTIME     MS_LAZYTIME
#define MS_ACTIVE       MS_ACTIVE
#define MS_NOUSER       MS_NOUSER
#define MS_RMT_MASK     MS_RMT_MASK
#define MS_MGC_VAL      MS_MGC_VAL
#define MS_MGC_MSK      MS_MGC_MSK
#define MNT_ASYNC       MNT_ASYNC
#define MNT_RELOAD      MNT_RELOAD
#define MNT_SUIDDIR     MNT_SUIDDIR
#define MNT_NOCLUSTERR  MNT_NOCLUSTERR
#define MNT_NOCLUSTERW  MNT_NOCLUSTERW
#define MNT_SNAPSHOT    MNT_SNAPSHOT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/mremap.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MREMAP_H_

#define MREMAP_MAYMOVE 1
#define MREMAP_FIXED   2



/*!BEGIN libc/sysv/consts/msg.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSG_H_
COSMOPOLITAN_C_START_

extern const int MSG_BATCH;
extern const int MSG_BCAST;
extern const int MSG_CMSG_CLOEXEC;
extern const int MSG_CONFIRM;
extern const int MSG_CTRUNC;
extern const int MSG_DONTROUTE;
extern const int MSG_DONTWAIT;
extern const int MSG_EOF;
extern const int MSG_EOR;
extern const int MSG_ERRQUEUE;
extern const int MSG_EXCEPT;
extern const int MSG_FASTOPEN;
extern const int MSG_FIN;
extern const int MSG_INFO;
extern const int MSG_MCAST;
extern const int MSG_MORE;
extern const int MSG_NOERROR;
extern const int MSG_NOSIGNAL;
extern const int MSG_NOTIFICATION;
extern const int MSG_OOB;
extern const int MSG_PARITY_ERROR;
extern const int MSG_PEEK;
extern const int MSG_PROXY;
extern const int MSG_RST;
extern const int MSG_STAT;
extern const int MSG_SYN;
extern const int MSG_TRUNC;
extern const int MSG_WAITALL;
extern const int MSG_WAITFORONE;

#define MSG_OOB       1
#define MSG_PEEK      2
#define MSG_DONTROUTE 4
#define MSG_DONTWAIT  MSG_DONTWAIT
#define MSG_FASTOPEN  MSG_FASTOPEN
#define MSG_WAITALL   MSG_WAITALL
#define MSG_TRUNC     MSG_TRUNC
#define MSG_CTRUNC    MSG_CTRUNC

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/msync.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MSYNC_H_
COSMOPOLITAN_C_START_

extern const int MS_SYNC;
extern const int MS_ASYNC;
extern const int MS_INVALIDATE;

#define MS_SYNC       MS_SYNC
#define MS_ASYNC      MS_ASYNC
#define MS_INVALIDATE MS_INVALIDATE

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/nrlinux.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_NRLINUX_H_
#ifdef _COSMO_SOURCE

#ifdef __x86_64__

#define __NR_linux_exit                    0x003c
#define __NR_linux_exit_group              0x00e7
#define __NR_linux_read                    0x0000
#define __NR_linux_write                   0x0001
#define __NR_linux_open                    0x0002
#define __NR_linux_close                   0x0003
#define __NR_linux_stat                    0x0004
#define __NR_linux_fstat                   0x0005
#define __NR_linux_lstat                   0x0006
#define __NR_linux_poll                    0x0007
#define __NR_linux_ppoll                   0x010f
#define __NR_linux_brk                     0x000c
#define __NR_linux_sigreturn               0x000f
#define __NR_linux_lseek                   0x0008
#define __NR_linux_mmap                    0x0009
#define __NR_linux_msync                   0x001a
#define __NR_linux_mprotect                0x000a
#define __NR_linux_munmap                  0x000b
#define __NR_linux_sigaction               0x000d
#define __NR_linux_sigprocmask             0x000e
#define __NR_linux_ioctl                   0x0010
#define __NR_linux_pread                   0x0011
#define __NR_linux_pwrite                  0x0012
#define __NR_linux_readv                   0x0013
#define __NR_linux_writev                  0x0014
#define __NR_linux_access                  0x0015
#define __NR_linux_pipe                    0x0016
#define __NR_linux_select                  0x0017
#define __NR_linux_pselect6                0x010e
#define __NR_linux_sched_yield             0x0018
#define __NR_linux_mremap                  0x0019
#define __NR_linux_mincore                 0x001b
#define __NR_linux_madvise                 0x001c
#define __NR_linux_shmget                  0x001d
#define __NR_linux_shmat                   0x001e
#define __NR_linux_shmctl                  0x001f
#define __NR_linux_dup                     0x0020
#define __NR_linux_dup2                    0x0021
#define __NR_linux_pause                   0x0022
#define __NR_linux_nanosleep               0x0023
#define __NR_linux_getitimer               0x0024
#define __NR_linux_setitimer               0x0026
#define __NR_linux_alarm                   0x0025
#define __NR_linux_getpid                  0x0027
#define __NR_linux_sendfile                0x0028
#define __NR_linux_socket                  0x0029
#define __NR_linux_connect                 0x002a
#define __NR_linux_accept                  0x002b
#define __NR_linux_sendto                  0x002c
#define __NR_linux_recvfrom                0x002d
#define __NR_linux_sendmsg                 0x002e
#define __NR_linux_recvmsg                 0x002f
#define __NR_linux_shutdown                0x0030
#define __NR_linux_bind                    0x0031
#define __NR_linux_listen                  0x0032
#define __NR_linux_getsockname             0x0033
#define __NR_linux_getpeername             0x0034
#define __NR_linux_socketpair              0x0035
#define __NR_linux_setsockopt              0x0036
#define __NR_linux_getsockopt              0x0037
#define __NR_linux_fork                    0x0039
#define __NR_linux_vfork                   0x003a
#define __NR_linux_execve                  0x003b
#define __NR_linux_wait4                   0x003d
#define __NR_linux_kill                    0x003e
#define __NR_linux_clone                   0x0038
#define __NR_linux_tkill                   0x00c8
#define __NR_linux_futex                   0x00ca
#define __NR_linux_set_robust_list         0x0111
#define __NR_linux_get_robust_list         0x0112
#define __NR_linux_uname                   0x003f
#define __NR_linux_semget                  0x0040
#define __NR_linux_semop                   0x0041
#define __NR_linux_semctl                  0x0042
#define __NR_linux_shmdt                   0x0043
#define __NR_linux_msgget                  0x0044
#define __NR_linux_msgsnd                  0x0045
#define __NR_linux_msgrcv                  0x0046
#define __NR_linux_msgctl                  0x0047
#define __NR_linux_fcntl                   0x0048
#define __NR_linux_flock                   0x0049
#define __NR_linux_fsync                   0x004a
#define __NR_linux_fdatasync               0x004b
#define __NR_linux_truncate                0x004c
#define __NR_linux_ftruncate               0x004d
#define __NR_linux_getcwd                  0x004f
#define __NR_linux_chdir                   0x0050
#define __NR_linux_fchdir                  0x0051
#define __NR_linux_rename                  0x0052
#define __NR_linux_mkdir                   0x0053
#define __NR_linux_rmdir                   0x0054
#define __NR_linux_creat                   0x0055
#define __NR_linux_link                    0x0056
#define __NR_linux_unlink                  0x0057
#define __NR_linux_symlink                 0x0058
#define __NR_linux_readlink                0x0059
#define __NR_linux_chmod                   0x005a
#define __NR_linux_fchmod                  0x005b
#define __NR_linux_chown                   0x005c
#define __NR_linux_fchown                  0x005d
#define __NR_linux_lchown                  0x005e
#define __NR_linux_umask                   0x005f
#define __NR_linux_gettimeofday            0x0060
#define __NR_linux_getrlimit               0x0061
#define __NR_linux_getrusage               0x0062
#define __NR_linux_sysinfo                 0x0063
#define __NR_linux_times                   0x0064
#define __NR_linux_ptrace                  0x0065
#define __NR_linux_syslog                  0x0067
#define __NR_linux_getuid                  0x0066
#define __NR_linux_getgid                  0x0068
#define __NR_linux_getppid                 0x006e
#define __NR_linux_getpgrp                 0x006f
#define __NR_linux_setsid                  0x0070
#define __NR_linux_getsid                  0x007c
#define __NR_linux_getpgid                 0x0079
#define __NR_linux_setpgid                 0x006d
#define __NR_linux_geteuid                 0x006b
#define __NR_linux_getegid                 0x006c
#define __NR_linux_getgroups               0x0073
#define __NR_linux_setgroups               0x0074
#define __NR_linux_setreuid                0x0071
#define __NR_linux_setregid                0x0072
#define __NR_linux_setuid                  0x0069
#define __NR_linux_setgid                  0x006a
#define __NR_linux_setresuid               0x0075
#define __NR_linux_setresgid               0x0077
#define __NR_linux_getresuid               0x0076
#define __NR_linux_getresgid               0x0078
#define __NR_linux_sigpending              0x007f
#define __NR_linux_sigsuspend              0x0082
#define __NR_linux_sigaltstack             0x0083
#define __NR_linux_mknod                   0x0085
#define __NR_linux_mknodat                 0x0103
#define __NR_linux_statfs                  0x0089
#define __NR_linux_fstatfs                 0x008a
#define __NR_linux_getpriority             0x008c
#define __NR_linux_setpriority             0x008d
#define __NR_linux_mlock                   0x0095
#define __NR_linux_munlock                 0x0096
#define __NR_linux_mlockall                0x0097
#define __NR_linux_munlockall              0x0098
#define __NR_linux_setrlimit               0x00a0
#define __NR_linux_chroot                  0x00a1
#define __NR_linux_sync                    0x00a2
#define __NR_linux_acct                    0x00a3
#define __NR_linux_settimeofday            0x00a4
#define __NR_linux_mount                   0x00a5
#define __NR_linux_reboot                  0x00a9
#define __NR_linux_quotactl                0x00b3
#define __NR_linux_setfsuid                0x007a
#define __NR_linux_setfsgid                0x007b
#define __NR_linux_capget                  0x007d
#define __NR_linux_capset                  0x007e
#define __NR_linux_sigtimedwait            0x0080
#define __NR_linux_sigqueueinfo            0x0081
#define __NR_linux_personality             0x0087
#define __NR_linux_ustat                   0x0088
#define __NR_linux_sysfs                   0x008b
#define __NR_linux_sched_setparam          0x008e
#define __NR_linux_sched_getparam          0x008f
#define __NR_linux_sched_setscheduler      0x0090
#define __NR_linux_sched_getscheduler      0x0091
#define __NR_linux_sched_get_priority_max  0x0092
#define __NR_linux_sched_get_priority_min  0x0093
#define __NR_linux_sched_rr_get_interval   0x0094
#define __NR_linux_vhangup                 0x0099
#define __NR_linux_modify_ldt              0x009a
#define __NR_linux_pivot_root              0x009b
#define __NR_linux__sysctl                 0x009c
#define __NR_linux_prctl                   0x009d
#define __NR_linux_arch_prctl              0x009e
#define __NR_linux_adjtimex                0x009f
#define __NR_linux_umount2                 0x00a6
#define __NR_linux_swapon                  0x00a7
#define __NR_linux_swapoff                 0x00a8
#define __NR_linux_sethostname             0x00aa
#define __NR_linux_setdomainname           0x00ab
#define __NR_linux_iopl                    0x00ac
#define __NR_linux_ioperm                  0x00ad
#define __NR_linux_init_module             0x00af
#define __NR_linux_delete_module           0x00b0
#define __NR_linux_gettid                  0x00ba
#define __NR_linux_readahead               0x00bb
#define __NR_linux_setxattr                0x00bc
#define __NR_linux_fsetxattr               0x00be
#define __NR_linux_getxattr                0x00bf
#define __NR_linux_fgetxattr               0x00c1
#define __NR_linux_listxattr               0x00c2
#define __NR_linux_flistxattr              0x00c4
#define __NR_linux_removexattr             0x00c5
#define __NR_linux_fremovexattr            0x00c7
#define __NR_linux_lsetxattr               0x00bd
#define __NR_linux_lgetxattr               0x00c0
#define __NR_linux_llistxattr              0x00c3
#define __NR_linux_lremovexattr            0x00c6
#define __NR_linux_sched_setaffinity       0x00cb
#define __NR_linux_sched_getaffinity       0x00cc
#define __NR_linux_io_setup                0x00ce
#define __NR_linux_io_destroy              0x00cf
#define __NR_linux_io_getevents            0x00d0
#define __NR_linux_io_submit               0x00d1
#define __NR_linux_io_cancel               0x00d2
#define __NR_linux_lookup_dcookie          0x00d4
#define __NR_linux_epoll_create            0x00d5
#define __NR_linux_epoll_wait              0x00e8
#define __NR_linux_epoll_ctl               0x00e9
#define __NR_linux_getdents                0x00d9
#define __NR_linux_oldgetdents             0x004e
#define __NR_linux_set_tid_address         0x00da
#define __NR_linux_restart_syscall         0x00db
#define __NR_linux_semtimedop              0x00dc
#define __NR_linux_fadvise                 0x00dd
#define __NR_linux_timer_create            0x00de
#define __NR_linux_timer_settime           0x00df
#define __NR_linux_timer_gettime           0x00e0
#define __NR_linux_timer_getoverrun        0x00e1
#define __NR_linux_timer_delete            0x00e2
#define __NR_linux_clock_settime           0x00e3
#define __NR_linux_clock_gettime           0x00e4
#define __NR_linux_clock_getres            0x00e5
#define __NR_linux_clock_nanosleep         0x00e6
#define __NR_linux_tgkill                  0x00ea
#define __NR_linux_mbind                   0x00ed
#define __NR_linux_set_mempolicy           0x00ee
#define __NR_linux_get_mempolicy           0x00ef
#define __NR_linux_mq_open                 0x00f0
#define __NR_linux_mq_unlink               0x00f1
#define __NR_linux_mq_timedsend            0x00f2
#define __NR_linux_mq_timedreceive         0x00f3
#define __NR_linux_mq_notify               0x00f4
#define __NR_linux_mq_getsetattr           0x00f5
#define __NR_linux_kexec_load              0x00f6
#define __NR_linux_waitid                  0x00f7
#define __NR_linux_add_key                 0x00f8
#define __NR_linux_request_key             0x00f9
#define __NR_linux_keyctl                  0x00fa
#define __NR_linux_ioprio_set              0x00fb
#define __NR_linux_ioprio_get              0x00fc
#define __NR_linux_inotify_init            0x00fd
#define __NR_linux_inotify_add_watch       0x00fe
#define __NR_linux_inotify_rm_watch        0x00ff
#define __NR_linux_openat                  0x0101
#define __NR_linux_mkdirat                 0x0102
#define __NR_linux_fchownat                0x0104
#define __NR_linux_utime                   0x0084
#define __NR_linux_utimes                  0x00eb
#define __NR_linux_futimesat               0x0105
#define __NR_linux_fstatat                 0x0106
#define __NR_linux_unlinkat                0x0107
#define __NR_linux_renameat                0x0108
#define __NR_linux_linkat                  0x0109
#define __NR_linux_symlinkat               0x010a
#define __NR_linux_readlinkat              0x010b
#define __NR_linux_fchmodat                0x010c
#define __NR_linux_faccessat               0x010d
#define __NR_linux_unshare                 0x0110
#define __NR_linux_splice                  0x0113
#define __NR_linux_tee                     0x0114
#define __NR_linux_sync_file_range         0x0115
#define __NR_linux_vmsplice                0x0116
#define __NR_linux_migrate_pages           0x0100
#define __NR_linux_move_pages              0x0117
#define __NR_linux_preadv                  0x0127
#define __NR_linux_pwritev                 0x0128
#define __NR_linux_utimensat               0x0118
#define __NR_linux_fallocate               0x011d
#define __NR_linux_accept4                 0x0120
#define __NR_linux_dup3                    0x0124
#define __NR_linux_pipe2                   0x0125
#define __NR_linux_epoll_pwait             0x0119
#define __NR_linux_epoll_create1           0x0123
#define __NR_linux_perf_event_open         0x012a
#define __NR_linux_inotify_init1           0x0126
#define __NR_linux_tgsigqueueinfo          0x0129
#define __NR_linux_signalfd                0x011a
#define __NR_linux_signalfd4               0x0121
#define __NR_linux_eventfd                 0x011c
#define __NR_linux_eventfd2                0x0122
#define __NR_linux_timerfd_create          0x011b
#define __NR_linux_timerfd_settime         0x011e
#define __NR_linux_timerfd_gettime         0x011f
#define __NR_linux_recvmmsg                0x012b
#define __NR_linux_fanotify_init           0x012c
#define __NR_linux_fanotify_mark           0x012d
#define __NR_linux_prlimit                 0x012e
#define __NR_linux_name_to_handle_at       0x012f
#define __NR_linux_open_by_handle_at       0x0130
#define __NR_linux_clock_adjtime           0x0131
#define __NR_linux_syncfs                  0x0132
#define __NR_linux_sendmmsg                0x0133
#define __NR_linux_setns                   0x0134
#define __NR_linux_getcpu                  0x0135
#define __NR_linux_process_vm_readv        0x0136
#define __NR_linux_process_vm_writev       0x0137
#define __NR_linux_kcmp                    0x0138
#define __NR_linux_finit_module            0x0139
#define __NR_linux_sched_setattr           0x013a
#define __NR_linux_sched_getattr           0x013b
#define __NR_linux_renameat2               0x013c
#define __NR_linux_seccomp                 0x013d
#define __NR_linux_getrandom               0x013e
#define __NR_linux_memfd_create            0x013f
#define __NR_linux_kexec_file_load         0x0140
#define __NR_linux_bpf                     0x0141
#define __NR_linux_execveat                0x0142
#define __NR_linux_userfaultfd             0x0143
#define __NR_linux_membarrier              0x0144
#define __NR_linux_mlock2                  0x0145
#define __NR_linux_copy_file_range         0x0146
#define __NR_linux_preadv2                 0x0147
#define __NR_linux_pwritev2                0x0148
#define __NR_linux_pkey_mprotect           0x0149
#define __NR_linux_pkey_alloc              0x014a
#define __NR_linux_pkey_free               0x014b
#define __NR_linux_statx                   0x014c
#define __NR_linux_io_pgetevents           0x014d
#define __NR_linux_rseq                    0x014e
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_quotactl_fd             0x01bb
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be
#define __NR_linux_memfd_secret            0x01bf
#define __NR_linux_process_mrelease        0x01c0
#define __NR_linux_futex_waitv             0x01c1
#define __NR_linux_set_mempolicy_home_node 0x01c2

#elif defined(__aarch64__)

#define __NR_linux_exit                    0x005d
#define __NR_linux_exit_group              0x005e
#define __NR_linux_read                    0x003f
#define __NR_linux_write                   0x0040
#define __NR_linux_open                    0x00b4
#define __NR_linux_close                   0x0039
#define __NR_linux_stat                    0x004f
#define __NR_linux_fstat                   0x0050
#define __NR_linux_ppoll                   0x0049
#define __NR_linux_brk                     0x00d6
#define __NR_linux_sigreturn               0x008b
#define __NR_linux_lseek                   0x003e
#define __NR_linux_mmap                    0x00de
#define __NR_linux_msync                   0x00e3
#define __NR_linux_mprotect                0x00e2
#define __NR_linux_munmap                  0x00d7
#define __NR_linux_sigaction               0x0086
#define __NR_linux_sigprocmask             0x0087
#define __NR_linux_ioctl                   0x001d
#define __NR_linux_pread                   0x0043
#define __NR_linux_pwrite                  0x0044
#define __NR_linux_readv                   0x0041
#define __NR_linux_writev                  0x0042
#define __NR_linux_pselect6                0x0048
#define __NR_linux_sched_yield             0x007c
#define __NR_linux_mremap                  0x00d8
#define __NR_linux_mincore                 0x00e8
#define __NR_linux_madvise                 0x00e9
#define __NR_linux_shmget                  0x00c2
#define __NR_linux_shmat                   0x00c4
#define __NR_linux_shmctl                  0x00c3
#define __NR_linux_dup                     0x0017
#define __NR_linux_nanosleep               0x0065
#define __NR_linux_getitimer               0x0066
#define __NR_linux_setitimer               0x0067
#define __NR_linux_getpid                  0x00ac
#define __NR_linux_sendfile                0x0047
#define __NR_linux_socket                  0x00c6
#define __NR_linux_connect                 0x00cb
#define __NR_linux_accept                  0x00ca
#define __NR_linux_sendto                  0x00ce
#define __NR_linux_recvfrom                0x00cf
#define __NR_linux_sendmsg                 0x00d3
#define __NR_linux_recvmsg                 0x00d4
#define __NR_linux_shutdown                0x00d2
#define __NR_linux_bind                    0x00c8
#define __NR_linux_listen                  0x00c9
#define __NR_linux_getsockname             0x00cc
#define __NR_linux_getpeername             0x00cd
#define __NR_linux_socketpair              0x00c7
#define __NR_linux_setsockopt              0x00d0
#define __NR_linux_getsockopt              0x00d1
#define __NR_linux_execve                  0x00dd
#define __NR_linux_wait4                   0x0104
#define __NR_linux_kill                    0x0081
#define __NR_linux_clone                   0x00dc
#define __NR_linux_tkill                   0x0082
#define __NR_linux_futex                   0x0062
#define __NR_linux_set_robust_list         0x0063
#define __NR_linux_get_robust_list         0x0064
#define __NR_linux_uname                   0x00a0
#define __NR_linux_semget                  0x00be
#define __NR_linux_semop                   0x00c1
#define __NR_linux_semctl                  0x00bf
#define __NR_linux_shmdt                   0x00c5
#define __NR_linux_msgget                  0x00ba
#define __NR_linux_msgsnd                  0x00bd
#define __NR_linux_msgrcv                  0x00bc
#define __NR_linux_msgctl                  0x00bb
#define __NR_linux_fcntl                   0x0019
#define __NR_linux_flock                   0x0020
#define __NR_linux_fsync                   0x0052
#define __NR_linux_fdatasync               0x0053
#define __NR_linux_truncate                0x002d
#define __NR_linux_ftruncate               0x002e
#define __NR_linux_getcwd                  0x0011
#define __NR_linux_chdir                   0x0031
#define __NR_linux_fchdir                  0x0032
#define __NR_linux_unlink                  0x00b5
#define __NR_linux_fchmod                  0x0034
#define __NR_linux_fchown                  0x0037
#define __NR_linux_umask                   0x00a6
#define __NR_linux_gettimeofday            0x00a9
#define __NR_linux_getrlimit               0x00a3
#define __NR_linux_getrusage               0x00a5
#define __NR_linux_sysinfo                 0x00b3
#define __NR_linux_times                   0x0099
#define __NR_linux_ptrace                  0x0075
#define __NR_linux_syslog                  0x0074
#define __NR_linux_getuid                  0x00ae
#define __NR_linux_getgid                  0x00b0
#define __NR_linux_getppid                 0x00ad
#define __NR_linux_setsid                  0x009d
#define __NR_linux_getsid                  0x009c
#define __NR_linux_getpgid                 0x009b
#define __NR_linux_setpgid                 0x009a
#define __NR_linux_geteuid                 0x00af
#define __NR_linux_getegid                 0x00b1
#define __NR_linux_getgroups               0x009e
#define __NR_linux_setgroups               0x009f
#define __NR_linux_setreuid                0x0091
#define __NR_linux_setregid                0x008f
#define __NR_linux_setuid                  0x0092
#define __NR_linux_setgid                  0x0090
#define __NR_linux_setresuid               0x0093
#define __NR_linux_setresgid               0x0095
#define __NR_linux_getresuid               0x0094
#define __NR_linux_getresgid               0x0096
#define __NR_linux_sigpending              0x0088
#define __NR_linux_sigsuspend              0x0085
#define __NR_linux_sigaltstack             0x0084
#define __NR_linux_mknodat                 0x0021
#define __NR_linux_statfs                  0x002b
#define __NR_linux_fstatfs                 0x002c
#define __NR_linux_getpriority             0x008d
#define __NR_linux_setpriority             0x008c
#define __NR_linux_mlock                   0x00e4
#define __NR_linux_munlock                 0x00e5
#define __NR_linux_mlockall                0x00e6
#define __NR_linux_munlockall              0x00e7
#define __NR_linux_setrlimit               0x00a4
#define __NR_linux_chroot                  0x0033
#define __NR_linux_sync                    0x0051
#define __NR_linux_acct                    0x0059
#define __NR_linux_settimeofday            0x00aa
#define __NR_linux_mount                   0x0028
#define __NR_linux_reboot                  0x008e
#define __NR_linux_quotactl                0x003c
#define __NR_linux_setfsuid                0x0097
#define __NR_linux_setfsgid                0x0098
#define __NR_linux_capget                  0x005a
#define __NR_linux_capset                  0x005b
#define __NR_linux_sigtimedwait            0x0089
#define __NR_linux_sigqueueinfo            0x008a
#define __NR_linux_personality             0x005c
#define __NR_linux_sched_setparam          0x0076
#define __NR_linux_sched_getparam          0x0079
#define __NR_linux_sched_setscheduler      0x0077
#define __NR_linux_sched_getscheduler      0x0078
#define __NR_linux_sched_get_priority_max  0x007d
#define __NR_linux_sched_get_priority_min  0x007e
#define __NR_linux_sched_rr_get_interval   0x007f
#define __NR_linux_vhangup                 0x003a
#define __NR_linux_pivot_root              0x0029
#define __NR_linux_prctl                   0x00a7
#define __NR_linux_adjtimex                0x00ab
#define __NR_linux_umount2                 0x0027
#define __NR_linux_swapon                  0x00e0
#define __NR_linux_swapoff                 0x00e1
#define __NR_linux_sethostname             0x00a1
#define __NR_linux_setdomainname           0x00a2
#define __NR_linux_init_module             0x0069
#define __NR_linux_delete_module           0x006a
#define __NR_linux_gettid                  0x00b2
#define __NR_linux_readahead               0x00d5
#define __NR_linux_setxattr                0x0005
#define __NR_linux_fsetxattr               0x0007
#define __NR_linux_getxattr                0x0008
#define __NR_linux_fgetxattr               0x000a
#define __NR_linux_listxattr               0x000b
#define __NR_linux_flistxattr              0x000d
#define __NR_linux_removexattr             0x000e
#define __NR_linux_fremovexattr            0x0010
#define __NR_linux_lsetxattr               0x0006
#define __NR_linux_lgetxattr               0x0009
#define __NR_linux_llistxattr              0x000c
#define __NR_linux_lremovexattr            0x000f
#define __NR_linux_sched_setaffinity       0x007a
#define __NR_linux_sched_getaffinity       0x007b
#define __NR_linux_io_setup                0x0000
#define __NR_linux_io_destroy              0x0001
#define __NR_linux_io_getevents            0x0004
#define __NR_linux_io_submit               0x0002
#define __NR_linux_io_cancel               0x0003
#define __NR_linux_lookup_dcookie          0x0012
#define __NR_linux_epoll_ctl               0x0015
#define __NR_linux_getdents                0x003d
#define __NR_linux_set_tid_address         0x0060
#define __NR_linux_restart_syscall         0x0080
#define __NR_linux_semtimedop              0x00c0
#define __NR_linux_fadvise                 0x00df
#define __NR_linux_timer_create            0x006b
#define __NR_linux_timer_settime           0x006e
#define __NR_linux_timer_gettime           0x006c
#define __NR_linux_timer_getoverrun        0x006d
#define __NR_linux_timer_delete            0x006f
#define __NR_linux_clock_settime           0x0070
#define __NR_linux_clock_gettime           0x0071
#define __NR_linux_clock_getres            0x0072
#define __NR_linux_clock_nanosleep         0x0073
#define __NR_linux_tgkill                  0x0083
#define __NR_linux_mbind                   0x00eb
#define __NR_linux_set_mempolicy           0x00ed
#define __NR_linux_get_mempolicy           0x00ec
#define __NR_linux_mq_open                 0x00b4
#define __NR_linux_mq_unlink               0x00b5
#define __NR_linux_mq_timedsend            0x00b6
#define __NR_linux_mq_timedreceive         0x00b7
#define __NR_linux_mq_notify               0x00b8
#define __NR_linux_mq_getsetattr           0x00b9
#define __NR_linux_kexec_load              0x0068
#define __NR_linux_waitid                  0x005f
#define __NR_linux_add_key                 0x00d9
#define __NR_linux_request_key             0x00da
#define __NR_linux_keyctl                  0x00db
#define __NR_linux_ioprio_set              0x001e
#define __NR_linux_ioprio_get              0x001f
#define __NR_linux_openat                  0x0038
#define __NR_linux_mkdirat                 0x0022
#define __NR_linux_fchownat                0x0036
#define __NR_linux_utime                   0x0062
#define __NR_linux_utimes                  0x0058
#define __NR_linux_fstatat                 0x004f
#define __NR_linux_unlinkat                0x0023
#define __NR_linux_renameat                0x0026
#define __NR_linux_linkat                  0x0025
#define __NR_linux_symlinkat               0x0024
#define __NR_linux_readlinkat              0x004e
#define __NR_linux_fchmodat                0x0035
#define __NR_linux_faccessat               0x0030
#define __NR_linux_unshare                 0x0061
#define __NR_linux_splice                  0x004c
#define __NR_linux_tee                     0x004d
#define __NR_linux_sync_file_range         0x0054
#define __NR_linux_vmsplice                0x004b
#define __NR_linux_migrate_pages           0x00ee
#define __NR_linux_move_pages              0x00ef
#define __NR_linux_preadv                  0x0045
#define __NR_linux_pwritev                 0x0046
#define __NR_linux_utimensat               0x0058
#define __NR_linux_fallocate               0x002f
#define __NR_linux_accept4                 0x00f2
#define __NR_linux_dup3                    0x0018
#define __NR_linux_pipe2                   0x003b
#define __NR_linux_epoll_pwait             0x0016
#define __NR_linux_epoll_create1           0x0014
#define __NR_linux_perf_event_open         0x00f1
#define __NR_linux_inotify_init1           0x001a
#define __NR_linux_tgsigqueueinfo          0x00f0
#define __NR_linux_signalfd4               0x004a
#define __NR_linux_eventfd2                0x0013
#define __NR_linux_timerfd_create          0x0055
#define __NR_linux_timerfd_settime         0x0056
#define __NR_linux_timerfd_gettime         0x0057
#define __NR_linux_recvmmsg                0x00f3
#define __NR_linux_fanotify_init           0x0106
#define __NR_linux_fanotify_mark           0x0107
#define __NR_linux_prlimit                 0x0105
#define __NR_linux_name_to_handle_at       0x0108
#define __NR_linux_open_by_handle_at       0x0109
#define __NR_linux_clock_adjtime           0x010a
#define __NR_linux_syncfs                  0x010b
#define __NR_linux_sendmmsg                0x010d
#define __NR_linux_setns                   0x010c
#define __NR_linux_getcpu                  0x00a8
#define __NR_linux_process_vm_readv        0x010e
#define __NR_linux_process_vm_writev       0x010f
#define __NR_linux_kcmp                    0x0110
#define __NR_linux_finit_module            0x0111
#define __NR_linux_sched_setattr           0x0112
#define __NR_linux_sched_getattr           0x0113
#define __NR_linux_renameat2               0x0114
#define __NR_linux_seccomp                 0x0115
#define __NR_linux_getrandom               0x0116
#define __NR_linux_memfd_create            0x0117
#define __NR_linux_bpf                     0x0118
#define __NR_linux_execveat                0x0119
#define __NR_linux_userfaultfd             0x011a
#define __NR_linux_membarrier              0x011b
#define __NR_linux_mlock2                  0x011c
#define __NR_linux_copy_file_range         0x011d
#define __NR_linux_preadv2                 0x011e
#define __NR_linux_pwritev2                0x011f
#define __NR_linux_pkey_mprotect           0x0120
#define __NR_linux_pkey_alloc              0x0121
#define __NR_linux_pkey_free               0x0122
#define __NR_linux_statx                   0x0123
#define __NR_linux_io_pgetevents           0x0124
#define __NR_linux_rseq                    0x0125
#define __NR_linux_kexec_file_load         0x0126
#define __NR_linux_pidfd_send_signal       0x01a8
#define __NR_linux_io_uring_setup          0x01a9
#define __NR_linux_io_uring_enter          0x01aa
#define __NR_linux_io_uring_register       0x01ab
#define __NR_linux_open_tree               0x01ac
#define __NR_linux_move_mount              0x01ad
#define __NR_linux_fsopen                  0x01ae
#define __NR_linux_fsconfig                0x01af
#define __NR_linux_fsmount                 0x01b0
#define __NR_linux_fspick                  0x01b1
#define __NR_linux_pidfd_open              0x01b2
#define __NR_linux_clone3                  0x01b3
#define __NR_linux_close_range             0x01b4
#define __NR_linux_openat2                 0x01b5
#define __NR_linux_pidfd_getfd             0x01b6
#define __NR_linux_faccessat2              0x01b7
#define __NR_linux_process_madvise         0x01b8
#define __NR_linux_epoll_pwait2            0x01b9
#define __NR_linux_mount_setattr           0x01ba
#define __NR_linux_landlock_create_ruleset 0x01bc
#define __NR_linux_landlock_add_rule       0x01bd
#define __NR_linux_landlock_restrict_self  0x01be

#endif /* __x86_64__ */

#endif /* _COSMO_SOURCE */


/*!BEGIN libc/sysv/consts/ok.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_OK_H_

#define F_OK 0
#define X_OK X_OK
#define W_OK W_OK
#define R_OK R_OK

COSMOPOLITAN_C_START_

extern const int X_OK;
extern const int W_OK;
extern const unsigned R_OK; /* warning: is sign bit on windows */

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/personality.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PERSONALITY_H_

#define ADDR_COMPAT_LAYOUT 0x0200000
#define READ_IMPLIES_EXEC  0x0400000
#define ADDR_LIMIT_3GB     0x8000000
#define FDPIC_FUNCPTRS     0x0080000
#define STICKY_TIMEOUTS    0x4000000
#define MMAP_PAGE_ZERO     0x0100000
#define ADDR_LIMIT_32BIT   0x0800000
#define WHOLE_SECONDS      0x2000000
#define ADDR_NO_RANDOMIZE  0x0040000
#define SHORT_INODE        0x1000000
#define UNAME26            0x0020000



/*!BEGIN libc/sysv/consts/pf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PF_H_
COSMOPOLITAN_C_START_

extern const int PF_ALG;
extern const int PF_APPLETALK;
extern const int PF_ASH;
extern const int PF_ATMPVC;
extern const int PF_ATMSVC;
extern const int PF_AX25;
extern const int PF_BLUETOOTH;
extern const int PF_BRIDGE;
extern const int PF_CAIF;
extern const int PF_CAN;
extern const int PF_ECONET;
extern const int PF_FILE;
extern const int PF_IB;
extern const int PF_IEEE802154;
extern const int PF_INET6;
extern const int PF_INET;
extern const int PF_IPX;
extern const int PF_IRDA;
extern const int PF_ISDN;
extern const int PF_IUCV;
extern const int PF_KCM;
extern const int PF_KEY;
extern const int PF_LLC;
extern const int PF_LOCAL;
extern const int PF_MAX;
extern const int PF_MPLS;
extern const int PF_NETBEUI;
extern const int PF_NETLINK;
extern const int PF_NETROM;
extern const int PF_NFC;
extern const int PF_PACKET;
extern const int PF_PHONET;
extern const int PF_PPPOX;
extern const int PF_RDS;
extern const int PF_ROSE;
extern const int PF_ROUTE;
extern const int PF_RXRPC;
extern const int PF_SECURITY;
extern const int PF_SNA;
extern const int PF_TIPC;
extern const int PF_UNIX;
extern const int PF_UNSPEC;
extern const int PF_VSOCK;
extern const int PF_WANPIPE;
extern const int PF_X25;

#define PF_ALG        PF_ALG
#define PF_APPLETALK  PF_APPLETALK
#define PF_ASH        PF_ASH
#define PF_ATMPVC     PF_ATMPVC
#define PF_ATMSVC     PF_ATMSVC
#define PF_AX25       PF_AX25
#define PF_BLUETOOTH  PF_BLUETOOTH
#define PF_BRIDGE     PF_BRIDGE
#define PF_CAIF       PF_CAIF
#define PF_CAN        PF_CAN
#define PF_ECONET     PF_ECONET
#define PF_FILE       PF_FILE
#define PF_IB         PF_IB
#define PF_IEEE802154 PF_IEEE802154
#define PF_INET       PF_INET
#define PF_INET6      PF_INET6
#define PF_IPX        PF_IPX
#define PF_IRDA       PF_IRDA
#define PF_ISDN       PF_ISDN
#define PF_IUCV       PF_IUCV
#define PF_KCM        PF_KCM
#define PF_KEY        PF_KEY
#define PF_LLC        PF_LLC
#define PF_LOCAL      PF_LOCAL
#define PF_MAX        PF_MAX
#define PF_MPLS       PF_MPLS
#define PF_NETBEUI    PF_NETBEUI
#define PF_NETLINK    PF_NETLINK
#define PF_NETROM     PF_NETROM
#define PF_NFC        PF_NFC
#define PF_PACKET     PF_PACKET
#define PF_PHONET     PF_PHONET
#define PF_PPPOX      PF_PPPOX
#define PF_RDS        PF_RDS
#define PF_ROSE       PF_ROSE
#define PF_ROUTE      PF_ROUTE
#define PF_RXRPC      PF_RXRPC
#define PF_SECURITY   PF_SECURITY
#define PF_SNA        PF_SNA
#define PF_TIPC       PF_TIPC
#define PF_UNIX       PF_UNIX
#define PF_UNSPEC     PF_UNSPEC
#define PF_VSOCK      PF_VSOCK
#define PF_WANPIPE    PF_WANPIPE
#define PF_X25        PF_X25


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/poll.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POLL_H_
COSMOPOLITAN_C_START_

extern const int16_t POLLERR;
extern const int16_t POLLHUP;
extern const int16_t POLLIN;
extern const int16_t POLLNVAL;
extern const int16_t POLLOUT;
extern const int16_t POLLPRI;
extern const int16_t POLLRDBAND;
extern const int16_t POLLRDHUP;
extern const int16_t POLLRDNORM;
extern const int16_t POLLWRBAND;
extern const int16_t POLLWRNORM;

#define INFTIM     (-1)
#define POLLERR    POLLERR
#define POLLHUP    POLLHUP
#define POLLIN     POLLIN
#define POLLNVAL   POLLNVAL
#define POLLOUT    POLLOUT
#define POLLPRI    POLLPRI
#define POLLRDBAND POLLRDBAND
#define POLLRDHUP  POLLRDHUP
#define POLLRDNORM POLLRDNORM
#define POLLWRBAND POLLWRBAND
#define POLLWRNORM POLLWRNORM


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/posix.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_POSIX_H_
COSMOPOLITAN_C_START_

extern const int POSIX_FADV_DONTNEED;
extern const int POSIX_FADV_NOREUSE;
extern const int POSIX_MADV_DONTNEED;
extern const int POSIX_MADV_DONTNEED;

#define POSIX_FADV_NORMAL     0
#define POSIX_FADV_RANDOM     1
#define POSIX_FADV_SEQUENTIAL 2
#define POSIX_FADV_WILLNEED   3

#define POSIX_FADV_DONTNEED POSIX_FADV_DONTNEED
#define POSIX_FADV_NOREUSE  POSIX_FADV_NOREUSE

#define POSIX_MADV_NORMAL     0
#define POSIX_MADV_RANDOM     1
#define POSIX_MADV_SEQUENTIAL 2
#define POSIX_MADV_WILLNEED   3

#define POSIX_MADV_DONTNEED POSIX_MADV_DONTNEED


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/pr.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PR_H_

#define PR_GET_SECCOMP        21
#define PR_SET_SECCOMP        22
#define SECCOMP_MODE_DISABLED 0
#define SECCOMP_MODE_STRICT   1
#define SECCOMP_MODE_FILTER   2

#define PR_CAPBSET_READ 23
#define PR_CAPBSET_DROP 24

#define PR_SET_NO_NEW_PRIVS 38
#define PR_GET_NO_NEW_PRIVS 39

#define PR_SET_NAME 15
#define PR_GET_NAME 16

#define PR_GET_TSC     25
#define PR_SET_TSC     26
#define PR_TSC_ENABLE  1
#define PR_TSC_SIGSEGV 2

#define PR_GET_FPEXC        11
#define PR_SET_FPEXC        12
#define PR_FP_EXC_SW_ENABLE 0x80
#define PR_FP_EXC_DIV       0x010000
#define PR_FP_EXC_OVF       0x020000
#define PR_FP_EXC_UND       0x040000
#define PR_FP_EXC_RES       0x080000
#define PR_FP_EXC_INV       0x100000
#define PR_FP_EXC_DISABLED  0
#define PR_FP_EXC_NONRECOV  1
#define PR_FP_EXC_ASYNC     2
#define PR_FP_EXC_PRECISE   3

#define PR_MCE_KILL_CLEAR           0
#define PR_MCE_KILL_LATE            0
#define PR_SPEC_NOT_AFFECTED        0
#define PR_SPEC_STORE_BYPASS        0
#define PR_CAP_AMBIENT_IS_SET       1
#define PR_FPEMU_NOPRINT            1
#define PR_MCE_KILL_EARLY           1
#define PR_MCE_KILL_SET             1
#define PR_SET_MM_START_CODE        1
#define PR_SET_PDEATHSIG            1
#define PR_SPEC_PRCTL               1
#define PR_CAP_AMBIENT_RAISE        2
#define PR_FPEMU_SIGFPE             2
#define PR_GET_PDEATHSIG            2
#define PR_MCE_KILL_DEFAULT         2
#define PR_SET_MM_END_CODE          2
#define PR_SPEC_ENABLE              2
#define PR_CAP_AMBIENT_LOWER        3
#define PR_GET_DUMPABLE             3
#define PR_SET_MM_START_DATA        3
#define PR_CAP_AMBIENT_CLEAR_ALL    4
#define PR_SET_DUMPABLE             4
#define PR_SET_MM_END_DATA          4
#define PR_SPEC_DISABLE             4
#define PR_SET_MM_START_STACK       5
#define PR_SET_MM_START_BRK         6
#define PR_GET_KEEPCAPS             7
#define PR_SET_MM_BRK               7
#define PR_SET_KEEPCAPS             8
#define PR_SET_MM_ARG_START         8
#define PR_SPEC_FORCE_DISABLE       8
#define PR_GET_FPEMU                9
#define PR_SET_MM_ARG_END           9
#define PR_SET_FPEMU                10
#define PR_SET_MM_ENV_START         10
#define PR_GET_FPEXC                11
#define PR_SET_MM_ENV_END           11
#define PR_SET_FPEXC                12
#define PR_SET_MM_AUXV              12
#define PR_SET_MM_EXE_FILE          13
#define PR_SET_MM_MAP               14
#define PR_SET_MM_MAP_SIZE          15
#define PR_GET_TSC                  25
#define PR_SET_TSC                  26
#define PR_GET_SECUREBITS           27
#define PR_SET_SECUREBITS           28
#define PR_SET_TIMERSLACK           29
#define PR_GET_TIMERSLACK           30
#define PR_TASK_PERF_EVENTS_DISABLE 31
#define PR_TASK_PERF_EVENTS_ENABLE  0x20
#define PR_MCE_KILL                 33
#define PR_MCE_KILL_GET             34
#define PR_SET_MM                   35
#define PR_SET_CHILD_SUBREAPER      36
#define PR_GET_CHILD_SUBREAPER      37
#define PR_GET_TID_ADDRESS          40
#define PR_SET_THP_DISABLE          41
#define PR_GET_THP_DISABLE          42
#define PR_MPX_ENABLE_MANAGEMENT    43
#define PR_MPX_DISABLE_MANAGEMENT   44
#define PR_CAP_AMBIENT              47
#define PR_GET_SPECULATION_CTRL     52
#define PR_SET_SPECULATION_CTRL     53
#define PR_SET_TAGGED_ADDR_CTRL     55
#define PR_GET_TAGGED_ADDR_CTRL     56
#define PR_SET_IO_FLUSHER           57
#define PR_GET_IO_FLUSHER           58
#define PR_SET_PTRACER              0x59616d61
#define PR_SET_PTRACER_ANY          -1
#define PR_SET_VMA                  0x53564d41
#define PR_SET_VMA_ANON_NAME        0



/*!BEGIN libc/sysv/consts/prio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PRIO_H_
COSMOPOLITAN_C_START_

extern const int PRIO_MAX;
extern const int PRIO_MIN;
extern const int PRIO_PGRP;
extern const int PRIO_PROCESS;
extern const int PRIO_USER;

#define PRIO_PROCESS 0
#define PRIO_PGRP    1
#define PRIO_USER    2
#define PRIO_MIN     -20
#define PRIO_MAX     20

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/prot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PROT_H_
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

extern const int PROT_NONE;
extern const int PROT_READ;
extern const int PROT_WRITE;
extern const int PROT_EXEC;
extern const int PROT_GROWSDOWN;
extern const int PROT_GROWSUP;

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */

#define PROT_NONE  0
#define PROT_READ  1
#define PROT_WRITE 2
#define PROT_EXEC  4



/*!BEGIN libc/sysv/consts/pt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PT_H_


/*!BEGIN libc/sysv/consts/ptrace.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTRACE_H_
COSMOPOLITAN_C_START_

extern const int PTRACE_TRACEME;
extern const int PTRACE_PEEKTEXT;
extern const int PTRACE_PEEKDATA;
extern const int PTRACE_PEEKUSER;
extern const int PTRACE_POKETEXT;
extern const int PTRACE_POKEDATA;
extern const int PTRACE_POKEUSER;
extern const int PTRACE_CONT;
extern const int PTRACE_KILL;
extern const int PTRACE_SINGLESTEP;
extern const int PTRACE_GETREGS;
extern const int PTRACE_SETREGS;
extern const int PTRACE_GETFPREGS;
extern const int PTRACE_SETFPREGS;
extern const int PTRACE_ATTACH;
extern const int PTRACE_DETACH;
extern const int PTRACE_GETFPXREGS;
extern const int PTRACE_SETFPXREGS;
extern const int PTRACE_SYSCALL;
extern const int PTRACE_GETEVENTMSG;
extern const int PTRACE_GETSIGINFO;
extern const int PTRACE_SETOPTIONS;
extern const int PTRACE_SETSIGINFO;
extern const int PTRACE_GETREGSET;
extern const int PTRACE_GETSIGMASK;
extern const int PTRACE_INTERRUPT;
extern const int PTRACE_LISTEN;
extern const int PTRACE_PEEKSIGINFO;
extern const int PTRACE_SECCOMP_GET_FILTER;
extern const int PTRACE_SECCOMP_GET_METADATA;
extern const int PTRACE_SEIZE;
extern const int PTRACE_SETREGSET;
extern const int PTRACE_SETSIGMASK;
extern const int PTRACE_O_TRACESYSGOOD;
extern const int PTRACE_O_TRACEFORK;
extern const int PTRACE_O_TRACEVFORK;
extern const int PTRACE_O_TRACECLONE;
extern const int PTRACE_O_TRACEEXEC;
extern const int PTRACE_O_TRACEVFORKDONE;
extern const int PTRACE_O_TRACEEXIT;
extern const int PTRACE_O_TRACESECCOMP;
extern const int PTRACE_O_MASK;
extern const int PTRACE_EVENT_FORK;
extern const int PTRACE_EVENT_VFORK;
extern const int PTRACE_EVENT_CLONE;
extern const int PTRACE_EVENT_EXEC;
extern const int PTRACE_EVENT_VFORK_DONE;
extern const int PTRACE_EVENT_EXIT;
extern const int PTRACE_EVENT_STOP;
extern const int PTRACE_EVENT_SECCOMP;

COSMOPOLITAN_C_END_

#define PTRACE_TRACEME              PTRACE_TRACEME
#define PTRACE_PEEKTEXT             PTRACE_PEEKTEXT
#define PTRACE_PEEKDATA             PTRACE_PEEKDATA
#define PTRACE_PEEKUSER             PTRACE_PEEKUSER
#define PTRACE_POKETEXT             PTRACE_POKETEXT
#define PTRACE_POKEDATA             PTRACE_POKEDATA
#define PTRACE_POKEUSER             PTRACE_POKEUSER
#define PTRACE_CONT                 PTRACE_CONT
#define PTRACE_KILL                 PTRACE_KILL
#define PTRACE_SINGLESTEP           PTRACE_SINGLESTEP
#define PTRACE_GETREGS              PTRACE_GETREGS
#define PTRACE_SETREGS              PTRACE_SETREGS
#define PTRACE_GETFPREGS            PTRACE_GETFPREGS
#define PTRACE_SETFPREGS            PTRACE_SETFPREGS
#define PTRACE_ATTACH               PTRACE_ATTACH
#define PTRACE_DETACH               PTRACE_DETACH
#define PTRACE_GETFPXREGS           PTRACE_GETFPXREGS
#define PTRACE_SETFPXREGS           PTRACE_SETFPXREGS
#define PTRACE_SYSCALL              PTRACE_SYSCALL
#define PTRACE_GETEVENTMSG          PTRACE_GETEVENTMSG
#define PTRACE_GETSIGINFO           PTRACE_GETSIGINFO
#define PTRACE_SETOPTIONS           PTRACE_SETOPTIONS
#define PTRACE_SETSIGINFO           PTRACE_SETSIGINFO
#define PTRACE_GETREGSET            PTRACE_GETREGSET
#define PTRACE_GETSIGMASK           PTRACE_GETSIGMASK
#define PTRACE_INTERRUPT            PTRACE_INTERRUPT
#define PTRACE_LISTEN               PTRACE_LISTEN
#define PTRACE_PEEKSIGINFO          PTRACE_PEEKSIGINFO
#define PTRACE_SECCOMP_GET_FILTER   PTRACE_SECCOMP_GET_FILTER
#define PTRACE_SECCOMP_GET_METADATA PTRACE_SECCOMP_GET_METADATA
#define PTRACE_SEIZE                PTRACE_SEIZE
#define PTRACE_SETREGSET            PTRACE_SETREGSET
#define PTRACE_SETSIGMASK           PTRACE_SETSIGMASK
#define PTRACE_O_TRACESYSGOOD       PTRACE_O_TRACESYSGOOD
#define PTRACE_O_TRACEFORK          PTRACE_O_TRACEFORK
#define PTRACE_O_TRACEVFORK         PTRACE_O_TRACEVFORK
#define PTRACE_O_TRACECLONE         PTRACE_O_TRACECLONE
#define PTRACE_O_TRACEEXEC          PTRACE_O_TRACEEXEC
#define PTRACE_O_TRACEVFORKDONE     PTRACE_O_TRACEVFORKDONE
#define PTRACE_O_TRACEEXIT          PTRACE_O_TRACEEXIT
#define PTRACE_O_TRACESECCOMP       PTRACE_O_TRACESECCOMP
#define PTRACE_O_MASK               PTRACE_O_MASK
#define PTRACE_EVENT_FORK           PTRACE_EVENT_FORK
#define PTRACE_EVENT_VFORK          PTRACE_EVENT_VFORK
#define PTRACE_EVENT_CLONE          PTRACE_EVENT_CLONE
#define PTRACE_EVENT_EXEC           PTRACE_EVENT_EXEC
#define PTRACE_EVENT_VFORK_DONE     PTRACE_EVENT_VFORK_DONE
#define PTRACE_EVENT_EXIT           PTRACE_EVENT_EXIT
#define PTRACE_EVENT_STOP           PTRACE_EVENT_STOP
#define PTRACE_EVENT_SECCOMP        PTRACE_EVENT_SECCOMP


#define PT_ATTACH      PTRACE_ATTACH
#define PT_CONTINUE    PTRACE_CONT
#define PT_DETACH      PTRACE_DETACH
#define PT_GETEVENTMSG PTRACE_GETEVENTMSG
#define PT_GETFPREGS   PTRACE_GETFPREGS
#define PT_GETFPXREGS  PTRACE_GETFPXREGS
#define PT_GETREGS     PTRACE_GETREGS
#define PT_GETSIGINFO  PTRACE_GETSIGINFO
#define PT_KILL        PTRACE_KILL
#define PT_READ_D      PTRACE_PEEKDATA
#define PT_READ_I      PTRACE_PEEKTEXT
#define PT_READ_U      PTRACE_PEEKUSER
#define PT_SETFPREGS   PTRACE_SETFPREGS
#define PT_SETFPXREGS  PTRACE_SETFPXREGS
#define PT_SETOPTIONS  PTRACE_SETOPTIONS
#define PT_SETREGS     PTRACE_SETREGS
#define PT_SETSIGINFO  PTRACE_SETSIGINFO
#define PT_STEP        PTRACE_SINGLESTEP
#define PT_SYSCALL     PTRACE_SYSCALL
#define PT_WRITE_D     PTRACE_POKEDATA
#define PT_WRITE_I     PTRACE_POKETEXT
#define PT_WRITE_U     PTRACE_POKEUSER



/*!BEGIN libc/sysv/consts/pty.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_PTY_H_
COSMOPOLITAN_C_START_

extern const int TIOCPKT;
extern const int TIOCPKT_DATA;
extern const int TIOCPKT_DOSTOP;
extern const int TIOCPKT_FLUSHREAD;
extern const int TIOCPKT_FLUSHWRITE;
extern const int TIOCPKT_IOCTL;
extern const int TIOCPKT_NOSTOP;
extern const int TIOCPKT_START;
extern const int TIOCPKT_STOP;

#define TIOCPKT_DATA       0x00
#define TIOCPKT_DOSTOP     0x01
#define TIOCPKT_FLUSHREAD  0x02
#define TIOCPKT_FLUSHWRITE 0x04
#define TIOCPKT_IOCTL      0x08
#define TIOCPKT_NOSTOP     0x10
#define TIOCPKT_START      0x20
#define TIOCPKT_STOP       0x40

#define TIOCPKT TIOCPKT


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/read.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_READ_H_

#define READ_10 READ_10
#define READ_12 READ_12
#define READ_6 READ_6
#define READ_BLOCK_LIMITS READ_BLOCK_LIMITS
#define READ_BUFFER READ_BUFFER
#define READ_CAPACITY READ_CAPACITY
#define READ_DEFECT_DATA READ_DEFECT_DATA
#define READ_ELEMENT_STATUS READ_ELEMENT_STATUS
#define READ_LONG READ_LONG
#define READ_POSITION READ_POSITION
#define READ_REVERSE READ_REVERSE
#define READ_TOC READ_TOC

COSMOPOLITAN_C_START_

extern const long READ_10;
extern const long READ_12;
extern const long READ_6;
extern const long READ_BLOCK_LIMITS;
extern const long READ_BUFFER;
extern const long READ_CAPACITY;
extern const long READ_DEFECT_DATA;
extern const long READ_ELEMENT_STATUS;
extern const long READ_LONG;
extern const long READ_POSITION;
extern const long READ_REVERSE;
extern const long READ_TOC;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/reboot.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_REBOOT_H_
COSMOPOLITAN_C_START_

extern const unsigned RB_AUTOBOOT;
extern const unsigned RB_POWER_OFF;
extern const unsigned RB_POWERDOWN;
extern const unsigned RB_POWEROFF;
extern const unsigned RB_HALT_SYSTEM;
extern const unsigned RB_HALT;
extern const unsigned RB_SW_SUSPEND;
extern const unsigned RB_KEXEC;
extern const unsigned RB_ENABLE_CAD;
extern const unsigned RB_DISABLE_CAD;
extern const unsigned RB_NOSYNC;

#define RB_AUTOBOOT    RB_AUTOBOOT
#define RB_POWER_OFF   RB_POWER_OFF
#define RB_POWERDOWN   RB_POWERDOWN
#define RB_POWEROFF    RB_POWEROFF
#define RB_HALT_SYSTEM RB_HALT_SYSTEM
#define RB_HALT        RB_HALT
#define RB_SW_SUSPEND  RB_SW_SUSPEND
#define RB_KEXEC       RB_KEXEC
#define RB_ENABLE_CAD  RB_ENABLE_CAD
#define RB_DISABLE_CAD RB_DISABLE_CAD
#define RB_NOSYNC      RB_NOSYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlim.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIM_H_
COSMOPOLITAN_C_START_

extern const uint64_t RLIM_INFINITY;
extern const uint64_t RLIM_NLIMITS;
extern const uint64_t RLIM_SAVED_CUR;
extern const uint64_t RLIM_SAVED_MAX;

#define RLIM_INFINITY  RLIM_INFINITY
#define RLIM_NLIMITS   RLIM_NLIMITS
#define RLIM_SAVED_CUR RLIM_SAVED_CUR
#define RLIM_SAVED_MAX RLIM_SAVED_MAX


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rlimit.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RLIMIT_H_
COSMOPOLITAN_C_START_

extern const unsigned RLIMIT_AS;
extern const unsigned RLIMIT_CORE;
extern const unsigned RLIMIT_CPU;
extern const unsigned RLIMIT_DATA;
extern const unsigned RLIMIT_FSIZE;
extern const unsigned RLIMIT_LOCKS;
extern const unsigned RLIMIT_MEMLOCK;
extern const unsigned RLIMIT_MSGQUEUE;
extern const unsigned RLIMIT_NICE;
extern const unsigned RLIMIT_NOFILE;
extern const unsigned RLIMIT_NPROC;
extern const unsigned RLIMIT_NPTS;
extern const unsigned RLIMIT_RSS;
extern const unsigned RLIMIT_RTPRIO;
extern const unsigned RLIMIT_RTTIME;
extern const unsigned RLIMIT_SBSIZE;
extern const unsigned RLIMIT_SIGPENDING;
extern const unsigned RLIMIT_STACK;
extern const unsigned RLIMIT_SWAP;
extern const unsigned RLIMIT_VMEM;

#define RLIMIT_AS         RLIMIT_AS
#define RLIMIT_CORE       RLIMIT_CORE
#define RLIMIT_CPU        RLIMIT_CPU
#define RLIMIT_DATA       RLIMIT_DATA
#define RLIMIT_FSIZE      RLIMIT_FSIZE
#define RLIMIT_LOCKS      RLIMIT_LOCKS
#define RLIMIT_MEMLOCK    RLIMIT_MEMLOCK
#define RLIMIT_MSGQUEUE   RLIMIT_MSGQUEUE
#define RLIMIT_NICE       RLIMIT_NICE
#define RLIMIT_NOFILE     RLIMIT_NOFILE
#define RLIMIT_NPROC      RLIMIT_NPROC
#define RLIMIT_NPTS       RLIMIT_NPTS
#define RLIMIT_RSS        RLIMIT_RSS
#define RLIMIT_RTPRIO     RLIMIT_RTPRIO
#define RLIMIT_RTTIME     RLIMIT_RTTIME
#define RLIMIT_SBSIZE     RLIMIT_SBSIZE
#define RLIMIT_SIGPENDING RLIMIT_SIGPENDING
#define RLIMIT_STACK      RLIMIT_STACK
#define RLIMIT_SWAP       RLIMIT_SWAP
#define RLIMIT_VMEM       RLIMIT_VMEM

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/rusage.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_RUSAGE_H_
COSMOPOLITAN_C_START_

extern const int RUSAGE_THREAD;
extern const int RUSAGE_CHILDREN;
extern const int RUSAGE_BOTH;

#define RUSAGE_SELF     0
#define RUSAGE_CHILDREN RUSAGE_CHILDREN

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/s.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_S_H_

#define S_IFIFO  0010000 /* pipe */
#define S_IFCHR  0020000 /* character device */
#define S_IFDIR  0040000 /* directory */
#define S_IFBLK  0060000 /* block device */
#define S_IFREG  0100000 /* regular file */
#define S_IFLNK  0120000 /* symbolic link */
#define S_IFSOCK 0140000 /* socket */
#define S_IFMT   0170000 /* mask of file types above */

#define S_ISVTX  0001000 /* THE STICKY BIT */
#define S_ISGID  0002000 /* the setgid bit */
#define S_ISUID  0004000 /* the setuid bit */
#define S_IXUSR  0000100 /* user  --x; just use octal */
#define S_IWUSR  0000200 /* user  -w-; just use octal */
#define S_IRUSR  0000400 /* user  r--; just use octal */
#define S_IRWXU  0000700 /* user  rwx; just use octal */
#define S_IXGRP  0000010 /* group --x; just use octal */
#define S_IWGRP  0000020 /* group -w-; just use octal */
#define S_IRGRP  0000040 /* group r--; just use octal */
#define S_IRWXG  0000070 /* group rwx; just use octal */
#define S_IXOTH  0000001 /* other --x; just use octal */
#define S_IWOTH  0000002 /* other -w-; just use octal */
#define S_IROTH  0000004 /* other r--; just use octal */
#define S_IRWXO  0000007 /* other rwx; just use octal */
#define S_IREAD  0000400 /* just use octal */
#define S_IEXEC  0000100 /* just use octal */
#define S_IWRITE 0000200 /* just use octal */
#define S_ISTXT  0001000 /* just use octal */

#define S_ISDIR(mode)  (((mode)&S_IFMT) == S_IFDIR)
#define S_ISCHR(mode)  (((mode)&S_IFMT) == S_IFCHR)
#define S_ISBLK(mode)  (((mode)&S_IFMT) == S_IFBLK)
#define S_ISREG(mode)  (((mode)&S_IFMT) == S_IFREG)
#define S_ISFIFO(mode) (((mode)&S_IFMT) == S_IFIFO)
#define S_ISLNK(mode)  (((mode)&S_IFMT) == S_IFLNK)
#define S_ISSOCK(mode) (((mode)&S_IFMT) == S_IFSOCK)

#define S_BLKSIZE   512
#define ALLPERMS    (S_ISUID | S_ISGID | S_ISTXT | S_IRWXU | S_IRWXG | S_IRWXO)
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)



/*!BEGIN libc/sysv/consts/sa.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SA_H_
COSMOPOLITAN_C_START_

extern const uint64_t SA_NOCLDSTOP;
extern const uint64_t SA_NOCLDWAIT;
extern const uint64_t SA_NODEFER;
extern const uint64_t SA_NOMASK;
extern const uint64_t SA_ONESHOT;
extern const uint64_t SA_ONSTACK;
extern const uint64_t SA_RESETHAND;
extern const uint64_t SA_RESTART;
extern const uint64_t SA_SIGINFO;

#define SA_NOCLDSTOP SA_NOCLDSTOP
#define SA_NOCLDWAIT SA_NOCLDWAIT
#define SA_NODEFER   SA_NODEFER
#define SA_NOMASK    SA_NOMASK
#define SA_ONESHOT   SA_ONESHOT
#define SA_ONSTACK   SA_ONSTACK
#define SA_RESETHAND SA_RESETHAND
#define SA_RESTART   SA_RESTART
#define SA_SIGINFO   SA_SIGINFO


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sched.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCHED_H_
COSMOPOLITAN_C_START_

extern const int SCHED_BATCH;
extern const int SCHED_DEADLINE;
extern const int SCHED_FIFO;
extern const int SCHED_IDLE;
extern const int SCHED_OTHER;
extern const int SCHED_RESET_ON_FORK;
extern const int SCHED_RR;

#define SCHED_BATCH         SCHED_BATCH
#define SCHED_DEADLINE      SCHED_DEADLINE
#define SCHED_FIFO          SCHED_FIFO
#define SCHED_IDLE          SCHED_IDLE
#define SCHED_NORMAL        SCHED_OTHER
#define SCHED_OTHER         SCHED_OTHER
#define SCHED_RESET_ON_FORK SCHED_RESET_ON_FORK
#define SCHED_RR            SCHED_RR


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/scm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SCM_H_
COSMOPOLITAN_C_START_

extern const int SCM_TIMESTAMP;
extern const int SCM_CREDENTIALS;
extern const int SCM_TIMESTAMPING;
extern const int SCM_TIMESTAMPNS;
extern const int SCM_WIFI_STATUS;

COSMOPOLITAN_C_END_

#define SCM_RIGHTS       1
#define SCM_TIMESTAMP    SCM_TIMESTAMP
#define SCM_CREDENTIALS  SCM_CREDENTIALS
#define SCM_TIMESTAMPING SCM_TIMESTAMPING
#define SCM_TIMESTAMPNS  SCM_TIMESTAMPNS
#define SCM_WIFI_STATUS  SCM_WIFI_STATUS




/*!BEGIN libc/sysv/consts/seek.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SEEK_H_
COSMOPOLITAN_C_START_

extern const int SEEK_DATA;
extern const int SEEK_HOLE;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sf.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SF_H_
COSMOPOLITAN_C_START_

struct sf_hdtr {
  struct iovec *headers;
  int hdr_cnt;
  struct iovec *trailers;
  int trl_cnt;
};

extern const int SF_MNOWAIT;
extern const int SF_NODISKIO;
extern const int SF_SYNC;

#define SF_MNOWAIT  SF_MNOWAIT
#define SF_NODISKIO SF_NODISKIO
#define SF_SYNC     SF_SYNC


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shm.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHM_H_

#define SHM_ANON      SHM_ANON
#define SHM_DEST      SHM_DEST
#define SHM_EXEC      SHM_EXEC
#define SHM_HUGETLB   SHM_HUGETLB
#define SHM_INFO      SHM_INFO
#define SHM_LOCK      SHM_LOCK
#define SHM_LOCKED    SHM_LOCKED
#define SHM_NORESERVE SHM_NORESERVE
#define SHM_R         SHM_R
#define SHM_RDONLY    SHM_RDONLY
#define SHM_REMAP     SHM_REMAP
#define SHM_RND       SHM_RND
#define SHM_STAT      SHM_STAT
#define SHM_UNLOCK    SHM_UNLOCK
#define SHM_W         SHM_W

COSMOPOLITAN_C_START_

extern const char *SHM_ANON;
extern const int SHM_DEST;
extern const int SHM_EXEC;
extern const int SHM_HUGETLB;
extern const int SHM_INFO;
extern const int SHM_LOCK;
extern const int SHM_LOCKED;
extern const int SHM_NORESERVE;
extern const int SHM_R;
extern const int SHM_RDONLY;
extern const int SHM_REMAP;
extern const int SHM_RND;
extern const int SHM_STAT;
extern const int SHM_UNLOCK;
extern const int SHM_W;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/shut.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SHUT_H_
COSMOPOLITAN_C_START_

extern const int SHUT_RD;
extern const int SHUT_RDWR;
extern const int SHUT_WR;

#define SHUT_RD   0
#define SHUT_RDWR 2
#define SHUT_WR   1

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sicode.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SICODE_H_
COSMOPOLITAN_C_START_

extern const int32_t SI_USER;
extern const int32_t SI_QUEUE;
extern const int32_t SI_TIMER;
extern const int32_t SI_MESGQ;
extern const int32_t SI_ASYNCIO;
extern const int32_t SI_TKILL;
extern const int32_t SI_ASYNCNL;
extern const int32_t SI_KERNEL;
extern const int32_t SI_NOINFO;
extern const int32_t CLD_EXITED;
extern const int32_t CLD_KILLED;
extern const int32_t CLD_DUMPED;
extern const int32_t CLD_TRAPPED;
extern const int32_t CLD_STOPPED;
extern const int32_t CLD_CONTINUED;
extern const int32_t TRAP_BRKPT;
extern const int32_t TRAP_TRACE;
extern const int32_t SEGV_MAPERR;
extern const int32_t SEGV_ACCERR;
extern const int32_t SEGV_PKUERR;
extern const int32_t FPE_INTDIV;
extern const int32_t FPE_INTOVF;
extern const int32_t FPE_FLTDIV;
extern const int32_t FPE_FLTOVF;
extern const int32_t FPE_FLTUND;
extern const int32_t FPE_FLTRES;
extern const int32_t FPE_FLTINV;
extern const int32_t FPE_FLTSUB;
extern const int32_t ILL_ILLOPC;
extern const int32_t ILL_ILLOPN;
extern const int32_t ILL_ILLADR;
extern const int32_t ILL_ILLTRP;
extern const int32_t ILL_PRVOPC;
extern const int32_t ILL_PRVREG;
extern const int32_t ILL_COPROC;
extern const int32_t ILL_BADSTK;
extern const int32_t BUS_ADRALN;
extern const int32_t BUS_ADRERR;
extern const int32_t BUS_OBJERR;
extern const int32_t BUS_MCEERR_AR;
extern const int32_t BUS_MCEERR_AO;
extern const int32_t BUS_OOMERR;
extern const int32_t POLL_IN;
extern const int32_t POLL_OUT;
extern const int32_t POLL_MSG;
extern const int32_t POLL_ERR;
extern const int32_t POLL_PRI;
extern const int32_t POLL_HUP;
extern const int32_t SYS_SECCOMP;
extern const int32_t SYS_USER_DISPATCH;

#define CLD_EXITED    1
#define CLD_KILLED    2
#define CLD_DUMPED    3
#define CLD_TRAPPED   4
#define CLD_STOPPED   5
#define CLD_CONTINUED 6
#define TRAP_BRKPT    1
#define TRAP_TRACE    2
#define SEGV_MAPERR   1
#define SEGV_ACCERR   2
#define ILL_ILLOPC    1
#define ILL_PRVREG    6
#define ILL_COPROC    7
#define ILL_BADSTK    8
#define BUS_ADRALN    1
#define BUS_ADRERR    2
#define BUS_OBJERR    3
#define POLL_IN       1
#define POLL_OUT      2
#define POLL_MSG      3
#define POLL_ERR      4
#define POLL_PRI      5
#define POLL_HUP      6

#define SI_USER           SI_USER
#define SI_QUEUE          SI_QUEUE
#define SI_TIMER          SI_TIMER
#define SI_MESGQ          SI_MESGQ
#define SI_ASYNCIO        SI_ASYNCIO
#define SI_TKILL          SI_TKILL
#define SI_ASYNCNL        SI_ASYNCNL
#define SI_KERNEL         SI_KERNEL
#define SI_NOINFO         SI_NOINFO
#define SEGV_PKUERR       SEGV_PKUERR
#define FPE_INTDIV        FPE_INTDIV
#define FPE_INTOVF        FPE_INTOVF
#define FPE_FLTDIV        FPE_FLTDIV
#define FPE_FLTOVF        FPE_FLTOVF
#define FPE_FLTUND        FPE_FLTUND
#define FPE_FLTRES        FPE_FLTRES
#define FPE_FLTINV        FPE_FLTINV
#define FPE_FLTSUB        FPE_FLTSUB
#define ILL_ILLOPN        ILL_ILLOPN
#define ILL_ILLADR        ILL_ILLADR
#define ILL_ILLTRP        ILL_ILLTRP
#define ILL_PRVOPC        ILL_PRVOPC
#define BUS_OOMERR        BUS_OOMERR
#define BUS_MCEERR_AR     BUS_MCEERR_AR
#define BUS_MCEERR_AO     BUS_MCEERR_AO
#define SYS_SECCOMP       SYS_SECCOMP
#define SYS_USER_DISPATCH SYS_USER_DISPATCH


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sig.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIG_H_
COSMOPOLITAN_C_START_

extern const int SIGABRT;
extern const int SIGALRM;
extern const int SIGBUS;
extern const int SIGTHR;
extern const int SIGCHLD;
extern const int SIGCONT;
extern const int SIGEMT;
extern const int SIGFPE;
extern const int SIGHUP;
extern const int SIGILL;
extern const int SIGINFO;
extern const int SIGINT;
extern const int SIGIO;
extern const int SIGIOT;
extern const int SIGKILL;
extern const int SIGPIPE;
extern const int SIGPOLL;
extern const int SIGPROF;
extern const int SIGPWR;
extern const int SIGQUIT;
extern const int SIGRTMAX;
extern const int SIGRTMIN;
extern const int SIGSEGV;
extern const int SIGSTKFLT;
extern const int SIGSTOP;
extern const int SIGSYS;
extern const int SIGTERM;
extern const int SIGTRAP;
extern const int SIGTSTP;
extern const int SIGTTIN;
extern const int SIGTTOU;
extern const int SIGUNUSED;
extern const int SIGURG;
extern const int SIGUSR1;
extern const int SIGUSR2;
extern const int SIGVTALRM;
extern const int SIGWINCH;
extern const int SIGXCPU;
extern const int SIGXFSZ;

extern const int SIG_BLOCK;
extern const int SIG_SETMASK;
extern const int SIG_UNBLOCK;

COSMOPOLITAN_C_END_

#define SIGABRT   6
#define SIGALRM   14
#define SIGFPE    8
#define SIGHUP    1
#define SIGILL    4
#define SIGINT    2
#define SIGIOT    6
#define SIGKILL   9
#define SIGPIPE   13
#define SIGPROF   27
#define SIGQUIT   3
#define SIGSEGV   11
#define SIGTERM   15
#define SIGTRAP   5
#define SIGTTIN   21
#define SIGTTOU   22
#define SIGVTALRM 26
#define SIGWINCH  28
#define SIGXCPU   24
#define SIGXFSZ   25

/*
 * - No macro is define for SIGIO and SIGPOLL in order to persuade
 *   ./configure scripts to favor using poll() or select() instead of
 *   interrupt-based i/o.
 *
 * - No macros are defined for SIGRTMIN and SIGRTMAX because the project
 *   hasn't fleshed them out yet.
 *
 * - SIGTHR doesn't have a macro since it's internal to posix threads.
 *
 * - SIGSTKFLT is Linux-only so no macro is defined.
 */

#define SIGBUS  SIGBUS
#define SIGCHLD SIGCHLD
#define SIGCONT SIGCONT
#define SIGEMT  SIGEMT
#define SIGINFO SIGINFO
#define SIGPWR  SIGPWR
#define SIGSTOP SIGSTOP
#define SIGSYS  SIGSYS
#define SIGTSTP SIGTSTP
#define SIGURG  SIGURG
#define SIGUSR1 SIGUSR1
#define SIGUSR2 SIGUSR2

#define SIG_BLOCK   SIG_BLOCK
#define SIG_SETMASK SIG_SETMASK
#define SIG_UNBLOCK SIG_UNBLOCK



/*!BEGIN libc/sysv/consts/sio.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SIO_H_
COSMOPOLITAN_C_START_

extern const unsigned long SIOCADDDLCI;
extern const unsigned long SIOCADDMULTI;
extern const unsigned long SIOCADDRT;
extern const unsigned long SIOCDARP;
extern const unsigned long SIOCDELDLCI;
extern const unsigned long SIOCDELMULTI;
extern const unsigned long SIOCDELRT;
extern const unsigned long SIOCDEVPRIVATE;
extern const unsigned long SIOCDIFADDR;
extern const unsigned long SIOCDRARP;
extern const unsigned long SIOCGARP;
extern const unsigned long SIOCGIFADDR;
extern const unsigned long SIOCGIFBR;
extern const unsigned long SIOCGIFBRDADDR;
extern const unsigned long SIOCGIFCONF;
extern const unsigned long SIOCGIFCOUNT;
extern const unsigned long SIOCGIFDSTADDR;
extern const unsigned long SIOCGIFENCAP;
extern const unsigned long SIOCGIFFLAGS;
extern const unsigned long SIOCGIFHWADDR;
extern const unsigned long SIOCGIFINDEX;
extern const unsigned long SIOCGIFMAP;
extern const unsigned long SIOCGIFMEM;
extern const unsigned long SIOCGIFMETRIC;
extern const unsigned long SIOCGIFMTU;
extern const unsigned long SIOCGIFNAME;
extern const unsigned long SIOCGIFNETMASK;
extern const unsigned long SIOCGIFPFLAGS;
extern const unsigned long SIOCGIFSLAVE;
extern const unsigned long SIOCGIFTXQLEN;
extern const unsigned long SIOCGPGRP;
extern const unsigned long SIOCGRARP;
extern const unsigned long SIOCGSTAMP;
extern const unsigned long SIOCGSTAMPNS;
extern const unsigned long SIOCPROTOPRIVATE;
extern const unsigned long SIOCRTMSG;
extern const unsigned long SIOCSARP;
extern const unsigned long SIOCSIFADDR;
extern const unsigned long SIOCSIFBR;
extern const unsigned long SIOCSIFBRDADDR;
extern const unsigned long SIOCSIFDSTADDR;
extern const unsigned long SIOCSIFENCAP;
extern const unsigned long SIOCSIFFLAGS;
extern const unsigned long SIOCSIFHWADDR;
extern const unsigned long SIOCSIFHWBROADCAST;
extern const unsigned long SIOCSIFLINK;
extern const unsigned long SIOCSIFMAP;
extern const unsigned long SIOCSIFMEM;
extern const unsigned long SIOCSIFMETRIC;
extern const unsigned long SIOCSIFMTU;
extern const unsigned long SIOCSIFNAME;
extern const unsigned long SIOCSIFNETMASK;
extern const unsigned long SIOCSIFPFLAGS;
extern const unsigned long SIOCSIFSLAVE;
extern const unsigned long SIOCSIFTXQLEN;
extern const unsigned long SIOCSPGRP;
extern const unsigned long SIOCSRARP;
extern const unsigned long SIOGIFINDEX;

#define SIOCGIFCONF    SIOCGIFCONF
#define SIOCGIFADDR    SIOCGIFADDR
#define SIOCSIFADDR    SIOCSIFADDR
#define SIOCDIFADDR    SIOCDIFADDR
#define SIOCGIFBRDADDR SIOCGIFBRDADDR
#define SIOCGIFNETMASK SIOCGIFNETMASK
#define SIOCGIFFLAGS   SIOCGIFFLAGS
#define SIOCSIFFLAGS   SIOCSIFFLAGS
#define SIOCGIFMETRIC  SIOCGIFMETRIC
#define SIOCSIFMETRIC  SIOCSIFMETRIC
#define SIOCSIFBRDADDR SIOCSIFBRDADDR
#define SIOCSIFNETMASK SIOCSIFNETMASK
#define SIOCGIFDSTADDR SIOCGIFDSTADDR
#define SIOCSIFDSTADDR SIOCSIFDSTADDR
#define SIOCGIFMTU     SIOCGIFMTU
#define SIOCSIFMTU     SIOCSIFMTU

#define SIOCGPGRP SIOCGPGRP
#define SIOCSPGRP SIOCSPGRP

#define SIOCADDMULTI SIOCADDMULTI
#define SIOCDELMULTI SIOCDELMULTI

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/so.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SO_H_

#define SO_DEBUG 1

COSMOPOLITAN_C_START_

extern const int SO_TYPE;
extern const int SO_ERROR;
extern const int SO_ACCEPTCONN;
extern const int SO_REUSEADDR;
extern const int SO_KEEPALIVE;
extern const int SO_DONTROUTE;
extern const int SO_BROADCAST;
extern const int SO_USELOOPBACK;
extern const int SO_LINGER;
extern const int SO_OOBINLINE;
extern const int SO_SNDBUF;
extern const int SO_RCVBUF;
extern const int SO_RCVTIMEO;
extern const int SO_SNDTIMEO;
extern const int SO_RCVLOWAT;
extern const int SO_SNDLOWAT;

#define SO_TYPE        SO_TYPE
#define SO_ERROR       SO_ERROR
#define SO_ACCEPTCONN  SO_ACCEPTCONN
#define SO_REUSEADDR   SO_REUSEADDR
#define SO_KEEPALIVE   SO_KEEPALIVE
#define SO_DONTROUTE   SO_DONTROUTE
#define SO_BROADCAST   SO_BROADCAST
#define SO_USELOOPBACK SO_USELOOPBACK
#define SO_LINGER      SO_LINGER
#define SO_OOBINLINE   SO_OOBINLINE
#define SO_SNDBUF      SO_SNDBUF
#define SO_RCVBUF      SO_RCVBUF
#define SO_RCVTIMEO    SO_RCVTIMEO
#define SO_SNDTIMEO    SO_SNDTIMEO
#define SO_RCVLOWAT    SO_RCVLOWAT
#define SO_SNDLOWAT    SO_SNDLOWAT

/*
 * this isn't available on windows, but it should be fine to use anyway,
 * setsockopt will return ENOPROTOOPT which is perfectly fine to ignore.
 */
extern const int SO_REUSEPORT;
#define SO_REUSEPORT SO_REUSEPORT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sock.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOCK_H_
COSMOPOLITAN_C_START_

extern const int SOCK_CLOEXEC;
extern const int SOCK_DCCP;
extern const int SOCK_DGRAM;
extern const int SOCK_NONBLOCK;
extern const int SOCK_PACKET;
extern const int SOCK_RAW;
extern const int SOCK_RDM;
extern const int SOCK_SEQPACKET;
extern const int SOCK_STREAM;

#define SOCK_STREAM    1
#define SOCK_DGRAM     2
#define SOCK_RAW       3
#define SOCK_RDM       4
#define SOCK_SEQPACKET 5
#define SOCK_CLOEXEC   SOCK_CLOEXEC
#define SOCK_NONBLOCK  SOCK_NONBLOCK

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/sol.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SOL_H_

#define SOL_IP     0
#define SOL_ICMP   1
#define SOL_TCP    6
#define SOL_UDP    17
#define SOL_IPV6   41
#define SOL_ICMPV6 58
#define SOL_RAW    255

COSMOPOLITAN_C_START_

extern const int SOL_SOCKET;
#define SOL_SOCKET SOL_SOCKET

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/splice.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SPLICE_H_
COSMOPOLITAN_C_START_

extern const unsigned int SPLICE_F_GIFT;
extern const unsigned int SPLICE_F_MORE;
extern const unsigned int SPLICE_F_MOVE;
extern const unsigned int SPLICE_F_NONBLOCK;

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/ss.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_SS_H_
COSMOPOLITAN_C_START_

extern const int SS_DISABLE;
extern const int _SIGSTKSZ;
extern const int _MINSIGSTKSZ;

COSMOPOLITAN_C_END_

#define SIGSTKSZ    32768
#define MINSIGSTKSZ 32768 /* xnu defines the highest minimum */
#define SS_ONSTACK  1
#define SS_DISABLE  SS_DISABLE



/*!BEGIN libc/sysv/consts/st.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_ST_H_
COSMOPOLITAN_C_START_

extern const int ST_APPEND;
extern const int ST_IMMUTABLE;
extern const int ST_MANDLOCK;
extern const int ST_NOATIME;
extern const int ST_NODEV;
extern const int ST_NODIRATIME;
extern const int ST_NOEXEC;
extern const int ST_NOSUID;
extern const int ST_RDONLY;
extern const int ST_RELATIME;
extern const int ST_SYNCHRONOUS;
extern const int ST_WRITE;

#define ST_APPEND      ST_APPEND
#define ST_IMMUTABLE   ST_IMMUTABLE
#define ST_MANDLOCK    ST_MANDLOCK
#define ST_NOATIME     ST_NOATIME
#define ST_NODEV       ST_NODEV
#define ST_NODIRATIME  ST_NODIRATIME
#define ST_NOEXEC      ST_NOEXEC
#define ST_NOSUID      ST_NOSUID
#define ST_RDONLY      ST_RDONLY
#define ST_RELATIME    ST_RELATIME
#define ST_SYNCHRONOUS ST_SYNCHRONOUS
#define ST_WRITE       ST_WRITE


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcp.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCP_H_
COSMOPOLITAN_C_START_

extern const int TCP_CC_INFO;
extern const int TCP_CONGESTION;
extern const int TCP_COOKIE_TRANSACTIONS;
extern const int TCP_CORK;
extern const int TCP_DEFER_ACCEPT;
extern const int TCP_FASTOPEN;
extern const int TCP_FASTOPEN_CONNECT;
extern const int TCP_INFO;
extern const int TCP_KEEPCNT;
extern const int TCP_KEEPIDLE;
extern const int TCP_KEEPINTVL;
extern const int TCP_LINGER2;
extern const int TCP_MAXSEG;
extern const int TCP_MD5SIG;
extern const int TCP_MD5SIG_MAXKEYLEN;
extern const int TCP_NODELAY;
extern const int TCP_NOTSENT_LOWAT;
extern const int TCP_QUEUE_SEQ;
extern const int TCP_QUICKACK;
extern const int TCP_REPAIR;
extern const int TCP_REPAIR_OPTIONS;
extern const int TCP_REPAIR_QUEUE;
extern const int TCP_SAVED_SYN;
extern const int TCP_SAVE_SYN;
extern const int TCP_SYNCNT;
extern const int TCP_THIN_DUPACK;
extern const int TCP_THIN_LINEAR_TIMEOUTS;
extern const int TCP_TIMESTAMP;
extern const int TCP_ULP;
extern const int TCP_USER_TIMEOUT;
extern const int TCP_WINDOW_CLAMP;

#define TCP_NODELAY              1
#define TCP_CC_INFO              TCP_CC_INFO
#define TCP_CONGESTION           TCP_CONGESTION
#define TCP_COOKIE_TRANSACTIONS  TCP_COOKIE_TRANSACTIONS
#define TCP_CORK                 TCP_CORK
#define TCP_DEFER_ACCEPT         TCP_DEFER_ACCEPT
#define TCP_FASTOPEN             TCP_FASTOPEN
#define TCP_FASTOPEN_CONNECT     TCP_FASTOPEN_CONNECT
#define TCP_INFO                 TCP_INFO
#define TCP_KEEPCNT              TCP_KEEPCNT
#define TCP_KEEPIDLE             TCP_KEEPIDLE
#define TCP_KEEPINTVL            TCP_KEEPINTVL
#define TCP_LINGER2              TCP_LINGER2
#define TCP_MAXSEG               TCP_MAXSEG
#define TCP_MD5SIG               TCP_MD5SIG
#define TCP_MD5SIG_MAXKEYLEN     TCP_MD5SIG_MAXKEYLEN
#define TCP_NOTSENT_LOWAT        TCP_NOTSENT_LOWAT
#define TCP_QUEUE_SEQ            TCP_QUEUE_SEQ
#define TCP_QUICKACK             TCP_QUICKACK
#define TCP_REPAIR               TCP_REPAIR
#define TCP_REPAIR_OPTIONS       TCP_REPAIR_OPTIONS
#define TCP_REPAIR_QUEUE         TCP_REPAIR_QUEUE
#define TCP_SAVED_SYN            TCP_SAVED_SYN
#define TCP_SAVE_SYN             TCP_SAVE_SYN
#define TCP_SYNCNT               TCP_SYNCNT
#define TCP_THIN_DUPACK          TCP_THIN_DUPACK
#define TCP_THIN_LINEAR_TIMEOUTS TCP_THIN_LINEAR_TIMEOUTS
#define TCP_TIMESTAMP            TCP_TIMESTAMP
#define TCP_ULP                  TCP_ULP
#define TCP_USER_TIMEOUT         TCP_USER_TIMEOUT
#define TCP_WINDOW_CLAMP         TCP_WINDOW_CLAMP


COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/tcpopt.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TCPOPT_H_

#define TCPOPT_EOL            0
#define TCPOPT_NOP            1
#define TCPOPT_MAXSEG         2
#define TCPOPT_WINDOW         3
#define TCPOPT_SACK_PERMITTED 4
#define TCPOPT_SACK           5
#define TCPOPT_TIMESTAMP      8

#define TCPOLEN_SACK_PERMITTED 2
#define TCPOLEN_WINDOW         3
#define TCPOLEN_MAXSEG         4
#define TCPOLEN_TIMESTAMP      10



/*!BEGIN libc/sysv/consts/th.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TH_H_

#define TH_FIN  1
#define TH_SYN  2
#define TH_RST  4
#define TH_PUSH 8
#define TH_URG  32
#define TH_ACK  16



/*!BEGIN libc/sysv/consts/timer.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_TIMER_H_

#define TIMER_ABSTIME 1



/*!BEGIN libc/sysv/consts/uc.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UC_H_
COSMOPOLITAN_C_START_

#define UC_FP_XSTATE         1
#define UC_SIGCONTEXT_SS     2
#define UC_STRICT_RESTORE_SS 4

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/unmount.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_MOUNT_H_
COSMOPOLITAN_C_START_

extern const int MNT_FORCE;
extern const int MNT_DETACH;
extern const int MNT_EXPIRE;
extern const int UMOUNT_NOFOLLOW;
extern const int MNT_BYFSID;

COSMOPOLITAN_C_END_

#define MNT_FORCE       MNT_FORCE
#define MNT_DETACH      MNT_DETACH
#define MNT_EXPIRE      MNT_EXPIRE
#define UMOUNT_NOFOLLOW UMOUNT_NOFOLLOW
#define MNT_BYFSID      MNT_BYFSID



/*!BEGIN libc/sysv/consts/utime.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_UTIME_H_
COSMOPOLITAN_C_START_

extern const int UTIME_NOW;
extern const int UTIME_OMIT;

COSMOPOLITAN_C_END_

#define UTIME_NOW  UTIME_NOW
#define UTIME_OMIT UTIME_OMIT




/*!BEGIN libc/sysv/consts/waitid.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_WAITID_H_
COSMOPOLITAN_C_START_

extern const int WEXITED;
extern const int WSTOPPED;
extern const int WNOWAIT;

#define WEXITED  WEXITED
#define WSTOPPED WSTOPPED
#define WNOWAIT  WNOWAIT

COSMOPOLITAN_C_END_


/*!BEGIN libc/sysv/consts/xopen.h */

#define COSMOPOLITAN_LIBC_SYSV_CONSTS_XOPEN_H_

#define _XOPEN_IOV_MAX  16
#define _XOPEN_ENH_I18N 1
#define _XOPEN_UNIX     1
#define _XOPEN_NAME_MAX 63
#define _XOPEN_PATH_MAX 1024
#define _XOPEN_SOURCE   700



/*!BEGIN libc/thread/semaphore.h */

#define COSMOPOLITAN_LIBC_CALLS_SEMAPHORE_H_
COSMOPOLITAN_C_START_

#define SEM_FAILED        ((sem_t *)0)
#define SEM_MAGIC_NAMED   0xDEADBEEFu
#define SEM_MAGIC_UNNAMED 0xFEEDABEEu
#define SEM_MAGIC_KERNEL  0xCAFEBABEu

typedef struct {
  union {
    struct {
      _Atomic(int) sem_value;
      _Atomic(int) sem_waiters;
      _Atomic(int) sem_prefs; /* named only */
      unsigned sem_magic;
      int64_t sem_dev;     /* named only */
      int64_t sem_ino;     /* named only */
      int sem_pid;         /* unnamed only */
      char sem_lazydelete; /* named only */
      char sem_pshared;
      int *sem_kernel;
    };
    void *sem_space[32];
  };
} sem_t;

int sem_init(sem_t *, int, unsigned) libcesque;
int sem_destroy(sem_t *) libcesque;
int sem_post(sem_t *) libcesque;
int sem_wait(sem_t *) libcesque;
int sem_trywait(sem_t *) libcesque;
int sem_timedwait(sem_t *, const struct timespec *) libcesque;
int sem_getvalue(sem_t *, int *) libcesque;
sem_t *sem_open(const char *, int, ...) libcesque;
int sem_close(sem_t *) libcesque;
int sem_unlink(const char *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/thread.h */

#define COSMOPOLITAN_LIBC_THREAD_THREAD_H_

#define PTHREAD_KEYS_MAX              128
#define PTHREAD_STACK_MIN             65536
#define PTHREAD_DESTRUCTOR_ITERATIONS 4

#define PTHREAD_BARRIER_SERIAL_THREAD 31337

#define PTHREAD_MUTEX_DEFAULT    0
#define PTHREAD_MUTEX_NORMAL     0
#define PTHREAD_MUTEX_RECURSIVE  1
#define PTHREAD_MUTEX_ERRORCHECK 2
#define PTHREAD_MUTEX_STALLED    0
#define PTHREAD_MUTEX_ROBUST     1

#define PTHREAD_PROCESS_PRIVATE 0
#define PTHREAD_PROCESS_SHARED  1

#define PTHREAD_CREATE_JOINABLE 0
#define PTHREAD_CREATE_DETACHED 1

#define PTHREAD_INHERIT_SCHED  0
#define PTHREAD_EXPLICIT_SCHED 1

#define PTHREAD_CANCELED ((void *)-1)

#define PTHREAD_CANCEL_ENABLE  0
#define PTHREAD_CANCEL_DISABLE 1
#define PTHREAD_CANCEL_MASKED  2

#define PTHREAD_CANCEL_DEFERRED     0
#define PTHREAD_CANCEL_ASYNCHRONOUS 1

#define PTHREAD_SCOPE_SYSTEM  0
#define PTHREAD_SCOPE_PROCESS 1

#define PTHREAD_ATTR_NO_SIGMASK_NP -1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

#define PTHREAD_ONCE_INIT          _PTHREAD_INIT
#define PTHREAD_COND_INITIALIZER   _PTHREAD_INIT
#define PTHREAD_RWLOCK_INITIALIZER _PTHREAD_INIT
#define PTHREAD_MUTEX_INITIALIZER  _PTHREAD_INIT
#define _PTHREAD_INIT \
  { 0 }

typedef uintptr_t pthread_t;
typedef int pthread_id_np_t;
typedef char pthread_condattr_t;
typedef char pthread_rwlockattr_t;
typedef char pthread_barrierattr_t;
typedef unsigned pthread_key_t;
typedef void (*pthread_key_dtor)(void *);

typedef struct pthread_once_s {
  _Atomic(uint32_t) _lock;
} pthread_once_t;

typedef struct pthread_spinlock_s {
  _Atomic(int) _lock;
} pthread_spinlock_t;

typedef struct pthread_mutex_s {
  _Atomic(int32_t) _lock;
  unsigned _type : 2;
  unsigned _pshared : 1;
  unsigned _depth : 6;
  unsigned _owner : 23;
  long _pid;
} pthread_mutex_t;

typedef struct pthread_mutexattr_s {
  char _type;
  char _pshared;
} pthread_mutexattr_t;

typedef struct pthread_cond_s {
  void *_nsync[2];
} pthread_cond_t;

typedef struct pthread_rwlock_s {
  void *_nsync[2];
  char _iswrite;
} pthread_rwlock_t;

typedef struct pthread_barrier_s {
  void *_nsync;
} pthread_barrier_t;

typedef struct pthread_attr_s {
  char __detachstate;
  char __inheritsched;
  char __havesigmask;
  int __schedparam;
  int __schedpolicy;
  int __contentionscope;
  int __guardsize;
  size_t __stacksize;
  uint64_t __sigmask;
  void *__stackaddr;
} pthread_attr_t;

struct _pthread_cleanup_buffer {
  void (*__routine)(void *);
  void *__arg;
  int __canceltype;
  struct _pthread_cleanup_buffer *__prev;
};

/* clang-format off */

int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)) dontthrow;
int pthread_attr_destroy(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_getdetachstate(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getguardsize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_getinheritsched(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getschedpolicy(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getscope(const pthread_attr_t *, int *) libcesque paramsnonnull();
int pthread_attr_getstack(const pthread_attr_t *, void **, size_t *) libcesque paramsnonnull();
int pthread_attr_getstacksize(const pthread_attr_t *, size_t *) libcesque paramsnonnull();
int pthread_attr_init(pthread_attr_t *) libcesque paramsnonnull();
int pthread_attr_setdetachstate(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setguardsize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_attr_setinheritsched(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setschedpolicy(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setscope(pthread_attr_t *, int) libcesque paramsnonnull();
int pthread_attr_setstack(pthread_attr_t *, void *, size_t) libcesque paramsnonnull((1));
int pthread_attr_setstacksize(pthread_attr_t *, size_t) libcesque paramsnonnull();
int pthread_barrier_destroy(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrier_init(pthread_barrier_t *, const pthread_barrierattr_t *, unsigned) libcesque paramsnonnull((1));
int pthread_barrier_wait(pthread_barrier_t *) libcesque paramsnonnull();
int pthread_barrierattr_destroy(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_getpshared(const pthread_barrierattr_t *, int *) libcesque paramsnonnull();
int pthread_barrierattr_init(pthread_barrierattr_t *) libcesque paramsnonnull();
int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int) libcesque paramsnonnull();
int pthread_cancel(pthread_t) libcesque;
int pthread_cond_broadcast(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_destroy(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_init(pthread_cond_t *, const pthread_condattr_t *) libcesque paramsnonnull((1));
int pthread_cond_signal(pthread_cond_t *) libcesque paramsnonnull();
int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *) libcesque paramsnonnull();
int pthread_condattr_destroy(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_getpshared(const pthread_condattr_t *, int *) libcesque paramsnonnull();
int pthread_condattr_init(pthread_condattr_t *) libcesque paramsnonnull();
int pthread_condattr_setpshared(pthread_condattr_t *, int) libcesque paramsnonnull();
int pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *) dontthrow paramsnonnull((1));
int pthread_detach(pthread_t) libcesque;
int pthread_equal(pthread_t, pthread_t) libcesque;
int pthread_getattr_np(pthread_t, pthread_attr_t *) libcesque paramsnonnull();
int pthread_getname_np(pthread_t, char *, size_t) libcesque paramsnonnull();
int pthread_getunique_np(pthread_t, pthread_id_np_t *) libcesque paramsnonnull();
int pthread_join(pthread_t, void **) libcesque;
int pthread_key_create(pthread_key_t *, pthread_key_dtor) libcesque paramsnonnull((1));
int pthread_key_delete(pthread_key_t) libcesque;
int pthread_kill(pthread_t, int) libcesque;
int pthread_mutex_consistent(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_destroy(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *) libcesque paramsnonnull((1));
int pthread_mutex_lock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_trylock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutex_unlock(pthread_mutex_t *) libcesque paramsnonnull();
int pthread_mutexattr_destroy(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_getpshared(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_gettype(const pthread_mutexattr_t *, int *) libcesque paramsnonnull();
int pthread_mutexattr_init(pthread_mutexattr_t *) libcesque paramsnonnull();
int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_mutexattr_settype(pthread_mutexattr_t *, int) libcesque paramsnonnull();
int pthread_once(pthread_once_t *, void (*)(void)) paramsnonnull();
int pthread_orphan_np(void) libcesque;
int pthread_rwlock_destroy(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *) libcesque paramsnonnull((1));
int pthread_rwlock_rdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_tryrdlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_trywrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_unlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlock_wrlock(pthread_rwlock_t *) libcesque paramsnonnull();
int pthread_rwlockattr_destroy(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *, int *) libcesque paramsnonnull();
int pthread_rwlockattr_init(pthread_rwlockattr_t *) libcesque paramsnonnull();
int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int) libcesque paramsnonnull();
int pthread_setcancelstate(int, int *) libcesque;
int pthread_setcanceltype(int, int *) libcesque;
int pthread_setname_np(pthread_t, const char *) libcesque paramsnonnull();
int pthread_setschedprio(pthread_t, int) libcesque;
int pthread_setspecific(pthread_key_t, const void *) libcesque;
int pthread_spin_destroy(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_init(pthread_spinlock_t *, int) libcesque paramsnonnull();
int pthread_spin_lock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_trylock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_spin_unlock(pthread_spinlock_t *) libcesque paramsnonnull();
int pthread_testcancel_np(void) libcesque;
int pthread_tryjoin_np(pthread_t, void **) libcesque;
int pthread_yield_np(void) libcesque;
int pthread_yield(void) libcesque;
pthread_id_np_t pthread_getthreadid_np(void) libcesque;
pthread_t pthread_self(void) libcesque pureconst;
void *pthread_getspecific(pthread_key_t) libcesque;
void pthread_cleanup_pop(struct _pthread_cleanup_buffer *, int) libcesque paramsnonnull();
void pthread_cleanup_push(struct _pthread_cleanup_buffer *, void (*)(void *), void *) libcesque paramsnonnull((1));
void pthread_exit(void *) libcesque wontreturn;
void pthread_testcancel(void) libcesque;
void pthread_pause_np(void) libcesque;

/* clang-format on */

#define pthread_cleanup_push(routine, arg)  \
  {                                         \
    struct _pthread_cleanup_buffer _buffer; \
    pthread_cleanup_push(&_buffer, (routine), (arg));

#define pthread_cleanup_pop(execute)        \
  pthread_cleanup_pop(&_buffer, (execute)); \
  }

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/thread/thread2.h */

#define COSMOPOLITAN_LIBC_INTRIN_PTHREAD2_H_
COSMOPOLITAN_C_START_
/* clang-format off */

int pthread_attr_getschedparam(const pthread_attr_t *, struct sched_param *) libcesque paramsnonnull();
int pthread_attr_getsigmask_np(const pthread_attr_t *, sigset_t *) libcesque paramsnonnull((1));
int pthread_attr_setschedparam(pthread_attr_t *, const struct sched_param *) libcesque paramsnonnull();
int pthread_attr_setsigmask_np(pthread_attr_t *, const sigset_t *) libcesque paramsnonnull((1));
int pthread_cond_timedwait(pthread_cond_t *, pthread_mutex_t *, const struct timespec *) libcesque paramsnonnull((1, 2));
int pthread_getaffinity_np(pthread_t, size_t, cpu_set_t *) libcesque paramsnonnull();
int pthread_getschedparam(pthread_t, int *, struct sched_param *) libcesque paramsnonnull();
int pthread_setaffinity_np(pthread_t, size_t, const cpu_set_t *) libcesque paramsnonnull();
int pthread_setschedparam(pthread_t, int, const struct sched_param *) libcesque paramsnonnull();
int pthread_timedjoin_np(pthread_t, void **, struct timespec *) libcesque;

/* clang-format off */
COSMOPOLITAN_C_END_
/* clang-format on */


/*!BEGIN libc/thread/threads.h */

#define COSMOPOLITAN_LIBC_THREAD_THREADS_H_
COSMOPOLITAN_C_START_

#if !defined(__cplusplus) &&                   \
    (!(defined(__GNUC__) && __GNUC__ >= 13) || \
     !(defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L))
#define thread_local _Thread_local
#endif

#define TSS_DTOR_ITERATIONS 4

enum {
  thrd_success = 0,
  thrd_busy = 1,
  thrd_error = 2,
  thrd_nomem = 3,
  thrd_timedout = 4,
};

enum {
  mtx_plain = 0,
  mtx_recursive = 1,
  mtx_timed = 2,
};

typedef uintptr_t thrd_t;
typedef void (*tss_dtor_t)(void *);
typedef int (*thrd_start_t)(void *);
typedef _Atomic(uint32_t) once_flag;

void call_once(once_flag *, void (*)(void));
int thrd_create(thrd_t *, thrd_start_t, void *);
void thrd_exit(int) wontreturn;
int thrd_join(thrd_t, int *);
int thrd_detach(thrd_t);
int thrd_equal(thrd_t, thrd_t);
thrd_t thrd_current(void);
void thrd_yield(void);

COSMOPOLITAN_C_END_


/*!BEGIN libc/thread/tls.h */

#define COSMOPOLITAN_LIBC_THREAD_TLS_H_

#define TLS_ALIGNMENT 64

#define TIB_FLAG_VFORKED 1

#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

struct CosmoFtrace {   /* 16 */
  char ft_once;        /*  0 */
  char ft_noreentry;   /*  1 */
  int ft_skew;         /*  4 */
  int64_t ft_lastaddr; /*  8 */
};

/* NOTE: update aarch64 libc/errno.h if sizeof changes */
/* NOTE: update aarch64 libc/proc/vfork.S if sizeof changes */
/* NOTE: update aarch64 libc/nexgen32e/gc.S if sizeof changes */
struct CosmoTib {
  struct CosmoTib *tib_self;      /* 0x00 */
  struct CosmoFtrace tib_ftracer; /* 0x08 */
  void *tib_garbages;             /* 0x18 */
  intptr_t tib_locale;            /* 0x20 */
  intptr_t tib_pthread;           /* 0x28 */
  struct CosmoTib *tib_self2;     /* 0x30 */
  _Atomic(int32_t) tib_tid;       /* 0x38 transitions -1 → tid → 0 */
  int32_t tib_errno;              /* 0x3c */
  uint64_t tib_flags;             /* 0x40 */
  int tib_ftrace;                 /* inherited */
  int tib_strace;                 /* inherited */
  _Atomic(uint64_t) tib_sigmask;  /* inherited */
  _Atomic(uint64_t) tib_sigpending;
  _Atomic(uint64_t) tib_syshand; /* win32=kThread, xnusilicon=pthread_t */
  char *tib_sigstack_addr;
  uint32_t tib_sigstack_size;
  uint32_t tib_sigstack_flags;
  void **tib_keys;
  void *tib_nsync;
  void *tib_todo[7];
} __attribute__((__aligned__(64)));

extern int __threaded;
extern char __tls_morphed;
extern unsigned __tls_index;

char *_mktls(struct CosmoTib **) libcesque;
void __bootstrap_tls(struct CosmoTib *, char *) libcesque;

#ifdef __x86_64__
extern char __tls_enabled;
#define __tls_enabled_set(x) __tls_enabled = x
#elif defined(__aarch64__)
#define __tls_enabled        true
#define __tls_enabled_set(x) (void)0
#else
#error "unsupported architecture"
#endif

void __set_tls(struct CosmoTib *) libcesque;

/**
 * Returns location of thread information block.
 *
 * This can't be used in privileged functions.
 */
forceinline pureconst struct CosmoTib *__get_tls(void) {
#ifdef __chibicc__
  return 0;
#elif __x86_64__
  struct CosmoTib *__tib;
  __asm__("mov\t%%gs:0x30,%0" : "=r"(__tib));
  return __tib;
#elif defined(__aarch64__)
  register struct CosmoTib *__tls __asm__("x28");
  return __tls - 1;
#endif
}

#ifdef __x86_64__
#define __adj_tls(tib) (tib)
#elif defined(__aarch64__)
#define __adj_tls(tib) ((struct CosmoTib *)(tib) + 1)
#endif

COSMOPOLITAN_C_END_
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */


/*!BEGIN libc/tinymath/emod.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMOD_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmod()
 */
#define emod(x, y)                            \
  ({                                          \
    double __x = x;                           \
    double __y = y;                           \
    __x - fabs(__y) * floor(__x / fabs(__y)); \
  })



/*!BEGIN libc/tinymath/emodl.h */

#define COSMOPOLITAN_LIBC_TINYMATH_EMODL_H_

/**
 * Returns Euclidean floating-point division remainder.
 *
 * @return (𝑥 mod 𝑦) ∈ [0.,𝑦)
 * @see fmodl()
 */
#define emodl(x, y)                              \
  ({                                             \
    long double __x = x;                         \
    long double __y = y;                         \
    __x - fabsl(__y) * floorl(__x / fabsl(__y)); \
  })



/*!BEGIN libc/tinymath/magicu.h */

#define COSMOPOLITAN_LIBC_TINYMATH_MAGICU_H_
COSMOPOLITAN_C_START_

struct magicu {
  uint32_t M;
  uint32_t s;
};

struct magicu __magicu_get(uint32_t);

/**
 * Performs fast division using precomputed magic for constant divisor.
 *
 * @param x is unsigned integer that shall be divided
 * @param d should be `__magicu_get(y)` if computing `x / y`
 * @return result of unsigned integer division
 */
forceinline uint32_t __magicu_div(uint32_t x, struct magicu d) {
  return ((((uint64_t)x * d.M) >> 32) + ((d.s & 64) ? x : 0)) >> (d.s & 63);
}

/**
 * Checks if 𝑑 contains a valid initialized divisor.
 */
static inline bool32 __magicu_valid(struct magicu d) {
  if (!d.M && !d.s) return false;     /* uninitialized */
  if (d.s & ~(64 | 63)) return false; /* corrupted */
  return true;
}

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/x.h */

#ifndef COSMOPOLITAN_LIBC_X_H_
#define COSMOPOLITAN_LIBC_X_H_

#define xwrite        __xwrite
#define xdie          __xdie
#define xmalloc       __xmalloc
#define xrealloc      __xrealloc
#define xcalloc       __xcalloc
#define xvalloc       __xvalloc
#define xmemalign     __xmemalign
#define xmemalignzero __xmemalignzero
#define xstrdup       __xstrdup
#define xstrndup      __xstrndup
#define xstrmul       __xstrmul
#define xinet_ntop    __xinet_ntop
#define xunbinga      __xunbinga
#define xunbing       __xunbing
#define utf8to16      __utf8to16
#define utf16to8      __utf16to8
#define utf8to32      __utf8to32
#define utf16to32     __utf16to32
#define utf32to8      __utf32to8
#define xhomedir      __xhomedir
#define xstripext     __xstripext
#define xstripexts    __xstripexts
#define xload         __xload
#define rmrf          __rmrf
#define xbasename     __xbasename
#define xdirname      __xdirname
#define xjoinpaths    __xjoinpaths
#define xfixpath      __xfixpath
#define xslurp        __xslurp
#define xbarf         __xbarf

COSMOPOLITAN_C_START_

int xwrite(int, const void *, uint64_t);
void xdie(void) wontreturn;
char *xdtoa(double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoaf(float)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdtoal(long double)
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmalloc(size_t) attributeallocsize((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xrealloc(void *, size_t)
    attributeallocsize((2)) dontthrow dontcallback __wur;
void *xcalloc(size_t, size_t) attributeallocsize((1, 2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xvalloc(size_t) attributeallocsize((1)) returnsaligned((65536))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalign(size_t, size_t) attributeallocalign((1)) attributeallocsize((2))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xmemalignzero(size_t, size_t) attributeallocalign((1))
    attributeallocsize((2))
        returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrdup(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrndup(const char *, size_t) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xstrcat(const char *, ...) paramsnonnull((1)) nullterminated()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
#define xstrcat(...) (xstrcat)(__VA_ARGS__, NULL)
char *xstrmul(const char *, size_t) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xinet_ntop(int, const void *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void *xunbinga(size_t, const char16_t *)
    attributeallocalign((1)) returnspointerwithnoaliases dontthrow dontcallback
    __wur returnsnonnull dontthrow dontcallback __wur returnsnonnull;
void *xunbing(const char16_t *)
    returnspointerwithnoaliases dontthrow dontcallback __wur
    returnsnonnull dontthrow dontcallback __wur returnsnonnull;
char16_t *utf8to16(const char *, size_t, size_t *) __wur;
char *utf16to8(const char16_t *, size_t, size_t *) __wur;
wchar_t *utf8to32(const char *, size_t, size_t *) __wur;
wchar_t *utf16to32(const char16_t *, size_t, size_t *) __wur;
char *utf32to8(const wchar_t *, size_t, size_t *) __wur;
char *xhomedir(void) __wur;
char *xstripext(const char *) __wur;
char *xstripexts(const char *) __wur;
void *xload(_Atomic(void *) *, const void *, size_t, size_t);
int rmrf(const char *);
char *xbasename(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xdirname(const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xjoinpaths(const char *, const char *) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
void xfixpath(void);
void *xslurp(const char *, size_t *)
    paramsnonnull((1)) returnspointerwithnoaliases returnsaligned((4096)) __wur;
int xbarf(const char *, const void *, size_t);

COSMOPOLITAN_C_END_
#endif /* COSMOPOLITAN_LIBC_X_H_ */


/*!BEGIN libc/x/xasprintf.h */

#define COSMOPOLITAN_LIBC_X_XASPRINTF_H_
COSMOPOLITAN_C_START_

char *xasprintf(const char *, ...) paramsnonnull((1))
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;
char *xvasprintf(const char *, va_list) paramsnonnull()
    returnspointerwithnoaliases dontthrow dontcallback __wur returnsnonnull;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xgetline.h */

#define COSMOPOLITAN_LIBC_X_XGETLINE_H_
COSMOPOLITAN_C_START_

char *xgetline(FILE *) paramsnonnull() mallocesque;

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xsigaction.h */

#define COSMOPOLITAN_LIBC_X_XSIGACTION_H_
COSMOPOLITAN_C_START_

int xsigaction(int, void *, uint64_t, uint64_t, struct sigaction *);

COSMOPOLITAN_C_END_


/*!BEGIN libc/x/xspawn.h */

#define COSMOPOLITAN_LIBC_X_XSPAWN_H_
COSMOPOLITAN_C_START_

int xspawn(struct rusage *);
int xvspawn(void (*)(void *), void *, struct rusage *) returnstwice;

COSMOPOLITAN_C_END_


/*!BEGIN net/http/csscolor.h */

#define COSMOPOLITAN_NET_HTTP_CSSCOLOR_H_

#define ALICEBLUE            0xFFFFF8F0u
#define ANTIQUEWHITE         0xFFD7EBFAu
#define ANTIQUEWHITE1        0xFFDBEFFFu
#define ANTIQUEWHITE2        0xFFCCDFEEu
#define ANTIQUEWHITE3        0xFFB0C0CDu
#define ANTIQUEWHITE4        0xFF78838Bu
#define AQUAMARINE           0xFFD4FF7Fu
#define AQUAMARINE1          0xFFD4FF7Fu
#define AQUAMARINE2          0xFFC6EE76u
#define AQUAMARINE3          0xFFAACD66u
#define AQUAMARINE4          0xFF748B45u
#define AZURE                0xFFFFFFF0u
#define AZURE1               0xFFFFFFF0u
#define AZURE2               0xFFEEEEE0u
#define AZURE3               0xFFCDCDC1u
#define AZURE4               0xFF8B8B83u
#define BEIGE                0xFFDCF5F5u
#define BISQUE               0xFFC4E4FFu
#define BISQUE1              0xFFC4E4FFu
#define BISQUE2              0xFFB7D5EEu
#define BISQUE3              0xFF9EB7CDu
#define BISQUE4              0xFF6B7D8Bu
#define BLACK                0xFF000000u
#define BLANCHEDALMOND       0xFFCDEBFFu
#define BLUE                 0xFFFF0000u
#define BLUE1                0xFFFF0000u
#define BLUE2                0xFFEE0000u
#define BLUE3                0xFFCD0000u
#define BLUE4                0xFF8B0000u
#define BLUEVIOLET           0xFFE22B8Au
#define BROWN                0xFF2A2AA5u
#define BROWN1               0xFF4040FFu
#define BROWN2               0xFF3B3BEEu
#define BROWN3               0xFF3333CDu
#define BROWN4               0xFF23238Bu
#define BURLYWOOD            0xFF87B8DEu
#define BURLYWOOD1           0xFF9BD3FFu
#define BURLYWOOD2           0xFF91C5EEu
#define BURLYWOOD3           0xFF7DAACDu
#define BURLYWOOD4           0xFF55738Bu
#define CADETBLUE            0xFFA09E5Fu
#define CADETBLUE1           0xFFFFF598u
#define CADETBLUE2           0xFFEEE58Eu
#define CADETBLUE3           0xFFCDC57Au
#define CADETBLUE4           0xFF8B8653u
#define CHARTREUSE           0xFF00FF7Fu
#define CHARTREUSE1          0xFF00FF7Fu
#define CHARTREUSE2          0xFF00EE76u
#define CHARTREUSE3          0xFF00CD66u
#define CHARTREUSE4          0xFF008B45u
#define CHOCOLATE            0xFF1E69D2u
#define CHOCOLATE1           0xFF247FFFu
#define CHOCOLATE2           0xFF2176EEu
#define CHOCOLATE3           0xFF1D66CDu
#define CHOCOLATE4           0xFF13458Bu
#define CORAL                0xFF507FFFu
#define CORAL1               0xFF5672FFu
#define CORAL2               0xFF506AEEu
#define CORAL3               0xFF455BCDu
#define CORAL4               0xFF2F3E8Bu
#define CORNFLOWERBLUE       0xFFED9564u
#define CORNSILK             0xFFDCF8FFu
#define CORNSILK1            0xFFDCF8FFu
#define CORNSILK2            0xFFCDE8EEu
#define CORNSILK3            0xFFB1C8CDu
#define CORNSILK4            0xFF78888Bu
#define CYAN                 0xFFFFFF00u
#define CYAN1                0xFFFFFF00u
#define CYAN2                0xFFEEEE00u
#define CYAN3                0xFFCDCD00u
#define CYAN4                0xFF8B8B00u
#define DARKBLUE             0xFF8B0000u
#define DARKCYAN             0xFF8B8B00u
#define DARKGOLDENROD        0xFF0B86B8u
#define DARKGOLDENROD1       0xFF0FB9FFu
#define DARKGOLDENROD2       0xFF0EADEEu
#define DARKGOLDENROD3       0xFF0C95CDu
#define DARKGOLDENROD4       0xFF08658Bu
#define DARKGRAY             0xFFA9A9A9u
#define DARKGREEN            0xFF006400u
#define DARKGREY             0xFFA9A9A9u
#define DARKKHAKI            0xFF6BB7BDu
#define DARKMAGENTA          0xFF8B008Bu
#define DARKOLIVEGREEN       0xFF2F6B55u
#define DARKOLIVEGREEN1      0xFF70FFCAu
#define DARKOLIVEGREEN2      0xFF68EEBCu
#define DARKOLIVEGREEN3      0xFF5ACDA2u
#define DARKOLIVEGREEN4      0xFF3D8B6Eu
#define DARKORANGE           0xFF008CFFu
#define DARKORANGE1          0xFF007FFFu
#define DARKORANGE2          0xFF0076EEu
#define DARKORANGE3          0xFF0066CDu
#define DARKORANGE4          0xFF00458Bu
#define DARKORCHID           0xFFCC3299u
#define DARKORCHID1          0xFFFF3EBFu
#define DARKORCHID2          0xFFEE3AB2u
#define DARKORCHID3          0xFFCD329Au
#define DARKORCHID4          0xFF8B2268u
#define DARKRED              0xFF00008Bu
#define DARKSALMON           0xFF7A96E9u
#define DARKSEAGREEN         0xFF8FBC8Fu
#define DARKSEAGREEN1        0xFFC1FFC1u
#define DARKSEAGREEN2        0xFFB4EEB4u
#define DARKSEAGREEN3        0xFF9BCD9Bu
#define DARKSEAGREEN4        0xFF698B69u
#define DARKSLATEBLUE        0xFF8B3D48u
#define DARKSLATEGRAY        0xFF4F4F2Fu
#define DARKSLATEGRAY1       0xFFFFFF97u
#define DARKSLATEGRAY2       0xFFEEEE8Du
#define DARKSLATEGRAY3       0xFFCDCD79u
#define DARKSLATEGRAY4       0xFF8B8B52u
#define DARKSLATEGREY        0xFF4F4F2Fu
#define DARKTURQUOISE        0xFFD1CE00u
#define DARKVIOLET           0xFFD30094u
#define DEEPPINK             0xFF9314FFu
#define DEEPPINK1            0xFF9314FFu
#define DEEPPINK2            0xFF8912EEu
#define DEEPPINK3            0xFF7610CDu
#define DEEPPINK4            0xFF500A8Bu
#define DEEPSKYBLUE          0xFFFFBF00u
#define DEEPSKYBLUE1         0xFFFFBF00u
#define DEEPSKYBLUE2         0xFFEEB200u
#define DEEPSKYBLUE3         0xFFCD9A00u
#define DEEPSKYBLUE4         0xFF8B6800u
#define DIMGRAY              0xFF696969u
#define DIMGREY              0xFF696969u
#define DODGERBLUE           0xFFFF901Eu
#define DODGERBLUE1          0xFFFF901Eu
#define DODGERBLUE2          0xFFEE861Cu
#define DODGERBLUE3          0xFFCD7418u
#define DODGERBLUE4          0xFF8B4E10u
#define FIREBRICK            0xFF2222B2u
#define FIREBRICK1           0xFF3030FFu
#define FIREBRICK2           0xFF2C2CEEu
#define FIREBRICK3           0xFF2626CDu
#define FIREBRICK4           0xFF1A1A8Bu
#define FLORALWHITE          0xFFF0FAFFu
#define FORESTGREEN          0xFF228B22u
#define GAINSBORO            0xFFDCDCDCu
#define GHOSTWHITE           0xFFFFF8F8u
#define GOLD                 0xFF00D7FFu
#define GOLD1                0xFF00D7FFu
#define GOLD2                0xFF00C9EEu
#define GOLD3                0xFF00ADCDu
#define GOLD4                0xFF00758Bu
#define GOLDENROD            0xFF20A5DAu
#define GOLDENROD1           0xFF25C1FFu
#define GOLDENROD2           0xFF22B4EEu
#define GOLDENROD3           0xFF1D9BCDu
#define GOLDENROD4           0xFF14698Bu
#define GRAY                 0xFFBEBEBEu
#define GRAY0                0xFF000000u
#define GRAY1                0xFF030303u
#define GRAY10               0xFF1A1A1Au
#define GRAY100              0xFFFFFFFFu
#define GRAY11               0xFF1C1C1Cu
#define GRAY12               0xFF1F1F1Fu
#define GRAY13               0xFF212121u
#define GRAY14               0xFF242424u
#define GRAY15               0xFF262626u
#define GRAY16               0xFF292929u
#define GRAY17               0xFF2B2B2Bu
#define GRAY18               0xFF2E2E2Eu
#define GRAY19               0xFF303030u
#define GRAY2                0xFF050505u
#define GRAY20               0xFF333333u
#define GRAY21               0xFF363636u
#define GRAY22               0xFF383838u
#define GRAY23               0xFF3B3B3Bu
#define GRAY24               0xFF3D3D3Du
#define GRAY25               0xFF404040u
#define GRAY26               0xFF424242u
#define GRAY27               0xFF454545u
#define GRAY28               0xFF474747u
#define GRAY29               0xFF4A4A4Au
#define GRAY3                0xFF080808u
#define GRAY30               0xFF4D4D4Du
#define GRAY31               0xFF4F4F4Fu
#define GRAY32               0xFF525252u
#define GRAY33               0xFF545454u
#define GRAY34               0xFF575757u
#define GRAY35               0xFF595959u
#define GRAY36               0xFF5C5C5Cu
#define GRAY37               0xFF5E5E5Eu
#define GRAY38               0xFF616161u
#define GRAY39               0xFF636363u
#define GRAY4                0xFF0A0A0Au
#define GRAY40               0xFF666666u
#define GRAY41               0xFF696969u
#define GRAY42               0xFF6B6B6Bu
#define GRAY43               0xFF6E6E6Eu
#define GRAY44               0xFF707070u
#define GRAY45               0xFF737373u
#define GRAY46               0xFF757575u
#define GRAY47               0xFF787878u
#define GRAY48               0xFF7A7A7Au
#define GRAY49               0xFF7D7D7Du
#define GRAY5                0xFF0D0D0Du
#define GRAY50               0xFF7F7F7Fu
#define GRAY51               0xFF828282u
#define GRAY52               0xFF858585u
#define GRAY53               0xFF878787u
#define GRAY54               0xFF8A8A8Au
#define GRAY55               0xFF8C8C8Cu
#define GRAY56               0xFF8F8F8Fu
#define GRAY57               0xFF919191u
#define GRAY58               0xFF949494u
#define GRAY59               0xFF969696u
#define GRAY6                0xFF0F0F0Fu
#define GRAY60               0xFF999999u
#define GRAY61               0xFF9C9C9Cu
#define GRAY62               0xFF9E9E9Eu
#define GRAY63               0xFFA1A1A1u
#define GRAY64               0xFFA3A3A3u
#define GRAY65               0xFFA6A6A6u
#define GRAY66               0xFFA8A8A8u
#define GRAY67               0xFFABABABu
#define GRAY68               0xFFADADADu
#define GRAY69               0xFFB0B0B0u
#define GRAY7                0xFF121212u
#define GRAY70               0xFFB3B3B3u
#define GRAY71               0xFFB5B5B5u
#define GRAY72               0xFFB8B8B8u
#define GRAY73               0xFFBABABAu
#define GRAY74               0xFFBDBDBDu
#define GRAY75               0xFFBFBFBFu
#define GRAY76               0xFFC2C2C2u
#define GRAY77               0xFFC4C4C4u
#define GRAY78               0xFFC7C7C7u
#define GRAY79               0xFFC9C9C9u
#define GRAY8                0xFF141414u
#define GRAY80               0xFFCCCCCCu
#define GRAY81               0xFFCFCFCFu
#define GRAY82               0xFFD1D1D1u
#define GRAY83               0xFFD4D4D4u
#define GRAY84               0xFFD6D6D6u
#define GRAY85               0xFFD9D9D9u
#define GRAY86               0xFFDBDBDBu
#define GRAY87               0xFFDEDEDEu
#define GRAY88               0xFFE0E0E0u
#define GRAY89               0xFFE3E3E3u
#define GRAY9                0xFF171717u
#define GRAY90               0xFFE5E5E5u
#define GRAY91               0xFFE8E8E8u
#define GRAY92               0xFFEBEBEBu
#define GRAY93               0xFFEDEDEDu
#define GRAY94               0xFFF0F0F0u
#define GRAY95               0xFFF2F2F2u
#define GRAY96               0xFFF5F5F5u
#define GRAY97               0xFFF7F7F7u
#define GRAY98               0xFFFAFAFAu
#define GRAY99               0xFFFCFCFCu
#define GREEN                0xFF00FF00u
#define GREEN1               0xFF00FF00u
#define GREEN2               0xFF00EE00u
#define GREEN3               0xFF00CD00u
#define GREEN4               0xFF008B00u
#define GREENYELLOW          0xFF2FFFADu
#define GREY                 0xFFBEBEBEu
#define GREY0                0xFF000000u
#define GREY1                0xFF030303u
#define GREY10               0xFF1A1A1Au
#define GREY100              0xFFFFFFFFu
#define GREY11               0xFF1C1C1Cu
#define GREY12               0xFF1F1F1Fu
#define GREY13               0xFF212121u
#define GREY14               0xFF242424u
#define GREY15               0xFF262626u
#define GREY16               0xFF292929u
#define GREY17               0xFF2B2B2Bu
#define GREY18               0xFF2E2E2Eu
#define GREY19               0xFF303030u
#define GREY2                0xFF050505u
#define GREY20               0xFF333333u
#define GREY21               0xFF363636u
#define GREY22               0xFF383838u
#define GREY23               0xFF3B3B3Bu
#define GREY24               0xFF3D3D3Du
#define GREY25               0xFF404040u
#define GREY26               0xFF424242u
#define GREY27               0xFF454545u
#define GREY28               0xFF474747u
#define GREY29               0xFF4A4A4Au
#define GREY3                0xFF080808u
#define GREY30               0xFF4D4D4Du
#define GREY31               0xFF4F4F4Fu
#define GREY32               0xFF525252u
#define GREY33               0xFF545454u
#define GREY34               0xFF575757u
#define GREY35               0xFF595959u
#define GREY36               0xFF5C5C5Cu
#define GREY37               0xFF5E5E5Eu
#define GREY38               0xFF616161u
#define GREY39               0xFF636363u
#define GREY4                0xFF0A0A0Au
#define GREY40               0xFF666666u
#define GREY41               0xFF696969u
#define GREY42               0xFF6B6B6Bu
#define GREY43               0xFF6E6E6Eu
#define GREY44               0xFF707070u
#define GREY45               0xFF737373u
#define GREY46               0xFF757575u
#define GREY47               0xFF787878u
#define GREY48               0xFF7A7A7Au
#define GREY49               0xFF7D7D7Du
#define GREY5                0xFF0D0D0Du
#define GREY50               0xFF7F7F7Fu
#define GREY51               0xFF828282u
#define GREY52               0xFF858585u
#define GREY53               0xFF878787u
#define GREY54               0xFF8A8A8Au
#define GREY55               0xFF8C8C8Cu
#define GREY56               0xFF8F8F8Fu
#define GREY57               0xFF919191u
#define GREY58               0xFF949494u
#define GREY59               0xFF969696u
#define GREY6                0xFF0F0F0Fu
#define GREY60               0xFF999999u
#define GREY61               0xFF9C9C9Cu
#define GREY62               0xFF9E9E9Eu
#define GREY63               0xFFA1A1A1u
#define GREY64               0xFFA3A3A3u
#define GREY65               0xFFA6A6A6u
#define GREY66               0xFFA8A8A8u
#define GREY67               0xFFABABABu
#define GREY68               0xFFADADADu
#define GREY69               0xFFB0B0B0u
#define GREY7                0xFF121212u
#define GREY70               0xFFB3B3B3u
#define GREY71               0xFFB5B5B5u
#define GREY72               0xFFB8B8B8u
#define GREY73               0xFFBABABAu
#define GREY74               0xFFBDBDBDu
#define GREY75               0xFFBFBFBFu
#define GREY76               0xFFC2C2C2u
#define GREY77               0xFFC4C4C4u
#define GREY78               0xFFC7C7C7u
#define GREY79               0xFFC9C9C9u
#define GREY8                0xFF141414u
#define GREY80               0xFFCCCCCCu
#define GREY81               0xFFCFCFCFu
#define GREY82               0xFFD1D1D1u
#define GREY83               0xFFD4D4D4u
#define GREY84               0xFFD6D6D6u
#define GREY85               0xFFD9D9D9u
#define GREY86               0xFFDBDBDBu
#define GREY87               0xFFDEDEDEu
#define GREY88               0xFFE0E0E0u
#define GREY89               0xFFE3E3E3u
#define GREY9                0xFF171717u
#define GREY90               0xFFE5E5E5u
#define GREY91               0xFFE8E8E8u
#define GREY92               0xFFEBEBEBu
#define GREY93               0xFFEDEDEDu
#define GREY94               0xFFF0F0F0u
#define GREY95               0xFFF2F2F2u
#define GREY96               0xFFF5F5F5u
#define GREY97               0xFFF7F7F7u
#define GREY98               0xFFFAFAFAu
#define GREY99               0xFFFCFCFCu
#define HONEYDEW             0xFFF0FFF0u
#define HONEYDEW1            0xFFF0FFF0u
#define HONEYDEW2            0xFFE0EEE0u
#define HONEYDEW3            0xFFC1CDC1u
#define HONEYDEW4            0xFF838B83u
#define HOTPINK              0xFFB469FFu
#define HOTPINK1             0xFFB46EFFu
#define HOTPINK2             0xFFA76AEEu
#define HOTPINK3             0xFF9060CDu
#define HOTPINK4             0xFF623A8Bu
#define INDIANRED            0xFF5C5CCDu
#define INDIANRED1           0xFF6A6AFFu
#define INDIANRED2           0xFF6363EEu
#define INDIANRED3           0xFF5555CDu
#define INDIANRED4           0xFF3A3A8Bu
#define IVORY                0xFFF0FFFFu
#define IVORY1               0xFFF0FFFFu
#define IVORY2               0xFFE0EEEEu
#define IVORY3               0xFFC1CDCDu
#define IVORY4               0xFF838B8Bu
#define KHAKI                0xFF8CE6F0u
#define KHAKI1               0xFF8FF6FFu
#define KHAKI2               0xFF85E6EEu
#define KHAKI3               0xFF73C6CDu
#define KHAKI4               0xFF4E868Bu
#define LAVENDER             0xFFFAE6E6u
#define LAVENDERBLUSH        0xFFF5F0FFu
#define LAVENDERBLUSH1       0xFFF5F0FFu
#define LAVENDERBLUSH2       0xFFE5E0EEu
#define LAVENDERBLUSH3       0xFFC5C1CDu
#define LAVENDERBLUSH4       0xFF86838Bu
#define LAWNGREEN            0xFF00FC7Cu
#define LEMONCHIFFON         0xFFCDFAFFu
#define LEMONCHIFFON1        0xFFCDFAFFu
#define LEMONCHIFFON2        0xFFBFE9EEu
#define LEMONCHIFFON3        0xFFA5C9CDu
#define LEMONCHIFFON4        0xFF70898Bu
#define LIGHTBLUE            0xFFE6D8ADu
#define LIGHTBLUE1           0xFFFFEFBFu
#define LIGHTBLUE2           0xFFEEDFB2u
#define LIGHTBLUE3           0xFFCDC09Au
#define LIGHTBLUE4           0xFF8B8368u
#define LIGHTCORAL           0xFF8080F0u
#define LIGHTCYAN            0xFFFFFFE0u
#define LIGHTCYAN1           0xFFFFFFE0u
#define LIGHTCYAN2           0xFFEEEED1u
#define LIGHTCYAN3           0xFFCDCDB4u
#define LIGHTCYAN4           0xFF8B8B7Au
#define LIGHTGOLDENROD       0xFF82DDEEu
#define LIGHTGOLDENROD1      0xFF8BECFFu
#define LIGHTGOLDENROD2      0xFF82DCEEu
#define LIGHTGOLDENROD3      0xFF70BECDu
#define LIGHTGOLDENROD4      0xFF4C818Bu
#define LIGHTGOLDENRODYELLOW 0xFFD2FAFAu
#define LIGHTGRAY            0xFFD3D3D3u
#define LIGHTGREEN           0xFF90EE90u
#define LIGHTGREY            0xFFD3D3D3u
#define LIGHTPINK            0xFFC1B6FFu
#define LIGHTPINK1           0xFFB9AEFFu
#define LIGHTPINK2           0xFFADA2EEu
#define LIGHTPINK3           0xFF958CCDu
#define LIGHTPINK4           0xFF655F8Bu
#define LIGHTSALMON          0xFF7AA0FFu
#define LIGHTSALMON1         0xFF7AA0FFu
#define LIGHTSALMON2         0xFF7295EEu
#define LIGHTSALMON3         0xFF6281CDu
#define LIGHTSALMON4         0xFF42578Bu
#define LIGHTSEAGREEN        0xFFAAB220u
#define LIGHTSKYBLUE         0xFFFACE87u
#define LIGHTSKYBLUE1        0xFFFFE2B0u
#define LIGHTSKYBLUE2        0xFFEED3A4u
#define LIGHTSKYBLUE3        0xFFCDB68Du
#define LIGHTSKYBLUE4        0xFF8B7B60u
#define LIGHTSLATEBLUE       0xFFFF7084u
#define LIGHTSLATEGRAY       0xFF998877u
#define LIGHTSLATEGREY       0xFF998877u
#define LIGHTSTEELBLUE       0xFFDEC4B0u
#define LIGHTSTEELBLUE1      0xFFFFE1CAu
#define LIGHTSTEELBLUE2      0xFFEED2BCu
#define LIGHTSTEELBLUE3      0xFFCDB5A2u
#define LIGHTSTEELBLUE4      0xFF8B7B6Eu
#define LIGHTYELLOW          0xFFE0FFFFu
#define LIGHTYELLOW1         0xFFE0FFFFu
#define LIGHTYELLOW2         0xFFD1EEEEu
#define LIGHTYELLOW3         0xFFB4CDCDu
#define LIGHTYELLOW4         0xFF7A8B8Bu
#define LIMEGREEN            0xFF32CD32u
#define LINEN                0xFFE6F0FAu
#define MAGENTA              0xFFFF00FFu
#define MAGENTA1             0xFFFF00FFu
#define MAGENTA2             0xFFEE00EEu
#define MAGENTA3             0xFFCD00CDu
#define MAGENTA4             0xFF8B008Bu
#define MAROON               0xFF6030B0u
#define MAROON1              0xFFB334FFu
#define MAROON2              0xFFA730EEu
#define MAROON3              0xFF9029CDu
#define MAROON4              0xFF621C8Bu
#define MEDIUMAQUAMARINE     0xFFAACD66u
#define MEDIUMBLUE           0xFFCD0000u
#define MEDIUMORCHID         0xFFD355BAu
#define MEDIUMORCHID1        0xFFFF66E0u
#define MEDIUMORCHID2        0xFFEE5FD1u
#define MEDIUMORCHID3        0xFFCD52B4u
#define MEDIUMORCHID4        0xFF8B377Au
#define MEDIUMPURPLE         0xFFDB7093u
#define MEDIUMPURPLE1        0xFFFF82ABu
#define MEDIUMPURPLE2        0xFFEE799Fu
#define MEDIUMPURPLE3        0xFFCD6889u
#define MEDIUMPURPLE4        0xFF8B475Du
#define MEDIUMSEAGREEN       0xFF71B33Cu
#define MEDIUMSLATEBLUE      0xFFEE687Bu
#define MEDIUMSPRINGGREEN    0xFF9AFA00u
#define MEDIUMTURQUOISE      0xFFCCD148u
#define MEDIUMVIOLETRED      0xFF8515C7u
#define MIDNIGHTBLUE         0xFF701919u
#define MINTCREAM            0xFFFAFFF5u
#define MISTYROSE            0xFFE1E4FFu
#define MISTYROSE1           0xFFE1E4FFu
#define MISTYROSE2           0xFFD2D5EEu
#define MISTYROSE3           0xFFB5B7CDu
#define MISTYROSE4           0xFF7B7D8Bu
#define MOCCASIN             0xFFB5E4FFu
#define NAVAJOWHITE          0xFFADDEFFu
#define NAVAJOWHITE1         0xFFADDEFFu
#define NAVAJOWHITE2         0xFFA1CFEEu
#define NAVAJOWHITE3         0xFF8BB3CDu
#define NAVAJOWHITE4         0xFF5E798Bu
#define NAVY                 0xFF800000u
#define NAVYBLUE             0xFF800000u
#define OLDLACE              0xFFE6F5FDu
#define OLIVEDRAB            0xFF238E6Bu
#define OLIVEDRAB1           0xFF3EFFC0u
#define OLIVEDRAB2           0xFF3AEEB3u
#define OLIVEDRAB3           0xFF32CD9Au
#define OLIVEDRAB4           0xFF228B69u
#define ORANGE               0xFF00A5FFu
#define ORANGE1              0xFF00A5FFu
#define ORANGE2              0xFF009AEEu
#define ORANGE3              0xFF0085CDu
#define ORANGE4              0xFF005A8Bu
#define ORANGERED            0xFF0045FFu
#define ORANGERED1           0xFF0045FFu
#define ORANGERED2           0xFF0040EEu
#define ORANGERED3           0xFF0037CDu
#define ORANGERED4           0xFF00258Bu
#define ORCHID               0xFFD670DAu
#define ORCHID1              0xFFFA83FFu
#define ORCHID2              0xFFE97AEEu
#define ORCHID3              0xFFC969CDu
#define ORCHID4              0xFF89478Bu
#define PALEGOLDENROD        0xFFAAE8EEu
#define PALEGREEN            0xFF98FB98u
#define PALEGREEN1           0xFF9AFF9Au
#define PALEGREEN2           0xFF90EE90u
#define PALEGREEN3           0xFF7CCD7Cu
#define PALEGREEN4           0xFF548B54u
#define PALETURQUOISE        0xFFEEEEAFu
#define PALETURQUOISE1       0xFFFFFFBBu
#define PALETURQUOISE2       0xFFEEEEAEu
#define PALETURQUOISE3       0xFFCDCD96u
#define PALETURQUOISE4       0xFF8B8B66u
#define PALEVIOLETRED        0xFF9370DBu
#define PALEVIOLETRED1       0xFFAB82FFu
#define PALEVIOLETRED2       0xFF9F79EEu
#define PALEVIOLETRED3       0xFF8968CDu
#define PALEVIOLETRED4       0xFF5D478Bu
#define PAPAYAWHIP           0xFFD5EFFFu
#define PEACHPUFF            0xFFB9DAFFu
#define PEACHPUFF1           0xFFB9DAFFu
#define PEACHPUFF2           0xFFADCBEEu
#define PEACHPUFF3           0xFF95AFCDu
#define PEACHPUFF4           0xFF65778Bu
#define PERU                 0xFF3F85CDu
#define PINK                 0xFFCBC0FFu
#define PINK1                0xFFC5B5FFu
#define PINK2                0xFFB8A9EEu
#define PINK3                0xFF9E91CDu
#define PINK4                0xFF6C638Bu
#define PLUM                 0xFFDDA0DDu
#define PLUM1                0xFFFFBBFFu
#define PLUM2                0xFFEEAEEEu
#define PLUM3                0xFFCD96CDu
#define PLUM4                0xFF8B668Bu
#define POWDERBLUE           0xFFE6E0B0u
#define PURPLE               0xFFF020A0u
#define PURPLE1              0xFFFF309Bu
#define PURPLE2              0xFFEE2C91u
#define PURPLE3              0xFFCD267Du
#define PURPLE4              0xFF8B1A55u
#define RED                  0xFF0000FFu
#define RED1                 0xFF0000FFu
#define RED2                 0xFF0000EEu
#define RED3                 0xFF0000CDu
#define RED4                 0xFF00008Bu
#define ROSYBROWN            0xFF8F8FBCu
#define ROSYBROWN1           0xFFC1C1FFu
#define ROSYBROWN2           0xFFB4B4EEu
#define ROSYBROWN3           0xFF9B9BCDu
#define ROSYBROWN4           0xFF69698Bu
#define ROYALBLUE            0xFFE16941u
#define ROYALBLUE1           0xFFFF7648u
#define ROYALBLUE2           0xFFEE6E43u
#define ROYALBLUE3           0xFFCD5F3Au
#define ROYALBLUE4           0xFF8B4027u
#define SADDLEBROWN          0xFF13458Bu
#define SALMON               0xFF7280FAu
#define SALMON1              0xFF698CFFu
#define SALMON2              0xFF6282EEu
#define SALMON3              0xFF5470CDu
#define SALMON4              0xFF394C8Bu
#define SANDYBROWN           0xFF60A4F4u
#define SEAGREEN             0xFF578B2Eu
#define SEAGREEN1            0xFF9FFF54u
#define SEAGREEN2            0xFF94EE4Eu
#define SEAGREEN3            0xFF80CD43u
#define SEAGREEN4            0xFF578B2Eu
#define SEASHELL             0xFFEEF5FFu
#define SEASHELL1            0xFFEEF5FFu
#define SEASHELL2            0xFFDEE5EEu
#define SEASHELL3            0xFFBFC5CDu
#define SEASHELL4            0xFF82868Bu
#define SIENNA               0xFF2D52A0u
#define SIENNA1              0xFF4782FFu
#define SIENNA2              0xFF4279EEu
#define SIENNA3              0xFF3968CDu
#define SIENNA4              0xFF26478Bu
#define SKYBLUE              0xFFEBCE87u
#define SKYBLUE1             0xFFFFCE87u
#define SKYBLUE2             0xFFEEC07Eu
#define SKYBLUE3             0xFFCDA66Cu
#define SKYBLUE4             0xFF8B704Au
#define SLATEBLUE            0xFFCD5A6Au
#define SLATEBLUE1           0xFFFF6F83u
#define SLATEBLUE2           0xFFEE677Au
#define SLATEBLUE3           0xFFCD5969u
#define SLATEBLUE4           0xFF8B3C47u
#define SLATEGRAY            0xFF908070u
#define SLATEGRAY1           0xFFFFE2C6u
#define SLATEGRAY2           0xFFEED3B9u
#define SLATEGRAY3           0xFFCDB69Fu
#define SLATEGRAY4           0xFF8B7B6Cu
#define SLATEGREY            0xFF908070u
#define SNOW                 0xFFFAFAFFu
#define SNOW1                0xFFFAFAFFu
#define SNOW2                0xFFE9E9EEu
#define SNOW3                0xFFC9C9CDu
#define SNOW4                0xFF89898Bu
#define SPRINGGREEN          0xFF7FFF00u
#define SPRINGGREEN1         0xFF7FFF00u
#define SPRINGGREEN2         0xFF76EE00u
#define SPRINGGREEN3         0xFF66CD00u
#define SPRINGGREEN4         0xFF458B00u
#define STEELBLUE            0xFFB48246u
#define STEELBLUE1           0xFFFFB863u
#define STEELBLUE2           0xFFEEAC5Cu
#define STEELBLUE3           0xFFCD944Fu
#define STEELBLUE4           0xFF8B6436u
#define TAN                  0xFF8CB4D2u
#define TAN1                 0xFF4FA5FFu
#define TAN2                 0xFF499AEEu
#define TAN3                 0xFF3F85CDu
#define TAN4                 0xFF2B5A8Bu
#define THISTLE              0xFFD8BFD8u
#define THISTLE1             0xFFFFE1FFu
#define THISTLE2             0xFFEED2EEu
#define THISTLE3             0xFFCDB5CDu
#define THISTLE4             0xFF8B7B8Bu
#define TOMATO               0xFF4763FFu
#define TOMATO1              0xFF4763FFu
#define TOMATO2              0xFF425CEEu
#define TOMATO3              0xFF394FCDu
#define TOMATO4              0xFF26368Bu
#define TURQUOISE            0xFFD0E040u
#define TURQUOISE1           0xFFFFF500u
#define TURQUOISE2           0xFFEEE500u
#define TURQUOISE3           0xFFCDC500u
#define TURQUOISE4           0xFF8B8600u
#define VIOLET               0xFFEE82EEu
#define VIOLETRED            0xFF9020D0u
#define VIOLETRED1           0xFF963EFFu
#define VIOLETRED2           0xFF8C3AEEu
#define VIOLETRED3           0xFF7832CDu
#define VIOLETRED4           0xFF52228Bu
#define WHEAT                0xFFB3DEF5u
#define WHEAT1               0xFFBAE7FFu
#define WHEAT2               0xFFAED8EEu
#define WHEAT3               0xFF96BACDu
#define WHEAT4               0xFF667E8Bu
#define WHITE                0xFFFFFFFFu
#define WHITESMOKE           0xFFF5F5F5u
#define YELLOW               0xFF00FFFFu
#define YELLOW1              0xFF00FFFFu
#define YELLOW2              0xFF00EEEEu
#define YELLOW3              0xFF00CDCDu
#define YELLOW4              0xFF008B8Bu
#define YELLOWGREEN          0xFF32CD9Au



/*!BEGIN net/http/escape.h */

#define COSMOPOLITAN_NET_HTTP_ESCAPE_H_

#define kControlWs 1
#define kControlC0 2
#define kControlC1 4

COSMOPOLITAN_C_START_

extern const char kEscapeAuthority[256];
extern const char kEscapeIp[256];
extern const char kEscapePath[256];
extern const char kEscapeSegment[256];
extern const char kEscapeParam[256];
extern const char kEscapeFragment[256];

char *EscapeHtml(const char *, size_t, size_t *);
char *EscapeUrl(const char *, size_t, size_t *, const char[256]);
char *EscapeUser(const char *, size_t, size_t *);
char *EscapePass(const char *, size_t, size_t *);
char *EscapeIp(const char *, size_t, size_t *);
char *EscapeHost(const char *, size_t, size_t *);
char *EscapePath(const char *, size_t, size_t *);
char *EscapeParam(const char *, size_t, size_t *);
char *EscapeFragment(const char *, size_t, size_t *);
char *EscapeSegment(const char *, size_t, size_t *);
char *EscapeJsStringLiteral(char **, size_t *, const char *, size_t, size_t *);

ssize_t HasControlCodes(const char *, size_t, int);
char *Underlong(const char *, size_t, size_t *);
char *DecodeLatin1(const char *, size_t, size_t *);
char *EncodeLatin1(const char *, size_t, size_t *, int);
char *EncodeHttpHeaderValue(const char *, size_t, size_t *);
char *VisualizeControlCodes(const char *, size_t, size_t *);
char *IndentLines(const char *, size_t, size_t *, size_t);
char *EncodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *DecodeBase32(const char *, size_t, const char *, size_t, size_t *);
char *EncodeBase64(const char *, size_t, size_t *);
char *DecodeBase64(const char *, size_t, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/http.h */

#define COSMOPOLITAN_LIBC_HTTP_HTTP_H_

#define kHttpRequest  0
#define kHttpResponse 1

#define kHttpGet     READ32LE("GET")
#define kHttpHead    READ32LE("HEAD")
#define kHttpPost    READ32LE("POST")
#define kHttpPut     READ32LE("PUT")
#define kHttpDelete  READ64LE("DELETE\0")
#define kHttpOptions READ64LE("OPTIONS")
#define kHttpConnect READ64LE("CONNECT")
#define kHttpTrace   READ64LE("TRACE\0\0")

#define kHttpStateStart   0
#define kHttpStateMethod  1
#define kHttpStateUri     2
#define kHttpStateVersion 3
#define kHttpStateStatus  4
#define kHttpStateMessage 5
#define kHttpStateName    6
#define kHttpStateColon   7
#define kHttpStateValue   8
#define kHttpStateCr      9
#define kHttpStateLf1     10
#define kHttpStateLf2     11

#define kHttpClientStateHeaders      0
#define kHttpClientStateBody         1
#define kHttpClientStateBodyChunked  2
#define kHttpClientStateBodyLengthed 3

#define kHttpStateChunkStart   0
#define kHttpStateChunkSize    1
#define kHttpStateChunkExt     2
#define kHttpStateChunkLf1     3
#define kHttpStateChunk        4
#define kHttpStateChunkCr2     5
#define kHttpStateChunkLf2     6
#define kHttpStateTrailerStart 7
#define kHttpStateTrailer      8
#define kHttpStateTrailerLf1   9
#define kHttpStateTrailerLf2   10

#define kHttpHost                          0
#define kHttpCacheControl                  1
#define kHttpConnection                    2
#define kHttpAccept                        3
#define kHttpAcceptLanguage                4
#define kHttpAcceptEncoding                5
#define kHttpUserAgent                     6
#define kHttpReferer                       7
#define kHttpXForwardedFor                 8
#define kHttpOrigin                        9
#define kHttpUpgradeInsecureRequests       10
#define kHttpPragma                        11
#define kHttpCookie                        12
#define kHttpDnt                           13
#define kHttpSecGpc                        14
#define kHttpFrom                          15
#define kHttpIfModifiedSince               16
#define kHttpXRequestedWith                17
#define kHttpXForwardedHost                18
#define kHttpXForwardedProto               19
#define kHttpXCsrfToken                    20
#define kHttpSaveData                      21
#define kHttpRange                         22
#define kHttpContentLength                 23
#define kHttpContentType                   24
#define kHttpVary                          25
#define kHttpDate                          26
#define kHttpServer                        27
#define kHttpExpires                       28
#define kHttpContentEncoding               29
#define kHttpLastModified                  30
#define kHttpEtag                          31
#define kHttpAllow                         32
#define kHttpContentRange                  33
#define kHttpAcceptCharset                 34
#define kHttpAccessControlAllowCredentials 35
#define kHttpAccessControlAllowHeaders     36
#define kHttpAccessControlAllowMethods     37
#define kHttpAccessControlAllowOrigin      38
#define kHttpAccessControlMaxAge           39
#define kHttpAccessControlMethod           40
#define kHttpAccessControlRequestHeaders   41
#define kHttpAccessControlRequestMethod    42
#define kHttpAccessControlRequestMethods   43
#define kHttpAge                           44
#define kHttpAuthorization                 45
#define kHttpContentBase                   46
#define kHttpContentDescription            47
#define kHttpContentDisposition            48
#define kHttpContentLanguage               49
#define kHttpContentLocation               50
#define kHttpContentMd5                    51
#define kHttpExpect                        52
#define kHttpIfMatch                       53
#define kHttpIfNoneMatch                   54
#define kHttpIfRange                       55
#define kHttpIfUnmodifiedSince             56
#define kHttpKeepAlive                     57
#define kHttpLink                          58
#define kHttpLocation                      59
#define kHttpMaxForwards                   60
#define kHttpProxyAuthenticate             61
#define kHttpProxyAuthorization            62
#define kHttpProxyConnection               63
#define kHttpPublic                        64
#define kHttpRetryAfter                    65
#define kHttpTe                            66
#define kHttpTrailer                       67
#define kHttpTransferEncoding              68
#define kHttpUpgrade                       69
#define kHttpWarning                       70
#define kHttpWwwAuthenticate               71
#define kHttpVia                           72
#define kHttpStrictTransportSecurity       73
#define kHttpXFrameOptions                 74
#define kHttpXContentTypeOptions           75
#define kHttpAltSvc                        76
#define kHttpReferrerPolicy                77
#define kHttpXXssProtection                78
#define kHttpAcceptRanges                  79
#define kHttpSetCookie                     80
#define kHttpSecChUa                       81
#define kHttpSecChUaMobile                 82
#define kHttpSecFetchSite                  83
#define kHttpSecFetchMode                  84
#define kHttpSecFetchUser                  85
#define kHttpSecFetchDest                  86
#define kHttpCfRay                         87
#define kHttpCfVisitor                     88
#define kHttpCfConnectingIp                89
#define kHttpCfIpcountry                   90
#define kHttpSecChUaPlatform               91
#define kHttpCdnLoop                       92
#define kHttpHeadersMax                    93

COSMOPOLITAN_C_START_

struct HttpSlice {
  short a, b;
};

struct HttpHeader {
  struct HttpSlice k;
  struct HttpSlice v;
};

struct HttpHeaders {
  unsigned n, c;
  struct HttpHeader *p;
};

struct HttpMessage {
  int i, a, status;
  unsigned char t;
  unsigned char type;
  unsigned char version;
  uint64_t method;
  struct HttpSlice k;
  struct HttpSlice uri;
  struct HttpSlice scratch;
  struct HttpSlice message;
  struct HttpSlice headers[kHttpHeadersMax];
  struct HttpHeaders xheaders;
};

struct HttpUnchunker {
  int t;
  size_t i;
  size_t j;
  ssize_t m;
};

extern const char kHttpToken[256];
extern const bool kHttpRepeatable[kHttpHeadersMax];

const char *GetHttpReason(int);
const char *GetHttpHeaderName(int);
int GetHttpHeader(const char *, size_t);
void InitHttpMessage(struct HttpMessage *, int);
void DestroyHttpMessage(struct HttpMessage *);
int ParseHttpMessage(struct HttpMessage *, const char *, size_t);
bool HeaderHas(struct HttpMessage *, const char *, int, const char *, size_t);
int64_t ParseContentLength(const char *, size_t);
char *FormatHttpDateTime(char[hasatleast 30], struct tm *);
bool ParseHttpRange(const char *, size_t, long, long *, long *);
int64_t ParseHttpDateTime(const char *, size_t);
uint64_t ParseHttpMethod(const char *, size_t);
bool IsValidHttpToken(const char *, size_t);
bool IsValidCookieValue(const char *, size_t);
bool IsAcceptablePath(const char *, size_t);
bool IsAcceptableHost(const char *, size_t);
bool IsAcceptablePort(const char *, size_t);
bool IsReasonablePath(const char *, size_t);
int ParseForwarded(const char *, size_t, uint32_t *, uint16_t *);
bool IsMimeType(const char *, size_t, const char *);
ssize_t Unchunk(struct HttpUnchunker *, char *, size_t, size_t *);
const char *FindContentType(const char *, size_t);
bool IsNoCompressExt(const char *, size_t);
char *FoldHeader(struct HttpMessage *, const char *, int, size_t *);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/ip.h */

#define COSMOPOLITAN_NET_HTTP_IP_H_

#define kIpUnknown    0
#define kIpMulticast  1
#define kIpLoopback   2
#define kIpPrivate    3
#define kIpTestnet    4
#define kIpAfrinic    5
#define kIpLacnic     6
#define kIpApnic      7
#define kIpArin       8
#define kIpRipe       9
#define kIpDod        10
#define kIpAtt        11
#define kIpApple      12
#define kIpFord       13
#define kIpCogent     14
#define kIpPrudential 15
#define kIpUsps       16
#define kIpComcast    17
#define kIpFuture     18
#define kIpAnonymous  19

COSMOPOLITAN_C_START_

struct Cidr {
  int64_t addr;
  int cidr;
};

int64_t ParseIp(const char *, size_t);
struct Cidr ParseCidr(const char *, size_t);
bool IsDodIp(uint32_t);
bool IsArinIp(uint32_t);
bool IsRipeIp(uint32_t);
bool IsApnicIp(uint32_t);
bool IsLacnicIp(uint32_t);
bool IsPublicIp(uint32_t);
bool IsPrivateIp(uint32_t);
bool IsAfrinicIp(uint32_t);
bool IsTestnetIp(uint32_t);
bool IsLoopbackIp(uint32_t);
bool IsMulticastIp(uint32_t);
bool IsAnonymousIp(uint32_t);
int CategorizeIp(uint32_t);
const char *GetIpCategoryName(int);
bool IsCloudflareIp(uint32_t);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/tokenbucket.h */

#define COSMOPOLITAN_NET_HTTP_TOKENBUCKET_H_
COSMOPOLITAN_C_START_

void ReplenishTokens(atomic_uint_fast64_t *, size_t);
int AcquireToken(atomic_schar *, uint32_t, int);
int CountTokens(atomic_schar *, uint32_t, int);

COSMOPOLITAN_C_END_


/*!BEGIN net/http/url.h */

#define COSMOPOLITAN_NET_HTTP_URL_H_

#define kUrlPlus   1
#define kUrlLatin1 2
#define kUrlOpaque 4

COSMOPOLITAN_C_START_

struct UrlView {
  size_t n;
  char *p;
};

struct UrlParams {
  size_t n;
  struct UrlParam {
    struct UrlView key;
    struct UrlView val;
  } * p;
};

struct Url {
  struct UrlView scheme; /* must be [A-Za-z][-+.0-9A-Za-z]* or empty */
  struct UrlView user;   /* depends on host non-absence */
  struct UrlView pass;   /* depends on user non-absence */
  struct UrlView host;   /* or reg_name */
  struct UrlView port;   /* depends on host non-absence */
  struct UrlView path;   /* or opaque_part */
  struct UrlParams params;
  struct UrlView fragment;
};

char *EncodeUrl(struct Url *, size_t *);
char *ParseUrl(const char *, size_t, struct Url *, int);
char *ParseParams(const char *, size_t, struct UrlParams *);
char *ParseHost(const char *, size_t, struct Url *);
char *EscapeUrlView(char *, struct UrlView *, const char[256]);

COSMOPOLITAN_C_END_


/*!BEGIN tool/args/args.h */

#define COSMOPOLITAN_TOOL_ARGS_ARGS_H_
COSMOPOLITAN_C_START_

int LoadZipArgs(int *, char ***);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/dlmalloc/dlmalloc.h */

#define COSMOPOLITAN_THIRD_PARTY_DLMALLOC_DLMALLOC_H_

#define dlbulk_free                  __dlbulk_free
#define dlcalloc                     __dlcalloc
#define dlfree                       __dlfree
#define dlindependent_calloc         __dlindependent_calloc
#define dlindependent_comalloc       __dlindependent_comalloc
#define dlmallinfo                   __dlmallinfo
#define dlmalloc                     __dlmalloc
#define dlmalloc_abort               __dlmalloc_abort
#define dlmalloc_atfork              __dlmalloc_atfork
#define dlmalloc_footprint           __dlmalloc_footprint
#define dlmalloc_footprint_limit     __dlmalloc_footprint_limit
#define dlmalloc_inspect_all         __dlmalloc_inspect_all
#define dlmalloc_max_footprint       __dlmalloc_max_footprint
#define dlmalloc_set_footprint_limit __dlmalloc_set_footprint_limit
#define dlmalloc_stats               __dlmalloc_stats
#define dlmalloc_trim                __dlmalloc_trim
#define dlmalloc_usable_size         __dlmalloc_usable_size
#define dlmallopt                    __dlmallopt
#define dlmallopt                    __dlmallopt
#define dlmemalign                   __dlmemalign
#define dlrealloc                    __dlrealloc
#define dlrealloc_in_place           __dlrealloc_in_place
#define dlrealloc_in_place           __dlrealloc_in_place

COSMOPOLITAN_C_START_

/*
  malloc(size_t n)
  Returns a pointer to a newly allocated chunk of at least n bytes, or
  null if no space is available, in which case errno is set to ENOMEM
  on ANSI C systems.

  If n is zero, malloc returns a minimum-sized chunk. (The minimum
  size is 16 bytes on most 32bit systems, and 32 bytes on 64bit
  systems.)  Note that size_t is an unsigned type, so calls with
  arguments that would be negative if signed are interpreted as
  requests for huge amounts of space, which will often fail. The
  maximum supported value of n differs across systems, but is in all
  cases less than the maximum representable value of a size_t.
*/
void* dlmalloc(size_t);

/*
  free(void* p)
  Releases the chunk of memory pointed to by p, that had been previously
  allocated using malloc or a related routine such as realloc.
  It has no effect if p is null. If p was not malloced or already
  freed, free(p) will by default cuase the current program to abort.
*/
void dlfree(void*);

/*
  calloc(size_t n_elements, size_t element_size);
  Returns a pointer to n_elements * element_size bytes, with all locations
  set to zero.
*/
void* dlcalloc(size_t, size_t);

/*
  realloc(void* p, size_t n)
  Returns a pointer to a chunk of size n that contains the same data
  as does chunk p up to the minimum of (n, p's size) bytes, or null
  if no space is available.

  The returned pointer may or may not be the same as p. The algorithm
  prefers extending p in most cases when possible, otherwise it
  employs the equivalent of a malloc-copy-free sequence.

  If p is null, realloc is equivalent to malloc.

  If space is not available, realloc returns null, errno is set (if on
  ANSI) and p is NOT freed.

  if n is for fewer bytes than already held by p, the newly unused
  space is lopped off and freed if possible.  realloc with a size
  argument of zero (re)allocates a minimum-sized chunk.

  The old unix realloc convention of allowing the last-free'd chunk
  to be used as an argument to realloc is not supported.
*/
void* dlrealloc(void*, size_t);

/*
  realloc_in_place(void* p, size_t n)
  Resizes the space allocated for p to size n, only if this can be
  done without moving p (i.e., only if there is adjacent space
  available if n is greater than p's current allocated size, or n is
  less than or equal to p's size). This may be used instead of plain
  realloc if an alternative allocation strategy is needed upon failure
  to expand space; for example, reallocation of a buffer that must be
  memory-aligned or cleared. You can use realloc_in_place to trigger
  these alternatives only when needed.

  Returns p if successful; otherwise null.
*/
void* dlrealloc_in_place(void*, size_t);

/*
  memalign(size_t alignment, size_t n);
  Returns a pointer to a newly allocated chunk of n bytes, aligned
  in accord with the alignment argument.

  The alignment argument should be a power of two. If the argument is
  not a power of two, the nearest greater power is used.
  8-byte alignment is guaranteed by normal malloc calls, so don't
  bother calling memalign with an argument of 8 or less.

  Overreliance on memalign is a sure way to fragment space.
*/
void* dlmemalign(size_t, size_t);

/*
  mallopt(int parameter_number, int parameter_value)
  Sets tunable parameters The format is to provide a
  (parameter-number, parameter-value) pair.  mallopt then sets the
  corresponding parameter to the argument value if it can (i.e., so
  long as the value is meaningful), and returns 1 if successful else
  0.  SVID/XPG/ANSI defines four standard param numbers for mallopt,
  normally defined in malloc.h.  None of these are use in this malloc,
  so setting them has no effect. But this malloc also supports other
  options in mallopt:

  Symbol            param #  default    allowed param values
  M_TRIM_THRESHOLD     -1   2*1024*1024   any   (-1U disables trimming)
  M_GRANULARITY        -2     page size   any power of 2 >= page size
  M_MMAP_THRESHOLD     -3      256*1024   any   (or 0 if no MMAP support)
*/
int dlmallopt(int, int);

/*
  malloc_footprint();
  Returns the number of bytes obtained from the system.  The total
  number of bytes allocated by malloc, realloc etc., is less than this
  value. Unlike mallinfo, this function returns only a precomputed
  result, so can be called frequently to monitor memory consumption.
  Even if locks are otherwise defined, this function does not use them,
  so results might not be up to date.
*/
size_t dlmalloc_footprint(void);

/*
  malloc_max_footprint();
  Returns the maximum number of bytes obtained from the system. This
  value will be greater than current footprint if deallocated space
  has been reclaimed by the system. The peak number of bytes allocated
  by malloc, realloc etc., is less than this value. Unlike mallinfo,
  this function returns only a precomputed result, so can be called
  frequently to monitor memory consumption.  Even if locks are
  otherwise defined, this function does not use them, so results might
  not be up to date.
*/
size_t dlmalloc_max_footprint(void);

/*
  malloc_footprint_limit();
  Returns the number of bytes that the heap is allowed to obtain from
  the system, returning the last value returned by
  malloc_set_footprint_limit, or the maximum size_t value if
  never set. The returned value reflects a permission. There is no
  guarantee that this number of bytes can actually be obtained from
  the system.
*/
size_t dlmalloc_footprint_limit(void);

/*
  malloc_set_footprint_limit();
  Sets the maximum number of bytes to obtain from the system, causing
  failure returns from malloc and related functions upon attempts to
  exceed this value. The argument value may be subject to page
  rounding to an enforceable limit; this actual value is returned.
  Using an argument of the maximum possible size_t effectively
  disables checks. If the argument is less than or equal to the
  current malloc_footprint, then all future allocations that require
  additional system memory will fail. However, invocation cannot
  retroactively deallocate existing used memory.
*/
size_t dlmalloc_set_footprint_limit(size_t bytes);

/*
  malloc_inspect_all(void(*handler)(void *start,
                                    void *end,
                                    size_t used_bytes,
                                    void* callback_arg),
                      void* arg);
  Traverses the heap and calls the given handler for each managed
  region, skipping all bytes that are (or may be) used for bookkeeping
  purposes.  Traversal does not include include chunks that have been
  directly memory mapped. Each reported region begins at the start
  address, and continues up to but not including the end address.  The
  first used_bytes of the region contain allocated data. If
  used_bytes is zero, the region is unallocated. The handler is
  invoked with the given callback argument. If locks are defined, they
  are held during the entire traversal. It is a bad idea to invoke
  other malloc functions from within the handler.

  For example, to count the number of in-use chunks with size greater
  than 1000, you could write:
  static int count = 0;
  void count_chunks(void* start, void* end, size_t used, void* arg) {
    if (used >= 1000) ++count;
  }
  then:
    malloc_inspect_all(count_chunks, NULL);

  malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined.
*/
void dlmalloc_inspect_all(void (*handler)(void*, void*, size_t, void*),
                          void* arg);

/*
  mallinfo()
  Returns (by copy) a struct containing various summary statistics:

  arena:     current total non-mmapped bytes allocated from system
  ordblks:   the number of free chunks
  smblks:    always zero.
  hblks:     current number of mmapped regions
  hblkhd:    total bytes held in mmapped regions
  usmblks:   the maximum total allocated space. This will be greater
                than current total if trimming has occurred.
  fsmblks:   always zero
  uordblks:  current total allocated space (normal or mmapped)
  fordblks:  total free space
  keepcost:  the maximum number of bytes that could ideally be released
               back to system via malloc_trim. ("ideally" means that
               it ignores page restrictions etc.)

  Because these fields are ints, but internal bookkeeping may
  be kept as longs, the reported values may wrap around zero and
  thus be inaccurate.
*/

struct mallinfo dlmallinfo(void);

/*
  independent_calloc(size_t n_elements, size_t element_size, void* chunks[]);

  independent_calloc is similar to calloc, but instead of returning a
  single cleared space, it returns an array of pointers to n_elements
  independent elements that can hold contents of size elem_size, each
  of which starts out cleared, and can be independently freed,
  realloc'ed etc. The elements are guaranteed to be adjacently
  allocated (this is not guaranteed to occur with multiple callocs or
  mallocs), which may also improve cache locality in some
  applications.

  The "chunks" argument is optional (i.e., may be null, which is
  probably the most typical usage). If it is null, the returned array
  is itself dynamically allocated and should also be freed when it is
  no longer needed. Otherwise, the chunks array must be of at least
  n_elements in length. It is filled in with the pointers to the
  chunks.

  In either case, independent_calloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and "chunks"
  is null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_calloc simplifies and speeds up implementations of many
  kinds of pools.  It may also be useful when constructing large data
  structures that initially have a fixed number of fixed-sized nodes,
  but the number is not known at compile time, and some of the nodes
  may later need to be freed. For example:

  struct Node { int item; struct Node* next; };

  struct Node* build_list() {
    struct Node** pool;
    int n = read_number_of_nodes_needed();
    if (n <= 0) return 0;
    pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0);
    if (pool == 0) die();
    // organize into a linked list...
    struct Node* first = pool[0];
    for (i = 0; i < n-1; ++i)
      pool[i]->next = pool[i+1];
    free(pool);     // Can now free the array (or not, if it is needed later)
    return first;
  }
*/
void** dlindependent_calloc(size_t, size_t, void**);

/*
  independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]);

  independent_comalloc allocates, all at once, a set of n_elements
  chunks with sizes indicated in the "sizes" array.    It returns
  an array of pointers to these elements, each of which can be
  independently freed, realloc'ed etc. The elements are guaranteed to
  be adjacently allocated (this is not guaranteed to occur with
  multiple callocs or mallocs), which may also improve cache locality
  in some applications.

  The "chunks" argument is optional (i.e., may be null). If it is null
  the returned array is itself dynamically allocated and should also
  be freed when it is no longer needed. Otherwise, the chunks array
  must be of at least n_elements in length. It is filled in with the
  pointers to the chunks.

  In either case, independent_comalloc returns this pointer array, or
  null if the allocation failed.  If n_elements is zero and chunks is
  null, it returns a chunk representing an array with zero elements
  (which should be freed if not wanted).

  Each element must be freed when it is no longer needed. This can be
  done all at once using bulk_free.

  independent_comallac differs from independent_calloc in that each
  element may have a different size, and also that it does not
  automatically clear elements.

  independent_comalloc can be used to speed up allocation in cases
  where several structs or objects must always be allocated at the
  same time.  For example:

  struct Head { ... }
  struct Foot { ... }

  void send_message(char* msg) {
    int msglen = strlen(msg);
    size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) };
    void* chunks[3];
    if (independent_comalloc(3, sizes, chunks) == 0)
      die();
    struct Head* head = (struct Head*)(chunks[0]);
    char*        body = (char*)(chunks[1]);
    struct Foot* foot = (struct Foot*)(chunks[2]);
    // ...
  }

  In general though, independent_comalloc is worth using only for
  larger values of n_elements. For small values, you probably won't
  detect enough difference from series of malloc calls to bother.

  Overuse of independent_comalloc can increase overall memory usage,
  since it cannot reuse existing noncontiguous small chunks that
  might be available for some of the elements.
*/
void** dlindependent_comalloc(size_t, size_t*, void**);

/*
  bulk_free(void* array[], size_t n_elements)
  Frees and clears (sets to null) each non-null pointer in the given
  array.  This is likely to be faster than freeing them one-by-one.
  If footers are used, pointers that have been allocated in different
  mspaces are not freed or cleared, and the count of all such pointers
  is returned.  For large arrays of pointers with poor locality, it
  may be worthwhile to sort this array before calling bulk_free.
*/
size_t dlbulk_free(void**, size_t n_elements);

/*
  malloc_trim(size_t pad);

  If possible, gives memory back to the system (via negative arguments
  to sbrk) if there is unused memory at the `high' end of the malloc
  pool or in unused MMAP segments. You can call this after freeing
  large blocks of memory to potentially reduce the system-level memory
  requirements of a program. However, it cannot guarantee to reduce
  memory. Under some allocation patterns, some large free blocks of
  memory will be locked between two used chunks, so they cannot be
  given back to the system.

  The `pad' argument to malloc_trim represents the amount of free
  trailing space to leave untrimmed. If this argument is zero, only
  the minimum amount of memory to maintain internal data structures
  will be left. Non-zero arguments can be supplied to maintain enough
  trailing space to service future expected allocations without having
  to re-obtain memory from the system.

  Malloc_trim returns 1 if it actually released any memory, else 0.
*/
int dlmalloc_trim(size_t);

/*
  malloc_stats();
  Prints on stderr the amount of space obtained from the system (both
  via sbrk and mmap), the maximum amount (which may be more than
  current if malloc_trim and/or munmap got called), and the current
  number of bytes allocated via malloc (or realloc, etc) but not yet
  freed. Note that this is the number of bytes allocated, not the
  number requested. It will be larger than the number requested
  because of alignment and bookkeeping overhead. Because it includes
  alignment wastage as being in use, this figure may be greater than
  zero even when no user-level chunks are allocated.

  The reported current and maximum system memory can be inaccurate if
  a program makes other calls to system memory allocation functions
  (normally sbrk) outside of malloc.

  malloc_stats prints only the most commonly interesting statistics.
  More information can be obtained by calling mallinfo.

  malloc_stats is not compiled if NO_MALLOC_STATS is defined.
*/
void dlmalloc_stats(void);

/*
  malloc_usable_size(void* p);

  Returns the number of bytes you can actually use in
  an allocated chunk, which may be more than you requested (although
  often not) due to alignment and minimum size constraints.
  You can use this many bytes without worrying about
  overwriting other allocated objects. This is not a particularly great
  programming practice. malloc_usable_size can be more useful in
  debugging and assertions, for example:

  p = malloc(n);
  assert(malloc_usable_size(p) >= 256);
*/
size_t dlmalloc_usable_size(void*);

/*
  mspace is an opaque type representing an independent
  region of space that supports mspace_malloc, etc.
*/
typedef void* mspace;

/*
  create_mspace creates and returns a new independent space with the
  given initial capacity, or, if 0, the default granularity size.  It
  returns null if there is no system memory available to create the
  space.  If argument locked is non-zero, the space uses a separate
  lock to control access. The capacity of the space will grow
  dynamically as needed to service mspace_malloc requests.  You can
  control the sizes of incremental increases of this space by
  compiling with a different DEFAULT_GRANULARITY or dynamically
  setting with mallopt(M_GRANULARITY, value).
*/
mspace create_mspace(size_t capacity, int locked);

/*
  destroy_mspace destroys the given space, and attempts to return all
  of its memory back to the system, returning the total number of
  bytes freed. After destruction, the results of access to all memory
  used by the space become undefined.
*/
size_t destroy_mspace(mspace msp);

/*
  create_mspace_with_base uses the memory supplied as the initial base
  of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this
  space is used for bookkeeping, so the capacity must be at least this
  large. (Otherwise 0 is returned.) When this initial space is
  exhausted, additional memory will be obtained from the system.
  Destroying this space will deallocate all additionally allocated
  space (if possible) but not the initial base.
*/
mspace create_mspace_with_base(void* base, size_t capacity, int locked);

/*
  mspace_track_large_chunks controls whether requests for large chunks
  are allocated in their own untracked mmapped regions, separate from
  others in this mspace. By default large chunks are not tracked,
  which reduces fragmentation. However, such chunks are not
  necessarily released to the system upon destroy_mspace.  Enabling
  tracking by setting to true may increase fragmentation, but avoids
  leakage when relying on destroy_mspace to release all memory
  allocated using this space.  The function returns the previous
  setting.
*/
int mspace_track_large_chunks(mspace msp, int enable);

/*
  mspace_mallinfo behaves as mallinfo, but reports properties of
  the given space.
*/
struct mallinfo mspace_mallinfo(mspace msp);

/*
  An alias for mallopt.
*/
int mspace_mallopt(int, int);

/*
  The following operate identically to their malloc counterparts
  but operate only for the given mspace argument
*/
void* mspace_malloc(mspace msp, size_t bytes);
void mspace_free(mspace msp, void* mem);
void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size);
void* mspace_realloc(mspace msp, void* mem, size_t newsize);
void* mspace_realloc_in_place(mspace msp, void* mem, size_t newsize);
void* mspace_memalign(mspace msp, size_t alignment, size_t bytes);
void** mspace_independent_calloc(mspace msp, size_t n_elements,
                                 size_t elem_size, void* chunks[]);
void** mspace_independent_comalloc(mspace msp, size_t n_elements,
                                   size_t sizes[], void* chunks[]);
size_t mspace_bulk_free(mspace msp, void**, size_t n_elements);
size_t mspace_usable_size(const void* mem);
void mspace_malloc_stats(mspace msp);
int mspace_trim(mspace msp, size_t pad);
size_t mspace_footprint(mspace msp);
size_t mspace_max_footprint(mspace msp);
size_t mspace_footprint_limit(mspace msp);
size_t mspace_set_footprint_limit(mspace msp, size_t bytes);
void mspace_inspect_all(mspace msp,
                        void (*handler)(void*, void*, size_t, void*),
                        void* arg);

void dlmalloc_atfork(void);
void dlmalloc_abort(void) relegated wontreturn;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/gdtoa/gdtoa.h */

#define COSMOPOLITAN_THIRD_PARTY_GDTOA_GDTOA_H_
COSMOPOLITAN_C_START_

#define dtoa      __dtoa
#define gdtoa     __gdtoa
#define strtodg   __strtodg
#define freedtoa  __freedtoa
#define g_ddfmt   __g_ddfmt
#define g_ddfmt_p __g_ddfmt_p
#define g_dfmt    __g_dfmt
#define g_dfmt_p  __g_dfmt_p
#define g_ffmt    __g_ffmt
#define g_ffmt_p  __g_ffmt_p
#define g_Qfmt    __g_Qfmt
#define g_Qfmt_p  __g_Qfmt_p
#define g_xfmt    __g_xfmt
#define g_xfmt_p  __g_xfmt_p
#define g_xLfmt   __g_xLfmt
#define g_xLfmt_p __g_xLfmt_p
#define strtoId   __strtoId
#define strtoIdd  __strtoIdd
#define strtoIf   __strtoIf
#define strtoIQ   __strtoIQ
#define strtoIx   __strtoIx
#define strtoIxL  __strtoIxL
#define strtord   __strtord
#define strtordd  __strtordd
#define strtorf   __strtorf
#define strtorQ   __strtorQ
#define strtorx   __strtorx
#define strtorxL  __strtorxL
#define strtodI   __strtodI
#define strtopd   __strtopd
#define strtopdd  __strtopdd
#define strtopf   __strtopf
#define strtopQ   __strtopQ
#define strtopx   __strtopx
#define strtopxL  __strtopxL

/**
 * Configures g_*fmt()
 *
 * @param ic
 * 	0 ==> Infinity or NaN
 * 	1 ==> infinity or nan
 * 	2 ==> INFINITY or NAN
 * 	3 ==> Inf or NaN
 * 	4 ==> inf or nan
 * 	5 ==> INF or NAN
 * @param ic determines if NaNs are rendered as NaN(...)
 * 	0 ==> no
 * 	1 ==> yes
 * 	2 ==> no for default NaN values; yes otherwise
 * @param ns determines sign of NaN values reported
 * 	0 ==> distinguish NaN and -NaN
 * 	1 ==> report both as NaN
 */
#define NIK(ic, nb, ns) (ic + 6 * (nb + 3 * ns))

enum {
  /* return values from strtodg */
  STRTOG_Zero = 0,
  STRTOG_Normal = 1,
  STRTOG_Denormal = 2,
  STRTOG_Infinite = 3,
  STRTOG_NaN = 4,
  STRTOG_NaNbits = 5,
  STRTOG_NoNumber = 6,
  STRTOG_Retmask = 7,
  /* The following may be or-ed into one of the above values. */
  STRTOG_Neg = 0x08,    /* does not affect STRTOG_Inexlo or STRTOG_Inexhi */
  STRTOG_Inexlo = 0x10, /* returned result rounded toward zero */
  STRTOG_Inexhi = 0x20, /* returned result rounded away from zero */
  STRTOG_Inexact = 0x30,
  STRTOG_Underflow = 0x40,
  STRTOG_Overflow = 0x80
};

typedef struct FPI {
  int nbits;
  int emin;
  int emax;
  int rounding;
  int sudden_underflow;
  int int_max;
} FPI;

enum {
  /* FPI.rounding values: same as FLT_ROUNDS */
  FPI_Round_zero = 0,
  FPI_Round_near = 1,
  FPI_Round_up = 2,
  FPI_Round_down = 3
};

char *dtoa(double, int, int, int *, int *, char **);
char *gdtoa(const FPI *, int, unsigned *, int *, int, int, int *, char **);
int strtodg(const char *, char **, const FPI *, int *, unsigned *);
void freedtoa(char *);

char *g_ddfmt(char *, double *, int, size_t);
char *g_ddfmt_p(char *, double *, int, size_t, int);
char *g_dfmt(char *, double *, int, size_t);
char *g_dfmt_p(char *, double *, int, size_t, int);
char *g_ffmt(char *, float *, int, size_t);
char *g_ffmt_p(char *, float *, int, size_t, int);
char *g_Qfmt(char *, void *, int, size_t);
char *g_Qfmt_p(char *, void *, int, size_t, int);
char *g_xfmt(char *, void *, int, size_t);
char *g_xfmt_p(char *, void *, int, size_t, int);
char *g_xLfmt(char *, void *, int, size_t);
char *g_xLfmt_p(char *, void *, int, size_t, int);

int strtoId(const char *, char **, double *, double *);
int strtoIdd(const char *, char **, double *, double *);
int strtoIf(const char *, char **, float *, float *);
int strtoIQ(const char *, char **, void *, void *);
int strtoIx(const char *, char **, void *, void *);
int strtoIxL(const char *, char **, void *, void *);
int strtord(const char *, char **, int, double *);
int strtordd(const char *, char **, int, double *);
int strtorf(const char *, char **, int, float *);
int strtorQ(const char *, char **, int, void *);
int strtorx(const char *, char **, int, void *);
int strtorxL(const char *, char **, int, void *);

int strtodI(const char *, char **, double *);
int strtopd(const char *, char **, double *);
int strtopdd(const char *, char **, double *);
int strtopf(const char *, char **, float *);
int strtopQ(const char *, char **, void *);
int strtopx(const char *, char **, void *);
int strtopxL(const char *, char **, void *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long1.h */

#define _GETOPT_CORE_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif
COSMOPOLITAN_C_START_

extern char *optarg;
extern int optind, opterr, optopt, optreset;

int getopt(int, char *const *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/getopt/long2.h */

#define _GETOPT_EXT_H
#ifdef COSMOPOLITAN_GETOPT_H_
#error "don't mix getopt_long() with cosmo's getopt()"
#endif

#define no_argument       0
#define required_argument 1
#define optional_argument 2

COSMOPOLITAN_C_START_

struct option {
  const char *name;
  int has_arg;
  int *flag;
  int val;
};

int getopt_long(int, char *const *, const char *, const struct option *, int *);
int getopt_long_only(int, char *const *, const char *, const struct option *,
                     int *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/crypt.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_CRYPT_H_
COSMOPOLITAN_C_START_

struct crypt_data {
  int initialized;
  char __buf[256];
};

char *crypt(const char *, const char *) libcesque;
char *crypt_r(const char *, const char *, struct crypt_data *) libcesque;

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/fnmatch.h */

#define COSMOPOLITAN_THIRD_PARTY_REGEX_FNMATCH_H_
COSMOPOLITAN_C_START_

#define FNM_PATHNAME    0x1
#define FNM_NOESCAPE    0x2
#define FNM_PERIOD      0x4
#define FNM_LEADING_DIR 0x8
#define FNM_CASEFOLD    0x10
#define FNM_FILE_NAME   FNM_PATHNAME

#define FNM_NOMATCH 1
#define FNM_NOSYS   (-1)

int fnmatch(const char *, const char *, int);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/glob.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_GLOB_H_
COSMOPOLITAN_C_START_

#define GLOB_ERR      0x01
#define GLOB_MARK     0x02
#define GLOB_NOSORT   0x04
#define GLOB_DOOFFS   0x08 /* reserves null slots at start of gl_pathv */
#define GLOB_NOCHECK  0x10 /* just yield pattern if GLOB_NOMATCH happens */
#define GLOB_APPEND   0x20 /* enables us to call glob() multiple times */
#define GLOB_NOESCAPE 0x40 /* don't allow things like \*\?\[\] escaping */
#define GLOB_PERIOD   0x80

#define GLOB_TILDE       0x1000
#define GLOB_TILDE_CHECK 0x4000

#define GLOB_NOSPACE 1
#define GLOB_ABORTED 2
#define GLOB_NOMATCH 3
#define GLOB_NOSYS   4

typedef struct {
  size_t gl_pathc;
  char **gl_pathv;
  size_t gl_offs;
  int __dummy1;
  void *__dummy2[5];
} glob_t;

int glob(const char *, int, int (*)(const char *, int), glob_t *);
void globfree(glob_t *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/lockf.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_LOCKF_H_

#define F_ULOCK 0
#define F_LOCK  1
#define F_TLOCK 2
#define F_TEST  3

COSMOPOLITAN_C_START_

int lockf(int, int, int64_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/mntent.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_MNTENT_H_
COSMOPOLITAN_C_START_

#define MOUNTED "/etc/mtab"

#define MNTTYPE_IGNORE  "ignore"
#define MNTTYPE_NFS     "nfs"
#define MNTTYPE_SWAP    "swap"
#define MNTOPT_DEFAULTS "defaults"
#define MNTOPT_RO       "ro"
#define MNTOPT_RW       "rw"
#define MNTOPT_SUID     "suid"
#define MNTOPT_NOSUID   "nosuid"
#define MNTOPT_NOAUTO   "noauto"

struct mntent {
  char *mnt_fsname;
  char *mnt_dir;
  char *mnt_type;
  char *mnt_opts;
  int mnt_freq;
  int mnt_passno;
};

FILE *setmntent(const char *, const char *);
int endmntent(FILE *);
struct mntent *getmntent(FILE *);
struct mntent *getmntent_r(FILE *, struct mntent *, char *, int);
int addmntent(FILE *, const struct mntent *);
char *hasmntopt(const struct mntent *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/nameser.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NAMESER_H_
COSMOPOLITAN_C_START_

#define __NAMESER	19991006
#define NS_PACKETSZ	512
#define NS_MAXDNAME	1025
#define NS_MAXMSG	65535
#define NS_MAXCDNAME	255
#define NS_MAXLABEL	63
#define NS_HFIXEDSZ	12
#define NS_QFIXEDSZ	4
#define NS_RRFIXEDSZ	10
#define NS_INT32SZ	4
#define NS_INT16SZ	2
#define NS_INT8SZ	1
#define NS_INADDRSZ	4
#define NS_IN6ADDRSZ	16
#define NS_CMPRSFLGS	0xc0
#define NS_DEFAULTPORT	53

typedef enum __ns_sect {
	ns_s_qd = 0,
	ns_s_zn = 0,
	ns_s_an = 1,
	ns_s_pr = 1,
	ns_s_ns = 2,
	ns_s_ud = 2,
	ns_s_ar = 3,
	ns_s_max = 4
} ns_sect;

typedef struct __ns_msg {
	const unsigned char *_msg, *_eom;
	uint16_t _id, _flags, _counts[ns_s_max];
	const unsigned char *_sections[ns_s_max];
	ns_sect _sect;
	int _rrnum;
	const unsigned char *_msg_ptr;
} ns_msg;

struct _ns_flagdata {  int mask, shift;  };
extern const struct _ns_flagdata _ns_flagdata[];

#define ns_msg_id(handle) ((handle)._id + 0)
#define ns_msg_base(handle) ((handle)._msg + 0)
#define ns_msg_end(handle) ((handle)._eom + 0)
#define ns_msg_size(handle) ((handle)._eom - (handle)._msg)
#define ns_msg_count(handle, section) ((handle)._counts[section] + 0)
#define ns_msg_getflag(handle, flag) \
	(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift)

typedef	struct __ns_rr {
	char		name[NS_MAXDNAME];
	uint16_t	type;
	uint16_t	rr_class;
	uint32_t	ttl;
	uint16_t	rdlength;
	const unsigned char *rdata;
} ns_rr;

#define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".")
#define ns_rr_type(rr)	((ns_type)((rr).type + 0))
#define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0))
#define ns_rr_ttl(rr)	((rr).ttl + 0)
#define ns_rr_rdlen(rr)	((rr).rdlength + 0)
#define ns_rr_rdata(rr)	((rr).rdata + 0)

typedef enum __ns_flag {
	ns_f_qr,
	ns_f_opcode,
	ns_f_aa,
	ns_f_tc,
	ns_f_rd,
	ns_f_ra,
	ns_f_z,
	ns_f_ad,
	ns_f_cd,
	ns_f_rcode,
	ns_f_max
} ns_flag;

typedef enum __ns_opcode {
	ns_o_query = 0,
	ns_o_iquery = 1,
	ns_o_status = 2,
	ns_o_notify = 4,
	ns_o_update = 5,
	ns_o_max = 6
} ns_opcode;

typedef	enum __ns_rcode {
	ns_r_noerror = 0,
	ns_r_formerr = 1,
	ns_r_servfail = 2,
	ns_r_nxdomain = 3,
	ns_r_notimpl = 4,
	ns_r_refused = 5,
	ns_r_yxdomain = 6,
	ns_r_yxrrset = 7,
	ns_r_nxrrset = 8,
	ns_r_notauth = 9,
	ns_r_notzone = 10,
	ns_r_max = 11,
	ns_r_badvers = 16,
	ns_r_badsig = 16,
	ns_r_badkey = 17,
	ns_r_badtime = 18
} ns_rcode;

typedef enum __ns_update_operation {
	ns_uop_delete = 0,
	ns_uop_add = 1,
	ns_uop_max = 2
} ns_update_operation;

struct ns_tsig_key {
        char name[NS_MAXDNAME], alg[NS_MAXDNAME];
        unsigned char *data;
        int len;
};
typedef struct ns_tsig_key ns_tsig_key;

struct ns_tcp_tsig_state {
	int counter;
	struct dst_key *key;
	void *ctx;
	unsigned char sig[NS_PACKETSZ];
	int siglen;
};
typedef struct ns_tcp_tsig_state ns_tcp_tsig_state;

#define NS_TSIG_FUDGE 300
#define NS_TSIG_TCP_COUNT 100
#define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT"

#define NS_TSIG_ERROR_NO_TSIG -10
#define NS_TSIG_ERROR_NO_SPACE -11
#define NS_TSIG_ERROR_FORMERR -12

typedef enum __ns_type {
	ns_t_invalid = 0,
	ns_t_a = 1,
	ns_t_ns = 2,
	ns_t_md = 3,
	ns_t_mf = 4,
	ns_t_cname = 5,
	ns_t_soa = 6,
	ns_t_mb = 7,
	ns_t_mg = 8,
	ns_t_mr = 9,
	ns_t_null = 10,
	ns_t_wks = 11,
	ns_t_ptr = 12,
	ns_t_hinfo = 13,
	ns_t_minfo = 14,
	ns_t_mx = 15,
	ns_t_txt = 16,
	ns_t_rp = 17,
	ns_t_afsdb = 18,
	ns_t_x25 = 19,
	ns_t_isdn = 20,
	ns_t_rt = 21,
	ns_t_nsap = 22,
	ns_t_nsap_ptr = 23,
	ns_t_sig = 24,
	ns_t_key = 25,
	ns_t_px = 26,
	ns_t_gpos = 27,
	ns_t_aaaa = 28,
	ns_t_loc = 29,
	ns_t_nxt = 30,
	ns_t_eid = 31,
	ns_t_nimloc = 32,
	ns_t_srv = 33,
	ns_t_atma = 34,
	ns_t_naptr = 35,
	ns_t_kx = 36,
	ns_t_cert = 37,
	ns_t_a6 = 38,
	ns_t_dname = 39,
	ns_t_sink = 40,
	ns_t_opt = 41,
	ns_t_apl = 42,
	ns_t_tkey = 249,
	ns_t_tsig = 250,
	ns_t_ixfr = 251,
	ns_t_axfr = 252,
	ns_t_mailb = 253,
	ns_t_maila = 254,
	ns_t_any = 255,
	ns_t_zxfr = 256,
	ns_t_max = 65536
} ns_type;

#define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \
		      (t) == ns_t_mailb || (t) == ns_t_maila)
#define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt)
#define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t))
#define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr)
#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \
		       (t) == ns_t_zxfr)

typedef enum __ns_class {
	ns_c_invalid = 0,
	ns_c_in = 1,
	ns_c_2 = 2,
	ns_c_chaos = 3,
	ns_c_hs = 4,
	ns_c_none = 254,
	ns_c_any = 255,
	ns_c_max = 65536
} ns_class;

typedef enum __ns_key_types {
	ns_kt_rsa = 1,
	ns_kt_dh  = 2,
	ns_kt_dsa = 3,
	ns_kt_private = 254
} ns_key_types;

typedef enum __ns_cert_types {
	cert_t_pkix = 1,
	cert_t_spki = 2,
	cert_t_pgp  = 3,
	cert_t_url  = 253,
	cert_t_oid  = 254
} ns_cert_types;

#define	NS_KEY_TYPEMASK		0xC000
#define	NS_KEY_TYPE_AUTH_CONF	0x0000
#define	NS_KEY_TYPE_CONF_ONLY	0x8000
#define	NS_KEY_TYPE_AUTH_ONLY	0x4000
#define	NS_KEY_TYPE_NO_KEY	0xC000
#define	NS_KEY_NO_AUTH		0x8000
#define	NS_KEY_NO_CONF		0x4000
#define	NS_KEY_RESERVED2	0x2000
#define	NS_KEY_EXTENDED_FLAGS	0x1000
#define	NS_KEY_RESERVED4	0x0800
#define	NS_KEY_RESERVED5	0x0400
#define	NS_KEY_NAME_TYPE	0x0300
#define	NS_KEY_NAME_USER	0x0000
#define	NS_KEY_NAME_ENTITY	0x0200
#define	NS_KEY_NAME_ZONE	0x0100
#define	NS_KEY_NAME_RESERVED	0x0300
#define	NS_KEY_RESERVED8	0x0080
#define	NS_KEY_RESERVED9	0x0040
#define	NS_KEY_RESERVED10	0x0020
#define	NS_KEY_RESERVED11	0x0010
#define	NS_KEY_SIGNATORYMASK	0x000F
#define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \
				  NS_KEY_RESERVED4 | \
				  NS_KEY_RESERVED5 | \
				  NS_KEY_RESERVED8 | \
				  NS_KEY_RESERVED9 | \
				  NS_KEY_RESERVED10 | \
				  NS_KEY_RESERVED11 )
#define NS_KEY_RESERVED_BITMASK2 0xFFFF
#define	NS_ALG_MD5RSA		1
#define	NS_ALG_DH               2
#define	NS_ALG_DSA              3
#define	NS_ALG_DSS              NS_ALG_DSA
#define	NS_ALG_EXPIRE_ONLY	253
#define	NS_ALG_PRIVATE_OID	254

#define NS_KEY_PROT_TLS         1
#define NS_KEY_PROT_EMAIL       2
#define NS_KEY_PROT_DNSSEC      3
#define NS_KEY_PROT_IPSEC       4
#define NS_KEY_PROT_ANY		255

#define	NS_MD5RSA_MIN_BITS	 512
#define	NS_MD5RSA_MAX_BITS	4096
#define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3)
#define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4)
#define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8)
#define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8)

#define NS_DSA_SIG_SIZE         41
#define NS_DSA_MIN_SIZE         213
#define NS_DSA_MAX_BYTES        405

#define	NS_SIG_TYPE	0
#define	NS_SIG_ALG	2
#define	NS_SIG_LABELS	3
#define	NS_SIG_OTTL	4
#define	NS_SIG_EXPIR	8
#define	NS_SIG_SIGNED	12
#define	NS_SIG_FOOT	16
#define	NS_SIG_SIGNER	18
#define	NS_NXT_BITS 8
#define	NS_NXT_BIT_SET(  n,p) (p[(n)/NS_NXT_BITS] |=  (0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS)))
#define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] &   (0x80>>((n)%NS_NXT_BITS)))
#define NS_NXT_MAX 127

#define NS_OPT_DNSSEC_OK        0x8000U
#define NS_OPT_NSID		3

#define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2))
#define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4))
#define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2)
#define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4)

unsigned ns_get16(const unsigned char *);
unsigned long ns_get32(const unsigned char *);
void ns_put16(unsigned, unsigned char *);
void ns_put32(unsigned long, unsigned char *);

int ns_initparse(const unsigned char *, int, ns_msg *);
int ns_parserr(ns_msg *, ns_sect, int, ns_rr *);
int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int);
int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t);


#define	__BIND		19950621

typedef struct {
	unsigned	id :16;
#if __BYTE_ORDER == __BIG_ENDIAN
	unsigned	qr: 1;
	unsigned	opcode: 4;
	unsigned	aa: 1;
	unsigned	tc: 1;
	unsigned	rd: 1;
	unsigned	ra: 1;
	unsigned	unused :1;
	unsigned	ad: 1;
	unsigned	cd: 1;
	unsigned	rcode :4;
#else
	unsigned	rd :1;
	unsigned	tc :1;
	unsigned	aa :1;
	unsigned	opcode :4;
	unsigned	qr :1;
	unsigned	rcode :4;
	unsigned	cd: 1;
	unsigned	ad: 1;
	unsigned	unused :1;
	unsigned	ra :1;
#endif
	unsigned	qdcount :16;
	unsigned	ancount :16;
	unsigned	nscount :16;
	unsigned	arcount :16;
} HEADER;

#define PACKETSZ	NS_PACKETSZ
#define MAXDNAME	NS_MAXDNAME
#define MAXCDNAME	NS_MAXCDNAME
#define MAXLABEL	NS_MAXLABEL
#define	HFIXEDSZ	NS_HFIXEDSZ
#define QFIXEDSZ	NS_QFIXEDSZ
#define RRFIXEDSZ	NS_RRFIXEDSZ
#define	INT32SZ		NS_INT32SZ
#define	INT16SZ		NS_INT16SZ
#define INT8SZ		NS_INT8SZ
#define	INADDRSZ	NS_INADDRSZ
#define	IN6ADDRSZ	NS_IN6ADDRSZ
#define	INDIR_MASK	NS_CMPRSFLGS
#define NAMESERVER_PORT	NS_DEFAULTPORT

#define S_ZONE		ns_s_zn
#define S_PREREQ	ns_s_pr
#define S_UPDATE	ns_s_ud
#define S_ADDT		ns_s_ar

#define QUERY		ns_o_query
#define IQUERY		ns_o_iquery
#define STATUS		ns_o_status
#define	NS_NOTIFY_OP	ns_o_notify
#define	NS_UPDATE_OP	ns_o_update

#define NOERROR		ns_r_noerror
#define FORMERR		ns_r_formerr
#define SERVFAIL	ns_r_servfail
#define NXDOMAIN	ns_r_nxdomain
#define NOTIMP		ns_r_notimpl
#define REFUSED		ns_r_refused
#define YXDOMAIN	ns_r_yxdomain
#define YXRRSET		ns_r_yxrrset
#define NXRRSET		ns_r_nxrrset
#define NOTAUTH		ns_r_notauth
#define NOTZONE		ns_r_notzone

#define DELETE		ns_uop_delete
#define ADD		ns_uop_add

#define T_A		ns_t_a
#define T_NS		ns_t_ns
#define T_MD		ns_t_md
#define T_MF		ns_t_mf
#define T_CNAME		ns_t_cname
#define T_SOA		ns_t_soa
#define T_MB		ns_t_mb
#define T_MG		ns_t_mg
#define T_MR		ns_t_mr
#define T_NULL		ns_t_null
#define T_WKS		ns_t_wks
#define T_PTR		ns_t_ptr
#define T_HINFO		ns_t_hinfo
#define T_MINFO		ns_t_minfo
#define T_MX		ns_t_mx
#define T_TXT		ns_t_txt
#define	T_RP		ns_t_rp
#define T_AFSDB		ns_t_afsdb
#define T_X25		ns_t_x25
#define T_ISDN		ns_t_isdn
#define T_RT		ns_t_rt
#define T_NSAP		ns_t_nsap
#define T_NSAP_PTR	ns_t_nsap_ptr
#define	T_SIG		ns_t_sig
#define	T_KEY		ns_t_key
#define	T_PX		ns_t_px
#define	T_GPOS		ns_t_gpos
#define	T_AAAA		ns_t_aaaa
#define	T_LOC		ns_t_loc
#define	T_NXT		ns_t_nxt
#define	T_EID		ns_t_eid
#define	T_NIMLOC	ns_t_nimloc
#define	T_SRV		ns_t_srv
#define T_ATMA		ns_t_atma
#define T_NAPTR		ns_t_naptr
#define T_A6		ns_t_a6
#define T_DNAME		ns_t_dname
#define	T_TSIG		ns_t_tsig
#define	T_IXFR		ns_t_ixfr
#define T_AXFR		ns_t_axfr
#define T_MAILB		ns_t_mailb
#define T_MAILA		ns_t_maila
#define T_ANY		ns_t_any

#define C_IN		ns_c_in
#define C_CHAOS		ns_c_chaos
#define C_HS		ns_c_hs
#define C_NONE		ns_c_none
#define C_ANY		ns_c_any

#define	GETSHORT		NS_GET16
#define	GETLONG			NS_GET32
#define	PUTSHORT		NS_PUT16
#define	PUTLONG			NS_PUT32

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/netdb.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_NETDB_H_
COSMOPOLITAN_C_START_

struct addrinfo {
	int ai_flags;
	int ai_family;
	int ai_socktype;
	int ai_protocol;
	uint32_t ai_addrlen;
	struct sockaddr *ai_addr;
	char *ai_canonname;
	struct addrinfo *ai_next;
};

#define AI_PASSIVE      0x01
#define AI_CANONNAME    0x02
#define AI_NUMERICHOST  0x04
#define AI_V4MAPPED     0x08
#define AI_ALL          0x10
#define AI_ADDRCONFIG   0x20
#define AI_NUMERICSERV  0x400

#define NI_NUMERICHOST  0x01
#define NI_NUMERICSERV  0x02
#define NI_NOFQDN       0x04
#define NI_NAMEREQD     0x08
#define NI_DGRAM        0x10
#define NI_NUMERICSCOPE 0x100

#define EAI_BADFLAGS   -1
#define EAI_NONAME     -2
#define EAI_AGAIN      -3
#define EAI_FAIL       -4
#define EAI_FAMILY     -6
#define EAI_SOCKTYPE   -7
#define EAI_SERVICE    -8
#define EAI_MEMORY     -10
#define EAI_SYSTEM     -11
#define EAI_OVERFLOW   -12

int getaddrinfo (const char *, const char *, const struct addrinfo *, struct addrinfo **);
void freeaddrinfo (struct addrinfo *);
int getnameinfo (const struct sockaddr *, uint32_t, char *, uint32_t, char *, uint32_t, int);
const char *gai_strerror(int);


/* Legacy functions follow (marked OBsolete in SUS) */

struct netent {
	char *n_name;
	char **n_aliases;
	int n_addrtype;
	uint32_t n_net;
};

struct hostent {
	char *h_name;
	char **h_aliases;
	int h_addrtype;
	int h_length;
	char **h_addr_list;
};
#define h_addr h_addr_list[0]

struct servent {
	char *s_name;
	char **s_aliases;
	int s_port;
	char *s_proto;
};

struct protoent {
	char *p_name;
	char **p_aliases;
	int p_proto;
};

void sethostent (int);
void endhostent (void);
struct hostent *gethostent (void);

void setnetent (int);
void endnetent (void);
struct netent *getnetent (void);
struct netent *getnetbyaddr (uint32_t, int);
struct netent *getnetbyname (const char *);

void setservent (int);
void endservent (void);
struct servent *getservent (void);
struct servent *getservbyname (const char *, const char *);
struct servent *getservbyport (int, const char *);

void setprotoent (int);
void endprotoent (void);
struct protoent *getprotoent (void);
struct protoent *getprotobyname (const char *);
struct protoent *getprotobynumber (int);

#define NI_MAXHOST 255
#define NI_MAXSERV 32

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \
 || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \
 || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
struct hostent *gethostbyname (const char *);
struct hostent *gethostbyaddr (const void *, uint32_t, int);
errno_t *__h_errno_location(void) dontthrow pureconst;
#define h_errno (*__h_errno_location())
#define HOST_NOT_FOUND 1
#define TRY_AGAIN      2
#define NO_RECOVERY    3
#define NO_DATA        4
#define NO_ADDRESS     NO_DATA
#endif

#if defined(_COSMO_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
void herror(const char *);
const char *hstrerror(int);
int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *);
int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *);
struct hostent *gethostbyname2(const char *, int);
int gethostbyaddr_r(const void *, uint32_t, int, struct hostent *, char *, size_t, struct hostent **, int *);
int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **);
int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **);
#define EAI_NODATA     -5
#define EAI_ADDRFAMILY -9
#define EAI_INPROGRESS -100
#define EAI_CANCELED   -101
#define EAI_NOTCANCELED -102
#define EAI_ALLDONE    -103
#define EAI_INTR       -104
#define EAI_IDN_ENCODE -105
#endif

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/passwd.h */

#define COSMOPOLITAN_LIBC_PASSWD_H_
COSMOPOLITAN_C_START_

struct passwd {
  char *pw_name;
  char *pw_passwd;
  uid_t pw_uid;
  gid_t pw_gid;
  char *pw_gecos;
  char *pw_dir;
  char *pw_shell;
};

void setpwent(void);
void endpwent(void);
struct passwd *getpwent(void);
struct passwd *getpwuid(uid_t);
struct passwd *getpwnam(const char *);
int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
int getpwnam_r(const char *, struct passwd *, char *, size_t, struct passwd **);
struct passwd *fgetpwent(FILE *);
int putpwent(const struct passwd *, FILE *);

struct group {
  char *gr_name;
  char *gr_passwd;
  gid_t gr_gid;
  char **gr_mem;
};

struct group *getgrgid(gid_t);
struct group *getgrnam(const char *);
int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **);
int getgrnam_r(const char *, struct group *, char *, size_t, struct group **);
struct group *getgrent(void);
void endgrent(void);
void setgrent(void);
struct group *fgetgrent(FILE *);
int putgrent(const struct group *, FILE *);
int getgrouplist(const char *, gid_t, gid_t *, int *);
int initgroups(const char *, gid_t);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/rand48.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RAND48_H_
COSMOPOLITAN_C_START_

double drand48(void);
double erand48(unsigned short[3]);
long int lrand48(void);
long int nrand48(unsigned short[3]);
long mrand48(void);
long jrand48(unsigned short[3]);
void srand48(long);
unsigned short *seed48(unsigned short[3]);
void lcong48(unsigned short[7]);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/resolv.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_RESOLV_H_
COSMOPOLITAN_C_START_

#define MAXNS			3
#define MAXDFLSRCH		3
#define MAXDNSRCH		6
#define LOCALDOMAINPARTS	2

#define RES_TIMEOUT		5
#define MAXRESOLVSORT		10
#define RES_MAXNDOTS		15
#define RES_MAXRETRANS		30
#define RES_MAXRETRY		5
#define RES_DFLRETRY		2
#define RES_MAXTIME		65535

/* unused; purely for broken apps */
typedef struct __res_state {
	int retrans;
	int retry;
	unsigned long options;
	int nscount;
	struct sockaddr_in nsaddr_list[MAXNS];
# define nsaddr	nsaddr_list[0]
	unsigned short id;
	char *dnsrch[MAXDNSRCH+1];
	char defdname[256];
	unsigned long pfcode;
	unsigned ndots:4;
	unsigned nsort:4;
	unsigned ipv6_unavail:1;
	unsigned unused:23;
	struct {
		struct in_addr addr;
		uint32_t mask;
	} sort_list[MAXRESOLVSORT];
	void *qhook;
	void *rhook;
	int res_h_errno;
	int _vcsock;
	unsigned _flags;
	union {
		char pad[52];
		struct {
			uint16_t		nscount;
			uint16_t		nsmap[MAXNS];
			int			nssocks[MAXNS];
			uint16_t		nscount6;
			uint16_t		nsinit;
			struct sockaddr_in6	*nsaddrs[MAXNS];
			unsigned int		_initstamp[2];
		} _ext;
	} _u;
} *res_state;

#define	__RES	19960801

#ifndef _PATH_RESCONF
#define _PATH_RESCONF        "/etc/resolv.conf"
#endif

struct res_sym {
	int number;
	char *name;
	char *humanname;
};

#define	RES_F_VC	0x00000001
#define	RES_F_CONN	0x00000002
#define RES_F_EDNS0ERR	0x00000004

#define	RES_EXHAUSTIVE	0x00000001

#define RES_INIT	0x00000001
#define RES_DEBUG	0x00000002
#define RES_AAONLY	0x00000004
#define RES_USEVC	0x00000008
#define RES_PRIMARY	0x00000010
#define RES_IGNTC	0x00000020
#define RES_RECURSE	0x00000040
#define RES_DEFNAMES	0x00000080
#define RES_STAYOPEN	0x00000100
#define RES_DNSRCH	0x00000200
#define	RES_INSECURE1	0x00000400
#define	RES_INSECURE2	0x00000800
#define	RES_NOALIASES	0x00001000
#define	RES_USE_INET6	0x00002000
#define RES_ROTATE	0x00004000
#define	RES_NOCHECKNAME	0x00008000
#define	RES_KEEPTSIG	0x00010000
#define	RES_BLAST	0x00020000
#define RES_USEBSTRING	0x00040000
#define RES_NOIP6DOTINT	0x00080000
#define RES_USE_EDNS0	0x00100000
#define RES_SNGLKUP	0x00200000
#define RES_SNGLKUPREOP	0x00400000
#define RES_USE_DNSSEC	0x00800000

#define RES_DEFAULT	(RES_RECURSE|RES_DEFNAMES|RES_DNSRCH|RES_NOIP6DOTINT)

#define RES_PRF_STATS	0x00000001
#define RES_PRF_UPDATE	0x00000002
#define RES_PRF_CLASS   0x00000004
#define RES_PRF_CMD	0x00000008
#define RES_PRF_QUES	0x00000010
#define RES_PRF_ANS	0x00000020
#define RES_PRF_AUTH	0x00000040
#define RES_PRF_ADD	0x00000080
#define RES_PRF_HEAD1	0x00000100
#define RES_PRF_HEAD2	0x00000200
#define RES_PRF_TTLID	0x00000400
#define RES_PRF_HEADX	0x00000800
#define RES_PRF_QUERY	0x00001000
#define RES_PRF_REPLY	0x00002000
#define RES_PRF_INIT	0x00004000

struct __res_state *__res_state(void);
#define _res (*__res_state())

int res_init(void);
int res_query(const char *, int, int, unsigned char *, int);
int res_querydomain(const char *, const char *, int, int, unsigned char *, int);
int res_search(const char *, int, int, unsigned char *, int);
int res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int);
int res_send(const unsigned char *, int, unsigned char *, int);
int dn_comp(const char *, unsigned char *, int, unsigned char **, unsigned char **);
int dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int);
int dn_skipname(const unsigned char *, const unsigned char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/search.h */

#define COSMOPOLITAN_THIRDPARTY_MUSL_SEARCH_H

typedef enum { FIND, ENTER } ACTION;
typedef enum { preorder, postorder, endorder, leaf } VISIT;

typedef struct entry {
	char *key;
	void *data;
} ENTRY;

int hcreate(size_t);
void hdestroy(void);
ENTRY *hsearch(ENTRY, ACTION);

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct hsearch_data {
	struct __tab *__tab;
	unsigned int __unused1;
	unsigned int __unused2;
};

int hcreate_r(size_t, struct hsearch_data *);
void hdestroy_r(struct hsearch_data *);
int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *);
#endif

void insque(void *, void *);
void remque(void *);

void *lsearch(const void *, void *, size_t *, size_t,
	int (*)(const void *, const void *));
void *lfind(const void *, const void *, size_t *, size_t,
	int (*)(const void *, const void *));

void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *));
void *tfind(const void *, void *const *, int(*)(const void *, const void *));
void *tsearch(const void *, void **, int (*)(const void *, const void *));
void twalk(const void *, void (*)(const void *, VISIT, int));

#if defined(_GNU_SOURCE) || defined(_COSMO_SOURCE)
struct qelem {
	struct qelem *q_forw, *q_back;
	char q_data[1];
};

void tdestroy(void *, void (*)(void *));
#endif



/*!BEGIN third_party/musl/shadow.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_SHADOW_H_
COSMOPOLITAN_C_START_

#define	SHADOW "/etc/shadow"

struct spwd {
	char *sp_namp;
	char *sp_pwdp;
	long sp_lstchg;
	long sp_min;
	long sp_max;
	long sp_warn;
	long sp_inact;
	long sp_expire;
	unsigned long sp_flag;
};

void setspent(void);
void endspent(void);
struct spwd *getspent(void);
struct spwd *fgetspent(FILE *);
struct spwd *sgetspent(const char *);
int putspent(const struct spwd *, FILE *);

struct spwd *getspnam(const char *);
int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **);

int lckpwdf(void);
int ulckpwdf(void);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/musl/tempnam.h */

#define COSMOPOLITAN_THIRD_PARTY_MUSL_TEMPNAM_H_
COSMOPOLITAN_C_START_

char *tempnam(const char *, const char *);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/zlib/zconf.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZCONF_H_

#define STDC
#define STDC99
#define MAX_MEM_LEVEL 9
#define DEF_MEM_LEVEL 8
#define MAX_WBITS     15 /* 32K LZ77 window */

#ifdef MODE_DBG
#define ZLIB_DEBUG
#endif

#define z_const const

#define Z_COSMO_PREFIX_SET

#define Bytef                    _Cz_Bytef
#define _dist_code               _Cz__dist_code
#define _length_code             _Cz__length_code
#define _tr_align                _Cz__tr_align
#define _tr_flush_bits           _Cz__tr_flush_bits
#define _tr_flush_block          _Cz__tr_flush_block
#define _tr_init                 _Cz__tr_init
#define _tr_stored_block         _Cz__tr_stored_block
#define _tr_tally                _Cz__tr_tally
#define adler32                  _Cz_adler32
#define adler32_combine          _Cz_adler32_combine
#define adler32_combine64        _Cz_adler32_combine64
#define adler32_simd_            _Cz_adler32_simd_
#define adler32_z                _Cz_adler32_z
#define alloc_func               _Cz_alloc_func
#define arm_check_features       _Cz_arm_check_features
#define arm_cpu_enable_crc32     _Cz_arm_cpu_enable_crc32
#define arm_cpu_enable_pmull     _Cz_arm_cpu_enable_pmull
#define armv8_crc32_little       _Cz_armv8_crc32_little
#define armv8_crc32_pmull_little _Cz_armv8_crc32_pmull_little
#define charf                    _Cz_charf
#define compress                 _Cz_compress
#define compress2                _Cz_compress2
#define compressBound            _Cz_compressBound
#define copy_with_crc            _Cz_copy_with_crc
#define cpu_check_features       _Cz_cpu_check_features
#define crc32                    _Cz_crc32
#define crc32_combine            _Cz_crc32_combine
#define crc32_combine64          _Cz_crc32_combine64
#define crc32_combine_gen        _Cz_crc32_combine_gen
#define crc32_combine_gen64      _Cz_crc32_combine_gen64
#define crc32_combine_op         _Cz_crc32_combine_op
#define crc32_sse42_simd_        _Cz_crc32_sse42_simd_
#define crc32_z                  _Cz_crc32_z
#define crc_finalize             _Cz_crc_finalize
#define crc_fold_512to32         _Cz_crc_fold_512to32
#define crc_fold_copy            _Cz_crc_fold_copy
#define crc_fold_init            _Cz_crc_fold_init
#define crc_reset                _Cz_crc_reset
#define deflate                  _Cz_deflate
#define deflateBound             _Cz_deflateBound
#define deflateCopy              _Cz_deflateCopy
#define deflateEnd               _Cz_deflateEnd
#define deflateGetDictionary     _Cz_deflateGetDictionary
#define deflateInit              _Cz_deflateInit
#define deflateInit2             _Cz_deflateInit2
#define deflateParams            _Cz_deflateParams
#define deflatePending           _Cz_deflatePending
#define deflatePrime             _Cz_deflatePrime
#define deflateReset             _Cz_deflateReset
#define deflateResetKeep         _Cz_deflateResetKeep
#define deflateSetDictionary     _Cz_deflateSetDictionary
#define deflateSetHeader         _Cz_deflateSetHeader
#define deflateTune              _Cz_deflateTune
#define deflate_copyright        _Cz_deflate_copyright
#define deflate_read_buf         _Cz_deflate_read_buf
#define fill_window_sse          _Cz_fill_window_sse
#define free_func                _Cz_free_func
#define get_crc_table            _Cz_get_crc_table
#define gzFile                   _Cz_gzFile
#define gz_error                 _Cz_gz_error
#define gz_header                _Cz_gz_header
#define gz_header_s              _Cz_gz_header_s
#define gz_headerp               _Cz_gz_headerp
#define gz_intmax                _Cz_gz_intmax
#define gz_strwinerror           _Cz_gz_strwinerror
#define gzbuffer                 _Cz_gzbuffer
#define gzclearerr               _Cz_gzclearerr
#define gzclose                  _Cz_gzclose
#define gzclose_r                _Cz_gzclose_r
#define gzclose_w                _Cz_gzclose_w
#define gzdirect                 _Cz_gzdirect
#define gzdopen                  _Cz_gzdopen
#define gzeof                    _Cz_gzeof
#define gzerror                  _Cz_gzerror
#define gzflush                  _Cz_gzflush
#define gzfread                  _Cz_gzfread
#define gzfwrite                 _Cz_gzfwrite
#define gzgetc                   _Cz_gzgetc
#define gzgetc_                  _Cz_gzgetc_
#define gzgets                   _Cz_gzgets
#define gzoffset                 _Cz_gzoffset
#define gzoffset64               _Cz_gzoffset64
#define gzopen                   _Cz_gzopen
#define gzopen64                 _Cz_gzopen64
#define gzopen_w                 _Cz_gzopen_w
#define gzprintf                 _Cz_gzprintf
#define gzputc                   _Cz_gzputc
#define gzputs                   _Cz_gzputs
#define gzread                   _Cz_gzread
#define gzrewind                 _Cz_gzrewind
#define gzseek                   _Cz_gzseek
#define gzseek64                 _Cz_gzseek64
#define gzsetparams              _Cz_gzsetparams
#define gztell                   _Cz_gztell
#define gztell64                 _Cz_gztell64
#define gzungetc                 _Cz_gzungetc
#define gzvprintf                _Cz_gzvprintf
#define gzwrite                  _Cz_gzwrite
#define in_func                  _Cz_in_func
#define inflate                  _Cz_inflate
#define inflateBack              _Cz_inflateBack
#define inflateBackEnd           _Cz_inflateBackEnd
#define inflateBackInit_         _Cz_inflateBackInit_
#define inflateCodesUsed         _Cz_inflateCodesUsed
#define inflateCopy              _Cz_inflateCopy
#define inflateEnd               _Cz_inflateEnd
#define inflateGetDictionary     _Cz_inflateGetDictionary
#define inflateGetHeader         _Cz_inflateGetHeader
#define inflateInit              _Cz_inflateInit
#define inflateInit2             _Cz_inflateInit2
#define inflateMark              _Cz_inflateMark
#define inflatePrime             _Cz_inflatePrime
#define inflateReset             _Cz_inflateReset
#define inflateReset2            _Cz_inflateReset2
#define inflateResetKeep         _Cz_inflateResetKeep
#define inflateSetDictionary     _Cz_inflateSetDictionary
#define inflateSync              _Cz_inflateSync
#define inflateSyncPoint         _Cz_inflateSyncPoint
#define inflateUndermine         _Cz_inflateUndermine
#define inflateValidate          _Cz_inflateValidate
#define inflate_copyright        _Cz_inflate_copyright
#define inflate_fast             _Cz_inflate_fast
#define inflate_fast_chunk_      _Cz_inflate_fast_chunk_
#define inflate_table            _Cz_inflate_table
#define intf                     _Cz_intf
#define out_func                 _Cz_out_func
#define uInt                     _Cz_uInt
#define uIntf                    _Cz_uIntf
#define uLong                    _Cz_uLong
#define uLongf                   _Cz_uLongf
#define uncompress               _Cz_uncompress
#define uncompress2              _Cz_uncompress2
#define voidp                    _Cz_voidp
#define voidpc                   _Cz_voidpc
#define voidpf                   _Cz_voidpf
#define x86_check_features       _Cz_x86_check_features
#define x86_cpu_enable_simd      _Cz_x86_cpu_enable_simd
#define x86_cpu_enable_sse2      _Cz_x86_cpu_enable_sse2
#define x86_cpu_enable_ssse3     _Cz_x86_cpu_enable_ssse3
#define zError                   _Cz_zError
#define z_errmsg                 _Cz_z_errmsg
#define zcalloc                  _Cz_zcalloc
#define zcfree                   _Cz_zcfree
#define zlibCompileFlags         _Cz_zlibCompileFlags
#define zlibVersion              _Cz_zlibVersion


typedef unsigned char Byte;
typedef unsigned int uInt;   /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
typedef Byte Bytef;
typedef char charf;
typedef int intf;
typedef uInt uIntf;
typedef uLong uLongf;
typedef void const *voidpc;
typedef void *voidpf;
typedef void *voidp;
typedef uint32_t z_crc_t;
typedef int64_t z_off64_t;
typedef size_t z_size_t;



/*!BEGIN third_party/zlib/zlib.h */

#define COSMOPOLITAN_THIRD_PARTY_ZLIB_ZLIB_H_

/**
 * @fileoverview zlib
 *
 * The 'zlib' compression library provides in-memory
 * compression and decompression functions, including integrity checks
 * of the uncompressed data. This version of the library supports only
 * one compression method (deflation) but other algorithms will be added
 * later and will have the same stream interface.
 *
 * Compression can be done in a single step if the buffers are large enough,
 * or can be done by repeated calls of the compression function.  In the latter
 * case, the application must provide more input and/or consume the output
 * (providing more output space) before each call.
 *
 * The compressed data format used by default by the in-memory functions is
 * the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
 * around a deflate stream, which is itself documented in RFC 1951.
 *
 * The library also supports reading and writing files in gzip (.gz) format
 * with an interface similar to that of stdio using the functions that start
 * with "gz".  The gzip format is different from the zlib format.  gzip is a
 * gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
 *
 * This library can optionally read and write gzip and raw deflate streams in
 * memory as well.
 *
 * The zlib format was designed to be compact and fast for use in memory
 * and on communications channels.  The gzip format was designed for single-
 * file compression on file systems, has a larger header than zlib to maintain
 * directory information, and uses a different, slower check method than zlib.
 *
 * The library does not install any signal handler.  The decoder checks
 * the consistency of the compressed data, so the library should never crash
 * even in the case of corrupted input.
 */

#define ZLIB_VERSION         "1.2.11"
#define ZLIB_VERNUM          0x12b0
#define ZLIB_VER_MAJOR       1
#define ZLIB_VER_MINOR       2
#define ZLIB_VER_REVISION    11
#define ZLIB_VER_SUBREVISION 0

/**
 * The application must update next_in and avail_in when avail_in has
 * dropped to zero. It must update next_out and avail_out when avail_out
 * has dropped to zero. The application must initialize zalloc, zfree
 * and opaque before calling the init function. All other fields are set
 * by the compression library and must not be updated by the
 * application.
 *
 * The opaque value provided by the application will be passed as the
 * first parameter for calls of zalloc and zfree. This can be useful for
 * custom memory management. The compression library attaches no meaning
 * to the opaque value.
 *
 * zalloc must return Z_NULL if there is not enough memory for the
 * object. If zlib is used in a multi-threaded application, zalloc and
 * zfree must be thread safe. In that case, zlib is thread-safe. When
 * zalloc and zfree are Z_NULL on entry to the initialization function,
 * they are set to internal routines that use the standard library
 * functions malloc() and free().
 *
 * On 16-bit systems, the functions zalloc and zfree must be able to
 * allocate exactly 65536 bytes, but will not be required to allocate
 * more than this if the symbol MAXSEG_64K is defined (see zconf.h).
 * WARNING: On MSDOS, pointers returned by zalloc for objects of exactly
 * 65536 bytes *must* have their offset normalized to zero. The default
 * allocation function provided by this library ensures this (see
 * zutil.c). To reduce memory requirements and avoid any allocation of
 * 64K objects, at the expense of compression ratio, compile the library
 * with -DMAX_WBITS=14 (see zconf.h).
 *
 * The fields total_in and total_out can be used for statistics or
 * progress reports. After compression, total_in holds the total size of
 * the uncompressed data and may be saved for use by the decompressor
 * (particularly if the decompressor wants to decompress everything in a
 * single step).
 */
#define Z_NO_FLUSH      0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH    2
#define Z_FULL_FLUSH    3
#define Z_FINISH        4
#define Z_BLOCK         5
#define Z_TREES         6

/**
 * Allowed flush values; see deflate() and inflate() below for details.
 */
#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO         (-1)
#define Z_STREAM_ERROR  (-2)
#define Z_DATA_ERROR    (-3)
#define Z_MEM_ERROR     (-4)
#define Z_BUF_ERROR     (-5)
#define Z_VERSION_ERROR (-6)

/**
 * Return codes for the compression/decompression functions. Negative
 * values are errors, positive values are used for special but normal
 * events.
 */
#define Z_NO_COMPRESSION      0
#define Z_BEST_SPEED          1
#define Z_BEST_COMPRESSION    9
#define Z_DEFAULT_COMPRESSION (-1)

/**
 * Compression levels.
 */
#define Z_FILTERED         1
#define Z_HUFFMAN_ONLY     2
#define Z_RLE              3
#define Z_FIXED            4
#define Z_DEFAULT_STRATEGY 0

/**
 * Compression strategy; see deflateInit2() below for details
 */
#define Z_BINARY  0
#define Z_TEXT    1
#define Z_ASCII   Z_TEXT /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN 2

/**
 * Possible values of the data_type field for deflate()
 */
#define Z_DEFLATED 8

/* The deflate compression method (the only one supported in this version) */
#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */

COSMOPOLITAN_C_START_

typedef voidpf (*alloc_func)(voidpf opaque, uInt items, uInt size);
typedef void (*free_func)(voidpf opaque, voidpf address);

struct internal_state;

typedef struct z_stream_s {
  const Bytef *next_in;         /* next input byte */
  uInt avail_in;                /* number of bytes available at next_in */
  uLong total_in;               /* total number of input bytes read so far */
  Bytef *next_out;              /* next output byte will go here */
  uInt avail_out;               /* remaining free space at next_out */
  uLong total_out;              /* total number of bytes output so far */
  const char *msg;              /* last error message, NULL if no error */
  struct internal_state *state; /* not visible by applications */
  alloc_func zalloc;            /* used to allocate the internal state */
  free_func zfree;              /* used to free the internal state */
  voidpf opaque;  /* private data object passed to zalloc and zfree */
  int data_type;  /* best guess about the data type: binary or text
                     for deflate, or the decoding state for inflate */
  uLong adler;    /* Adler-32 or CRC-32 value of the uncompressed data */
  uLong reserved; /* reserved for future use */
} z_stream;

typedef z_stream *z_streamp;

/**
 * gzip header information passed to and from zlib routines. See RFC
 * 1952 for more details on the meanings of these fields.
 */
typedef struct gz_header_s {
  int text;       /* true if compressed data believed to be text */
  uLong time_;    /* modification time */
  int xflags;     /* extra flags (not used when writing a gzip file) */
  int os;         /* operating system */
  Bytef *extra;   /* pointer to extra field or Z_NULL if none */
  uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  uInt extra_max; /* space at extra (only when reading header) */
  Bytef *name;    /* pointer to zero-terminated file name or Z_NULL */
  uInt name_max;  /* space at name (only when reading header) */
  Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  uInt comm_max;  /* space at comment (only when reading header) */
  int hcrc;       /* true if there was or will be a header crc */
  int done;       /* true when done reading gzip header (not used
                     when writing a gzip file) */
} gz_header;

typedef gz_header *gz_headerp;

#define zlib_version zlibVersion()

/**
 * The application can compare zlibVersion and ZLIB_VERSION for consistency.
 * If the first character differs, the library code actually used is not
 * compatible with the zlib.h header file used by the application.  This check
 * is automatically made by deflateInit and inflateInit.
 */
const char *zlibVersion(void);

/**
 * Initializes the internal stream state for compression.  The fields
 * zalloc, zfree and opaque must be initialized before by the caller.  If
 * zalloc and zfree are set to Z_NULL, deflateInit updates them to use default
 * allocation functions.
 *
 * The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
 * 1 gives best speed, 9 gives best compression, 0 gives no compression at all
 * (the input data is simply copied a block at a time).  Z_DEFAULT_COMPRESSION
 * requests a default compromise between speed and compression (currently
 * equivalent to level 6).
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if level is not a valid compression level. msg
 *     is set to null if there is no error message. deflateInit does not
 *     perform any compression: this will be done by deflate().
 */
int deflateInit(z_streamp strm, int level);

/**
 * deflate compresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full. It may
 * introduce some output latency (reading input without producing any
 * output) except when forced to flush.
 *
 * The detailed semantics are as follows. deflate performs one or both
 * of the following actions:
 *
 * - Compress more input starting at next_in and update next_in and
 *  avail_in accordingly. If not all input can be processed (because
 *  there is not enough room in the output buffer), next_in and avail_in
 *  are updated and processing will resume at this point for the next
 *  call of deflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *  avail_out accordingly. This action is forced if the parameter flush
 *  is non zero. Forcing flush frequently degrades the compression
 *  ratio, so this parameter should be set only when necessary. Some
 *  output may be provided even if flush is zero.
 *
 * Before the call of deflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating avail_in or avail_out
 * accordingly; avail_out should never be zero before the call. The
 * application can consume the compressed output when it wants, for
 * example when the output buffer is full (avail_out == 0), or after
 * each call of deflate(). If deflate returns Z_OK and with zero
 * avail_out, it must be called again after making room in the output
 * buffer because there might be more output pending. See
 * deflatePending(), which can be used if desired to determine whether
 * or not there is more ouput in that case.
 *
 * Normally the parameter flush is set to Z_NO_FLUSH, which allows
 * deflate to decide how much data to accumulate before producing
 * output, in order to maximize compression.
 *
 * If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
 * flushed to the output buffer and the output is aligned on a byte
 * boundary, so that the decompressor can get all input data available
 * so far. (In particular avail_in is zero after the call if enough
 * output space has been provided before the call.) Flushing may degrade
 * compression for some compression algorithms and so it should be used
 * only when necessary. This completes the current deflate block and
 * follows it with an empty stored block that is three bits plus filler
 * bits to the next byte, followed by four bytes (00 00 ff ff).
 *
 * If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to
 * the output buffer, but the output is not aligned to a byte boundary.
 * All of the input data so far will be available to the decompressor,
 * as for Z_SYNC_FLUSH. This completes the current deflate block and
 * follows it with an empty fixed codes block that is 10 bits long. This
 * assures that enough bytes are output in order for the decompressor to
 * finish the block before the empty fixed codes block.
 *
 * If flush is set to Z_BLOCK, a deflate block is completed and emitted,
 * as for Z_SYNC_FLUSH, but the output is not aligned on a byte
 * boundary, and up to seven bits of the current block are held to be
 * written as the next byte after the next deflate block is completed.
 * In this case, the decompressor may not be provided enough bits at
 * this point in order to complete decompression of the data provided so
 * far to the compressor. It may need to wait for the next block to be
 * emitted. This is for advanced applications that need to control the
 * emission of deflate blocks.
 *
 * If flush is set to Z_FULL_FLUSH, all output is flushed as with
 * Z_SYNC_FLUSH, and the compression state is reset so that
 * decompression can restart from this point if previous compressed data
 * has been damaged or if random access is desired. Using Z_FULL_FLUSH
 * too often can seriously degrade compression.
 *
 * If deflate returns with avail_out == 0, this function must be called
 * again with the same value of the flush parameter and more output
 * space (updated avail_out), until the flush is complete (deflate
 * returns with non-zero avail_out). In the case of a Z_FULL_FLUSH or
 * Z_SYNC_FLUSH, make sure that avail_out is greater than six to avoid
 * repeated flush markers due to avail_out == 0 on return.
 *
 * If the parameter flush is set to Z_FINISH, pending input is
 * processed, pending output is flushed and deflate returns with
 * Z_STREAM_END if there was enough output space. If deflate returns
 * with Z_OK or Z_BUF_ERROR, this function must be called again with
 * Z_FINISH and more output space (updated avail_out) but no more input
 * data, until it returns with Z_STREAM_END or an error. After deflate
 * has returned Z_STREAM_END, the only possible operations on the stream
 * are deflateReset or deflateEnd.
 *
 * Z_FINISH can be used in the first deflate call after deflateInit if
 * all the compression is to be done in a single step. In order to
 * complete in one call, avail_out must be at least the value returned
 * by deflateBound (see below). Then deflate is guaranteed to return
 * Z_STREAM_END. If not enough output space is provided, deflate will
 * not return Z_STREAM_END, and it must be called again as described
 * above.
 *
 * deflate() sets strm->adler to the Adler-32 checksum of all input read
 * so far (that is, total_in bytes). If a gzip stream is being
 * generated, then strm->adler will be the CRC-32 checksum of the input
 * read so far. (See deflateInit2 below.)
 *
 * deflate() may update strm->data_type if it can make a good guess about
 * the input data type (Z_BINARY or Z_TEXT).  If in doubt, the data is
 * considered binary.  This field is only for information purposes and does not
 * affect the compression algorithm in any manner.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if all input has been
 *     consumed and all output has been produced (only when flush is set
 *     to Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent
 *     (for example if next_in or next_out was Z_NULL or the state was
 *     inadvertently written over by the application), or Z_BUF_ERROR if
 *     no progress is possible (for example avail_in or avail_out was
 *     zero). Note that Z_BUF_ERROR is not fatal, and deflate() can be
 *     called again with more input and more output space to continue
 *     compressing.
 */
int deflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the stream state was
 *     inconsistent, Z_DATA_ERROR if the stream was freed prematurely
 *     (some input or output was discarded). In the error case, msg may
 *     be set but then points to a static string (which must not be
 *     deallocated).
 */
int deflateEnd(z_streamp strm);

/**
 * Initializes the internal stream state for decompression. The fields
 * next_in, avail_in, zalloc, zfree and opaque must be initialized
 * before by the caller. In the current version of inflate, the provided
 * input is not read or consumed. The allocation of a sliding window
 * will be deferred to the first call of inflate (if the decompression
 * does not complete on the first call). If zalloc and zfree are set to
 * Z_NULL, inflateInit updates them to use default allocation functions.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit does not perform any decompression. Actual
 *     decompression will be done by inflate(). So next_in, and
 *     avail_in, next_out, and avail_out are unused and unchanged. The
 *     current implementation of inflateInit() does not process any
 *     header information -- that is deferred until inflate() is called.
 */
int inflateInit(z_streamp strm);

/**
 * inflate decompresses as much data as possible, and stops when the input
 * buffer becomes empty or the output buffer becomes full.  It may introduce
 * some output latency (reading input without producing any output) except when
 * forced to flush.
 *
 * The detailed semantics are as follows.  inflate performs one or both of the
 * following actions:
 *
 * - Decompress more input starting at next_in and update next_in and
 *   avail_in accordingly. If not all input can be processed (because
 *   there is not enough room in the output buffer), then next_in and
 *   avail_in are updated accordingly, and processing will resume at
 *   this point for the next call of inflate().
 *
 * - Generate more output starting at next_out and update next_out and
 *   avail_out accordingly. inflate() provides as much output as
 *   possible, until there is no more input data or no more space in the
 *   output buffer (see below about the flush parameter).
 *
 * Before the call of inflate(), the application should ensure that at
 * least one of the actions is possible, by providing more input and/or
 * consuming more output, and updating the next_* and avail_* values
 * accordingly. If the caller of inflate() does not provide both
 * available input and available output space, it is possible that there
 * will be no progress made. The application can consume the
 * uncompressed output when it wants, for example when the output buffer
 * is full (avail_out == 0), or after each call of inflate(). If inflate
 * returns Z_OK and with zero avail_out, it must be called again after
 * making room in the output buffer because there might be more output
 * pending.
 *
 * The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
 * Z_FINISH, Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate()
 * flush as much output as possible to the output buffer. Z_BLOCK
 * requests that inflate() stop if and when it gets to the next deflate
 * block boundary. When decoding the zlib or gzip format, this will
 * cause inflate() to return immediately after the header and before the
 * first block. When doing a raw inflate, inflate() will go ahead and
 * process the first block, and will return when it gets to the end of
 * that block, or when it runs out of data.
 *
 * The Z_BLOCK option assists in appending to or combining deflate
 * streams. To assist in this, on return inflate() always sets
 * strm->data_type to the number of unused bits in the last byte taken
 * from strm->next_in, plus 64 if inflate() is currently decoding the
 * last block in the deflate stream, plus 128 if inflate() returned
 * immediately after decoding an end-of-block code or decoding the
 * complete header up to just before the first byte of the deflate
 * stream. The end-of-block will not be indicated until all of the
 * uncompressed data from that block has been written to strm->next_out.
 * The number of unused bits may in general be greater than seven,
 * except when bit 7 of data_type is set, in which case the number of
 * unused bits will be less than eight. data_type is set as noted here
 * every time inflate() returns for all flush options, and so can be
 * used to determine the amount of currently consumed input in bits.
 *
 * The Z_TREES option behaves as Z_BLOCK does, but it also returns when
 * the end of each deflate block header is reached, before any actual
 * data in that block is decoded. This allows the caller to determine
 * the length of the deflate block header for later use in random access
 * within a deflate block. 256 is added to the value of strm->data_type
 * when inflate() returns immediately after reaching the end of the
 * deflate block header.
 *
 * inflate() should normally be called until it returns Z_STREAM_END or
 * an error. However if all decompression is to be performed in a single
 * step (a single call of inflate), the parameter flush should be set to
 * Z_FINISH. In this case all pending input is processed and all pending
 * output is flushed; avail_out must be large enough to hold all of the
 * uncompressed data for the operation to complete. (The size of the
 * uncompressed data may have been saved by the compressor for this
 * purpose.) The use of Z_FINISH is not required to perform an inflation
 * in one step. However it may be used to inform inflate that a faster
 * approach can be used for the single inflate() call. Z_FINISH also
 * informs inflate to not maintain a sliding window if the stream
 * completes, which reduces inflate's memory footprint. If the stream
 * does not complete, either because not all of the stream is provided
 * or not enough output space is provided, then a sliding window will be
 * allocated and inflate() can be called again to continue the operation
 * as if Z_NO_FLUSH had been used.
 *
 * In this implementation, inflate() always flushes as much output as
 * possible to the output buffer, and always uses the faster approach on
 * the first call. So the effects of the flush parameter in this
 * implementation are on the return value of inflate() as noted below,
 * when inflate() returns early when Z_BLOCK or Z_TREES is used, and
 * when inflate() avoids the allocation of memory for a sliding window
 * when Z_FINISH is used.
 *
 * If a preset dictionary is needed after this call (see
 * inflateSetDictionary below), inflate sets strm->adler to the Adler-32
 * checksum of the dictionary chosen by the compressor and returns
 * Z_NEED_DICT; otherwise it sets strm->adler to the Adler-32 checksum
 * of all output produced so far (that is, total_out bytes) and returns
 * Z_OK, Z_STREAM_END or an error code as described below. At the end of
 * the stream, inflate() checks that its computed Adler-32 checksum is
 * equal to that saved by the compressor and returns Z_STREAM_END only
 * if the checksum is correct.
 *
 * inflate() can decompress and check either zlib-wrapped or
 * gzip-wrapped deflate data. The header type is detected automatically,
 * if requested when initializing with inflateInit2(). Any information
 * contained in the gzip header is not retained unless
 * inflateGetHeader() is used. When processing gzip-wrapped deflate
 * data, strm->adler32 is set to the CRC-32 of the output produced so
 * far. The CRC-32 is checked against the gzip trailer, as is the
 * uncompressed length, modulo 2^32.
 *
 * @return Z_OK if some progress has been made (more input processed or
 *     more output produced), Z_STREAM_END if the end of the compressed
 *     data has been reached and all uncompressed output has been
 *     produced, Z_NEED_DICT if a preset dictionary is needed at this
 *     point, Z_DATA_ERROR if the input data was corrupted (input stream
 *     not conforming to the zlib format or incorrect check value, in
 *     which case strm->msg points to a string with a more specific
 *     error), Z_STREAM_ERROR if the stream structure was inconsistent
 *     (for example next_in or next_out was Z_NULL, or the state was
 *     inadvertently written over by the application), Z_MEM_ERROR if
 *     there was not enough memory, Z_BUF_ERROR if no progress was
 *     possible or if there was not enough room in the output buffer
 *     when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
 *     inflate() can be called again with more input and more output
 *     space to continue decompressing. If Z_DATA_ERROR is returned, the
 *     application may then call inflateSync() to look for a good
 *     compression block if a partial recovery of the data is to be
 *     attempted.
 */
int inflate(z_streamp strm, int flush);

/**
 * All dynamically allocated data structures for this stream are freed.
 * This function discards any unprocessed input and does not flush any
 * pending output.
 *
 * @return Z_OK or Z_STREAM_ERROR if stream state inconsistent
 */
int inflateEnd(z_streamp strm);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » special functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  the following functions are needed only in some special applications */

/**
 * This is another version of deflateInit with more compression options.
 * The fields next_in, zalloc, zfree and opaque must be initialized
 * before by the caller.
 *
 * The method parameter is the compression method. It must be Z_DEFLATED
 * in this version of the library.
 *
 * The windowBits parameter is the base two logarithm of the window size
 * (the size of the history buffer). It should be in the range 8..15 for
 * this version of the library. Larger values of this parameter result
 * in better compression at the expense of memory usage. The default
 * value is 15 if deflateInit is used instead.
 *
 * For the current implementation of deflate(), a windowBits value of 8
 * (a window size of 256 bytes) is not supported. As a result, a request
 * for 8 will result in 9 (a 512-byte window). In that case, providing 8
 * to inflateInit2() will result in an error when the zlib header with 9
 * is checked against the initialization of inflate(). The remedy is to
 * not use 8 with deflateInit2() with this initialization, or at least
 * in that case use 9 with inflateInit2().
 *
 * windowBits can also be -8..-15 for raw deflate. In this case,
 * -windowBits determines the window size. deflate() will then generate
 * raw deflate data with no zlib header or trailer, and will not compute
 * a check value.
 *
 * windowBits can also be greater than 15 for optional gzip encoding.
 * Add 16 to windowBits to write a simple gzip header and trailer around
 * the compressed data instead of a zlib wrapper. The gzip header will
 * have no file name, no extra data, no comment, no modification time
 * (set to zero), no header crc, and the operating system will be set to
 * the appropriate value, if the operating system was determined at
 * compile time. If a gzip stream is being written, strm->adler is a
 * CRC-32 instead of an Adler-32.
 *
 * For raw deflate or gzip encoding, a request for a 256-byte window is
 * rejected as invalid, since only the zlib header provides a means of
 * transmitting the window size to the decompressor.
 *
 * The memLevel parameter specifies how much memory should be allocated
 * for the internal compression state. memLevel=1 uses minimum memory
 * but is slow and reduces compression ratio; memLevel=9 uses maximum
 * memory for optimal speed. The default value is 8. See zconf.h for
 * total memory usage as a function of windowBits and memLevel.
 *
 * The strategy parameter is used to tune the compression algorithm. Use
 * the value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data
 * produced by a filter (or predictor), Z_HUFFMAN_ONLY to force Huffman
 * encoding only (no string match), or Z_RLE to limit match distances to
 * one (run-length encoding). Filtered data consists mostly of small
 * values with a somewhat random distribution. In this case, the
 * compression algorithm is tuned to compress them better. The effect of
 * Z_FILTERED is to force more Huffman coding and less string matching;
 * it is somewhat intermediate between Z_DEFAULT_STRATEGY and
 * Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
 * Z_HUFFMAN_ONLY, but give better compression for PNG image data. The
 * strategy parameter only affects the compression ratio but not the
 * correctness of the compressed output even if it is not set
 * appropriately. Z_FIXED prevents the use of dynamic Huffman codes,
 * allowing for a simpler decoder for special applications.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if any parameter is invalid (such as an invalid
 *     method). msg is set to null if there is no error message.
 *     deflateInit2 does not perform any compression: this will be done
 *     by deflate().
 */
int deflateInit2(z_streamp strm, int level, int method, int windowBits,
                 int memLevel, int strategy);

/**
 * Initializes the compression dictionary from the given byte sequence
 * without producing any compressed output. When using the zlib format,
 * this function must be called immediately after deflateInit,
 * deflateInit2 or deflateReset, and before any call of deflate. When
 * doing raw deflate, this function must be called either before any
 * call of deflate, or immediately after the completion of a deflate
 * block, i.e. after all input has been consumed and all output has been
 * delivered when using any of the flush options Z_BLOCK,
 * Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The compressor and
 * decompressor must use exactly the same dictionary (see
 * inflateSetDictionary).
 *
 * The dictionary should consist of strings (byte sequences) that are
 * likely to be encountered later in the data to be compressed, with the
 * most commonly used strings preferably put towards the end of the
 * dictionary. Using a dictionary is most useful when the data to be
 * compressed is short and can be predicted with good accuracy; the data
 * can then be compressed better than with the default empty dictionary.
 *
 * Depending on the size of the compression data structures selected by
 * deflateInit or deflateInit2, a part of the dictionary may in effect
 * be discarded, for example if the dictionary is larger than the window
 * size provided in deflateInit or deflateInit2. Thus the strings most
 * likely to be useful should be put at the end of the dictionary, not
 * at the front. In addition, the current implementation of deflate will
 * use at most the window size minus 262 bytes of the provided
 * dictionary.
 *
 * Upon return of this function, strm->adler is set to the Adler-32
 * value of the dictionary; the decompressor may later use this value to
 * determine which dictionary has been used by the compressor. (The
 * Adler-32 value applies to the whole dictionary even if only a subset
 * of the dictionary is actually used by the compressor.) If a raw
 * deflate was requested, then the Adler-32 value is not computed and
 * strm->adler is not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent (for example if deflate has already been called for
 *     this stream or if not at a block boundary for raw deflate).
 *     deflateSetDictionary does not perform any compression: this will
 *     be done by deflate().
 */
int deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by deflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If deflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * deflateGetDictionary() may return a length less than the window size, even
 * when more than the window size in input has been provided. It may return up
 * to 258 bytes less in that case, due to how zlib's implementation of deflate
 * manages the sliding window and lookahead for matches, where matches can be
 * up to 258 bytes long. If the application needs the last window-size bytes of
 * input, then that would need to be saved by the application outside of zlib.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int deflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Sets destination stream as a complete copy of the source stream.
 *
 * This function can be useful when several compression strategies will be
 * tried, for example when there are several ways of pre-processing the input
 * data with a filter.  The streams that will be discarded should then be freed
 * by calling deflateEnd.  Note that deflateCopy duplicates the internal
 * compression state which can be quite large, so this strategy is slow and can
 * consume lots of memory.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int deflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to deflateEnd followed by deflateInit, but
 * does not free and reallocate the internal compression state.  The stream
 * will leave the compression level and any other attributes that may have been
 * set unchanged.
 *
 * deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
 * stream state was inconsistent (such as zalloc or state being Z_NULL).
 */
int deflateReset(z_streamp strm);

/**
 * Dynamically update the compression level and compression strategy.  The
 * interpretation of level and strategy is as in deflateInit2().  This can be
 * used to switch between compression and straight copy of the input data, or
 * to switch to a different kind of input data requiring a different strategy.
 * If the compression approach (which is a function of the level) or the
 * strategy is changed, and if any input has been consumed in a previous
 * deflate() call, then the input available so far is compressed with the old
 * level and strategy using deflate(strm, Z_BLOCK).  There are three approaches
 * for the compression levels 0, 1..3, and 4..9 respectively.  The new level
 * and strategy will take effect at the next call of deflate().
 *
 * If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does
 * not have enough output space to complete, then the parameter change will not
 * take effect.  In this case, deflateParams() can be called again with the
 * same parameters and more output space to try again.
 *
 * In order to assure a change in the parameters on the first try, the
 * deflate stream should be flushed using deflate() with Z_BLOCK or other flush
 * request until strm.avail_out is not zero, before calling deflateParams().
 * Then no more input data should be provided before the deflateParams() call.
 * If this is done, the old level and strategy will be applied to the data
 * compressed before deflateParams(), and the new level and strategy will be
 * applied to the the data compressed after deflateParams().
 *
 * deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream
 * state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if
 * there was not enough output space to complete the compression of the
 * available input data before a change in the strategy or approach.  Note that
 * in the case of a Z_BUF_ERROR, the parameters are not changed.  A return
 * value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be
 * retried with more output space.
 */
int deflateParams(z_streamp strm, int level, int strategy);

/**
 * Fine tune deflate's internal compression parameters. This should only
 * be used by someone who understands the algorithm used by zlib's
 * deflate for searching for the best matching string, and even then
 * only by the most fanatic optimizer trying to squeeze out the last
 * compressed bit for their specific input data. Read the deflate.c
 * source code for the meaning of the max_lazy, good_length,
 * nice_length, and max_chain parameters.
 *
 * deflateTune() can be called after deflateInit() or deflateInit2(), and
 * returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
 */
int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length,
                int max_chain);

/**
 * deflateBound() returns an upper bound on the compressed size after
 * deflation of sourceLen bytes. It must be called after deflateInit()
 * or deflateInit2(), and after deflateSetHeader(), if used. This would
 * be used to allocate an output buffer for deflation in a single pass,
 * and so would be called before deflate(). If that first deflate() call
 * is provided the sourceLen input bytes, an output buffer allocated to
 * the size returned by deflateBound(), and the flush value Z_FINISH,
 * then deflate() is guaranteed to return Z_STREAM_END. Note that it is
 * possible for the compressed size to be larger than the value returned
 * by deflateBound() if flush options other than Z_FINISH or Z_NO_FLUSH
 * are used.
 */
uLong deflateBound(z_streamp strm, uLong sourceLen);

/**
 * deflatePending() returns the number of bytes and bits of output that
 * have been generated, but not yet provided in the available output.
 * The bytes not provided would be due to the available output space
 * having being consumed. The number of bits of output not provided are
 * between 0 and 7, where they await more bits to join them in order to
 * fill out a full byte. If pending or bits are Z_NULL, then those
 * values are not set.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int deflatePending(z_streamp strm, unsigned *pending, int *bits);

/**
 * deflatePrime() inserts bits in the deflate output stream.  The intent
 * is that this function is used to start off the deflate output with the bits
 * leftover from a previous deflate stream when appending to it.  As such, this
 * function can only be used for raw deflate, and must be used before the first
 * deflate() call after a deflateInit2() or deflateReset().  bits must be less
 * than or equal to 16, and that many of the least significant bits of value
 * will be inserted in the output.
 *
 * @return Z_OK if success, Z_BUF_ERROR if there was not enough room in
 *     the internal buffer to insert the bits, or Z_STREAM_ERROR if the
 *     source stream state was inconsistent.
 */
int deflatePrime(z_streamp strm, int bits, int value);

/**
 * Provides gzip header information for when a gzip stream is requested
 * by deflateInit2(). deflateSetHeader() may be called after
 * deflateInit2() or deflateReset() and before the first call of
 * deflate(). The text, time, os, extra field, name, and comment
 * information in the provided gz_header structure are written to the
 * gzip header (xflag is ignored -- the extra flags are set according to
 * the compression level). The caller must assure that, if not Z_NULL,
 * name and comment are terminated with a zero byte, and that if extra
 * is not Z_NULL, that extra_len bytes are available there. If hcrc is
 * true, a gzip header crc is included. Note that the current versions
 * of the command-line version of gzip (up through version 1.3.x) do not
 * support header crc's, and will report that it is a "multi-part gzip
 * file" and give up.
 *
 * If deflateSetHeader is not used, the default gzip header has text
 * false, the time set to zero, and os set to 255, with no extra, name,
 * or comment fields. The gzip header is returned to the default state
 * by deflateReset().
 *
 * deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the
 * source stream state was inconsistent.
 */
int deflateSetHeader(z_streamp strm, gz_headerp head);

/**
 * This is another version of inflateInit with an extra parameter. The
 * fields next_in, avail_in, zalloc, zfree and opaque must be
 * initialized before by the caller.
 *
 * The windowBits parameter is the base two logarithm of the maximum
 * window size (the size of the history buffer). It should be in the
 * range 8..15 for this version of the library. The default value is 15
 * if inflateInit is used instead. windowBits must be greater than or
 * equal to the windowBits value provided to deflateInit2() while
 * compressing, or it must be equal to 15 if deflateInit2() was not
 * used. If a compressed stream with a larger window size is given as
 * input, inflate() will return with the error code Z_DATA_ERROR instead
 * of trying to allocate a larger window.
 *
 * windowBits can also be zero to request that inflate use the window
 * size in the zlib header of the compressed stream.
 *
 * windowBits can also be -8..-15 for raw inflate. In this case,
 * -windowBits determines the window size. inflate() will then process
 * raw deflate data, not looking for a zlib or gzip header, not
 * generating a check value, and not looking for any check values for
 * comparison at the end of the stream. This is for use with other
 * formats that use the deflate compressed data format such as zip.
 * Those formats provide their own check values. If a custom format is
 * developed using the raw deflate format for compressed data, it is
 * recommended that a check value such as an Adler-32 or a CRC-32 be
 * applied to the uncompressed data as is done in the zlib, gzip, and
 * zip formats. For most applications, the zlib format should be used as
 * is. Note that comments above on the use in deflateInit2() applies to
 * the magnitude of windowBits.
 *
 * windowBits can also be greater than 15 for optional gzip decoding.
 * Add 32 to windowBits to enable zlib and gzip decoding with automatic
 * header detection, or add 16 to decode only the gzip format (the zlib
 * format will return a Z_DATA_ERROR). If a gzip stream is being
 * decoded, strm->adler is a CRC-32 instead of an Adler-32. Unlike the
 * gunzip utility and gzread() (see below), inflate() will not
 * automatically decode concatenated gzip streams. inflate() will return
 * Z_STREAM_END at the end of the gzip stream. The state would need to
 * be reset to continue decoding a subsequent gzip stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     or Z_STREAM_ERROR if the parameters are invalid, such as a null
 *     pointer to the structure. msg is set to null if there is no error
 *     message. inflateInit2 does not perform any decompression apart
 *     from possibly reading the zlib header if present: actual
 *     decompression will be done by inflate(). (So next_in and avail_in
 *     may be modified, but next_out and avail_out are unused and
 *     unchanged.) The current implementation of inflateInit2() does not
 *     process any header information -- that is deferred until
 *     inflate() is called.
 */
int inflateInit2(z_streamp strm, int windowBits);

/**
 * Initializes the decompression dictionary from the given uncompressed
 * byte sequence. This function must be called immediately after a call
 * of inflate, if that call returned Z_NEED_DICT. The dictionary chosen
 * by the compressor can be determined from the Adler-32 value returned
 * by that call of inflate. The compressor and decompressor must use
 * exactly the same dictionary (see deflateSetDictionary). For raw
 * inflate, this function can be called at any time to set the
 * dictionary. If the provided dictionary is smaller than the window and
 * there is already data in the window, then the provided dictionary
 * will amend what's there. The application must insure that the
 * dictionary that was used for compression is provided.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if a parameter is invalid
 *     (e.g. dictionary being Z_NULL) or the stream state is
 *     inconsistent, Z_DATA_ERROR if the given dictionary doesn't match
 *     the expected one (incorrect Adler-32 value). inflateSetDictionary
 *     does not perform any decompression: this will be done by
 *     subsequent calls of inflate().
 */
int inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
                         uInt dictLength);

/**
 * Returns the sliding dictionary being maintained by inflate.  dictLength is
 * set to the number of bytes in the dictionary, and that many bytes are copied
 * to dictionary.  dictionary must have enough space, where 32768 bytes is
 * always enough.  If inflateGetDictionary() is called with dictionary equal to
 * Z_NULL, then only the dictionary length is returned, and nothing is copied.
 * Similary, if dictLength is Z_NULL, then it is not set.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state is
 *     inconsistent.
 */
int inflateGetDictionary(z_streamp strm, Bytef *dictionary, uInt *dictLength);

/**
 * Skips invalid compressed data until a possible full flush point (see
 * above for the description of deflate with Z_FULL_FLUSH) can be found,
 * or until all available input is skipped. No output is provided.
 *
 * inflateSync searches for a 00 00 FF FF pattern in the compressed
 * data. All full flush points have this pattern, but not all
 * occurrences of this pattern are full flush points.
 *
 * @return Z_OK if a possible full flush point has been found,
 *     Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no
 *     flush point has been found, or Z_STREAM_ERROR if the stream
 *     structure was inconsistent. In the success case, the application
 *     may save the current current value of total_in which indicates
 *     where valid compressed data was found. In the error case, the
 *     application may repeatedly call inflateSync, providing more input
 *     each time, until success or end of the input data.
 */
int inflateSync(z_streamp strm);

/**
 * Sets the destination stream as a complete copy of the source stream.
 *
 * This function can be useful when randomly accessing a large stream.
 * The first pass through the stream can periodically record the inflate
 * state, allowing restarting inflate at those points when randomly
 * accessing the stream.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_STREAM_ERROR if the source stream state was inconsistent (such
 *     as zalloc being Z_NULL). msg is left unchanged in both source and
 *     destination.
 */
int inflateCopy(z_streamp dest, z_streamp source);

/**
 * This function is equivalent to inflateEnd followed by inflateInit,
 * but does not free and reallocate the internal decompression state.  The
 * stream will keep attributes that may have been set by inflateInit2.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL).
 */
int inflateReset(z_streamp strm);

/**
 * This function is the same as inflateReset, but it also permits changing
 * the wrap and window size requests.  The windowBits parameter is interpreted
 * the same as it is for inflateInit2.  If the window size is changed, then the
 * memory allocated for the window is freed, and the window will be reallocated
 * by inflate() if needed.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent (such as zalloc or state being Z_NULL), or if
 *     the windowBits parameter is invalid.
 */
int inflateReset2(z_streamp strm, int windowBits);

/**
 * This function inserts bits in the inflate input stream.  The intent is
 * that this function is used to start inflating at a bit position in the
 * middle of a byte.  The provided bits will be used before any bytes are used
 * from next_in.  This function should only be used with raw inflate, and
 * should be used before the first inflate() call after inflateInit2() or
 * inflateReset().  bits must be less than or equal to 16, and that many of the
 * least significant bits of value will be inserted in the input.
 *
 * If bits is negative, then the input stream bit buffer is emptied.  Then
 * inflatePrime() can be called again to put bits in the buffer.  This is used
 * to clear out bits leftover after feeding inflate a block description prior
 * to feeding inflate codes.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflatePrime(z_streamp strm, int bits, int value);

/**
 * Returns two values, one in the lower 16 bits of the return value, and
 * the other in the remaining upper bits, obtained by shifting the
 * return value down 16 bits. If the upper value is -1 and the lower
 * value is zero, then inflate() is currently decoding information
 * outside of a block. If the upper value is -1 and the lower value is
 * non-zero, then inflate is in the middle of a stored block, with the
 * lower value equaling the number of bytes from the input remaining to
 * copy. If the upper value is not -1, then it is the number of bits
 * back from the current bit position in the input of the code (literal
 * or length/distance pair) currently being processed. In that case the
 * lower value is the number of bytes already emitted for that code.
 *
 * A code is being processed if inflate is waiting for more input to
 * complete decoding of the code, or if it has completed decoding but is
 * waiting for more output space to write the literal or match data.
 *
 * inflateMark() is used to mark locations in the input data for random
 * access, which may be at bit positions, and to note those cases where
 * the output of a code may span boundaries of random access blocks. The
 * current location in the input stream can be determined from avail_in
 * and data_type as noted in the description for the Z_BLOCK flush
 * parameter for inflate.
 *
 * @return the value noted above, or -65536 if the provided source
 *     stream state was inconsistent.
 */
long inflateMark(z_streamp strm);

/**
 * inflateGetHeader() requests that gzip header information be stored in
 * the provided gz_header structure. inflateGetHeader() may be called
 * after inflateInit2() or inflateReset(), and before the first call of
 * inflate(). As inflate() processes the gzip stream, head->done is zero
 * until the header is completed, at which time head->done is set to
 * one. If a zlib stream is being decoded, then head->done is set to -1
 * to indicate that there will be no gzip header information
 * forthcoming. Note that Z_BLOCK or Z_TREES can be used to force
 * inflate() to return immediately after header processing is complete
 * and before any actual data is decompressed.
 *
 * The text, time, xflags, and os fields are filled in with the gzip
 * header contents. hcrc is set to true if there is a header CRC. (The
 * header CRC was valid if done is set to one.) If extra is not Z_NULL,
 * then extra_max contains the maximum number of bytes to write to
 * extra. Once done is true, extra_len contains the actual extra field
 * length, and extra contains the extra field, or that field truncated
 * if extra_max is less than extra_len. If name is not Z_NULL, then up
 * to name_max characters are written there, terminated with a zero
 * unless the length is greater than name_max. If comment is not Z_NULL,
 * then up to comm_max characters are written there, terminated with a
 * zero unless the length is greater than comm_max. When any of extra,
 * name, or comment are not Z_NULL and the respective field is not
 * present in the header, then that field is set to Z_NULL to signal its
 * absence. This allows the use of deflateSetHeader() with the returned
 * structure to duplicate the header. However if those fields are set to
 * allocated memory, then the application will need to save those
 * pointers elsewhere so that they can be eventually freed.
 *
 * If inflateGetHeader is not used, then the header information is
 * simply discarded. The header is always checked for validity,
 * including the header CRC if present. inflateReset() will reset the
 * process to discard the header information. The application would need
 * to call inflateGetHeader() again to retrieve the header from the next
 * gzip stream.
 *
 * @return Z_OK if success, or Z_STREAM_ERROR if the source stream state
 *     was inconsistent.
 */
int inflateGetHeader(z_streamp strm, gz_headerp head);

/**
 * Initialize internal stream state for decompression using
 * inflateBack() calls. The fields zalloc, zfree and opaque in strm must
 * be initialized before the call. If zalloc and zfree are Z_NULL, then
 * the default library- derived memory allocation routines are used.
 * windowBits is the base two logarithm of the window size, in the range
 * 8..15. window is a caller supplied buffer of that size. Except for
 * special applications where it is assured that deflate was used with
 * small window sizes, windowBits must be 15 and a 32K byte window must
 * be supplied to be able to decompress general deflate streams.
 *
 * See inflateBack() for the usage of these routines.
 *
 * @return Z_OK on success, Z_STREAM_ERROR if any of the parameters are
 *     invalid, or Z_MEM_ERROR if the internal state could not be
 *     allocated.
 */
int inflateBackInit(z_streamp strm, int windowBits, unsigned char *window);

typedef unsigned (*in_func)(void *, const unsigned char **);
typedef int (*out_func)(void *, unsigned char *, unsigned);

/**
 * inflateBack() does a raw inflate with a single call using a call-back
 * interface for input and output. This is potentially more efficient
 * than inflate() for file i/o applications, in that it avoids copying
 * between the output and the sliding window by simply making the window
 * itself the output buffer. inflate() can be faster on modern CPUs when
 * used with large buffers. inflateBack() trusts the application to not
 * change the output buffer passed by the output function, at least
 * until inflateBack() returns.
 *
 * inflateBackInit() must be called first to allocate the internal state
 * and to initialize the state with the user-provided window buffer.
 * inflateBack() may then be used multiple times to inflate a complete,
 * raw deflate stream with each call. inflateBackEnd() is then called to
 * free the allocated state.
 *
 * A raw deflate stream is one with no zlib or gzip header or trailer.
 * This routine would normally be used in a utility that reads zip or
 * gzip files and writes out uncompressed files. The utility would
 * decode the header and process the trailer on its own, hence this
 * routine expects only the raw deflate stream to decompress. This is
 * different from the default behavior of inflate(), which expects a
 * zlib header and trailer around the deflate stream.
 *
 * inflateBack() uses two subroutines supplied by the caller that are
 * then called by inflateBack() for input and output. inflateBack()
 * calls those routines until it reads a complete deflate stream and
 * writes out all of the uncompressed data, or until it encounters an
 * error. The function's parameters and return types are defined above
 * in the in_func and out_func typedefs. inflateBack() will call
 * in(in_desc, &buf) which should return the number of bytes of provided
 * input, and a pointer to that input in buf. If there is no input
 * available, in() must return zero -- buf is ignored in that case --
 * and inflateBack() will return a buffer error. inflateBack() will call
 * out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
 * out() should return zero on success, or non-zero on failure. If out()
 * returns non-zero, inflateBack() will return with an error. Neither
 * in() nor out() are permitted to change the contents of the window
 * provided to inflateBackInit(), which is also the buffer that out()
 * uses to write from. The length written by out() will be at most the
 * window size. Any non-zero amount of input may be provided by in().
 *
 * For convenience, inflateBack() can be provided input on the first
 * call by setting strm->next_in and strm->avail_in. If that input is
 * exhausted, then in() will be called. Therefore strm->next_in must be
 * initialized before calling inflateBack(). If strm->next_in is Z_NULL,
 * then in() will be called immediately for input. If strm->next_in is
 * not Z_NULL, then strm->avail_in must also be initialized, and then if
 * strm->avail_in is not zero, input will initially be taken from
 * strm->next_in[0 .. strm->avail_in - 1].
 *
 * The in_desc and out_desc parameters of inflateBack() is passed as the
 * first parameter of in() and out() respectively when they are called.
 * These descriptors can be optionally used to pass any information that
 * the caller- supplied in() and out() functions need to do their job.
 *
 * On return, inflateBack() will set strm->next_in and strm->avail_in to
 * pass back any unused input that was provided by the last in() call.
 * The return values of inflateBack() can be Z_STREAM_END on success,
 * Z_BUF_ERROR if in() or out() returned an error, Z_DATA_ERROR if there
 * was a format error in the deflate stream (in which case strm->msg is
 * set to indicate the nature of the error), or Z_STREAM_ERROR if the
 * stream was not properly initialized. In the case of Z_BUF_ERROR, an
 * input or output error can be distinguished using strm->next_in which
 * will be Z_NULL only if in() returned an error. If strm->next_in is
 * not Z_NULL, then the Z_BUF_ERROR was due to out() returning non-zero.
 * (in() will always be called before out(), so strm->next_in is assured
 * to be defined if out() returns non-zero.) Note that inflateBack()
 * cannot return Z_OK.
 */
int inflateBack(z_streamp strm, in_func in, void *in_desc, out_func out,
                void *out_desc);

/**
 * All memory allocated by inflateBackInit() is freed.
 *
 * @return Z_OK on success, or Z_STREAM_ERROR if the stream state was
 *     inconsistent.
 */
int inflateBackEnd(z_streamp strm);

/*
 * Return flags indicating compile-time options.
 *
 * Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
 *   1.0: size of uInt
 *   3.2: size of uLong
 *   5.4: size of voidpf (pointer)
 *   7.6: size of off_t
 *
 * Compiler, assembler, and debug options:
 *   8: ZLIB_DEBUG
 *   9: ASMV or ASMINF -- use ASM code
 *   10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
 *   11: 0 (reserved)
 *
 * One-time table building (smaller code, but not thread-safe if true):
 *   12: BUILDFIXED -- build static block decoding tables when needed
 *   13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
 *   14,15: 0 (reserved)
 *
 * Library content (indicates missing functionality):
 *
 *   16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
 *   deflate code when not needed)
 *
 *   17: NO_GZIP -- deflate can't write gzip streams, and inflate can't
 *   detect and decode gzip streams (to avoid linking crc code)
 *
 *   18-19: 0 (reserved)
 *
 * Operation variations (changes in library functionality):
 *   20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
 *   21: FASTEST -- deflate algorithm with only one, lowest compression level
 *   22,23: 0 (reserved)
 *
 * The sprintf variant used by gzprintf (zero is best):
 *   24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
 *   25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
 *   26: 0 = returns value, 1 = void -- 1 means inferred string length returned
 *
 * Remainder is:
 *   27-31: 0 (reserved)
 */
uLong zlibCompileFlags(void);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » utility functions                                  ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  The following utility functions are implemented on top of the basic
  stream-oriented functions. To simplify the interface, some default
  options are assumed (compression level and memory usage, standard
  memory allocation functions). The source code of these utility
  functions can be modified if you need special options. */

/**
 * Compresses source buffer into the destination buffer. sourceLen is
 * the byte length of the source buffer. Upon entry, destLen is the
 * total size of the destination buffer, which must be at least the
 * value returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data. compress() is equivalent to
 * compress2() with a level parameter of Z_DEFAULT_COMPRESSION.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer.
 */
int compress(Bytef *dest, uLongf *destLen, const Bytef *source,
             uLong sourceLen);

/**
 * Compresses source buffer into the destination buffer. The level
 * parameter has the same meaning as in deflateInit. sourceLen is the
 * byte length of the source buffer. Upon entry, destLen is the total
 * size of the destination buffer, which must be at least the value
 * returned by compressBound(sourceLen). Upon exit, destLen is the
 * actual size of the compressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer,
 *     Z_STREAM_ERROR if the level parameter is invalid.
 */
int compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
              uLong sourceLen, int level);

/**
 * Returns an upper bound on the compressed size after compress() or
 * compress2() on sourceLen bytes. It would be used before a compress()
 * or compress2() call to allocate the destination buffer.
 */
uLong compressBound(uLong sourceLen);

/**
 * Decompresses the source buffer into the destination buffer.  sourceLen is
 * the byte length of the source buffer.  Upon entry, destLen is the total size
 * of the destination buffer, which must be large enough to hold the entire
 * uncompressed data.  (The size of the uncompressed data must have been saved
 * previously by the compressor and transmitted to the decompressor by some
 * mechanism outside the scope of this compression library.) Upon exit, destLen
 * is the actual size of the uncompressed data.
 *
 * @return Z_OK if success, Z_MEM_ERROR if there was not enough memory,
 *     Z_BUF_ERROR if there was not enough room in the output buffer, or
 *     Z_DATA_ERROR if the input data was corrupted or incomplete. In
 *     the case where there is not enough room, uncompress() will fill
 *     the output buffer with the uncompressed data up to that point.
 */
int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
               uLong sourceLen);

/**
 * Same as uncompress, except that sourceLen is a pointer, where the
 * length of the source is *sourceLen.  On return, *sourceLen is the number of
 * source bytes consumed.
 */
int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,
                uLong *sourceLen);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » gzip                                               ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│─╝
  This library supports reading and writing files in gzip (.gz) format
  with an interface similar to that of stdio, using the functions that
  start with "gz". The gzip format is different from the zlib format.
  gzip is a gzip wrapper, documented in RFC 1952, wrapped around a
  deflate stream. */

typedef struct gzFile_s *gzFile; /* semi-opaque gzip file descriptor */

/**
 * Opens a gzip (.gz) file for reading or writing.
 *
 * The mode parameter is as in fopen ("rb" or "wb") but can also include
 * a compression level ("wb9") or a strategy: 'f' for filtered data as
 * in "wb6f", 'h' for Huffman-only compression as in "wb1h", 'R' for
 * run-length encoding as in "wb1R", or 'F' for fixed code compression
 * as in "wb9F". (See the description of deflateInit2 for more
 * information about the strategy parameter.) 'T' will request
 * transparent writing or appending with no compression and not using
 * the gzip format.
 *
 * "a" can be used instead of "w" to request that the gzip stream that
 * will be written be appended to the file. "+" will result in an error,
 * since reading and writing to the same gzip file is not supported. The
 * addition of "x" when writing will create the file exclusively, which
 * fails if the file already exists. On systems that support it, the
 * addition of "e" when reading or writing will set the flag to close
 * the file on an execve() call.
 *
 * These functions, as well as gzip, will read and decode a sequence of
 * gzip streams in a file. The append function of gzopen() can be used
 * to create such a file. (Also see gzflush() for another way to do
 * this.) When appending, gzopen does not test whether the file begins
 * with a gzip stream, nor does it look for the end of the gzip streams
 * to begin appending. gzopen will simply append a gzip stream to the
 * existing file.
 *
 * gzopen can be used to read a file which is not in gzip format; in
 * this case gzread will directly read from the file without
 * decompression. When reading, this will be detected automatically by
 * looking for the magic two- byte gzip header.
 *
 * @return Z_OK if the file could not be opened, if there was insufficient
 *     memory to allocate the gzFile state, or if an invalid mode was
 *     specified (an 'r', 'w', or 'a' was not provided, or '+' was
 *     provided). errno can be checked to determine if the reason gzopen
 *     failed was that the file could not be opened.
 */
gzFile gzopen(const char *path, const char *mode);

/**
 * Associates gzFile with the file descriptor.
 *
 * File descriptors are obtained from calls like open, dup, creat, pipe
 * or fileno (if the file has been previously opened with fopen). The
 * mode parameter is as in gzopen.
 *
 * The next call of gzclose on the returned gzFile will also close the file
 * descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor
 * fd.  If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd,
 * mode);.  The duplicated descriptor should be saved to avoid a leak, since
 * gzdopen does not close fd if it fails.  If you are using fileno() to get the
 * file descriptor from a FILE *, then you will have to use dup() to avoid
 * double-close()ing the file descriptor.  Both gzclose() and fclose() will
 * close the associated file descriptor, so they need to have different file
 * descriptors.
 *
 * @return Z_OK if there was insufficient memory to allocate the gzFile
 *     state, if an invalid mode was specified (an 'r', 'w', or 'a' was
 *     not provided, or '+' was provided), or if fd is -1. The file
 *     descriptor is not used until the next gz* read, write, seek, or
 *     close operation, so gzdopen will not detect if fd is invalid
 *     (unless fd is -1).
 */
gzFile gzdopen(int fd, const char *mode);

/**
 * Sets internal buffer size used by this library's functions. The
 * default buffer size is 8192 bytes. This function must be called after
 * gzopen() or gzdopen(), and before any other calls that read or write
 * the file. The buffer memory allocation is always deferred to the
 * first read or write. Three times that size in buffer space is
 * allocated. A larger buffer size of, for example, 64K or 128K bytes
 * will noticeably increase the speed of decompression (reading).
 *
 * The new buffer size also affects the maximum length for gzprintf().
 *
 * @return Z_OK on success, or -1 on failure, such as being called too
 *     late.
 */
int gzbuffer(gzFile file, unsigned size);

/**
 * Dynamically update the compression level or strategy.  See the description
 * of deflateInit2 for the meaning of these parameters.  Previously provided
 * data is flushed before the parameter change.
 *
 * @return Z_OK if success, Z_STREAM_ERROR if the file was not opened for
 *     writing, Z_ERRNO if there is an error writing the flushed data,
 *     or Z_MEM_ERROR if there is a memory allocation error.
 */
int gzsetparams(gzFile file, int level, int strategy);

/**
 * Reads given number of uncompressed bytes from the compressed file. If
 * the input file is not in gzip format, gzread copies the given number
 * of bytes into the buffer directly from the file.
 *
 * After reaching the end of a gzip stream in the input, gzread will continue
 * to read, looking for another gzip stream.  Any number of gzip streams may be
 * concatenated in the input file, and will all be decompressed by gzread().
 * If something other than a gzip stream is encountered after a gzip stream,
 * that remaining trailing garbage is ignored (and no error is returned).
 *
 * gzread can be used to read a gzip file that is being concurrently written.
 * Upon reaching the end of the input, gzread will return with the available
 * data.  If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then
 * gzclearerr can be used to clear the end of file indicator in order to permit
 * gzread to be tried again.  Z_OK indicates that a gzip stream was completed
 * on the last gzread.  Z_BUF_ERROR indicates that the input file ended in the
 * middle of a gzip stream.  Note that gzread does not return -1 in the event
 * of an incomplete gzip stream.  This error is deferred until gzclose(), which
 * will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip
 * stream.  Alternatively, gzerror can be used before gzclose to detect this
 * case.
 *
 * @return Z_OK number of uncompressed bytes actually read, less than
 *     len for end of file, or -1 for error. If len is too large to fit
 *     in an int, then nothing is read, -1 is returned, and the error
 *     state is set to Z_STREAM_ERROR.
 */
int gzread(gzFile file, voidp buf, unsigned len);

/**
 * Read up to nitems items of size size from file to buf, otherwise operating
 * as gzread() does.  This duplicates the interface of stdio's fread(), with
 * size_t request and return types.  If the library defines size_t, then
 * size_t is identical to size_t.  If not, then size_t is an unsigned
 * integer type that can contain a pointer.
 *
 * gzfread() returns the number of full items read of size size, or zero if
 * the end of the file was reached and a full item could not be read, or if
 * there was an error.  gzerror() must be consulted if zero is returned in
 * order to determine if there was an error.  If the multiplication of size and
 * nitems overflows, i.e. the product does not fit in a size_t, then nothing
 * is read, zero is returned, and the error state is set to Z_STREAM_ERROR.
 *
 * In the event that the end of file is reached and only a partial item is
 * available at the end, i.e. the remaining uncompressed data length is not a
 * multiple of size, then the final partial item is nevetheless read into buf
 * and the end-of-file flag is set.  The length of the partial item read is not
 * provided, but could be inferred from the result of gztell().  This behavior
 * is the same as the behavior of fread() implementations in common libraries,
 * but it prevents the direct use of gzfread() to read a concurrently written
 * file, reseting and retrying on end-of-file, when size is not 1.
 */
size_t gzfread(voidp buf, size_t size, size_t nitems, gzFile file);

/**
 * Writes given number of uncompressed bytes into the compressed file.
 * gzwrite returns the number of uncompressed bytes written or 0 in case
 * of error.
 */
int gzwrite(gzFile file, voidpc buf, unsigned len);

/**
 * Writes nitems items of size size from buf to file, duplicating the
 * interface of stdio's fwrite(), with size_t request and return types.
 * If the library defines size_t, then size_t is identical to size_t. If
 * not, then size_t is an unsigned integer type that can contain a
 * pointer.
 *
 * gzfwrite() returns the number of full items written of size size, or zero
 * if there was an error.  If the multiplication of size and nitems overflows,
 * i.e. the product does not fit in a size_t, then nothing is written, zero
 * is returned, and the error state is set to Z_STREAM_ERROR.
 */
size_t gzfwrite(voidpc buf, size_t size, size_t nitems, gzFile file);

/**
 * Converts, formats, and writes the arguments to the compressed file
 * under control of the format string, as in fprintf. gzprintf returns
 * the number of uncompressed bytes actually written, or a negative zlib
 * error code in case of error. The number of uncompressed bytes written
 * is limited to 8191, or one less than the buffer size given to
 * gzbuffer(). The caller should assure that this limit is not exceeded.
 * If it is exceeded, then gzprintf() will return an error (0) with
 * nothing written. In this case, there may also be a buffer overflow
 * with unpredictable consequences, which is possible only if zlib was
 * compiled with the insecure functions sprintf() or vsprintf() because
 * the secure snprintf() or vsnprintf() functions were not available.
 * This can be determined using zlibCompileFlags().
 */
int gzprintf(gzFile file, const char *format, ...);

/**
 * Writes the given null-terminated string to the compressed file, excluding
 * the terminating null character.
 *
 * @return Z_OK number of characters written, or -1 in case of error.
 */
int gzputs(gzFile file, const char *s);

/**
 * Reads bytes from the compressed file until len-1 characters are read,
 * or a newline character is read and transferred to buf, or an
 * end-of-file condition is encountered. If any characters are read or
 * if len == 1, the string is terminated with a null character. If no
 * characters are read due to an end-of-file or len < 1, then the buffer
 * is left untouched.
 *
 * @return buf which is a null-terminated string, or it returns NULL for
 *     end-of-file or in case of error. If there was an error, the
 *     contents at buf are indeterminate.
 */
char *gzgets(gzFile file, char *buf, int len);

/**
 * Writes character converted to an unsigned char into compressed file.
 * @return value that was written, or -1 on error
 */
int gzputc(gzFile file, int c);

/**
 * Reads one byte from the compressed file. gzgetc returns this byte or
 * -1 in case of end of file or error. This is implemented as a macro
 * for speed. As such, it does not do all of the checking the other
 * functions do. I.e. it does not check to see if file is NULL, nor
 * whether the structure file points to has been clobbered or not.
 */
int gzgetc(gzFile file);

/**
 * Pushes one character back onto the stream to be read as the first
 * character on the next read. At least one character of push-back is
 * allowed. gzungetc() returns the character pushed, or -1 on failure.
 * gzungetc() will fail if c is -1, and may fail if a character has been
 * pushed but not read yet. If gzungetc is used immediately after gzopen
 * or gzdopen, at least the output buffer size of pushed characters is
 * allowed. (See gzbuffer above.) The pushed character will be discarded
 * if the stream is repositioned with gzseek() or gzrewind().
 */
int gzungetc(int c, gzFile file);

/**
 * Flushes all pending output into the compressed file. The parameter
 * flush is as in the deflate() function. The return value is the zlib
 * error number (see function gzerror below). gzflush is only permitted
 * when writing.
 *
 * If the flush parameter is Z_FINISH, the remaining data is written and
 * the gzip stream is completed in the output. If gzwrite() is called
 * again, a new gzip stream will be started in the output. gzread() is
 * able to read such concatenated gzip streams.
 *
 * gzflush should be called only when strictly necessary because it will
 * degrade compression if called too often.
 */
int gzflush(gzFile file, int flush);

/**
 * Sets starting position for the next gzread or gzwrite on the given
 * compressed file. The offset represents a number of bytes in the
 * uncompressed data stream. The whence parameter is defined as in
 * lseek(2); the value SEEK_END is not supported.
 *
 * If the file is opened for reading, this function is emulated but can be
 * extremely slow.  If the file is opened for writing, only forward seeks are
 * supported; gzseek then compresses a sequence of zeroes up to the new
 * starting position.
 *
 * @return resulting offset location as measured in bytes from the
 *     beginning of the uncompressed stream, or -1 in case of error, in
 *     particular if the file is opened for writing and the new starting
 *     position would be before the current position.
 */
ssize_t gzseek(gzFile file, int64_t offset, int whence);

/**
 * Rewinds file.
 *
 * This function is supported only for reading.
 *
 * @note gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
 */
int gzrewind(gzFile file);

/**
 * Returns starting position for the next gzread or gzwrite on the given
 * compressed file. This position represents a number of bytes in the
 * uncompressed data stream, and is zero when starting, even if
 * appending or reading a gzip stream from the middle of a file using
 * gzdopen().
 *
 * @note gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
 */
ssize_t gztell(gzFile file);

/**
 * Returns current offset in the file being read or written. This offset
 * includes the count of bytes that precede the gzip stream, for example
 * when appending or when using gzdopen() for reading. When reading, the
 * offset does not include as yet unused buffered input. This
 * information can be used for a progress indicator. On error,
 * gzoffset() returns -1.
 */
ssize_t gzoffset(gzFile file);

/**
 * Returns true (1) if the end-of-file indicator has been set while
 * reading, false (0) otherwise. Note that the end-of-file indicator is
 * set only if the read tried to go past the end of the input, but came
 * up short. Therefore, just like feof(), gzeof() may return false even
 * if there is no more data to read, in the event that the last read
 * request was for the exact number of bytes remaining in the input
 * file. This will happen if the input file size is an exact multiple of
 * the buffer size.
 *
 * If gzeof() returns true, then the read functions will return no more
 * data, unless the end-of-file indicator is reset by gzclearerr() and
 * the input file has grown since the previous end of file was detected.
 */
int gzeof(gzFile file);

/**
 * Returns true (1) if file is being copied directly while reading, or
 * false (0) if file is a gzip stream being decompressed.
 *
 * If the input file is empty, gzdirect() will return true, since the
 * input does not contain a gzip stream.
 *
 * If gzdirect() is used immediately after gzopen() or gzdopen() it will
 * cause buffers to be allocated to allow reading the file to determine
 * if it is a gzip file. Therefore if gzbuffer() is used, it should be
 * called before gzdirect().
 *
 * When writing, gzdirect() returns true (1) if transparent writing was
 * requested ("wT" for the gzopen() mode), or false (0) otherwise.
 * (Note: gzdirect() is not needed when writing. Transparent writing
 * must be explicitly requested, so the application already knows the
 * answer. When linking statically, using gzdirect() will include all of
 * the zlib code for gzip file reading and decompression, which may not
 * be desired.)
 */
int gzdirect(gzFile file);

/**
 * Flushes all pending output if necessary, closes the compressed file
 * and deallocates the (de)compression state. Note that once file is
 * closed, you cannot call gzerror with file, since its structures have
 * been deallocated. gzclose must not be called more than once on the
 * same file, just as free must not be called more than once on the same
 * allocation.
 *
 * @return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a file
 *     operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the
 *     last read ended in the middle of a gzip stream, or Z_OK on
 *     success.
 */
int gzclose(gzFile file);

/**
 * Same as gzclose(), but gzclose_r() is only for use when reading, and
 * gzclose_w() is only for use when writing or appending. The advantage
 * to using these instead of gzclose() is that they avoid linking in
 * zlib compression or decompression code that is not used when only
 * reading or only writing respectively. If gzclose() is used, then both
 * compression and decompression code will be included the application
 * when linking to a static zlib library.
 */
int gzclose_r(gzFile file);
int gzclose_w(gzFile file);

/**
 * Returns the error message for the last error which occurred on the given
 * compressed file.  errnum is set to zlib error number.  If an error occurred
 * in the file system and not in the compression library, errnum is set to
 * Z_ERRNO and the application may consult errno to get the exact error code.
 *
 * The application must not modify the returned string.  Future calls to
 * this function may invalidate the previously returned string.  If file is
 * closed, then the string previously returned by gzerror will no longer be
 * available.
 *
 * gzerror() should be used to distinguish errors from end-of-file for those
 * functions above that do not distinguish those cases in their return values.
 */
const char *gzerror(gzFile file, int *errnum);

/**
 * Clears the error and end-of-file flags for file.  This is analogous to the
 * clearerr() function in stdio.  This is useful for continuing to read a gzip
 * file that is being written concurrently.
 */
void gzclearerr(gzFile file);

/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § zlib » checksums                                          ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/

/**
 * Updates running Adler-32 checksum with the bytes buf[0..len-1] and
 * return the updated checksum. If buf is Z_NULL, this function returns
 * the required initial value for the checksum.
 */
uLong adler32(uLong adler, const Bytef *buf, uInt len);

/**
 * Same as adler32(), but with a size_t length.
 */
uLong adler32_z(uLong adler, const Bytef *buf, size_t len);

/**
 * Combine two Adler-32 checksums into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, Adler-32 checksums were
 * calculated for each, adler1 and adler2. adler32_combine() returns the
 * Adler-32 checksum of seq1 and seq2 concatenated, requiring only
 * adler1, adler2, and len2. Note that the off_t type (like off_t) is a
 * signed integer. If len2 is negative, the result has no meaning or
 * utility.
 */
uLong adler32_combine(uLong adler1, uLong adler2, int64_t len2);

/**
 * Update a running CRC-32 with the bytes buf[0..len-1] and return the
 * updated CRC-32.  If buf is Z_NULL, this function returns the required
 * initial value for the crc.  Pre- and post-conditioning (one's complement) is
 * performed within this function so it shouldn't be done by the application.
 *
 * Usage example:
 *
 *     uLong crc = crc32(0L, Z_NULL, 0);
 *     while (read_buffer(buffer, length) != EOF) {
 *       crc = crc32(crc, buffer, length);
 *     }
 *     if (crc != original_crc) error();
 */
uLong crc32(uLong crc, const Bytef *buf, uInt len);

/**
 * Same as crc32(), but with a size_t length.
 */
uint32_t crc32_z(uint32_t crc, const void *buf, size_t len);

/**
 * Combine two CRC-32 check values into one. For two sequences of bytes,
 * seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
 * calculated for each, crc1 and crc2. crc32_combine() returns the
 * CRC-32 check value of seq1 and seq2 concatenated, requiring only
 * crc1, crc2, and len2.
 */
uLong crc32_combine(uLong crc1, uLong crc2, int64_t len2);

/**
 * gzgetc() macro and its supporting function and exposed data
 * structure. Note that the real internal state is much larger than the
 * exposed structure. This abbreviated structure exposes just enough for
 * the gzgetc() macro. The user should not mess with these exposed
 * elements, since their names or behavior could change in the future,
 * perhaps even capriciously. They can only be used by the gzgetc()
 * macro. You have been warned.
 */
struct gzFile_s {
  unsigned have;
  unsigned char *next;
  int64_t pos;
};

int gzgetc_(gzFile file); /* backward compatibility */
#ifdef Z_PREFIX_SET
#undef z_gzgetc
#define z_gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#elif defined(Z_COSMO_PREFIX_SET)
#undef gzgetc
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (__gzgetc)(g))
#else
#define gzgetc(g) \
  ((g)->have ? ((g)->have--, (g)->pos++, *((g)->next)++) : (gzgetc)(g))
#endif

/* undocumented functions */
const char *zError(int);
int inflateSyncPoint(z_streamp);
int inflateUndermine(z_streamp, int);
int inflateValidate(z_streamp, int);
unsigned long inflateCodesUsed(z_streamp);
int inflateResetKeep(z_streamp);
int deflateResetKeep(z_streamp);
int gzvprintf(gzFile file, const char *format, va_list va);
void inflate_fast_chunk(z_streamp strm, unsigned start);

COSMOPOLITAN_C_END_


/*!BEGIN third_party/regex/regex.h */

#define COSMOPOLITAN_LIBC_REGEX_REGEX_H_
COSMOPOLITAN_C_START_

#if 0
/*───────────────────────────────────────────────────────────────────────────│─╗
│ cosmopolitan § regular expressions                                       ─╬─│┼
╚────────────────────────────────────────────────────────────────────────────│*/
#endif

#define REG_EXTENDED 1
#define REG_ICASE    2
#define REG_NEWLINE  4
#define REG_NOSUB    8

#define REG_NOTBOL 1 /* ^ should not match beginning of string */
#define REG_NOTEOL 2 /* $ should not match end of string */

#define REG_OK       0
#define REG_NOMATCH  1
#define REG_BADPAT   2
#define REG_ECOLLATE 3
#define REG_ECTYPE   4
#define REG_EESCAPE  5
#define REG_ESUBREG  6
#define REG_EBRACK   7
#define REG_EPAREN   8
#define REG_EBRACE   9
#define REG_BADBR    10
#define REG_ERANGE   11
#define REG_ESPACE   12
#define REG_BADRPT   13

#define REG_ENOSYS -1

typedef long regoff_t;

struct PosixRegex {
  size_t re_nsub;
  void *__opaque, *__padding[4];
  size_t __nsub2;
  char __padding2;
};

struct PosixRegexMatch {
  regoff_t rm_so;
  regoff_t rm_eo;
};

typedef struct PosixRegex regex_t;
typedef struct PosixRegexMatch regmatch_t;

int regcomp(regex_t *, const char *, int);
int regexec(const regex_t *, const char *, size_t, regmatch_t *, int);
size_t regerror(int, const regex_t *, char *, size_t);
void regfree(regex_t *);

COSMOPOLITAN_C_END_

#endif /* COSMOPOLITAN_H_ */
